• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COMPONENTS_NG_MANAGER_SELECT_CONTENT_OVERLAY_SELECT_OVERLAY_HOLDER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_SELECT_CONTENT_OVERLAY_SELECT_OVERLAY_HOLDER_H
18 
19 #include <optional>
20 
21 #include "base/memory/ace_type.h"
22 #include "base/memory/referenced.h"
23 #include "base/utils/utils.h"
24 #include "core/components_ng/base/frame_node.h"
25 #include "core/components_ng/event/gesture_event_hub.h"
26 #include "core/components_ng/manager/select_content_overlay/select_overlay_callback.h"
27 #include "core/components_ng/pattern/select_overlay/select_overlay_property.h"
28 
29 namespace OHOS::Ace::NG {
30 
31 enum class SelectRectsType {
32     ALL_LINES, LEFT_TOP_POINT, RIGHT_BOTTOM_POINT
33 };
34 
35 class ACE_EXPORT SelectOverlayHolder : public virtual AceType {
36     DECLARE_ACE_TYPE(SelectOverlayHolder, AceType);
37 
38 public:
39     SelectOverlayHolder() = default;
40     ~SelectOverlayHolder() override = default;
41 
OnBind(const WeakPtr<AceType> & manager)42     void OnBind(const WeakPtr<AceType>& manager)
43     {
44         bindManager_ = manager;
45         if (manager.Invalid()) {
46             auto callback = GetCallback();
47             CHECK_NULL_VOID(callback);
48             callback->OnUnbind();
49         }
50     }
51 
52     template<typename T>
GetManager()53     RefPtr<T> GetManager() const
54     {
55         return DynamicCast<T>(bindManager_.Upgrade());
56     }
57 
GetOwnerId()58     virtual int32_t GetOwnerId()
59     {
60         auto owner = GetOwner();
61         return owner ? owner->GetId() : -1;
62     }
63 
GetOwner()64     virtual RefPtr<FrameNode> GetOwner()
65     {
66         return nullptr;
67     }
68 
GetFirstHandleInfo()69     virtual std::optional<SelectHandleInfo> GetFirstHandleInfo()
70     {
71         return std::nullopt;
72     }
73 
GetSecondHandleInfo()74     virtual std::optional<SelectHandleInfo> GetSecondHandleInfo()
75     {
76         return std::nullopt;
77     }
78 
OnUpdateMenuInfo(SelectMenuInfo & menuInfo,SelectOverlayDirtyFlag dirtyFlag)79     virtual void OnUpdateMenuInfo(SelectMenuInfo& menuInfo, SelectOverlayDirtyFlag dirtyFlag) {}
80 
OnUpdateSelectOverlayInfo(SelectOverlayInfo & overlayInfo,int32_t requestCode)81     virtual void OnUpdateSelectOverlayInfo(SelectOverlayInfo& overlayInfo, int32_t requestCode) {}
82 
OnHandleMarkInfoChange(std::shared_ptr<SelectOverlayInfo> info,SelectOverlayDirtyFlag flag)83     virtual void OnHandleMarkInfoChange(std::shared_ptr<SelectOverlayInfo> info, SelectOverlayDirtyFlag flag) {}
84 
OnHandleExistOverlay(SelectOverlayInfo info,int32_t requestCode)85     virtual void OnHandleExistOverlay(SelectOverlayInfo info, int32_t requestCode) {}
86 
GetAncestorNodeViewPort()87     virtual std::optional<RectF> GetAncestorNodeViewPort()
88     {
89         return std::nullopt;
90     }
91 
CheckRestartHiddenHandleTask(int32_t requestCode)92     virtual bool CheckRestartHiddenHandleTask(int32_t requestCode)
93     {
94         return true;
95     }
96 
GetCallback()97     virtual RefPtr<SelectOverlayCallback> GetCallback()
98     {
99         return nullptr;
100     }
101 
GetSelectArea()102     virtual RectF GetSelectArea()
103     {
104         return GetSelectAreaFromRects(SelectRectsType::ALL_LINES);
105     }
106 
GetSelectAreaStartLeftTop()107     virtual EdgeF GetSelectAreaStartLeftTop()
108     {
109         auto rect = GetSelectAreaFromRects(SelectRectsType::LEFT_TOP_POINT);
110         return { rect.Left(), rect.Top() };
111     }
112 
GetSelectAreaEndRightBottom()113     virtual EdgeF GetSelectAreaEndRightBottom()
114     {
115         auto rect = GetSelectAreaFromRects(SelectRectsType::RIGHT_BOTTOM_POINT);
116         return { rect.Right(), rect.Bottom() };
117     }
118 
GetSelectedText()119     virtual std::string GetSelectedText()
120     {
121         return "";
122     }
123 
IsEnableContainerModal()124     virtual bool IsEnableContainerModal()
125     {
126         return false;
127     }
128 
IsStopBackPress()129     virtual bool IsStopBackPress() const
130     {
131         return true;
132     }
133 
134 protected:
GetSelectAreaFromRects(SelectRectsType pos)135     virtual RectF GetSelectAreaFromRects(SelectRectsType pos)
136     {
137         return {};
138     }
139 
140 private:
141     WeakPtr<AceType> bindManager_;
142 
143     ACE_DISALLOW_COPY_AND_MOVE(SelectOverlayHolder);
144 };
145 } // namespace OHOS::Ace::NG
146 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_SELECT_CONTENT_OVERLAY_SELECT_OVERLAY_HOLDER_H
147