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