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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_OVERLAY_LAYOUT_ALGORITHM_H 16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_OVERLAY_LAYOUT_ALGORITHM_H 17 18 #include <optional> 19 #include <utility> 20 21 #include "base/geometry/ng/offset_t.h" 22 #include "base/utils/noncopyable.h" 23 #include "core/components_ng/layout/box_layout_algorithm.h" 24 #include "core/components_ng/pattern/select_overlay/select_overlay_property.h" 25 26 namespace OHOS::Ace::NG { 27 28 class ACE_EXPORT SelectOverlayLayoutAlgorithm : public BoxLayoutAlgorithm { 29 DECLARE_ACE_TYPE(SelectOverlayLayoutAlgorithm, BoxLayoutAlgorithm); 30 31 public: SelectOverlayLayoutAlgorithm(std::shared_ptr<SelectOverlayInfo> info,const OffsetF & defaultMenuEndOffset,const std::optional<float> & menuWidth,const std::optional<float> & menuHeight)32 explicit SelectOverlayLayoutAlgorithm(std::shared_ptr<SelectOverlayInfo> info, const OffsetF& defaultMenuEndOffset, 33 const std::optional<float>& menuWidth, const std::optional<float>& menuHeight) 34 : info_(std::move(info)), defaultMenuEndOffset_(defaultMenuEndOffset), menuWidth_(menuWidth), 35 menuHeight_(menuHeight) 36 {} 37 ~SelectOverlayLayoutAlgorithm() override = default; 38 39 void Layout(LayoutWrapper* layoutWrapper) override; 40 void Measure(LayoutWrapper* layoutWrapper) override; 41 42 static bool CheckInShowArea(const SelectOverlayInfo& info); 43 GetDefaultMenuEndOffset()44 const OffsetF& GetDefaultMenuEndOffset() const 45 { 46 return defaultMenuEndOffset_; 47 } 48 GetMenuWidth()49 const std::optional<float>& GetMenuWidth() const 50 { 51 return menuWidth_; 52 } 53 GetMenuHeight()54 const std::optional<float>& GetMenuHeight() const 55 { 56 return menuHeight_; 57 } 58 GetHasExtensionMenu()59 bool GetHasExtensionMenu() const 60 { 61 return hasExtensionMenu_; 62 } 63 64 private: 65 OffsetF ComputeSelectMenuPosition(LayoutWrapper* layoutWrapper); 66 OffsetF ComputeExtensionMenuPosition(LayoutWrapper* layoutWrapper, const OffsetF& offset); 67 OffsetF AdjustSelectMenuOffset( 68 LayoutWrapper* layoutWrapper, const RectF& menuRect, double spaceBetweenText, double spaceBetweenHandle); 69 OffsetF CalculateCustomMenuByMouseOffset(LayoutWrapper* layoutWrapper); 70 void CalculateCustomMenuLayoutConstraint(LayoutWrapper* layoutWrapper, LayoutConstraintF& layoutConstraint); 71 bool IsTextAreaSelectAll(); 72 OffsetF NewMenuAvoidStrategy(float menuWidth, float menuHeight); 73 74 std::shared_ptr<SelectOverlayInfo> info_; 75 76 OffsetF defaultMenuEndOffset_; 77 std::optional<float> menuWidth_; 78 std::optional<float> menuHeight_; 79 bool hasExtensionMenu_ = false; 80 81 ACE_DISALLOW_COPY_AND_MOVE(SelectOverlayLayoutAlgorithm); 82 }; 83 } // namespace OHOS::Ace::NG 84 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_OVERLAY_LAYOUT_ALGORITHM_H