1 /* 2 * Copyright (c) 2023-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_PATTERNS_CONTAINER_MODAL_CONTAINER_MODAL_PATTERN_ENHANCE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CONTAINER_MODAL_CONTAINER_MODAL_PATTERN_ENHANCE_H 18 19 #include <functional> 20 #include <unordered_map> 21 22 #include "core/components_ng/pattern/container_modal/container_modal_pattern.h" 23 #include "core/components_ng/base/inspector.h" 24 25 namespace OHOS::Ace::NG { 26 using ButtonsRectChangeListener = std::function<void(const RectF& containerModal, const RectF& buttonsRect)>; 27 28 class ACE_EXPORT ContainerModalPatternEnhance : public ContainerModalPattern { 29 DECLARE_ACE_TYPE(ContainerModalPatternEnhance, ContainerModalPattern); 30 31 public: 32 ContainerModalPatternEnhance() = default; 33 ~ContainerModalPatternEnhance() override = default; 34 void OnWindowForceUnfocused() override; 35 void UpdateTitleInTargetPos(bool isShow, int32_t height); 36 void ShowTitle(bool isShow, bool hasDeco = true, bool needUpdate = false) override; 37 void SetContainerButtonHide(bool hideSplit, bool hideMaximize, bool hideMinimize, bool hideClose) override; 38 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>&, const DirtySwapConfig&) override; 39 void EnableContainerModalGesture(bool isEnable) override; 40 void CallContainerModalNative(const std::string& name, const std::string& value) override; 41 void OnContainerModalEvent(const std::string& name, const std::string& value) override; 42 void ClearTapGestureEvent(RefPtr<FrameNode>& containerTitleRow); 43 RefPtr<FrameNode> GetOrCreateMenuList(const RefPtr<FrameNode>& targetNode); 44 /* event */ 45 void SetTapGestureEvent(RefPtr<FrameNode>& gestureRow); 46 RefPtr<FrameNode> ShowMaxMenu(const RefPtr<FrameNode>& targetNode); 47 void OnMaxButtonClick(GestureEvent& info); 48 void OnMinButtonClick(GestureEvent& info); 49 void OnCloseButtonClick(GestureEvent& info); 50 void OnMaxBtnInputEvent(MouseInfo& info); 51 void OnMaxBtnHoverEvent(bool hover, WeakPtr<FrameNode>& maximizeBtn); 52 void OnMenuItemClickGesture(bool isSplistLeft); 53 static void OnMenuItemHoverEvent(RefPtr<FrameNode> item, bool isHover); 54 static void OnMenuItemClickEvent(RefPtr<FrameNode> item, MouseInfo& info); 55 void EnablePanEventOnNode( 56 RefPtr<FrameNode>& node, bool isEnable, const std::string& rowName); 57 void EnableTapGestureOnNode( 58 RefPtr<FrameNode>& node, bool isEnable, const std::string& rowName); 59 bool GetFloatingTitleVisible() override; 60 bool GetCustomTitleVisible() override; 61 bool GetControlButtonVisible() override; 62 void OnColorConfigurationUpdate() override; 63 64 void Init() override; 65 void SetCloseButtonStatus(bool isEnabled) override; 66 void InitButtonsLayoutProperty() override; 67 CalcLength GetControlButtonRowWidth() override; 68 bool GetContainerModalButtonsRect(RectF& containerModal, RectF& buttons) override; 69 bool GetContainerModalComponentRect(RectF& containerModal, RectF& buttons); 70 void OnMaxButtonClick(); 71 void OnMinButtonClick(); 72 void OnCloseButtonClick(); 73 void CallMenuWidthChange(int32_t resId); 74 int32_t AddButtonsRectChangeListener(ButtonsRectChangeListener&& listener); 75 void RemoveButtonsRectChangeListener(int32_t id); 76 77 private: GetButtonRowByInspectorId()78 RefPtr<FrameNode> GetButtonRowByInspectorId() 79 { 80 return NG::Inspector::GetFrameNodeByKey("containerModalButtonRowId"); 81 } 82 GetMaximizeButton()83 RefPtr<FrameNode> GetMaximizeButton() 84 { 85 return NG::Inspector::GetFrameNodeByKey("EnhanceMaximizeBtn"); 86 } 87 GetMinimizeButton()88 RefPtr<FrameNode> GetMinimizeButton() 89 { 90 return NG::Inspector::GetFrameNodeByKey("EnhanceMinimizeBtn"); 91 } 92 GetCloseButton()93 RefPtr<FrameNode> GetCloseButton() 94 { 95 return NG::Inspector::GetFrameNodeByKey("EnhanceCloseBtn"); 96 } 97 RefPtr<UINode> GetTitleItemByIndex(const RefPtr<FrameNode>& controlButtonsNode, int32_t originIndex) override; 98 void ChangeFloatingTitle(bool isFocus) override; 99 void ChangeCustomTitle(bool isFocus) override; 100 void ChangeControlButtons(bool isFocus) override; 101 102 RefPtr<FrameNode> ShowMaxMenu(RefPtr<FrameNode>& container, const RefPtr<FrameNode>& targetNode); 103 void ResetHoverTimer(); 104 Dimension GetMenuWidth(); 105 void CalculateMenuOffset(const RefPtr<FrameNode>& targetNode); 106 void BuildMenuList(); 107 108 void SetColorConfigurationUpdate(); 109 void SetMaximizeIconIsRecover(); 110 void NotifyButtonsRectChange(const RectF& containerModal, const RectF& buttonsRect) override; 111 112 VisibleType controlButtonVisibleBeforeAnim_; 113 RefPtr<FrameNode> menuList_; 114 OffsetF menuOffset_; 115 float textWidth_ = 0.0f; 116 bool isMenuPending_ = false; 117 bool isForbidMenuEvent_ = false; 118 bool enableSplit_ = true; 119 CancelableCallback<void()> contextTimer_; 120 bool enableContainerModalGesture_ = true; 121 std::unordered_map<int32_t, ButtonsRectChangeListener> rectChangeListeners_; 122 }; 123 } // namespace OHOS::Ace::NG 124 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CONTAINER_MODAL_CONTAINER_MODAL_PATTERN_ENHANCE_H 125