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 GetFirstHandleLocalPaintRect() override; 42 RectF GetSecondHandleLocalPaintRect() override; 43 void OnAncestorNodeChanged(FrameNodeChangeInfoFlag flag) override; 44 45 // override SelectOverlayHolder 46 std::optional<SelectHandleInfo> GetFirstHandleInfo() override; 47 std::optional<SelectHandleInfo> GetSecondHandleInfo() override; 48 void OnUpdateMenuInfo(SelectMenuInfo& menuInfo, SelectOverlayDirtyFlag dirtyFlag) override; 49 void OnUpdateSelectOverlayInfo(SelectOverlayInfo& overlayInfo, int32_t requestCode) override; 50 void GetSelectAreaFromHandle(RectF& rect); 51 std::string GetSelectedText() override; 52 53 // override SelectOverlayCallback 54 void OnMenuItemAction(OptionMenuActionId id, OptionMenuType type) 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 83 protected: 84 virtual void UpdateSelectorOnHandleMove(const OffsetF& handleOffset, bool isFirstHandle); UpdateTransformFlag()85 void UpdateTransformFlag() override 86 { 87 hasTransform_ = CheckHasTransformAttr(); 88 } IsClipHandleWithViewPort()89 bool IsClipHandleWithViewPort() override 90 { 91 return !HasRenderTransform(); 92 } 93 void UpdateClipHandleViewPort(RectF& rect) override; 94 bool AllowTranslate() override; 95 bool selectTextUseTopHandle = false; 96 RectF GetSelectAreaFromRects(SelectRectsType pos) override; 97 98 private: 99 OffsetF GetHotPaintOffset(); 100 OffsetF handleGlobalOffset_; 101 bool isDraggingFirstHandle_ = true; 102 OffsetF hostPaintOffset_; 103 ACE_DISALLOW_COPY_AND_MOVE(TextSelectOverlay); 104 }; 105 106 } // namespace OHOS::Ace::NG 107 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_TEXT_SELECT_OVERLAY_H 108