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