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 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_ROOT_ROOT_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_ROOT_ROOT_PATTERN_H 18 19 #include "base/utils/noncopyable.h" 20 #include "core/components_ng/pattern/pattern.h" 21 #include "core/components_ng/pattern/root/root_layout_algorithm.h" 22 23 namespace OHOS::Ace::NG { 24 // RootPattern is the base class for root render node. 25 class ACE_EXPORT RootPattern : public Pattern { 26 DECLARE_ACE_TYPE(RootPattern, Pattern); 27 28 public: 29 RootPattern() = default; 30 ~RootPattern() override = default; 31 IsRootPattern()32 bool IsRootPattern() const override 33 { 34 return true; 35 } 36 IsMeasureBoundary()37 bool IsMeasureBoundary() const override 38 { 39 return true; 40 } 41 IsAtomicNode()42 bool IsAtomicNode() const override 43 { 44 return false; 45 } 46 CreateLayoutAlgorithm()47 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 48 { 49 return MakeRefPtr<RootLayoutAlgorithm>(); 50 } 51 OnAttachToFrameNode()52 void OnAttachToFrameNode() override 53 { 54 auto host = GetHost(); 55 CHECK_NULL_VOID(host); 56 host->GetLayoutProperty()->UpdateAlignment(Alignment::TOP_LEFT); 57 } 58 SetAppBgColor(const Color & color,bool isContainerModal)59 void SetAppBgColor(const Color& color, bool isContainerModal) 60 { 61 auto rootNode = GetHost(); 62 CHECK_NULL_VOID(rootNode); 63 RefPtr<FrameNode> stage; 64 if (isContainerModal) { 65 auto container = DynamicCast<FrameNode>(rootNode->GetChildren().front()); 66 CHECK_NULL_VOID(container); 67 auto column = DynamicCast<FrameNode>(container->GetChildren().front()); 68 CHECK_NULL_VOID(column); 69 auto stack = DynamicCast<FrameNode>(column->GetChildren().back()); 70 CHECK_NULL_VOID(stack); 71 stage = DynamicCast<FrameNode>(stack->GetChildren().front()); 72 } else { 73 stage = DynamicCast<FrameNode>(rootNode->GetChildren().front()); 74 } 75 CHECK_NULL_VOID(stage); 76 LOGI("SetAppBgColor in page node successfully, bgColor is %{public}u", color.GetValue()); 77 stage->GetRenderContext()->UpdateBackgroundColor(color); 78 } 79 GetFocusPattern()80 FocusPattern GetFocusPattern() const override 81 { 82 return { FocusType::SCOPE, true }; 83 } 84 85 private: 86 ACE_DISALLOW_COPY_AND_MOVE(RootPattern); 87 }; 88 } // namespace OHOS::Ace::NG 89 90 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_ROOT_ROOT_PATTERN_H 91