1 /* 2 * Copyright (c) 2023 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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_BASE_NODE_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_BASE_NODE_H 18 19 #include "base/geometry/ng/size_t.h" 20 #include "base/memory/ace_type.h" 21 #include "base/utils/utils.h" 22 #include "bridge/declarative_frontend/engine/functions/js_function.h" 23 #include "bridge/declarative_frontend/engine/js_types.h" 24 #include "core/components_ng/base/frame_node.h" 25 #include "core/components_ng/base/ui_node.h" 26 #include "core/components_ng/base/view_stack_processor.h" 27 #include "frameworks/bridge/declarative_frontend/engine/bindings_defines.h" 28 29 namespace OHOS::Ace::Framework { 30 class JSBaseNode : public AceType { 31 DECLARE_ACE_TYPE(JSBaseNode, AceType); 32 public: 33 JSBaseNode() = default; JSBaseNode(const NG::OptionalSizeF & size,NodeRenderType renderType,std::string surfaceId)34 JSBaseNode(const NG::OptionalSizeF& size, NodeRenderType renderType, std::string surfaceId) 35 : size_(size), renderType_(renderType), surfaceId_(std::move(surfaceId)) 36 {} 37 ~JSBaseNode() override = default; 38 39 static void JSBind(BindingTarget globalObj); 40 static void ConstructorCallback(const JSCallbackInfo& info); 41 static void DestructorCallback(JSBaseNode* node); 42 void FinishUpdateFunc(const JSCallbackInfo& info); 43 void Create(const JSCallbackInfo& info); 44 void BuildNode(const JSCallbackInfo& info); 45 void ProccessNode(bool isSupportExportTexture, bool isSupportLazyBuild); 46 void PostTouchEvent(const JSCallbackInfo& info); 47 void PostInputEvent(const JSCallbackInfo& info); 48 void UpdateStart(const JSCallbackInfo& info); 49 void UpdateEnd(const JSCallbackInfo& info); 50 void OnRecycleWithBindThis(const JSCallbackInfo& info); 51 void OnReuseWithBindThis(const JSCallbackInfo& info); Dispose(const JSCallbackInfo &)52 void Dispose(const JSCallbackInfo& /*info*/) 53 { 54 viewNode_.Reset(); 55 realNode_.Reset(); 56 } 57 58 private: 59 bool InitTouchEvent(const JSCallbackInfo& info, TouchEvent& touchEvent, bool isPostTouchEvent); 60 bool InitMouseEvent(const JSCallbackInfo& info, MouseEvent& mouseEvent); 61 bool InitAxisEvent(const JSCallbackInfo& info, AxisEvent& axisEvent); 62 bool GetTouches(const JSCallbackInfo& info, TouchEvent& touchEvent); 63 bool GetInputTouches(const JSCallbackInfo& info, TouchEvent& touchEvent); 64 bool ParamTouchEvent(const JSCallbackInfo& info, TouchEvent& touchEvent); 65 bool ParamMouseEvent(const JSCallbackInfo& info, MouseEvent& mouseEvent); 66 bool ParamAxisEvent(const JSCallbackInfo& info, AxisEvent& axisEvent); 67 bool GetChangedTouches(const JSCallbackInfo& info, TouchEvent& touchEvent); 68 RefPtr<NG::FrameNode> viewNode_; 69 RefPtr<NG::UINode> realNode_; 70 NG::OptionalSizeF size_; 71 NodeRenderType renderType_ = NodeRenderType::RENDER_TYPE_DISPLAY; 72 std::string surfaceId_; 73 std::unique_ptr<NG::ScopedViewStackProcessor> scopedViewStackProcessor_; 74 }; 75 } // namespace OHOS::Ace::Framework 76 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_BASE_NODE_H 77