1 /* 2 * Copyright (c) 2022 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_PATTERNS_SELECT_OVERLAY_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SELECT_OVERLAY_PROPERTY_H 18 19 #include <cstdint> 20 #include <functional> 21 #include <vector> 22 23 #include "base/geometry/ng/offset_t.h" 24 #include "base/geometry/ng/rect_t.h" 25 #include "core/components_ng/event/gesture_event_hub.h" 26 #include "core/components_ng/pattern/text/text_menu_extension.h" 27 28 namespace OHOS::Ace::NG { 29 30 constexpr int32_t MENU_SHOW_ANIMATION_DURATION = 250; 31 constexpr int32_t MENU_HIDE_ANIMATION_DURATION = 200; 32 constexpr int32_t HANDLE_ANIMATION_DURATION = 150; 33 34 struct SelectHandleInfo { 35 bool isShow = true; 36 bool needLayout = false; 37 // in Global coordinates. 38 RectF paintRect; 39 40 bool operator==(const SelectHandleInfo& info) const 41 { 42 return (isShow == info.isShow) && (paintRect == info.paintRect); 43 } 44 45 bool operator!=(const SelectHandleInfo& info) const 46 { 47 return !(*this == info); 48 } 49 50 static Dimension GetDefaultLineWidth(); 51 }; 52 53 struct SelectMenuInfo { 54 bool menuDisable = false; 55 bool menuIsShow = false; 56 bool singleHandleMenuIsShow = false; 57 bool showCopy = true; 58 bool showPaste = true; 59 bool showCopyAll = true; 60 bool showCut = true; 61 bool showCameraInput = false; 62 std::optional<OffsetF> menuOffset; 63 64 // Customize menu information. 65 std::optional<int32_t> responseType; 66 std::optional<int32_t> editorType; 67 std::function<void()> menuBuilder; 68 IsIconChangedSelectMenuInfo69 bool IsIconChanged(const SelectMenuInfo& info) const 70 { 71 if (menuBuilder != nullptr || info.menuBuilder != nullptr) { 72 return true; 73 } 74 return !((showCopy == info.showCopy) && (showPaste == info.showPaste) && (showCopyAll == info.showCopyAll) && 75 (showCut == info.showCut) && (showCameraInput == info.showCameraInput)); 76 } 77 }; 78 79 struct SelectMenuCallback { 80 std::function<void()> onCopy; 81 std::function<void()> onPaste; 82 std::function<void()> onSelectAll; 83 std::function<void()> onCut; 84 std::function<void()> onCameraInput; 85 86 std::function<void()> onAppear; 87 std::function<void()> onDisappear; 88 }; 89 90 struct SelectedByMouseInfo { 91 WeakPtr<FrameNode> selectedNode; 92 std::function<void()> onResetSelection; 93 94 bool operator!=(const SelectedByMouseInfo& info) const 95 { 96 CHECK_NULL_RETURN(selectedNode.Upgrade(), true); 97 CHECK_NULL_RETURN(info.selectedNode.Upgrade(), true); 98 return selectedNode.Upgrade() != info.selectedNode.Upgrade(); 99 } 100 clearSelectedByMouseInfo101 void clear() 102 { 103 selectedNode.Reset(); 104 onResetSelection = nullptr; 105 } 106 }; 107 108 struct SelectOverlayInfo { 109 bool isUsingMouse = false; 110 bool isSingleHandle = false; 111 // when handleReverse is true, The first one is on the right side of the second. 112 bool handleReverse = false; 113 // Used to determine the range of judgment that is parallel to the first and second handles. 114 float singleLineHeight = 10.0f; 115 bool isSelectRegionVisible = false; 116 bool isNewAvoid = false; 117 SelectHandleInfo firstHandle; 118 SelectHandleInfo secondHandle; 119 HitTestMode hitTestMode = HitTestMode::HTMTRANSPARENT_SELF; 120 121 // show area 122 bool useFullScreen = true; 123 RectF showArea; 124 RectF selectArea; 125 126 OffsetF rightClickOffset; 127 128 // handle touch event 129 std::function<void(const TouchEventInfo&)> onTouchDown; 130 std::function<void(const TouchEventInfo&)> onTouchUp; 131 std::function<void(const TouchEventInfo&)> onTouchMove; 132 133 // handle move callback. 134 std::function<void(bool isFirst)> onHandleMoveStart; 135 std::function<void(const RectF&, bool isFirst)> onHandleMove; 136 std::function<void(const RectF&, bool isFirst)> onHandleMoveDone; 137 std::function<void(bool)> onHandleReverse; 138 139 // menu info. 140 SelectMenuInfo menuInfo; 141 SelectMenuCallback menuCallback; 142 143 std::vector<MenuOptionsParam> menuOptionItems; 144 145 // force hide callback, which may be called when other textOverlay shows. 146 std::function<void(bool)> onClose; 147 148 std::function<bool(const PointF&)> checkIsTouchInHostArea; 149 150 OHOS::Ace::WeakPtr<FrameNode> callerFrameNode; 151 152 bool isHandleLineShow = true; 153 }; 154 155 } // namespace OHOS::Ace::NG 156 157 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SELECT_OVERLAY_PROPERTY_H 158