1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ACELITE_EVENT_UTIL_H 17 #define OHOS_ACELITE_EVENT_UTIL_H 18 19 #include "non_copyable.h" 20 #include "ui_view.h" 21 #include "wrapper/js.h" 22 23 namespace OHOS { 24 namespace ACELite { 25 struct CallbackParams : public MemoryHeap { 26 JSValue vm; 27 JSValue fn; 28 JSValue arg; 29 }; 30 class EventUtil final : public MemoryHeap { 31 public: 32 ACE_DISALLOW_COPY_AND_MOVE(EventUtil); 33 34 /** 35 * @brief Create a JAVASCRIPT plain object that is used as the input parameter of 36 * the callback function for click or longpress event. 37 */ 38 static JSValue CreateEvent(const char *type, UIView &view, const Event &event); 39 40 /** 41 * @brief Create a JAVASCRIPT plain object that is used as the input parameter of 42 * the callback function for swipe event. 43 */ 44 static JSValue CreateSwipeEvent(UIView &view, const DragEvent &event); 45 46 /** 47 * @brief Create a JAVASCRIPT plain object that is used as the input parameter of 48 * the callback function for touch event. 49 */ 50 static JSValue CreateTouchEvent(UIView &view, const DragEvent &event); 51 52 /** 53 * @brief Invoke the callback function of event. 54 */ 55 static void InvokeCallback(JSValue vm, JSValue callback, JSValue event, const void *context = nullptr); 56 57 static const char *EVENT_CLICK; 58 static const char *EVENT_LONGPRESS; 59 static const char *EVENT_SWIPE; 60 static const char *EVENT_TOUCH; 61 62 private: EventUtil()63 EventUtil() {} ~EventUtil()64 ~EventUtil() {} 65 66 /** 67 * @brief Get the DOM element that is reference to view 68 */ 69 static JSValue GetElementByUIView(UIView *view); 70 }; 71 } // namespace ACELite 72 } // namespace OHOS 73 74 #endif // OHOS_ACELITE_EVENT_UTIL_H 75