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 class ACE_EXPORT SelectOverlayHolder : public virtual AceType {
31     DECLARE_ACE_TYPE(SelectOverlayHolder, AceType);
32 
33 public:
34     SelectOverlayHolder() = default;
35     ~SelectOverlayHolder() override = default;
36 
OnBind(const WeakPtr<AceType> & manager)37     void OnBind(const WeakPtr<AceType>& manager)
38     {
39         bindManager_ = manager;
40         if (manager.Invalid()) {
41             auto callback = GetCallback();
42             CHECK_NULL_VOID(callback);
43             callback->OnUnbind();
44         }
45     }
46 
47     template<typename T>
GetManager()48     RefPtr<T> GetManager() const
49     {
50         return DynamicCast<T>(bindManager_.Upgrade());
51     }
52 
GetOwnerId()53     virtual int32_t GetOwnerId()
54     {
55         auto owner = GetOwner();
56         return owner ? owner->GetId() : -1;
57     }
58 
GetOwner()59     virtual RefPtr<FrameNode> GetOwner()
60     {
61         return nullptr;
62     }
63 
GetFirstHandleInfo()64     virtual std::optional<SelectHandleInfo> GetFirstHandleInfo()
65     {
66         return std::nullopt;
67     }
68 
GetSecondHandleInfo()69     virtual std::optional<SelectHandleInfo> GetSecondHandleInfo()
70     {
71         return std::nullopt;
72     }
73 
OnUpdateMenuInfo(SelectMenuInfo & menuInfo,SelectOverlayDirtyFlag dirtyFlag)74     virtual void OnUpdateMenuInfo(SelectMenuInfo& menuInfo, SelectOverlayDirtyFlag dirtyFlag) {}
75 
OnUpdateSelectOverlayInfo(SelectOverlayInfo & overlayInfo,int32_t requestCode)76     virtual void OnUpdateSelectOverlayInfo(SelectOverlayInfo& overlayInfo, int32_t requestCode) {}
77 
OnHandleMarkInfoChange(std::shared_ptr<SelectOverlayInfo> info,SelectOverlayDirtyFlag flag)78     virtual void OnHandleMarkInfoChange(std::shared_ptr<SelectOverlayInfo> info, SelectOverlayDirtyFlag flag) {}
79 
OnHandleExistOverlay(SelectOverlayInfo info,int32_t requestCode)80     virtual void OnHandleExistOverlay(SelectOverlayInfo info, int32_t requestCode) {}
81 
GetAncestorNodeViewPort()82     virtual std::optional<RectF> GetAncestorNodeViewPort()
83     {
84         return std::nullopt;
85     }
86 
CheckRestartHiddenHandleTask(int32_t requestCode)87     virtual bool CheckRestartHiddenHandleTask(int32_t requestCode)
88     {
89         return true;
90     }
91 
GetCallback()92     virtual RefPtr<SelectOverlayCallback> GetCallback()
93     {
94         return nullptr;
95     }
96 
GetSelectArea()97     virtual RectF GetSelectArea()
98     {
99         return {};
100     }
101 
GetSelectedText()102     virtual std::string GetSelectedText()
103     {
104         return "";
105     }
106 private:
107     WeakPtr<AceType> bindManager_;
108     ACE_DISALLOW_COPY_AND_MOVE(SelectOverlayHolder);
109 };
110 } // namespace OHOS::Ace::NG
111 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_SELECT_CONTENT_OVERLAY_SELECT_OVERLAY_HOLDER_H
112