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 41 static bool CheckInShowArea(const SelectOverlayInfo& info); 42 GetDefaultMenuEndOffset()43 const OffsetF& GetDefaultMenuEndOffset() const 44 { 45 return defaultMenuEndOffset_; 46 } 47 GetMenuWidth()48 const std::optional<float>& GetMenuWidth() const 49 { 50 return menuWidth_; 51 } 52 GetMenuHeight()53 const std::optional<float>& GetMenuHeight() const 54 { 55 return menuHeight_; 56 } 57 GetHasExtensionMenu()58 bool GetHasExtensionMenu() const 59 { 60 return hasExtensionMenu_; 61 } 62 63 private: 64 OffsetF ComputeSelectMenuPosition(LayoutWrapper* layoutWrapper); 65 OffsetF ComputeExtensionMenuPosition(LayoutWrapper* layoutWrapper, const OffsetF& offset); 66 bool IsTextAreaSelectAll(); 67 68 std::shared_ptr<SelectOverlayInfo> info_; 69 70 OffsetF defaultMenuEndOffset_; 71 std::optional<float> menuWidth_; 72 std::optional<float> menuHeight_; 73 bool hasExtensionMenu_ = false; 74 75 ACE_DISALLOW_COPY_AND_MOVE(SelectOverlayLayoutAlgorithm); 76 }; 77 } // namespace OHOS::Ace::NG 78 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_OVERLAY_LAYOUT_ALGORITHM_H