• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_SELECT_OVERLAY_SELECT_OVERLAY_CLIENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_SELECT_OVERLAY_SELECT_OVERLAY_CLIENT_H
18 
19 #include <cstdint>
20 #include <functional>
21 #include <vector>
22 
23 #include "base/geometry/offset.h"
24 #include "base/memory/ace_type.h"
25 #include "base/memory/referenced.h"
26 #include "core/components_ng/base/frame_node.h"
27 #include "core/components_ng/manager/select_overlay/select_overlay_proxy.h"
28 #include "core/components_ng/manager/select_overlay/selection_host.h"
29 #include "core/components_ng/pattern/select_overlay/select_overlay_property.h"
30 #include "core/pipeline_ng/pipeline_context.h"
31 
32 namespace OHOS::Ace::NG {
33 
34 enum class HandleShowMode { DOUBLE, SINGLE, NONE };
35 
36 struct OverlayExtraInfo {
37     std::map<std::string, bool> boolExtra;
38 
GetBoolOrDefaultOverlayExtraInfo39     bool GetBoolOrDefault(std::string key, bool defaultValue)
40     {
41         auto it = boolExtra.find(key);
42         if (it == boolExtra.end()) {
43             return defaultValue;
44         }
45         return it->second;
46     };
47 };
48 
49 struct ClientOverlayInfo {
50     std::optional<SelectHandleInfo> firstHandleInfo;
51     std::optional<SelectHandleInfo> secondHandleInfo;
52     RectF selectArea;
53     bool isNewAvoid = false;
54     bool animation = true;
55     bool isMenuShow = true;
56     bool isShowMouseMenu = false;
57     bool isShowPaste = false;
58     bool isUpdateMenu = true;
59 };
60 
61 struct ScrollableParentInfo {
62     bool hasParent = true;
63     std::vector<int32_t> parentIds;
64 };
65 
66 enum class SelectOverlayMenuId {
67     COPY,
68     CUT,
69     PASTE,
70     SELECT_ALL,
71     CAMERA_INPUT
72 };
73 
74 class SelectOverlayClient : public SelectionHost {
75     DECLARE_ACE_TYPE(SelectOverlayClient, SelectionHost);
76 
77 public:
78     void InitSelectOverlay();
79     void RequestOpenSelectOverlay(ClientOverlayInfo& overlayInfo);
80     virtual void RequestCloseSelectOverlay(bool animation);
81     bool SelectOverlayIsOn();
82 
CheckHandleVisible(const RectF & paintRect)83     virtual bool CheckHandleVisible(const RectF& paintRect)
84     {
85         return true;
86     }
87 
CheckSelectionRectVisible()88     virtual bool CheckSelectionRectVisible()
89     {
90         return false;
91     }
92 
OnPreShowSelectOverlay(SelectOverlayInfo & overlayInfo,const ClientOverlayInfo & clientInfo,bool isSelectOverlayOn)93     virtual bool OnPreShowSelectOverlay(
94         SelectOverlayInfo& overlayInfo, const ClientOverlayInfo& clientInfo, bool isSelectOverlayOn)
95     {
96         return false;
97     }
98 
OnSelectOverlayMenuClicked(SelectOverlayMenuId menuId)99     virtual void OnSelectOverlayMenuClicked(SelectOverlayMenuId menuId) {}
OnHandleMoveStart(bool isFirst)100     virtual void OnHandleMoveStart(bool isFirst) {}
OnHandleMove(const RectF &,bool isFirst)101     virtual void OnHandleMove(const RectF&, bool isFirst) {}
OnHandleMoveDone(const RectF &,bool isFirst)102     virtual void OnHandleMoveDone(const RectF&, bool isFirst) {}
OnHandleClosed(bool closedByGlobalEvent)103     virtual void OnHandleClosed(bool closedByGlobalEvent)
104     {
105         if (closedByGlobalEvent) {
106             StopListeningScrollableParent(GetClientHost());
107         }
108     }
109 
110     virtual RefPtr<FrameNode> GetClientHost() const = 0;
111     void UpdateSelectInfo(const std::string& selectInfo);
112 
SetMenuOptionItems(std::vector<MenuOptionsParam> && menuOptionItems)113     void SetMenuOptionItems(std::vector<MenuOptionsParam>&& menuOptionItems)
114     {
115         menuOptionItems_ = std::move(menuOptionItems);
116     }
117 
GetMenuOptionItems()118     const std::vector<MenuOptionsParam>&& GetMenuOptionItems() const
119     {
120         return std::move(menuOptionItems_);
121     }
122 
123     virtual void OnParentScrollStartOrEnd(bool isEnd, bool noAnimation = false);
124 
OnParentScrollCallback(Axis axis,int32_t offset)125     virtual void OnParentScrollCallback(Axis axis, int32_t offset) {};
126 
127     void StartListeningScrollableParent(const RefPtr<FrameNode>& host);
128 
129     void StopListeningScrollableParent(const RefPtr<FrameNode>& host);
130 
131     void UpdateSelectMenuInfo(std::function<void(SelectMenuInfo&)> updateAction);
132 
133     void UpdateSelectMenuVisibility(bool isVisible);
134 
IsShowingSingleHandle()135     bool IsShowingSingleHandle()
136     {
137         auto proxy = GetSelectOverlayProxy();
138         CHECK_NULL_RETURN(proxy, false);
139         return proxy->IsSingleHandle();
140     }
141 
142     RectF GetVisibleContentRect(WeakPtr<FrameNode> parent, RectF visibleRect);
143 
144 protected:
GetSelectOverlayProxy()145     const RefPtr<SelectOverlayProxy>& GetSelectOverlayProxy()
146     {
147         return selectOverlayProxy_;
148     }
149 
ResetSelectOverlayClient()150     void ResetSelectOverlayClient()
151     {
152         scrollableParentInfo_.hasParent = true;
153         scrollableParentInfo_.parentIds.clear();
154     }
155 
UpdateOriginIsMenuShow(bool isShow)156     void UpdateOriginIsMenuShow(bool isShow)
157     {
158         originIsMenuShow_ = isShow;
159     }
160 
GetOriginIsMenuShow()161     bool GetOriginIsMenuShow()
162     {
163         return originIsMenuShow_;
164     }
165 
166 private:
167     bool originIsMenuShow_ = true;
168     void RegisterParentScrollCallback(int32_t parentId, int32_t callbackId);
169     std::optional<SelectOverlayInfo> GetSelectOverlayInfo(const ClientOverlayInfo& clientInfo);
170     void CreateSelectOverlay(const ClientOverlayInfo& showOverlayInfo);
171     void UpdateShowingSelectOverlay(ClientOverlayInfo& clientInfo);
172     ScrollableParentInfo scrollableParentInfo_;
173     SelectOverlayInfo selectOverlayInfo_;
174     RefPtr<SelectOverlayProxy> selectOverlayProxy_;
175     std::vector<MenuOptionsParam> menuOptionItems_;
176 };
177 } // namespace OHOS::Ace::NG
178 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_SELECT_OVERLAY_SELECT_OVERLAY_CLIENT_H