• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
SetFlexMeasureResult(FlexMeasureResult measureResult,uintptr_t addr)70     void SetFlexMeasureResult(FlexMeasureResult measureResult, uintptr_t addr)
71     {
72         measureResult_ = measureResult;
73         measuredAddress_ = addr;
74     }
75 
GetFlexMeasureResult()76     FlexMeasureResult GetFlexMeasureResult()
77     {
78         return measureResult_;
79     }
80 
SetFlexLayoutResult(FlexLayoutResult layoutResult,uintptr_t addr)81     void SetFlexLayoutResult(FlexLayoutResult layoutResult, uintptr_t addr)
82     {
83         layoutResult_ = layoutResult;
84         layoutedAddress_ = addr;
85     }
86 
GetMeasureLayoutPaired()87     bool GetMeasureLayoutPaired()
88     {
89         return (measuredAddress_ && layoutedAddress_ && (measuredAddress_.value() == layoutedAddress_.value()));
90     }
91 
DumpInfo()92     void DumpInfo() override
93     {
94         DumpLog::GetInstance().AddDesc(std::string("FlexMeasureLayoutPaired: ")
95                                            .append(std::to_string(static_cast<int>(GetMeasureLayoutPaired())).c_str()));
96         DumpLog::GetInstance().AddDesc(std::string("FlexFrontSpace: ")
97                                            .append(std::to_string(layoutResult_.frontSpace).c_str())
98                                            .append(std::string(" FlexBetweenSpace: "))
99                                            .append(std::to_string(layoutResult_.betweenSpace).c_str()));
100         auto host = GetHost();
101         CHECK_NULL_VOID(host);
102         auto layoutProperty = DynamicCast<LinearLayoutProperty>(host->GetLayoutProperty());
103         CHECK_NULL_VOID(layoutProperty);
104         auto space = layoutProperty->GetSpace();
105         if (space.has_value()) {
106             DumpLog::GetInstance().AddDesc(std::string("space: ").append(space.value().ToString().c_str()));
107         }
108     }
109 
DumpSimplifyInfo(std::shared_ptr<JsonValue> & json)110     void DumpSimplifyInfo(std::shared_ptr<JsonValue>& json) override
111     {
112         json->Put("FlexMeasureLayoutPaired", GetMeasureLayoutPaired());
113         json->Put("FlexFrontSpace", static_cast<double>(layoutResult_.frontSpace));
114         json->Put("FlexBetweenSpace", static_cast<double>(layoutResult_.betweenSpace));
115     }
116 
117 private:
118     bool isVertical_ = false;
119     FlexMeasureResult measureResult_;
120     FlexLayoutResult layoutResult_;
121     std::optional<uintptr_t> measuredAddress_;
122     std::optional<uintptr_t> layoutedAddress_;
123 
124     ACE_DISALLOW_COPY_AND_MOVE(LinearLayoutPattern);
125 };
126 } // namespace OHOS::Ace::NG
127 
128 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LINEAR_LAYOUT_PATTERN_H
129