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
18 #include <cstdint>
19 #include <optional>
20 #include <string>
21 #include <utility>
22 #if !defined(PREVIEW) && !defined(ACE_UNITTEST) && defined(OHOS_PLATFORM)
23 #include "interfaces/inner_api/ui_session/ui_session_manager.h"
24 #endif
25
26 #include "base/geometry/dimension.h"
27 #include "base/geometry/matrix4.h"
28 #include "base/geometry/ng/offset_t.h"
29 #include "base/memory/ace_type.h"
30 #include "base/subwindow/subwindow.h"
31 #include "base/utils/system_properties.h"
32 #include "base/utils/utils.h"
33 #include "core/common/ace_application_info.h"
34 #include "base/log/log_wrapper.h"
35 #include "core/common/container.h"
36 #include "core/common/container_scope.h"
37 #include "core/components/common/layout/constants.h"
38 #include "core/components/common/properties/shadow.h"
39 #include "core/components/theme/shadow_theme.h"
40 #include "core/components_ng/base/frame_node.h"
41 #include "core/components_ng/base/view_stack_processor.h"
42 #include "core/components_ng/layout/layout_property.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_pattern.h"
47 #include "core/components_ng/pattern/menu/menu_view.h"
48 #include "core/components_ng/pattern/menu/preview/menu_preview_pattern.h"
49 #include "core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h"
50 #include "core/components_ng/pattern/option/option_paint_property.h"
51 #include "core/components_ng/pattern/overlay/dialog_manager.h"
52 #include "core/components_ng/pattern/text/span_node.h"
53 #include "core/components_ng/property/border_property.h"
54 #include "core/components_ng/property/calc_length.h"
55 #include "core/components_ng/property/measure_property.h"
56 #include "core/components_ng/property/property.h"
57 #include "core/components_ng/property/safe_area_insets.h"
58 #include "core/components_v2/inspector/inspector_constants.h"
59 #include "core/image/image_source_info.h"
60 #include "core/pipeline_ng/pipeline_context.h"
61 #include "core/pipeline_ng/ui_task_scheduler.h"
62
63 namespace OHOS::Ace::NG {
64
SetWidth(const CalcLength & width)65 void ViewAbstract::SetWidth(const CalcLength& width)
66 {
67 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
68 return;
69 }
70 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
71 CHECK_NULL_VOID(frameNode);
72 auto layoutProperty = frameNode->GetLayoutProperty();
73 CHECK_NULL_VOID(layoutProperty);
74 // get previously user defined ideal height
75 std::optional<CalcLength> height = std::nullopt;
76 auto&& layoutConstraint = layoutProperty->GetCalcLayoutConstraint();
77 if (layoutConstraint && layoutConstraint->selfIdealSize) {
78 height = layoutConstraint->selfIdealSize->Height();
79 }
80 layoutProperty->UpdateUserDefinedIdealSize(CalcSize(width, height));
81 }
82
SetHeight(const CalcLength & height)83 void ViewAbstract::SetHeight(const CalcLength& height)
84 {
85 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
86 return;
87 }
88 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
89 CHECK_NULL_VOID(frameNode);
90 auto layoutProperty = frameNode->GetLayoutProperty();
91 CHECK_NULL_VOID(layoutProperty);
92 // get previously user defined ideal width
93 std::optional<CalcLength> width = std::nullopt;
94 auto&& layoutConstraint = layoutProperty->GetCalcLayoutConstraint();
95 if (layoutConstraint && layoutConstraint->selfIdealSize) {
96 width = layoutConstraint->selfIdealSize->Width();
97 }
98 layoutProperty->UpdateUserDefinedIdealSize(CalcSize(width, height));
99 }
100
SetClickEffectLevel(const ClickEffectLevel & level,float scaleValue)101 void ViewAbstract::SetClickEffectLevel(const ClickEffectLevel& level, float scaleValue)
102 {
103 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
104 return;
105 }
106 ClickEffectInfo clickEffectInfo;
107 clickEffectInfo.level = level;
108 clickEffectInfo.scaleNumber = scaleValue;
109 ACE_UPDATE_RENDER_CONTEXT(ClickEffectLevel, clickEffectInfo);
110 }
111
ClearWidthOrHeight(bool isWidth)112 void ViewAbstract::ClearWidthOrHeight(bool isWidth)
113 {
114 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
115 return;
116 }
117 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
118 CHECK_NULL_VOID(frameNode);
119 auto layoutProperty = frameNode->GetLayoutProperty();
120 CHECK_NULL_VOID(layoutProperty);
121 layoutProperty->ClearUserDefinedIdealSize(isWidth, !isWidth);
122 }
123
SetMinWidth(const CalcLength & width)124 void ViewAbstract::SetMinWidth(const CalcLength& width)
125 {
126 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
127 return;
128 }
129 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
130 CHECK_NULL_VOID(frameNode);
131 auto layoutProperty = frameNode->GetLayoutProperty();
132 CHECK_NULL_VOID(layoutProperty);
133 layoutProperty->UpdateCalcMinSize(CalcSize(width, std::nullopt));
134 }
135
SetMinHeight(const CalcLength & height)136 void ViewAbstract::SetMinHeight(const CalcLength& height)
137 {
138 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
139 return;
140 }
141 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
142 CHECK_NULL_VOID(frameNode);
143 auto layoutProperty = frameNode->GetLayoutProperty();
144 CHECK_NULL_VOID(layoutProperty);
145 layoutProperty->UpdateCalcMinSize(CalcSize(std::nullopt, height));
146 }
147
ResetMinSize(bool resetWidth)148 void ViewAbstract::ResetMinSize(bool resetWidth)
149 {
150 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
151 return;
152 }
153 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
154 CHECK_NULL_VOID(frameNode);
155 auto layoutProperty = frameNode->GetLayoutProperty();
156 CHECK_NULL_VOID(layoutProperty);
157 layoutProperty->ResetCalcMinSize(resetWidth);
158 }
159
SetMaxWidth(const CalcLength & width)160 void ViewAbstract::SetMaxWidth(const CalcLength& width)
161 {
162 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
163 return;
164 }
165 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
166 CHECK_NULL_VOID(frameNode);
167 auto layoutProperty = frameNode->GetLayoutProperty();
168 CHECK_NULL_VOID(layoutProperty);
169 layoutProperty->UpdateCalcMaxSize(CalcSize(width, std::nullopt));
170 }
171
SetMaxHeight(const CalcLength & height)172 void ViewAbstract::SetMaxHeight(const CalcLength& height)
173 {
174 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
175 return;
176 }
177 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
178 CHECK_NULL_VOID(frameNode);
179 auto layoutProperty = frameNode->GetLayoutProperty();
180 CHECK_NULL_VOID(layoutProperty);
181 layoutProperty->UpdateCalcMaxSize(CalcSize(std::nullopt, height));
182 }
183
ResetMaxSize(bool resetWidth)184 void ViewAbstract::ResetMaxSize(bool resetWidth)
185 {
186 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
187 return;
188 }
189 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
190 CHECK_NULL_VOID(frameNode);
191 auto layoutProperty = frameNode->GetLayoutProperty();
192 CHECK_NULL_VOID(layoutProperty);
193 layoutProperty->ResetCalcMaxSize(resetWidth);
194 }
195
SetAspectRatio(float ratio)196 void ViewAbstract::SetAspectRatio(float ratio)
197 {
198 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
199 return;
200 }
201 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, AspectRatio, ratio);
202 }
203
ResetAspectRatio()204 void ViewAbstract::ResetAspectRatio()
205 {
206 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
207 return;
208 }
209 ACE_RESET_LAYOUT_PROPERTY(LayoutProperty, AspectRatio);
210 }
211
SetBackgroundAlign(const Alignment & align)212 void ViewAbstract::SetBackgroundAlign(const Alignment& align)
213 {
214 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
215 return;
216 }
217 ACE_UPDATE_RENDER_CONTEXT(BackgroundAlign, align);
218 }
219
SetBackgroundColor(const Color & color)220 void ViewAbstract::SetBackgroundColor(const Color& color)
221 {
222 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
223 return;
224 }
225
226 Color updateColor = color;
227 auto pipeline = PipelineContext::GetCurrentContext();
228 if (pipeline != nullptr) {
229 pipeline->CheckNeedUpdateBackgroundColor(updateColor);
230 }
231
232 ACE_UPDATE_RENDER_CONTEXT(BackgroundColor, updateColor);
233 }
234
SetBackgroundColor(FrameNode * frameNode,const Color & color)235 void ViewAbstract::SetBackgroundColor(FrameNode* frameNode, const Color& color)
236 {
237 ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundColor, color, frameNode);
238 }
239
SetBackgroundImage(const ImageSourceInfo & src)240 void ViewAbstract::SetBackgroundImage(const ImageSourceInfo& src)
241 {
242 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
243 return;
244 }
245 auto pipeline = PipelineContext::GetCurrentContext();
246 if (pipeline != nullptr) {
247 bool disableSetImage = pipeline->CheckNeedDisableUpdateBackgroundImage();
248 if (disableSetImage) {
249 return;
250 }
251 }
252 ACE_UPDATE_RENDER_CONTEXT(BackgroundImage, src);
253 }
254
SetBackgroundImage(FrameNode * frameNode,const ImageSourceInfo & src)255 void ViewAbstract::SetBackgroundImage(FrameNode* frameNode, const ImageSourceInfo& src)
256 {
257 ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImage, src, frameNode);
258 }
259
SetBackgroundImageRepeat(const ImageRepeat & imageRepeat)260 void ViewAbstract::SetBackgroundImageRepeat(const ImageRepeat& imageRepeat)
261 {
262 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
263 return;
264 }
265 ACE_UPDATE_RENDER_CONTEXT(BackgroundImageRepeat, imageRepeat);
266 }
267
SetBackgroundImageRepeat(FrameNode * frameNode,const ImageRepeat & imageRepeat)268 void ViewAbstract::SetBackgroundImageRepeat(FrameNode* frameNode, const ImageRepeat& imageRepeat)
269 {
270 ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImageRepeat, imageRepeat, frameNode);
271 }
272
SetBackgroundImageSize(const BackgroundImageSize & bgImgSize)273 void ViewAbstract::SetBackgroundImageSize(const BackgroundImageSize& bgImgSize)
274 {
275 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
276 return;
277 }
278 ACE_UPDATE_RENDER_CONTEXT(BackgroundImageSize, bgImgSize);
279 }
280
SetBackgroundImageSize(FrameNode * frameNode,const BackgroundImageSize & bgImgSize)281 void ViewAbstract::SetBackgroundImageSize(FrameNode* frameNode, const BackgroundImageSize& bgImgSize)
282 {
283 ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImageSize, bgImgSize, frameNode);
284 }
285
SetBackgroundImagePosition(const BackgroundImagePosition & bgImgPosition)286 void ViewAbstract::SetBackgroundImagePosition(const BackgroundImagePosition& bgImgPosition)
287 {
288 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
289 return;
290 }
291 ACE_UPDATE_RENDER_CONTEXT(BackgroundImagePosition, bgImgPosition);
292 }
293
SetBackgroundImagePosition(FrameNode * frameNode,const BackgroundImagePosition & bgImgPosition)294 void ViewAbstract::SetBackgroundImagePosition(FrameNode* frameNode, const BackgroundImagePosition& bgImgPosition)
295 {
296 ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImagePosition, bgImgPosition, frameNode);
297 }
298
SetBackgroundBlurStyle(const BlurStyleOption & bgBlurStyle)299 void ViewAbstract::SetBackgroundBlurStyle(const BlurStyleOption& bgBlurStyle)
300 {
301 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
302 return;
303 }
304 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
305 CHECK_NULL_VOID(frameNode);
306 SetBackgroundBlurStyle(frameNode, bgBlurStyle);
307 }
308
SetForegroundEffect(float radius)309 void ViewAbstract::SetForegroundEffect(float radius)
310 {
311 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
312 return;
313 }
314 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
315 CHECK_NULL_VOID(frameNode);
316 auto target = frameNode->GetRenderContext();
317 if (target) {
318 target->UpdateForegroundEffect(radius);
319 }
320 }
321
SetMotionBlur(const MotionBlurOption & motionBlurOption)322 void ViewAbstract::SetMotionBlur(const MotionBlurOption &motionBlurOption)
323 {
324 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
325 return;
326 }
327 ACE_UPDATE_RENDER_CONTEXT(MotionBlur, motionBlurOption);
328 }
329
SetBackgroundEffect(const EffectOption & effectOption)330 void ViewAbstract::SetBackgroundEffect(const EffectOption& effectOption)
331 {
332 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
333 return;
334 }
335 SetBackgroundEffect(ViewStackProcessor::GetInstance()->GetMainFrameNode(), effectOption);
336 }
337
SetForegroundBlurStyle(const BlurStyleOption & fgBlurStyle)338 void ViewAbstract::SetForegroundBlurStyle(const BlurStyleOption& fgBlurStyle)
339 {
340 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
341 return;
342 }
343 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
344 CHECK_NULL_VOID(frameNode);
345 auto target = frameNode->GetRenderContext();
346 if (target) {
347 target->UpdateFrontBlurStyle(fgBlurStyle);
348 if (target->GetFrontBlurRadius().has_value()) {
349 target->UpdateFrontBlurRadius(Dimension());
350 }
351 }
352 }
353
SetSphericalEffect(double radio)354 void ViewAbstract::SetSphericalEffect(double radio)
355 {
356 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
357 return;
358 }
359 ACE_UPDATE_RENDER_CONTEXT(SphericalEffect, radio);
360 }
361
SetPixelStretchEffect(PixStretchEffectOption & option)362 void ViewAbstract::SetPixelStretchEffect(PixStretchEffectOption& option)
363 {
364 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
365 return;
366 }
367 ACE_UPDATE_RENDER_CONTEXT(PixelStretchEffect, option);
368 }
369
SetLightUpEffect(double radio)370 void ViewAbstract::SetLightUpEffect(double radio)
371 {
372 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
373 return;
374 }
375 ACE_UPDATE_RENDER_CONTEXT(LightUpEffect, radio);
376 }
377
SetLayoutWeight(float value)378 void ViewAbstract::SetLayoutWeight(float value)
379 {
380 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
381 return;
382 }
383 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, LayoutWeight, static_cast<float>(value));
384 }
385
SetLayoutWeight(const NG::LayoutWeightPair & value)386 void ViewAbstract::SetLayoutWeight(const NG::LayoutWeightPair& value)
387 {
388 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
389 return;
390 }
391 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, ChainWeight, value);
392 }
393
SetPixelRound(uint16_t value)394 void ViewAbstract::SetPixelRound(uint16_t value)
395 {
396 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
397 return;
398 }
399 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, PixelRound, value);
400 }
401
SetPixelRound(FrameNode * frameNode,uint16_t value)402 void ViewAbstract::SetPixelRound(FrameNode* frameNode, uint16_t value)
403 {
404 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, PixelRound, value, frameNode);
405 }
406
SetLayoutDirection(TextDirection value)407 void ViewAbstract::SetLayoutDirection(TextDirection value)
408 {
409 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
410 return;
411 }
412 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, LayoutDirection, value);
413 }
414
SetAlignRules(const std::map<AlignDirection,AlignRule> & alignRules)415 void ViewAbstract::SetAlignRules(const std::map<AlignDirection, AlignRule>& alignRules)
416 {
417 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
418 return;
419 }
420 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, AlignRules, alignRules);
421 }
422
SetChainStyle(const ChainInfo & chainInfo)423 void ViewAbstract::SetChainStyle(const ChainInfo& chainInfo)
424 {
425 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
426 return;
427 }
428 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, ChainStyle, chainInfo);
429 }
430
SetBias(const BiasPair & biasPair)431 void ViewAbstract::SetBias(const BiasPair& biasPair)
432 {
433 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
434 return;
435 }
436 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Bias, biasPair);
437 }
438
SetAlignSelf(FlexAlign value)439 void ViewAbstract::SetAlignSelf(FlexAlign value)
440 {
441 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
442 return;
443 }
444 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, AlignSelf, value);
445 }
446
SetFlexShrink(float value)447 void ViewAbstract::SetFlexShrink(float value)
448 {
449 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
450 return;
451 }
452 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, FlexShrink, value);
453 }
454
ResetFlexShrink()455 void ViewAbstract::ResetFlexShrink()
456 {
457 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
458 return;
459 }
460 ACE_RESET_LAYOUT_PROPERTY(LayoutProperty, FlexShrink);
461 }
462
SetFlexGrow(float value)463 void ViewAbstract::SetFlexGrow(float value)
464 {
465 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
466 return;
467 }
468 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, FlexGrow, value);
469 }
470
SetFlexBasis(const Dimension & value)471 void ViewAbstract::SetFlexBasis(const Dimension& value)
472 {
473 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
474 return;
475 }
476 if (LessNotEqual(value.Value(), 0.0f)) {
477 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, FlexBasis, Dimension());
478 return;
479 }
480 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, FlexBasis, value);
481 }
482
SetDisplayIndex(int32_t value)483 void ViewAbstract::SetDisplayIndex(int32_t value)
484 {
485 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
486 return;
487 }
488 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, DisplayIndex, value);
489 }
490
SetPadding(const CalcLength & value)491 void ViewAbstract::SetPadding(const CalcLength& value)
492 {
493 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
494 return;
495 }
496 PaddingProperty padding;
497 padding.SetEdges(value);
498 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Padding, padding);
499 }
500
SetPadding(const PaddingProperty & value)501 void ViewAbstract::SetPadding(const PaddingProperty& value)
502 {
503 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
504 return;
505 }
506 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Padding, value);
507 }
508
SetSafeAreaPadding(const CalcLength & value)509 void ViewAbstract::SetSafeAreaPadding(const CalcLength& value)
510 {
511 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
512 return;
513 }
514 PaddingProperty padding;
515 padding.SetEdges(value);
516 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaPadding, padding);
517 }
518
SetSafeAreaPadding(const PaddingProperty & value)519 void ViewAbstract::SetSafeAreaPadding(const PaddingProperty& value)
520 {
521 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
522 return;
523 }
524 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaPadding, value);
525 }
526
ResetSafeAreaPadding()527 void ViewAbstract::ResetSafeAreaPadding()
528 {
529 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
530 return;
531 }
532 ACE_RESET_LAYOUT_PROPERTY(LayoutProperty, SafeAreaPadding);
533 }
534
SetSafeAreaPadding(FrameNode * frameNode,const CalcLength & value)535 void ViewAbstract::SetSafeAreaPadding(FrameNode* frameNode, const CalcLength& value)
536 {
537 CHECK_NULL_VOID(frameNode);
538 PaddingProperty padding;
539 padding.SetEdges(value);
540 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaPadding, padding, frameNode);
541 }
542
SetSafeAreaPadding(FrameNode * frameNode,const PaddingProperty & value)543 void ViewAbstract::SetSafeAreaPadding(FrameNode* frameNode, const PaddingProperty& value)
544 {
545 CHECK_NULL_VOID(frameNode);
546 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaPadding, value, frameNode);
547 }
548
ResetSafeAreaPadding(FrameNode * frameNode)549 void ViewAbstract::ResetSafeAreaPadding(FrameNode* frameNode)
550 {
551 CHECK_NULL_VOID(frameNode);
552 ACE_RESET_NODE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaPadding, frameNode);
553 }
554
SetMargin(const CalcLength & value)555 void ViewAbstract::SetMargin(const CalcLength& value)
556 {
557 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
558 return;
559 }
560 MarginProperty margin;
561 margin.SetEdges(value);
562 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Margin, margin);
563 }
564
SetMargin(const MarginProperty & value)565 void ViewAbstract::SetMargin(const MarginProperty& value)
566 {
567 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
568 return;
569 }
570 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Margin, value);
571 }
572
SetBorderRadius(const Dimension & value)573 void ViewAbstract::SetBorderRadius(const Dimension& value)
574 {
575 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
576 return;
577 }
578 BorderRadiusProperty borderRadius;
579 borderRadius.SetRadius(value);
580 borderRadius.multiValued = false;
581 ACE_UPDATE_RENDER_CONTEXT(BorderRadius, borderRadius);
582 }
583
SetBorderRadius(const BorderRadiusProperty & value)584 void ViewAbstract::SetBorderRadius(const BorderRadiusProperty& value)
585 {
586 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
587 return;
588 }
589 ACE_UPDATE_RENDER_CONTEXT(BorderRadius, value);
590 }
591
SetBorderColor(const Color & value)592 void ViewAbstract::SetBorderColor(const Color& value)
593 {
594 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
595 return;
596 }
597 BorderColorProperty borderColor;
598 borderColor.SetColor(value);
599 ACE_UPDATE_RENDER_CONTEXT(BorderColor, borderColor);
600 }
601
SetBorderColor(const BorderColorProperty & value)602 void ViewAbstract::SetBorderColor(const BorderColorProperty& value)
603 {
604 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
605 return;
606 }
607 ACE_UPDATE_RENDER_CONTEXT(BorderColor, value);
608 }
609
SetBorderWidth(const Dimension & value)610 void ViewAbstract::SetBorderWidth(const Dimension& value)
611 {
612 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
613 return;
614 }
615 BorderWidthProperty borderWidth;
616 if (Negative(value.Value())) {
617 borderWidth.SetBorderWidth(Dimension(0));
618 } else {
619 borderWidth.SetBorderWidth(value);
620 }
621 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, BorderWidth, borderWidth);
622 ACE_UPDATE_RENDER_CONTEXT(BorderWidth, borderWidth);
623 }
624
SetBorderWidth(const BorderWidthProperty & value)625 void ViewAbstract::SetBorderWidth(const BorderWidthProperty& value)
626 {
627 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
628 return;
629 }
630 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, BorderWidth, value);
631 ACE_UPDATE_RENDER_CONTEXT(BorderWidth, value);
632 }
633
SetBorderStyle(const BorderStyle & value)634 void ViewAbstract::SetBorderStyle(const BorderStyle& value)
635 {
636 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
637 return;
638 }
639 BorderStyleProperty borderStyle;
640 borderStyle.SetBorderStyle(value);
641 ACE_UPDATE_RENDER_CONTEXT(BorderStyle, borderStyle);
642 }
643
SetBorderStyle(FrameNode * frameNode,const BorderStyle & value)644 void ViewAbstract::SetBorderStyle(FrameNode* frameNode, const BorderStyle& value)
645 {
646 BorderStyleProperty borderStyle;
647 borderStyle.SetBorderStyle(value);
648 ACE_UPDATE_NODE_RENDER_CONTEXT(BorderStyle, borderStyle, frameNode);
649 }
650
SetBorderStyle(const BorderStyleProperty & value)651 void ViewAbstract::SetBorderStyle(const BorderStyleProperty& value)
652 {
653 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
654 return;
655 }
656 ACE_UPDATE_RENDER_CONTEXT(BorderStyle, value);
657 }
658
SetBorderStyle(FrameNode * frameNode,const BorderStyleProperty & value)659 void ViewAbstract::SetBorderStyle(FrameNode* frameNode, const BorderStyleProperty& value)
660 {
661 ACE_UPDATE_NODE_RENDER_CONTEXT(BorderStyle, value, frameNode);
662 }
663
SetDashGap(const Dimension & value)664 void ViewAbstract::SetDashGap(const Dimension& value)
665 {
666 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
667 return;
668 }
669 BorderWidthProperty dashGap;
670 dashGap.SetBorderWidth(value);
671
672 ACE_UPDATE_RENDER_CONTEXT(DashGap, dashGap);
673 }
674
SetDashGap(FrameNode * frameNode,const Dimension & value)675 void ViewAbstract::SetDashGap(FrameNode *frameNode, const Dimension& value)
676 {
677 BorderWidthProperty dashGap;
678 dashGap.SetBorderWidth(value);
679
680 ACE_UPDATE_NODE_RENDER_CONTEXT(DashGap, dashGap, frameNode);
681 }
682
SetDashGap(const BorderWidthProperty & value)683 void ViewAbstract::SetDashGap(const BorderWidthProperty& value)
684 {
685 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
686 return;
687 }
688 ACE_UPDATE_RENDER_CONTEXT(DashGap, value);
689 }
690
SetDashGap(FrameNode * frameNode,const BorderWidthProperty & value)691 void ViewAbstract::SetDashGap(FrameNode *frameNode, const BorderWidthProperty& value)
692 {
693 ACE_UPDATE_NODE_RENDER_CONTEXT(DashGap, value, frameNode);
694 }
695
SetDashWidth(const Dimension & value)696 void ViewAbstract::SetDashWidth(const Dimension& value)
697 {
698 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
699 return;
700 }
701 BorderWidthProperty dashWidth;
702 dashWidth.SetBorderWidth(value);
703
704 ACE_UPDATE_RENDER_CONTEXT(DashWidth, dashWidth);
705 }
706
SetDashWidth(FrameNode * frameNode,const Dimension & value)707 void ViewAbstract::SetDashWidth(FrameNode *frameNode, const Dimension& value)
708 {
709 BorderWidthProperty dashWidth;
710 dashWidth.SetBorderWidth(value);
711
712 ACE_UPDATE_NODE_RENDER_CONTEXT(DashWidth, dashWidth, frameNode);
713 }
714
SetDashWidth(const BorderWidthProperty & value)715 void ViewAbstract::SetDashWidth(const BorderWidthProperty& value)
716 {
717 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
718 return;
719 }
720 ACE_UPDATE_RENDER_CONTEXT(DashWidth, value);
721 }
722
SetDashWidth(FrameNode * frameNode,const BorderWidthProperty & value)723 void ViewAbstract::SetDashWidth(FrameNode *frameNode, const BorderWidthProperty& value)
724 {
725 ACE_UPDATE_NODE_RENDER_CONTEXT(DashWidth, value, frameNode);
726 }
727
SetOuterBorderRadius(const Dimension & value)728 void ViewAbstract::SetOuterBorderRadius(const Dimension& value)
729 {
730 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
731 return;
732 }
733 BorderRadiusProperty borderRadius;
734 borderRadius.SetRadius(value);
735 borderRadius.multiValued = false;
736 ACE_UPDATE_RENDER_CONTEXT(OuterBorderRadius, borderRadius);
737 }
738
SetOuterBorderRadius(FrameNode * frameNode,const Dimension & value)739 void ViewAbstract::SetOuterBorderRadius(FrameNode* frameNode, const Dimension& value)
740 {
741 BorderRadiusProperty borderRadius;
742 borderRadius.SetRadius(value);
743 borderRadius.multiValued = false;
744 ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderRadius, borderRadius, frameNode);
745 }
746
SetOuterBorderRadius(const BorderRadiusProperty & value)747 void ViewAbstract::SetOuterBorderRadius(const BorderRadiusProperty& value)
748 {
749 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
750 return;
751 }
752 ACE_UPDATE_RENDER_CONTEXT(OuterBorderRadius, value);
753 }
754
SetOuterBorderRadius(FrameNode * frameNode,const BorderRadiusProperty & value)755 void ViewAbstract::SetOuterBorderRadius(FrameNode* frameNode, const BorderRadiusProperty& value)
756 {
757 ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderRadius, value, frameNode);
758 }
759
SetOuterBorderColor(const Color & value)760 void ViewAbstract::SetOuterBorderColor(const Color& value)
761 {
762 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
763 return;
764 }
765 BorderColorProperty borderColor;
766 borderColor.SetColor(value);
767 ACE_UPDATE_RENDER_CONTEXT(OuterBorderColor, borderColor);
768 }
769
SetOuterBorderColor(FrameNode * frameNode,const Color & value)770 void ViewAbstract::SetOuterBorderColor(FrameNode* frameNode, const Color& value)
771 {
772 BorderColorProperty borderColor;
773 borderColor.SetColor(value);
774 ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderColor, borderColor, frameNode);
775 }
776
SetOuterBorderColor(const BorderColorProperty & value)777 void ViewAbstract::SetOuterBorderColor(const BorderColorProperty& value)
778 {
779 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
780 return;
781 }
782 ACE_UPDATE_RENDER_CONTEXT(OuterBorderColor, value);
783 }
784
SetOuterBorderColor(FrameNode * frameNode,const BorderColorProperty & value)785 void ViewAbstract::SetOuterBorderColor(FrameNode* frameNode, const BorderColorProperty& value)
786 {
787 ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderColor, value, frameNode);
788 }
789
SetOuterBorderWidth(const Dimension & value)790 void ViewAbstract::SetOuterBorderWidth(const Dimension& value)
791 {
792 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
793 return;
794 }
795 BorderWidthProperty borderWidth;
796 if (Negative(value.Value())) {
797 borderWidth.SetBorderWidth(Dimension(0));
798 } else {
799 borderWidth.SetBorderWidth(value);
800 }
801 ACE_UPDATE_RENDER_CONTEXT(OuterBorderWidth, borderWidth);
802 }
803
SetOuterBorderWidth(FrameNode * frameNode,const Dimension & value)804 void ViewAbstract::SetOuterBorderWidth(FrameNode* frameNode, const Dimension& value)
805 {
806 BorderWidthProperty borderWidth;
807 if (Negative(value.Value())) {
808 borderWidth.SetBorderWidth(Dimension(0));
809 } else {
810 borderWidth.SetBorderWidth(value);
811 }
812 ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderWidth, borderWidth, frameNode);
813 }
814
SetOuterBorderWidth(const BorderWidthProperty & value)815 void ViewAbstract::SetOuterBorderWidth(const BorderWidthProperty& value)
816 {
817 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
818 return;
819 }
820 ACE_UPDATE_RENDER_CONTEXT(OuterBorderWidth, value);
821 }
822
SetOuterBorderWidth(FrameNode * frameNode,const BorderWidthProperty & value)823 void ViewAbstract::SetOuterBorderWidth(FrameNode* frameNode, const BorderWidthProperty& value)
824 {
825 ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderWidth, value, frameNode);
826 }
827
SetOuterBorderStyle(const BorderStyleProperty & value)828 void ViewAbstract::SetOuterBorderStyle(const BorderStyleProperty& value)
829 {
830 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
831 return;
832 }
833 ACE_UPDATE_RENDER_CONTEXT(OuterBorderStyle, value);
834 }
835
SetOuterBorderStyle(FrameNode * frameNode,const BorderStyleProperty & value)836 void ViewAbstract::SetOuterBorderStyle(FrameNode* frameNode, const BorderStyleProperty& value)
837 {
838 ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderStyle, value, frameNode);
839 }
840
SetOuterBorderStyle(const BorderStyle & value)841 void ViewAbstract::SetOuterBorderStyle(const BorderStyle& value)
842 {
843 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
844 return;
845 }
846 BorderStyleProperty borderStyle;
847 borderStyle.SetBorderStyle(value);
848 ACE_UPDATE_RENDER_CONTEXT(OuterBorderStyle, borderStyle);
849 }
850
SetOuterBorderStyle(FrameNode * frameNode,const BorderStyle & value)851 void ViewAbstract::SetOuterBorderStyle(FrameNode* frameNode, const BorderStyle& value)
852 {
853 BorderStyleProperty borderStyle;
854 borderStyle.SetBorderStyle(value);
855 ACE_UPDATE_NODE_RENDER_CONTEXT(OuterBorderStyle, borderStyle, frameNode);
856 }
857
DisableOnClick()858 void ViewAbstract::DisableOnClick()
859 {
860 auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
861 CHECK_NULL_VOID(gestureHub);
862 gestureHub->ClearUserOnClick();
863 }
864
DisableOnTouch()865 void ViewAbstract::DisableOnTouch()
866 {
867 auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
868 CHECK_NULL_VOID(gestureHub);
869 gestureHub->ClearUserOnTouch();
870 }
871
DisableOnKeyEvent()872 void ViewAbstract::DisableOnKeyEvent()
873 {
874 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
875 CHECK_NULL_VOID(focusHub);
876 focusHub->ClearOnKeyCallback();
877 }
878
DisableOnKeyEventDispatch()879 void ViewAbstract::DisableOnKeyEventDispatch()
880 {
881 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
882 CHECK_NULL_VOID(focusHub);
883 focusHub->ClearOnKeyEventDispatchCallback();
884 }
885
DisableOnHover()886 void ViewAbstract::DisableOnHover()
887 {
888 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
889 CHECK_NULL_VOID(eventHub);
890 eventHub->ClearUserOnHover();
891 }
892
DisableOnHoverMove()893 void ViewAbstract::DisableOnHoverMove()
894 {
895 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
896 CHECK_NULL_VOID(eventHub);
897 eventHub->ClearUserOnHoverMove();
898 }
899
DisableOnAccessibilityHover()900 void ViewAbstract::DisableOnAccessibilityHover()
901 {
902 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
903 CHECK_NULL_VOID(eventHub);
904 eventHub->ClearUserOnAccessibilityHover();
905 }
906
DisableOnMouse()907 void ViewAbstract::DisableOnMouse()
908 {
909 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
910 CHECK_NULL_VOID(eventHub);
911 eventHub->ClearUserOnMouse();
912 }
913
DisableOnAppear()914 void ViewAbstract::DisableOnAppear()
915 {
916 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
917 CHECK_NULL_VOID(eventHub);
918 eventHub->ClearUserOnAppear();
919 }
920
DisableOnDisAppear()921 void ViewAbstract::DisableOnDisAppear()
922 {
923 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
924 CHECK_NULL_VOID(eventHub);
925 eventHub->ClearUserOnDisAppear();
926 }
927
DisableOnAttach()928 void ViewAbstract::DisableOnAttach()
929 {
930 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
931 CHECK_NULL_VOID(eventHub);
932 eventHub->ClearOnAttach();
933 }
934
DisableOnDetach()935 void ViewAbstract::DisableOnDetach()
936 {
937 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
938 CHECK_NULL_VOID(eventHub);
939 eventHub->ClearOnDetach();
940 }
941
DisableOnAreaChange()942 void ViewAbstract::DisableOnAreaChange()
943 {
944 auto pipeline = PipelineContext::GetCurrentContext();
945 CHECK_NULL_VOID(pipeline);
946 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
947 CHECK_NULL_VOID(frameNode);
948 frameNode->ClearUserOnAreaChange();
949 }
950
DisableOnFocus()951 void ViewAbstract::DisableOnFocus()
952 {
953 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
954 CHECK_NULL_VOID(focusHub);
955 focusHub->ClearOnFocusCallback();
956 }
957
DisableOnBlur()958 void ViewAbstract::DisableOnBlur()
959 {
960 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
961 CHECK_NULL_VOID(focusHub);
962 focusHub->ClearOnBlurCallback();
963 }
964
DisableOnFocusAxisEvent()965 void ViewAbstract::DisableOnFocusAxisEvent()
966 {
967 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
968 CHECK_NULL_VOID(focusHub);
969 focusHub->ClearOnFocusAxisCallback();
970 }
971
DisableOnFocusAxisEvent(FrameNode * frameNode)972 void ViewAbstract::DisableOnFocusAxisEvent(FrameNode* frameNode)
973 {
974 auto focusHub = frameNode->GetOrCreateFocusHub();
975 CHECK_NULL_VOID(focusHub);
976 focusHub->ClearOnFocusAxisCallback();
977 }
978
DisableOnClick(FrameNode * frameNode)979 void ViewAbstract::DisableOnClick(FrameNode* frameNode)
980 {
981 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
982 CHECK_NULL_VOID(gestureHub);
983 gestureHub->ClearUserOnClick();
984 }
985
DisableOnDragStart(FrameNode * frameNode)986 void ViewAbstract::DisableOnDragStart(FrameNode* frameNode)
987 {
988 CHECK_NULL_VOID(frameNode);
989 auto eventHub = frameNode->GetEventHub<EventHub>();
990 CHECK_NULL_VOID(eventHub);
991 eventHub->ClearCustomerOnDragStart();
992 }
993
DisableOnDragEnter(FrameNode * frameNode)994 void ViewAbstract::DisableOnDragEnter(FrameNode* frameNode)
995 {
996 CHECK_NULL_VOID(frameNode);
997 auto eventHub = frameNode->GetEventHub<EventHub>();
998 CHECK_NULL_VOID(eventHub);
999 eventHub->ClearCustomerOnDragEnter();
1000 }
1001
DisableOnDragMove(FrameNode * frameNode)1002 void ViewAbstract::DisableOnDragMove(FrameNode* frameNode)
1003 {
1004 CHECK_NULL_VOID(frameNode);
1005 auto eventHub = frameNode->GetEventHub<EventHub>();
1006 CHECK_NULL_VOID(eventHub);
1007 eventHub->ClearCustomerOnDragMove();
1008 }
1009
DisableOnDragLeave(FrameNode * frameNode)1010 void ViewAbstract::DisableOnDragLeave(FrameNode* frameNode)
1011 {
1012 CHECK_NULL_VOID(frameNode);
1013 auto eventHub = frameNode->GetEventHub<EventHub>();
1014 CHECK_NULL_VOID(eventHub);
1015 eventHub->ClearCustomerOnDragLeave();
1016 }
1017
DisableOnDrop(FrameNode * frameNode)1018 void ViewAbstract::DisableOnDrop(FrameNode* frameNode)
1019 {
1020 CHECK_NULL_VOID(frameNode);
1021 auto eventHub = frameNode->GetEventHub<EventHub>();
1022 CHECK_NULL_VOID(eventHub);
1023 eventHub->ClearCustomerOnDrop();
1024 }
1025
DisableOnDragEnd(FrameNode * frameNode)1026 void ViewAbstract::DisableOnDragEnd(FrameNode* frameNode)
1027 {
1028 CHECK_NULL_VOID(frameNode);
1029 auto eventHub = frameNode->GetEventHub<EventHub>();
1030 CHECK_NULL_VOID(eventHub);
1031 eventHub->ClearCustomerOnDragEnd();
1032 }
1033
DisableOnTouch(FrameNode * frameNode)1034 void ViewAbstract::DisableOnTouch(FrameNode* frameNode)
1035 {
1036 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
1037 CHECK_NULL_VOID(gestureHub);
1038 gestureHub->ClearUserOnTouch();
1039 }
1040
DisableOnKeyEvent(FrameNode * frameNode)1041 void ViewAbstract::DisableOnKeyEvent(FrameNode* frameNode)
1042 {
1043 auto focusHub = frameNode->GetOrCreateFocusHub();
1044 CHECK_NULL_VOID(focusHub);
1045 focusHub->ClearOnKeyCallback();
1046 }
1047
DisableOnKeyEventDispatch(FrameNode * frameNode)1048 void ViewAbstract::DisableOnKeyEventDispatch(FrameNode* frameNode)
1049 {
1050 auto focusHub = frameNode->GetOrCreateFocusHub();
1051 CHECK_NULL_VOID(focusHub);
1052 focusHub->ClearOnKeyEventDispatchCallback();
1053 }
1054
DisableOnHover(FrameNode * frameNode)1055 void ViewAbstract::DisableOnHover(FrameNode* frameNode)
1056 {
1057 auto eventHub = frameNode->GetOrCreateInputEventHub();
1058 CHECK_NULL_VOID(eventHub);
1059 eventHub->ClearUserOnHover();
1060 }
1061
DisableOnHoverMove(FrameNode * frameNode)1062 void ViewAbstract::DisableOnHoverMove(FrameNode* frameNode)
1063 {
1064 auto eventHub = frameNode->GetOrCreateInputEventHub();
1065 CHECK_NULL_VOID(eventHub);
1066 eventHub->ClearUserOnHoverMove();
1067 }
1068
DisableOnMouse(FrameNode * frameNode)1069 void ViewAbstract::DisableOnMouse(FrameNode* frameNode)
1070 {
1071 auto eventHub = frameNode->GetOrCreateInputEventHub();
1072 CHECK_NULL_VOID(eventHub);
1073 eventHub->ClearUserOnMouse();
1074 }
1075
DisableOnAppear(FrameNode * frameNode)1076 void ViewAbstract::DisableOnAppear(FrameNode* frameNode)
1077 {
1078 auto eventHub = frameNode->GetEventHub<EventHub>();
1079 CHECK_NULL_VOID(eventHub);
1080 eventHub->ClearUserOnAppear();
1081 }
1082
DisableOnDisappear(FrameNode * frameNode)1083 void ViewAbstract::DisableOnDisappear(FrameNode* frameNode)
1084 {
1085 auto eventHub = frameNode->GetEventHub<EventHub>();
1086 CHECK_NULL_VOID(eventHub);
1087 eventHub->ClearUserOnDisAppear();
1088 }
1089
DisableOnAttach(FrameNode * frameNode)1090 void ViewAbstract::DisableOnAttach(FrameNode* frameNode)
1091 {
1092 auto eventHub = frameNode->GetEventHub<EventHub>();
1093 CHECK_NULL_VOID(eventHub);
1094 eventHub->ClearOnAttach();
1095 }
1096
DisableOnDetach(FrameNode * frameNode)1097 void ViewAbstract::DisableOnDetach(FrameNode* frameNode)
1098 {
1099 auto eventHub = frameNode->GetEventHub<EventHub>();
1100 CHECK_NULL_VOID(eventHub);
1101 eventHub->ClearOnDetach();
1102 }
1103
DisableOnFocus(FrameNode * frameNode)1104 void ViewAbstract::DisableOnFocus(FrameNode* frameNode)
1105 {
1106 auto focusHub = frameNode->GetOrCreateFocusHub();
1107 CHECK_NULL_VOID(focusHub);
1108 focusHub->ClearOnFocusCallback();
1109 }
1110
DisableOnBlur(FrameNode * frameNode)1111 void ViewAbstract::DisableOnBlur(FrameNode* frameNode)
1112 {
1113 auto focusHub = frameNode->GetOrCreateFocusHub();
1114 CHECK_NULL_VOID(focusHub);
1115 focusHub->ClearOnBlurCallback();
1116 }
1117
DisableOnAreaChange(FrameNode * frameNode)1118 void ViewAbstract::DisableOnAreaChange(FrameNode* frameNode)
1119 {
1120 CHECK_NULL_VOID(frameNode);
1121 frameNode->ClearUserOnAreaChange();
1122 }
1123
SetOnClick(GestureEventFunc && clickEventFunc,double distanceThreshold)1124 void ViewAbstract::SetOnClick(GestureEventFunc&& clickEventFunc, double distanceThreshold)
1125 {
1126 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1127 CHECK_NULL_VOID(frameNode);
1128 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
1129 CHECK_NULL_VOID(gestureHub);
1130 gestureHub->SetUserOnClick(std::move(clickEventFunc), distanceThreshold);
1131
1132 auto focusHub = frameNode->GetOrCreateFocusHub();
1133 CHECK_NULL_VOID(focusHub);
1134 focusHub->SetFocusable(true, false);
1135 }
1136
SetOnGestureJudgeBegin(GestureJudgeFunc && gestureJudgeFunc)1137 void ViewAbstract::SetOnGestureJudgeBegin(GestureJudgeFunc&& gestureJudgeFunc)
1138 {
1139 auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
1140 CHECK_NULL_VOID(gestureHub);
1141 gestureHub->SetOnGestureJudgeBegin(std::move(gestureJudgeFunc));
1142 }
1143
SetOnTouchIntercept(TouchInterceptFunc && touchInterceptFunc)1144 void ViewAbstract::SetOnTouchIntercept(TouchInterceptFunc&& touchInterceptFunc)
1145 {
1146 auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
1147 CHECK_NULL_VOID(gestureHub);
1148 gestureHub->SetOnTouchIntercept(std::move(touchInterceptFunc));
1149 }
1150
SetShouldBuiltInRecognizerParallelWith(NG::ShouldBuiltInRecognizerParallelWithFunc && shouldBuiltInRecognizerParallelWithFunc)1151 void ViewAbstract::SetShouldBuiltInRecognizerParallelWith(
1152 NG::ShouldBuiltInRecognizerParallelWithFunc&& shouldBuiltInRecognizerParallelWithFunc)
1153 {
1154 auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
1155 CHECK_NULL_VOID(gestureHub);
1156 gestureHub->SetShouldBuildinRecognizerParallelWithFunc(std::move(shouldBuiltInRecognizerParallelWithFunc));
1157 }
1158
SetOnGestureRecognizerJudgeBegin(GestureRecognizerJudgeFunc && gestureRecognizerJudgeFunc,bool exposeInnerGestureFlag)1159 void ViewAbstract::SetOnGestureRecognizerJudgeBegin(
1160 GestureRecognizerJudgeFunc&& gestureRecognizerJudgeFunc, bool exposeInnerGestureFlag)
1161 {
1162 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1163 CHECK_NULL_VOID(frameNode);
1164 frameNode->SetExposeInnerGestureFlag(exposeInnerGestureFlag);
1165
1166 auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
1167 CHECK_NULL_VOID(gestureHub);
1168 gestureHub->SetOnGestureRecognizerJudgeBegin(std::move(gestureRecognizerJudgeFunc));
1169 }
1170
SetOnTouch(TouchEventFunc && touchEventFunc)1171 void ViewAbstract::SetOnTouch(TouchEventFunc&& touchEventFunc)
1172 {
1173 auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
1174 CHECK_NULL_VOID(gestureHub);
1175 gestureHub->SetTouchEvent(std::move(touchEventFunc));
1176 }
1177
SetOnMouse(OnMouseEventFunc && onMouseEventFunc)1178 void ViewAbstract::SetOnMouse(OnMouseEventFunc&& onMouseEventFunc)
1179 {
1180 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
1181 CHECK_NULL_VOID(eventHub);
1182 eventHub->SetMouseEvent(std::move(onMouseEventFunc));
1183 }
1184
SetOnHover(OnHoverFunc && onHoverEventFunc)1185 void ViewAbstract::SetOnHover(OnHoverFunc&& onHoverEventFunc)
1186 {
1187 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
1188 CHECK_NULL_VOID(eventHub);
1189 eventHub->SetHoverEvent(std::move(onHoverEventFunc));
1190 }
1191
SetOnHoverMove(OnHoverMoveFunc && onHoverMoveEventFunc)1192 void ViewAbstract::SetOnHoverMove(OnHoverMoveFunc&& onHoverMoveEventFunc)
1193 {
1194 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
1195 CHECK_NULL_VOID(eventHub);
1196 eventHub->SetHoverMoveEvent(std::move(onHoverMoveEventFunc));
1197 }
1198
SetOnAccessibilityHover(OnAccessibilityHoverFunc && onAccessibilityHoverEventFunc)1199 void ViewAbstract::SetOnAccessibilityHover(OnAccessibilityHoverFunc &&onAccessibilityHoverEventFunc)
1200 {
1201 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
1202 CHECK_NULL_VOID(eventHub);
1203 eventHub->SetAccessibilityHoverEvent(std::move(onAccessibilityHoverEventFunc));
1204 }
1205
SetHoverEffect(HoverEffectType hoverEffect)1206 void ViewAbstract::SetHoverEffect(HoverEffectType hoverEffect)
1207 {
1208 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
1209 CHECK_NULL_VOID(eventHub);
1210 eventHub->SetHoverEffect(hoverEffect);
1211 }
1212
SetHoverEffectAuto(HoverEffectType hoverEffect)1213 void ViewAbstract::SetHoverEffectAuto(HoverEffectType hoverEffect)
1214 {
1215 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeInputEventHub();
1216 CHECK_NULL_VOID(eventHub);
1217 eventHub->SetHoverEffectAuto(hoverEffect);
1218 }
1219
SetEnabled(bool enabled)1220 void ViewAbstract::SetEnabled(bool enabled)
1221 {
1222 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1223 CHECK_NULL_VOID(frameNode);
1224 auto eventHub = frameNode->GetEventHub<EventHub>();
1225 if (eventHub) {
1226 eventHub->SetEnabled(enabled);
1227 }
1228
1229 // The SetEnabled of focusHub must be after at eventHub
1230 auto focusHub = frameNode->GetOrCreateFocusHub();
1231 if (focusHub) {
1232 focusHub->SetEnabled(enabled);
1233 }
1234 }
1235
SetFocusable(bool focusable)1236 void ViewAbstract::SetFocusable(bool focusable)
1237 {
1238 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
1239 CHECK_NULL_VOID(focusHub);
1240 focusHub->SetFocusable(focusable);
1241 }
1242
SetTabStop(bool tabStop)1243 void ViewAbstract::SetTabStop(bool tabStop)
1244 {
1245 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1246 CHECK_NULL_VOID(frameNode);
1247 auto focusHub = frameNode->GetOrCreateFocusHub();
1248 CHECK_NULL_VOID(focusHub);
1249 focusHub->SetTabStop(tabStop);
1250 }
1251
SetOnFocus(OnFocusFunc && onFocusCallback)1252 void ViewAbstract::SetOnFocus(OnFocusFunc&& onFocusCallback)
1253 {
1254 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
1255 CHECK_NULL_VOID(focusHub);
1256 focusHub->SetOnFocusCallback(std::move(onFocusCallback));
1257 }
1258
SetOnBlur(OnBlurFunc && onBlurCallback)1259 void ViewAbstract::SetOnBlur(OnBlurFunc&& onBlurCallback)
1260 {
1261 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
1262 CHECK_NULL_VOID(focusHub);
1263 focusHub->SetOnBlurCallback(std::move(onBlurCallback));
1264 }
1265
SetOnKeyEvent(OnKeyConsumeFunc && onKeyCallback)1266 void ViewAbstract::SetOnKeyEvent(OnKeyConsumeFunc&& onKeyCallback)
1267 {
1268 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
1269 CHECK_NULL_VOID(focusHub);
1270 focusHub->SetOnKeyCallback(std::move(onKeyCallback));
1271 }
1272
SetTabIndex(int32_t index)1273 void ViewAbstract::SetTabIndex(int32_t index)
1274 {
1275 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
1276 CHECK_NULL_VOID(focusHub);
1277 focusHub->SetTabIndex(index);
1278 }
1279
SetFocusOnTouch(bool isSet)1280 void ViewAbstract::SetFocusOnTouch(bool isSet)
1281 {
1282 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
1283 CHECK_NULL_VOID(focusHub);
1284 focusHub->SetIsFocusOnTouch(isSet);
1285 }
1286
SetFocusBoxStyle(const NG::FocusBoxStyle & style)1287 void ViewAbstract::SetFocusBoxStyle(const NG::FocusBoxStyle& style)
1288 {
1289 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
1290 CHECK_NULL_VOID(focusHub);
1291 focusHub->GetFocusBox().SetStyle(style);
1292 }
1293
SetDefaultFocus(bool isSet)1294 void ViewAbstract::SetDefaultFocus(bool isSet)
1295 {
1296 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
1297 CHECK_NULL_VOID(focusHub);
1298 focusHub->SetIsDefaultFocus(isSet);
1299 }
1300
SetGroupDefaultFocus(bool isSet)1301 void ViewAbstract::SetGroupDefaultFocus(bool isSet)
1302 {
1303 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
1304 CHECK_NULL_VOID(focusHub);
1305 focusHub->SetIsDefaultGroupFocus(isSet);
1306 }
1307
SetOnAppear(std::function<void ()> && onAppear)1308 void ViewAbstract::SetOnAppear(std::function<void()>&& onAppear)
1309 {
1310 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
1311 CHECK_NULL_VOID(eventHub);
1312 eventHub->SetOnAppear(std::move(onAppear));
1313 }
1314
SetOnDisappear(std::function<void ()> && onDisappear)1315 void ViewAbstract::SetOnDisappear(std::function<void()>&& onDisappear)
1316 {
1317 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
1318 CHECK_NULL_VOID(eventHub);
1319 eventHub->SetOnDisappear(std::move(onDisappear));
1320 }
1321
SetOnAttach(std::function<void ()> && onAttach)1322 void ViewAbstract::SetOnAttach(std::function<void()> &&onAttach)
1323 {
1324 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
1325 CHECK_NULL_VOID(eventHub);
1326 eventHub->SetOnAttach(std::move(onAttach));
1327 }
1328
SetOnDetach(std::function<void ()> && onDetach)1329 void ViewAbstract::SetOnDetach(std::function<void()> &&onDetach)
1330 {
1331 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
1332 CHECK_NULL_VOID(eventHub);
1333 eventHub->SetOnDetach(std::move(onDetach));
1334 }
1335
SetOnAreaChanged(std::function<void (const RectF & oldRect,const OffsetF & oldOrigin,const RectF & rect,const OffsetF & origin)> && onAreaChanged)1336 void ViewAbstract::SetOnAreaChanged(
1337 std::function<void(const RectF& oldRect, const OffsetF& oldOrigin, const RectF& rect, const OffsetF& origin)>&&
1338 onAreaChanged)
1339 {
1340 auto pipeline = PipelineContext::GetCurrentContext();
1341 CHECK_NULL_VOID(pipeline);
1342 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1343 CHECK_NULL_VOID(frameNode);
1344 frameNode->SetOnAreaChangeCallback(std::move(onAreaChanged));
1345 pipeline->AddOnAreaChangeNode(frameNode->GetId());
1346 }
1347
SetOnSizeChanged(std::function<void (const RectF & oldRect,const RectF & rect)> && onSizeChanged)1348 void ViewAbstract::SetOnSizeChanged(std::function<void(const RectF &oldRect, const RectF &rect)> &&onSizeChanged)
1349 {
1350 auto pipeline = PipelineContext::GetCurrentContext();
1351 CHECK_NULL_VOID(pipeline);
1352 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1353 CHECK_NULL_VOID(frameNode);
1354 frameNode->SetOnSizeChangeCallback(std::move(onSizeChanged));
1355 }
1356
SetOnVisibleChange(std::function<void (bool,double)> && onVisibleChange,const std::vector<double> & ratioList)1357 void ViewAbstract::SetOnVisibleChange(std::function<void(bool, double)> &&onVisibleChange,
1358 const std::vector<double> &ratioList)
1359 {
1360 auto pipeline = PipelineContext::GetCurrentContext();
1361 CHECK_NULL_VOID(pipeline);
1362 auto frameNode = AceType::Claim(ViewStackProcessor::GetInstance()->GetMainFrameNode());
1363 CHECK_NULL_VOID(frameNode);
1364 frameNode->CleanVisibleAreaUserCallback();
1365 pipeline->AddVisibleAreaChangeNode(frameNode, ratioList, onVisibleChange);
1366 }
1367
SetOnVisibleChange(FrameNode * frameNode,std::function<void (bool,double)> && onVisibleChange,const std::vector<double> & ratioList)1368 void ViewAbstract::SetOnVisibleChange(FrameNode* frameNode, std::function<void(bool, double)>&& onVisibleChange,
1369 const std::vector<double> &ratioList)
1370 {
1371 CHECK_NULL_VOID(frameNode);
1372 auto pipeline = frameNode->GetContext();
1373 CHECK_NULL_VOID(pipeline);
1374 frameNode->CleanVisibleAreaUserCallback();
1375 pipeline->AddVisibleAreaChangeNode(AceType::Claim<FrameNode>(frameNode), ratioList, onVisibleChange);
1376 }
1377
GetColorBlend(FrameNode * frameNode)1378 Color ViewAbstract::GetColorBlend(FrameNode* frameNode)
1379 {
1380 Color defaultColor = Color::TRANSPARENT;
1381 CHECK_NULL_RETURN(frameNode, defaultColor);
1382 const auto& target = frameNode->GetRenderContext();
1383 CHECK_NULL_RETURN(target, defaultColor);
1384 return target->GetFrontColorBlendValue(defaultColor);
1385 }
1386
ResetAreaChanged(FrameNode * frameNode)1387 void ViewAbstract::ResetAreaChanged(FrameNode* frameNode)
1388 {
1389 CHECK_NULL_VOID(frameNode);
1390 auto pipeline = frameNode->GetContext();
1391 CHECK_NULL_VOID(pipeline);
1392 frameNode->ClearUserOnAreaChange();
1393 pipeline->RemoveOnAreaChangeNode(frameNode->GetId());
1394 }
1395
ResetVisibleChange(FrameNode * frameNode)1396 void ViewAbstract::ResetVisibleChange(FrameNode* frameNode)
1397 {
1398 CHECK_NULL_VOID(frameNode);
1399 auto pipeline = frameNode->GetContext();
1400 CHECK_NULL_VOID(pipeline);
1401 frameNode->CleanVisibleAreaUserCallback();
1402 pipeline->RemoveVisibleAreaChangeNode(frameNode->GetId());
1403 }
1404
SetResponseRegion(const std::vector<DimensionRect> & responseRegion)1405 void ViewAbstract::SetResponseRegion(const std::vector<DimensionRect>& responseRegion)
1406 {
1407 auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
1408 CHECK_NULL_VOID(gestureHub);
1409 gestureHub->SetResponseRegion(responseRegion);
1410 }
1411
SetMouseResponseRegion(const std::vector<DimensionRect> & mouseRegion)1412 void ViewAbstract::SetMouseResponseRegion(const std::vector<DimensionRect>& mouseRegion)
1413 {
1414 auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
1415 CHECK_NULL_VOID(gestureHub);
1416 gestureHub->SetMouseResponseRegion(mouseRegion);
1417 }
1418
SetTouchable(bool touchable)1419 void ViewAbstract::SetTouchable(bool touchable)
1420 {
1421 auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
1422 CHECK_NULL_VOID(gestureHub);
1423 gestureHub->SetTouchable(touchable);
1424 }
1425
SetMonopolizeEvents(bool monopolizeEvents)1426 void ViewAbstract::SetMonopolizeEvents(bool monopolizeEvents)
1427 {
1428 auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
1429 CHECK_NULL_VOID(gestureHub);
1430 gestureHub->SetMonopolizeEvents(monopolizeEvents);
1431 }
1432
SetHitTestMode(HitTestMode hitTestMode)1433 void ViewAbstract::SetHitTestMode(HitTestMode hitTestMode)
1434 {
1435 auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
1436 CHECK_NULL_VOID(gestureHub);
1437 gestureHub->SetHitTestMode(hitTestMode);
1438 }
1439
SetOnTouchTestFunc(NG::OnChildTouchTestFunc && onChildTouchTest)1440 void ViewAbstract::SetOnTouchTestFunc(NG::OnChildTouchTestFunc&& onChildTouchTest)
1441 {
1442 auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
1443 CHECK_NULL_VOID(gestureHub);
1444 gestureHub->SetOnTouchTestFunc(std::move(onChildTouchTest));
1445 }
1446
SetOnFocusAxisEvent(OnFocusAxisEventFunc && onFocusAxisCallback)1447 void ViewAbstract::SetOnFocusAxisEvent(OnFocusAxisEventFunc&& onFocusAxisCallback)
1448 {
1449 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
1450 CHECK_NULL_VOID(focusHub);
1451 focusHub->SetOnFocusAxisCallback(std::move(onFocusAxisCallback));
1452 }
1453
SetOnFocusAxisEvent(FrameNode * frameNode,OnFocusAxisEventFunc && onFocusAxisCallback)1454 void ViewAbstract::SetOnFocusAxisEvent(FrameNode* frameNode, OnFocusAxisEventFunc &&onFocusAxisCallback)
1455 {
1456 CHECK_NULL_VOID(frameNode);
1457 auto focusHub = frameNode->GetOrCreateFocusHub();
1458 focusHub->SetOnFocusAxisCallback(std::move(onFocusAxisCallback));
1459 }
1460
AddDragFrameNodeToManager()1461 void ViewAbstract::AddDragFrameNodeToManager()
1462 {
1463 auto pipeline = PipelineContext::GetCurrentContext();
1464 CHECK_NULL_VOID(pipeline);
1465 auto dragDropManager = pipeline->GetDragDropManager();
1466 CHECK_NULL_VOID(dragDropManager);
1467 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1468 CHECK_NULL_VOID(frameNode);
1469
1470 dragDropManager->AddDragFrameNode(frameNode->GetId(), AceType::WeakClaim(frameNode));
1471 }
1472
AddDragFrameNodeToManager(FrameNode * frameNode)1473 void ViewAbstract::AddDragFrameNodeToManager(FrameNode* frameNode)
1474 {
1475 CHECK_NULL_VOID(frameNode);
1476 auto pipeline = frameNode->GetContext();
1477 CHECK_NULL_VOID(pipeline);
1478 auto dragDropManager = pipeline->GetDragDropManager();
1479 CHECK_NULL_VOID(dragDropManager);
1480
1481 dragDropManager->AddDragFrameNode(frameNode->GetId(), AceType::WeakClaim(frameNode));
1482 }
1483
SetDraggable(bool draggable)1484 void ViewAbstract::SetDraggable(bool draggable)
1485 {
1486 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1487 CHECK_NULL_VOID(frameNode);
1488 auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
1489 CHECK_NULL_VOID(gestureHub);
1490 if (draggable) {
1491 if (!frameNode->IsDraggable()) {
1492 gestureHub->InitDragDropEvent();
1493 }
1494 } else {
1495 gestureHub->RemoveDragEvent();
1496 }
1497 frameNode->SetCustomerDraggable(draggable);
1498 }
1499
SetDragPreviewOptions(const DragPreviewOption & previewOption)1500 void ViewAbstract::SetDragPreviewOptions(const DragPreviewOption& previewOption)
1501 {
1502 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1503 CHECK_NULL_VOID(frameNode);
1504 frameNode->SetDragPreviewOptions(previewOption);
1505 }
1506
SetOnDragStart(std::function<DragDropInfo (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragStart)1507 void ViewAbstract::SetOnDragStart(
1508 std::function<DragDropInfo(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragStart)
1509 {
1510 auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
1511 CHECK_NULL_VOID(gestureHub);
1512 gestureHub->InitDragDropEvent();
1513
1514 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
1515 CHECK_NULL_VOID(eventHub);
1516 eventHub->SetOnDragStart(std::move(onDragStart));
1517 }
1518
SetOnDragStart(FrameNode * frameNode,std::function<DragDropInfo (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragStart)1519 void ViewAbstract::SetOnDragStart(FrameNode* frameNode,
1520 std::function<DragDropInfo(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragStart)
1521 {
1522 CHECK_NULL_VOID(frameNode);
1523 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
1524 CHECK_NULL_VOID(gestureHub);
1525 gestureHub->InitDragDropEvent();
1526
1527 auto eventHub = frameNode->GetEventHub<EventHub>();
1528 CHECK_NULL_VOID(eventHub);
1529 eventHub->SetOnDragStart(std::move(onDragStart));
1530 }
1531
SetOnDragEnter(FrameNode * frameNode,std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragEnter)1532 void ViewAbstract::SetOnDragEnter(FrameNode* frameNode,
1533 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragEnter)
1534 {
1535 CHECK_NULL_VOID(frameNode);
1536 auto eventHub = frameNode->GetEventHub<EventHub>();
1537 CHECK_NULL_VOID(eventHub);
1538 eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_ENTER, std::move(onDragEnter));
1539
1540 AddDragFrameNodeToManager(frameNode);
1541 }
1542
SetOnDragMove(FrameNode * frameNode,std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragMove)1543 void ViewAbstract::SetOnDragMove(FrameNode* frameNode,
1544 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragMove)
1545 {
1546 CHECK_NULL_VOID(frameNode);
1547 auto eventHub = frameNode->GetEventHub<EventHub>();
1548 CHECK_NULL_VOID(eventHub);
1549 eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_MOVE, std::move(onDragMove));
1550
1551 AddDragFrameNodeToManager(frameNode);
1552 }
1553
SetOnDragLeave(FrameNode * frameNode,std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragLeave)1554 void ViewAbstract::SetOnDragLeave(FrameNode* frameNode,
1555 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragLeave)
1556 {
1557 CHECK_NULL_VOID(frameNode);
1558 auto eventHub = frameNode->GetEventHub<EventHub>();
1559 CHECK_NULL_VOID(eventHub);
1560 eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_LEAVE, std::move(onDragLeave));
1561
1562 AddDragFrameNodeToManager(frameNode);
1563 }
1564
SetOnPreDrag(std::function<void (const PreDragStatus)> && onPreDragFunc)1565 void ViewAbstract::SetOnPreDrag(std::function<void(const PreDragStatus)>&& onPreDragFunc)
1566 {
1567 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
1568 CHECK_NULL_VOID(eventHub);
1569 eventHub->SetOnPreDrag(std::move(onPreDragFunc));
1570 }
1571
SetOnPreDrag(FrameNode * frameNode,std::function<void (const PreDragStatus)> && onPreDragFunc)1572 void ViewAbstract::SetOnPreDrag(FrameNode* frameNode, std::function<void(const PreDragStatus)>&& onPreDragFunc)
1573 {
1574 CHECK_NULL_VOID(frameNode);
1575 auto eventHub = frameNode->GetEventHub<EventHub>();
1576 CHECK_NULL_VOID(eventHub);
1577 eventHub->SetOnPreDrag(std::move(onPreDragFunc));
1578 }
1579
SetOnDragEnter(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragEnter)1580 void ViewAbstract::SetOnDragEnter(
1581 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragEnter)
1582 {
1583 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
1584 CHECK_NULL_VOID(eventHub);
1585 eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_ENTER, std::move(onDragEnter));
1586
1587 AddDragFrameNodeToManager();
1588 }
1589
SetOnDragLeave(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragLeave)1590 void ViewAbstract::SetOnDragLeave(
1591 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragLeave)
1592 {
1593 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
1594 CHECK_NULL_VOID(eventHub);
1595 eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_LEAVE, std::move(onDragLeave));
1596
1597 AddDragFrameNodeToManager();
1598 }
1599
SetOnDragMove(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDragMove)1600 void ViewAbstract::SetOnDragMove(
1601 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragMove)
1602 {
1603 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
1604 CHECK_NULL_VOID(eventHub);
1605 eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_MOVE, std::move(onDragMove));
1606
1607 AddDragFrameNodeToManager();
1608 }
1609
SetOnDrop(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDrop)1610 void ViewAbstract::SetOnDrop(std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDrop)
1611 {
1612 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
1613 CHECK_NULL_VOID(eventHub);
1614 eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_DROP, std::move(onDrop));
1615
1616 AddDragFrameNodeToManager();
1617 }
1618
SetOnDragEnd(std::function<void (const RefPtr<OHOS::Ace::DragEvent> &)> && onDragEnd)1619 void ViewAbstract::SetOnDragEnd(std::function<void(const RefPtr<OHOS::Ace::DragEvent>&)>&& onDragEnd)
1620 {
1621 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
1622 CHECK_NULL_VOID(eventHub);
1623 eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_END, std::move(onDragEnd));
1624
1625 AddDragFrameNodeToManager();
1626 }
1627
SetOnDragEnd(FrameNode * frameNode,std::function<void (const RefPtr<OHOS::Ace::DragEvent> &)> && onDragEnd)1628 void ViewAbstract::SetOnDragEnd(
1629 FrameNode* frameNode, std::function<void(const RefPtr<OHOS::Ace::DragEvent>&)>&& onDragEnd)
1630 {
1631 CHECK_NULL_VOID(frameNode);
1632 auto eventHub = frameNode->GetEventHub<EventHub>();
1633 CHECK_NULL_VOID(eventHub);
1634 eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_END, std::move(onDragEnd));
1635
1636 AddDragFrameNodeToManager(frameNode);
1637 }
1638
SetOnDrop(FrameNode * frameNode,std::function<void (const RefPtr<OHOS::Ace::DragEvent> &,const std::string &)> && onDrop)1639 void ViewAbstract::SetOnDrop(
1640 FrameNode* frameNode, std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDrop)
1641 {
1642 CHECK_NULL_VOID(frameNode);
1643 auto eventHub = frameNode->GetEventHub<EventHub>();
1644 CHECK_NULL_VOID(eventHub);
1645
1646 eventHub->SetCustomerOnDragFunc(DragFuncType::DRAG_DROP, std::move(onDrop));
1647
1648 AddDragFrameNodeToManager(frameNode);
1649 }
1650
SetAlign(Alignment alignment)1651 void ViewAbstract::SetAlign(Alignment alignment)
1652 {
1653 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1654 return;
1655 }
1656 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Alignment, alignment);
1657 }
1658
SetAlign(FrameNode * frameNode,Alignment alignment)1659 void ViewAbstract::SetAlign(FrameNode* frameNode, Alignment alignment)
1660 {
1661 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Alignment, alignment, frameNode);
1662 }
1663
SetVisibility(VisibleType visible)1664 void ViewAbstract::SetVisibility(VisibleType visible)
1665 {
1666 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1667 return;
1668 }
1669 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1670 CHECK_NULL_VOID(frameNode);
1671 auto layoutProperty = frameNode->GetLayoutProperty();
1672 if (layoutProperty) {
1673 layoutProperty->UpdateVisibility(visible, true);
1674 }
1675
1676 auto focusHub = frameNode->GetOrCreateFocusHub();
1677 if (focusHub) {
1678 focusHub->SetShow(visible == VisibleType::VISIBLE);
1679 }
1680 }
1681
SetGeometryTransition(const std::string & id,bool followWithoutTransition,bool doRegisterSharedTransition)1682 void ViewAbstract::SetGeometryTransition(const std::string& id,
1683 bool followWithoutTransition, bool doRegisterSharedTransition)
1684 {
1685 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1686 CHECK_NULL_VOID(frameNode);
1687 auto layoutProperty = frameNode->GetLayoutProperty();
1688 if (layoutProperty) {
1689 layoutProperty->UpdateGeometryTransition(id, followWithoutTransition, doRegisterSharedTransition);
1690 }
1691 }
1692
SetGeometryTransition(FrameNode * frameNode,const std::string & id,bool followWithoutTransition,bool doRegisterSharedTransition)1693 void ViewAbstract::SetGeometryTransition(FrameNode *frameNode, const std::string& id,
1694 bool followWithoutTransition, bool doRegisterSharedTransition)
1695 {
1696 CHECK_NULL_VOID(frameNode);
1697 auto layoutProperty = frameNode->GetLayoutProperty();
1698 if (layoutProperty) {
1699 layoutProperty->UpdateGeometryTransition(id, followWithoutTransition, doRegisterSharedTransition);
1700 }
1701 }
1702
GetGeometryTransition(FrameNode * frameNode,bool * followWithoutTransition,bool * doRegisterSharedTransition)1703 const std::string ViewAbstract::GetGeometryTransition(FrameNode* frameNode,
1704 bool* followWithoutTransition, bool* doRegisterSharedTransition)
1705 {
1706 CHECK_NULL_RETURN(frameNode, "");
1707 auto layoutProperty = frameNode->GetLayoutProperty();
1708 if (layoutProperty) {
1709 auto geometryTransition = layoutProperty->GetGeometryTransition();
1710 if (geometryTransition) {
1711 *followWithoutTransition = geometryTransition->GetFollowWithoutTransition();
1712 *doRegisterSharedTransition = geometryTransition->GetDoRegisterSharedTransition();
1713 return geometryTransition->GetId();
1714 }
1715 }
1716 return "";
1717 }
1718
SetOpacity(double opacity)1719 void ViewAbstract::SetOpacity(double opacity)
1720 {
1721 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1722 return;
1723 }
1724 ACE_UPDATE_RENDER_CONTEXT(Opacity, opacity);
1725 }
SetAllowDrop(const std::set<std::string> & allowDrop)1726 void ViewAbstract::SetAllowDrop(const std::set<std::string>& allowDrop)
1727 {
1728 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1729 CHECK_NULL_VOID(frameNode);
1730 frameNode->SetAllowDrop(allowDrop);
1731 }
1732
SetDrawModifier(const RefPtr<NG::DrawModifier> & drawModifier)1733 void ViewAbstract::SetDrawModifier(const RefPtr<NG::DrawModifier>& drawModifier)
1734 {
1735 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1736 CHECK_NULL_VOID(frameNode);
1737 frameNode->SetDrawModifier(drawModifier);
1738 }
1739
GetFrameNode()1740 void* ViewAbstract::GetFrameNode()
1741 {
1742 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1743 return static_cast<void*>(frameNode);
1744 }
1745
SetDragPreview(const NG::DragDropInfo & info)1746 void ViewAbstract::SetDragPreview(const NG::DragDropInfo& info)
1747 {
1748 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1749 CHECK_NULL_VOID(frameNode);
1750 frameNode->SetDragPreview(info);
1751 }
1752
SetPosition(const OffsetT<Dimension> & value)1753 void ViewAbstract::SetPosition(const OffsetT<Dimension>& value)
1754 {
1755 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1756 return;
1757 }
1758 ACE_RESET_RENDER_CONTEXT(RenderContext, PositionEdges);
1759 ACE_UPDATE_RENDER_CONTEXT(Position, value);
1760 }
1761
SetPositionEdges(const EdgesParam & value)1762 void ViewAbstract::SetPositionEdges(const EdgesParam& value)
1763 {
1764 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1765 return;
1766 }
1767 ACE_RESET_RENDER_CONTEXT(RenderContext, Position);
1768 ACE_UPDATE_RENDER_CONTEXT(PositionEdges, value);
1769 }
1770
SetOffset(const OffsetT<Dimension> & value)1771 void ViewAbstract::SetOffset(const OffsetT<Dimension>& value)
1772 {
1773 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1774 return;
1775 }
1776 ACE_RESET_RENDER_CONTEXT(RenderContext, OffsetEdges);
1777 ACE_UPDATE_RENDER_CONTEXT(Offset, value);
1778 }
1779
SetOffsetEdges(const EdgesParam & value)1780 void ViewAbstract::SetOffsetEdges(const EdgesParam& value)
1781 {
1782 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1783 return;
1784 }
1785 ACE_RESET_RENDER_CONTEXT(RenderContext, Offset);
1786 ACE_UPDATE_RENDER_CONTEXT(OffsetEdges, value);
1787 }
1788
MarkAnchor(const OffsetT<Dimension> & value)1789 void ViewAbstract::MarkAnchor(const OffsetT<Dimension>& value)
1790 {
1791 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1792 return;
1793 }
1794 ACE_UPDATE_RENDER_CONTEXT(Anchor, value);
1795 }
1796
ResetPosition()1797 void ViewAbstract::ResetPosition()
1798 {
1799 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1800 return;
1801 }
1802 ACE_RESET_RENDER_CONTEXT(RenderContext, Position);
1803 ACE_RESET_RENDER_CONTEXT(RenderContext, PositionEdges);
1804 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1805 CHECK_NULL_VOID(frameNode);
1806 auto parentNode = frameNode->GetAncestorNodeOfFrame(false);
1807 CHECK_NULL_VOID(parentNode);
1808
1809 // Row/Column/Flex measure and layout differently depending on whether the child nodes have position property.
1810 if (parentNode->GetTag() == V2::COLUMN_ETS_TAG || parentNode->GetTag() == V2::ROW_ETS_TAG ||
1811 parentNode->GetTag() == V2::FLEX_ETS_TAG) {
1812 frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
1813 } else {
1814 auto renderContext = frameNode->GetRenderContext();
1815 CHECK_NULL_VOID(renderContext);
1816 renderContext->RecalculatePosition();
1817 }
1818 }
1819
SetZIndex(int32_t value)1820 void ViewAbstract::SetZIndex(int32_t value)
1821 {
1822 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1823 return;
1824 }
1825 ACE_UPDATE_RENDER_CONTEXT(ZIndex, value);
1826 }
1827
SetScale(const NG::VectorF & value)1828 void ViewAbstract::SetScale(const NG::VectorF& value)
1829 {
1830 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1831 return;
1832 }
1833 ACE_UPDATE_RENDER_CONTEXT(TransformScale, value);
1834 }
1835
SetScale(FrameNode * frameNode,const NG::VectorF & value)1836 void ViewAbstract::SetScale(FrameNode* frameNode, const NG::VectorF& value)
1837 {
1838 ACE_UPDATE_NODE_RENDER_CONTEXT(TransformScale, value, frameNode);
1839 }
1840
SetPivot(const DimensionOffset & value)1841 void ViewAbstract::SetPivot(const DimensionOffset& value)
1842 {
1843 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1844 return;
1845 }
1846 ACE_UPDATE_RENDER_CONTEXT(TransformCenter, value);
1847 }
1848
SetPivot(FrameNode * frameNode,const DimensionOffset & value)1849 void ViewAbstract::SetPivot(FrameNode* frameNode, const DimensionOffset& value)
1850 {
1851 ACE_UPDATE_NODE_RENDER_CONTEXT(TransformCenter, value, frameNode);
1852 }
1853
SetTranslate(const NG::TranslateOptions & value)1854 void ViewAbstract::SetTranslate(const NG::TranslateOptions& value)
1855 {
1856 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1857 return;
1858 }
1859 ACE_UPDATE_RENDER_CONTEXT(TransformTranslate, value);
1860 }
1861
SetTranslate(FrameNode * frameNode,const NG::TranslateOptions & value)1862 void ViewAbstract::SetTranslate(FrameNode* frameNode, const NG::TranslateOptions& value)
1863 {
1864 ACE_UPDATE_NODE_RENDER_CONTEXT(TransformTranslate, value, frameNode);
1865 }
1866
SetRotate(const NG::Vector5F & value)1867 void ViewAbstract::SetRotate(const NG::Vector5F& value)
1868 {
1869 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1870 return;
1871 }
1872 ACE_UPDATE_RENDER_CONTEXT(TransformRotate, value);
1873 }
1874
SetRotate(FrameNode * frameNode,const NG::Vector5F & value)1875 void ViewAbstract::SetRotate(FrameNode* frameNode, const NG::Vector5F& value)
1876 {
1877 ACE_UPDATE_NODE_RENDER_CONTEXT(TransformRotate, value, frameNode);
1878 }
1879
SetTransformMatrix(const Matrix4 & matrix)1880 void ViewAbstract::SetTransformMatrix(const Matrix4& matrix)
1881 {
1882 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
1883 return;
1884 }
1885 ACE_UPDATE_RENDER_CONTEXT(TransformMatrix, matrix);
1886 }
1887
BindPopup(const RefPtr<PopupParam> & param,const RefPtr<FrameNode> & targetNode,const RefPtr<UINode> & customNode)1888 void ViewAbstract::BindPopup(
1889 const RefPtr<PopupParam>& param, const RefPtr<FrameNode>& targetNode, const RefPtr<UINode>& customNode)
1890 {
1891 TAG_LOGD(AceLogTag::ACE_DIALOG, "bind popup enter");
1892 CHECK_NULL_VOID(targetNode);
1893 auto targetId = targetNode->GetId();
1894 auto targetTag = targetNode->GetTag();
1895 auto context = targetNode->GetContext();
1896 CHECK_NULL_VOID(context);
1897 auto instanceId = context->GetInstanceId();
1898
1899 auto overlayManager = context->GetOverlayManager();
1900 CHECK_NULL_VOID(overlayManager);
1901 auto popupInfo = overlayManager->GetPopupInfo(targetId);
1902 auto isShow = param->IsShow();
1903 auto isUseCustom = param->IsUseCustom();
1904 auto showInSubWindow = param->IsShowInSubWindow();
1905 // subwindow model needs to use subContainer to get popupInfo
1906 if (showInSubWindow) {
1907 auto subwindow = SubwindowManager::GetInstance()->GetSubwindow(instanceId);
1908 if (subwindow) {
1909 subwindow->GetPopupInfoNG(targetId, popupInfo);
1910 }
1911 }
1912
1913 auto popupId = popupInfo.popupId;
1914 auto popupNode = popupInfo.popupNode;
1915 RefPtr<BubblePattern> popupPattern;
1916 if (popupNode) {
1917 popupPattern = popupNode->GetPattern<BubblePattern>();
1918 }
1919
1920 if (popupInfo.isCurrentOnShow) {
1921 // Entering / Normal / Exiting
1922 bool popupShowing = popupPattern ? popupPattern->IsOnShow() : false;
1923 popupInfo.markNeedUpdate = popupShowing || !isShow;
1924 } else {
1925 // Invisable
1926 if (!isShow) {
1927 TAG_LOGW(AceLogTag::ACE_DIALOG, "Popup is already hidden");
1928 return;
1929 }
1930 popupInfo.markNeedUpdate = true;
1931 }
1932
1933 // Create new popup.
1934 if (popupInfo.popupId == -1 || !popupNode) {
1935 if (!isUseCustom) {
1936 popupNode = BubbleView::CreateBubbleNode(targetTag, targetId, param);
1937 } else {
1938 CHECK_NULL_VOID(customNode);
1939 popupNode = BubbleView::CreateCustomBubbleNode(targetTag, targetId, customNode, param);
1940 }
1941 if (popupNode) {
1942 popupId = popupNode->GetId();
1943 }
1944 if (!showInSubWindow) {
1945 // erase popup when target node destroy
1946 auto destructor = [id = targetNode->GetId()]() {
1947 auto pipeline = NG::PipelineContext::GetCurrentContext();
1948 CHECK_NULL_VOID(pipeline);
1949 auto overlayManager = pipeline->GetOverlayManager();
1950 CHECK_NULL_VOID(overlayManager);
1951 overlayManager->ErasePopup(id);
1952 SubwindowManager::GetInstance()->HideSubWindowNG();
1953 };
1954 targetNode->PushDestroyCallback(destructor);
1955 } else {
1956 // erase popup in subwindow when target node destroy
1957 auto destructor = [id = targetNode->GetId(), containerId = instanceId]() {
1958 auto subwindow = SubwindowManager::GetInstance()->GetSubwindow(containerId);
1959 CHECK_NULL_VOID(subwindow);
1960 auto overlayManager = subwindow->GetOverlayManager();
1961 CHECK_NULL_VOID(overlayManager);
1962 overlayManager->ErasePopup(id);
1963 SubwindowManager::GetInstance()->HideSubWindowNG();
1964 };
1965 targetNode->PushDestroyCallback(destructor);
1966 }
1967 } else {
1968 // use param to update PopupParm
1969 if (!isUseCustom) {
1970 BubbleView::UpdatePopupParam(popupId, param, targetNode);
1971 popupNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
1972 } else {
1973 BubbleView::UpdateCustomPopupParam(popupId, param);
1974 popupNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
1975 }
1976 }
1977 // update PopupInfo props
1978 popupInfo.popupId = popupId;
1979 popupInfo.popupNode = popupNode;
1980 popupInfo.isBlockEvent = param->IsBlockEvent();
1981 popupInfo.isAvoidKeyboard = param->GetKeyBoardAvoidMode() == PopupKeyboardAvoidMode::DEFAULT;
1982 if (popupNode) {
1983 popupNode->MarkModifyDone();
1984 popupPattern = popupNode->GetPattern<BubblePattern>();
1985 auto accessibilityProperty = popupNode->GetAccessibilityProperty<NG::AccessibilityProperty>();
1986 if (accessibilityProperty) {
1987 accessibilityProperty->SetAccessibilityHoverPriority(param->IsBlockEvent());
1988 }
1989 }
1990 popupInfo.focusable = param->GetFocusable();
1991 popupInfo.target = AceType::WeakClaim(AceType::RawPtr(targetNode));
1992 popupInfo.targetSize = SizeF(param->GetTargetSize().Width(), param->GetTargetSize().Height());
1993 popupInfo.targetOffset = OffsetF(param->GetTargetOffset().GetX(), param->GetTargetOffset().GetY());
1994 if (showInSubWindow) {
1995 if (isShow) {
1996 SubwindowManager::GetInstance()->ShowPopupNG(
1997 targetNode, popupInfo, param->GetOnWillDismiss(), param->GetInteractiveDismiss());
1998 } else {
1999 SubwindowManager::GetInstance()->HidePopupNG(targetId);
2000 }
2001 return;
2002 }
2003 if (isShow) {
2004 if (popupInfo.isCurrentOnShow != isShow) {
2005 overlayManager->ShowPopup(targetId, popupInfo, param->GetOnWillDismiss(), param->GetInteractiveDismiss());
2006 }
2007 } else {
2008 overlayManager->HidePopup(targetId, popupInfo);
2009 }
2010 }
2011
DismissPopup()2012 void ViewAbstract::DismissPopup()
2013 {
2014 auto context = PipelineContext::GetCurrentContext();
2015 CHECK_NULL_VOID(context);
2016 auto overlayManager = context->GetOverlayManager();
2017 CHECK_NULL_VOID(overlayManager);
2018 overlayManager->DismissPopup();
2019 }
2020
DismissDialog()2021 void ViewAbstract::DismissDialog()
2022 {
2023 auto context = PipelineContext::GetCurrentContext();
2024 CHECK_NULL_VOID(context);
2025 auto overlayManager = context->GetOverlayManager();
2026 CHECK_NULL_VOID(overlayManager);
2027 auto rootNode = overlayManager->GetRootNode().Upgrade();
2028 CHECK_NULL_VOID(rootNode);
2029 RefPtr<FrameNode> dialogNode;
2030 auto dialogId = DialogManager::GetInstance().GetDismissDialogId();
2031 auto dialogTag = DialogManager::GetInstance().GetDialogTag();
2032 if (dialogId && !dialogTag.empty()) {
2033 dialogNode = FrameNode::GetFrameNode(dialogTag, dialogId);
2034 }
2035 if (!dialogNode) {
2036 if (overlayManager->GetDismissDialogId()) {
2037 dialogNode = overlayManager->GetDialog(overlayManager->GetDismissDialogId());
2038 } else {
2039 dialogNode = AceType::DynamicCast<FrameNode>(rootNode->GetLastChild());
2040 }
2041 }
2042 CHECK_NULL_VOID(dialogNode);
2043 auto pattern = dialogNode->GetPattern();
2044 CHECK_NULL_VOID(pattern);
2045 auto dialogPattern = AceType::DynamicCast<DialogPattern>(pattern);
2046 if (dialogPattern) {
2047 dialogPattern->OverlayDismissDialog(dialogNode);
2048 #if !defined(PREVIEW) && !defined(ACE_UNITTEST) && defined(OHOS_PLATFORM)
2049 UiSessionManager::GetInstance().ReportComponentChangeEvent("onVisibleChange", "destroy");
2050 #endif
2051 }
2052 }
2053
BindMenuWithItems(std::vector<OptionParam> && params,const RefPtr<FrameNode> & targetNode,const NG::OffsetF & offset,const MenuParam & menuParam)2054 void ViewAbstract::BindMenuWithItems(std::vector<OptionParam>&& params, const RefPtr<FrameNode>& targetNode,
2055 const NG::OffsetF& offset, const MenuParam& menuParam)
2056 {
2057 TAG_LOGD(AceLogTag::ACE_DIALOG, "bind menu with items enter");
2058 CHECK_NULL_VOID(targetNode);
2059
2060 if (params.empty()) {
2061 return;
2062 }
2063 auto menuNode =
2064 MenuView::Create(std::move(params), targetNode->GetId(), targetNode->GetTag(), MenuType::MENU, menuParam);
2065 CHECK_NULL_VOID(menuNode);
2066 auto menuWrapperPattern = menuNode->GetPattern<MenuWrapperPattern>();
2067 CHECK_NULL_VOID(menuWrapperPattern);
2068 menuWrapperPattern->RegisterMenuCallback(menuNode, menuParam);
2069 menuWrapperPattern->SetMenuTransitionEffect(menuNode, menuParam);
2070 auto pipeline = PipelineBase::GetCurrentContext();
2071 CHECK_NULL_VOID(pipeline);
2072 auto theme = pipeline->GetTheme<SelectTheme>();
2073 CHECK_NULL_VOID(theme);
2074 auto expandDisplay = theme->GetExpandDisplay();
2075
2076 auto pipelineContext = targetNode->GetContext();
2077 CHECK_NULL_VOID(pipelineContext);
2078 auto overlayManager = pipelineContext->GetOverlayManager();
2079 CHECK_NULL_VOID(overlayManager);
2080
2081 if (expandDisplay && menuParam.isShowInSubWindow && targetNode->GetTag() != V2::SELECT_ETS_TAG) {
2082 bool isShown = SubwindowManager::GetInstance()->GetShown();
2083 if (!isShown) {
2084 SubwindowManager::GetInstance()->ShowMenuNG(menuNode, menuParam, targetNode, offset);
2085 } else {
2086 auto menuNode = overlayManager->GetMenuNode(targetNode->GetId());
2087 SubwindowManager::GetInstance()->HideMenuNG(menuNode, targetNode->GetId());
2088 }
2089 return;
2090 }
2091
2092 overlayManager->ShowMenu(targetNode->GetId(), offset, menuNode);
2093 }
2094
BindMenuWithCustomNode(std::function<void ()> && buildFunc,const RefPtr<FrameNode> & targetNode,const NG::OffsetF & offset,MenuParam menuParam,std::function<void ()> && previewBuildFunc)2095 void ViewAbstract::BindMenuWithCustomNode(std::function<void()>&& buildFunc, const RefPtr<FrameNode>& targetNode,
2096 const NG::OffsetF& offset, MenuParam menuParam, std::function<void()>&& previewBuildFunc)
2097 {
2098 if (!buildFunc || !targetNode) {
2099 return;
2100 }
2101 #ifdef PREVIEW
2102 // unable to use the subWindow in the Previewer.
2103 menuParam.type = MenuType::MENU;
2104 #endif
2105 TAG_LOGD(AceLogTag::ACE_DIALOG, "bind menu with custom node enter");
2106 auto pipeline = PipelineBase::GetCurrentContext();
2107 CHECK_NULL_VOID(pipeline);
2108 auto theme = pipeline->GetTheme<SelectTheme>();
2109 CHECK_NULL_VOID(theme);
2110 auto expandDisplay = theme->GetExpandDisplay();
2111 auto pipelineContext = targetNode->GetContext();
2112 CHECK_NULL_VOID(pipelineContext);
2113 auto overlayManager = pipelineContext->GetOverlayManager();
2114 CHECK_NULL_VOID(overlayManager);
2115 if (menuParam.type == MenuType::CONTEXT_MENU) {
2116 SubwindowManager::GetInstance()->ShowMenuNG(
2117 std::move(buildFunc), std::move(previewBuildFunc), menuParam, targetNode, offset);
2118 return;
2119 }
2120 if (menuParam.type == MenuType::MENU && expandDisplay && menuParam.isShowInSubWindow &&
2121 targetNode->GetTag() != V2::SELECT_ETS_TAG) {
2122 bool isShown = SubwindowManager::GetInstance()->GetShown();
2123 if (!isShown) {
2124 SubwindowManager::GetInstance()->ShowMenuNG(
2125 std::move(buildFunc), std::move(previewBuildFunc), menuParam, targetNode, offset);
2126 } else {
2127 auto menuNode = overlayManager->GetMenuNode(targetNode->GetId());
2128 SubwindowManager::GetInstance()->HideMenuNG(menuNode, targetNode->GetId());
2129 }
2130 return;
2131 }
2132 NG::ScopedViewStackProcessor builderViewStackProcessor;
2133 buildFunc();
2134 auto customNode = NG::ViewStackProcessor::GetInstance()->Finish();
2135 RefPtr<NG::UINode> previewCustomNode;
2136 if (previewBuildFunc && menuParam.previewMode == MenuPreviewMode::CUSTOM) {
2137 previewBuildFunc();
2138 previewCustomNode = NG::ViewStackProcessor::GetInstance()->Finish();
2139 }
2140 auto menuNode =
2141 NG::MenuView::Create(customNode, targetNode->GetId(), targetNode->GetTag(), menuParam, true, previewCustomNode);
2142 auto menuWrapperPattern = menuNode->GetPattern<NG::MenuWrapperPattern>();
2143 CHECK_NULL_VOID(menuWrapperPattern);
2144 menuWrapperPattern->RegisterMenuCallback(menuNode, menuParam);
2145 menuWrapperPattern->SetMenuTransitionEffect(menuNode, menuParam);
2146 overlayManager->ShowMenu(targetNode->GetId(), offset, menuNode);
2147 }
2148
SetBackdropBlur(const Dimension & radius,const BlurOption & blurOption)2149 void ViewAbstract::SetBackdropBlur(const Dimension& radius, const BlurOption& blurOption)
2150 {
2151 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2152 return;
2153 }
2154 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2155 CHECK_NULL_VOID(frameNode);
2156 auto target = frameNode->GetRenderContext();
2157 if (target) {
2158 if (target->GetBackgroundEffect().has_value()) {
2159 target->UpdateBackgroundEffect(std::nullopt);
2160 }
2161 target->UpdateBackBlur(radius, blurOption);
2162 if (target->GetBackBlurStyle().has_value()) {
2163 target->UpdateBackBlurStyle(std::nullopt);
2164 }
2165 }
2166 }
2167
SetNodeBackdropBlur(FrameNode * frameNode,const Dimension & radius,const BlurOption & blurOption)2168 void ViewAbstract::SetNodeBackdropBlur(FrameNode *frameNode, const Dimension& radius, const BlurOption& blurOption)
2169 {
2170 CHECK_NULL_VOID(frameNode);
2171 auto target = frameNode->GetRenderContext();
2172 if (target) {
2173 if (target->GetBackgroundEffect().has_value()) {
2174 target->UpdateBackgroundEffect(std::nullopt);
2175 }
2176 if (target->GetBackBlurStyle().has_value()) {
2177 target->UpdateBackBlurStyle(std::nullopt);
2178 }
2179 target->UpdateNodeBackBlur(radius, blurOption);
2180 }
2181 }
2182
SetBackdropBlur(FrameNode * frameNode,const Dimension & radius,const BlurOption & blurOption)2183 void ViewAbstract::SetBackdropBlur(FrameNode *frameNode, const Dimension &radius, const BlurOption &blurOption)
2184 {
2185 CHECK_NULL_VOID(frameNode);
2186 auto target = frameNode->GetRenderContext();
2187 if (target) {
2188 if (target->GetBackgroundEffect().has_value()) {
2189 target->UpdateBackgroundEffect(std::nullopt);
2190 }
2191 target->UpdateBackBlur(radius, blurOption);
2192 if (target->GetBackBlurStyle().has_value()) {
2193 target->UpdateBackBlurStyle(std::nullopt);
2194 }
2195 }
2196 }
2197
SetLinearGradientBlur(const NG::LinearGradientBlurPara & blurPara)2198 void ViewAbstract::SetLinearGradientBlur(const NG::LinearGradientBlurPara& blurPara)
2199 {
2200 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2201 return;
2202 }
2203 ACE_UPDATE_RENDER_CONTEXT(LinearGradientBlur, blurPara);
2204 }
2205
SetDynamicLightUp(float rate,float lightUpDegree)2206 void ViewAbstract::SetDynamicLightUp(float rate, float lightUpDegree)
2207 {
2208 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2209 return;
2210 }
2211 ACE_UPDATE_RENDER_CONTEXT(DynamicLightUpRate, rate);
2212 ACE_UPDATE_RENDER_CONTEXT(DynamicLightUpDegree, lightUpDegree);
2213 }
2214
SetBgDynamicBrightness(const BrightnessOption & brightnessOption)2215 void ViewAbstract::SetBgDynamicBrightness(const BrightnessOption& brightnessOption)
2216 {
2217 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2218 return;
2219 }
2220 ACE_UPDATE_RENDER_CONTEXT(BgDynamicBrightnessOption, brightnessOption);
2221 }
2222
SetFgDynamicBrightness(const BrightnessOption & brightnessOption)2223 void ViewAbstract::SetFgDynamicBrightness(const BrightnessOption& brightnessOption)
2224 {
2225 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2226 return;
2227 }
2228 ACE_UPDATE_RENDER_CONTEXT(FgDynamicBrightnessOption, brightnessOption);
2229 }
2230
SetBrightnessBlender(const OHOS::Rosen::BrightnessBlender * brightnessBlender)2231 void ViewAbstract::SetBrightnessBlender(const OHOS::Rosen::BrightnessBlender* brightnessBlender)
2232 {
2233 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2234 return;
2235 }
2236 ACE_UPDATE_RENDER_CONTEXT(BrightnessBlender, brightnessBlender);
2237 }
2238
SetFrontBlur(const Dimension & radius,const BlurOption & blurOption)2239 void ViewAbstract::SetFrontBlur(const Dimension& radius, const BlurOption& blurOption)
2240 {
2241 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2242 return;
2243 }
2244 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2245 CHECK_NULL_VOID(frameNode);
2246 auto target = frameNode->GetRenderContext();
2247 if (target) {
2248 target->UpdateFrontBlur(radius, blurOption);
2249 if (target->GetFrontBlurStyle().has_value()) {
2250 target->UpdateFrontBlurStyle(std::nullopt);
2251 }
2252 }
2253 }
2254
SetDynamicDim(float DimDegree)2255 void ViewAbstract::SetDynamicDim(float DimDegree)
2256 {
2257 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2258 return;
2259 }
2260 ACE_UPDATE_RENDER_CONTEXT(DynamicDimDegree, DimDegree);
2261 }
2262
SetFrontBlur(FrameNode * frameNode,const Dimension & radius,const BlurOption & blurOption)2263 void ViewAbstract::SetFrontBlur(FrameNode *frameNode, const Dimension &radius, const BlurOption &blurOption)
2264 {
2265 CHECK_NULL_VOID(frameNode);
2266 auto target = frameNode->GetRenderContext();
2267 if (target) {
2268 target->UpdateFrontBlur(radius, blurOption);
2269 if (target->GetFrontBlurStyle().has_value()) {
2270 target->UpdateFrontBlurStyle(std::nullopt);
2271 }
2272 }
2273 }
2274
SetBackShadow(const Shadow & shadow)2275 void ViewAbstract::SetBackShadow(const Shadow& shadow)
2276 {
2277 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2278 return;
2279 }
2280 ACE_UPDATE_RENDER_CONTEXT(BackShadow, shadow);
2281 }
2282
SetBackShadow(FrameNode * frameNode,const Shadow & shadow)2283 void ViewAbstract::SetBackShadow(FrameNode* frameNode, const Shadow& shadow)
2284 {
2285 ACE_UPDATE_NODE_RENDER_CONTEXT(BackShadow, shadow, frameNode);
2286 }
2287
SetBlendMode(BlendMode blendMode)2288 void ViewAbstract::SetBlendMode(BlendMode blendMode)
2289 {
2290 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2291 return;
2292 }
2293 ACE_UPDATE_RENDER_CONTEXT(BackBlendMode, blendMode);
2294 }
2295
SetBlendApplyType(BlendApplyType blendApplyType)2296 void ViewAbstract::SetBlendApplyType(BlendApplyType blendApplyType)
2297 {
2298 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2299 return;
2300 }
2301 ACE_UPDATE_RENDER_CONTEXT(BackBlendApplyType, blendApplyType);
2302 }
2303
SetLinearGradient(const NG::Gradient & gradient)2304 void ViewAbstract::SetLinearGradient(const NG::Gradient& gradient)
2305 {
2306 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2307 return;
2308 }
2309 ACE_UPDATE_RENDER_CONTEXT(LastGradientType, NG::GradientType::LINEAR);
2310 ACE_UPDATE_RENDER_CONTEXT(LinearGradient, gradient);
2311 }
2312
SetSweepGradient(const NG::Gradient & gradient)2313 void ViewAbstract::SetSweepGradient(const NG::Gradient& gradient)
2314 {
2315 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2316 return;
2317 }
2318 ACE_UPDATE_RENDER_CONTEXT(LastGradientType, NG::GradientType::SWEEP);
2319 ACE_UPDATE_RENDER_CONTEXT(SweepGradient, gradient);
2320 }
2321
SetRadialGradient(const NG::Gradient & gradient)2322 void ViewAbstract::SetRadialGradient(const NG::Gradient& gradient)
2323 {
2324 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2325 return;
2326 }
2327 ACE_UPDATE_RENDER_CONTEXT(LastGradientType, NG::GradientType::RADIAL);
2328 ACE_UPDATE_RENDER_CONTEXT(RadialGradient, gradient);
2329 }
2330
SetInspectorId(const std::string & inspectorId)2331 void ViewAbstract::SetInspectorId(const std::string& inspectorId)
2332 {
2333 auto& uiNode = ViewStackProcessor::GetInstance()->GetMainElementNode();
2334 if (uiNode) {
2335 if (uiNode->GetInspectorId().has_value() && uiNode->GetInspectorIdValue() != inspectorId) {
2336 ElementRegister::GetInstance()->RemoveFrameNodeByInspectorId(
2337 uiNode->GetInspectorIdValue(), uiNode->GetId());
2338 }
2339 uiNode->UpdateInspectorId(inspectorId);
2340 }
2341 }
2342
SetAutoEventParam(const std::string & param)2343 void ViewAbstract::SetAutoEventParam(const std::string& param)
2344 {
2345 auto& uiNode = ViewStackProcessor::GetInstance()->GetMainElementNode();
2346 if (uiNode) {
2347 uiNode->UpdateAutoEventParam(param);
2348 }
2349 }
2350
SetRestoreId(int32_t restoreId)2351 void ViewAbstract::SetRestoreId(int32_t restoreId)
2352 {
2353 auto& uiNode = ViewStackProcessor::GetInstance()->GetMainElementNode();
2354 if (uiNode) {
2355 uiNode->SetRestoreId(restoreId);
2356 }
2357 }
2358
SetDebugLine(const std::string & line)2359 void ViewAbstract::SetDebugLine(const std::string& line)
2360 {
2361 auto& uiNode = ViewStackProcessor::GetInstance()->GetMainElementNode();
2362 if (uiNode) {
2363 uiNode->SetDebugLine(line);
2364 }
2365 }
2366
SetGrid(std::optional<int32_t> span,std::optional<int32_t> offset,GridSizeType type)2367 void ViewAbstract::SetGrid(std::optional<int32_t> span, std::optional<int32_t> offset, GridSizeType type)
2368 {
2369 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2370 CHECK_NULL_VOID(frameNode);
2371 auto layoutProperty = frameNode->GetLayoutProperty();
2372 CHECK_NULL_VOID(layoutProperty);
2373 // frame node is mounted to parent when pop from stack later, no grid-container is added here
2374 layoutProperty->UpdateGridProperty(span, offset, type);
2375 }
2376
Pop()2377 void ViewAbstract::Pop()
2378 {
2379 ViewStackProcessor::GetInstance()->Pop();
2380 }
2381
SetTransition(const TransitionOptions & options)2382 void ViewAbstract::SetTransition(const TransitionOptions& options)
2383 {
2384 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2385 return;
2386 }
2387 ACE_UPDATE_RENDER_CONTEXT(Transition, options);
2388 }
2389
CleanTransition()2390 void ViewAbstract::CleanTransition()
2391 {
2392 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2393 return;
2394 }
2395 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2396 CHECK_NULL_VOID(frameNode);
2397 auto target = frameNode->GetRenderContext();
2398 if (target) {
2399 target->CleanTransition();
2400 }
2401 }
2402
SetChainedTransition(const RefPtr<NG::ChainedTransitionEffect> & effect,NG::TransitionFinishCallback && finishCallback)2403 void ViewAbstract::SetChainedTransition(
2404 const RefPtr<NG::ChainedTransitionEffect>& effect, NG::TransitionFinishCallback&& finishCallback)
2405 {
2406 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2407 return;
2408 }
2409 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2410 CHECK_NULL_VOID(frameNode);
2411 const auto& target = frameNode->GetRenderContext();
2412 if (target) {
2413 target->UpdateChainedTransition(effect);
2414 target->SetTransitionUserCallback(std::move(finishCallback));
2415 }
2416 }
2417
SetClipShape(const RefPtr<BasicShape> & basicShape)2418 void ViewAbstract::SetClipShape(const RefPtr<BasicShape>& basicShape)
2419 {
2420 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2421 return;
2422 }
2423 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2424 CHECK_NULL_VOID(frameNode);
2425 auto target = frameNode->GetRenderContext();
2426 if (target) {
2427 if (target->GetClipEdge().has_value()) {
2428 target->UpdateClipEdge(false);
2429 }
2430 target->UpdateClipShape(basicShape);
2431 }
2432 }
2433
SetClipShape(FrameNode * frameNode,const RefPtr<BasicShape> & basicShape)2434 void ViewAbstract::SetClipShape(FrameNode* frameNode, const RefPtr<BasicShape>& basicShape)
2435 {
2436 CHECK_NULL_VOID(frameNode);
2437 auto target = frameNode->GetRenderContext();
2438 if (target) {
2439 if (target->GetClipEdge().has_value()) {
2440 target->UpdateClipEdge(false);
2441 }
2442 target->UpdateClipShape(basicShape);
2443 }
2444 }
2445
SetClipEdge(bool isClip)2446 void ViewAbstract::SetClipEdge(bool isClip)
2447 {
2448 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2449 return;
2450 }
2451 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2452 CHECK_NULL_VOID(frameNode);
2453 auto target = frameNode->GetRenderContext();
2454 if (target) {
2455 if (target->GetClipShape().has_value()) {
2456 target->ResetClipShape();
2457 target->OnClipShapeUpdate(nullptr);
2458 }
2459 target->UpdateClipEdge(isClip);
2460 }
2461 }
2462
SetClipEdge(FrameNode * frameNode,bool isClip)2463 void ViewAbstract::SetClipEdge(FrameNode* frameNode, bool isClip)
2464 {
2465 CHECK_NULL_VOID(frameNode);
2466 auto target = frameNode->GetRenderContext();
2467 if (target) {
2468 if (target->GetClipShape().has_value()) {
2469 target->ResetClipShape();
2470 target->OnClipShapeUpdate(nullptr);
2471 }
2472 target->UpdateClipEdge(isClip);
2473 }
2474 }
2475
SetMask(const RefPtr<BasicShape> & basicShape)2476 void ViewAbstract::SetMask(const RefPtr<BasicShape>& basicShape)
2477 {
2478 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2479 return;
2480 }
2481 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2482 CHECK_NULL_VOID(frameNode);
2483 auto target = frameNode->GetRenderContext();
2484 if (target) {
2485 if (target->HasProgressMask()) {
2486 target->ResetProgressMask();
2487 target->OnProgressMaskUpdate(nullptr);
2488 }
2489 target->UpdateClipMask(basicShape);
2490 }
2491 }
2492
SetProgressMask(const RefPtr<ProgressMaskProperty> & progress)2493 void ViewAbstract::SetProgressMask(const RefPtr<ProgressMaskProperty>& progress)
2494 {
2495 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2496 return;
2497 }
2498 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2499 CHECK_NULL_VOID(frameNode);
2500 auto target = frameNode->GetRenderContext();
2501 if (target) {
2502 if (target->HasClipMask()) {
2503 target->ResetClipMask();
2504 target->OnClipMaskUpdate(nullptr);
2505 }
2506 target->UpdateProgressMask(progress);
2507 }
2508 }
2509
SetBrightness(const Dimension & brightness)2510 void ViewAbstract::SetBrightness(const Dimension& brightness)
2511 {
2512 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2513 return;
2514 }
2515 ACE_UPDATE_RENDER_CONTEXT(FrontBrightness, brightness);
2516 }
2517
SetBrightness(FrameNode * frameNode,const Dimension & brightness)2518 void ViewAbstract::SetBrightness(FrameNode* frameNode, const Dimension& brightness)
2519 {
2520 ACE_UPDATE_NODE_RENDER_CONTEXT(FrontBrightness, brightness, frameNode);
2521 }
2522
SetGrayScale(const Dimension & grayScale)2523 void ViewAbstract::SetGrayScale(const Dimension& grayScale)
2524 {
2525 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2526 return;
2527 }
2528 ACE_UPDATE_RENDER_CONTEXT(FrontGrayScale, grayScale);
2529 }
2530
SetGrayScale(FrameNode * frameNode,const Dimension & grayScale)2531 void ViewAbstract::SetGrayScale(FrameNode* frameNode, const Dimension& grayScale)
2532 {
2533 ACE_UPDATE_NODE_RENDER_CONTEXT(FrontGrayScale, grayScale, frameNode);
2534 }
2535
SetContrast(const Dimension & contrast)2536 void ViewAbstract::SetContrast(const Dimension& contrast)
2537 {
2538 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2539 return;
2540 }
2541 ACE_UPDATE_RENDER_CONTEXT(FrontContrast, contrast);
2542 }
2543
SetContrast(FrameNode * frameNode,const Dimension & contrast)2544 void ViewAbstract::SetContrast(FrameNode* frameNode, const Dimension& contrast)
2545 {
2546 ACE_UPDATE_NODE_RENDER_CONTEXT(FrontContrast, contrast, frameNode);
2547 }
2548
SetSaturate(const Dimension & saturate)2549 void ViewAbstract::SetSaturate(const Dimension& saturate)
2550 {
2551 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2552 return;
2553 }
2554 ACE_UPDATE_RENDER_CONTEXT(FrontSaturate, saturate);
2555 }
2556
SetSaturate(FrameNode * frameNode,const Dimension & saturate)2557 void ViewAbstract::SetSaturate(FrameNode* frameNode, const Dimension& saturate)
2558 {
2559 ACE_UPDATE_NODE_RENDER_CONTEXT(FrontSaturate, saturate, frameNode);
2560 }
2561
SetSepia(const Dimension & sepia)2562 void ViewAbstract::SetSepia(const Dimension& sepia)
2563 {
2564 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2565 return;
2566 }
2567 ACE_UPDATE_RENDER_CONTEXT(FrontSepia, sepia);
2568 }
2569
SetSepia(FrameNode * frameNode,const Dimension & sepia)2570 void ViewAbstract::SetSepia(FrameNode* frameNode, const Dimension& sepia)
2571 {
2572 ACE_UPDATE_NODE_RENDER_CONTEXT(FrontSepia, sepia, frameNode);
2573 }
2574
SetInvert(const InvertVariant & invert)2575 void ViewAbstract::SetInvert(const InvertVariant& invert)
2576 {
2577 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2578 return;
2579 }
2580 ACE_UPDATE_RENDER_CONTEXT(FrontInvert, invert);
2581 }
2582
SetInvert(FrameNode * frameNode,const InvertVariant & invert)2583 void ViewAbstract::SetInvert(FrameNode* frameNode, const InvertVariant& invert)
2584 {
2585 ACE_UPDATE_NODE_RENDER_CONTEXT(FrontInvert, invert, frameNode);
2586 }
2587
SetSystemBarEffect(bool systemBarEffect)2588 void ViewAbstract::SetSystemBarEffect(bool systemBarEffect)
2589 {
2590 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2591 return;
2592 }
2593 ACE_UPDATE_RENDER_CONTEXT(SystemBarEffect, systemBarEffect);
2594 }
2595
SetSystemBarEffect(FrameNode * frameNode,bool enable)2596 void ViewAbstract::SetSystemBarEffect(FrameNode *frameNode, bool enable)
2597 {
2598 ACE_UPDATE_NODE_RENDER_CONTEXT(SystemBarEffect, enable, frameNode);
2599 }
2600
SetHueRotate(float hueRotate)2601 void ViewAbstract::SetHueRotate(float hueRotate)
2602 {
2603 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2604 return;
2605 }
2606 ACE_UPDATE_RENDER_CONTEXT(FrontHueRotate, hueRotate);
2607 }
2608
SetHueRotate(FrameNode * frameNode,float hueRotate)2609 void ViewAbstract::SetHueRotate(FrameNode* frameNode, float hueRotate)
2610 {
2611 ACE_UPDATE_NODE_RENDER_CONTEXT(FrontHueRotate, hueRotate, frameNode);
2612 }
2613
SetColorBlend(const Color & colorBlend)2614 void ViewAbstract::SetColorBlend(const Color& colorBlend)
2615 {
2616 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2617 return;
2618 }
2619 ACE_UPDATE_RENDER_CONTEXT(FrontColorBlend, colorBlend);
2620 }
2621
SetColorBlend(FrameNode * frameNode,const Color & colorBlend)2622 void ViewAbstract::SetColorBlend(FrameNode* frameNode, const Color& colorBlend)
2623 {
2624 ACE_UPDATE_NODE_RENDER_CONTEXT(FrontColorBlend, colorBlend, frameNode);
2625 }
2626
SetBorderImage(const RefPtr<BorderImage> & borderImage)2627 void ViewAbstract::SetBorderImage(const RefPtr<BorderImage>& borderImage)
2628 {
2629 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2630 return;
2631 }
2632 ACE_UPDATE_RENDER_CONTEXT(BorderImage, borderImage);
2633 }
2634
SetBorderImageSource(const std::string & bdImageSrc,const std::string & bundleName,const std::string & moduleName)2635 void ViewAbstract::SetBorderImageSource(
2636 const std::string& bdImageSrc, const std::string& bundleName, const std::string& moduleName)
2637 {
2638 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2639 return;
2640 }
2641 ImageSourceInfo imageSourceInfo(bdImageSrc, bundleName, moduleName);
2642 ACE_UPDATE_RENDER_CONTEXT(BorderImageSource, imageSourceInfo);
2643 ACE_UPDATE_RENDER_CONTEXT(BorderSourceFromImage, true);
2644 }
2645
SetHasBorderImageSlice(bool tag)2646 void ViewAbstract::SetHasBorderImageSlice(bool tag)
2647 {
2648 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2649 return;
2650 }
2651 ACE_UPDATE_RENDER_CONTEXT(HasBorderImageSlice, tag);
2652 }
2653
SetHasBorderImageWidth(bool tag)2654 void ViewAbstract::SetHasBorderImageWidth(bool tag)
2655 {
2656 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2657 return;
2658 }
2659 ACE_UPDATE_RENDER_CONTEXT(HasBorderImageWidth, tag);
2660 }
2661
SetHasBorderImageOutset(bool tag)2662 void ViewAbstract::SetHasBorderImageOutset(bool tag)
2663 {
2664 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2665 return;
2666 }
2667 ACE_UPDATE_RENDER_CONTEXT(HasBorderImageOutset, tag);
2668 }
2669
SetHasBorderImageRepeat(bool tag)2670 void ViewAbstract::SetHasBorderImageRepeat(bool tag)
2671 {
2672 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2673 return;
2674 }
2675 ACE_UPDATE_RENDER_CONTEXT(HasBorderImageRepeat, tag);
2676 }
2677
SetBorderImageGradient(const Gradient & gradient)2678 void ViewAbstract::SetBorderImageGradient(const Gradient& gradient)
2679 {
2680 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2681 return;
2682 }
2683 ACE_UPDATE_RENDER_CONTEXT(BorderImageGradient, gradient);
2684 ACE_UPDATE_RENDER_CONTEXT(BorderSourceFromImage, false);
2685 }
2686
SetVisualEffect(const OHOS::Rosen::VisualEffect * visualEffect)2687 void ViewAbstract::SetVisualEffect(const OHOS::Rosen::VisualEffect* visualEffect)
2688 {
2689 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2690 return;
2691 }
2692 ACE_UPDATE_RENDER_CONTEXT(VisualEffect, visualEffect);
2693 }
2694
SetBackgroundFilter(const OHOS::Rosen::Filter * backgroundFilter)2695 void ViewAbstract::SetBackgroundFilter(const OHOS::Rosen::Filter* backgroundFilter)
2696 {
2697 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2698 return;
2699 }
2700 ACE_UPDATE_RENDER_CONTEXT(BackgroundFilter, backgroundFilter);
2701 }
2702
SetForegroundFilter(const OHOS::Rosen::Filter * foregroundFilter)2703 void ViewAbstract::SetForegroundFilter(const OHOS::Rosen::Filter* foregroundFilter)
2704 {
2705 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2706 return;
2707 }
2708 ACE_UPDATE_RENDER_CONTEXT(ForegroundFilter, foregroundFilter);
2709 }
2710
SetCompositingFilter(const OHOS::Rosen::Filter * compositingFilter)2711 void ViewAbstract::SetCompositingFilter(const OHOS::Rosen::Filter* compositingFilter)
2712 {
2713 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2714 return;
2715 }
2716 ACE_UPDATE_RENDER_CONTEXT(CompositingFilter, compositingFilter);
2717 }
2718
SetOverlay(const OverlayOptions & overlay)2719 void ViewAbstract::SetOverlay(const OverlayOptions& overlay)
2720 {
2721 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2722 return;
2723 }
2724 ACE_UPDATE_RENDER_CONTEXT(OverlayText, overlay);
2725 }
2726
SetOverlayBuilder(std::function<void ()> && buildFunc,const std::optional<Alignment> & align,const std::optional<Dimension> & offsetX,const std::optional<Dimension> & offsetY)2727 void ViewAbstract::SetOverlayBuilder(std::function<void()>&& buildFunc,
2728 const std::optional<Alignment>& align, const std::optional<Dimension>& offsetX,
2729 const std::optional<Dimension>& offsetY)
2730 {
2731 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2732 return;
2733 }
2734 if (buildFunc) {
2735 auto buildNodeFunc = [func = std::move(buildFunc)]() -> RefPtr<UINode> {
2736 ScopedViewStackProcessor builderViewStackProcessor;
2737 func();
2738 auto customNode = ViewStackProcessor::GetInstance()->Finish();
2739 return customNode;
2740 };
2741 auto overlayNode = AceType::DynamicCast<FrameNode>(buildNodeFunc());
2742 CHECK_NULL_VOID(overlayNode);
2743 AddOverlayToFrameNode(overlayNode, align, offsetX, offsetY);
2744 } else {
2745 AddOverlayToFrameNode(nullptr, align, offsetX, offsetY);
2746 }
2747 }
2748
SetOverlayComponentContent(const RefPtr<NG::FrameNode> & contentNode,const std::optional<Alignment> & align,const std::optional<Dimension> & offsetX,const std::optional<Dimension> & offsetY)2749 void ViewAbstract::SetOverlayComponentContent(const RefPtr<NG::FrameNode>& contentNode,
2750 const std::optional<Alignment>& align, const std::optional<Dimension>& offsetX,
2751 const std::optional<Dimension>& offsetY)
2752 {
2753 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2754 return;
2755 }
2756 AddOverlayToFrameNode(contentNode, align, offsetX, offsetY);
2757 }
2758
AddOverlayToFrameNode(const RefPtr<NG::FrameNode> & overlayNode,const std::optional<Alignment> & align,const std::optional<Dimension> & offsetX,const std::optional<Dimension> & offsetY)2759 void ViewAbstract::AddOverlayToFrameNode(const RefPtr<NG::FrameNode>& overlayNode,
2760 const std::optional<Alignment>& align, const std::optional<Dimension>& offsetX,
2761 const std::optional<Dimension>& offsetY)
2762 {
2763 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2764 CHECK_NULL_VOID(frameNode);
2765 if (overlayNode == nullptr) {
2766 frameNode->SetOverlayNode(nullptr);
2767 return;
2768 }
2769 frameNode->SetOverlayNode(overlayNode);
2770 overlayNode->SetParent(AceType::WeakClaim(frameNode));
2771 overlayNode->SetActive(true);
2772 overlayNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
2773 auto layoutProperty = AceType::DynamicCast<LayoutProperty>(overlayNode->GetLayoutProperty());
2774 CHECK_NULL_VOID(layoutProperty);
2775 layoutProperty->SetIsOverlayNode(true);
2776 layoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT);
2777 layoutProperty->UpdateAlignment(align.value_or(Alignment::TOP_LEFT));
2778 layoutProperty->SetOverlayOffset(offsetX, offsetY);
2779 auto renderContext = overlayNode->GetRenderContext();
2780 CHECK_NULL_VOID(renderContext);
2781 renderContext->UpdateZIndex(INT32_MAX);
2782 auto focusHub = overlayNode->GetOrCreateFocusHub();
2783 CHECK_NULL_VOID(focusHub);
2784 focusHub->SetFocusable(false);
2785 }
2786
SetMotionPath(const MotionPathOption & motionPath)2787 void ViewAbstract::SetMotionPath(const MotionPathOption& motionPath)
2788 {
2789 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2790 return;
2791 }
2792 ACE_UPDATE_RENDER_CONTEXT(MotionPath, motionPath);
2793 }
2794
SetSharedTransition(const std::string & shareId,const std::shared_ptr<SharedTransitionOption> & option)2795 void ViewAbstract::SetSharedTransition(
2796 const std::string& shareId, const std::shared_ptr<SharedTransitionOption>& option)
2797 {
2798 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2799 CHECK_NULL_VOID(frameNode);
2800 auto target = frameNode->GetRenderContext();
2801 if (target) {
2802 target->SetSharedTransitionOptions(option);
2803 target->SetShareId(shareId);
2804 }
2805 }
2806
SetMask(FrameNode * frameNode,const RefPtr<BasicShape> & basicShape)2807 void ViewAbstract::SetMask(FrameNode* frameNode, const RefPtr<BasicShape>& basicShape)
2808 {
2809 CHECK_NULL_VOID(frameNode);
2810 auto target = frameNode->GetRenderContext();
2811 if (target) {
2812 if (target->HasProgressMask()) {
2813 target->ResetProgressMask();
2814 target->OnProgressMaskUpdate(nullptr);
2815 }
2816 target->UpdateClipMask(basicShape);
2817 }
2818 }
2819
SetProgressMask(FrameNode * frameNode,const RefPtr<ProgressMaskProperty> & progress)2820 void ViewAbstract::SetProgressMask(FrameNode* frameNode, const RefPtr<ProgressMaskProperty>& progress)
2821 {
2822 CHECK_NULL_VOID(frameNode);
2823 auto target = frameNode->GetRenderContext();
2824 if (target) {
2825 if (target->HasClipMask()) {
2826 target->ResetClipMask();
2827 target->OnClipMaskUpdate(nullptr);
2828 }
2829 target->UpdateProgressMask(progress);
2830 }
2831 }
2832
SetUseEffect(bool useEffect,EffectType effectType)2833 void ViewAbstract::SetUseEffect(bool useEffect, EffectType effectType)
2834 {
2835 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2836 return;
2837 }
2838 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2839 SetUseEffect(frameNode, useEffect, effectType);
2840 }
2841
SetFreeze(bool freeze)2842 void ViewAbstract::SetFreeze(bool freeze)
2843 {
2844 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2845 return;
2846 }
2847 ACE_UPDATE_RENDER_CONTEXT(Freeze, freeze);
2848 }
2849
SetUseShadowBatching(bool useShadowBatching)2850 void ViewAbstract::SetUseShadowBatching(bool useShadowBatching)
2851 {
2852 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2853 return;
2854 }
2855 ACE_UPDATE_RENDER_CONTEXT(UseShadowBatching, useShadowBatching);
2856 }
2857
SetForegroundColor(const Color & color)2858 void ViewAbstract::SetForegroundColor(const Color& color)
2859 {
2860 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2861 return;
2862 }
2863 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2864 CHECK_NULL_VOID(frameNode);
2865 auto renderContext = frameNode->GetRenderContext();
2866 CHECK_NULL_VOID(renderContext);
2867 if (renderContext->GetForegroundColorStrategy().has_value()) {
2868 renderContext->UpdateForegroundColorStrategy(ForegroundColorStrategy::NONE);
2869 renderContext->ResetForegroundColorStrategy();
2870 }
2871 renderContext->UpdateForegroundColor(color);
2872 renderContext->UpdateForegroundColorFlag(true);
2873 }
2874
SetForegroundColorStrategy(const ForegroundColorStrategy & strategy)2875 void ViewAbstract::SetForegroundColorStrategy(const ForegroundColorStrategy& strategy)
2876 {
2877 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2878 return;
2879 }
2880 ACE_UPDATE_RENDER_CONTEXT(ForegroundColorStrategy, strategy);
2881 ACE_RESET_RENDER_CONTEXT(RenderContext, ForegroundColor);
2882 ACE_UPDATE_RENDER_CONTEXT(ForegroundColorFlag, true);
2883 }
2884
SetKeyboardShortcut(const std::string & value,const std::vector<ModifierKey> & keys,std::function<void ()> && onKeyboardShortcutAction)2885 void ViewAbstract::SetKeyboardShortcut(
2886 const std::string& value, const std::vector<ModifierKey>& keys, std::function<void()>&& onKeyboardShortcutAction)
2887 {
2888 auto pipeline = PipelineContext::GetCurrentContext();
2889 CHECK_NULL_VOID(pipeline);
2890 auto eventManager = pipeline->GetEventManager();
2891 CHECK_NULL_VOID(eventManager);
2892 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
2893 CHECK_NULL_VOID(eventHub);
2894 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2895 CHECK_NULL_VOID(frameNode);
2896 if (value.empty()) {
2897 eventHub->ClearSingleKeyboardShortcut();
2898 return;
2899 }
2900 auto key = eventManager->GetKeyboardShortcutKeys(keys);
2901 if ((key == 0 && value.length() == 1) || (key == 0 && keys.size() > 0 && value.length() > 1)) {
2902 return;
2903 }
2904 if (eventManager->IsSameKeyboardShortcutNode(value, key)) {
2905 return;
2906 }
2907 eventHub->SetKeyboardShortcut(value, key, std::move(onKeyboardShortcutAction));
2908 eventManager->AddKeyboardShortcutNode(AceType::WeakClaim(frameNode));
2909 }
2910
CreateAnimatablePropertyFloat(const std::string & propertyName,float value,const std::function<void (float)> & onCallbackEvent)2911 void ViewAbstract::CreateAnimatablePropertyFloat(
2912 const std::string& propertyName, float value, const std::function<void(float)>& onCallbackEvent)
2913 {
2914 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2915 CHECK_NULL_VOID(frameNode);
2916 frameNode->CreateAnimatablePropertyFloat(propertyName, value, onCallbackEvent);
2917 }
2918
UpdateAnimatablePropertyFloat(const std::string & propertyName,float value)2919 void ViewAbstract::UpdateAnimatablePropertyFloat(const std::string& propertyName, float value)
2920 {
2921 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2922 CHECK_NULL_VOID(frameNode);
2923 frameNode->UpdateAnimatablePropertyFloat(propertyName, value);
2924 }
2925
CreateAnimatableArithmeticProperty(const std::string & propertyName,RefPtr<CustomAnimatableArithmetic> & value,std::function<void (const RefPtr<CustomAnimatableArithmetic> &)> & onCallbackEvent)2926 void ViewAbstract::CreateAnimatableArithmeticProperty(const std::string& propertyName,
2927 RefPtr<CustomAnimatableArithmetic>& value,
2928 std::function<void(const RefPtr<CustomAnimatableArithmetic>&)>& onCallbackEvent)
2929 {
2930 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2931 CHECK_NULL_VOID(frameNode);
2932 frameNode->CreateAnimatableArithmeticProperty(propertyName, value, onCallbackEvent);
2933 }
2934
UpdateAnimatableArithmeticProperty(const std::string & propertyName,RefPtr<CustomAnimatableArithmetic> & value)2935 void ViewAbstract::UpdateAnimatableArithmeticProperty(
2936 const std::string& propertyName, RefPtr<CustomAnimatableArithmetic>& value)
2937 {
2938 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2939 CHECK_NULL_VOID(frameNode);
2940 frameNode->UpdateAnimatableArithmeticProperty(propertyName, value);
2941 }
2942
SetObscured(const std::vector<ObscuredReasons> & reasons)2943 void ViewAbstract::SetObscured(const std::vector<ObscuredReasons>& reasons)
2944 {
2945 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2946 return;
2947 }
2948 ACE_UPDATE_RENDER_CONTEXT(Obscured, reasons);
2949 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2950 CHECK_NULL_VOID(frameNode);
2951 frameNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
2952 }
2953
SetPrivacySensitive(bool flag)2954 void ViewAbstract::SetPrivacySensitive(bool flag)
2955 {
2956 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2957 return;
2958 }
2959 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2960 CHECK_NULL_VOID(frameNode);
2961 frameNode->SetPrivacySensitive(flag);
2962 frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
2963 }
2964
UpdateSafeAreaExpandOpts(const SafeAreaExpandOpts & opts)2965 void ViewAbstract::UpdateSafeAreaExpandOpts(const SafeAreaExpandOpts& opts)
2966 {
2967 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2968 return;
2969 }
2970 ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaExpandOpts, opts);
2971 }
2972
SetRenderGroup(bool isRenderGroup)2973 void ViewAbstract::SetRenderGroup(bool isRenderGroup)
2974 {
2975 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2976 return;
2977 }
2978 ACE_UPDATE_RENDER_CONTEXT(RenderGroup, isRenderGroup);
2979 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2980 CHECK_NULL_VOID(frameNode);
2981 frameNode->SetApplicationRenderGroupMarked(true);
2982 }
2983
SetRenderFit(RenderFit renderFit)2984 void ViewAbstract::SetRenderFit(RenderFit renderFit)
2985 {
2986 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
2987 return;
2988 }
2989 ACE_UPDATE_RENDER_CONTEXT(RenderFit, renderFit);
2990 }
2991
SetBorderRadius(FrameNode * frameNode,const BorderRadiusProperty & value)2992 void ViewAbstract::SetBorderRadius(FrameNode* frameNode, const BorderRadiusProperty& value)
2993 {
2994 ACE_UPDATE_NODE_RENDER_CONTEXT(BorderRadius, value, frameNode);
2995 }
2996
SetBorderRadius(FrameNode * frameNode,const Dimension & value)2997 void ViewAbstract::SetBorderRadius(FrameNode* frameNode, const Dimension& value)
2998 {
2999 BorderRadiusProperty borderRadius;
3000 borderRadius.SetRadius(value);
3001 borderRadius.multiValued = false;
3002 ACE_UPDATE_NODE_RENDER_CONTEXT(BorderRadius, borderRadius, frameNode);
3003 }
3004
SetBorderWidth(FrameNode * frameNode,const BorderWidthProperty & value)3005 void ViewAbstract::SetBorderWidth(FrameNode* frameNode, const BorderWidthProperty& value)
3006 {
3007 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, BorderWidth, value, frameNode);
3008 ACE_UPDATE_NODE_RENDER_CONTEXT(BorderWidth, value, frameNode);
3009 }
3010
SetBorderWidth(FrameNode * frameNode,const Dimension & value)3011 void ViewAbstract::SetBorderWidth(FrameNode* frameNode, const Dimension& value)
3012 {
3013 BorderWidthProperty borderWidth;
3014 if (Negative(value.Value())) {
3015 borderWidth.SetBorderWidth(Dimension(0));
3016 LOGW("border width is negative, reset to 0");
3017 } else {
3018 borderWidth.SetBorderWidth(value);
3019 }
3020 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, BorderWidth, borderWidth, frameNode);
3021 ACE_UPDATE_NODE_RENDER_CONTEXT(BorderWidth, borderWidth, frameNode);
3022 }
3023
SetBorderColor(FrameNode * frameNode,const BorderColorProperty & value)3024 void ViewAbstract::SetBorderColor(FrameNode* frameNode, const BorderColorProperty& value)
3025 {
3026 ACE_UPDATE_NODE_RENDER_CONTEXT(BorderColor, value, frameNode);
3027 }
3028
SetBorderColor(FrameNode * frameNode,const Color & value)3029 void ViewAbstract::SetBorderColor(FrameNode* frameNode, const Color& value)
3030 {
3031 BorderColorProperty borderColor;
3032 borderColor.SetColor(value);
3033 ACE_UPDATE_NODE_RENDER_CONTEXT(BorderColor, borderColor, frameNode);
3034 }
3035
SetWidth(FrameNode * frameNode,const CalcLength & width)3036 void ViewAbstract::SetWidth(FrameNode* frameNode, const CalcLength& width)
3037 {
3038 CHECK_NULL_VOID(frameNode);
3039 auto layoutProperty = frameNode->GetLayoutProperty();
3040 CHECK_NULL_VOID(layoutProperty);
3041 // get previously user defined ideal height
3042 std::optional<CalcLength> height = std::nullopt;
3043 auto&& layoutConstraint = layoutProperty->GetCalcLayoutConstraint();
3044 if (layoutConstraint && layoutConstraint->selfIdealSize) {
3045 height = layoutConstraint->selfIdealSize->Height();
3046 }
3047 layoutProperty->UpdateUserDefinedIdealSize(CalcSize(width, height));
3048 }
3049
SetHeight(FrameNode * frameNode,const CalcLength & height)3050 void ViewAbstract::SetHeight(FrameNode* frameNode, const CalcLength& height)
3051 {
3052 CHECK_NULL_VOID(frameNode);
3053 auto layoutProperty = frameNode->GetLayoutProperty();
3054 CHECK_NULL_VOID(layoutProperty);
3055 std::optional<CalcLength> width = std::nullopt;
3056 auto&& layoutConstraint = layoutProperty->GetCalcLayoutConstraint();
3057 if (layoutConstraint && layoutConstraint->selfIdealSize) {
3058 width = layoutConstraint->selfIdealSize->Width();
3059 }
3060 layoutProperty->UpdateUserDefinedIdealSize(CalcSize(width, height));
3061 }
3062
ClearWidthOrHeight(FrameNode * frameNode,bool isWidth)3063 void ViewAbstract::ClearWidthOrHeight(FrameNode* frameNode, bool isWidth)
3064 {
3065 CHECK_NULL_VOID(frameNode);
3066 auto layoutProperty = frameNode->GetLayoutProperty();
3067 CHECK_NULL_VOID(layoutProperty);
3068 layoutProperty->ClearUserDefinedIdealSize(isWidth, !isWidth);
3069 }
3070
SetPosition(FrameNode * frameNode,const OffsetT<Dimension> & value)3071 void ViewAbstract::SetPosition(FrameNode* frameNode, const OffsetT<Dimension>& value)
3072 {
3073 CHECK_NULL_VOID(frameNode);
3074 ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, PositionEdges, frameNode);
3075 ACE_UPDATE_NODE_RENDER_CONTEXT(Position, value, frameNode);
3076 }
3077
SetPositionEdges(FrameNode * frameNode,const EdgesParam & value)3078 void ViewAbstract::SetPositionEdges(FrameNode* frameNode, const EdgesParam& value)
3079 {
3080 CHECK_NULL_VOID(frameNode);
3081 ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, Position, frameNode);
3082 ACE_UPDATE_NODE_RENDER_CONTEXT(PositionEdges, value, frameNode);
3083 }
3084
ResetPosition(FrameNode * frameNode)3085 void ViewAbstract::ResetPosition(FrameNode* frameNode)
3086 {
3087 ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, Position, frameNode);
3088 ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, PositionEdges, frameNode);
3089 CHECK_NULL_VOID(frameNode);
3090 auto parentNode = frameNode->GetAncestorNodeOfFrame(false);
3091 CHECK_NULL_VOID(parentNode);
3092 auto parentPattern = parentNode->GetPattern();
3093
3094 if (parentNode->GetTag() == V2::COLUMN_ETS_TAG || parentNode->GetTag() == V2::ROW_ETS_TAG ||
3095 parentNode->GetTag() == V2::FLEX_ETS_TAG) {
3096 frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
3097 } else {
3098 auto renderContext = frameNode->GetRenderContext();
3099 CHECK_NULL_VOID(renderContext);
3100 renderContext->RecalculatePosition();
3101 }
3102 }
3103
SetTransformMatrix(FrameNode * frameNode,const Matrix4 & matrix)3104 void ViewAbstract::SetTransformMatrix(FrameNode* frameNode, const Matrix4& matrix)
3105 {
3106 ACE_UPDATE_NODE_RENDER_CONTEXT(TransformMatrix, matrix, frameNode);
3107 }
3108
SetHitTestMode(FrameNode * frameNode,HitTestMode hitTestMode)3109 void ViewAbstract::SetHitTestMode(FrameNode* frameNode, HitTestMode hitTestMode)
3110 {
3111 CHECK_NULL_VOID(frameNode);
3112 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
3113 CHECK_NULL_VOID(gestureHub);
3114 gestureHub->SetHitTestMode(hitTestMode);
3115 }
3116
SetOpacity(FrameNode * frameNode,double opacity)3117 void ViewAbstract::SetOpacity(FrameNode* frameNode, double opacity)
3118 {
3119 ACE_UPDATE_NODE_RENDER_CONTEXT(Opacity, opacity, frameNode);
3120 }
3121
SetZIndex(FrameNode * frameNode,int32_t value)3122 void ViewAbstract::SetZIndex(FrameNode* frameNode, int32_t value)
3123 {
3124 ACE_UPDATE_NODE_RENDER_CONTEXT(ZIndex, value, frameNode);
3125 }
3126
SetLinearGradient(FrameNode * frameNode,const NG::Gradient & gradient)3127 void ViewAbstract::SetLinearGradient(FrameNode* frameNode, const NG::Gradient& gradient)
3128 {
3129 ACE_UPDATE_NODE_RENDER_CONTEXT(LastGradientType, NG::GradientType::LINEAR, frameNode);
3130 ACE_UPDATE_NODE_RENDER_CONTEXT(LinearGradient, gradient, frameNode);
3131 }
3132
SetSweepGradient(FrameNode * frameNode,const NG::Gradient & gradient)3133 void ViewAbstract::SetSweepGradient(FrameNode* frameNode, const NG::Gradient& gradient)
3134 {
3135 ACE_UPDATE_NODE_RENDER_CONTEXT(LastGradientType, NG::GradientType::SWEEP, frameNode);
3136 ACE_UPDATE_NODE_RENDER_CONTEXT(SweepGradient, gradient, frameNode);
3137 }
3138
SetRadialGradient(FrameNode * frameNode,const NG::Gradient & gradient)3139 void ViewAbstract::SetRadialGradient(FrameNode* frameNode, const NG::Gradient& gradient)
3140 {
3141 ACE_UPDATE_NODE_RENDER_CONTEXT(LastGradientType, NG::GradientType::RADIAL, frameNode);
3142 ACE_UPDATE_NODE_RENDER_CONTEXT(RadialGradient, gradient, frameNode);
3143 }
3144
SetOverlay(FrameNode * frameNode,const NG::OverlayOptions & overlay)3145 void ViewAbstract::SetOverlay(FrameNode* frameNode, const NG::OverlayOptions& overlay)
3146 {
3147 ACE_UPDATE_NODE_RENDER_CONTEXT(OverlayText, overlay, frameNode);
3148 }
3149
SetBorderImage(FrameNode * frameNode,const RefPtr<BorderImage> & borderImage)3150 void ViewAbstract::SetBorderImage(FrameNode* frameNode, const RefPtr<BorderImage>& borderImage)
3151 {
3152 ACE_UPDATE_NODE_RENDER_CONTEXT(BorderImage, borderImage, frameNode);
3153 }
3154
SetBorderImageSource(FrameNode * frameNode,const std::string & bdImageSrc)3155 void ViewAbstract::SetBorderImageSource(FrameNode* frameNode, const std::string& bdImageSrc)
3156 {
3157 ImageSourceInfo imageSourceInfo(bdImageSrc);
3158 ACE_UPDATE_NODE_RENDER_CONTEXT(BorderImageSource, imageSourceInfo, frameNode);
3159 ACE_UPDATE_NODE_RENDER_CONTEXT(BorderSourceFromImage, true, frameNode);
3160 }
3161
SetHasBorderImageSlice(FrameNode * frameNode,bool tag)3162 void ViewAbstract::SetHasBorderImageSlice(FrameNode* frameNode, bool tag)
3163 {
3164 ACE_UPDATE_NODE_RENDER_CONTEXT(HasBorderImageSlice, tag, frameNode);
3165 }
3166
SetHasBorderImageWidth(FrameNode * frameNode,bool tag)3167 void ViewAbstract::SetHasBorderImageWidth(FrameNode* frameNode, bool tag)
3168 {
3169 ACE_UPDATE_NODE_RENDER_CONTEXT(HasBorderImageWidth, tag, frameNode);
3170 }
3171
SetHasBorderImageOutset(FrameNode * frameNode,bool tag)3172 void ViewAbstract::SetHasBorderImageOutset(FrameNode* frameNode, bool tag)
3173 {
3174 ACE_UPDATE_NODE_RENDER_CONTEXT(HasBorderImageOutset, tag, frameNode);
3175 }
3176
SetHasBorderImageRepeat(FrameNode * frameNode,bool tag)3177 void ViewAbstract::SetHasBorderImageRepeat(FrameNode* frameNode, bool tag)
3178 {
3179 ACE_UPDATE_NODE_RENDER_CONTEXT(HasBorderImageRepeat, tag, frameNode);
3180 }
3181
SetBorderImageGradient(FrameNode * frameNode,const NG::Gradient & gradient)3182 void ViewAbstract::SetBorderImageGradient(FrameNode* frameNode, const NG::Gradient& gradient)
3183 {
3184 ACE_UPDATE_NODE_RENDER_CONTEXT(BorderImageGradient, gradient, frameNode);
3185 ACE_UPDATE_NODE_RENDER_CONTEXT(BorderSourceFromImage, false, frameNode);
3186 }
3187
SetForegroundBlurStyle(FrameNode * frameNode,const BlurStyleOption & fgBlurStyle)3188 void ViewAbstract::SetForegroundBlurStyle(FrameNode* frameNode, const BlurStyleOption& fgBlurStyle)
3189 {
3190 const auto target = frameNode->GetRenderContext();
3191 if (target) {
3192 target->UpdateFrontBlurStyle(fgBlurStyle);
3193 if (target->GetFrontBlurRadius().has_value()) {
3194 target->UpdateFrontBlurRadius(Dimension());
3195 }
3196 }
3197 }
3198
SetLinearGradientBlur(FrameNode * frameNode,const NG::LinearGradientBlurPara & blurPara)3199 void ViewAbstract::SetLinearGradientBlur(FrameNode *frameNode, const NG::LinearGradientBlurPara& blurPara)
3200 {
3201 ACE_UPDATE_NODE_RENDER_CONTEXT(LinearGradientBlur, blurPara, frameNode);
3202 }
3203
SetMagnifier(FrameNode * frameNode,const MagnifierParams & magnifierOffset)3204 void ViewAbstract::SetMagnifier(FrameNode* frameNode, const MagnifierParams& magnifierOffset)
3205 {
3206 ACE_UPDATE_NODE_RENDER_CONTEXT(Magnifier, magnifierOffset, frameNode);
3207 }
3208
ReSetMagnifier(FrameNode * frameNode)3209 void ViewAbstract::ReSetMagnifier(FrameNode* frameNode)
3210 {
3211 ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, Magnifier, frameNode);
3212 }
3213
SetBackgroundBlurStyle(FrameNode * frameNode,const BlurStyleOption & bgBlurStyle)3214 void ViewAbstract::SetBackgroundBlurStyle(FrameNode *frameNode, const BlurStyleOption& bgBlurStyle)
3215 {
3216 auto pipeline = frameNode->GetContext();
3217 CHECK_NULL_VOID(pipeline);
3218 if (bgBlurStyle.policy == BlurStyleActivePolicy::FOLLOWS_WINDOW_ACTIVE_STATE) {
3219 pipeline->AddWindowFocusChangedCallback(frameNode->GetId());
3220 } else {
3221 pipeline->RemoveWindowFocusChangedCallback(frameNode->GetId());
3222 }
3223 auto target = frameNode->GetRenderContext();
3224 if (target) {
3225 if (target->GetBackgroundEffect().has_value()) {
3226 target->UpdateBackgroundEffect(std::nullopt);
3227 }
3228 target->UpdateBackBlurStyle(bgBlurStyle);
3229 if (target->GetBackBlurRadius().has_value()) {
3230 target->UpdateBackBlurRadius(Dimension());
3231 }
3232 }
3233 }
3234
SetPixelStretchEffect(FrameNode * frameNode,PixStretchEffectOption & option)3235 void ViewAbstract::SetPixelStretchEffect(FrameNode* frameNode, PixStretchEffectOption& option)
3236 {
3237 ACE_UPDATE_NODE_RENDER_CONTEXT(PixelStretchEffect, option, frameNode);
3238 }
3239
SetLightUpEffect(FrameNode * frameNode,double radio)3240 void ViewAbstract::SetLightUpEffect(FrameNode* frameNode, double radio)
3241 {
3242 ACE_UPDATE_NODE_RENDER_CONTEXT(LightUpEffect, radio, frameNode);
3243 }
3244
SetSphericalEffect(FrameNode * frameNode,double radio)3245 void ViewAbstract::SetSphericalEffect(FrameNode* frameNode, double radio)
3246 {
3247 ACE_UPDATE_NODE_RENDER_CONTEXT(SphericalEffect, radio, frameNode);
3248 }
3249
SetRenderGroup(FrameNode * frameNode,bool isRenderGroup)3250 void ViewAbstract::SetRenderGroup(FrameNode* frameNode, bool isRenderGroup)
3251 {
3252 ACE_UPDATE_NODE_RENDER_CONTEXT(RenderGroup, isRenderGroup, frameNode);
3253 CHECK_NULL_VOID(frameNode);
3254 frameNode->SetApplicationRenderGroupMarked(true);
3255 }
3256
SetRenderFit(FrameNode * frameNode,RenderFit renderFit)3257 void ViewAbstract::SetRenderFit(FrameNode* frameNode, RenderFit renderFit)
3258 {
3259 ACE_UPDATE_NODE_RENDER_CONTEXT(RenderFit, renderFit, frameNode);
3260 }
3261
SetUseEffect(FrameNode * frameNode,bool useEffect,EffectType effectType)3262 void ViewAbstract::SetUseEffect(FrameNode* frameNode, bool useEffect, EffectType effectType)
3263 {
3264 CHECK_NULL_VOID(frameNode);
3265 auto* pipeline = frameNode->GetContext();
3266 CHECK_NULL_VOID(pipeline);
3267 if (useEffect && effectType == EffectType::WINDOW_EFFECT) {
3268 pipeline->AddWindowFocusChangedCallback(frameNode->GetId());
3269 } else {
3270 pipeline->RemoveWindowFocusChangedCallback(frameNode->GetId());
3271 }
3272 const auto& target = frameNode->GetRenderContext();
3273 if (target) {
3274 target->UpdateUseEffect(useEffect);
3275 target->UpdateUseEffectType(effectType);
3276 }
3277 }
3278
SetForegroundColor(FrameNode * frameNode,const Color & color)3279 void ViewAbstract::SetForegroundColor(FrameNode* frameNode, const Color& color)
3280 {
3281 auto renderContext = frameNode->GetRenderContext();
3282 CHECK_NULL_VOID(renderContext);
3283 if (renderContext->GetForegroundColorStrategy().has_value()) {
3284 renderContext->UpdateForegroundColorStrategy(ForegroundColorStrategy::NONE);
3285 renderContext->ResetForegroundColorStrategy();
3286 }
3287 renderContext->UpdateForegroundColor(color);
3288 renderContext->UpdateForegroundColorFlag(true);
3289 }
3290
SetForegroundColorStrategy(FrameNode * frameNode,const ForegroundColorStrategy & strategy)3291 void ViewAbstract::SetForegroundColorStrategy(FrameNode* frameNode, const ForegroundColorStrategy& strategy)
3292 {
3293 ACE_UPDATE_NODE_RENDER_CONTEXT(ForegroundColorStrategy, strategy, frameNode);
3294 ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, ForegroundColor, frameNode);
3295 ACE_UPDATE_NODE_RENDER_CONTEXT(ForegroundColorFlag, true, frameNode);
3296 }
3297
SetLightPosition(const CalcDimension & positionX,const CalcDimension & positionY,const CalcDimension & positionZ)3298 void ViewAbstract::SetLightPosition(
3299 const CalcDimension& positionX, const CalcDimension& positionY, const CalcDimension& positionZ)
3300 {
3301 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3302 return;
3303 }
3304 ACE_UPDATE_RENDER_CONTEXT(LightPosition, TranslateOptions(positionX, positionY, positionZ));
3305 }
3306
SetLightIntensity(const float value)3307 void ViewAbstract::SetLightIntensity(const float value)
3308 {
3309 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3310 return;
3311 }
3312 ACE_UPDATE_RENDER_CONTEXT(LightIntensity, value);
3313 }
3314
SetLightColor(const Color & value)3315 void ViewAbstract::SetLightColor(const Color& value)
3316 {
3317 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3318 return;
3319 }
3320 ACE_UPDATE_RENDER_CONTEXT(LightColor, value);
3321 }
3322
SetLightIlluminated(const uint32_t value)3323 void ViewAbstract::SetLightIlluminated(const uint32_t value)
3324 {
3325 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3326 return;
3327 }
3328 ACE_UPDATE_RENDER_CONTEXT(LightIlluminated, value);
3329 }
3330
SetIlluminatedBorderWidth(const Dimension & value)3331 void ViewAbstract::SetIlluminatedBorderWidth(const Dimension& value)
3332 {
3333 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3334 return;
3335 }
3336 ACE_UPDATE_RENDER_CONTEXT(IlluminatedBorderWidth, value);
3337 }
3338
SetBloom(const float value)3339 void ViewAbstract::SetBloom(const float value)
3340 {
3341 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
3342 return;
3343 }
3344 ACE_UPDATE_RENDER_CONTEXT(Bloom, value);
3345 }
3346
SetLightPosition(FrameNode * frameNode,const CalcDimension & positionX,const CalcDimension & positionY,const CalcDimension & positionZ)3347 void ViewAbstract::SetLightPosition(FrameNode* frameNode, const CalcDimension& positionX,
3348 const CalcDimension& positionY, const CalcDimension& positionZ)
3349 {
3350 CHECK_NULL_VOID(frameNode);
3351 ACE_UPDATE_NODE_RENDER_CONTEXT(LightPosition, TranslateOptions(positionX, positionY, positionZ), frameNode);
3352 }
3353
SetLightIntensity(FrameNode * frameNode,const float value)3354 void ViewAbstract::SetLightIntensity(FrameNode* frameNode, const float value)
3355 {
3356 CHECK_NULL_VOID(frameNode);
3357 ACE_UPDATE_NODE_RENDER_CONTEXT(LightIntensity, value, frameNode);
3358 }
3359
SetLightColor(FrameNode * frameNode,const Color & value)3360 void ViewAbstract::SetLightColor(FrameNode* frameNode, const Color& value)
3361 {
3362 CHECK_NULL_VOID(frameNode);
3363 ACE_UPDATE_NODE_RENDER_CONTEXT(LightColor, value, frameNode);
3364 }
3365
SetLightIlluminated(FrameNode * frameNode,const uint32_t value)3366 void ViewAbstract::SetLightIlluminated(FrameNode* frameNode, const uint32_t value)
3367 {
3368 CHECK_NULL_VOID(frameNode);
3369 ACE_UPDATE_NODE_RENDER_CONTEXT(LightIlluminated, value, frameNode);
3370 }
3371
SetIlluminatedBorderWidth(FrameNode * frameNode,const Dimension & value)3372 void ViewAbstract::SetIlluminatedBorderWidth(FrameNode* frameNode, const Dimension& value)
3373 {
3374 CHECK_NULL_VOID(frameNode);
3375 ACE_UPDATE_NODE_RENDER_CONTEXT(IlluminatedBorderWidth, value, frameNode);
3376 }
3377
SetBloom(FrameNode * frameNode,const float value)3378 void ViewAbstract::SetBloom(FrameNode* frameNode, const float value)
3379 {
3380 CHECK_NULL_VOID(frameNode);
3381 ACE_UPDATE_NODE_RENDER_CONTEXT(Bloom, value, frameNode);
3382 }
3383
SetMotionPath(FrameNode * frameNode,const MotionPathOption & motionPath)3384 void ViewAbstract::SetMotionPath(FrameNode* frameNode, const MotionPathOption& motionPath)
3385 {
3386 ACE_UPDATE_NODE_RENDER_CONTEXT(MotionPath, motionPath, frameNode);
3387 }
3388
SetFocusOnTouch(FrameNode * frameNode,bool isSet)3389 void ViewAbstract::SetFocusOnTouch(FrameNode* frameNode, bool isSet)
3390 {
3391 CHECK_NULL_VOID(frameNode);
3392 auto focusHub = frameNode->GetOrCreateFocusHub();
3393 CHECK_NULL_VOID(focusHub);
3394 focusHub->SetIsFocusOnTouch(isSet);
3395 }
3396
SetGroupDefaultFocus(FrameNode * frameNode,bool isSet)3397 void ViewAbstract::SetGroupDefaultFocus(FrameNode* frameNode, bool isSet)
3398 {
3399 CHECK_NULL_VOID(frameNode);
3400 auto focusHub = frameNode->GetOrCreateFocusHub();
3401 CHECK_NULL_VOID(focusHub);
3402 focusHub->SetIsDefaultGroupFocus(isSet);
3403 }
3404
SetFocusable(FrameNode * frameNode,bool focusable)3405 void ViewAbstract::SetFocusable(FrameNode* frameNode, bool focusable)
3406 {
3407 CHECK_NULL_VOID(frameNode);
3408 auto focusHub = frameNode->GetOrCreateFocusHub();
3409 CHECK_NULL_VOID(focusHub);
3410 focusHub->SetFocusable(focusable);
3411 }
3412
SetTabStop(FrameNode * frameNode,bool tabStop)3413 void ViewAbstract::SetTabStop(FrameNode* frameNode, bool tabStop)
3414 {
3415 CHECK_NULL_VOID(frameNode);
3416 auto focusHub = frameNode->GetOrCreateFocusHub();
3417 CHECK_NULL_VOID(focusHub);
3418 focusHub->SetTabStop(tabStop);
3419 }
3420
SetFocusType(FrameNode * frameNode,FocusType focusType)3421 void ViewAbstract::SetFocusType(FrameNode* frameNode, FocusType focusType)
3422 {
3423 CHECK_NULL_VOID(frameNode);
3424 auto focusHub = frameNode->GetOrCreateFocusHub();
3425 CHECK_NULL_VOID(focusHub);
3426 focusHub->SetFocusType(focusType);
3427 }
3428
SetTouchable(FrameNode * frameNode,bool touchable)3429 void ViewAbstract::SetTouchable(FrameNode* frameNode, bool touchable)
3430 {
3431 CHECK_NULL_VOID(frameNode);
3432 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
3433 CHECK_NULL_VOID(gestureHub);
3434 gestureHub->SetTouchable(touchable);
3435 }
3436
SetDefaultFocus(FrameNode * frameNode,bool isSet)3437 void ViewAbstract::SetDefaultFocus(FrameNode* frameNode, bool isSet)
3438 {
3439 CHECK_NULL_VOID(frameNode);
3440 auto focusHub = frameNode->GetOrCreateFocusHub();
3441 CHECK_NULL_VOID(focusHub);
3442 focusHub->SetIsDefaultFocus(isSet);
3443 }
3444
SetDisplayIndex(FrameNode * frameNode,int32_t value)3445 void ViewAbstract::SetDisplayIndex(FrameNode* frameNode, int32_t value)
3446 {
3447 CHECK_NULL_VOID(frameNode);
3448 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, DisplayIndex, value, frameNode);
3449 }
3450
SetOffset(FrameNode * frameNode,const OffsetT<Dimension> & value)3451 void ViewAbstract::SetOffset(FrameNode* frameNode, const OffsetT<Dimension>& value)
3452 {
3453 CHECK_NULL_VOID(frameNode);
3454 ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, OffsetEdges, frameNode);
3455 ACE_UPDATE_NODE_RENDER_CONTEXT(Offset, value, frameNode);
3456 }
3457
SetOffsetEdges(FrameNode * frameNode,const EdgesParam & value)3458 void ViewAbstract::SetOffsetEdges(FrameNode* frameNode, const EdgesParam& value)
3459 {
3460 CHECK_NULL_VOID(frameNode);
3461 ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, Offset, frameNode);
3462 ACE_UPDATE_NODE_RENDER_CONTEXT(OffsetEdges, value, frameNode);
3463 }
3464
MarkAnchor(FrameNode * frameNode,const OffsetT<Dimension> & value)3465 void ViewAbstract::MarkAnchor(FrameNode* frameNode, const OffsetT<Dimension>& value)
3466 {
3467 CHECK_NULL_VOID(frameNode);
3468 ACE_UPDATE_NODE_RENDER_CONTEXT(Anchor, value, frameNode);
3469 }
3470
SetVisibility(FrameNode * frameNode,VisibleType visible)3471 void ViewAbstract::SetVisibility(FrameNode* frameNode, VisibleType visible)
3472 {
3473 CHECK_NULL_VOID(frameNode);
3474 auto layoutProperty = frameNode->GetLayoutProperty();
3475 if (layoutProperty) {
3476 layoutProperty->UpdateVisibility(visible, true);
3477 }
3478
3479 auto focusHub = frameNode->GetOrCreateFocusHub();
3480 if (focusHub) {
3481 focusHub->SetShow(visible == VisibleType::VISIBLE);
3482 }
3483 }
3484
SetPadding(FrameNode * frameNode,const CalcLength & value)3485 void ViewAbstract::SetPadding(FrameNode* frameNode, const CalcLength& value)
3486 {
3487 CHECK_NULL_VOID(frameNode);
3488 PaddingProperty padding;
3489 padding.SetEdges(value);
3490 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Padding, padding, frameNode);
3491 }
3492
SetPadding(FrameNode * frameNode,const PaddingProperty & value)3493 void ViewAbstract::SetPadding(FrameNode* frameNode, const PaddingProperty& value)
3494 {
3495 CHECK_NULL_VOID(frameNode);
3496 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Padding, value, frameNode);
3497 }
3498
SetMargin(FrameNode * frameNode,const CalcLength & value)3499 void ViewAbstract::SetMargin(FrameNode* frameNode, const CalcLength& value)
3500 {
3501 CHECK_NULL_VOID(frameNode);
3502 MarginProperty margin;
3503 margin.SetEdges(value);
3504 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Margin, margin, frameNode);
3505 }
3506
SetMargin(FrameNode * frameNode,const PaddingProperty & value)3507 void ViewAbstract::SetMargin(FrameNode* frameNode, const PaddingProperty& value)
3508 {
3509 CHECK_NULL_VOID(frameNode);
3510 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Margin, value, frameNode);
3511 }
3512
SetLayoutDirection(FrameNode * frameNode,TextDirection value)3513 void ViewAbstract::SetLayoutDirection(FrameNode* frameNode, TextDirection value)
3514 {
3515 CHECK_NULL_VOID(frameNode);
3516 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, LayoutDirection, value, frameNode);
3517 }
3518
UpdateSafeAreaExpandOpts(FrameNode * frameNode,const SafeAreaExpandOpts & opts)3519 void ViewAbstract::UpdateSafeAreaExpandOpts(FrameNode* frameNode, const SafeAreaExpandOpts& opts)
3520 {
3521 CHECK_NULL_VOID(frameNode);
3522 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, SafeAreaExpandOpts, opts, frameNode);
3523 }
3524
SetAspectRatio(FrameNode * frameNode,float ratio)3525 void ViewAbstract::SetAspectRatio(FrameNode* frameNode, float ratio)
3526 {
3527 CHECK_NULL_VOID(frameNode);
3528 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, AspectRatio, ratio, frameNode);
3529 }
3530
SetAlignSelf(FrameNode * frameNode,FlexAlign value)3531 void ViewAbstract::SetAlignSelf(FrameNode* frameNode, FlexAlign value)
3532 {
3533 CHECK_NULL_VOID(frameNode);
3534 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, AlignSelf, value, frameNode);
3535 }
3536
SetFlexBasis(FrameNode * frameNode,const Dimension & value)3537 void ViewAbstract::SetFlexBasis(FrameNode* frameNode, const Dimension& value)
3538 {
3539 CHECK_NULL_VOID(frameNode);
3540 if (LessNotEqual(value.Value(), 0.0f)) {
3541 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, FlexBasis, Dimension(), frameNode);
3542 return;
3543 }
3544 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, FlexBasis, value, frameNode);
3545 }
3546
ResetFlexShrink(FrameNode * frameNode)3547 void ViewAbstract::ResetFlexShrink(FrameNode* frameNode)
3548 {
3549 CHECK_NULL_VOID(frameNode);
3550 ACE_RESET_NODE_LAYOUT_PROPERTY(LayoutProperty, FlexShrink, frameNode);
3551 }
3552
SetFlexShrink(FrameNode * frameNode,float value)3553 void ViewAbstract::SetFlexShrink(FrameNode* frameNode, float value)
3554 {
3555 CHECK_NULL_VOID(frameNode);
3556 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, FlexShrink, value, frameNode);
3557 }
3558
SetFlexGrow(FrameNode * frameNode,float value)3559 void ViewAbstract::SetFlexGrow(FrameNode* frameNode, float value)
3560 {
3561 CHECK_NULL_VOID(frameNode);
3562 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, FlexGrow, value, frameNode);
3563 }
3564
SetLayoutWeight(FrameNode * frameNode,float value)3565 void ViewAbstract::SetLayoutWeight(FrameNode* frameNode, float value)
3566 {
3567 CHECK_NULL_VOID(frameNode);
3568 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, LayoutWeight, value, frameNode);
3569 }
3570
SetLayoutWeight(FrameNode * frameNode,const NG::LayoutWeightPair & value)3571 void ViewAbstract::SetLayoutWeight(FrameNode* frameNode, const NG::LayoutWeightPair& value)
3572 {
3573 CHECK_NULL_VOID(frameNode);
3574 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, ChainWeight, value, frameNode);
3575 }
3576
ResetMaxSize(FrameNode * frameNode,bool resetWidth)3577 void ViewAbstract::ResetMaxSize(FrameNode* frameNode, bool resetWidth)
3578 {
3579 CHECK_NULL_VOID(frameNode);
3580 auto layoutProperty = frameNode->GetLayoutProperty();
3581 CHECK_NULL_VOID(layoutProperty);
3582 layoutProperty->ResetCalcMaxSize(resetWidth);
3583 }
3584
ResetMinSize(FrameNode * frameNode,bool resetWidth)3585 void ViewAbstract::ResetMinSize(FrameNode* frameNode, bool resetWidth)
3586 {
3587 CHECK_NULL_VOID(frameNode);
3588 auto layoutProperty = frameNode->GetLayoutProperty();
3589 CHECK_NULL_VOID(layoutProperty);
3590 layoutProperty->ResetCalcMinSize(resetWidth);
3591 }
3592
SetMinWidth(FrameNode * frameNode,const CalcLength & minWidth)3593 void ViewAbstract::SetMinWidth(FrameNode* frameNode, const CalcLength& minWidth)
3594 {
3595 CHECK_NULL_VOID(frameNode);
3596 auto layoutProperty = frameNode->GetLayoutProperty();
3597 CHECK_NULL_VOID(layoutProperty);
3598 layoutProperty->UpdateCalcMinSize(CalcSize(minWidth, std::nullopt));
3599 }
3600
SetMaxWidth(FrameNode * frameNode,const CalcLength & maxWidth)3601 void ViewAbstract::SetMaxWidth(FrameNode* frameNode, const CalcLength& maxWidth)
3602 {
3603 CHECK_NULL_VOID(frameNode);
3604 auto layoutProperty = frameNode->GetLayoutProperty();
3605 CHECK_NULL_VOID(layoutProperty);
3606 layoutProperty->UpdateCalcMaxSize(CalcSize(maxWidth, std::nullopt));
3607 }
3608
SetMinHeight(FrameNode * frameNode,const CalcLength & minHeight)3609 void ViewAbstract::SetMinHeight(FrameNode* frameNode, const CalcLength& minHeight)
3610 {
3611 CHECK_NULL_VOID(frameNode);
3612 auto layoutProperty = frameNode->GetLayoutProperty();
3613 CHECK_NULL_VOID(layoutProperty);
3614 layoutProperty->UpdateCalcMinSize(CalcSize(std::nullopt, minHeight));
3615 }
3616
SetMaxHeight(FrameNode * frameNode,const CalcLength & maxHeight)3617 void ViewAbstract::SetMaxHeight(FrameNode* frameNode, const CalcLength& maxHeight)
3618 {
3619 CHECK_NULL_VOID(frameNode);
3620 auto layoutProperty = frameNode->GetLayoutProperty();
3621 CHECK_NULL_VOID(layoutProperty);
3622 layoutProperty->UpdateCalcMaxSize(CalcSize(std::nullopt, maxHeight));
3623 }
3624
SetAlignRules(FrameNode * frameNode,const std::map<AlignDirection,AlignRule> & alignRules)3625 void ViewAbstract::SetAlignRules(FrameNode* frameNode, const std::map<AlignDirection, AlignRule>& alignRules)
3626 {
3627 CHECK_NULL_VOID(frameNode);
3628 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, AlignRules, alignRules, frameNode);
3629 }
3630
GetAlignRules(FrameNode * frameNode)3631 std::map<AlignDirection, AlignRule> ViewAbstract::GetAlignRules(FrameNode* frameNode)
3632 {
3633 std::map<AlignDirection, AlignRule> alignRules;
3634 CHECK_NULL_RETURN(frameNode, alignRules);
3635 auto layoutProperty = frameNode->GetLayoutProperty();
3636 CHECK_NULL_RETURN(layoutProperty, alignRules);
3637 CHECK_NULL_RETURN(layoutProperty->GetFlexItemProperty(), alignRules);
3638 return layoutProperty->GetFlexItemProperty()->GetAlignRules().value_or(alignRules);
3639 }
3640
ResetAlignRules(FrameNode * frameNode)3641 void ViewAbstract::ResetAlignRules(FrameNode* frameNode)
3642 {
3643 CHECK_NULL_VOID(frameNode);
3644 auto layoutProperty = frameNode->GetLayoutProperty();
3645 CHECK_NULL_VOID(layoutProperty);
3646 CHECK_NULL_VOID(layoutProperty->GetFlexItemProperty());
3647 return layoutProperty->GetFlexItemProperty()->ResetAlignRules();
3648 }
3649
SetChainStyle(FrameNode * frameNode,const ChainInfo & chainInfo)3650 void ViewAbstract::SetChainStyle(FrameNode* frameNode, const ChainInfo& chainInfo)
3651 {
3652 CHECK_NULL_VOID(frameNode);
3653 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, ChainStyle, chainInfo, frameNode);
3654 }
3655
GetChainStyle(FrameNode * frameNode)3656 ChainInfo ViewAbstract::GetChainStyle(FrameNode* frameNode)
3657 {
3658 ChainInfo chainInfo;
3659 CHECK_NULL_RETURN(frameNode, chainInfo);
3660 auto layoutProperty = frameNode->GetLayoutProperty();
3661 CHECK_NULL_RETURN(layoutProperty->GetFlexItemProperty(), chainInfo);
3662 layoutProperty->GetFlexItemProperty()->GetHorizontalChainStyle().value_or(chainInfo);
3663 if (chainInfo.direction.has_value()) {
3664 return chainInfo;
3665 }
3666 return layoutProperty->GetFlexItemProperty()->GetVerticalChainStyle().value_or(chainInfo);
3667 }
3668
ResetChainStyle(FrameNode * frameNode)3669 void ViewAbstract::ResetChainStyle(FrameNode* frameNode)
3670 {
3671 CHECK_NULL_VOID(frameNode);
3672 ChainInfo nullChainInfo;
3673 auto layoutProperty = frameNode->GetLayoutProperty();
3674 CHECK_NULL_VOID(layoutProperty->GetFlexItemProperty());
3675 layoutProperty->GetFlexItemProperty()->UpdateHorizontalChainStyle(nullChainInfo);
3676 layoutProperty->GetFlexItemProperty()->UpdateVerticalChainStyle(nullChainInfo);
3677 }
3678
SetGrid(FrameNode * frameNode,std::optional<int32_t> span,std::optional<int32_t> offset,GridSizeType type)3679 void ViewAbstract::SetGrid(
3680 FrameNode* frameNode, std::optional<int32_t> span, std::optional<int32_t> offset, GridSizeType type)
3681 {
3682 CHECK_NULL_VOID(frameNode);
3683 auto layoutProperty = frameNode->GetLayoutProperty();
3684 CHECK_NULL_VOID(layoutProperty);
3685 // frame node is mounted to parent when pop from stack later, no grid-container is added here
3686 layoutProperty->UpdateGridProperty(span, offset, type);
3687 }
3688
ResetAspectRatio(FrameNode * frameNode)3689 void ViewAbstract::ResetAspectRatio(FrameNode* frameNode)
3690 {
3691 ACE_RESET_NODE_LAYOUT_PROPERTY(LayoutProperty, AspectRatio, frameNode);
3692 }
3693
SetAllowDrop(FrameNode * frameNode,const std::set<std::string> & allowDrop)3694 void ViewAbstract::SetAllowDrop(FrameNode* frameNode, const std::set<std::string>& allowDrop)
3695 {
3696 CHECK_NULL_VOID(frameNode);
3697 frameNode->SetAllowDrop(allowDrop);
3698 }
3699
SetInspectorId(FrameNode * frameNode,const std::string & inspectorId)3700 void ViewAbstract::SetInspectorId(FrameNode* frameNode, const std::string& inspectorId)
3701 {
3702 if (frameNode) {
3703 if (frameNode->GetInspectorId().has_value() && frameNode->GetInspectorIdValue() != inspectorId) {
3704 ElementRegister::GetInstance()->RemoveFrameNodeByInspectorId(
3705 frameNode->GetInspectorIdValue(), frameNode->GetId());
3706 }
3707 frameNode->UpdateInspectorId(inspectorId);
3708 }
3709 }
3710
SetRestoreId(FrameNode * frameNode,int32_t restoreId)3711 void ViewAbstract::SetRestoreId(FrameNode* frameNode, int32_t restoreId)
3712 {
3713 if (frameNode) {
3714 frameNode->SetRestoreId(restoreId);
3715 }
3716 }
3717
SetTabIndex(FrameNode * frameNode,int32_t index)3718 void ViewAbstract::SetTabIndex(FrameNode* frameNode, int32_t index)
3719 {
3720 CHECK_NULL_VOID(frameNode);
3721 auto focusHub = frameNode->GetOrCreateFocusHub();
3722 CHECK_NULL_VOID(focusHub);
3723 focusHub->SetTabIndex(index);
3724 }
3725
SetObscured(FrameNode * frameNode,const std::vector<ObscuredReasons> & reasons)3726 void ViewAbstract::SetObscured(FrameNode* frameNode, const std::vector<ObscuredReasons>& reasons)
3727 {
3728 CHECK_NULL_VOID(frameNode);
3729 ACE_UPDATE_NODE_RENDER_CONTEXT(Obscured, reasons, frameNode);
3730 frameNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
3731 }
3732
SetForegroundEffect(FrameNode * frameNode,float radius)3733 void ViewAbstract::SetForegroundEffect(FrameNode* frameNode, float radius)
3734 {
3735 CHECK_NULL_VOID(frameNode);
3736 auto target = frameNode->GetRenderContext();
3737 if (target) {
3738 target->UpdateForegroundEffect(radius);
3739 }
3740 }
3741
SetMotionBlur(FrameNode * frameNode,const MotionBlurOption & motionBlurOption)3742 void ViewAbstract::SetMotionBlur(FrameNode* frameNode, const MotionBlurOption& motionBlurOption)
3743 {
3744 ACE_UPDATE_NODE_RENDER_CONTEXT(MotionBlur, motionBlurOption, frameNode);
3745 }
3746
SetBackgroundEffect(FrameNode * frameNode,const EffectOption & effectOption)3747 void ViewAbstract::SetBackgroundEffect(FrameNode* frameNode, const EffectOption &effectOption)
3748 {
3749 CHECK_NULL_VOID(frameNode);
3750 auto pipeline = frameNode->GetContext();
3751 CHECK_NULL_VOID(pipeline);
3752 if (effectOption.policy == BlurStyleActivePolicy::FOLLOWS_WINDOW_ACTIVE_STATE) {
3753 pipeline->AddWindowFocusChangedCallback(frameNode->GetId());
3754 } else {
3755 pipeline->RemoveWindowFocusChangedCallback(frameNode->GetId());
3756 }
3757 auto target = frameNode->GetRenderContext();
3758 if (target) {
3759 if (target->GetBackBlurRadius().has_value()) {
3760 target->UpdateBackBlurRadius(Dimension());
3761 }
3762 if (target->GetBackBlurStyle().has_value()) {
3763 target->UpdateBackBlurStyle(std::nullopt);
3764 }
3765 target->UpdateBackgroundEffect(effectOption);
3766 }
3767 }
3768
SetDynamicLightUp(FrameNode * frameNode,float rate,float lightUpDegree)3769 void ViewAbstract::SetDynamicLightUp(FrameNode* frameNode, float rate, float lightUpDegree)
3770 {
3771 ACE_UPDATE_NODE_RENDER_CONTEXT(DynamicLightUpRate, rate, frameNode);
3772 ACE_UPDATE_NODE_RENDER_CONTEXT(DynamicLightUpDegree, lightUpDegree, frameNode);
3773 }
3774
SetBgDynamicBrightness(FrameNode * frameNode,const BrightnessOption & brightnessOption)3775 void ViewAbstract::SetBgDynamicBrightness(FrameNode* frameNode, const BrightnessOption& brightnessOption)
3776 {
3777 CHECK_NULL_VOID(frameNode);
3778 ACE_UPDATE_NODE_RENDER_CONTEXT(BgDynamicBrightnessOption, brightnessOption, frameNode);
3779 }
3780
SetFgDynamicBrightness(FrameNode * frameNode,const BrightnessOption & brightnessOption)3781 void ViewAbstract::SetFgDynamicBrightness(FrameNode* frameNode, const BrightnessOption& brightnessOption)
3782 {
3783 CHECK_NULL_VOID(frameNode);
3784 ACE_UPDATE_NODE_RENDER_CONTEXT(FgDynamicBrightnessOption, brightnessOption, frameNode);
3785 }
3786
SetBrightnessBlender(FrameNode * frameNode,const OHOS::Rosen::BrightnessBlender * brightnessBlender)3787 void ViewAbstract::SetBrightnessBlender(FrameNode* frameNode, const OHOS::Rosen::BrightnessBlender* brightnessBlender)
3788 {
3789 CHECK_NULL_VOID(frameNode);
3790 ACE_UPDATE_NODE_RENDER_CONTEXT(BrightnessBlender, brightnessBlender, frameNode);
3791 }
3792
SetDragPreviewOptions(FrameNode * frameNode,const DragPreviewOption & previewOption)3793 void ViewAbstract::SetDragPreviewOptions(FrameNode* frameNode, const DragPreviewOption& previewOption)
3794 {
3795 CHECK_NULL_VOID(frameNode);
3796 frameNode->SetDragPreviewOptions(previewOption);
3797 }
3798
SetDragPreview(FrameNode * frameNode,const DragDropInfo & dragDropInfo)3799 void ViewAbstract::SetDragPreview(FrameNode* frameNode, const DragDropInfo& dragDropInfo)
3800 {
3801 CHECK_NULL_VOID(frameNode);
3802 frameNode->SetDragPreview(dragDropInfo);
3803 }
3804
SetResponseRegion(FrameNode * frameNode,const std::vector<DimensionRect> & responseRegion)3805 void ViewAbstract::SetResponseRegion(FrameNode* frameNode, const std::vector<DimensionRect>& responseRegion)
3806 {
3807 CHECK_NULL_VOID(frameNode);
3808 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
3809 CHECK_NULL_VOID(gestureHub);
3810 gestureHub->SetResponseRegion(responseRegion);
3811 }
3812
SetMouseResponseRegion(FrameNode * frameNode,const std::vector<DimensionRect> & mouseResponseRegion)3813 void ViewAbstract::SetMouseResponseRegion(FrameNode* frameNode, const std::vector<DimensionRect>& mouseResponseRegion)
3814 {
3815 CHECK_NULL_VOID(frameNode);
3816 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
3817 CHECK_NULL_VOID(gestureHub);
3818 gestureHub->SetMouseResponseRegion(mouseResponseRegion);
3819 }
3820
SetSharedTransition(FrameNode * frameNode,const std::string & shareId,const std::shared_ptr<SharedTransitionOption> & option)3821 void ViewAbstract::SetSharedTransition(
3822 FrameNode* frameNode, const std::string& shareId, const std::shared_ptr<SharedTransitionOption>& option)
3823 {
3824 CHECK_NULL_VOID(frameNode);
3825 const auto& target = frameNode->GetRenderContext();
3826 if (target) {
3827 target->SetSharedTransitionOptions(option);
3828 target->SetShareId(shareId);
3829 }
3830 }
3831
SetTransition(FrameNode * frameNode,const TransitionOptions & options)3832 void ViewAbstract::SetTransition(FrameNode* frameNode, const TransitionOptions& options)
3833 {
3834 ACE_UPDATE_NODE_RENDER_CONTEXT(Transition, options, frameNode);
3835 }
3836
CleanTransition(FrameNode * frameNode)3837 void ViewAbstract::CleanTransition(FrameNode* frameNode)
3838 {
3839 CHECK_NULL_VOID(frameNode);
3840 const auto& renderContext = frameNode->GetRenderContext();
3841 if (renderContext) {
3842 renderContext->CleanTransition();
3843 }
3844 }
3845
SetChainedTransition(FrameNode * frameNode,const RefPtr<NG::ChainedTransitionEffect> & effect,NG::TransitionFinishCallback && finishCallback)3846 void ViewAbstract::SetChainedTransition(FrameNode* frameNode, const RefPtr<NG::ChainedTransitionEffect>& effect,
3847 NG::TransitionFinishCallback&& finishCallback)
3848 {
3849 CHECK_NULL_VOID(frameNode);
3850 const auto& target = frameNode->GetRenderContext();
3851 if (target) {
3852 target->UpdateChainedTransition(effect);
3853 target->SetTransitionUserCallback(std::move(finishCallback));
3854 }
3855 }
3856
SetEnabled(FrameNode * frameNode,bool enabled)3857 void ViewAbstract::SetEnabled(FrameNode* frameNode, bool enabled)
3858 {
3859 CHECK_NULL_VOID(frameNode);
3860 auto eventHub = frameNode->GetEventHub<EventHub>();
3861 if (eventHub) {
3862 eventHub->SetEnabled(enabled);
3863 }
3864 auto focusHub = frameNode->GetOrCreateFocusHub();
3865 if (focusHub) {
3866 focusHub->SetEnabled(enabled);
3867 }
3868 }
3869
SetUseShadowBatching(FrameNode * frameNode,bool useShadowBatching)3870 void ViewAbstract::SetUseShadowBatching(FrameNode* frameNode, bool useShadowBatching)
3871 {
3872 ACE_UPDATE_NODE_RENDER_CONTEXT(UseShadowBatching, useShadowBatching, frameNode);
3873 }
3874
SetBlendMode(FrameNode * frameNode,BlendMode blendMode)3875 void ViewAbstract::SetBlendMode(FrameNode* frameNode, BlendMode blendMode)
3876 {
3877 ACE_UPDATE_NODE_RENDER_CONTEXT(BackBlendMode, blendMode, frameNode);
3878 }
3879
SetBlendApplyType(FrameNode * frameNode,BlendApplyType blendApplyType)3880 void ViewAbstract::SetBlendApplyType(FrameNode* frameNode, BlendApplyType blendApplyType)
3881 {
3882 ACE_UPDATE_NODE_RENDER_CONTEXT(BackBlendApplyType, blendApplyType, frameNode);
3883 }
3884
SetMonopolizeEvents(FrameNode * frameNode,bool monopolizeEvents)3885 void ViewAbstract::SetMonopolizeEvents(FrameNode* frameNode, bool monopolizeEvents)
3886 {
3887 CHECK_NULL_VOID(frameNode);
3888 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
3889 CHECK_NULL_VOID(gestureHub);
3890 gestureHub->SetMonopolizeEvents(monopolizeEvents);
3891 }
3892
SetDraggable(FrameNode * frameNode,bool draggable)3893 void ViewAbstract::SetDraggable(FrameNode* frameNode, bool draggable)
3894 {
3895 CHECK_NULL_VOID(frameNode);
3896 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
3897 CHECK_NULL_VOID(gestureHub);
3898 if (draggable) {
3899 if (!frameNode->IsDraggable()) {
3900 gestureHub->InitDragDropEvent();
3901 }
3902 } else {
3903 gestureHub->RemoveDragEvent();
3904 }
3905 frameNode->SetDraggable(draggable);
3906 }
3907
SetHoverEffect(FrameNode * frameNode,HoverEffectType hoverEffect)3908 void ViewAbstract::SetHoverEffect(FrameNode* frameNode, HoverEffectType hoverEffect)
3909 {
3910 CHECK_NULL_VOID(frameNode);
3911 auto eventHub = frameNode->GetOrCreateInputEventHub();
3912 CHECK_NULL_VOID(eventHub);
3913 eventHub->SetHoverEffect(hoverEffect);
3914 }
3915
SetClickEffectLevel(FrameNode * frameNode,const ClickEffectLevel & level,float scaleValue)3916 void ViewAbstract::SetClickEffectLevel(FrameNode* frameNode, const ClickEffectLevel& level, float scaleValue)
3917 {
3918 ClickEffectInfo clickEffectInfo;
3919 clickEffectInfo.level = level;
3920 clickEffectInfo.scaleNumber = scaleValue;
3921 ACE_UPDATE_NODE_RENDER_CONTEXT(ClickEffectLevel, clickEffectInfo, frameNode);
3922 }
3923
SetKeyboardShortcut(FrameNode * frameNode,const std::string & value,const std::vector<ModifierKey> & keys,std::function<void ()> && onKeyboardShortcutAction)3924 void ViewAbstract::SetKeyboardShortcut(FrameNode* frameNode, const std::string& value,
3925 const std::vector<ModifierKey>& keys, std::function<void()>&& onKeyboardShortcutAction)
3926 {
3927 CHECK_NULL_VOID(frameNode);
3928 auto pipeline = frameNode->GetContext();
3929 CHECK_NULL_VOID(pipeline);
3930 auto eventManager = pipeline->GetEventManager();
3931 CHECK_NULL_VOID(eventManager);
3932 auto eventHub = frameNode->GetEventHub<EventHub>();
3933 CHECK_NULL_VOID(eventHub);
3934 auto frameNodeRef = AceType::Claim<FrameNode>(frameNode);
3935 if (value.empty() || keys.empty()) {
3936 eventHub->ClearSingleKeyboardShortcut();
3937 return;
3938 }
3939 auto key = eventManager->GetKeyboardShortcutKeys(keys);
3940 if ((key == 0 && value.length() == 1) || (key == 0 && !keys.empty() && value.length() > 1)) {
3941 return;
3942 }
3943 if (eventManager->IsSameKeyboardShortcutNode(value, key)) {
3944 return;
3945 }
3946 eventHub->SetKeyboardShortcut(value, key, onKeyboardShortcutAction);
3947 eventManager->AddKeyboardShortcutNode(WeakPtr<NG::FrameNode>(frameNodeRef));
3948 }
3949
SetOnAppear(FrameNode * frameNode,std::function<void ()> && onAppear)3950 void ViewAbstract::SetOnAppear(FrameNode* frameNode, std::function<void()> &&onAppear)
3951 {
3952 CHECK_NULL_VOID(frameNode);
3953 auto eventHub = frameNode->GetEventHub<EventHub>();
3954 CHECK_NULL_VOID(eventHub);
3955 eventHub->SetOnAppear(std::move(onAppear));
3956 }
3957
SetOnDisappear(FrameNode * frameNode,std::function<void ()> && onDisappear)3958 void ViewAbstract::SetOnDisappear(FrameNode* frameNode, std::function<void()> &&onDisappear)
3959 {
3960 CHECK_NULL_VOID(frameNode);
3961 auto eventHub = frameNode->GetEventHub<EventHub>();
3962 CHECK_NULL_VOID(eventHub);
3963 eventHub->SetOnDisappear(std::move(onDisappear));
3964 }
3965
SetOnAttach(FrameNode * frameNode,std::function<void ()> && onAttach)3966 void ViewAbstract::SetOnAttach(FrameNode* frameNode, std::function<void()> &&onAttach)
3967 {
3968 CHECK_NULL_VOID(frameNode);
3969 auto eventHub = frameNode->GetEventHub<EventHub>();
3970 CHECK_NULL_VOID(eventHub);
3971 eventHub->SetOnAttach(std::move(onAttach));
3972 }
3973
SetOnDetach(FrameNode * frameNode,std::function<void ()> && onDetach)3974 void ViewAbstract::SetOnDetach(FrameNode* frameNode, std::function<void()> &&onDetach)
3975 {
3976 CHECK_NULL_VOID(frameNode);
3977 auto eventHub = frameNode->GetEventHub<EventHub>();
3978 CHECK_NULL_VOID(eventHub);
3979 eventHub->SetOnDetach(std::move(onDetach));
3980 }
3981
SetOnAreaChanged(FrameNode * frameNode,std::function<void (const RectF & oldRect,const OffsetF & oldOrigin,const RectF & rect,const OffsetF & origin)> && onAreaChanged)3982 void ViewAbstract::SetOnAreaChanged(FrameNode* frameNode, std::function<void(const RectF &oldRect,
3983 const OffsetF &oldOrigin, const RectF &rect, const OffsetF &origin)> &&onAreaChanged)
3984 {
3985 CHECK_NULL_VOID(frameNode);
3986 auto pipeline = frameNode->GetContext();
3987 CHECK_NULL_VOID(pipeline);
3988 frameNode->SetOnAreaChangeCallback(std::move(onAreaChanged));
3989 pipeline->AddOnAreaChangeNode(frameNode->GetId());
3990 }
3991
SetOnFocus(FrameNode * frameNode,OnFocusFunc && onFocusCallback)3992 void ViewAbstract::SetOnFocus(FrameNode* frameNode, OnFocusFunc &&onFocusCallback)
3993 {
3994 CHECK_NULL_VOID(frameNode);
3995 auto focusHub = frameNode->GetOrCreateFocusHub();
3996 focusHub->SetOnFocusCallback(std::move(onFocusCallback));
3997 }
3998
SetOnBlur(FrameNode * frameNode,OnBlurFunc && onBlurCallback)3999 void ViewAbstract::SetOnBlur(FrameNode* frameNode, OnBlurFunc &&onBlurCallback)
4000 {
4001 CHECK_NULL_VOID(frameNode);
4002 auto focusHub = frameNode->GetOrCreateFocusHub();
4003 focusHub->SetOnBlurCallback(std::move(onBlurCallback));
4004 }
4005
SetOnClick(FrameNode * frameNode,GestureEventFunc && clickEventFunc,double distanceThreshold)4006 void ViewAbstract::SetOnClick(FrameNode* frameNode, GestureEventFunc&& clickEventFunc, double distanceThreshold)
4007 {
4008 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
4009 CHECK_NULL_VOID(gestureHub);
4010 gestureHub->SetUserOnClick(std::move(clickEventFunc), distanceThreshold);
4011
4012 auto focusHub = frameNode->GetFocusHub();
4013 CHECK_NULL_VOID(focusHub);
4014 focusHub->SetFocusable(true, false);
4015 }
4016
SetOnTouch(FrameNode * frameNode,TouchEventFunc && touchEventFunc)4017 void ViewAbstract::SetOnTouch(FrameNode* frameNode, TouchEventFunc &&touchEventFunc)
4018 {
4019 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
4020 CHECK_NULL_VOID(gestureHub);
4021 gestureHub->SetTouchEvent(std::move(touchEventFunc));
4022 }
4023
SetOnMouse(FrameNode * frameNode,OnMouseEventFunc && onMouseEventFunc)4024 void ViewAbstract::SetOnMouse(FrameNode* frameNode, OnMouseEventFunc &&onMouseEventFunc)
4025 {
4026 auto eventHub = frameNode->GetOrCreateInputEventHub();
4027 CHECK_NULL_VOID(eventHub);
4028 eventHub->SetMouseEvent(std::move(onMouseEventFunc));
4029 }
4030
SetOnHover(FrameNode * frameNode,OnHoverFunc && onHoverEventFunc)4031 void ViewAbstract::SetOnHover(FrameNode* frameNode, OnHoverFunc &&onHoverEventFunc)
4032 {
4033 auto eventHub = frameNode->GetOrCreateInputEventHub();
4034 CHECK_NULL_VOID(eventHub);
4035 eventHub->SetHoverEvent(std::move(onHoverEventFunc));
4036 }
4037
SetOnHoverMove(FrameNode * frameNode,OnHoverMoveFunc && onHoverMoveEventFunc)4038 void ViewAbstract::SetOnHoverMove(FrameNode* frameNode, OnHoverMoveFunc &&onHoverMoveEventFunc)
4039 {
4040 auto eventHub = frameNode->GetOrCreateInputEventHub();
4041 CHECK_NULL_VOID(eventHub);
4042 eventHub->SetHoverMoveEvent(std::move(onHoverMoveEventFunc));
4043 }
4044
SetOnKeyEvent(FrameNode * frameNode,OnKeyConsumeFunc && onKeyCallback)4045 void ViewAbstract::SetOnKeyEvent(FrameNode* frameNode, OnKeyConsumeFunc &&onKeyCallback)
4046 {
4047 auto focusHub = frameNode->GetOrCreateFocusHub();
4048 CHECK_NULL_VOID(focusHub);
4049 focusHub->SetOnKeyCallback(std::move(onKeyCallback));
4050 }
4051
SetOnKeyEventDispatch(OnKeyEventDispatchFunc && onKeyDispatchCallback)4052 void ViewAbstract::SetOnKeyEventDispatch(OnKeyEventDispatchFunc&& onKeyDispatchCallback)
4053 {
4054 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
4055 CHECK_NULL_VOID(focusHub);
4056 focusHub->SetOnKeyEventDispatchCallback(std::move(onKeyDispatchCallback));
4057 }
4058
SetOnKeyEventDispatch(FrameNode * frameNode,OnKeyEventDispatchFunc && onKeyDispatchCallback)4059 void ViewAbstract::SetOnKeyEventDispatch(FrameNode* frameNode, OnKeyEventDispatchFunc&& onKeyDispatchCallback)
4060 {
4061 CHECK_NULL_VOID(frameNode);
4062 auto focusHub = frameNode->GetOrCreateFocusHub();
4063 CHECK_NULL_VOID(focusHub);
4064 focusHub->SetOnKeyEventDispatchCallback(std::move(onKeyDispatchCallback));
4065 }
4066
DispatchKeyEvent(FrameNode * frameNode,KeyEvent & keyEvent)4067 void ViewAbstract::DispatchKeyEvent(FrameNode* frameNode, KeyEvent& keyEvent)
4068 {
4069 CHECK_NULL_VOID(frameNode);
4070 auto focusHub = frameNode->GetOrCreateFocusHub();
4071 CHECK_NULL_VOID(focusHub);
4072 focusHub->HandleEvent(keyEvent);
4073 }
4074
GetFocusable(FrameNode * frameNode)4075 bool ViewAbstract::GetFocusable(FrameNode* frameNode)
4076 {
4077 CHECK_NULL_RETURN(frameNode, false);
4078 auto focusHub = frameNode->GetOrCreateFocusHub();
4079 CHECK_NULL_RETURN(focusHub, false);
4080 return focusHub->IsFocusable();
4081 }
4082
GetTabStop(FrameNode * frameNode)4083 bool ViewAbstract::GetTabStop(FrameNode* frameNode)
4084 {
4085 CHECK_NULL_RETURN(frameNode, false);
4086 auto focusHub = frameNode->GetOrCreateFocusHub();
4087 CHECK_NULL_RETURN(focusHub, false);
4088 return focusHub->IsTabStop();
4089 }
4090
GetDefaultFocus(FrameNode * frameNode)4091 bool ViewAbstract::GetDefaultFocus(FrameNode* frameNode)
4092 {
4093 CHECK_NULL_RETURN(frameNode, false);
4094 auto focusHub = frameNode->GetOrCreateFocusHub();
4095 CHECK_NULL_RETURN(focusHub, false);
4096 return focusHub->IsDefaultFocus();
4097 }
4098
GetResponseRegion(FrameNode * frameNode)4099 std::vector<DimensionRect> ViewAbstract::GetResponseRegion(FrameNode* frameNode)
4100 {
4101 std::vector<DimensionRect> defaultRect;
4102 CHECK_NULL_RETURN(frameNode, defaultRect);
4103 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
4104 CHECK_NULL_RETURN(gestureHub, defaultRect);
4105 return gestureHub->GetResponseRegion();
4106 }
4107
GetOverlay(FrameNode * frameNode)4108 NG::OverlayOptions ViewAbstract::GetOverlay(FrameNode* frameNode)
4109 {
4110 NG::OverlayOptions defaultOptions;
4111 const auto& target = frameNode->GetRenderContext();
4112 return target->GetOverlayTextValue(defaultOptions);
4113 }
4114
SetNeedFocus(FrameNode * frameNode,bool value)4115 void ViewAbstract::SetNeedFocus(FrameNode* frameNode, bool value)
4116 {
4117 CHECK_NULL_VOID(frameNode);
4118 auto focusHub = frameNode->GetOrCreateFocusHub();
4119 CHECK_NULL_VOID(focusHub);
4120 if (value) {
4121 auto context = frameNode->GetContext();
4122 CHECK_NULL_VOID(context);
4123 auto instanceId = context->GetInstanceId();
4124 ContainerScope scope(instanceId);
4125 focusHub->RequestFocus();
4126 } else {
4127 auto context = frameNode->GetAttachedContext();
4128 if (!context) {
4129 TAG_LOGW(AceLogTag::ACE_FOCUS,
4130 "Can't find Node %{public}s/%{public}d attachedContext, please check the timing of the function call.",
4131 frameNode->GetTag().c_str(), frameNode->GetId());
4132 return;
4133 }
4134 auto instanceId = context->GetInstanceId();
4135 ContainerScope scope(instanceId);
4136 focusHub->LostFocusToViewRoot();
4137 }
4138 }
4139
GetNeedFocus(FrameNode * frameNode)4140 bool ViewAbstract::GetNeedFocus(FrameNode* frameNode)
4141 {
4142 CHECK_NULL_RETURN(frameNode, false);
4143 auto focusHub = frameNode->GetOrCreateFocusHub();
4144 CHECK_NULL_RETURN(focusHub, false);
4145 return focusHub->IsCurrentFocus();
4146 }
4147
RequestFocus(FrameNode * frameNode)4148 int ViewAbstract::RequestFocus(FrameNode* frameNode)
4149 {
4150 CHECK_NULL_RETURN(frameNode, ERROR_CODE_NON_EXIST);
4151 auto context = frameNode->GetContext();
4152 CHECK_NULL_RETURN(context, ERROR_CODE_NON_EXIST);
4153 auto instanceId = context->GetInstanceId();
4154 ContainerScope scope(instanceId);
4155 auto focusManager = context->GetOrCreateFocusManager();
4156 focusManager->ResetRequestFocusResult();
4157 auto focusHub = frameNode->GetOrCreateFocusHub();
4158 // check node focusable
4159 if (focusHub->IsSyncRequestFocusable()) {
4160 focusHub->RequestFocusImmediately();
4161 }
4162 auto retCode = focusManager->GetRequestFocusResult();
4163 focusManager->ResetRequestFocusResult();
4164 return retCode;
4165 }
4166
ClearFocus(int32_t instanceId)4167 void ViewAbstract::ClearFocus(int32_t instanceId)
4168 {
4169 auto context = PipelineContext::GetContextByContainerId(instanceId);
4170 if (!context) {
4171 TAG_LOGW(AceLogTag::ACE_FOCUS, "Can't find attachedContext, please check the timing of the function call.");
4172 return;
4173 }
4174 FocusHub::LostFocusToViewRoot();
4175 }
4176
FocusActivate(int32_t instanceId,bool isActive,bool isAutoInactive)4177 void ViewAbstract::FocusActivate(int32_t instanceId, bool isActive, bool isAutoInactive)
4178 {
4179 auto context = PipelineContext::GetContextByContainerId(instanceId);
4180 if (!context) {
4181 TAG_LOGW(AceLogTag::ACE_FOCUS, "Can't find attachedContext, please check the timing of the function call.");
4182 return;
4183 }
4184 context->SetIsFocusActive(isActive, NG::FocusActiveReason::USE_API, isAutoInactive);
4185 }
4186
SetAutoFocusTransfer(int32_t instanceId,bool isAutoFocusTransfer)4187 void ViewAbstract::SetAutoFocusTransfer(int32_t instanceId, bool isAutoFocusTransfer)
4188 {
4189 auto context = PipelineContext::GetContextByContainerId(instanceId);
4190 if (!context) {
4191 TAG_LOGW(AceLogTag::ACE_FOCUS, "Can't find attachedContext, please check the timing of the function call.");
4192 return;
4193 }
4194 auto focusManager = context->GetOrCreateFocusManager();
4195 CHECK_NULL_VOID(focusManager);
4196 focusManager->SetIsAutoFocusTransfer(isAutoFocusTransfer);
4197 }
4198
GetOpacity(FrameNode * frameNode)4199 double ViewAbstract::GetOpacity(FrameNode* frameNode)
4200 {
4201 double opacity = 1.0f;
4202 const auto& target = frameNode->GetRenderContext();
4203 CHECK_NULL_RETURN(target, opacity);
4204 return target->GetOpacityValue(opacity);
4205 }
4206
GetBorderWidth(FrameNode * frameNode)4207 BorderWidthProperty ViewAbstract::GetBorderWidth(FrameNode* frameNode)
4208 {
4209 Dimension defaultDimension(0);
4210 BorderWidthProperty borderWidths = { defaultDimension, defaultDimension, defaultDimension, defaultDimension };
4211 const auto& target = frameNode->GetRenderContext();
4212 CHECK_NULL_RETURN(target, borderWidths);
4213 return target->GetBorderWidthValue(borderWidths);
4214 }
4215
GetLayoutBorderWidth(FrameNode * frameNode)4216 BorderWidthProperty ViewAbstract::GetLayoutBorderWidth(FrameNode* frameNode)
4217 {
4218 Dimension defaultDimen = Dimension(0, DimensionUnit::VP);
4219 BorderWidthProperty borderWidths;
4220 borderWidths.topDimen = std::optional<Dimension>(defaultDimen);
4221 borderWidths.rightDimen = std::optional<Dimension>(defaultDimen);
4222 borderWidths.bottomDimen = std::optional<Dimension>(defaultDimen);
4223 borderWidths.leftDimen = std::optional<Dimension>(defaultDimen);
4224 const auto& layoutProperty = frameNode->GetLayoutProperty();
4225 CHECK_NULL_RETURN(layoutProperty, borderWidths);
4226 const auto& property = layoutProperty->GetBorderWidthProperty();
4227 CHECK_NULL_RETURN(property, borderWidths);
4228 borderWidths.topDimen = std::optional<Dimension>(property->topDimen);
4229 borderWidths.rightDimen = std::optional<Dimension>(property->rightDimen);
4230 borderWidths.bottomDimen = std::optional<Dimension>(property->bottomDimen);
4231 borderWidths.leftDimen = std::optional<Dimension>(property->leftDimen);
4232 return borderWidths;
4233 }
4234
GetBorderRadius(FrameNode * frameNode)4235 BorderRadiusProperty ViewAbstract::GetBorderRadius(FrameNode* frameNode)
4236 {
4237 Dimension defaultDimension(0);
4238 BorderRadiusProperty borderRadius = { defaultDimension, defaultDimension, defaultDimension, defaultDimension };
4239 const auto& target = frameNode->GetRenderContext();
4240 CHECK_NULL_RETURN(target, borderRadius);
4241 return target->GetBorderRadiusValue(borderRadius);
4242 }
4243
GetBorderColor(FrameNode * frameNode)4244 BorderColorProperty ViewAbstract::GetBorderColor(FrameNode* frameNode)
4245 {
4246 Color defaultColor(0xff000000);
4247 BorderColorProperty borderColors = { defaultColor, defaultColor, defaultColor, defaultColor };
4248 const auto& target = frameNode->GetRenderContext();
4249 CHECK_NULL_RETURN(target, borderColors);
4250 return target->GetBorderColorValue(borderColors);
4251 }
4252
GetBorderStyle(FrameNode * frameNode)4253 BorderStyleProperty ViewAbstract::GetBorderStyle(FrameNode* frameNode)
4254 {
4255 BorderStyle defaultStyle = BorderStyle::SOLID;
4256 BorderStyleProperty borderStyles = { defaultStyle, defaultStyle, defaultStyle, defaultStyle };
4257 const auto& target = frameNode->GetRenderContext();
4258 CHECK_NULL_RETURN(target, borderStyles);
4259 return target->GetBorderStyleValue(borderStyles);
4260 }
4261
GetZIndex(FrameNode * frameNode)4262 int ViewAbstract::GetZIndex(FrameNode* frameNode)
4263 {
4264 int zindex = 0;
4265 const auto& target = frameNode->GetRenderContext();
4266 CHECK_NULL_RETURN(target, zindex);
4267 return target->GetZIndexValue(zindex);
4268 }
4269
GetVisibility(FrameNode * frameNode)4270 VisibleType ViewAbstract::GetVisibility(FrameNode* frameNode)
4271 {
4272 VisibleType visibility = VisibleType::VISIBLE;
4273 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(LayoutProperty, Visibility, visibility, frameNode, visibility);
4274 return visibility;
4275 }
4276
GetClip(FrameNode * frameNode)4277 bool ViewAbstract::GetClip(FrameNode* frameNode)
4278 {
4279 bool value = false;
4280 const auto& target = frameNode->GetRenderContext();
4281 CHECK_NULL_RETURN(target, value);
4282 return target->GetClipEdgeValue(value);
4283 }
4284
GetClipShape(FrameNode * frameNode)4285 RefPtr<BasicShape> ViewAbstract::GetClipShape(FrameNode* frameNode)
4286 {
4287 RefPtr<BasicShape> value = AceType::MakeRefPtr<BasicShape>();
4288 const auto& target = frameNode->GetRenderContext();
4289 CHECK_NULL_RETURN(target, value);
4290 return target->GetClipShapeValue(value);
4291 }
4292
GetTransform(FrameNode * frameNode)4293 Matrix4 ViewAbstract::GetTransform(FrameNode* frameNode)
4294 {
4295 Matrix4 value;
4296 const auto& target = frameNode->GetRenderContext();
4297 CHECK_NULL_RETURN(target, value);
4298 return target->GetTransformMatrixValue(value);
4299 }
4300
GetHitTestBehavior(FrameNode * frameNode)4301 HitTestMode ViewAbstract::GetHitTestBehavior(FrameNode* frameNode)
4302 {
4303 auto gestureHub = frameNode->GetHitTestMode();
4304 return gestureHub;
4305 }
4306
GetPosition(FrameNode * frameNode)4307 OffsetT<Dimension> ViewAbstract::GetPosition(FrameNode* frameNode)
4308 {
4309 Dimension PositionX(0, DimensionUnit::VP);
4310 Dimension PositionY(0, DimensionUnit::VP);
4311 OffsetT<Dimension> position(PositionX, PositionY);
4312 const auto& target = frameNode->GetRenderContext();
4313 CHECK_NULL_RETURN(target, position);
4314 return target->GetPositionValue(position);
4315 }
4316
GetShadow(FrameNode * frameNode)4317 std::optional<Shadow> ViewAbstract::GetShadow(FrameNode* frameNode)
4318 {
4319 Shadow value;
4320 const auto& target = frameNode->GetRenderContext();
4321 CHECK_NULL_RETURN(target, value);
4322 return target->GetBackShadowValue(value);
4323 }
4324
GetSweepGradient(FrameNode * frameNode)4325 NG::Gradient ViewAbstract::GetSweepGradient(FrameNode* frameNode)
4326 {
4327 Gradient value;
4328 value.CreateGradientWithType(NG::GradientType::SWEEP);
4329 const auto& target = frameNode->GetRenderContext();
4330 CHECK_NULL_RETURN(target, value);
4331 return target->GetSweepGradientValue(value);
4332 }
4333
GetRadialGradient(FrameNode * frameNode)4334 NG::Gradient ViewAbstract::GetRadialGradient(FrameNode* frameNode)
4335 {
4336 Gradient value;
4337 value.CreateGradientWithType(NG::GradientType::RADIAL);
4338 const auto& target = frameNode->GetRenderContext();
4339 CHECK_NULL_RETURN(target, value);
4340 return target->GetRadialGradientValue(value);
4341 }
4342
GetMask(FrameNode * frameNode)4343 RefPtr<BasicShape> ViewAbstract::GetMask(FrameNode* frameNode)
4344 {
4345 RefPtr<BasicShape> value = AceType::MakeRefPtr<BasicShape>();
4346 const auto& target = frameNode->GetRenderContext();
4347 CHECK_NULL_RETURN(target, nullptr);
4348 if (target->HasClipMask()) {
4349 return target->GetClipMaskValue(value);
4350 }
4351 return nullptr;
4352 }
4353
GetMaskProgress(FrameNode * frameNode)4354 RefPtr<ProgressMaskProperty> ViewAbstract::GetMaskProgress(FrameNode* frameNode)
4355 {
4356 RefPtr<ProgressMaskProperty> value = AceType::MakeRefPtr<ProgressMaskProperty>();
4357 const auto& target = frameNode->GetRenderContext();
4358 CHECK_NULL_RETURN(target, nullptr);
4359 if (target->HasProgressMask()) {
4360 return target->GetProgressMaskValue(value);
4361 }
4362 return nullptr;
4363 }
4364
GetBlendMode(FrameNode * frameNode)4365 BlendMode ViewAbstract::GetBlendMode(FrameNode* frameNode)
4366 {
4367 BlendMode value = BlendMode::NONE;
4368 auto target = frameNode->GetRenderContext();
4369 CHECK_NULL_RETURN(target, value);
4370 return target->GetBackBlendModeValue(value);
4371 }
4372
GetDirection(FrameNode * frameNode)4373 TextDirection ViewAbstract::GetDirection(FrameNode* frameNode)
4374 {
4375 TextDirection direction = TextDirection::AUTO;
4376 auto target = frameNode->GetLayoutProperty<LayoutProperty>();
4377 direction = target->GetLayoutDirection();
4378 return direction;
4379 }
4380
GetAlignSelf(FrameNode * frameNode)4381 FlexAlign ViewAbstract::GetAlignSelf(FrameNode* frameNode)
4382 {
4383 FlexAlign value = FlexAlign::AUTO;
4384 const auto& flexItemProperty = frameNode->GetLayoutProperty()->GetFlexItemProperty();
4385 CHECK_NULL_RETURN(flexItemProperty, value);
4386 auto getValue = flexItemProperty->GetAlignSelf();
4387 if (getValue.has_value()) {
4388 return getValue.value();
4389 }
4390 return value;
4391 }
4392
GetFlexGrow(FrameNode * frameNode)4393 float ViewAbstract::GetFlexGrow(FrameNode* frameNode)
4394 {
4395 float value = 0.0f;
4396 const auto& layoutProperty = frameNode->GetLayoutProperty();
4397 CHECK_NULL_RETURN(layoutProperty, value);
4398 const auto& property = layoutProperty->GetFlexItemProperty();
4399 CHECK_NULL_RETURN(property, value);
4400 auto getValue = property->GetFlexGrow();
4401 if (getValue.has_value()) {
4402 return getValue.value();
4403 }
4404 return value;
4405 }
4406
GetFlexShrink(FrameNode * frameNode)4407 float ViewAbstract::GetFlexShrink(FrameNode* frameNode)
4408 {
4409 float value = 0.0f;
4410 const auto& layoutProperty = frameNode->GetLayoutProperty();
4411 CHECK_NULL_RETURN(layoutProperty, value);
4412 const auto& property = layoutProperty->GetFlexItemProperty();
4413 CHECK_NULL_RETURN(property, value);
4414 auto getValue = property->GetFlexShrink();
4415 if (getValue.has_value()) {
4416 return getValue.value();
4417 }
4418 return value;
4419 }
4420
GetFlexBasis(FrameNode * frameNode)4421 Dimension ViewAbstract::GetFlexBasis(FrameNode* frameNode)
4422 {
4423 Dimension value;
4424 const auto& layoutProperty = frameNode->GetLayoutProperty();
4425 CHECK_NULL_RETURN(layoutProperty, value);
4426 const auto& property = layoutProperty->GetFlexItemProperty();
4427 CHECK_NULL_RETURN(property, value);
4428 auto getValue = property->GetFlexBasis();
4429 if (getValue.has_value()) {
4430 return getValue.value();
4431 }
4432 return value;
4433 }
4434
GetMinWidth(FrameNode * frameNode)4435 Dimension ViewAbstract::GetMinWidth(FrameNode* frameNode)
4436 {
4437 Dimension value = Dimension(0.0f);
4438 const auto& layoutProperty = frameNode->GetLayoutProperty();
4439 CHECK_NULL_RETURN(layoutProperty, value);
4440 const auto& property = layoutProperty->GetCalcLayoutConstraint();
4441 CHECK_NULL_RETURN(property, value);
4442 auto size = property->minSize;
4443 if (size.has_value()) {
4444 auto width = size->Width();
4445 if (width.has_value()) {
4446 return width.value().GetDimension();
4447 }
4448 }
4449 return value;
4450 }
4451
GetMaxWidth(FrameNode * frameNode)4452 Dimension ViewAbstract::GetMaxWidth(FrameNode* frameNode)
4453 {
4454 Dimension value = Dimension(0.0f);
4455 const auto& layoutProperty = frameNode->GetLayoutProperty();
4456 CHECK_NULL_RETURN(layoutProperty, value);
4457 const auto& property = layoutProperty->GetCalcLayoutConstraint();
4458 CHECK_NULL_RETURN(property, value);
4459 auto size = property->maxSize;
4460 if (size.has_value()) {
4461 auto width = size->Width();
4462 if (width.has_value()) {
4463 return width.value().GetDimension();
4464 }
4465 }
4466 return value;
4467 }
4468
GetMinHeight(FrameNode * frameNode)4469 Dimension ViewAbstract::GetMinHeight(FrameNode* frameNode)
4470 {
4471 Dimension value = Dimension(0.0f);
4472 const auto& layoutProperty = frameNode->GetLayoutProperty();
4473 CHECK_NULL_RETURN(layoutProperty, value);
4474 const auto& property = layoutProperty->GetCalcLayoutConstraint();
4475 CHECK_NULL_RETURN(property, value);
4476 auto size = property->minSize;
4477 if (size.has_value()) {
4478 auto height = size->Height();
4479 if (height.has_value()) {
4480 return height.value().GetDimension();
4481 }
4482 }
4483 return value;
4484 }
4485
GetMaxHeight(FrameNode * frameNode)4486 Dimension ViewAbstract::GetMaxHeight(FrameNode* frameNode)
4487 {
4488 Dimension value = Dimension(0.0f);
4489 const auto& layoutProperty = frameNode->GetLayoutProperty();
4490 CHECK_NULL_RETURN(layoutProperty, value);
4491 const auto& property = layoutProperty->GetCalcLayoutConstraint();
4492 CHECK_NULL_RETURN(property, value);
4493 auto size = property->maxSize;
4494 if (size.has_value()) {
4495 auto height = size->Height();
4496 if (height.has_value()) {
4497 return height.value().GetDimension();
4498 }
4499 }
4500 return value;
4501 }
4502
GetGrayScale(FrameNode * frameNode)4503 Dimension ViewAbstract::GetGrayScale(FrameNode* frameNode)
4504 {
4505 Dimension value;
4506 auto target = frameNode->GetRenderContext();
4507 CHECK_NULL_RETURN(target, value);
4508 return target->GetFrontGrayScaleValue(value);
4509 }
4510
GetInvert(FrameNode * frameNode)4511 InvertVariant ViewAbstract::GetInvert(FrameNode* frameNode)
4512 {
4513 InvertVariant value = 0.0f;
4514 auto target = frameNode->GetRenderContext();
4515 CHECK_NULL_RETURN(target, value);
4516 return target->GetFrontInvertValue(value);
4517 }
4518
GetSepia(FrameNode * frameNode)4519 Dimension ViewAbstract::GetSepia(FrameNode* frameNode)
4520 {
4521 Dimension value;
4522 auto target = frameNode->GetRenderContext();
4523 CHECK_NULL_RETURN(target, value);
4524 return target->GetFrontSepiaValue(value);
4525 }
4526
GetContrast(FrameNode * frameNode)4527 Dimension ViewAbstract::GetContrast(FrameNode* frameNode)
4528 {
4529 Dimension value(1.0f);
4530 auto target = frameNode->GetRenderContext();
4531 CHECK_NULL_RETURN(target, value);
4532 return target->GetFrontContrastValue(value);
4533 }
4534
GetForegroundColor(FrameNode * frameNode)4535 Color ViewAbstract::GetForegroundColor(FrameNode* frameNode)
4536 {
4537 Color value;
4538 auto target = frameNode->GetRenderContext();
4539 CHECK_NULL_RETURN(target, value);
4540 return target->GetForegroundColorValue(value);
4541 }
4542
GetScale(FrameNode * frameNode)4543 NG::VectorF ViewAbstract::GetScale(FrameNode* frameNode)
4544 {
4545 NG::VectorF defaultVector = { 1.0f, 1.0f };
4546 CHECK_NULL_RETURN(frameNode, defaultVector);
4547 auto renderContext = frameNode->GetRenderContext();
4548 CHECK_NULL_RETURN(renderContext, defaultVector);
4549 return renderContext->GetTransformScale().value_or(defaultVector);
4550 }
4551
GetRotate(FrameNode * frameNode)4552 NG::Vector5F ViewAbstract::GetRotate(FrameNode* frameNode)
4553 {
4554 NG::Vector5F defaultVector = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
4555 CHECK_NULL_RETURN(frameNode, defaultVector);
4556 auto renderContext = frameNode->GetRenderContext();
4557 CHECK_NULL_RETURN(renderContext, defaultVector);
4558 return renderContext->GetTransformRotate().value_or(defaultVector);
4559 }
4560
GetBrightness(FrameNode * frameNode)4561 Dimension ViewAbstract::GetBrightness(FrameNode* frameNode)
4562 {
4563 Dimension defaultBrightness(1.0);
4564 CHECK_NULL_RETURN(frameNode, defaultBrightness);
4565 auto renderContext = frameNode->GetRenderContext();
4566 CHECK_NULL_RETURN(renderContext, defaultBrightness);
4567 return renderContext->GetFrontBrightness().value_or(defaultBrightness);
4568 }
4569
GetSaturate(FrameNode * frameNode)4570 Dimension ViewAbstract::GetSaturate(FrameNode* frameNode)
4571 {
4572 Dimension defaultSaturate(1.0);
4573 CHECK_NULL_RETURN(frameNode, defaultSaturate);
4574 auto renderContext = frameNode->GetRenderContext();
4575 CHECK_NULL_RETURN(renderContext, defaultSaturate);
4576 return renderContext->GetFrontSaturate().value_or(defaultSaturate);
4577 }
4578
GetBackgroundImagePosition(FrameNode * frameNode)4579 BackgroundImagePosition ViewAbstract::GetBackgroundImagePosition(FrameNode* frameNode)
4580 {
4581 BackgroundImagePosition defaultImagePosition;
4582 CHECK_NULL_RETURN(frameNode, defaultImagePosition);
4583 auto renderContext = frameNode->GetRenderContext();
4584 CHECK_NULL_RETURN(renderContext, defaultImagePosition);
4585 return renderContext->GetBackgroundImagePosition().value_or(defaultImagePosition);
4586 }
4587
GetFrontBlur(FrameNode * frameNode)4588 Dimension ViewAbstract::GetFrontBlur(FrameNode* frameNode)
4589 {
4590 Dimension value;
4591 auto target = frameNode->GetRenderContext();
4592 CHECK_NULL_RETURN(target, value);
4593 auto& property = target->GetForeground();
4594 CHECK_NULL_RETURN(property, value);
4595 auto getValue = property->propBlurRadius;
4596 if (getValue.has_value()) {
4597 return getValue.value();
4598 }
4599 return value;
4600 }
4601
GetLinearGradient(FrameNode * frameNode)4602 NG::Gradient ViewAbstract::GetLinearGradient(FrameNode *frameNode)
4603 {
4604 NG::Gradient value;
4605 value.CreateGradientWithType(NG::GradientType::LINEAR);
4606 auto target = frameNode->GetRenderContext();
4607 CHECK_NULL_RETURN(target, value);
4608 return target->GetLinearGradientValue(value);
4609 }
4610
GetAlign(FrameNode * frameNode)4611 Alignment ViewAbstract::GetAlign(FrameNode *frameNode)
4612 {
4613 Alignment value = Alignment::CENTER;
4614 const auto& layoutProperty = frameNode->GetLayoutProperty();
4615 CHECK_NULL_RETURN(layoutProperty, value);
4616 const auto& property = layoutProperty->GetPositionProperty();
4617 CHECK_NULL_RETURN(property, value);
4618 auto getValue = property->GetAlignment();
4619 if (getValue.has_value()) {
4620 return getValue.value();
4621 }
4622 return value;
4623 }
4624
GetWidth(FrameNode * frameNode)4625 Dimension ViewAbstract::GetWidth(FrameNode* frameNode)
4626 {
4627 Dimension value = Dimension(-1.0f);
4628 const auto& layoutProperty = frameNode->GetLayoutProperty();
4629 CHECK_NULL_RETURN(layoutProperty, value);
4630 const auto& property = layoutProperty->GetCalcLayoutConstraint();
4631 CHECK_NULL_RETURN(property, value);
4632 auto size = property->selfIdealSize;
4633 if (size.has_value()) {
4634 auto width = size->Width();
4635 if (width.has_value()) {
4636 return width.value().GetDimension();
4637 }
4638 }
4639 return value;
4640 }
4641
GetHeight(FrameNode * frameNode)4642 Dimension ViewAbstract::GetHeight(FrameNode* frameNode)
4643 {
4644 Dimension value = Dimension(-1.0f);
4645 const auto& layoutProperty = frameNode->GetLayoutProperty();
4646 CHECK_NULL_RETURN(layoutProperty, value);
4647 const auto& property = layoutProperty->GetCalcLayoutConstraint();
4648 CHECK_NULL_RETURN(property, value);
4649 auto size = property->selfIdealSize;
4650 if (size.has_value()) {
4651 auto height = size->Height();
4652 if (height.has_value()) {
4653 return height.value().GetDimension();
4654 }
4655 }
4656 return value;
4657 }
4658
GetBackgroundColor(FrameNode * frameNode)4659 Color ViewAbstract::GetBackgroundColor(FrameNode* frameNode)
4660 {
4661 Color value;
4662 auto target = frameNode->GetRenderContext();
4663 CHECK_NULL_RETURN(target, value);
4664 return target->GetBackgroundColorValue(value);
4665 }
4666
GetBackgroundImageSrc(FrameNode * frameNode)4667 std::string ViewAbstract::GetBackgroundImageSrc(FrameNode* frameNode)
4668 {
4669 auto target = frameNode->GetRenderContext();
4670 CHECK_NULL_RETURN(target, "");
4671 if (target->GetBackgroundImage().has_value()) {
4672 return target->GetBackgroundImage()->GetSrc();
4673 }
4674 return "";
4675 }
4676
GetBackgroundImageRepeat(FrameNode * frameNode)4677 ImageRepeat ViewAbstract::GetBackgroundImageRepeat(FrameNode* frameNode)
4678 {
4679 ImageRepeat value = ImageRepeat::NO_REPEAT;
4680 auto target = frameNode->GetRenderContext();
4681 CHECK_NULL_RETURN(target, value);
4682 if (target->GetBackgroundImageRepeat().has_value()) {
4683 return target->GetBackgroundImageRepeat().value();
4684 }
4685 return value;
4686 }
4687
GetPadding(FrameNode * frameNode)4688 PaddingProperty ViewAbstract::GetPadding(FrameNode* frameNode)
4689 {
4690 CalcLength defaultDimen = CalcLength(0, DimensionUnit::VP);
4691 PaddingProperty paddings;
4692 paddings.top = std::optional<CalcLength>(defaultDimen);
4693 paddings.right = std::optional<CalcLength>(defaultDimen);
4694 paddings.bottom = std::optional<CalcLength>(defaultDimen);
4695 paddings.left = std::optional<CalcLength>(defaultDimen);
4696 const auto& layoutProperty = frameNode->GetLayoutProperty();
4697 CHECK_NULL_RETURN(layoutProperty, paddings);
4698 const auto& property = layoutProperty->GetPaddingProperty();
4699 CHECK_NULL_RETURN(property, paddings);
4700 paddings.top = std::optional<CalcLength>(property->top);
4701 paddings.right = std::optional<CalcLength>(property->right);
4702 paddings.bottom = std::optional<CalcLength>(property->bottom);
4703 paddings.left = std::optional<CalcLength>(property->left);
4704 return paddings;
4705 }
4706
GetConfigSize(FrameNode * frameNode)4707 std::optional<CalcSize> ViewAbstract::GetConfigSize(FrameNode* frameNode)
4708 {
4709 auto value = std::optional<CalcSize>();
4710 const auto& layoutProperty = frameNode->GetLayoutProperty();
4711 CHECK_NULL_RETURN(layoutProperty, value);
4712 const auto& property = layoutProperty->GetCalcLayoutConstraint();
4713 CHECK_NULL_RETURN(property, value);
4714 auto size = property->selfIdealSize;
4715 if (size.has_value()) {
4716 value = size;
4717 }
4718 return value;
4719 }
4720
GetKey(FrameNode * frameNode)4721 std::string ViewAbstract::GetKey(FrameNode* frameNode)
4722 {
4723 std::string value;
4724 CHECK_NULL_RETURN(frameNode, value);
4725 return value = frameNode->GetInspectorIdValue();
4726 }
4727
GetEnabled(FrameNode * frameNode)4728 bool ViewAbstract::GetEnabled(FrameNode* frameNode)
4729 {
4730 auto eventHub = frameNode->GetEventHub<EventHub>();
4731 CHECK_NULL_RETURN(eventHub, false);
4732 return eventHub->IsEnabled();
4733 }
4734
GetMargin(FrameNode * frameNode)4735 MarginProperty ViewAbstract::GetMargin(FrameNode* frameNode)
4736 {
4737 CalcLength defaultDimen = CalcLength(0, DimensionUnit::VP);
4738 MarginProperty margins;
4739 margins.top = std::optional<CalcLength>(defaultDimen);
4740 margins.right = std::optional<CalcLength>(defaultDimen);
4741 margins.bottom = std::optional<CalcLength>(defaultDimen);
4742 margins.left = std::optional<CalcLength>(defaultDimen);
4743 const auto& layoutProperty = frameNode->GetLayoutProperty();
4744 CHECK_NULL_RETURN(layoutProperty, margins);
4745 const auto& property = layoutProperty->GetMarginProperty();
4746 CHECK_NULL_RETURN(property, margins);
4747 margins.top = std::optional<CalcLength>(property->top);
4748 margins.right = std::optional<CalcLength>(property->right);
4749 margins.bottom = std::optional<CalcLength>(property->bottom);
4750 margins.left = std::optional<CalcLength>(property->left);
4751 return margins;
4752 }
4753
GetTranslate(FrameNode * frameNode)4754 TranslateOptions ViewAbstract::GetTranslate(FrameNode* frameNode)
4755 {
4756 TranslateOptions value(0.0f, 0.0f, 0.0f);
4757 auto target = frameNode->GetRenderContext();
4758 CHECK_NULL_RETURN(target, value);
4759 return target->GetTransformTranslateValue(value);
4760 }
4761
GetAspectRatio(FrameNode * frameNode)4762 float ViewAbstract::GetAspectRatio(FrameNode* frameNode)
4763 {
4764 float aspectRatio = 1.0f;
4765 const auto& layoutProperty = frameNode->GetLayoutProperty();
4766 CHECK_NULL_RETURN(layoutProperty, aspectRatio);
4767 aspectRatio = layoutProperty->GetAspectRatio();
4768 return aspectRatio;
4769 }
4770
SetJSFrameNodeOnClick(FrameNode * frameNode,GestureEventFunc && clickEventFunc)4771 void ViewAbstract::SetJSFrameNodeOnClick(FrameNode* frameNode, GestureEventFunc&& clickEventFunc)
4772 {
4773 CHECK_NULL_VOID(frameNode);
4774 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
4775 CHECK_NULL_VOID(gestureHub);
4776 gestureHub->SetJSFrameNodeOnClick(std::move(clickEventFunc));
4777 }
4778
ClearJSFrameNodeOnClick(FrameNode * frameNode)4779 void ViewAbstract::ClearJSFrameNodeOnClick(FrameNode* frameNode)
4780 {
4781 CHECK_NULL_VOID(frameNode);
4782 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
4783 CHECK_NULL_VOID(gestureHub);
4784 gestureHub->ClearJSFrameNodeOnClick();
4785 }
4786
SetJSFrameNodeOnTouch(FrameNode * frameNode,TouchEventFunc && touchEventFunc)4787 void ViewAbstract::SetJSFrameNodeOnTouch(FrameNode* frameNode, TouchEventFunc&& touchEventFunc)
4788 {
4789 CHECK_NULL_VOID(frameNode);
4790 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
4791 CHECK_NULL_VOID(gestureHub);
4792 gestureHub->SetJSFrameNodeOnTouchEvent(std::move(touchEventFunc));
4793 }
4794
ClearJSFrameNodeOnTouch(FrameNode * frameNode)4795 void ViewAbstract::ClearJSFrameNodeOnTouch(FrameNode* frameNode)
4796 {
4797 CHECK_NULL_VOID(frameNode);
4798 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
4799 CHECK_NULL_VOID(gestureHub);
4800 gestureHub->ClearJSFrameNodeOnTouch();
4801 }
4802
SetJSFrameNodeOnAppear(FrameNode * frameNode,std::function<void ()> && onAppear)4803 void ViewAbstract::SetJSFrameNodeOnAppear(FrameNode* frameNode, std::function<void()>&& onAppear)
4804 {
4805 CHECK_NULL_VOID(frameNode);
4806 auto eventHub = frameNode->GetEventHub<NG::EventHub>();
4807 CHECK_NULL_VOID(eventHub);
4808 eventHub->SetJSFrameNodeOnAppear(std::move(onAppear));
4809 }
4810
ClearJSFrameNodeOnAppear(FrameNode * frameNode)4811 void ViewAbstract::ClearJSFrameNodeOnAppear(FrameNode* frameNode)
4812 {
4813 CHECK_NULL_VOID(frameNode);
4814 auto eventHub = frameNode->GetEventHub<NG::EventHub>();
4815 CHECK_NULL_VOID(eventHub);
4816 eventHub->ClearJSFrameNodeOnAppear();
4817 }
4818
SetJSFrameNodeOnDisappear(FrameNode * frameNode,std::function<void ()> && onDisappear)4819 void ViewAbstract::SetJSFrameNodeOnDisappear(FrameNode* frameNode, std::function<void()>&& onDisappear)
4820 {
4821 CHECK_NULL_VOID(frameNode);
4822 auto eventHub = frameNode->GetEventHub<NG::EventHub>();
4823 CHECK_NULL_VOID(eventHub);
4824 eventHub->SetJSFrameNodeOnDisappear(std::move(onDisappear));
4825 }
4826
ClearJSFrameNodeOnDisappear(FrameNode * frameNode)4827 void ViewAbstract::ClearJSFrameNodeOnDisappear(FrameNode* frameNode)
4828 {
4829 CHECK_NULL_VOID(frameNode);
4830 auto eventHub = frameNode->GetEventHub<NG::EventHub>();
4831 CHECK_NULL_VOID(eventHub);
4832 eventHub->ClearJSFrameNodeOnDisappear();
4833 }
4834
SetJSFrameNodeOnKeyCallback(FrameNode * frameNode,OnKeyCallbackFunc && onKeyCallback)4835 void ViewAbstract::SetJSFrameNodeOnKeyCallback(FrameNode* frameNode, OnKeyCallbackFunc&& onKeyCallback)
4836 {
4837 CHECK_NULL_VOID(frameNode);
4838 auto focusHub = frameNode->GetOrCreateFocusHub();
4839 CHECK_NULL_VOID(focusHub);
4840 focusHub->SetJSFrameNodeOnKeyCallback(std::move(onKeyCallback));
4841 }
4842
ClearJSFrameNodeOnKeyCallback(FrameNode * frameNode)4843 void ViewAbstract::ClearJSFrameNodeOnKeyCallback(FrameNode* frameNode)
4844 {
4845 CHECK_NULL_VOID(frameNode);
4846 auto focusHub = frameNode->GetOrCreateFocusHub();
4847 CHECK_NULL_VOID(focusHub);
4848 focusHub->ClearJSFrameNodeOnKeyCallback();
4849 }
4850
SetJSFrameNodeOnFocusCallback(FrameNode * frameNode,OnFocusFunc && onFocusCallback)4851 void ViewAbstract::SetJSFrameNodeOnFocusCallback(FrameNode* frameNode, OnFocusFunc&& onFocusCallback)
4852 {
4853 CHECK_NULL_VOID(frameNode);
4854 auto focusHub = frameNode->GetOrCreateFocusHub();
4855 CHECK_NULL_VOID(focusHub);
4856 focusHub->SetJSFrameNodeOnFocusCallback(std::move(onFocusCallback));
4857 }
4858
ClearJSFrameNodeOnFocusCallback(FrameNode * frameNode)4859 void ViewAbstract::ClearJSFrameNodeOnFocusCallback(FrameNode* frameNode)
4860 {
4861 CHECK_NULL_VOID(frameNode);
4862 auto focusHub = frameNode->GetOrCreateFocusHub();
4863 CHECK_NULL_VOID(focusHub);
4864 focusHub->ClearJSFrameNodeOnFocusCallback();
4865 }
4866
SetJSFrameNodeOnBlurCallback(FrameNode * frameNode,OnBlurFunc && onBlurCallback)4867 void ViewAbstract::SetJSFrameNodeOnBlurCallback(FrameNode* frameNode, OnBlurFunc&& onBlurCallback)
4868 {
4869 CHECK_NULL_VOID(frameNode);
4870 auto focusHub = frameNode->GetOrCreateFocusHub();
4871 CHECK_NULL_VOID(focusHub);
4872 focusHub->SetJSFrameNodeOnBlurCallback(std::move(onBlurCallback));
4873 }
4874
ClearJSFrameNodeOnBlurCallback(FrameNode * frameNode)4875 void ViewAbstract::ClearJSFrameNodeOnBlurCallback(FrameNode* frameNode)
4876 {
4877 CHECK_NULL_VOID(frameNode);
4878 auto focusHub = frameNode->GetOrCreateFocusHub();
4879 CHECK_NULL_VOID(focusHub);
4880 focusHub->ClearJSFrameNodeOnBlurCallback();
4881 }
4882
SetJSFrameNodeOnHover(FrameNode * frameNode,OnHoverFunc && onHoverEventFunc)4883 void ViewAbstract::SetJSFrameNodeOnHover(FrameNode* frameNode, OnHoverFunc&& onHoverEventFunc)
4884 {
4885 CHECK_NULL_VOID(frameNode);
4886 auto eventHub = frameNode->GetOrCreateInputEventHub();
4887 CHECK_NULL_VOID(eventHub);
4888 eventHub->SetJSFrameNodeOnHoverEvent(std::move(onHoverEventFunc));
4889 }
4890
ClearJSFrameNodeOnHover(FrameNode * frameNode)4891 void ViewAbstract::ClearJSFrameNodeOnHover(FrameNode* frameNode)
4892 {
4893 CHECK_NULL_VOID(frameNode);
4894 auto eventHub = frameNode->GetOrCreateInputEventHub();
4895 CHECK_NULL_VOID(eventHub);
4896 eventHub->ClearJSFrameNodeOnHover();
4897 }
4898
SetJSFrameNodeOnHoverMove(FrameNode * frameNode,OnHoverMoveFunc && onHoverMoveEventFunc)4899 void ViewAbstract::SetJSFrameNodeOnHoverMove(FrameNode* frameNode, OnHoverMoveFunc&& onHoverMoveEventFunc)
4900 {
4901 CHECK_NULL_VOID(frameNode);
4902 auto eventHub = frameNode->GetOrCreateInputEventHub();
4903 CHECK_NULL_VOID(eventHub);
4904 eventHub->SetJSFrameNodeOnHoverMoveEvent(std::move(onHoverMoveEventFunc));
4905 }
4906
ClearJSFrameNodeOnHoverMove(FrameNode * frameNode)4907 void ViewAbstract::ClearJSFrameNodeOnHoverMove(FrameNode* frameNode)
4908 {
4909 CHECK_NULL_VOID(frameNode);
4910 auto eventHub = frameNode->GetOrCreateInputEventHub();
4911 CHECK_NULL_VOID(eventHub);
4912 eventHub->ClearJSFrameNodeOnHoverMove();
4913 }
4914
SetJSFrameNodeOnMouse(FrameNode * frameNode,OnMouseEventFunc && onMouseEventFunc)4915 void ViewAbstract::SetJSFrameNodeOnMouse(FrameNode* frameNode, OnMouseEventFunc&& onMouseEventFunc)
4916 {
4917 CHECK_NULL_VOID(frameNode);
4918 auto eventHub = frameNode->GetOrCreateInputEventHub();
4919 CHECK_NULL_VOID(eventHub);
4920 eventHub->SetJSFrameNodeOnMouseEvent(std::move(onMouseEventFunc));
4921 }
4922
ClearJSFrameNodeOnMouse(FrameNode * frameNode)4923 void ViewAbstract::ClearJSFrameNodeOnMouse(FrameNode* frameNode)
4924 {
4925 CHECK_NULL_VOID(frameNode);
4926 auto eventHub = frameNode->GetOrCreateInputEventHub();
4927 CHECK_NULL_VOID(eventHub);
4928 eventHub->ClearJSFrameNodeOnMouse();
4929 }
4930
GetBlendApplyType(FrameNode * frameNode)4931 BlendApplyType ViewAbstract::GetBlendApplyType(FrameNode* frameNode)
4932 {
4933 BlendApplyType value = BlendApplyType::FAST;
4934 const auto& target = frameNode->GetRenderContext();
4935 CHECK_NULL_RETURN(target, value);
4936 return target->GetBackBlendApplyTypeValue(value);
4937 }
4938
SetJSFrameNodeOnSizeChange(FrameNode * frameNode,std::function<void (const RectF & oldRect,const RectF & rect)> && onSizeChanged)4939 void ViewAbstract::SetJSFrameNodeOnSizeChange(
4940 FrameNode* frameNode, std::function<void(const RectF& oldRect, const RectF& rect)>&& onSizeChanged)
4941 {
4942 CHECK_NULL_VOID(frameNode);
4943 frameNode->SetJSFrameNodeOnSizeChangeCallback(std::move(onSizeChanged));
4944 }
4945
ClearJSFrameNodeOnSizeChange(FrameNode * frameNode)4946 void ViewAbstract::ClearJSFrameNodeOnSizeChange(FrameNode* frameNode)
4947 {
4948 CHECK_NULL_VOID(frameNode);
4949 auto eventHub = frameNode->GetEventHub<NG::EventHub>();
4950 CHECK_NULL_VOID(eventHub);
4951 eventHub->ClearJSFrameNodeOnSizeChange();
4952 }
4953
SetJSFrameNodeOnVisibleAreaApproximateChange(FrameNode * frameNode,const std::function<void (bool,double)> && jsCallback,const std::vector<double> & ratioList,int32_t interval)4954 void ViewAbstract::SetJSFrameNodeOnVisibleAreaApproximateChange(FrameNode* frameNode,
4955 const std::function<void(bool, double)>&& jsCallback, const std::vector<double>& ratioList,
4956 int32_t interval)
4957 {
4958 CHECK_NULL_VOID(frameNode);
4959 auto pipeline = frameNode->GetContext();
4960 CHECK_NULL_VOID(pipeline);
4961 frameNode->CleanVisibleAreaUserCallback(true);
4962
4963 constexpr uint32_t minInterval = 100; // 100ms
4964 if (interval < 0 || static_cast<uint32_t>(interval) < minInterval) {
4965 interval = minInterval;
4966 }
4967 VisibleCallbackInfo callback;
4968 callback.callback = std::move(jsCallback);
4969 callback.isCurrentVisible = false;
4970 callback.period = static_cast<uint32_t>(interval);
4971 pipeline->AddVisibleAreaChangeNode(frameNode->GetId());
4972 frameNode->SetVisibleAreaUserCallback(ratioList, callback);
4973 }
4974
ClearJSFrameNodeOnVisibleAreaApproximateChange(FrameNode * frameNode)4975 void ViewAbstract::ClearJSFrameNodeOnVisibleAreaApproximateChange(FrameNode* frameNode)
4976 {
4977 CHECK_NULL_VOID(frameNode);
4978 frameNode->CleanVisibleAreaUserCallback(true);
4979 }
4980
SetOnGestureJudgeBegin(FrameNode * frameNode,GestureJudgeFunc && gestureJudgeFunc)4981 void ViewAbstract::SetOnGestureJudgeBegin(FrameNode* frameNode, GestureJudgeFunc&& gestureJudgeFunc)
4982 {
4983 CHECK_NULL_VOID(frameNode);
4984 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
4985 CHECK_NULL_VOID(gestureHub);
4986 gestureHub->SetOnGestureJudgeBegin(std::move(gestureJudgeFunc));
4987 }
4988
SetOnSizeChanged(FrameNode * frameNode,std::function<void (const RectF & oldRect,const RectF & rect)> && onSizeChanged)4989 void ViewAbstract::SetOnSizeChanged(
4990 FrameNode* frameNode, std::function<void(const RectF& oldRect, const RectF& rect)>&& onSizeChanged)
4991 {
4992 CHECK_NULL_VOID(frameNode);
4993 frameNode->SetOnSizeChangeCallback(std::move(onSizeChanged));
4994 }
4995
SetOnGestureRecognizerJudgeBegin(FrameNode * frameNode,GestureRecognizerJudgeFunc && gestureRecognizerJudgeFunc)4996 void ViewAbstract::SetOnGestureRecognizerJudgeBegin(
4997 FrameNode* frameNode, GestureRecognizerJudgeFunc&& gestureRecognizerJudgeFunc)
4998 {
4999 CHECK_NULL_VOID(frameNode);
5000 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
5001 CHECK_NULL_VOID(gestureHub);
5002 gestureHub->SetOnGestureRecognizerJudgeBegin(std::move(gestureRecognizerJudgeFunc));
5003 }
5004
SetShouldBuiltInRecognizerParallelWith(FrameNode * frameNode,NG::ShouldBuiltInRecognizerParallelWithFunc && shouldBuiltInRecognizerParallelWithFunc)5005 void ViewAbstract::SetShouldBuiltInRecognizerParallelWith(
5006 FrameNode* frameNode, NG::ShouldBuiltInRecognizerParallelWithFunc&& shouldBuiltInRecognizerParallelWithFunc)
5007 {
5008 CHECK_NULL_VOID(frameNode);
5009 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
5010 CHECK_NULL_VOID(gestureHub);
5011 gestureHub->SetShouldBuildinRecognizerParallelWithFunc(std::move(shouldBuiltInRecognizerParallelWithFunc));
5012 }
5013
SetFocusBoxStyle(FrameNode * frameNode,const NG::FocusBoxStyle & style)5014 void ViewAbstract::SetFocusBoxStyle(FrameNode* frameNode, const NG::FocusBoxStyle& style)
5015 {
5016 CHECK_NULL_VOID(frameNode);
5017 auto focusHub = frameNode->GetOrCreateFocusHub();
5018 CHECK_NULL_VOID(focusHub);
5019 focusHub->GetFocusBox().SetStyle(style);
5020 }
5021
SetDragEventStrictReportingEnabled(bool dragEventStrictReportingEnabled)5022 void ViewAbstract::SetDragEventStrictReportingEnabled(bool dragEventStrictReportingEnabled)
5023 {
5024 auto pipeline = PipelineContext::GetCurrentContext();
5025 CHECK_NULL_VOID(pipeline);
5026 auto dragDropManager = pipeline->GetDragDropManager();
5027 CHECK_NULL_VOID(dragDropManager);
5028 dragDropManager->SetEventStrictReportingEnabled(dragEventStrictReportingEnabled);
5029 }
5030
SetDragEventStrictReportingEnabled(int32_t instanceId,bool dragEventStrictReportingEnabled)5031 void ViewAbstract::SetDragEventStrictReportingEnabled(int32_t instanceId, bool dragEventStrictReportingEnabled)
5032 {
5033 auto pipeline = PipelineContext::GetContextByContainerId(instanceId);
5034 CHECK_NULL_VOID(pipeline);
5035 auto dragDropManager = pipeline->GetDragDropManager();
5036 CHECK_NULL_VOID(dragDropManager);
5037 dragDropManager->SetEventStrictReportingEnabled(dragEventStrictReportingEnabled);
5038 }
5039
SetDisallowDropForcedly(bool isDisallowDropForcedly)5040 void ViewAbstract::SetDisallowDropForcedly(bool isDisallowDropForcedly)
5041 {
5042 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5043 CHECK_NULL_VOID(frameNode);
5044 frameNode->SetDisallowDropForcedly(isDisallowDropForcedly);
5045 }
5046
SetBackgroundImageResizableSlice(const ImageResizableSlice & slice)5047 void ViewAbstract::SetBackgroundImageResizableSlice(const ImageResizableSlice& slice)
5048 {
5049 if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) {
5050 return;
5051 }
5052 ACE_UPDATE_RENDER_CONTEXT(BackgroundImageResizableSlice, slice);
5053 }
5054
SetBackgroundImageResizableSlice(FrameNode * frameNode,const ImageResizableSlice & slice)5055 void ViewAbstract::SetBackgroundImageResizableSlice(FrameNode* frameNode, const ImageResizableSlice& slice)
5056 {
5057 ACE_UPDATE_NODE_RENDER_CONTEXT(BackgroundImageResizableSlice, slice, frameNode);
5058 }
SetOnTouchIntercept(FrameNode * frameNode,TouchInterceptFunc && touchInterceptFunc)5059 void ViewAbstract::SetOnTouchIntercept(FrameNode* frameNode, TouchInterceptFunc&& touchInterceptFunc)
5060 {
5061 auto gestureHub = frameNode->GetOrCreateGestureEventHub();
5062 CHECK_NULL_VOID(gestureHub);
5063 gestureHub->SetOnTouchIntercept(std::move(touchInterceptFunc));
5064 }
5065
GetLayoutWeight(FrameNode * frameNode)5066 float ViewAbstract::GetLayoutWeight(FrameNode* frameNode)
5067 {
5068 float layoutWeight = 0.0f;
5069 CHECK_NULL_RETURN(frameNode, layoutWeight);
5070 auto layoutProperty = frameNode->GetLayoutProperty();
5071 CHECK_NULL_RETURN(layoutProperty, layoutWeight);
5072 auto& magicItemProperty = layoutProperty->GetMagicItemProperty();
5073 if (magicItemProperty.HasLayoutWeight()) {
5074 return magicItemProperty.GetLayoutWeight().value_or(layoutWeight);
5075 }
5076 return layoutWeight;
5077 }
5078
GetDisplayIndex(FrameNode * frameNode)5079 int32_t ViewAbstract::GetDisplayIndex(FrameNode* frameNode)
5080 {
5081 int32_t defaultDisplayIndex = 0;
5082 CHECK_NULL_RETURN(frameNode, defaultDisplayIndex);
5083 const auto& layoutProperty = frameNode->GetLayoutProperty();
5084 CHECK_NULL_RETURN(layoutProperty, defaultDisplayIndex);
5085 const auto& flexItemProperty = layoutProperty->GetFlexItemProperty();
5086 CHECK_NULL_RETURN(flexItemProperty, defaultDisplayIndex);
5087 return flexItemProperty->GetDisplayIndex().value_or(defaultDisplayIndex);
5088 }
5089
GetOuterBorderWidth(FrameNode * frameNode)5090 NG::BorderWidthProperty ViewAbstract::GetOuterBorderWidth(FrameNode* frameNode)
5091 {
5092 BorderWidthProperty borderWidth;
5093 CHECK_NULL_RETURN(frameNode, borderWidth);
5094 auto context = frameNode->GetRenderContext();
5095 CHECK_NULL_RETURN(context, borderWidth);
5096 auto outBorderWidth = context->GetOuterBorder()->GetOuterBorderWidth();
5097 CHECK_NULL_RETURN(outBorderWidth, borderWidth);
5098 return outBorderWidth.value_or(borderWidth);
5099 }
5100
SetBias(FrameNode * frameNode,const BiasPair & biasPair)5101 void ViewAbstract::SetBias(FrameNode* frameNode, const BiasPair& biasPair)
5102 {
5103 CHECK_NULL_VOID(frameNode);
5104 ACE_UPDATE_NODE_LAYOUT_PROPERTY(LayoutProperty, Bias, biasPair, frameNode);
5105 }
5106
GetBias(FrameNode * frameNode)5107 BiasPair ViewAbstract::GetBias(FrameNode* frameNode)
5108 {
5109 BiasPair biasPair(-1.0f, -1.0f);
5110 CHECK_NULL_RETURN(frameNode, biasPair);
5111 auto layoutProperty = frameNode->GetLayoutProperty();
5112 CHECK_NULL_RETURN(layoutProperty, biasPair);
5113 CHECK_NULL_RETURN(layoutProperty->GetFlexItemProperty(), biasPair);
5114 return layoutProperty->GetFlexItemProperty()->GetBias().value_or(biasPair);
5115 }
5116
ResetBias(FrameNode * frameNode)5117 void ViewAbstract::ResetBias(FrameNode* frameNode)
5118 {
5119 CHECK_NULL_VOID(frameNode);
5120 auto layoutProperty = frameNode->GetLayoutProperty();
5121 CHECK_NULL_VOID(layoutProperty);
5122 CHECK_NULL_VOID(layoutProperty->GetFlexItemProperty());
5123 layoutProperty->GetFlexItemProperty()->ResetBias();
5124 }
5125
GetRenderFit(FrameNode * frameNode)5126 RenderFit ViewAbstract::GetRenderFit(FrameNode* frameNode)
5127 {
5128 RenderFit defalutRenderFit = RenderFit::TOP_LEFT;
5129 CHECK_NULL_RETURN(frameNode, defalutRenderFit);
5130 auto renderContext = frameNode->GetRenderContext();
5131 CHECK_NULL_RETURN(renderContext, defalutRenderFit);
5132 return renderContext->GetRenderFit().value_or(defalutRenderFit);
5133 }
5134
GetOuterBorderColor(FrameNode * frameNode)5135 BorderColorProperty ViewAbstract::GetOuterBorderColor(FrameNode* frameNode)
5136 {
5137 Color defaultColor(0xff000000);
5138 BorderColorProperty borderColors = { defaultColor, defaultColor, defaultColor, defaultColor };
5139 CHECK_NULL_RETURN(frameNode, borderColors);
5140 const auto& target = frameNode->GetRenderContext();
5141 CHECK_NULL_RETURN(target, borderColors);
5142 return target->GetOuterBorderColorValue(borderColors);
5143 }
5144
GetRenderGroup(FrameNode * frameNode)5145 bool ViewAbstract::GetRenderGroup(FrameNode* frameNode)
5146 {
5147 CHECK_NULL_RETURN(frameNode, false);
5148 const auto& target = frameNode->GetRenderContext();
5149 CHECK_NULL_RETURN(target, false);
5150 return target->GetRenderGroupValue(false);
5151 }
5152
SetLayoutRect(FrameNode * frameNode,const NG::RectF & rect)5153 void ViewAbstract::SetLayoutRect(FrameNode* frameNode, const NG::RectF& rect)
5154 {
5155 CHECK_NULL_VOID(frameNode);
5156 frameNode->SetIsMeasureBoundary(true);
5157 const auto& layoutProperty = frameNode->GetLayoutProperty();
5158 CHECK_NULL_VOID(layoutProperty);
5159 layoutProperty->SetLayoutRect(rect);
5160 }
5161
ResetLayoutRect(FrameNode * frameNode)5162 void ViewAbstract::ResetLayoutRect(FrameNode* frameNode)
5163 {
5164 CHECK_NULL_VOID(frameNode);
5165 frameNode->SetIsMeasureBoundary(false);
5166 const auto& layoutProperty = frameNode->GetLayoutProperty();
5167 CHECK_NULL_VOID(layoutProperty);
5168 layoutProperty->ResetLayoutRect();
5169 }
5170
GetLayoutRect(FrameNode * frameNode)5171 NG::RectF ViewAbstract::GetLayoutRect(FrameNode* frameNode)
5172 {
5173 CHECK_NULL_RETURN(frameNode, NG::RectF());
5174 const auto& layoutProperty = frameNode->GetLayoutProperty();
5175 CHECK_NULL_RETURN(layoutProperty, NG::RectF());
5176 return layoutProperty->GetLayoutRect().value_or(NG::RectF());
5177 }
5178
GetFocusOnTouch(FrameNode * frameNode)5179 bool ViewAbstract::GetFocusOnTouch(FrameNode* frameNode)
5180 {
5181 CHECK_NULL_RETURN(frameNode, false);
5182 auto focusHub = frameNode->GetFocusHub();
5183 CHECK_NULL_RETURN(focusHub, false);
5184 return focusHub->IsFocusOnTouch().value_or(false);
5185 }
5186
SetFocusScopeId(const std::string & focusScopeId,bool isGroup,bool arrowKeyStepOut)5187 void ViewAbstract::SetFocusScopeId(const std::string& focusScopeId, bool isGroup, bool arrowKeyStepOut)
5188 {
5189 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
5190 CHECK_NULL_VOID(focusHub);
5191 focusHub->SetFocusScopeId(focusScopeId, isGroup, arrowKeyStepOut);
5192 }
5193
SetFocusScopePriority(const std::string & focusScopeId,const uint32_t focusPriority)5194 void ViewAbstract::SetFocusScopePriority(const std::string& focusScopeId, const uint32_t focusPriority)
5195 {
5196 auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
5197 CHECK_NULL_VOID(focusHub);
5198 focusHub->SetFocusScopePriority(focusScopeId, focusPriority);
5199 }
5200
SetFocusScopeId(FrameNode * frameNode,const std::string & focusScopeId,bool isGroup,bool arrowKeyStepOut)5201 void ViewAbstract::SetFocusScopeId(FrameNode* frameNode, const std::string& focusScopeId, bool isGroup,
5202 bool arrowKeyStepOut)
5203 {
5204 CHECK_NULL_VOID(frameNode);
5205 auto focusHub = frameNode->GetOrCreateFocusHub();
5206 CHECK_NULL_VOID(focusHub);
5207 focusHub->SetFocusScopeId(focusScopeId, isGroup, arrowKeyStepOut);
5208 }
5209
SetFocusScopePriority(FrameNode * frameNode,const std::string & focusScopeId,const uint32_t focusPriority)5210 void ViewAbstract::SetFocusScopePriority(FrameNode* frameNode, const std::string& focusScopeId,
5211 const uint32_t focusPriority)
5212 {
5213 CHECK_NULL_VOID(frameNode);
5214 auto focusHub = frameNode->GetOrCreateFocusHub();
5215 CHECK_NULL_VOID(focusHub);
5216 focusHub->SetFocusScopePriority(focusScopeId, focusPriority);
5217 }
5218
GetSafeAreaExpandType(FrameNode * frameNode)5219 uint32_t ViewAbstract::GetSafeAreaExpandType(FrameNode* frameNode)
5220 {
5221 uint32_t value = SAFE_AREA_TYPE_ALL;
5222 CHECK_NULL_RETURN(frameNode, value);
5223 const auto& layoutProperty = frameNode->GetLayoutProperty();
5224 CHECK_NULL_RETURN(layoutProperty, value);
5225 const auto& SafeAreaExpandOpts = layoutProperty->GetSafeAreaExpandOpts();
5226 CHECK_NULL_RETURN(SafeAreaExpandOpts, value);
5227 if (SafeAreaExpandOpts->type > 0) {
5228 value = SafeAreaExpandOpts->type;
5229 }
5230 return value;
5231 }
5232
GetSafeAreaExpandEdges(FrameNode * frameNode)5233 uint32_t ViewAbstract::GetSafeAreaExpandEdges(FrameNode* frameNode)
5234 {
5235 uint32_t value = SAFE_AREA_EDGE_ALL;
5236 CHECK_NULL_RETURN(frameNode, value);
5237 const auto& layoutProperty = frameNode->GetLayoutProperty();
5238 CHECK_NULL_RETURN(layoutProperty, value);
5239 const auto& SafeAreaExpandOpts = layoutProperty->GetSafeAreaExpandOpts();
5240 CHECK_NULL_RETURN(SafeAreaExpandOpts, value);
5241 if (SafeAreaExpandOpts->edges > 0) {
5242 value = SafeAreaExpandOpts->edges;
5243 }
5244 return value;
5245 }
5246
SetPositionLocalizedEdges(bool needLocalized)5247 void ViewAbstract::SetPositionLocalizedEdges(bool needLocalized)
5248 {
5249 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5250 CHECK_NULL_VOID(frameNode);
5251 auto layoutProperty = frameNode->GetLayoutProperty();
5252 CHECK_NULL_VOID(layoutProperty);
5253 layoutProperty->UpdateNeedPositionLocalizedEdges(needLocalized);
5254 }
5255
SetLocalizedMarkAnchor(bool needLocalized)5256 void ViewAbstract::SetLocalizedMarkAnchor(bool needLocalized)
5257 {
5258 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5259 CHECK_NULL_VOID(frameNode);
5260 auto layoutProperty = frameNode->GetLayoutProperty();
5261 CHECK_NULL_VOID(layoutProperty);
5262 layoutProperty->UpdatNeedMarkAnchorPosition(needLocalized);
5263 }
5264
SetOffsetLocalizedEdges(bool needLocalized)5265 void ViewAbstract::SetOffsetLocalizedEdges(bool needLocalized)
5266 {
5267 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
5268 CHECK_NULL_VOID(frameNode);
5269 auto layoutProperty = frameNode->GetLayoutProperty();
5270 CHECK_NULL_VOID(layoutProperty);
5271 layoutProperty->UpdateNeedOffsetLocalizedEdges(needLocalized);
5272 }
5273
SetSystemColorModeChangeEvent(FrameNode * frameNode,std::function<void (int32_t)> && onColorModeChange)5274 void ViewAbstract::SetSystemColorModeChangeEvent(
5275 FrameNode* frameNode, std::function<void(int32_t)>&& onColorModeChange)
5276 {
5277 CHECK_NULL_VOID(frameNode);
5278 frameNode->SetNDKColorModeUpdateCallback(std::move(onColorModeChange));
5279 }
5280
SetSystemFontChangeEvent(FrameNode * frameNode,std::function<void (float,float)> && onFontChange)5281 void ViewAbstract::SetSystemFontChangeEvent(FrameNode* frameNode, std::function<void(float, float)>&& onFontChange)
5282 {
5283 CHECK_NULL_VOID(frameNode);
5284 frameNode->SetNDKFontUpdateCallback(std::move(onFontChange));
5285 }
5286
SetDrawCompleteEvent(FrameNode * frameNode,std::function<void ()> && onDraw)5287 void ViewAbstract::SetDrawCompleteEvent(
5288 FrameNode* frameNode, std::function<void()>&& onDraw)
5289 {
5290 CHECK_NULL_VOID(frameNode);
5291 auto eventHub = frameNode->GetEventHub<NG::EventHub>();
5292 CHECK_NULL_VOID(eventHub);
5293 eventHub->SetNDKDrawCompletedCallback(std::move(onDraw));
5294 }
5295
SetLayoutEvent(FrameNode * frameNode,std::function<void ()> && onLayout)5296 void ViewAbstract::SetLayoutEvent(
5297 FrameNode* frameNode, std::function<void()>&& onLayout)
5298 {
5299 CHECK_NULL_VOID(frameNode);
5300 auto eventHub = frameNode->GetEventHub<NG::EventHub>();
5301 CHECK_NULL_VOID(eventHub);
5302 eventHub->SetNDKLayoutCallback(std::move(onLayout));
5303 }
5304
AddCustomProperty(UINode * frameNode,const std::string & key,const std::string & value)5305 void ViewAbstract::AddCustomProperty(UINode* frameNode, const std::string& key, const std::string& value)
5306 {
5307 CHECK_NULL_VOID(frameNode);
5308 frameNode->AddCustomProperty(key, value);
5309 }
5310
RemoveCustomProperty(UINode * frameNode,const std::string & key)5311 void ViewAbstract::RemoveCustomProperty(UINode* frameNode, const std::string& key)
5312 {
5313 CHECK_NULL_VOID(frameNode);
5314 frameNode->RemoveCustomProperty(key);
5315 }
5316
CancelDataLoading(const std::string & key)5317 int32_t ViewAbstract::CancelDataLoading(const std::string& key)
5318 {
5319 auto pipeline = PipelineContext::GetCurrentContext();
5320 CHECK_NULL_RETURN(pipeline, -1);
5321 auto dragDropManager = pipeline->GetDragDropManager();
5322 CHECK_NULL_RETURN(dragDropManager, -1);
5323 return dragDropManager->CancelUDMFDataLoading(key);
5324 }
5325
SetDisableDataPrefetch(bool disableDataPrefetch)5326 void ViewAbstract::SetDisableDataPrefetch(bool disableDataPrefetch)
5327 {
5328 auto eventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<EventHub>();
5329 CHECK_NULL_VOID(eventHub);
5330 eventHub->SetDisableDataPrefetch(disableDataPrefetch);
5331 }
5332
SetDisableDataPrefetch(FrameNode * frameNode,bool disableDataPrefetch)5333 void ViewAbstract::SetDisableDataPrefetch(FrameNode* frameNode, bool disableDataPrefetch)
5334 {
5335 CHECK_NULL_VOID(frameNode);
5336 auto eventHub = frameNode->GetEventHub<EventHub>();
5337 CHECK_NULL_VOID(eventHub);
5338
5339 eventHub->SetDisableDataPrefetch(disableDataPrefetch);
5340 }
5341 } // namespace OHOS::Ace::NG
5342