• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h"
17 
18 #include "base/log/ace_scoring_log.h"
19 #include "bridge/declarative_frontend/jsview/js_interactable_view.h"
20 #include "bridge/declarative_frontend/jsview/models/grid_container_model_impl.h"
21 #include "bridge/declarative_frontend/view_stack_processor.h"
22 #include "core/components/box/box_component_helper.h"
23 #include "core/gestures/long_press_gesture.h"
24 
25 // avoid windows build error about macro defined in winuser.h
26 #ifdef GetMessage
27 #undef GetMessage
28 #endif
29 
30 namespace OHOS::Ace::Framework {
31 
32 constexpr int32_t DEFAULT_LONG_PRESS_FINGER = 1;
33 constexpr int32_t DEFAULT_LONG_PRESS_DURATION = 500;
34 
GetBackDecoration()35 RefPtr<Decoration> GetBackDecoration()
36 {
37     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
38     auto decoration = box->GetBackDecoration();
39     if (!decoration) {
40         decoration = AceType::MakeRefPtr<Decoration>();
41         box->SetBackDecoration(decoration);
42     }
43     return decoration;
44 }
45 
GetFrontDecoration()46 RefPtr<Decoration> GetFrontDecoration()
47 {
48     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
49     auto decoration = box->GetFrontDecoration();
50     if (!decoration) {
51         decoration = AceType::MakeRefPtr<Decoration>();
52         box->SetFrontDecoration(decoration);
53     }
54 
55     return decoration;
56 }
57 
ToAnimatableDimension(const Dimension & dimension)58 AnimatableDimension ToAnimatableDimension(const Dimension& dimension)
59 {
60     AnimatableDimension result(dimension);
61     AnimationOption option = ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
62     result.SetAnimationOption(option);
63     return result;
64 }
65 
ToGradient(const NG::Gradient & gradient)66 Gradient ToGradient(const NG::Gradient& gradient)
67 {
68     Gradient retGradient;
69     retGradient.SetType(static_cast<GradientType>(gradient.GetType()));
70     AnimationOption option = ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
71     if (retGradient.GetType() == GradientType::LINEAR) {
72         auto angle = gradient.GetLinearGradient()->angle;
73         if (angle.has_value()) {
74             retGradient.GetLinearGradient().angle = ToAnimatableDimension(angle.value());
75         }
76         auto linearX = gradient.GetLinearGradient()->linearX;
77         if (linearX.has_value()) {
78             retGradient.GetLinearGradient().linearX = static_cast<GradientDirection>(linearX.value());
79         }
80         auto linearY = gradient.GetLinearGradient()->linearY;
81         if (linearY.has_value()) {
82             retGradient.GetLinearGradient().linearY = static_cast<GradientDirection>(linearY.value());
83         }
84     }
85 
86     if (retGradient.GetType() == GradientType::RADIAL) {
87         auto radialCenterX = gradient.GetRadialGradient()->radialCenterX;
88         if (radialCenterX.has_value()) {
89             retGradient.GetRadialGradient().radialCenterX = ToAnimatableDimension(radialCenterX.value());
90         }
91         auto radialCenterY = gradient.GetRadialGradient()->radialCenterY;
92         if (radialCenterY.has_value()) {
93             retGradient.GetRadialGradient().radialCenterY = ToAnimatableDimension(radialCenterY.value());
94         }
95         auto radialVerticalSize = gradient.GetRadialGradient()->radialVerticalSize;
96         if (radialVerticalSize.has_value()) {
97             retGradient.GetRadialGradient().radialVerticalSize = ToAnimatableDimension(radialVerticalSize.value());
98         }
99         auto radialHorizontalSize = gradient.GetRadialGradient()->radialHorizontalSize;
100         if (radialVerticalSize.has_value()) {
101             retGradient.GetRadialGradient().radialHorizontalSize = ToAnimatableDimension(radialHorizontalSize.value());
102         }
103     }
104 
105     if (retGradient.GetType() == GradientType::SWEEP) {
106         auto centerX = gradient.GetSweepGradient()->centerX;
107         if (centerX.has_value()) {
108             retGradient.GetSweepGradient().centerX = ToAnimatableDimension(centerX.value());
109         }
110         auto centerY = gradient.GetSweepGradient()->centerY;
111         if (centerY.has_value()) {
112             retGradient.GetSweepGradient().centerY = ToAnimatableDimension(centerY.value());
113         }
114         auto startAngle = gradient.GetSweepGradient()->startAngle;
115         if (startAngle.has_value()) {
116             retGradient.GetSweepGradient().startAngle = ToAnimatableDimension(startAngle.value());
117         }
118         auto endAngle = gradient.GetSweepGradient()->endAngle;
119         if (endAngle.has_value()) {
120             retGradient.GetSweepGradient().endAngle = ToAnimatableDimension(endAngle.value());
121         }
122         auto rotation = gradient.GetSweepGradient()->rotation;
123         if (rotation.has_value()) {
124             retGradient.GetSweepGradient().rotation = ToAnimatableDimension(rotation.value());
125         }
126     }
127 
128     retGradient.SetRepeat(gradient.GetRepeat());
129     const auto& colorStops = gradient.GetColors();
130 
131     for (const auto& item : colorStops) {
132         GradientColor gradientColor;
133         gradientColor.SetColor(item.GetColor());
134         gradientColor.SetHasValue(item.GetHasValue());
135         gradientColor.SetDimension(item.GetDimension());
136         retGradient.AddColor(gradientColor);
137     }
138     return retGradient;
139 }
140 
SwapBackBorder(const RefPtr<Decoration> & decoration)141 void ViewAbstractModelImpl::SwapBackBorder(const RefPtr<Decoration>& decoration)
142 {
143     CHECK_NULL_VOID(decoration);
144     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
145     auto boxDecoration = box->GetBackDecoration();
146     if (boxDecoration) {
147         decoration->SetBorder(boxDecoration->GetBorder());
148         boxDecoration->SetBorder({});
149     }
150 }
151 
ToDragFunc(NG::OnDragStartFunc && onDragStart)152 OnDragFunc ViewAbstractModelImpl::ToDragFunc(NG::OnDragStartFunc&& onDragStart)
153 {
154     auto dragStart = [dragStartFunc = std::move(onDragStart)](
155                          const RefPtr<DragEvent>& event, const std::string& extraParams) -> DragItemInfo {
156         auto dragInfo = dragStartFunc(event, extraParams);
157         DragItemInfo info;
158         info.extraInfo = dragInfo.extraInfo;
159         info.pixelMap = dragInfo.pixelMap;
160         info.customComponent = AceType::DynamicCast<Component>(dragInfo.node);
161         return info;
162     };
163     return dragStart;
164 }
165 
SetWidth(const CalcDimension & width)166 void ViewAbstractModelImpl::SetWidth(const CalcDimension& width)
167 {
168     bool isPercentSize = (width.Unit() == DimensionUnit::PERCENT);
169     if (isPercentSize) {
170         auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
171         auto renderComponent = AceType::DynamicCast<RenderComponent>(component);
172         if (renderComponent) {
173             renderComponent->SetIsPercentSize(isPercentSize);
174         }
175     }
176 
177     auto* stack = ViewStackProcessor::GetInstance();
178     auto box = stack->GetBoxComponent();
179     auto option = stack->GetImplicitAnimationOption();
180     if (!stack->IsVisualStateSet()) {
181         box->SetWidth(width, option);
182     } else {
183         box->GetStateAttributes()->AddAttribute<AnimatableDimension>(
184             BoxStateAttribute::WIDTH, AnimatableDimension(width, option), stack->GetVisualState());
185         if (!box->GetStateAttributes()->HasAttribute(BoxStateAttribute::WIDTH, VisualState::NORMAL)) {
186             box->GetStateAttributes()->AddAttribute<AnimatableDimension>(
187                 BoxStateAttribute::WIDTH, AnimatableDimension(box->GetWidth(), option), VisualState::NORMAL);
188         }
189     }
190 }
191 
SetHeight(const CalcDimension & height)192 void ViewAbstractModelImpl::SetHeight(const CalcDimension& height)
193 {
194     bool isPercentSize = (height.Unit() == DimensionUnit::PERCENT);
195     if (isPercentSize) {
196         auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
197         auto renderComponent = AceType::DynamicCast<RenderComponent>(component);
198         if (renderComponent) {
199             renderComponent->SetIsPercentSize(isPercentSize);
200         }
201     }
202 
203     auto* stack = ViewStackProcessor::GetInstance();
204     auto box = stack->GetBoxComponent();
205     auto option = stack->GetImplicitAnimationOption();
206     if (!stack->IsVisualStateSet()) {
207         box->SetHeight(height, option);
208     } else {
209         box->GetStateAttributes()->AddAttribute<AnimatableDimension>(
210             BoxStateAttribute::HEIGHT, AnimatableDimension(height, option), stack->GetVisualState());
211         if (!box->GetStateAttributes()->HasAttribute(BoxStateAttribute::HEIGHT, VisualState::NORMAL)) {
212             box->GetStateAttributes()->AddAttribute<AnimatableDimension>(
213                 BoxStateAttribute::HEIGHT, AnimatableDimension(box->GetHeight(), option), VisualState::NORMAL);
214         }
215     }
216 }
217 
SetMinWidth(const CalcDimension & minWidth)218 void ViewAbstractModelImpl::SetMinWidth(const CalcDimension& minWidth)
219 {
220     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
221     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
222     box->SetMinWidth(minWidth);
223     flexItem->SetMinWidth(minWidth);
224 }
225 
SetMinHeight(const CalcDimension & minHeight)226 void ViewAbstractModelImpl::SetMinHeight(const CalcDimension& minHeight)
227 {
228     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
229     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
230     box->SetMinHeight(minHeight);
231     flexItem->SetMinHeight(minHeight);
232 }
233 
SetMaxWidth(const CalcDimension & maxWidth)234 void ViewAbstractModelImpl::SetMaxWidth(const CalcDimension& maxWidth)
235 {
236     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
237     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
238     box->SetMaxWidth(maxWidth);
239     flexItem->SetMaxWidth(maxWidth);
240 }
241 
SetMaxHeight(const CalcDimension & maxHeight)242 void ViewAbstractModelImpl::SetMaxHeight(const CalcDimension& maxHeight)
243 {
244     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
245     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
246     box->SetMaxHeight(maxHeight);
247     flexItem->SetMaxHeight(maxHeight);
248 }
249 
SetBackgroundColor(const Color & color)250 void ViewAbstractModelImpl::SetBackgroundColor(const Color& color)
251 {
252     auto* stack = ViewStackProcessor::GetInstance();
253     auto boxComponent = stack->GetBoxComponent();
254     auto option = stack->GetImplicitAnimationOption();
255     if (!stack->IsVisualStateSet()) {
256         boxComponent->SetColor(color, option);
257     } else {
258         boxComponent->GetStateAttributes()->AddAttribute<AnimatableColor>(
259             BoxStateAttribute::COLOR, AnimatableColor(color, option), stack->GetVisualState());
260         if (!boxComponent->GetStateAttributes()->HasAttribute(BoxStateAttribute::COLOR, VisualState::NORMAL)) {
261             boxComponent->GetStateAttributes()->AddAttribute<AnimatableColor>(
262                 BoxStateAttribute::COLOR, AnimatableColor(boxComponent->GetColor(), option), VisualState::NORMAL);
263         }
264     }
265 }
266 
SetBackgroundImage(const ImageSourceInfo & src,RefPtr<ThemeConstants> themeConstant)267 void ViewAbstractModelImpl::SetBackgroundImage(const ImageSourceInfo& src, RefPtr<ThemeConstants> themeConstant)
268 {
269     auto decoration = GetBackDecoration();
270     auto image = decoration->GetImage();
271     if (!image) {
272         image = AceType::MakeRefPtr<BackgroundImage>();
273     }
274 
275     if (themeConstant) {
276         image->SetSrc(src.GetSrc(), themeConstant);
277     } else {
278         image->SetParsedSrc(src.GetSrc());
279     }
280 
281     decoration->SetImage(image);
282 }
283 
SetBackgroundImageRepeat(const ImageRepeat & imageRepeat)284 void ViewAbstractModelImpl::SetBackgroundImageRepeat(const ImageRepeat& imageRepeat)
285 {
286     auto decoration = GetBackDecoration();
287     auto image = decoration->GetImage();
288     if (!image) {
289         image = AceType::MakeRefPtr<BackgroundImage>();
290     }
291     image->SetImageRepeat(imageRepeat);
292     decoration->SetImage(image);
293 }
294 
SetBackgroundImageSize(const BackgroundImageSize & bgImgSize)295 void ViewAbstractModelImpl::SetBackgroundImageSize(const BackgroundImageSize& bgImgSize)
296 {
297     auto decoration = GetBackDecoration();
298     auto image = decoration->GetImage();
299     if (!image) {
300         image = AceType::MakeRefPtr<BackgroundImage>();
301     }
302     image->SetImageSize(bgImgSize);
303     decoration->SetImage(image);
304 }
305 
SetBackgroundImagePosition(const BackgroundImagePosition & bgImgPosition)306 void ViewAbstractModelImpl::SetBackgroundImagePosition(const BackgroundImagePosition& bgImgPosition)
307 {
308     auto decoration = GetBackDecoration();
309     auto image = decoration->GetImage();
310     if (!image) {
311         image = AceType::MakeRefPtr<BackgroundImage>();
312     }
313     image->SetImagePosition(bgImgPosition);
314     decoration->SetImage(image);
315 }
316 
SetBackgroundBlurStyle(const BlurStyleOption & bgBlurStyle,const SysOptions & sysOptions)317 void ViewAbstractModelImpl::SetBackgroundBlurStyle(const BlurStyleOption& bgBlurStyle, const SysOptions& sysOptions)
318 {
319     auto decoration = GetBackDecoration();
320     decoration->SetBlurStyle(bgBlurStyle);
321     double radius = 0.0;
322     Dimension dimensionRadius(radius, DimensionUnit::PX);
323     decoration->SetBlurRadius(ToAnimatableDimension(dimensionRadius));
324 }
325 
SetPadding(const CalcDimension & value)326 void ViewAbstractModelImpl::SetPadding(const CalcDimension& value)
327 {
328     AnimatableDimension animValue = ToAnimatableDimension(value);
329     SetPaddings(animValue, animValue, animValue, animValue);
330 }
331 
SetPaddings(const std::optional<CalcDimension> & top,const std::optional<CalcDimension> & bottom,const std::optional<CalcDimension> & left,const std::optional<CalcDimension> & right)332 void ViewAbstractModelImpl::SetPaddings(const std::optional<CalcDimension>& top,
333     const std::optional<CalcDimension>& bottom, const std::optional<CalcDimension>& left,
334     const std::optional<CalcDimension>& right)
335 {
336     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
337     Edge padding = box->GetPadding();
338     if (top.has_value()) {
339         padding.SetTop(ToAnimatableDimension(top.value()));
340     }
341     if (bottom.has_value()) {
342         padding.SetBottom(ToAnimatableDimension(bottom.value()));
343     }
344     if (left.has_value()) {
345         padding.SetLeft(ToAnimatableDimension(left.value()));
346     }
347     if (right.has_value()) {
348         padding.SetRight(ToAnimatableDimension(right.value()));
349     }
350     box->SetPadding(padding);
351 }
352 
SetMargin(const CalcDimension & value)353 void ViewAbstractModelImpl::SetMargin(const CalcDimension& value)
354 {
355     AnimatableDimension animValue = ToAnimatableDimension(value);
356     SetMargins(animValue, animValue, animValue, animValue);
357 }
358 
SetMargins(const std::optional<CalcDimension> & top,const std::optional<CalcDimension> & bottom,const std::optional<CalcDimension> & left,const std::optional<CalcDimension> & right)359 void ViewAbstractModelImpl::SetMargins(const std::optional<CalcDimension>& top,
360     const std::optional<CalcDimension>& bottom, const std::optional<CalcDimension>& left,
361     const std::optional<CalcDimension>& right)
362 {
363     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
364     Edge margin = box->GetMargin();
365     if (top.has_value()) {
366         margin.SetTop(ToAnimatableDimension(top.value()));
367     }
368     if (bottom.has_value()) {
369         margin.SetBottom(ToAnimatableDimension(bottom.value()));
370     }
371     if (left.has_value()) {
372         margin.SetLeft(ToAnimatableDimension(left.value()));
373     }
374     if (right.has_value()) {
375         margin.SetRight(ToAnimatableDimension(right.value()));
376     }
377     box->SetMargin(margin);
378 }
379 
SetBorderRadius(const Dimension & value)380 void ViewAbstractModelImpl::SetBorderRadius(const Dimension& value)
381 {
382     SetBorderRadius(value, value, value, value);
383 }
384 
SetBorderRadius(const std::optional<Dimension> & radiusTopLeft,const std::optional<Dimension> & radiusTopRight,const std::optional<Dimension> & radiusBottomLeft,const std::optional<Dimension> & radiusBottomRight)385 void ViewAbstractModelImpl::SetBorderRadius(const std::optional<Dimension>& radiusTopLeft,
386     const std::optional<Dimension>& radiusTopRight, const std::optional<Dimension>& radiusBottomLeft,
387     const std::optional<Dimension>& radiusBottomRight)
388 {
389     auto decoration = GetBackDecoration();
390     Dimension topLeft = radiusTopLeft.has_value() ? radiusTopLeft.value()
391                                                   : BoxComponentHelper::GetBorderRadiusTopLeft(decoration).GetX();
392     Dimension topRight = radiusTopRight.has_value() ? radiusTopRight.value()
393                                                     : BoxComponentHelper::GetBorderRadiusTopRight(decoration).GetX();
394     Dimension bottomLeft = radiusBottomLeft.has_value()
395                                ? radiusBottomLeft.value()
396                                : BoxComponentHelper::GetBorderRadiusBottomLeft(decoration).GetX();
397     Dimension bottomRight = radiusBottomRight.has_value()
398                                 ? radiusBottomRight.value()
399                                 : BoxComponentHelper::GetBorderRadiusBottomRight(decoration).GetX();
400     auto* stack = ViewStackProcessor::GetInstance();
401     AnimationOption option = stack->GetImplicitAnimationOption();
402     if (!stack->IsVisualStateSet()) {
403         BoxComponentHelper::SetBorderRadius(decoration, topLeft, topRight, bottomLeft, bottomRight, option);
404     } else {
405         auto boxComponent = stack->GetBoxComponent();
406         boxComponent->GetStateAttributes()->AddAttribute<AnimatableDimension>(
407             BoxStateAttribute::BORDER_RADIUS, AnimatableDimension(topLeft, option), stack->GetVisualState());
408         if (!boxComponent->GetStateAttributes()->HasAttribute(BoxStateAttribute::BORDER_RADIUS, VisualState::NORMAL)) {
409             boxComponent->GetStateAttributes()->AddAttribute<AnimatableDimension>(
410                 BoxStateAttribute::BORDER_RADIUS, AnimatableDimension(topLeft, option), VisualState::NORMAL);
411         }
412     }
413 }
414 
SetBorderColor(const Color & value)415 void ViewAbstractModelImpl::SetBorderColor(const Color& value)
416 {
417     SetBorderColor(value, value, value, value);
418 }
419 
SetBorderColor(const std::optional<Color> & colorLeft,const std::optional<Color> & colorRight,const std::optional<Color> & colorTop,const std::optional<Color> & colorBottom)420 void ViewAbstractModelImpl::SetBorderColor(const std::optional<Color>& colorLeft,
421     const std::optional<Color>& colorRight, const std::optional<Color>& colorTop,
422     const std::optional<Color>& colorBottom)
423 {
424     auto decoration = GetBackDecoration();
425     Color leftColor = colorLeft.has_value() ? colorLeft.value() : BoxComponentHelper::GetBorderColorTop(decoration);
426     Color rightColor =
427         colorRight.has_value() ? colorRight.value() : BoxComponentHelper::GetBorderColorBottom(decoration);
428     Color topColor = colorTop.has_value() ? colorTop.value() : BoxComponentHelper::GetBorderColorLeft(decoration);
429     Color bottomColor =
430         colorBottom.has_value() ? colorBottom.value() : BoxComponentHelper::GetBorderColorRight(decoration);
431     auto* stack = ViewStackProcessor::GetInstance();
432     AnimationOption option = stack->GetImplicitAnimationOption();
433     if (!stack->IsVisualStateSet()) {
434         BoxComponentHelper::SetBorderColor(decoration, leftColor, rightColor, topColor, bottomColor, option);
435     } else {
436         auto boxComponent = stack->GetBoxComponent();
437         boxComponent->GetStateAttributes()->AddAttribute<AnimatableColor>(
438             BoxStateAttribute::BORDER_COLOR, AnimatableColor(leftColor, option), stack->GetVisualState());
439         if (!boxComponent->GetStateAttributes()->HasAttribute(BoxStateAttribute::BORDER_COLOR, VisualState::NORMAL)) {
440             boxComponent->GetStateAttributes()->AddAttribute<AnimatableColor>(BoxStateAttribute::BORDER_COLOR,
441                 AnimatableColor(BoxComponentHelper::GetBorderColor(decoration), option), VisualState::NORMAL);
442         }
443     }
444 }
445 
SetBorderWidth(const Dimension & value)446 void ViewAbstractModelImpl::SetBorderWidth(const Dimension& value)
447 {
448     SetBorderWidth(value, value, value, value);
449 }
450 
SetBorderWidth(const std::optional<Dimension> & left,const std::optional<Dimension> & right,const std::optional<Dimension> & top,const std::optional<Dimension> & bottom)451 void ViewAbstractModelImpl::SetBorderWidth(const std::optional<Dimension>& left, const std::optional<Dimension>& right,
452     const std::optional<Dimension>& top, const std::optional<Dimension>& bottom)
453 {
454     auto decoration = GetBackDecoration();
455     Dimension leftDimen =
456         left.has_value() ? left.value() : Dimension(BoxComponentHelper::GetBorderLeftWidth(decoration));
457     Dimension rightDimen =
458         right.has_value() ? right.value() : Dimension(BoxComponentHelper::GetBorderRightWidth(decoration));
459     Dimension topDimen = top.has_value() ? top.value() : Dimension(BoxComponentHelper::GetBorderTopWidth(decoration));
460     Dimension bottomDimen =
461         bottom.has_value() ? bottom.value() : Dimension(BoxComponentHelper::GetBorderBottomWidth(decoration));
462     auto* stack = ViewStackProcessor::GetInstance();
463     AnimationOption option = stack->GetImplicitAnimationOption();
464     if (!stack->IsVisualStateSet()) {
465         BoxComponentHelper::SetBorderWidth(decoration, leftDimen, rightDimen, topDimen, bottomDimen, option);
466     } else {
467         auto boxComponent = stack->GetBoxComponent();
468         boxComponent->GetStateAttributes()->AddAttribute<AnimatableDimension>(
469             BoxStateAttribute::BORDER_WIDTH, AnimatableDimension(leftDimen, option), stack->GetVisualState());
470         if (!boxComponent->GetStateAttributes()->HasAttribute(BoxStateAttribute::BORDER_WIDTH, VisualState::NORMAL)) {
471             boxComponent->GetStateAttributes()->AddAttribute<AnimatableDimension>(BoxStateAttribute::BORDER_WIDTH,
472                 AnimatableDimension(BoxComponentHelper::GetBorderWidth(decoration), option), VisualState::NORMAL);
473         }
474     }
475 }
476 
SetBorderStyle(const BorderStyle & value)477 void ViewAbstractModelImpl::SetBorderStyle(const BorderStyle& value)
478 {
479     SetBorderStyle(value, value, value, value);
480 }
481 
SetBorderStyle(const std::optional<BorderStyle> & styleLeft,const std::optional<BorderStyle> & styleRight,const std::optional<BorderStyle> & styleTop,const std::optional<BorderStyle> & styleBottom)482 void ViewAbstractModelImpl::SetBorderStyle(const std::optional<BorderStyle>& styleLeft,
483     const std::optional<BorderStyle>& styleRight, const std::optional<BorderStyle>& styleTop,
484     const std::optional<BorderStyle>& styleBottom)
485 {
486     auto decoration = GetBackDecoration();
487     BorderStyle left = styleLeft.value_or(BorderStyle::SOLID);
488     BorderStyle right = styleRight.value_or(BorderStyle::SOLID);
489     BorderStyle top = styleTop.value_or(BorderStyle::SOLID);
490     BorderStyle bottom = styleBottom.value_or(BorderStyle::SOLID);
491     auto* stack = ViewStackProcessor::GetInstance();
492     AnimationOption option = stack->GetImplicitAnimationOption();
493     if (!stack->IsVisualStateSet()) {
494         BoxComponentHelper::SetBorderStyle(decoration, left, right, top, bottom);
495     } else {
496         auto boxComponent = stack->GetBoxComponent();
497         boxComponent->GetStateAttributes()->AddAttribute<BorderStyle>(
498             BoxStateAttribute::BORDER_STYLE, left, stack->GetVisualState());
499         if (!boxComponent->GetStateAttributes()->HasAttribute(BoxStateAttribute::BORDER_STYLE, VisualState::NORMAL)) {
500             boxComponent->GetStateAttributes()->AddAttribute<BorderStyle>(
501                 BoxStateAttribute::BORDER_STYLE, BoxComponentHelper::GetBorderStyle(decoration), VisualState::NORMAL);
502         }
503     }
504 }
505 
SetBorderImage(const RefPtr<BorderImage> & borderImage,uint8_t bitset)506 void ViewAbstractModelImpl::SetBorderImage(const RefPtr<BorderImage>& borderImage, uint8_t bitset)
507 {
508     auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
509     auto boxDecoration = GetBackDecoration();
510     if (bitset | BorderImage::OUTSET_BIT) {
511         boxDecoration->SetHasBorderImageOutset(true);
512     }
513     if (bitset | BorderImage::REPEAT_BIT) {
514         boxDecoration->SetHasBorderImageRepeat(true);
515     }
516     if (bitset | BorderImage::SLICE_BIT) {
517         boxDecoration->SetHasBorderImageSlice(true);
518     }
519     if (bitset | BorderImage::SOURCE_BIT) {
520         boxDecoration->SetHasBorderImageSource(true);
521     }
522     if (bitset | BorderImage::WIDTH_BIT) {
523         boxDecoration->SetHasBorderImageWidth(true);
524     }
525     if (bitset | BorderImage::GRADIENT_BIT) {
526         boxDecoration->SetHasBorderImageGradient(true);
527     }
528     boxDecoration->SetBorderImage(borderImage);
529     boxComponent->SetBackDecoration(boxDecoration);
530 }
531 
SetBorderImageGradient(const NG::Gradient & gradient)532 void ViewAbstractModelImpl::SetBorderImageGradient(const NG::Gradient& gradient)
533 {
534     auto boxDecoration = GetBackDecoration();
535     Gradient borderGradient = ToGradient(gradient);
536     boxDecoration->SetBorderImageGradient(borderGradient);
537     boxDecoration->SetHasBorderImageGradient(true);
538 }
539 
SetLayoutPriority(int32_t priority)540 void ViewAbstractModelImpl::SetLayoutPriority(int32_t priority)
541 {
542     auto flex = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
543     flex->SetDisplayIndex(priority);
544 }
545 
SetPixelRound(uint16_t value)546 void ViewAbstractModelImpl::SetPixelRound(uint16_t value) {}
547 
SetLayoutWeight(float value)548 void ViewAbstractModelImpl::SetLayoutWeight(float value)
549 {
550     auto flex = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
551     flex->SetFlexWeight(value);
552 }
553 
SetLayoutDirection(TextDirection value)554 void ViewAbstractModelImpl::SetLayoutDirection(TextDirection value)
555 {
556     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
557     box->SetTextDirection(value);
558     box->SetInspectorDirection(value);
559     if (value == TextDirection::AUTO) {
560         box->SetTextDirection(
561             AceApplicationInfo::GetInstance().IsRightToLeft() ? TextDirection::RTL : TextDirection::LTR);
562     }
563 }
564 
SetAspectRatio(float ratio)565 void ViewAbstractModelImpl::SetAspectRatio(float ratio)
566 {
567     auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
568     AnimationOption option = ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
569     boxComponent->SetAspectRatio(ratio, option);
570 }
571 
SetAlign(const Alignment & alignment)572 void ViewAbstractModelImpl::SetAlign(const Alignment& alignment)
573 {
574     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
575     box->SetAlignment(alignment);
576 }
577 
SetAlignRules(const std::map<AlignDirection,AlignRule> & alignRules)578 void ViewAbstractModelImpl::SetAlignRules(const std::map<AlignDirection, AlignRule>& alignRules)
579 {
580     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
581     flexItem->SetAlignRules(alignRules);
582 }
583 
SetUseAlign(AlignDeclarationPtr declaration,AlignDeclaration::Edge edge,const std::optional<Dimension> & offset)584 void ViewAbstractModelImpl::SetUseAlign(
585     AlignDeclarationPtr declaration, AlignDeclaration::Edge edge, const std::optional<Dimension>& offset)
586 {
587     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
588     box->SetAlignDeclarationPtr(declaration);
589     box->SetUseAlignSide(edge);
590     if (offset.has_value()) {
591         box->SetUseAlignOffset(offset.value());
592     }
593 }
594 
SetGrid(std::optional<uint32_t> span,std::optional<int32_t> offset,GridSizeType type)595 void ViewAbstractModelImpl::SetGrid(std::optional<uint32_t> span, std::optional<int32_t> offset, GridSizeType type)
596 {
597     auto info = GridContainerModelImpl::GetContainer();
598     if (info != nullptr) {
599         auto builder = ViewStackProcessor::GetInstance()->GetBoxComponent()->GetGridColumnInfoBuilder();
600         builder->SetParent(info);
601         if (span.has_value()) {
602             if (type == GridSizeType::UNDEFINED) {
603                 builder->SetColumns(span.value());
604             } else {
605                 builder->SetSizeColumn(type, span.value());
606             }
607         }
608         if (offset.has_value()) {
609             if (type == GridSizeType::UNDEFINED) {
610                 builder->SetOffset(offset.value());
611             } else {
612                 builder->SetOffset(offset.value(), type);
613             }
614         }
615     }
616 }
617 
SetPosition(const Dimension & x,const Dimension & y)618 void ViewAbstractModelImpl::SetPosition(const Dimension& x, const Dimension& y)
619 {
620     auto flexItemComponent = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
621     flexItemComponent->SetLeft(ToAnimatableDimension(x));
622     flexItemComponent->SetTop(ToAnimatableDimension(y));
623     flexItemComponent->SetPositionType(PositionType::PTABSOLUTE);
624 }
625 
SetOffset(const Dimension & x,const Dimension & y)626 void ViewAbstractModelImpl::SetOffset(const Dimension& x, const Dimension& y)
627 {
628     auto flexItemComponent = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
629     flexItemComponent->SetLeft(ToAnimatableDimension(x));
630     flexItemComponent->SetTop(ToAnimatableDimension(y));
631     flexItemComponent->SetPositionType(PositionType::PTOFFSET);
632 }
633 
MarkAnchor(const Dimension & x,const Dimension & y)634 void ViewAbstractModelImpl::MarkAnchor(const Dimension& x, const Dimension& y)
635 {
636     auto flexItemComponent = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
637     flexItemComponent->SetAnchorX(ToAnimatableDimension(x));
638     flexItemComponent->SetAnchorY(ToAnimatableDimension(y));
639 }
640 
SetScale(float x,float y,float z)641 void ViewAbstractModelImpl::SetScale(float x, float y, float z)
642 {
643     RefPtr<TransformComponent> transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
644     AnimationOption option = ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
645     transform->Scale(x, y, z, option);
646 }
647 
SetPivot(const Dimension & x,const Dimension & y,const Dimension &)648 void ViewAbstractModelImpl::SetPivot(const Dimension& x, const Dimension& y, const Dimension& /* z */)
649 {
650     RefPtr<TransformComponent> transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
651     transform->SetOriginDimension(DimensionOffset(x, y));
652 }
653 
SetTranslate(const Dimension & x,const Dimension & y,const Dimension & z)654 void ViewAbstractModelImpl::SetTranslate(const Dimension& x, const Dimension& y, const Dimension& z)
655 {
656     RefPtr<TransformComponent> transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
657     AnimationOption option = ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
658     transform->Translate(x, y, z, option);
659 }
660 
SetRotate(float x,float y,float z,float angle,float perspective)661 void ViewAbstractModelImpl::SetRotate(float x, float y, float z, float angle, float perspective)
662 {
663     RefPtr<TransformComponent> transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
664     AnimationOption option = ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
665     if (!option.IsValid()) {
666         auto pipeline = PipelineBase::GetCurrentContext();
667         if (pipeline) {
668             option = pipeline->GetSyncAnimationOption();
669         }
670     }
671 
672     option.SetAllowRunningAsynchronously(false);
673     transform->Rotate(x, y, z, angle, option);
674 }
675 
SetTransformMatrix(const std::vector<float> & matrix)676 void ViewAbstractModelImpl::SetTransformMatrix(const std::vector<float>& matrix)
677 {
678     RefPtr<TransformComponent> transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
679     AnimationOption option = ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
680     transform->Matrix3d(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5], matrix[6], matrix[7],
681         matrix[8], matrix[9], matrix[10], matrix[11], matrix[12], matrix[13], matrix[14], matrix[15], option);
682 }
683 
SetOpacity(double opacity,bool passThrough)684 void ViewAbstractModelImpl::SetOpacity(double opacity, bool passThrough)
685 {
686     auto display = ViewStackProcessor::GetInstance()->GetDisplayComponent();
687     auto stack = ViewStackProcessor::GetInstance();
688     auto option = stack->GetImplicitAnimationOption();
689     if (!stack->IsVisualStateSet()) {
690         display->SetOpacity(opacity, option);
691     } else {
692         display->GetStateAttributes()->AddAttribute<AnimatableDouble>(
693             DisplayStateAttribute::OPACITY, AnimatableDouble(opacity, option), stack->GetVisualState());
694         if (!display->GetStateAttributes()->HasAttribute(DisplayStateAttribute::OPACITY, VisualState::NORMAL)) {
695             display->GetStateAttributes()->AddAttribute<AnimatableDouble>(
696                 DisplayStateAttribute::OPACITY, AnimatableDouble(display->GetOpacity(), option), VisualState::NORMAL);
697         }
698     }
699     if (passThrough && ViewStackProcessor::GetInstance()->HasDisplayComponent()) {
700         auto display = ViewStackProcessor::GetInstance()->GetDisplayComponent();
701         display->DisableLayer(true);
702     }
703 }
704 
SetTransition(const NG::TransitionOptions & transitionOptions,bool passThrough)705 void ViewAbstractModelImpl::SetTransition(const NG::TransitionOptions& transitionOptions, bool passThrough)
706 {
707     if (transitionOptions.HasOpacity()) {
708         auto display = ViewStackProcessor::GetInstance()->GetDisplayComponent();
709         display->SetTransition(transitionOptions.Type, transitionOptions.GetOpacityValue());
710     }
711     if (transitionOptions.HasTranslate()) {
712         auto transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
713         const auto& value = transitionOptions.GetTranslateValue();
714         transform->SetTranslateTransition(transitionOptions.Type, value.x, value.y, value.z);
715     }
716     if (transitionOptions.HasScale()) {
717         auto transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
718         const auto& value = transitionOptions.GetScaleValue();
719         transform->SetScaleTransition(transitionOptions.Type, value.xScale, value.yScale, value.zScale);
720         transform->SetOriginDimension(DimensionOffset(value.centerX, value.centerY));
721     }
722     if (transitionOptions.HasRotate()) {
723         auto transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
724         const auto& value = transitionOptions.GetRotateValue();
725         transform->SetRotateTransition(
726             transitionOptions.Type, value.xDirection, value.yDirection, value.zDirection, value.angle);
727         transform->SetOriginDimension(DimensionOffset(value.centerX, value.centerY));
728     }
729     if (passThrough && ViewStackProcessor::GetInstance()->HasDisplayComponent()) {
730         auto display = ViewStackProcessor::GetInstance()->GetDisplayComponent();
731         display->DisableLayer(true);
732     }
733 }
734 
SetOverlay(const std::string & text,std::function<void ()> && buildFunc,const RefPtr<NG::FrameNode> & contentNode,const std::optional<Alignment> & align,const std::optional<Dimension> & offsetX,const std::optional<Dimension> & offsetY,NG::OverlayType type)735 void ViewAbstractModelImpl::SetOverlay(const std::string& text, std::function<void()>&& buildFunc,
736     const RefPtr<NG::FrameNode>& contentNode, const std::optional<Alignment>& align,
737     const std::optional<Dimension>& offsetX, const std::optional<Dimension>& offsetY, NG::OverlayType type)
738 {
739     if (buildFunc || contentNode) {
740         return;
741     }
742     auto coverageComponent = ViewStackProcessor::GetInstance()->GetCoverageComponent();
743     coverageComponent->SetTextVal(text);
744     coverageComponent->SetIsOverLay(true);
745     coverageComponent->SetAlignment(align.value_or(Alignment::TOP_LEFT));
746     if (offsetX.has_value()) {
747         coverageComponent->SetX(offsetX.value());
748     }
749     if (offsetY.has_value()) {
750         coverageComponent->SetY(offsetY.value());
751     }
752 }
753 
SetVisibility(VisibleType visible,std::function<void (int32_t)> && changeEventFunc)754 void ViewAbstractModelImpl::SetVisibility(VisibleType visible, std::function<void(int32_t)>&& changeEventFunc)
755 {
756     auto display = ViewStackProcessor::GetInstance()->GetDisplayComponent();
757     display->SetVisible(visible);
758     auto eventMarker = EventMarker([func = std::move(changeEventFunc)](const BaseEventInfo* info) {
759         const auto& param = info->GetType();
760         int32_t newValue = StringToInt(param);
761         func(newValue);
762     });
763 
764     display->SetVisibleChangeEvent(eventMarker);
765 }
766 
SetSharedTransition(const std::string & shareId,const std::shared_ptr<SharedTransitionOption> & option)767 void ViewAbstractModelImpl::SetSharedTransition(
768     const std::string& shareId, const std::shared_ptr<SharedTransitionOption>& option)
769 {
770     auto sharedTransitionComponent = ViewStackProcessor::GetInstance()->GetSharedTransitionComponent();
771     sharedTransitionComponent->SetShareId(shareId);
772     if (!option) {
773         return;
774     }
775     TweenOption tweenOption;
776     tweenOption.SetCurve(option->curve);
777     tweenOption.SetDuration(option->duration);
778     tweenOption.SetDelay(option->delay);
779     tweenOption.SetMotionPathOption(option->motionPathOption);
780     auto sharedTransitionEffect =
781         SharedTransitionEffect::GetSharedTransitionEffect(option->type, sharedTransitionComponent->GetShareId());
782     sharedTransitionComponent->SetEffect(sharedTransitionEffect);
783     sharedTransitionComponent->SetOption(tweenOption);
784     if (option->zIndex != 0) {
785         sharedTransitionComponent->SetZIndex(option->zIndex);
786     }
787 }
788 
SetGeometryTransition(const std::string & id,bool followWithoutTransition,bool doRegisterSharedTransition)789 void ViewAbstractModelImpl::SetGeometryTransition(const std::string& id,
790     bool followWithoutTransition, bool doRegisterSharedTransition)
791 {
792     auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
793     boxComponent->SetGeometryTransitionId(id);
794 }
795 
SetMotionPath(const MotionPathOption & option)796 void ViewAbstractModelImpl::SetMotionPath(const MotionPathOption& option)
797 {
798     if (option.GetRotate()) {
799         ViewStackProcessor::GetInstance()->GetTransformComponent();
800     }
801     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
802     flexItem->SetMotionPathOption(option);
803 }
804 
SetFlexBasis(const Dimension & value)805 void ViewAbstractModelImpl::SetFlexBasis(const Dimension& value)
806 {
807     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
808     flexItem->SetFlexBasis(value);
809 }
810 
SetAlignSelf(FlexAlign value)811 void ViewAbstractModelImpl::SetAlignSelf(FlexAlign value)
812 {
813     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
814     flexItem->SetAlignSelf(value);
815 }
816 
SetFlexShrink(float value)817 void ViewAbstractModelImpl::SetFlexShrink(float value)
818 {
819     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
820     flexItem->SetFlexShrink(value);
821 }
822 
SetFlexGrow(float value)823 void ViewAbstractModelImpl::SetFlexGrow(float value)
824 {
825     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
826     flexItem->SetFlexGrow(value);
827 }
828 
SetDisplayIndex(int32_t value)829 void ViewAbstractModelImpl::SetDisplayIndex(int32_t value)
830 {
831     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
832     flexItem->SetDisplayIndex(value);
833 }
834 
SetZIndex(int32_t value)835 void ViewAbstractModelImpl::SetZIndex(int32_t value)
836 {
837     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
838     auto renderComponent = AceType::DynamicCast<RenderComponent>(component);
839     if (renderComponent) {
840         renderComponent->SetZIndex(value);
841     }
842 }
843 
SetLinearGradient(const NG::Gradient & gradient)844 void ViewAbstractModelImpl::SetLinearGradient(const NG::Gradient& gradient)
845 {
846     auto lineGradient = ToGradient(gradient);
847     auto* stack = ViewStackProcessor::GetInstance();
848     if (!stack->IsVisualStateSet()) {
849         auto decoration = GetBackDecoration();
850         if (decoration) {
851             decoration->SetGradient(lineGradient);
852         }
853     } else {
854         auto boxComponent = stack->GetBoxComponent();
855         boxComponent->GetStateAttributes()->AddAttribute<Gradient>(
856             BoxStateAttribute::GRADIENT, lineGradient, stack->GetVisualState());
857         if (!boxComponent->GetStateAttributes()->HasAttribute(BoxStateAttribute::GRADIENT, VisualState::NORMAL)) {
858             boxComponent->GetStateAttributes()->AddAttribute<Gradient>(
859                 BoxStateAttribute::GRADIENT, GetBackDecoration()->GetGradient(), VisualState::NORMAL);
860         }
861     }
862 }
863 
SetSweepGradient(const NG::Gradient & gradient)864 void ViewAbstractModelImpl::SetSweepGradient(const NG::Gradient& gradient)
865 {
866     auto sweepGradient = ToGradient(gradient);
867     auto* stack = ViewStackProcessor::GetInstance();
868     if (!stack->IsVisualStateSet()) {
869         auto decoration = GetBackDecoration();
870         if (decoration) {
871             decoration->SetGradient(sweepGradient);
872         }
873     } else {
874         auto boxComponent = stack->GetBoxComponent();
875         boxComponent->GetStateAttributes()->AddAttribute<Gradient>(
876             BoxStateAttribute::GRADIENT, sweepGradient, stack->GetVisualState());
877         if (!boxComponent->GetStateAttributes()->HasAttribute(BoxStateAttribute::GRADIENT, VisualState::NORMAL)) {
878             boxComponent->GetStateAttributes()->AddAttribute<Gradient>(
879                 BoxStateAttribute::GRADIENT, GetBackDecoration()->GetGradient(), VisualState::NORMAL);
880         }
881     }
882 }
883 
SetRadialGradient(const NG::Gradient & gradient)884 void ViewAbstractModelImpl::SetRadialGradient(const NG::Gradient& gradient)
885 {
886     auto radialGradient = ToGradient(gradient);
887     auto* stack = ViewStackProcessor::GetInstance();
888     if (!stack->IsVisualStateSet()) {
889         auto decoration = GetBackDecoration();
890         if (decoration) {
891             decoration->SetGradient(radialGradient);
892         }
893     } else {
894         auto boxComponent = stack->GetBoxComponent();
895         boxComponent->GetStateAttributes()->AddAttribute<Gradient>(
896             BoxStateAttribute::GRADIENT, radialGradient, stack->GetVisualState());
897         if (!boxComponent->GetStateAttributes()->HasAttribute(BoxStateAttribute::GRADIENT, VisualState::NORMAL)) {
898             boxComponent->GetStateAttributes()->AddAttribute<Gradient>(
899                 BoxStateAttribute::GRADIENT, GetBackDecoration()->GetGradient(), VisualState::NORMAL);
900         }
901     }
902 }
903 
SetClipShape(const RefPtr<BasicShape> & shape)904 void ViewAbstractModelImpl::SetClipShape(const RefPtr<BasicShape>& shape)
905 {
906     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
907     auto clipPath = AceType::MakeRefPtr<ClipPath>();
908     clipPath->SetBasicShape(shape);
909     box->SetClipPath(clipPath);
910 }
911 
SetClipEdge(bool isClip)912 void ViewAbstractModelImpl::SetClipEdge(bool isClip)
913 {
914     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
915     box->SetBoxClipFlag(isClip);
916 }
917 
SetMask(const RefPtr<BasicShape> & shape)918 void ViewAbstractModelImpl::SetMask(const RefPtr<BasicShape>& shape)
919 {
920     auto maskPath = AceType::MakeRefPtr<MaskPath>();
921     maskPath->SetBasicShape(shape);
922     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
923     box->SetMask(maskPath);
924 }
925 
SetBackdropBlur(const Dimension & radius,const BlurOption & blurOption,const SysOptions & sysOptions)926 void ViewAbstractModelImpl::SetBackdropBlur(
927     const Dimension& radius, const BlurOption& blurOption, const SysOptions& sysOptions)
928 {
929     auto decoration = GetBackDecoration();
930     decoration->SetBlurRadius(ToAnimatableDimension(radius));
931     decoration->SetBlurStyle(BlurStyleOption());
932 }
933 
SetFrontBlur(const Dimension & radius,const BlurOption & blurOption,const SysOptions & sysOptions)934 void ViewAbstractModelImpl::SetFrontBlur(
935     const Dimension& radius, const BlurOption& blurOption, const SysOptions& sysOptions)
936 {
937     auto decoration = GetFrontDecoration();
938     decoration->SetBlurRadius(ToAnimatableDimension(radius));
939 }
940 
SetBackShadow(const std::vector<Shadow> & shadows)941 void ViewAbstractModelImpl::SetBackShadow(const std::vector<Shadow>& shadows)
942 {
943     auto backDecoration = GetBackDecoration();
944     backDecoration->SetShadows(shadows);
945 }
946 
SetBlendMode(BlendMode blendMode)947 void ViewAbstractModelImpl::SetBlendMode(BlendMode blendMode)
948 {
949     auto backDecoration = GetBackDecoration();
950     backDecoration->SetBlendMode(blendMode);
951 }
952 
SetBlendApplyType(BlendApplyType blendApplyType)953 void ViewAbstractModelImpl::SetBlendApplyType(BlendApplyType blendApplyType)
954 {
955     auto backDecoration = GetBackDecoration();
956     backDecoration->SetBlendApplyType(blendApplyType);
957 }
958 
SetColorBlend(const Color & value)959 void ViewAbstractModelImpl::SetColorBlend(const Color& value)
960 {
961     auto decoration = GetFrontDecoration();
962     decoration->SetColorBlend(value);
963 }
964 
SetWindowBlur(float progress,WindowBlurStyle blurStyle)965 void ViewAbstractModelImpl::SetWindowBlur(float progress, WindowBlurStyle blurStyle)
966 {
967     auto decoration = GetBackDecoration();
968     decoration->SetWindowBlurProgress(progress);
969     decoration->SetWindowBlurStyle(blurStyle);
970 }
971 
SetBrightness(const Dimension & value)972 void ViewAbstractModelImpl::SetBrightness(const Dimension& value)
973 {
974     auto frontDecoration = GetFrontDecoration();
975     frontDecoration->SetBrightness(value);
976 }
977 
SetGrayScale(const Dimension & value)978 void ViewAbstractModelImpl::SetGrayScale(const Dimension& value)
979 {
980     auto frontDecoration = GetFrontDecoration();
981     frontDecoration->SetGrayScale(value);
982 }
983 
SetContrast(const Dimension & value)984 void ViewAbstractModelImpl::SetContrast(const Dimension& value)
985 {
986     auto frontDecoration = GetFrontDecoration();
987     frontDecoration->SetContrast(value);
988 }
989 
SetSaturate(const Dimension & value)990 void ViewAbstractModelImpl::SetSaturate(const Dimension& value)
991 {
992     auto frontDecoration = GetFrontDecoration();
993     frontDecoration->SetSaturate(value);
994 }
995 
SetSepia(const Dimension & value)996 void ViewAbstractModelImpl::SetSepia(const Dimension& value)
997 {
998     auto frontDecoration = GetFrontDecoration();
999     frontDecoration->SetSepia(value);
1000 }
1001 
SetInvert(const InvertVariant & value)1002 void ViewAbstractModelImpl::SetInvert(const InvertVariant& value)
1003 {
1004     auto frontDecoration = GetFrontDecoration();
1005     if (value.index() == 0) {
1006         float invert = std::get<float>(value);
1007         frontDecoration->SetInvert(Dimension(invert, DimensionUnit::VP));
1008     }
1009 }
1010 
SetHueRotate(float value)1011 void ViewAbstractModelImpl::SetHueRotate(float value)
1012 {
1013     auto frontDecoration = GetFrontDecoration();
1014     frontDecoration->SetHueRotate(value);
1015 }
1016 
SetOnClick(GestureEventFunc && tapEventFunc,ClickEventFunc && clickEventFunc,double distanceThreshold)1017 void ViewAbstractModelImpl::SetOnClick(
1018     GestureEventFunc&& tapEventFunc, ClickEventFunc&& clickEventFunc, double distanceThreshold)
1019 {
1020     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1021     CHECK_NULL_VOID(inspector);
1022     auto impl = inspector->GetInspectorFunctionImpl();
1023     RefPtr<Gesture> tapGesture = AceType::MakeRefPtr<TapGesture>(1, 1, distanceThreshold);
1024     tapGesture->SetOnActionId([func = std::move(tapEventFunc), impl](GestureEvent& info) {
1025         if (impl) {
1026             impl->UpdateEventInfo(info);
1027         }
1028         func(info);
1029     });
1030     auto click = ViewStackProcessor::GetInstance()->GetBoxComponent();
1031     click->SetOnClick(tapGesture);
1032 
1033     auto onClickId = EventMarker([func = std::move(clickEventFunc), impl](const BaseEventInfo* info) {
1034         const auto* clickInfo = TypeInfoHelper::DynamicCast<ClickInfo>(info);
1035         if (!clickInfo) {
1036             return;
1037         }
1038         auto newInfo = *clickInfo;
1039         if (impl) {
1040             impl->UpdateEventInfo(newInfo);
1041         }
1042         func(clickInfo);
1043     });
1044     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(false);
1045     if (focusableComponent) {
1046         focusableComponent->SetOnClickId(onClickId);
1047     }
1048 }
1049 
SetOnTouch(TouchEventFunc && touchEventFunc)1050 void ViewAbstractModelImpl::SetOnTouch(TouchEventFunc&& touchEventFunc)
1051 {
1052     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1053     CHECK_NULL_VOID(inspector);
1054     auto impl = inspector->GetInspectorFunctionImpl();
1055     auto onTouchId = EventMarker(
1056         [func = std::move(touchEventFunc), impl](BaseEventInfo* info) {
1057             if (impl) {
1058                 impl->UpdateEventInfo(*info);
1059             }
1060             auto* touchInfo = TypeInfoHelper::DynamicCast<TouchEventInfo>(info);
1061             func(*touchInfo);
1062         },
1063         "onTouch");
1064     auto touchComponent = ViewStackProcessor::GetInstance()->GetTouchListenerComponent();
1065     touchComponent->SetOnTouchId(onTouchId);
1066 }
1067 
SetOnKeyEvent(OnKeyConsumeFunc && onKeyCallback)1068 void ViewAbstractModelImpl::SetOnKeyEvent(OnKeyConsumeFunc&& onKeyCallback)
1069 {
1070     auto onKeyId = EventMarker(
1071         [func = std::move(onKeyCallback)](BaseEventInfo* info) {
1072             auto* keyInfo = TypeInfoHelper::DynamicCast<KeyEventInfo>(info);
1073             func(*keyInfo);
1074         },
1075         "onKey", 0);
1076     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(true);
1077     if (focusableComponent) {
1078         focusableComponent->SetOnKeyId(onKeyId);
1079     }
1080 }
1081 
SetOnMouse(OnMouseEventFunc && onMouseEventFunc)1082 void ViewAbstractModelImpl::SetOnMouse(OnMouseEventFunc&& onMouseEventFunc)
1083 {
1084     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1085     CHECK_NULL_VOID(inspector);
1086     auto impl = inspector->GetInspectorFunctionImpl();
1087     auto onMouseId = [func = std::move(onMouseEventFunc), impl](MouseInfo& mouseInfo) {
1088         if (impl) {
1089             impl->UpdateEventInfo(mouseInfo);
1090         }
1091         func(mouseInfo);
1092     };
1093     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1094     box->SetOnMouseId(onMouseId);
1095 }
1096 
SetOnAxisEvent(OnAxisEventFunc && onAxisEventFunc)1097 void ViewAbstractModelImpl::SetOnAxisEvent(OnAxisEventFunc&& onAxisEventFunc) {}
1098 
SetOnHover(OnHoverFunc && onHoverEventFunc)1099 void ViewAbstractModelImpl::SetOnHover(OnHoverFunc&& onHoverEventFunc)
1100 {
1101     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1102     box->SetOnHoverId(onHoverEventFunc);
1103 }
1104 
SetOnHoverMove(OnHoverMoveFunc && onHoverMoveEventFunc)1105 void ViewAbstractModelImpl::SetOnHoverMove(OnHoverMoveFunc&& onHoverMoveEventFunc)
1106 {
1107     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1108     box->SetOnHoverMoveId(onHoverMoveEventFunc);
1109 }
1110 
SetOnDelete(std::function<void ()> && onDeleteCallback)1111 void ViewAbstractModelImpl::SetOnDelete(std::function<void()>&& onDeleteCallback)
1112 {
1113     auto onDeleteId = EventMarker(std::move(onDeleteCallback));
1114     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(false);
1115     if (focusableComponent) {
1116         focusableComponent->SetOnDeleteId(onDeleteId);
1117     }
1118 }
1119 
SetOnAppear(std::function<void ()> && onAppearCallback)1120 void ViewAbstractModelImpl::SetOnAppear(std::function<void()>&& onAppearCallback)
1121 {
1122     auto onAppearId = EventMarker(std::move(onAppearCallback));
1123     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
1124     CHECK_NULL_VOID(component);
1125     component->SetOnAppearEventId(onAppearId);
1126 }
1127 
SetOnDisAppear(std::function<void ()> && onDisAppearCallback)1128 void ViewAbstractModelImpl::SetOnDisAppear(std::function<void()>&& onDisAppearCallback)
1129 {
1130     auto onDisAppearId = EventMarker(std::move(onDisAppearCallback));
1131     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
1132     CHECK_NULL_VOID(component);
1133     component->SetOnDisappearEventId(onDisAppearId);
1134 }
1135 
SetOnAccessibility(std::function<void (const std::string &)> && onAccessibilityCallback)1136 void ViewAbstractModelImpl::SetOnAccessibility(std::function<void(const std::string&)>&& onAccessibilityCallback)
1137 {
1138     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1139     CHECK_NULL_VOID(inspector);
1140     inspector->SetAccessibilityEvent(EventMarker(std::move(onAccessibilityCallback)));
1141 }
1142 
SetOnRemoteMessage(RemoteCallback && onRemoteCallback)1143 void ViewAbstractModelImpl::SetOnRemoteMessage(RemoteCallback&& onRemoteCallback)
1144 {
1145     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1146     box->SetRemoteMessageEvent(EventMarker(std::move(onRemoteCallback)));
1147 }
1148 
SetOnFocusMove(std::function<void (int32_t)> && onFocusMoveCallback)1149 void ViewAbstractModelImpl::SetOnFocusMove(std::function<void(int32_t)>&& onFocusMoveCallback)
1150 {
1151     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(false);
1152     if (focusableComponent) {
1153         focusableComponent->SetOnFocusMove(onFocusMoveCallback);
1154     }
1155 }
1156 
SetOnFocus(OnFocusFunc && onFocusCallback)1157 void ViewAbstractModelImpl::SetOnFocus(OnFocusFunc&& onFocusCallback)
1158 {
1159     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(true);
1160     if (focusableComponent) {
1161         focusableComponent->SetOnFocus(onFocusCallback);
1162     }
1163 }
1164 
SetOnBlur(OnBlurFunc && onBlurCallback)1165 void ViewAbstractModelImpl::SetOnBlur(OnBlurFunc&& onBlurCallback)
1166 {
1167     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(true);
1168     if (focusableComponent) {
1169         focusableComponent->SetOnBlur(onBlurCallback);
1170     }
1171 }
1172 
SetOnDragStart(NG::OnDragStartFunc && onDragStart)1173 void ViewAbstractModelImpl::SetOnDragStart(NG::OnDragStartFunc&& onDragStart)
1174 {
1175     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1176     box->SetOnDragStartId(ToDragFunc(std::move(onDragStart)));
1177 }
1178 
SetOnPreDrag(NG::OnPreDragFunc && onPreDrag)1179 void ViewAbstractModelImpl::SetOnPreDrag(NG::OnPreDragFunc&& onPreDrag) {}
1180 
SetOnDragEnter(NG::OnDragDropFunc && onDragEnter)1181 void ViewAbstractModelImpl::SetOnDragEnter(NG::OnDragDropFunc&& onDragEnter)
1182 {
1183     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1184     box->SetOnDragEnterId(onDragEnter);
1185 }
1186 
SetOnDragEnd(OnNewDragFunc && onDragEnd)1187 void ViewAbstractModelImpl::SetOnDragEnd(OnNewDragFunc&& onDragEnd)
1188 {
1189     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1190     box->SetOnDragEndId(onDragEnd);
1191 }
1192 
SetOnDragLeave(NG::OnDragDropFunc && onDragLeave)1193 void ViewAbstractModelImpl::SetOnDragLeave(NG::OnDragDropFunc&& onDragLeave)
1194 {
1195     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1196     box->SetOnDragLeaveId(onDragLeave);
1197 }
1198 
SetOnDragMove(NG::OnDragDropFunc && onDragMove)1199 void ViewAbstractModelImpl::SetOnDragMove(NG::OnDragDropFunc&& onDragMove)
1200 {
1201     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1202     box->SetOnDragMoveId(onDragMove);
1203 }
1204 
SetOnDrop(NG::OnDragDropFunc && onDrop)1205 void ViewAbstractModelImpl::SetOnDrop(NG::OnDragDropFunc&& onDrop)
1206 {
1207     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1208     box->SetOnDropId(onDrop);
1209 }
1210 
SetOnVisibleChange(std::function<void (bool,double)> && onVisibleChange,const std::vector<double> & ratios)1211 void ViewAbstractModelImpl::SetOnVisibleChange(
1212     std::function<void(bool, double)>&& onVisibleChange, const std::vector<double>& ratios)
1213 {
1214     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1215     CHECK_NULL_VOID(inspector);
1216     auto container = Container::Current();
1217     CHECK_NULL_VOID(container);
1218     auto context = AceType::DynamicCast<PipelineContext>(container->GetPipelineContext());
1219     CHECK_NULL_VOID(context);
1220     auto nodeId = inspector->GetId();
1221 
1222     for (const auto& ratio : ratios) {
1223         context->AddVisibleAreaChangeNode(nodeId, ratio, onVisibleChange);
1224     }
1225 }
1226 
SetOnAreaChanged(std::function<void (const Rect &,const Offset &,const Rect &,const Offset &)> && onAreaChanged)1227 void ViewAbstractModelImpl::SetOnAreaChanged(
1228     std::function<void(const Rect&, const Offset&, const Rect&, const Offset&)>&& onAreaChanged)
1229 {
1230     auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
1231     boxComponent->GetEventExtensions()->GetOnAreaChangeExtension()->AddOnAreaChangeEvent(std::move(onAreaChanged));
1232 }
1233 
SetResponseRegion(const std::vector<DimensionRect> & responseRegion)1234 void ViewAbstractModelImpl::SetResponseRegion(const std::vector<DimensionRect>& responseRegion)
1235 {
1236     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
1237     auto renderComponent = AceType::DynamicCast<RenderComponent>(component);
1238     if (renderComponent) {
1239         renderComponent->SetResponseRegion(responseRegion);
1240         renderComponent->MarkResponseRegion(true);
1241     }
1242     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1243     box->SetResponseRegion(responseRegion);
1244     box->MarkResponseRegion(true);
1245     if (ViewStackProcessor::GetInstance()->HasClickGestureListenerComponent()) {
1246         auto click = ViewStackProcessor::GetInstance()->GetClickGestureListenerComponent();
1247         click->SetResponseRegion(responseRegion);
1248         click->MarkResponseRegion(true);
1249     }
1250     if (ViewStackProcessor::GetInstance()->HasTouchListenerComponent()) {
1251         auto touch = ViewStackProcessor::GetInstance()->GetTouchListenerComponent();
1252         touch->SetResponseRegion(responseRegion);
1253         touch->MarkResponseRegion(true);
1254     }
1255 }
1256 
SetEnabled(bool enabled)1257 void ViewAbstractModelImpl::SetEnabled(bool enabled)
1258 {
1259     auto mainComponent = ViewStackProcessor::GetInstance()->GetMainComponent();
1260     if (mainComponent) {
1261         mainComponent->SetDisabledStatus(!enabled);
1262     }
1263 
1264     auto focusComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(!enabled);
1265     if (focusComponent) {
1266         focusComponent->SetEnabled(enabled);
1267     }
1268 }
1269 
SetTouchable(bool touchable)1270 void ViewAbstractModelImpl::SetTouchable(bool touchable)
1271 {
1272     auto mainComponent = ViewStackProcessor::GetInstance()->GetMainComponent();
1273     CHECK_NULL_VOID(mainComponent);
1274     mainComponent->SetTouchable(touchable);
1275 }
1276 
SetFocusable(bool focusable)1277 void ViewAbstractModelImpl::SetFocusable(bool focusable)
1278 {
1279     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent();
1280     if (focusableComponent) {
1281         focusableComponent->SetFocusable(focusable);
1282     }
1283 }
1284 
SetFocusNode(bool focus)1285 void ViewAbstractModelImpl::SetFocusNode(bool focus)
1286 {
1287     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(false);
1288     if (focusableComponent) {
1289         focusableComponent->SetFocusNode(!focus);
1290     }
1291 }
1292 
SetTabIndex(int32_t index)1293 void ViewAbstractModelImpl::SetTabIndex(int32_t index)
1294 {
1295     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(true);
1296     if (focusableComponent) {
1297         focusableComponent->SetFocusable(true);
1298         focusableComponent->SetTabIndex(index);
1299     }
1300 }
1301 
SetFocusOnTouch(bool isSet)1302 void ViewAbstractModelImpl::SetFocusOnTouch(bool isSet)
1303 {
1304     auto touchComponent = ViewStackProcessor::GetInstance()->GetTouchListenerComponent();
1305     if (!touchComponent) {
1306         LOGE("Touch listener component get failed!");
1307         return;
1308     }
1309     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(true);
1310     if (!focusableComponent) {
1311         LOGE("focusable component get failed!");
1312         return;
1313     }
1314     focusableComponent->SetIsFocusOnTouch(isSet);
1315     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
1316     if (!component) {
1317         LOGE("main component get failed!");
1318         return;
1319     }
1320     component->SetIsFocusOnTouch(isSet);
1321 }
1322 
SetDefaultFocus(bool isSet)1323 void ViewAbstractModelImpl::SetDefaultFocus(bool isSet)
1324 {
1325     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(true);
1326     if (!focusableComponent) {
1327         LOGE("focusable component get failed!");
1328         return;
1329     }
1330     focusableComponent->SetIsDefaultFocus(isSet);
1331 }
1332 
SetGroupDefaultFocus(bool isSet)1333 void ViewAbstractModelImpl::SetGroupDefaultFocus(bool isSet)
1334 {
1335     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(true);
1336     if (!focusableComponent) {
1337         LOGE("focusable component get failed!");
1338         return;
1339     }
1340     focusableComponent->SetIsDefaultGroupFocus(isSet);
1341 }
1342 
SetInspectorId(const std::string & inspectorId)1343 void ViewAbstractModelImpl::SetInspectorId(const std::string& inspectorId)
1344 {
1345     auto component = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1346     if (component) {
1347         component->SetInspectorKey(inspectorId);
1348     }
1349 
1350     if (!AceType::InstanceOf<TextSpanComponent>(ViewStackProcessor::GetInstance()->GetMainComponent())) {
1351         auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
1352         if (flexItem) {
1353             flexItem->SetInspectorKey(inspectorId);
1354         }
1355     }
1356 
1357     if (!AceType::InstanceOf<TextSpanComponent>(ViewStackProcessor::GetInstance()->GetMainComponent())) {
1358         auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent();
1359         if (focusableComponent) {
1360             focusableComponent->SetInspectorKey(inspectorId);
1361         }
1362     }
1363 }
1364 
SetRestoreId(int32_t restoreId)1365 void ViewAbstractModelImpl::SetRestoreId(int32_t restoreId)
1366 {
1367     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
1368     if (component) {
1369         component->SetRestoreId(restoreId);
1370     }
1371 }
1372 
SetDebugLine(const std::string & line)1373 void ViewAbstractModelImpl::SetDebugLine(const std::string& line)
1374 {
1375     auto component = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1376     if (component) {
1377         component->SetDebugLine(line);
1378     }
1379 }
1380 
SetHoverEffect(HoverEffectType hoverEffect)1381 void ViewAbstractModelImpl::SetHoverEffect(HoverEffectType hoverEffect)
1382 {
1383     auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
1384     if (!boxComponent) {
1385         LOGE("boxComponent is null");
1386         return;
1387     }
1388     boxComponent->SetMouseAnimationType(static_cast<HoverAnimationType>(hoverEffect));
1389 }
1390 
SetHitTestMode(NG::HitTestMode hitTestMode)1391 void ViewAbstractModelImpl::SetHitTestMode(NG::HitTestMode hitTestMode)
1392 {
1393     auto mode = static_cast<HitTestMode>(hitTestMode);
1394     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
1395     if (component) {
1396         component->SetHitTestMode(mode);
1397     }
1398 }
1399 
BindPopup(const RefPtr<PopupParam> & param,const RefPtr<AceType> & customNode)1400 void ViewAbstractModelImpl::BindPopup(const RefPtr<PopupParam>& param, const RefPtr<AceType>& customNode)
1401 {
1402     ViewStackProcessor::GetInstance()->GetCoverageComponent();
1403     auto popupComponent = ViewStackProcessor::GetInstance()->GetPopupComponent(true);
1404     CHECK_NULL_VOID(popupComponent);
1405 
1406     auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
1407     param->SetTargetMargin(boxComponent->GetMargin());
1408     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1409     CHECK_NULL_VOID(inspector);
1410     param->SetTargetId(inspector->GetId());
1411 
1412     popupComponent->SetPopupParam(param);
1413     if (param->GetOnStateChange()) {
1414         auto changeEvent = EventMarker(param->GetOnStateChange());
1415         popupComponent->SetOnStateChange(changeEvent);
1416     }
1417     popupComponent->SetMessage(param->GetMessage());
1418     popupComponent->SetPlacementOnTop(param->GetPlacement() == Placement::TOP);
1419 
1420     auto btnPropFirst = param->GetPrimaryButtonProperties();
1421     if (btnPropFirst.touchFunc) {
1422         btnPropFirst.actionId = EventMarker([onTouch = btnPropFirst.touchFunc]() {
1423             TouchEventInfo info("unknown");
1424             onTouch(info);
1425         });
1426     }
1427     popupComponent->SetPrimaryButtonProperties(btnPropFirst);
1428 
1429     auto btnPropSecond = param->GetSecondaryButtonProperties();
1430     if (btnPropSecond.touchFunc) {
1431         btnPropSecond.actionId = EventMarker([onTouch = btnPropSecond.touchFunc]() {
1432             TouchEventInfo info("unknown");
1433             onTouch(info);
1434         });
1435     }
1436     popupComponent->SetSecondaryButtonProperties(btnPropSecond);
1437 
1438     auto customComponent = AceType::DynamicCast<Component>(customNode);
1439     if (customComponent) {
1440         popupComponent->SetCustomComponent(customComponent);
1441     }
1442 }
1443 
BindTips(const RefPtr<PopupParam> & param)1444 void ViewAbstractModelImpl::BindTips(const RefPtr<PopupParam>& param)
1445 {
1446     ViewStackProcessor::GetInstance()->GetCoverageComponent();
1447     auto tipsComponent = ViewStackProcessor::GetInstance()->GetPopupComponent(true);
1448     CHECK_NULL_VOID(tipsComponent);
1449 
1450     auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
1451     param->SetTargetMargin(boxComponent->GetMargin());
1452     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1453     CHECK_NULL_VOID(inspector);
1454     param->SetTargetId(inspector->GetId());
1455 
1456     tipsComponent->SetPopupParam(param);
1457     tipsComponent->SetMessage(param->GetMessage());
1458     tipsComponent->SetPlacementOnTop(param->GetPlacement() == Placement::TOP);
1459 }
1460 
GetSelectTheme()1461 RefPtr<SelectTheme> GetSelectTheme()
1462 {
1463     auto container = Container::Current();
1464     CHECK_NULL_RETURN(container, nullptr);
1465     auto context = container->GetPipelineContext();
1466     CHECK_NULL_RETURN(context, nullptr);
1467     return context->GetTheme<SelectTheme>();
1468 }
1469 
BindBackground(std::function<void ()> && buildFunc,const Alignment & align)1470 void ViewAbstractModelImpl::BindBackground(std::function<void()>&& buildFunc, const Alignment& align) {}
1471 
CreateMenuEventWithParams(const WeakPtr<OHOS::Ace::MenuComponent> & weak,std::vector<NG::OptionParam> && params)1472 GestureEventFunc CreateMenuEventWithParams(
1473     const WeakPtr<OHOS::Ace::MenuComponent>& weak, std::vector<NG::OptionParam>&& params)
1474 {
1475     return [weak, params](const GestureEvent& info) {
1476         auto menuComponent = weak.Upgrade();
1477         CHECK_NULL_VOID(menuComponent);
1478         auto menuTheme = GetSelectTheme();
1479         if (menuTheme) {
1480             menuComponent->SetTheme(menuTheme);
1481         }
1482         menuComponent->ClearOptions();
1483 
1484         for (const auto& param : params) {
1485             auto optionTheme = GetSelectTheme();
1486             if (!optionTheme) {
1487                 continue;
1488             }
1489             auto optionComponent = AceType::MakeRefPtr<OHOS::Ace::OptionComponent>(optionTheme);
1490             auto textComponent = AceType::MakeRefPtr<OHOS::Ace::TextComponent>(param.value);
1491 
1492             optionComponent->SetTextStyle(optionTheme->GetOptionTextStyle());
1493             optionComponent->SetTheme(optionTheme);
1494             optionComponent->SetText(textComponent);
1495             optionComponent->SetValue(param.value);
1496             optionComponent->SetCustomizedCallback(param.action);
1497             optionComponent->SetSelectedBackgroundColor(optionTheme->GetSelectedColor());
1498             menuComponent->AppendOption(optionComponent);
1499         }
1500 
1501         auto showDialog = menuComponent->GetTargetCallback();
1502         showDialog("BindMenu", info.GetGlobalLocation());
1503     };
1504 }
1505 
ExecMenuBuilder(const std::function<void ()> & builderFunc,const RefPtr<MenuComponent> & menuComponent)1506 void ExecMenuBuilder(const std::function<void()>& builderFunc, const RefPtr<MenuComponent>& menuComponent)
1507 {
1508     // use another VSP instance while executing the builder function
1509     ScopedViewStackProcessor builderViewStackProcessor;
1510     {
1511         ACE_SCORING_EVENT("contextMenu.builder");
1512         builderFunc();
1513     }
1514     auto customComponent = ViewStackProcessor::GetInstance()->Finish();
1515     CHECK_NULL_VOID(customComponent);
1516 
1517     // Set the theme
1518     auto menuTheme = GetSelectTheme();
1519     if (menuTheme) {
1520         menuComponent->SetTheme(menuTheme);
1521     }
1522     auto optionTheme = GetSelectTheme();
1523     auto optionComponent = AceType::MakeRefPtr<OHOS::Ace::OptionComponent>(optionTheme);
1524 
1525     // Set the custom component
1526     optionComponent->SetCustomComponent(customComponent);
1527     menuComponent->ClearOptions();
1528     menuComponent->AppendOption(optionComponent);
1529 }
1530 
CreateMenuEventWithBuilder(const WeakPtr<OHOS::Ace::MenuComponent> & weak,std::function<void ()> && buildFunc)1531 GestureEventFunc CreateMenuEventWithBuilder(
1532     const WeakPtr<OHOS::Ace::MenuComponent>& weak, std::function<void()>&& buildFunc)
1533 {
1534     return [weak, builderFunc = std::move(buildFunc)](const GestureEvent& info) {
1535         auto menuComponent = weak.Upgrade();
1536         CHECK_NULL_VOID(menuComponent);
1537         menuComponent->SetIsCustomMenu(true);
1538         ExecMenuBuilder(builderFunc, menuComponent);
1539         auto showDialog = menuComponent->GetTargetCallback();
1540         showDialog("BindMenu", info.GetGlobalLocation());
1541     };
1542 }
1543 
BindMenu(std::vector<NG::OptionParam> && params,std::function<void ()> && buildFunc,const NG::MenuParam &)1544 void ViewAbstractModelImpl::BindMenu(
1545     std::vector<NG::OptionParam>&& params, std::function<void()>&& buildFunc, const NG::MenuParam&)
1546 {
1547     ViewStackProcessor::GetInstance()->GetCoverageComponent();
1548     auto menuComponent = ViewStackProcessor::GetInstance()->GetMenuComponent(true);
1549     CHECK_NULL_VOID(menuComponent);
1550     auto weak = WeakPtr<OHOS::Ace::MenuComponent>(menuComponent);
1551     GestureEventFunc eventFunc;
1552     if (!params.empty()) {
1553         eventFunc = CreateMenuEventWithParams(weak, std::move(params));
1554     } else if (buildFunc) {
1555         eventFunc = CreateMenuEventWithBuilder(weak, std::move(buildFunc));
1556     } else {
1557         LOGE("No param object.");
1558         return;
1559     }
1560     auto click = ViewStackProcessor::GetInstance()->GetBoxComponent();
1561     RefPtr<Gesture> tapGesture = AceType::MakeRefPtr<TapGesture>();
1562     tapGesture->SetOnActionId(eventFunc);
1563     click->SetOnClick(tapGesture);
1564 }
1565 
BindContextMenu(ResponseType type,std::function<void ()> & buildFunc,const NG::MenuParam & menuParam,std::function<void ()> & previewBuildFunc)1566 void ViewAbstractModelImpl::BindContextMenu(ResponseType type, std::function<void()>& buildFunc,
1567     const NG::MenuParam& menuParam, std::function<void()>& previewBuildFunc)
1568 {
1569     ViewStackProcessor::GetInstance()->GetCoverageComponent();
1570     auto menuComponent = ViewStackProcessor::GetInstance()->GetMenuComponent(true);
1571     CHECK_NULL_VOID(menuComponent);
1572 #if defined(MULTIPLE_WINDOW_SUPPORTED)
1573     menuComponent->SetIsContextMenu(true);
1574 #endif
1575 
1576     auto weak = WeakPtr<OHOS::Ace::MenuComponent>(menuComponent);
1577     if (type == ResponseType::RIGHT_CLICK) {
1578         auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1579         box->SetOnMouseId([weak, builderFunc = std::move(buildFunc)](MouseInfo& info) {
1580             auto menuComponent = weak.Upgrade();
1581             CHECK_NULL_VOID(menuComponent);
1582             if (info.GetButton() == MouseButton::RIGHT_BUTTON && info.GetAction() == MouseAction::RELEASE) {
1583                 ExecMenuBuilder(builderFunc, menuComponent);
1584                 auto showMenu = menuComponent->GetTargetCallback();
1585                 info.SetStopPropagation(true);
1586                 LOGI("Context menu is triggered, type is right click.");
1587 #if defined(MULTIPLE_WINDOW_SUPPORTED)
1588                 showMenu("", info.GetScreenLocation());
1589 #else
1590                 showMenu("", info.GetGlobalLocation());
1591 #endif
1592             }
1593         });
1594     } else if (type == ResponseType::LONG_PRESS) {
1595         auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1596         RefPtr<Gesture> longGesture = AceType::MakeRefPtr<LongPressGesture>(
1597             DEFAULT_LONG_PRESS_FINGER, false, DEFAULT_LONG_PRESS_DURATION, false, true);
1598         longGesture->SetOnActionId([weak, builderFunc = std::move(buildFunc)](const GestureEvent& info) mutable {
1599             auto menuComponent = weak.Upgrade();
1600             CHECK_NULL_VOID(menuComponent);
1601             ExecMenuBuilder(builderFunc, menuComponent);
1602             auto showMenu = menuComponent->GetTargetCallback();
1603 #if defined(MULTIPLE_WINDOW_SUPPORTED)
1604             showMenu("", info.GetScreenLocation());
1605 #else
1606             showMenu("", info.GetGlobalLocation());
1607 #endif
1608         });
1609         box->SetOnLongPress(longGesture);
1610     } else {
1611         LOGE("The arg responseType is invalid.");
1612     }
1613 }
1614 
SetAccessibilityGroup(bool accessible)1615 void ViewAbstractModelImpl::SetAccessibilityGroup(bool accessible)
1616 {
1617     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1618     if (!inspector) {
1619         LOGE("this component does not have inspector");
1620         return;
1621     }
1622     inspector->SetAccessibilityGroup(accessible);
1623 }
1624 
SetAccessibilityText(const std::string & text)1625 void ViewAbstractModelImpl::SetAccessibilityText(const std::string& text)
1626 {
1627     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1628     if (!inspector) {
1629         LOGE("this component does not have inspector");
1630         return;
1631     }
1632     inspector->SetAccessibilitytext(text);
1633 }
1634 
SetAccessibilityTextHint(const std::string & text)1635 void ViewAbstractModelImpl::SetAccessibilityTextHint(const std::string& text)
1636 {}
1637 
SetAccessibilityVirtualNode(std::function<void ()> && buildFunc)1638 void ViewAbstractModelImpl::SetAccessibilityVirtualNode(std::function<void()>&& buildFunc) {}
1639 
SetAccessibilityDescription(const std::string & description)1640 void ViewAbstractModelImpl::SetAccessibilityDescription(const std::string& description)
1641 {
1642     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1643     if (!inspector) {
1644         LOGE("this component does not have inspector");
1645         return;
1646     }
1647     inspector->SetAccessibilityDescription(description);
1648 }
1649 
SetAccessibilityImportance(const std::string & importance)1650 void ViewAbstractModelImpl::SetAccessibilityImportance(const std::string& importance)
1651 {
1652     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1653     if (!inspector) {
1654         LOGE("this component does not have inspector");
1655         return;
1656     }
1657     inspector->SetAccessibilityImportance(importance);
1658 }
1659 
SetAccessibilitySelected(bool selected,bool resetValue)1660 void ViewAbstractModelImpl::SetAccessibilitySelected(bool selected, bool resetValue)
1661 {}
1662 
SetAccessibilityChecked(bool checked,bool resetValue)1663 void ViewAbstractModelImpl::SetAccessibilityChecked(bool checked, bool resetValue)
1664 {}
1665 
SetAccessibilityTextPreferred(bool accessibilityTextPreferred)1666 void ViewAbstractModelImpl::SetAccessibilityTextPreferred(bool accessibilityTextPreferred)
1667 {}
1668 
SetAccessibilityNextFocusId(const std::string & nextFocusId)1669 void ViewAbstractModelImpl::SetAccessibilityNextFocusId(const std::string& nextFocusId)
1670 {}
1671 
SetAccessibilityRole(const std::string & role,bool resetValue)1672 void ViewAbstractModelImpl::SetAccessibilityRole(const std::string& role, bool resetValue)
1673 {}
1674 
SetOnAccessibilityFocus(NG::OnAccessibilityFocusCallbackImpl && onAccessibilityFocusCallbackImpl)1675 void ViewAbstractModelImpl::SetOnAccessibilityFocus(
1676     NG::OnAccessibilityFocusCallbackImpl&& onAccessibilityFocusCallbackImpl)
1677 {}
1678 
ResetOnAccessibilityFocus()1679 void ViewAbstractModelImpl::ResetOnAccessibilityFocus()
1680 {}
1681 
SetAccessibilityDefaultFocus(bool isFocus)1682 void ViewAbstractModelImpl::SetAccessibilityDefaultFocus(bool isFocus)
1683 {}
1684 
SetAccessibilityUseSamePage(const std::string & pageMode)1685 void ViewAbstractModelImpl::SetAccessibilityUseSamePage(const std::string& pageMode)
1686 {}
1687 
SetAccessibilityScrollTriggerable(bool triggerable,bool resetValue)1688 void ViewAbstractModelImpl::SetAccessibilityScrollTriggerable(bool triggerable, bool resetValue)
1689 {}
1690 
SetAccessibilityFocusDrawLevel(int32_t drawLevel)1691 void ViewAbstractModelImpl::SetAccessibilityFocusDrawLevel(int32_t drawLevel)
1692 {}
1693 
1694 } // namespace OHOS::Ace::Framework
1695