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 void HandleGestureRowHitTestMode(RefPtr<FrameNode>& gestureRow); 60 bool GetFloatingTitleVisible() override; 61 bool GetCustomTitleVisible() override; 62 bool GetControlButtonVisible() override; 63 void OnColorConfigurationUpdate() override; 64 65 void Init() override; 66 void SetCloseButtonStatus(bool isEnabled) override; 67 void InitButtonsLayoutProperty() override; 68 CalcLength GetControlButtonRowWidth() override; 69 bool GetContainerModalButtonsRect(RectF& containerModal, RectF& buttons) override; 70 bool GetContainerModalComponentRect(RectF& containerModal, RectF& buttons); 71 72 void OnMaxButtonClick(); 73 void OnMinButtonClick(); 74 void OnCloseButtonClick(); 75 void AddPointLight(); 76 void CallMenuWidthChange(int32_t resId); 77 int32_t AddButtonsRectChangeListener(ButtonsRectChangeListener&& listener); 78 void RemoveButtonsRectChangeListener(int32_t id); 79 80 private: GetButtonRowByInspectorId()81 RefPtr<FrameNode> GetButtonRowByInspectorId() 82 { 83 return NG::Inspector::GetFrameNodeByKey("containerModalButtonRowId"); 84 } 85 GetMaximizeButton()86 RefPtr<FrameNode> GetMaximizeButton() 87 { 88 return NG::Inspector::GetFrameNodeByKey("EnhanceMaximizeBtn"); 89 } 90 GetMinimizeButton()91 RefPtr<FrameNode> GetMinimizeButton() 92 { 93 return NG::Inspector::GetFrameNodeByKey("EnhanceMinimizeBtn"); 94 } 95 GetCloseButton()96 RefPtr<FrameNode> GetCloseButton() 97 { 98 return NG::Inspector::GetFrameNodeByKey("EnhanceCloseBtn"); 99 } 100 RefPtr<UINode> GetTitleItemByIndex(const RefPtr<FrameNode>& controlButtonsNode, int32_t originIndex) override; 101 void ChangeFloatingTitle(bool isFocus) override; 102 void ChangeCustomTitle(bool isFocus) override; 103 void ChangeControlButtons(bool isFocus) override; 104 RefPtr<FrameNode> ShowMaxMenu(RefPtr<FrameNode>& container, const RefPtr<FrameNode>& targetNode); 105 void ResetHoverTimer(); 106 Dimension GetMenuWidth(); 107 void CalculateMenuOffset(const RefPtr<FrameNode>& targetNode); 108 void BuildMenuList(); 109 110 void SetColorConfigurationUpdate(); 111 void SetMaximizeIconIsRecover(); 112 void NotifyButtonsRectChange(const RectF& containerModal, const RectF& buttonsRect) override; 113 114 VisibleType controlButtonVisibleBeforeAnim_; 115 RefPtr<FrameNode> menuList_; 116 OffsetF menuOffset_; 117 bool enableContainerModalGesture_ = true; 118 float textWidth_ = 0.0f; 119 bool isMenuPending_ = false; 120 bool isForbidMenuEvent_ = false; 121 bool enableSplit_ = true; 122 CancelableCallback<void()> contextTimer_; 123 std::unordered_map<int32_t, ButtonsRectChangeListener> rectChangeListeners_; 124 }; 125 } // namespace OHOS::Ace::NG 126 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CONTAINER_MODAL_CONTAINER_MODAL_PATTERN_ENHANCE_H 127