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 
SetPixelRound(uint16_t value)562 void ViewAbstractModelImpl::SetPixelRound(uint16_t value) {}
563 
SetLayoutWeight(float value)564 void ViewAbstractModelImpl::SetLayoutWeight(float value)
565 {
566     auto flex = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
567     flex->SetFlexWeight(value);
568 }
569 
SetLayoutDirection(TextDirection value)570 void ViewAbstractModelImpl::SetLayoutDirection(TextDirection value)
571 {
572     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
573     box->SetTextDirection(value);
574     box->SetInspectorDirection(value);
575     if (value == TextDirection::AUTO) {
576         box->SetTextDirection(
577             AceApplicationInfo::GetInstance().IsRightToLeft() ? TextDirection::RTL : TextDirection::LTR);
578     }
579 }
580 
SetAspectRatio(float ratio)581 void ViewAbstractModelImpl::SetAspectRatio(float ratio)
582 {
583     auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
584     AnimationOption option = ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
585     boxComponent->SetAspectRatio(ratio, option);
586 }
587 
SetAlign(const Alignment & alignment)588 void ViewAbstractModelImpl::SetAlign(const Alignment& alignment)
589 {
590     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
591     box->SetAlignment(alignment);
592 }
593 
SetAlignRules(const std::map<AlignDirection,AlignRule> & alignRules)594 void ViewAbstractModelImpl::SetAlignRules(const std::map<AlignDirection, AlignRule>& alignRules)
595 {
596     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
597     flexItem->SetAlignRules(alignRules);
598 }
599 
SetUseAlign(AlignDeclarationPtr declaration,AlignDeclaration::Edge edge,const std::optional<Dimension> & offset)600 void ViewAbstractModelImpl::SetUseAlign(
601     AlignDeclarationPtr declaration, AlignDeclaration::Edge edge, const std::optional<Dimension>& offset)
602 {
603     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
604     box->SetAlignDeclarationPtr(declaration);
605     box->SetUseAlignSide(edge);
606     if (offset.has_value()) {
607         box->SetUseAlignOffset(offset.value());
608     }
609 }
610 
SetGrid(std::optional<uint32_t> span,std::optional<int32_t> offset,GridSizeType type)611 void ViewAbstractModelImpl::SetGrid(std::optional<uint32_t> span, std::optional<int32_t> offset, GridSizeType type)
612 {
613     auto info = GridContainerModelImpl::GetContainer();
614     if (info != nullptr) {
615         auto builder = ViewStackProcessor::GetInstance()->GetBoxComponent()->GetGridColumnInfoBuilder();
616         builder->SetParent(info);
617         if (span.has_value()) {
618             if (type == GridSizeType::UNDEFINED) {
619                 builder->SetColumns(span.value());
620             } else {
621                 builder->SetSizeColumn(type, span.value());
622             }
623         }
624         if (offset.has_value()) {
625             if (type == GridSizeType::UNDEFINED) {
626                 builder->SetOffset(offset.value());
627             } else {
628                 builder->SetOffset(offset.value(), type);
629             }
630         }
631     }
632 }
633 
SetPosition(const Dimension & x,const Dimension & y)634 void ViewAbstractModelImpl::SetPosition(const Dimension& x, const Dimension& y)
635 {
636     auto flexItemComponent = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
637     flexItemComponent->SetLeft(ToAnimatableDimension(x));
638     flexItemComponent->SetTop(ToAnimatableDimension(y));
639     flexItemComponent->SetPositionType(PositionType::PTABSOLUTE);
640 }
641 
SetOffset(const Dimension & x,const Dimension & y)642 void ViewAbstractModelImpl::SetOffset(const Dimension& x, const Dimension& y)
643 {
644     auto flexItemComponent = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
645     flexItemComponent->SetLeft(ToAnimatableDimension(x));
646     flexItemComponent->SetTop(ToAnimatableDimension(y));
647     flexItemComponent->SetPositionType(PositionType::PTOFFSET);
648 }
649 
MarkAnchor(const Dimension & x,const Dimension & y)650 void ViewAbstractModelImpl::MarkAnchor(const Dimension& x, const Dimension& y)
651 {
652     auto flexItemComponent = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
653     flexItemComponent->SetAnchorX(ToAnimatableDimension(x));
654     flexItemComponent->SetAnchorY(ToAnimatableDimension(y));
655 }
656 
SetScale(float x,float y,float z)657 void ViewAbstractModelImpl::SetScale(float x, float y, float z)
658 {
659     RefPtr<TransformComponent> transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
660     AnimationOption option = ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
661     transform->Scale(x, y, z, option);
662 }
663 
SetPivot(const Dimension & x,const Dimension & y,const Dimension &)664 void ViewAbstractModelImpl::SetPivot(const Dimension& x, const Dimension& y, const Dimension& /* z */)
665 {
666     RefPtr<TransformComponent> transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
667     transform->SetOriginDimension(DimensionOffset(x, y));
668 }
669 
SetTranslate(const Dimension & x,const Dimension & y,const Dimension & z)670 void ViewAbstractModelImpl::SetTranslate(const Dimension& x, const Dimension& y, const Dimension& z)
671 {
672     RefPtr<TransformComponent> transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
673     AnimationOption option = ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
674     transform->Translate(x, y, z, option);
675 }
676 
SetRotate(float x,float y,float z,float angle,float perspective)677 void ViewAbstractModelImpl::SetRotate(float x, float y, float z, float angle, float perspective)
678 {
679     RefPtr<TransformComponent> transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
680     AnimationOption option = ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
681     if (!option.IsValid()) {
682         auto pipeline = PipelineBase::GetCurrentContext();
683         if (pipeline) {
684             option = pipeline->GetSyncAnimationOption();
685         }
686     }
687 
688     option.SetAllowRunningAsynchronously(false);
689     transform->Rotate(x, y, z, angle, option);
690 }
691 
SetTransformMatrix(const std::vector<float> & matrix)692 void ViewAbstractModelImpl::SetTransformMatrix(const std::vector<float>& matrix)
693 {
694     RefPtr<TransformComponent> transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
695     AnimationOption option = ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
696     transform->Matrix3d(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5], matrix[6], matrix[7],
697         matrix[8], matrix[9], matrix[10], matrix[11], matrix[12], matrix[13], matrix[14], matrix[15], option);
698 }
699 
SetOpacity(double opacity,bool passThrough)700 void ViewAbstractModelImpl::SetOpacity(double opacity, bool passThrough)
701 {
702     auto display = ViewStackProcessor::GetInstance()->GetDisplayComponent();
703     auto stack = ViewStackProcessor::GetInstance();
704     auto option = stack->GetImplicitAnimationOption();
705     if (!stack->IsVisualStateSet()) {
706         display->SetOpacity(opacity, option);
707     } else {
708         display->GetStateAttributes()->AddAttribute<AnimatableDouble>(
709             DisplayStateAttribute::OPACITY, AnimatableDouble(opacity, option), stack->GetVisualState());
710         if (!display->GetStateAttributes()->HasAttribute(DisplayStateAttribute::OPACITY, VisualState::NORMAL)) {
711             display->GetStateAttributes()->AddAttribute<AnimatableDouble>(
712                 DisplayStateAttribute::OPACITY, AnimatableDouble(display->GetOpacity(), option), VisualState::NORMAL);
713         }
714     }
715     if (passThrough && ViewStackProcessor::GetInstance()->HasDisplayComponent()) {
716         auto display = ViewStackProcessor::GetInstance()->GetDisplayComponent();
717         display->DisableLayer(true);
718     }
719 }
720 
SetTransition(const NG::TransitionOptions & transitionOptions,bool passThrough)721 void ViewAbstractModelImpl::SetTransition(const NG::TransitionOptions& transitionOptions, bool passThrough)
722 {
723     if (transitionOptions.HasOpacity()) {
724         auto display = ViewStackProcessor::GetInstance()->GetDisplayComponent();
725         display->SetTransition(transitionOptions.Type, transitionOptions.GetOpacityValue());
726     }
727     if (transitionOptions.HasTranslate()) {
728         auto transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
729         const auto& value = transitionOptions.GetTranslateValue();
730         transform->SetTranslateTransition(transitionOptions.Type, value.x, value.y, value.z);
731     }
732     if (transitionOptions.HasScale()) {
733         auto transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
734         const auto& value = transitionOptions.GetScaleValue();
735         transform->SetScaleTransition(transitionOptions.Type, value.xScale, value.yScale, value.zScale);
736         transform->SetOriginDimension(DimensionOffset(value.centerX, value.centerY));
737     }
738     if (transitionOptions.HasRotate()) {
739         auto transform = ViewStackProcessor::GetInstance()->GetTransformComponent();
740         const auto& value = transitionOptions.GetRotateValue();
741         transform->SetRotateTransition(
742             transitionOptions.Type, value.xDirection, value.yDirection, value.zDirection, value.angle);
743         transform->SetOriginDimension(DimensionOffset(value.centerX, value.centerY));
744     }
745     if (passThrough && ViewStackProcessor::GetInstance()->HasDisplayComponent()) {
746         auto display = ViewStackProcessor::GetInstance()->GetDisplayComponent();
747         display->DisableLayer(true);
748     }
749 }
750 
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)751 void ViewAbstractModelImpl::SetOverlay(const std::string& text, std::function<void()>&& buildFunc,
752     const RefPtr<NG::FrameNode>& contentNode, const std::optional<Alignment>& align,
753     const std::optional<Dimension>& offsetX, const std::optional<Dimension>& offsetY, NG::OverlayType type)
754 {
755     if (buildFunc || contentNode) {
756         return;
757     }
758     auto coverageComponent = ViewStackProcessor::GetInstance()->GetCoverageComponent();
759     coverageComponent->SetTextVal(text);
760     coverageComponent->SetIsOverLay(true);
761     coverageComponent->SetAlignment(align.value_or(Alignment::TOP_LEFT));
762     if (offsetX.has_value()) {
763         coverageComponent->SetX(offsetX.value());
764     }
765     if (offsetY.has_value()) {
766         coverageComponent->SetY(offsetY.value());
767     }
768 }
769 
SetVisibility(VisibleType visible,std::function<void (int32_t)> && changeEventFunc)770 void ViewAbstractModelImpl::SetVisibility(VisibleType visible, std::function<void(int32_t)>&& changeEventFunc)
771 {
772     auto display = ViewStackProcessor::GetInstance()->GetDisplayComponent();
773     display->SetVisible(visible);
774     auto eventMarker = EventMarker([func = std::move(changeEventFunc)](const BaseEventInfo* info) {
775         const auto& param = info->GetType();
776         int32_t newValue = StringToInt(param);
777         func(newValue);
778     });
779 
780     display->SetVisibleChangeEvent(eventMarker);
781 }
782 
SetSharedTransition(const std::string & shareId,const std::shared_ptr<SharedTransitionOption> & option)783 void ViewAbstractModelImpl::SetSharedTransition(
784     const std::string& shareId, const std::shared_ptr<SharedTransitionOption>& option)
785 {
786     auto sharedTransitionComponent = ViewStackProcessor::GetInstance()->GetSharedTransitionComponent();
787     sharedTransitionComponent->SetShareId(shareId);
788     if (!option) {
789         return;
790     }
791     TweenOption tweenOption;
792     tweenOption.SetCurve(option->curve);
793     tweenOption.SetDuration(option->duration);
794     tweenOption.SetDelay(option->delay);
795     tweenOption.SetMotionPathOption(option->motionPathOption);
796     auto sharedTransitionEffect =
797         SharedTransitionEffect::GetSharedTransitionEffect(option->type, sharedTransitionComponent->GetShareId());
798     sharedTransitionComponent->SetEffect(sharedTransitionEffect);
799     sharedTransitionComponent->SetOption(tweenOption);
800     if (option->zIndex != 0) {
801         sharedTransitionComponent->SetZIndex(option->zIndex);
802     }
803 }
804 
SetGeometryTransition(const std::string & id,bool followWithoutTransition,bool doRegisterSharedTransition)805 void ViewAbstractModelImpl::SetGeometryTransition(const std::string& id,
806     bool followWithoutTransition, bool doRegisterSharedTransition)
807 {
808     auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
809     boxComponent->SetGeometryTransitionId(id);
810 }
811 
SetMotionPath(const MotionPathOption & option)812 void ViewAbstractModelImpl::SetMotionPath(const MotionPathOption& option)
813 {
814     if (option.GetRotate()) {
815         ViewStackProcessor::GetInstance()->GetTransformComponent();
816     }
817     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
818     flexItem->SetMotionPathOption(option);
819 }
820 
SetFlexBasis(const Dimension & value)821 void ViewAbstractModelImpl::SetFlexBasis(const Dimension& value)
822 {
823     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
824     flexItem->SetFlexBasis(value);
825 }
826 
SetAlignSelf(FlexAlign value)827 void ViewAbstractModelImpl::SetAlignSelf(FlexAlign value)
828 {
829     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
830     flexItem->SetAlignSelf(value);
831 }
832 
SetFlexShrink(float value)833 void ViewAbstractModelImpl::SetFlexShrink(float value)
834 {
835     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
836     flexItem->SetFlexShrink(value);
837 }
838 
SetFlexGrow(float value)839 void ViewAbstractModelImpl::SetFlexGrow(float value)
840 {
841     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
842     flexItem->SetFlexGrow(value);
843 }
844 
SetDisplayIndex(int32_t value)845 void ViewAbstractModelImpl::SetDisplayIndex(int32_t value)
846 {
847     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
848     flexItem->SetDisplayIndex(value);
849 }
850 
SetZIndex(int32_t value)851 void ViewAbstractModelImpl::SetZIndex(int32_t value)
852 {
853     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
854     auto renderComponent = AceType::DynamicCast<RenderComponent>(component);
855     if (renderComponent) {
856         renderComponent->SetZIndex(value);
857     }
858 }
859 
SetLinearGradient(const NG::Gradient & gradient)860 void ViewAbstractModelImpl::SetLinearGradient(const NG::Gradient& gradient)
861 {
862     auto lineGradient = ToGradient(gradient);
863     auto* stack = ViewStackProcessor::GetInstance();
864     if (!stack->IsVisualStateSet()) {
865         auto decoration = GetBackDecoration();
866         if (decoration) {
867             decoration->SetGradient(lineGradient);
868         }
869     } else {
870         auto boxComponent = stack->GetBoxComponent();
871         boxComponent->GetStateAttributes()->AddAttribute<Gradient>(
872             BoxStateAttribute::GRADIENT, lineGradient, stack->GetVisualState());
873         if (!boxComponent->GetStateAttributes()->HasAttribute(BoxStateAttribute::GRADIENT, VisualState::NORMAL)) {
874             boxComponent->GetStateAttributes()->AddAttribute<Gradient>(
875                 BoxStateAttribute::GRADIENT, GetBackDecoration()->GetGradient(), VisualState::NORMAL);
876         }
877     }
878 }
879 
SetSweepGradient(const NG::Gradient & gradient)880 void ViewAbstractModelImpl::SetSweepGradient(const NG::Gradient& gradient)
881 {
882     auto sweepGradient = ToGradient(gradient);
883     auto* stack = ViewStackProcessor::GetInstance();
884     if (!stack->IsVisualStateSet()) {
885         auto decoration = GetBackDecoration();
886         if (decoration) {
887             decoration->SetGradient(sweepGradient);
888         }
889     } else {
890         auto boxComponent = stack->GetBoxComponent();
891         boxComponent->GetStateAttributes()->AddAttribute<Gradient>(
892             BoxStateAttribute::GRADIENT, sweepGradient, stack->GetVisualState());
893         if (!boxComponent->GetStateAttributes()->HasAttribute(BoxStateAttribute::GRADIENT, VisualState::NORMAL)) {
894             boxComponent->GetStateAttributes()->AddAttribute<Gradient>(
895                 BoxStateAttribute::GRADIENT, GetBackDecoration()->GetGradient(), VisualState::NORMAL);
896         }
897     }
898 }
899 
SetRadialGradient(const NG::Gradient & gradient)900 void ViewAbstractModelImpl::SetRadialGradient(const NG::Gradient& gradient)
901 {
902     auto radialGradient = ToGradient(gradient);
903     auto* stack = ViewStackProcessor::GetInstance();
904     if (!stack->IsVisualStateSet()) {
905         auto decoration = GetBackDecoration();
906         if (decoration) {
907             decoration->SetGradient(radialGradient);
908         }
909     } else {
910         auto boxComponent = stack->GetBoxComponent();
911         boxComponent->GetStateAttributes()->AddAttribute<Gradient>(
912             BoxStateAttribute::GRADIENT, radialGradient, stack->GetVisualState());
913         if (!boxComponent->GetStateAttributes()->HasAttribute(BoxStateAttribute::GRADIENT, VisualState::NORMAL)) {
914             boxComponent->GetStateAttributes()->AddAttribute<Gradient>(
915                 BoxStateAttribute::GRADIENT, GetBackDecoration()->GetGradient(), VisualState::NORMAL);
916         }
917     }
918 }
919 
SetClipShape(const RefPtr<BasicShape> & shape)920 void ViewAbstractModelImpl::SetClipShape(const RefPtr<BasicShape>& shape)
921 {
922     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
923     auto clipPath = AceType::MakeRefPtr<ClipPath>();
924     clipPath->SetBasicShape(shape);
925     box->SetClipPath(clipPath);
926 }
927 
SetClipEdge(bool isClip)928 void ViewAbstractModelImpl::SetClipEdge(bool isClip)
929 {
930     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
931     box->SetBoxClipFlag(isClip);
932 }
933 
SetMask(const RefPtr<BasicShape> & shape)934 void ViewAbstractModelImpl::SetMask(const RefPtr<BasicShape>& shape)
935 {
936     auto maskPath = AceType::MakeRefPtr<MaskPath>();
937     maskPath->SetBasicShape(shape);
938     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
939     box->SetMask(maskPath);
940 }
941 
SetBackdropBlur(const Dimension & radius,const BlurOption & blurOption)942 void ViewAbstractModelImpl::SetBackdropBlur(const Dimension& radius, const BlurOption& blurOption)
943 {
944     auto decoration = GetBackDecoration();
945     decoration->SetBlurRadius(ToAnimatableDimension(radius));
946     decoration->SetBlurStyle(BlurStyleOption());
947 }
948 
SetFrontBlur(const Dimension & radius,const BlurOption & blurOption)949 void ViewAbstractModelImpl::SetFrontBlur(const Dimension& radius, const BlurOption& blurOption)
950 {
951     auto decoration = GetFrontDecoration();
952     decoration->SetBlurRadius(ToAnimatableDimension(radius));
953 }
954 
SetBackShadow(const std::vector<Shadow> & shadows)955 void ViewAbstractModelImpl::SetBackShadow(const std::vector<Shadow>& shadows)
956 {
957     auto backDecoration = GetBackDecoration();
958     backDecoration->SetShadows(shadows);
959 }
960 
SetBlendMode(BlendMode blendMode)961 void ViewAbstractModelImpl::SetBlendMode(BlendMode blendMode)
962 {
963     auto backDecoration = GetBackDecoration();
964     backDecoration->SetBlendMode(blendMode);
965 }
966 
SetBlendApplyType(BlendApplyType blendApplyType)967 void ViewAbstractModelImpl::SetBlendApplyType(BlendApplyType blendApplyType)
968 {
969     auto backDecoration = GetBackDecoration();
970     backDecoration->SetBlendApplyType(blendApplyType);
971 }
972 
SetColorBlend(const Color & value)973 void ViewAbstractModelImpl::SetColorBlend(const Color& value)
974 {
975     auto decoration = GetFrontDecoration();
976     decoration->SetColorBlend(value);
977 }
978 
SetWindowBlur(float progress,WindowBlurStyle blurStyle)979 void ViewAbstractModelImpl::SetWindowBlur(float progress, WindowBlurStyle blurStyle)
980 {
981     auto decoration = GetBackDecoration();
982     decoration->SetWindowBlurProgress(progress);
983     decoration->SetWindowBlurStyle(blurStyle);
984 }
985 
SetBrightness(const Dimension & value)986 void ViewAbstractModelImpl::SetBrightness(const Dimension& value)
987 {
988     auto frontDecoration = GetFrontDecoration();
989     frontDecoration->SetBrightness(value);
990 }
991 
SetGrayScale(const Dimension & value)992 void ViewAbstractModelImpl::SetGrayScale(const Dimension& value)
993 {
994     auto frontDecoration = GetFrontDecoration();
995     frontDecoration->SetGrayScale(value);
996 }
997 
SetContrast(const Dimension & value)998 void ViewAbstractModelImpl::SetContrast(const Dimension& value)
999 {
1000     auto frontDecoration = GetFrontDecoration();
1001     frontDecoration->SetContrast(value);
1002 }
1003 
SetSaturate(const Dimension & value)1004 void ViewAbstractModelImpl::SetSaturate(const Dimension& value)
1005 {
1006     auto frontDecoration = GetFrontDecoration();
1007     frontDecoration->SetSaturate(value);
1008 }
1009 
SetSepia(const Dimension & value)1010 void ViewAbstractModelImpl::SetSepia(const Dimension& value)
1011 {
1012     auto frontDecoration = GetFrontDecoration();
1013     frontDecoration->SetSepia(value);
1014 }
1015 
SetInvert(const InvertVariant & value)1016 void ViewAbstractModelImpl::SetInvert(const InvertVariant& value)
1017 {
1018     auto frontDecoration = GetFrontDecoration();
1019     if (value.index() == 0) {
1020         float invert = std::get<float>(value);
1021         frontDecoration->SetInvert(Dimension(invert, DimensionUnit::VP));
1022     }
1023 }
1024 
SetHueRotate(float value)1025 void ViewAbstractModelImpl::SetHueRotate(float value)
1026 {
1027     auto frontDecoration = GetFrontDecoration();
1028     frontDecoration->SetHueRotate(value);
1029 }
1030 
SetOnClick(GestureEventFunc && tapEventFunc,ClickEventFunc && clickEventFunc,double distanceThreshold)1031 void ViewAbstractModelImpl::SetOnClick(
1032     GestureEventFunc&& tapEventFunc, ClickEventFunc&& clickEventFunc, double distanceThreshold)
1033 {
1034     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1035     CHECK_NULL_VOID(inspector);
1036     auto impl = inspector->GetInspectorFunctionImpl();
1037     RefPtr<Gesture> tapGesture = AceType::MakeRefPtr<TapGesture>(1, 1, distanceThreshold);
1038     tapGesture->SetOnActionId([func = std::move(tapEventFunc), impl](GestureEvent& info) {
1039         if (impl) {
1040             impl->UpdateEventInfo(info);
1041         }
1042         func(info);
1043     });
1044     auto click = ViewStackProcessor::GetInstance()->GetBoxComponent();
1045     click->SetOnClick(tapGesture);
1046 
1047     auto onClickId = EventMarker([func = std::move(clickEventFunc), impl](const BaseEventInfo* info) {
1048         const auto* clickInfo = TypeInfoHelper::DynamicCast<ClickInfo>(info);
1049         if (!clickInfo) {
1050             return;
1051         }
1052         auto newInfo = *clickInfo;
1053         if (impl) {
1054             impl->UpdateEventInfo(newInfo);
1055         }
1056         func(clickInfo);
1057     });
1058     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(false);
1059     if (focusableComponent) {
1060         focusableComponent->SetOnClickId(onClickId);
1061     }
1062 }
1063 
SetOnTouch(TouchEventFunc && touchEventFunc)1064 void ViewAbstractModelImpl::SetOnTouch(TouchEventFunc&& touchEventFunc)
1065 {
1066     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1067     CHECK_NULL_VOID(inspector);
1068     auto impl = inspector->GetInspectorFunctionImpl();
1069     auto onTouchId = EventMarker(
1070         [func = std::move(touchEventFunc), impl](BaseEventInfo* info) {
1071             if (impl) {
1072                 impl->UpdateEventInfo(*info);
1073             }
1074             auto* touchInfo = TypeInfoHelper::DynamicCast<TouchEventInfo>(info);
1075             func(*touchInfo);
1076         },
1077         "onTouch");
1078     auto touchComponent = ViewStackProcessor::GetInstance()->GetTouchListenerComponent();
1079     touchComponent->SetOnTouchId(onTouchId);
1080 }
1081 
SetOnKeyEvent(OnKeyConsumeFunc && onKeyCallback)1082 void ViewAbstractModelImpl::SetOnKeyEvent(OnKeyConsumeFunc&& onKeyCallback)
1083 {
1084     auto onKeyId = EventMarker(
1085         [func = std::move(onKeyCallback)](BaseEventInfo* info) {
1086             auto* keyInfo = TypeInfoHelper::DynamicCast<KeyEventInfo>(info);
1087             func(*keyInfo);
1088         },
1089         "onKey", 0);
1090     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(true);
1091     if (focusableComponent) {
1092         focusableComponent->SetOnKeyId(onKeyId);
1093     }
1094 }
1095 
SetOnMouse(OnMouseEventFunc && onMouseEventFunc)1096 void ViewAbstractModelImpl::SetOnMouse(OnMouseEventFunc&& onMouseEventFunc)
1097 {
1098     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1099     CHECK_NULL_VOID(inspector);
1100     auto impl = inspector->GetInspectorFunctionImpl();
1101     auto onMouseId = [func = std::move(onMouseEventFunc), impl](MouseInfo& mouseInfo) {
1102         if (impl) {
1103             impl->UpdateEventInfo(mouseInfo);
1104         }
1105         func(mouseInfo);
1106     };
1107     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1108     box->SetOnMouseId(onMouseId);
1109 }
1110 
SetOnHover(OnHoverFunc && onHoverEventFunc)1111 void ViewAbstractModelImpl::SetOnHover(OnHoverFunc&& onHoverEventFunc)
1112 {
1113     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1114     box->SetOnHoverId(onHoverEventFunc);
1115 }
1116 
SetOnDelete(std::function<void ()> && onDeleteCallback)1117 void ViewAbstractModelImpl::SetOnDelete(std::function<void()>&& onDeleteCallback)
1118 {
1119     auto onDeleteId = EventMarker(std::move(onDeleteCallback));
1120     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(false);
1121     if (focusableComponent) {
1122         focusableComponent->SetOnDeleteId(onDeleteId);
1123     }
1124 }
1125 
SetOnAppear(std::function<void ()> && onAppearCallback)1126 void ViewAbstractModelImpl::SetOnAppear(std::function<void()>&& onAppearCallback)
1127 {
1128     auto onAppearId = EventMarker(std::move(onAppearCallback));
1129     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
1130     CHECK_NULL_VOID(component);
1131     component->SetOnAppearEventId(onAppearId);
1132 }
1133 
SetOnDisAppear(std::function<void ()> && onDisAppearCallback)1134 void ViewAbstractModelImpl::SetOnDisAppear(std::function<void()>&& onDisAppearCallback)
1135 {
1136     auto onDisAppearId = EventMarker(std::move(onDisAppearCallback));
1137     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
1138     CHECK_NULL_VOID(component);
1139     component->SetOnDisappearEventId(onDisAppearId);
1140 }
1141 
SetOnAccessibility(std::function<void (const std::string &)> && onAccessibilityCallback)1142 void ViewAbstractModelImpl::SetOnAccessibility(std::function<void(const std::string&)>&& onAccessibilityCallback)
1143 {
1144     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1145     CHECK_NULL_VOID(inspector);
1146     inspector->SetAccessibilityEvent(EventMarker(std::move(onAccessibilityCallback)));
1147 }
1148 
SetOnRemoteMessage(RemoteCallback && onRemoteCallback)1149 void ViewAbstractModelImpl::SetOnRemoteMessage(RemoteCallback&& onRemoteCallback)
1150 {
1151     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1152     box->SetRemoteMessageEvent(EventMarker(std::move(onRemoteCallback)));
1153 }
1154 
SetOnFocusMove(std::function<void (int32_t)> && onFocusMoveCallback)1155 void ViewAbstractModelImpl::SetOnFocusMove(std::function<void(int32_t)>&& onFocusMoveCallback)
1156 {
1157     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(false);
1158     if (focusableComponent) {
1159         focusableComponent->SetOnFocusMove(onFocusMoveCallback);
1160     }
1161 }
1162 
SetOnFocus(OnFocusFunc && onFocusCallback)1163 void ViewAbstractModelImpl::SetOnFocus(OnFocusFunc&& onFocusCallback)
1164 {
1165     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(true);
1166     if (focusableComponent) {
1167         focusableComponent->SetOnFocus(onFocusCallback);
1168     }
1169 }
1170 
SetOnBlur(OnBlurFunc && onBlurCallback)1171 void ViewAbstractModelImpl::SetOnBlur(OnBlurFunc&& onBlurCallback)
1172 {
1173     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(true);
1174     if (focusableComponent) {
1175         focusableComponent->SetOnBlur(onBlurCallback);
1176     }
1177 }
1178 
SetOnDragStart(NG::OnDragStartFunc && onDragStart)1179 void ViewAbstractModelImpl::SetOnDragStart(NG::OnDragStartFunc&& onDragStart)
1180 {
1181     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1182     box->SetOnDragStartId(ToDragFunc(std::move(onDragStart)));
1183 }
1184 
SetOnPreDrag(NG::OnPreDragFunc && onPreDrag)1185 void ViewAbstractModelImpl::SetOnPreDrag(NG::OnPreDragFunc&& onPreDrag) {}
1186 
SetOnDragEnter(NG::OnDragDropFunc && onDragEnter)1187 void ViewAbstractModelImpl::SetOnDragEnter(NG::OnDragDropFunc&& onDragEnter)
1188 {
1189     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1190     box->SetOnDragEnterId(onDragEnter);
1191 }
1192 
SetOnDragEnd(OnNewDragFunc && onDragEnd)1193 void ViewAbstractModelImpl::SetOnDragEnd(OnNewDragFunc&& onDragEnd)
1194 {
1195     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1196     box->SetOnDragEndId(onDragEnd);
1197 }
1198 
SetOnDragLeave(NG::OnDragDropFunc && onDragLeave)1199 void ViewAbstractModelImpl::SetOnDragLeave(NG::OnDragDropFunc&& onDragLeave)
1200 {
1201     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1202     box->SetOnDragLeaveId(onDragLeave);
1203 }
1204 
SetOnDragMove(NG::OnDragDropFunc && onDragMove)1205 void ViewAbstractModelImpl::SetOnDragMove(NG::OnDragDropFunc&& onDragMove)
1206 {
1207     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1208     box->SetOnDragMoveId(onDragMove);
1209 }
1210 
SetOnDrop(NG::OnDragDropFunc && onDrop)1211 void ViewAbstractModelImpl::SetOnDrop(NG::OnDragDropFunc&& onDrop)
1212 {
1213     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1214     box->SetOnDropId(onDrop);
1215 }
1216 
SetOnVisibleChange(std::function<void (bool,double)> && onVisibleChange,const std::vector<double> & ratios)1217 void ViewAbstractModelImpl::SetOnVisibleChange(
1218     std::function<void(bool, double)>&& onVisibleChange, const std::vector<double>& ratios)
1219 {
1220     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1221     CHECK_NULL_VOID(inspector);
1222     auto container = Container::Current();
1223     CHECK_NULL_VOID(container);
1224     auto context = AceType::DynamicCast<PipelineContext>(container->GetPipelineContext());
1225     CHECK_NULL_VOID(context);
1226     auto nodeId = inspector->GetId();
1227 
1228     for (const auto& ratio : ratios) {
1229         context->AddVisibleAreaChangeNode(nodeId, ratio, onVisibleChange);
1230     }
1231 }
1232 
SetOnAreaChanged(std::function<void (const Rect &,const Offset &,const Rect &,const Offset &)> && onAreaChanged)1233 void ViewAbstractModelImpl::SetOnAreaChanged(
1234     std::function<void(const Rect&, const Offset&, const Rect&, const Offset&)>&& onAreaChanged)
1235 {
1236     auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
1237     boxComponent->GetEventExtensions()->GetOnAreaChangeExtension()->AddOnAreaChangeEvent(std::move(onAreaChanged));
1238 }
1239 
SetResponseRegion(const std::vector<DimensionRect> & responseRegion)1240 void ViewAbstractModelImpl::SetResponseRegion(const std::vector<DimensionRect>& responseRegion)
1241 {
1242     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
1243     auto renderComponent = AceType::DynamicCast<RenderComponent>(component);
1244     if (renderComponent) {
1245         renderComponent->SetResponseRegion(responseRegion);
1246         renderComponent->MarkResponseRegion(true);
1247     }
1248     auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1249     box->SetResponseRegion(responseRegion);
1250     box->MarkResponseRegion(true);
1251     if (ViewStackProcessor::GetInstance()->HasClickGestureListenerComponent()) {
1252         auto click = ViewStackProcessor::GetInstance()->GetClickGestureListenerComponent();
1253         click->SetResponseRegion(responseRegion);
1254         click->MarkResponseRegion(true);
1255     }
1256     if (ViewStackProcessor::GetInstance()->HasTouchListenerComponent()) {
1257         auto touch = ViewStackProcessor::GetInstance()->GetTouchListenerComponent();
1258         touch->SetResponseRegion(responseRegion);
1259         touch->MarkResponseRegion(true);
1260     }
1261 }
1262 
SetEnabled(bool enabled)1263 void ViewAbstractModelImpl::SetEnabled(bool enabled)
1264 {
1265     auto mainComponent = ViewStackProcessor::GetInstance()->GetMainComponent();
1266     if (mainComponent) {
1267         mainComponent->SetDisabledStatus(!enabled);
1268     }
1269 
1270     auto focusComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(!enabled);
1271     if (focusComponent) {
1272         focusComponent->SetEnabled(enabled);
1273     }
1274 }
1275 
SetTouchable(bool touchable)1276 void ViewAbstractModelImpl::SetTouchable(bool touchable)
1277 {
1278     auto mainComponent = ViewStackProcessor::GetInstance()->GetMainComponent();
1279     CHECK_NULL_VOID(mainComponent);
1280     mainComponent->SetTouchable(touchable);
1281 }
1282 
SetFocusable(bool focusable)1283 void ViewAbstractModelImpl::SetFocusable(bool focusable)
1284 {
1285     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent();
1286     if (focusableComponent) {
1287         focusableComponent->SetFocusable(focusable);
1288     }
1289 }
1290 
SetFocusNode(bool focus)1291 void ViewAbstractModelImpl::SetFocusNode(bool focus)
1292 {
1293     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(false);
1294     if (focusableComponent) {
1295         focusableComponent->SetFocusNode(!focus);
1296     }
1297 }
1298 
SetTabIndex(int32_t index)1299 void ViewAbstractModelImpl::SetTabIndex(int32_t index)
1300 {
1301     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(true);
1302     if (focusableComponent) {
1303         focusableComponent->SetFocusable(true);
1304         focusableComponent->SetTabIndex(index);
1305     }
1306 }
1307 
SetFocusOnTouch(bool isSet)1308 void ViewAbstractModelImpl::SetFocusOnTouch(bool isSet)
1309 {
1310     auto touchComponent = ViewStackProcessor::GetInstance()->GetTouchListenerComponent();
1311     if (!touchComponent) {
1312         LOGE("Touch listener component get failed!");
1313         return;
1314     }
1315     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(true);
1316     if (!focusableComponent) {
1317         LOGE("focusable component get failed!");
1318         return;
1319     }
1320     focusableComponent->SetIsFocusOnTouch(isSet);
1321     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
1322     if (!component) {
1323         LOGE("main component get failed!");
1324         return;
1325     }
1326     component->SetIsFocusOnTouch(isSet);
1327 }
1328 
SetDefaultFocus(bool isSet)1329 void ViewAbstractModelImpl::SetDefaultFocus(bool isSet)
1330 {
1331     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(true);
1332     if (!focusableComponent) {
1333         LOGE("focusable component get failed!");
1334         return;
1335     }
1336     focusableComponent->SetIsDefaultFocus(isSet);
1337 }
1338 
SetGroupDefaultFocus(bool isSet)1339 void ViewAbstractModelImpl::SetGroupDefaultFocus(bool isSet)
1340 {
1341     auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent(true);
1342     if (!focusableComponent) {
1343         LOGE("focusable component get failed!");
1344         return;
1345     }
1346     focusableComponent->SetIsDefaultGroupFocus(isSet);
1347 }
1348 
SetInspectorId(const std::string & inspectorId)1349 void ViewAbstractModelImpl::SetInspectorId(const std::string& inspectorId)
1350 {
1351     auto component = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1352     if (component) {
1353         component->SetInspectorKey(inspectorId);
1354     }
1355 
1356     if (!AceType::InstanceOf<TextSpanComponent>(ViewStackProcessor::GetInstance()->GetMainComponent())) {
1357         auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
1358         if (flexItem) {
1359             flexItem->SetInspectorKey(inspectorId);
1360         }
1361     }
1362 
1363     if (!AceType::InstanceOf<TextSpanComponent>(ViewStackProcessor::GetInstance()->GetMainComponent())) {
1364         auto focusableComponent = ViewStackProcessor::GetInstance()->GetFocusableComponent();
1365         if (focusableComponent) {
1366             focusableComponent->SetInspectorKey(inspectorId);
1367         }
1368     }
1369 }
1370 
SetRestoreId(int32_t restoreId)1371 void ViewAbstractModelImpl::SetRestoreId(int32_t restoreId)
1372 {
1373     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
1374     if (component) {
1375         component->SetRestoreId(restoreId);
1376     }
1377 }
1378 
SetDebugLine(const std::string & line)1379 void ViewAbstractModelImpl::SetDebugLine(const std::string& line)
1380 {
1381     auto component = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1382     if (component) {
1383         component->SetDebugLine(line);
1384     }
1385 }
1386 
SetHoverEffect(HoverEffectType hoverEffect)1387 void ViewAbstractModelImpl::SetHoverEffect(HoverEffectType hoverEffect)
1388 {
1389     auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
1390     if (!boxComponent) {
1391         LOGE("boxComponent is null");
1392         return;
1393     }
1394     boxComponent->SetMouseAnimationType(static_cast<HoverAnimationType>(hoverEffect));
1395 }
1396 
SetHitTestMode(NG::HitTestMode hitTestMode)1397 void ViewAbstractModelImpl::SetHitTestMode(NG::HitTestMode hitTestMode)
1398 {
1399     auto mode = static_cast<HitTestMode>(hitTestMode);
1400     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
1401     if (component) {
1402         component->SetHitTestMode(mode);
1403     }
1404 }
1405 
BindPopup(const RefPtr<PopupParam> & param,const RefPtr<AceType> & customNode)1406 void ViewAbstractModelImpl::BindPopup(const RefPtr<PopupParam>& param, const RefPtr<AceType>& customNode)
1407 {
1408     ViewStackProcessor::GetInstance()->GetCoverageComponent();
1409     auto popupComponent = ViewStackProcessor::GetInstance()->GetPopupComponent(true);
1410     CHECK_NULL_VOID(popupComponent);
1411 
1412     auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
1413     param->SetTargetMargin(boxComponent->GetMargin());
1414     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1415     CHECK_NULL_VOID(inspector);
1416     param->SetTargetId(inspector->GetId());
1417 
1418     popupComponent->SetPopupParam(param);
1419     if (param->GetOnStateChange()) {
1420         auto changeEvent = EventMarker(param->GetOnStateChange());
1421         popupComponent->SetOnStateChange(changeEvent);
1422     }
1423     popupComponent->SetMessage(param->GetMessage());
1424     popupComponent->SetPlacementOnTop(param->GetPlacement() == Placement::TOP);
1425 
1426     auto btnPropFirst = param->GetPrimaryButtonProperties();
1427     if (btnPropFirst.touchFunc) {
1428         btnPropFirst.actionId = EventMarker([onTouch = btnPropFirst.touchFunc]() {
1429             TouchEventInfo info("unknown");
1430             onTouch(info);
1431         });
1432     }
1433     popupComponent->SetPrimaryButtonProperties(btnPropFirst);
1434 
1435     auto btnPropSecond = param->GetSecondaryButtonProperties();
1436     if (btnPropSecond.touchFunc) {
1437         btnPropSecond.actionId = EventMarker([onTouch = btnPropSecond.touchFunc]() {
1438             TouchEventInfo info("unknown");
1439             onTouch(info);
1440         });
1441     }
1442     popupComponent->SetSecondaryButtonProperties(btnPropSecond);
1443 
1444     auto customComponent = AceType::DynamicCast<Component>(customNode);
1445     if (customComponent) {
1446         popupComponent->SetCustomComponent(customComponent);
1447     }
1448 }
1449 
GetSelectTheme()1450 RefPtr<SelectTheme> GetSelectTheme()
1451 {
1452     auto container = Container::Current();
1453     CHECK_NULL_RETURN(container, nullptr);
1454     auto context = container->GetPipelineContext();
1455     CHECK_NULL_RETURN(context, nullptr);
1456     return context->GetTheme<SelectTheme>();
1457 }
1458 
BindBackground(std::function<void ()> && buildFunc,const Alignment & align)1459 void ViewAbstractModelImpl::BindBackground(std::function<void()>&& buildFunc, const Alignment& align) {}
1460 
CreateMenuEventWithParams(const WeakPtr<OHOS::Ace::MenuComponent> & weak,std::vector<NG::OptionParam> && params)1461 GestureEventFunc CreateMenuEventWithParams(
1462     const WeakPtr<OHOS::Ace::MenuComponent>& weak, std::vector<NG::OptionParam>&& params)
1463 {
1464     return [weak, params](const GestureEvent& info) {
1465         auto menuComponent = weak.Upgrade();
1466         CHECK_NULL_VOID(menuComponent);
1467         auto menuTheme = GetSelectTheme();
1468         if (menuTheme) {
1469             menuComponent->SetTheme(menuTheme);
1470         }
1471         menuComponent->ClearOptions();
1472 
1473         for (const auto& param : params) {
1474             auto optionTheme = GetSelectTheme();
1475             if (!optionTheme) {
1476                 continue;
1477             }
1478             auto optionComponent = AceType::MakeRefPtr<OHOS::Ace::OptionComponent>(optionTheme);
1479             auto textComponent = AceType::MakeRefPtr<OHOS::Ace::TextComponent>(param.value);
1480 
1481             optionComponent->SetTextStyle(optionTheme->GetOptionTextStyle());
1482             optionComponent->SetTheme(optionTheme);
1483             optionComponent->SetText(textComponent);
1484             optionComponent->SetValue(param.value);
1485             optionComponent->SetCustomizedCallback(param.action);
1486             optionComponent->SetSelectedBackgroundColor(optionTheme->GetSelectedColor());
1487             menuComponent->AppendOption(optionComponent);
1488         }
1489 
1490         auto showDialog = menuComponent->GetTargetCallback();
1491         showDialog("BindMenu", info.GetGlobalLocation());
1492     };
1493 }
1494 
ExecMenuBuilder(const std::function<void ()> & builderFunc,const RefPtr<MenuComponent> & menuComponent)1495 void ExecMenuBuilder(const std::function<void()>& builderFunc, const RefPtr<MenuComponent>& menuComponent)
1496 {
1497     // use another VSP instance while executing the builder function
1498     ScopedViewStackProcessor builderViewStackProcessor;
1499     {
1500         ACE_SCORING_EVENT("contextMenu.builder");
1501         builderFunc();
1502     }
1503     auto customComponent = ViewStackProcessor::GetInstance()->Finish();
1504     CHECK_NULL_VOID(customComponent);
1505 
1506     // Set the theme
1507     auto menuTheme = GetSelectTheme();
1508     if (menuTheme) {
1509         menuComponent->SetTheme(menuTheme);
1510     }
1511     auto optionTheme = GetSelectTheme();
1512     auto optionComponent = AceType::MakeRefPtr<OHOS::Ace::OptionComponent>(optionTheme);
1513 
1514     // Set the custom component
1515     optionComponent->SetCustomComponent(customComponent);
1516     menuComponent->ClearOptions();
1517     menuComponent->AppendOption(optionComponent);
1518 }
1519 
CreateMenuEventWithBuilder(const WeakPtr<OHOS::Ace::MenuComponent> & weak,std::function<void ()> && buildFunc)1520 GestureEventFunc CreateMenuEventWithBuilder(
1521     const WeakPtr<OHOS::Ace::MenuComponent>& weak, std::function<void()>&& buildFunc)
1522 {
1523     return [weak, builderFunc = std::move(buildFunc)](const GestureEvent& info) {
1524         auto menuComponent = weak.Upgrade();
1525         CHECK_NULL_VOID(menuComponent);
1526         menuComponent->SetIsCustomMenu(true);
1527         ExecMenuBuilder(builderFunc, menuComponent);
1528         auto showDialog = menuComponent->GetTargetCallback();
1529         showDialog("BindMenu", info.GetGlobalLocation());
1530     };
1531 }
1532 
BindMenu(std::vector<NG::OptionParam> && params,std::function<void ()> && buildFunc,const NG::MenuParam &)1533 void ViewAbstractModelImpl::BindMenu(
1534     std::vector<NG::OptionParam>&& params, std::function<void()>&& buildFunc, const NG::MenuParam&)
1535 {
1536     ViewStackProcessor::GetInstance()->GetCoverageComponent();
1537     auto menuComponent = ViewStackProcessor::GetInstance()->GetMenuComponent(true);
1538     CHECK_NULL_VOID(menuComponent);
1539     auto weak = WeakPtr<OHOS::Ace::MenuComponent>(menuComponent);
1540     GestureEventFunc eventFunc;
1541     if (!params.empty()) {
1542         eventFunc = CreateMenuEventWithParams(weak, std::move(params));
1543     } else if (buildFunc) {
1544         eventFunc = CreateMenuEventWithBuilder(weak, std::move(buildFunc));
1545     } else {
1546         LOGE("No param object.");
1547         return;
1548     }
1549     auto click = ViewStackProcessor::GetInstance()->GetBoxComponent();
1550     RefPtr<Gesture> tapGesture = AceType::MakeRefPtr<TapGesture>();
1551     tapGesture->SetOnActionId(eventFunc);
1552     click->SetOnClick(tapGesture);
1553 }
1554 
BindContextMenu(ResponseType type,std::function<void ()> & buildFunc,const NG::MenuParam & menuParam,std::function<void ()> & previewBuildFunc)1555 void ViewAbstractModelImpl::BindContextMenu(ResponseType type, std::function<void()>& buildFunc,
1556     const NG::MenuParam& menuParam, std::function<void()>& previewBuildFunc)
1557 {
1558     ViewStackProcessor::GetInstance()->GetCoverageComponent();
1559     auto menuComponent = ViewStackProcessor::GetInstance()->GetMenuComponent(true);
1560     CHECK_NULL_VOID(menuComponent);
1561 #if defined(MULTIPLE_WINDOW_SUPPORTED)
1562     menuComponent->SetIsContextMenu(true);
1563 #endif
1564 
1565     auto weak = WeakPtr<OHOS::Ace::MenuComponent>(menuComponent);
1566     if (type == ResponseType::RIGHT_CLICK) {
1567         auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1568         box->SetOnMouseId([weak, builderFunc = std::move(buildFunc)](MouseInfo& info) {
1569             auto menuComponent = weak.Upgrade();
1570             CHECK_NULL_VOID(menuComponent);
1571             if (info.GetButton() == MouseButton::RIGHT_BUTTON && info.GetAction() == MouseAction::RELEASE) {
1572                 ExecMenuBuilder(builderFunc, menuComponent);
1573                 auto showMenu = menuComponent->GetTargetCallback();
1574                 info.SetStopPropagation(true);
1575                 LOGI("Context menu is triggered, type is right click.");
1576 #if defined(MULTIPLE_WINDOW_SUPPORTED)
1577                 showMenu("", info.GetScreenLocation());
1578 #else
1579                 showMenu("", info.GetGlobalLocation());
1580 #endif
1581             }
1582         });
1583     } else if (type == ResponseType::LONG_PRESS) {
1584         auto box = ViewStackProcessor::GetInstance()->GetBoxComponent();
1585         RefPtr<Gesture> longGesture = AceType::MakeRefPtr<LongPressGesture>(
1586             DEFAULT_LONG_PRESS_FINGER, false, DEFAULT_LONG_PRESS_DURATION, false, true);
1587         longGesture->SetOnActionId([weak, builderFunc = std::move(buildFunc)](const GestureEvent& info) mutable {
1588             auto menuComponent = weak.Upgrade();
1589             CHECK_NULL_VOID(menuComponent);
1590             ExecMenuBuilder(builderFunc, menuComponent);
1591             auto showMenu = menuComponent->GetTargetCallback();
1592 #if defined(MULTIPLE_WINDOW_SUPPORTED)
1593             showMenu("", info.GetScreenLocation());
1594 #else
1595             showMenu("", info.GetGlobalLocation());
1596 #endif
1597         });
1598         box->SetOnLongPress(longGesture);
1599     } else {
1600         LOGE("The arg responseType is invalid.");
1601     }
1602 }
1603 
SetAccessibilityGroup(bool accessible)1604 void ViewAbstractModelImpl::SetAccessibilityGroup(bool accessible)
1605 {
1606     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1607     if (!inspector) {
1608         LOGE("this component does not have inspector");
1609         return;
1610     }
1611     inspector->SetAccessibilityGroup(accessible);
1612 }
1613 
SetAccessibilityText(const std::string & text)1614 void ViewAbstractModelImpl::SetAccessibilityText(const std::string& text)
1615 {
1616     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1617     if (!inspector) {
1618         LOGE("this component does not have inspector");
1619         return;
1620     }
1621     inspector->SetAccessibilitytext(text);
1622 }
1623 
SetAccessibilityTextHint(const std::string & text)1624 void ViewAbstractModelImpl::SetAccessibilityTextHint(const std::string& text)
1625 {}
1626 
SetAccessibilityVirtualNode(std::function<void ()> && buildFunc)1627 void ViewAbstractModelImpl::SetAccessibilityVirtualNode(std::function<void()>&& buildFunc) {}
1628 
SetAccessibilityDescription(const std::string & description)1629 void ViewAbstractModelImpl::SetAccessibilityDescription(const std::string& description)
1630 {
1631     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1632     if (!inspector) {
1633         LOGE("this component does not have inspector");
1634         return;
1635     }
1636     inspector->SetAccessibilityDescription(description);
1637 }
1638 
SetAccessibilityImportance(const std::string & importance)1639 void ViewAbstractModelImpl::SetAccessibilityImportance(const std::string& importance)
1640 {
1641     auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
1642     if (!inspector) {
1643         LOGE("this component does not have inspector");
1644         return;
1645     }
1646     inspector->SetAccessibilityImportance(importance);
1647 }
1648 
SetAccessibilitySelected(bool selected,bool resetValue)1649 void ViewAbstractModelImpl::SetAccessibilitySelected(bool selected, bool resetValue)
1650 {}
1651 
SetAccessibilityChecked(bool checked,bool resetValue)1652 void ViewAbstractModelImpl::SetAccessibilityChecked(bool checked, bool resetValue)
1653 {}
1654 
SetAccessibilityTextPreferred(bool accessibilityTextPreferred)1655 void ViewAbstractModelImpl::SetAccessibilityTextPreferred(bool accessibilityTextPreferred)
1656 {}
1657 } // namespace OHOS::Ace::Framework
1658