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 #include "core/components_ng/base/geometry_node.h"
17
18 namespace OHOS::Ace::NG {
19
Reset()20 void GeometryNode::Reset()
21 {
22 frame_.Reset();
23 margin_.reset();
24 padding_.reset();
25 content_.reset();
26 parentGlobalOffset_.Reset();
27 parentAbsoluteOffset_.Reset();
28 parentLayoutConstraint_.reset();
29 resolvedSingleSafeAreaPadding_.reset();
30 accumulatedSafeAreaExpand_.reset();
31 }
32
Clone() const33 RefPtr<GeometryNode> GeometryNode::Clone() const
34 {
35 auto node = MakeRefPtr<GeometryNode>();
36 node->frame_ = frame_;
37 if (margin_) {
38 node->margin_ = std::make_unique<MarginPropertyF>(*margin_);
39 }
40 if (padding_) {
41 node->padding_ = std::make_unique<MarginPropertyF>(*padding_);
42 }
43 if (content_) {
44 node->content_ = std::make_unique<GeometryProperty>(*content_);
45 }
46 if (accumulatedSafeAreaExpand_) {
47 node->accumulatedSafeAreaExpand_ = std::make_unique<PaddingPropertyF>(*accumulatedSafeAreaExpand_);
48 }
49 if (resolvedSingleSafeAreaPadding_) {
50 node->resolvedSingleSafeAreaPadding_ = std::make_unique<PaddingPropertyF>(*resolvedSingleSafeAreaPadding_);
51 }
52 node->parentGlobalOffset_ = parentGlobalOffset_;
53 node->parentLayoutConstraint_ = parentLayoutConstraint_;
54 node->parentAbsoluteOffset_ = parentAbsoluteOffset_;
55 node->selfAdjust_ = selfAdjust_;
56 return node;
57 }
58
ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter) const59 void GeometryNode::ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const
60 {
61 #if defined(PREVIEW)
62 auto frameSize = frame_.rect_.GetSize();
63 json->Put("width", std::to_string(frameSize.Width()).c_str());
64 json->Put("height", std::to_string(frameSize.Height()).c_str());
65
66 auto jsonSize = JsonUtil::Create(true);
67 jsonSize->Put("width", std::to_string(frameSize.Width()).c_str());
68 jsonSize->Put("height", std::to_string(frameSize.Height()).c_str());
69 json->Put("size", jsonSize);
70 #endif
71 }
72
SetAccumulatedSafeAreaEdges(const ExpandEdges & safeAreaPadding)73 void GeometryNode::SetAccumulatedSafeAreaEdges(const ExpandEdges& safeAreaPadding)
74 {
75 if (!accumulatedSafeAreaExpand_) {
76 accumulatedSafeAreaExpand_ = std::make_unique<ExpandEdges>(safeAreaPadding);
77 return;
78 }
79 if (safeAreaPadding.left) {
80 accumulatedSafeAreaExpand_->left = safeAreaPadding.left;
81 }
82 if (safeAreaPadding.right) {
83 accumulatedSafeAreaExpand_->right = safeAreaPadding.right;
84 }
85 if (safeAreaPadding.top) {
86 accumulatedSafeAreaExpand_->top = safeAreaPadding.top;
87 }
88 if (safeAreaPadding.bottom) {
89 accumulatedSafeAreaExpand_->bottom = safeAreaPadding.bottom;
90 }
91 }
92
GetAccumulatedSafeAreaExpand() const93 const std::unique_ptr<ExpandEdges>& GeometryNode::GetAccumulatedSafeAreaExpand() const
94 {
95 return accumulatedSafeAreaExpand_;
96 }
97
ResetAccumulatedSafeAreaPadding()98 void GeometryNode::ResetAccumulatedSafeAreaPadding()
99 {
100 CHECK_NULL_VOID(accumulatedSafeAreaExpand_);
101 accumulatedSafeAreaExpand_.reset();
102 }
103
SetResolvedSingleSafeAreaPadding(const PaddingPropertyF & safeAreaPadding)104 void GeometryNode::SetResolvedSingleSafeAreaPadding(const PaddingPropertyF& safeAreaPadding)
105 {
106 resolvedSingleSafeAreaPadding_ = std::make_unique<PaddingPropertyF>(safeAreaPadding);
107 }
108
GetResolvedSingleSafeAreaPadding() const109 const std::unique_ptr<PaddingPropertyF>& GeometryNode::GetResolvedSingleSafeAreaPadding() const
110 {
111 return resolvedSingleSafeAreaPadding_;
112 }
113
ResetResolvedSelfSafeAreaPadding()114 void GeometryNode::ResetResolvedSelfSafeAreaPadding()
115 {
116 resolvedSingleSafeAreaPadding_.reset();
117 }
118
GetParentAdjust() const119 RectF GeometryNode::GetParentAdjust() const
120 {
121 return parentAdjust_;
122 }
123
SetParentAdjust(RectF parentAdjust)124 void GeometryNode::SetParentAdjust(RectF parentAdjust)
125 {
126 parentAdjust_ = parentAdjust;
127 }
128
GetSelfAdjust() const129 RectF GeometryNode::GetSelfAdjust() const
130 {
131 return selfAdjust_;
132 }
133
SetSelfAdjust(RectF selfAdjust)134 void GeometryNode::SetSelfAdjust(RectF selfAdjust)
135 {
136 selfAdjust_ = selfAdjust;
137 }
138 } // namespace OHOS::Ace::NG
139