• 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_PATTERN_RICH_EDITOR_RICH_EDITOR_SELECT_OVERLAY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_RICH_EDITOR_RICH_EDITOR_SELECT_OVERLAY_H
18 #include <optional>
19 
20 #include "core/components_ng/pattern/text/text_select_overlay.h"
21 
22 namespace OHOS::Ace::NG {
23 class RichEditorSelectOverlay : public TextSelectOverlay {
24     DECLARE_ACE_TYPE(RichEditorSelectOverlay, TextSelectOverlay);
25 
26 public:
RichEditorSelectOverlay(const WeakPtr<TextBase> & textBase)27     explicit RichEditorSelectOverlay(const WeakPtr<TextBase>& textBase) : TextSelectOverlay(textBase) {}
28     ~RichEditorSelectOverlay() = default;
29 
30     // override TextBaseSelectOverlay
31     bool PreProcessOverlay(const OverlayRequest& request) override;
32     bool CheckHandleVisible(const RectF& paintRect) override;
33     void OnResetTextSelection() override;
34     void AfterCloseOverlay() override;
35     void OnAncestorNodeChanged(FrameNodeChangeInfoFlag flag) override;
36 
37     // override SelectOverlayHolder
38     std::optional<SelectHandleInfo> GetFirstHandleInfo() override;
39     std::optional<SelectHandleInfo> GetSecondHandleInfo() override;
40     void OnUpdateMenuInfo(SelectMenuInfo& menuInfo, SelectOverlayDirtyFlag dirtyFlag) override;
41     void OnUpdateSelectOverlayInfo(SelectOverlayInfo& overlayInfo, int32_t requestCode) override;
42     std::string GetSelectedText() override;
43     bool IsStopBackPress() const override;
44 
45     // override SelectOverlayCallback
46     void OnMenuItemAction(OptionMenuActionId id, OptionMenuType type) override;
47     void OnMenuItemAction(OptionMenuActionId id, OptionMenuType type, const std::string& labelInfo) override;
48     void OnOverlayTouchDown(const TouchEventInfo& event) override;
49     void OnHandleMove(const RectF& rect, bool isFirst) override;
50     void OnHandleMoveDone(const RectF& rect, bool isFirst) override;
51     void OnCloseOverlay(OptionMenuType menuType, CloseReason reason, RefPtr<OverlayInfo> info = nullptr) override;
52     void OnHandleGlobalTouchEvent(SourceType sourceType, TouchType touchType, bool touchInside = true) override;
53     void OnHandleLevelModeChanged(HandleLevelMode mode) override;
54     void OnHandleMarkInfoChange(std::shared_ptr<SelectOverlayInfo> info, SelectOverlayDirtyFlag flag) override;
55     void UpdateHandleColor();
56     std::optional<SelectOverlayInfo> GetSelectOverlayInfo();
57     bool IsSingleHandleShow();
58     void UpdateMenuOffset();
59     bool IsBothHandlesShow();
60     bool IsHandleShow();
61     void OnHandleMoveStart(const GestureEvent& event, bool isFirst) override;
62     void UpdateHandleOffset();
63     void UpdateFirstHandleOffset() override;
64     void UpdateSecondHandleOffset() override;
65     void UpdateSelectOverlayOnAreaChanged();
66     void ToggleMenu();
GetIsHandleMoving()67     bool GetIsHandleMoving()
68     {
69         return isHandleMoving_;
70     }
GetIsHandleHidden()71     bool GetIsHandleHidden()
72     {
73         return handleIsHidden_;
74     }
IsSingleHandleMoving()75     bool IsSingleHandleMoving()
76     {
77         return isHandleMoving_ && IsSingleHandle();
78     }
NeedRefreshMenu()79     bool NeedRefreshMenu()
80     {
81         return needRefreshMenu_;
82     }
83     void OnHandleIsHidden() override;
84     void OnOverlayClick(const GestureEvent& event, bool isFirst) override;
85     void OnHandleMouseEvent(const MouseInfo& event) override;
86     void OnAfterSelectOverlayShow(bool isCreate) override;
87     bool IsRightButtonCustomMenuShow();
IsRegisterTouchCallback()88     bool IsRegisterTouchCallback() override
89     {
90         return true;
91     }
92     RectF GetVisibleRect();
93     float GetHandleHotZoneRadius();
94     bool IsMenuShow();
95 
96 protected:
97     RectF GetSelectAreaFromRects(SelectRectsType pos) override;
98 
99 private:
100     void RemoveAreaChangeInner();
101     void CloseMagnifier();
102     void UpdateSelectorOnHandleMove(const OffsetF& handleOffset, bool isFirstHandle) override;
103     void CheckMenuParamChange(SelectOverlayInfo& selectInfo, TextSpanType selectType, TextResponseType responseType);
104     void SwitchCaretState(std::shared_ptr<SelectOverlayInfo> info);
105     void SetMagnifierOffset(const OffsetF& localOffset, const RectF& handleRect);
106     void OnUpdateOnCreateMenuCallback(SelectOverlayInfo& selectInfo);
107     void ResumeTwinkling();
108     std::shared_ptr<SelectionMenuParams> lastMenuParams_ = nullptr;
109     std::pair<TextSpanType, TextResponseType> lastSelectResponseComb_;
110     bool needRefreshMenu_ = false;
111     bool recreateAfterMoveDone_ = false;
112     bool handleIsHidden_ = true;
113     std::pair<int32_t, int32_t> initSelector_ = { 0, 0 };
114 
115     ACE_DISALLOW_COPY_AND_MOVE(RichEditorSelectOverlay);
116 };
117 
118 } // namespace OHOS::Ace::NG
119 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_RICH_EDITOR_RICH_EDITOR_SELECT_OVERLAY_H
120