1 /*
2  * Copyright (c) 2024 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 FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_EXTENSION_COMPANION_NODE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_EXTENSION_COMPANION_NODE_H
18 
19 #include "core/components_ng/base/extension_handler.h"
20 #include "core/interfaces/arkoala/arkoala_api.h"
21 
22 namespace OHOS::Ace::NG {
23 
24 class ExtensionCompanionNode : public ExtensionHandler {
25     DECLARE_ACE_TYPE(ExtensionCompanionNode, ExtensionHandler);
26 
27 public:
ExtensionCompanionNode(int peerId,int flags,void * peer)28     ExtensionCompanionNode(int peerId, int flags, void* peer)
29         : peerId_(peerId), flags_(flags), peer_(peer)
30     {}
31 
32     ~ExtensionCompanionNode() = default;
33 
34     ArkUI_Int32 GetPeerId() const;
35     ArkUI_Int32 GetCallbackId() const;
36     void SetCallbackId(ArkUIVMContext context, int id);
37 
SetAlignmentValue(ArkUI_Int32 value)38     void SetAlignmentValue(ArkUI_Int32 value)
39     {
40         alignment_ = value;
41     }
GetAlignmentValue()42     ArkUI_Int32 GetAlignmentValue() const
43     {
44         return alignment_;
45     }
46 
SetFlags(ArkUI_Uint32 flags)47     void SetFlags(ArkUI_Uint32 flags)
48     {
49         flags_ = flags;
50     }
51 
GetFlags()52     ArkUI_Uint32 GetFlags() const
53     {
54         return flags_;
55     }
56 
SetPeer(void * peer)57     void SetPeer(void* peer)
58     {
59         peer_ = peer;
60     }
61 
62     bool HasCustomerMeasure() const override;
63     bool HasCustomerLayout() const override;
64     bool NeedRender() const override;
65 
66     void SetExtraParam(ArkUI_Int32 type, void* extraParam);
67     ArkUI_Int64 GetExtraParam(ArkUI_Int32 type);
68     void EraseExtraParam(ArkUI_Int32 type);
69 
70 protected:
71     // FrameNode measure, layout, draw process stump function.
72     // call InnerMeasure InnerLayout InnerDraw to process origin logic.
73     void OnMeasure(const ExtensionLayoutConstraint& layoutConstraint) override;
74     void OnLayout(int32_t width, int32_t height, int32_t positionX, int32_t positionY) override;
75     void OnForegroundDraw(DrawingContext& context) override;
76     void OnDraw(DrawingContext& context) override;
77     void OnOverlayDraw(DrawingContext& context) override;
78 
79 private:
80     ArkUI_Int32 peerId_ = 0;
81     ArkUI_Int32 customCallbackId_ = 0;
82     ArkUI_Uint32 flags_ = 0;
83     void* peer_ = nullptr;
84     ArkUIVMContext context_ = nullptr;
85     ArkUI_Int32 alignment_ = 0;
86 
87     ArkUICanvasHandle GetCanvas();
88     ArkUIEventCallbackArg Arg(ArkUI_Float32 f32);
89     ArkUIEventCallbackArg Arg(ArkUI_Int32 i32);
90 
91     std::unordered_map<ArkUI_Int32, void*> extraParamMap_;
92 };
93 
94 } // namespace OHOS::Ace::NG
95 
96 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_EXTENSION_COMPANION_NODE_H