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 UpdateStart(const JSCallbackInfo& info);
48     void UpdateEnd(const JSCallbackInfo& info);
Dispose(const JSCallbackInfo &)49     void Dispose(const JSCallbackInfo&  /*info*/)
50     {
51         viewNode_.Reset();
52     }
53 
54 private:
55     RefPtr<NG::FrameNode> viewNode_;
56     NG::OptionalSizeF size_;
57     NodeRenderType renderType_ = NodeRenderType::RENDER_TYPE_DISPLAY;
58     std::string surfaceId_;
59     std::unique_ptr<NG::ScopedViewStackProcessor> scopedViewStackProcessor_;
60 };
61 } // namespace OHOS::Ace::Framework
62 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_BASE_NODE_H
63