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 showCopy = true; 57 bool showPaste = true; 58 bool showCopyAll = true; 59 bool showCut = true; 60 std::optional<OffsetF> menuOffset; 61 std::function<void()> menuBuilder; 62 IsIconChangedSelectMenuInfo63 bool IsIconChanged(const SelectMenuInfo& info) const 64 { 65 if (menuBuilder != nullptr || info.menuBuilder != nullptr) { 66 return true; 67 } 68 return !((showCopy == info.showCopy) && (showPaste == info.showPaste) && (showCopyAll == info.showCopyAll) && 69 (showCut == info.showCut)); 70 } 71 }; 72 73 struct SelectMenuCallback { 74 std::function<void()> onCopy; 75 std::function<void()> onPaste; 76 std::function<void()> onSelectAll; 77 std::function<void()> onCut; 78 79 std::function<void()> onAppear; 80 std::function<void()> onDisappear; 81 }; 82 83 struct SelectOverlayInfo { 84 bool isUsingMouse = false; 85 bool isSingleHandle = false; 86 // when handleReverse is true, The first one is on the right side of the second. 87 bool handleReverse = false; 88 // Used to determine the range of judgment that is parallel to the first and second handles. 89 float singleLineHeight = 10.0f; 90 SelectHandleInfo firstHandle; 91 SelectHandleInfo secondHandle; 92 HitTestMode hitTestMode = HitTestMode::HTMTRANSPARENT_SELF; 93 94 // show area 95 bool useFullScreen = true; 96 RectF showArea; 97 98 OffsetF rightClickOffset; 99 100 // handle touch event 101 std::function<void(const TouchEventInfo&)> onTouchDown; 102 std::function<void(const TouchEventInfo&)> onTouchUp; 103 std::function<void(const TouchEventInfo&)> onTouchMove; 104 105 // handle move callback. 106 std::function<void(bool isFirst)> onHandleMoveStart; 107 std::function<void(const RectF&, bool isFirst)> onHandleMove; 108 std::function<void(const RectF&, bool isFirst)> onHandleMoveDone; 109 std::function<void(bool)> onHandleReverse; 110 111 // menu info. 112 SelectMenuInfo menuInfo; 113 SelectMenuCallback menuCallback; 114 115 std::vector<MenuOptionsParam> menuOptionItems; 116 117 // force hide callback, which may be called when other textOverlay shows. 118 std::function<void(bool)> onClose; 119 120 OHOS::Ace::WeakPtr<FrameNode> callerFrameNode; 121 122 bool isHandleLineShow = true; 123 }; 124 125 } // namespace OHOS::Ace::NG 126 127 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SELECT_OVERLAY_PROPERTY_H 128