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_TEXT_TEXT_SELECT_OVERLAY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_TEXT_SELECT_OVERLAY_H 18 #include <optional> 19 20 #include "base/geometry/ng/rect_t.h" 21 #include "base/memory/ace_type.h" 22 #include "base/memory/referenced.h" 23 #include "core/components_ng/pattern/scrollable/scrollable_pattern.h" 24 #include "core/components_ng/pattern/text/base_text_select_overlay.h" 25 #include "core/components_ng/pattern/text/text_base.h" 26 27 namespace OHOS::Ace::NG { 28 class TextSelectOverlay : public BaseTextSelectOverlay { 29 DECLARE_ACE_TYPE(TextSelectOverlay, BaseTextSelectOverlay); 30 31 public: TextSelectOverlay(const WeakPtr<TextBase> & textBase)32 explicit TextSelectOverlay(const WeakPtr<TextBase>& textBase) : BaseTextSelectOverlay(textBase) {} 33 ~TextSelectOverlay() = default; 34 35 // override TextBaseSelectOverlay 36 bool PreProcessOverlay(const OverlayRequest& request) override; 37 bool CheckHandleVisible(const RectF& paintRect) override; 38 bool CheckAndAdjustHandle(RectF& paintRect); 39 bool CheckAndAdjustHandleWithContent(const RectF& contentRect, RectF& paintRect); 40 void OnResetTextSelection() override; 41 RectF GetHandleLocalPaintRect(DragHandleIndex dragHandleIndex) override; 42 void OnAncestorNodeChanged(FrameNodeChangeInfoFlag flag) override; 43 44 // override SelectOverlayHolder 45 std::optional<SelectHandleInfo> GetFirstHandleInfo() override; 46 std::optional<SelectHandleInfo> GetSecondHandleInfo() override; 47 void OnUpdateMenuInfo(SelectMenuInfo& menuInfo, SelectOverlayDirtyFlag dirtyFlag) override; 48 void OnUpdateSelectOverlayInfo(SelectOverlayInfo& overlayInfo, int32_t requestCode) override; 49 void GetSelectAreaFromHandle(RectF& rect); 50 std::string GetSelectedText() override; 51 52 // override SelectOverlayCallback 53 void OnMenuItemAction(OptionMenuActionId id, OptionMenuType type) override; 54 void OnMenuItemAction(OptionMenuActionId id, OptionMenuType type, const std::string& labelInfo) override; 55 void OnHandleMove(const RectF& rect, bool isFirst) override; 56 void OnHandleMoveDone(const RectF& rect, bool isFirst) override; 57 void OnCloseOverlay(OptionMenuType menuType, CloseReason reason, RefPtr<OverlayInfo> info = nullptr) override; 58 void OnHandleGlobalTouchEvent(SourceType sourceType, TouchType touchType, bool touchInside = true) override; 59 void OnHandleLevelModeChanged(HandleLevelMode mode) override; 60 void OnHandleMoveStart(const GestureEvent& event, bool isFirst) override; 61 UpdateHandleGlobalOffset()62 void UpdateHandleGlobalOffset() 63 { 64 HasRenderTransform(); 65 handleGlobalOffset_ = GetPaintOffsetWithoutTransform(); 66 } 67 GetHandleGlobalOffset()68 const OffsetF& GetHandleGlobalOffset() const 69 { 70 return handleGlobalOffset_; 71 } 72 IsRegisterTouchCallback()73 bool IsRegisterTouchCallback() override 74 { 75 return true; 76 } 77 void OnOverlayClick(const GestureEvent& event, bool isFirst) override; 78 void TriggerScrollableParentToScroll( 79 const RefPtr<ScrollablePattern> scrollableParent, const Offset& globalOffset, bool isStopAutoScroll); 80 const RefPtr<ScrollablePattern> FindScrollableParent(); 81 std::optional<Color> GetHandleColor() override; 82 std::optional<SelectOverlayInfo> GetSelectOverlayInfo(); 83 bool ChangeSecondHandleHeight(const GestureEvent& event, bool isOverlayMode) override; 84 void GetVisibleDragViewHandles(RectF& first, RectF& second); 85 void IsAIMenuOptionChanged(SelectMenuInfo& menuInfo) override; 86 87 protected: 88 OffsetF GetHandleReferenceOffset(const RectF& handleRect); 89 virtual void UpdateSelectorOnHandleMove(const OffsetF& handleOffset, bool isFirstHandle); UpdateTransformFlag()90 void UpdateTransformFlag() override 91 { 92 hasTransform_ = CheckHasTransformAttr(); 93 } IsClipHandleWithViewPort()94 bool IsClipHandleWithViewPort() override 95 { 96 return !HasRenderTransform(); 97 } 98 void UpdateClipHandleViewPort(RectF& rect) override; 99 bool AllowTranslate() override; 100 bool AllowSearch() override; 101 bool AllowShare() override; 102 bool selectTextUseTopHandle = false; 103 RectF GetSelectAreaFromRects(SelectRectsType pos) override; 104 105 private: 106 OffsetF GetHotPaintOffset(); 107 bool GetRenderClipValue() const; 108 OffsetF handleGlobalOffset_; 109 bool isDraggingFirstHandle_ = true; 110 OffsetF hostPaintOffset_; 111 ACE_DISALLOW_COPY_AND_MOVE(TextSelectOverlay); 112 }; 113 114 } // namespace OHOS::Ace::NG 115 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_TEXT_SELECT_OVERLAY_H 116