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