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