• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "core/components/common/properties/decoration.h"
17 
18 #include "core/pipeline/pipeline_context.h"
19 namespace OHOS::Ace {
20 
SetContextAndCallback(const WeakPtr<PipelineContext> & context,const RenderNodeAnimationCallback & callback)21 void Decoration::SetContextAndCallback(
22     const WeakPtr<PipelineContext>& context, const RenderNodeAnimationCallback& callback)
23 {
24     backgroundColor_.SetContextAndCallback(context, callback);
25     border_.SetContextAndCallback(context, callback);
26     blurRadius_.SetContextAndCallback(context, callback);
27 }
28 
AddShadow(const Shadow & shadow)29 void Decoration::AddShadow(const Shadow& shadow)
30 {
31     shadows_.push_back(shadow);
32 }
33 
ClearAllShadow()34 void Decoration::ClearAllShadow()
35 {
36     shadows_.clear();
37 }
38 
GetOccupiedSize(double dipScale) const39 Size Decoration::GetOccupiedSize(double dipScale) const
40 {
41     return border_.GetLayoutSize(dipScale) + padding_.GetLayoutSizeInPx(dipScale);
42 }
43 
GetOffset(double dipScale) const44 Offset Decoration::GetOffset(double dipScale) const
45 {
46     return border_.GetOffset(dipScale) + padding_.GetOffsetInPx(dipScale);
47 }
48 
VerticalSpaceOccupied(double dipScale) const49 double Decoration::VerticalSpaceOccupied(double dipScale) const
50 {
51     return border_.VerticalWidth(dipScale) + padding_.VerticalInPx(dipScale);
52 }
53 
HorizontalSpaceOccupied(double dipScale) const54 double Decoration::HorizontalSpaceOccupied(double dipScale) const
55 {
56     return border_.HorizontalWidth(dipScale) + padding_.HorizontalInPx(dipScale);
57 }
58 
SetGradient(const Gradient & gradient,const WeakPtr<PipelineContext> & context,const RenderNodeAnimationCallback & callback)59 void Decoration::SetGradient(
60     const Gradient& gradient, const WeakPtr<PipelineContext>& context, const RenderNodeAnimationCallback& callback)
61 {
62     gradient_ = gradient;
63     if (callback) {
64         switch (gradient_.GetType()) {
65             case GradientType::LINEAR:
66                 if (gradient_.GetLinearGradient().angle) {
67                     gradient_.GetLinearGradient().angle->SetContextAndCallbackAfterFirstAssign(context, callback);
68                 }
69                 break;
70             case GradientType::SWEEP:
71                 if (gradient_.GetSweepGradient().centerX) {
72                     gradient_.GetSweepGradient().centerX->SetContextAndCallbackAfterFirstAssign(context, callback);
73                 }
74                 if (gradient_.GetSweepGradient().centerY) {
75                     gradient_.GetSweepGradient().centerY->SetContextAndCallbackAfterFirstAssign(context, callback);
76                 }
77                 if (gradient_.GetSweepGradient().startAngle) {
78                     gradient_.GetSweepGradient().startAngle->SetContextAndCallbackAfterFirstAssign(
79                         context, callback);
80                 }
81                 if (gradient_.GetSweepGradient().endAngle) {
82                     gradient_.GetSweepGradient().endAngle->SetContextAndCallbackAfterFirstAssign(context, callback);
83                 }
84                 if (gradient_.GetSweepGradient().rotation) {
85                     gradient_.GetSweepGradient().rotation->SetContextAndCallbackAfterFirstAssign(context, callback);
86                 }
87                 break;
88             case GradientType::RADIAL:
89                 if (gradient_.GetRadialGradient().radialHorizontalSize) {
90                     gradient_.GetRadialGradient().radialHorizontalSize->SetContextAndCallbackAfterFirstAssign(
91                         context, callback);
92                 }
93                 if (gradient_.GetRadialGradient().radialVerticalSize) {
94                     gradient_.GetRadialGradient().radialVerticalSize->SetContextAndCallbackAfterFirstAssign(
95                         context, callback);
96                 }
97                 if (gradient_.GetRadialGradient().radialCenterX) {
98                     gradient_.GetRadialGradient().radialCenterX->SetContextAndCallbackAfterFirstAssign(
99                         context, callback);
100                 }
101                 if (gradient_.GetRadialGradient().radialCenterY) {
102                     gradient_.GetRadialGradient().radialCenterY->SetContextAndCallbackAfterFirstAssign(
103                         context, callback);
104                 }
105                 break;
106             default:
107                 break;
108         }
109     }
110 }
111 
AddColor(const GradientColor & color)112 void Gradient::AddColor(const GradientColor& color)
113 {
114     colors_.push_back(color);
115 }
116 
ClearColors()117 void Gradient::ClearColors()
118 {
119     colors_.clear();
120 }
121 
SetSrc(const std::string & src,const RefPtr<ThemeConstants> & themeConstants)122 void BackgroundImage::SetSrc(const std::string& src, const RefPtr<ThemeConstants>& themeConstants)
123 {
124     // If match the regex, src with the outer "url()" removed is returned.
125     // Otherwise return a copy of src directly.
126     auto imgSrc = std::regex_replace(src, std::regex(R"(^url\(\s*['"]?\s*([^()]+?)\s*['"]?\s*\)$)"), "$1");
127     src_ = ThemeUtils::ProcessImageSource(imgSrc, themeConstants);
128 }
129 
130 void BackgroundImageSize::SetSizeTypeX(BackgroundImageSizeType type)
131 {
132     typeX_ = type;
133 }
134 
135 void BackgroundImageSize::SetSizeTypeY(BackgroundImageSizeType type)
136 {
137     if (type == BackgroundImageSizeType::CONTAIN || type == BackgroundImageSizeType::COVER) {
138         return;
139     }
140     typeY_ = type;
141 }
142 
143 void BackgroundImageSize::SetSizeValueX(double value)
144 {
145     if (value < -0.0) {
146         return;
147     }
148     valueX_ = value;
149 }
150 
151 void BackgroundImageSize::SetSizeValueY(double value)
152 {
153     if (value < -0.0) {
154         return;
155     }
156     valueY_ = value;
157 }
158 
159 bool BackgroundImageSize::IsValid() const
160 {
161     if (typeY_ == BackgroundImageSizeType::CONTAIN || typeY_ == BackgroundImageSizeType::COVER) {
162         return false;
163     }
164 
165     if ((typeX_ == BackgroundImageSizeType::LENGTH || typeX_ == BackgroundImageSizeType::PERCENT) &&
166         LessOrEqual(valueX_, 0.0)) {
167         return false;
168     }
169 
170     if ((typeY_ == BackgroundImageSizeType::LENGTH || typeY_ == BackgroundImageSizeType::PERCENT) &&
171         LessOrEqual(valueY_, 0.0)) {
172         return false;
173     }
174 
175     return true;
176 }
177 
178 BackgroundImageSizeType BackgroundImageSize::GetSizeTypeX() const
179 {
180     return typeX_;
181 }
182 
183 BackgroundImageSizeType BackgroundImageSize::GetSizeTypeY() const
184 {
185     return typeY_;
186 }
187 
188 double BackgroundImageSize::GetSizeValueX() const
189 {
190     return valueX_;
191 }
192 
193 double BackgroundImageSize::GetSizeValueY() const
194 {
195     return valueY_;
196 }
197 
198 BackgroundImageSize BackgroundImageSize::operator+(const BackgroundImageSize& rhs) const
199 {
200     if ((rhs.GetSizeTypeX() != GetSizeTypeX()) || (rhs.GetSizeTypeY() != GetSizeTypeY())) {
201         // error: unit not same, just return lhs value
202         return *this;
203     }
204     auto rhsX = rhs.GetSizeValueX();
205     auto rhsY = rhs.GetSizeValueY();
206     auto lhsX = GetSizeValueX();
207     auto lhsY = GetSizeValueY();
208     BackgroundImageSize size;
209     size.SetSizeValueX(rhsX + lhsX);
210     size.SetSizeTypeX(GetSizeTypeX());
211     size.SetSizeValueY(rhsY + lhsY);
212     size.SetSizeTypeY(GetSizeTypeY());
213     return size;
214 }
215 
216 BackgroundImageSize BackgroundImageSize::operator-(const BackgroundImageSize& rhs) const
217 {
218     auto rhsX = rhs.GetSizeValueX();
219     auto rhsY = rhs.GetSizeValueY();
220     auto lhsX = GetSizeValueX();
221     auto lhsY = GetSizeValueY();
222     if ((rhs.GetSizeTypeX() != GetSizeTypeX()) || (rhs.GetSizeTypeY() != GetSizeTypeY())) {
223         // error: unit not same, just return lhs value
224         return *this;
225     }
226     BackgroundImageSize size;
227     size.SetSizeValueX(lhsX - rhsX);
228     size.SetSizeTypeX(GetSizeTypeX());
229     size.SetSizeValueY(lhsY - rhsY);
230     size.SetSizeTypeY(GetSizeTypeY());
231     return size;
232 }
233 
234 BackgroundImageSize BackgroundImageSize::operator*(double value) const
235 {
236     BackgroundImageSize size;
237     size.SetSizeValueX(GetSizeValueX() * value);
238     size.SetSizeTypeX(GetSizeTypeX());
239     size.SetSizeValueY(GetSizeValueY() * value);
240     size.SetSizeTypeY(GetSizeTypeY());
241     return size;
242 }
243 
244 bool BackgroundImageSize::operator==(const BackgroundImageSize& size) const
245 {
246     return typeX_ == size.GetSizeTypeX() && NearEqual(valueX_, size.GetSizeValueX()) && typeY_ == size.GetSizeTypeY() &&
247            NearEqual(valueY_, size.GetSizeValueY());
248 }
249 
250 bool BackgroundImageSize::operator!=(const BackgroundImageSize& size) const
251 {
252     return !operator==(size);
253 }
254 
255 std::string BackgroundImageSize::ToString() const
256 {
257     auto widthType = GetSizeTypeX();
258     if (widthType == BackgroundImageSizeType::CONTAIN) {
259         return "ImageSize.Contain";
260     }
261     if (widthType == BackgroundImageSizeType::COVER) {
262         return "ImageSize.Cover";
263     }
264     if (widthType == BackgroundImageSizeType::AUTO) {
265         return "ImageSize.Auto";
266     }
267     if (widthType == BackgroundImageSizeType::FILL) {
268         return "ImageSize.FILL";
269     }
270     auto jsonValue = JsonUtil::Create(true);
271     Dimension width = Dimension((GetSizeValueX()), DimensionUnit::PX);
272     Dimension height = Dimension((GetSizeValueY()), DimensionUnit::PX);
273     jsonValue->Put("width", width.ToString().c_str());
274     jsonValue->Put("height", height.ToString().c_str());
275     return jsonValue->ToString();
276 }
277 
278 BackgroundImagePosition BackgroundImagePosition::operator+(const BackgroundImagePosition& rhs) const
279 {
280     auto rhsX = rhs.GetSizeValueX();
281     auto rhsY = rhs.GetSizeValueY();
282     auto lhsX = GetSizeValueX();
283     auto lhsY = GetSizeValueY();
284     if ((rhs.GetSizeTypeX() != GetSizeTypeX()) || (rhs.GetSizeTypeY() != GetSizeTypeY())) {
285         // error: unit not same, just return lhs value
286         return *this;
287     }
288     BackgroundImagePosition position;
289     position.SetSizeValueX(lhsX + rhsX);
290     position.SetSizeTypeX(GetSizeTypeX());
291     position.SetSizeValueY(lhsY + rhsY);
292     position.SetSizeTypeY(GetSizeTypeY());
293     return position;
294 }
295 
296 BackgroundImagePosition BackgroundImagePosition::operator-(const BackgroundImagePosition& rhs) const
297 {
298     auto rhsX = rhs.GetSizeValueX();
299     auto rhsY = rhs.GetSizeValueY();
300     auto lhsX = GetSizeValueX();
301     auto lhsY = GetSizeValueY();
302     if ((rhs.GetSizeTypeX() != GetSizeTypeX()) || (rhs.GetSizeTypeY() != GetSizeTypeY())) {
303         // error: unit not same, just return lhs value
304         return *this;
305     }
306     BackgroundImagePosition position;
307     position.SetSizeValueX(lhsX - rhsX);
308     position.SetSizeTypeX(GetSizeTypeX());
309     position.SetSizeValueY(lhsY - rhsY);
310     position.SetSizeTypeY(GetSizeTypeY());
311     return position;
312 }
313 
314 BackgroundImagePosition BackgroundImagePosition::operator*(double value) const
315 {
316     BackgroundImagePosition position;
317     position.SetSizeValueX(GetSizeValueX() * value);
318     position.SetSizeTypeX(GetSizeTypeX());
319     position.SetSizeValueY(GetSizeValueY() * value);
320     position.SetSizeTypeY(GetSizeTypeY());
321     return position;
322 }
323 
324 bool BackgroundImagePosition::operator==(const BackgroundImagePosition& backgroundImagePosition) const
325 {
326     bool isXAxisEqual = (GetSizeX() == backgroundImagePosition.GetSizeX()) &&
327                         GetSizeTypeX() == backgroundImagePosition.GetSizeTypeX();
328     bool isYAxisEqual = (GetSizeY() == backgroundImagePosition.GetSizeY()) &&
329                         GetSizeTypeY() == backgroundImagePosition.GetSizeTypeY();
330     return isXAxisEqual && isYAxisEqual;
331 }
332 
333 bool BackgroundImagePosition::operator!=(const BackgroundImagePosition& backgroundImagePosition) const
334 {
335     return !operator==(backgroundImagePosition);
336 }
337 
338 static std::string GetAlignmentType(double width, double height)
339 {
340     const double halfDimension = 50.0;
341     auto jsonValue = JsonUtil::Create(true);
342     if (NearZero(width)) {
343         if (NearZero(height)) {
344             return "Alignment.TopStart";
345         }
346         if (NearEqual(height, halfDimension)) { // Determine whether the vertical element is centered
347             return "Alignment.Start";
348         }
349         return "Alignment.BottomStart";
350     } else if (NearEqual(width, halfDimension)) { // Judge whether the horizontal element is centered
351         if (NearZero(height)) {
352             return "Alignment.Top";
353         }
354         if (NearEqual(height, halfDimension)) {
355             return "Alignment.Center";
356         }
357         return "Alignment.Bottom";
358     } else {
359         if (NearZero(height)) {
360             return "Alignment.TopEnd";
361         }
362         if (NearEqual(height, halfDimension)) {
363             return "Alignment.End";
364         }
365         return "Alignment.BottomEnd";
366     }
367 }
368 
369 std::string BackgroundImagePosition::ToString() const
370 {
371     if (GetSizeTypeX() == BackgroundImagePositionType::PX) {
372         auto width = GetSizeValueX();
373         auto height = GetSizeValueY();
374         auto jsonValue = JsonUtil::Create(true);
375         jsonValue->Put("x", width);
376         jsonValue->Put("y", height);
377         return jsonValue->ToString();
378     }
379     auto width = GetSizeValueX();
380     auto height = GetSizeValueY();
381     return GetAlignmentType(width, height);
382 }
383 
384 CanvasPath2D::CanvasPath2D(const std::string& cmds)
385 {
386     PathArgs args;
387     args.cmds = cmds;
388     caches_.emplace_back(PathCmd::CMDS, args);
389 }
390 
391 CanvasPath2D::CanvasPath2D(const RefPtr<CanvasPath2D>& path)
392 {
393     if (path != nullptr) {
394         auto caches = path->GetCaches();
395         caches_.swap(caches);
396     }
397 }
398 
399 void CanvasPath2D::AddPath(const RefPtr<CanvasPath2D>& path)
400 {
401     if (path != nullptr) {
402         auto caches = path->GetCaches();
403         caches_.insert(caches_.end(), caches.begin(), caches.end());
404     }
405 }
406 
407 void CanvasPath2D::SetTransform(double a, double b, double c, double d, double e, double f)
408 {
409     PathArgs args;
410     args.para1 = a;
411     args.para2 = b;
412     args.para3 = c;
413     args.para4 = d;
414     args.para5 = e;
415     args.para6 = f;
416     caches_.emplace_back(PathCmd::TRANSFORM, args);
417 }
418 
419 void CanvasPath2D::MoveTo(double x, double y)
420 {
421     PathArgs args;
422     args.para1 = x;
423     args.para2 = y;
424     caches_.emplace_back(PathCmd::MOVE_TO, args);
425 }
426 
427 void CanvasPath2D::LineTo(double x, double y)
428 {
429     PathArgs args;
430     args.para1 = x;
431     args.para2 = y;
432     caches_.emplace_back(PathCmd::LINE_TO, args);
433 }
434 
435 void CanvasPath2D::Arc(double x, double y, double radius, double startAngle, double endAngle, double ccw)
436 {
437     PathArgs args;
438     args.para1 = x;
439     args.para2 = y;
440     args.para3 = radius;
441     args.para4 = startAngle;
442     args.para5 = endAngle;
443     args.para6 = ccw;
444     caches_.emplace_back(PathCmd::ARC, args);
445 }
446 
447 void CanvasPath2D::ArcTo(double x1, double y1, double x2, double y2, double radius)
448 {
449     PathArgs args;
450     args.para1 = x1;
451     args.para2 = y1;
452     args.para3 = x2;
453     args.para4 = y2;
454     args.para5 = radius;
455     caches_.emplace_back(PathCmd::ARC_TO, args);
456 }
457 
458 void CanvasPath2D::QuadraticCurveTo(double cpx, double cpy, double x, double y)
459 {
460     PathArgs args;
461     args.para1 = cpx;
462     args.para2 = cpy;
463     args.para3 = x;
464     args.para4 = y;
465     caches_.emplace_back(PathCmd::QUADRATIC_CURVE_TO, args);
466 }
467 
468 void CanvasPath2D::BezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y)
469 {
470     PathArgs args;
471     args.para1 = cp1x;
472     args.para2 = cp1y;
473     args.para3 = cp2x;
474     args.para4 = cp2y;
475     args.para5 = x;
476     args.para6 = y;
477     caches_.emplace_back(PathCmd::BEZIER_CURVE_TO, args);
478 }
479 
480 void CanvasPath2D::Ellipse(
481     double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle, double ccw)
482 {
483     PathArgs args;
484     args.para1 = x;
485     args.para2 = y;
486     args.para3 = radiusX;
487     args.para4 = radiusY;
488     args.para5 = rotation;
489     args.para6 = startAngle;
490     args.para7 = endAngle;
491     args.para8 = ccw;
492     caches_.emplace_back(PathCmd::ELLIPSE, args);
493 }
494 
495 void CanvasPath2D::Rect(double x, double y, double width, double height)
496 {
497     PathArgs args;
498     args.para1 = x;
499     args.para2 = y;
500     args.para3 = width;
501     args.para4 = height;
502     caches_.emplace_back(PathCmd::RECT, args);
503 }
504 
505 void CanvasPath2D::ClosePath()
506 {
507     PathArgs args;
508     caches_.emplace_back(PathCmd::CLOSE_PATH, args);
509 }
510 
511 const std::vector<std::pair<PathCmd, PathArgs>>& CanvasPath2D::GetCaches() const
512 {
513     return caches_;
514 }
515 
516 std::string CanvasPath2D::ToString() const
517 {
518     std::string str;
519     for (const auto& cache : caches_) {
520         switch (cache.first) {
521             case PathCmd::CMDS: {
522                 str.append("CMDS:");
523                 str.append(cache.second.cmds).append(" ");
524                 break;
525             }
526             case PathCmd::TRANSFORM: {
527                 str.append("TRANSFORM:");
528                 str.append(std::to_string(cache.second.para1)).append(",");
529                 str.append(std::to_string(cache.second.para2)).append(",");
530                 str.append(std::to_string(cache.second.para3)).append(",");
531                 str.append(std::to_string(cache.second.para4)).append(",");
532                 str.append(std::to_string(cache.second.para5)).append(",");
533                 str.append(std::to_string(cache.second.para6)).append(" ");
534                 break;
535             }
536             case PathCmd::MOVE_TO: {
537                 str.append("MOVE_TO:");
538                 str.append(std::to_string(cache.second.para1)).append(",");
539                 str.append(std::to_string(cache.second.para2)).append(" ");
540                 break;
541             }
542             case PathCmd::LINE_TO: {
543                 str.append("LINE_TO:");
544                 str.append(std::to_string(cache.second.para1)).append(",");
545                 str.append(std::to_string(cache.second.para2)).append(" ");
546                 break;
547             }
548             case PathCmd::ARC: {
549                 str.append("ARC:");
550                 str.append(std::to_string(cache.second.para1)).append(",");
551                 str.append(std::to_string(cache.second.para2)).append(",");
552                 str.append(std::to_string(cache.second.para3)).append(",");
553                 str.append(std::to_string(cache.second.para4)).append(",");
554                 str.append(std::to_string(cache.second.para5)).append(",");
555                 str.append(std::to_string(cache.second.para6)).append(" ");
556                 break;
557             }
558             case PathCmd::ARC_TO: {
559                 str.append("ARC_TO:");
560                 str.append(std::to_string(cache.second.para1)).append(",");
561                 str.append(std::to_string(cache.second.para2)).append(",");
562                 str.append(std::to_string(cache.second.para3)).append(",");
563                 str.append(std::to_string(cache.second.para4)).append(",");
564                 str.append(std::to_string(cache.second.para5)).append(" ");
565                 break;
566             }
567             case PathCmd::QUADRATIC_CURVE_TO: {
568                 str.append("QUADRATIC_CURVE_TO:");
569                 str.append(std::to_string(cache.second.para1)).append(",");
570                 str.append(std::to_string(cache.second.para2)).append(",");
571                 str.append(std::to_string(cache.second.para3)).append(",");
572                 str.append(std::to_string(cache.second.para4)).append(" ");
573                 break;
574             }
575             case PathCmd::BEZIER_CURVE_TO: {
576                 str.append("BEZIER_CURVE_TO:");
577                 str.append(std::to_string(cache.second.para1)).append(",");
578                 str.append(std::to_string(cache.second.para2)).append(",");
579                 str.append(std::to_string(cache.second.para3)).append(",");
580                 str.append(std::to_string(cache.second.para4)).append(",");
581                 str.append(std::to_string(cache.second.para5)).append(",");
582                 str.append(std::to_string(cache.second.para6)).append(" ");
583                 break;
584             }
585             case PathCmd::ELLIPSE: {
586                 str.append("ELLIPSE:");
587                 str.append(std::to_string(cache.second.para1)).append(",");
588                 str.append(std::to_string(cache.second.para2)).append(",");
589                 str.append(std::to_string(cache.second.para3)).append(",");
590                 str.append(std::to_string(cache.second.para4)).append(",");
591                 str.append(std::to_string(cache.second.para5)).append(",");
592                 str.append(std::to_string(cache.second.para6)).append(",");
593                 str.append(std::to_string(cache.second.para7)).append(",");
594                 str.append(std::to_string(cache.second.para8)).append(" ");
595                 break;
596             }
597             case PathCmd::RECT: {
598                 str.append("RECT:");
599                 str.append(std::to_string(cache.second.para1)).append(",");
600                 str.append(std::to_string(cache.second.para2)).append(",");
601                 str.append(std::to_string(cache.second.para3)).append(",");
602                 str.append(std::to_string(cache.second.para4)).append(" ");
603                 break;
604             }
605             case PathCmd::CLOSE_PATH: {
606                 str.append("CLOSE_PATH").append(" ");
607                 break;
608             }
609             default: {
610                 break;
611             }
612         }
613     }
614     return str;
615 }
616 
617 std::unique_ptr<JsonValue> BrightnessOption::GetJsonObject() const
618 {
619     auto jsonBrightnessOption = JsonUtil::Create(true);
620     jsonBrightnessOption->Put("rate", rate);
621     jsonBrightnessOption->Put("lightUpDegree", lightUpDegree);
622     jsonBrightnessOption->Put("cubicCoeff", cubicCoeff);
623     jsonBrightnessOption->Put("quadCoeff", quadCoeff);
624     std::string posRGBstr = "[0.0,0.0,0.0]";
625     if (posRGB.size() > 1) {
626         posRGBstr = ("[" + std::to_string(posRGB[0]) + "," + std::to_string(posRGB[1]) + "," +
627                      std::to_string(posRGB[2]) + "]")
628                         .c_str();
629     }
630     jsonBrightnessOption->Put("posRGB", posRGBstr.c_str());
631     std::string negRGBstr = "[0.0,0.0,0.0]";
632     if (negRGB.size() > 1) {
633         negRGBstr = ("[" + std::to_string(negRGB[0]) + "," + std::to_string(negRGB[1]) + "," +
634                      std::to_string(negRGB[2]) + "]")
635                         .c_str();
636     }
637     jsonBrightnessOption->Put("negRGB", negRGBstr.c_str());
638     jsonBrightnessOption->Put("fraction", fraction);
639     return jsonBrightnessOption;
640 }
641 
642 void BrightnessOption::ToJsonValue(
643     std::unique_ptr<JsonValue>& json, const NG::InspectorFilter& filter, std::string key) const
644 {
645     /* no fixed attr below, just return */
646     if (filter.IsFastFilter()) {
647         return;
648     }
649     json->PutExtAttr(key.c_str(), GetJsonObject(), filter);
650 }
651 
652 void BackgroundImagePosition::SetContextAndCallback(
653     const WeakPtr<PipelineContext>& context, const RenderNodeAnimationCallback& callback)
654 {
655     valueX_.SetContextAndCallback(context, callback);
656     valueY_.SetContextAndCallback(context, callback);
657 }
658 
659 } // namespace OHOS::Ace
660