• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 
18 #include <cstdint>
19 #include <optional>
20 #include <utility>
21 
22 #include "base/geometry/dimension.h"
23 #include "base/geometry/ng/offset_t.h"
24 #include "base/memory/ace_type.h"
25 #include "base/utils/system_properties.h"
26 #include "base/utils/utils.h"
27 #include "core/common/container.h"
28 #include "core/components_ng/base/frame_node.h"
29 #include "core/components_ng/base/view_stack_processor.h"
30 #include "core/components_ng/layout/layout_property.h"
31 #include "core/components_ng/pattern/bubble/bubble_pattern.h"
32 #include "core/components_ng/pattern/bubble/bubble_view.h"
33 #include "core/components_ng/pattern/menu/menu_pattern.h"
34 #include "core/components_ng/pattern/menu/menu_view.h"
35 #include "core/components_ng/pattern/option/option_paint_property.h"
36 #include "core/components_ng/pattern/text/span_node.h"
37 #include "core/components_ng/property/calc_length.h"
38 #include "core/components_ng/property/safe_area_insets.h"
39 #include "core/image/image_source_info.h"
40 #include "core/pipeline_ng/pipeline_context.h"
41 #include "core/pipeline_ng/ui_task_scheduler.h"
42 
43 namespace OHOS::Ace::NG {
44 
45 namespace {
46 
47 // common function to bind menu
BindMenu(const RefPtr<FrameNode> & menuNode,int32_t targetId,const NG::OffsetF & offset)48 void BindMenu(const RefPtr<FrameNode>& menuNode, int32_t targetId, const NG::OffsetF& offset)
49 {
50     LOGD("ViewAbstract::BindMenu");
51     auto container = Container::Current();
52     CHECK_NULL_VOID(container);
53     auto pipelineContext = container->GetPipelineContext();
54     CHECK_NULL_VOID(pipelineContext);
55     auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
56     CHECK_NULL_VOID(context);
57     auto overlayManager = context->GetOverlayManager();
58     CHECK_NULL_VOID(overlayManager);
59 
60     // pass in menuNode to register it in OverlayManager
61     overlayManager->ShowMenu(targetId, offset, menuNode);
62     LOGD("ViewAbstract BindMenu finished %{public}d", menuNode->GetId());
63 }
64 } // namespace
65 
SetWidth(const CalcLength & width)66 void ViewAbstract::SetWidth(const CalcLength& width)
67 {
68     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
69         LOGD("current state is not processed, return");
70         return;
71     }
72     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
73     CHECK_NULL_VOID(frameNode);
74     auto layoutProperty = frameNode->GetLayoutProperty();
75     CHECK_NULL_VOID(layoutProperty);
76     // get previously user defined ideal height
77     std::optional<CalcLength> height = std::nullopt;
78     auto&& layoutConstraint = layoutProperty->GetCalcLayoutConstraint();
79     if (layoutConstraint && layoutConstraint->selfIdealSize) {
80         height = layoutConstraint->selfIdealSize->Height();
81     }
82     layoutProperty->UpdateUserDefinedIdealSize(CalcSize(width, height));
83 }
84 
SetHeight(const CalcLength & height)85 void ViewAbstract::SetHeight(const CalcLength& height)
86 {
87     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
88         LOGD("current state is not processed, return");
89         return;
90     }
91     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
92     CHECK_NULL_VOID(frameNode);
93     auto layoutProperty = frameNode->GetLayoutProperty();
94     CHECK_NULL_VOID(layoutProperty);
95     // get previously user defined ideal width
96     std::optional<CalcLength> width = std::nullopt;
97     auto&& layoutConstraint = layoutProperty->GetCalcLayoutConstraint();
98     if (layoutConstraint && layoutConstraint->selfIdealSize) {
99         width = layoutConstraint->selfIdealSize->Width();
100     }
101     layoutProperty->UpdateUserDefinedIdealSize(CalcSize(width, height));
102 }
103 
SetClickEffectLevel(const ClickEffectLevel & level,float scaleValue)104 void ViewAbstract::SetClickEffectLevel(const ClickEffectLevel& level, float scaleValue)
105 {
106     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
107         LOGD("current state is not processed, return");
108         return;
109     }
110     ClickEffectInfo clickEffectInfo;
111     clickEffectInfo.level = level;
112     clickEffectInfo.scaleNumber = scaleValue;
113     ACE_UPDATE_RENDER_CONTEXT(ClickEffectLevel, clickEffectInfo);
114 }
115 
ClearWidthOrHeight(bool isWidth)116 void ViewAbstract::ClearWidthOrHeight(bool isWidth)
117 {
118     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
119         LOGD("current state is not processed, return");
120         return;
121     }
122     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
123     CHECK_NULL_VOID(frameNode);
124     auto layoutProperty = frameNode->GetLayoutProperty();
125     CHECK_NULL_VOID(layoutProperty);
126     layoutProperty->ClearUserDefinedIdealSize(isWidth, !isWidth);
127 }
128 
SetMinWidth(const CalcLength & width)129 void ViewAbstract::SetMinWidth(const CalcLength& width)
130 {
131     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
132         LOGD("current state is not processed, return");
133         return;
134     }
135     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
136     CHECK_NULL_VOID(frameNode);
137     auto layoutProperty = frameNode->GetLayoutProperty();
138     CHECK_NULL_VOID(layoutProperty);
139     layoutProperty->UpdateCalcMinSize(CalcSize(width, std::nullopt));
140 }
141 
SetMinHeight(const CalcLength & height)142 void ViewAbstract::SetMinHeight(const CalcLength& height)
143 {
144     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
145         LOGD("current state is not processed, return");
146         return;
147     }
148     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
149     CHECK_NULL_VOID(frameNode);
150     auto layoutProperty = frameNode->GetLayoutProperty();
151     CHECK_NULL_VOID(layoutProperty);
152     layoutProperty->UpdateCalcMinSize(CalcSize(std::nullopt, height));
153 }
154 
ResetMinSize(bool resetWidth)155 void ViewAbstract::ResetMinSize(bool resetWidth)
156 {
157     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
158         LOGD("current state is not processed, return");
159         return;
160     }
161     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
162     CHECK_NULL_VOID(frameNode);
163     auto layoutProperty = frameNode->GetLayoutProperty();
164     CHECK_NULL_VOID(layoutProperty);
165     layoutProperty->ResetCalcMinSize(resetWidth);
166 }
167 
SetMaxWidth(const CalcLength & width)168 void ViewAbstract::SetMaxWidth(const CalcLength& width)
169 {
170     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
171         LOGD("current state is not processed, return");
172         return;
173     }
174     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
175     CHECK_NULL_VOID(frameNode);
176     auto layoutProperty = frameNode->GetLayoutProperty();
177     CHECK_NULL_VOID(layoutProperty);
178     layoutProperty->UpdateCalcMaxSize(CalcSize(width, std::nullopt));
179 }
180 
SetMaxHeight(const CalcLength & height)181 void ViewAbstract::SetMaxHeight(const CalcLength& height)
182 {
183     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
184         LOGD("current state is not processed, return");
185         return;
186     }
187     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
188     CHECK_NULL_VOID(frameNode);
189     auto layoutProperty = frameNode->GetLayoutProperty();
190     CHECK_NULL_VOID(layoutProperty);
191     layoutProperty->UpdateCalcMaxSize(CalcSize(std::nullopt, height));
192 }
193 
ResetMaxSize(bool resetWidth)194 void ViewAbstract::ResetMaxSize(bool resetWidth)
195 {
196     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
197         LOGD("current state is not processed, return");
198         return;
199     }
200     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
201     CHECK_NULL_VOID(frameNode);
202     auto layoutProperty = frameNode->GetLayoutProperty();
203     CHECK_NULL_VOID(layoutProperty);
204     layoutProperty->ResetCalcMaxSize(resetWidth);
205 }
206 
SetAspectRatio(float ratio)207 void ViewAbstract::SetAspectRatio(float ratio)
208 {
209     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
210         LOGD("current state is not processed, return");
211         return;
212     }
213     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, AspectRatio, ratio);
214 }
215 
ResetAspectRatio()216 void ViewAbstract::ResetAspectRatio()
217 {
218     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
219         LOGD("current state is not processed, return");
220         return;
221     }
222     ACE_RESET_LAYOUT_PROPERTY(LayoutProperty, AspectRatio);
223 }
224 
SetBackgroundAlign(const Alignment & align)225 void ViewAbstract::SetBackgroundAlign(const Alignment& align)
226 {
227     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
228         LOGD("current state is not processed, return");
229         return;
230     }
231     ACE_UPDATE_RENDER_CONTEXT(BackgroundAlign, align);
232 }
233 
SetBackgroundColor(const Color & color)234 void ViewAbstract::SetBackgroundColor(const Color& color)
235 {
236     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
237         LOGD("current state is not processed, return");
238         return;
239     }
240     ACE_UPDATE_RENDER_CONTEXT(BackgroundColor, color);
241 }
242 
SetBackgroundImage(const ImageSourceInfo & src)243 void ViewAbstract::SetBackgroundImage(const ImageSourceInfo& src)
244 {
245     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
246         LOGD("current state is not processed, return");
247         return;
248     }
249     ACE_UPDATE_RENDER_CONTEXT(BackgroundImage, src);
250 }
251 
SetBackgroundImageRepeat(const ImageRepeat & imageRepeat)252 void ViewAbstract::SetBackgroundImageRepeat(const ImageRepeat& imageRepeat)
253 {
254     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
255         LOGD("current state is not processed, return");
256         return;
257     }
258     ACE_UPDATE_RENDER_CONTEXT(BackgroundImageRepeat, imageRepeat);
259 }
260 
SetBackgroundImageSize(const BackgroundImageSize & bgImgSize)261 void ViewAbstract::SetBackgroundImageSize(const BackgroundImageSize& bgImgSize)
262 {
263     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
264         LOGD("current state is not processed, return");
265         return;
266     }
267     ACE_UPDATE_RENDER_CONTEXT(BackgroundImageSize, bgImgSize);
268 }
269 
SetBackgroundImagePosition(const BackgroundImagePosition & bgImgPosition)270 void ViewAbstract::SetBackgroundImagePosition(const BackgroundImagePosition& bgImgPosition)
271 {
272     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
273         LOGD("current state is not processed, return");
274         return;
275     }
276     ACE_UPDATE_RENDER_CONTEXT(BackgroundImagePosition, bgImgPosition);
277 }
278 
SetBackgroundBlurStyle(const BlurStyleOption & bgBlurStyle)279 void ViewAbstract::SetBackgroundBlurStyle(const BlurStyleOption& bgBlurStyle)
280 {
281     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
282         LOGD("current state is not processed, return");
283         return;
284     }
285     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
286     CHECK_NULL_VOID(frameNode);
287     auto target = frameNode->GetRenderContext();
288     if (target) {
289         if (target->GetBackgroundEffect().has_value()) {
290             target->UpdateBackgroundEffect(std::nullopt);
291         }
292         target->UpdateBackBlurStyle(bgBlurStyle);
293         if (target->GetBackBlurRadius().has_value()) {
294             target->UpdateBackBlurRadius(Dimension());
295         }
296     }
297 }
298 
SetBackgroundEffect(const EffectOption & effectOption)299 void ViewAbstract::SetBackgroundEffect(const EffectOption& effectOption)
300 {
301     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
302         LOGD("current state is not processed, return");
303         return;
304     }
305     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
306     CHECK_NULL_VOID(frameNode);
307     auto target = frameNode->GetRenderContext();
308     if (target) {
309         if (target->GetBackBlurRadius().has_value()) {
310             target->UpdateBackBlurRadius(Dimension());
311         }
312         if (target->GetBackBlurStyle().has_value()) {
313             target->UpdateBackBlurStyle(std::nullopt);
314         }
315         target->UpdateBackgroundEffect(effectOption);
316     }
317 }
318 
SetForegroundBlurStyle(const BlurStyleOption & fgBlurStyle)319 void ViewAbstract::SetForegroundBlurStyle(const BlurStyleOption& fgBlurStyle)
320 {
321     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
322         LOGD("current state is not processed, return");
323         return;
324     }
325     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
326     CHECK_NULL_VOID(frameNode);
327     auto target = frameNode->GetRenderContext();
328     if (target) {
329         target->UpdateFrontBlurStyle(fgBlurStyle);
330         if (target->GetFrontBlurRadius().has_value()) {
331             target->UpdateFrontBlurRadius(Dimension());
332         }
333     }
334 }
335 
SetSphericalEffect(double radio)336 void ViewAbstract::SetSphericalEffect(double radio)
337 {
338     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
339         LOGD("current state is not processed, return");
340         return;
341     }
342     ACE_UPDATE_RENDER_CONTEXT(SphericalEffect, radio);
343 }
344 
SetPixelStretchEffect(PixStretchEffectOption & option)345 void ViewAbstract::SetPixelStretchEffect(PixStretchEffectOption& option)
346 {
347     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
348         LOGD("current state is not processed, return");
349         return;
350     }
351     ACE_UPDATE_RENDER_CONTEXT(PixelStretchEffect, option);
352 }
353 
SetLightUpEffect(double radio)354 void ViewAbstract::SetLightUpEffect(double radio)
355 {
356     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
357         LOGD("current state is not processed, return");
358         return;
359     }
360     ACE_UPDATE_RENDER_CONTEXT(LightUpEffect, radio);
361 }
362 
SetLayoutWeight(int32_t value)363 void ViewAbstract::SetLayoutWeight(int32_t value)
364 {
365     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
366         LOGD("current state is not processed, return");
367         return;
368     }
369     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, LayoutWeight, static_cast<float>(value));
370 }
371 
SetLayoutDirection(TextDirection value)372 void ViewAbstract::SetLayoutDirection(TextDirection value)
373 {
374     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
375         LOGD("current state is not processed, return");
376         return;
377     }
378     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, LayoutDirection, value);
379 }
380 
SetAlignRules(const std::map<AlignDirection,AlignRule> & alignRules)381 void ViewAbstract::SetAlignRules(const std::map<AlignDirection, AlignRule>& alignRules)
382 {
383     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
384         LOGD("current state is not processed, return");
385         return;
386     }
387     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, AlignRules, alignRules);
388 }
389 
SetAlignSelf(FlexAlign value)390 void ViewAbstract::SetAlignSelf(FlexAlign value)
391 {
392     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
393         LOGD("current state is not processed, return");
394         return;
395     }
396     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, AlignSelf, value);
397 }
398 
SetFlexShrink(float value)399 void ViewAbstract::SetFlexShrink(float value)
400 {
401     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
402         LOGD("current state is not processed, return");
403         return;
404     }
405     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, FlexShrink, value);
406 }
407 
ResetFlexShrink()408 void ViewAbstract::ResetFlexShrink()
409 {
410     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
411         LOGD("current state is not processed, return");
412         return;
413     }
414     ACE_RESET_LAYOUT_PROPERTY(LayoutProperty, FlexShrink);
415 }
416 
SetFlexGrow(float value)417 void ViewAbstract::SetFlexGrow(float value)
418 {
419     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
420         LOGD("current state is not processed, return");
421         return;
422     }
423     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, FlexGrow, value);
424 }
425 
SetFlexBasis(const Dimension & value)426 void ViewAbstract::SetFlexBasis(const Dimension& value)
427 {
428     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
429         LOGD("current state is not processed, return");
430         return;
431     }
432     if (LessNotEqual(value.Value(), 0.0f)) {
433         ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, FlexBasis, Dimension());
434         return;
435     }
436     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, FlexBasis, value);
437 }
438 
SetDisplayIndex(int32_t value)439 void ViewAbstract::SetDisplayIndex(int32_t value)
440 {
441     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
442         LOGD("current state is not processed, return");
443         return;
444     }
445     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, DisplayIndex, value);
446 }
447 
SetPadding(const CalcLength & value)448 void ViewAbstract::SetPadding(const CalcLength& value)
449 {
450     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
451         LOGD("current state is not processed, return");
452         return;
453     }
454     PaddingProperty padding;
455     padding.SetEdges(value);
456     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Padding, padding);
457 }
458 
SetPadding(const PaddingProperty & value)459 void ViewAbstract::SetPadding(const PaddingProperty& value)
460 {
461     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
462         LOGD("current state is not processed, return");
463         return;
464     }
465     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Padding, value);
466 }
467 
SetMargin(const CalcLength & value)468 void ViewAbstract::SetMargin(const CalcLength& value)
469 {
470     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
471         LOGD("current state is not processed, return");
472         return;
473     }
474     MarginProperty margin;
475     margin.SetEdges(value);
476     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Margin, margin);
477 }
478 
SetMargin(const MarginProperty & value)479 void ViewAbstract::SetMargin(const MarginProperty& value)
480 {
481     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
482         LOGD("current state is not processed, return");
483         return;
484     }
485     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Margin, value);
486 }
487 
SetBorderRadius(const Dimension & value)488 void ViewAbstract::SetBorderRadius(const Dimension& value)
489 {
490     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
491         LOGD("current state is not processed, return");
492         return;
493     }
494     BorderRadiusProperty borderRadius;
495     borderRadius.SetRadius(value);
496     borderRadius.multiValued = false;
497     ACE_UPDATE_RENDER_CONTEXT(BorderRadius, borderRadius);
498 }
499 
SetBorderRadius(const BorderRadiusProperty & value)500 void ViewAbstract::SetBorderRadius(const BorderRadiusProperty& value)
501 {
502     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
503         LOGD("current state is not processed, return");
504         return;
505     }
506     ACE_UPDATE_RENDER_CONTEXT(BorderRadius, value);
507 }
508 
SetBorderColor(const Color & value)509 void ViewAbstract::SetBorderColor(const Color& value)
510 {
511     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
512         LOGD("current state is not processed, return");
513         return;
514     }
515     BorderColorProperty borderColor;
516     borderColor.SetColor(value);
517     ACE_UPDATE_RENDER_CONTEXT(BorderColor, borderColor);
518 }
519 
SetBorderColor(const BorderColorProperty & value)520 void ViewAbstract::SetBorderColor(const BorderColorProperty& value)
521 {
522     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
523         LOGD("current state is not processed, return");
524         return;
525     }
526     ACE_UPDATE_RENDER_CONTEXT(BorderColor, value);
527 }
528 
SetBorderWidth(const Dimension & value)529 void ViewAbstract::SetBorderWidth(const Dimension& value)
530 {
531     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
532         LOGD("current state is not processed, return");
533         return;
534     }
535     BorderWidthProperty borderWidth;
536     if (Negative(value.Value())) {
537         borderWidth.SetBorderWidth(Dimension(0));
538         LOGW("border width is negative, reset to 0");
539     } else {
540         borderWidth.SetBorderWidth(value);
541     }
542     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, BorderWidth, borderWidth);
543     ACE_UPDATE_RENDER_CONTEXT(BorderWidth, borderWidth);
544 }
545 
SetBorderWidth(const BorderWidthProperty & value)546 void ViewAbstract::SetBorderWidth(const BorderWidthProperty& value)
547 {
548     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
549         LOGD("current state is not processed, return");
550         return;
551     }
552     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, BorderWidth, value);
553     ACE_UPDATE_RENDER_CONTEXT(BorderWidth, value);
554 }
555 
SetBorderStyle(const BorderStyle & value)556 void ViewAbstract::SetBorderStyle(const BorderStyle& value)
557 {
558     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
559         LOGD("current state is not processed, return");
560         return;
561     }
562     BorderStyleProperty borderStyle;
563     borderStyle.SetBorderStyle(value);
564     ACE_UPDATE_RENDER_CONTEXT(BorderStyle, borderStyle);
565 }
566 
SetBorderStyle(const BorderStyleProperty & value)567 void ViewAbstract::SetBorderStyle(const BorderStyleProperty& value)
568 {
569     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
570         LOGD("current state is not processed, return");
571         return;
572     }
573     ACE_UPDATE_RENDER_CONTEXT(BorderStyle, value);
574 }
575 
DisableOnClick()576 void ViewAbstract::DisableOnClick()
577 {
578     LOGD("Disable OnClick event");
579     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
580     CHECK_NULL_VOID(gestureHub);
581     gestureHub->ClearUserOnClick();
582 }
583 
DisableOnTouch()584 void ViewAbstract::DisableOnTouch()
585 {
586     LOGD("Disable OnTouch event");
587     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
588     CHECK_NULL_VOID(gestureHub);
589     gestureHub->ClearUserOnTouch();
590 }
591 
DisableOnKeyEvent()592 void ViewAbstract::DisableOnKeyEvent()
593 {
594     LOGD("Disable OnKey event");
595     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
596     CHECK_NULL_VOID(focusHub);
597     focusHub->ClearUserOnKey();
598 }
599 
DisableOnHover()600 void ViewAbstract::DisableOnHover()
601 {
602     LOGD("Disable OnHover event");
603     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
604     CHECK_NULL_VOID(eventHub);
605     eventHub->ClearUserOnHover();
606 }
607 
DisableOnMouse()608 void ViewAbstract::DisableOnMouse()
609 {
610     LOGD("Disable OnMouse event");
611     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
612     CHECK_NULL_VOID(eventHub);
613     eventHub->ClearUserOnMouse();
614 }
615 
DisableOnAppear()616 void ViewAbstract::DisableOnAppear()
617 {
618     LOGD("Disable OnAppear event");
619     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
620     CHECK_NULL_VOID(eventHub);
621     eventHub->ClearUserOnAppear();
622 }
623 
DisableOnDisAppear()624 void ViewAbstract::DisableOnDisAppear()
625 {
626     LOGD("Disable OnDisAppear event");
627     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
628     CHECK_NULL_VOID(eventHub);
629     eventHub->ClearUserOnDisAppear();
630 }
631 
DisableOnAreaChange()632 void ViewAbstract::DisableOnAreaChange()
633 {
634     LOGD("Disable OnAreaChange event");
635     auto pipeline = PipelineContext::GetCurrentContext();
636     CHECK_NULL_VOID(pipeline);
637     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
638     CHECK_NULL_VOID(frameNode);
639     frameNode->ClearUserOnAreaChange();
640 }
641 
DisableOnFocus()642 void ViewAbstract::DisableOnFocus()
643 {
644     LOGD("Disable OnFocus event");
645     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
646     CHECK_NULL_VOID(focusHub);
647     focusHub->ClearUserOnFocus();
648 }
649 
DisableOnBlur()650 void ViewAbstract::DisableOnBlur()
651 {
652     LOGD("Disable OnBlur event");
653     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
654     CHECK_NULL_VOID(focusHub);
655     focusHub->ClearUserOnBlur();
656 }
657 
SetOnClick(GestureEventFunc && clickEventFunc)658 void ViewAbstract::SetOnClick(GestureEventFunc&& clickEventFunc)
659 {
660     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
661     CHECK_NULL_VOID(gestureHub);
662     gestureHub->SetUserOnClick(std::move(clickEventFunc));
663 }
664 
SetOnTouch(TouchEventFunc && touchEventFunc)665 void ViewAbstract::SetOnTouch(TouchEventFunc&& touchEventFunc)
666 {
667     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
668     CHECK_NULL_VOID(gestureHub);
669     gestureHub->SetTouchEvent(std::move(touchEventFunc));
670 }
671 
SetOnMouse(OnMouseEventFunc && onMouseEventFunc)672 void ViewAbstract::SetOnMouse(OnMouseEventFunc&& onMouseEventFunc)
673 {
674     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
675     CHECK_NULL_VOID(eventHub);
676     eventHub->SetMouseEvent(std::move(onMouseEventFunc));
677 }
678 
SetOnHover(OnHoverFunc && onHoverEventFunc)679 void ViewAbstract::SetOnHover(OnHoverFunc&& onHoverEventFunc)
680 {
681     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
682     CHECK_NULL_VOID(eventHub);
683     eventHub->SetHoverEvent(std::move(onHoverEventFunc));
684 }
685 
SetHoverEffect(HoverEffectType hoverEffect)686 void ViewAbstract::SetHoverEffect(HoverEffectType hoverEffect)
687 {
688     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
689     CHECK_NULL_VOID(eventHub);
690     eventHub->SetHoverEffect(hoverEffect);
691 }
692 
SetHoverEffectAuto(HoverEffectType hoverEffect)693 void ViewAbstract::SetHoverEffectAuto(HoverEffectType hoverEffect)
694 {
695     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
696     CHECK_NULL_VOID(eventHub);
697     eventHub->SetHoverEffectAuto(hoverEffect);
698 }
699 
SetEnabled(bool enabled)700 void ViewAbstract::SetEnabled(bool enabled)
701 {
702     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
703     if (eventHub) {
704         eventHub->SetEnabled(enabled);
705     }
706 
707     // The SetEnabled of focusHub must be after at eventHub
708     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
709     if (focusHub) {
710         focusHub->SetEnabled(enabled);
711     }
712 }
713 
SetFocusable(bool focusable)714 void ViewAbstract::SetFocusable(bool focusable)
715 {
716     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
717     CHECK_NULL_VOID(focusHub);
718     focusHub->SetFocusable(focusable);
719 }
720 
SetOnFocus(OnFocusFunc && onFocusCallback)721 void ViewAbstract::SetOnFocus(OnFocusFunc&& onFocusCallback)
722 {
723     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
724     CHECK_NULL_VOID(focusHub);
725     focusHub->SetOnFocusCallback(std::move(onFocusCallback));
726 }
727 
SetOnBlur(OnBlurFunc && onBlurCallback)728 void ViewAbstract::SetOnBlur(OnBlurFunc&& onBlurCallback)
729 {
730     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
731     CHECK_NULL_VOID(focusHub);
732     focusHub->SetOnBlurCallback(std::move(onBlurCallback));
733 }
734 
SetOnKeyEvent(OnKeyCallbackFunc && onKeyCallback)735 void ViewAbstract::SetOnKeyEvent(OnKeyCallbackFunc&& onKeyCallback)
736 {
737     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
738     CHECK_NULL_VOID(focusHub);
739     focusHub->SetOnKeyCallback(std::move(onKeyCallback));
740 }
741 
SetTabIndex(int32_t index)742 void ViewAbstract::SetTabIndex(int32_t index)
743 {
744     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
745     CHECK_NULL_VOID(focusHub);
746     focusHub->SetTabIndex(index);
747 }
748 
SetFocusOnTouch(bool isSet)749 void ViewAbstract::SetFocusOnTouch(bool isSet)
750 {
751     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
752     CHECK_NULL_VOID(focusHub);
753     focusHub->SetIsFocusOnTouch(isSet);
754 }
755 
SetDefaultFocus(bool isSet)756 void ViewAbstract::SetDefaultFocus(bool isSet)
757 {
758     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
759     CHECK_NULL_VOID(focusHub);
760     focusHub->SetIsDefaultFocus(isSet);
761 }
762 
SetGroupDefaultFocus(bool isSet)763 void ViewAbstract::SetGroupDefaultFocus(bool isSet)
764 {
765     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
766     CHECK_NULL_VOID(focusHub);
767     focusHub->SetIsDefaultGroupFocus(isSet);
768 }
769 
SetOnAppear(std::function<void ()> && onAppear)770 void ViewAbstract::SetOnAppear(std::function<void()>&& onAppear)
771 {
772     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
773     CHECK_NULL_VOID(eventHub);
774     eventHub->SetOnAppear(std::move(onAppear));
775 }
776 
SetOnDisappear(std::function<void ()> && onDisappear)777 void ViewAbstract::SetOnDisappear(std::function<void()>&& onDisappear)
778 {
779     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
780     CHECK_NULL_VOID(eventHub);
781     eventHub->SetOnDisappear(std::move(onDisappear));
782 }
783 
SetOnAreaChanged(std::function<void (const RectF & oldRect,const OffsetF & oldOrigin,const RectF & rect,const OffsetF & origin)> && onAreaChanged)784 void ViewAbstract::SetOnAreaChanged(
785     std::function<void(const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect, const OffsetF& origin)>&&
786         onAreaChanged)
787 {
788     auto pipeline = PipelineContext::GetCurrentContext();
789     CHECK_NULL_VOID(pipeline);
790     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
791     CHECK_NULL_VOID(frameNode);
792     frameNode->SetOnAreaChangeCallback(std::move(onAreaChanged));
793     pipeline->AddOnAreaChangeNode(frameNode->GetId());
794 }
795 
SetOnVisibleChange(std::function<void (bool,double)> && onVisibleChange,const std::vector<double> & ratioList)796 void ViewAbstract::SetOnVisibleChange(
797     std::function<void(bool, double)>&& onVisibleChange, const std::vector<double>& ratioList)
798 {
799     auto pipeline = PipelineContext::GetCurrentContext();
800     CHECK_NULL_VOID(pipeline);
801     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
802     CHECK_NULL_VOID(frameNode);
803     frameNode->ClearVisibleAreaUserCallback();
804 
805     for (const auto& ratio : ratioList) {
806         pipeline->AddVisibleAreaChangeNode(frameNode, ratio, onVisibleChange);
807     }
808 }
809 
SetResponseRegion(const std::vector<DimensionRect> & responseRegion)810 void ViewAbstract::SetResponseRegion(const std::vector<DimensionRect>& responseRegion)
811 {
812     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
813     CHECK_NULL_VOID(gestureHub);
814     gestureHub->MarkResponseRegion(true);
815     gestureHub->SetResponseRegion(responseRegion);
816 }
817 
SetMouseResponseRegion(const std::vector<DimensionRect> & mouseRegion)818 void ViewAbstract::SetMouseResponseRegion(const std::vector<DimensionRect>& mouseRegion)
819 {
820     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
821     CHECK_NULL_VOID(gestureHub);
822     gestureHub->MarkResponseRegion(true);
823     gestureHub->SetMouseResponseRegion(mouseRegion);
824 }
825 
SetTouchable(bool touchable)826 void ViewAbstract::SetTouchable(bool touchable)
827 {
828     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
829     CHECK_NULL_VOID(gestureHub);
830     gestureHub->SetTouchable(touchable);
831 }
832 
SetHitTestMode(HitTestMode hitTestMode)833 void ViewAbstract::SetHitTestMode(HitTestMode hitTestMode)
834 {
835     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
836     CHECK_NULL_VOID(gestureHub);
837     gestureHub->SetHitTestMode(hitTestMode);
838 }
839 
AddDragFrameNodeToManager()840 void ViewAbstract::AddDragFrameNodeToManager()
841 {
842     auto pipeline = PipelineContext::GetCurrentContext();
843     CHECK_NULL_VOID(pipeline);
844     auto dragDropManager = pipeline->GetDragDropManager();
845     CHECK_NULL_VOID(dragDropManager);
846     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
847     CHECK_NULL_VOID(frameNode);
848 
849     dragDropManager->AddDragFrameNode(frameNode->GetId(), AceType::WeakClaim(AceType::RawPtr(frameNode)));
850 }
851 
SetDraggable(bool draggable)852 void ViewAbstract::SetDraggable(bool draggable)
853 {
854     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
855     CHECK_NULL_VOID(frameNode);
856     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
857     CHECK_NULL_VOID(gestureHub);
858     if (draggable) {
859         if (!frameNode->IsDraggable()) {
860             gestureHub->InitDragDropEvent();
861         }
862     } else {
863         gestureHub->RemoveDragEvent();
864     }
865     frameNode->SetDraggable(draggable);
866 }
867 
SetOnDragStart(std::function<DragDropInfo (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragStart)868 void ViewAbstract::SetOnDragStart(
869     std::function<DragDropInfo(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragStart)
870 {
871     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
872     CHECK_NULL_VOID(gestureHub);
873     gestureHub->InitDragDropEvent();
874 
875     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
876     CHECK_NULL_VOID(eventHub);
877     eventHub->SetOnDragStart(std::move(onDragStart));
878 }
879 
SetOnDragEnter(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragEnter)880 void ViewAbstract::SetOnDragEnter(
881     std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragEnter)
882 {
883     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
884     CHECK_NULL_VOID(eventHub);
885     eventHub->SetOnDragEnter(std::move(onDragEnter));
886 
887     AddDragFrameNodeToManager();
888 }
889 
SetOnDragLeave(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragLeave)890 void ViewAbstract::SetOnDragLeave(
891     std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragLeave)
892 {
893     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
894     CHECK_NULL_VOID(eventHub);
895     eventHub->SetOnDragLeave(std::move(onDragLeave));
896 
897     AddDragFrameNodeToManager();
898 }
899 
SetOnDragMove(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragMove)900 void ViewAbstract::SetOnDragMove(
901     std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragMove)
902 {
903     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
904     CHECK_NULL_VOID(eventHub);
905     eventHub->SetOnDragMove(std::move(onDragMove));
906 
907     AddDragFrameNodeToManager();
908 }
909 
SetOnDrop(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDrop)910 void ViewAbstract::SetOnDrop(std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDrop)
911 {
912     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
913     CHECK_NULL_VOID(eventHub);
914     eventHub->SetOnDrop(std::move(onDrop));
915 
916     AddDragFrameNodeToManager();
917 }
918 
SetOnDragEnd(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &)> && onDragEnd)919 void ViewAbstract::SetOnDragEnd(std::function<void(const RefPtr<OHOS::Ace::DragEvent>&)>&& onDragEnd)
920 {
921     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
922     CHECK_NULL_VOID(eventHub);
923     eventHub->SetOnDragEnd(std::move(onDragEnd));
924 
925     AddDragFrameNodeToManager();
926 }
927 
SetAlign(Alignment alignment)928 void ViewAbstract::SetAlign(Alignment alignment)
929 {
930     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
931         LOGD("current state is not processed, return");
932         return;
933     }
934     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Alignment, alignment);
935 }
936 
SetVisibility(VisibleType visible)937 void ViewAbstract::SetVisibility(VisibleType visible)
938 {
939     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
940         LOGD("current state is not processed, return");
941         return;
942     }
943     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
944     CHECK_NULL_VOID(frameNode);
945     auto layoutProperty = frameNode->GetLayoutProperty();
946     if (layoutProperty) {
947         layoutProperty->UpdateVisibility(visible, true);
948     }
949 
950     auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
951     if (focusHub) {
952         focusHub->SetShow(visible == VisibleType::VISIBLE);
953     }
954 }
955 
SetGeometryTransition(const std::string & id,bool followWithoutTransition)956 void ViewAbstract::SetGeometryTransition(const std::string& id, bool followWithoutTransition)
957 {
958     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
959     CHECK_NULL_VOID(frameNode);
960     auto layoutProperty = frameNode->GetLayoutProperty();
961     if (layoutProperty) {
962         layoutProperty->UpdateGeometryTransition(id, followWithoutTransition);
963     }
964 }
965 
SetOpacity(double opacity)966 void ViewAbstract::SetOpacity(double opacity)
967 {
968     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
969         LOGD("current state is not processed, return");
970         return;
971     }
972     ACE_UPDATE_RENDER_CONTEXT(Opacity, opacity);
973 }
SetAllowDrop(const std::set<std::string> & allowDrop)974 void ViewAbstract::SetAllowDrop(const std::set<std::string>& allowDrop)
975 {
976     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
977     CHECK_NULL_VOID(frameNode);
978     frameNode->SetAllowDrop(allowDrop);
979 }
980 
SetPosition(const OffsetT<Dimension> & value)981 void ViewAbstract::SetPosition(const OffsetT<Dimension>& value)
982 {
983     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
984         LOGD("current state is not processed, return");
985         return;
986     }
987     ACE_UPDATE_RENDER_CONTEXT(Position, value);
988 }
989 
SetOffset(const OffsetT<Dimension> & value)990 void ViewAbstract::SetOffset(const OffsetT<Dimension>& value)
991 {
992     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
993         LOGD("current state is not processed, return");
994         return;
995     }
996     ACE_UPDATE_RENDER_CONTEXT(Offset, value);
997 }
998 
MarkAnchor(const OffsetT<Dimension> & value)999 void ViewAbstract::MarkAnchor(const OffsetT<Dimension>& value)
1000 {
1001     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1002         LOGD("current state is not processed, return");
1003         return;
1004     }
1005     ACE_UPDATE_RENDER_CONTEXT(Anchor, value);
1006 }
1007 
SetZIndex(int32_t value)1008 void ViewAbstract::SetZIndex(int32_t value)
1009 {
1010     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1011         LOGD("current state is not processed, return");
1012         return;
1013     }
1014     ACE_UPDATE_RENDER_CONTEXT(ZIndex, value);
1015 }
1016 
SetScale(const NG::VectorF & value)1017 void ViewAbstract::SetScale(const NG::VectorF& value)
1018 {
1019     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1020         LOGD("current state is not processed, return");
1021         return;
1022     }
1023     ACE_UPDATE_RENDER_CONTEXT(TransformScale, value);
1024 }
1025 
SetPivot(const DimensionOffset & value)1026 void ViewAbstract::SetPivot(const DimensionOffset& value)
1027 {
1028     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1029         LOGD("current state is not processed, return");
1030         return;
1031     }
1032     ACE_UPDATE_RENDER_CONTEXT(TransformCenter, value);
1033 }
1034 
SetTranslate(const NG::TranslateOptions & value)1035 void ViewAbstract::SetTranslate(const NG::TranslateOptions& value)
1036 {
1037     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1038         LOGD("current state is not processed, return");
1039         return;
1040     }
1041     ACE_UPDATE_RENDER_CONTEXT(TransformTranslate, value);
1042 }
1043 
SetRotate(const NG::Vector5F & value)1044 void ViewAbstract::SetRotate(const NG::Vector5F& value)
1045 {
1046     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1047         LOGD("current state is not processed, return");
1048         return;
1049     }
1050     ACE_UPDATE_RENDER_CONTEXT(TransformRotate, value);
1051 }
1052 
SetTransformMatrix(const Matrix4 & matrix)1053 void ViewAbstract::SetTransformMatrix(const Matrix4& matrix)
1054 {
1055     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1056         LOGD("current state is not processed, return");
1057         return;
1058     }
1059     ACE_UPDATE_RENDER_CONTEXT(TransformMatrix, matrix);
1060 }
1061 
BindPopup(const RefPtr<PopupParam> & param,const RefPtr<FrameNode> & targetNode,const RefPtr<UINode> & customNode)1062 void ViewAbstract::BindPopup(
1063     const RefPtr<PopupParam>& param, const RefPtr<FrameNode>& targetNode, const RefPtr<UINode>& customNode)
1064 {
1065     CHECK_NULL_VOID(targetNode);
1066     auto targetId = targetNode->GetId();
1067     auto targetTag = targetNode->GetTag();
1068     auto container = Container::Current();
1069     CHECK_NULL_VOID(container);
1070     auto pipelineContext = container->GetPipelineContext();
1071     CHECK_NULL_VOID(pipelineContext);
1072     auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
1073     CHECK_NULL_VOID(context);
1074     auto overlayManager = context->GetOverlayManager();
1075     CHECK_NULL_VOID(overlayManager);
1076     auto popupInfo = overlayManager->GetPopupInfo(targetId);
1077     auto isShow = param->IsShow();
1078     auto isUseCustom = param->IsUseCustom();
1079     auto showInSubWindow = param->IsShowInSubWindow();
1080     // subwindow model needs to use subContainer to get popupInfo
1081     if (showInSubWindow) {
1082         auto subwindow = SubwindowManager::GetInstance()->GetSubwindow(Container::CurrentId());
1083         if (subwindow) {
1084             subwindow->GetPopupInfoNG(targetId, popupInfo);
1085         }
1086     }
1087 
1088     auto popupId = popupInfo.popupId;
1089     auto popupNode = popupInfo.popupNode;
1090     RefPtr<BubblePattern> popupPattern;
1091     if (popupNode) {
1092         popupPattern = popupNode->GetPattern<BubblePattern>();
1093     }
1094 
1095     if (popupInfo.isCurrentOnShow) {
1096         // Entering / Normal / Exiting
1097         bool popupShowing = popupPattern ? popupPattern->IsOnShow() : false;
1098         if (popupShowing == isShow) {
1099             LOGI("No need to change popup show flag, current show %{public}d", isShow);
1100             return;
1101         }
1102         if (!popupShowing && isShow) {
1103             popupInfo.markNeedUpdate = false;
1104         } else {
1105             popupInfo.markNeedUpdate = true;
1106         }
1107     } else {
1108         // Invisable
1109         if (!isShow) {
1110             LOGI("No need to change popup show flag, current show %{public}d", isShow);
1111             return;
1112         }
1113         popupInfo.markNeedUpdate = true;
1114     }
1115 
1116     // Create new popup.
1117     if (popupInfo.popupId == -1 || !popupNode) {
1118         if (!isUseCustom) {
1119             popupNode = BubbleView::CreateBubbleNode(targetTag, targetId, param);
1120         } else {
1121             CHECK_NULL_VOID(customNode);
1122             popupNode = BubbleView::CreateCustomBubbleNode(targetTag, targetId, customNode, param);
1123         }
1124         if (popupNode) {
1125             popupId = popupNode->GetId();
1126         }
1127     } else {
1128         // use param to update PopupParm
1129         if (!isUseCustom) {
1130             BubbleView::UpdatePopupParam(popupId, param, targetNode);
1131             popupNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
1132             LOGI("Update normal Popup node.");
1133         } else {
1134             BubbleView::UpdateCustomPopupParam(popupId, param);
1135             popupNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
1136             LOGI("Update Custom Popup node.");
1137         }
1138     }
1139     // update PopupInfo props
1140     popupInfo.popupId = popupId;
1141     popupInfo.popupNode = popupNode;
1142     popupInfo.isBlockEvent = param->IsBlockEvent();
1143     if (popupNode) {
1144         popupNode->MarkModifyDone();
1145         popupPattern = popupNode->GetPattern<BubblePattern>();
1146     }
1147     popupInfo.target = AceType::WeakClaim(AceType::RawPtr(targetNode));
1148     popupInfo.targetSize = SizeF(param->GetTargetSize().Width(), param->GetTargetSize().Height());
1149     popupInfo.targetOffset = OffsetF(param->GetTargetOffset().GetX(), param->GetTargetOffset().GetY());
1150     if (showInSubWindow) {
1151         if (isShow) {
1152             LOGI("Popup now show in subwindow.");
1153             SubwindowManager::GetInstance()->ShowPopupNG(targetId, popupInfo);
1154         } else {
1155             SubwindowManager::GetInstance()->HidePopupNG(targetId);
1156         }
1157         return;
1158     }
1159     auto destroyCallback = [weakOverlayManger = AceType::WeakClaim(AceType::RawPtr(overlayManager)), targetId]() {
1160         auto overlay = weakOverlayManger.Upgrade();
1161         CHECK_NULL_VOID(overlay);
1162         overlay->ErasePopup(targetId);
1163     };
1164     targetNode->PushDestroyCallback(destroyCallback);
1165     if (!popupInfo.isCurrentOnShow) {
1166         targetNode->OnAccessibilityEvent(
1167             AccessibilityEventType::CHANGE, WindowsContentChangeTypes::CONTENT_CHANGE_TYPE_SUBTREE);
1168     }
1169     if (isShow) {
1170         LOGI("begin to update popup node.");
1171         overlayManager->ShowPopup(targetId, popupInfo);
1172     } else {
1173         overlayManager->HidePopup(targetId, popupInfo);
1174     }
1175 }
1176 
BindMenuWithItems(std::vector<OptionParam> && params,const RefPtr<FrameNode> & targetNode,const NG::OffsetF & offset,const MenuParam & menuParam)1177 void ViewAbstract::BindMenuWithItems(std::vector<OptionParam>&& params,
1178     const RefPtr<FrameNode>& targetNode, const NG::OffsetF& offset, const MenuParam& menuParam)
1179 {
1180     CHECK_NULL_VOID(targetNode);
1181 
1182     if (params.empty()) {
1183         LOGD("menu params is empty");
1184         return;
1185     }
1186     auto menuNode =
1187         MenuView::Create(std::move(params), targetNode->GetId(), targetNode->GetTag(), MenuType::MENU, menuParam);
1188     BindMenu(menuNode, targetNode->GetId(), offset);
1189 }
1190 
BindMenuWithCustomNode(const RefPtr<UINode> & customNode,const RefPtr<FrameNode> & targetNode,MenuType menuType,const NG::OffsetF & offset,const MenuParam & menuParam)1191 void ViewAbstract::BindMenuWithCustomNode(const RefPtr<UINode>& customNode, const RefPtr<FrameNode>& targetNode,
1192     MenuType menuType, const NG::OffsetF& offset, const MenuParam& menuParam)
1193 {
1194     LOGD("ViewAbstract::BindMenuWithCustomNode");
1195     CHECK_NULL_VOID(customNode);
1196     CHECK_NULL_VOID(targetNode);
1197     auto type = menuType;
1198 #ifdef PREVIEW
1199     // unable to use the subWindow in the Previewer.
1200     type = MenuType::MENU;
1201 #endif
1202     auto menuNode = MenuView::Create(customNode, targetNode->GetId(), targetNode->GetTag(), type, menuParam);
1203     if (type == MenuType::CONTEXT_MENU) {
1204         SubwindowManager::GetInstance()->ShowMenuNG(menuNode, targetNode->GetId(), offset, menuParam.isAboveApps);
1205         return;
1206     }
1207     BindMenu(menuNode, targetNode->GetId(), offset);
1208 }
1209 
ShowMenu(int32_t targetId,const NG::OffsetF & offset,bool isContextMenu)1210 void ViewAbstract::ShowMenu(int32_t targetId, const NG::OffsetF& offset, bool isContextMenu)
1211 {
1212     if (isContextMenu) {
1213         SubwindowManager::GetInstance()->ShowMenuNG(nullptr, targetId, offset);
1214         return;
1215     }
1216     LOGD("ViewAbstract::ShowMenu");
1217     auto container = Container::Current();
1218     CHECK_NULL_VOID(container);
1219     auto pipelineContext = container->GetPipelineContext();
1220     CHECK_NULL_VOID(pipelineContext);
1221     auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
1222     CHECK_NULL_VOID(context);
1223     auto overlayManager = context->GetOverlayManager();
1224     CHECK_NULL_VOID(overlayManager);
1225 
1226     overlayManager->ShowMenu(targetId, offset, nullptr);
1227 }
1228 
SetBackdropBlur(const Dimension & radius)1229 void ViewAbstract::SetBackdropBlur(const Dimension& radius)
1230 {
1231     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1232         LOGD("current state is not processed, return");
1233         return;
1234     }
1235     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1236     CHECK_NULL_VOID(frameNode);
1237     auto target = frameNode->GetRenderContext();
1238     if (target) {
1239         if (target->GetBackgroundEffect().has_value()) {
1240             target->UpdateBackgroundEffect(std::nullopt);
1241         }
1242         target->UpdateBackBlurRadius(radius);
1243         if (target->GetBackBlurStyle().has_value()) {
1244             target->UpdateBackBlurStyle(std::nullopt);
1245         }
1246     }
1247 }
1248 
SetLinearGradientBlur(NG::LinearGradientBlurPara blurPara)1249 void ViewAbstract::SetLinearGradientBlur(NG::LinearGradientBlurPara blurPara)
1250 {
1251     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1252         LOGD("current state is not processed, return");
1253         return;
1254     }
1255     ACE_UPDATE_RENDER_CONTEXT(LinearGradientBlur, blurPara);
1256 }
1257 
SetDynamicLightUp(float rate,float lightUpDegree)1258 void ViewAbstract::SetDynamicLightUp(float rate, float lightUpDegree)
1259 {
1260     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1261         LOGD("current state is not processed, return");
1262         return;
1263     }
1264     ACE_UPDATE_RENDER_CONTEXT(DynamicLightUpRate, rate);
1265     ACE_UPDATE_RENDER_CONTEXT(DynamicLightUpDegree, lightUpDegree);
1266 }
1267 
SetFrontBlur(const Dimension & radius)1268 void ViewAbstract::SetFrontBlur(const Dimension& radius)
1269 {
1270     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1271         LOGD("current state is not processed, return");
1272         return;
1273     }
1274     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1275     CHECK_NULL_VOID(frameNode);
1276     auto target = frameNode->GetRenderContext();
1277     if (target) {
1278         target->UpdateFrontBlurRadius(radius);
1279         if (target->GetFrontBlurStyle().has_value()) {
1280             target->UpdateFrontBlurStyle(std::nullopt);
1281         }
1282     }
1283 }
1284 
SetBackShadow(const Shadow & shadow)1285 void ViewAbstract::SetBackShadow(const Shadow& shadow)
1286 {
1287     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1288         LOGD("current state is not processed, return");
1289         return;
1290     }
1291     ACE_UPDATE_RENDER_CONTEXT(BackShadow, shadow);
1292 }
1293 
SetLinearGradient(const NG::Gradient & gradient)1294 void ViewAbstract::SetLinearGradient(const NG::Gradient& gradient)
1295 {
1296     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1297         LOGD("current state is not processed, return");
1298         return;
1299     }
1300     ACE_UPDATE_RENDER_CONTEXT(LinearGradient, gradient);
1301 }
1302 
SetSweepGradient(const NG::Gradient & gradient)1303 void ViewAbstract::SetSweepGradient(const NG::Gradient& gradient)
1304 {
1305     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1306         LOGD("current state is not processed, return");
1307         return;
1308     }
1309     ACE_UPDATE_RENDER_CONTEXT(SweepGradient, gradient);
1310 }
1311 
SetRadialGradient(const NG::Gradient & gradient)1312 void ViewAbstract::SetRadialGradient(const NG::Gradient& gradient)
1313 {
1314     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1315         LOGD("current state is not processed, return");
1316         return;
1317     }
1318     ACE_UPDATE_RENDER_CONTEXT(RadialGradient, gradient);
1319 }
1320 
SetInspectorId(const std::string & inspectorId)1321 void ViewAbstract::SetInspectorId(const std::string& inspectorId)
1322 {
1323     auto uiNode = ViewStackProcessor::GetInstance()->GetMainElementNode();
1324     if (uiNode) {
1325         uiNode->UpdateInspectorId(inspectorId);
1326     }
1327 }
1328 
SetRestoreId(int32_t restoreId)1329 void ViewAbstract::SetRestoreId(int32_t restoreId)
1330 {
1331     auto uiNode = ViewStackProcessor::GetInstance()->GetMainElementNode();
1332     if (uiNode) {
1333         uiNode->SetRestoreId(restoreId);
1334     }
1335 }
1336 
SetDebugLine(const std::string & line)1337 void ViewAbstract::SetDebugLine(const std::string& line)
1338 {
1339 #ifdef PREVIEW
1340     auto uiNode = ViewStackProcessor::GetInstance()->GetMainElementNode();
1341     if (uiNode) {
1342         uiNode->SetDebugLine(line);
1343     }
1344 #endif
1345 }
1346 
SetGrid(std::optional<int32_t> span,std::optional<int32_t> offset,GridSizeType type)1347 void ViewAbstract::SetGrid(std::optional<int32_t> span, std::optional<int32_t> offset, GridSizeType type)
1348 {
1349     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1350     CHECK_NULL_VOID(frameNode);
1351     auto layoutProperty = frameNode->GetLayoutProperty();
1352     CHECK_NULL_VOID(layoutProperty);
1353     // frame node is mounted to parent when pop from stack later, no grid-container is added here
1354     layoutProperty->UpdateGridProperty(span, offset, type);
1355 }
1356 
Pop()1357 void ViewAbstract::Pop()
1358 {
1359     ViewStackProcessor::GetInstance()->Pop();
1360 }
1361 
SetTransition(const TransitionOptions & options)1362 void ViewAbstract::SetTransition(const TransitionOptions& options)
1363 {
1364     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1365         LOGD("current state is not processed, return");
1366         return;
1367     }
1368     ACE_UPDATE_RENDER_CONTEXT(Transition, options);
1369 }
1370 
SetChainedTransition(const RefPtr<NG::ChainedTransitionEffect> & effect)1371 void ViewAbstract::SetChainedTransition(const RefPtr<NG::ChainedTransitionEffect>& effect)
1372 {
1373     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1374         LOGD("current state is not processed, return");
1375         return;
1376     }
1377     ACE_UPDATE_RENDER_CONTEXT(ChainedTransition, effect);
1378 }
1379 
SetClipShape(const RefPtr<BasicShape> & basicShape)1380 void ViewAbstract::SetClipShape(const RefPtr<BasicShape>& basicShape)
1381 {
1382     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1383         LOGD("current state is not processed, return");
1384         return;
1385     }
1386     ACE_UPDATE_RENDER_CONTEXT(ClipShape, basicShape);
1387 }
1388 
SetClipEdge(bool isClip)1389 void ViewAbstract::SetClipEdge(bool isClip)
1390 {
1391     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1392         LOGD("current state is not processed, return");
1393         return;
1394     }
1395     ACE_UPDATE_RENDER_CONTEXT(ClipEdge, isClip);
1396 }
1397 
SetMask(const RefPtr<BasicShape> & basicShape)1398 void ViewAbstract::SetMask(const RefPtr<BasicShape>& basicShape)
1399 {
1400     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1401         LOGD("current state is not processed, return");
1402         return;
1403     }
1404     ACE_UPDATE_RENDER_CONTEXT(ClipMask, basicShape);
1405 }
1406 
SetProgressMask(const RefPtr<ProgressMaskProperty> & progress)1407 void ViewAbstract::SetProgressMask(const RefPtr<ProgressMaskProperty>& progress)
1408 {
1409     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1410         LOGD("current state is not processed, return");
1411         return;
1412     }
1413     ACE_UPDATE_RENDER_CONTEXT(ProgressMask, progress);
1414 }
1415 
SetBrightness(const Dimension & brightness)1416 void ViewAbstract::SetBrightness(const Dimension& brightness)
1417 {
1418     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1419         LOGD("current state is not processed, return");
1420         return;
1421     }
1422     ACE_UPDATE_RENDER_CONTEXT(FrontBrightness, brightness);
1423 }
1424 
SetGrayScale(const Dimension & grayScale)1425 void ViewAbstract::SetGrayScale(const Dimension& grayScale)
1426 {
1427     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1428         LOGD("current state is not processed, return");
1429         return;
1430     }
1431     ACE_UPDATE_RENDER_CONTEXT(FrontGrayScale, grayScale);
1432 }
1433 
SetContrast(const Dimension & contrast)1434 void ViewAbstract::SetContrast(const Dimension& contrast)
1435 {
1436     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1437         LOGD("current state is not processed, return");
1438         return;
1439     }
1440     ACE_UPDATE_RENDER_CONTEXT(FrontContrast, contrast);
1441 }
1442 
SetSaturate(const Dimension & saturate)1443 void ViewAbstract::SetSaturate(const Dimension& saturate)
1444 {
1445     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1446         LOGD("current state is not processed, return");
1447         return;
1448     }
1449     ACE_UPDATE_RENDER_CONTEXT(FrontSaturate, saturate);
1450 }
1451 
SetSepia(const Dimension & sepia)1452 void ViewAbstract::SetSepia(const Dimension& sepia)
1453 {
1454     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1455         LOGD("current state is not processed, return");
1456         return;
1457     }
1458     ACE_UPDATE_RENDER_CONTEXT(FrontSepia, sepia);
1459 }
1460 
SetInvert(const Dimension & invert)1461 void ViewAbstract::SetInvert(const Dimension& invert)
1462 {
1463     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1464         LOGD("current state is not processed, return");
1465         return;
1466     }
1467     ACE_UPDATE_RENDER_CONTEXT(FrontInvert, invert);
1468 }
1469 
SetHueRotate(float hueRotate)1470 void ViewAbstract::SetHueRotate(float hueRotate)
1471 {
1472     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1473         LOGD("current state is not processed, return");
1474         return;
1475     }
1476     ACE_UPDATE_RENDER_CONTEXT(FrontHueRotate, hueRotate);
1477 }
1478 
SetColorBlend(const Color & colorBlend)1479 void ViewAbstract::SetColorBlend(const Color& colorBlend)
1480 {
1481     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1482         LOGD("current state is not processed, return");
1483         return;
1484     }
1485     ACE_UPDATE_RENDER_CONTEXT(FrontColorBlend, colorBlend);
1486 }
1487 
SetBorderImage(const RefPtr<BorderImage> & borderImage)1488 void ViewAbstract::SetBorderImage(const RefPtr<BorderImage>& borderImage)
1489 {
1490     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1491         LOGD("current state is not processed, return");
1492         return;
1493     }
1494     ACE_UPDATE_RENDER_CONTEXT(BorderImage, borderImage);
1495 }
1496 
SetBorderImageSource(const std::string & bdImageSrc)1497 void ViewAbstract::SetBorderImageSource(const std::string& bdImageSrc)
1498 {
1499     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1500         LOGD("current state is not processed, return");
1501         return;
1502     }
1503     ImageSourceInfo imageSourceInfo(bdImageSrc);
1504     ACE_UPDATE_RENDER_CONTEXT(BorderImageSource, imageSourceInfo);
1505 }
1506 
SetHasBorderImageSlice(bool tag)1507 void ViewAbstract::SetHasBorderImageSlice(bool tag)
1508 {
1509     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1510         LOGD("current state is not processed, return");
1511         return;
1512     }
1513     ACE_UPDATE_RENDER_CONTEXT(HasBorderImageSlice, tag);
1514 }
1515 
SetHasBorderImageWidth(bool tag)1516 void ViewAbstract::SetHasBorderImageWidth(bool tag)
1517 {
1518     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1519         LOGD("current state is not processed, return");
1520         return;
1521     }
1522     ACE_UPDATE_RENDER_CONTEXT(HasBorderImageWidth, tag);
1523 }
1524 
SetHasBorderImageOutset(bool tag)1525 void ViewAbstract::SetHasBorderImageOutset(bool tag)
1526 {
1527     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1528         LOGD("current state is not processed, return");
1529         return;
1530     }
1531     ACE_UPDATE_RENDER_CONTEXT(HasBorderImageOutset, tag);
1532 }
1533 
SetHasBorderImageRepeat(bool tag)1534 void ViewAbstract::SetHasBorderImageRepeat(bool tag)
1535 {
1536     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1537         LOGD("current state is not processed, return");
1538         return;
1539     }
1540     ACE_UPDATE_RENDER_CONTEXT(HasBorderImageRepeat, tag);
1541 }
1542 
SetBorderImageGradient(const Gradient & gradient)1543 void ViewAbstract::SetBorderImageGradient(const Gradient& gradient)
1544 {
1545     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1546         LOGD("current state is not processed, return");
1547         return;
1548     }
1549     ACE_UPDATE_RENDER_CONTEXT(BorderImageGradient, gradient);
1550 }
1551 
SetOverlay(const OverlayOptions & overlay)1552 void ViewAbstract::SetOverlay(const OverlayOptions& overlay)
1553 {
1554     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1555         LOGD("current state is not processed, return");
1556         return;
1557     }
1558     ACE_UPDATE_RENDER_CONTEXT(OverlayText, overlay);
1559 }
1560 
SetMotionPath(const MotionPathOption & motionPath)1561 void ViewAbstract::SetMotionPath(const MotionPathOption& motionPath)
1562 {
1563     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1564         LOGD("current state is not processed, return");
1565         return;
1566     }
1567     ACE_UPDATE_RENDER_CONTEXT(MotionPath, motionPath);
1568 }
1569 
SetSharedTransition(const std::string & shareId,const std::shared_ptr<SharedTransitionOption> & option)1570 void ViewAbstract::SetSharedTransition(
1571     const std::string& shareId, const std::shared_ptr<SharedTransitionOption>& option)
1572 {
1573     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1574     CHECK_NULL_VOID(frameNode);
1575     auto target = frameNode->GetRenderContext();
1576     if (target) {
1577         target->SetSharedTransitionOptions(option);
1578         target->SetShareId(shareId);
1579     }
1580 }
1581 
SetUseEffect(bool useEffect)1582 void ViewAbstract::SetUseEffect(bool useEffect)
1583 {
1584     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1585         LOGD("current state is not processed, return");
1586         return;
1587     }
1588     ACE_UPDATE_RENDER_CONTEXT(UseEffect, useEffect);
1589 }
1590 
SetForegroundColor(const Color & color)1591 void ViewAbstract::SetForegroundColor(const Color& color)
1592 {
1593     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1594         LOGD("current state is not processed, return");
1595         return;
1596     }
1597     ACE_UPDATE_RENDER_CONTEXT(ForegroundColor, color);
1598     ACE_RESET_RENDER_CONTEXT(RenderContext, ForegroundColorStrategy);
1599     ACE_UPDATE_RENDER_CONTEXT(ForegroundColorFlag, true);
1600 }
1601 
SetForegroundColorStrategy(const ForegroundColorStrategy & strategy)1602 void ViewAbstract::SetForegroundColorStrategy(const ForegroundColorStrategy& strategy)
1603 {
1604     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1605         LOGD("current state is not processed, return");
1606         return;
1607     }
1608     ACE_UPDATE_RENDER_CONTEXT(ForegroundColorStrategy, strategy);
1609     ACE_RESET_RENDER_CONTEXT(RenderContext, ForegroundColor);
1610     ACE_UPDATE_RENDER_CONTEXT(ForegroundColorFlag, true);
1611 }
1612 
SetKeyboardShortcut(const std::string & value,const std::vector<ModifierKey> & keys,std::function<void ()> && onKeyboardShortcutAction)1613 void ViewAbstract::SetKeyboardShortcut(
1614     const std::string& value, const std::vector<ModifierKey>& keys, std::function<void()>&& onKeyboardShortcutAction)
1615 {
1616     auto pipeline = PipelineContext::GetCurrentContext();
1617     CHECK_NULL_VOID(pipeline);
1618     auto eventManager = pipeline->GetEventManager();
1619     CHECK_NULL_VOID(eventManager);
1620     auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
1621     CHECK_NULL_VOID(eventHub);
1622     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1623     CHECK_NULL_VOID(frameNode);
1624     if (value.empty() || (keys.size() == 0 && value.length() == 1)) {
1625         LOGI("KeyboardShortcut value and keys is invalid, return");
1626         eventHub->SetKeyboardShortcut("", 0, nullptr);
1627         return;
1628     }
1629     auto key = eventManager->GetKeyboardShortcutKeys(keys);
1630     if ((key == 0 && value.length() == 1) || (key == 0 && keys.size() > 0 && value.length() > 1)) {
1631         LOGI("KeyboardShortcut's keys are the same, return");
1632         return;
1633     }
1634     if (eventManager->IsSameKeyboardShortcutNode(value, key)) {
1635         LOGI("KeyboardShortcut is the same, return");
1636         return;
1637     }
1638     eventHub->SetKeyboardShortcut(value, key, std::move(onKeyboardShortcutAction));
1639     eventManager->AddKeyboardShortcutNode(WeakPtr<NG::FrameNode>(frameNode));
1640 }
1641 
CreateAnimatablePropertyFloat(const std::string & propertyName,float value,const std::function<void (float)> & onCallbackEvent)1642 void ViewAbstract::CreateAnimatablePropertyFloat(const std::string& propertyName, float value,
1643     const std::function<void(float)>& onCallbackEvent)
1644 {
1645     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1646     CHECK_NULL_VOID(frameNode);
1647     frameNode->CreateAnimatablePropertyFloat(propertyName, value, onCallbackEvent);
1648 }
1649 
UpdateAnimatablePropertyFloat(const std::string & propertyName,float value)1650 void ViewAbstract::UpdateAnimatablePropertyFloat(const std::string& propertyName, float value)
1651 {
1652     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1653     CHECK_NULL_VOID(frameNode);
1654     frameNode->UpdateAnimatablePropertyFloat(propertyName, value);
1655 }
1656 
CreateAnimatableArithmeticProperty(const std::string & propertyName,RefPtr<CustomAnimatableArithmetic> & value,std::function<void (const RefPtr<CustomAnimatableArithmetic> &)> & onCallbackEvent)1657 void ViewAbstract::CreateAnimatableArithmeticProperty(const std::string& propertyName,
1658     RefPtr<CustomAnimatableArithmetic>& value,
1659     std::function<void(const RefPtr<CustomAnimatableArithmetic>&)>& onCallbackEvent)
1660 {
1661     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1662     CHECK_NULL_VOID(frameNode);
1663     frameNode->CreateAnimatableArithmeticProperty(propertyName, value, onCallbackEvent);
1664 }
1665 
UpdateAnimatableArithmeticProperty(const std::string & propertyName,RefPtr<CustomAnimatableArithmetic> & value)1666 void ViewAbstract::UpdateAnimatableArithmeticProperty(const std::string& propertyName,
1667     RefPtr<CustomAnimatableArithmetic>& value)
1668 {
1669     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1670     CHECK_NULL_VOID(frameNode);
1671     frameNode->UpdateAnimatableArithmeticProperty(propertyName, value);
1672 }
1673 
SetObscured(const std::vector<ObscuredReasons> & reasons)1674 void ViewAbstract::SetObscured(const std::vector<ObscuredReasons>& reasons)
1675 {
1676     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1677         LOGD("current state is not processed, return");
1678         return;
1679     }
1680     ACE_UPDATE_RENDER_CONTEXT(Obscured, reasons);
1681     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1682     CHECK_NULL_VOID(frameNode);
1683     frameNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
1684 }
1685 
UpdateSafeAreaExpandOpts(const SafeAreaExpandOpts & opts)1686 void ViewAbstract::UpdateSafeAreaExpandOpts(const SafeAreaExpandOpts& opts)
1687 {
1688     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1689         LOGD("current state is not processed, return");
1690         return;
1691     }
1692     ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaExpandOpts, opts);
1693 }
1694 
SetRenderGroup(bool isRenderGroup)1695 void ViewAbstract::SetRenderGroup(bool isRenderGroup)
1696 {
1697     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1698         LOGD("current state is not processed, return");
1699         return;
1700     }
1701     ACE_UPDATE_RENDER_CONTEXT(RenderGroup, isRenderGroup);
1702 }
1703 
SetRenderFit(RenderFit renderFit)1704 void ViewAbstract::SetRenderFit(RenderFit renderFit)
1705 {
1706     if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1707         LOGD("current state is not processed, return");
1708         return;
1709     }
1710     ACE_UPDATE_RENDER_CONTEXT(RenderFit, renderFit);
1711 }
1712 } // namespace OHOS::Ace::NG
1713