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 RectF GetSelectArea() override; 51 void GetSelectAreaFromHandle(RectF& rect); 52 std::string GetSelectedText() override; 53 54 // override SelectOverlayCallback 55 void OnMenuItemAction(OptionMenuActionId id, OptionMenuType type) override; 56 void OnHandleMove(const RectF& rect, bool isFirst) override; 57 void OnHandleMoveDone(const RectF& rect, bool isFirst) override; 58 void OnCloseOverlay(OptionMenuType menuType, CloseReason reason, RefPtr<OverlayInfo> info = nullptr) override; 59 void OnHandleGlobalTouchEvent(SourceType sourceType, TouchType touchType, bool touchInside = true) override; 60 void OnHandleLevelModeChanged(HandleLevelMode mode) override; 61 void OnHandleMoveStart(const GestureEvent& event, bool isFirst) override; 62 UpdateHandleGlobalOffset()63 void UpdateHandleGlobalOffset() 64 { 65 HasRenderTransform(); 66 handleGlobalOffset_ = GetPaintOffsetWithoutTransform(); 67 } 68 GetHandleGlobalOffset()69 const OffsetF& GetHandleGlobalOffset() const 70 { 71 return handleGlobalOffset_; 72 } 73 IsRegisterTouchCallback()74 bool IsRegisterTouchCallback() override 75 { 76 return true; 77 } 78 void OnOverlayClick(const GestureEvent& event, bool isFirst) override; 79 void TriggerScrollableParentToScroll( 80 const RefPtr<ScrollablePattern> scrollableParent, const Offset& globalOffset, bool isStopAutoScroll); 81 const RefPtr<ScrollablePattern> FindScrollableParent(); 82 std::optional<Color> GetHandleColor() override; 83 84 protected: 85 virtual void UpdateSelectorOnHandleMove(const OffsetF& handleOffset, bool isFirstHandle); UpdateTransformFlag()86 void UpdateTransformFlag() override 87 { 88 hasTransform_ = CheckHasTransformAttr(); 89 } IsClipHandleWithViewPort()90 bool IsClipHandleWithViewPort() override 91 { 92 return !HasRenderTransform(); 93 } 94 void UpdateClipHandleViewPort(RectF& rect) override; 95 bool selectTextUseTopHandle = false; 96 97 private: 98 OffsetF GetHotPaintOffset(); 99 OffsetF handleGlobalOffset_; 100 bool isDraggingFirstHandle_ = true; 101 OffsetF hostPaintOffset_; 102 ACE_DISALLOW_COPY_AND_MOVE(TextSelectOverlay); 103 }; 104 105 } // namespace OHOS::Ace::NG 106 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_TEXT_SELECT_OVERLAY_H 107