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_PATTERN_LINEAR_LAYOUT_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LINEAR_LAYOUT_PATTERN_H 18 19 #include "base/log/dump_log.h" 20 #include "base/utils/noncopyable.h" 21 #include "core/components/common/layout/constants.h" 22 #include "core/components_ng/pattern/linear_layout/linear_layout_algorithm.h" 23 #include "core/components_ng/pattern/linear_layout/linear_layout_property.h" 24 #include "core/components_ng/pattern/pattern.h" 25 26 namespace OHOS::Ace::NG { 27 // PagePattern is the base class for page render node. 28 class LinearLayoutPattern : virtual public Pattern { 29 DECLARE_ACE_TYPE(LinearLayoutPattern, Pattern); 30 31 public: LinearLayoutPattern(bool isVertical)32 explicit LinearLayoutPattern(bool isVertical) : isVertical_(isVertical) {}; 33 ~LinearLayoutPattern() override = default; 34 IsAtomicNode()35 bool IsAtomicNode() const override 36 { 37 return false; 38 } 39 IsNeedPercent()40 bool IsNeedPercent() const override 41 { 42 return true; 43 } 44 CreateLayoutProperty()45 RefPtr<LayoutProperty> CreateLayoutProperty() override 46 { 47 return MakeRefPtr<LinearLayoutProperty>(isVertical_); 48 } 49 CreateLayoutAlgorithm()50 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 51 { 52 return MakeRefPtr<LinearLayoutAlgorithm>(); 53 } 54 GetFocusPattern()55 FocusPattern GetFocusPattern() const override 56 { 57 return { FocusType::SCOPE, true }; 58 } 59 GetScopeFocusAlgorithm()60 ScopeFocusAlgorithm GetScopeFocusAlgorithm() override 61 { 62 return { isVertical_, true, ScopeType::FLEX }; 63 } 64 GetIsVertical()65 bool GetIsVertical() const 66 { 67 return isVertical_; 68 } 69 DumpInfo()70 void DumpInfo() override 71 { 72 auto host = GetHost(); 73 CHECK_NULL_VOID(host); 74 auto layoutProperty = DynamicCast<LinearLayoutProperty>(host->GetLayoutProperty()); 75 CHECK_NULL_VOID(layoutProperty); 76 auto widthLayoutPolicy = layoutProperty->GetWidthLayoutPolicy(); 77 auto heightLayoutPolicy = layoutProperty->GetHeightLayoutPolicy(); 78 std::string layoutPolicy = ""; 79 if (widthLayoutPolicy.has_value() && 80 widthLayoutPolicy.value() != static_cast<uint8_t>(LayoutCalPolicy::NO_MATCH)) { 81 layoutPolicy.append("WidthLayoutPolicy: ").append(std::to_string(widthLayoutPolicy.value())); 82 } 83 if (heightLayoutPolicy.has_value() && 84 heightLayoutPolicy.value() != static_cast<uint8_t>(LayoutCalPolicy::NO_MATCH)) { 85 layoutPolicy.append(layoutPolicy.length() == 0 ? "HeightLayoutPolicy: " : " HeightLayoutPolicy: ") 86 .append(std::to_string(heightLayoutPolicy.value())); 87 } 88 if (layoutPolicy.length() > 0) { 89 DumpLog::GetInstance().AddDesc(layoutPolicy); 90 } 91 } 92 IsNeedInitClickEventRecorder()93 bool IsNeedInitClickEventRecorder() const override 94 { 95 return true; 96 } 97 98 private: 99 bool isVertical_ = false; 100 101 ACE_DISALLOW_COPY_AND_MOVE(LinearLayoutPattern); 102 }; 103 } // namespace OHOS::Ace::NG 104 105 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LINEAR_LAYOUT_PATTERN_H 106