• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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/view_abstract.h"
17 #include <cstdint>
18 #include <functional>
19 #include <unordered_map>
20 #include "base/log/log_wrapper.h"
21 #include "core/components_ng/pattern/overlay/overlay_manager.h"
22 
23 #include "interfaces/inner_api/ui_session/ui_session_manager.h"
24 
25 #include "base/error/error_code.h"
26 #include "base/subwindow/subwindow_manager.h"
27 #include "base/utils/multi_thread.h"
28 #include "base/utils/system_properties.h"
29 #include "base/utils/utils.h"
30 #include "core/common/ace_engine.h"
31 #include "core/common/container.h"
32 #include "core/common/container_scope.h"
33 #include "core/common/resource/resource_manager.h"
34 #include "core/common/resource/resource_wrapper.h"
35 #include "core/common/resource/resource_parse_utils.h"
36 #include "core/components/common/layout/constants.h"
37 #include "core/components/common/properties/shadow.h"
38 #include "core/components/theme/shadow_theme.h"
39 #include "core/components_ng/base/frame_node.h"
40 #include "core/components_ng/base/view_stack_processor.h"
41 #include "core/components_ng/layout/layout_property.h"
42 #include "core/components_ng/base/view_abstract_model.h"
43 #include "core/components_ng/pattern/bubble/bubble_pattern.h"
44 #include "core/components_ng/pattern/bubble/bubble_view.h"
45 #include "core/components_ng/pattern/dialog/dialog_pattern.h"
46 #include "core/components_ng/pattern/menu/menu_view.h"
47 #include "core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h"
48 #include "core/components_ng/pattern/overlay/dialog_manager.h"
49 #include "core/components_ng/pattern/stack/stack_pattern.h"
50 #include "core/components_ng/pattern/scrollable/scrollable_event_hub.h"
51 #include "core/components_ng/pattern/list/list_event_hub.h"
52 #include "core/components_ng/pattern/scroll/scroll_event_hub.h"
53 #include "core/components_ng/pattern/grid/grid_event_hub.h"
54 #include "core/components_ng/pattern/waterflow/water_flow_event_hub.h"
55 #include "core/components_ng/manager/drag_drop/drag_drop_global_controller.h"
56 #include "core/components_ng/pattern/text_field/text_field_paint_property.h"
57 
58 namespace OHOS::Ace::NG {
59 
60 namespace {
61 constexpr double FULL_DIMENSION = 100.0;
62 
PropertyVectorToString(const std::vector<AnimationPropertyType> & vec)63 std::string PropertyVectorToString(const std::vector<AnimationPropertyType>& vec)
64 {
65     std::string res = "[";
66     if (vec.size()) {
67         res.append(std::to_string(static_cast<int32_t>(vec[0])));
68     }
69     for (size_t i = 1; i != vec.size(); ++i) {
70         res.append(",").append(std::to_string(static_cast<int32_t>(vec[i])));
71     }
72     res.append("]");
73     return res;
74 }
75 
76 } // namespace
77 
RemoveResObj(const std::string & key)78 void ViewAbstract::RemoveResObj(const std::string& key)
79 {
80     if (!SystemProperties::ConfigChangePerform()) {
81         return;
82     }
83     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
84     CHECK_NULL_VOID(frameNode);
85     auto pattern = frameNode->GetPattern<Pattern>();
86     CHECK_NULL_VOID(pattern);
87     pattern->RemoveResObj(key);
88 }
89 
SetWidth(const CalcLength & width)90 void ViewAbstract::SetWidth(const CalcLength& width)
91 {
92     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
93         return;
94     }
95     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
96     CHECK_NULL_VOID(frameNode);
97     auto layoutProperty = frameNode->GetLayoutProperty();
98     CHECK_NULL_VOID(layoutProperty);
99     // get previously user defined ideal height
100     std::optional<CalcLength> height = std::nullopt;
101     auto&& layoutConstraint = layoutProperty->GetCalcLayoutConstraint();
102     if (layoutConstraint && layoutConstraint->selfIdealSize) {
103         height = layoutConstraint->selfIdealSize->Height();
104     }
105     layoutProperty->UpdateUserDefinedIdealSize(CalcSize(width, height));
106 }
107 
SetWidth(const RefPtr<ResourceObject> & resObj)108 void ViewAbstract::SetWidth(const RefPtr<ResourceObject>& resObj)
109 {
110     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
111         return;
112     }
113     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
114     CHECK_NULL_VOID(frameNode);
115     auto pattern = frameNode->GetPattern<Pattern>();
116     CHECK_NULL_VOID(pattern);
117     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
118         auto frameNode = weak.Upgrade();
119         CHECK_NULL_VOID(frameNode);
120         auto pattern = frameNode->GetPattern<Pattern>();
121         CHECK_NULL_VOID(pattern);
122         std::string widthString = pattern->GetResCacheMapByKey("width");
123         CalcDimension value;
124         if (widthString.empty()) {
125             ResourceParseUtils::ParseResDimensionVpNG(resObj, value);
126             pattern->AddResCache("width", value.ToString());
127         } else {
128             value = StringUtils::StringToCalcDimension(widthString);
129         }
130         if (LessNotEqual(value.Value(), 0.0)) {
131             if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) {
132                 ClearWidthOrHeight(true);
133                 return;
134             } else {
135                 value.SetValue(0.0);
136             }
137         }
138         CalcLength width;
139         if (value.Unit() == DimensionUnit::CALC) {
140             width = NG::CalcLength(value.CalcValue());
141         } else {
142             width = NG::CalcLength(value);
143         }
144         auto layoutProperty = frameNode->GetLayoutProperty();
145         CHECK_NULL_VOID(layoutProperty);
146         // get previously user defined ideal height
147         std::optional<CalcLength> height = std::nullopt;
148         auto&& layoutConstraint = layoutProperty->GetCalcLayoutConstraint();
149         if (layoutConstraint && layoutConstraint->selfIdealSize) {
150             height = layoutConstraint->selfIdealSize->Height();
151         }
152         layoutProperty->UpdateUserDefinedIdealSize(CalcSize(width, height));
153         frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
154     };
155     updateFunc(resObj);
156     pattern->AddResObj("width", resObj, std::move(updateFunc));
157 }
158 
SetHeight(const CalcLength & height)159 void ViewAbstract::SetHeight(const CalcLength& height)
160 {
161     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
162         return;
163     }
164     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
165     CHECK_NULL_VOID(frameNode);
166     auto layoutProperty = frameNode->GetLayoutProperty();
167     CHECK_NULL_VOID(layoutProperty);
168     // get previously user defined ideal width
169     std::optional<CalcLength> width = std::nullopt;
170     auto&& layoutConstraint = layoutProperty->GetCalcLayoutConstraint();
171     if (layoutConstraint && layoutConstraint->selfIdealSize) {
172         width = layoutConstraint->selfIdealSize->Width();
173     }
174     layoutProperty->UpdateUserDefinedIdealSize(CalcSize(width, height));
175 }
176 
SetHeight(const RefPtr<ResourceObject> & resObj)177 void ViewAbstract::SetHeight(const RefPtr<ResourceObject>& resObj)
178 {
179     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
180         return;
181     }
182     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
183     CHECK_NULL_VOID(frameNode);
184     auto pattern = frameNode->GetPattern<Pattern>();
185     CHECK_NULL_VOID(pattern);
186     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
187         auto frameNode = weak.Upgrade();
188         CHECK_NULL_VOID(frameNode);
189         auto pattern = frameNode->GetPattern<Pattern>();
190         CHECK_NULL_VOID(pattern);
191         std::string heightString = pattern->GetResCacheMapByKey("height");
192         CalcDimension value;
193         if (heightString.empty()) {
194             ResourceParseUtils::ParseResDimensionVpNG(resObj, value);
195             pattern->AddResCache("height", value.ToString());
196         } else {
197             value = StringUtils::StringToCalcDimension(heightString);
198         }
199         if (LessNotEqual(value.Value(), 0.0)) {
200             if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) {
201                 ClearWidthOrHeight(false);
202                 return;
203             } else {
204                 value.SetValue(0.0);
205             }
206         }
207         CalcLength height;
208         if (value.Unit() == DimensionUnit::CALC) {
209             height = NG::CalcLength(value.CalcValue());
210         } else {
211             height = NG::CalcLength(value);
212         }
213         auto layoutProperty = frameNode->GetLayoutProperty();
214         CHECK_NULL_VOID(layoutProperty);
215         // get previously user defined ideal width
216         std::optional<CalcLength> width = std::nullopt;
217         auto&& layoutConstraint = layoutProperty->GetCalcLayoutConstraint();
218         if (layoutConstraint && layoutConstraint->selfIdealSize) {
219             width = layoutConstraint->selfIdealSize->Width();
220         }
221         layoutProperty->UpdateUserDefinedIdealSize(CalcSize(width, height));
222         frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
223     };
224     updateFunc(resObj);
225     pattern->AddResObj("height", resObj, std::move(updateFunc));
226 }
227 
SetClickEffectLevel(const ClickEffectLevel & level,float scaleValue)228 void ViewAbstract::SetClickEffectLevel(const ClickEffectLevel& level, float scaleValue)
229 {
230     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
231         return;
232     }
233     ClickEffectInfo clickEffectInfo;
234     clickEffectInfo.level = level;
235     clickEffectInfo.scaleNumber = scaleValue;
236     ACE_UPDATE_RENDER_CONTEXT(ClickEffectLevel, clickEffectInfo);
237 }
238 
ClearWidthOrHeight(bool isWidth)239 void ViewAbstract::ClearWidthOrHeight(bool isWidth)
240 {
241     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
242         return;
243     }
244     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
245     CHECK_NULL_VOID(frameNode);
246     auto layoutProperty = frameNode->GetLayoutProperty();
247     CHECK_NULL_VOID(layoutProperty);
248     layoutProperty->ClearUserDefinedIdealSize(isWidth, !isWidth);
249 }
250 
SetMinWidth(const CalcLength & width)251 void ViewAbstract::SetMinWidth(const CalcLength& width)
252 {
253     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
254         return;
255     }
256     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
257     CHECK_NULL_VOID(frameNode);
258     auto layoutProperty = frameNode->GetLayoutProperty();
259     CHECK_NULL_VOID(layoutProperty);
260     layoutProperty->UpdateCalcMinSize(CalcSize(width, std::nullopt));
261 }
262 
SetMinWidth(const RefPtr<ResourceObject> & resObj)263 void ViewAbstract::SetMinWidth(const RefPtr<ResourceObject>& resObj)
264 {
265     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
266         return;
267     }
268     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
269     CHECK_NULL_VOID(frameNode);
270     auto pattern = frameNode->GetPattern<Pattern>();
271     CHECK_NULL_VOID(pattern);
272     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
273         auto frameNode = weak.Upgrade();
274         CHECK_NULL_VOID(frameNode);
275         auto pattern = frameNode->GetPattern<Pattern>();
276         CHECK_NULL_VOID(pattern);
277         std::string minWidthString = pattern->GetResCacheMapByKey("constraintSize.minWidth");
278         CalcDimension value;
279         if (minWidthString.empty()) {
280             ResourceParseUtils::ParseResDimensionVp(resObj, value);
281             pattern->AddResCache("constraintSize.minWidth", value.ToString());
282         } else {
283             value = StringUtils::StringToCalcDimension(minWidthString);
284         }
285         NG::CalcLength width;
286         width = (value.Unit() == DimensionUnit::CALC) ? NG::CalcLength(value.CalcValue()) : NG::CalcLength(value);
287         auto layoutProperty = frameNode->GetLayoutProperty();
288         CHECK_NULL_VOID(layoutProperty);
289         layoutProperty->UpdateCalcMinSize(CalcSize(width, std::nullopt));
290         frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
291     };
292     pattern->AddResObj("constraintSize.minWidth", resObj, std::move(updateFunc));
293 }
294 
SetMinHeight(const CalcLength & height)295 void ViewAbstract::SetMinHeight(const CalcLength& height)
296 {
297     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
298         return;
299     }
300     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
301     CHECK_NULL_VOID(frameNode);
302     auto layoutProperty = frameNode->GetLayoutProperty();
303     CHECK_NULL_VOID(layoutProperty);
304     layoutProperty->UpdateCalcMinSize(CalcSize(std::nullopt, height));
305 }
306 
SetMinHeight(const RefPtr<ResourceObject> & resObj)307 void ViewAbstract::SetMinHeight(const RefPtr<ResourceObject>& resObj)
308 {
309     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
310         return;
311     }
312     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
313     CHECK_NULL_VOID(frameNode);
314     auto pattern = frameNode->GetPattern<Pattern>();
315     CHECK_NULL_VOID(pattern);
316     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
317         auto frameNode = weak.Upgrade();
318         CHECK_NULL_VOID(frameNode);
319         auto pattern = frameNode->GetPattern<Pattern>();
320         CHECK_NULL_VOID(pattern);
321         std::string minWidthString = pattern->GetResCacheMapByKey("constraintSize.minHeight");
322         CalcDimension value;
323         if (minWidthString.empty()) {
324             ResourceParseUtils::ParseResDimensionVp(resObj, value);
325             pattern->AddResCache("constraintSize.minHeight", value.ToString());
326         } else {
327             value = StringUtils::StringToCalcDimension(minWidthString);
328         }
329         NG::CalcLength height;
330         height = (value.Unit() == DimensionUnit::CALC) ? NG::CalcLength(value.CalcValue()) : NG::CalcLength(value);
331         auto layoutProperty = frameNode->GetLayoutProperty();
332         CHECK_NULL_VOID(layoutProperty);
333         layoutProperty->UpdateCalcMinSize(CalcSize(std::nullopt, height));
334         frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
335     };
336     pattern->AddResObj("constraintSize.minHeight", resObj, std::move(updateFunc));
337 }
338 
ResetMinSize(bool resetWidth)339 void ViewAbstract::ResetMinSize(bool resetWidth)
340 {
341     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
342         return;
343     }
344     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
345     CHECK_NULL_VOID(frameNode);
346     auto layoutProperty = frameNode->GetLayoutProperty();
347     CHECK_NULL_VOID(layoutProperty);
348     layoutProperty->ResetCalcMinSize(resetWidth);
349 }
350 
SetMaxWidth(const CalcLength & width)351 void ViewAbstract::SetMaxWidth(const CalcLength& width)
352 {
353     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
354         return;
355     }
356     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
357     CHECK_NULL_VOID(frameNode);
358     auto layoutProperty = frameNode->GetLayoutProperty();
359     CHECK_NULL_VOID(layoutProperty);
360     layoutProperty->UpdateCalcMaxSize(CalcSize(width, std::nullopt));
361 }
362 
SetMaxWidth(const RefPtr<ResourceObject> & resObj)363 void ViewAbstract::SetMaxWidth(const RefPtr<ResourceObject>& resObj)
364 {
365     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
366         return;
367     }
368     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
369     CHECK_NULL_VOID(frameNode);
370     auto pattern = frameNode->GetPattern<Pattern>();
371     CHECK_NULL_VOID(pattern);
372     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
373         auto frameNode = weak.Upgrade();
374         CHECK_NULL_VOID(frameNode);
375         auto pattern = frameNode->GetPattern<Pattern>();
376         CHECK_NULL_VOID(pattern);
377         std::string minWidthString = pattern->GetResCacheMapByKey("constraintSize.maxWidth");
378         CalcDimension value;
379         if (minWidthString.empty()) {
380             ResourceParseUtils::ParseResDimensionVp(resObj, value);
381             pattern->AddResCache("constraintSize.maxWidth", value.ToString());
382         } else {
383             value = StringUtils::StringToCalcDimension(minWidthString);
384         }
385         NG::CalcLength width;
386         width = (value.Unit() == DimensionUnit::CALC) ? NG::CalcLength(value.CalcValue()) : NG::CalcLength(value);
387         auto layoutProperty = frameNode->GetLayoutProperty();
388         CHECK_NULL_VOID(layoutProperty);
389         layoutProperty->UpdateCalcMaxSize(CalcSize(width, std::nullopt));
390         frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
391     };
392     pattern->AddResObj("constraintSize.maxWidth", resObj, std::move(updateFunc));
393 }
394 
SetMaxHeight(const CalcLength & height)395 void ViewAbstract::SetMaxHeight(const CalcLength& height)
396 {
397     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
398         return;
399     }
400     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
401     CHECK_NULL_VOID(frameNode);
402     auto layoutProperty = frameNode->GetLayoutProperty();
403     CHECK_NULL_VOID(layoutProperty);
404     layoutProperty->UpdateCalcMaxSize(CalcSize(std::nullopt, height));
405 }
406 
SetMaxHeight(const RefPtr<ResourceObject> & resObj)407 void ViewAbstract::SetMaxHeight(const RefPtr<ResourceObject>& resObj)
408 {
409     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
410         return;
411     }
412     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
413     CHECK_NULL_VOID(frameNode);
414     auto pattern = frameNode->GetPattern<Pattern>();
415     CHECK_NULL_VOID(pattern);
416     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
417         auto frameNode = weak.Upgrade();
418         CHECK_NULL_VOID(frameNode);
419         auto pattern = frameNode->GetPattern<Pattern>();
420         CHECK_NULL_VOID(pattern);
421         std::string minWidthString = pattern->GetResCacheMapByKey("constraintSize.maxHeight");
422         CalcDimension value;
423         if (minWidthString.empty()) {
424             ResourceParseUtils::ParseResDimensionVp(resObj, value);
425             pattern->AddResCache("constraintSize.maxHeight", value.ToString());
426         } else {
427             value = StringUtils::StringToCalcDimension(minWidthString);
428         }
429         NG::CalcLength height;
430         height = (value.Unit() == DimensionUnit::CALC) ? NG::CalcLength(value.CalcValue()) : NG::CalcLength(value);
431         auto layoutProperty = frameNode->GetLayoutProperty();
432         CHECK_NULL_VOID(layoutProperty);
433         layoutProperty->UpdateCalcMaxSize(CalcSize(std::nullopt, height));
434         frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
435     };
436     pattern->AddResObj("constraintSize.maxHeight", resObj, std::move(updateFunc));
437 }
438 
ResetMaxSize(bool resetWidth)439 void ViewAbstract::ResetMaxSize(bool resetWidth)
440 {
441     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
442         return;
443     }
444     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
445     CHECK_NULL_VOID(frameNode);
446     auto layoutProperty = frameNode->GetLayoutProperty();
447     CHECK_NULL_VOID(layoutProperty);
448     layoutProperty->ResetCalcMaxSize(resetWidth);
449 }
450 
SetAspectRatio(float ratio)451 void ViewAbstract::SetAspectRatio(float ratio)
452 {
453     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
454         return;
455     }
456     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, AspectRatio, ratio);
457 }
458 
ResetAspectRatio()459 void ViewAbstract::ResetAspectRatio()
460 {
461     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
462         return;
463     }
464     ACE_RESET_LAYOUT_PROPERTY(LayoutProperty, AspectRatio);
465 }
466 
SetBackgroundAlign(const Alignment & align)467 void ViewAbstract::SetBackgroundAlign(const Alignment& align)
468 {
469     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
470         return;
471     }
472     ACE_UPDATE_RENDER_CONTEXT(BackgroundAlign, align);
473 }
474 
SetCustomBackgroundColor(const Color & color)475 void ViewAbstract::SetCustomBackgroundColor(const Color& color)
476 {
477     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
478         return;
479     }
480 
481     ACE_UPDATE_RENDER_CONTEXT(CustomBackgroundColor, color);
482 }
483 
SetBackgroundIgnoresLayoutSafeAreaEdges(const uint32_t layoutSafeAreaEdges)484 void ViewAbstract::SetBackgroundIgnoresLayoutSafeAreaEdges(const uint32_t layoutSafeAreaEdges)
485 {
486     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
487         return;
488     }
489     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
490     CHECK_NULL_VOID(frameNode);
491     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, BackgroundIgnoresLayoutSafeAreaEdges, layoutSafeAreaEdges);
492     frameNode->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT);
493 }
494 
SetIsTransitionBackground(bool val)495 void ViewAbstract::SetIsTransitionBackground(bool val)
496 {
497     ACE_UPDATE_RENDER_CONTEXT(IsTransitionBackground, val);
498 }
499 
SetIsBuilderBackground(bool val)500 void ViewAbstract::SetIsBuilderBackground(bool val)
501 {
502     ACE_UPDATE_RENDER_CONTEXT(BuilderBackgroundFlag, val);
503 }
504 
SetCustomBackgroundColorWithResourceObj(const Color & color,const RefPtr<ResourceObject> & resObj)505 void ViewAbstract::SetCustomBackgroundColorWithResourceObj(const Color& color, const RefPtr<ResourceObject>& resObj)
506 {
507     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
508         return;
509     }
510     SetCustomBackgroundColor(color);
511 
512     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
513     CHECK_NULL_VOID(frameNode);
514     auto pattern = frameNode->GetPattern<Pattern>();
515     CHECK_NULL_VOID(pattern);
516     pattern->RemoveResObj("customBackgroundColor");
517     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
518         CHECK_NULL_VOID(resObj);
519         auto frameNode = weak.Upgrade();
520         CHECK_NULL_VOID(frameNode);
521         auto pattern = frameNode->GetPattern<Pattern>();
522         CHECK_NULL_VOID(pattern);
523         Color backgroundColor = Color::TRANSPARENT;
524         ResourceParseUtils::ParseResColor(resObj, backgroundColor);
525         ACE_UPDATE_NODE_RENDER_CONTEXT(CustomBackgroundColor, backgroundColor, frameNode);
526     };
527     pattern->AddResObj("customBackgroundColor", resObj, std::move(updateFunc));
528 }
529 
SetBackgroundAlign(FrameNode * frameNode,const Alignment & align)530 void ViewAbstract::SetBackgroundAlign(FrameNode* frameNode, const Alignment& align)
531 {
532     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
533         return;
534     }
535     ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundAlign, align, frameNode);
536 }
537 
SetCustomBackgroundColor(FrameNode * frameNode,const Color & color)538 void ViewAbstract::SetCustomBackgroundColor(FrameNode* frameNode, const Color& color)
539 {
540     CHECK_NULL_VOID(frameNode);
541     auto pattern = frameNode->GetPattern<Pattern>();
542     CHECK_NULL_VOID(pattern);
543     pattern->RemoveResObj("customBackgroundColor");
544     ACE_UPDATE_NODE_RENDER_CONTEXT(CustomBackgroundColor, color, frameNode);
545 }
546 
SetBackgroundIgnoresLayoutSafeAreaEdges(FrameNode * frameNode,const uint32_t layoutSafeAreaEdges)547 void ViewAbstract::SetBackgroundIgnoresLayoutSafeAreaEdges(FrameNode* frameNode, const uint32_t layoutSafeAreaEdges)
548 {
549     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
550         return;
551     }
552     CHECK_NULL_VOID(frameNode);
553     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
554         LayoutProperty, BackgroundIgnoresLayoutSafeAreaEdges, layoutSafeAreaEdges, frameNode);
555     frameNode->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT);
556 }
557 
SetIsTransitionBackground(FrameNode * frameNode,bool val)558 void ViewAbstract::SetIsTransitionBackground(FrameNode* frameNode, bool val)
559 {
560     CHECK_NULL_VOID(frameNode);
561     ACE_UPDATE_NODE_RENDER_CONTEXT(IsTransitionBackground, val, frameNode);
562 }
563 
SetIsBuilderBackground(FrameNode * frameNode,bool val)564 void ViewAbstract::SetIsBuilderBackground(FrameNode* frameNode, bool val)
565 {
566     CHECK_NULL_VOID(frameNode);
567     ACE_UPDATE_NODE_RENDER_CONTEXT(BuilderBackgroundFlag, val, frameNode);
568 }
569 
SetCustomBackgroundColorWithResourceObj(FrameNode * frameNode,const Color & color,const RefPtr<ResourceObject> & resObj)570 void ViewAbstract::SetCustomBackgroundColorWithResourceObj(
571     FrameNode* frameNode, const Color& color, const RefPtr<ResourceObject>& resObj)
572 {
573     CHECK_NULL_VOID(frameNode);
574     auto pattern = frameNode->GetPattern<Pattern>();
575     CHECK_NULL_VOID(pattern);
576     pattern->RemoveResObj("customBackgroundColor");
577     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
578         CHECK_NULL_VOID(resObj);
579         auto frameNode = weak.Upgrade();
580         CHECK_NULL_VOID(frameNode);
581         auto pattern = frameNode->GetPattern<Pattern>();
582         CHECK_NULL_VOID(pattern);
583         Color backgroundColor = Color::TRANSPARENT;
584         ResourceParseUtils::ParseResColor(resObj, backgroundColor);
585         ACE_UPDATE_NODE_RENDER_CONTEXT(CustomBackgroundColor, backgroundColor, frameNode);
586     };
587     pattern->AddResObj("customBackgroundColor", resObj, std::move(updateFunc));
588     ACE_UPDATE_NODE_RENDER_CONTEXT(CustomBackgroundColor, color, frameNode);
589 }
590 
RequestFrame()591 void ViewAbstract::RequestFrame()
592 {
593     auto pipeline = PipelineContext::GetCurrentContextSafelyWithCheck();
594     if (pipeline != nullptr) {
595         pipeline->RequestFrame();
596     }
597 }
598 
SetBackgroundColor(const Color & color)599 void ViewAbstract::SetBackgroundColor(const Color& color)
600 {
601     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
602         return;
603     }
604 
605     Color updateColor = color;
606     auto pipeline = PipelineContext::GetCurrentContext();
607     if (pipeline != nullptr) {
608         pipeline->CheckNeedUpdateBackgroundColor(updateColor);
609     }
610 
611     ACE_UPDATE_RENDER_CONTEXT(BackgroundColor, updateColor);
612 }
613 
SetBackgroundColorWithResourceObj(const Color & color,const RefPtr<ResourceObject> & resObj)614 void ViewAbstract::SetBackgroundColorWithResourceObj(const Color& color, const RefPtr<ResourceObject>& resObj)
615 {
616     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
617         return;
618     }
619     SetBackgroundColor(color);
620 
621     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
622     CHECK_NULL_VOID(frameNode);
623     auto pattern = frameNode->GetPattern<Pattern>();
624     CHECK_NULL_VOID(pattern);
625     pattern->RemoveResObj("backgroundColor");
626     auto &&updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject> &resObj) {
627         CHECK_NULL_VOID(resObj);
628         auto frameNode = weak.Upgrade();
629         CHECK_NULL_VOID(frameNode);
630         auto pattern = frameNode->GetPattern<Pattern>();
631         CHECK_NULL_VOID(pattern);
632         Color backgroundColor = Color::TRANSPARENT;
633         ResourceParseUtils::ParseResColor(resObj, backgroundColor);
634         auto pipeline = frameNode->GetContext();
635         if (pipeline != nullptr) {
636             pipeline->CheckNeedUpdateBackgroundColor(backgroundColor);
637         }
638         ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundColor, backgroundColor, frameNode);
639     };
640     pattern->AddResObj("backgroundColor", resObj, std::move(updateFunc));
641 }
642 
SetBackgroundColor(FrameNode * frameNode,const Color & color)643 void ViewAbstract::SetBackgroundColor(FrameNode* frameNode, const Color& color)
644 {
645     CHECK_NULL_VOID(frameNode);
646     auto pattern = frameNode->GetPattern<Pattern>();
647     CHECK_NULL_VOID(pattern);
648     pattern->RemoveResObj("backgroundColor");
649     ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundColor, color, frameNode);
650 }
651 
SetBackgroundColor(FrameNode * frameNode,const Color & color,const RefPtr<ResourceObject> & resObj)652 void ViewAbstract::SetBackgroundColor(FrameNode* frameNode, const Color& color, const RefPtr<ResourceObject>& resObj)
653 {
654     CHECK_NULL_VOID(frameNode);
655     auto pattern = frameNode->GetPattern<Pattern>();
656     CHECK_NULL_VOID(pattern);
657     auto &&updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject> &resObj) {
658         CHECK_NULL_VOID(resObj);
659         auto frameNode = weak.Upgrade();
660         CHECK_NULL_VOID(frameNode);
661         auto pattern = frameNode->GetPattern<Pattern>();
662         CHECK_NULL_VOID(pattern);
663         Color backgroundColor;
664         ResourceParseUtils::ParseResColor(resObj, backgroundColor);
665         ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundColor, backgroundColor, frameNode);
666     };
667     pattern->AddResObj("backgroundColor", resObj, std::move(updateFunc));
668     ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundColor, color, frameNode);
669 }
670 
SetBackgroundImage(const ImageSourceInfo & src)671 void ViewAbstract::SetBackgroundImage(const ImageSourceInfo& src)
672 {
673     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
674         return;
675     }
676     auto pipeline = PipelineContext::GetCurrentContext();
677     if (pipeline != nullptr) {
678         bool disableSetImage = pipeline->CheckNeedDisableUpdateBackgroundImage();
679         if (disableSetImage) {
680             return;
681         }
682     }
683     ACE_UPDATE_RENDER_CONTEXT(BackgroundImage, src);
684 }
685 
SetBackgroundImageWithResourceObj(const RefPtr<ResourceObject> & resObj,const ImageSourceInfo & src)686 void ViewAbstract::SetBackgroundImageWithResourceObj(const RefPtr<ResourceObject>& resObj, const ImageSourceInfo& src)
687 {
688     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
689         return;
690     }
691     SetBackgroundImage(src);
692 
693     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
694     CHECK_NULL_VOID(frameNode);
695     auto pattern = frameNode->GetPattern<Pattern>();
696     CHECK_NULL_VOID(pattern);
697     if (!resObj) {
698         pattern->RemoveResObj("backgroundImageSrc");
699         return;
700     }
701     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode), bundleName = src.GetBundleName(),
702                             moduleName = src.GetModuleName()](const RefPtr<ResourceObject>& resObj) {
703         CHECK_NULL_VOID(resObj);
704         auto frameNode = weak.Upgrade();
705         CHECK_NULL_VOID(frameNode);
706         auto pattern = frameNode->GetPattern<Pattern>();
707         CHECK_NULL_VOID(pattern);
708         std::string src;
709         ResourceParseUtils::ParseResMedia(resObj, src);
710         auto pipeline = frameNode->GetContext();
711         if (pipeline && pipeline->CheckNeedDisableUpdateBackgroundImage()) {
712             return;
713         }
714         auto imageSrc = ImageSourceInfo { src, bundleName, moduleName };
715         ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImage, imageSrc, frameNode);
716 
717         const auto& target = frameNode->GetRenderContext();
718         if (target) {
719             target->OnBackgroundImageUpdate(imageSrc);
720         }
721     };
722     pattern->AddResObj("backgroundImageSrc", resObj, std::move(updateFunc));
723 }
724 
SetBackgroundImage(FrameNode * frameNode,const ImageSourceInfo & src)725 void ViewAbstract::SetBackgroundImage(FrameNode* frameNode, const ImageSourceInfo& src)
726 {
727     CHECK_NULL_VOID(frameNode);
728     auto pattern = frameNode->GetPattern<Pattern>();
729     CHECK_NULL_VOID(pattern);
730     pattern->RemoveResObj("backgroundImageSrc");
731     ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImage, src, frameNode);
732 }
733 
SetBackgroundImage(FrameNode * frameNode,const ImageSourceInfo & src,const RefPtr<ResourceObject> & resObj)734 void ViewAbstract::SetBackgroundImage(
735     FrameNode* frameNode, const ImageSourceInfo& src, const RefPtr<ResourceObject>& resObj)
736 {
737     CHECK_NULL_VOID(frameNode);
738     auto pattern = frameNode->GetPattern<Pattern>();
739     CHECK_NULL_VOID(pattern);
740     auto &&updateFunc = [weak = AceType::WeakClaim(frameNode),
741                             bundleName = src.GetBundleName(),
742                             moduleName = src.GetModuleName()](const RefPtr<ResourceObject> &resObj) {
743         CHECK_NULL_VOID(resObj);
744         auto frameNode = weak.Upgrade();
745         CHECK_NULL_VOID(frameNode);
746         auto pattern = frameNode->GetPattern<Pattern>();
747         CHECK_NULL_VOID(pattern);
748         std::string src;
749         ResourceParseUtils::ParseResMedia(resObj, src);
750         auto pipeline = frameNode->GetContext();
751         if (pipeline != nullptr) {
752             bool disableSetImage = pipeline->CheckNeedDisableUpdateBackgroundImage();
753             if (disableSetImage) {
754                 return;
755             }
756         }
757         auto imageSrc = ImageSourceInfo{src, bundleName, moduleName};
758         ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImage, imageSrc, frameNode);
759 
760         const auto& target = frameNode->GetRenderContext();
761         if (target) {
762             target->OnBackgroundImageUpdate(imageSrc);
763         }
764     };
765     pattern->AddResObj("backgroundImageSrc", resObj, std::move(updateFunc));
766     ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImage, src, frameNode);
767 }
768 
SetBackgroundImageRepeat(const ImageRepeat & imageRepeat)769 void ViewAbstract::SetBackgroundImageRepeat(const ImageRepeat& imageRepeat)
770 {
771     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
772         return;
773     }
774     ACE_UPDATE_RENDER_CONTEXT(BackgroundImageRepeat, imageRepeat);
775 }
776 
SetBackgroundImageRepeat(FrameNode * frameNode,const ImageRepeat & imageRepeat)777 void ViewAbstract::SetBackgroundImageRepeat(FrameNode* frameNode, const ImageRepeat& imageRepeat)
778 {
779     ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImageRepeat, imageRepeat, frameNode);
780 }
781 
SetBackgroundImageSyncMode(bool syncMode)782 void ViewAbstract::SetBackgroundImageSyncMode(bool syncMode)
783 {
784     ACE_UPDATE_RENDER_CONTEXT(BackgroundImageSyncMode, syncMode);
785 }
786 
SetBackgroundImageSyncMode(FrameNode * frameNode,bool syncMode)787 void ViewAbstract::SetBackgroundImageSyncMode(FrameNode* frameNode, bool syncMode)
788 {
789     ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImageSyncMode, syncMode, frameNode);
790 }
791 
SetBackgroundImageSizeUpdateFunc(BackgroundImageSize & bgImgSize,const RefPtr<ResourceObject> & resObj,const std::string direction)792 void ViewAbstract::SetBackgroundImageSizeUpdateFunc(
793     BackgroundImageSize& bgImgSize, const RefPtr<ResourceObject>& resObj, const std::string direction)
794 {
795     if (direction.empty()) {
796         return;
797     }
798     if (!resObj) {
799         (direction == "width") ? bgImgSize.RemoveResource("backgroundImageSizeWidth")
800                             : bgImgSize.RemoveResource("backgroundImageSizeHeight");
801         return;
802     }
803     auto&& updateFunc = [direction](const RefPtr<ResourceObject>& resObj, BackgroundImageSize& bgImgSize) {
804         CHECK_NULL_VOID(resObj);
805         CalcDimension dimension;
806         ResourceParseUtils::ParseResDimensionVp(resObj, dimension);
807         double value = dimension.ConvertToPx();
808         BackgroundImageSizeType type = BackgroundImageSizeType::LENGTH;
809         if (dimension.Unit() == DimensionUnit::PERCENT) {
810             type = BackgroundImageSizeType::PERCENT;
811             value = dimension.Value() * FULL_DIMENSION;
812         }
813         if (direction == "width") {
814             bgImgSize.SetSizeTypeX(type);
815             bgImgSize.SetSizeValueX(value);
816         } else if (direction == "height") {
817             bgImgSize.SetSizeTypeY(type);
818             bgImgSize.SetSizeValueY(value);
819         }
820     };
821     (direction == "width") ? bgImgSize.AddResource("backgroundImageSizeWidth", resObj, std::move(updateFunc))
822                         : bgImgSize.AddResource("backgroundImageSizeHeight", resObj, std::move(updateFunc));
823 }
824 
SetBackgroundImageSize(BackgroundImageSize & bgImgSize)825 void ViewAbstract::SetBackgroundImageSize(BackgroundImageSize& bgImgSize)
826 {
827     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
828         return;
829     }
830 
831     if (SystemProperties::ConfigChangePerform()) {
832         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
833         CHECK_NULL_VOID(frameNode);
834         auto pattern = frameNode->GetPattern();
835         CHECK_NULL_VOID(pattern);
836         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>();
837         auto&& updateFunc = [bgImgSize, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
838             auto frameNode = weak.Upgrade();
839             CHECK_NULL_VOID(frameNode);
840             BackgroundImageSize bgImgSizeValue = bgImgSize;
841             bgImgSizeValue.ReloadResources();
842             ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImageSize, bgImgSizeValue, frameNode);
843         };
844         pattern->AddResObj("backgroundImageSize", resObj, std::move(updateFunc));
845     }
846 
847     ACE_UPDATE_RENDER_CONTEXT(BackgroundImageSize, bgImgSize);
848 }
849 
SetBackgroundImageSize(FrameNode * frameNode,BackgroundImageSize & bgImgSize,bool isReset)850 void ViewAbstract::SetBackgroundImageSize(FrameNode* frameNode, BackgroundImageSize& bgImgSize, bool isReset)
851 {
852     CHECK_NULL_VOID(frameNode);
853     if (SystemProperties::ConfigChangePerform()) {
854         auto pattern = frameNode->GetPattern();
855         CHECK_NULL_VOID(pattern);
856         if (isReset) {
857             pattern->RemoveResObj("backgroundImageSize");
858         } else {
859             RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>();
860             auto&& updateFunc = [bgImgSize, weak = AceType::WeakClaim(frameNode)](
861                                     const RefPtr<ResourceObject>& resObj) {
862                 auto frameNode = weak.Upgrade();
863                 CHECK_NULL_VOID(frameNode);
864                 BackgroundImageSize bgImgSizeValue = bgImgSize;
865                 bgImgSizeValue.ReloadResources();
866                 ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImageSize, bgImgSizeValue, frameNode);
867             };
868             pattern->AddResObj("backgroundImageSize", resObj, std::move(updateFunc));
869         }
870     }
871     ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImageSize, bgImgSize, frameNode);
872 }
873 
SetBackgroundImagePositionUpdateFunc(FrameNode * frameNode,BackgroundImagePosition & bgImgPosition)874 void SetBackgroundImagePositionUpdateFunc(FrameNode* frameNode, BackgroundImagePosition& bgImgPosition)
875 {
876     CHECK_NULL_VOID(frameNode);
877     auto pattern = frameNode->GetPattern();
878     CHECK_NULL_VOID(pattern);
879     RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>();
880     auto&& updateFunc = [bgImgPosition, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
881         auto frameNode = weak.Upgrade();
882         CHECK_NULL_VOID(frameNode);
883         BackgroundImagePosition bgImgPositionValue = bgImgPosition;
884         bgImgPositionValue.ReloadResources();
885         ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImagePosition, bgImgPositionValue, frameNode);
886     };
887     pattern->AddResObj("backgroundImagePosition", resObj, std::move(updateFunc));
888 }
889 
SetBackgroundImagePosition(BackgroundImagePosition & bgImgPosition)890 void ViewAbstract::SetBackgroundImagePosition(BackgroundImagePosition& bgImgPosition)
891 {
892     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
893         return;
894     }
895 
896     if (SystemProperties::ConfigChangePerform()) {
897         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
898         SetBackgroundImagePositionUpdateFunc(frameNode, bgImgPosition);
899     }
900 
901     ACE_UPDATE_RENDER_CONTEXT(BackgroundImagePosition, bgImgPosition);
902 }
903 
SetBackgroundImagePosition(FrameNode * frameNode,BackgroundImagePosition & bgImgPosition,bool isReset)904 void ViewAbstract::SetBackgroundImagePosition(
905     FrameNode* frameNode, BackgroundImagePosition& bgImgPosition, bool isReset)
906 {
907     CHECK_NULL_VOID(frameNode);
908     if (SystemProperties::ConfigChangePerform()) {
909         if (isReset) {
910             auto pattern = frameNode->GetPattern();
911             CHECK_NULL_VOID(pattern);
912             pattern->RemoveResObj("backgroundImagePosition");
913         } else {
914             SetBackgroundImagePositionUpdateFunc(frameNode, bgImgPosition);
915         }
916     }
917 
918     ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImagePosition, bgImgPosition, frameNode);
919 }
920 
ClearResObj(const std::string resObjName)921 void ViewAbstract::ClearResObj(const std::string resObjName)
922 {
923     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
924     CHECK_NULL_VOID(frameNode);
925     auto pattern = frameNode->GetPattern();
926     CHECK_NULL_VOID(pattern);
927     pattern->RemoveResObj(resObjName);
928 }
929 
SetBackgroundBlurStyle(const BlurStyleOption & bgBlurStyle,const SysOptions & sysOptions)930 void ViewAbstract::SetBackgroundBlurStyle(const BlurStyleOption& bgBlurStyle, const SysOptions& sysOptions)
931 {
932     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
933         return;
934     }
935     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
936     CHECK_NULL_VOID(frameNode);
937     SetBackgroundBlurStyle(frameNode, bgBlurStyle, sysOptions);
938 }
939 
SetForegroundEffect(float radius)940 void ViewAbstract::SetForegroundEffect(float radius)
941 {
942     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
943         return;
944     }
945     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
946     CHECK_NULL_VOID(frameNode);
947     auto target = frameNode->GetRenderContext();
948     if (target) {
949         target->UpdateForegroundEffect(radius);
950     }
951 }
952 
SetMotionBlur(const MotionBlurOption & motionBlurOption)953 void ViewAbstract::SetMotionBlur(const MotionBlurOption &motionBlurOption)
954 {
955     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
956         return;
957     }
958     ACE_UPDATE_RENDER_CONTEXT(MotionBlur, motionBlurOption);
959 }
960 
SetBackgroundEffect(const EffectOption & effectOption,const SysOptions & sysOptions)961 void ViewAbstract::SetBackgroundEffect(const EffectOption& effectOption, const SysOptions& sysOptions)
962 {
963     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
964         return;
965     }
966     SetBackgroundEffect(ViewStackProcessor::GetInstance()->GetMainFrameNode(), effectOption, sysOptions);
967 }
968 
SetForegroundBlurStyle(const BlurStyleOption & fgBlurStyle,const SysOptions & sysOptions)969 void ViewAbstract::SetForegroundBlurStyle(const BlurStyleOption& fgBlurStyle, const SysOptions& sysOptions)
970 {
971     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
972         return;
973     }
974     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
975     CHECK_NULL_VOID(frameNode);
976     auto target = frameNode->GetRenderContext();
977     if (target) {
978         target->UpdateFrontBlurStyle(fgBlurStyle, sysOptions);
979         if (target->GetFrontBlurRadius().has_value()) {
980             target->UpdateFrontBlurRadius(Dimension());
981         }
982     }
983 }
984 
SetSphericalEffect(double radio)985 void ViewAbstract::SetSphericalEffect(double radio)
986 {
987     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
988         return;
989     }
990     ACE_UPDATE_RENDER_CONTEXT(SphericalEffect, radio);
991 }
992 
SetPixelStretchEffect(PixStretchEffectOption & option)993 void ViewAbstract::SetPixelStretchEffect(PixStretchEffectOption& option)
994 {
995     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
996         return;
997     }
998     if (SystemProperties::ConfigChangePerform()) {
999         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1000         CHECK_NULL_VOID(frameNode);
1001         auto pattern = frameNode->GetPattern();
1002         CHECK_NULL_VOID(pattern);
1003         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1004         auto&& updateFunc = [option, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1005             auto frameNode = weak.Upgrade();
1006             CHECK_NULL_VOID(frameNode);
1007             PixStretchEffectOption& value = const_cast<PixStretchEffectOption&>(option);
1008             value.ReloadResources();
1009             ACE_UPDATE_NODE_RENDER_CONTEXT(PixelStretchEffect, value, frameNode);
1010         };
1011         pattern->AddResObj("pixelStretchEffect", resObj, std::move(updateFunc));
1012     }
1013     ACE_UPDATE_RENDER_CONTEXT(PixelStretchEffect, option);
1014 }
1015 
SetLightUpEffect(double radio)1016 void ViewAbstract::SetLightUpEffect(double radio)
1017 {
1018     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1019         return;
1020     }
1021     ACE_UPDATE_RENDER_CONTEXT(LightUpEffect, radio);
1022 }
1023 
SetLayoutWeight(float value)1024 void ViewAbstract::SetLayoutWeight(float value)
1025 {
1026     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1027         return;
1028     }
1029     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, LayoutWeight, static_cast<float>(value));
1030 }
1031 
SetChainWeight(const NG::ChainWeightPair & value)1032 void ViewAbstract::SetChainWeight(const NG::ChainWeightPair& value)
1033 {
1034     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1035         return;
1036     }
1037     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, ChainWeight, value);
1038 }
1039 
SetPixelRound(uint16_t value)1040 void ViewAbstract::SetPixelRound(uint16_t value)
1041 {
1042     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1043         return;
1044     }
1045     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, PixelRound, value);
1046 }
1047 
SetPixelRound(FrameNode * frameNode,uint16_t value)1048 void ViewAbstract::SetPixelRound(FrameNode* frameNode, uint16_t value)
1049 {
1050     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, PixelRound, value, frameNode);
1051 }
1052 
SetLayoutDirection(TextDirection value)1053 void ViewAbstract::SetLayoutDirection(TextDirection value)
1054 {
1055     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1056         return;
1057     }
1058     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, LayoutDirection, value);
1059 }
1060 
SetAlignRules(const std::map<AlignDirection,AlignRule> & alignRules)1061 void ViewAbstract::SetAlignRules(const std::map<AlignDirection, AlignRule>& alignRules)
1062 {
1063     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1064         return;
1065     }
1066     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, AlignRules, alignRules);
1067 }
1068 
SetChainStyle(const ChainInfo & chainInfo)1069 void ViewAbstract::SetChainStyle(const ChainInfo& chainInfo)
1070 {
1071     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1072         return;
1073     }
1074     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, ChainStyle, chainInfo);
1075 }
1076 
SetBias(const BiasPair & biasPair)1077 void ViewAbstract::SetBias(const BiasPair& biasPair)
1078 {
1079     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1080         return;
1081     }
1082     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Bias, biasPair);
1083 }
1084 
SetAlignSelf(FlexAlign value)1085 void ViewAbstract::SetAlignSelf(FlexAlign value)
1086 {
1087     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1088         return;
1089     }
1090     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, AlignSelf, value);
1091 }
1092 
SetFlexShrink(float value)1093 void ViewAbstract::SetFlexShrink(float value)
1094 {
1095     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1096         return;
1097     }
1098     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, FlexShrink, value);
1099 }
1100 
ResetFlexShrink()1101 void ViewAbstract::ResetFlexShrink()
1102 {
1103     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1104         return;
1105     }
1106     ACE_RESET_LAYOUT_PROPERTY(LayoutProperty, FlexShrink);
1107 }
1108 
SetFlexGrow(float value)1109 void ViewAbstract::SetFlexGrow(float value)
1110 {
1111     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1112         return;
1113     }
1114     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, FlexGrow, value);
1115 }
1116 
SetFlexBasis(const Dimension & value)1117 void ViewAbstract::SetFlexBasis(const Dimension& value)
1118 {
1119     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1120         return;
1121     }
1122     if (LessNotEqual(value.Value(), 0.0f)) {
1123         ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, FlexBasis, Dimension());
1124         return;
1125     }
1126     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, FlexBasis, value);
1127 }
1128 
SetDisplayIndex(int32_t value)1129 void ViewAbstract::SetDisplayIndex(int32_t value)
1130 {
1131     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1132         return;
1133     }
1134     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, DisplayIndex, value);
1135 }
1136 
CheckLocalizedMarginOrPadding(PaddingProperty & value,const TextDirection & direction)1137 void ViewAbstract::CheckLocalizedMarginOrPadding(PaddingProperty& value, const TextDirection& direction)
1138 {
1139     PaddingProperty padding = value;
1140     if (padding.start.has_value()) {
1141         value.start = padding.start;
1142         if (direction == TextDirection::RTL) {
1143             value.right = padding.start;
1144         } else {
1145             value.left = padding.start;
1146         }
1147     }
1148     if (padding.end.has_value()) {
1149         value.end = padding.end;
1150         if (direction == TextDirection::RTL) {
1151             value.left = padding.end;
1152         } else {
1153             value.right = padding.end;
1154         }
1155     }
1156     if (padding.top.has_value()) {
1157         value.top = padding.top;
1158     }
1159     if (padding.bottom.has_value()) {
1160         value.bottom = padding.bottom;
1161     }
1162     if (value.left.has_value() && !value.right.has_value()) {
1163         value.right = std::optional<CalcLength>(CalcLength(0));
1164     }
1165     if (!value.left.has_value() && value.right.has_value()) {
1166         value.left = std::optional<CalcLength>(CalcLength(0));
1167     }
1168 }
1169 
CheckPositionOrOffsetLocalizedEdges(EdgesParam & value,TextDirection layoutDirection)1170 void ViewAbstract::CheckPositionOrOffsetLocalizedEdges(EdgesParam& value, TextDirection layoutDirection)
1171 {
1172     EdgesParam edges = value;
1173     if (!edges.start.has_value() && !edges.end.has_value()) {
1174         return;
1175     }
1176     if (edges.top.has_value()) {
1177         value.SetTop(edges.top.value_or(Dimension(0.0)));
1178     }
1179     if (edges.bottom.has_value()) {
1180         value.SetBottom(edges.bottom.value_or(Dimension(0.0)));
1181     }
1182     if (edges.start.has_value()) {
1183         value.start = edges.start.value();
1184         if (layoutDirection == TextDirection::RTL) {
1185             value.SetRight(edges.start.value_or(Dimension(0.0)));
1186         } else {
1187             value.SetLeft(edges.start.value_or(Dimension(0.0)));
1188         }
1189     }
1190     if (edges.end.has_value()) {
1191         value.end = edges.end.value();
1192         if (layoutDirection == TextDirection::RTL) {
1193             value.SetLeft(edges.end.value_or(Dimension(0.0)));
1194         } else {
1195             value.SetRight(edges.end.value_or(Dimension(0.0)));
1196         }
1197     }
1198 }
1199 
SetPadding(const CalcLength & value)1200 void ViewAbstract::SetPadding(const CalcLength& value)
1201 {
1202     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1203         return;
1204     }
1205     PaddingProperty padding;
1206     padding.SetEdges(value);
1207     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Padding, padding);
1208 }
1209 
SetPadding(const PaddingProperty & value)1210 void ViewAbstract::SetPadding(const PaddingProperty& value)
1211 {
1212     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1213         return;
1214     }
1215     if (SystemProperties::ConfigChangePerform()) {
1216         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1217         CHECK_NULL_VOID(frameNode);
1218         auto pattern = frameNode->GetPattern<Pattern>();
1219         CHECK_NULL_VOID(pattern);
1220         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1221         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1222             auto frameNode = weak.Upgrade();
1223             CHECK_NULL_VOID(frameNode);
1224             PaddingProperty &padding = const_cast<PaddingProperty &>(value);
1225             padding.ReloadResources();
1226             auto layoutProperty = frameNode->GetLayoutProperty();
1227             CHECK_NULL_VOID(layoutProperty);
1228             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
1229             CheckLocalizedMarginOrPadding(padding, layoutDirection);
1230             ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Padding, padding, frameNode);
1231             if (frameNode->GetTag() == V2::TEXTAREA_ETS_TAG || frameNode->GetTag() ==V2::TEXTINPUT_ETS_TAG) {
1232                 ACE_UPDATE_NODE_PAINT_PROPERTY(TextFieldPaintProperty, PaddingByUser, padding, frameNode);
1233             }
1234             frameNode->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT | PROPERTY_UPDATE_MEASURE);
1235         };
1236         pattern->AddResObj("padding", resObj, std::move(updateFunc));
1237     }
1238     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Padding, value);
1239 }
1240 
SetPadding(const RefPtr<ResourceObject> & resObj)1241 void ViewAbstract::SetPadding(const RefPtr<ResourceObject>& resObj)
1242 {
1243     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1244         return;
1245     }
1246     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1247     CHECK_NULL_VOID(frameNode);
1248 
1249     auto pattern = frameNode->GetPattern<Pattern>();
1250     CHECK_NULL_VOID(pattern);
1251     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1252         auto frameNode = weak.Upgrade();
1253         CHECK_NULL_VOID(frameNode);
1254         auto pattern = frameNode->GetPattern<Pattern>();
1255         CHECK_NULL_VOID(pattern);
1256         std::string padding = pattern->GetResCacheMapByKey("padding");
1257         CalcDimension result;
1258         if (padding.empty()) {
1259             ResourceParseUtils::ParseResDimensionVp(resObj, result);
1260             pattern->AddResCache("padding", result.ToString());
1261         } else {
1262             result = StringUtils::StringToCalcDimension(padding);
1263         }
1264         CalcLength paddingLength;
1265         if (result.Unit() == DimensionUnit::CALC) {
1266             // padding must great or equal zero.
1267             paddingLength = NG::CalcLength(result.IsNonNegative() ? result.CalcValue() : CalcDimension().CalcValue());
1268         } else {
1269             // padding must great or equal zero.
1270             paddingLength = NG::CalcLength(result.IsNonNegative() ? result : CalcDimension());
1271         }
1272         PaddingProperty paddingProperty;
1273         paddingProperty.SetEdges(paddingLength);
1274         ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Padding, paddingProperty, frameNode);
1275         if (frameNode->GetTag() == V2::TEXTAREA_ETS_TAG || frameNode->GetTag() ==V2::TEXTINPUT_ETS_TAG) {
1276             ACE_UPDATE_NODE_PAINT_PROPERTY(TextFieldPaintProperty, PaddingByUser, paddingProperty, frameNode);
1277         }
1278         frameNode->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT | PROPERTY_UPDATE_MEASURE);
1279     };
1280     updateFunc(resObj);
1281     pattern->AddResObj("padding", resObj, std::move(updateFunc));
1282 }
1283 
SetSafeAreaPadding(const CalcLength & value)1284 void ViewAbstract::SetSafeAreaPadding(const CalcLength& value)
1285 {
1286     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1287         return;
1288     }
1289     PaddingProperty padding;
1290     padding.SetEdges(value);
1291     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaPadding, padding);
1292 }
1293 
SetSafeAreaPadding(const PaddingProperty & value)1294 void ViewAbstract::SetSafeAreaPadding(const PaddingProperty& value)
1295 {
1296     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1297         return;
1298     }
1299     if (SystemProperties::ConfigChangePerform()) {
1300         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1301         CHECK_NULL_VOID(frameNode);
1302         auto pattern = frameNode->GetPattern<Pattern>();
1303         CHECK_NULL_VOID(pattern);
1304         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1305         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1306             auto frameNode = weak.Upgrade();
1307             CHECK_NULL_VOID(frameNode);
1308             PaddingProperty &padding = const_cast<PaddingProperty &>(value);
1309             padding.ReloadResources();
1310             auto layoutProperty = frameNode->GetLayoutProperty();
1311             CHECK_NULL_VOID(layoutProperty);
1312             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
1313             CheckLocalizedMarginOrPadding(padding, layoutDirection);
1314             ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaPadding, padding, frameNode);
1315             frameNode->MarkModifyDone();
1316             frameNode->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT | PROPERTY_UPDATE_MEASURE);
1317         };
1318         pattern->AddResObj("safeAreaPadding", resObj, std::move(updateFunc));
1319     }
1320     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaPadding, value);
1321 }
1322 
ResetSafeAreaPadding()1323 void ViewAbstract::ResetSafeAreaPadding()
1324 {
1325     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1326         return;
1327     }
1328     ACE_RESET_LAYOUT_PROPERTY(LayoutProperty, SafeAreaPadding);
1329 }
1330 
SetSafeAreaPadding(FrameNode * frameNode,const CalcLength & value)1331 void ViewAbstract::SetSafeAreaPadding(FrameNode* frameNode, const CalcLength& value)
1332 {
1333     CHECK_NULL_VOID(frameNode);
1334     PaddingProperty padding;
1335     padding.SetEdges(value);
1336     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaPadding, padding, frameNode);
1337 }
1338 
SetSafeAreaPadding(FrameNode * frameNode,const PaddingProperty & value)1339 void ViewAbstract::SetSafeAreaPadding(FrameNode* frameNode, const PaddingProperty& value)
1340 {
1341     CHECK_NULL_VOID(frameNode);
1342     if (SystemProperties::ConfigChangePerform()) {
1343         auto pattern = frameNode->GetPattern<Pattern>();
1344         CHECK_NULL_VOID(pattern);
1345         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1346         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1347             auto frameNode = weak.Upgrade();
1348             CHECK_NULL_VOID(frameNode);
1349             PaddingProperty &padding = const_cast<PaddingProperty &>(value);
1350             padding.ReloadResources();
1351             auto layoutProperty = frameNode->GetLayoutProperty();
1352             CHECK_NULL_VOID(layoutProperty);
1353             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
1354             CheckLocalizedMarginOrPadding(padding, layoutDirection);
1355             ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaPadding, padding, frameNode);
1356             frameNode->MarkModifyDone();
1357             frameNode->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT | PROPERTY_UPDATE_MEASURE);
1358         };
1359         pattern->AddResObj("safeAreaPadding", resObj, std::move(updateFunc));
1360     }
1361     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaPadding, value, frameNode);
1362 }
1363 
ResetSafeAreaPadding(FrameNode * frameNode)1364 void ViewAbstract::ResetSafeAreaPadding(FrameNode* frameNode)
1365 {
1366     CHECK_NULL_VOID(frameNode);
1367     ACE_RESET_NODE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaPadding, frameNode);
1368 }
1369 
SetMargin(const CalcLength & value)1370 void ViewAbstract::SetMargin(const CalcLength& value)
1371 {
1372     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1373         return;
1374     }
1375     MarginProperty margin;
1376     margin.SetEdges(value);
1377     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Margin, margin);
1378 }
1379 
SetMargin(const MarginProperty & value)1380 void ViewAbstract::SetMargin(const MarginProperty& value)
1381 {
1382     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1383         return;
1384     }
1385     if (SystemProperties::ConfigChangePerform()) {
1386         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1387         CHECK_NULL_VOID(frameNode);
1388         auto pattern = frameNode->GetPattern<Pattern>();
1389         CHECK_NULL_VOID(pattern);
1390         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1391         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1392             auto frameNode = weak.Upgrade();
1393             CHECK_NULL_VOID(frameNode);
1394             MarginProperty &margin = const_cast<MarginProperty &>(value);
1395             margin.ReloadResources();
1396             auto layoutProperty = frameNode->GetLayoutProperty();
1397             CHECK_NULL_VOID(layoutProperty);
1398             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
1399             CheckLocalizedMarginOrPadding(margin, layoutDirection);
1400             ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Margin, margin, frameNode);
1401             auto pattern = frameNode->GetPattern<Pattern>();
1402             CHECK_NULL_VOID(pattern);
1403             pattern->UpdateMarginResource();
1404             frameNode->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT | PROPERTY_UPDATE_MEASURE);
1405         };
1406         pattern->AddResObj("margin", resObj, std::move(updateFunc));
1407     }
1408     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Margin, value);
1409 }
1410 
SetMargin(const RefPtr<ResourceObject> & resObj)1411 void ViewAbstract::SetMargin(const RefPtr<ResourceObject>& resObj)
1412 {
1413     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1414         return;
1415     }
1416     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1417     CHECK_NULL_VOID(frameNode);
1418 
1419     auto pattern = frameNode->GetPattern<Pattern>();
1420     CHECK_NULL_VOID(pattern);
1421     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1422         auto frameNode = weak.Upgrade();
1423         CHECK_NULL_VOID(frameNode);
1424         auto pattern = frameNode->GetPattern<Pattern>();
1425         CHECK_NULL_VOID(pattern);
1426         std::string margin = pattern->GetResCacheMapByKey("margin");
1427         CalcDimension result;
1428         if (margin.empty()) {
1429             ResourceParseUtils::ParseResDimensionVp(resObj, result);
1430             pattern->AddResCache("margin", result.ToString());
1431         } else {
1432             result = StringUtils::StringToCalcDimension(margin);
1433         }
1434         CalcLength marginLength;
1435         if (result.Unit() == DimensionUnit::CALC) {
1436             marginLength = NG::CalcLength(result.CalcValue());
1437         } else {
1438             marginLength = NG::CalcLength(result);
1439         }
1440         MarginProperty marginProperty;
1441         marginProperty.SetEdges(marginLength);
1442         ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Margin, marginProperty, frameNode);
1443         pattern->UpdateMarginResource();
1444         frameNode->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT | PROPERTY_UPDATE_MEASURE);
1445     };
1446     updateFunc(resObj);
1447     pattern->AddResObj("margin", resObj, std::move(updateFunc));
1448 }
1449 
SetBorderRadius(const Dimension & value)1450 void ViewAbstract::SetBorderRadius(const Dimension& value)
1451 {
1452     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1453         return;
1454     }
1455     BorderRadiusProperty borderRadius;
1456     borderRadius.SetRadius(value);
1457     borderRadius.multiValued = false;
1458     ACE_UPDATE_RENDER_CONTEXT(BorderRadius, borderRadius);
1459 }
1460 
SetBorderRadius(const BorderRadiusProperty & value)1461 void ViewAbstract::SetBorderRadius(const BorderRadiusProperty& value)
1462 {
1463     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1464         return;
1465     }
1466     if (SystemProperties::ConfigChangePerform()) {
1467         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1468         CHECK_NULL_VOID(frameNode);
1469         auto pattern = frameNode->GetPattern<Pattern>();
1470         CHECK_NULL_VOID(pattern);
1471         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1472         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1473             auto frameNode = weak.Upgrade();
1474             CHECK_NULL_VOID(frameNode);
1475             BorderRadiusProperty &borderRadius = const_cast<BorderRadiusProperty &>(value);
1476             borderRadius.ReloadResources();
1477             auto layoutProperty = frameNode->GetLayoutProperty();
1478             CHECK_NULL_VOID(layoutProperty);
1479             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
1480             CheckLocalizedBorderRadiuses(borderRadius, layoutDirection);
1481             ACE_UPDATE_NODE_RENDER_CONTEXT(BorderRadius, borderRadius, frameNode);
1482             auto pattern = frameNode->GetPattern<Pattern>();
1483             CHECK_NULL_VOID(pattern);
1484             pattern->UpdateBorderResource();
1485         };
1486         pattern->AddResObj("borderRadius", resObj, std::move(updateFunc));
1487     }
1488     ACE_UPDATE_RENDER_CONTEXT(BorderRadius, value);
1489 }
1490 
SetBorderRadius(const RefPtr<ResourceObject> & resObj)1491 void ViewAbstract::SetBorderRadius(const RefPtr<ResourceObject>& resObj)
1492 {
1493     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1494         return;
1495     }
1496     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1497     CHECK_NULL_VOID(frameNode);
1498     auto pattern = frameNode->GetPattern<Pattern>();
1499     CHECK_NULL_VOID(pattern);
1500     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1501         auto frameNode = weak.Upgrade();
1502         CHECK_NULL_VOID(frameNode);
1503         auto pattern = frameNode->GetPattern<Pattern>();
1504         CHECK_NULL_VOID(pattern);
1505         std::string borderRadiusString = pattern->GetResCacheMapByKey("borderRadius");
1506         CalcDimension borderRadius;
1507         if (borderRadiusString.empty()) {
1508             ResourceParseUtils::ParseResDimensionVp(resObj, borderRadius);
1509             pattern->AddResCache("borderRadius", borderRadius.ToString());
1510         } else {
1511             borderRadius = StringUtils::StringToCalcDimension(borderRadiusString);
1512         }
1513         BorderRadiusProperty borderRadiusProperty;
1514         borderRadiusProperty.SetRadius(borderRadius);
1515         borderRadiusProperty.multiValued = false;
1516         ACE_UPDATE_NODE_RENDER_CONTEXT(BorderRadius, borderRadiusProperty, frameNode);
1517         pattern->UpdateBorderResource();
1518     };
1519     updateFunc(resObj);
1520     pattern->AddResObj("borderRadius", resObj, std::move(updateFunc));
1521 }
1522 
SetBorderColor(const Color & value)1523 void ViewAbstract::SetBorderColor(const Color& value)
1524 {
1525     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1526         return;
1527     }
1528     BorderColorProperty borderColor;
1529     borderColor.SetColor(value);
1530     ACE_UPDATE_RENDER_CONTEXT(BorderColor, borderColor);
1531 }
1532 
SetBorderColor(const BorderColorProperty & value)1533 void ViewAbstract::SetBorderColor(const BorderColorProperty& value)
1534 {
1535     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1536         return;
1537     }
1538     if (SystemProperties::ConfigChangePerform()) {
1539         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1540         CHECK_NULL_VOID(frameNode);
1541         auto pattern = frameNode->GetPattern<Pattern>();
1542         CHECK_NULL_VOID(pattern);
1543         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1544         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1545             auto frameNode = weak.Upgrade();
1546             CHECK_NULL_VOID(frameNode);
1547             BorderColorProperty &borderColor = const_cast<BorderColorProperty &>(value);
1548             borderColor.ReloadResources();
1549             auto layoutProperty = frameNode->GetLayoutProperty();
1550             CHECK_NULL_VOID(layoutProperty);
1551             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
1552             CheckLocalizedBorderColor(borderColor, layoutDirection);
1553             ACE_UPDATE_NODE_RENDER_CONTEXT(BorderColor, borderColor, frameNode);
1554             auto pattern = frameNode->GetPattern<Pattern>();
1555             CHECK_NULL_VOID(pattern);
1556             pattern->UpdateBorderResource();
1557             frameNode->MarkModifyDone();
1558         };
1559         pattern->AddResObj("borderColor", resObj, std::move(updateFunc));
1560     }
1561     ACE_UPDATE_RENDER_CONTEXT(BorderColor, value);
1562 }
1563 
SetBorderColor(const RefPtr<ResourceObject> & resObj)1564 void ViewAbstract::SetBorderColor(const RefPtr<ResourceObject>& resObj)
1565 {
1566     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1567         return;
1568     }
1569     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1570     CHECK_NULL_VOID(frameNode);
1571     auto pattern = frameNode->GetPattern<Pattern>();
1572     CHECK_NULL_VOID(pattern);
1573     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1574         auto frameNode = weak.Upgrade();
1575         CHECK_NULL_VOID(frameNode);
1576         auto pattern = frameNode->GetPattern<Pattern>();
1577         CHECK_NULL_VOID(pattern);
1578         std::string borderColorString = pattern->GetResCacheMapByKey("borderColor");
1579         Color borderColor;
1580         if (borderColorString.empty()) {
1581             ResourceParseUtils::ParseResColor(resObj, borderColor);
1582             pattern->AddResCache("borderColor", borderColor.ColorToString());
1583         } else {
1584             borderColor = Color::ColorFromString(borderColorString);
1585         }
1586         BorderColorProperty borderColorProperty;
1587         borderColorProperty.SetColor(borderColor);
1588         ACE_UPDATE_NODE_RENDER_CONTEXT(BorderColor, borderColorProperty, frameNode);
1589         pattern->UpdateBorderResource();
1590     };
1591     updateFunc(resObj);
1592     pattern->AddResObj("borderColor", resObj, std::move(updateFunc));
1593 }
1594 
SetBorderWidth(const Dimension & value)1595 void ViewAbstract::SetBorderWidth(const Dimension& value)
1596 {
1597     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1598         return;
1599     }
1600     BorderWidthProperty borderWidth;
1601     if (Negative(value.Value())) {
1602         borderWidth.SetBorderWidth(Dimension(0));
1603     } else {
1604         borderWidth.SetBorderWidth(value);
1605     }
1606     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, BorderWidth, borderWidth);
1607     ACE_UPDATE_RENDER_CONTEXT(BorderWidth, borderWidth);
1608 }
1609 
SetBorderWidth(const BorderWidthProperty & value)1610 void ViewAbstract::SetBorderWidth(const BorderWidthProperty& value)
1611 {
1612     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1613         return;
1614     }
1615     if (SystemProperties::ConfigChangePerform()) {
1616         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1617         CHECK_NULL_VOID(frameNode);
1618         auto pattern = frameNode->GetPattern<Pattern>();
1619         CHECK_NULL_VOID(pattern);
1620         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1621         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1622             auto frameNode = weak.Upgrade();
1623             CHECK_NULL_VOID(frameNode);
1624             BorderWidthProperty &borderWidth = const_cast<BorderWidthProperty &>(value);
1625             borderWidth.ReloadResources();
1626             auto layoutProperty = frameNode->GetLayoutProperty();
1627             CHECK_NULL_VOID(layoutProperty);
1628             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
1629             CheckLocalizedEdgeWidths(borderWidth, layoutDirection);
1630             ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, BorderWidth, borderWidth, frameNode);
1631             ACE_UPDATE_NODE_RENDER_CONTEXT(BorderWidth, borderWidth, frameNode);
1632             auto pattern = frameNode->GetPattern<Pattern>();
1633             CHECK_NULL_VOID(pattern);
1634             pattern->UpdateBorderResource();
1635             frameNode->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT | PROPERTY_UPDATE_MEASURE);
1636         };
1637         pattern->AddResObj("borderWidth", resObj, std::move(updateFunc));
1638     }
1639     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, BorderWidth, value);
1640     ACE_UPDATE_RENDER_CONTEXT(BorderWidth, value);
1641 }
1642 
SetBorderWidth(const RefPtr<ResourceObject> & resObj)1643 void ViewAbstract::SetBorderWidth(const RefPtr<ResourceObject>& resObj)
1644 {
1645     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1646         return;
1647     }
1648     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1649     CHECK_NULL_VOID(frameNode);
1650     auto pattern = frameNode->GetPattern<Pattern>();
1651     CHECK_NULL_VOID(pattern);
1652     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1653         auto frameNode = weak.Upgrade();
1654         CHECK_NULL_VOID(frameNode);
1655         auto pattern = frameNode->GetPattern<Pattern>();
1656         CHECK_NULL_VOID(pattern);
1657         std::string borderWidthString = pattern->GetResCacheMapByKey("borderWidth");
1658         CalcDimension borderWidth;
1659         if (borderWidthString.empty()) {
1660             ResourceParseUtils::ParseResDimensionVp(resObj, borderWidth);
1661             pattern->AddResCache("borderWidth", borderWidth.ToString());
1662         } else {
1663             borderWidth = StringUtils::StringToCalcDimension(borderWidthString);
1664         }
1665         BorderWidthProperty borderWidthProperty;
1666         if (Negative(borderWidth.Value())) {
1667             borderWidthProperty.SetBorderWidth(Dimension(0));
1668         } else {
1669             borderWidthProperty.SetBorderWidth(borderWidth);
1670         }
1671         ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, BorderWidth, borderWidthProperty, frameNode);
1672         ACE_UPDATE_NODE_RENDER_CONTEXT(BorderWidth, borderWidthProperty, frameNode);
1673         pattern->UpdateBorderResource();
1674     };
1675     updateFunc(resObj);
1676     pattern->AddResObj("borderWidth", resObj, std::move(updateFunc));
1677 }
1678 
SetBorderStyle(const BorderStyle & value)1679 void ViewAbstract::SetBorderStyle(const BorderStyle& value)
1680 {
1681     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1682         return;
1683     }
1684     BorderStyleProperty borderStyle;
1685     borderStyle.SetBorderStyle(value);
1686     ACE_UPDATE_RENDER_CONTEXT(BorderStyle, borderStyle);
1687 }
1688 
SetBorderStyle(FrameNode * frameNode,const BorderStyle & value)1689 void ViewAbstract::SetBorderStyle(FrameNode* frameNode, const BorderStyle& value)
1690 {
1691     BorderStyleProperty borderStyle;
1692     borderStyle.SetBorderStyle(value);
1693     ACE_UPDATE_NODE_RENDER_CONTEXT(BorderStyle, borderStyle, frameNode);
1694 }
1695 
SetBorderStyle(const BorderStyleProperty & value)1696 void ViewAbstract::SetBorderStyle(const BorderStyleProperty& value)
1697 {
1698     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1699         return;
1700     }
1701     ACE_UPDATE_RENDER_CONTEXT(BorderStyle, value);
1702 }
1703 
SetBorderStyle(FrameNode * frameNode,const BorderStyleProperty & value)1704 void ViewAbstract::SetBorderStyle(FrameNode* frameNode, const BorderStyleProperty& value)
1705 {
1706     ACE_UPDATE_NODE_RENDER_CONTEXT(BorderStyle, value, frameNode);
1707 }
1708 
SetDashGap(const Dimension & value)1709 void ViewAbstract::SetDashGap(const Dimension& value)
1710 {
1711     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1712         return;
1713     }
1714     BorderWidthProperty dashGap;
1715     dashGap.SetBorderWidth(value);
1716 
1717     ACE_UPDATE_RENDER_CONTEXT(DashGap, dashGap);
1718 }
1719 
SetDashGap(FrameNode * frameNode,const Dimension & value)1720 void ViewAbstract::SetDashGap(FrameNode *frameNode, const Dimension& value)
1721 {
1722     BorderWidthProperty dashGap;
1723     dashGap.SetBorderWidth(value);
1724 
1725     ACE_UPDATE_NODE_RENDER_CONTEXT(DashGap, dashGap, frameNode);
1726 }
1727 
SetDashGap(const BorderWidthProperty & value)1728 void ViewAbstract::SetDashGap(const BorderWidthProperty& value)
1729 {
1730     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1731         return;
1732     }
1733     if (SystemProperties::ConfigChangePerform()) {
1734         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1735         CHECK_NULL_VOID(frameNode);
1736         auto pattern = frameNode->GetPattern<Pattern>();
1737         CHECK_NULL_VOID(pattern);
1738         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1739         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1740             auto frameNode = weak.Upgrade();
1741             CHECK_NULL_VOID(frameNode);
1742             BorderWidthProperty &dashGap = const_cast<BorderWidthProperty &>(value);
1743             dashGap.ReloadResources();
1744             auto layoutProperty = frameNode->GetLayoutProperty();
1745             CHECK_NULL_VOID(layoutProperty);
1746             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
1747             CheckLocalizedEdgeWidths(dashGap, layoutDirection);
1748             ACE_UPDATE_NODE_RENDER_CONTEXT(DashGap, dashGap, frameNode);
1749         };
1750         pattern->AddResObj("border.dashGap", resObj, std::move(updateFunc));
1751     }
1752     ACE_UPDATE_RENDER_CONTEXT(DashGap, value);
1753 }
1754 
SetDashGap(FrameNode * frameNode,const BorderWidthProperty & value)1755 void ViewAbstract::SetDashGap(FrameNode *frameNode, const BorderWidthProperty& value)
1756 {
1757     CHECK_NULL_VOID(frameNode);
1758     if (SystemProperties::ConfigChangePerform()) {
1759         auto pattern = frameNode->GetPattern<Pattern>();
1760         CHECK_NULL_VOID(pattern);
1761         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1762         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1763             auto frameNode = weak.Upgrade();
1764             CHECK_NULL_VOID(frameNode);
1765             BorderWidthProperty &dashGap = const_cast<BorderWidthProperty &>(value);
1766             dashGap.ReloadResources();
1767             auto layoutProperty = frameNode->GetLayoutProperty();
1768             CHECK_NULL_VOID(layoutProperty);
1769             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
1770             CheckLocalizedEdgeWidths(dashGap, layoutDirection);
1771             ACE_UPDATE_NODE_RENDER_CONTEXT(DashGap, dashGap, frameNode);
1772         };
1773         pattern->AddResObj("border.dashGap", resObj, std::move(updateFunc));
1774     }
1775     ACE_UPDATE_NODE_RENDER_CONTEXT(DashGap, value, frameNode);
1776 }
1777 
SetDashWidth(const Dimension & value)1778 void ViewAbstract::SetDashWidth(const Dimension& value)
1779 {
1780     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1781         return;
1782     }
1783     BorderWidthProperty dashWidth;
1784     dashWidth.SetBorderWidth(value);
1785 
1786     ACE_UPDATE_RENDER_CONTEXT(DashWidth, dashWidth);
1787 }
1788 
SetDashWidth(FrameNode * frameNode,const Dimension & value)1789 void ViewAbstract::SetDashWidth(FrameNode *frameNode, const Dimension& value)
1790 {
1791     BorderWidthProperty dashWidth;
1792     dashWidth.SetBorderWidth(value);
1793 
1794     ACE_UPDATE_NODE_RENDER_CONTEXT(DashWidth, dashWidth, frameNode);
1795 }
1796 
SetDashWidth(const BorderWidthProperty & value)1797 void ViewAbstract::SetDashWidth(const BorderWidthProperty& value)
1798 {
1799     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1800         return;
1801     }
1802     if (SystemProperties::ConfigChangePerform()) {
1803         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1804         CHECK_NULL_VOID(frameNode);
1805         auto pattern = frameNode->GetPattern<Pattern>();
1806         CHECK_NULL_VOID(pattern);
1807         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1808         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1809             auto frameNode = weak.Upgrade();
1810             CHECK_NULL_VOID(frameNode);
1811             BorderWidthProperty &dashWidth = const_cast<BorderWidthProperty &>(value);
1812             dashWidth.ReloadResources();
1813             auto layoutProperty = frameNode->GetLayoutProperty();
1814             CHECK_NULL_VOID(layoutProperty);
1815             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
1816             CheckLocalizedEdgeWidths(dashWidth, layoutDirection);
1817             ACE_UPDATE_NODE_RENDER_CONTEXT(DashWidth, dashWidth, frameNode);
1818         };
1819         pattern->AddResObj("border.dashWidth", resObj, std::move(updateFunc));
1820     }
1821     ACE_UPDATE_RENDER_CONTEXT(DashWidth, value);
1822 }
1823 
SetDashWidth(FrameNode * frameNode,const BorderWidthProperty & value)1824 void ViewAbstract::SetDashWidth(FrameNode *frameNode, const BorderWidthProperty& value)
1825 {
1826     CHECK_NULL_VOID(frameNode);
1827     if (SystemProperties::ConfigChangePerform()) {
1828         auto pattern = frameNode->GetPattern<Pattern>();
1829         CHECK_NULL_VOID(pattern);
1830         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1831         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1832             auto frameNode = weak.Upgrade();
1833             CHECK_NULL_VOID(frameNode);
1834             BorderWidthProperty &dashWidth = const_cast<BorderWidthProperty &>(value);
1835             dashWidth.ReloadResources();
1836             auto layoutProperty = frameNode->GetLayoutProperty();
1837             CHECK_NULL_VOID(layoutProperty);
1838             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
1839             CheckLocalizedEdgeWidths(dashWidth, layoutDirection);
1840             ACE_UPDATE_NODE_RENDER_CONTEXT(DashWidth, dashWidth, frameNode);
1841         };
1842         pattern->AddResObj("border.dashWidth", resObj, std::move(updateFunc));
1843     }
1844     ACE_UPDATE_NODE_RENDER_CONTEXT(DashWidth, value, frameNode);
1845 }
1846 
SetOuterBorderRadius(const Dimension & value)1847 void ViewAbstract::SetOuterBorderRadius(const Dimension& value)
1848 {
1849     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1850         return;
1851     }
1852     BorderRadiusProperty borderRadius;
1853     borderRadius.SetRadius(value);
1854     borderRadius.multiValued = false;
1855     ACE_UPDATE_RENDER_CONTEXT(OuterBorderRadius, borderRadius);
1856 }
1857 
SetOuterBorderRadius(FrameNode * frameNode,const Dimension & value)1858 void ViewAbstract::SetOuterBorderRadius(FrameNode* frameNode, const Dimension& value)
1859 {
1860     BorderRadiusProperty borderRadius;
1861     borderRadius.SetRadius(value);
1862     borderRadius.multiValued = false;
1863     ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderRadius, borderRadius, frameNode);
1864 }
1865 
SetOuterBorderRadius(const BorderRadiusProperty & value)1866 void ViewAbstract::SetOuterBorderRadius(const BorderRadiusProperty& value)
1867 {
1868     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1869         return;
1870     }
1871     if (SystemProperties::ConfigChangePerform()) {
1872         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1873         CHECK_NULL_VOID(frameNode);
1874         auto pattern = frameNode->GetPattern();
1875         CHECK_NULL_VOID(pattern);
1876         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1877         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1878             auto frameNode = weak.Upgrade();
1879             CHECK_NULL_VOID(frameNode);
1880             BorderRadiusProperty& outerBorderRadius = const_cast<BorderRadiusProperty &>(value);
1881             outerBorderRadius.ReloadResources();
1882             ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderRadius, outerBorderRadius, frameNode);
1883             frameNode->MarkModifyDone();
1884             frameNode->MarkDirtyNode();
1885         };
1886         pattern->AddResObj("outerBorderRadius", resObj, std::move(updateFunc));
1887     }
1888     ACE_UPDATE_RENDER_CONTEXT(OuterBorderRadius, value);
1889 }
1890 
SetOuterBorderRadius(FrameNode * frameNode,const BorderRadiusProperty & value)1891 void ViewAbstract::SetOuterBorderRadius(FrameNode* frameNode, const BorderRadiusProperty& value)
1892 {
1893     if (SystemProperties::ConfigChangePerform()) {
1894         CHECK_NULL_VOID(frameNode);
1895         auto pattern = frameNode->GetPattern();
1896         CHECK_NULL_VOID(pattern);
1897         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1898         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1899             auto frameNode = weak.Upgrade();
1900             CHECK_NULL_VOID(frameNode);
1901             BorderRadiusProperty& outerBorderRadius = const_cast<BorderRadiusProperty &>(value);
1902             outerBorderRadius.ReloadResources();
1903             ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderRadius, outerBorderRadius, frameNode);
1904             frameNode->MarkModifyDone();
1905             frameNode->MarkDirtyNode();
1906         };
1907         pattern->AddResObj("outerBorderRadius", resObj, std::move(updateFunc));
1908     }
1909     ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderRadius, value, frameNode);
1910 }
1911 
SetOuterBorderColor(const Color & value)1912 void ViewAbstract::SetOuterBorderColor(const Color& value)
1913 {
1914     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1915         return;
1916     }
1917     BorderColorProperty borderColor;
1918     borderColor.SetColor(value);
1919     ACE_UPDATE_RENDER_CONTEXT(OuterBorderColor, borderColor);
1920 }
1921 
SetOuterBorderColor(FrameNode * frameNode,const Color & value)1922 void ViewAbstract::SetOuterBorderColor(FrameNode* frameNode, const Color& value)
1923 {
1924     BorderColorProperty borderColor;
1925     borderColor.SetColor(value);
1926     ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderColor, borderColor, frameNode);
1927 }
1928 
SetOuterBorderColor(const BorderColorProperty & value)1929 void ViewAbstract::SetOuterBorderColor(const BorderColorProperty& value)
1930 {
1931     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1932         return;
1933     }
1934     if (SystemProperties::ConfigChangePerform()) {
1935         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1936         CHECK_NULL_VOID(frameNode);
1937         auto pattern = frameNode->GetPattern();
1938         CHECK_NULL_VOID(pattern);
1939         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1940         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1941             auto frameNode = weak.Upgrade();
1942             CHECK_NULL_VOID(frameNode);
1943             BorderColorProperty& outerBorderColor = const_cast<BorderColorProperty &>(value);
1944             outerBorderColor.ReloadResources();
1945             ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderColor, outerBorderColor, frameNode);
1946         };
1947         pattern->AddResObj("outerBorderColor", resObj, std::move(updateFunc));
1948     }
1949     ACE_UPDATE_RENDER_CONTEXT(OuterBorderColor, value);
1950 }
1951 
SetOuterBorderColor(FrameNode * frameNode,const BorderColorProperty & value)1952 void ViewAbstract::SetOuterBorderColor(FrameNode* frameNode, const BorderColorProperty& value)
1953 {
1954     if (SystemProperties::ConfigChangePerform()) {
1955         CHECK_NULL_VOID(frameNode);
1956         auto pattern = frameNode->GetPattern();
1957         CHECK_NULL_VOID(pattern);
1958         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
1959         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
1960             auto frameNode = weak.Upgrade();
1961             CHECK_NULL_VOID(frameNode);
1962             BorderColorProperty& outerBorderColor = const_cast<BorderColorProperty &>(value);
1963             outerBorderColor.ReloadResources();
1964             ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderColor, outerBorderColor, frameNode);
1965         };
1966         pattern->AddResObj("outerBorderColor", resObj, std::move(updateFunc));
1967     }
1968     ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderColor, value, frameNode);
1969 }
1970 
SetOuterBorderWidth(const Dimension & value)1971 void ViewAbstract::SetOuterBorderWidth(const Dimension& value)
1972 {
1973     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1974         return;
1975     }
1976     BorderWidthProperty borderWidth;
1977     if (Negative(value.Value())) {
1978         borderWidth.SetBorderWidth(Dimension(0));
1979     } else {
1980         borderWidth.SetBorderWidth(value);
1981     }
1982     ACE_UPDATE_RENDER_CONTEXT(OuterBorderWidth, borderWidth);
1983 }
1984 
SetOuterBorderWidth(FrameNode * frameNode,const Dimension & value)1985 void ViewAbstract::SetOuterBorderWidth(FrameNode* frameNode, const Dimension& value)
1986 {
1987     BorderWidthProperty borderWidth;
1988     if (Negative(value.Value())) {
1989         borderWidth.SetBorderWidth(Dimension(0));
1990     } else {
1991         borderWidth.SetBorderWidth(value);
1992     }
1993     ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderWidth, borderWidth, frameNode);
1994 }
1995 
SetOuterBorderWidth(const BorderWidthProperty & value)1996 void ViewAbstract::SetOuterBorderWidth(const BorderWidthProperty& value)
1997 {
1998     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1999         return;
2000     }
2001     if (SystemProperties::ConfigChangePerform()) {
2002         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2003         CHECK_NULL_VOID(frameNode);
2004         auto pattern = frameNode->GetPattern();
2005         CHECK_NULL_VOID(pattern);
2006         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
2007         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
2008             auto frameNode = weak.Upgrade();
2009             CHECK_NULL_VOID(frameNode);
2010             BorderWidthProperty& outerBorderWidth = const_cast<BorderWidthProperty &>(value);
2011             outerBorderWidth.ReloadResources();
2012             ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderWidth, outerBorderWidth, frameNode);
2013             frameNode->MarkModifyDone();
2014             frameNode->MarkDirtyNode();
2015         };
2016         pattern->AddResObj("outerBorderWidth", resObj, std::move(updateFunc));
2017     }
2018     ACE_UPDATE_RENDER_CONTEXT(OuterBorderWidth, value);
2019 }
2020 
SetOuterBorderWidth(FrameNode * frameNode,const BorderWidthProperty & value)2021 void ViewAbstract::SetOuterBorderWidth(FrameNode* frameNode, const BorderWidthProperty& value)
2022 {
2023     if (SystemProperties::ConfigChangePerform()) {
2024         CHECK_NULL_VOID(frameNode);
2025         auto pattern = frameNode->GetPattern();
2026         CHECK_NULL_VOID(pattern);
2027         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
2028         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
2029             auto frameNode = weak.Upgrade();
2030             CHECK_NULL_VOID(frameNode);
2031             BorderWidthProperty& outerBorderWidth = const_cast<BorderWidthProperty &>(value);
2032             outerBorderWidth.ReloadResources();
2033             ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderWidth, outerBorderWidth, frameNode);
2034             frameNode->MarkModifyDone();
2035             frameNode->MarkDirtyNode();
2036         };
2037         pattern->AddResObj("outerBorderWidth", resObj, std::move(updateFunc));
2038     }
2039     ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderWidth, value, frameNode);
2040 }
2041 
SetOuterBorderStyle(const BorderStyleProperty & value)2042 void ViewAbstract::SetOuterBorderStyle(const BorderStyleProperty& value)
2043 {
2044     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2045         return;
2046     }
2047     ACE_UPDATE_RENDER_CONTEXT(OuterBorderStyle, value);
2048 }
2049 
SetOuterBorderStyle(FrameNode * frameNode,const BorderStyleProperty & value)2050 void ViewAbstract::SetOuterBorderStyle(FrameNode* frameNode, const BorderStyleProperty& value)
2051 {
2052     ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderStyle, value, frameNode);
2053 }
2054 
SetOuterBorderStyle(const BorderStyle & value)2055 void ViewAbstract::SetOuterBorderStyle(const BorderStyle& value)
2056 {
2057     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2058         return;
2059     }
2060     BorderStyleProperty borderStyle;
2061     borderStyle.SetBorderStyle(value);
2062     ACE_UPDATE_RENDER_CONTEXT(OuterBorderStyle, borderStyle);
2063 }
2064 
SetOuterBorderStyle(FrameNode * frameNode,const BorderStyle & value)2065 void ViewAbstract::SetOuterBorderStyle(FrameNode* frameNode, const BorderStyle& value)
2066 {
2067     BorderStyleProperty borderStyle;
2068     borderStyle.SetBorderStyle(value);
2069     ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderStyle, borderStyle, frameNode);
2070 }
2071 
DisableOnClick()2072 void ViewAbstract::DisableOnClick()
2073 {
2074     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2075     CHECK_NULL_VOID(gestureHub);
2076     gestureHub->ClearUserOnClick();
2077 }
2078 
DisableOnTouch()2079 void ViewAbstract::DisableOnTouch()
2080 {
2081     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2082     CHECK_NULL_VOID(gestureHub);
2083     gestureHub->ClearUserOnTouch();
2084 }
2085 
DisableOnKeyEvent()2086 void ViewAbstract::DisableOnKeyEvent()
2087 {
2088     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2089     CHECK_NULL_VOID(focusHub);
2090     focusHub->ClearOnKeyCallback();
2091 }
2092 
DisableOnKeyEventDispatch()2093 void ViewAbstract::DisableOnKeyEventDispatch()
2094 {
2095     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2096     CHECK_NULL_VOID(focusHub);
2097     focusHub->ClearOnKeyEventDispatchCallback();
2098 }
2099 
2100 #ifdef SUPPORT_DIGITAL_CROWN
DisableOnCrownEvent()2101 void ViewAbstract::DisableOnCrownEvent()
2102 {
2103     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2104     CHECK_NULL_VOID(focusHub);
2105     focusHub->ClearOnCrownCallback();
2106 }
2107 
DisableOnCrownEvent(FrameNode * frameNode)2108 void ViewAbstract::DisableOnCrownEvent(FrameNode* frameNode)
2109 {
2110     auto focusHub = frameNode->GetOrCreateFocusHub();
2111     CHECK_NULL_VOID(focusHub);
2112     focusHub->ClearOnCrownCallback();
2113 }
2114 
SetOnCrownEvent(OnCrownCallbackFunc && onCrownCallback)2115 void ViewAbstract::SetOnCrownEvent(OnCrownCallbackFunc &&onCrownCallback)
2116 {
2117     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2118     CHECK_NULL_VOID(focusHub);
2119     focusHub->SetOnCrownCallback(std::move(onCrownCallback));
2120 }
2121 
SetOnCrownEvent(FrameNode * frameNode,OnCrownCallbackFunc && onCrownCallback)2122 void ViewAbstract::SetOnCrownEvent(FrameNode* frameNode, OnCrownCallbackFunc &&onCrownCallback)
2123 {
2124     CHECK_NULL_VOID(frameNode);
2125     auto focusHub = frameNode->GetOrCreateFocusHub();
2126     focusHub->SetOnCrownCallback(std::move(onCrownCallback));
2127 }
2128 #endif
2129 
DisableOnHover()2130 void ViewAbstract::DisableOnHover()
2131 {
2132     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
2133     CHECK_NULL_VOID(eventHub);
2134     eventHub->ClearUserOnHover();
2135 }
2136 
DisableOnHoverMove()2137 void ViewAbstract::DisableOnHoverMove()
2138 {
2139     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
2140     CHECK_NULL_VOID(eventHub);
2141     eventHub->ClearUserOnHoverMove();
2142 }
2143 
DisableOnAccessibilityHover()2144 void ViewAbstract::DisableOnAccessibilityHover()
2145 {
2146     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
2147     CHECK_NULL_VOID(eventHub);
2148     eventHub->ClearUserOnAccessibilityHover();
2149 }
2150 
DisableOnMouse()2151 void ViewAbstract::DisableOnMouse()
2152 {
2153     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
2154     CHECK_NULL_VOID(eventHub);
2155     eventHub->ClearUserOnMouse();
2156 }
2157 
DisableOnAxisEvent()2158 void ViewAbstract::DisableOnAxisEvent()
2159 {
2160     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
2161     CHECK_NULL_VOID(eventHub);
2162     eventHub->ClearUserOnAxisEvent();
2163 }
2164 
DisableOnAppear()2165 void ViewAbstract::DisableOnAppear()
2166 {
2167     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2168     CHECK_NULL_VOID(eventHub);
2169     eventHub->ClearUserOnAppear();
2170 }
2171 
DisableOnDisAppear()2172 void ViewAbstract::DisableOnDisAppear()
2173 {
2174     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2175     CHECK_NULL_VOID(eventHub);
2176     eventHub->ClearUserOnDisAppear();
2177 }
2178 
DisableOnAttach()2179 void ViewAbstract::DisableOnAttach()
2180 {
2181     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2182     CHECK_NULL_VOID(eventHub);
2183     eventHub->ClearOnAttach();
2184 }
2185 
DisableOnDetach()2186 void ViewAbstract::DisableOnDetach()
2187 {
2188     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2189     CHECK_NULL_VOID(eventHub);
2190     eventHub->ClearOnDetach();
2191 }
2192 
DisableOnAreaChange()2193 void ViewAbstract::DisableOnAreaChange()
2194 {
2195     auto pipeline = PipelineContext::GetCurrentContext();
2196     CHECK_NULL_VOID(pipeline);
2197     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2198     CHECK_NULL_VOID(frameNode);
2199     frameNode->ClearUserOnAreaChange();
2200 }
2201 
DisableOnFocus()2202 void ViewAbstract::DisableOnFocus()
2203 {
2204     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2205     CHECK_NULL_VOID(focusHub);
2206     focusHub->ClearOnFocusCallback();
2207 }
2208 
DisableOnBlur()2209 void ViewAbstract::DisableOnBlur()
2210 {
2211     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2212     CHECK_NULL_VOID(focusHub);
2213     focusHub->ClearOnBlurCallback();
2214 }
2215 
DisableOnFocusAxisEvent()2216 void ViewAbstract::DisableOnFocusAxisEvent()
2217 {
2218     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2219     CHECK_NULL_VOID(focusHub);
2220     focusHub->ClearOnFocusAxisCallback();
2221 }
2222 
DisableOnFocusAxisEvent(FrameNode * frameNode)2223 void ViewAbstract::DisableOnFocusAxisEvent(FrameNode* frameNode)
2224 {
2225     auto focusHub = frameNode->GetOrCreateFocusHub();
2226     CHECK_NULL_VOID(focusHub);
2227     focusHub->ClearOnFocusAxisCallback();
2228 }
2229 
DisableOnClick(FrameNode * frameNode)2230 void ViewAbstract::DisableOnClick(FrameNode* frameNode)
2231 {
2232     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
2233     CHECK_NULL_VOID(gestureHub);
2234     gestureHub->ClearUserOnClick();
2235     auto* uiNode = reinterpret_cast<UINode*>(frameNode);
2236     CHECK_NULL_VOID(uiNode);
2237     uiNode->SetModifierEventRegistrationState(uiNode->IsCNode(), false);
2238 }
2239 
DisableOnDragStart(FrameNode * frameNode)2240 void ViewAbstract::DisableOnDragStart(FrameNode* frameNode)
2241 {
2242     CHECK_NULL_VOID(frameNode);
2243     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2244     CHECK_NULL_VOID(eventHub);
2245     eventHub->ClearCustomerOnDragStart();
2246 }
2247 
DisableOnDragEnter(FrameNode * frameNode)2248 void ViewAbstract::DisableOnDragEnter(FrameNode* frameNode)
2249 {
2250     CHECK_NULL_VOID(frameNode);
2251     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2252     CHECK_NULL_VOID(eventHub);
2253     eventHub->ClearCustomerOnDragEnter();
2254 }
2255 
DisableOnDragSpringLoading(FrameNode * frameNode)2256 void ViewAbstract::DisableOnDragSpringLoading(FrameNode* frameNode)
2257 {
2258     CHECK_NULL_VOID(frameNode);
2259     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2260     CHECK_NULL_VOID(eventHub);
2261     eventHub->ClearCustomerOnDragSpringLoading();
2262     auto relatedConfigurations = frameNode->GetOrCreateDragDropRelatedConfigurations();
2263     CHECK_NULL_VOID(relatedConfigurations);
2264     relatedConfigurations->SetDragSpringLoadingConfiguration(nullptr);
2265 }
2266 
DisableOnDragMove(FrameNode * frameNode)2267 void ViewAbstract::DisableOnDragMove(FrameNode* frameNode)
2268 {
2269     CHECK_NULL_VOID(frameNode);
2270     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2271     CHECK_NULL_VOID(eventHub);
2272     eventHub->ClearCustomerOnDragMove();
2273 }
2274 
DisableOnDragLeave(FrameNode * frameNode)2275 void ViewAbstract::DisableOnDragLeave(FrameNode* frameNode)
2276 {
2277     CHECK_NULL_VOID(frameNode);
2278     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2279     CHECK_NULL_VOID(eventHub);
2280     eventHub->ClearCustomerOnDragLeave();
2281 }
2282 
DisableOnDrop(FrameNode * frameNode)2283 void ViewAbstract::DisableOnDrop(FrameNode* frameNode)
2284 {
2285     CHECK_NULL_VOID(frameNode);
2286     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2287     CHECK_NULL_VOID(eventHub);
2288     eventHub->ClearCustomerOnDrop();
2289 }
2290 
DisableOnDragEnd(FrameNode * frameNode)2291 void ViewAbstract::DisableOnDragEnd(FrameNode* frameNode)
2292 {
2293     CHECK_NULL_VOID(frameNode);
2294     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2295     CHECK_NULL_VOID(eventHub);
2296     eventHub->ClearCustomerOnDragEnd();
2297 }
2298 
DisableOnTouch(FrameNode * frameNode)2299 void ViewAbstract::DisableOnTouch(FrameNode* frameNode)
2300 {
2301     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
2302     CHECK_NULL_VOID(gestureHub);
2303     gestureHub->ClearUserOnTouch();
2304 }
2305 
DisableOnKeyEvent(FrameNode * frameNode)2306 void ViewAbstract::DisableOnKeyEvent(FrameNode* frameNode)
2307 {
2308     auto focusHub = frameNode->GetOrCreateFocusHub();
2309     CHECK_NULL_VOID(focusHub);
2310     focusHub->ClearOnKeyCallback();
2311 }
2312 
DisableOnKeyEventDispatch(FrameNode * frameNode)2313 void ViewAbstract::DisableOnKeyEventDispatch(FrameNode* frameNode)
2314 {
2315     auto focusHub = frameNode->GetOrCreateFocusHub();
2316     CHECK_NULL_VOID(focusHub);
2317     focusHub->ClearOnKeyEventDispatchCallback();
2318 }
2319 
DisableOnHover(FrameNode * frameNode)2320 void ViewAbstract::DisableOnHover(FrameNode* frameNode)
2321 {
2322     auto eventHub = frameNode->GetOrCreateInputEventHub();
2323     CHECK_NULL_VOID(eventHub);
2324     eventHub->ClearUserOnHover();
2325 }
2326 
DisableOnHoverMove(FrameNode * frameNode)2327 void ViewAbstract::DisableOnHoverMove(FrameNode* frameNode)
2328 {
2329     auto eventHub = frameNode->GetOrCreateInputEventHub();
2330     CHECK_NULL_VOID(eventHub);
2331     eventHub->ClearUserOnHoverMove();
2332 }
2333 
DisableOnAccessibilityHover(FrameNode * frameNode)2334 void ViewAbstract::DisableOnAccessibilityHover(FrameNode* frameNode)
2335 {
2336     CHECK_NULL_VOID(frameNode);
2337     auto eventHub = frameNode->GetOrCreateInputEventHub();
2338     CHECK_NULL_VOID(eventHub);
2339     eventHub->ClearUserOnAccessibilityHover();
2340 }
2341 
DisableOnMouse(FrameNode * frameNode)2342 void ViewAbstract::DisableOnMouse(FrameNode* frameNode)
2343 {
2344     auto eventHub = frameNode->GetOrCreateInputEventHub();
2345     CHECK_NULL_VOID(eventHub);
2346     eventHub->ClearUserOnMouse();
2347 }
2348 
DisableOnAxisEvent(FrameNode * frameNode)2349 void ViewAbstract::DisableOnAxisEvent(FrameNode* frameNode)
2350 {
2351     auto eventHub = frameNode->GetOrCreateInputEventHub();
2352     CHECK_NULL_VOID(eventHub);
2353     eventHub->ClearUserOnAxisEvent();
2354 }
2355 
DisableOnAppear(FrameNode * frameNode)2356 void ViewAbstract::DisableOnAppear(FrameNode* frameNode)
2357 {
2358     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2359     CHECK_NULL_VOID(eventHub);
2360     eventHub->ClearUserOnAppear();
2361 }
2362 
DisableOnDisappear(FrameNode * frameNode)2363 void ViewAbstract::DisableOnDisappear(FrameNode* frameNode)
2364 {
2365     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2366     CHECK_NULL_VOID(eventHub);
2367     eventHub->ClearUserOnDisAppear();
2368 }
2369 
DisableOnAttach(FrameNode * frameNode)2370 void ViewAbstract::DisableOnAttach(FrameNode* frameNode)
2371 {
2372     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2373     CHECK_NULL_VOID(eventHub);
2374     eventHub->ClearOnAttach();
2375 }
2376 
DisableOnDetach(FrameNode * frameNode)2377 void ViewAbstract::DisableOnDetach(FrameNode* frameNode)
2378 {
2379     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2380     CHECK_NULL_VOID(eventHub);
2381     eventHub->ClearOnDetach();
2382 }
2383 
DisableOnPreDrag(FrameNode * frameNode)2384 void ViewAbstract::DisableOnPreDrag(FrameNode* frameNode)
2385 {
2386     CHECK_NULL_VOID(frameNode);
2387     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2388     CHECK_NULL_VOID(eventHub);
2389     eventHub->ClearOnPreDrag();
2390 }
2391 
DisableOnFocus(FrameNode * frameNode)2392 void ViewAbstract::DisableOnFocus(FrameNode* frameNode)
2393 {
2394     auto focusHub = frameNode->GetOrCreateFocusHub();
2395     CHECK_NULL_VOID(focusHub);
2396     focusHub->ClearOnFocusCallback();
2397 }
2398 
DisableOnBlur(FrameNode * frameNode)2399 void ViewAbstract::DisableOnBlur(FrameNode* frameNode)
2400 {
2401     auto focusHub = frameNode->GetOrCreateFocusHub();
2402     CHECK_NULL_VOID(focusHub);
2403     focusHub->ClearOnBlurCallback();
2404 }
2405 
DisableOnAreaChange(FrameNode * frameNode)2406 void ViewAbstract::DisableOnAreaChange(FrameNode* frameNode)
2407 {
2408     CHECK_NULL_VOID(frameNode);
2409     frameNode->ClearUserOnAreaChange();
2410 }
2411 
SetOnClick(GestureEventFunc && clickEventFunc,double distanceThreshold)2412 void ViewAbstract::SetOnClick(GestureEventFunc&& clickEventFunc, double distanceThreshold)
2413 {
2414     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2415     CHECK_NULL_VOID(frameNode);
2416     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
2417     CHECK_NULL_VOID(gestureHub);
2418     gestureHub->SetUserOnClick(std::move(clickEventFunc), distanceThreshold);
2419 
2420     auto focusHub = frameNode->GetOrCreateFocusHub();
2421     CHECK_NULL_VOID(focusHub);
2422     focusHub->SetFocusable(true, false);
2423 
2424     auto* uiNode = reinterpret_cast<UINode*>(frameNode);
2425     CHECK_NULL_VOID(uiNode);
2426     uiNode->SetModifierEventRegistrationState(uiNode->IsCNode(), true);
2427 }
2428 
SetOnClick(GestureEventFunc && clickEventFunc,Dimension distanceThreshold)2429 void ViewAbstract::SetOnClick(GestureEventFunc&& clickEventFunc, Dimension distanceThreshold)
2430 {
2431     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2432     CHECK_NULL_VOID(frameNode);
2433     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
2434     CHECK_NULL_VOID(gestureHub);
2435     gestureHub->SetUserOnClick(std::move(clickEventFunc), distanceThreshold);
2436 
2437     auto focusHub = frameNode->GetOrCreateFocusHub();
2438     CHECK_NULL_VOID(focusHub);
2439     focusHub->SetFocusable(true, false);
2440 
2441     auto* uiNode = reinterpret_cast<UINode*>(frameNode);
2442     CHECK_NULL_VOID(uiNode);
2443     uiNode->SetModifierEventRegistrationState(uiNode->IsCNode(), true);
2444 }
2445 
SetOnGestureJudgeBegin(GestureJudgeFunc && gestureJudgeFunc)2446 void ViewAbstract::SetOnGestureJudgeBegin(GestureJudgeFunc&& gestureJudgeFunc)
2447 {
2448     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2449     CHECK_NULL_VOID(gestureHub);
2450     gestureHub->SetOnGestureJudgeBegin(std::move(gestureJudgeFunc));
2451 }
2452 
SetOnTouchIntercept(TouchInterceptFunc && touchInterceptFunc)2453 void ViewAbstract::SetOnTouchIntercept(TouchInterceptFunc&& touchInterceptFunc)
2454 {
2455     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2456     CHECK_NULL_VOID(gestureHub);
2457     gestureHub->SetOnTouchIntercept(std::move(touchInterceptFunc));
2458 }
2459 
SetShouldBuiltInRecognizerParallelWith(NG::ShouldBuiltInRecognizerParallelWithFunc && shouldBuiltInRecognizerParallelWithFunc)2460 void ViewAbstract::SetShouldBuiltInRecognizerParallelWith(
2461     NG::ShouldBuiltInRecognizerParallelWithFunc&& shouldBuiltInRecognizerParallelWithFunc)
2462 {
2463     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2464     CHECK_NULL_VOID(gestureHub);
2465     gestureHub->SetShouldBuildinRecognizerParallelWithFunc(std::move(shouldBuiltInRecognizerParallelWithFunc));
2466 }
2467 
SetOnGestureRecognizerJudgeBegin(GestureRecognizerJudgeFunc && gestureRecognizerJudgeFunc,bool exposeInnerGestureFlag)2468 void ViewAbstract::SetOnGestureRecognizerJudgeBegin(
2469     GestureRecognizerJudgeFunc&& gestureRecognizerJudgeFunc, bool exposeInnerGestureFlag)
2470 {
2471     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2472     CHECK_NULL_VOID(frameNode);
2473     frameNode->SetExposeInnerGestureFlag(exposeInnerGestureFlag);
2474 
2475     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2476     CHECK_NULL_VOID(gestureHub);
2477     gestureHub->SetOnGestureRecognizerJudgeBegin(std::move(gestureRecognizerJudgeFunc));
2478 }
2479 
SetOnTouchTestDone(NG::TouchTestDoneCallback && touchTestDoneCallback)2480 void ViewAbstract::SetOnTouchTestDone(NG::TouchTestDoneCallback&& touchTestDoneCallback)
2481 {
2482     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2483     CHECK_NULL_VOID(frameNode);
2484     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2485     CHECK_NULL_VOID(gestureHub);
2486     gestureHub->SetOnTouchTestDoneCallback(std::move(touchTestDoneCallback));
2487 }
2488 
SetOnTouchTestDone(FrameNode * frameNode,NG::TouchTestDoneCallback && touchTestDoneCallback)2489 void ViewAbstract::SetOnTouchTestDone(FrameNode* frameNode, NG::TouchTestDoneCallback&& touchTestDoneCallback)
2490 {
2491     CHECK_NULL_VOID(frameNode);
2492     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
2493     CHECK_NULL_VOID(gestureHub);
2494     gestureHub->SetOnTouchTestDoneCallback(std::move(touchTestDoneCallback));
2495 }
2496 
SetOnTouch(TouchEventFunc && touchEventFunc)2497 void ViewAbstract::SetOnTouch(TouchEventFunc&& touchEventFunc)
2498 {
2499     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2500     CHECK_NULL_VOID(gestureHub);
2501     gestureHub->SetTouchEvent(std::move(touchEventFunc));
2502 }
2503 
SetOnMouse(OnMouseEventFunc && onMouseEventFunc)2504 void ViewAbstract::SetOnMouse(OnMouseEventFunc&& onMouseEventFunc)
2505 {
2506     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
2507     CHECK_NULL_VOID(eventHub);
2508     eventHub->SetMouseEvent(std::move(onMouseEventFunc));
2509 }
2510 
SetOnAxisEvent(OnAxisEventFunc && onAxisEventFunc)2511 void ViewAbstract::SetOnAxisEvent(OnAxisEventFunc&& onAxisEventFunc)
2512 {
2513     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
2514     CHECK_NULL_VOID(eventHub);
2515     eventHub->SetAxisEvent(std::move(onAxisEventFunc));
2516 }
2517 
SetOnHover(OnHoverFunc && onHoverEventFunc)2518 void ViewAbstract::SetOnHover(OnHoverFunc&& onHoverEventFunc)
2519 {
2520     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
2521     CHECK_NULL_VOID(eventHub);
2522     eventHub->SetHoverEvent(std::move(onHoverEventFunc));
2523 }
2524 
SetOnHoverMove(OnHoverMoveFunc && onHoverMoveEventFunc)2525 void ViewAbstract::SetOnHoverMove(OnHoverMoveFunc&& onHoverMoveEventFunc)
2526 {
2527     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
2528     CHECK_NULL_VOID(eventHub);
2529     eventHub->SetHoverMoveEvent(std::move(onHoverMoveEventFunc));
2530 }
2531 
SetOnAccessibilityHover(OnAccessibilityHoverFunc && onAccessibilityHoverEventFunc)2532 void ViewAbstract::SetOnAccessibilityHover(OnAccessibilityHoverFunc &&onAccessibilityHoverEventFunc)
2533 {
2534     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
2535     CHECK_NULL_VOID(eventHub);
2536     eventHub->SetAccessibilityHoverEvent(std::move(onAccessibilityHoverEventFunc));
2537 }
2538 
SetHoverEffect(HoverEffectType hoverEffect)2539 void ViewAbstract::SetHoverEffect(HoverEffectType hoverEffect)
2540 {
2541     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
2542     CHECK_NULL_VOID(eventHub);
2543     eventHub->SetHoverEffect(hoverEffect);
2544 }
2545 
SetHoverEffectAuto(HoverEffectType hoverEffect)2546 void ViewAbstract::SetHoverEffectAuto(HoverEffectType hoverEffect)
2547 {
2548     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
2549     CHECK_NULL_VOID(eventHub);
2550     eventHub->SetHoverEffectAuto(hoverEffect);
2551 }
2552 
SetEnabled(bool enabled)2553 void ViewAbstract::SetEnabled(bool enabled)
2554 {
2555     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2556     CHECK_NULL_VOID(frameNode);
2557     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2558     if (eventHub) {
2559         eventHub->SetEnabled(enabled);
2560     }
2561 
2562     // The SetEnabled of focusHub must be after at eventHub
2563     auto focusHub = frameNode->GetOrCreateFocusHub();
2564     if (focusHub) {
2565         focusHub->SetEnabled(enabled);
2566     }
2567 }
2568 
SetFocusable(bool focusable)2569 void ViewAbstract::SetFocusable(bool focusable)
2570 {
2571     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2572     CHECK_NULL_VOID(focusHub);
2573     focusHub->SetFocusable(focusable);
2574 }
2575 
SetTabStop(bool tabStop)2576 void ViewAbstract::SetTabStop(bool tabStop)
2577 {
2578     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2579     CHECK_NULL_VOID(frameNode);
2580     auto focusHub = frameNode->GetOrCreateFocusHub();
2581     CHECK_NULL_VOID(focusHub);
2582     focusHub->SetTabStop(tabStop);
2583 }
2584 
SetOnFocus(OnFocusFunc && onFocusCallback)2585 void ViewAbstract::SetOnFocus(OnFocusFunc&& onFocusCallback)
2586 {
2587     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2588     CHECK_NULL_VOID(focusHub);
2589     focusHub->SetOnFocusCallback(std::move(onFocusCallback));
2590 }
2591 
SetOnBlur(OnBlurFunc && onBlurCallback)2592 void ViewAbstract::SetOnBlur(OnBlurFunc&& onBlurCallback)
2593 {
2594     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2595     CHECK_NULL_VOID(focusHub);
2596     focusHub->SetOnBlurCallback(std::move(onBlurCallback));
2597 }
2598 
SetOnKeyEvent(OnKeyConsumeFunc && onKeyCallback)2599 void ViewAbstract::SetOnKeyEvent(OnKeyConsumeFunc&& onKeyCallback)
2600 {
2601     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2602     CHECK_NULL_VOID(focusHub);
2603     focusHub->SetOnKeyCallback(std::move(onKeyCallback));
2604 }
2605 
SetTabIndex(int32_t index)2606 void ViewAbstract::SetTabIndex(int32_t index)
2607 {
2608     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2609     CHECK_NULL_VOID(focusHub);
2610     focusHub->SetTabIndex(index);
2611 }
2612 
SetFocusOnTouch(bool isSet)2613 void ViewAbstract::SetFocusOnTouch(bool isSet)
2614 {
2615     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2616     CHECK_NULL_VOID(focusHub);
2617     focusHub->SetIsFocusOnTouch(isSet);
2618 }
2619 
SetNextFocus(FocusIntension key,const std::string & nextFocus)2620 void ViewAbstract::SetNextFocus(FocusIntension key, const std::string& nextFocus)
2621 {
2622     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2623     CHECK_NULL_VOID(focusHub);
2624     focusHub->SetNextFocus(key, nextFocus);
2625 }
2626 
ResetNextFocus()2627 void ViewAbstract::ResetNextFocus()
2628 {
2629     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2630     CHECK_NULL_VOID(focusHub);
2631     focusHub->ResetNextFocus();
2632 }
2633 
SetFocusBoxUpdateFunc(FrameNode * frameNode,const NG::FocusBoxStyle & style)2634 void SetFocusBoxUpdateFunc(FrameNode* frameNode, const NG::FocusBoxStyle& style)
2635 {
2636     CHECK_NULL_VOID(frameNode);
2637     auto pattern = frameNode->GetPattern<Pattern>();
2638     CHECK_NULL_VOID(pattern);
2639     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode), style](const RefPtr<ResourceObject>& resObj) {
2640         CHECK_NULL_VOID(resObj);
2641         auto frameNode = weak.Upgrade();
2642         CHECK_NULL_VOID(frameNode);
2643         auto focusHub = frameNode->GetOrCreateFocusHub();
2644         CHECK_NULL_VOID(focusHub);
2645         NG::FocusBoxStyle focusBoxStyle = style;
2646         focusBoxStyle.ReloadResources();
2647         focusHub->GetFocusBox().SetStyle(focusBoxStyle);
2648     };
2649     RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>();
2650     pattern->AddResObj("focusBox", resObj, std::move(updateFunc));
2651 }
2652 
SetFocusBoxStyle(const NG::FocusBoxStyle & style)2653 void ViewAbstract::SetFocusBoxStyle(const NG::FocusBoxStyle& style)
2654 {
2655     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2656     CHECK_NULL_VOID(focusHub);
2657     focusHub->GetFocusBox().SetStyle(style);
2658 
2659     if (SystemProperties::ConfigChangePerform()) {
2660         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2661         CHECK_NULL_VOID(frameNode);
2662         SetFocusBoxUpdateFunc(frameNode, style);
2663     }
2664 }
2665 
SetClickDistance(FrameNode * frameNode,double clickDistance)2666 void ViewAbstract::SetClickDistance(FrameNode* frameNode, double clickDistance)
2667 {
2668     CHECK_NULL_VOID(frameNode);
2669     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
2670     CHECK_NULL_VOID(gestureHub);
2671     gestureHub->SetNodeClickDistance(clickDistance);
2672 }
2673 
SetDefaultFocus(bool isSet)2674 void ViewAbstract::SetDefaultFocus(bool isSet)
2675 {
2676     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2677     CHECK_NULL_VOID(focusHub);
2678     focusHub->SetIsDefaultFocus(isSet);
2679 }
2680 
SetGroupDefaultFocus(bool isSet)2681 void ViewAbstract::SetGroupDefaultFocus(bool isSet)
2682 {
2683     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2684     CHECK_NULL_VOID(focusHub);
2685     focusHub->SetIsDefaultGroupFocus(isSet);
2686 }
2687 
SetOnAppear(std::function<void ()> && onAppear)2688 void ViewAbstract::SetOnAppear(std::function<void()>&& onAppear)
2689 {
2690     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2691     CHECK_NULL_VOID(eventHub);
2692     eventHub->SetOnAppear(std::move(onAppear));
2693 }
2694 
SetOnDisappear(std::function<void ()> && onDisappear)2695 void ViewAbstract::SetOnDisappear(std::function<void()>&& onDisappear)
2696 {
2697     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2698     CHECK_NULL_VOID(eventHub);
2699     eventHub->SetOnDisappear(std::move(onDisappear));
2700 }
2701 
SetOnAttach(std::function<void ()> && onAttach)2702 void ViewAbstract::SetOnAttach(std::function<void()> &&onAttach)
2703 {
2704     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2705     CHECK_NULL_VOID(eventHub);
2706     eventHub->SetOnAttach(std::move(onAttach));
2707 }
2708 
SetOnDetach(std::function<void ()> && onDetach)2709 void ViewAbstract::SetOnDetach(std::function<void()> &&onDetach)
2710 {
2711     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2712     CHECK_NULL_VOID(eventHub);
2713     eventHub->SetOnDetach(std::move(onDetach));
2714 }
2715 
SetOnAreaChanged(std::function<void (const RectF & oldRect,const OffsetF & oldOrigin,const RectF & rect,const OffsetF & origin)> && onAreaChanged)2716 void ViewAbstract::SetOnAreaChanged(
2717     std::function<void(const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect, const OffsetF& origin)>&&
2718         onAreaChanged)
2719 {
2720     auto pipeline = PipelineContext::GetCurrentContext();
2721     CHECK_NULL_VOID(pipeline);
2722     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2723     CHECK_NULL_VOID(frameNode);
2724     frameNode->SetOnAreaChangeCallback(std::move(onAreaChanged));
2725     pipeline->AddOnAreaChangeNode(frameNode->GetId());
2726 }
2727 
SetOnSizeChanged(std::function<void (const RectF & oldRect,const RectF & rect)> && onSizeChanged)2728 void ViewAbstract::SetOnSizeChanged(std::function<void(const RectF &oldRect, const RectF &rect)> &&onSizeChanged)
2729 {
2730     auto pipeline = PipelineContext::GetCurrentContext();
2731     CHECK_NULL_VOID(pipeline);
2732     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2733     CHECK_NULL_VOID(frameNode);
2734     frameNode->SetOnSizeChangeCallback(std::move(onSizeChanged));
2735 }
2736 
SetOnVisibleChange(std::function<void (bool,double)> && onVisibleChange,const std::vector<double> & ratioList,bool isOutOfBoundsAllowed)2737 void ViewAbstract::SetOnVisibleChange(std::function<void(bool, double)> &&onVisibleChange,
2738     const std::vector<double> &ratioList, bool isOutOfBoundsAllowed)
2739 {
2740     auto pipeline = PipelineContext::GetCurrentContext();
2741     CHECK_NULL_VOID(pipeline);
2742     auto frameNode = AceType::Claim(ViewStackProcessor::GetInstance()->GetMainFrameNode());
2743     CHECK_NULL_VOID(frameNode);
2744     frameNode->CleanVisibleAreaUserCallback();
2745     pipeline->AddVisibleAreaChangeNode(frameNode, ratioList, onVisibleChange);
2746     auto eventHub = frameNode->GetEventHub<EventHub>();
2747     CHECK_NULL_VOID(eventHub);
2748     auto& visibleAreaUserCallback = eventHub->GetVisibleAreaCallback(true);
2749     visibleAreaUserCallback.isOutOfBoundsAllowed = isOutOfBoundsAllowed;
2750 }
2751 
SetResponseRegion(const std::vector<DimensionRect> & responseRegion)2752 void ViewAbstract::SetResponseRegion(const std::vector<DimensionRect>& responseRegion)
2753 {
2754     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2755     CHECK_NULL_VOID(gestureHub);
2756     gestureHub->SetResponseRegion(responseRegion);
2757 }
2758 
SetMouseResponseRegion(const std::vector<DimensionRect> & mouseRegion)2759 void ViewAbstract::SetMouseResponseRegion(const std::vector<DimensionRect>& mouseRegion)
2760 {
2761     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2762     CHECK_NULL_VOID(gestureHub);
2763     gestureHub->SetMouseResponseRegion(mouseRegion);
2764 }
2765 
SetTouchable(bool touchable)2766 void ViewAbstract::SetTouchable(bool touchable)
2767 {
2768     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2769     CHECK_NULL_VOID(gestureHub);
2770     gestureHub->SetTouchable(touchable);
2771 }
2772 
SetMonopolizeEvents(bool monopolizeEvents)2773 void ViewAbstract::SetMonopolizeEvents(bool monopolizeEvents)
2774 {
2775     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2776     CHECK_NULL_VOID(gestureHub);
2777     gestureHub->SetMonopolizeEvents(monopolizeEvents);
2778 }
2779 
SetHitTestMode(HitTestMode hitTestMode)2780 void ViewAbstract::SetHitTestMode(HitTestMode hitTestMode)
2781 {
2782     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2783     CHECK_NULL_VOID(gestureHub);
2784     gestureHub->SetHitTestMode(hitTestMode);
2785 }
2786 
SetOnTouchTestFunc(NG::OnChildTouchTestFunc && onChildTouchTest)2787 void ViewAbstract::SetOnTouchTestFunc(NG::OnChildTouchTestFunc&& onChildTouchTest)
2788 {
2789     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2790     CHECK_NULL_VOID(gestureHub);
2791     gestureHub->SetOnTouchTestFunc(std::move(onChildTouchTest));
2792 }
2793 
SetOnFocusAxisEvent(OnFocusAxisEventFunc && onFocusAxisCallback)2794 void ViewAbstract::SetOnFocusAxisEvent(OnFocusAxisEventFunc&& onFocusAxisCallback)
2795 {
2796     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
2797     CHECK_NULL_VOID(focusHub);
2798     focusHub->SetOnFocusAxisCallback(std::move(onFocusAxisCallback));
2799 }
2800 
SetOnFocusAxisEvent(FrameNode * frameNode,OnFocusAxisEventFunc && onFocusAxisCallback)2801 void ViewAbstract::SetOnFocusAxisEvent(FrameNode* frameNode, OnFocusAxisEventFunc &&onFocusAxisCallback)
2802 {
2803     CHECK_NULL_VOID(frameNode);
2804     auto focusHub = frameNode->GetOrCreateFocusHub();
2805     focusHub->SetOnFocusAxisCallback(std::move(onFocusAxisCallback));
2806 }
2807 
NotifyDragStartRequest(DragStartRequestStatus dragStatus)2808 void ViewAbstract::NotifyDragStartRequest(DragStartRequestStatus dragStatus)
2809 {
2810     auto pipeline = PipelineContext::GetCurrentContext();
2811     CHECK_NULL_VOID(pipeline);
2812     auto dragDropManager = pipeline->GetDragDropManager();
2813     CHECK_NULL_VOID(dragDropManager);
2814     dragDropManager->HandleSyncOnDragStart(dragStatus);
2815 }
2816 
SetDraggable(bool draggable)2817 void ViewAbstract::SetDraggable(bool draggable)
2818 {
2819     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2820     CHECK_NULL_VOID(frameNode);
2821     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2822     CHECK_NULL_VOID(gestureHub);
2823     if (draggable) {
2824         if (!frameNode->IsDraggable()) {
2825             gestureHub->InitDragDropEvent();
2826         }
2827     } else {
2828         gestureHub->RemoveDragEvent();
2829     }
2830     frameNode->SetCustomerDraggable(draggable);
2831 }
2832 
SetDragPreviewOptions(const DragPreviewOption & previewOption)2833 void ViewAbstract::SetDragPreviewOptions(const DragPreviewOption& previewOption)
2834 {
2835     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2836     CHECK_NULL_VOID(frameNode);
2837     frameNode->SetDragPreviewOptions(previewOption, false);
2838 }
2839 
SetOnDragStart(std::function<DragDropInfo (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragStart)2840 void ViewAbstract::SetOnDragStart(
2841     std::function<DragDropInfo(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragStart)
2842 {
2843     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
2844     CHECK_NULL_VOID(gestureHub);
2845     gestureHub->InitDragDropEvent();
2846 
2847     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2848     CHECK_NULL_VOID(eventHub);
2849     eventHub->SetOnDragStart(std::move(onDragStart));
2850 }
2851 
SetOnDragStart(FrameNode * frameNode,std::function<DragDropInfo (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragStart)2852 void ViewAbstract::SetOnDragStart(FrameNode* frameNode,
2853     std::function<DragDropInfo(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragStart)
2854 {
2855     CHECK_NULL_VOID(frameNode);
2856     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
2857     CHECK_NULL_VOID(gestureHub);
2858     gestureHub->InitDragDropEvent();
2859 
2860     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2861     CHECK_NULL_VOID(eventHub);
2862     eventHub->SetOnDragStart(std::move(onDragStart));
2863 }
2864 
SetOnDragEnter(FrameNode * frameNode,std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragEnter)2865 void ViewAbstract::SetOnDragEnter(FrameNode* frameNode,
2866     std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragEnter)
2867 {
2868     CHECK_NULL_VOID(frameNode);
2869     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2870     CHECK_NULL_VOID(eventHub);
2871     eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_ENTER, std::move(onDragEnter));
2872 }
2873 
SetOnDragMove(FrameNode * frameNode,std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragMove)2874 void ViewAbstract::SetOnDragMove(FrameNode* frameNode,
2875     std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragMove)
2876 {
2877     CHECK_NULL_VOID(frameNode);
2878     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2879     CHECK_NULL_VOID(eventHub);
2880     eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_MOVE, std::move(onDragMove));
2881 }
2882 
SetOnDragSpringLoading(std::function<void (const RefPtr<DragSpringLoadingContext> &)> && onDragSpringLoading)2883 void ViewAbstract::SetOnDragSpringLoading(
2884     std::function<void(const RefPtr<DragSpringLoadingContext>&)>&& onDragSpringLoading)
2885 {
2886     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2887     CHECK_NULL_VOID(eventHub);
2888     eventHub->SetCustomerOnDragSpringLoading(std::move(onDragSpringLoading));
2889 }
2890 
SetOnDragSpringLoading(FrameNode * frameNode,std::function<void (const RefPtr<DragSpringLoadingContext> &)> && onDragSpringLoading)2891 void ViewAbstract::SetOnDragSpringLoading(
2892     FrameNode* frameNode, std::function<void(const RefPtr<DragSpringLoadingContext>&)>&& onDragSpringLoading)
2893 {
2894     CHECK_NULL_VOID(frameNode);
2895     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2896     CHECK_NULL_VOID(eventHub);
2897     eventHub->SetCustomerOnDragSpringLoading(std::move(onDragSpringLoading));
2898 }
2899 
SetOnDragSpringLoadingConfiguration(const RefPtr<DragSpringLoadingConfiguration> & dragSpringLoadingConfiguration)2900 void ViewAbstract::SetOnDragSpringLoadingConfiguration(
2901     const RefPtr<DragSpringLoadingConfiguration>& dragSpringLoadingConfiguration)
2902 {
2903     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2904     CHECK_NULL_VOID(frameNode);
2905     auto relatedConfigurations = frameNode->GetOrCreateDragDropRelatedConfigurations();
2906     CHECK_NULL_VOID(relatedConfigurations);
2907     relatedConfigurations->SetDragSpringLoadingConfiguration(std::move(dragSpringLoadingConfiguration));
2908 }
2909 
SetOnDragSpringLoadingConfiguration(FrameNode * frameNode,const RefPtr<DragSpringLoadingConfiguration> & dragSpringLoadingConfiguration)2910 void ViewAbstract::SetOnDragSpringLoadingConfiguration(
2911     FrameNode* frameNode, const RefPtr<DragSpringLoadingConfiguration>& dragSpringLoadingConfiguration)
2912 {
2913     CHECK_NULL_VOID(frameNode);
2914     auto relatedConfigurations = frameNode->GetOrCreateDragDropRelatedConfigurations();
2915     CHECK_NULL_VOID(relatedConfigurations);
2916     relatedConfigurations->SetDragSpringLoadingConfiguration(std::move(dragSpringLoadingConfiguration));
2917 }
2918 
SetOnDragLeave(FrameNode * frameNode,std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragLeave)2919 void ViewAbstract::SetOnDragLeave(FrameNode* frameNode,
2920     std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragLeave)
2921 {
2922     CHECK_NULL_VOID(frameNode);
2923     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2924     CHECK_NULL_VOID(eventHub);
2925     eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_LEAVE, std::move(onDragLeave));
2926 }
2927 
SetOnPreDrag(std::function<void (const PreDragStatus)> && onPreDragFunc)2928 void ViewAbstract::SetOnPreDrag(std::function<void(const PreDragStatus)>&& onPreDragFunc)
2929 {
2930     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2931     CHECK_NULL_VOID(eventHub);
2932     eventHub->SetOnPreDrag(std::move(onPreDragFunc));
2933 }
2934 
SetOnPreDrag(FrameNode * frameNode,std::function<void (const PreDragStatus)> && onPreDragFunc)2935 void ViewAbstract::SetOnPreDrag(FrameNode* frameNode, std::function<void(const PreDragStatus)>&& onPreDragFunc)
2936 {
2937     CHECK_NULL_VOID(frameNode);
2938     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2939     CHECK_NULL_VOID(eventHub);
2940     eventHub->SetOnPreDrag(std::move(onPreDragFunc));
2941 }
2942 
SetOnDragEnter(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragEnter)2943 void ViewAbstract::SetOnDragEnter(
2944     std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragEnter)
2945 {
2946     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2947     CHECK_NULL_VOID(eventHub);
2948     eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_ENTER, std::move(onDragEnter));
2949 }
2950 
SetOnDragLeave(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragLeave)2951 void ViewAbstract::SetOnDragLeave(
2952     std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragLeave)
2953 {
2954     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2955     CHECK_NULL_VOID(eventHub);
2956     eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_LEAVE, std::move(onDragLeave));
2957 }
2958 
SetOnDragMove(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragMove)2959 void ViewAbstract::SetOnDragMove(
2960     std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragMove)
2961 {
2962     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2963     CHECK_NULL_VOID(eventHub);
2964     eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_MOVE, std::move(onDragMove));
2965 }
2966 
SetOnDrop(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDrop)2967 void ViewAbstract::SetOnDrop(std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDrop)
2968 {
2969     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2970     CHECK_NULL_VOID(eventHub);
2971     eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_DROP, std::move(onDrop));
2972 }
2973 
SetOnDragEnd(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &)> && onDragEnd)2974 void ViewAbstract::SetOnDragEnd(std::function<void(const RefPtr<OHOS::Ace::DragEvent>&)>&& onDragEnd)
2975 {
2976     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2977     CHECK_NULL_VOID(eventHub);
2978     eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_END, std::move(onDragEnd));
2979 }
2980 
SetOnDragEnd(FrameNode * frameNode,std::function<void (const RefPtr<OHOS::Ace::DragEvent> &)> && onDragEnd)2981 void ViewAbstract::SetOnDragEnd(
2982     FrameNode* frameNode, std::function<void(const RefPtr<OHOS::Ace::DragEvent>&)>&& onDragEnd)
2983 {
2984     CHECK_NULL_VOID(frameNode);
2985     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2986     CHECK_NULL_VOID(eventHub);
2987     eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_END, std::move(onDragEnd));
2988 }
2989 
SetOnDrop(FrameNode * frameNode,std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDrop)2990 void ViewAbstract::SetOnDrop(
2991     FrameNode* frameNode, std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDrop)
2992 {
2993     CHECK_NULL_VOID(frameNode);
2994     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
2995     CHECK_NULL_VOID(eventHub);
2996 
2997     eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_DROP, std::move(onDrop));
2998 }
2999 
SetAlign(Alignment alignment)3000 void ViewAbstract::SetAlign(Alignment alignment)
3001 {
3002     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3003         return;
3004     }
3005     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Alignment, alignment);
3006 }
3007 
SetAlign(std::string localizedAlignment)3008 void ViewAbstract::SetAlign(std::string localizedAlignment)
3009 {
3010     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3011         return;
3012     }
3013     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, LocalizedAlignment, localizedAlignment);
3014 }
3015 
SetLayoutGravity(Alignment alignment)3016 void ViewAbstract::SetLayoutGravity(Alignment alignment)
3017 {
3018     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3019         return;
3020     }
3021     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, LayoutGravity, alignment);
3022 }
3023 
SetIsMirrorable(bool isMirrorable)3024 void ViewAbstract::SetIsMirrorable(bool isMirrorable)
3025 {
3026     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3027         return;
3028     }
3029     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, IsMirrorable, isMirrorable);
3030 }
3031 
SetAlign(FrameNode * frameNode,Alignment alignment)3032 void ViewAbstract::SetAlign(FrameNode* frameNode, Alignment alignment)
3033 {
3034     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Alignment, alignment, frameNode);
3035 }
3036 
SetLayoutGravity(FrameNode * frameNode,Alignment alignment)3037 void ViewAbstract::SetLayoutGravity(FrameNode* frameNode, Alignment alignment)
3038 {
3039     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, LayoutGravity, alignment, frameNode);
3040 }
3041 
SetVisibility(VisibleType visible)3042 void ViewAbstract::SetVisibility(VisibleType visible)
3043 {
3044     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3045         return;
3046     }
3047     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3048     CHECK_NULL_VOID(frameNode);
3049     auto layoutProperty = frameNode->GetLayoutProperty();
3050     if (layoutProperty) {
3051         layoutProperty->UpdateVisibility(visible, true, true);
3052     }
3053 
3054     auto focusHub = frameNode->GetOrCreateFocusHub();
3055     if (focusHub) {
3056         focusHub->SetShow(visible == VisibleType::VISIBLE);
3057     }
3058 }
3059 
SetGeometryTransition(const std::string & id,bool followWithoutTransition,bool doRegisterSharedTransition)3060 void ViewAbstract::SetGeometryTransition(const std::string& id,
3061     bool followWithoutTransition, bool doRegisterSharedTransition)
3062 {
3063     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3064     CHECK_NULL_VOID(frameNode);
3065     auto layoutProperty = frameNode->GetLayoutProperty();
3066     if (layoutProperty) {
3067         layoutProperty->UpdateGeometryTransition(id, followWithoutTransition, doRegisterSharedTransition);
3068     }
3069 }
3070 
SetGeometryTransition(FrameNode * frameNode,const std::string & id,bool followWithoutTransition,bool doRegisterSharedTransition)3071 void ViewAbstract::SetGeometryTransition(FrameNode *frameNode, const std::string& id,
3072     bool followWithoutTransition, bool doRegisterSharedTransition)
3073 {
3074     CHECK_NULL_VOID(frameNode);
3075     auto layoutProperty = frameNode->GetLayoutProperty();
3076     if (layoutProperty) {
3077         layoutProperty->UpdateGeometryTransition(id, followWithoutTransition, doRegisterSharedTransition);
3078     }
3079 }
3080 
GetGeometryTransition(FrameNode * frameNode,bool * followWithoutTransition,bool * doRegisterSharedTransition)3081 const std::string ViewAbstract::GetGeometryTransition(FrameNode* frameNode,
3082     bool* followWithoutTransition, bool* doRegisterSharedTransition)
3083 {
3084     CHECK_NULL_RETURN(frameNode, "");
3085     auto layoutProperty = frameNode->GetLayoutProperty();
3086     if (layoutProperty) {
3087         auto geometryTransition = layoutProperty->GetGeometryTransition();
3088         if (geometryTransition) {
3089             *followWithoutTransition = geometryTransition->GetFollowWithoutTransition();
3090             *doRegisterSharedTransition = geometryTransition->GetDoRegisterSharedTransition();
3091             return geometryTransition->GetId();
3092         }
3093     }
3094     return "";
3095 }
3096 
SetOpacity(double opacity)3097 void ViewAbstract::SetOpacity(double opacity)
3098 {
3099     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3100         return;
3101     }
3102     ACE_UPDATE_RENDER_CONTEXT(Opacity, opacity);
3103 }
SetAllowDrop(const std::set<std::string> & allowDrop)3104 void ViewAbstract::SetAllowDrop(const std::set<std::string>& allowDrop)
3105 {
3106     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3107     CHECK_NULL_VOID(frameNode);
3108     frameNode->SetAllowDrop(allowDrop);
3109 }
3110 
SetDrawModifier(const RefPtr<NG::DrawModifier> & drawModifier)3111 void ViewAbstract::SetDrawModifier(const RefPtr<NG::DrawModifier>& drawModifier)
3112 {
3113     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3114     CHECK_NULL_VOID(frameNode);
3115     frameNode->SetDrawModifier(drawModifier);
3116 }
3117 
GetFrameNode()3118 void* ViewAbstract::GetFrameNode()
3119 {
3120     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3121     return static_cast<void*>(frameNode);
3122 }
3123 
SetDragPreview(const NG::DragDropInfo & info)3124 void ViewAbstract::SetDragPreview(const NG::DragDropInfo& info)
3125 {
3126     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3127     CHECK_NULL_VOID(frameNode);
3128     frameNode->SetDragPreview(info);
3129 }
3130 
SetPosition(const OffsetT<Dimension> & value)3131 void ViewAbstract::SetPosition(const OffsetT<Dimension>& value)
3132 {
3133     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3134         return;
3135     }
3136     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3137     CHECK_NULL_VOID(frameNode);
3138     CheckIfParentNeedMarkDirty(frameNode);
3139     ACE_RESET_RENDER_CONTEXT(RenderContext, PositionEdges);
3140     ACE_UPDATE_RENDER_CONTEXT(Position, value);
3141 }
3142 
SetPosition(const Dimension & x,const Dimension & y,const RefPtr<ResourceObject> & xresObj,const RefPtr<ResourceObject> & yresObj)3143 void ViewAbstract::SetPosition(const Dimension& x, const Dimension& y,
3144     const RefPtr<ResourceObject>& xresObj, const RefPtr<ResourceObject>& yresObj)
3145 {
3146     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3147         return;
3148     }
3149     OffsetT<Dimension> value = { x, y };
3150     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3151     CHECK_NULL_VOID(frameNode);
3152     SetPositionX(value, xresObj);
3153     SetPositionY(value, yresObj);
3154     CheckIfParentNeedMarkDirty(frameNode);
3155     ACE_RESET_RENDER_CONTEXT(RenderContext, PositionEdges);
3156     ACE_UPDATE_RENDER_CONTEXT(Position, value);
3157 }
3158 
SetPositionX(OffsetT<Dimension> & value,const RefPtr<ResourceObject> & xresObj)3159 void ViewAbstract::SetPositionX(OffsetT<Dimension>& value, const RefPtr<ResourceObject>& xresObj)
3160 {
3161     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3162     CHECK_NULL_VOID(frameNode);
3163     auto pattern = frameNode->GetPattern<Pattern>();
3164     CHECK_NULL_VOID(pattern);
3165     if (!xresObj) {
3166         return;
3167     }
3168     auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
3169         auto frameNode = weak.Upgrade();
3170         CHECK_NULL_VOID(frameNode);
3171         auto pattern = frameNode->GetPattern<Pattern>();
3172         CHECK_NULL_VOID(pattern);
3173         std::string xString = pattern->GetResCacheMapByKey("position.x");
3174         OffsetT<Dimension> &offset = const_cast<OffsetT<Dimension> &>(value);
3175         CalcDimension x;
3176         if (xString.empty()) {
3177             ResourceParseUtils::ParseResDimensionVpNG(resObj, x);
3178             pattern->AddResCache("position.x", x.ToString());
3179         } else {
3180             x = StringUtils::StringToCalcDimension(xString);
3181         }
3182         const auto& renderContext = frameNode->GetRenderContext();
3183         CHECK_NULL_VOID(renderContext);
3184         auto position = renderContext->GetPositionValue({});
3185         offset.SetY(position.GetY());
3186         offset.SetX(x);
3187         auto parentNode = frameNode->GetAncestorNodeOfFrame(false);
3188         CHECK_NULL_VOID(parentNode);
3189         if (parentNode->GetTag() == V2::COLUMN_ETS_TAG || parentNode->GetTag() == V2::ROW_ETS_TAG ||
3190             parentNode->GetTag() == V2::FLEX_ETS_TAG) {
3191             auto renderContext = frameNode->GetRenderContext();
3192             CHECK_NULL_VOID(renderContext);
3193             if (!renderContext->HasPositionEdges() && !renderContext->HasPosition()) {
3194                 parentNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
3195             }
3196         }
3197         ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, PositionEdges, frameNode);
3198         ACE_UPDATE_NODE_RENDER_CONTEXT(Position, offset, frameNode);
3199     };
3200     pattern->AddResObj("position.x", xresObj, std::move(updateFunc));
3201 }
3202 
SetPositionY(OffsetT<Dimension> & value,const RefPtr<ResourceObject> & yresObj)3203 void ViewAbstract::SetPositionY(OffsetT<Dimension>& value, const RefPtr<ResourceObject>& yresObj)
3204 {
3205     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3206     CHECK_NULL_VOID(frameNode);
3207     auto pattern = frameNode->GetPattern<Pattern>();
3208     CHECK_NULL_VOID(pattern);
3209     if (!yresObj) {
3210         return;
3211     }
3212     auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
3213         auto frameNode = weak.Upgrade();
3214         CHECK_NULL_VOID(frameNode);
3215         auto pattern = frameNode->GetPattern<Pattern>();
3216         CHECK_NULL_VOID(pattern);
3217         std::string yString = pattern->GetResCacheMapByKey("position.y");
3218         OffsetT<Dimension> &offset = const_cast<OffsetT<Dimension> &>(value);
3219         CalcDimension y;
3220         if (yString.empty()) {
3221             ResourceParseUtils::ParseResDimensionVpNG(resObj, y);
3222             pattern->AddResCache("position.y", y.ToString());
3223         } else {
3224             y = StringUtils::StringToCalcDimension(yString);
3225         }
3226         const auto& renderContext = frameNode->GetRenderContext();
3227         CHECK_NULL_VOID(renderContext);
3228         auto position = renderContext->GetPositionValue({});
3229         offset.SetX(position.GetX());
3230         offset.SetY(y);
3231         auto parentNode = frameNode->GetAncestorNodeOfFrame(false);
3232         CHECK_NULL_VOID(parentNode);
3233         if (parentNode->GetTag() == V2::COLUMN_ETS_TAG || parentNode->GetTag() == V2::ROW_ETS_TAG ||
3234             parentNode->GetTag() == V2::FLEX_ETS_TAG) {
3235             auto renderContext = frameNode->GetRenderContext();
3236             CHECK_NULL_VOID(renderContext);
3237             if (!renderContext->HasPositionEdges() && !renderContext->HasPosition()) {
3238                 parentNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
3239             }
3240         }
3241         ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, PositionEdges, frameNode);
3242         ACE_UPDATE_NODE_RENDER_CONTEXT(Position, offset, frameNode);
3243     };
3244     pattern->AddResObj("position.y", yresObj, std::move(updateFunc));
3245 }
3246 
SetPositionEdges(const EdgesParam & value)3247 void ViewAbstract::SetPositionEdges(const EdgesParam& value)
3248 {
3249     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3250         return;
3251     }
3252     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3253     CHECK_NULL_VOID(frameNode);
3254     if (SystemProperties::ConfigChangePerform()) {
3255         auto pattern = frameNode->GetPattern<Pattern>();
3256         CHECK_NULL_VOID(pattern);
3257         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
3258         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
3259             auto frameNode = weak.Upgrade();
3260             CHECK_NULL_VOID(frameNode);
3261             EdgesParam &edges = const_cast<EdgesParam &>(value);
3262             edges.ReloadResources();
3263             auto layoutProperty = frameNode->GetLayoutProperty();
3264             CHECK_NULL_VOID(layoutProperty);
3265             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
3266             CheckPositionOrOffsetLocalizedEdges(edges, layoutDirection);
3267             auto parentNode = frameNode->GetAncestorNodeOfFrame(false);
3268             CHECK_NULL_VOID(parentNode);
3269             if (parentNode->GetTag() == V2::COLUMN_ETS_TAG || parentNode->GetTag() == V2::ROW_ETS_TAG ||
3270                 parentNode->GetTag() == V2::FLEX_ETS_TAG) {
3271                 auto renderContext = frameNode->GetRenderContext();
3272                 CHECK_NULL_VOID(renderContext);
3273                 if (!renderContext->HasPositionEdges() && !renderContext->HasPosition()) {
3274                     parentNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
3275                 }
3276             }
3277             ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, Position, frameNode);
3278             ACE_UPDATE_NODE_RENDER_CONTEXT(PositionEdges, edges, frameNode);
3279         };
3280         pattern->AddResObj("position.edges", resObj, std::move(updateFunc));
3281     }
3282     CheckIfParentNeedMarkDirty(frameNode);
3283     ACE_RESET_RENDER_CONTEXT(RenderContext, Position);
3284     ACE_UPDATE_RENDER_CONTEXT(PositionEdges, value);
3285 }
3286 
CheckIfParentNeedMarkDirty(FrameNode * frameNode)3287 void ViewAbstract::CheckIfParentNeedMarkDirty(FrameNode* frameNode)
3288 {
3289     CHECK_NULL_VOID(frameNode);
3290     auto parentNode = frameNode->GetAncestorNodeOfFrame(false);
3291     CHECK_NULL_VOID(parentNode);
3292     // Row/Column/Flex measure and layout differently depending on whether the child nodes have position property,
3293     // need to remeasure in the dynamic switch scenario.
3294     if (parentNode->GetTag() == V2::COLUMN_ETS_TAG || parentNode->GetTag() == V2::ROW_ETS_TAG ||
3295         parentNode->GetTag() == V2::FLEX_ETS_TAG) {
3296         auto renderContext = frameNode->GetRenderContext();
3297         CHECK_NULL_VOID(renderContext);
3298         if (!renderContext->HasPositionEdges() && !renderContext->HasPosition()) {
3299             parentNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
3300         }
3301     }
3302 }
3303 
SetOffset(const OffsetT<Dimension> & value)3304 void ViewAbstract::SetOffset(const OffsetT<Dimension>& value)
3305 {
3306     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3307         return;
3308     }
3309     ACE_RESET_RENDER_CONTEXT(RenderContext, OffsetEdges);
3310     ACE_UPDATE_RENDER_CONTEXT(Offset, value);
3311 }
3312 
SetOffset(const Dimension & x,const Dimension & y,const RefPtr<ResourceObject> & xresObj,const RefPtr<ResourceObject> & yresObj)3313 void ViewAbstract::SetOffset(const Dimension& x, const Dimension& y,
3314     const RefPtr<ResourceObject>& xresObj, const RefPtr<ResourceObject>& yresObj)
3315 {
3316     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3317         return;
3318     }
3319     OffsetT<Dimension> value = { x, y };
3320     SetOffsetX(value, xresObj);
3321     SetOffsetY(value, yresObj);
3322     ACE_RESET_RENDER_CONTEXT(RenderContext, OffsetEdges);
3323     ACE_UPDATE_RENDER_CONTEXT(Offset, value);
3324 }
3325 
SetOffsetX(OffsetT<Dimension> & value,const RefPtr<ResourceObject> & xresObj)3326 void ViewAbstract::SetOffsetX(OffsetT<Dimension>& value, const RefPtr<ResourceObject>& xresObj)
3327 {
3328     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3329     CHECK_NULL_VOID(frameNode);
3330     auto pattern = frameNode->GetPattern<Pattern>();
3331     CHECK_NULL_VOID(pattern);
3332     if (xresObj) {
3333         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
3334             auto frameNode = weak.Upgrade();
3335             CHECK_NULL_VOID(frameNode);
3336             auto pattern = frameNode->GetPattern<Pattern>();
3337             CHECK_NULL_VOID(pattern);
3338             std::string xString = pattern->GetResCacheMapByKey("offset.x");
3339             OffsetT<Dimension> &offset = const_cast<OffsetT<Dimension> &>(value);
3340             CalcDimension x;
3341             if (xString.empty()) {
3342                 ResourceParseUtils::ParseResDimensionVpNG(resObj, x);
3343                 pattern->AddResCache("offset.x", x.ToString());
3344             } else {
3345                 x = StringUtils::StringToCalcDimension(xString);
3346             }
3347             const auto& renderContext = frameNode->GetRenderContext();
3348             CHECK_NULL_VOID(renderContext);
3349             auto offsetValue = renderContext->GetOffsetValue({});
3350             offset.SetY(offsetValue.GetY());
3351             offset.SetX(x);
3352             ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, OffsetEdges, frameNode);
3353             ACE_UPDATE_NODE_RENDER_CONTEXT(Offset, offset, frameNode);
3354         };
3355         pattern->AddResObj("offset.x", xresObj, std::move(updateFunc));
3356     }
3357 }
3358 
SetOffsetY(OffsetT<Dimension> & value,const RefPtr<ResourceObject> & yresObj)3359 void ViewAbstract::SetOffsetY(OffsetT<Dimension>& value, const RefPtr<ResourceObject>& yresObj)
3360 {
3361     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3362     CHECK_NULL_VOID(frameNode);
3363     auto pattern = frameNode->GetPattern<Pattern>();
3364     CHECK_NULL_VOID(pattern);
3365     if (yresObj) {
3366         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
3367             auto frameNode = weak.Upgrade();
3368             CHECK_NULL_VOID(frameNode);
3369             auto pattern = frameNode->GetPattern<Pattern>();
3370             CHECK_NULL_VOID(pattern);
3371             std::string yString = pattern->GetResCacheMapByKey("offset.y");
3372             OffsetT<Dimension> &offset = const_cast<OffsetT<Dimension> &>(value);
3373             CalcDimension y;
3374             if (yString.empty()) {
3375                 ResourceParseUtils::ParseResDimensionVpNG(resObj, y);
3376                 pattern->AddResCache("offset.y", y.ToString());
3377             } else {
3378                 y = StringUtils::StringToCalcDimension(yString);
3379             }
3380             const auto& renderContext = frameNode->GetRenderContext();
3381             CHECK_NULL_VOID(renderContext);
3382             auto offsetValue = renderContext->GetOffsetValue({});
3383             offset.SetX(offsetValue.GetX());
3384             offset.SetY(y);
3385             ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, OffsetEdges, frameNode);
3386             ACE_UPDATE_NODE_RENDER_CONTEXT(Offset, offset, frameNode);
3387         };
3388         pattern->AddResObj("offset.y", yresObj, std::move(updateFunc));
3389     }
3390 }
3391 
SetOffsetEdges(const EdgesParam & value)3392 void ViewAbstract::SetOffsetEdges(const EdgesParam& value)
3393 {
3394     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3395         return;
3396     }
3397     if (SystemProperties::ConfigChangePerform()) {
3398         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3399         CHECK_NULL_VOID(frameNode);
3400         auto pattern = frameNode->GetPattern<Pattern>();
3401         CHECK_NULL_VOID(pattern);
3402         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
3403         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
3404             auto frameNode = weak.Upgrade();
3405             CHECK_NULL_VOID(frameNode);
3406             EdgesParam &edges = const_cast<EdgesParam &>(value);
3407             edges.ReloadResources();
3408             auto layoutProperty = frameNode->GetLayoutProperty();
3409             CHECK_NULL_VOID(layoutProperty);
3410             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
3411             CheckPositionOrOffsetLocalizedEdges(edges, layoutDirection);
3412             ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, Offset, frameNode);
3413             ACE_UPDATE_NODE_RENDER_CONTEXT(OffsetEdges, edges, frameNode);
3414         };
3415         pattern->AddResObj("offset.edges", resObj, std::move(updateFunc));
3416     }
3417     ACE_RESET_RENDER_CONTEXT(RenderContext, Offset);
3418     ACE_UPDATE_RENDER_CONTEXT(OffsetEdges, value);
3419 }
3420 
MarkAnchor(const OffsetT<Dimension> & value)3421 void ViewAbstract::MarkAnchor(const OffsetT<Dimension>& value)
3422 {
3423     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3424         return;
3425     }
3426     ACE_UPDATE_RENDER_CONTEXT(Anchor, value);
3427 }
3428 
MarkAnchor(const Dimension & x,const Dimension & y,const RefPtr<ResourceObject> & xresObj,const RefPtr<ResourceObject> & yresObj)3429 void ViewAbstract::MarkAnchor(const Dimension& x, const Dimension& y,
3430     const RefPtr<ResourceObject>& xresObj, const RefPtr<ResourceObject>& yresObj)
3431 {
3432     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3433         return;
3434     }
3435     OffsetT<Dimension> value = { x, y };
3436     MarkAnchorX(value, xresObj);
3437     MarkAnchorY(value, yresObj);
3438     ACE_UPDATE_RENDER_CONTEXT(Anchor, value);
3439 }
3440 
MarkAnchorX(OffsetT<Dimension> & value,const RefPtr<ResourceObject> & xresObj)3441 void ViewAbstract::MarkAnchorX(OffsetT<Dimension>& value, const RefPtr<ResourceObject>& xresObj)
3442 {
3443     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3444     CHECK_NULL_VOID(frameNode);
3445     auto pattern = frameNode->GetPattern<Pattern>();
3446     CHECK_NULL_VOID(pattern);
3447     if (xresObj) {
3448         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
3449             auto frameNode = weak.Upgrade();
3450             CHECK_NULL_VOID(frameNode);
3451             auto pattern = frameNode->GetPattern<Pattern>();
3452             CHECK_NULL_VOID(pattern);
3453             std::string xString = pattern->GetResCacheMapByKey("markAnchor.x");
3454             OffsetT<Dimension> &offset = const_cast<OffsetT<Dimension> &>(value);
3455             CalcDimension x;
3456             if (xString.empty()) {
3457                 ResourceParseUtils::ParseResDimensionVpNG(resObj, x);
3458                 pattern->AddResCache("markAnchor.x", x.ToString());
3459             } else {
3460                 x = StringUtils::StringToCalcDimension(xString);
3461             }
3462             const auto& renderContext = frameNode->GetRenderContext();
3463             CHECK_NULL_VOID(renderContext);
3464             auto anchor = renderContext->GetAnchorValue({});
3465             offset.SetY(anchor.GetY());
3466             offset.SetX(x);
3467             ACE_UPDATE_NODE_RENDER_CONTEXT(Anchor, offset, frameNode);
3468         };
3469         pattern->AddResObj("markAnchor.x", xresObj, std::move(updateFunc));
3470     }
3471 }
3472 
MarkAnchorY(OffsetT<Dimension> & value,const RefPtr<ResourceObject> & yresObj)3473 void ViewAbstract::MarkAnchorY(OffsetT<Dimension>& value, const RefPtr<ResourceObject>& yresObj)
3474 {
3475     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3476     CHECK_NULL_VOID(frameNode);
3477     auto pattern = frameNode->GetPattern<Pattern>();
3478     CHECK_NULL_VOID(pattern);
3479     if (yresObj) {
3480         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
3481             auto frameNode = weak.Upgrade();
3482             CHECK_NULL_VOID(frameNode);
3483             auto pattern = frameNode->GetPattern<Pattern>();
3484             CHECK_NULL_VOID(pattern);
3485             std::string yString = pattern->GetResCacheMapByKey("markAnchor.y");
3486             OffsetT<Dimension> &offset = const_cast<OffsetT<Dimension> &>(value);
3487             CalcDimension y;
3488             if (yString.empty()) {
3489                 ResourceParseUtils::ParseResDimensionVpNG(resObj, y);
3490                 pattern->AddResCache("markAnchor.y", y.ToString());
3491             } else {
3492                 y = StringUtils::StringToCalcDimension(yString);
3493             }
3494             const auto& renderContext = frameNode->GetRenderContext();
3495             CHECK_NULL_VOID(renderContext);
3496             auto anchor = renderContext->GetAnchorValue({});
3497             offset.SetX(anchor.GetX());
3498             offset.SetY(y);
3499             ACE_UPDATE_NODE_RENDER_CONTEXT(Anchor, offset, frameNode);
3500         };
3501         pattern->AddResObj("markAnchor.y", yresObj, std::move(updateFunc));
3502     }
3503 }
3504 
ResetPosition()3505 void ViewAbstract::ResetPosition()
3506 {
3507     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3508         return;
3509     }
3510     ACE_RESET_RENDER_CONTEXT(RenderContext, Position);
3511     ACE_RESET_RENDER_CONTEXT(RenderContext, PositionEdges);
3512     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3513     CHECK_NULL_VOID(frameNode);
3514     auto parentNode = frameNode->GetAncestorNodeOfFrame(false);
3515     CHECK_NULL_VOID(parentNode);
3516 
3517     // Row/Column/Flex measure and layout differently depending on whether the child nodes have position property.
3518     if (parentNode->GetTag() == V2::COLUMN_ETS_TAG || parentNode->GetTag() == V2::ROW_ETS_TAG ||
3519         parentNode->GetTag() == V2::FLEX_ETS_TAG) {
3520         frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
3521     } else {
3522         auto renderContext = frameNode->GetRenderContext();
3523         CHECK_NULL_VOID(renderContext);
3524         renderContext->RecalculatePosition();
3525     }
3526 }
3527 
SetZIndex(int32_t value)3528 void ViewAbstract::SetZIndex(int32_t value)
3529 {
3530     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3531         return;
3532     }
3533     ACE_UPDATE_RENDER_CONTEXT(ZIndex, value);
3534 }
3535 
SetScale(const NG::VectorF & value)3536 void ViewAbstract::SetScale(const NG::VectorF& value)
3537 {
3538     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3539         return;
3540     }
3541     ACE_UPDATE_RENDER_CONTEXT(TransformScale, value);
3542 }
3543 
SetScale(FrameNode * frameNode,const NG::VectorF & value)3544 void ViewAbstract::SetScale(FrameNode* frameNode, const NG::VectorF& value)
3545 {
3546     ACE_UPDATE_NODE_RENDER_CONTEXT(TransformScale, value, frameNode);
3547 }
3548 
SetPivot(const DimensionOffset & value)3549 void ViewAbstract::SetPivot(const DimensionOffset& value)
3550 {
3551     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3552         return;
3553     }
3554     ACE_UPDATE_RENDER_CONTEXT(TransformCenter, value);
3555 }
3556 
SetPivot(FrameNode * frameNode,const DimensionOffset & value)3557 void ViewAbstract::SetPivot(FrameNode* frameNode, const DimensionOffset& value)
3558 {
3559     ACE_UPDATE_NODE_RENDER_CONTEXT(TransformCenter, value, frameNode);
3560 }
3561 
SetTranslate(const NG::TranslateOptions & value)3562 void ViewAbstract::SetTranslate(const NG::TranslateOptions& value)
3563 {
3564     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3565         return;
3566     }
3567     ACE_UPDATE_RENDER_CONTEXT(TransformTranslate, value);
3568 }
3569 
SetTranslate(FrameNode * frameNode,const NG::TranslateOptions & value)3570 void ViewAbstract::SetTranslate(FrameNode* frameNode, const NG::TranslateOptions& value)
3571 {
3572     ACE_UPDATE_NODE_RENDER_CONTEXT(TransformTranslate, value, frameNode);
3573 }
3574 
SetRotate(const NG::Vector5F & value)3575 void ViewAbstract::SetRotate(const NG::Vector5F& value)
3576 {
3577     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3578         return;
3579     }
3580     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3581     SetRotate(frameNode, value);
3582 }
3583 
SetRotateAngle(const NG::Vector4F & value)3584 void ViewAbstract::SetRotateAngle(const NG::Vector4F& value)
3585 {
3586     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3587         return;
3588     }
3589     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3590     SetRotateAngle(frameNode, value);
3591 }
3592 
SetRotate(FrameNode * frameNode,const NG::Vector5F & value)3593 void ViewAbstract::SetRotate(FrameNode* frameNode, const NG::Vector5F& value)
3594 {
3595     CHECK_NULL_VOID(frameNode);
3596     auto renderContext = frameNode->GetRenderContext();
3597     CHECK_NULL_VOID(renderContext);
3598     if (renderContext->HasTransformRotateAngle()) {
3599         renderContext->ResetTransformRotate();
3600         renderContext->ResetTransformRotateAngle();
3601     }
3602     renderContext->UpdateTransformRotate(value);
3603 }
3604 
SetRotateAngle(FrameNode * frameNode,const NG::Vector4F & value)3605 void ViewAbstract::SetRotateAngle(FrameNode* frameNode, const NG::Vector4F& value)
3606 {
3607     CHECK_NULL_VOID(frameNode);
3608     auto renderContext = frameNode->GetRenderContext();
3609     CHECK_NULL_VOID(renderContext);
3610     if (renderContext->HasTransformRotate()) {
3611         renderContext->ResetTransformRotate();
3612         renderContext->ResetTransformRotateAngle();
3613     }
3614     renderContext->UpdateTransformRotateAngle(value);
3615 }
3616 
SetTransformMatrix(const Matrix4 & matrix)3617 void ViewAbstract::SetTransformMatrix(const Matrix4& matrix)
3618 {
3619     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3620         return;
3621     }
3622     ACE_UPDATE_RENDER_CONTEXT(TransformMatrix, matrix);
3623 }
3624 
UpdatePopupParamResource(const RefPtr<PopupParam> & param,const RefPtr<FrameNode> & frameNode)3625 void ViewAbstract::UpdatePopupParamResource(const RefPtr<PopupParam>& param, const RefPtr<FrameNode>& frameNode)
3626 {
3627 #ifndef ACE_UNITTEST
3628     if (SystemProperties::ConfigChangePerform()) {
3629         CHECK_NULL_VOID(frameNode);
3630         PopupType type = POPUPTYPE_TEXTCOLOR;
3631         auto textColorResourceObject = param->GetTextColorResourceObject();
3632         ViewAbstractModel::GetInstance()->CreateWithResourceObj(frameNode, textColorResourceObject, type);
3633         auto popupColorResourceObject = param->GetPopupColorResourceObject();
3634         type = POPUPTYPE_POPUPCOLOR;
3635         ViewAbstractModel::GetInstance()->CreateWithResourceObj(frameNode, popupColorResourceObject, type);
3636         type = POPUPTYPE_MASKCOLOR;
3637         if (!param->GetIsWithTheme()) {
3638             auto maskColorResourceObject = param->GetMaskColorResourceObject();
3639             ViewAbstractModel::GetInstance()->CreateWithResourceObj(frameNode, maskColorResourceObject, type);
3640         }
3641         auto maskResourceObject = param->GetMaskResourceObject();
3642         ViewAbstractModel::GetInstance()->CreateWithResourceObj(frameNode, maskResourceObject);
3643         auto widthResourceObject = param->GetWidthResourceObject();
3644         PopupOptionsType optionsType = POPUP_OPTIONTYPE_WIDTH;
3645         ViewAbstractModel::GetInstance()->CreateWithResourceObj(frameNode, widthResourceObject, optionsType);
3646         auto arrowWidthResourceObject = param->GetArrowWidthResourceObject();
3647         optionsType = POPUP_OPTIONTYPE_ARROWWIDTH;
3648         ViewAbstractModel::GetInstance()->CreateWithResourceObj(frameNode, arrowWidthResourceObject, optionsType);
3649         auto arrowHeightResourceObject = param->GetArrowHeightResourceObject();
3650         optionsType = POPUP_OPTIONTYPE_ARROWHEIGHT;
3651         ViewAbstractModel::GetInstance()->CreateWithResourceObj(frameNode, arrowHeightResourceObject, optionsType);
3652         auto radiusResourceObject = param->GetRadiusResourceObject();
3653         optionsType = POPUP_OPTIONTYPE_RADIUS;
3654         ViewAbstractModel::GetInstance()->CreateWithResourceObj(frameNode, radiusResourceObject, optionsType);
3655         auto outLineResourceObject = param->GetOutlineWidthResourceObject();
3656         optionsType = POPUP_OPTIONTYPE_OUTLINEWIDTH;
3657         ViewAbstractModel::GetInstance()->CreateWithResourceObj(frameNode, outLineResourceObject, optionsType);
3658         auto borderResourceObject = param->GetBorderWidthResourceObject();
3659         optionsType = POPUP_OPTIONTYPE_BORDERWIDTH;
3660         ViewAbstractModel::GetInstance()->CreateWithResourceObj(frameNode, borderResourceObject, optionsType);
3661     }
3662 #endif
3663 }
3664 
SetTransform3DMatrix(const Matrix4 & matrix)3665 void ViewAbstract::SetTransform3DMatrix(const Matrix4& matrix)
3666 {
3667     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3668         return;
3669     }
3670     ACE_UPDATE_RENDER_CONTEXT(Transform3DMatrix, matrix);
3671 }
3672 
BindPopup(const RefPtr<PopupParam> & param,const RefPtr<FrameNode> & targetNode,const RefPtr<UINode> & customNode)3673 void ViewAbstract::BindPopup(
3674     const RefPtr<PopupParam>& param, const RefPtr<FrameNode>& targetNode, const RefPtr<UINode>& customNode)
3675 {
3676     TAG_LOGD(AceLogTag::ACE_DIALOG, "bind popup enter");
3677     CHECK_NULL_VOID(targetNode);
3678     auto targetId = targetNode->GetId();
3679     auto targetTag = targetNode->GetTag();
3680     auto context = targetNode->GetContext();
3681     CHECK_NULL_VOID(context);
3682     auto instanceId = context->GetInstanceId();
3683 
3684     auto overlayManager = context->GetOverlayManager();
3685     CHECK_NULL_VOID(overlayManager);
3686     auto popupInfo = overlayManager->GetPopupInfo(targetId);
3687     auto isShow = param->IsShow();
3688     auto isUseCustom = param->IsUseCustom();
3689     auto showInSubWindow = param->IsShowInSubWindow();
3690     auto container = AceEngine::Get().GetContainer(instanceId);
3691     // Do not need change showInSubWindow to false when targetNode is in subwindow.
3692     if (popupInfo.popupNode && container && !container->IsSubContainer()) {
3693         showInSubWindow = false;
3694     } else {
3695         // subwindow model needs to use subContainer to get popupInfo
3696         auto subwindow = SubwindowManager::GetInstance()->GetSubwindowByType(instanceId, SubwindowType::TYPE_POPUP);
3697         if (subwindow) {
3698             subwindow->GetPopupInfoNG(targetId, popupInfo);
3699         }
3700         if (popupInfo.popupNode) {
3701             if (popupInfo.isTips && subwindow) {
3702                 auto overlayManager1 = subwindow->GetOverlayManager();
3703                 CHECK_NULL_VOID(overlayManager1);
3704                 overlayManager1->ErasePopup(targetId);
3705                 popupInfo = {};
3706                 overlayManager1->HideTips(targetId, popupInfo, 0);
3707             } else {
3708                 showInSubWindow = true;
3709             }
3710         }
3711     }
3712     param->SetShowInSubWindow(showInSubWindow);
3713     if (popupInfo.popupNode && popupInfo.isTips) {
3714         // subwindow need to handle
3715         overlayManager->ErasePopup(targetId);
3716         popupInfo = {};
3717         overlayManager->HideTips(targetId, popupInfo, 0);
3718     }
3719     auto popupId = popupInfo.popupId;
3720     auto popupNode = popupInfo.popupNode;
3721     RefPtr<BubblePattern> popupPattern;
3722     if (popupNode) {
3723         popupPattern = popupNode->GetPattern<BubblePattern>();
3724     }
3725 
3726     if (popupInfo.isCurrentOnShow) {
3727         // Entering / Normal / Exiting
3728         bool popupShowing = popupPattern ? popupPattern->IsOnShow() : false;
3729         popupInfo.markNeedUpdate = popupShowing || !isShow;
3730     } else {
3731         // Invisable
3732         if (!isShow) {
3733             TAG_LOGD(AceLogTag::ACE_DIALOG, "Popup is already hidden");
3734             return;
3735         }
3736         popupInfo.markNeedUpdate = true;
3737     }
3738 
3739     // Create new popup.
3740     if (popupInfo.popupId == -1 || !popupNode) {
3741         if (!isUseCustom) {
3742             popupNode = BubbleView::CreateBubbleNode(targetTag, targetId, param);
3743         } else {
3744             CHECK_NULL_VOID(customNode);
3745             popupNode = BubbleView::CreateCustomBubbleNode(targetTag, targetId, customNode, param);
3746         }
3747         if (popupNode) {
3748             popupId = popupNode->GetId();
3749         }
3750 
3751         UpdatePopupParamResource(param, popupNode);
3752         if (!showInSubWindow) {
3753             // erase popup when target node destroy
3754             auto destructor = [id = targetNode->GetId(), weak = AceType::WeakClaim(context)]() {
3755                 auto pipeline = weak.Upgrade();
3756                 CHECK_NULL_VOID(pipeline);
3757                 auto overlayManager = pipeline->GetOverlayManager();
3758                 CHECK_NULL_VOID(overlayManager);
3759                 overlayManager->ErasePopup(id);
3760                 SubwindowManager::GetInstance()->HideSubWindowNG();
3761             };
3762             targetNode->PushDestroyCallbackWithTag(destructor, std::to_string(popupId));
3763         } else {
3764             // erase popup in subwindow when target node destroy
3765             auto destructor = [id = targetNode->GetId(), containerId = instanceId]() {
3766                 auto subwindow = SubwindowManager::GetInstance()->GetSubwindowByType(
3767                     containerId, SubwindowType::TYPE_POPUP);
3768                 CHECK_NULL_VOID(subwindow);
3769                 auto overlayManager = subwindow->GetOverlayManager();
3770                 CHECK_NULL_VOID(overlayManager);
3771                 overlayManager->ErasePopup(id);
3772                 SubwindowManager::GetInstance()->HideSubWindowNG();
3773             };
3774             targetNode->PushDestroyCallbackWithTag(destructor, std::to_string(popupId));
3775         }
3776     } else {
3777         // use param to update PopupParm
3778         if (!isUseCustom) {
3779             BubbleView::UpdatePopupParam(popupId, param, targetNode);
3780             popupNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
3781         } else {
3782             BubbleView::UpdateCustomPopupParam(popupId, param);
3783             popupNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
3784         }
3785     }
3786     // update PopupInfo props
3787     popupInfo.popupId = popupId;
3788     popupInfo.popupNode = popupNode;
3789     popupInfo.isBlockEvent = param->IsBlockEvent();
3790     popupInfo.isAvoidKeyboard = param->GetKeyBoardAvoidMode() == PopupKeyboardAvoidMode::DEFAULT;
3791     if (popupNode) {
3792         popupNode->MarkModifyDone();
3793         popupPattern = popupNode->GetPattern<BubblePattern>();
3794         popupPattern->SetPopupParam(param);
3795         popupPattern->RegisterDoubleBindCallback(param->GetDoubleBindCallback());
3796         auto accessibilityProperty = popupNode->GetAccessibilityProperty<NG::AccessibilityProperty>();
3797         if (accessibilityProperty) {
3798             accessibilityProperty->SetAccessibilityHoverPriority(param->IsBlockEvent());
3799         }
3800     }
3801     popupInfo.focusable = param->GetFocusable();
3802     popupInfo.target = AceType::WeakClaim(AceType::RawPtr(targetNode));
3803     popupInfo.targetSize = SizeF(param->GetTargetSize().Width(), param->GetTargetSize().Height());
3804     popupInfo.targetOffset = OffsetF(param->GetTargetOffset().GetX(), param->GetTargetOffset().GetY());
3805     if (showInSubWindow) {
3806         if (isShow) {
3807             SubwindowManager::GetInstance()->ShowPopupNG(
3808                 targetNode, popupInfo, param->GetOnWillDismiss(), param->GetInteractiveDismiss());
3809         } else {
3810             SubwindowManager::GetInstance()->HidePopupNG(targetId, instanceId);
3811         }
3812         return;
3813     }
3814     if (isShow) {
3815         if (popupInfo.isCurrentOnShow != isShow) {
3816             overlayManager->ShowPopup(targetId, popupInfo, param->GetOnWillDismiss(), param->GetInteractiveDismiss());
3817         }
3818     } else {
3819         overlayManager->HidePopup(targetId, popupInfo);
3820     }
3821 }
3822 
BindTips(const RefPtr<PopupParam> & param,const RefPtr<FrameNode> & targetNode,const RefPtr<SpanString> & spanString)3823 void ViewAbstract::BindTips(
3824     const RefPtr<PopupParam>& param, const RefPtr<FrameNode>& targetNode, const RefPtr<SpanString>& spanString)
3825 {
3826     CHECK_NULL_VOID(param);
3827     CHECK_NULL_VOID(targetNode);
3828     auto targetId = targetNode->GetId();
3829     auto targetTag = targetNode->GetTag();
3830     auto context = targetNode->GetContext();
3831     CHECK_NULL_VOID(context);
3832     auto instanceId = context->GetInstanceId();
3833     auto overlayManager = context->GetOverlayManager();
3834     CHECK_NULL_VOID(overlayManager);
3835     auto tipsInfo = overlayManager->GetPopupInfo(targetId);
3836     if (tipsInfo.isTips) {
3837         return;
3838     }
3839     auto showInSubWindow = param->IsShowInSubWindow();
3840     if (tipsInfo.popupNode) {
3841         showInSubWindow = false;
3842     } else {
3843         auto subwindow = SubwindowManager::GetInstance()->GetSubwindowByType(instanceId, SubwindowType::TYPE_TIPS);
3844         if (subwindow) {
3845             subwindow->GetPopupInfoNG(targetId, tipsInfo);
3846         }
3847         if (tipsInfo.popupNode) {
3848             showInSubWindow = true;
3849         }
3850     }
3851     targetNode->SetBindTips(true);
3852     HandleHoverTipsInfo(param, targetNode, tipsInfo, showInSubWindow, spanString);
3853 }
3854 
HandleHoverTipsInfo(const RefPtr<PopupParam> & param,const RefPtr<FrameNode> & targetNode,PopupInfo & tipsInfo,bool showInSubWindow,const RefPtr<SpanString> & spanString)3855 void ViewAbstract::HandleHoverTipsInfo(const RefPtr<PopupParam>& param, const RefPtr<FrameNode>& targetNode,
3856     PopupInfo& tipsInfo, bool showInSubWindow, const RefPtr<SpanString>& spanString)
3857 {
3858     CHECK_NULL_VOID(param);
3859     CHECK_NULL_VOID(targetNode);
3860     auto targetId = targetNode->GetId();
3861     auto targetTag = targetNode->GetTag();
3862     auto popupId = tipsInfo.popupId;
3863     auto popupNode = tipsInfo.popupNode;
3864     auto context = targetNode->GetContext();
3865     CHECK_NULL_VOID(context);
3866     auto instanceId = context->GetInstanceId();
3867     if (!tipsInfo.isTips && popupNode) {
3868         return;
3869     }
3870     RefPtr<BubblePattern> popupPattern;
3871     tipsInfo.markNeedUpdate = true;
3872     popupNode = BubbleView::CreateBubbleNode(targetTag, targetId, param, spanString);
3873     popupId = popupNode ? popupNode->GetId() : popupId;
3874     if (!showInSubWindow) {
3875         auto destructor = [id = targetNode->GetId()]() {
3876             auto pipeline = NG::PipelineContext::GetCurrentContext();
3877             CHECK_NULL_VOID(pipeline);
3878             auto overlayManager = pipeline->GetOverlayManager();
3879             CHECK_NULL_VOID(overlayManager);
3880             overlayManager->ErasePopup(id);
3881             SubwindowManager::GetInstance()->HideSubWindowNG();
3882         };
3883         targetNode->PushDestroyCallbackWithTag(destructor, std::to_string(popupId));
3884     } else {
3885         auto destructor = [id = targetNode->GetId(), containerId = instanceId]() {
3886             auto subwindow =
3887                 SubwindowManager::GetInstance()->GetSubwindowByType(containerId, SubwindowType::TYPE_TIPS);
3888             CHECK_NULL_VOID(subwindow);
3889             auto overlayManager = subwindow->GetOverlayManager();
3890             CHECK_NULL_VOID(overlayManager);
3891             overlayManager->ErasePopup(id);
3892             SubwindowManager::GetInstance()->HideSubWindowNG();
3893         };
3894         targetNode->PushDestroyCallbackWithTag(destructor, std::to_string(popupId));
3895     }
3896     UpdateTipsInfo(tipsInfo, popupId, popupNode, param, true);
3897     if (popupNode) {
3898         popupNode->MarkModifyDone();
3899         auto accessibilityProperty = popupNode->GetAccessibilityProperty<NG::AccessibilityProperty>();
3900         if (accessibilityProperty) {
3901             accessibilityProperty->SetAccessibilityHoverPriority(param->IsBlockEvent());
3902         }
3903     }
3904     AddHoverEventForTips(param, targetNode, tipsInfo, showInSubWindow);
3905 }
3906 
UpdateTipsInfo(PopupInfo & tipsInfo,int32_t popupId,const RefPtr<FrameNode> & popupNode,const RefPtr<PopupParam> & param,bool isAvoidKeyboard)3907 void ViewAbstract::UpdateTipsInfo(PopupInfo& tipsInfo, int32_t popupId, const RefPtr<FrameNode>& popupNode,
3908     const RefPtr<PopupParam>& param, bool isAvoidKeyboard)
3909 {
3910     tipsInfo.popupId = popupId;
3911     tipsInfo.popupNode = popupNode;
3912     tipsInfo.isBlockEvent = param->IsBlockEvent();
3913     tipsInfo.isAvoidKeyboard = isAvoidKeyboard;
3914     tipsInfo.isTips = true;
3915 }
3916 
AddHoverEventForTips(const RefPtr<PopupParam> & param,const RefPtr<FrameNode> & targetNode,PopupInfo & tipsInfo,bool showInSubWindow)3917 void ViewAbstract::AddHoverEventForTips(
3918     const RefPtr<PopupParam>& param, const RefPtr<FrameNode>& targetNode, PopupInfo& tipsInfo, bool showInSubWindow)
3919 {
3920     tipsInfo.disappearingTimeWithContinuousOperation = param->GetDisappearingTimeWithContinuousOperation();
3921     tipsInfo.focusable = param->GetFocusable();
3922     tipsInfo.target = AceType::WeakClaim(AceType::RawPtr(targetNode));
3923     tipsInfo.targetSize = SizeF(param->GetTargetSize().Width(), param->GetTargetSize().Height());
3924     tipsInfo.targetOffset = OffsetF(param->GetTargetOffset().GetX(), param->GetTargetOffset().GetY());
3925     auto popupId = tipsInfo.popupId;
3926     auto popupNode = tipsInfo.popupNode;
3927     CHECK_NULL_VOID(popupNode);
3928     auto targetId = targetNode->GetId();
3929     auto context = targetNode->GetContext();
3930     CHECK_NULL_VOID(context);
3931     auto containerId = context->GetInstanceId();
3932     auto overlayManager = context->GetOverlayManager();
3933     auto eventHub = targetNode->GetOrCreateEventHub<EventHub>();
3934     CHECK_NULL_VOID(eventHub);
3935     auto inputHub = eventHub->GetOrCreateInputEventHub();
3936     CHECK_NULL_VOID(inputHub);
3937     auto hoverTask = [targetNode, targetId, tipsInfo, param, overlayManager, showInSubWindow, popupId, popupNode,
3938                          containerId](bool isHover) {
3939         if (isHover && !overlayManager->GetPopupInfo(targetId).isTips &&
3940             overlayManager->GetPopupInfo(targetId).popupNode) {
3941             return;
3942         }
3943         if (isHover) {
3944             BubbleView::UpdatePopupParam(popupId, param, targetNode);
3945             popupNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
3946             if (showInSubWindow) {
3947                 SubwindowManager::GetInstance()->ShowTipsNG(
3948                     targetNode, tipsInfo, param->GetAppearingTime(), param->GetAppearingTimeWithContinuousOperation());
3949                 return;
3950             }
3951             overlayManager->ShowTips(
3952                 targetId, tipsInfo, param->GetAppearingTime(), param->GetAppearingTimeWithContinuousOperation(), false);
3953         } else {
3954             if (showInSubWindow) {
3955                 SubwindowManager::GetInstance()->HideTipsNG(targetId, param->GetDisappearingTime(), containerId);
3956                 return;
3957             }
3958             overlayManager->HideTips(targetId, tipsInfo, param->GetDisappearingTime());
3959         }
3960     };
3961     auto hoverEvent = AceType::MakeRefPtr<InputEvent>(std::move(hoverTask));
3962     hoverEvent->SetIstips(true);
3963     inputHub->RemoveAllTipsHoverEvents();
3964     inputHub->AddOnHoverEvent(hoverEvent);
3965     if (param->GetAnchorType() == TipsAnchorType::CURSOR) {
3966         AddMouseEventForTips(targetNode, tipsInfo);
3967     }
3968 }
3969 
AddMouseEventForTips(const RefPtr<FrameNode> & targetNode,PopupInfo & tipsInfo)3970 void ViewAbstract::AddMouseEventForTips(const RefPtr<FrameNode>& targetNode, PopupInfo& tipsInfo)
3971 {
3972     auto eventHub = targetNode->GetEventHub<EventHub>();
3973     CHECK_NULL_VOID(eventHub);
3974     auto inputHub = eventHub->GetOrCreateInputEventHub();
3975     CHECK_NULL_VOID(inputHub);
3976     auto context = targetNode->GetContext();
3977     CHECK_NULL_VOID(context);
3978     auto mouseTask = [popupNode = AceType::WeakClaim(AceType::RawPtr(tipsInfo.popupNode))](MouseInfo& info) {
3979         auto popup = popupNode.Upgrade();
3980         CHECK_NULL_VOID(popup);
3981         auto pattern = popup->GetPattern<BubblePattern>();
3982         CHECK_NULL_VOID(pattern);
3983         pattern->SetMouseOffset(info.GetScreenLocation());
3984     };
3985     auto mouseEvent = AceType::MakeRefPtr<InputEvent>(std::move(mouseTask));
3986     mouseEvent->SetIstips(true);
3987     mouseEvent->SetTipsFollowCursor(true);
3988     inputHub->RemoveAllTipsMouseEvents();
3989     inputHub->AddOnMouseEvent(mouseEvent);
3990 }
3991 
GetCurOverlayManager(const RefPtr<UINode> & node)3992 RefPtr<OverlayManager> ViewAbstract::GetCurOverlayManager(const RefPtr<UINode>& node)
3993 {
3994     auto context = node->GetContextWithCheck();
3995     CHECK_NULL_RETURN(context, nullptr);
3996     if (GetTargetNodeIsInSubwindow(node)) {
3997         auto instanceId = context->GetInstanceId();
3998         auto subwindow = SubwindowManager::GetInstance()->GetSubwindowByType(instanceId, SubwindowType::TYPE_MENU);
3999         if (subwindow) {
4000             auto overlayManager = subwindow->GetOverlayManager();
4001             return overlayManager;
4002         } else {
4003             return nullptr;
4004         }
4005     }
4006     auto overlayManager = context->GetOverlayManager();
4007     return overlayManager;
4008 }
4009 
GetTargetNodeIsInSubwindow(const RefPtr<UINode> & targetNode)4010 bool ViewAbstract::GetTargetNodeIsInSubwindow(const RefPtr<UINode>& targetNode)
4011 {
4012     CHECK_NULL_RETURN(targetNode, false);
4013     auto pipelineContext = targetNode->GetContext();
4014     CHECK_NULL_RETURN(pipelineContext, false);
4015     auto instanceId = pipelineContext->GetInstanceId();
4016     auto aceContainer = AceEngine::Get().GetContainer(instanceId);
4017     CHECK_NULL_RETURN(aceContainer, false);
4018     return aceContainer->IsSubContainer();
4019 }
4020 
OpenPopup(const RefPtr<PopupParam> & param,const RefPtr<UINode> & customNode)4021 int32_t ViewAbstract::OpenPopup(const RefPtr<PopupParam>& param, const RefPtr<UINode>& customNode)
4022 {
4023     if (!param) {
4024         TAG_LOGE(AceLogTag::ACE_DIALOG, "The param of popup is null.");
4025         return ERROR_CODE_INTERNAL_ERROR;
4026     }
4027     if (!customNode) {
4028         TAG_LOGE(AceLogTag::ACE_DIALOG, "The customNode of popup is null.");
4029         return ERROR_CODE_DIALOG_CONTENT_ERROR;
4030     }
4031     int32_t targetId = StringUtils::StringToInt(param->GetTargetId(), -1);
4032     if (targetId < 0) {
4033         TAG_LOGE(AceLogTag::ACE_DIALOG, "The targetId is error.");
4034         return ERROR_CODE_TARGET_INFO_NOT_EXIST;
4035     }
4036     auto targetNode = ElementRegister::GetInstance()->GetSpecificItemById<NG::FrameNode>(targetId);
4037     if (!targetNode) {
4038         TAG_LOGE(AceLogTag::ACE_DIALOG, "The targetNode does not exist when oepn popup.");
4039         return ERROR_CODE_TARGET_INFO_NOT_EXIST;
4040     }
4041     if (!targetNode->IsOnMainTree()) {
4042         TAG_LOGE(AceLogTag::ACE_DIALOG, "The targetNode does not on main tree.");
4043         return ERROR_CODE_TARGET_NOT_ON_COMPONENT_TREE;
4044     }
4045     auto popupInfo = BubbleView::GetPopupInfoWithCustomNode(customNode);
4046     if (popupInfo.popupNode) {
4047         TAG_LOGE(AceLogTag::ACE_DIALOG, "The customNode of popup is already existed.");
4048         return ERROR_CODE_DIALOG_CONTENT_ALREADY_EXIST;
4049     }
4050     auto overlayManager = BubbleView::GetPopupOverlayManager(customNode, targetId);
4051     if (overlayManager) {
4052         auto popupInfo = overlayManager->GetPopupInfo(targetId);
4053         if (popupInfo.popupNode) {
4054             popupInfo.markNeedUpdate = true;
4055             overlayManager->HidePopup(targetId, popupInfo, true);
4056         }
4057     }
4058     BindPopup(param, targetNode, customNode);
4059     popupInfo = BubbleView::GetPopupInfoWithTargetId(customNode, targetId);
4060     if (!popupInfo.popupNode) {
4061         TAG_LOGE(AceLogTag::ACE_DIALOG, "The popupNode of popup is null.");
4062         return ERROR_CODE_INTERNAL_ERROR;
4063     }
4064     auto popupPattern = popupInfo.popupNode->GetPattern<BubblePattern>();
4065     if (!popupPattern) {
4066         TAG_LOGE(AceLogTag::ACE_DIALOG, "The popupPattern does not exist.");
4067         return ERROR_CODE_INTERNAL_ERROR;
4068     }
4069     popupPattern->SetCustomNode(AceType::WeakClaim(AceType::RawPtr(customNode)));
4070     return ERROR_CODE_NO_ERROR;
4071 }
4072 
UpdatePopup(const RefPtr<PopupParam> & param,const RefPtr<UINode> & customNode)4073 int32_t ViewAbstract::UpdatePopup(const RefPtr<PopupParam>& param, const RefPtr<UINode>& customNode)
4074 {
4075     if (!param) {
4076         TAG_LOGE(AceLogTag::ACE_DIALOG, "The param of popup is null.");
4077         return ERROR_CODE_INTERNAL_ERROR;
4078     }
4079     if (!customNode) {
4080         TAG_LOGE(AceLogTag::ACE_DIALOG, "The customNode of popup is null.");
4081         return ERROR_CODE_DIALOG_CONTENT_ERROR;
4082     }
4083     int32_t targetId = StringUtils::StringToInt(param->GetTargetId(), -1);
4084     if (targetId < 0) {
4085         TAG_LOGE(AceLogTag::ACE_DIALOG, "The targetId is error.");
4086         return ERROR_CODE_INTERNAL_ERROR;
4087     }
4088     auto targetNode = ElementRegister::GetInstance()->GetSpecificItemById<NG::FrameNode>(targetId);
4089     if (!targetNode) {
4090         TAG_LOGE(AceLogTag::ACE_DIALOG, "The targetNode does not exist when update popup.");
4091         return ERROR_CODE_INTERNAL_ERROR;
4092     }
4093     auto popupInfo = BubbleView::GetPopupInfoWithTargetId(customNode, targetId);
4094     if (!popupInfo.popupNode) {
4095         TAG_LOGE(AceLogTag::ACE_DIALOG, "The popupNode of popup is null.");
4096         return ERROR_CODE_INTERNAL_ERROR;
4097     }
4098     if (!popupInfo.isCurrentOnShow) {
4099         TAG_LOGE(AceLogTag::ACE_DIALOG, "The popup is not on show.");
4100         return ERROR_CODE_INTERNAL_ERROR;
4101     }
4102     BubbleView::ResetBubbleProperty(popupInfo.popupNode->GetId());
4103     BindPopup(param, targetNode, customNode);
4104     return ERROR_CODE_NO_ERROR;
4105 }
4106 
ClosePopup(const RefPtr<UINode> & customNode)4107 int32_t ViewAbstract::ClosePopup(const RefPtr<UINode>& customNode)
4108 {
4109     if (!customNode) {
4110         TAG_LOGE(AceLogTag::ACE_DIALOG, "The customNode of popup is null.");
4111         return ERROR_CODE_DIALOG_CONTENT_ERROR;
4112     }
4113     auto param = AceType::MakeRefPtr<PopupParam>();
4114     if (!param) {
4115         TAG_LOGE(AceLogTag::ACE_DIALOG, "The popupParam is null.");
4116         return ERROR_CODE_INTERNAL_ERROR;
4117     }
4118     auto result = GetPopupParam(param, customNode);
4119     if (result != ERROR_CODE_NO_ERROR) {
4120         TAG_LOGE(AceLogTag::ACE_DIALOG, "GetPopupParam failed");
4121         return result;
4122     }
4123     int32_t targetId = StringUtils::StringToInt(param->GetTargetId(), -1);
4124     if (targetId < 0) {
4125         TAG_LOGE(AceLogTag::ACE_DIALOG, "The targetId is error.");
4126         return ERROR_CODE_INTERNAL_ERROR;
4127     }
4128     auto overlayManager = BubbleView::GetPopupOverlayManager(customNode, targetId);
4129     if (!overlayManager) {
4130         TAG_LOGE(AceLogTag::ACE_DIALOG, "The overlayManager of popup is null.");
4131         return ERROR_CODE_INTERNAL_ERROR;
4132     }
4133     auto popupInfo = overlayManager->GetPopupInfo(targetId);
4134     if (!popupInfo.popupNode) {
4135         TAG_LOGE(AceLogTag::ACE_DIALOG, "The popupNode of popup is null.");
4136         return ERROR_CODE_INTERNAL_ERROR;
4137     }
4138     if (!popupInfo.isCurrentOnShow) {
4139         TAG_LOGE(AceLogTag::ACE_DIALOG, "The popup is not on show.");
4140         return ERROR_CODE_DIALOG_CONTENT_NOT_FOUND;
4141     }
4142     popupInfo.markNeedUpdate = true;
4143     overlayManager->HidePopup(targetId, popupInfo);
4144     return ERROR_CODE_NO_ERROR;
4145 }
4146 
GetPopupParam(RefPtr<PopupParam> & param,const RefPtr<UINode> & customNode)4147 int32_t ViewAbstract::GetPopupParam(RefPtr<PopupParam>& param, const RefPtr<UINode>& customNode)
4148 {
4149     CHECK_NULL_RETURN(param, ERROR_CODE_INTERNAL_ERROR);
4150     CHECK_NULL_RETURN(customNode, ERROR_CODE_DIALOG_CONTENT_ERROR);
4151     auto popupInfo = BubbleView::GetPopupInfoWithCustomNode(customNode);
4152     CHECK_NULL_RETURN(popupInfo.popupNode, ERROR_CODE_DIALOG_CONTENT_NOT_FOUND);
4153     auto popupPattern = popupInfo.popupNode->GetPattern<BubblePattern>();
4154     CHECK_NULL_RETURN(popupPattern, ERROR_CODE_INTERNAL_ERROR);
4155     param = popupPattern->GetPopupParam();
4156     CHECK_NULL_RETURN(param, ERROR_CODE_INTERNAL_ERROR);
4157     int32_t targetId = StringUtils::StringToInt(param->GetTargetId(), -1);
4158     if (targetId < 0) {
4159         return ERROR_CODE_INTERNAL_ERROR;
4160     }
4161     return ERROR_CODE_NO_ERROR;
4162 }
4163 
DismissPopup()4164 void ViewAbstract::DismissPopup()
4165 {
4166     auto context = PipelineContext::GetCurrentContext();
4167     CHECK_NULL_VOID(context);
4168     auto overlayManager = context->GetOverlayManager();
4169     CHECK_NULL_VOID(overlayManager);
4170     overlayManager->DismissPopup();
4171 }
4172 
DismissDialog()4173 void ViewAbstract::DismissDialog()
4174 {
4175     auto context = PipelineContext::GetCurrentContext();
4176     CHECK_NULL_VOID(context);
4177     auto overlayManager = context->GetOverlayManager();
4178     CHECK_NULL_VOID(overlayManager);
4179     auto rootNode = overlayManager->GetRootNode().Upgrade();
4180     CHECK_NULL_VOID(rootNode);
4181     RefPtr<FrameNode> dialogNode;
4182     auto dialogId = DialogManager::GetInstance().GetDismissDialogId();
4183     auto dialogTag = DialogManager::GetInstance().GetDialogTag();
4184     if (dialogId && !dialogTag.empty()) {
4185         dialogNode = FrameNode::GetFrameNodeOnly(dialogTag, dialogId);
4186     }
4187     if (!dialogNode) {
4188         if (overlayManager->GetDismissDialogId()) {
4189             dialogNode = overlayManager->GetDialog(overlayManager->GetDismissDialogId());
4190         } else {
4191             dialogNode = AceType::DynamicCast<FrameNode>(rootNode->GetLastChild());
4192         }
4193     }
4194     CHECK_NULL_VOID(dialogNode);
4195     auto pattern = dialogNode->GetPattern();
4196     CHECK_NULL_VOID(pattern);
4197     auto dialogPattern = AceType::DynamicCast<DialogPattern>(pattern);
4198     if (dialogPattern) {
4199         dialogPattern->OverlayDismissDialog(dialogNode);
4200         UiSessionManager::GetInstance()->ReportComponentChangeEvent("onVisibleChange", "destroy");
4201     }
4202 }
4203 
ShowMenuPreview(const RefPtr<FrameNode> & targetNode,const RefPtr<FrameNode> & wrapperNode,NG::MenuParam & menuParam)4204 void ViewAbstract::ShowMenuPreview(
4205     const RefPtr<FrameNode>& targetNode, const RefPtr<FrameNode>& wrapperNode, NG::MenuParam& menuParam)
4206 {
4207 #ifdef PREVIEW
4208     menuParam.previewMode = MenuPreviewMode::NONE;
4209 #endif
4210     CHECK_NULL_VOID(targetNode);
4211     CHECK_NULL_VOID(wrapperNode);
4212     auto menuWrapperPattern = wrapperNode->GetPattern<NG::MenuWrapperPattern>();
4213     CHECK_NULL_VOID(menuWrapperPattern);
4214     if (menuParam.previewMode == MenuPreviewMode::IMAGE || menuParam.isShowHoverImage) {
4215         ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, IsBindOverlay, true, targetNode);
4216         auto context = targetNode->GetRenderContext();
4217         CHECK_NULL_VOID(context);
4218         auto eventHub = targetNode->GetOrCreateEventHub<EventHub>();
4219         CHECK_NULL_VOID(eventHub);
4220         auto gestureHub = eventHub->GetGestureEventHub();
4221         CHECK_NULL_VOID(gestureHub);
4222         auto pixelMap = context->GetThumbnailPixelMap();
4223         CHECK_NULL_VOID(pixelMap);
4224         gestureHub->SetPixelMap(pixelMap);
4225         menuWrapperPattern->SetIsShowFromUser(true);
4226         MenuView::GetMenuPixelMap(targetNode, menuParam, wrapperNode);
4227     }
4228 }
4229 
OpenMenu(NG::MenuParam & menuParam,const RefPtr<NG::UINode> & customNode,const int32_t & targetId)4230 int32_t ViewAbstract::OpenMenu(NG::MenuParam& menuParam, const RefPtr<NG::UINode>& customNode, const int32_t& targetId)
4231 {
4232     if (!customNode) {
4233         TAG_LOGE(AceLogTag::ACE_DIALOG, "Content of menu is null.");
4234         return ERROR_CODE_DIALOG_CONTENT_ERROR;
4235     }
4236     auto targetNode = ElementRegister::GetInstance()->GetSpecificItemById<NG::FrameNode>(targetId);
4237     if (!targetNode) {
4238         TAG_LOGE(AceLogTag::ACE_DIALOG, "The targetNode does not exist.");
4239         return ERROR_CODE_TARGET_INFO_NOT_EXIST;
4240     }
4241     if (!targetNode->IsOnMainTree()) {
4242         TAG_LOGE(AceLogTag::ACE_DIALOG, "The targetNode does not on main tree.");
4243         return ERROR_CODE_TARGET_NOT_ON_COMPONENT_TREE;
4244     }
4245     auto overlayManager = GetCurOverlayManager(customNode);
4246     CHECK_NULL_RETURN(overlayManager, ERROR_CODE_INTERNAL_ERROR);
4247     if (overlayManager->GetMenuNodeWithExistContent(customNode)) {
4248         TAG_LOGW(AceLogTag::ACE_DIALOG, "Content of menu already existed.");
4249         return ERROR_CODE_DIALOG_CONTENT_ALREADY_EXIST;
4250     }
4251     auto isShowMenu = overlayManager->GetMenuNode(targetNode->GetId());
4252     if (isShowMenu) {
4253         // The menu is already opened, close the previous menu and open the new menu
4254         overlayManager->HideMenu(isShowMenu, targetNode->GetId(), false, HideMenuType::OPEN_MENU);
4255     }
4256     auto wrapperNode = NG::MenuView::Create(customNode, targetNode->GetId(), targetNode->GetTag(), menuParam);
4257     CHECK_NULL_RETURN(wrapperNode, ERROR_CODE_INTERNAL_ERROR);
4258     ShowMenuPreview(targetNode, wrapperNode, menuParam);
4259     auto menuWrapperPattern = wrapperNode->GetPattern<NG::MenuWrapperPattern>();
4260     CHECK_NULL_RETURN(menuWrapperPattern, ERROR_CODE_INTERNAL_ERROR);
4261     menuWrapperPattern->RegisterMenuCallback(wrapperNode, menuParam);
4262     menuWrapperPattern->SetMenuTransitionEffect(wrapperNode, menuParam);
4263     auto menu = menuWrapperPattern->GetMenu();
4264     CHECK_NULL_RETURN(menu, ERROR_CODE_INTERNAL_ERROR);
4265     auto menuPattern = AceType::DynamicCast<MenuPattern>(menu->GetPattern());
4266     CHECK_NULL_RETURN(menuPattern, ERROR_CODE_INTERNAL_ERROR);
4267     auto node = WeakPtr<UINode>(customNode);
4268     menuPattern->SetCustomNode(node);
4269     auto pipelineContext = targetNode->GetContext();
4270     CHECK_NULL_RETURN(pipelineContext, ERROR_CODE_INTERNAL_ERROR);
4271     menuWrapperPattern->SetIsOpenMenu(true);
4272     NG::OffsetF menuPosition { menuParam.positionOffset.GetX(), menuParam.positionOffset.GetY() };
4273     if (menuParam.anchorPosition.has_value()) {
4274         NG::OffsetF targetNodePosition = targetNode->GetPositionToWindowWithTransform();
4275         menuPosition = { menuParam.anchorPosition->GetX() + menuParam.positionOffset.GetX() +
4276                         targetNodePosition.GetX(),
4277                         menuParam.anchorPosition->GetY() + menuParam.positionOffset.GetY() +
4278                         targetNodePosition.GetY() };
4279     }
4280     if (menuParam.isShowInSubWindow && targetNode->GetTag() != V2::SELECT_ETS_TAG) {
4281         SubwindowManager::GetInstance()->ShowMenuNG(wrapperNode, menuParam, targetNode, menuPosition);
4282         return ERROR_CODE_NO_ERROR;
4283     }
4284     overlayManager->ShowMenu(targetNode->GetId(), menuPosition, wrapperNode);
4285     return ERROR_CODE_NO_ERROR;
4286 }
4287 
UpdateMenu(const NG::MenuParam & menuParam,const RefPtr<NG::UINode> & customNode)4288 int32_t ViewAbstract::UpdateMenu(const NG::MenuParam& menuParam, const RefPtr<NG::UINode>& customNode)
4289 {
4290     if (!customNode) {
4291         TAG_LOGE(AceLogTag::ACE_DIALOG, "Content of menu is null.");
4292         return ERROR_CODE_DIALOG_CONTENT_ERROR;
4293     }
4294     auto overlayManager = GetCurOverlayManager(customNode);
4295     if (!overlayManager) {
4296         return ERROR_CODE_INTERNAL_ERROR;
4297     }
4298     auto menuWrapperNode = overlayManager->GetMenuNodeWithExistContent(customNode);
4299     if (!menuWrapperNode) {
4300         return ERROR_CODE_DIALOG_CONTENT_NOT_FOUND;
4301     }
4302     auto wrapperPattern = AceType::DynamicCast<MenuWrapperPattern>(menuWrapperNode->GetPattern());
4303     CHECK_NULL_RETURN(wrapperPattern, ERROR_CODE_INTERNAL_ERROR);
4304     auto menu = wrapperPattern->GetMenu();
4305     CHECK_NULL_RETURN(menu, ERROR_CODE_INTERNAL_ERROR);
4306     wrapperPattern->SetMenuParam(menuParam);
4307     MenuView::UpdateMenuParam(menuWrapperNode, menu, menuParam);
4308     MenuView::UpdateMenuProperties(menuWrapperNode, menu, menuParam, menuParam.type);
4309     if (menuParam.anchorPosition.has_value()) {
4310         auto menuProperty = menu->GetLayoutProperty<MenuLayoutProperty>();
4311         if (menuProperty) {
4312             auto target = ElementRegister::GetInstance()->
4313                 GetSpecificItemById<NG::FrameNode>(wrapperPattern->GetTargetId());
4314             CHECK_NULL_RETURN(target, ERROR_CODE_INTERNAL_ERROR);
4315             NG::OffsetF targetNodePosition = target->GetPositionToWindowWithTransform();
4316             NG::OffsetF menuPosition = { menuParam.anchorPosition->GetX() + menuParam.positionOffset.GetX() +
4317                                          targetNodePosition.GetX(),
4318                                          menuParam.anchorPosition->GetY() + menuParam.positionOffset.GetY() +
4319                                          targetNodePosition.GetY() };
4320             menuProperty->UpdateMenuOffset(menuPosition);
4321             menuProperty->ResetMenuPlacement();
4322         }
4323     }
4324     auto pipeline = menuWrapperNode->GetContextRefPtr();
4325     if (pipeline) {
4326         wrapperPattern->SetForceUpdateEmbeddedMenu(true);
4327     }
4328     auto menuPattern = AceType::DynamicCast<MenuPattern>(menu->GetPattern());
4329     CHECK_NULL_RETURN(menuPattern, ERROR_CODE_INTERNAL_ERROR);
4330     auto embeddedMenuItems = menuPattern->GetEmbeddedMenuItems();
4331     for (auto iter = embeddedMenuItems.begin(); iter != embeddedMenuItems.end(); ++iter) {
4332         auto menuItemPattern = (*iter)->GetPattern<MenuItemPattern>();
4333         if (!menuItemPattern) {
4334             continue;
4335         }
4336         menuItemPattern->HideEmbedded(false);
4337     }
4338     uint32_t minChildrenSize = 1;
4339     if (menuWrapperNode->GetChildren().size() > minChildrenSize) {
4340         auto subMenu = menuWrapperNode->GetChildren().back();
4341         if (subMenu && subMenu->GetTag() == V2::MENU_ETS_TAG) {
4342             wrapperPattern->HideSubMenu();
4343         }
4344     }
4345     menuWrapperNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_CHILD);
4346     menu->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_CHILD);
4347     if (pipeline) {
4348         pipeline->FlushUITasks();
4349         wrapperPattern->SetForceUpdateEmbeddedMenu(false);
4350     }
4351     return ERROR_CODE_NO_ERROR;
4352 }
4353 
CloseMenu(const RefPtr<UINode> & customNode)4354 int32_t ViewAbstract::CloseMenu(const RefPtr<UINode>& customNode)
4355 {
4356     if (!customNode) {
4357         TAG_LOGE(AceLogTag::ACE_DIALOG, "Content of menu is null.");
4358         return ERROR_CODE_DIALOG_CONTENT_ERROR;
4359     }
4360     auto overlayManager = GetCurOverlayManager(customNode);
4361     if (!overlayManager) {
4362         return ERROR_CODE_INTERNAL_ERROR;
4363     }
4364     auto menuWrapperNode = overlayManager->GetMenuNodeWithExistContent(customNode);
4365     if (!menuWrapperNode) {
4366         return ERROR_CODE_DIALOG_CONTENT_NOT_FOUND;
4367     }
4368     overlayManager->HideMenu(menuWrapperNode, customNode->GetId(), false, HideMenuType::CLOSE_MENU);
4369     return ERROR_CODE_NO_ERROR;
4370 }
4371 
BindMenuWithItems(std::vector<OptionParam> && params,const RefPtr<FrameNode> & targetNode,const NG::OffsetF & offset,const MenuParam & menuParam)4372 void ViewAbstract::BindMenuWithItems(std::vector<OptionParam>&& params, const RefPtr<FrameNode>& targetNode,
4373     const NG::OffsetF& offset, const MenuParam& menuParam)
4374 {
4375     TAG_LOGD(AceLogTag::ACE_DIALOG, "bind menu with items enter");
4376     CHECK_NULL_VOID(targetNode);
4377 
4378     if (params.empty()) {
4379         return;
4380     }
4381     auto menuNode =
4382         MenuView::Create(std::move(params), targetNode->GetId(), targetNode->GetTag(), MenuType::MENU, menuParam);
4383     CHECK_NULL_VOID(menuNode);
4384     auto menuWrapperPattern = menuNode->GetPattern<MenuWrapperPattern>();
4385     CHECK_NULL_VOID(menuWrapperPattern);
4386     menuWrapperPattern->RegisterMenuCallback(menuNode, menuParam);
4387     menuWrapperPattern->SetMenuTransitionEffect(menuNode, menuParam);
4388     auto pipeline = PipelineBase::GetCurrentContext();
4389     CHECK_NULL_VOID(pipeline);
4390     auto theme = pipeline->GetTheme<SelectTheme>();
4391     CHECK_NULL_VOID(theme);
4392     auto expandDisplay = theme->GetExpandDisplay();
4393 
4394     auto pipelineContext = targetNode->GetContext();
4395     CHECK_NULL_VOID(pipelineContext);
4396     auto overlayManager = pipelineContext->GetOverlayManager();
4397     CHECK_NULL_VOID(overlayManager);
4398 
4399     if (expandDisplay && menuParam.isShowInSubWindow && targetNode->GetTag() != V2::SELECT_ETS_TAG) {
4400         SubwindowManager::GetInstance()->ShowMenuNG(menuNode, menuParam, targetNode, offset);
4401         return;
4402     }
4403 
4404     overlayManager->ShowMenu(targetNode->GetId(), offset, menuNode);
4405 }
4406 
BindMenuWithCustomNode(std::function<void ()> && buildFunc,const RefPtr<FrameNode> & targetNode,const NG::OffsetF & offset,MenuParam menuParam,std::function<void ()> && previewBuildFunc)4407 void ViewAbstract::BindMenuWithCustomNode(std::function<void()>&& buildFunc, const RefPtr<FrameNode>& targetNode,
4408     const NG::OffsetF& offset, MenuParam menuParam, std::function<void()>&& previewBuildFunc)
4409 {
4410     if (!buildFunc || !targetNode) {
4411         return;
4412     }
4413 #ifdef PREVIEW
4414     // unable to use the subWindow in the Previewer.
4415     menuParam.type = MenuType::MENU;
4416     menuParam.previewMode = MenuPreviewMode::NONE;
4417 #endif
4418     TAG_LOGD(AceLogTag::ACE_DIALOG, "bind menu with custom node enter %{public}d", menuParam.type);
4419     auto pipeline = PipelineBase::GetCurrentContext();
4420     CHECK_NULL_VOID(pipeline);
4421     auto theme = pipeline->GetTheme<SelectTheme>();
4422     CHECK_NULL_VOID(theme);
4423     auto expandDisplay = theme->GetExpandDisplay();
4424     auto pipelineContext = targetNode->GetContext();
4425     CHECK_NULL_VOID(pipelineContext);
4426     auto overlayManager = pipelineContext->GetOverlayManager();
4427     CHECK_NULL_VOID(overlayManager);
4428     if (menuParam.type == MenuType::CONTEXT_MENU) {
4429         SubwindowManager::GetInstance()->ShowMenuNG(
4430             std::move(buildFunc), std::move(previewBuildFunc), menuParam, targetNode, offset);
4431         return;
4432     }
4433     if (menuParam.type == MenuType::MENU && expandDisplay && menuParam.isShowInSubWindow &&
4434         targetNode->GetTag() != V2::SELECT_ETS_TAG) {
4435         SubwindowManager::GetInstance()->ShowMenuNG(
4436             std::move(buildFunc), std::move(previewBuildFunc), menuParam, targetNode, offset);
4437         return;
4438     }
4439     NG::ScopedViewStackProcessor builderViewStackProcessor;
4440     buildFunc();
4441     auto customNode = NG::ViewStackProcessor::GetInstance()->Finish();
4442     RefPtr<NG::UINode> previewCustomNode;
4443     if (previewBuildFunc && menuParam.previewMode == MenuPreviewMode::CUSTOM) {
4444         previewBuildFunc();
4445         previewCustomNode = NG::ViewStackProcessor::GetInstance()->Finish();
4446     }
4447     auto menuNode =
4448         NG::MenuView::Create(customNode, targetNode->GetId(), targetNode->GetTag(), menuParam, true, previewCustomNode);
4449     auto menuWrapperPattern = menuNode->GetPattern<NG::MenuWrapperPattern>();
4450     CHECK_NULL_VOID(menuWrapperPattern);
4451     menuWrapperPattern->RegisterMenuCallback(menuNode, menuParam);
4452     menuWrapperPattern->SetMenuTransitionEffect(menuNode, menuParam);
4453     overlayManager->ShowMenu(targetNode->GetId(), offset, menuNode);
4454 }
4455 
SetBackdropBlur(const Dimension & radius,const BlurOption & blurOption,const SysOptions & sysOptions)4456 void ViewAbstract::SetBackdropBlur(const Dimension& radius, const BlurOption& blurOption, const SysOptions& sysOptions)
4457 {
4458     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4459         return;
4460     }
4461     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
4462     CHECK_NULL_VOID(frameNode);
4463     auto target = frameNode->GetRenderContext();
4464     if (target) {
4465         if (target->GetBackgroundEffect().has_value()) {
4466             target->UpdateBackgroundEffect(std::nullopt);
4467         }
4468         target->UpdateBackBlur(radius, blurOption, sysOptions);
4469         if (target->GetBackBlurStyle().has_value()) {
4470             target->UpdateBackBlurStyle(std::nullopt);
4471         }
4472     }
4473 }
4474 
SetNodeBackdropBlur(FrameNode * frameNode,const Dimension & radius,const BlurOption & blurOption)4475 void ViewAbstract::SetNodeBackdropBlur(FrameNode *frameNode, const Dimension& radius, const BlurOption& blurOption)
4476 {
4477     CHECK_NULL_VOID(frameNode);
4478     auto target = frameNode->GetRenderContext();
4479     if (target) {
4480         if (target->GetBackgroundEffect().has_value()) {
4481             target->UpdateBackgroundEffect(std::nullopt);
4482         }
4483         if (target->GetBackBlurStyle().has_value()) {
4484             target->UpdateBackBlurStyle(std::nullopt);
4485         }
4486         target->UpdateNodeBackBlur(radius, blurOption);
4487     }
4488 }
4489 
SetBackdropBlur(FrameNode * frameNode,const Dimension & radius,const BlurOption & blurOption,const SysOptions & sysOptions)4490 void ViewAbstract::SetBackdropBlur(
4491     FrameNode* frameNode, const Dimension& radius, const BlurOption& blurOption, const SysOptions& sysOptions)
4492 {
4493     CHECK_NULL_VOID(frameNode);
4494     auto target = frameNode->GetRenderContext();
4495     if (target) {
4496         if (target->GetBackgroundEffect().has_value()) {
4497             target->UpdateBackgroundEffect(std::nullopt);
4498         }
4499         target->UpdateBackBlur(radius, blurOption, sysOptions);
4500         if (target->GetBackBlurStyle().has_value()) {
4501             target->UpdateBackBlurStyle(std::nullopt);
4502         }
4503     }
4504 }
4505 
SetLinearGradientBlur(const NG::LinearGradientBlurPara & blurPara)4506 void ViewAbstract::SetLinearGradientBlur(const NG::LinearGradientBlurPara& blurPara)
4507 {
4508     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4509         return;
4510     }
4511     ACE_UPDATE_RENDER_CONTEXT(LinearGradientBlur, blurPara);
4512 }
4513 
SetDynamicLightUp(float rate,float lightUpDegree)4514 void ViewAbstract::SetDynamicLightUp(float rate, float lightUpDegree)
4515 {
4516     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4517         return;
4518     }
4519     ACE_UPDATE_RENDER_CONTEXT(DynamicLightUpRate, rate);
4520     ACE_UPDATE_RENDER_CONTEXT(DynamicLightUpDegree, lightUpDegree);
4521 }
4522 
SetBgDynamicBrightness(const BrightnessOption & brightnessOption)4523 void ViewAbstract::SetBgDynamicBrightness(const BrightnessOption& brightnessOption)
4524 {
4525     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4526         return;
4527     }
4528     ACE_UPDATE_RENDER_CONTEXT(BgDynamicBrightnessOption, brightnessOption);
4529 }
4530 
SetFgDynamicBrightness(const BrightnessOption & brightnessOption)4531 void ViewAbstract::SetFgDynamicBrightness(const BrightnessOption& brightnessOption)
4532 {
4533     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4534         return;
4535     }
4536     ACE_UPDATE_RENDER_CONTEXT(FgDynamicBrightnessOption, brightnessOption);
4537 }
4538 
SetBlender(const OHOS::Rosen::Blender * blender)4539 void ViewAbstract::SetBlender(const OHOS::Rosen::Blender* blender)
4540 {
4541     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4542         return;
4543     }
4544     ACE_UPDATE_RENDER_CONTEXT(Blender, blender);
4545 }
4546 
SetFrontBlur(const Dimension & radius,const BlurOption & blurOption,const SysOptions & sysOptions)4547 void ViewAbstract::SetFrontBlur(const Dimension& radius, const BlurOption& blurOption, const SysOptions& sysOptions)
4548 {
4549     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4550         return;
4551     }
4552     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
4553     CHECK_NULL_VOID(frameNode);
4554     auto target = frameNode->GetRenderContext();
4555     if (target) {
4556         target->UpdateFrontBlur(radius, blurOption, sysOptions);
4557         if (target->GetFrontBlurStyle().has_value()) {
4558             target->UpdateFrontBlurStyle(std::nullopt);
4559         }
4560     }
4561 }
4562 
SetDynamicDim(float DimDegree)4563 void ViewAbstract::SetDynamicDim(float DimDegree)
4564 {
4565     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4566         return;
4567     }
4568     ACE_UPDATE_RENDER_CONTEXT(DynamicDimDegree, DimDegree);
4569 }
4570 
SetFrontBlur(FrameNode * frameNode,const Dimension & radius,const BlurOption & blurOption,const SysOptions & sysOptions)4571 void ViewAbstract::SetFrontBlur(
4572     FrameNode* frameNode, const Dimension& radius, const BlurOption& blurOption, const SysOptions& sysOptions)
4573 {
4574     CHECK_NULL_VOID(frameNode);
4575     auto target = frameNode->GetRenderContext();
4576     if (target) {
4577         target->UpdateFrontBlur(radius, blurOption, sysOptions);
4578         if (target->GetFrontBlurStyle().has_value()) {
4579             target->UpdateFrontBlurStyle(std::nullopt);
4580         }
4581     }
4582 }
4583 
SetBackShadow(const Shadow & shadow)4584 void ViewAbstract::SetBackShadow(const Shadow& shadow)
4585 {
4586     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4587         return;
4588     }
4589     if (SystemProperties::ConfigChangePerform()) {
4590         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
4591         CHECK_NULL_VOID(frameNode);
4592         auto pattern = frameNode->GetPattern();
4593         CHECK_NULL_VOID(pattern);
4594         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
4595         auto&& updateFunc = [shadow, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
4596             auto frameNode = weak.Upgrade();
4597             CHECK_NULL_VOID(frameNode);
4598             Shadow& shadowValue = const_cast<Shadow&>(shadow);
4599             shadowValue.ReloadResources();
4600             ACE_UPDATE_NODE_RENDER_CONTEXT(BackShadow, shadowValue, frameNode);
4601         };
4602         pattern->AddResObj("shadow", resObj, std::move(updateFunc));
4603     }
4604     ACE_UPDATE_RENDER_CONTEXT(BackShadow, shadow);
4605 }
4606 
SetBackShadow(FrameNode * frameNode,const Shadow & shadow)4607 void ViewAbstract::SetBackShadow(FrameNode* frameNode, const Shadow& shadow)
4608 {
4609     if (SystemProperties::ConfigChangePerform()) {
4610         CHECK_NULL_VOID(frameNode);
4611         auto pattern = frameNode->GetPattern();
4612         CHECK_NULL_VOID(pattern);
4613         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
4614         auto&& updateFunc = [shadow, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
4615             auto frameNode = weak.Upgrade();
4616             CHECK_NULL_VOID(frameNode);
4617             Shadow& shadowValue = const_cast<Shadow&>(shadow);
4618             shadowValue.ReloadResources();
4619             ACE_UPDATE_NODE_RENDER_CONTEXT(BackShadow, shadowValue, frameNode);
4620         };
4621         pattern->AddResObj("shadow", resObj, std::move(updateFunc));
4622     }
4623     ACE_UPDATE_NODE_RENDER_CONTEXT(BackShadow, shadow, frameNode);
4624 }
4625 
SetBlendMode(BlendMode blendMode)4626 void ViewAbstract::SetBlendMode(BlendMode blendMode)
4627 {
4628     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4629         return;
4630     }
4631     ACE_UPDATE_RENDER_CONTEXT(BackBlendMode, blendMode);
4632 }
4633 
SetBlendApplyType(BlendApplyType blendApplyType)4634 void ViewAbstract::SetBlendApplyType(BlendApplyType blendApplyType)
4635 {
4636     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4637         return;
4638     }
4639     ACE_UPDATE_RENDER_CONTEXT(BackBlendApplyType, blendApplyType);
4640 }
4641 
SetLinearGradient(const NG::Gradient & gradient)4642 void ViewAbstract::SetLinearGradient(const NG::Gradient& gradient)
4643 {
4644     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4645         return;
4646     }
4647     if (SystemProperties::ConfigChangePerform()) {
4648         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
4649         CHECK_NULL_VOID(frameNode);
4650         auto pattern = frameNode->GetPattern();
4651         CHECK_NULL_VOID(pattern);
4652         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
4653         auto&& updateFunc = [gradient, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
4654             auto frameNode = weak.Upgrade();
4655             CHECK_NULL_VOID(frameNode);
4656             Gradient& gradientValue = const_cast<Gradient &>(gradient);
4657             gradientValue.ReloadResources();
4658             ACE_UPDATE_NODE_RENDER_CONTEXT(LastGradientType, NG::GradientType::LINEAR, frameNode);
4659             ACE_UPDATE_NODE_RENDER_CONTEXT(LinearGradient, gradientValue, frameNode);
4660         };
4661         pattern->AddResObj("LinearGradient.gradient", resObj, std::move(updateFunc));
4662     }
4663     ACE_UPDATE_RENDER_CONTEXT(LastGradientType, NG::GradientType::LINEAR);
4664     ACE_UPDATE_RENDER_CONTEXT(LinearGradient, gradient);
4665 }
4666 
SetSweepGradient(const NG::Gradient & gradient)4667 void ViewAbstract::SetSweepGradient(const NG::Gradient& gradient)
4668 {
4669     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4670         return;
4671     }
4672     if (SystemProperties::ConfigChangePerform()) {
4673         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
4674         CHECK_NULL_VOID(frameNode);
4675         auto pattern = frameNode->GetPattern();
4676         CHECK_NULL_VOID(pattern);
4677         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
4678         auto&& updateFunc = [gradient, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
4679             auto frameNode = weak.Upgrade();
4680             CHECK_NULL_VOID(frameNode);
4681             Gradient& gradientValue = const_cast<Gradient &>(gradient);
4682             auto sweepGradientPtr = gradientValue.GetSweepGradient();
4683             if (sweepGradientPtr) {
4684                 gradientValue.SetSweepGradient(*sweepGradientPtr);
4685             }
4686             gradientValue.ReloadResources();
4687             ACE_UPDATE_NODE_RENDER_CONTEXT(LastGradientType, NG::GradientType::SWEEP, frameNode);
4688             ACE_UPDATE_NODE_RENDER_CONTEXT(SweepGradient, gradientValue, frameNode);
4689             const auto& target = frameNode->GetRenderContext();
4690             if (target) {
4691                 target->OnSweepGradientUpdate(gradientValue);
4692             }
4693         };
4694         pattern->AddResObj("SweepGradient.gradient", resObj, std::move(updateFunc));
4695     }
4696     ACE_UPDATE_RENDER_CONTEXT(LastGradientType, NG::GradientType::SWEEP);
4697     ACE_UPDATE_RENDER_CONTEXT(SweepGradient, gradient);
4698 }
4699 
SetRadialGradient(const NG::Gradient & gradient)4700 void ViewAbstract::SetRadialGradient(const NG::Gradient& gradient)
4701 {
4702     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4703         return;
4704     }
4705     if (SystemProperties::ConfigChangePerform()) {
4706         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
4707         CHECK_NULL_VOID(frameNode);
4708         auto pattern = frameNode->GetPattern();
4709         CHECK_NULL_VOID(pattern);
4710         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
4711         auto&& updateFunc = [gradient, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
4712             auto frameNode = weak.Upgrade();
4713             CHECK_NULL_VOID(frameNode);
4714             Gradient& gradientValue = const_cast<Gradient &>(gradient);
4715             auto radialGradientPtr = gradientValue.GetRadialGradient();
4716             if (radialGradientPtr) {
4717                 gradientValue.SetRadialGradient(*radialGradientPtr);
4718             }
4719             gradientValue.ReloadResources();
4720             ACE_UPDATE_NODE_RENDER_CONTEXT(LastGradientType, NG::GradientType::RADIAL, frameNode);
4721             ACE_UPDATE_NODE_RENDER_CONTEXT(RadialGradient, gradientValue, frameNode);
4722             frameNode->MarkModifyDone();
4723             frameNode->MarkDirtyNode();
4724         };
4725         pattern->AddResObj("RadialGradient.gradient", resObj, std::move(updateFunc));
4726     }
4727     ACE_UPDATE_RENDER_CONTEXT(LastGradientType, NG::GradientType::RADIAL);
4728     ACE_UPDATE_RENDER_CONTEXT(RadialGradient, gradient);
4729 }
4730 
CreateWithForegroundColorResourceObj(const RefPtr<ResourceObject> & resObj)4731 void ViewAbstract::CreateWithForegroundColorResourceObj(const RefPtr<ResourceObject>& resObj)
4732 {
4733     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
4734     CHECK_NULL_VOID(frameNode);
4735     auto pattern = frameNode->GetPattern<Pattern>();
4736     CHECK_NULL_VOID(pattern);
4737     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
4738         auto frameNode = weak.Upgrade();
4739         CHECK_NULL_VOID(frameNode);
4740         auto pattern = frameNode->GetPattern<Pattern>();
4741         CHECK_NULL_VOID(pattern);
4742         std::string foregroundColor = pattern->GetResCacheMapByKey("foregroundColor");
4743         Color result;
4744         ResourceParseUtils::ParseResColor(resObj, result);
4745         if (foregroundColor.empty()) {
4746             pattern->AddResCache("foregroundColor", result.ColorToString());
4747         }
4748         SetForegroundColor(AceType::RawPtr(frameNode), result);
4749         auto target = frameNode->GetRenderContext();
4750         if (target) {
4751             target->OnForegroundColorUpdate(result);
4752         }
4753         frameNode->MarkModifyDone();
4754         frameNode->MarkDirtyNode();
4755     };
4756     updateFunc(resObj);
4757     pattern->AddResObj("foregroundColor", resObj, std::move(updateFunc));
4758 }
4759 
CreateWithOuterBorderColorResourceObj(const RefPtr<ResourceObject> & resObj)4760 void ViewAbstract::CreateWithOuterBorderColorResourceObj(const RefPtr<ResourceObject>& resObj)
4761 {
4762     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
4763     CHECK_NULL_VOID(frameNode);
4764     auto pattern = frameNode->GetPattern<Pattern>();
4765     CHECK_NULL_VOID(pattern);
4766     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
4767         auto frameNode = weak.Upgrade();
4768         CHECK_NULL_VOID(frameNode);
4769         auto pattern = frameNode->GetPattern<Pattern>();
4770         CHECK_NULL_VOID(pattern);
4771         std::string outerBorderColor = pattern->GetResCacheMapByKey("outerBorderColorRes");
4772         Color result;
4773         ResourceParseUtils::ParseResColor(resObj, result);
4774         if (outerBorderColor.empty()) {
4775             pattern->AddResCache("outerBorderColorRes", result.ColorToString());
4776         }
4777         SetOuterBorderColor(AceType::RawPtr(frameNode), result);
4778     };
4779     updateFunc(resObj);
4780     pattern->AddResObj("outerBorderColorRes", resObj, std::move(updateFunc));
4781 }
4782 
CreateWithOuterBorderRadiusResourceObj(const RefPtr<ResourceObject> & resObj)4783 void ViewAbstract::CreateWithOuterBorderRadiusResourceObj(const RefPtr<ResourceObject>& resObj)
4784 {
4785     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
4786     CHECK_NULL_VOID(frameNode);
4787     auto pattern = frameNode->GetPattern<Pattern>();
4788     CHECK_NULL_VOID(pattern);
4789     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
4790         auto frameNode = weak.Upgrade();
4791         CHECK_NULL_VOID(frameNode);
4792         auto pattern = frameNode->GetPattern<Pattern>();
4793         CHECK_NULL_VOID(pattern);
4794         std::string outerBorderRadius = pattern->GetResCacheMapByKey("outerBorderRadiusRes");
4795         CalcDimension result;
4796         ResourceParseUtils::ParseResDimensionVp(resObj, result);
4797         if (outerBorderRadius.empty()) {
4798             pattern->AddResCache("outerBorderRadiusRes", result.ToString());
4799         }
4800         SetOuterBorderRadius(AceType::RawPtr(frameNode), result);
4801         frameNode->MarkModifyDone();
4802         frameNode->MarkDirtyNode();
4803     };
4804     updateFunc(resObj);
4805     pattern->AddResObj("outerBorderRadiusRes", resObj, std::move(updateFunc));
4806 }
4807 
CreateWithLightColorResourceObj(const RefPtr<ResourceObject> & resObj)4808 void ViewAbstract::CreateWithLightColorResourceObj(const RefPtr<ResourceObject>& resObj)
4809 {
4810     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
4811     CHECK_NULL_VOID(frameNode);
4812     auto pattern = frameNode->GetPattern<Pattern>();
4813     CHECK_NULL_VOID(pattern);
4814     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
4815         auto frameNode = weak.Upgrade();
4816         CHECK_NULL_VOID(frameNode);
4817         auto pattern = frameNode->GetPattern<Pattern>();
4818         CHECK_NULL_VOID(pattern);
4819         std::string lightColor = pattern->GetResCacheMapByKey("LightColorRes");
4820         Color result;
4821         ResourceParseUtils::ParseResColor(resObj, result);
4822         if (lightColor.empty()) {
4823             pattern->AddResCache("LightColorRes", result.ColorToString());
4824         }
4825         ACE_UPDATE_NODE_RENDER_CONTEXT(LightColor, result, frameNode);
4826         frameNode->MarkModifyDone();
4827         frameNode->MarkDirtyNode();
4828     };
4829     updateFunc(resObj);
4830     pattern->AddResObj("LightColorRes", resObj, std::move(updateFunc));
4831 }
4832 
CreateWithOuterBorderWidthResourceObj(const RefPtr<ResourceObject> & resObj)4833 void ViewAbstract::CreateWithOuterBorderWidthResourceObj(const RefPtr<ResourceObject>& resObj)
4834 {
4835     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
4836     CHECK_NULL_VOID(frameNode);
4837     auto pattern = frameNode->GetPattern<Pattern>();
4838     CHECK_NULL_VOID(pattern);
4839     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
4840         auto frameNode = weak.Upgrade();
4841         CHECK_NULL_VOID(frameNode);
4842         auto pattern = frameNode->GetPattern<Pattern>();
4843         CHECK_NULL_VOID(pattern);
4844         std::string outerBorderWidth = pattern->GetResCacheMapByKey("outerBorderWidthRes");
4845         CalcDimension result;
4846         ResourceParseUtils::ParseResDimensionVp(resObj, result);
4847         if (outerBorderWidth.empty()) {
4848             pattern->AddResCache("outerBorderWidthRes", result.ToString());
4849         }
4850         SetOuterBorderWidth(AceType::RawPtr(frameNode), result);
4851         frameNode->MarkModifyDone();
4852         frameNode->MarkDirtyNode();
4853     };
4854     updateFunc(resObj);
4855     pattern->AddResObj("outerBorderWidthRes", resObj, std::move(updateFunc));
4856 }
4857 
SetInspectorId(const std::string & inspectorId)4858 void ViewAbstract::SetInspectorId(const std::string& inspectorId)
4859 {
4860     auto& uiNode = ViewStackProcessor::GetInstance()->GetMainElementNode();
4861     if (uiNode) {
4862         if (uiNode->GetInspectorId().has_value() && uiNode->GetInspectorIdValue() != inspectorId) {
4863             ElementRegister::GetInstance()->RemoveFrameNodeByInspectorId(
4864                 uiNode->GetInspectorIdValue(), uiNode->GetId());
4865         }
4866         uiNode->UpdateInspectorId(inspectorId);
4867     }
4868 }
4869 
SetAutoEventParam(const std::string & param)4870 void ViewAbstract::SetAutoEventParam(const std::string& param)
4871 {
4872     auto& uiNode = ViewStackProcessor::GetInstance()->GetMainElementNode();
4873     if (uiNode) {
4874         uiNode->UpdateAutoEventParam(param);
4875     }
4876 }
4877 
SetRestoreId(int32_t restoreId)4878 void ViewAbstract::SetRestoreId(int32_t restoreId)
4879 {
4880     auto& uiNode = ViewStackProcessor::GetInstance()->GetMainElementNode();
4881     if (uiNode) {
4882         uiNode->SetRestoreId(restoreId);
4883     }
4884 }
4885 
SetDebugLine(const std::string & line)4886 void ViewAbstract::SetDebugLine(const std::string& line)
4887 {
4888     auto& uiNode = ViewStackProcessor::GetInstance()->GetMainElementNode();
4889     if (uiNode) {
4890         uiNode->SetDebugLine(line);
4891     }
4892 }
4893 
SetGrid(std::optional<int32_t> span,std::optional<int32_t> offset,GridSizeType type)4894 void ViewAbstract::SetGrid(std::optional<int32_t> span, std::optional<int32_t> offset, GridSizeType type)
4895 {
4896     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
4897     CHECK_NULL_VOID(frameNode);
4898     auto layoutProperty = frameNode->GetLayoutProperty();
4899     CHECK_NULL_VOID(layoutProperty);
4900     // frame node is mounted to parent when pop from stack later, no grid-container is added here
4901     layoutProperty->UpdateGridProperty(span, offset, type);
4902 }
4903 
Pop()4904 void ViewAbstract::Pop()
4905 {
4906     ViewStackProcessor::GetInstance()->Pop();
4907 }
4908 
SetTransition(const TransitionOptions & options)4909 void ViewAbstract::SetTransition(const TransitionOptions& options)
4910 {
4911     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4912         return;
4913     }
4914     ACE_UPDATE_RENDER_CONTEXT(Transition, options);
4915 }
4916 
CleanTransition()4917 void ViewAbstract::CleanTransition()
4918 {
4919     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4920         return;
4921     }
4922     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
4923     CHECK_NULL_VOID(frameNode);
4924     auto target = frameNode->GetRenderContext();
4925     if (target) {
4926         target->CleanTransition();
4927     }
4928 }
4929 
SetChainedTransition(const RefPtr<NG::ChainedTransitionEffect> & effect,NG::TransitionFinishCallback && finishCallback)4930 void ViewAbstract::SetChainedTransition(
4931     const RefPtr<NG::ChainedTransitionEffect>& effect, NG::TransitionFinishCallback&& finishCallback)
4932 {
4933     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4934         return;
4935     }
4936     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
4937     CHECK_NULL_VOID(frameNode);
4938     const auto& target = frameNode->GetRenderContext();
4939     if (target) {
4940         target->UpdateChainedTransition(effect);
4941         target->SetTransitionUserCallback(std::move(finishCallback));
4942     }
4943 }
4944 
SetClipShape(const RefPtr<BasicShape> & basicShape)4945 void ViewAbstract::SetClipShape(const RefPtr<BasicShape>& basicShape)
4946 {
4947     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
4948         return;
4949     }
4950     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
4951     CHECK_NULL_VOID(frameNode);
4952     if (SystemProperties::ConfigChangePerform()) {
4953         auto pattern = frameNode->GetPattern();
4954         CHECK_NULL_VOID(pattern);
4955         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
4956         auto&& updateFunc = [basicShape, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
4957             auto frameNode = weak.Upgrade();
4958             CHECK_NULL_VOID(frameNode);
4959             RefPtr<BasicShape>& basicShapeValue = const_cast<RefPtr<BasicShape>&>(basicShape);
4960             CHECK_NULL_VOID(basicShapeValue);
4961             basicShapeValue->ReloadResources();
4962             CHECK_NULL_VOID(frameNode);
4963             auto target = frameNode->GetRenderContext();
4964             CHECK_NULL_VOID(target);
4965             if (target->GetClipEdge().has_value()) {
4966                 target->UpdateClipEdge(false);
4967             }
4968             target->UpdateClipShape(basicShapeValue);
4969             target->OnClipShapeUpdate(basicShapeValue);
4970             frameNode->MarkModifyDone();
4971             frameNode->MarkDirtyNode();
4972         };
4973         pattern->AddResObj("clipShape", resObj, std::move(updateFunc));
4974     }
4975     auto target = frameNode->GetRenderContext();
4976     if (target) {
4977         if (target->GetClipEdge().has_value()) {
4978             target->UpdateClipEdge(false);
4979         }
4980         target->UpdateClipShape(basicShape);
4981     }
4982 }
4983 
SetClipShape(FrameNode * frameNode,const RefPtr<BasicShape> & basicShape)4984 void ViewAbstract::SetClipShape(FrameNode* frameNode, const RefPtr<BasicShape>& basicShape)
4985 {
4986     CHECK_NULL_VOID(frameNode);
4987     if (SystemProperties::ConfigChangePerform()) {
4988         auto pattern = frameNode->GetPattern();
4989         CHECK_NULL_VOID(pattern);
4990         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
4991         auto&& updateFunc = [basicShape, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
4992             auto frameNode = weak.Upgrade();
4993             CHECK_NULL_VOID(frameNode);
4994             RefPtr<BasicShape>& basicShapeValue = const_cast<RefPtr<BasicShape>&>(basicShape);
4995             CHECK_NULL_VOID(basicShapeValue);
4996             basicShapeValue->ReloadResources();
4997             CHECK_NULL_VOID(frameNode);
4998             auto target = frameNode->GetRenderContext();
4999             CHECK_NULL_VOID(target);
5000             if (target->GetClipEdge().has_value()) {
5001                 target->UpdateClipEdge(false);
5002             }
5003             target->UpdateClipShape(basicShapeValue);
5004             target->OnClipShapeUpdate(basicShapeValue);
5005             frameNode->MarkModifyDone();
5006             frameNode->MarkDirtyNode();
5007         };
5008         pattern->AddResObj("clipShape", resObj, std::move(updateFunc));
5009     }
5010     auto target = frameNode->GetRenderContext();
5011     if (target) {
5012         if (target->GetClipEdge().has_value()) {
5013             target->UpdateClipEdge(false);
5014         }
5015         target->UpdateClipShape(basicShape);
5016     }
5017 }
5018 
SetClipEdge(bool isClip)5019 void ViewAbstract::SetClipEdge(bool isClip)
5020 {
5021     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5022         return;
5023     }
5024     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5025     CHECK_NULL_VOID(frameNode);
5026     auto target = frameNode->GetRenderContext();
5027     if (target) {
5028         if (target->GetClipShape().has_value()) {
5029             target->ResetClipShape();
5030             target->OnClipShapeUpdate(nullptr);
5031         }
5032         target->UpdateClipEdge(isClip);
5033     }
5034 }
5035 
SetClipEdge(FrameNode * frameNode,bool isClip)5036 void ViewAbstract::SetClipEdge(FrameNode* frameNode, bool isClip)
5037 {
5038     CHECK_NULL_VOID(frameNode);
5039     auto target = frameNode->GetRenderContext();
5040     if (target) {
5041         if (target->GetClipShape().has_value()) {
5042             target->ResetClipShape();
5043             target->OnClipShapeUpdate(nullptr);
5044         }
5045         target->UpdateClipEdge(isClip);
5046     }
5047 }
5048 
SetMask(const RefPtr<BasicShape> & basicShape)5049 void ViewAbstract::SetMask(const RefPtr<BasicShape>& basicShape)
5050 {
5051     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5052         return;
5053     }
5054     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5055     CHECK_NULL_VOID(frameNode);
5056     if (SystemProperties::ConfigChangePerform()) {
5057         auto pattern = frameNode->GetPattern();
5058         CHECK_NULL_VOID(pattern);
5059         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
5060         auto&& updateFunc = [basicShape, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
5061             auto frameNode = weak.Upgrade();
5062             CHECK_NULL_VOID(frameNode);
5063             RefPtr<BasicShape>& basicShapeValue = const_cast<RefPtr<BasicShape>&>(basicShape);
5064             CHECK_NULL_VOID(basicShapeValue);
5065             basicShapeValue->ReloadResources();
5066             auto target = frameNode->GetRenderContext();
5067             CHECK_NULL_VOID(target);
5068             if (target->HasProgressMask()) {
5069                 target->ResetProgressMask();
5070                 target->OnProgressMaskUpdate(nullptr);
5071             }
5072             target->UpdateClipMask(basicShapeValue);
5073             target->OnClipMaskUpdate(basicShapeValue);
5074         };
5075         pattern->AddResObj("maskShape", resObj, std::move(updateFunc));
5076     }
5077     auto target = frameNode->GetRenderContext();
5078     if (target) {
5079         if (target->HasProgressMask()) {
5080             target->ResetProgressMask();
5081             target->OnProgressMaskUpdate(nullptr);
5082         }
5083         target->UpdateClipMask(basicShape);
5084     }
5085 }
5086 
SetProgressMask(const RefPtr<ProgressMaskProperty> & progress)5087 void ViewAbstract::SetProgressMask(const RefPtr<ProgressMaskProperty>& progress)
5088 {
5089     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5090         return;
5091     }
5092     if (SystemProperties::ConfigChangePerform()) {
5093         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5094         CHECK_NULL_VOID(frameNode);
5095         auto pattern = frameNode->GetPattern();
5096         CHECK_NULL_VOID(pattern);
5097         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
5098         auto&& updateFunc = [progress, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
5099             auto frameNode = weak.Upgrade();
5100             CHECK_NULL_VOID(frameNode);
5101             RefPtr<ProgressMaskProperty>& progressValue = const_cast<RefPtr<ProgressMaskProperty>&>(progress);
5102             CHECK_NULL_VOID(progressValue);
5103             progressValue->ReloadResources();
5104             auto target = frameNode->GetRenderContext();
5105             CHECK_NULL_VOID(target);
5106             if (target->HasClipMask()) {
5107                 target->ResetClipMask();
5108                 target->OnClipMaskUpdate(nullptr);
5109             }
5110             target->UpdateProgressMask(progressValue);
5111             target->OnProgressMaskUpdate(progressValue);
5112         };
5113         pattern->AddResObj("ProgressMask", resObj, std::move(updateFunc));
5114     }
5115     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5116     CHECK_NULL_VOID(frameNode);
5117     auto target = frameNode->GetRenderContext();
5118     if (target) {
5119         if (target->HasClipMask()) {
5120             target->ResetClipMask();
5121             target->OnClipMaskUpdate(nullptr);
5122         }
5123         target->UpdateProgressMask(progress);
5124     }
5125 }
5126 
SetBrightness(const Dimension & brightness)5127 void ViewAbstract::SetBrightness(const Dimension& brightness)
5128 {
5129     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5130         return;
5131     }
5132     ACE_UPDATE_RENDER_CONTEXT(FrontBrightness, brightness);
5133 }
5134 
SetBrightness(FrameNode * frameNode,const Dimension & brightness)5135 void ViewAbstract::SetBrightness(FrameNode* frameNode, const Dimension& brightness)
5136 {
5137     ACE_UPDATE_NODE_RENDER_CONTEXT(FrontBrightness, brightness, frameNode);
5138 }
5139 
SetGrayScale(const Dimension & grayScale)5140 void ViewAbstract::SetGrayScale(const Dimension& grayScale)
5141 {
5142     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5143         return;
5144     }
5145     ACE_UPDATE_RENDER_CONTEXT(FrontGrayScale, grayScale);
5146 }
5147 
SetGrayScale(FrameNode * frameNode,const Dimension & grayScale)5148 void ViewAbstract::SetGrayScale(FrameNode* frameNode, const Dimension& grayScale)
5149 {
5150     ACE_UPDATE_NODE_RENDER_CONTEXT(FrontGrayScale, grayScale, frameNode);
5151 }
5152 
SetContrast(const Dimension & contrast)5153 void ViewAbstract::SetContrast(const Dimension& contrast)
5154 {
5155     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5156         return;
5157     }
5158     ACE_UPDATE_RENDER_CONTEXT(FrontContrast, contrast);
5159 }
5160 
SetContrast(FrameNode * frameNode,const Dimension & contrast)5161 void ViewAbstract::SetContrast(FrameNode* frameNode, const Dimension& contrast)
5162 {
5163     ACE_UPDATE_NODE_RENDER_CONTEXT(FrontContrast, contrast, frameNode);
5164 }
5165 
SetSaturate(const Dimension & saturate)5166 void ViewAbstract::SetSaturate(const Dimension& saturate)
5167 {
5168     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5169         return;
5170     }
5171     ACE_UPDATE_RENDER_CONTEXT(FrontSaturate, saturate);
5172 }
5173 
SetSaturate(FrameNode * frameNode,const Dimension & saturate)5174 void ViewAbstract::SetSaturate(FrameNode* frameNode, const Dimension& saturate)
5175 {
5176     ACE_UPDATE_NODE_RENDER_CONTEXT(FrontSaturate, saturate, frameNode);
5177 }
5178 
SetSepia(const Dimension & sepia)5179 void ViewAbstract::SetSepia(const Dimension& sepia)
5180 {
5181     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5182         return;
5183     }
5184     ACE_UPDATE_RENDER_CONTEXT(FrontSepia, sepia);
5185 }
5186 
SetSepia(FrameNode * frameNode,const Dimension & sepia)5187 void ViewAbstract::SetSepia(FrameNode* frameNode, const Dimension& sepia)
5188 {
5189     ACE_UPDATE_NODE_RENDER_CONTEXT(FrontSepia, sepia, frameNode);
5190 }
5191 
SetInvert(const InvertVariant & invert)5192 void ViewAbstract::SetInvert(const InvertVariant& invert)
5193 {
5194     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5195         return;
5196     }
5197     ACE_UPDATE_RENDER_CONTEXT(FrontInvert, invert);
5198 }
5199 
SetInvert(FrameNode * frameNode,const InvertVariant & invert)5200 void ViewAbstract::SetInvert(FrameNode* frameNode, const InvertVariant& invert)
5201 {
5202     ACE_UPDATE_NODE_RENDER_CONTEXT(FrontInvert, invert, frameNode);
5203 }
5204 
SetSystemBarEffect(bool systemBarEffect)5205 void ViewAbstract::SetSystemBarEffect(bool systemBarEffect)
5206 {
5207     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5208         return;
5209     }
5210     ACE_UPDATE_RENDER_CONTEXT(SystemBarEffect, systemBarEffect);
5211 }
5212 
SetSystemBarEffect(FrameNode * frameNode,bool enable)5213 void ViewAbstract::SetSystemBarEffect(FrameNode *frameNode, bool enable)
5214 {
5215     ACE_UPDATE_NODE_RENDER_CONTEXT(SystemBarEffect, enable, frameNode);
5216 }
5217 
SetHueRotate(float hueRotate)5218 void ViewAbstract::SetHueRotate(float hueRotate)
5219 {
5220     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5221         return;
5222     }
5223     ACE_UPDATE_RENDER_CONTEXT(FrontHueRotate, hueRotate);
5224 }
5225 
SetHueRotate(FrameNode * frameNode,float hueRotate)5226 void ViewAbstract::SetHueRotate(FrameNode* frameNode, float hueRotate)
5227 {
5228     ACE_UPDATE_NODE_RENDER_CONTEXT(FrontHueRotate, hueRotate, frameNode);
5229 }
5230 
SetColorBlend(const Color & colorBlend)5231 void ViewAbstract::SetColorBlend(const Color& colorBlend)
5232 {
5233     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5234         return;
5235     }
5236     ACE_UPDATE_RENDER_CONTEXT(FrontColorBlend, colorBlend);
5237 }
5238 
SetColorBlend(FrameNode * frameNode,const Color & colorBlend)5239 void ViewAbstract::SetColorBlend(FrameNode* frameNode, const Color& colorBlend)
5240 {
5241     ACE_UPDATE_NODE_RENDER_CONTEXT(FrontColorBlend, colorBlend, frameNode);
5242 }
5243 
SetColorBlend(FrameNode * frameNode,const Color & colorBlend,const RefPtr<ResourceObject> & resObj)5244 void ViewAbstract::SetColorBlend(FrameNode* frameNode, const Color& colorBlend, const RefPtr<ResourceObject>& resObj)
5245 {
5246     if (SystemProperties::ConfigChangePerform() && resObj) {
5247         auto pattern = frameNode->GetPattern();
5248         CHECK_NULL_VOID(pattern);
5249         auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
5250             auto frameNode = weak.Upgrade();
5251             CHECK_NULL_VOID(frameNode);
5252             auto pattern = frameNode->GetPattern();
5253             CHECK_NULL_VOID(pattern);
5254             std::string viewAbstractColorBlend = pattern->GetResCacheMapByKey("viewAbstract.colorBlend");
5255             Color result;
5256             ResourceParseUtils::ParseResColor(resObj, result);
5257             if (viewAbstractColorBlend.empty()) {
5258                 pattern->AddResCache("viewAbstract.colorBlend", result.ColorToString());
5259             } else {
5260                 result = Color::ColorFromString(viewAbstractColorBlend);
5261             }
5262             ACE_UPDATE_NODE_RENDER_CONTEXT(FrontColorBlend, result, frameNode);
5263             frameNode->MarkModifyDone();
5264             frameNode->MarkDirtyNode();
5265         };
5266         updateFunc(resObj);
5267         pattern->AddResObj("viewAbstract.colorBlend", resObj, std::move(updateFunc));
5268     }
5269 }
5270 
CreateWithColorBlendResourceObj(const RefPtr<ResourceObject> & resObj)5271 void ViewAbstract::CreateWithColorBlendResourceObj(const RefPtr<ResourceObject>& resObj)
5272 {
5273     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5274     CHECK_NULL_VOID(frameNode);
5275 
5276     auto pattern = frameNode->GetPattern();
5277     CHECK_NULL_VOID(pattern);
5278     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
5279         auto frameNode = weak.Upgrade();
5280         CHECK_NULL_VOID(frameNode);
5281         auto pattern = frameNode->GetPattern();
5282         CHECK_NULL_VOID(pattern);
5283         std::string viewAbstractColorBlend = pattern->GetResCacheMapByKey("viewAbstract.colorBlend");
5284         Color result;
5285         ResourceParseUtils::ParseResColor(resObj, result);
5286         if (viewAbstractColorBlend.empty()) {
5287             pattern->AddResCache("viewAbstract.colorBlend", result.ColorToString());
5288         } else {
5289             result = Color::ColorFromString(viewAbstractColorBlend);
5290         }
5291         ACE_UPDATE_NODE_RENDER_CONTEXT(FrontColorBlend, result, frameNode);
5292         frameNode->MarkModifyDone();
5293         frameNode->MarkDirtyNode();
5294     };
5295     updateFunc(resObj);
5296     pattern->AddResObj("viewAbstract.colorBlend", resObj, std::move(updateFunc));
5297 }
5298 
SetBorderImage(const RefPtr<BorderImage> & borderImage)5299 void ViewAbstract::SetBorderImage(const RefPtr<BorderImage>& borderImage)
5300 {
5301     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5302         return;
5303     }
5304     ACE_UPDATE_RENDER_CONTEXT(BorderImage, borderImage);
5305 }
5306 
SetBorderImageSource(const std::string & bdImageSrc,const std::string & bundleName,const std::string & moduleName)5307 void ViewAbstract::SetBorderImageSource(
5308     const std::string& bdImageSrc, const std::string& bundleName, const std::string& moduleName)
5309 {
5310     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5311         return;
5312     }
5313     ImageSourceInfo imageSourceInfo(bdImageSrc, bundleName, moduleName);
5314     ACE_UPDATE_RENDER_CONTEXT(BorderImageSource, imageSourceInfo);
5315     ACE_UPDATE_RENDER_CONTEXT(BorderSourceFromImage, true);
5316 }
5317 
SetHasBorderImageSlice(bool tag)5318 void ViewAbstract::SetHasBorderImageSlice(bool tag)
5319 {
5320     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5321         return;
5322     }
5323     ACE_UPDATE_RENDER_CONTEXT(HasBorderImageSlice, tag);
5324 }
5325 
SetHasBorderImageWidth(bool tag)5326 void ViewAbstract::SetHasBorderImageWidth(bool tag)
5327 {
5328     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5329         return;
5330     }
5331     ACE_UPDATE_RENDER_CONTEXT(HasBorderImageWidth, tag);
5332 }
5333 
SetHasBorderImageOutset(bool tag)5334 void ViewAbstract::SetHasBorderImageOutset(bool tag)
5335 {
5336     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5337         return;
5338     }
5339     ACE_UPDATE_RENDER_CONTEXT(HasBorderImageOutset, tag);
5340 }
5341 
SetHasBorderImageRepeat(bool tag)5342 void ViewAbstract::SetHasBorderImageRepeat(bool tag)
5343 {
5344     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5345         return;
5346     }
5347     ACE_UPDATE_RENDER_CONTEXT(HasBorderImageRepeat, tag);
5348 }
5349 
SetBorderImageGradient(const Gradient & gradient)5350 void ViewAbstract::SetBorderImageGradient(const Gradient& gradient)
5351 {
5352     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5353         return;
5354     }
5355     ACE_UPDATE_RENDER_CONTEXT(BorderImageGradient, gradient);
5356     ACE_UPDATE_RENDER_CONTEXT(BorderSourceFromImage, false);
5357 }
5358 
5359 std::mutex ViewAbstract::visualEffectMutex_;
5360 OEMVisualEffectFunc ViewAbstract::oemVisualEffectFunc = nullptr;
RegisterOEMVisualEffect(OEMVisualEffectFunc func)5361 void ViewAbstract::RegisterOEMVisualEffect(OEMVisualEffectFunc func)
5362 {
5363     std::lock_guard<std::mutex> lock(visualEffectMutex_);
5364     ViewAbstract::oemVisualEffectFunc = func;
5365 }
5366 
SetVisualEffect(const OHOS::Rosen::VisualEffect * visualEffect)5367 void ViewAbstract::SetVisualEffect(const OHOS::Rosen::VisualEffect* visualEffect)
5368 {
5369     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5370         return;
5371     }
5372 
5373     std::lock_guard<std::mutex> lock(visualEffectMutex_);
5374     if (!oemVisualEffectFunc) {
5375         ACE_UPDATE_RENDER_CONTEXT(VisualEffect, visualEffect);
5376     } else {
5377         Rosen::VisualEffect* graphicVisualEffect = oemVisualEffectFunc(visualEffect);
5378         ACE_UPDATE_RENDER_CONTEXT(VisualEffect, graphicVisualEffect);
5379     }
5380 }
5381 
SetVisualEffect(FrameNode * frameNode,const OHOS::Rosen::VisualEffect * visualEffect)5382 void ViewAbstract::SetVisualEffect(FrameNode* frameNode, const OHOS::Rosen::VisualEffect* visualEffect)
5383 {
5384     CHECK_NULL_VOID(frameNode);
5385     std::lock_guard<std::mutex> lock(visualEffectMutex_);
5386     auto target = frameNode->GetRenderContext();
5387     CHECK_NULL_VOID(target);
5388     if (!oemVisualEffectFunc) {
5389         target->UpdateVisualEffect(visualEffect);
5390     } else {
5391         Rosen::VisualEffect* graphicVisualEffect = oemVisualEffectFunc(visualEffect);
5392         target->UpdateVisualEffect(graphicVisualEffect);
5393     }
5394 }
5395 
SetBackgroundFilter(const OHOS::Rosen::Filter * backgroundFilter)5396 void ViewAbstract::SetBackgroundFilter(const OHOS::Rosen::Filter* backgroundFilter)
5397 {
5398     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5399         return;
5400     }
5401     ACE_UPDATE_RENDER_CONTEXT(BackgroundFilter, backgroundFilter);
5402 }
5403 
SetBackgroundFilter(FrameNode * frameNode,const OHOS::Rosen::Filter * backgroundFilter)5404 void ViewAbstract::SetBackgroundFilter(FrameNode* frameNode, const OHOS::Rosen::Filter* backgroundFilter)
5405 {
5406     CHECK_NULL_VOID(frameNode);
5407     auto target = frameNode->GetRenderContext();
5408     CHECK_NULL_VOID(target);
5409     target->UpdateBackgroundFilter(backgroundFilter);
5410 }
5411 
SetForegroundFilter(const OHOS::Rosen::Filter * foregroundFilter)5412 void ViewAbstract::SetForegroundFilter(const OHOS::Rosen::Filter* foregroundFilter)
5413 {
5414     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5415         return;
5416     }
5417     ACE_UPDATE_RENDER_CONTEXT(ForegroundFilter, foregroundFilter);
5418 }
5419 
SetForegroundFilter(FrameNode * frameNode,const OHOS::Rosen::Filter * foregroundFilter)5420 void ViewAbstract::SetForegroundFilter(FrameNode* frameNode, const OHOS::Rosen::Filter* foregroundFilter)
5421 {
5422     CHECK_NULL_VOID(frameNode);
5423     auto target = frameNode->GetRenderContext();
5424     CHECK_NULL_VOID(target);
5425     target->UpdateForegroundFilter(foregroundFilter);
5426 }
5427 
SetCompositingFilter(const OHOS::Rosen::Filter * compositingFilter)5428 void ViewAbstract::SetCompositingFilter(const OHOS::Rosen::Filter* compositingFilter)
5429 {
5430     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5431         return;
5432     }
5433     ACE_UPDATE_RENDER_CONTEXT(CompositingFilter, compositingFilter);
5434 }
5435 
SetCompositingFilter(FrameNode * frameNode,const OHOS::Rosen::Filter * compositingFilter)5436 void ViewAbstract::SetCompositingFilter(FrameNode* frameNode, const OHOS::Rosen::Filter* compositingFilter)
5437 {
5438     CHECK_NULL_VOID(frameNode);
5439     auto target = frameNode->GetRenderContext();
5440     CHECK_NULL_VOID(target);
5441     target->UpdateCompositingFilter(compositingFilter);
5442 }
5443 
SetOverlay(const OverlayOptions & overlay)5444 void ViewAbstract::SetOverlay(const OverlayOptions& overlay)
5445 {
5446     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5447         return;
5448     }
5449     ACE_UPDATE_RENDER_CONTEXT(OverlayText, overlay);
5450 }
5451 
SetOverlayBuilder(std::function<void ()> && buildFunc,const std::optional<Alignment> & align,const std::optional<Dimension> & offsetX,const std::optional<Dimension> & offsetY)5452 void ViewAbstract::SetOverlayBuilder(std::function<void()>&& buildFunc,
5453     const std::optional<Alignment>& align, const std::optional<Dimension>& offsetX,
5454     const std::optional<Dimension>& offsetY)
5455 {
5456     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5457         return;
5458     }
5459     if (buildFunc) {
5460         auto buildNodeFunc = [func = std::move(buildFunc)]() -> RefPtr<UINode> {
5461             ScopedViewStackProcessor builderViewStackProcessor;
5462             func();
5463             auto customNode = ViewStackProcessor::GetInstance()->Finish();
5464             return customNode;
5465         };
5466         auto node = buildNodeFunc();
5467         auto overlayNode = AceType::DynamicCast<FrameNode>(node);
5468         if (!overlayNode && node) {
5469             auto* stack = ViewStackProcessor::GetInstance();
5470             auto nodeId = stack->ClaimNodeId();
5471             auto stackNode = FrameNode::CreateFrameNode(V2::STACK_ETS_TAG, nodeId, AceType::MakeRefPtr<StackPattern>());
5472             stackNode->AddChild(node);
5473             overlayNode = stackNode;
5474         }
5475         AddOverlayToFrameNode(overlayNode, align, offsetX, offsetY);
5476     } else {
5477         AddOverlayToFrameNode(nullptr, align, offsetX, offsetY);
5478     }
5479 }
5480 
5481 #if defined(ACE_STATIC)
SetOverlayBuilder(FrameNode * frameNode,const RefPtr<NG::UINode> & customNode,const std::optional<Alignment> & align,const std::optional<Dimension> & offsetX,const std::optional<Dimension> & offsetY)5482 void ViewAbstract::SetOverlayBuilder(FrameNode* frameNode, const RefPtr<NG::UINode>& customNode,
5483     const std::optional<Alignment>& align, const std::optional<Dimension>& offsetX,
5484     const std::optional<Dimension>& offsetY)
5485 {
5486     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess() || !frameNode || !customNode) {
5487         return;
5488     }
5489     auto overlayNode = AceType::DynamicCast<FrameNode>(customNode);
5490     if (!overlayNode && customNode) {
5491         auto* stack = ViewStackProcessor::GetInstance();
5492         auto nodeId = stack->ClaimNodeId();
5493         auto stackNode = FrameNode::CreateFrameNode(V2::STACK_ETS_TAG, nodeId, AceType::MakeRefPtr<StackPattern>());
5494         if (stackNode) {
5495             stackNode->AddChild(customNode);
5496         }
5497         overlayNode = stackNode;
5498     }
5499     if (overlayNode == nullptr) {
5500         frameNode->SetOverlayNode(nullptr);
5501         return;
5502     }
5503     frameNode->SetOverlayNode(overlayNode);
5504     overlayNode->SetParent(AceType::WeakClaim(frameNode));
5505     overlayNode->SetActive(true);
5506     overlayNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
5507     auto layoutProperty = AceType::DynamicCast<LayoutProperty>(overlayNode->GetLayoutProperty());
5508     CHECK_NULL_VOID(layoutProperty);
5509     layoutProperty->SetIsOverlayNode(true);
5510     layoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT);
5511     layoutProperty->UpdateAlignment(align.value_or(Alignment::TOP_LEFT));
5512     layoutProperty->SetOverlayOffset(offsetX, offsetY);
5513     auto renderContext = overlayNode->GetRenderContext();
5514     CHECK_NULL_VOID(renderContext);
5515     renderContext->UpdateZIndex(INT32_MAX);
5516     auto focusHub = overlayNode->GetOrCreateFocusHub();
5517     CHECK_NULL_VOID(focusHub);
5518     focusHub->SetFocusable(false);
5519 }
5520 #endif
5521 
SetOverlayComponentContent(const RefPtr<NG::FrameNode> & contentNode,const std::optional<Alignment> & align,const std::optional<Dimension> & offsetX,const std::optional<Dimension> & offsetY)5522 void ViewAbstract::SetOverlayComponentContent(const RefPtr<NG::FrameNode>& contentNode,
5523     const std::optional<Alignment>& align, const std::optional<Dimension>& offsetX,
5524     const std::optional<Dimension>& offsetY)
5525 {
5526     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5527         return;
5528     }
5529     AddOverlayToFrameNode(contentNode, align, offsetX, offsetY);
5530 }
5531 
AddOverlayToFrameNode(const RefPtr<NG::FrameNode> & overlayNode,const std::optional<Alignment> & align,const std::optional<Dimension> & offsetX,const std::optional<Dimension> & offsetY)5532 void ViewAbstract::AddOverlayToFrameNode(const RefPtr<NG::FrameNode>& overlayNode,
5533     const std::optional<Alignment>& align, const std::optional<Dimension>& offsetX,
5534     const std::optional<Dimension>& offsetY)
5535 {
5536     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5537     CHECK_NULL_VOID(frameNode);
5538     if (overlayNode == nullptr) {
5539         frameNode->SetOverlayNode(nullptr);
5540         return;
5541     }
5542     frameNode->SetOverlayNode(overlayNode);
5543     overlayNode->SetParent(AceType::WeakClaim(frameNode));
5544     overlayNode->SetActive(true);
5545     overlayNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
5546     auto layoutProperty = AceType::DynamicCast<LayoutProperty>(overlayNode->GetLayoutProperty());
5547     CHECK_NULL_VOID(layoutProperty);
5548     layoutProperty->SetIsOverlayNode(true);
5549     layoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT);
5550     layoutProperty->UpdateAlignment(align.value_or(Alignment::TOP_LEFT));
5551     layoutProperty->SetOverlayOffset(offsetX, offsetY);
5552     auto renderContext = overlayNode->GetRenderContext();
5553     CHECK_NULL_VOID(renderContext);
5554     renderContext->UpdateZIndex(INT32_MAX);
5555     auto focusHub = overlayNode->GetOrCreateFocusHub();
5556     CHECK_NULL_VOID(focusHub);
5557     focusHub->SetFocusable(false);
5558 }
5559 
SetMotionPath(const MotionPathOption & motionPath)5560 void ViewAbstract::SetMotionPath(const MotionPathOption& motionPath)
5561 {
5562     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5563         return;
5564     }
5565     ACE_UPDATE_RENDER_CONTEXT(MotionPath, motionPath);
5566 }
5567 
SetSharedTransition(const std::string & shareId,const std::shared_ptr<SharedTransitionOption> & option)5568 void ViewAbstract::SetSharedTransition(
5569     const std::string& shareId, const std::shared_ptr<SharedTransitionOption>& option)
5570 {
5571     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5572     CHECK_NULL_VOID(frameNode);
5573     auto target = frameNode->GetRenderContext();
5574     if (target) {
5575         target->SetSharedTransitionOptions(option);
5576         target->SetShareId(shareId);
5577     }
5578 }
5579 
SetMask(FrameNode * frameNode,const RefPtr<BasicShape> & basicShape)5580 void ViewAbstract::SetMask(FrameNode* frameNode, const RefPtr<BasicShape>& basicShape)
5581 {
5582     CHECK_NULL_VOID(frameNode);
5583     if (SystemProperties::ConfigChangePerform()) {
5584         auto pattern = frameNode->GetPattern();
5585         CHECK_NULL_VOID(pattern);
5586         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
5587         auto&& updateFunc = [basicShape, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
5588             auto frameNode = weak.Upgrade();
5589             CHECK_NULL_VOID(frameNode);
5590             RefPtr<BasicShape>& basicShapeValue = const_cast<RefPtr<BasicShape>&>(basicShape);
5591             CHECK_NULL_VOID(basicShapeValue);
5592             basicShapeValue->ReloadResources();
5593             auto target = frameNode->GetRenderContext();
5594             CHECK_NULL_VOID(target);
5595             if (target->HasProgressMask()) {
5596                 target->ResetProgressMask();
5597                 target->OnProgressMaskUpdate(nullptr);
5598             }
5599             target->UpdateClipMask(basicShapeValue);
5600             target->OnClipMaskUpdate(basicShapeValue);
5601         };
5602         pattern->AddResObj("maskShape", resObj, std::move(updateFunc));
5603     }
5604     auto target = frameNode->GetRenderContext();
5605     if (target) {
5606         if (target->HasProgressMask()) {
5607             target->ResetProgressMask();
5608             target->OnProgressMaskUpdate(nullptr);
5609         }
5610         target->UpdateClipMask(basicShape);
5611     }
5612 }
5613 
SetProgressMask(FrameNode * frameNode,const RefPtr<ProgressMaskProperty> & progress)5614 void ViewAbstract::SetProgressMask(FrameNode* frameNode, const RefPtr<ProgressMaskProperty>& progress)
5615 {
5616     CHECK_NULL_VOID(frameNode);
5617     if (SystemProperties::ConfigChangePerform()) {
5618         auto pattern = frameNode->GetPattern();
5619         CHECK_NULL_VOID(pattern);
5620         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
5621         auto&& updateFunc = [progress, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
5622             auto frameNode = weak.Upgrade();
5623             CHECK_NULL_VOID(frameNode);
5624             RefPtr<ProgressMaskProperty>& progressValue = const_cast<RefPtr<ProgressMaskProperty>&>(progress);
5625             CHECK_NULL_VOID(progressValue);
5626             progressValue->ReloadResources();
5627             auto target = frameNode->GetRenderContext();
5628             CHECK_NULL_VOID(target);
5629             if (target->HasClipMask()) {
5630                 target->ResetClipMask();
5631                 target->OnClipMaskUpdate(nullptr);
5632             }
5633             target->UpdateProgressMask(progressValue);
5634             target->OnProgressMaskUpdate(progressValue);
5635         };
5636         pattern->AddResObj("ProgressMask", resObj, std::move(updateFunc));
5637     }
5638     auto target = frameNode->GetRenderContext();
5639     if (target) {
5640         if (target->HasClipMask()) {
5641             target->ResetClipMask();
5642             target->OnClipMaskUpdate(nullptr);
5643         }
5644         target->UpdateProgressMask(progress);
5645     }
5646 }
5647 
SetUseEffect(bool useEffect,EffectType effectType)5648 void ViewAbstract::SetUseEffect(bool useEffect, EffectType effectType)
5649 {
5650     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5651         return;
5652     }
5653     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5654     SetUseEffect(frameNode, useEffect, effectType);
5655 }
5656 
SetFreeze(bool freeze)5657 void ViewAbstract::SetFreeze(bool freeze)
5658 {
5659     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5660         return;
5661     }
5662     ACE_UPDATE_RENDER_CONTEXT(Freeze, freeze);
5663 }
5664 
SetFreeze(FrameNode * frameNode,bool freeze)5665 void ViewAbstract::SetFreeze(FrameNode* frameNode, bool freeze)
5666 {
5667     CHECK_NULL_VOID(frameNode);
5668     auto target = frameNode->GetRenderContext();
5669     CHECK_NULL_VOID(target);
5670     target->UpdateFreeze(freeze);
5671 }
5672 
SetUseShadowBatching(bool useShadowBatching)5673 void ViewAbstract::SetUseShadowBatching(bool useShadowBatching)
5674 {
5675     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5676         return;
5677     }
5678     ACE_UPDATE_RENDER_CONTEXT(UseShadowBatching, useShadowBatching);
5679 }
5680 
SetForegroundColor(const Color & color)5681 void ViewAbstract::SetForegroundColor(const Color& color)
5682 {
5683     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5684         return;
5685     }
5686     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5687     CHECK_NULL_VOID(frameNode);
5688     auto renderContext = frameNode->GetRenderContext();
5689     CHECK_NULL_VOID(renderContext);
5690     if (renderContext->GetForegroundColorStrategy().has_value()) {
5691         renderContext->UpdateForegroundColorStrategy(ForegroundColorStrategy::NONE);
5692         renderContext->ResetForegroundColorStrategy();
5693     }
5694     renderContext->UpdateForegroundColor(color);
5695     renderContext->UpdateForegroundColorFlag(true);
5696 }
5697 
SetForegroundColorStrategy(const ForegroundColorStrategy & strategy)5698 void ViewAbstract::SetForegroundColorStrategy(const ForegroundColorStrategy& strategy)
5699 {
5700     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5701         return;
5702     }
5703     ACE_UPDATE_RENDER_CONTEXT(ForegroundColorStrategy, strategy);
5704     ACE_RESET_RENDER_CONTEXT(RenderContext, ForegroundColor);
5705     ACE_UPDATE_RENDER_CONTEXT(ForegroundColorFlag, true);
5706     if (SystemProperties::ConfigChangePerform()) {
5707         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5708         CHECK_NULL_VOID(frameNode);
5709         auto pattern = frameNode->GetPattern<Pattern>();
5710         CHECK_NULL_VOID(pattern);
5711         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
5712         auto&& updateFunc = [weak = AceType::WeakClaim(frameNode), strategy](const RefPtr<ResourceObject>& resObj) {
5713             auto frameNode = weak.Upgrade();
5714             CHECK_NULL_VOID(frameNode);
5715             ACE_UPDATE_NODE_RENDER_CONTEXT(ForegroundColorStrategy, strategy, frameNode);
5716             ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, ForegroundColor, frameNode);
5717             ACE_UPDATE_NODE_RENDER_CONTEXT(ForegroundColorFlag, true, frameNode);
5718             frameNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
5719         };
5720         pattern->AddResObj("foregroundColorStrategy", resObj, std::move(updateFunc));
5721     }
5722 }
5723 
SetKeyboardShortcut(const std::string & value,const std::vector<ModifierKey> & keys,std::function<void ()> && onKeyboardShortcutAction)5724 void ViewAbstract::SetKeyboardShortcut(
5725     const std::string& value, const std::vector<ModifierKey>& keys, std::function<void()>&& onKeyboardShortcutAction)
5726 {
5727     auto pipeline = PipelineContext::GetCurrentContext();
5728     CHECK_NULL_VOID(pipeline);
5729     auto eventManager = pipeline->GetEventManager();
5730     CHECK_NULL_VOID(eventManager);
5731     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
5732     CHECK_NULL_VOID(eventHub);
5733     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5734     CHECK_NULL_VOID(frameNode);
5735     if (value.empty()) {
5736         eventHub->ClearSingleKeyboardShortcut();
5737         return;
5738     }
5739     auto key = eventManager->GetKeyboardShortcutKeys(keys);
5740     if ((key == 0 && value.length() == 1) || (key == 0 && keys.size() > 0 && value.length() > 1)) {
5741         return;
5742     }
5743     if (eventManager->IsSameKeyboardShortcutNode(value, key)) {
5744         return;
5745     }
5746     eventHub->SetKeyboardShortcut(value, key, std::move(onKeyboardShortcutAction));
5747     eventManager->AddKeyboardShortcutNode(AceType::WeakClaim(frameNode));
5748 }
5749 
CreateAnimatablePropertyFloat(const std::string & propertyName,float value,const std::function<void (float)> & onCallbackEvent)5750 void ViewAbstract::CreateAnimatablePropertyFloat(
5751     const std::string& propertyName, float value, const std::function<void(float)>& onCallbackEvent)
5752 {
5753     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5754     CHECK_NULL_VOID(frameNode);
5755     frameNode->CreateAnimatablePropertyFloat(propertyName, value, onCallbackEvent);
5756 }
5757 
UpdateAnimatablePropertyFloat(const std::string & propertyName,float value)5758 void ViewAbstract::UpdateAnimatablePropertyFloat(const std::string& propertyName, float value)
5759 {
5760     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5761     CHECK_NULL_VOID(frameNode);
5762     frameNode->UpdateAnimatablePropertyFloat(propertyName, value);
5763 }
5764 
CreateAnimatableArithmeticProperty(const std::string & propertyName,RefPtr<CustomAnimatableArithmetic> & value,std::function<void (const RefPtr<CustomAnimatableArithmetic> &)> & onCallbackEvent)5765 void ViewAbstract::CreateAnimatableArithmeticProperty(const std::string& propertyName,
5766     RefPtr<CustomAnimatableArithmetic>& value,
5767     std::function<void(const RefPtr<CustomAnimatableArithmetic>&)>& onCallbackEvent)
5768 {
5769     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5770     CHECK_NULL_VOID(frameNode);
5771     frameNode->CreateAnimatableArithmeticProperty(propertyName, value, onCallbackEvent);
5772 }
5773 
UpdateAnimatableArithmeticProperty(const std::string & propertyName,RefPtr<CustomAnimatableArithmetic> & value)5774 void ViewAbstract::UpdateAnimatableArithmeticProperty(
5775     const std::string& propertyName, RefPtr<CustomAnimatableArithmetic>& value)
5776 {
5777     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5778     CHECK_NULL_VOID(frameNode);
5779     frameNode->UpdateAnimatableArithmeticProperty(propertyName, value);
5780 }
5781 
SetObscured(const std::vector<ObscuredReasons> & reasons)5782 void ViewAbstract::SetObscured(const std::vector<ObscuredReasons>& reasons)
5783 {
5784     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5785         return;
5786     }
5787     ACE_UPDATE_RENDER_CONTEXT(Obscured, reasons);
5788     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5789     CHECK_NULL_VOID(frameNode);
5790     frameNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
5791 }
5792 
SetPrivacySensitive(bool flag)5793 void ViewAbstract::SetPrivacySensitive(bool flag)
5794 {
5795     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5796         return;
5797     }
5798     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5799     CHECK_NULL_VOID(frameNode);
5800     frameNode->SetPrivacySensitive(flag);
5801     frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
5802 }
5803 
SetPrivacySensitive(FrameNode * frameNode,bool flag)5804 void ViewAbstract::SetPrivacySensitive(FrameNode* frameNode, bool flag)
5805 {
5806     CHECK_NULL_VOID(frameNode);
5807     frameNode->SetPrivacySensitive(flag);
5808     frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
5809 }
5810 
UpdateSafeAreaExpandOpts(const SafeAreaExpandOpts & opts)5811 void ViewAbstract::UpdateSafeAreaExpandOpts(const SafeAreaExpandOpts& opts)
5812 {
5813     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5814         return;
5815     }
5816     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaExpandOpts, opts);
5817 }
5818 
UpdateIgnoreLayoutSafeAreaOpts(const IgnoreLayoutSafeAreaOpts & opts)5819 void ViewAbstract::UpdateIgnoreLayoutSafeAreaOpts(const IgnoreLayoutSafeAreaOpts& opts)
5820 {
5821     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5822         return;
5823     }
5824     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, IgnoreLayoutSafeAreaOpts, opts);
5825 }
5826 
SetRenderGroup(bool isRenderGroup)5827 void ViewAbstract::SetRenderGroup(bool isRenderGroup)
5828 {
5829     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5830         return;
5831     }
5832     ACE_UPDATE_RENDER_CONTEXT(RenderGroup, isRenderGroup);
5833     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5834     CHECK_NULL_VOID(frameNode);
5835     frameNode->SetApplicationRenderGroupMarked(true);
5836 }
5837 
SetRenderFit(RenderFit renderFit)5838 void ViewAbstract::SetRenderFit(RenderFit renderFit)
5839 {
5840     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5841         return;
5842     }
5843     ACE_UPDATE_RENDER_CONTEXT(RenderFit, renderFit);
5844 }
5845 
SetAttractionEffect(const AttractionEffect & effect)5846 void ViewAbstract::SetAttractionEffect(const AttractionEffect& effect)
5847 {
5848     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5849         return;
5850     }
5851     ACE_UPDATE_RENDER_CONTEXT(AttractionEffect, effect);
5852 }
5853 
SetBorderRadius(FrameNode * frameNode,const BorderRadiusProperty & value)5854 void ViewAbstract::SetBorderRadius(FrameNode *frameNode, const BorderRadiusProperty& value)
5855 {
5856     CHECK_NULL_VOID(frameNode);
5857     if (SystemProperties::ConfigChangePerform()) {
5858         auto pattern = frameNode->GetPattern<Pattern>();
5859         CHECK_NULL_VOID(pattern);
5860         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
5861         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
5862             auto frameNode = weak.Upgrade();
5863             CHECK_NULL_VOID(frameNode);
5864             BorderRadiusProperty &borderRadius = const_cast<BorderRadiusProperty &>(value);
5865             borderRadius.ReloadResources();
5866             auto layoutProperty = frameNode->GetLayoutProperty();
5867             CHECK_NULL_VOID(layoutProperty);
5868             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
5869             CheckLocalizedBorderRadiuses(borderRadius, layoutDirection);
5870             ACE_UPDATE_NODE_RENDER_CONTEXT(BorderRadius, borderRadius, frameNode);
5871         };
5872         pattern->AddResObj("borderRadius", resObj, std::move(updateFunc));
5873     }
5874     ACE_UPDATE_NODE_RENDER_CONTEXT(BorderRadius, value, frameNode);
5875 }
5876 
SetBorderRadius(FrameNode * frameNode,const Dimension & value)5877 void ViewAbstract::SetBorderRadius(FrameNode* frameNode, const Dimension& value)
5878 {
5879     BorderRadiusProperty borderRadius;
5880     borderRadius.SetRadius(value);
5881     borderRadius.multiValued = false;
5882     ACE_UPDATE_NODE_RENDER_CONTEXT(BorderRadius, borderRadius, frameNode);
5883 }
5884 
SetBorderWidth(FrameNode * frameNode,const BorderWidthProperty & value)5885 void ViewAbstract::SetBorderWidth(FrameNode* frameNode, const BorderWidthProperty& value)
5886 {
5887     CHECK_NULL_VOID(frameNode);
5888     if (SystemProperties::ConfigChangePerform()) {
5889         auto pattern = frameNode->GetPattern<Pattern>();
5890         CHECK_NULL_VOID(pattern);
5891         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
5892         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
5893             auto frameNode = weak.Upgrade();
5894             CHECK_NULL_VOID(frameNode);
5895             BorderWidthProperty &borderWidth = const_cast<BorderWidthProperty &>(value);
5896             borderWidth.ReloadResources();
5897             auto layoutProperty = frameNode->GetLayoutProperty();
5898             CHECK_NULL_VOID(layoutProperty);
5899             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
5900             CheckLocalizedEdgeWidths(borderWidth, layoutDirection);
5901             ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, BorderWidth, borderWidth, frameNode);
5902             ACE_UPDATE_NODE_RENDER_CONTEXT(BorderWidth, borderWidth, frameNode);
5903             frameNode->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT | PROPERTY_UPDATE_MEASURE);
5904         };
5905         pattern->AddResObj("borderWidth", resObj, std::move(updateFunc));
5906     }
5907     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, BorderWidth, value, frameNode);
5908     ACE_UPDATE_NODE_RENDER_CONTEXT(BorderWidth, value, frameNode);
5909 }
5910 
SetBorderWidth(FrameNode * frameNode,const Dimension & value)5911 void ViewAbstract::SetBorderWidth(FrameNode* frameNode, const Dimension& value)
5912 {
5913     BorderWidthProperty borderWidth;
5914     if (Negative(value.Value())) {
5915         borderWidth.SetBorderWidth(Dimension(0));
5916         LOGW("border width is negative, reset to 0");
5917     } else {
5918         borderWidth.SetBorderWidth(value);
5919     }
5920     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, BorderWidth, borderWidth, frameNode);
5921     ACE_UPDATE_NODE_RENDER_CONTEXT(BorderWidth, borderWidth, frameNode);
5922 }
5923 
SetBorderColor(FrameNode * frameNode,const BorderColorProperty & value)5924 void ViewAbstract::SetBorderColor(FrameNode* frameNode, const BorderColorProperty& value)
5925 {
5926     CHECK_NULL_VOID(frameNode);
5927     if (SystemProperties::ConfigChangePerform()) {
5928         auto pattern = frameNode->GetPattern<Pattern>();
5929         CHECK_NULL_VOID(pattern);
5930         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
5931         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
5932             auto frameNode = weak.Upgrade();
5933             CHECK_NULL_VOID(frameNode);
5934             BorderColorProperty &borderColor = const_cast<BorderColorProperty &>(value);
5935             borderColor.ReloadResources();
5936             auto layoutProperty = frameNode->GetLayoutProperty();
5937             CHECK_NULL_VOID(layoutProperty);
5938             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
5939             CheckLocalizedBorderColor(borderColor, layoutDirection);
5940             ACE_UPDATE_NODE_RENDER_CONTEXT(BorderColor, borderColor, frameNode);
5941             frameNode->MarkModifyDone();
5942         };
5943         pattern->AddResObj("borderColor", resObj, std::move(updateFunc));
5944     }
5945     ACE_UPDATE_NODE_RENDER_CONTEXT(BorderColor, value, frameNode);
5946 }
5947 
SetBorderColor(FrameNode * frameNode,const Color & value)5948 void ViewAbstract::SetBorderColor(FrameNode* frameNode, const Color& value)
5949 {
5950     BorderColorProperty borderColor;
5951     borderColor.SetColor(value);
5952     ACE_UPDATE_NODE_RENDER_CONTEXT(BorderColor, borderColor, frameNode);
5953 }
5954 
SetWidth(FrameNode * frameNode,const CalcLength & width)5955 void ViewAbstract::SetWidth(FrameNode* frameNode, const CalcLength& width)
5956 {
5957     CHECK_NULL_VOID(frameNode);
5958     auto layoutProperty = frameNode->GetLayoutProperty();
5959     CHECK_NULL_VOID(layoutProperty);
5960     // get previously user defined ideal height
5961     std::optional<CalcLength> height = std::nullopt;
5962     auto&& layoutConstraint = layoutProperty->GetCalcLayoutConstraint();
5963     if (layoutConstraint && layoutConstraint->selfIdealSize) {
5964         height = layoutConstraint->selfIdealSize->Height();
5965     }
5966     layoutProperty->UpdateUserDefinedIdealSize(CalcSize(width, height));
5967 }
5968 
SetWidth(FrameNode * frameNode,const RefPtr<ResourceObject> & resObj)5969 void ViewAbstract::SetWidth(FrameNode* frameNode, const RefPtr<ResourceObject>& resObj)
5970 {
5971     CHECK_NULL_VOID(frameNode);
5972     auto pattern = frameNode->GetPattern<Pattern>();
5973     CHECK_NULL_VOID(pattern);
5974     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
5975         auto frameNode = weak.Upgrade();
5976         CHECK_NULL_VOID(frameNode);
5977         auto pattern = frameNode->GetPattern<Pattern>();
5978         CHECK_NULL_VOID(pattern);
5979         std::string widthString = pattern->GetResCacheMapByKey("width");
5980         CalcDimension value;
5981         if (widthString.empty()) {
5982             ResourceParseUtils::ParseResDimensionVpNG(resObj, value);
5983             pattern->AddResCache("width", value.ToString());
5984         } else {
5985             value = StringUtils::StringToCalcDimension(widthString);
5986         }
5987         CalcLength width;
5988         if (value.Unit() == DimensionUnit::CALC) {
5989             width = NG::CalcLength(value.CalcValue());
5990         } else {
5991             width = NG::CalcLength(value);
5992         }
5993         if (LessNotEqual(value.Value(), 0.0)) {
5994             ClearWidthOrHeight(AceType::RawPtr(frameNode), true);
5995             return;
5996         }
5997         auto layoutProperty = frameNode->GetLayoutProperty();
5998         CHECK_NULL_VOID(layoutProperty);
5999         // get previously user defined ideal height
6000         std::optional<CalcLength> height = std::nullopt;
6001         auto&& layoutConstraint = layoutProperty->GetCalcLayoutConstraint();
6002         if (layoutConstraint && layoutConstraint->selfIdealSize) {
6003             height = layoutConstraint->selfIdealSize->Height();
6004         }
6005         layoutProperty->UpdateUserDefinedIdealSize(CalcSize(width, height));
6006         frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
6007     };
6008     updateFunc(resObj);
6009     pattern->AddResObj("width", resObj, std::move(updateFunc));
6010 }
6011 
SetHeight(FrameNode * frameNode,const CalcLength & height)6012 void ViewAbstract::SetHeight(FrameNode* frameNode, const CalcLength& height)
6013 {
6014     CHECK_NULL_VOID(frameNode);
6015     auto layoutProperty = frameNode->GetLayoutProperty();
6016     CHECK_NULL_VOID(layoutProperty);
6017     std::optional<CalcLength> width = std::nullopt;
6018     auto&& layoutConstraint = layoutProperty->GetCalcLayoutConstraint();
6019     if (layoutConstraint && layoutConstraint->selfIdealSize) {
6020         width = layoutConstraint->selfIdealSize->Width();
6021     }
6022     layoutProperty->UpdateUserDefinedIdealSize(CalcSize(width, height));
6023 }
6024 
SetHeight(FrameNode * frameNode,const RefPtr<ResourceObject> & resObj)6025 void ViewAbstract::SetHeight(FrameNode* frameNode, const RefPtr<ResourceObject>& resObj)
6026 {
6027     CHECK_NULL_VOID(frameNode);
6028     auto pattern = frameNode->GetPattern<Pattern>();
6029     CHECK_NULL_VOID(pattern);
6030     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6031         auto frameNode = weak.Upgrade();
6032         CHECK_NULL_VOID(frameNode);
6033         auto pattern = frameNode->GetPattern<Pattern>();
6034         CHECK_NULL_VOID(pattern);
6035         std::string heightString = pattern->GetResCacheMapByKey("height");
6036         CalcDimension value;
6037         if (heightString.empty()) {
6038             ResourceParseUtils::ParseResDimensionVpNG(resObj, value);
6039             pattern->AddResCache("height", value.ToString());
6040         } else {
6041             value = StringUtils::StringToCalcDimension(heightString);
6042         }
6043         if (LessNotEqual(value.Value(), 0.0)) {
6044             ClearWidthOrHeight(AceType::RawPtr(frameNode), false);
6045             return;
6046         }
6047         CalcLength height;
6048         if (value.Unit() == DimensionUnit::CALC) {
6049             height = NG::CalcLength(value.CalcValue());
6050         } else {
6051             height = NG::CalcLength(value);
6052         }
6053         auto layoutProperty = frameNode->GetLayoutProperty();
6054         CHECK_NULL_VOID(layoutProperty);
6055         // get previously user defined ideal width
6056         std::optional<CalcLength> width = std::nullopt;
6057         auto&& layoutConstraint = layoutProperty->GetCalcLayoutConstraint();
6058         if (layoutConstraint && layoutConstraint->selfIdealSize) {
6059             width = layoutConstraint->selfIdealSize->Width();
6060         }
6061         layoutProperty->UpdateUserDefinedIdealSize(CalcSize(width, height));
6062         frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
6063     };
6064     updateFunc(resObj);
6065     pattern->AddResObj("height", resObj, std::move(updateFunc));
6066 }
6067 
ClearWidthOrHeight(FrameNode * frameNode,bool isWidth)6068 void ViewAbstract::ClearWidthOrHeight(FrameNode* frameNode, bool isWidth)
6069 {
6070     CHECK_NULL_VOID(frameNode);
6071     auto layoutProperty = frameNode->GetLayoutProperty();
6072     CHECK_NULL_VOID(layoutProperty);
6073     layoutProperty->ClearUserDefinedIdealSize(isWidth, !isWidth);
6074 }
6075 
SetPositionX(FrameNode * frameNode,OffsetT<Dimension> & value,const RefPtr<ResourceObject> & xresObj)6076 void ViewAbstract::SetPositionX(FrameNode* frameNode, OffsetT<Dimension>& value, const RefPtr<ResourceObject>& xresObj)
6077 {
6078     CHECK_NULL_VOID(frameNode);
6079     auto pattern = frameNode->GetPattern<Pattern>();
6080     CHECK_NULL_VOID(pattern);
6081     if (!xresObj) {
6082         return;
6083     }
6084     auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6085         auto frameNode = weak.Upgrade();
6086         CHECK_NULL_VOID(frameNode);
6087         auto pattern = frameNode->GetPattern<Pattern>();
6088         CHECK_NULL_VOID(pattern);
6089         std::string xString = pattern->GetResCacheMapByKey("position.x");
6090         OffsetT<Dimension> &offset = const_cast<OffsetT<Dimension> &>(value);
6091         CalcDimension x;
6092         if (xString.empty()) {
6093             ResourceParseUtils::ParseResDimensionVpNG(resObj, x);
6094             pattern->AddResCache("position.x", x.ToString());
6095         } else {
6096             x = StringUtils::StringToCalcDimension(xString);
6097         }
6098         const auto& renderContext = frameNode->GetRenderContext();
6099         CHECK_NULL_VOID(renderContext);
6100         auto position = renderContext->GetPositionValue({});
6101         offset.SetY(position.GetY());
6102         offset.SetX(x);
6103         auto parentNode = frameNode->GetAncestorNodeOfFrame(false);
6104         CHECK_NULL_VOID(parentNode);
6105         if (parentNode->GetTag() == V2::COLUMN_ETS_TAG || parentNode->GetTag() == V2::ROW_ETS_TAG ||
6106             parentNode->GetTag() == V2::FLEX_ETS_TAG) {
6107             auto renderContext = frameNode->GetRenderContext();
6108             CHECK_NULL_VOID(renderContext);
6109             if (!renderContext->HasPositionEdges() && !renderContext->HasPosition()) {
6110                 parentNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
6111             }
6112         }
6113         ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, PositionEdges, frameNode);
6114         ACE_UPDATE_NODE_RENDER_CONTEXT(Position, offset, frameNode);
6115     };
6116     pattern->AddResObj("position.x", xresObj, std::move(updateFunc));
6117 }
6118 
SetPositionY(FrameNode * frameNode,OffsetT<Dimension> & value,const RefPtr<ResourceObject> & yresObj)6119 void ViewAbstract::SetPositionY(FrameNode* frameNode, OffsetT<Dimension>& value, const RefPtr<ResourceObject>& yresObj)
6120 {
6121     CHECK_NULL_VOID(frameNode);
6122     auto pattern = frameNode->GetPattern<Pattern>();
6123     CHECK_NULL_VOID(pattern);
6124     if (!yresObj) {
6125         return;
6126     }
6127     auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6128         auto frameNode = weak.Upgrade();
6129         CHECK_NULL_VOID(frameNode);
6130         auto pattern = frameNode->GetPattern<Pattern>();
6131         CHECK_NULL_VOID(pattern);
6132         std::string yString = pattern->GetResCacheMapByKey("position.y");
6133         OffsetT<Dimension> &offset = const_cast<OffsetT<Dimension> &>(value);
6134         CalcDimension y;
6135         if (yString.empty()) {
6136             ResourceParseUtils::ParseResDimensionVpNG(resObj, y);
6137             pattern->AddResCache("position.y", y.ToString());
6138         } else {
6139             y = StringUtils::StringToCalcDimension(yString);
6140         }
6141         const auto& renderContext = frameNode->GetRenderContext();
6142         CHECK_NULL_VOID(renderContext);
6143         auto position = renderContext->GetPositionValue({});
6144         offset.SetX(position.GetX());
6145         offset.SetY(y);
6146         auto parentNode = frameNode->GetAncestorNodeOfFrame(false);
6147         CHECK_NULL_VOID(parentNode);
6148         if (parentNode->GetTag() == V2::COLUMN_ETS_TAG || parentNode->GetTag() == V2::ROW_ETS_TAG ||
6149             parentNode->GetTag() == V2::FLEX_ETS_TAG) {
6150             auto renderContext = frameNode->GetRenderContext();
6151             CHECK_NULL_VOID(renderContext);
6152             if (!renderContext->HasPositionEdges() && !renderContext->HasPosition()) {
6153                 parentNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
6154             }
6155         }
6156         ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, PositionEdges, frameNode);
6157         ACE_UPDATE_NODE_RENDER_CONTEXT(Position, offset, frameNode);
6158     };
6159     pattern->AddResObj("position.y", yresObj, std::move(updateFunc));
6160 }
6161 
SetPosition(FrameNode * frameNode,const OffsetT<Dimension> & value)6162 void ViewAbstract::SetPosition(FrameNode* frameNode, const OffsetT<Dimension>& value)
6163 {
6164     CHECK_NULL_VOID(frameNode);
6165     CheckIfParentNeedMarkDirty(frameNode);
6166     ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, PositionEdges, frameNode);
6167     ACE_UPDATE_NODE_RENDER_CONTEXT(Position, value, frameNode);
6168 }
6169 
SetPosition(FrameNode * frameNode,OffsetT<Dimension> & value,const RefPtr<ResourceObject> & xresObj,const RefPtr<ResourceObject> & yresObj)6170 void ViewAbstract::SetPosition(FrameNode* frameNode, OffsetT<Dimension>& value, const RefPtr<ResourceObject>& xresObj,
6171     const RefPtr<ResourceObject>& yresObj)
6172 {
6173     CHECK_NULL_VOID(frameNode);
6174     SetPositionX(frameNode, value, xresObj);
6175     SetPositionY(frameNode, value, yresObj);
6176     CheckIfParentNeedMarkDirty(frameNode);
6177     ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, PositionEdges, frameNode);
6178     ACE_UPDATE_NODE_RENDER_CONTEXT(Position, value, frameNode);
6179 }
6180 
SetPositionEdges(FrameNode * frameNode,const EdgesParam & value)6181 void ViewAbstract::SetPositionEdges(FrameNode* frameNode, const EdgesParam& value)
6182 {
6183     CHECK_NULL_VOID(frameNode);
6184     CheckIfParentNeedMarkDirty(frameNode);
6185     ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, Position, frameNode);
6186     ACE_UPDATE_NODE_RENDER_CONTEXT(PositionEdges, value, frameNode);
6187     if (!SystemProperties::ConfigChangePerform()) {
6188         return;
6189     }
6190     auto pattern = frameNode->GetPattern<Pattern>();
6191     CHECK_NULL_VOID(pattern);
6192     RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
6193     auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6194         auto frameNode = weak.Upgrade();
6195         CHECK_NULL_VOID(frameNode);
6196         EdgesParam &edges = const_cast<EdgesParam &>(value);
6197         edges.ReloadResources();
6198         auto layoutProperty = frameNode->GetLayoutProperty();
6199         CHECK_NULL_VOID(layoutProperty);
6200         auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
6201         CheckPositionOrOffsetLocalizedEdges(edges, layoutDirection);
6202         auto parentNode = frameNode->GetAncestorNodeOfFrame(false);
6203         CHECK_NULL_VOID(parentNode);
6204         if (parentNode->GetTag() == V2::COLUMN_ETS_TAG || parentNode->GetTag() == V2::ROW_ETS_TAG ||
6205             parentNode->GetTag() == V2::FLEX_ETS_TAG) {
6206             auto renderContext = frameNode->GetRenderContext();
6207             CHECK_NULL_VOID(renderContext);
6208             if (!renderContext->HasPositionEdges() && !renderContext->HasPosition()) {
6209                 parentNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
6210             }
6211         }
6212         ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, Position, frameNode);
6213         ACE_UPDATE_NODE_RENDER_CONTEXT(PositionEdges, edges, frameNode);
6214     };
6215     pattern->AddResObj("position.edges", resObj, std::move(updateFunc));
6216 }
6217 
ResetPosition(FrameNode * frameNode)6218 void ViewAbstract::ResetPosition(FrameNode* frameNode)
6219 {
6220     ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, Position, frameNode);
6221     ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, PositionEdges, frameNode);
6222     CHECK_NULL_VOID(frameNode);
6223     auto parentNode = frameNode->GetAncestorNodeOfFrame(false);
6224     CHECK_NULL_VOID(parentNode);
6225     auto parentPattern = parentNode->GetPattern();
6226 
6227     if (parentNode->GetTag() == V2::COLUMN_ETS_TAG || parentNode->GetTag() == V2::ROW_ETS_TAG ||
6228         parentNode->GetTag() == V2::FLEX_ETS_TAG) {
6229         frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
6230     } else {
6231         auto renderContext = frameNode->GetRenderContext();
6232         CHECK_NULL_VOID(renderContext);
6233         renderContext->RecalculatePosition();
6234     }
6235 }
6236 
SetTransformMatrix(FrameNode * frameNode,const Matrix4 & matrix)6237 void ViewAbstract::SetTransformMatrix(FrameNode* frameNode, const Matrix4& matrix)
6238 {
6239     ACE_UPDATE_NODE_RENDER_CONTEXT(TransformMatrix, matrix, frameNode);
6240 }
6241 
SetTransform3DMatrix(FrameNode * frameNode,const Matrix4 & matrix)6242 void ViewAbstract::SetTransform3DMatrix(FrameNode* frameNode, const Matrix4& matrix)
6243 {
6244     ACE_UPDATE_NODE_RENDER_CONTEXT(Transform3DMatrix, matrix, frameNode);
6245 }
6246 
SetHitTestMode(FrameNode * frameNode,HitTestMode hitTestMode)6247 void ViewAbstract::SetHitTestMode(FrameNode* frameNode, HitTestMode hitTestMode)
6248 {
6249     CHECK_NULL_VOID(frameNode);
6250     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
6251     CHECK_NULL_VOID(gestureHub);
6252     gestureHub->SetHitTestMode(hitTestMode);
6253 }
6254 
SetOpacity(FrameNode * frameNode,double opacity)6255 void ViewAbstract::SetOpacity(FrameNode* frameNode, double opacity)
6256 {
6257     ACE_UPDATE_NODE_RENDER_CONTEXT(Opacity, opacity, frameNode);
6258 }
6259 
SetOpacity(FrameNode * frameNode,double opacity,const RefPtr<ResourceObject> & resObj)6260 void ViewAbstract::SetOpacity(FrameNode* frameNode, double opacity, const RefPtr<ResourceObject>& resObj)
6261 {
6262     CHECK_NULL_VOID(frameNode);
6263     auto pattern = frameNode->GetPattern();
6264     CHECK_NULL_VOID(pattern);
6265     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6266         auto frameNode = weak.Upgrade();
6267         CHECK_NULL_VOID(frameNode);
6268         auto pattern = frameNode->GetPattern();
6269         CHECK_NULL_VOID(pattern);
6270         std::string viewAbstractOpacity = pattern->GetResCacheMapByKey("viewAbstract.opacity");
6271         double result;
6272         ResourceParseUtils::ParseResDouble(resObj, result);
6273         if (result > 1.0 || LessNotEqual(result, 0.0)) {
6274             result = 1.0;
6275         }
6276         if (viewAbstractOpacity.empty()) {
6277             pattern->AddResCache("viewAbstract.opacity", std::to_string(result));
6278         }
6279         ACE_UPDATE_NODE_RENDER_CONTEXT(Opacity, result, frameNode);
6280     };
6281     pattern->AddResObj("viewAbstract.opacity", resObj, std::move(updateFunc));
6282     ACE_UPDATE_NODE_RENDER_CONTEXT(Opacity, opacity, frameNode);
6283 }
6284 
CreateWithOpacityResourceObj(const RefPtr<ResourceObject> & resObj)6285 void ViewAbstract::CreateWithOpacityResourceObj(const RefPtr<ResourceObject>& resObj)
6286 {
6287     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
6288     CHECK_NULL_VOID(frameNode);
6289 
6290     auto pattern = frameNode->GetPattern();
6291     CHECK_NULL_VOID(pattern);
6292     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6293         auto frameNode = weak.Upgrade();
6294         CHECK_NULL_VOID(frameNode);
6295         auto pattern = frameNode->GetPattern();
6296         CHECK_NULL_VOID(pattern);
6297         std::string viewAbstractOpacity = pattern->GetResCacheMapByKey("viewAbstract.opacity");
6298         double result;
6299         ResourceParseUtils::ParseResDouble(resObj, result);
6300         if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
6301                 result = std::clamp(result, 0.0, 1.0);
6302             } else {
6303                 if (result > 1.0 || LessNotEqual(result, 0.0)) {
6304                     result = 1.0;
6305                 }
6306             }
6307         if (viewAbstractOpacity.empty()) {
6308             pattern->AddResCache("viewAbstract.opacity", std::to_string(result));
6309         } else {
6310         }
6311         ACE_UPDATE_NODE_RENDER_CONTEXT(Opacity, result, frameNode);
6312     };
6313     updateFunc(resObj);
6314     pattern->AddResObj("viewAbstract.opacity", resObj, std::move(updateFunc));
6315 }
6316 
SetZIndex(FrameNode * frameNode,int32_t value)6317 void ViewAbstract::SetZIndex(FrameNode* frameNode, int32_t value)
6318 {
6319     ACE_UPDATE_NODE_RENDER_CONTEXT(ZIndex, value, frameNode);
6320 }
6321 
SetLinearGradient(FrameNode * frameNode,const NG::Gradient & gradient)6322 void ViewAbstract::SetLinearGradient(FrameNode* frameNode, const NG::Gradient& gradient)
6323 {
6324     if (SystemProperties::ConfigChangePerform()) {
6325         CHECK_NULL_VOID(frameNode);
6326         auto pattern = frameNode->GetPattern();
6327         CHECK_NULL_VOID(pattern);
6328         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
6329         auto&& updateFunc = [gradient, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6330             auto frameNode = weak.Upgrade();
6331             CHECK_NULL_VOID(frameNode);
6332             Gradient& gradientValue = const_cast<Gradient &>(gradient);
6333             gradientValue.ReloadResources();
6334             ACE_UPDATE_NODE_RENDER_CONTEXT(LastGradientType, NG::GradientType::LINEAR, frameNode);
6335             ACE_UPDATE_NODE_RENDER_CONTEXT(LinearGradient, gradientValue, frameNode);
6336         };
6337         pattern->AddResObj("LinearGradient.gradient", resObj, std::move(updateFunc));
6338     }
6339     ACE_UPDATE_NODE_RENDER_CONTEXT(LastGradientType, NG::GradientType::LINEAR, frameNode);
6340     ACE_UPDATE_NODE_RENDER_CONTEXT(LinearGradient, gradient, frameNode);
6341 }
6342 
SetSweepGradient(FrameNode * frameNode,const NG::Gradient & gradient)6343 void ViewAbstract::SetSweepGradient(FrameNode* frameNode, const NG::Gradient& gradient)
6344 {
6345     if (SystemProperties::ConfigChangePerform()) {
6346         CHECK_NULL_VOID(frameNode);
6347         auto pattern = frameNode->GetPattern();
6348         CHECK_NULL_VOID(pattern);
6349         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
6350         auto&& updateFunc = [gradient, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6351             auto frameNode = weak.Upgrade();
6352             CHECK_NULL_VOID(frameNode);
6353             Gradient& gradientValue = const_cast<Gradient &>(gradient);
6354             auto sweepGradientPtr = gradientValue.GetSweepGradient();
6355             if (sweepGradientPtr) {
6356                 gradientValue.SetSweepGradient(*sweepGradientPtr);
6357             }
6358             gradientValue.ReloadResources();
6359             ACE_UPDATE_NODE_RENDER_CONTEXT(LastGradientType, NG::GradientType::SWEEP, frameNode);
6360             ACE_UPDATE_NODE_RENDER_CONTEXT(SweepGradient, gradientValue, frameNode);
6361             const auto& target = frameNode->GetRenderContext();
6362             if (target) {
6363                 target->OnSweepGradientUpdate(gradientValue);
6364             }
6365         };
6366         pattern->AddResObj("SweepGradient.gradient", resObj, std::move(updateFunc));
6367     }
6368     ACE_UPDATE_NODE_RENDER_CONTEXT(LastGradientType, NG::GradientType::SWEEP, frameNode);
6369     ACE_UPDATE_NODE_RENDER_CONTEXT(SweepGradient, gradient, frameNode);
6370 }
6371 
SetRadialGradient(FrameNode * frameNode,const NG::Gradient & gradient)6372 void ViewAbstract::SetRadialGradient(FrameNode* frameNode, const NG::Gradient& gradient)
6373 {
6374     if (SystemProperties::ConfigChangePerform()) {
6375         CHECK_NULL_VOID(frameNode);
6376         auto pattern = frameNode->GetPattern();
6377         CHECK_NULL_VOID(pattern);
6378         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
6379         auto&& updateFunc = [gradient, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6380             auto frameNode = weak.Upgrade();
6381             CHECK_NULL_VOID(frameNode);
6382             Gradient& gradientValue = const_cast<Gradient &>(gradient);
6383             auto radialGradientPtr = gradientValue.GetRadialGradient();
6384             if (radialGradientPtr) {
6385                 gradientValue.SetRadialGradient(*radialGradientPtr);
6386             }
6387             gradientValue.ReloadResources();
6388             ACE_UPDATE_NODE_RENDER_CONTEXT(LastGradientType, NG::GradientType::RADIAL, frameNode);
6389             ACE_UPDATE_NODE_RENDER_CONTEXT(RadialGradient, gradientValue, frameNode);
6390         };
6391         pattern->AddResObj("RadialGradient.gradient", resObj, std::move(updateFunc));
6392     }
6393     ACE_UPDATE_NODE_RENDER_CONTEXT(LastGradientType, NG::GradientType::RADIAL, frameNode);
6394     ACE_UPDATE_NODE_RENDER_CONTEXT(RadialGradient, gradient, frameNode);
6395 }
6396 
SetOverlay(FrameNode * frameNode,const NG::OverlayOptions & overlay)6397 void ViewAbstract::SetOverlay(FrameNode* frameNode, const NG::OverlayOptions& overlay)
6398 {
6399     ACE_UPDATE_NODE_RENDER_CONTEXT(OverlayText, overlay, frameNode);
6400 }
6401 
SetBorderImage(FrameNode * frameNode,const RefPtr<BorderImage> & borderImage)6402 void ViewAbstract::SetBorderImage(FrameNode* frameNode, const RefPtr<BorderImage>& borderImage)
6403 {
6404     ACE_UPDATE_NODE_RENDER_CONTEXT(BorderImage, borderImage, frameNode);
6405 }
6406 
SetBorderImageSource(FrameNode * frameNode,const std::string & bdImageSrc)6407 void ViewAbstract::SetBorderImageSource(FrameNode* frameNode, const std::string& bdImageSrc)
6408 {
6409     ImageSourceInfo imageSourceInfo(bdImageSrc);
6410     ACE_UPDATE_NODE_RENDER_CONTEXT(BorderImageSource, imageSourceInfo, frameNode);
6411     ACE_UPDATE_NODE_RENDER_CONTEXT(BorderSourceFromImage, true, frameNode);
6412 }
6413 
SetHasBorderImageSlice(FrameNode * frameNode,bool tag)6414 void ViewAbstract::SetHasBorderImageSlice(FrameNode* frameNode, bool tag)
6415 {
6416     ACE_UPDATE_NODE_RENDER_CONTEXT(HasBorderImageSlice, tag, frameNode);
6417 }
6418 
SetHasBorderImageWidth(FrameNode * frameNode,bool tag)6419 void ViewAbstract::SetHasBorderImageWidth(FrameNode* frameNode, bool tag)
6420 {
6421     ACE_UPDATE_NODE_RENDER_CONTEXT(HasBorderImageWidth, tag, frameNode);
6422 }
6423 
SetHasBorderImageOutset(FrameNode * frameNode,bool tag)6424 void ViewAbstract::SetHasBorderImageOutset(FrameNode* frameNode, bool tag)
6425 {
6426     ACE_UPDATE_NODE_RENDER_CONTEXT(HasBorderImageOutset, tag, frameNode);
6427 }
6428 
SetHasBorderImageRepeat(FrameNode * frameNode,bool tag)6429 void ViewAbstract::SetHasBorderImageRepeat(FrameNode* frameNode, bool tag)
6430 {
6431     ACE_UPDATE_NODE_RENDER_CONTEXT(HasBorderImageRepeat, tag, frameNode);
6432 }
6433 
SetBorderImageGradient(FrameNode * frameNode,const NG::Gradient & gradient)6434 void ViewAbstract::SetBorderImageGradient(FrameNode* frameNode, const NG::Gradient& gradient)
6435 {
6436     ACE_UPDATE_NODE_RENDER_CONTEXT(BorderImageGradient, gradient, frameNode);
6437     ACE_UPDATE_NODE_RENDER_CONTEXT(BorderSourceFromImage, false, frameNode);
6438 }
6439 
SetForegroundBlurStyle(FrameNode * frameNode,const BlurStyleOption & fgBlurStyle,const SysOptions & sysOptions)6440 void ViewAbstract::SetForegroundBlurStyle(
6441     FrameNode* frameNode, const BlurStyleOption& fgBlurStyle, const SysOptions& sysOptions)
6442 {
6443     const auto target = frameNode->GetRenderContext();
6444     if (target) {
6445         target->UpdateFrontBlurStyle(fgBlurStyle, sysOptions);
6446         if (target->GetFrontBlurRadius().has_value()) {
6447             target->UpdateFrontBlurRadius(Dimension());
6448         }
6449     }
6450 }
6451 
SetLinearGradientBlur(FrameNode * frameNode,const NG::LinearGradientBlurPara & blurPara)6452 void ViewAbstract::SetLinearGradientBlur(FrameNode *frameNode, const NG::LinearGradientBlurPara& blurPara)
6453 {
6454     ACE_UPDATE_NODE_RENDER_CONTEXT(LinearGradientBlur, blurPara, frameNode);
6455 }
6456 
SetMagnifier(FrameNode * frameNode,const MagnifierParams & magnifierOffset)6457 void ViewAbstract::SetMagnifier(FrameNode* frameNode, const MagnifierParams& magnifierOffset)
6458 {
6459     ACE_UPDATE_NODE_RENDER_CONTEXT(Magnifier, magnifierOffset, frameNode);
6460 }
6461 
ReSetMagnifier(FrameNode * frameNode)6462 void ViewAbstract::ReSetMagnifier(FrameNode* frameNode)
6463 {
6464     ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, Magnifier, frameNode);
6465 }
6466 
UpdateBackgroundBlurStyle(FrameNode * frameNode,const BlurStyleOption & bgBlurStyle,const SysOptions & sysOptions)6467 void ViewAbstract::UpdateBackgroundBlurStyle(
6468     FrameNode* frameNode, const BlurStyleOption& bgBlurStyle, const SysOptions& sysOptions)
6469 {
6470     FREE_NODE_CHECK(frameNode, UpdateBackgroundBlurStyle, frameNode, bgBlurStyle, sysOptions);
6471     CHECK_NULL_VOID(frameNode);
6472     auto pipeline = frameNode->GetContext();
6473     CHECK_NULL_VOID(pipeline);
6474     if (bgBlurStyle.policy == BlurStyleActivePolicy::FOLLOWS_WINDOW_ACTIVE_STATE) {
6475         pipeline->AddWindowFocusChangedCallback(frameNode->GetId());
6476     } else {
6477         pipeline->RemoveWindowFocusChangedCallback(frameNode->GetId());
6478     }
6479     auto target = frameNode->GetRenderContext();
6480     if (target) {
6481         if (target->GetBackgroundEffect().has_value()) {
6482             target->UpdateBackgroundEffect(std::nullopt);
6483         }
6484         target->UpdateBackBlurStyle(bgBlurStyle, sysOptions);
6485         if (target->GetBackBlurRadius().has_value()) {
6486             target->UpdateBackBlurRadius(Dimension());
6487         }
6488     }
6489 }
6490 
SetBackgroundBlurStyle(FrameNode * frameNode,const BlurStyleOption & bgBlurStyle,const SysOptions & sysOptions)6491 void ViewAbstract::SetBackgroundBlurStyle(
6492     FrameNode* frameNode, const BlurStyleOption& bgBlurStyle, const SysOptions& sysOptions)
6493 {
6494     CHECK_NULL_VOID(frameNode);
6495     if (SystemProperties::ConfigChangePerform()) {
6496         auto pattern = frameNode->GetPattern();
6497         CHECK_NULL_VOID(pattern);
6498         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
6499         auto&& updateFunc = [bgBlurStyle, sysOptions, weak = AceType::WeakClaim(frameNode)](
6500                                 const RefPtr<ResourceObject>& resObj) {
6501             auto frameNode = weak.Upgrade();
6502             CHECK_NULL_VOID(frameNode);
6503             BlurStyleOption& bgBlurStyleValue = const_cast<BlurStyleOption&>(bgBlurStyle);
6504             bgBlurStyleValue.ReloadResources();
6505             UpdateBackgroundBlurStyle(AceType::RawPtr(frameNode), bgBlurStyleValue, sysOptions);
6506         };
6507         pattern->AddResObj("backgroundBlurStyle.backgroundBlurStyleOptions", resObj, std::move(updateFunc));
6508     }
6509     UpdateBackgroundBlurStyle(frameNode, bgBlurStyle, sysOptions);
6510 }
6511 
SetPixelStretchEffect(FrameNode * frameNode,PixStretchEffectOption & option)6512 void ViewAbstract::SetPixelStretchEffect(FrameNode* frameNode, PixStretchEffectOption& option)
6513 {
6514     if (SystemProperties::ConfigChangePerform()) {
6515         CHECK_NULL_VOID(frameNode);
6516         auto pattern = frameNode->GetPattern();
6517         CHECK_NULL_VOID(pattern);
6518         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
6519         auto&& updateFunc = [option, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6520             auto frameNode = weak.Upgrade();
6521             CHECK_NULL_VOID(frameNode);
6522             PixStretchEffectOption& value = const_cast<PixStretchEffectOption&>(option);
6523             value.ReloadResources();
6524             ACE_UPDATE_NODE_RENDER_CONTEXT(PixelStretchEffect, value, frameNode);
6525         };
6526         pattern->AddResObj("pixelStretchEffect", resObj, std::move(updateFunc));
6527     }
6528     ACE_UPDATE_NODE_RENDER_CONTEXT(PixelStretchEffect, option, frameNode);
6529 }
6530 
SetLightUpEffect(FrameNode * frameNode,double radio)6531 void ViewAbstract::SetLightUpEffect(FrameNode* frameNode, double radio)
6532 {
6533     ACE_UPDATE_NODE_RENDER_CONTEXT(LightUpEffect, radio, frameNode);
6534 }
6535 
SetSphericalEffect(FrameNode * frameNode,double radio)6536 void ViewAbstract::SetSphericalEffect(FrameNode* frameNode, double radio)
6537 {
6538     ACE_UPDATE_NODE_RENDER_CONTEXT(SphericalEffect, radio, frameNode);
6539 }
6540 
SetRenderGroup(FrameNode * frameNode,bool isRenderGroup)6541 void ViewAbstract::SetRenderGroup(FrameNode* frameNode, bool isRenderGroup)
6542 {
6543     ACE_UPDATE_NODE_RENDER_CONTEXT(RenderGroup, isRenderGroup, frameNode);
6544     CHECK_NULL_VOID(frameNode);
6545     frameNode->SetApplicationRenderGroupMarked(true);
6546 }
6547 
SetRenderFit(FrameNode * frameNode,RenderFit renderFit)6548 void ViewAbstract::SetRenderFit(FrameNode* frameNode, RenderFit renderFit)
6549 {
6550     ACE_UPDATE_NODE_RENDER_CONTEXT(RenderFit, renderFit, frameNode);
6551 }
6552 
SetUseEffect(FrameNode * frameNode,bool useEffect,EffectType effectType)6553 void ViewAbstract::SetUseEffect(FrameNode* frameNode, bool useEffect, EffectType effectType)
6554 {
6555     CHECK_NULL_VOID(frameNode);
6556     auto* pipeline = frameNode->GetContext();
6557     CHECK_NULL_VOID(pipeline);
6558     if (useEffect && effectType == EffectType::WINDOW_EFFECT) {
6559         pipeline->AddWindowActivateChangedCallback(frameNode->GetId());
6560     } else {
6561         pipeline->RemoveWindowActivateChangedCallback(frameNode->GetId());
6562     }
6563     const auto& target = frameNode->GetRenderContext();
6564     if (target) {
6565         target->UpdateUseEffect(useEffect);
6566         target->UpdateUseEffectType(effectType);
6567     }
6568 }
6569 
SetForegroundColor(FrameNode * frameNode,const Color & color)6570 void ViewAbstract::SetForegroundColor(FrameNode* frameNode, const Color& color)
6571 {
6572     auto renderContext = frameNode->GetRenderContext();
6573     CHECK_NULL_VOID(renderContext);
6574     if (renderContext->GetForegroundColorStrategy().has_value()) {
6575         renderContext->UpdateForegroundColorStrategy(ForegroundColorStrategy::NONE);
6576         renderContext->ResetForegroundColorStrategy();
6577     }
6578     renderContext->UpdateForegroundColor(color);
6579     renderContext->UpdateForegroundColorFlag(true);
6580 }
6581 
SetForegroundColor(FrameNode * frameNode,const Color & color,const RefPtr<ResourceObject> & resObj)6582 void ViewAbstract::SetForegroundColor(FrameNode* frameNode, const Color& color, const RefPtr<ResourceObject>& resObj)
6583 {
6584     if (SystemProperties::ConfigChangePerform() && resObj) {
6585         auto pattern = frameNode->GetPattern<Pattern>();
6586         CHECK_NULL_VOID(pattern);
6587         auto &&updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject> &resObj) {
6588             auto frameNode = weak.Upgrade();
6589             CHECK_NULL_VOID(frameNode);
6590             auto pattern = frameNode->GetPattern<Pattern>();
6591             CHECK_NULL_VOID(pattern);
6592             std::string foregroundColorStr = pattern->GetResCacheMapByKey("foregroundColor");
6593             Color foregroundColor;
6594             if (foregroundColorStr.empty()) {
6595                 ResourceParseUtils::ParseResColor(resObj, foregroundColor);
6596                 pattern->AddResCache("foregroundColor", foregroundColor.ColorToString());
6597             } else {
6598                 Color::ParseColorString(foregroundColorStr, foregroundColor);
6599             }
6600             SetForegroundColor(AceType::RawPtr(frameNode), foregroundColor);
6601             auto target = frameNode->GetRenderContext();
6602             if (target) {
6603                 target->OnForegroundColorUpdate(foregroundColor);
6604             }
6605             frameNode->MarkModifyDone();
6606             frameNode->MarkDirtyNode();
6607         };
6608         updateFunc(resObj);
6609         pattern->AddResObj("foregroundColor", resObj, std::move(updateFunc));
6610     }
6611     SetForegroundColor(frameNode, color);
6612 }
6613 
SetForegroundColorStrategy(FrameNode * frameNode,const ForegroundColorStrategy & strategy)6614 void ViewAbstract::SetForegroundColorStrategy(FrameNode* frameNode, const ForegroundColorStrategy& strategy)
6615 {
6616     ACE_UPDATE_NODE_RENDER_CONTEXT(ForegroundColorStrategy, strategy, frameNode);
6617     ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, ForegroundColor, frameNode);
6618     ACE_UPDATE_NODE_RENDER_CONTEXT(ForegroundColorFlag, true, frameNode);
6619     if (SystemProperties::ConfigChangePerform()) {
6620         auto pattern = frameNode->GetPattern<Pattern>();
6621         CHECK_NULL_VOID(pattern);
6622         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
6623         auto&& updateFunc = [weak = AceType::WeakClaim(frameNode), strategy](const RefPtr<ResourceObject>& resObj) {
6624             auto frameNode = weak.Upgrade();
6625             CHECK_NULL_VOID(frameNode);
6626             ACE_UPDATE_NODE_RENDER_CONTEXT(ForegroundColorStrategy, strategy, frameNode);
6627             ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, ForegroundColor, frameNode);
6628             ACE_UPDATE_NODE_RENDER_CONTEXT(ForegroundColorFlag, true, frameNode);
6629             frameNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
6630         };
6631         pattern->AddResObj("foregroundColorStrategy", resObj, std::move(updateFunc));
6632     }
6633 }
6634 
SetLightPosition(const CalcDimension & positionX,const CalcDimension & positionY,const CalcDimension & positionZ)6635 void ViewAbstract::SetLightPosition(
6636     const CalcDimension& positionX, const CalcDimension& positionY, const CalcDimension& positionZ)
6637 {
6638     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
6639         return;
6640     }
6641     ACE_UPDATE_RENDER_CONTEXT(LightPosition, TranslateOptions(positionX, positionY, positionZ));
6642 }
6643 
SetLightPosition(FrameNode * frameNode,const NG::TranslateOptions & options)6644 void ViewAbstract::SetLightPosition(FrameNode* frameNode, const NG::TranslateOptions& options)
6645 {
6646     CHECK_NULL_VOID(frameNode);
6647     ACE_UPDATE_NODE_RENDER_CONTEXT(LightPosition, options, frameNode);
6648     if (SystemProperties::ConfigChangePerform()) {
6649         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
6650         CHECK_NULL_VOID(frameNode);
6651         auto pattern = frameNode->GetPattern();
6652         CHECK_NULL_VOID(pattern);
6653         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
6654         auto&& updateFunc = [options, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6655             auto frameNode = weak.Upgrade();
6656             CHECK_NULL_VOID(frameNode);
6657             NG::TranslateOptions& optionsValue = const_cast<NG::TranslateOptions &>(options);
6658             optionsValue.ReloadResources();
6659             ACE_UPDATE_NODE_RENDER_CONTEXT(LightPosition, optionsValue, frameNode);
6660         };
6661         pattern->AddResObj("pointLight.LightSource", resObj, std::move(updateFunc));
6662     }
6663 }
6664 
SetLightPosition(const NG::TranslateOptions & options)6665 void ViewAbstract::SetLightPosition(const NG::TranslateOptions& options)
6666 {
6667     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
6668         return;
6669     }
6670     if (SystemProperties::ConfigChangePerform()) {
6671         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
6672         CHECK_NULL_VOID(frameNode);
6673         auto pattern = frameNode->GetPattern();
6674         CHECK_NULL_VOID(pattern);
6675         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
6676         auto&& updateFunc = [options, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6677             auto frameNode = weak.Upgrade();
6678             CHECK_NULL_VOID(frameNode);
6679             NG::TranslateOptions& optionsValue = const_cast<NG::TranslateOptions &>(options);
6680             optionsValue.ReloadResources();
6681             ACE_UPDATE_NODE_RENDER_CONTEXT(LightPosition, optionsValue, frameNode);
6682             frameNode->MarkModifyDone();
6683             frameNode->MarkDirtyNode();
6684         };
6685         pattern->AddResObj("pointLight.LightSource", resObj, std::move(updateFunc));
6686     }
6687     ACE_UPDATE_RENDER_CONTEXT(LightPosition, options);
6688 }
6689 
SetLightIntensity(const float value)6690 void ViewAbstract::SetLightIntensity(const float value)
6691 {
6692     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
6693         return;
6694     }
6695     ACE_UPDATE_RENDER_CONTEXT(LightIntensity, value);
6696 }
6697 
SetLightColor(const Color & value)6698 void ViewAbstract::SetLightColor(const Color& value)
6699 {
6700     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
6701         return;
6702     }
6703     ACE_UPDATE_RENDER_CONTEXT(LightColor, value);
6704 }
6705 
SetLightIlluminated(const uint32_t value)6706 void ViewAbstract::SetLightIlluminated(const uint32_t value)
6707 {
6708     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
6709         return;
6710     }
6711     ACE_UPDATE_RENDER_CONTEXT(LightIlluminated, value);
6712 }
6713 
SetIlluminatedBorderWidth(const Dimension & value)6714 void ViewAbstract::SetIlluminatedBorderWidth(const Dimension& value)
6715 {
6716     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
6717         return;
6718     }
6719     ACE_UPDATE_RENDER_CONTEXT(IlluminatedBorderWidth, value);
6720 }
6721 
SetBloom(const float value)6722 void ViewAbstract::SetBloom(const float value)
6723 {
6724     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
6725         return;
6726     }
6727     ACE_UPDATE_RENDER_CONTEXT(Bloom, value);
6728 }
6729 
SetLightPosition(FrameNode * frameNode,const CalcDimension & positionX,const CalcDimension & positionY,const CalcDimension & positionZ)6730 void ViewAbstract::SetLightPosition(FrameNode* frameNode, const CalcDimension& positionX,
6731     const CalcDimension& positionY, const CalcDimension& positionZ)
6732 {
6733     CHECK_NULL_VOID(frameNode);
6734     ACE_UPDATE_NODE_RENDER_CONTEXT(LightPosition, TranslateOptions(positionX, positionY, positionZ), frameNode);
6735 }
6736 
SetLightIntensity(FrameNode * frameNode,const float value)6737 void ViewAbstract::SetLightIntensity(FrameNode* frameNode, const float value)
6738 {
6739     CHECK_NULL_VOID(frameNode);
6740     ACE_UPDATE_NODE_RENDER_CONTEXT(LightIntensity, value, frameNode);
6741 }
6742 
SetLightColor(FrameNode * frameNode,const Color & value)6743 void ViewAbstract::SetLightColor(FrameNode* frameNode, const Color& value)
6744 {
6745     CHECK_NULL_VOID(frameNode);
6746     ACE_UPDATE_NODE_RENDER_CONTEXT(LightColor, value, frameNode);
6747 }
6748 
SetLightColor(FrameNode * frameNode,const Color & value,const RefPtr<ResourceObject> & resObj)6749 void ViewAbstract::SetLightColor(FrameNode* frameNode, const Color& value, const RefPtr<ResourceObject>& resObj)
6750 {
6751     CHECK_NULL_VOID(frameNode);
6752     auto pattern = frameNode->GetPattern<Pattern>();
6753     CHECK_NULL_VOID(pattern);
6754     auto &&updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject> &resObj) {
6755         auto frameNode = weak.Upgrade();
6756         CHECK_NULL_VOID(frameNode);
6757         auto pattern = frameNode->GetPattern<Pattern>();
6758         CHECK_NULL_VOID(pattern);
6759         std::string colorStr = pattern->GetResCacheMapByKey("LightColorRes");
6760         Color lightColor;
6761         if (colorStr.empty()) {
6762             ResourceParseUtils::ParseResColor(resObj, lightColor);
6763             pattern->AddResCache("LightColorRes", lightColor.ColorToString());
6764         } else {
6765             Color::ParseColorString(colorStr, lightColor);
6766         }
6767         ACE_UPDATE_NODE_RENDER_CONTEXT(LightColor, lightColor, frameNode);
6768     };
6769     updateFunc(resObj);
6770     pattern->AddResObj("LightColorRes", resObj, std::move(updateFunc));
6771 }
6772 
SetLightIlluminated(FrameNode * frameNode,const uint32_t value)6773 void ViewAbstract::SetLightIlluminated(FrameNode* frameNode, const uint32_t value)
6774 {
6775     CHECK_NULL_VOID(frameNode);
6776     ACE_UPDATE_NODE_RENDER_CONTEXT(LightIlluminated, value, frameNode);
6777 }
6778 
SetIlluminatedBorderWidth(FrameNode * frameNode,const Dimension & value)6779 void ViewAbstract::SetIlluminatedBorderWidth(FrameNode* frameNode, const Dimension& value)
6780 {
6781     CHECK_NULL_VOID(frameNode);
6782     ACE_UPDATE_NODE_RENDER_CONTEXT(IlluminatedBorderWidth, value, frameNode);
6783 }
6784 
SetBloom(FrameNode * frameNode,const float value)6785 void ViewAbstract::SetBloom(FrameNode* frameNode, const float value)
6786 {
6787     CHECK_NULL_VOID(frameNode);
6788     ACE_UPDATE_NODE_RENDER_CONTEXT(Bloom, value, frameNode);
6789 }
6790 
SetMotionPath(FrameNode * frameNode,const MotionPathOption & motionPath)6791 void ViewAbstract::SetMotionPath(FrameNode* frameNode, const MotionPathOption& motionPath)
6792 {
6793     ACE_UPDATE_NODE_RENDER_CONTEXT(MotionPath, motionPath, frameNode);
6794 }
6795 
SetFocusOnTouch(FrameNode * frameNode,bool isSet)6796 void ViewAbstract::SetFocusOnTouch(FrameNode* frameNode, bool isSet)
6797 {
6798     CHECK_NULL_VOID(frameNode);
6799     auto focusHub = frameNode->GetOrCreateFocusHub();
6800     CHECK_NULL_VOID(focusHub);
6801     focusHub->SetIsFocusOnTouch(isSet);
6802 }
6803 
SetGroupDefaultFocus(FrameNode * frameNode,bool isSet)6804 void ViewAbstract::SetGroupDefaultFocus(FrameNode* frameNode, bool isSet)
6805 {
6806     CHECK_NULL_VOID(frameNode);
6807     auto focusHub = frameNode->GetOrCreateFocusHub();
6808     CHECK_NULL_VOID(focusHub);
6809     focusHub->SetIsDefaultGroupFocus(isSet);
6810 }
6811 
SetFocusable(FrameNode * frameNode,bool focusable)6812 void ViewAbstract::SetFocusable(FrameNode* frameNode, bool focusable)
6813 {
6814     CHECK_NULL_VOID(frameNode);
6815     auto focusHub = frameNode->GetOrCreateFocusHub();
6816     CHECK_NULL_VOID(focusHub);
6817     focusHub->SetFocusable(focusable);
6818 }
6819 
SetTabStop(FrameNode * frameNode,bool tabStop)6820 void ViewAbstract::SetTabStop(FrameNode* frameNode, bool tabStop)
6821 {
6822     CHECK_NULL_VOID(frameNode);
6823     auto focusHub = frameNode->GetOrCreateFocusHub();
6824     CHECK_NULL_VOID(focusHub);
6825     focusHub->SetTabStop(tabStop);
6826 }
6827 
SetFocusType(FrameNode * frameNode,FocusType focusType)6828 void ViewAbstract::SetFocusType(FrameNode* frameNode, FocusType focusType)
6829 {
6830     CHECK_NULL_VOID(frameNode);
6831     auto focusHub = frameNode->GetOrCreateFocusHub();
6832     CHECK_NULL_VOID(focusHub);
6833     focusHub->SetFocusType(focusType);
6834 }
6835 
SetTouchable(FrameNode * frameNode,bool touchable)6836 void ViewAbstract::SetTouchable(FrameNode* frameNode, bool touchable)
6837 {
6838     CHECK_NULL_VOID(frameNode);
6839     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
6840     CHECK_NULL_VOID(gestureHub);
6841     gestureHub->SetTouchable(touchable);
6842 }
6843 
SetDefaultFocus(FrameNode * frameNode,bool isSet)6844 void ViewAbstract::SetDefaultFocus(FrameNode* frameNode, bool isSet)
6845 {
6846     CHECK_NULL_VOID(frameNode);
6847     auto focusHub = frameNode->GetOrCreateFocusHub();
6848     CHECK_NULL_VOID(focusHub);
6849     focusHub->SetIsDefaultFocus(isSet);
6850 }
6851 
SetDisplayIndex(FrameNode * frameNode,int32_t value)6852 void ViewAbstract::SetDisplayIndex(FrameNode* frameNode, int32_t value)
6853 {
6854     CHECK_NULL_VOID(frameNode);
6855     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, DisplayIndex, value, frameNode);
6856 }
6857 
SetOffsetX(FrameNode * frameNode,OffsetT<Dimension> & value,const RefPtr<ResourceObject> & xresObj)6858 void ViewAbstract::SetOffsetX(FrameNode* frameNode, OffsetT<Dimension>& value, const RefPtr<ResourceObject>& xresObj)
6859 {
6860     CHECK_NULL_VOID(frameNode);
6861     auto pattern = frameNode->GetPattern<Pattern>();
6862     CHECK_NULL_VOID(pattern);
6863     if (xresObj) {
6864         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6865             auto frameNode = weak.Upgrade();
6866             CHECK_NULL_VOID(frameNode);
6867             auto pattern = frameNode->GetPattern<Pattern>();
6868             CHECK_NULL_VOID(pattern);
6869             std::string xString = pattern->GetResCacheMapByKey("offset.x");
6870             OffsetT<Dimension> &offset = const_cast<OffsetT<Dimension> &>(value);
6871             CalcDimension x;
6872             if (xString.empty()) {
6873                 ResourceParseUtils::ParseResDimensionVpNG(resObj, x);
6874                 pattern->AddResCache("offset.x", x.ToString());
6875             } else {
6876                 x = StringUtils::StringToCalcDimension(xString);
6877             }
6878             const auto& renderContext = frameNode->GetRenderContext();
6879             CHECK_NULL_VOID(renderContext);
6880             auto offsetValue = renderContext->GetOffsetValue({});
6881             offset.SetY(offsetValue.GetY());
6882             offset.SetX(x);
6883             ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, OffsetEdges, frameNode);
6884             ACE_UPDATE_NODE_RENDER_CONTEXT(Offset, offset, frameNode);
6885         };
6886         pattern->AddResObj("offset.x", xresObj, std::move(updateFunc));
6887     }
6888 }
6889 
SetOffsetY(FrameNode * frameNode,OffsetT<Dimension> & value,const RefPtr<ResourceObject> & yresObj)6890 void ViewAbstract::SetOffsetY(FrameNode* frameNode, OffsetT<Dimension>& value, const RefPtr<ResourceObject>& yresObj)
6891 {
6892     CHECK_NULL_VOID(frameNode);
6893     auto pattern = frameNode->GetPattern<Pattern>();
6894     CHECK_NULL_VOID(pattern);
6895     if (yresObj) {
6896         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6897             auto frameNode = weak.Upgrade();
6898             CHECK_NULL_VOID(frameNode);
6899             auto pattern = frameNode->GetPattern<Pattern>();
6900             CHECK_NULL_VOID(pattern);
6901             std::string yString = pattern->GetResCacheMapByKey("offset.y");
6902             OffsetT<Dimension> &offset = const_cast<OffsetT<Dimension> &>(value);
6903             CalcDimension y;
6904             if (yString.empty()) {
6905                 ResourceParseUtils::ParseResDimensionVpNG(resObj, y);
6906                 pattern->AddResCache("offset.y", y.ToString());
6907             } else {
6908                 y = StringUtils::StringToCalcDimension(yString);
6909             }
6910             const auto& renderContext = frameNode->GetRenderContext();
6911             CHECK_NULL_VOID(renderContext);
6912             auto offsetValue = renderContext->GetOffsetValue({});
6913             offset.SetX(offsetValue.GetX());
6914             offset.SetY(y);
6915             ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, OffsetEdges, frameNode);
6916             ACE_UPDATE_NODE_RENDER_CONTEXT(Offset, offset, frameNode);
6917         };
6918         pattern->AddResObj("offset.y", yresObj, std::move(updateFunc));
6919     }
6920 }
6921 
SetOffset(FrameNode * frameNode,const OffsetT<Dimension> & value)6922 void ViewAbstract::SetOffset(FrameNode* frameNode, const OffsetT<Dimension>& value)
6923 {
6924     CHECK_NULL_VOID(frameNode);
6925     ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, OffsetEdges, frameNode);
6926     ACE_UPDATE_NODE_RENDER_CONTEXT(Offset, value, frameNode);
6927 }
6928 
SetOffset(FrameNode * frameNode,OffsetT<Dimension> & value,const RefPtr<ResourceObject> & xresObj,const RefPtr<ResourceObject> & yresObj)6929 void ViewAbstract::SetOffset(FrameNode* frameNode, OffsetT<Dimension>& value,
6930     const RefPtr<ResourceObject>& xresObj, const RefPtr<ResourceObject>& yresObj)
6931 {
6932     CHECK_NULL_VOID(frameNode);
6933     SetOffsetX(frameNode, value, xresObj);
6934     SetOffsetY(frameNode, value, yresObj);
6935     ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, OffsetEdges, frameNode);
6936     ACE_UPDATE_NODE_RENDER_CONTEXT(Offset, value, frameNode);
6937 }
6938 
SetOffsetEdges(FrameNode * frameNode,const EdgesParam & value)6939 void ViewAbstract::SetOffsetEdges(FrameNode* frameNode, const EdgesParam& value)
6940 {
6941     CHECK_NULL_VOID(frameNode);
6942     ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, Offset, frameNode);
6943     ACE_UPDATE_NODE_RENDER_CONTEXT(OffsetEdges, value, frameNode);
6944     if (!SystemProperties::ConfigChangePerform()) {
6945         return;
6946     }
6947     auto pattern = frameNode->GetPattern<Pattern>();
6948     CHECK_NULL_VOID(pattern);
6949     RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
6950     auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6951         auto frameNode = weak.Upgrade();
6952         CHECK_NULL_VOID(frameNode);
6953         EdgesParam &edges = const_cast<EdgesParam &>(value);
6954         edges.ReloadResources();
6955         auto layoutProperty = frameNode->GetLayoutProperty();
6956         CHECK_NULL_VOID(layoutProperty);
6957         auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
6958         CheckPositionOrOffsetLocalizedEdges(edges, layoutDirection);
6959         ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, Offset, frameNode);
6960         ACE_UPDATE_NODE_RENDER_CONTEXT(OffsetEdges, edges, frameNode);
6961     };
6962     pattern->AddResObj("offset.edges", resObj, std::move(updateFunc));
6963 }
6964 
MarkAnchorX(FrameNode * frameNode,const OffsetT<Dimension> & value,const RefPtr<ResourceObject> & xresObj)6965 void ViewAbstract::MarkAnchorX(
6966     FrameNode* frameNode, const OffsetT<Dimension>& value, const RefPtr<ResourceObject>& xresObj)
6967 {
6968     CHECK_NULL_VOID(frameNode);
6969     auto pattern = frameNode->GetPattern<Pattern>();
6970     CHECK_NULL_VOID(pattern);
6971     if (xresObj) {
6972         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
6973             auto frameNode = weak.Upgrade();
6974             CHECK_NULL_VOID(frameNode);
6975             auto pattern = frameNode->GetPattern<Pattern>();
6976             CHECK_NULL_VOID(pattern);
6977             std::string xString = pattern->GetResCacheMapByKey("markAnchor.x");
6978             OffsetT<Dimension> &offset = const_cast<OffsetT<Dimension> &>(value);
6979             CalcDimension x;
6980             auto layoutProperty = frameNode->GetLayoutProperty();
6981             CHECK_NULL_VOID(layoutProperty);
6982             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
6983             if (xString.empty()) {
6984                 ResourceParseUtils::ParseResDimensionVpNG(resObj, x);
6985                 pattern->AddResCache("markAnchor.x", x.ToString());
6986             } else {
6987                 x = layoutDirection == TextDirection::RTL ? -StringUtils::StringToCalcDimension(xString)
6988                                     : StringUtils::StringToCalcDimension(xString);
6989             }
6990             const auto& renderContext = frameNode->GetRenderContext();
6991             CHECK_NULL_VOID(renderContext);
6992             auto anchor = renderContext->GetAnchorValue({});
6993             offset.SetY(anchor.GetY());
6994             offset.SetX(x);
6995             ACE_UPDATE_NODE_RENDER_CONTEXT(Anchor, offset, frameNode);
6996         };
6997         pattern->AddResObj("markAnchor.x", xresObj, std::move(updateFunc));
6998     }
6999 }
7000 
MarkAnchorY(FrameNode * frameNode,const OffsetT<Dimension> & value,const RefPtr<ResourceObject> & yresObj)7001 void ViewAbstract::MarkAnchorY(
7002     FrameNode* frameNode, const OffsetT<Dimension>& value, const RefPtr<ResourceObject>& yresObj)
7003 {
7004     CHECK_NULL_VOID(frameNode);
7005     auto pattern = frameNode->GetPattern<Pattern>();
7006     CHECK_NULL_VOID(pattern);
7007     if (yresObj) {
7008         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
7009             auto frameNode = weak.Upgrade();
7010             CHECK_NULL_VOID(frameNode);
7011             auto pattern = frameNode->GetPattern<Pattern>();
7012             CHECK_NULL_VOID(pattern);
7013             std::string yString = pattern->GetResCacheMapByKey("markAnchor.y");
7014             OffsetT<Dimension> &offset = const_cast<OffsetT<Dimension> &>(value);
7015             CalcDimension y;
7016             auto layoutProperty = frameNode->GetLayoutProperty();
7017             CHECK_NULL_VOID(layoutProperty);
7018             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
7019             if (yString.empty()) {
7020                 ResourceParseUtils::ParseResDimensionVpNG(resObj, y);
7021                 pattern->AddResCache("markAnchor.y", y.ToString());
7022             } else {
7023                 y = layoutDirection == TextDirection::RTL ? -StringUtils::StringToCalcDimension(yString)
7024                                     : StringUtils::StringToCalcDimension(yString);
7025             }
7026             const auto& renderContext = frameNode->GetRenderContext();
7027             CHECK_NULL_VOID(renderContext);
7028             auto anchor = renderContext->GetAnchorValue({});
7029             offset.SetX(anchor.GetX());
7030             offset.SetY(y);
7031             ACE_UPDATE_NODE_RENDER_CONTEXT(Anchor, offset, frameNode);
7032         };
7033         pattern->AddResObj("markAnchor.y", yresObj, std::move(updateFunc));
7034     }
7035 }
7036 
CheckLocalizedEdgeWidths(BorderWidthProperty & value,const TextDirection & direction)7037 void ViewAbstract::CheckLocalizedEdgeWidths(BorderWidthProperty& value, const TextDirection& direction)
7038 {
7039     BorderWidthProperty borderWidth = value;
7040     if (borderWidth.startDimen.has_value()) {
7041         value.startDimen = borderWidth.startDimen;
7042         if (direction == TextDirection::RTL) {
7043             value.rightDimen = borderWidth.startDimen;
7044         } else {
7045             value.leftDimen = borderWidth.startDimen;
7046         }
7047     }
7048     if (borderWidth.endDimen.has_value()) {
7049         value.endDimen = borderWidth.endDimen;
7050         if (direction == TextDirection::RTL) {
7051             value.leftDimen = borderWidth.endDimen;
7052         } else {
7053             value.rightDimen = borderWidth.endDimen;
7054         }
7055     }
7056     if (borderWidth.topDimen.has_value()) {
7057         value.topDimen = borderWidth.topDimen;
7058     }
7059     if (borderWidth.bottomDimen.has_value()) {
7060         value.bottomDimen = borderWidth.bottomDimen;
7061     }
7062     if (value.leftDimen.has_value() && !value.rightDimen.has_value()) {
7063         value.rightDimen = std::optional<Dimension>(Dimension(0));
7064     }
7065     if (!value.leftDimen.has_value() && value.rightDimen.has_value()) {
7066         value.leftDimen = std::optional<Dimension>(Dimension(0));
7067     }
7068     value.multiValued = true;
7069 }
7070 
CheckLocalizedBorderColor(NG::BorderColorProperty & value,const TextDirection & direction)7071 void ViewAbstract::CheckLocalizedBorderColor(NG::BorderColorProperty& value, const TextDirection& direction)
7072 {
7073     NG::BorderColorProperty borderColors = value;
7074     borderColors.multiValued = true;
7075     if (borderColors.startColor.has_value()) {
7076         value.startColor = borderColors.startColor;
7077         if (direction == TextDirection::RTL) {
7078             value.rightColor = borderColors.startColor;
7079         } else {
7080             value.leftColor = borderColors.startColor;
7081         }
7082     }
7083     if (borderColors.endColor.has_value()) {
7084         value.endColor = borderColors.endColor;
7085         if (direction == TextDirection::RTL) {
7086             value.leftColor = borderColors.endColor;
7087         } else {
7088             value.rightColor = borderColors.endColor;
7089         }
7090     }
7091     if (borderColors.topColor.has_value()) {
7092         value.topColor = borderColors.topColor;
7093     }
7094     if (borderColors.bottomColor.has_value()) {
7095         value.bottomColor = borderColors.bottomColor;
7096     }
7097 }
7098 
CheckLocalizedBorderRadiuses(BorderRadiusProperty & value,const TextDirection & direction)7099 void ViewAbstract::CheckLocalizedBorderRadiuses(BorderRadiusProperty& value, const TextDirection& direction)
7100 {
7101     BorderRadiusProperty borderRadius = value;
7102     if (borderRadius.radiusTopStart.has_value()) {
7103         value.radiusTopStart = borderRadius.radiusTopStart;
7104         if (direction == TextDirection::RTL) {
7105             value.radiusTopRight = borderRadius.radiusTopStart;
7106         } else {
7107             value.radiusTopLeft = borderRadius.radiusTopStart;
7108         }
7109     }
7110     if (borderRadius.radiusTopEnd.has_value()) {
7111         value.radiusTopEnd = borderRadius.radiusTopEnd;
7112         if (direction == TextDirection::RTL) {
7113             value.radiusTopLeft = borderRadius.radiusTopEnd;
7114         } else {
7115             value.radiusTopRight = borderRadius.radiusTopEnd;
7116         }
7117     }
7118     if (borderRadius.radiusBottomStart.has_value()) {
7119         value.radiusBottomStart = borderRadius.radiusBottomStart;
7120         if (direction == TextDirection::RTL) {
7121             value.radiusBottomRight = borderRadius.radiusBottomStart;
7122         } else {
7123             value.radiusBottomLeft = borderRadius.radiusBottomStart;
7124         }
7125     }
7126     if (borderRadius.radiusBottomEnd.has_value()) {
7127         value.radiusBottomEnd = borderRadius.radiusBottomEnd;
7128         if (direction == TextDirection::RTL) {
7129             value.radiusBottomLeft = borderRadius.radiusBottomEnd;
7130         } else {
7131             value.radiusBottomRight = borderRadius.radiusBottomEnd;
7132         }
7133     }
7134 }
7135 
MarkAnchor(FrameNode * frameNode,const OffsetT<Dimension> & value)7136 void ViewAbstract::MarkAnchor(FrameNode* frameNode, const OffsetT<Dimension>& value)
7137 {
7138     CHECK_NULL_VOID(frameNode);
7139     ACE_UPDATE_NODE_RENDER_CONTEXT(Anchor, value, frameNode);
7140 }
7141 
MarkAnchor(FrameNode * frameNode,const OffsetT<Dimension> & value,const RefPtr<ResourceObject> & xresObj,const RefPtr<ResourceObject> & yresObj)7142 void ViewAbstract::MarkAnchor(FrameNode* frameNode, const OffsetT<Dimension>& value,
7143     const RefPtr<ResourceObject>& xresObj, const RefPtr<ResourceObject>& yresObj)
7144 {
7145     CHECK_NULL_VOID(frameNode);
7146     MarkAnchorX(frameNode, value, xresObj);
7147     MarkAnchorY(frameNode, value, yresObj);
7148     ACE_UPDATE_NODE_RENDER_CONTEXT(Anchor, value, frameNode);
7149 }
7150 
SetVisibility(FrameNode * frameNode,VisibleType visible)7151 void ViewAbstract::SetVisibility(FrameNode* frameNode, VisibleType visible)
7152 {
7153     CHECK_NULL_VOID(frameNode);
7154     auto layoutProperty = frameNode->GetLayoutProperty();
7155     if (layoutProperty) {
7156         layoutProperty->UpdateVisibility(visible, true, true);
7157     }
7158 
7159     auto focusHub = frameNode->GetOrCreateFocusHub();
7160     if (focusHub) {
7161         focusHub->SetShow(visible == VisibleType::VISIBLE);
7162     }
7163 }
7164 
SetPadding(FrameNode * frameNode,const CalcLength & value)7165 void ViewAbstract::SetPadding(FrameNode* frameNode, const CalcLength& value)
7166 {
7167     CHECK_NULL_VOID(frameNode);
7168     PaddingProperty padding;
7169     padding.SetEdges(value);
7170     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Padding, padding, frameNode);
7171 }
7172 
SetPadding(FrameNode * frameNode,const PaddingProperty & value)7173 void ViewAbstract::SetPadding(FrameNode* frameNode, const PaddingProperty& value)
7174 {
7175     CHECK_NULL_VOID(frameNode);
7176     if (SystemProperties::ConfigChangePerform()) {
7177         auto pattern = frameNode->GetPattern<Pattern>();
7178         CHECK_NULL_VOID(pattern);
7179         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
7180         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
7181             auto frameNode = weak.Upgrade();
7182             CHECK_NULL_VOID(frameNode);
7183             PaddingProperty& padding = const_cast<PaddingProperty&>(value);
7184             padding.ReloadResources();
7185             auto layoutProperty = frameNode->GetLayoutProperty();
7186             CHECK_NULL_VOID(layoutProperty);
7187             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
7188             CheckLocalizedMarginOrPadding(padding, layoutDirection);
7189             ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Padding, padding, frameNode);
7190             frameNode->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT | PROPERTY_UPDATE_MEASURE);
7191         };
7192         pattern->AddResObj("padding", resObj, std::move(updateFunc));
7193     }
7194     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Padding, value, frameNode);
7195 }
7196 
SetMargin(FrameNode * frameNode,const CalcLength & value)7197 void ViewAbstract::SetMargin(FrameNode* frameNode, const CalcLength& value)
7198 {
7199     CHECK_NULL_VOID(frameNode);
7200     MarginProperty margin;
7201     margin.SetEdges(value);
7202     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Margin, margin, frameNode);
7203 }
7204 
SetMargin(FrameNode * frameNode,const PaddingProperty & value)7205 void ViewAbstract::SetMargin(FrameNode* frameNode, const PaddingProperty& value)
7206 {
7207     CHECK_NULL_VOID(frameNode);
7208     if (SystemProperties::ConfigChangePerform()) {
7209         auto pattern = frameNode->GetPattern<Pattern>();
7210         CHECK_NULL_VOID(pattern);
7211         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
7212         auto&& updateFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
7213             auto frameNode = weak.Upgrade();
7214             CHECK_NULL_VOID(frameNode);
7215             MarginProperty &margin = const_cast<MarginProperty &>(value);
7216             margin.ReloadResources();
7217             auto layoutProperty = frameNode->GetLayoutProperty();
7218             CHECK_NULL_VOID(layoutProperty);
7219             auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
7220             CheckLocalizedMarginOrPadding(margin, layoutDirection);
7221             ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Margin, margin, frameNode);
7222             frameNode->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT | PROPERTY_UPDATE_MEASURE);
7223         };
7224         pattern->AddResObj("margin", resObj, std::move(updateFunc));
7225     }
7226     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Margin, value, frameNode);
7227 }
7228 
SetLayoutDirection(FrameNode * frameNode,TextDirection value)7229 void ViewAbstract::SetLayoutDirection(FrameNode* frameNode, TextDirection value)
7230 {
7231     CHECK_NULL_VOID(frameNode);
7232     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, LayoutDirection, value, frameNode);
7233 }
7234 
UpdateSafeAreaExpandOpts(FrameNode * frameNode,const SafeAreaExpandOpts & opts)7235 void ViewAbstract::UpdateSafeAreaExpandOpts(FrameNode* frameNode, const SafeAreaExpandOpts& opts)
7236 {
7237     CHECK_NULL_VOID(frameNode);
7238     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaExpandOpts, opts, frameNode);
7239 }
7240 
UpdateIgnoreLayoutSafeAreaOpts(FrameNode * frameNode,const IgnoreLayoutSafeAreaOpts & opts)7241 void ViewAbstract::UpdateIgnoreLayoutSafeAreaOpts(FrameNode* frameNode, const IgnoreLayoutSafeAreaOpts& opts)
7242 {
7243     CHECK_NULL_VOID(frameNode);
7244     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, IgnoreLayoutSafeAreaOpts, opts, frameNode);
7245 }
7246 
SetAspectRatio(FrameNode * frameNode,float ratio)7247 void ViewAbstract::SetAspectRatio(FrameNode* frameNode, float ratio)
7248 {
7249     CHECK_NULL_VOID(frameNode);
7250     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, AspectRatio, ratio, frameNode);
7251 }
7252 
SetAlignSelf(FrameNode * frameNode,FlexAlign value)7253 void ViewAbstract::SetAlignSelf(FrameNode* frameNode, FlexAlign value)
7254 {
7255     CHECK_NULL_VOID(frameNode);
7256     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, AlignSelf, value, frameNode);
7257 }
7258 
SetFlexBasis(FrameNode * frameNode,const Dimension & value)7259 void ViewAbstract::SetFlexBasis(FrameNode* frameNode, const Dimension& value)
7260 {
7261     CHECK_NULL_VOID(frameNode);
7262     if (LessNotEqual(value.Value(), 0.0f)) {
7263         ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, FlexBasis, Dimension(), frameNode);
7264         return;
7265     }
7266     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, FlexBasis, value, frameNode);
7267 }
7268 
ResetFlexShrink(FrameNode * frameNode)7269 void ViewAbstract::ResetFlexShrink(FrameNode* frameNode)
7270 {
7271     CHECK_NULL_VOID(frameNode);
7272     ACE_RESET_NODE_LAYOUT_PROPERTY(LayoutProperty, FlexShrink, frameNode);
7273 }
7274 
SetFlexShrink(FrameNode * frameNode,float value)7275 void ViewAbstract::SetFlexShrink(FrameNode* frameNode, float value)
7276 {
7277     CHECK_NULL_VOID(frameNode);
7278     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, FlexShrink, value, frameNode);
7279 }
7280 
SetFlexGrow(FrameNode * frameNode,float value)7281 void ViewAbstract::SetFlexGrow(FrameNode* frameNode, float value)
7282 {
7283     CHECK_NULL_VOID(frameNode);
7284     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, FlexGrow, value, frameNode);
7285 }
7286 
SetLayoutWeight(FrameNode * frameNode,float value)7287 void ViewAbstract::SetLayoutWeight(FrameNode* frameNode, float value)
7288 {
7289     CHECK_NULL_VOID(frameNode);
7290     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, LayoutWeight, value, frameNode);
7291 }
7292 
SetChainWeight(FrameNode * frameNode,const NG::ChainWeightPair & value)7293 void ViewAbstract::SetChainWeight(FrameNode* frameNode, const NG::ChainWeightPair& value)
7294 {
7295     CHECK_NULL_VOID(frameNode);
7296     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, ChainWeight, value, frameNode);
7297 }
7298 
ResetMaxSize(FrameNode * frameNode,bool resetWidth)7299 void ViewAbstract::ResetMaxSize(FrameNode* frameNode, bool resetWidth)
7300 {
7301     CHECK_NULL_VOID(frameNode);
7302     auto layoutProperty = frameNode->GetLayoutProperty();
7303     CHECK_NULL_VOID(layoutProperty);
7304     layoutProperty->ResetCalcMaxSize(resetWidth);
7305 }
7306 
ResetMinSize(FrameNode * frameNode,bool resetWidth)7307 void ViewAbstract::ResetMinSize(FrameNode* frameNode, bool resetWidth)
7308 {
7309     CHECK_NULL_VOID(frameNode);
7310     auto layoutProperty = frameNode->GetLayoutProperty();
7311     CHECK_NULL_VOID(layoutProperty);
7312     layoutProperty->ResetCalcMinSize(resetWidth);
7313 }
7314 
SetMinWidth(FrameNode * frameNode,const CalcLength & minWidth)7315 void ViewAbstract::SetMinWidth(FrameNode* frameNode, const CalcLength& minWidth)
7316 {
7317     CHECK_NULL_VOID(frameNode);
7318     auto layoutProperty = frameNode->GetLayoutProperty();
7319     CHECK_NULL_VOID(layoutProperty);
7320     layoutProperty->UpdateCalcMinSize(CalcSize(minWidth, std::nullopt));
7321 }
7322 
SetMinWidth(FrameNode * frameNode,const RefPtr<ResourceObject> & resObj)7323 void ViewAbstract::SetMinWidth(FrameNode* frameNode, const RefPtr<ResourceObject>& resObj)
7324 {
7325     CHECK_NULL_VOID(frameNode);
7326     auto pattern = frameNode->GetPattern<Pattern>();
7327     CHECK_NULL_VOID(pattern);
7328     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
7329         auto frameNode = weak.Upgrade();
7330         CHECK_NULL_VOID(frameNode);
7331         auto pattern = frameNode->GetPattern<Pattern>();
7332         CHECK_NULL_VOID(pattern);
7333         std::string minWidthString = pattern->GetResCacheMapByKey("constraintSize.minWidth");
7334         CalcDimension value;
7335         if (minWidthString.empty()) {
7336             ResourceParseUtils::ParseResDimensionVp(resObj, value);
7337             pattern->AddResCache("constraintSize.minWidth", value.ToString());
7338         } else {
7339             value = StringUtils::StringToCalcDimension(minWidthString);
7340         }
7341         NG::CalcLength width;
7342         width = (value.Unit() == DimensionUnit::CALC) ? NG::CalcLength(value.CalcValue()) : NG::CalcLength(value);
7343         auto layoutProperty = frameNode->GetLayoutProperty();
7344         CHECK_NULL_VOID(layoutProperty);
7345         layoutProperty->UpdateCalcMinSize(CalcSize(width, std::nullopt));
7346         frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
7347     };
7348     pattern->AddResObj("constraintSize.minWidth", resObj, std::move(updateFunc));
7349 }
7350 
SetMaxWidth(FrameNode * frameNode,const CalcLength & maxWidth)7351 void ViewAbstract::SetMaxWidth(FrameNode* frameNode, const CalcLength& maxWidth)
7352 {
7353     CHECK_NULL_VOID(frameNode);
7354     auto layoutProperty = frameNode->GetLayoutProperty();
7355     CHECK_NULL_VOID(layoutProperty);
7356     layoutProperty->UpdateCalcMaxSize(CalcSize(maxWidth, std::nullopt));
7357 }
7358 
SetMaxWidth(FrameNode * frameNode,const RefPtr<ResourceObject> & resObj)7359 void ViewAbstract::SetMaxWidth(FrameNode* frameNode, const RefPtr<ResourceObject>& resObj)
7360 {
7361     CHECK_NULL_VOID(frameNode);
7362     auto pattern = frameNode->GetPattern<Pattern>();
7363     CHECK_NULL_VOID(pattern);
7364     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
7365         auto frameNode = weak.Upgrade();
7366         CHECK_NULL_VOID(frameNode);
7367         auto pattern = frameNode->GetPattern<Pattern>();
7368         CHECK_NULL_VOID(pattern);
7369         std::string minWidthString = pattern->GetResCacheMapByKey("constraintSize.maxWidth");
7370         CalcDimension value;
7371         if (minWidthString.empty()) {
7372             ResourceParseUtils::ParseResDimensionVp(resObj, value);
7373             pattern->AddResCache("constraintSize.maxWidth", value.ToString());
7374         } else {
7375             value = StringUtils::StringToCalcDimension(minWidthString);
7376         }
7377         NG::CalcLength width;
7378         width = (value.Unit() == DimensionUnit::CALC) ? NG::CalcLength(value.CalcValue()) : NG::CalcLength(value);
7379         auto layoutProperty = frameNode->GetLayoutProperty();
7380         CHECK_NULL_VOID(layoutProperty);
7381         layoutProperty->UpdateCalcMaxSize(CalcSize(width, std::nullopt));
7382         frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
7383     };
7384     pattern->AddResObj("constraintSize.maxWidth", resObj, std::move(updateFunc));
7385 }
7386 
SetMinHeight(FrameNode * frameNode,const CalcLength & minHeight)7387 void ViewAbstract::SetMinHeight(FrameNode* frameNode, const CalcLength& minHeight)
7388 {
7389     CHECK_NULL_VOID(frameNode);
7390     auto layoutProperty = frameNode->GetLayoutProperty();
7391     CHECK_NULL_VOID(layoutProperty);
7392     layoutProperty->UpdateCalcMinSize(CalcSize(std::nullopt, minHeight));
7393 }
7394 
SetMinHeight(FrameNode * frameNode,const RefPtr<ResourceObject> & resObj)7395 void ViewAbstract::SetMinHeight(FrameNode* frameNode, const RefPtr<ResourceObject>& resObj)
7396 {
7397     CHECK_NULL_VOID(frameNode);
7398     auto pattern = frameNode->GetPattern<Pattern>();
7399     CHECK_NULL_VOID(pattern);
7400     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
7401         auto frameNode = weak.Upgrade();
7402         CHECK_NULL_VOID(frameNode);
7403         auto pattern = frameNode->GetPattern<Pattern>();
7404         CHECK_NULL_VOID(pattern);
7405         std::string minWidthString = pattern->GetResCacheMapByKey("constraintSize.minHeight");
7406         CalcDimension value;
7407         if (minWidthString.empty()) {
7408             ResourceParseUtils::ParseResDimensionVp(resObj, value);
7409             pattern->AddResCache("constraintSize.minHeight", value.ToString());
7410         } else {
7411             value = StringUtils::StringToCalcDimension(minWidthString);
7412         }
7413         NG::CalcLength height;
7414         height = (value.Unit() == DimensionUnit::CALC) ? NG::CalcLength(value.CalcValue()) : NG::CalcLength(value);
7415         auto layoutProperty = frameNode->GetLayoutProperty();
7416         CHECK_NULL_VOID(layoutProperty);
7417         layoutProperty->UpdateCalcMinSize(CalcSize(std::nullopt, height));
7418         frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
7419     };
7420     pattern->AddResObj("constraintSize.minHeight", resObj, std::move(updateFunc));
7421 }
7422 
SetMaxHeight(FrameNode * frameNode,const CalcLength & maxHeight)7423 void ViewAbstract::SetMaxHeight(FrameNode* frameNode, const CalcLength& maxHeight)
7424 {
7425     CHECK_NULL_VOID(frameNode);
7426     auto layoutProperty = frameNode->GetLayoutProperty();
7427     CHECK_NULL_VOID(layoutProperty);
7428     layoutProperty->UpdateCalcMaxSize(CalcSize(std::nullopt, maxHeight));
7429 }
7430 
SetMaxHeight(FrameNode * frameNode,const RefPtr<ResourceObject> & resObj)7431 void ViewAbstract::SetMaxHeight(FrameNode* frameNode, const RefPtr<ResourceObject>& resObj)
7432 {
7433     CHECK_NULL_VOID(frameNode);
7434     auto pattern = frameNode->GetPattern<Pattern>();
7435     CHECK_NULL_VOID(pattern);
7436     auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
7437         auto frameNode = weak.Upgrade();
7438         CHECK_NULL_VOID(frameNode);
7439         auto pattern = frameNode->GetPattern<Pattern>();
7440         CHECK_NULL_VOID(pattern);
7441         std::string minWidthString = pattern->GetResCacheMapByKey("constraintSize.maxHeight");
7442         CalcDimension value;
7443         if (minWidthString.empty()) {
7444             ResourceParseUtils::ParseResDimensionVp(resObj, value);
7445             pattern->AddResCache("constraintSize.maxHeight", value.ToString());
7446         } else {
7447             value = StringUtils::StringToCalcDimension(minWidthString);
7448         }
7449         NG::CalcLength height;
7450         height = (value.Unit() == DimensionUnit::CALC) ? NG::CalcLength(value.CalcValue()) : NG::CalcLength(value);
7451         auto layoutProperty = frameNode->GetLayoutProperty();
7452         CHECK_NULL_VOID(layoutProperty);
7453         layoutProperty->UpdateCalcMaxSize(CalcSize(std::nullopt, height));
7454         frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
7455     };
7456     pattern->AddResObj("constraintSize.maxHeight", resObj, std::move(updateFunc));
7457 }
7458 
SetAlignRules(FrameNode * frameNode,const std::map<AlignDirection,AlignRule> & alignRules)7459 void ViewAbstract::SetAlignRules(FrameNode* frameNode, const std::map<AlignDirection, AlignRule>& alignRules)
7460 {
7461     CHECK_NULL_VOID(frameNode);
7462     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, AlignRules, alignRules, frameNode);
7463 }
7464 
GetAlignRules(FrameNode * frameNode)7465 std::map<AlignDirection, AlignRule> ViewAbstract::GetAlignRules(FrameNode* frameNode)
7466 {
7467     std::map<AlignDirection, AlignRule> alignRules;
7468     CHECK_NULL_RETURN(frameNode, alignRules);
7469     auto layoutProperty = frameNode->GetLayoutProperty();
7470     CHECK_NULL_RETURN(layoutProperty, alignRules);
7471     CHECK_NULL_RETURN(layoutProperty->GetFlexItemProperty(), alignRules);
7472     return layoutProperty->GetFlexItemProperty()->GetAlignRules().value_or(alignRules);
7473 }
7474 
ResetAlignRules(FrameNode * frameNode)7475 void ViewAbstract::ResetAlignRules(FrameNode* frameNode)
7476 {
7477     CHECK_NULL_VOID(frameNode);
7478     auto layoutProperty = frameNode->GetLayoutProperty();
7479     CHECK_NULL_VOID(layoutProperty);
7480     CHECK_NULL_VOID(layoutProperty->GetFlexItemProperty());
7481     return layoutProperty->GetFlexItemProperty()->ResetAlignRules();
7482 }
7483 
SetChainStyle(FrameNode * frameNode,const ChainInfo & chainInfo)7484 void ViewAbstract::SetChainStyle(FrameNode* frameNode, const ChainInfo& chainInfo)
7485 {
7486     CHECK_NULL_VOID(frameNode);
7487     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, ChainStyle, chainInfo, frameNode);
7488 }
7489 
GetChainStyle(FrameNode * frameNode)7490 ChainInfo ViewAbstract::GetChainStyle(FrameNode* frameNode)
7491 {
7492     ChainInfo chainInfo;
7493     CHECK_NULL_RETURN(frameNode, chainInfo);
7494     auto layoutProperty = frameNode->GetLayoutProperty();
7495     CHECK_NULL_RETURN(layoutProperty->GetFlexItemProperty(), chainInfo);
7496     layoutProperty->GetFlexItemProperty()->GetHorizontalChainStyle().value_or(chainInfo);
7497     if (chainInfo.direction.has_value()) {
7498         return chainInfo;
7499     }
7500     return layoutProperty->GetFlexItemProperty()->GetVerticalChainStyle().value_or(chainInfo);
7501 }
7502 
ResetChainStyle(FrameNode * frameNode)7503 void ViewAbstract::ResetChainStyle(FrameNode* frameNode)
7504 {
7505     CHECK_NULL_VOID(frameNode);
7506     ChainInfo nullChainInfo;
7507     auto layoutProperty = frameNode->GetLayoutProperty();
7508     CHECK_NULL_VOID(layoutProperty->GetFlexItemProperty());
7509     layoutProperty->GetFlexItemProperty()->UpdateHorizontalChainStyle(nullChainInfo);
7510     layoutProperty->GetFlexItemProperty()->UpdateVerticalChainStyle(nullChainInfo);
7511 }
7512 
SetGrid(FrameNode * frameNode,std::optional<int32_t> span,std::optional<int32_t> offset,GridSizeType type)7513 void ViewAbstract::SetGrid(
7514     FrameNode* frameNode, std::optional<int32_t> span, std::optional<int32_t> offset, GridSizeType type)
7515 {
7516     CHECK_NULL_VOID(frameNode);
7517     auto layoutProperty = frameNode->GetLayoutProperty();
7518     CHECK_NULL_VOID(layoutProperty);
7519     // frame node is mounted to parent when pop from stack later, no grid-container is added here
7520     layoutProperty->UpdateGridProperty(span, offset, type);
7521 }
7522 
ResetAspectRatio(FrameNode * frameNode)7523 void ViewAbstract::ResetAspectRatio(FrameNode* frameNode)
7524 {
7525     ACE_RESET_NODE_LAYOUT_PROPERTY(LayoutProperty, AspectRatio, frameNode);
7526 }
7527 
SetAllowDrop(FrameNode * frameNode,const std::set<std::string> & allowDrop)7528 void ViewAbstract::SetAllowDrop(FrameNode* frameNode, const std::set<std::string>& allowDrop)
7529 {
7530     CHECK_NULL_VOID(frameNode);
7531     frameNode->SetAllowDrop(allowDrop);
7532 }
7533 
SetInspectorId(FrameNode * frameNode,const std::string & inspectorId)7534 void ViewAbstract::SetInspectorId(FrameNode* frameNode, const std::string& inspectorId)
7535 {
7536     FREE_NODE_CHECK(frameNode, SetInspectorId, frameNode, inspectorId);
7537     if (frameNode) {
7538         if (frameNode->GetInspectorId().has_value() && frameNode->GetInspectorIdValue() != inspectorId) {
7539             ElementRegister::GetInstance()->RemoveFrameNodeByInspectorId(
7540                 frameNode->GetInspectorIdValue(), frameNode->GetId());
7541         }
7542         frameNode->UpdateInspectorId(inspectorId);
7543     }
7544 }
7545 
SetRestoreId(FrameNode * frameNode,int32_t restoreId)7546 void ViewAbstract::SetRestoreId(FrameNode* frameNode, int32_t restoreId)
7547 {
7548     if (frameNode) {
7549         frameNode->SetRestoreId(restoreId);
7550     }
7551 }
7552 
SetTabIndex(FrameNode * frameNode,int32_t index)7553 void ViewAbstract::SetTabIndex(FrameNode* frameNode, int32_t index)
7554 {
7555     CHECK_NULL_VOID(frameNode);
7556     auto focusHub = frameNode->GetOrCreateFocusHub();
7557     CHECK_NULL_VOID(focusHub);
7558     focusHub->SetTabIndex(index);
7559 }
7560 
SetObscured(FrameNode * frameNode,const std::vector<ObscuredReasons> & reasons)7561 void ViewAbstract::SetObscured(FrameNode* frameNode, const std::vector<ObscuredReasons>& reasons)
7562 {
7563     CHECK_NULL_VOID(frameNode);
7564     ACE_UPDATE_NODE_RENDER_CONTEXT(Obscured, reasons, frameNode);
7565     frameNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
7566 }
7567 
SetForegroundEffect(FrameNode * frameNode,float radius)7568 void ViewAbstract::SetForegroundEffect(FrameNode* frameNode, float radius)
7569 {
7570     CHECK_NULL_VOID(frameNode);
7571     auto target = frameNode->GetRenderContext();
7572     if (target) {
7573         target->UpdateForegroundEffect(radius);
7574     }
7575 }
7576 
SetMotionBlur(FrameNode * frameNode,const MotionBlurOption & motionBlurOption)7577 void ViewAbstract::SetMotionBlur(FrameNode* frameNode, const MotionBlurOption &motionBlurOption)
7578 {
7579     ACE_UPDATE_NODE_RENDER_CONTEXT(MotionBlur, motionBlurOption, frameNode);
7580 }
7581 
UpdateBackgroundEffect(FrameNode * frameNode,const EffectOption & effectOption,const SysOptions & sysOptions)7582 void ViewAbstract::UpdateBackgroundEffect(
7583     FrameNode* frameNode, const EffectOption& effectOption, const SysOptions& sysOptions)
7584 {
7585     CHECK_NULL_VOID(frameNode);
7586     auto pipeline = frameNode->GetContext();
7587     CHECK_NULL_VOID(pipeline);
7588     if (effectOption.policy == BlurStyleActivePolicy::FOLLOWS_WINDOW_ACTIVE_STATE) {
7589         pipeline->AddWindowFocusChangedCallback(frameNode->GetId());
7590     } else {
7591         pipeline->RemoveWindowFocusChangedCallback(frameNode->GetId());
7592     }
7593     auto target = frameNode->GetRenderContext();
7594     if (target) {
7595         if (target->GetBackBlurRadius().has_value()) {
7596             target->UpdateBackBlurRadius(Dimension());
7597         }
7598         if (target->GetBackBlurStyle().has_value()) {
7599             target->UpdateBackBlurStyle(std::nullopt);
7600         }
7601         target->UpdateBackgroundEffect(effectOption, sysOptions);
7602     }
7603 }
7604 
SetBackgroundEffect(FrameNode * frameNode,const EffectOption & effectOption,const SysOptions & sysOptions)7605 void ViewAbstract::SetBackgroundEffect(
7606     FrameNode* frameNode, const EffectOption& effectOption, const SysOptions& sysOptions)
7607 {
7608     CHECK_NULL_VOID(frameNode);
7609     if (SystemProperties::ConfigChangePerform()) {
7610         auto pattern = frameNode->GetPattern();
7611         CHECK_NULL_VOID(pattern);
7612         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>("", "", -1);
7613         auto&& updateFunc = [effectOption, sysOptions, weak = AceType::WeakClaim(frameNode)](
7614                                 const RefPtr<ResourceObject>& resObj) {
7615             auto frameNode = weak.Upgrade();
7616             CHECK_NULL_VOID(frameNode);
7617             EffectOption& effectOptionValue = const_cast<EffectOption&>(effectOption);
7618             effectOptionValue.ReloadResources();
7619             UpdateBackgroundEffect(AceType::RawPtr(frameNode), effectOptionValue, sysOptions);
7620         };
7621         pattern->AddResObj("backgroundEffect", resObj, std::move(updateFunc));
7622     }
7623     UpdateBackgroundEffect(frameNode, effectOption, sysOptions);
7624 }
7625 
SetDynamicLightUp(FrameNode * frameNode,float rate,float lightUpDegree)7626 void ViewAbstract::SetDynamicLightUp(FrameNode* frameNode, float rate, float lightUpDegree)
7627 {
7628     ACE_UPDATE_NODE_RENDER_CONTEXT(DynamicLightUpRate, rate, frameNode);
7629     ACE_UPDATE_NODE_RENDER_CONTEXT(DynamicLightUpDegree, lightUpDegree, frameNode);
7630 }
7631 
SetBgDynamicBrightness(FrameNode * frameNode,const BrightnessOption & brightnessOption)7632 void ViewAbstract::SetBgDynamicBrightness(FrameNode* frameNode, const BrightnessOption& brightnessOption)
7633 {
7634     CHECK_NULL_VOID(frameNode);
7635     ACE_UPDATE_NODE_RENDER_CONTEXT(BgDynamicBrightnessOption, brightnessOption, frameNode);
7636 }
7637 
SetFgDynamicBrightness(FrameNode * frameNode,const BrightnessOption & brightnessOption)7638 void ViewAbstract::SetFgDynamicBrightness(FrameNode* frameNode, const BrightnessOption& brightnessOption)
7639 {
7640     CHECK_NULL_VOID(frameNode);
7641     ACE_UPDATE_NODE_RENDER_CONTEXT(FgDynamicBrightnessOption, brightnessOption, frameNode);
7642 }
7643 
SetBlender(FrameNode * frameNode,const OHOS::Rosen::Blender * blender)7644 void ViewAbstract::SetBlender(FrameNode* frameNode, const OHOS::Rosen::Blender* blender)
7645 {
7646     CHECK_NULL_VOID(frameNode);
7647     ACE_UPDATE_NODE_RENDER_CONTEXT(Blender, blender, frameNode);
7648 }
7649 
SetDragPreviewOptions(FrameNode * frameNode,const DragPreviewOption & previewOption)7650 void ViewAbstract::SetDragPreviewOptions(FrameNode* frameNode, const DragPreviewOption& previewOption)
7651 {
7652     CHECK_NULL_VOID(frameNode);
7653     frameNode->SetDragPreviewOptions(previewOption, false);
7654 }
7655 
SetDragPreview(FrameNode * frameNode,const DragDropInfo & dragDropInfo)7656 void ViewAbstract::SetDragPreview(FrameNode* frameNode, const DragDropInfo& dragDropInfo)
7657 {
7658     CHECK_NULL_VOID(frameNode);
7659     frameNode->SetDragPreview(dragDropInfo);
7660 }
7661 
SetResponseRegion(FrameNode * frameNode,const std::vector<DimensionRect> & responseRegion)7662 void ViewAbstract::SetResponseRegion(FrameNode* frameNode, const std::vector<DimensionRect>& responseRegion)
7663 {
7664     CHECK_NULL_VOID(frameNode);
7665     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
7666     CHECK_NULL_VOID(gestureHub);
7667     gestureHub->SetResponseRegion(responseRegion);
7668 }
7669 
SetMouseResponseRegion(FrameNode * frameNode,const std::vector<DimensionRect> & mouseResponseRegion)7670 void ViewAbstract::SetMouseResponseRegion(FrameNode* frameNode, const std::vector<DimensionRect>& mouseResponseRegion)
7671 {
7672     CHECK_NULL_VOID(frameNode);
7673     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
7674     CHECK_NULL_VOID(gestureHub);
7675     gestureHub->SetMouseResponseRegion(mouseResponseRegion);
7676 }
7677 
SetSharedTransition(FrameNode * frameNode,const std::string & shareId,const std::shared_ptr<SharedTransitionOption> & option)7678 void ViewAbstract::SetSharedTransition(
7679     FrameNode* frameNode, const std::string& shareId, const std::shared_ptr<SharedTransitionOption>& option)
7680 {
7681     CHECK_NULL_VOID(frameNode);
7682     const auto& target = frameNode->GetRenderContext();
7683     if (target) {
7684         target->SetSharedTransitionOptions(option);
7685         target->SetShareId(shareId);
7686     }
7687 }
7688 
SetTransition(FrameNode * frameNode,const TransitionOptions & options)7689 void ViewAbstract::SetTransition(FrameNode* frameNode, const TransitionOptions& options)
7690 {
7691     ACE_UPDATE_NODE_RENDER_CONTEXT(Transition, options, frameNode);
7692 }
7693 
CleanTransition(FrameNode * frameNode)7694 void ViewAbstract::CleanTransition(FrameNode* frameNode)
7695 {
7696     CHECK_NULL_VOID(frameNode);
7697     const auto& renderContext = frameNode->GetRenderContext();
7698     if (renderContext) {
7699         renderContext->CleanTransition();
7700     }
7701 }
7702 
SetChainedTransition(FrameNode * frameNode,const RefPtr<NG::ChainedTransitionEffect> & effect,NG::TransitionFinishCallback && finishCallback)7703 void ViewAbstract::SetChainedTransition(FrameNode* frameNode, const RefPtr<NG::ChainedTransitionEffect>& effect,
7704     NG::TransitionFinishCallback&& finishCallback)
7705 {
7706     CHECK_NULL_VOID(frameNode);
7707     const auto& target = frameNode->GetRenderContext();
7708     if (target) {
7709         target->UpdateChainedTransition(effect);
7710         target->SetTransitionUserCallback(std::move(finishCallback));
7711     }
7712 }
7713 
SetEnabled(FrameNode * frameNode,bool enabled)7714 void ViewAbstract::SetEnabled(FrameNode* frameNode, bool enabled)
7715 {
7716     CHECK_NULL_VOID(frameNode);
7717     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
7718     if (eventHub) {
7719         eventHub->SetEnabled(enabled);
7720     }
7721     auto focusHub = frameNode->GetOrCreateFocusHub();
7722     if (focusHub) {
7723         focusHub->SetEnabled(enabled);
7724     }
7725 }
7726 
SetUseShadowBatching(FrameNode * frameNode,bool useShadowBatching)7727 void ViewAbstract::SetUseShadowBatching(FrameNode* frameNode, bool useShadowBatching)
7728 {
7729     ACE_UPDATE_NODE_RENDER_CONTEXT(UseShadowBatching, useShadowBatching, frameNode);
7730 }
7731 
SetBlendMode(FrameNode * frameNode,BlendMode blendMode)7732 void ViewAbstract::SetBlendMode(FrameNode* frameNode, BlendMode blendMode)
7733 {
7734     ACE_UPDATE_NODE_RENDER_CONTEXT(BackBlendMode, blendMode, frameNode);
7735 }
7736 
SetBlendApplyType(FrameNode * frameNode,BlendApplyType blendApplyType)7737 void ViewAbstract::SetBlendApplyType(FrameNode* frameNode, BlendApplyType blendApplyType)
7738 {
7739     ACE_UPDATE_NODE_RENDER_CONTEXT(BackBlendApplyType, blendApplyType, frameNode);
7740 }
7741 
SetMonopolizeEvents(FrameNode * frameNode,bool monopolizeEvents)7742 void ViewAbstract::SetMonopolizeEvents(FrameNode* frameNode, bool monopolizeEvents)
7743 {
7744     CHECK_NULL_VOID(frameNode);
7745     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
7746     CHECK_NULL_VOID(gestureHub);
7747     gestureHub->SetMonopolizeEvents(monopolizeEvents);
7748 }
7749 
SetDraggable(FrameNode * frameNode,bool draggable)7750 void ViewAbstract::SetDraggable(FrameNode* frameNode, bool draggable)
7751 {
7752     CHECK_NULL_VOID(frameNode);
7753     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
7754     CHECK_NULL_VOID(gestureHub);
7755     if (draggable) {
7756         if (!frameNode->IsDraggable()) {
7757             gestureHub->InitDragDropEvent();
7758         }
7759     } else {
7760         gestureHub->RemoveDragEvent();
7761     }
7762     frameNode->SetCustomerDraggable(draggable);
7763 }
7764 
SetHoverEffect(FrameNode * frameNode,HoverEffectType hoverEffect)7765 void ViewAbstract::SetHoverEffect(FrameNode* frameNode, HoverEffectType hoverEffect)
7766 {
7767     CHECK_NULL_VOID(frameNode);
7768     auto eventHub = frameNode->GetOrCreateInputEventHub();
7769     CHECK_NULL_VOID(eventHub);
7770     eventHub->SetHoverEffect(hoverEffect);
7771 }
7772 
SetClickEffectLevel(FrameNode * frameNode,const ClickEffectLevel & level,float scaleValue)7773 void ViewAbstract::SetClickEffectLevel(FrameNode* frameNode, const ClickEffectLevel& level, float scaleValue)
7774 {
7775     ClickEffectInfo clickEffectInfo;
7776     clickEffectInfo.level = level;
7777     clickEffectInfo.scaleNumber = scaleValue;
7778     ACE_UPDATE_NODE_RENDER_CONTEXT(ClickEffectLevel, clickEffectInfo, frameNode);
7779 }
7780 
SetKeyboardShortcut(FrameNode * frameNode,const std::string & value,const std::vector<ModifierKey> & keys,std::function<void ()> && onKeyboardShortcutAction)7781 void ViewAbstract::SetKeyboardShortcut(FrameNode* frameNode, const std::string& value,
7782     const std::vector<ModifierKey>& keys, std::function<void()>&& onKeyboardShortcutAction)
7783 {
7784     CHECK_NULL_VOID(frameNode);
7785     auto pipeline = frameNode->GetContext();
7786     CHECK_NULL_VOID(pipeline);
7787     auto eventManager = pipeline->GetEventManager();
7788     CHECK_NULL_VOID(eventManager);
7789     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
7790     CHECK_NULL_VOID(eventHub);
7791     auto frameNodeRef = AceType::Claim<FrameNode>(frameNode);
7792     if (value.empty() || keys.empty()) {
7793         eventHub->ClearSingleKeyboardShortcut();
7794         return;
7795     }
7796     auto key = eventManager->GetKeyboardShortcutKeys(keys);
7797     if ((key == 0 && value.length() == 1) || (key == 0 && !keys.empty() && value.length() > 1)) {
7798         return;
7799     }
7800     if (eventManager->IsSameKeyboardShortcutNode(value, key)) {
7801         return;
7802     }
7803     eventHub->SetKeyboardShortcut(value, key, onKeyboardShortcutAction);
7804     eventManager->AddKeyboardShortcutNode(WeakPtr<NG::FrameNode>(frameNodeRef));
7805 }
7806 
SetOnAppear(FrameNode * frameNode,std::function<void ()> && onAppear)7807 void ViewAbstract::SetOnAppear(FrameNode* frameNode, std::function<void()> &&onAppear)
7808 {
7809     CHECK_NULL_VOID(frameNode);
7810     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
7811     CHECK_NULL_VOID(eventHub);
7812     eventHub->SetOnAppear(std::move(onAppear));
7813 }
7814 
SetOnDisappear(FrameNode * frameNode,std::function<void ()> && onDisappear)7815 void ViewAbstract::SetOnDisappear(FrameNode* frameNode, std::function<void()> &&onDisappear)
7816 {
7817     CHECK_NULL_VOID(frameNode);
7818     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
7819     CHECK_NULL_VOID(eventHub);
7820     eventHub->SetOnDisappear(std::move(onDisappear));
7821 }
7822 
SetOnAttach(FrameNode * frameNode,std::function<void ()> && onAttach)7823 void ViewAbstract::SetOnAttach(FrameNode* frameNode, std::function<void()> &&onAttach)
7824 {
7825     CHECK_NULL_VOID(frameNode);
7826     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
7827     CHECK_NULL_VOID(eventHub);
7828     eventHub->SetOnAttach(std::move(onAttach));
7829 }
7830 
SetOnDetach(FrameNode * frameNode,std::function<void ()> && onDetach)7831 void ViewAbstract::SetOnDetach(FrameNode* frameNode, std::function<void()> &&onDetach)
7832 {
7833     CHECK_NULL_VOID(frameNode);
7834     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
7835     CHECK_NULL_VOID(eventHub);
7836     eventHub->SetOnDetach(std::move(onDetach));
7837 }
7838 
SetOnAreaChanged(FrameNode * frameNode,std::function<void (const RectF & oldRect,const OffsetF & oldOrigin,const RectF & rect,const OffsetF & origin)> && onAreaChanged)7839 void ViewAbstract::SetOnAreaChanged(FrameNode* frameNode, std::function<void(const RectF &oldRect,
7840     const OffsetF &oldOrigin, const RectF &rect, const OffsetF &origin)> &&onAreaChanged)
7841 {
7842     FREE_NODE_CHECK(frameNode, SetOnAreaChanged, frameNode, std::move(onAreaChanged));
7843     CHECK_NULL_VOID(frameNode);
7844     auto pipeline = frameNode->GetContext();
7845     CHECK_NULL_VOID(pipeline);
7846     frameNode->SetOnAreaChangeCallback(std::move(onAreaChanged));
7847     pipeline->AddOnAreaChangeNode(frameNode->GetId());
7848 }
7849 
SetOnFocus(FrameNode * frameNode,OnFocusFunc && onFocusCallback)7850 void ViewAbstract::SetOnFocus(FrameNode* frameNode, OnFocusFunc &&onFocusCallback)
7851 {
7852     CHECK_NULL_VOID(frameNode);
7853     auto focusHub = frameNode->GetOrCreateFocusHub();
7854     focusHub->SetOnFocusCallback(std::move(onFocusCallback));
7855 }
7856 
SetOnBlur(FrameNode * frameNode,OnBlurFunc && onBlurCallback)7857 void ViewAbstract::SetOnBlur(FrameNode* frameNode, OnBlurFunc &&onBlurCallback)
7858 {
7859     CHECK_NULL_VOID(frameNode);
7860     auto focusHub = frameNode->GetOrCreateFocusHub();
7861     focusHub->SetOnBlurCallback(std::move(onBlurCallback));
7862 }
7863 
SetOnClick(FrameNode * frameNode,GestureEventFunc && clickEventFunc,double distanceThreshold)7864 void ViewAbstract::SetOnClick(FrameNode* frameNode, GestureEventFunc&& clickEventFunc, double distanceThreshold)
7865 {
7866     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
7867     CHECK_NULL_VOID(gestureHub);
7868     gestureHub->SetUserOnClick(std::move(clickEventFunc), distanceThreshold);
7869 
7870     auto focusHub = frameNode->GetOrCreateFocusHub();
7871     CHECK_NULL_VOID(focusHub);
7872     focusHub->SetFocusable(true, false);
7873 
7874     auto* uiNode = reinterpret_cast<UINode*>(frameNode);
7875     CHECK_NULL_VOID(uiNode);
7876     uiNode->SetModifierEventRegistrationState(uiNode->IsCNode(), true);
7877 }
7878 
SetOnClick(FrameNode * frameNode,GestureEventFunc && clickEventFunc,Dimension distanceThreshold)7879 void ViewAbstract::SetOnClick(FrameNode* frameNode, GestureEventFunc&& clickEventFunc, Dimension distanceThreshold)
7880 {
7881     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
7882     CHECK_NULL_VOID(gestureHub);
7883     gestureHub->SetUserOnClick(std::move(clickEventFunc), distanceThreshold);
7884 
7885     auto focusHub = frameNode->GetOrCreateFocusHub();
7886     CHECK_NULL_VOID(focusHub);
7887     focusHub->SetFocusable(true, false);
7888 
7889     auto* uiNode = reinterpret_cast<UINode*>(frameNode);
7890     CHECK_NULL_VOID(uiNode);
7891     uiNode->SetModifierEventRegistrationState(uiNode->IsCNode(), true);
7892 }
7893 
SetOnTouch(FrameNode * frameNode,TouchEventFunc && touchEventFunc)7894 void ViewAbstract::SetOnTouch(FrameNode* frameNode, TouchEventFunc &&touchEventFunc)
7895 {
7896     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
7897     CHECK_NULL_VOID(gestureHub);
7898     gestureHub->SetTouchEvent(std::move(touchEventFunc));
7899 }
7900 
SetOnMouse(FrameNode * frameNode,OnMouseEventFunc && onMouseEventFunc)7901 void ViewAbstract::SetOnMouse(FrameNode* frameNode, OnMouseEventFunc &&onMouseEventFunc)
7902 {
7903     auto eventHub = frameNode->GetOrCreateInputEventHub();
7904     CHECK_NULL_VOID(eventHub);
7905     eventHub->SetMouseEvent(std::move(onMouseEventFunc));
7906 }
7907 
SetOnAxisEvent(FrameNode * frameNode,OnAxisEventFunc && onAxisEventFunc)7908 void ViewAbstract::SetOnAxisEvent(FrameNode* frameNode, OnAxisEventFunc&& onAxisEventFunc)
7909 {
7910     auto eventHub = frameNode->GetOrCreateInputEventHub();
7911     CHECK_NULL_VOID(eventHub);
7912     eventHub->SetAxisEvent(std::move(onAxisEventFunc));
7913 }
7914 
SetOnHover(FrameNode * frameNode,OnHoverFunc && onHoverEventFunc)7915 void ViewAbstract::SetOnHover(FrameNode* frameNode, OnHoverFunc &&onHoverEventFunc)
7916 {
7917     auto eventHub = frameNode->GetOrCreateInputEventHub();
7918     CHECK_NULL_VOID(eventHub);
7919     eventHub->SetHoverEvent(std::move(onHoverEventFunc));
7920 }
7921 
SetOnHoverMove(FrameNode * frameNode,OnHoverMoveFunc && onHoverMoveEventFunc)7922 void ViewAbstract::SetOnHoverMove(FrameNode* frameNode, OnHoverMoveFunc &&onHoverMoveEventFunc)
7923 {
7924     auto eventHub = frameNode->GetOrCreateInputEventHub();
7925     CHECK_NULL_VOID(eventHub);
7926     eventHub->SetHoverMoveEvent(std::move(onHoverMoveEventFunc));
7927 }
7928 
SetOnAccessibilityHover(FrameNode * frameNode,OnAccessibilityHoverFunc && onAccessibilityHoverEventFunc)7929 void ViewAbstract::SetOnAccessibilityHover(FrameNode* frameNode,
7930     OnAccessibilityHoverFunc &&onAccessibilityHoverEventFunc)
7931 {
7932     CHECK_NULL_VOID(frameNode);
7933     auto eventHub = frameNode->GetOrCreateInputEventHub();
7934     CHECK_NULL_VOID(eventHub);
7935     eventHub->SetAccessibilityHoverEvent(std::move(onAccessibilityHoverEventFunc));
7936 }
7937 
SetOnKeyEvent(FrameNode * frameNode,OnKeyConsumeFunc && onKeyCallback)7938 void ViewAbstract::SetOnKeyEvent(FrameNode* frameNode, OnKeyConsumeFunc &&onKeyCallback)
7939 {
7940     auto focusHub = frameNode->GetOrCreateFocusHub();
7941     CHECK_NULL_VOID(focusHub);
7942     focusHub->SetOnKeyCallback(std::move(onKeyCallback));
7943 }
7944 
SetOnKeyEventDispatch(OnKeyEventDispatchFunc && onKeyDispatchCallback)7945 void ViewAbstract::SetOnKeyEventDispatch(OnKeyEventDispatchFunc&& onKeyDispatchCallback)
7946 {
7947     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
7948     CHECK_NULL_VOID(focusHub);
7949     focusHub->SetOnKeyEventDispatchCallback(std::move(onKeyDispatchCallback));
7950 }
7951 
SetOnKeyEventDispatch(FrameNode * frameNode,OnKeyEventDispatchFunc && onKeyDispatchCallback)7952 void ViewAbstract::SetOnKeyEventDispatch(FrameNode* frameNode, OnKeyEventDispatchFunc&& onKeyDispatchCallback)
7953 {
7954     CHECK_NULL_VOID(frameNode);
7955     auto focusHub = frameNode->GetOrCreateFocusHub();
7956     CHECK_NULL_VOID(focusHub);
7957     focusHub->SetOnKeyEventDispatchCallback(std::move(onKeyDispatchCallback));
7958 }
7959 
DispatchKeyEvent(FrameNode * frameNode,KeyEvent & keyEvent)7960 void ViewAbstract::DispatchKeyEvent(FrameNode* frameNode, KeyEvent& keyEvent)
7961 {
7962     CHECK_NULL_VOID(frameNode);
7963     auto focusHub = frameNode->GetOrCreateFocusHub();
7964     CHECK_NULL_VOID(focusHub);
7965     focusHub->HandleEvent(keyEvent);
7966 }
7967 
GetFocusable(FrameNode * frameNode)7968 bool ViewAbstract::GetFocusable(FrameNode* frameNode)
7969 {
7970     CHECK_NULL_RETURN(frameNode, false);
7971     auto focusHub = frameNode->GetOrCreateFocusHub();
7972     CHECK_NULL_RETURN(focusHub, false);
7973     return focusHub->IsFocusable();
7974 }
7975 
GetTabStop(FrameNode * frameNode)7976 bool ViewAbstract::GetTabStop(FrameNode* frameNode)
7977 {
7978     CHECK_NULL_RETURN(frameNode, false);
7979     auto focusHub = frameNode->GetOrCreateFocusHub();
7980     CHECK_NULL_RETURN(focusHub, false);
7981     return focusHub->IsTabStop();
7982 }
7983 
GetDefaultFocus(FrameNode * frameNode)7984 bool ViewAbstract::GetDefaultFocus(FrameNode* frameNode)
7985 {
7986     CHECK_NULL_RETURN(frameNode, false);
7987     auto focusHub = frameNode->GetOrCreateFocusHub();
7988     CHECK_NULL_RETURN(focusHub, false);
7989     return focusHub->IsDefaultFocus();
7990 }
7991 
GetResponseRegion(FrameNode * frameNode)7992 std::vector<DimensionRect> ViewAbstract::GetResponseRegion(FrameNode* frameNode)
7993 {
7994     std::vector<DimensionRect> defaultRect;
7995     CHECK_NULL_RETURN(frameNode, defaultRect);
7996     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
7997     CHECK_NULL_RETURN(gestureHub, defaultRect);
7998     return gestureHub->GetResponseRegion();
7999 }
8000 
GetOverlay(FrameNode * frameNode)8001 NG::OverlayOptions ViewAbstract::GetOverlay(FrameNode* frameNode)
8002 {
8003     NG::OverlayOptions defaultOptions;
8004     const auto& target = frameNode->GetRenderContext();
8005     return target->GetOverlayTextValue(defaultOptions);
8006 }
8007 
SetNeedFocus(FrameNode * frameNode,bool value)8008 void ViewAbstract::SetNeedFocus(FrameNode* frameNode, bool value)
8009 {
8010     CHECK_NULL_VOID(frameNode);
8011     FREE_NODE_CHECK(frameNode, SetNeedFocus, frameNode, value);
8012     auto focusHub = frameNode->GetOrCreateFocusHub();
8013     CHECK_NULL_VOID(focusHub);
8014     if (value) {
8015         auto context = frameNode->GetContext();
8016         CHECK_NULL_VOID(context);
8017         auto instanceId = context->GetInstanceId();
8018         ContainerScope scope(instanceId);
8019         focusHub->RequestFocus();
8020     } else {
8021         auto context = frameNode->GetAttachedContext();
8022         if (!context) {
8023             TAG_LOGW(AceLogTag::ACE_FOCUS,
8024                 "Can't find Node %{public}s/%{public}d attachedContext, please check the timing of the function call.",
8025                 frameNode->GetTag().c_str(), frameNode->GetId());
8026             return;
8027         }
8028         auto instanceId = context->GetInstanceId();
8029         ContainerScope scope(instanceId);
8030         focusHub->LostFocusToViewRoot();
8031     }
8032 }
8033 
GetNeedFocus(FrameNode * frameNode)8034 bool ViewAbstract::GetNeedFocus(FrameNode* frameNode)
8035 {
8036     CHECK_NULL_RETURN(frameNode, false);
8037     auto focusHub = frameNode->GetOrCreateFocusHub();
8038     CHECK_NULL_RETURN(focusHub, false);
8039     return focusHub->IsCurrentFocus();
8040 }
8041 
RequestFocus(FrameNode * frameNode)8042 int ViewAbstract::RequestFocus(FrameNode* frameNode)
8043 {
8044     CHECK_NULL_RETURN(frameNode, ERROR_CODE_NON_EXIST);
8045     auto context = frameNode->GetContext();
8046     CHECK_NULL_RETURN(context, ERROR_CODE_NON_EXIST);
8047     auto instanceId = context->GetInstanceId();
8048     ContainerScope scope(instanceId);
8049     auto focusManager = context->GetOrCreateFocusManager();
8050     focusManager->ResetRequestFocusResult();
8051     auto focusHub = frameNode->GetOrCreateFocusHub();
8052     // check node focusable
8053     if (focusHub->IsSyncRequestFocusable()) {
8054         focusHub->RequestFocusImmediately();
8055     }
8056     auto retCode = focusManager->GetRequestFocusResult();
8057     focusManager->ResetRequestFocusResult();
8058     return retCode;
8059 }
8060 
ClearFocus(int32_t instanceId)8061 void ViewAbstract::ClearFocus(int32_t instanceId)
8062 {
8063     auto context = PipelineContext::GetContextByContainerId(instanceId);
8064     if (!context) {
8065         TAG_LOGW(AceLogTag::ACE_FOCUS, "Can't find attachedContext, please check the timing of the function call.");
8066         return;
8067     }
8068     FocusHub::LostFocusToViewRoot();
8069 }
8070 
FocusActivate(int32_t instanceId,bool isActive,bool isAutoInactive)8071 void ViewAbstract::FocusActivate(int32_t instanceId, bool isActive, bool isAutoInactive)
8072 {
8073     auto context = PipelineContext::GetContextByContainerId(instanceId);
8074     if (!context) {
8075         TAG_LOGW(AceLogTag::ACE_FOCUS, "Can't find attachedContext, please check the timing of the function call.");
8076         return;
8077     }
8078     context->SetIsFocusActive(isActive, NG::FocusActiveReason::USE_API, isAutoInactive);
8079 }
8080 
GetFocusActive()8081 bool ViewAbstract::GetFocusActive()
8082 {
8083     auto pipeline = PipelineContext::GetCurrentContext();
8084     CHECK_NULL_RETURN(pipeline, false);
8085     bool ret = pipeline->GetIsFocusActive();
8086     return ret;
8087 }
8088 
SetAutoFocusTransfer(int32_t instanceId,bool isAutoFocusTransfer)8089 void ViewAbstract::SetAutoFocusTransfer(int32_t instanceId, bool isAutoFocusTransfer)
8090 {
8091     auto context = PipelineContext::GetContextByContainerId(instanceId);
8092     if (!context) {
8093         TAG_LOGW(AceLogTag::ACE_FOCUS, "Can't find attachedContext, please check the timing of the function call.");
8094         return;
8095     }
8096     auto focusManager = context->GetOrCreateFocusManager();
8097     CHECK_NULL_VOID(focusManager);
8098     focusManager->SetIsAutoFocusTransfer(isAutoFocusTransfer);
8099 }
8100 
GetOpacity(FrameNode * frameNode)8101 double ViewAbstract::GetOpacity(FrameNode* frameNode)
8102 {
8103     double opacity = 1.0f;
8104     const auto& target = frameNode->GetRenderContext();
8105     CHECK_NULL_RETURN(target, opacity);
8106     return target->GetOpacityValue(opacity);
8107 }
8108 
GetBorderWidth(FrameNode * frameNode)8109 BorderWidthProperty ViewAbstract::GetBorderWidth(FrameNode* frameNode)
8110 {
8111     Dimension defaultDimension(0);
8112     BorderWidthProperty borderWidths = { defaultDimension, defaultDimension, defaultDimension, defaultDimension,
8113         std::nullopt, std::nullopt};
8114     const auto& target = frameNode->GetRenderContext();
8115     CHECK_NULL_RETURN(target, borderWidths);
8116     return target->GetBorderWidthValue(borderWidths);
8117 }
8118 
GetLayoutBorderWidth(FrameNode * frameNode)8119 BorderWidthProperty ViewAbstract::GetLayoutBorderWidth(FrameNode* frameNode)
8120 {
8121     Dimension defaultDimen = Dimension(0, DimensionUnit::VP);
8122     BorderWidthProperty borderWidths;
8123     borderWidths.topDimen = std::optional<Dimension>(defaultDimen);
8124     borderWidths.rightDimen = std::optional<Dimension>(defaultDimen);
8125     borderWidths.bottomDimen = std::optional<Dimension>(defaultDimen);
8126     borderWidths.leftDimen = std::optional<Dimension>(defaultDimen);
8127     const auto& layoutProperty = frameNode->GetLayoutProperty();
8128     CHECK_NULL_RETURN(layoutProperty, borderWidths);
8129     const auto& property = layoutProperty->GetBorderWidthProperty();
8130     CHECK_NULL_RETURN(property, borderWidths);
8131     borderWidths.topDimen = std::optional<Dimension>(property->topDimen);
8132     borderWidths.rightDimen = std::optional<Dimension>(property->rightDimen);
8133     borderWidths.bottomDimen = std::optional<Dimension>(property->bottomDimen);
8134     borderWidths.leftDimen = std::optional<Dimension>(property->leftDimen);
8135     return borderWidths;
8136 }
8137 
GetBorderRadius(FrameNode * frameNode)8138 BorderRadiusProperty ViewAbstract::GetBorderRadius(FrameNode* frameNode)
8139 {
8140     Dimension defaultDimension(0);
8141     BorderRadiusProperty borderRadius = { defaultDimension, defaultDimension, defaultDimension, defaultDimension };
8142     const auto& target = frameNode->GetRenderContext();
8143     CHECK_NULL_RETURN(target, borderRadius);
8144     return target->GetBorderRadiusValue(borderRadius);
8145 }
8146 
GetBorderColor(FrameNode * frameNode)8147 BorderColorProperty ViewAbstract::GetBorderColor(FrameNode* frameNode)
8148 {
8149     Color defaultColor(0xff000000);
8150     BorderColorProperty borderColors = { defaultColor, defaultColor, defaultColor, defaultColor,
8151         std::nullopt, std::nullopt };
8152     const auto& target = frameNode->GetRenderContext();
8153     CHECK_NULL_RETURN(target, borderColors);
8154     return target->GetBorderColorValue(borderColors);
8155 }
8156 
GetBorderStyle(FrameNode * frameNode)8157 BorderStyleProperty ViewAbstract::GetBorderStyle(FrameNode* frameNode)
8158 {
8159     BorderStyle defaultStyle = BorderStyle::SOLID;
8160     BorderStyleProperty borderStyles = { defaultStyle, defaultStyle, defaultStyle, defaultStyle };
8161     const auto& target = frameNode->GetRenderContext();
8162     CHECK_NULL_RETURN(target, borderStyles);
8163     return target->GetBorderStyleValue(borderStyles);
8164 }
8165 
GetZIndex(FrameNode * frameNode)8166 int ViewAbstract::GetZIndex(FrameNode* frameNode)
8167 {
8168     int zindex = 0;
8169     const auto& target = frameNode->GetRenderContext();
8170     CHECK_NULL_RETURN(target, zindex);
8171     return target->GetZIndexValue(zindex);
8172 }
8173 
GetVisibility(FrameNode * frameNode)8174 VisibleType ViewAbstract::GetVisibility(FrameNode* frameNode)
8175 {
8176     VisibleType visibility = VisibleType::VISIBLE;
8177     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(LayoutProperty, Visibility, visibility, frameNode, visibility);
8178     return visibility;
8179 }
8180 
GetClip(FrameNode * frameNode)8181 bool ViewAbstract::GetClip(FrameNode* frameNode)
8182 {
8183     bool value = false;
8184     const auto& target = frameNode->GetRenderContext();
8185     CHECK_NULL_RETURN(target, value);
8186     return target->GetClipEdgeValue(value);
8187 }
8188 
GetClipShape(FrameNode * frameNode)8189 RefPtr<BasicShape> ViewAbstract::GetClipShape(FrameNode* frameNode)
8190 {
8191     RefPtr<BasicShape> value = AceType::MakeRefPtr<BasicShape>();
8192     const auto& target = frameNode->GetRenderContext();
8193     CHECK_NULL_RETURN(target, value);
8194     return target->GetClipShapeValue(value);
8195 }
8196 
GetTransform(FrameNode * frameNode)8197 Matrix4 ViewAbstract::GetTransform(FrameNode* frameNode)
8198 {
8199     Matrix4 value;
8200     const auto& target = frameNode->GetRenderContext();
8201     CHECK_NULL_RETURN(target, value);
8202     return target->GetTransformMatrixValue(value);
8203 }
8204 
GetHitTestBehavior(FrameNode * frameNode)8205 HitTestMode ViewAbstract::GetHitTestBehavior(FrameNode* frameNode)
8206 {
8207     auto gestureHub = frameNode->GetHitTestMode();
8208     return gestureHub;
8209 }
8210 
GetPosition(FrameNode * frameNode)8211 OffsetT<Dimension> ViewAbstract::GetPosition(FrameNode* frameNode)
8212 {
8213     Dimension PositionX(0, DimensionUnit::VP);
8214     Dimension PositionY(0, DimensionUnit::VP);
8215     OffsetT<Dimension> position(PositionX, PositionY);
8216     const auto& target = frameNode->GetRenderContext();
8217     CHECK_NULL_RETURN(target, position);
8218     return target->GetPositionValue(position);
8219 }
8220 
GetShadow(FrameNode * frameNode)8221 std::optional<Shadow> ViewAbstract::GetShadow(FrameNode* frameNode)
8222 {
8223     Shadow value;
8224     const auto& target = frameNode->GetRenderContext();
8225     CHECK_NULL_RETURN(target, value);
8226     return target->GetBackShadowValue(value);
8227 }
8228 
GetSweepGradient(FrameNode * frameNode)8229 NG::Gradient ViewAbstract::GetSweepGradient(FrameNode* frameNode)
8230 {
8231     Gradient value;
8232     value.CreateGradientWithType(NG::GradientType::SWEEP);
8233     const auto& target = frameNode->GetRenderContext();
8234     CHECK_NULL_RETURN(target, value);
8235     return target->GetSweepGradientValue(value);
8236 }
8237 
GetRadialGradient(FrameNode * frameNode)8238 NG::Gradient ViewAbstract::GetRadialGradient(FrameNode* frameNode)
8239 {
8240     Gradient value;
8241     value.CreateGradientWithType(NG::GradientType::RADIAL);
8242     const auto& target = frameNode->GetRenderContext();
8243     CHECK_NULL_RETURN(target, value);
8244     return target->GetRadialGradientValue(value);
8245 }
8246 
GetMask(FrameNode * frameNode)8247 RefPtr<BasicShape> ViewAbstract::GetMask(FrameNode* frameNode)
8248 {
8249     RefPtr<BasicShape> value = AceType::MakeRefPtr<BasicShape>();
8250     const auto& target = frameNode->GetRenderContext();
8251     CHECK_NULL_RETURN(target, nullptr);
8252     if (target->HasClipMask()) {
8253         return target->GetClipMaskValue(value);
8254     }
8255     return nullptr;
8256 }
8257 
GetMaskProgress(FrameNode * frameNode)8258 RefPtr<ProgressMaskProperty> ViewAbstract::GetMaskProgress(FrameNode* frameNode)
8259 {
8260     RefPtr<ProgressMaskProperty> value = AceType::MakeRefPtr<ProgressMaskProperty>();
8261     const auto& target = frameNode->GetRenderContext();
8262     CHECK_NULL_RETURN(target, nullptr);
8263     if (target->HasProgressMask()) {
8264         return target->GetProgressMaskValue(value);
8265     }
8266     return nullptr;
8267 }
8268 
GetBlendMode(FrameNode * frameNode)8269 BlendMode ViewAbstract::GetBlendMode(FrameNode* frameNode)
8270 {
8271     BlendMode value = BlendMode::NONE;
8272     auto target = frameNode->GetRenderContext();
8273     CHECK_NULL_RETURN(target, value);
8274     return target->GetBackBlendModeValue(value);
8275 }
8276 
GetDirection(FrameNode * frameNode)8277 TextDirection ViewAbstract::GetDirection(FrameNode* frameNode)
8278 {
8279     TextDirection direction = TextDirection::AUTO;
8280     auto target = frameNode->GetLayoutProperty<LayoutProperty>();
8281     direction = target->GetLayoutDirection();
8282     return direction;
8283 }
8284 
GetAlignSelf(FrameNode * frameNode)8285 FlexAlign ViewAbstract::GetAlignSelf(FrameNode* frameNode)
8286 {
8287     FlexAlign value = FlexAlign::AUTO;
8288     const auto& flexItemProperty = frameNode->GetLayoutProperty()->GetFlexItemProperty();
8289     CHECK_NULL_RETURN(flexItemProperty, value);
8290     auto getValue = flexItemProperty->GetAlignSelf();
8291     if (getValue.has_value()) {
8292         return getValue.value();
8293     }
8294     return value;
8295 }
8296 
GetFlexGrow(FrameNode * frameNode)8297 float ViewAbstract::GetFlexGrow(FrameNode* frameNode)
8298 {
8299     float value = 0.0f;
8300     const auto& layoutProperty = frameNode->GetLayoutProperty();
8301     CHECK_NULL_RETURN(layoutProperty, value);
8302     const auto& property = layoutProperty->GetFlexItemProperty();
8303     CHECK_NULL_RETURN(property, value);
8304     auto getValue = property->GetFlexGrow();
8305     if (getValue.has_value()) {
8306         return getValue.value();
8307     }
8308     return value;
8309 }
8310 
GetFlexShrink(FrameNode * frameNode)8311 float ViewAbstract::GetFlexShrink(FrameNode* frameNode)
8312 {
8313     float value = 0.0f;
8314     const auto& layoutProperty = frameNode->GetLayoutProperty();
8315     CHECK_NULL_RETURN(layoutProperty, value);
8316     const auto& property = layoutProperty->GetFlexItemProperty();
8317     CHECK_NULL_RETURN(property, value);
8318     auto getValue = property->GetFlexShrink();
8319     if (getValue.has_value()) {
8320         return getValue.value();
8321     }
8322     return value;
8323 }
8324 
GetFlexBasis(FrameNode * frameNode)8325 Dimension ViewAbstract::GetFlexBasis(FrameNode* frameNode)
8326 {
8327     Dimension value;
8328     const auto& layoutProperty = frameNode->GetLayoutProperty();
8329     CHECK_NULL_RETURN(layoutProperty, value);
8330     const auto& property = layoutProperty->GetFlexItemProperty();
8331     CHECK_NULL_RETURN(property, value);
8332     auto getValue = property->GetFlexBasis();
8333     if (getValue.has_value()) {
8334         return getValue.value();
8335     }
8336     return value;
8337 }
8338 
GetMinWidth(FrameNode * frameNode)8339 Dimension ViewAbstract::GetMinWidth(FrameNode* frameNode)
8340 {
8341     Dimension value = Dimension(0.0f);
8342     const auto& layoutProperty = frameNode->GetLayoutProperty();
8343     CHECK_NULL_RETURN(layoutProperty, value);
8344     const auto& property = layoutProperty->GetCalcLayoutConstraint();
8345     CHECK_NULL_RETURN(property, value);
8346     auto size = property->minSize;
8347     if (size.has_value()) {
8348         auto width = size->Width();
8349         if (width.has_value()) {
8350             return width.value().GetDimension();
8351         }
8352     }
8353     return value;
8354 }
8355 
GetMaxWidth(FrameNode * frameNode)8356 Dimension ViewAbstract::GetMaxWidth(FrameNode* frameNode)
8357 {
8358     Dimension value = Dimension(0.0f);
8359     const auto& layoutProperty = frameNode->GetLayoutProperty();
8360     CHECK_NULL_RETURN(layoutProperty, value);
8361     const auto& property = layoutProperty->GetCalcLayoutConstraint();
8362     CHECK_NULL_RETURN(property, value);
8363     auto size = property->maxSize;
8364     if (size.has_value()) {
8365         auto width = size->Width();
8366         if (width.has_value()) {
8367             return width.value().GetDimension();
8368         }
8369     }
8370     return value;
8371 }
8372 
GetMinHeight(FrameNode * frameNode)8373 Dimension ViewAbstract::GetMinHeight(FrameNode* frameNode)
8374 {
8375     Dimension value = Dimension(0.0f);
8376     const auto& layoutProperty = frameNode->GetLayoutProperty();
8377     CHECK_NULL_RETURN(layoutProperty, value);
8378     const auto& property = layoutProperty->GetCalcLayoutConstraint();
8379     CHECK_NULL_RETURN(property, value);
8380     auto size = property->minSize;
8381     if (size.has_value()) {
8382         auto height = size->Height();
8383         if (height.has_value()) {
8384             return height.value().GetDimension();
8385         }
8386     }
8387     return value;
8388 }
8389 
GetMaxHeight(FrameNode * frameNode)8390 Dimension ViewAbstract::GetMaxHeight(FrameNode* frameNode)
8391 {
8392     Dimension value = Dimension(0.0f);
8393     const auto& layoutProperty = frameNode->GetLayoutProperty();
8394     CHECK_NULL_RETURN(layoutProperty, value);
8395     const auto& property = layoutProperty->GetCalcLayoutConstraint();
8396     CHECK_NULL_RETURN(property, value);
8397     auto size = property->maxSize;
8398     if (size.has_value()) {
8399         auto height = size->Height();
8400         if (height.has_value()) {
8401             return height.value().GetDimension();
8402         }
8403     }
8404     return value;
8405 }
8406 
GetGrayScale(FrameNode * frameNode)8407 Dimension ViewAbstract::GetGrayScale(FrameNode* frameNode)
8408 {
8409     Dimension value;
8410     auto target = frameNode->GetRenderContext();
8411     CHECK_NULL_RETURN(target, value);
8412     return target->GetFrontGrayScaleValue(value);
8413 }
8414 
GetInvert(FrameNode * frameNode)8415 InvertVariant ViewAbstract::GetInvert(FrameNode* frameNode)
8416 {
8417     InvertVariant value = 0.0f;
8418     auto target = frameNode->GetRenderContext();
8419     CHECK_NULL_RETURN(target, value);
8420     return target->GetFrontInvertValue(value);
8421 }
8422 
GetSepia(FrameNode * frameNode)8423 Dimension ViewAbstract::GetSepia(FrameNode* frameNode)
8424 {
8425     Dimension value;
8426     auto target = frameNode->GetRenderContext();
8427     CHECK_NULL_RETURN(target, value);
8428     return target->GetFrontSepiaValue(value);
8429 }
8430 
GetContrast(FrameNode * frameNode)8431 Dimension ViewAbstract::GetContrast(FrameNode* frameNode)
8432 {
8433     Dimension value(1.0f);
8434     auto target = frameNode->GetRenderContext();
8435     CHECK_NULL_RETURN(target, value);
8436     return target->GetFrontContrastValue(value);
8437 }
8438 
GetForegroundColor(FrameNode * frameNode)8439 Color ViewAbstract::GetForegroundColor(FrameNode* frameNode)
8440 {
8441     Color value;
8442     auto target = frameNode->GetRenderContext();
8443     CHECK_NULL_RETURN(target, value);
8444     return target->GetForegroundColorValue(value);
8445 }
8446 
GetScale(FrameNode * frameNode)8447 NG::VectorF ViewAbstract::GetScale(FrameNode* frameNode)
8448 {
8449     NG::VectorF defaultVector = { 1.0f, 1.0f };
8450     CHECK_NULL_RETURN(frameNode, defaultVector);
8451     auto renderContext = frameNode->GetRenderContext();
8452     CHECK_NULL_RETURN(renderContext, defaultVector);
8453     return renderContext->GetTransformScale().value_or(defaultVector);
8454 }
8455 
GetRotate(FrameNode * frameNode)8456 NG::Vector5F ViewAbstract::GetRotate(FrameNode* frameNode)
8457 {
8458     NG::Vector5F defaultVector = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
8459     CHECK_NULL_RETURN(frameNode, defaultVector);
8460     auto renderContext = frameNode->GetRenderContext();
8461     CHECK_NULL_RETURN(renderContext, defaultVector);
8462     return renderContext->GetTransformRotate().value_or(defaultVector);
8463 }
8464 
GetRotateAngle(FrameNode * frameNode)8465 NG::Vector4F ViewAbstract::GetRotateAngle(FrameNode* frameNode)
8466 {
8467     NG::Vector4F defaultVector { 0.0f, 0.0f, 0.0f, 0.0f };
8468     CHECK_NULL_RETURN(frameNode, defaultVector);
8469     auto renderContext = frameNode->GetRenderContext();
8470     CHECK_NULL_RETURN(renderContext, defaultVector);
8471     return renderContext->GetTransformRotateAngle().value_or(defaultVector);
8472 }
8473 
GetBrightness(FrameNode * frameNode)8474 Dimension ViewAbstract::GetBrightness(FrameNode* frameNode)
8475 {
8476     Dimension defaultBrightness(1.0);
8477     CHECK_NULL_RETURN(frameNode, defaultBrightness);
8478     auto renderContext = frameNode->GetRenderContext();
8479     CHECK_NULL_RETURN(renderContext, defaultBrightness);
8480     return renderContext->GetFrontBrightness().value_or(defaultBrightness);
8481 }
8482 
GetSaturate(FrameNode * frameNode)8483 Dimension ViewAbstract::GetSaturate(FrameNode* frameNode)
8484 {
8485     Dimension defaultSaturate(1.0);
8486     CHECK_NULL_RETURN(frameNode, defaultSaturate);
8487     auto renderContext = frameNode->GetRenderContext();
8488     CHECK_NULL_RETURN(renderContext, defaultSaturate);
8489     return renderContext->GetFrontSaturate().value_or(defaultSaturate);
8490 }
8491 
GetBackgroundImagePosition(FrameNode * frameNode)8492 BackgroundImagePosition ViewAbstract::GetBackgroundImagePosition(FrameNode* frameNode)
8493 {
8494     BackgroundImagePosition defaultImagePosition;
8495     CHECK_NULL_RETURN(frameNode, defaultImagePosition);
8496     auto renderContext = frameNode->GetRenderContext();
8497     CHECK_NULL_RETURN(renderContext, defaultImagePosition);
8498     return renderContext->GetBackgroundImagePosition().value_or(defaultImagePosition);
8499 }
8500 
GetFrontBlur(FrameNode * frameNode)8501 Dimension ViewAbstract::GetFrontBlur(FrameNode* frameNode)
8502 {
8503     Dimension value;
8504     auto target = frameNode->GetRenderContext();
8505     CHECK_NULL_RETURN(target, value);
8506     auto& property = target->GetForeground();
8507     CHECK_NULL_RETURN(property, value);
8508     auto getValue = property->propBlurRadius;
8509     if (getValue.has_value()) {
8510         return getValue.value();
8511     }
8512     return value;
8513 }
8514 
GetLinearGradient(FrameNode * frameNode)8515 NG::Gradient ViewAbstract::GetLinearGradient(FrameNode *frameNode)
8516 {
8517     NG::Gradient value;
8518     value.CreateGradientWithType(NG::GradientType::LINEAR);
8519     auto target = frameNode->GetRenderContext();
8520     CHECK_NULL_RETURN(target, value);
8521     return target->GetLinearGradientValue(value);
8522 }
8523 
GetAlign(FrameNode * frameNode)8524 Alignment ViewAbstract::GetAlign(FrameNode *frameNode)
8525 {
8526     Alignment value = Alignment::CENTER;
8527     const auto& layoutProperty = frameNode->GetLayoutProperty();
8528     CHECK_NULL_RETURN(layoutProperty, value);
8529     const auto& property = layoutProperty->GetPositionProperty();
8530     CHECK_NULL_RETURN(property, value);
8531     auto getValue = property->GetAlignment();
8532     if (getValue.has_value()) {
8533         return getValue.value();
8534     }
8535     return value;
8536 }
8537 
GetWidth(FrameNode * frameNode)8538 Dimension ViewAbstract::GetWidth(FrameNode* frameNode)
8539 {
8540     Dimension value = Dimension(-1.0f);
8541     const auto& layoutProperty = frameNode->GetLayoutProperty();
8542     CHECK_NULL_RETURN(layoutProperty, value);
8543     const auto& property = layoutProperty->GetCalcLayoutConstraint();
8544     CHECK_NULL_RETURN(property, value);
8545     auto size = property->selfIdealSize;
8546     if (size.has_value()) {
8547         auto width = size->Width();
8548         if (width.has_value()) {
8549             return width.value().GetDimension();
8550         }
8551     }
8552     return value;
8553 }
8554 
GetHeight(FrameNode * frameNode)8555 Dimension ViewAbstract::GetHeight(FrameNode* frameNode)
8556 {
8557     Dimension value = Dimension(-1.0f);
8558     const auto& layoutProperty = frameNode->GetLayoutProperty();
8559     CHECK_NULL_RETURN(layoutProperty, value);
8560     const auto& property = layoutProperty->GetCalcLayoutConstraint();
8561     CHECK_NULL_RETURN(property, value);
8562     auto size = property->selfIdealSize;
8563     if (size.has_value()) {
8564         auto height = size->Height();
8565         if (height.has_value()) {
8566             return height.value().GetDimension();
8567         }
8568     }
8569     return value;
8570 }
8571 
GetBackgroundColor(FrameNode * frameNode)8572 Color ViewAbstract::GetBackgroundColor(FrameNode* frameNode)
8573 {
8574     Color value;
8575     auto target = frameNode->GetRenderContext();
8576     CHECK_NULL_RETURN(target, value);
8577     return target->GetBackgroundColorValue(value);
8578 }
8579 
GetBackgroundImageSrc(FrameNode * frameNode)8580 std::string ViewAbstract::GetBackgroundImageSrc(FrameNode* frameNode)
8581 {
8582     auto target = frameNode->GetRenderContext();
8583     CHECK_NULL_RETURN(target, "");
8584     if (target->GetBackgroundImage().has_value()) {
8585         return target->GetBackgroundImage()->GetSrc();
8586     }
8587     return "";
8588 }
8589 
GetBackgroundImageRepeat(FrameNode * frameNode)8590 ImageRepeat ViewAbstract::GetBackgroundImageRepeat(FrameNode* frameNode)
8591 {
8592     ImageRepeat value = ImageRepeat::NO_REPEAT;
8593     auto target = frameNode->GetRenderContext();
8594     CHECK_NULL_RETURN(target, value);
8595     if (target->GetBackgroundImageRepeat().has_value()) {
8596         return target->GetBackgroundImageRepeat().value();
8597     }
8598     return value;
8599 }
8600 
GetPadding(FrameNode * frameNode)8601 PaddingProperty ViewAbstract::GetPadding(FrameNode* frameNode)
8602 {
8603     CalcLength defaultDimen = CalcLength(0, DimensionUnit::VP);
8604     PaddingProperty paddings;
8605     paddings.top = std::optional<CalcLength>(defaultDimen);
8606     paddings.right = std::optional<CalcLength>(defaultDimen);
8607     paddings.bottom = std::optional<CalcLength>(defaultDimen);
8608     paddings.left = std::optional<CalcLength>(defaultDimen);
8609     const auto& layoutProperty = frameNode->GetLayoutProperty();
8610     CHECK_NULL_RETURN(layoutProperty, paddings);
8611     const auto& property = layoutProperty->GetPaddingProperty();
8612     CHECK_NULL_RETURN(property, paddings);
8613     paddings.top = std::optional<CalcLength>(property->top);
8614     paddings.right = std::optional<CalcLength>(property->right);
8615     paddings.bottom = std::optional<CalcLength>(property->bottom);
8616     paddings.left = std::optional<CalcLength>(property->left);
8617     return paddings;
8618 }
8619 
GetConfigSize(FrameNode * frameNode)8620 std::optional<CalcSize> ViewAbstract::GetConfigSize(FrameNode* frameNode)
8621 {
8622     auto value = std::optional<CalcSize>();
8623     const auto& layoutProperty = frameNode->GetLayoutProperty();
8624     CHECK_NULL_RETURN(layoutProperty, value);
8625     const auto& property = layoutProperty->GetCalcLayoutConstraint();
8626     CHECK_NULL_RETURN(property, value);
8627     auto size = property->selfIdealSize;
8628     if (size.has_value()) {
8629         value = size;
8630     }
8631     return value;
8632 }
8633 
GetKey(FrameNode * frameNode)8634 std::string ViewAbstract::GetKey(FrameNode* frameNode)
8635 {
8636     std::string value;
8637     CHECK_NULL_RETURN(frameNode, value);
8638     return value = frameNode->GetInspectorIdValue();
8639 }
8640 
GetEnabled(FrameNode * frameNode)8641 bool ViewAbstract::GetEnabled(FrameNode* frameNode)
8642 {
8643     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
8644     CHECK_NULL_RETURN(eventHub, false);
8645     return eventHub->IsEnabled();
8646 }
8647 
GetMargin(FrameNode * frameNode)8648 MarginProperty ViewAbstract::GetMargin(FrameNode* frameNode)
8649 {
8650     CalcLength defaultDimen = CalcLength(0, DimensionUnit::VP);
8651     MarginProperty margins;
8652     margins.top = std::optional<CalcLength>(defaultDimen);
8653     margins.right = std::optional<CalcLength>(defaultDimen);
8654     margins.bottom = std::optional<CalcLength>(defaultDimen);
8655     margins.left = std::optional<CalcLength>(defaultDimen);
8656     const auto& layoutProperty = frameNode->GetLayoutProperty();
8657     CHECK_NULL_RETURN(layoutProperty, margins);
8658     const auto& property = layoutProperty->GetMarginProperty();
8659     CHECK_NULL_RETURN(property, margins);
8660     margins.top = std::optional<CalcLength>(property->top);
8661     margins.right = std::optional<CalcLength>(property->right);
8662     margins.bottom = std::optional<CalcLength>(property->bottom);
8663     margins.left = std::optional<CalcLength>(property->left);
8664     return margins;
8665 }
8666 
GetTranslate(FrameNode * frameNode)8667 TranslateOptions ViewAbstract::GetTranslate(FrameNode* frameNode)
8668 {
8669     TranslateOptions value(0.0f, 0.0f, 0.0f);
8670     auto target = frameNode->GetRenderContext();
8671     CHECK_NULL_RETURN(target, value);
8672     return target->GetTransformTranslateValue(value);
8673 }
8674 
GetAspectRatio(FrameNode * frameNode)8675 float ViewAbstract::GetAspectRatio(FrameNode* frameNode)
8676 {
8677     float aspectRatio = 1.0f;
8678     const auto& layoutProperty = frameNode->GetLayoutProperty();
8679     CHECK_NULL_RETURN(layoutProperty, aspectRatio);
8680     aspectRatio = layoutProperty->GetAspectRatio();
8681     return aspectRatio;
8682 }
8683 
SetJSFrameNodeOnClick(FrameNode * frameNode,GestureEventFunc && clickEventFunc)8684 void ViewAbstract::SetJSFrameNodeOnClick(FrameNode* frameNode, GestureEventFunc&& clickEventFunc)
8685 {
8686     CHECK_NULL_VOID(frameNode);
8687     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
8688     CHECK_NULL_VOID(gestureHub);
8689     gestureHub->SetJSFrameNodeOnClick(std::move(clickEventFunc));
8690     auto focusHub = frameNode->GetOrCreateFocusHub();
8691     CHECK_NULL_VOID(focusHub);
8692     focusHub->SetFocusable(true, false);
8693     auto* uiNode = reinterpret_cast<UINode*>(frameNode);
8694     CHECK_NULL_VOID(uiNode);
8695     uiNode->SetNodeEventRegistrationState(true);
8696 }
8697 
ClearJSFrameNodeOnClick(FrameNode * frameNode)8698 void ViewAbstract::ClearJSFrameNodeOnClick(FrameNode* frameNode)
8699 {
8700     CHECK_NULL_VOID(frameNode);
8701     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
8702     CHECK_NULL_VOID(gestureHub);
8703     gestureHub->ClearJSFrameNodeOnClick();
8704     auto* uiNode = reinterpret_cast<UINode*>(frameNode);
8705     CHECK_NULL_VOID(uiNode);
8706     uiNode->SetNodeEventRegistrationState(false);
8707 }
8708 
SetJSFrameNodeOnTouch(FrameNode * frameNode,TouchEventFunc && touchEventFunc)8709 void ViewAbstract::SetJSFrameNodeOnTouch(FrameNode* frameNode, TouchEventFunc&& touchEventFunc)
8710 {
8711     CHECK_NULL_VOID(frameNode);
8712     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
8713     CHECK_NULL_VOID(gestureHub);
8714     gestureHub->SetJSFrameNodeOnTouchEvent(std::move(touchEventFunc));
8715 }
8716 
ClearJSFrameNodeOnTouch(FrameNode * frameNode)8717 void ViewAbstract::ClearJSFrameNodeOnTouch(FrameNode* frameNode)
8718 {
8719     CHECK_NULL_VOID(frameNode);
8720     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
8721     CHECK_NULL_VOID(gestureHub);
8722     gestureHub->ClearJSFrameNodeOnTouch();
8723 }
8724 
SetJSFrameNodeOnAppear(FrameNode * frameNode,std::function<void ()> && onAppear)8725 void ViewAbstract::SetJSFrameNodeOnAppear(FrameNode* frameNode, std::function<void()>&& onAppear)
8726 {
8727     CHECK_NULL_VOID(frameNode);
8728     auto eventHub = frameNode->GetOrCreateEventHub<NG::EventHub>();
8729     CHECK_NULL_VOID(eventHub);
8730     eventHub->SetJSFrameNodeOnAppear(std::move(onAppear));
8731 }
8732 
ClearJSFrameNodeOnAppear(FrameNode * frameNode)8733 void ViewAbstract::ClearJSFrameNodeOnAppear(FrameNode* frameNode)
8734 {
8735     CHECK_NULL_VOID(frameNode);
8736     auto eventHub = frameNode->GetOrCreateEventHub<NG::EventHub>();
8737     CHECK_NULL_VOID(eventHub);
8738     eventHub->ClearJSFrameNodeOnAppear();
8739 }
8740 
SetJSFrameNodeOnDisappear(FrameNode * frameNode,std::function<void ()> && onDisappear)8741 void ViewAbstract::SetJSFrameNodeOnDisappear(FrameNode* frameNode, std::function<void()>&& onDisappear)
8742 {
8743     CHECK_NULL_VOID(frameNode);
8744     auto eventHub = frameNode->GetOrCreateEventHub<NG::EventHub>();
8745     CHECK_NULL_VOID(eventHub);
8746     eventHub->SetJSFrameNodeOnDisappear(std::move(onDisappear));
8747 }
8748 
ClearJSFrameNodeOnDisappear(FrameNode * frameNode)8749 void ViewAbstract::ClearJSFrameNodeOnDisappear(FrameNode* frameNode)
8750 {
8751     CHECK_NULL_VOID(frameNode);
8752     auto eventHub = frameNode->GetOrCreateEventHub<NG::EventHub>();
8753     CHECK_NULL_VOID(eventHub);
8754     eventHub->ClearJSFrameNodeOnDisappear();
8755 }
8756 
SetJSFrameNodeOnKeyCallback(FrameNode * frameNode,OnKeyCallbackFunc && onKeyCallback)8757 void ViewAbstract::SetJSFrameNodeOnKeyCallback(FrameNode* frameNode, OnKeyCallbackFunc&& onKeyCallback)
8758 {
8759     CHECK_NULL_VOID(frameNode);
8760     auto focusHub = frameNode->GetOrCreateFocusHub();
8761     CHECK_NULL_VOID(focusHub);
8762     focusHub->SetJSFrameNodeOnKeyCallback(std::move(onKeyCallback));
8763 }
8764 
ClearJSFrameNodeOnKeyCallback(FrameNode * frameNode)8765 void ViewAbstract::ClearJSFrameNodeOnKeyCallback(FrameNode* frameNode)
8766 {
8767     CHECK_NULL_VOID(frameNode);
8768     auto focusHub = frameNode->GetOrCreateFocusHub();
8769     CHECK_NULL_VOID(focusHub);
8770     focusHub->ClearJSFrameNodeOnKeyCallback();
8771 }
8772 
SetJSFrameNodeOnFocusCallback(FrameNode * frameNode,OnFocusFunc && onFocusCallback)8773 void ViewAbstract::SetJSFrameNodeOnFocusCallback(FrameNode* frameNode, OnFocusFunc&& onFocusCallback)
8774 {
8775     CHECK_NULL_VOID(frameNode);
8776     auto focusHub = frameNode->GetOrCreateFocusHub();
8777     CHECK_NULL_VOID(focusHub);
8778     focusHub->SetJSFrameNodeOnFocusCallback(std::move(onFocusCallback));
8779 }
8780 
ClearJSFrameNodeOnFocusCallback(FrameNode * frameNode)8781 void ViewAbstract::ClearJSFrameNodeOnFocusCallback(FrameNode* frameNode)
8782 {
8783     CHECK_NULL_VOID(frameNode);
8784     auto focusHub = frameNode->GetOrCreateFocusHub();
8785     CHECK_NULL_VOID(focusHub);
8786     focusHub->ClearJSFrameNodeOnFocusCallback();
8787 }
8788 
SetJSFrameNodeOnBlurCallback(FrameNode * frameNode,OnBlurFunc && onBlurCallback)8789 void ViewAbstract::SetJSFrameNodeOnBlurCallback(FrameNode* frameNode, OnBlurFunc&& onBlurCallback)
8790 {
8791     CHECK_NULL_VOID(frameNode);
8792     auto focusHub = frameNode->GetOrCreateFocusHub();
8793     CHECK_NULL_VOID(focusHub);
8794     focusHub->SetJSFrameNodeOnBlurCallback(std::move(onBlurCallback));
8795 }
8796 
ClearJSFrameNodeOnBlurCallback(FrameNode * frameNode)8797 void ViewAbstract::ClearJSFrameNodeOnBlurCallback(FrameNode* frameNode)
8798 {
8799     CHECK_NULL_VOID(frameNode);
8800     auto focusHub = frameNode->GetOrCreateFocusHub();
8801     CHECK_NULL_VOID(focusHub);
8802     focusHub->ClearJSFrameNodeOnBlurCallback();
8803 }
8804 
SetJSFrameNodeOnHover(FrameNode * frameNode,OnHoverFunc && onHoverEventFunc)8805 void ViewAbstract::SetJSFrameNodeOnHover(FrameNode* frameNode, OnHoverFunc&& onHoverEventFunc)
8806 {
8807     CHECK_NULL_VOID(frameNode);
8808     auto eventHub = frameNode->GetOrCreateInputEventHub();
8809     CHECK_NULL_VOID(eventHub);
8810     eventHub->SetJSFrameNodeOnHoverEvent(std::move(onHoverEventFunc));
8811 }
8812 
ClearJSFrameNodeOnHover(FrameNode * frameNode)8813 void ViewAbstract::ClearJSFrameNodeOnHover(FrameNode* frameNode)
8814 {
8815     CHECK_NULL_VOID(frameNode);
8816     auto eventHub = frameNode->GetOrCreateInputEventHub();
8817     CHECK_NULL_VOID(eventHub);
8818     eventHub->ClearJSFrameNodeOnHover();
8819 }
8820 
SetJSFrameNodeOnHoverMove(FrameNode * frameNode,OnHoverMoveFunc && onHoverMoveEventFunc)8821 void ViewAbstract::SetJSFrameNodeOnHoverMove(FrameNode* frameNode, OnHoverMoveFunc&& onHoverMoveEventFunc)
8822 {
8823     CHECK_NULL_VOID(frameNode);
8824     auto eventHub = frameNode->GetOrCreateInputEventHub();
8825     CHECK_NULL_VOID(eventHub);
8826     eventHub->SetJSFrameNodeOnHoverMoveEvent(std::move(onHoverMoveEventFunc));
8827 }
8828 
ClearJSFrameNodeOnHoverMove(FrameNode * frameNode)8829 void ViewAbstract::ClearJSFrameNodeOnHoverMove(FrameNode* frameNode)
8830 {
8831     CHECK_NULL_VOID(frameNode);
8832     auto eventHub = frameNode->GetOrCreateInputEventHub();
8833     CHECK_NULL_VOID(eventHub);
8834     eventHub->ClearJSFrameNodeOnHoverMove();
8835 }
8836 
SetJSFrameNodeOnMouse(FrameNode * frameNode,OnMouseEventFunc && onMouseEventFunc)8837 void ViewAbstract::SetJSFrameNodeOnMouse(FrameNode* frameNode, OnMouseEventFunc&& onMouseEventFunc)
8838 {
8839     CHECK_NULL_VOID(frameNode);
8840     auto eventHub = frameNode->GetOrCreateInputEventHub();
8841     CHECK_NULL_VOID(eventHub);
8842     eventHub->SetJSFrameNodeOnMouseEvent(std::move(onMouseEventFunc));
8843 }
8844 
ClearJSFrameNodeOnMouse(FrameNode * frameNode)8845 void ViewAbstract::ClearJSFrameNodeOnMouse(FrameNode* frameNode)
8846 {
8847     CHECK_NULL_VOID(frameNode);
8848     auto eventHub = frameNode->GetOrCreateInputEventHub();
8849     CHECK_NULL_VOID(eventHub);
8850     eventHub->ClearJSFrameNodeOnMouse();
8851 }
8852 
GetBlendApplyType(FrameNode * frameNode)8853 BlendApplyType ViewAbstract::GetBlendApplyType(FrameNode* frameNode)
8854 {
8855     BlendApplyType value = BlendApplyType::FAST;
8856     const auto& target = frameNode->GetRenderContext();
8857     CHECK_NULL_RETURN(target, value);
8858     return target->GetBackBlendApplyTypeValue(value);
8859 }
8860 
SetJSFrameNodeOnSizeChange(FrameNode * frameNode,std::function<void (const RectF & oldRect,const RectF & rect)> && onSizeChanged)8861 void ViewAbstract::SetJSFrameNodeOnSizeChange(
8862     FrameNode* frameNode, std::function<void(const RectF& oldRect, const RectF& rect)>&& onSizeChanged)
8863 {
8864     CHECK_NULL_VOID(frameNode);
8865     frameNode->SetJSFrameNodeOnSizeChangeCallback(std::move(onSizeChanged));
8866 }
8867 
ClearJSFrameNodeOnSizeChange(FrameNode * frameNode)8868 void ViewAbstract::ClearJSFrameNodeOnSizeChange(FrameNode* frameNode)
8869 {
8870     CHECK_NULL_VOID(frameNode);
8871     auto eventHub = frameNode->GetOrCreateEventHub<NG::EventHub>();
8872     CHECK_NULL_VOID(eventHub);
8873     eventHub->ClearJSFrameNodeOnSizeChange();
8874 }
8875 
SetJSFrameNodeOnVisibleAreaApproximateChange(FrameNode * frameNode,const std::function<void (bool,double)> && jsCallback,const std::vector<double> & ratioList,int32_t interval)8876 void ViewAbstract::SetJSFrameNodeOnVisibleAreaApproximateChange(FrameNode* frameNode,
8877     const std::function<void(bool, double)>&& jsCallback, const std::vector<double>& ratioList,
8878     int32_t interval)
8879 {
8880     CHECK_NULL_VOID(frameNode);
8881     auto pipeline = frameNode->GetContext();
8882     CHECK_NULL_VOID(pipeline);
8883     frameNode->CleanVisibleAreaUserCallback(true);
8884 
8885     constexpr uint32_t minInterval = 100; // 100ms
8886     if (interval < 0 || static_cast<uint32_t>(interval) < minInterval) {
8887         interval = minInterval;
8888     }
8889     VisibleCallbackInfo callback;
8890     callback.callback = std::move(jsCallback);
8891     callback.isCurrentVisible = false;
8892     callback.period = static_cast<uint32_t>(interval);
8893     pipeline->AddVisibleAreaChangeNode(frameNode->GetId());
8894     frameNode->SetVisibleAreaUserCallback(ratioList, callback);
8895 }
8896 
ClearJSFrameNodeOnVisibleAreaApproximateChange(FrameNode * frameNode)8897 void ViewAbstract::ClearJSFrameNodeOnVisibleAreaApproximateChange(FrameNode* frameNode)
8898 {
8899     CHECK_NULL_VOID(frameNode);
8900     frameNode->CleanVisibleAreaUserCallback(true);
8901 }
8902 
SetOnGestureJudgeBegin(FrameNode * frameNode,GestureJudgeFunc && gestureJudgeFunc)8903 void ViewAbstract::SetOnGestureJudgeBegin(FrameNode* frameNode, GestureJudgeFunc&& gestureJudgeFunc)
8904 {
8905     CHECK_NULL_VOID(frameNode);
8906     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
8907     CHECK_NULL_VOID(gestureHub);
8908     gestureHub->SetOnGestureJudgeBegin(std::move(gestureJudgeFunc));
8909 }
8910 
SetOnSizeChanged(FrameNode * frameNode,std::function<void (const RectF & oldRect,const RectF & rect)> && onSizeChanged)8911 void ViewAbstract::SetOnSizeChanged(
8912     FrameNode* frameNode, std::function<void(const RectF& oldRect, const RectF& rect)>&& onSizeChanged)
8913 {
8914     CHECK_NULL_VOID(frameNode);
8915     frameNode->SetOnSizeChangeCallback(std::move(onSizeChanged));
8916 }
8917 
SetOnGestureRecognizerJudgeBegin(FrameNode * frameNode,GestureRecognizerJudgeFunc && gestureRecognizerJudgeFunc)8918 void ViewAbstract::SetOnGestureRecognizerJudgeBegin(
8919     FrameNode* frameNode, GestureRecognizerJudgeFunc&& gestureRecognizerJudgeFunc)
8920 {
8921     CHECK_NULL_VOID(frameNode);
8922     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
8923     CHECK_NULL_VOID(gestureHub);
8924     gestureHub->SetOnGestureRecognizerJudgeBegin(std::move(gestureRecognizerJudgeFunc));
8925 }
8926 
SetShouldBuiltInRecognizerParallelWith(FrameNode * frameNode,NG::ShouldBuiltInRecognizerParallelWithFunc && shouldBuiltInRecognizerParallelWithFunc)8927 void ViewAbstract::SetShouldBuiltInRecognizerParallelWith(
8928     FrameNode* frameNode, NG::ShouldBuiltInRecognizerParallelWithFunc&& shouldBuiltInRecognizerParallelWithFunc)
8929 {
8930     CHECK_NULL_VOID(frameNode);
8931     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
8932     CHECK_NULL_VOID(gestureHub);
8933     gestureHub->SetShouldBuildinRecognizerParallelWithFunc(std::move(shouldBuiltInRecognizerParallelWithFunc));
8934 }
8935 
SetNextFocus(FrameNode * frameNode,FocusIntension key,std::variant<WeakPtr<AceType>,std::string> nextFocus)8936 void ViewAbstract::SetNextFocus(FrameNode* frameNode, FocusIntension key,
8937     std::variant<WeakPtr<AceType>, std::string> nextFocus)
8938 {
8939     CHECK_NULL_VOID(frameNode);
8940     auto focusHub = frameNode->GetOrCreateFocusHub();
8941     CHECK_NULL_VOID(focusHub);
8942     focusHub->SetNextFocus(key, nextFocus);
8943 }
8944 
ResetNextFocus(FrameNode * frameNode)8945 void ViewAbstract::ResetNextFocus(FrameNode* frameNode)
8946 {
8947     CHECK_NULL_VOID(frameNode);
8948     auto focusHub = frameNode->GetOrCreateFocusHub();
8949     CHECK_NULL_VOID(focusHub);
8950     focusHub->ResetNextFocus();
8951 }
8952 
SetFocusBoxStyleUpdateFunc(NG::FocusBoxStyle & style,const RefPtr<ResourceObject> & resObj,const std::string & property)8953 void ViewAbstract::SetFocusBoxStyleUpdateFunc(
8954     NG::FocusBoxStyle& style, const RefPtr<ResourceObject>& resObj, const std::string& property)
8955 {
8956     if (property.empty()) {
8957         return;
8958     }
8959     if (!resObj) {
8960         style.RemoveResource(property);
8961         return;
8962     }
8963     auto&& updateFunc = [property](const RefPtr<ResourceObject>& resObj, NG::FocusBoxStyle& style) {
8964         if (property == "focusBoxStyleColor") {
8965             Color strokeColor;
8966             ResourceParseUtils::ParseResColor(resObj, strokeColor);
8967             style.strokeColor = strokeColor;
8968         } else if (property == "focusBoxStyleMargin") {
8969             CalcDimension margin;
8970             ResourceParseUtils::ParseResDimensionFpNG(resObj, margin, false);
8971             style.margin = margin;
8972         } else if (property == "focusBoxStyleWidth") {
8973             CalcDimension strokeWidth;
8974             ResourceParseUtils::ParseResDimensionFpNG(resObj, strokeWidth, false);
8975             style.strokeWidth = strokeWidth;
8976         }
8977     };
8978     style.AddResource(property, resObj, std::move(updateFunc));
8979 }
8980 
SetFocusBoxStyle(FrameNode * frameNode,const NG::FocusBoxStyle & style,bool isReset)8981 void ViewAbstract::SetFocusBoxStyle(FrameNode* frameNode, const NG::FocusBoxStyle& style, bool isReset)
8982 {
8983     CHECK_NULL_VOID(frameNode);
8984     auto focusHub = frameNode->GetOrCreateFocusHub();
8985     CHECK_NULL_VOID(focusHub);
8986     focusHub->GetFocusBox().SetStyle(style);
8987 
8988     if (SystemProperties::ConfigChangePerform()) {
8989         if (isReset) {
8990             auto pattern = frameNode->GetPattern();
8991             CHECK_NULL_VOID(pattern);
8992             pattern->RemoveResObj("focusBox");
8993         } else {
8994             SetFocusBoxUpdateFunc(frameNode, style);
8995         }
8996     }
8997 }
8998 
SetDragEventStrictReportingEnabled(bool dragEventStrictReportingEnabled)8999 void ViewAbstract::SetDragEventStrictReportingEnabled(bool dragEventStrictReportingEnabled)
9000 {
9001     auto pipeline = PipelineContext::GetCurrentContext();
9002     CHECK_NULL_VOID(pipeline);
9003     auto dragDropManager = pipeline->GetDragDropManager();
9004     CHECK_NULL_VOID(dragDropManager);
9005     dragDropManager->SetEventStrictReportingEnabled(dragEventStrictReportingEnabled);
9006 }
9007 
SetDragEventStrictReportingEnabled(int32_t instanceId,bool dragEventStrictReportingEnabled)9008 void ViewAbstract::SetDragEventStrictReportingEnabled(int32_t instanceId, bool dragEventStrictReportingEnabled)
9009 {
9010     auto pipeline = PipelineContext::GetContextByContainerId(instanceId);
9011     CHECK_NULL_VOID(pipeline);
9012     auto dragDropManager = pipeline->GetDragDropManager();
9013     CHECK_NULL_VOID(dragDropManager);
9014     dragDropManager->SetEventStrictReportingEnabled(dragEventStrictReportingEnabled);
9015 }
9016 
EnableDropDisallowedBadge(bool enableDropDisallowedBadge)9017 void ViewAbstract::EnableDropDisallowedBadge(bool enableDropDisallowedBadge)
9018 {
9019     DragDropGlobalController::GetInstance().SetEnableDropDisallowedBadge(enableDropDisallowedBadge);
9020 }
9021 
SetDisallowDropForcedly(bool isDisallowDropForcedly)9022 void ViewAbstract::SetDisallowDropForcedly(bool isDisallowDropForcedly)
9023 {
9024     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
9025     CHECK_NULL_VOID(frameNode);
9026     frameNode->SetDisallowDropForcedly(isDisallowDropForcedly);
9027 }
9028 
SetBackgroundImageResizableSlice(ImageResizableSlice & slice)9029 void ViewAbstract::SetBackgroundImageResizableSlice(ImageResizableSlice& slice)
9030 {
9031     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
9032         return;
9033     }
9034 
9035     if (SystemProperties::ConfigChangePerform()) {
9036         auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
9037         CHECK_NULL_VOID(frameNode);
9038         auto pattern = frameNode->GetPattern();
9039         CHECK_NULL_VOID(pattern);
9040         RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>();
9041         auto&& updateFunc = [slice, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
9042             auto frameNode = weak.Upgrade();
9043             CHECK_NULL_VOID(frameNode);
9044             ImageResizableSlice sliceValue = slice;
9045             sliceValue.ReloadResources();
9046             ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImageResizableSlice, sliceValue, frameNode);
9047         };
9048         pattern->AddResObj("backgroundImageResizableSlice", resObj, std::move(updateFunc));
9049     }
9050 
9051     ACE_UPDATE_RENDER_CONTEXT(BackgroundImageResizableSlice, slice);
9052 }
9053 
SetBackgroundImageResizableSlice(FrameNode * frameNode,ImageResizableSlice & slice,bool isReset)9054 void ViewAbstract::SetBackgroundImageResizableSlice(FrameNode* frameNode, ImageResizableSlice& slice, bool isReset)
9055 {
9056     CHECK_NULL_VOID(frameNode);
9057     if (SystemProperties::ConfigChangePerform()) {
9058         auto pattern = frameNode->GetPattern();
9059         CHECK_NULL_VOID(pattern);
9060         if (isReset) {
9061             pattern->RemoveResObj("backgroundImageResizableSlice");
9062         } else {
9063             RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>();
9064             auto&& updateFunc = [slice, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
9065                 auto frameNode = weak.Upgrade();
9066                 CHECK_NULL_VOID(frameNode);
9067                 ImageResizableSlice sliceValue = slice;
9068                 sliceValue.ReloadResources();
9069                 ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImageResizableSlice, sliceValue, frameNode);
9070             };
9071             pattern->AddResObj("backgroundImageResizableSlice", resObj, std::move(updateFunc));
9072         }
9073     }
9074     ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImageResizableSlice, slice, frameNode);
9075 }
9076 
GetBackgroundImageResizableSlice(FrameNode * frameNode)9077 ImageResizableSlice ViewAbstract::GetBackgroundImageResizableSlice(FrameNode* frameNode)
9078 {
9079     ImageResizableSlice slice;
9080     CHECK_NULL_RETURN(frameNode, slice);
9081     const auto& target = frameNode->GetRenderContext();
9082     CHECK_NULL_RETURN(target, slice);
9083     return target->GetBackgroundImageResizableSliceValue(slice);
9084 }
9085 
SetOnTouchIntercept(FrameNode * frameNode,TouchInterceptFunc && touchInterceptFunc)9086 void ViewAbstract::SetOnTouchIntercept(FrameNode* frameNode, TouchInterceptFunc&& touchInterceptFunc)
9087 {
9088     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
9089     CHECK_NULL_VOID(gestureHub);
9090     gestureHub->SetOnTouchIntercept(std::move(touchInterceptFunc));
9091 }
9092 
GetLayoutWeight(FrameNode * frameNode)9093 float ViewAbstract::GetLayoutWeight(FrameNode* frameNode)
9094 {
9095     float layoutWeight = 0.0f;
9096     CHECK_NULL_RETURN(frameNode, layoutWeight);
9097     auto layoutProperty = frameNode->GetLayoutProperty();
9098     CHECK_NULL_RETURN(layoutProperty, layoutWeight);
9099     auto& magicItemProperty = layoutProperty->GetMagicItemProperty();
9100     if (magicItemProperty.HasLayoutWeight()) {
9101         return magicItemProperty.GetLayoutWeight().value_or(layoutWeight);
9102     }
9103     return layoutWeight;
9104 }
9105 
GetDisplayIndex(FrameNode * frameNode)9106 int32_t ViewAbstract::GetDisplayIndex(FrameNode* frameNode)
9107 {
9108     int32_t defaultDisplayIndex = 0;
9109     CHECK_NULL_RETURN(frameNode, defaultDisplayIndex);
9110     const auto& layoutProperty = frameNode->GetLayoutProperty();
9111     CHECK_NULL_RETURN(layoutProperty, defaultDisplayIndex);
9112     const auto& flexItemProperty = layoutProperty->GetFlexItemProperty();
9113     CHECK_NULL_RETURN(flexItemProperty, defaultDisplayIndex);
9114     return flexItemProperty->GetDisplayIndex().value_or(defaultDisplayIndex);
9115 }
9116 
GetOuterBorderWidth(FrameNode * frameNode)9117 NG::BorderWidthProperty ViewAbstract::GetOuterBorderWidth(FrameNode* frameNode)
9118 {
9119     BorderWidthProperty borderWidth;
9120     CHECK_NULL_RETURN(frameNode, borderWidth);
9121     auto context = frameNode->GetRenderContext();
9122     CHECK_NULL_RETURN(context, borderWidth);
9123     auto outBorderWidth = context->GetOuterBorder()->GetOuterBorderWidth();
9124     CHECK_NULL_RETURN(outBorderWidth, borderWidth);
9125     return outBorderWidth.value_or(borderWidth);
9126 }
9127 
SetBias(FrameNode * frameNode,const BiasPair & biasPair)9128 void ViewAbstract::SetBias(FrameNode* frameNode, const BiasPair& biasPair)
9129 {
9130     CHECK_NULL_VOID(frameNode);
9131     ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Bias, biasPair, frameNode);
9132 }
9133 
GetBias(FrameNode * frameNode)9134 BiasPair ViewAbstract::GetBias(FrameNode* frameNode)
9135 {
9136     BiasPair biasPair(-1.0f, -1.0f);
9137     CHECK_NULL_RETURN(frameNode, biasPair);
9138     auto layoutProperty = frameNode->GetLayoutProperty();
9139     CHECK_NULL_RETURN(layoutProperty, biasPair);
9140     CHECK_NULL_RETURN(layoutProperty->GetFlexItemProperty(), biasPair);
9141     return layoutProperty->GetFlexItemProperty()->GetBias().value_or(biasPair);
9142 }
9143 
ResetBias(FrameNode * frameNode)9144 void ViewAbstract::ResetBias(FrameNode* frameNode)
9145 {
9146     CHECK_NULL_VOID(frameNode);
9147     auto layoutProperty = frameNode->GetLayoutProperty();
9148     CHECK_NULL_VOID(layoutProperty);
9149     CHECK_NULL_VOID(layoutProperty->GetFlexItemProperty());
9150     layoutProperty->GetFlexItemProperty()->ResetBias();
9151 }
9152 
GetRenderFit(FrameNode * frameNode)9153 RenderFit ViewAbstract::GetRenderFit(FrameNode* frameNode)
9154 {
9155     RenderFit defalutRenderFit = RenderFit::TOP_LEFT;
9156     CHECK_NULL_RETURN(frameNode, defalutRenderFit);
9157     auto renderContext = frameNode->GetRenderContext();
9158     CHECK_NULL_RETURN(renderContext, defalutRenderFit);
9159     return renderContext->GetRenderFit().value_or(defalutRenderFit);
9160 }
9161 
GetOuterBorderColor(FrameNode * frameNode)9162 BorderColorProperty ViewAbstract::GetOuterBorderColor(FrameNode* frameNode)
9163 {
9164     Color defaultColor(0xff000000);
9165     BorderColorProperty borderColors = { defaultColor, defaultColor, defaultColor, defaultColor,
9166         std::nullopt, std::nullopt };
9167     CHECK_NULL_RETURN(frameNode, borderColors);
9168     const auto& target = frameNode->GetRenderContext();
9169     CHECK_NULL_RETURN(target, borderColors);
9170     return target->GetOuterBorderColorValue(borderColors);
9171 }
9172 
GetRenderGroup(FrameNode * frameNode)9173 bool ViewAbstract::GetRenderGroup(FrameNode* frameNode)
9174 {
9175     CHECK_NULL_RETURN(frameNode, false);
9176     const auto& target = frameNode->GetRenderContext();
9177     CHECK_NULL_RETURN(target, false);
9178     return target->GetRenderGroupValue(false);
9179 }
9180 
SetOnVisibleChange(FrameNode * frameNode,std::function<void (bool,double)> && onVisibleChange,const std::vector<double> & ratioList)9181 void ViewAbstract::SetOnVisibleChange(FrameNode* frameNode, std::function<void(bool, double)>&& onVisibleChange,
9182     const std::vector<double> &ratioList)
9183 {
9184     FREE_NODE_CHECK(frameNode, SetOnVisibleChange, frameNode, std::move(onVisibleChange), ratioList);
9185     CHECK_NULL_VOID(frameNode);
9186     auto pipeline = frameNode->GetContext();
9187     CHECK_NULL_VOID(pipeline);
9188     frameNode->CleanVisibleAreaUserCallback();
9189     pipeline->AddVisibleAreaChangeNode(AceType::Claim<FrameNode>(frameNode), ratioList, onVisibleChange);
9190 }
9191 
SetOnVisibleAreaApproximateChange(FrameNode * frameNode,const std::function<void (bool,double)> && onVisibleChange,const std::vector<double> & ratioList,int32_t expectedUpdateInterval)9192 void ViewAbstract::SetOnVisibleAreaApproximateChange(FrameNode* frameNode,
9193     const std::function<void(bool, double)>&& onVisibleChange, const std::vector<double>& ratioList,
9194     int32_t expectedUpdateInterval)
9195 {
9196     FREE_NODE_CHECK(frameNode, SetOnVisibleAreaApproximateChange, frameNode, std::move(onVisibleChange),
9197         ratioList, expectedUpdateInterval);
9198     CHECK_NULL_VOID(frameNode);
9199     auto pipeline = frameNode->GetContext();
9200     CHECK_NULL_VOID(pipeline);
9201     frameNode->CleanVisibleAreaUserCallback(true);
9202 
9203     constexpr uint32_t minInterval = 100; // 100ms
9204     if (expectedUpdateInterval < 0 || static_cast<uint32_t>(expectedUpdateInterval) < minInterval) {
9205         expectedUpdateInterval = minInterval;
9206     }
9207     VisibleCallbackInfo callback;
9208     callback.callback = std::move(onVisibleChange);
9209     callback.isCurrentVisible = false;
9210     callback.period = static_cast<uint32_t>(expectedUpdateInterval);
9211     pipeline->AddVisibleAreaChangeNode(frameNode->GetId());
9212     frameNode->SetVisibleAreaUserCallback(ratioList, callback);
9213 }
9214 
SetOnVisibleAreaApproximateChange(const std::function<void (bool,double)> && onVisibleChange,const std::vector<double> & ratioList,int32_t expectedUpdateInterval)9215 void ViewAbstract::SetOnVisibleAreaApproximateChange(const std::function<void(bool, double)>&& onVisibleChange,
9216     const std::vector<double>& ratioList, int32_t expectedUpdateInterval)
9217 {
9218     auto pipeline = PipelineContext::GetCurrentContext();
9219     CHECK_NULL_VOID(pipeline);
9220     auto frameNode = AceType::Claim(ViewStackProcessor::GetInstance()->GetMainFrameNode());
9221     CHECK_NULL_VOID(frameNode);
9222     frameNode->CleanVisibleAreaUserCallback(true);
9223 
9224     constexpr uint32_t minInterval = 100; // 100ms
9225     if (expectedUpdateInterval < 0 || static_cast<uint32_t>(expectedUpdateInterval) < minInterval) {
9226         expectedUpdateInterval = minInterval;
9227     }
9228     VisibleCallbackInfo callback;
9229     callback.callback = std::move(onVisibleChange);
9230     callback.isCurrentVisible = false;
9231     callback.period = static_cast<uint32_t>(expectedUpdateInterval);
9232     pipeline->AddVisibleAreaChangeNode(frameNode->GetId());
9233     frameNode->SetVisibleAreaUserCallback(ratioList, callback);
9234 }
9235 
GetColorBlend(FrameNode * frameNode)9236 Color ViewAbstract::GetColorBlend(FrameNode* frameNode)
9237 {
9238     Color defaultColor = Color::TRANSPARENT;
9239     CHECK_NULL_RETURN(frameNode, defaultColor);
9240     const auto& target = frameNode->GetRenderContext();
9241     CHECK_NULL_RETURN(target, defaultColor);
9242     return target->GetFrontColorBlendValue(defaultColor);
9243 }
9244 
ResetAreaChanged(FrameNode * frameNode)9245 void ViewAbstract::ResetAreaChanged(FrameNode* frameNode)
9246 {
9247     FREE_NODE_CHECK(frameNode, ResetAreaChanged, frameNode);
9248     CHECK_NULL_VOID(frameNode);
9249     auto pipeline = frameNode->GetContext();
9250     CHECK_NULL_VOID(pipeline);
9251     frameNode->ClearUserOnAreaChange();
9252     pipeline->RemoveOnAreaChangeNode(frameNode->GetId());
9253 }
9254 
ResetVisibleChange(FrameNode * frameNode)9255 void ViewAbstract::ResetVisibleChange(FrameNode* frameNode)
9256 {
9257     FREE_NODE_CHECK(frameNode, ResetVisibleChange, frameNode);
9258     CHECK_NULL_VOID(frameNode);
9259     auto pipeline = frameNode->GetContext();
9260     CHECK_NULL_VOID(pipeline);
9261     frameNode->CleanVisibleAreaUserCallback();
9262     pipeline->RemoveVisibleAreaChangeNode(frameNode->GetId());
9263 }
9264 
SetLayoutRect(FrameNode * frameNode,const NG::RectF & rect)9265 void ViewAbstract::SetLayoutRect(FrameNode* frameNode, const NG::RectF& rect)
9266 {
9267     CHECK_NULL_VOID(frameNode);
9268     frameNode->SetIsMeasureBoundary(true);
9269     const auto& layoutProperty = frameNode->GetLayoutProperty();
9270     CHECK_NULL_VOID(layoutProperty);
9271     layoutProperty->SetLayoutRect(rect);
9272 }
9273 
ResetLayoutRect(FrameNode * frameNode)9274 void ViewAbstract::ResetLayoutRect(FrameNode* frameNode)
9275 {
9276     CHECK_NULL_VOID(frameNode);
9277     frameNode->SetIsMeasureBoundary(false);
9278     const auto& layoutProperty = frameNode->GetLayoutProperty();
9279     CHECK_NULL_VOID(layoutProperty);
9280     layoutProperty->ResetLayoutRect();
9281 }
9282 
GetLayoutRect(FrameNode * frameNode)9283 NG::RectF ViewAbstract::GetLayoutRect(FrameNode* frameNode)
9284 {
9285     CHECK_NULL_RETURN(frameNode, NG::RectF());
9286     const auto& layoutProperty = frameNode->GetLayoutProperty();
9287     CHECK_NULL_RETURN(layoutProperty, NG::RectF());
9288     return layoutProperty->GetLayoutRect().value_or(NG::RectF());
9289 }
9290 
GetFocusOnTouch(FrameNode * frameNode)9291 bool ViewAbstract::GetFocusOnTouch(FrameNode* frameNode)
9292 {
9293     CHECK_NULL_RETURN(frameNode, false);
9294     auto focusHub = frameNode->GetFocusHub();
9295     CHECK_NULL_RETURN(focusHub, false);
9296     return focusHub->IsFocusOnTouch().value_or(false);
9297 }
9298 
SetFocusScopeId(const std::string & focusScopeId,bool isGroup,bool arrowKeyStepOut)9299 void ViewAbstract::SetFocusScopeId(const std::string& focusScopeId, bool isGroup, bool arrowKeyStepOut)
9300 {
9301     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
9302     CHECK_NULL_VOID(focusHub);
9303     focusHub->SetFocusScopeId(focusScopeId, isGroup, arrowKeyStepOut);
9304 }
9305 
SetFocusScopePriority(const std::string & focusScopeId,const uint32_t focusPriority)9306 void ViewAbstract::SetFocusScopePriority(const std::string& focusScopeId, const uint32_t focusPriority)
9307 {
9308     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
9309     CHECK_NULL_VOID(focusHub);
9310     focusHub->SetFocusScopePriority(focusScopeId, focusPriority);
9311 }
9312 
SetFocusScopeId(FrameNode * frameNode,const std::string & focusScopeId,bool isGroup,bool arrowKeyStepOut)9313 void ViewAbstract::SetFocusScopeId(FrameNode* frameNode, const std::string& focusScopeId, bool isGroup,
9314     bool arrowKeyStepOut)
9315 {
9316     CHECK_NULL_VOID(frameNode);
9317     auto focusHub = frameNode->GetOrCreateFocusHub();
9318     CHECK_NULL_VOID(focusHub);
9319     focusHub->SetFocusScopeId(focusScopeId, isGroup, arrowKeyStepOut);
9320 }
9321 
SetFocusScopePriority(FrameNode * frameNode,const std::string & focusScopeId,const uint32_t focusPriority)9322 void ViewAbstract::SetFocusScopePriority(FrameNode* frameNode, const std::string& focusScopeId,
9323     const uint32_t focusPriority)
9324 {
9325     CHECK_NULL_VOID(frameNode);
9326     auto focusHub = frameNode->GetOrCreateFocusHub();
9327     CHECK_NULL_VOID(focusHub);
9328     focusHub->SetFocusScopePriority(focusScopeId, focusPriority);
9329 }
9330 
FreezeUINodeById(const std::string & id,bool isFreeze)9331 void ViewAbstract::FreezeUINodeById(const std::string& id, bool isFreeze)
9332 {
9333     auto targetNode = ElementRegister::GetInstance()->GetAttachedFrameNodeById(id, true);
9334     CHECK_NULL_VOID(targetNode);
9335     auto pipeline = targetNode->GetContext();
9336     if (pipeline != nullptr) {
9337         pipeline->SetOpenInvisibleFreeze(true);
9338     }
9339     targetNode->SetFreeze(isFreeze, true, true);
9340 }
9341 
FreezeUINodeByUniqueId(const int32_t & uniqueId,bool isFreeze)9342 void ViewAbstract::FreezeUINodeByUniqueId(const int32_t& uniqueId, bool isFreeze)
9343 {
9344     auto targetNodeElement = ElementRegister::GetInstance()->GetNodeById(uniqueId);
9345     auto targetNode = AceType::DynamicCast<NG::FrameNode>(targetNodeElement);
9346     CHECK_NULL_VOID(targetNode);
9347     auto pipeline = targetNode->GetContext();
9348     if (pipeline != nullptr) {
9349         pipeline->SetOpenInvisibleFreeze(true);
9350     }
9351     targetNode->SetFreeze(isFreeze, true, true);
9352 }
9353 
GetSafeAreaExpandType(FrameNode * frameNode)9354 uint32_t ViewAbstract::GetSafeAreaExpandType(FrameNode* frameNode)
9355 {
9356     uint32_t value = SAFE_AREA_TYPE_ALL;
9357     CHECK_NULL_RETURN(frameNode, value);
9358     const auto& layoutProperty = frameNode->GetLayoutProperty();
9359     CHECK_NULL_RETURN(layoutProperty, value);
9360     const auto& SafeAreaExpandOpts = layoutProperty->GetSafeAreaExpandOpts();
9361     CHECK_NULL_RETURN(SafeAreaExpandOpts, value);
9362     if (SafeAreaExpandOpts->type > 0) {
9363         value = SafeAreaExpandOpts->type;
9364     }
9365     return value;
9366 }
9367 
GetSafeAreaExpandEdges(FrameNode * frameNode)9368 uint32_t ViewAbstract::GetSafeAreaExpandEdges(FrameNode* frameNode)
9369 {
9370     uint32_t value = SAFE_AREA_EDGE_ALL;
9371     CHECK_NULL_RETURN(frameNode, value);
9372     const auto& layoutProperty = frameNode->GetLayoutProperty();
9373     CHECK_NULL_RETURN(layoutProperty, value);
9374     const auto& SafeAreaExpandOpts = layoutProperty->GetSafeAreaExpandOpts();
9375     CHECK_NULL_RETURN(SafeAreaExpandOpts, value);
9376     if (SafeAreaExpandOpts->edges > 0) {
9377         value = SafeAreaExpandOpts->edges;
9378     }
9379     return value;
9380 }
9381 
SetPositionLocalizedEdges(bool needLocalized)9382 void ViewAbstract::SetPositionLocalizedEdges(bool needLocalized)
9383 {
9384     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
9385     CHECK_NULL_VOID(frameNode);
9386     auto layoutProperty = frameNode->GetLayoutProperty();
9387     CHECK_NULL_VOID(layoutProperty);
9388     layoutProperty->UpdateNeedPositionLocalizedEdges(needLocalized);
9389 }
9390 
SetMarkAnchorStart(Dimension & markAnchorStart)9391 void ViewAbstract::SetMarkAnchorStart(Dimension& markAnchorStart)
9392 {
9393     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
9394     CHECK_NULL_VOID(frameNode);
9395     auto layoutProperty = frameNode->GetLayoutProperty();
9396     CHECK_NULL_VOID(layoutProperty);
9397     layoutProperty->UpdateMarkAnchorStart(markAnchorStart);
9398 }
9399 
ResetMarkAnchorStart()9400 void ViewAbstract::ResetMarkAnchorStart()
9401 {
9402     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
9403     CHECK_NULL_VOID(frameNode);
9404     auto layoutProperty = frameNode->GetLayoutProperty();
9405     CHECK_NULL_VOID(layoutProperty);
9406     layoutProperty->ResetMarkAnchorStart();
9407 }
9408 
SetOffsetLocalizedEdges(bool needLocalized)9409 void ViewAbstract::SetOffsetLocalizedEdges(bool needLocalized)
9410 {
9411     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
9412     CHECK_NULL_VOID(frameNode);
9413     auto layoutProperty = frameNode->GetLayoutProperty();
9414     CHECK_NULL_VOID(layoutProperty);
9415     layoutProperty->UpdateNeedOffsetLocalizedEdges(needLocalized);
9416 }
9417 
SetSystemColorModeChangeEvent(FrameNode * frameNode,std::function<void (int32_t)> && onColorModeChange)9418 void ViewAbstract::SetSystemColorModeChangeEvent(
9419     FrameNode* frameNode, std::function<void(int32_t)>&& onColorModeChange)
9420 {
9421     CHECK_NULL_VOID(frameNode);
9422     frameNode->SetNDKColorModeUpdateCallback(std::move(onColorModeChange));
9423 }
9424 
SetSystemFontChangeEvent(FrameNode * frameNode,std::function<void (float,float)> && onFontChange)9425 void ViewAbstract::SetSystemFontChangeEvent(FrameNode* frameNode, std::function<void(float, float)>&& onFontChange)
9426 {
9427     CHECK_NULL_VOID(frameNode);
9428     frameNode->SetNDKFontUpdateCallback(std::move(onFontChange));
9429 }
9430 
SetDrawCompleteEvent(FrameNode * frameNode,std::function<void ()> && onDraw)9431 void ViewAbstract::SetDrawCompleteEvent(
9432     FrameNode* frameNode, std::function<void()>&& onDraw)
9433 {
9434     CHECK_NULL_VOID(frameNode);
9435     auto eventHub = frameNode->GetOrCreateEventHub<NG::EventHub>();
9436     CHECK_NULL_VOID(eventHub);
9437     eventHub->SetNDKDrawCompletedCallback(std::move(onDraw));
9438 }
9439 
SetLayoutEvent(FrameNode * frameNode,std::function<void ()> && onLayout)9440 void ViewAbstract::SetLayoutEvent(
9441     FrameNode* frameNode, std::function<void()>&& onLayout)
9442 {
9443     CHECK_NULL_VOID(frameNode);
9444     auto eventHub = frameNode->GetOrCreateEventHub<NG::EventHub>();
9445     CHECK_NULL_VOID(eventHub);
9446     eventHub->SetNDKLayoutCallback(std::move(onLayout));
9447 }
9448 
AddCustomProperty(UINode * frameNode,const std::string & key,const std::string & value)9449 void ViewAbstract::AddCustomProperty(UINode* frameNode, const std::string& key, const std::string& value)
9450 {
9451     CHECK_NULL_VOID(frameNode);
9452     frameNode->AddCustomProperty(key, value);
9453 }
9454 
RemoveCustomProperty(UINode * frameNode,const std::string & key)9455 void ViewAbstract::RemoveCustomProperty(UINode* frameNode, const std::string& key)
9456 {
9457     CHECK_NULL_VOID(frameNode);
9458     frameNode->RemoveCustomProperty(key);
9459 }
9460 
CancelDataLoading(const std::string & key)9461 int32_t ViewAbstract::CancelDataLoading(const std::string& key)
9462 {
9463     auto pipeline = PipelineContext::GetCurrentContext();
9464     CHECK_NULL_RETURN(pipeline, -1);
9465     auto dragDropManager = pipeline->GetDragDropManager();
9466     CHECK_NULL_RETURN(dragDropManager, -1);
9467     return dragDropManager->CancelUDMFDataLoading(key);
9468 }
9469 
SetDisableDataPrefetch(bool disableDataPrefetch)9470 void ViewAbstract::SetDisableDataPrefetch(bool disableDataPrefetch)
9471 {
9472     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
9473     CHECK_NULL_VOID(eventHub);
9474     eventHub->SetDisableDataPrefetch(disableDataPrefetch);
9475 }
9476 
SetDisableDataPrefetch(FrameNode * frameNode,bool disableDataPrefetch)9477 void ViewAbstract::SetDisableDataPrefetch(FrameNode* frameNode, bool disableDataPrefetch)
9478 {
9479     CHECK_NULL_VOID(frameNode);
9480     auto eventHub = frameNode->GetOrCreateEventHub<EventHub>();
9481     CHECK_NULL_VOID(eventHub);
9482 
9483     eventHub->SetDisableDataPrefetch(disableDataPrefetch);
9484 }
9485 
SetOnTouchTestFunc(FrameNode * frameNode,NG::OnChildTouchTestFunc && onChildTouchTest)9486 void ViewAbstract::SetOnTouchTestFunc(FrameNode* frameNode, NG::OnChildTouchTestFunc&& onChildTouchTest)
9487 {
9488     CHECK_NULL_VOID(frameNode);
9489     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
9490     CHECK_NULL_VOID(gestureHub);
9491     gestureHub->SetOnTouchTestFunc(std::move(onChildTouchTest));
9492 }
9493 
SetJSFrameNodeOnReachStart(FrameNode * frameNode,OnReachEvent && onReachStart)9494 void ViewAbstract::SetJSFrameNodeOnReachStart(FrameNode* frameNode, OnReachEvent&& onReachStart)
9495 {
9496     CHECK_NULL_VOID(frameNode);
9497     auto eventHub = frameNode->GetOrCreateEventHub<ScrollableEventHub>();
9498     CHECK_NULL_VOID(eventHub);
9499 
9500     eventHub->SetJSFrameNodeOnReachStart(std::move(onReachStart));
9501 }
9502 
ClearJSFrameNodeOnReachStart(FrameNode * frameNode)9503 void ViewAbstract::ClearJSFrameNodeOnReachStart(FrameNode* frameNode)
9504 {
9505     CHECK_NULL_VOID(frameNode);
9506     auto eventHub = frameNode->GetOrCreateEventHub<ScrollableEventHub>();
9507     CHECK_NULL_VOID(eventHub);
9508 
9509     eventHub->ClearJSFrameNodeOnReachStart();
9510 }
9511 
SetJSFrameNodeOnReachEnd(FrameNode * frameNode,OnReachEvent && onReachEnd)9512 void ViewAbstract::SetJSFrameNodeOnReachEnd(FrameNode* frameNode, OnReachEvent&& onReachEnd)
9513 {
9514     CHECK_NULL_VOID(frameNode);
9515     auto eventHub = frameNode->GetOrCreateEventHub<ScrollableEventHub>();
9516     CHECK_NULL_VOID(eventHub);
9517 
9518     eventHub->SetJSFrameNodeOnReachEnd(std::move(onReachEnd));
9519 }
9520 
ClearJSFrameNodeOnReachEnd(FrameNode * frameNode)9521 void ViewAbstract::ClearJSFrameNodeOnReachEnd(FrameNode* frameNode)
9522 {
9523     CHECK_NULL_VOID(frameNode);
9524     auto eventHub = frameNode->GetOrCreateEventHub<ScrollableEventHub>();
9525     CHECK_NULL_VOID(eventHub);
9526 
9527     eventHub->ClearJSFrameNodeOnReachEnd();
9528 }
9529 
SetJSFrameNodeOnScrollStart(FrameNode * frameNode,OnScrollStartEvent && onScrollStart)9530 void ViewAbstract::SetJSFrameNodeOnScrollStart(FrameNode* frameNode, OnScrollStartEvent&& onScrollStart)
9531 {
9532     CHECK_NULL_VOID(frameNode);
9533     auto eventHub = frameNode->GetOrCreateEventHub<ScrollableEventHub>();
9534     CHECK_NULL_VOID(eventHub);
9535 
9536     eventHub->SetJSFrameNodeOnScrollStart(std::move(onScrollStart));
9537 }
9538 
ClearJSFrameNodeOnScrollStart(FrameNode * frameNode)9539 void ViewAbstract::ClearJSFrameNodeOnScrollStart(FrameNode* frameNode)
9540 {
9541     CHECK_NULL_VOID(frameNode);
9542     auto eventHub = frameNode->GetOrCreateEventHub<ScrollableEventHub>();
9543     CHECK_NULL_VOID(eventHub);
9544 
9545     eventHub->ClearJSFrameNodeOnScrollStart();
9546 }
9547 
SetJSFrameNodeOnScrollStop(FrameNode * frameNode,OnScrollStopEvent && onScrollStop)9548 void ViewAbstract::SetJSFrameNodeOnScrollStop(FrameNode* frameNode, OnScrollStopEvent&& onScrollStop)
9549 {
9550     CHECK_NULL_VOID(frameNode);
9551     auto eventHub = frameNode->GetOrCreateEventHub<ScrollableEventHub>();
9552     CHECK_NULL_VOID(eventHub);
9553 
9554     eventHub->SetJSFrameNodeOnScrollStop(std::move(onScrollStop));
9555 }
9556 
ClearJSFrameNodeOnScrollStop(FrameNode * frameNode)9557 void ViewAbstract::ClearJSFrameNodeOnScrollStop(FrameNode* frameNode)
9558 {
9559     CHECK_NULL_VOID(frameNode);
9560     auto eventHub = frameNode->GetOrCreateEventHub<ScrollableEventHub>();
9561     CHECK_NULL_VOID(eventHub);
9562 
9563     eventHub->ClearJSFrameNodeOnScrollStop();
9564 }
9565 
SetJSFrameNodeOnScrollFrameBegin(FrameNode * frameNode,OnScrollFrameBeginEvent && onScrollFrameBegin)9566 void ViewAbstract::SetJSFrameNodeOnScrollFrameBegin(FrameNode* frameNode, OnScrollFrameBeginEvent&& onScrollFrameBegin)
9567 {
9568     CHECK_NULL_VOID(frameNode);
9569     auto eventHub = frameNode->GetOrCreateEventHub<ScrollableEventHub>();
9570     CHECK_NULL_VOID(eventHub);
9571 
9572     eventHub->SetJSFrameNodeOnScrollFrameBegin(std::move(onScrollFrameBegin));
9573 }
9574 
ClearJSFrameNodeOnScrollFrameBegin(FrameNode * frameNode)9575 void ViewAbstract::ClearJSFrameNodeOnScrollFrameBegin(FrameNode* frameNode)
9576 {
9577     CHECK_NULL_VOID(frameNode);
9578     auto eventHub = frameNode->GetOrCreateEventHub<ScrollableEventHub>();
9579     CHECK_NULL_VOID(eventHub);
9580 
9581     eventHub->ClearJSFrameNodeOnScrollFrameBegin();
9582 }
9583 
SetJSFrameNodeOnWillScroll(FrameNode * frameNode,OnWillScrollEvent && onWillScroll)9584 void ViewAbstract::SetJSFrameNodeOnWillScroll(FrameNode* frameNode, OnWillScrollEvent&& onWillScroll)
9585 {
9586     CHECK_NULL_VOID(frameNode);
9587     auto eventHub = frameNode->GetOrCreateEventHub<ScrollableEventHub>();
9588     CHECK_NULL_VOID(eventHub);
9589 
9590     eventHub->SetJSFrameNodeOnWillScroll(std::move(onWillScroll));
9591 }
9592 
ClearJSFrameNodeOnWillScroll(FrameNode * frameNode)9593 void ViewAbstract::ClearJSFrameNodeOnWillScroll(FrameNode* frameNode)
9594 {
9595     CHECK_NULL_VOID(frameNode);
9596     auto eventHub = frameNode->GetOrCreateEventHub<ScrollableEventHub>();
9597     CHECK_NULL_VOID(eventHub);
9598 
9599     eventHub->ClearJSFrameNodeOnWillScroll();
9600 }
9601 
SetJSFrameNodeOnDidScroll(FrameNode * frameNode,OnScrollEvent && onDidScroll)9602 void ViewAbstract::SetJSFrameNodeOnDidScroll(FrameNode* frameNode, OnScrollEvent&& onDidScroll)
9603 {
9604     CHECK_NULL_VOID(frameNode);
9605     auto eventHub = frameNode->GetOrCreateEventHub<ScrollableEventHub>();
9606     CHECK_NULL_VOID(eventHub);
9607 
9608     eventHub->SetJSFrameNodeOnDidScroll(std::move(onDidScroll));
9609 }
9610 
ClearJSFrameNodeOnDidScroll(FrameNode * frameNode)9611 void ViewAbstract::ClearJSFrameNodeOnDidScroll(FrameNode* frameNode)
9612 {
9613     CHECK_NULL_VOID(frameNode);
9614     auto eventHub = frameNode->GetOrCreateEventHub<ScrollableEventHub>();
9615     CHECK_NULL_VOID(eventHub);
9616 
9617     eventHub->ClearJSFrameNodeOnDidScroll();
9618 }
9619 
SetJSFrameNodeOnListScrollIndex(FrameNode * frameNode,OnScrollIndexEvent && onScrollIndex)9620 void ViewAbstract::SetJSFrameNodeOnListScrollIndex(FrameNode* frameNode, OnScrollIndexEvent&& onScrollIndex)
9621 {
9622     CHECK_NULL_VOID(frameNode);
9623     auto eventHub = frameNode->GetOrCreateEventHub<ListEventHub>();
9624     CHECK_NULL_VOID(eventHub);
9625 
9626     eventHub->SetJSFrameNodeOnListScrollIndex(std::move(onScrollIndex));
9627 }
9628 
ClearJSFrameNodeOnListScrollIndex(FrameNode * frameNode)9629 void ViewAbstract::ClearJSFrameNodeOnListScrollIndex(FrameNode* frameNode)
9630 {
9631     CHECK_NULL_VOID(frameNode);
9632     auto eventHub = frameNode->GetOrCreateEventHub<ListEventHub>();
9633     CHECK_NULL_VOID(eventHub);
9634 
9635     eventHub->ClearJSFrameNodeOnListScrollIndex();
9636 }
9637 
SetJSFrameNodeOnScrollVisibleContentChange(FrameNode * frameNode,OnScrollVisibleContentChangeEvent && onScrollVisibleContentChange)9638 void ViewAbstract::SetJSFrameNodeOnScrollVisibleContentChange(FrameNode* frameNode,
9639     OnScrollVisibleContentChangeEvent&& onScrollVisibleContentChange)
9640 {
9641     CHECK_NULL_VOID(frameNode);
9642     auto eventHub = frameNode->GetOrCreateEventHub<ListEventHub>();
9643     CHECK_NULL_VOID(eventHub);
9644 
9645     eventHub->SetJSFrameNodeOnScrollVisibleContentChange(std::move(onScrollVisibleContentChange));
9646 }
9647 
ClearJSFrameNodeOnScrollVisibleContentChange(FrameNode * frameNode)9648 void ViewAbstract::ClearJSFrameNodeOnScrollVisibleContentChange(FrameNode* frameNode)
9649 {
9650     CHECK_NULL_VOID(frameNode);
9651     auto eventHub = frameNode->GetOrCreateEventHub<ListEventHub>();
9652     CHECK_NULL_VOID(eventHub);
9653 
9654     eventHub->ClearJSFrameNodeOnScrollVisibleContentChange();
9655 }
9656 
SetJSFrameNodeOnScrollWillScroll(FrameNode * frameNode,ScrollEventWithReturn && onWillScroll)9657 void ViewAbstract::SetJSFrameNodeOnScrollWillScroll(FrameNode* frameNode, ScrollEventWithReturn&& onWillScroll)
9658 {
9659     CHECK_NULL_VOID(frameNode);
9660     auto eventHub = frameNode->GetOrCreateEventHub<ScrollEventHub>();
9661     CHECK_NULL_VOID(eventHub);
9662 
9663     eventHub->SetJSFrameNodeOnScrollWillScroll(std::move(onWillScroll));
9664 }
9665 
ClearJSFrameNodeOnScrollWillScroll(FrameNode * frameNode)9666 void ViewAbstract::ClearJSFrameNodeOnScrollWillScroll(FrameNode* frameNode)
9667 {
9668     CHECK_NULL_VOID(frameNode);
9669     auto eventHub = frameNode->GetOrCreateEventHub<ScrollEventHub>();
9670     CHECK_NULL_VOID(eventHub);
9671 
9672     eventHub->ClearJSFrameNodeOnScrollWillScroll();
9673 }
9674 
SetJSFrameNodeOnScrollDidScroll(FrameNode * frameNode,ScrollEventWithState && onDidScroll)9675 void ViewAbstract::SetJSFrameNodeOnScrollDidScroll(FrameNode* frameNode, ScrollEventWithState&& onDidScroll)
9676 {
9677     CHECK_NULL_VOID(frameNode);
9678     auto eventHub = frameNode->GetOrCreateEventHub<ScrollEventHub>();
9679     CHECK_NULL_VOID(eventHub);
9680 
9681     eventHub->SetJSFrameNodeOnScrollDidScroll(std::move(onDidScroll));
9682 }
9683 
ClearJSFrameNodeOnScrollDidScroll(FrameNode * frameNode)9684 void ViewAbstract::ClearJSFrameNodeOnScrollDidScroll(FrameNode* frameNode)
9685 {
9686     CHECK_NULL_VOID(frameNode);
9687     auto eventHub = frameNode->GetOrCreateEventHub<ScrollEventHub>();
9688     CHECK_NULL_VOID(eventHub);
9689 
9690     eventHub->ClearJSFrameNodeOnScrollDidScroll();
9691 }
9692 
SetJSFrameNodeOnGridScrollIndex(FrameNode * frameNode,ScrollIndexFunc && onScrollIndex)9693 void ViewAbstract::SetJSFrameNodeOnGridScrollIndex(FrameNode* frameNode, ScrollIndexFunc&& onScrollIndex)
9694 {
9695     CHECK_NULL_VOID(frameNode);
9696     auto eventHub = frameNode->GetOrCreateEventHub<GridEventHub>();
9697     CHECK_NULL_VOID(eventHub);
9698 
9699     eventHub->SetJSFrameNodeOnGridScrollIndex(std::move(onScrollIndex));
9700 }
9701 
ClearJSFrameNodeOnGridScrollIndex(FrameNode * frameNode)9702 void ViewAbstract::ClearJSFrameNodeOnGridScrollIndex(FrameNode* frameNode)
9703 {
9704     CHECK_NULL_VOID(frameNode);
9705     auto eventHub = frameNode->GetOrCreateEventHub<GridEventHub>();
9706     CHECK_NULL_VOID(eventHub);
9707 
9708     eventHub->ClearJSFrameNodeOnGridScrollIndex();
9709 }
9710 
SetJSFrameNodeOnWaterFlowScrollIndex(FrameNode * frameNode,ScrollIndexFunc && onScrollIndex)9711 void ViewAbstract::SetJSFrameNodeOnWaterFlowScrollIndex(FrameNode* frameNode, ScrollIndexFunc&& onScrollIndex)
9712 {
9713     CHECK_NULL_VOID(frameNode);
9714     auto eventHub = frameNode->GetOrCreateEventHub<WaterFlowEventHub>();
9715     CHECK_NULL_VOID(eventHub);
9716 
9717     eventHub->SetJSFrameNodeOnWaterFlowScrollIndex(std::move(onScrollIndex));
9718 }
9719 
ClearJSFrameNodeOnWaterFlowScrollIndex(FrameNode * frameNode)9720 void ViewAbstract::ClearJSFrameNodeOnWaterFlowScrollIndex(FrameNode* frameNode)
9721 {
9722     CHECK_NULL_VOID(frameNode);
9723     auto eventHub = frameNode->GetOrCreateEventHub<WaterFlowEventHub>();
9724     CHECK_NULL_VOID(eventHub);
9725 
9726     eventHub->ClearJSFrameNodeOnWaterFlowScrollIndex();
9727 }
9728 
ResetResObj(FrameNode * frameNode,const std::string & key)9729 void ViewAbstract::ResetResObj(FrameNode* frameNode, const std::string& key)
9730 {
9731     if (!SystemProperties::ConfigChangePerform()) {
9732         return;
9733     }
9734     CHECK_NULL_VOID(frameNode);
9735     auto pattern = frameNode->GetPattern<Pattern>();
9736     CHECK_NULL_VOID(pattern);
9737     pattern->RemoveResObj(key);
9738 }
9739 
CreatePropertyAnimation(FrameNode * frameNode,AnimationPropertyType property,const std::vector<float> & startValue,const std::vector<float> & endValue,const AnimationOption & option)9740 bool ViewAbstract::CreatePropertyAnimation(FrameNode* frameNode, AnimationPropertyType property,
9741     const std::vector<float>& startValue, const std::vector<float>& endValue, const AnimationOption& option)
9742 {
9743     CHECK_NULL_RETURN(frameNode, false);
9744     auto renderContext = frameNode->GetRenderContext();
9745     CHECK_NULL_RETURN(renderContext, false);
9746     if (startValue.size()) {
9747         AnimationUtils::ExecuteWithoutAnimation([renderContext, property, &startValue]() {
9748             renderContext->SetAnimationPropertyValue(property, startValue);
9749         });
9750     }
9751     std::shared_ptr<bool> hasAnimation;
9752     std::function<void()> finishCallback;
9753     if (option.GetOnFinishEvent()) {
9754         hasAnimation = std::make_shared<bool>(true);
9755         finishCallback = [finish = option.GetOnFinishEvent(), hasAnimation]() {
9756             // wrap animation callback, if no animation is generated, skip frontend finish callback.
9757             if (*hasAnimation) {
9758                 finish();
9759             }
9760         };
9761     }
9762     AnimationUtils::OpenImplicitAnimation(option, option.GetCurve(), finishCallback);
9763     renderContext->SetAnimationPropertyValue(property, endValue);
9764     auto result = AnimationUtils::CloseImplicitAnimation();
9765     renderContext->SyncRSPropertyToRenderContext(property);
9766     if (!result) {
9767         if (hasAnimation) {
9768             *hasAnimation = false;
9769         }
9770         TAG_LOGI(AceLogTag::ACE_ANIMATION,
9771             "no animation generated because the value is same or first set, property:%{public}d",
9772             static_cast<int32_t>(property));
9773     }
9774     auto pipeline = frameNode->GetContextWithCheck();
9775     if (pipeline) {
9776         pipeline->RequestFrame();
9777     }
9778     return result;
9779 }
9780 
CancelPropertyAnimations(FrameNode * frameNode,const std::vector<AnimationPropertyType> & properties)9781 bool ViewAbstract::CancelPropertyAnimations(
9782     FrameNode* frameNode, const std::vector<AnimationPropertyType>& properties)
9783 {
9784     CHECK_NULL_RETURN(frameNode, false);
9785     auto renderContext = frameNode->GetRenderContext();
9786     CHECK_NULL_RETURN(renderContext, false);
9787     if (properties.empty()) {
9788         // no need to cancel
9789         return true;
9790     }
9791     auto propertyStr = PropertyVectorToString(properties);
9792     ACE_SCOPED_TRACE("CancelPropertyAnimations %s", propertyStr.c_str());
9793     // use duration 0 animation param to cancel animation.
9794     AnimationOption option { Curves::LINEAR, 0 };
9795     AnimationUtils::OpenImplicitAnimation(option, option.GetCurve(), nullptr);
9796     for (auto property : properties) {
9797         renderContext->CancelPropertyAnimation(property);
9798     }
9799     auto status = AnimationUtils::CloseImplicitCancelAnimationReturnStatus();
9800     if (status == CancelAnimationStatus::SUCCESS) {
9801         // restore the rs property to property saved in renderContext.
9802         for (auto property : properties) {
9803             renderContext->SyncRSPropertyToRenderContext(property);
9804         }
9805         return true;
9806     } else if (status == CancelAnimationStatus::EMPTY_PENDING_SYNC_LIST) {
9807         return true;
9808     }
9809     TAG_LOGW(AceLogTag::ACE_ANIMATION,
9810         "cancel animation error, property:%{public}s, node tag:%{public}s, error:%{public}d", propertyStr.c_str(),
9811         frameNode->GetTag().c_str(), static_cast<int32_t>(status));
9812     return false;
9813 }
9814 
GetRenderNodePropertyValue(FrameNode * frameNode,AnimationPropertyType property)9815 std::vector<float> ViewAbstract::GetRenderNodePropertyValue(FrameNode* frameNode, AnimationPropertyType property)
9816 {
9817     CHECK_NULL_RETURN(frameNode, {});
9818     auto renderContext = frameNode->GetRenderContext();
9819     CHECK_NULL_RETURN(renderContext, {});
9820     return renderContext->GetRenderNodePropertyValue(property);
9821 }
9822 
ResetResObj(const std::string & key)9823 void ViewAbstract::ResetResObj(const std::string& key)
9824 {
9825     if (!SystemProperties::ConfigChangePerform()) {
9826         return;
9827     }
9828     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
9829     CHECK_NULL_VOID(frameNode);
9830     auto pattern = frameNode->GetPattern<Pattern>();
9831     CHECK_NULL_VOID(pattern);
9832     pattern->RemoveResObj(key);
9833 }
9834 } // namespace OHOS::Ace::NG
9835