1 /* 2 * Copyright (c) 2022-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_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CONTAINER_MODAL_CONTAINER_MODAL_PATTERN_H 18 19 #include "base/geometry/dimension.h" 20 #include "base/memory/referenced.h" 21 #include "core/components/container_modal/container_modal_constants.h" 22 #include "core/components_ng/base/frame_node.h" 23 #include "core/components_ng/pattern/container_modal/container_modal_accessibility_property.h" 24 #include "core/components_ng/pattern/container_modal/container_modal_toolbar.h" 25 #include "core/components_ng/pattern/custom/custom_title_node.h" 26 #include "core/components_ng/pattern/pattern.h" 27 #include "core/pipeline_ng/pipeline_context.h" 28 29 namespace OHOS::Ace::NG { 30 class ACE_EXPORT ContainerModalPattern : public Pattern { 31 DECLARE_ACE_TYPE(ContainerModalPattern, Pattern); 32 33 public: 34 ContainerModalPattern() = default; 35 ~ContainerModalPattern() override = default; 36 37 void OnColorConfigurationUpdate() override; 38 CreateAccessibilityProperty()39 RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override 40 { 41 return MakeRefPtr<ContainerModalAccessibilityProperty>(); 42 } 43 IsMeasureBoundary()44 bool IsMeasureBoundary() const override 45 { 46 return true; 47 } 48 IsAtomicNode()49 bool IsAtomicNode() const override 50 { 51 return false; 52 } 53 54 void CallSetContainerWindow(bool considerFloatingWindow); 55 OnAttachToFrameNode()56 void OnAttachToFrameNode() override 57 { 58 auto pipeline = PipelineContext::GetCurrentContext(); 59 CHECK_NULL_VOID(pipeline); 60 auto host = GetHost(); 61 CHECK_NULL_VOID(host); 62 pipeline->AddWindowActivateChangedCallback(host->GetId()); 63 } 64 65 void OnWindowActivated() override; 66 67 void OnWindowDeactivated() override; 68 69 virtual void OnWindowForceUnfocused(); 70 71 virtual void Init(); 72 73 virtual void ShowTitle(bool isShow, bool hasDeco = true, bool needUpdate = false); 74 75 void SetAppTitle(const std::string& title); 76 77 void SetAppIcon(const RefPtr<PixelMap>& icon); 78 79 virtual void SetContainerButtonHide(bool hideSplit, bool hideMaximize, bool hideMinimize, bool hideClose); 80 81 virtual void SetCloseButtonStatus(bool isEnabled); 82 83 virtual void SetWindowContainerColor(const Color& activeColor, const Color& inactiveColor); 84 GetIsFocus()85 bool GetIsFocus() const 86 { 87 return isFocus_; 88 } 89 GetAppLabel()90 std::string GetAppLabel() 91 { 92 return appLabel_; 93 } 94 GetColumnNode()95 RefPtr<FrameNode> GetColumnNode() 96 { 97 auto host = GetHost(); 98 CHECK_NULL_RETURN(host, nullptr); 99 return AceType::DynamicCast<FrameNode>(host->GetChildren().front()); 100 } 101 GetFloatingTitleRow()102 RefPtr<FrameNode> GetFloatingTitleRow() 103 { 104 auto host = GetHost(); 105 CHECK_NULL_RETURN(host, nullptr); 106 return AceType::DynamicCast<FrameNode>(host->GetChildAtIndex(1)); 107 } 108 GetControlButtonRow()109 RefPtr<FrameNode> GetControlButtonRow() 110 { 111 auto host = GetHost(); 112 CHECK_NULL_RETURN(host, nullptr); 113 return AceType::DynamicCast<FrameNode>(host->GetChildren().back()); 114 } 115 GetCustomTitleRow()116 RefPtr<FrameNode> GetCustomTitleRow() 117 { 118 auto columnNode = GetColumnNode(); 119 CHECK_NULL_RETURN(columnNode, nullptr); 120 return AceType::DynamicCast<FrameNode>(columnNode->GetChildren().front()); 121 } 122 GetCustomTitleNode()123 RefPtr<CustomTitleNode> GetCustomTitleNode() 124 { 125 auto row = GetCustomTitleRow(); 126 CHECK_NULL_RETURN(row, nullptr); 127 auto title = row->GetChildren().front(); 128 CHECK_NULL_RETURN(title, nullptr); 129 return AceType::DynamicCast<CustomTitleNode>(title->GetChildren().front()); 130 } 131 GetStackNode()132 RefPtr<FrameNode> GetStackNode() 133 { 134 auto columnNode = GetColumnNode(); 135 CHECK_NULL_RETURN(columnNode, nullptr); 136 return AceType::DynamicCast<FrameNode>(columnNode->GetChildAtIndex(1)); 137 } 138 GetContentNode()139 RefPtr<FrameNode> GetContentNode() 140 { 141 auto stack = GetStackNode(); 142 CHECK_NULL_RETURN(stack, nullptr); 143 return AceType::DynamicCast<FrameNode>(stack->GetChildren().front()); 144 } 145 GetPageNode()146 RefPtr<FrameNode> GetPageNode() 147 { 148 auto stageNode = GetContentNode(); 149 CHECK_NULL_RETURN(stageNode, nullptr); 150 return AceType::DynamicCast<FrameNode>(stageNode->GetChildren().front()); 151 } 152 GetFloatingTitleNode()153 RefPtr<CustomTitleNode> GetFloatingTitleNode() 154 { 155 auto row = GetFloatingTitleRow(); 156 CHECK_NULL_RETURN(row, nullptr); 157 auto title = row->GetChildren().front(); 158 CHECK_NULL_RETURN(title, nullptr); 159 return AceType::DynamicCast<CustomTitleNode>(title->GetChildren().front()); 160 } 161 GetGestureRow()162 RefPtr<FrameNode> GetGestureRow() 163 { 164 auto column = GetColumnNode(); 165 CHECK_NULL_RETURN(column, nullptr); 166 return AceType::DynamicCast<FrameNode>(column->GetChildAtIndex(2)); 167 } 168 GetCustomButtonNode()169 RefPtr<CustomTitleNode> GetCustomButtonNode() 170 { 171 auto row = GetControlButtonRow(); 172 CHECK_NULL_RETURN(row, nullptr); 173 return AceType::DynamicCast<CustomTitleNode>(row->GetChildren().front()); 174 } 175 void UpdateRowHeight(const RefPtr<FrameNode>& row, Dimension height); 176 void UpdateGestureRowVisible(); 177 void SetContainerModalTitleVisible(bool customTitleSettedShow, bool floatingTitleSettedShow); 178 bool GetContainerModalTitleVisible(bool isImmersive); 179 virtual void SetContainerModalTitleHeight(int32_t height); 180 void SetContainerModalTitleWithoutButtonsHeight(Dimension height); 181 void SetControlButtonsRowHeight(Dimension height); 182 int32_t GetContainerModalTitleHeight(); 183 virtual bool GetContainerModalButtonsRect(RectF& containerModal, RectF& buttons); 184 void SubscribeContainerModalButtonsRectChange( 185 std::function<void(RectF& containerModal, RectF& buttons)>&& callback); CallContainerModalNative(const std::string & name,const std::string & value)186 virtual void CallContainerModalNative(const std::string& name, const std::string& value) {}; OnContainerModalEvent(const std::string & name,const std::string & value)187 virtual void OnContainerModalEvent(const std::string& name, const std::string& value) {}; 188 void GetWindowPaintRectWithoutMeasureAndLayout(RectInt& rect); 189 void GetWindowPaintRectWithoutMeasureAndLayout(Rect& rect, bool isContainerModal); 190 void CallButtonsRectChange(); 191 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>&, const DirtySwapConfig&) override; 192 193 void OnLanguageConfigurationUpdate() override; 194 195 void InitColumnTouchTestFunc(); 196 GetIsHoveredMenu()197 bool GetIsHoveredMenu() 198 { 199 return isHoveredMenu_; 200 } 201 202 Dimension GetCustomTitleHeight(); 203 EnableContainerModalGesture(bool isEnable)204 virtual void EnableContainerModalGesture(bool isEnable) {} 205 GetFloatingTitleVisible()206 virtual bool GetFloatingTitleVisible() 207 { 208 return false; 209 } 210 GetCustomTitleVisible()211 virtual bool GetCustomTitleVisible() 212 { 213 return false; 214 } 215 GetControlButtonVisible()216 virtual bool GetControlButtonVisible() 217 { 218 return false; 219 } 220 221 void InitAllTitleRowLayoutProperty(); 222 SetEnableContainerModalCustomGesture(bool enable)223 void SetEnableContainerModalCustomGesture(bool enable) 224 { 225 this->enableContainerModalCustomGesture_ = enable; 226 } 227 228 static void EnableContainerModalCustomGesture(RefPtr<PipelineContext> pipeline, bool enable); 229 void SetToolbarBuilder(const RefPtr<FrameNode>& parent, std::function<RefPtr<UINode>()>&& builder); 230 virtual CalcLength GetControlButtonRowWidth(); 231 SetIsHaveToolBar(bool isHave)232 void SetIsHaveToolBar(bool isHave) 233 { 234 isHaveToolBar_ = isHave; 235 } 236 GetIsHaveToolBar()237 bool GetIsHaveToolBar() const 238 { 239 return isHaveToolBar_; 240 } 241 242 bool IsContainerModalTransparent() const; 243 244 Dimension titleHeight_ = CONTAINER_TITLE_HEIGHT; 245 GetTitleManager()246 RefPtr<ContainerModalToolBar> GetTitleManager() 247 { 248 return titleMgr_; 249 } 250 IsExpandStackNode()251 bool IsExpandStackNode() const 252 { 253 return isTitleShow_ && customTitleSettedShow_ && IsContainerModalTransparent(); 254 } 255 256 protected: GetTitleItemByIndex(const RefPtr<FrameNode> & controlButtonsNode,int32_t originIndex)257 virtual RefPtr<UINode> GetTitleItemByIndex(const RefPtr<FrameNode>& controlButtonsNode, int32_t originIndex) 258 { 259 return controlButtonsNode->GetChildAtIndex(originIndex); 260 } 261 262 virtual void AddPanEvent(const RefPtr<FrameNode>& controlButtonsNode); 263 264 virtual void RemovePanEvent(const RefPtr<FrameNode>& controlButtonsNode); 265 266 virtual void ChangeFloatingTitle(bool isFocus); 267 268 virtual void ChangeCustomTitle(bool isFocus); 269 270 virtual void ChangeControlButtons(bool isFocus); 271 272 virtual void ChangeTitleButtonIcon( 273 const RefPtr<FrameNode>& buttonNode, InternalResource::ResourceId icon, bool isFocus, bool isCloseBtn); 274 CanHideFloatingTitle()275 virtual bool CanHideFloatingTitle() 276 { 277 return true; 278 } 279 280 bool CanShowFloatingTitle(); 281 bool CanShowCustomTitle(); 282 void TrimFloatingWindowLayout(); 283 Color GetContainerColor(bool isFocus); 284 285 WindowMode windowMode_; 286 bool customTitleSettedShow_ = true; 287 bool floatingTitleSettedShow_ = true; 288 std::function<void(RectF&, RectF&)> controlButtonsRectChangeCallback_; 289 RectF buttonsRect_; 290 bool isInitButtonsRect_ = false; 291 Color activeColor_; 292 Color inactiveColor_; 293 void InitTitleRowLayoutProperty(RefPtr<FrameNode> titleRow, bool isFloating); 294 295 RefPtr<FrameNode> sideBarDivider_ = nullptr; 296 RefPtr<FrameNode> navbarRow_ = nullptr; 297 RefPtr<FrameNode> leftNavRow_ = nullptr; 298 RefPtr<FrameNode> rightNavRow_ = nullptr; 299 RefPtr<FrameNode> navBarDivider_ = nullptr; 300 RefPtr<FrameNode> navDestbarRow_ = nullptr; 301 RefPtr<FrameNode> leftNavDestRow_ = nullptr; 302 RefPtr<FrameNode> rightNavDestRow_ = nullptr; 303 304 protected: 305 void WindowFocus(bool isFocus); 306 void SetTitleButtonHide( 307 const RefPtr<FrameNode>& controlButtonsNode, bool hideSplit, bool hideMaximize, bool hideMinimize, 308 bool hideClose); 309 void InitTitle(); 310 void InitContainerEvent(); 311 void InitLayoutProperty(); 312 void InitContainerColor(); 313 314 virtual void InitButtonsLayoutProperty(); NotifyButtonsRectChange(const RectF & containerModal,const RectF & buttonsRect)315 virtual void NotifyButtonsRectChange(const RectF& containerModal, const RectF& buttonsRect) {} 316 317 void UpdateContainerBgColor(); 318 std::string appLabel_; 319 RefPtr<PanEvent> panEvent_ = nullptr; 320 321 float moveX_ = 0.0f; 322 float moveY_ = 0.0f; 323 bool hasDeco_ = true; 324 bool isFocus_ = false; 325 bool hideSplitButton_ = false; 326 bool isHoveredMenu_ = false; 327 bool isTitleShow_ = false; 328 bool enableContainerModalCustomGesture_ = false; 329 RRect windowPaintRect_; 330 bool isCustomColor_; 331 RefPtr<ContainerModalToolBar> titleMgr_; 332 RefPtr<ContainerModalToolBar> floatTitleMgr_; 333 bool isHaveToolBar_ = false; 334 }; 335 } // namespace OHOS::Ace::NG 336 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CONTAINER_MODAL_CONTAINER_MODAL_PATTERN_H 337