• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_IMAGE_IMAGE_MODEL_NG_CPP
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_IMAGE_IMAGE_MODEL_NG_CPP
18 
19 #include "core/components_ng/pattern/image/image_model_ng.h"
20 
21 #include "interfaces/native/node/resource.h"
22 
23 #include "base/image/image_defines.h"
24 #include "core/components/common/layout/constants.h"
25 #include "core/components/image/image_theme.h"
26 #include "core/components_ng/base/frame_node.h"
27 #include "core/components_ng/base/view_stack_processor.h"
28 #include "core/components_ng/pattern/image/image_render_property.h"
29 #include "core/components_ng/pattern/text/span_node.h"
30 #include "core/image/image_source_info.h"
31 #ifndef ACE_UNITTEST
32 #include "core/components_ng/base/view_abstract.h"
33 #endif
34 
35 namespace OHOS::Ace::NG {
36 namespace {
37 const std::vector<float> DEFAULT_COLOR_FILTER = { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0 };
CreateSourceInfo(const std::shared_ptr<std::string> & src,RefPtr<PixelMap> & pixmap,const std::string & bundleName,const std::string & moduleName)38 ImageSourceInfo CreateSourceInfo(const std::shared_ptr<std::string>& src, RefPtr<PixelMap>& pixmap,
39     const std::string& bundleName, const std::string& moduleName)
40 {
41 #if defined(PIXEL_MAP_SUPPORTED)
42     if (pixmap) {
43         return ImageSourceInfo(pixmap);
44     }
45 #endif
46     return { src, bundleName, moduleName };
47 }
48 
CreateSourceInfo(const std::string & src,RefPtr<PixelMap> & pixmap,const std::string & bundleName,const std::string & moduleName)49 ImageSourceInfo CreateSourceInfo(
50     const std::string& src, RefPtr<PixelMap>& pixmap, const std::string& bundleName, const std::string& moduleName)
51 {
52 #if defined(PIXEL_MAP_SUPPORTED)
53     if (pixmap) {
54         return ImageSourceInfo(pixmap);
55     }
56 #endif
57     return { src, bundleName, moduleName };
58 }
59 } // namespace
60 
Create(const ImageInfoConfig & imageInfoConfig,RefPtr<PixelMap> & pixMap)61 void ImageModelNG::Create(const ImageInfoConfig& imageInfoConfig, RefPtr<PixelMap>& pixMap)
62 {
63     auto* stack = ViewStackProcessor::GetInstance();
64     auto nodeId = stack->ClaimNodeId();
65     const std::string& src = imageInfoConfig.src ? *imageInfoConfig.src : "";
66     ACE_IMAGE_SCOPED_TRACE("Create[%s][self:%d] [src:%s]", V2::IMAGE_ETS_TAG, nodeId, src.c_str());
67     RefPtr<FrameNode> frameNode;
68     if (imageInfoConfig.isImageSpan) {
69         frameNode = ImageSpanNode::GetOrCreateSpanNode(
70             V2::IMAGE_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<ImagePattern>(); });
71     } else {
72         frameNode = FrameNode::GetOrCreateFrameNode(
73             V2::IMAGE_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<ImagePattern>(); });
74     }
75     stack->Push(frameNode);
76     auto pattern = frameNode->GetPattern<ImagePattern>();
77     CHECK_NULL_VOID(pattern);
78     if (src.empty() && !pixMap && pattern->GetIsAnimation()) {
79         pattern->SetSrcUndefined(true);
80         return;
81     }
82 
83     SetDraggableForFrameNode(frameNode, imageInfoConfig.isImageSpan);
84     auto srcInfo =
85         CreateSourceInfo(imageInfoConfig.src, pixMap, imageInfoConfig.bundleName, imageInfoConfig.moduleName);
86     srcInfo.SetIsUriPureNumber(imageInfoConfig.isUriPureNumber);
87 
88     if (pattern->GetImageType() != ImageType::BASE) {
89         if (pattern->GetHasSizeChanged()) {
90             pattern->ResetPictureSize();
91         }
92         pattern->StopAnimation();
93         pattern->ResetImages();
94         if (!frameNode->GetChildren().empty()) {
95             auto imageFrameNode = AceType::DynamicCast<FrameNode>(frameNode->GetChildren().front());
96             ACE_RESET_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageSourceInfo, imageFrameNode);
97             frameNode->RemoveChild(imageFrameNode);
98         }
99     }
100     pattern->SetNeedLoadAlt(true);
101     pattern->SetImageType(ImageType::BASE);
102 
103     ACE_UPDATE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageSourceInfo, srcInfo);
104 }
105 
Create(const RefPtr<DrawableDescriptor> & drawable)106 void ImageModelNG::Create(const RefPtr<DrawableDescriptor>& drawable)
107 {
108     auto* stack = ViewStackProcessor::GetInstance();
109     auto nodeId = stack->ClaimNodeId();
110     auto frameNode = FrameNode::GetOrCreateFrameNode(
111         V2::IMAGE_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<ImagePattern>(); });
112     stack->Push(frameNode);
113     auto pattern = frameNode->GetPattern<ImagePattern>();
114     pattern->SetNeedLoadAlt(true);
115     pattern->SetImageType(ImageType::PIXELMAP_DRAWABLE);
116     pattern->SetDrawable(drawable);
117     frameNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
118     SetDraggableForFrameNode(frameNode);
119 }
120 
SetDraggableForFrameNode(RefPtr<FrameNode> frameNode,bool isImageSpan)121 void ImageModelNG::SetDraggableForFrameNode(RefPtr<FrameNode> frameNode, bool isImageSpan)
122 {
123     if (frameNode->IsFirstBuilding() && !isImageSpan) {
124         auto pipeline = frameNode->GetContext();
125         CHECK_NULL_VOID(pipeline);
126         auto draggable = pipeline->GetDraggable<ImageTheme>();
127         if (draggable && !frameNode->IsDraggable()) {
128             auto gestureHub = frameNode->GetOrCreateGestureEventHub();
129             CHECK_NULL_VOID(gestureHub);
130             gestureHub->InitDragDropEvent();
131         }
132         frameNode->SetDraggable(draggable);
133     }
134 }
135 
ResetImage()136 void ImageModelNG::ResetImage()
137 {
138     auto* stack = ViewStackProcessor::GetInstance();
139     auto nodeId = stack->ClaimNodeId();
140     RefPtr<FrameNode> frameNode;
141     frameNode = FrameNode::GetOrCreateFrameNode(
142         V2::IMAGE_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<ImagePattern>(); });
143     stack->Push(frameNode);
144     ImageSourceInfo sourceInfo("");
145     sourceInfo.SetIsFromReset(true);
146     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageSourceInfo, sourceInfo, frameNode);
147     frameNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
148     auto pattern = frameNode->GetPattern<ImagePattern>();
149     CHECK_NULL_VOID(pattern);
150     pattern->SetNeedLoadAlt(false);
151     pattern->ResetImageAndAlt();
152     if (pattern->GetImageType() == ImageType::ANIMATED_DRAWABLE) {
153         if (pattern->GetHasSizeChanged()) {
154             pattern->ResetPictureSize();
155         }
156         pattern->StopAnimation();
157         pattern->ResetImages();
158         if (!frameNode->GetChildren().empty()) {
159             auto imageFrameNode = AceType::DynamicCast<FrameNode>(frameNode->GetChildren().front());
160             ACE_RESET_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageSourceInfo, imageFrameNode);
161             frameNode->RemoveChild(imageFrameNode);
162         }
163         pattern->SetImageType(ImageType::BASE);
164     }
165 }
166 
ResetImage(FrameNode * frameNode)167 void ImageModelNG::ResetImage(FrameNode* frameNode)
168 {
169     ImageSourceInfo sourceInfo("");
170     sourceInfo.SetIsFromReset(true);
171     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageSourceInfo, sourceInfo, frameNode);
172     frameNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
173     auto pattern = frameNode->GetPattern<ImagePattern>();
174     CHECK_NULL_VOID(pattern);
175     pattern->SetNeedLoadAlt(false);
176     pattern->ResetImageAndAlt();
177 }
178 
SetInitialSrc(FrameNode * frameNode,const std::string & src,const std::string & bundleName,const std::string & moduleName,bool isUriPureNumber)179 void ImageModelNG::SetInitialSrc(FrameNode* frameNode, const std::string& src, const std::string& bundleName,
180     const std::string& moduleName, bool isUriPureNumber)
181 {
182     auto srcInfo = ImageSourceInfo { src, bundleName, moduleName };
183     srcInfo.SetIsUriPureNumber(isUriPureNumber);
184 
185     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageSourceInfo, srcInfo, frameNode);
186 }
187 
SetInitialPixelMap(FrameNode * frameNode,RefPtr<PixelMap> & pixMap)188 void ImageModelNG::SetInitialPixelMap(FrameNode* frameNode, RefPtr<PixelMap>& pixMap)
189 {
190     auto srcInfo = ImageSourceInfo(pixMap);
191     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageSourceInfo, srcInfo, frameNode);
192 }
193 
CreateAnimation(const std::vector<ImageProperties> & imageList,int32_t duration,int32_t iteration)194 void ImageModelNG::CreateAnimation(const std::vector<ImageProperties>& imageList, int32_t duration, int32_t iteration)
195 {
196     auto* stack = ViewStackProcessor::GetInstance();
197     auto nodeId = stack->ClaimNodeId();
198     ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::IMAGE_ETS_TAG, nodeId);
199     auto frameNode = FrameNode::GetOrCreateFrameNode(
200         V2::IMAGE_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<ImagePattern>(); });
201     CHECK_NULL_VOID(frameNode);
202     if (frameNode->GetChildren().empty()) {
203         auto imageNode = FrameNode::CreateFrameNode(
204             V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
205         CHECK_NULL_VOID(imageNode);
206         auto imageLayoutProperty = AceType::DynamicCast<ImageLayoutProperty>(imageNode->GetLayoutProperty());
207         CHECK_NULL_VOID(imageLayoutProperty);
208         imageLayoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT);
209         frameNode->GetLayoutProperty()->UpdateAlignment(Alignment::TOP_LEFT);
210         frameNode->AddChild(imageNode);
211     }
212     stack->Push(frameNode);
213 
214     auto pattern = frameNode->GetPattern<ImagePattern>();
215     CHECK_NULL_VOID(pattern);
216     if (!pattern->GetIsAnimation()) {
217         auto castImageLayoutProperty = frameNode->GetLayoutPropertyPtr<ImageLayoutProperty>();
218         CHECK_NULL_VOID(castImageLayoutProperty);
219         castImageLayoutProperty->Reset();
220         auto castImageRenderProperty = frameNode->GetPaintPropertyPtr<ImageRenderProperty>();
221         CHECK_NULL_VOID(castImageRenderProperty);
222         castImageRenderProperty->Reset();
223         pattern->ResetImageAndAlt();
224         pattern->ResetImageProperties();
225     }
226     // set draggable for framenode
227     auto pipeline = frameNode->GetContext();
228     CHECK_NULL_VOID(pipeline);
229     auto draggable = pipeline->GetDraggable<ImageTheme>();
230     if (draggable && !frameNode->IsDraggable()) {
231         auto gestureHub = frameNode->GetOrCreateGestureEventHub();
232         CHECK_NULL_VOID(gestureHub);
233         gestureHub->InitDragDropEvent();
234     }
235     frameNode->SetDraggable(draggable);
236     pattern->SetSrcUndefined(false);
237     pattern->StopAnimation();
238     pattern->SetImageType(ImageType::ANIMATED_DRAWABLE);
239     std::vector<ImageProperties> images = imageList;
240     pattern->SetImages(std::move(images));
241     pattern->SetDuration(duration);
242     pattern->SetIteration(iteration);
243     pattern->StartAnimation();
244 }
245 
CreateFrameNode(int32_t nodeId,const std::string & src,RefPtr<PixelMap> & pixMap,const std::string & bundleName,const std::string & moduleName,bool isUriPureNumber)246 RefPtr<FrameNode> ImageModelNG::CreateFrameNode(int32_t nodeId, const std::string& src, RefPtr<PixelMap>& pixMap,
247     const std::string& bundleName, const std::string& moduleName, bool isUriPureNumber)
248 {
249     auto frameNode = FrameNode::CreateFrameNode(V2::IMAGE_ETS_TAG, nodeId, AceType::MakeRefPtr<ImagePattern>());
250     CHECK_NULL_RETURN(frameNode, nullptr);
251     // set draggable for framenode
252     auto pipeline = PipelineContext::GetCurrentContextSafelyWithCheck();
253     CHECK_NULL_RETURN(pipeline, nullptr);
254     auto draggable = pipeline->GetDraggable<ImageTheme>();
255     if (draggable && !frameNode->IsDraggable()) {
256         auto gestureHub = frameNode->GetOrCreateGestureEventHub();
257         CHECK_NULL_RETURN(gestureHub, nullptr);
258         gestureHub->InitDragDropEvent();
259     }
260     frameNode->SetDraggable(draggable);
261     auto srcInfo = CreateSourceInfo(src, pixMap, bundleName, moduleName);
262     srcInfo.SetIsUriPureNumber(isUriPureNumber);
263     auto layoutProperty = frameNode->GetLayoutProperty<ImageLayoutProperty>();
264     CHECK_NULL_RETURN(layoutProperty, nullptr);
265     layoutProperty->UpdateImageSourceInfo(srcInfo);
266     return frameNode;
267 }
268 
SetAlt(const ImageSourceInfo & src)269 void ImageModelNG::SetAlt(const ImageSourceInfo& src)
270 {
271     ACE_UPDATE_LAYOUT_PROPERTY(ImageLayoutProperty, Alt, src);
272 }
273 
SetSmoothEdge(float value)274 void ImageModelNG::SetSmoothEdge(float value)
275 {
276     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, SmoothEdge, value);
277 }
278 
SetSmoothEdge(FrameNode * frameNode,float value)279 void ImageModelNG::SetSmoothEdge(FrameNode* frameNode, float value)
280 {
281     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, SmoothEdge, value, frameNode);
282 }
283 
SetDynamicRangeMode(DynamicRangeMode dynamicRangeMode)284 void ImageModelNG::SetDynamicRangeMode(DynamicRangeMode dynamicRangeMode)
285 {
286     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, DynamicMode, dynamicRangeMode);
287     ACE_UPDATE_RENDER_CONTEXT(DynamicRangeMode, dynamicRangeMode);
288 }
289 
SetDynamicRangeMode(FrameNode * frameNode,DynamicRangeMode dynamicRangeMode)290 void ImageModelNG::SetDynamicRangeMode(FrameNode* frameNode, DynamicRangeMode dynamicRangeMode)
291 {
292     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, DynamicMode, dynamicRangeMode, frameNode);
293     ACE_UPDATE_NODE_RENDER_CONTEXT(DynamicRangeMode, dynamicRangeMode, frameNode);
294 }
295 
SetEnhancedImageQuality(AIImageQuality imageQuality)296 void ImageModelNG::SetEnhancedImageQuality(AIImageQuality imageQuality)
297 {
298     auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<ImagePattern>();
299     CHECK_NULL_VOID(pattern);
300     pattern->SetImageQuality(imageQuality);
301 }
302 
SetEnhancedImageQuality(FrameNode * frameNode,AIImageQuality imageQuality)303 void ImageModelNG::SetEnhancedImageQuality(FrameNode* frameNode, AIImageQuality imageQuality)
304 {
305     auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<ImagePattern>(frameNode);
306     CHECK_NULL_VOID(pattern);
307     pattern->SetImageQuality(imageQuality);
308 }
309 
SetBorder(const Border & border)310 void ImageModelNG::SetBorder(const Border& border) {}
311 
SetBorderRadius(const Dimension & value)312 void ImageModelNG::SetBorderRadius(const Dimension& value)
313 {
314     BorderRadiusProperty borderRadius;
315     borderRadius.SetRadius(value);
316     borderRadius.multiValued = false;
317     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, NeedBorderRadius, true);
318     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, BorderRadius, borderRadius);
319     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
320     CHECK_NULL_VOID(frameNode);
321     auto pattern = frameNode->GetPattern<ImagePattern>();
322     CHECK_NULL_VOID(pattern);
323     pattern->SetNeedBorderRadius(true);
324 }
325 
SetBorderRadius(const std::optional<Dimension> & radiusTopLeft,const std::optional<Dimension> & radiusTopRight,const std::optional<Dimension> & radiusBottomLeft,const std::optional<Dimension> & radiusBottomRight)326 void ImageModelNG::SetBorderRadius(const std::optional<Dimension>& radiusTopLeft,
327     const std::optional<Dimension>& radiusTopRight, const std::optional<Dimension>& radiusBottomLeft,
328     const std::optional<Dimension>& radiusBottomRight)
329 {
330     NG::BorderRadiusProperty borderRadius;
331     borderRadius.radiusTopLeft = radiusTopLeft;
332     borderRadius.radiusTopRight = radiusTopRight;
333     borderRadius.radiusBottomLeft = radiusBottomLeft;
334     borderRadius.radiusBottomRight = radiusBottomRight;
335     borderRadius.multiValued = true;
336     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, NeedBorderRadius, true);
337     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, BorderRadius, borderRadius);
338     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
339     CHECK_NULL_VOID(frameNode);
340     auto pattern = frameNode->GetPattern<ImagePattern>();
341     CHECK_NULL_VOID(pattern);
342     pattern->SetNeedBorderRadius(true);
343 }
344 
SetBorderRadius(const NG::BorderRadiusProperty & borderRadius)345 void ImageModelNG::SetBorderRadius(const NG::BorderRadiusProperty& borderRadius)
346 {
347     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, NeedBorderRadius, true);
348     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, BorderRadius, borderRadius);
349     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
350     CHECK_NULL_VOID(frameNode);
351     auto pattern = frameNode->GetPattern<ImagePattern>();
352     CHECK_NULL_VOID(pattern);
353     pattern->SetNeedBorderRadius(true);
354 }
355 
SetBorderRadius(FrameNode * frameNode,const Dimension & value)356 void ImageModelNG::SetBorderRadius(FrameNode* frameNode, const Dimension& value)
357 {
358     BorderRadiusProperty borderRadius;
359     borderRadius.SetRadius(value);
360     borderRadius.multiValued = false;
361     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, BorderRadius, borderRadius, frameNode);
362     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, NeedBorderRadius, true, frameNode);
363     auto pattern = frameNode->GetPattern<ImagePattern>();
364     CHECK_NULL_VOID(pattern);
365     pattern->SetNeedBorderRadius(true);
366 }
367 
SetBorderRadius(FrameNode * frameNode,const std::optional<Dimension> & radiusTopLeft,const std::optional<Dimension> & radiusTopRight,const std::optional<Dimension> & radiusBottomLeft,const std::optional<Dimension> & radiusBottomRight)368 void ImageModelNG::SetBorderRadius(FrameNode* frameNode, const std::optional<Dimension>& radiusTopLeft,
369     const std::optional<Dimension>& radiusTopRight, const std::optional<Dimension>& radiusBottomLeft,
370     const std::optional<Dimension>& radiusBottomRight)
371 {
372     NG::BorderRadiusProperty borderRadius;
373     borderRadius.radiusTopLeft = radiusTopLeft;
374     borderRadius.radiusTopRight = radiusTopRight;
375     borderRadius.radiusBottomLeft = radiusBottomLeft;
376     borderRadius.radiusBottomRight = radiusBottomRight;
377     borderRadius.multiValued = true;
378     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, NeedBorderRadius, true, frameNode);
379     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, BorderRadius, borderRadius, frameNode);
380     auto pattern = frameNode->GetPattern<ImagePattern>();
381     CHECK_NULL_VOID(pattern);
382     pattern->SetNeedBorderRadius(true);
383 }
384 
SetBorderRadius(FrameNode * frameNode,const NG::BorderRadiusProperty & borderRadius)385 void ImageModelNG::SetBorderRadius(FrameNode* frameNode, const NG::BorderRadiusProperty& borderRadius)
386 {
387     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, NeedBorderRadius, true, frameNode);
388     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, BorderRadius, borderRadius, frameNode);
389     auto pattern = frameNode->GetPattern<ImagePattern>();
390     CHECK_NULL_VOID(pattern);
391     pattern->SetNeedBorderRadius(true);
392 }
393 
SetBackBorder()394 void ImageModelNG::SetBackBorder()
395 {
396     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, NeedBorderRadius, true);
397     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
398     CHECK_NULL_VOID(frameNode);
399     auto pattern = frameNode->GetPattern<ImagePattern>();
400     CHECK_NULL_VOID(pattern);
401     pattern->SetNeedBorderRadius(true);
402 }
403 
SetBackBorder(FrameNode * frameNode)404 void ImageModelNG::SetBackBorder(FrameNode* frameNode)
405 {
406     CHECK_NULL_VOID(frameNode);
407     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, NeedBorderRadius, true, frameNode);
408     auto pattern = frameNode->GetPattern<ImagePattern>();
409     CHECK_NULL_VOID(pattern);
410     pattern->SetNeedBorderRadius(true);
411 }
412 
ResetBackBorder(FrameNode * frameNode)413 void ImageModelNG::ResetBackBorder(FrameNode* frameNode)
414 {
415     CHECK_NULL_VOID(frameNode);
416     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, NeedBorderRadius, true, frameNode);
417     auto pattern = frameNode->GetPattern<ImagePattern>();
418     CHECK_NULL_VOID(pattern);
419     pattern->SetNeedBorderRadius(false);
420 }
421 
SetBlur(double blur)422 void ImageModelNG::SetBlur(double blur) {}
423 
SetImageFit(ImageFit value)424 void ImageModelNG::SetImageFit(ImageFit value)
425 {
426     ACE_UPDATE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageFit, value);
427     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, ImageFit, value);
428 }
429 
SetImageMatrix(const Matrix4 & value)430 void ImageModelNG::SetImageMatrix(const Matrix4& value)
431 {
432     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, ImageMatrix, value);
433 }
434 
SetMatchTextDirection(bool value)435 void ImageModelNG::SetMatchTextDirection(bool value)
436 {
437     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, MatchTextDirection, value);
438 }
439 
SetFitOriginSize(bool value)440 void ImageModelNG::SetFitOriginSize(bool value)
441 {
442     ACE_UPDATE_LAYOUT_PROPERTY(ImageLayoutProperty, FitOriginalSize, value);
443 }
444 
SetOnComplete(std::function<void (const LoadImageSuccessEvent & info)> && callback)445 void ImageModelNG::SetOnComplete(std::function<void(const LoadImageSuccessEvent& info)>&& callback)
446 {
447     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
448     CHECK_NULL_VOID(frameNode);
449     auto eventHub = frameNode->GetEventHub<ImageEventHub>();
450     CHECK_NULL_VOID(eventHub);
451     eventHub->SetOnComplete(std::move(callback));
452 }
453 
SetOnError(std::function<void (const LoadImageFailEvent & info)> && callback)454 void ImageModelNG::SetOnError(std::function<void(const LoadImageFailEvent& info)>&& callback)
455 {
456     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
457     CHECK_NULL_VOID(frameNode);
458     auto eventHub = frameNode->GetEventHub<ImageEventHub>();
459     CHECK_NULL_VOID(eventHub);
460     eventHub->SetOnError(std::move(callback));
461 }
462 
SetSvgAnimatorFinishEvent(std::function<void ()> && callback)463 void ImageModelNG::SetSvgAnimatorFinishEvent(std::function<void()>&& callback)
464 {
465     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
466     CHECK_NULL_VOID(frameNode);
467     auto eventHub = frameNode->GetEventHub<ImageEventHub>();
468     CHECK_NULL_VOID(eventHub);
469     eventHub->SetOnFinish(std::move(callback));
470 }
471 
SetImageSourceSize(const std::pair<Dimension,Dimension> & size)472 void ImageModelNG::SetImageSourceSize(const std::pair<Dimension, Dimension>& size)
473 {
474     SizeF sourceSize =
475         SizeF(static_cast<float>(size.first.ConvertToPx()), static_cast<float>(size.second.ConvertToPx()));
476     ACE_UPDATE_LAYOUT_PROPERTY(ImageLayoutProperty, SourceSize, sourceSize);
477 }
478 
SetImageFill(const Color & color)479 void ImageModelNG::SetImageFill(const Color& color)
480 {
481     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, SvgFillColor, color);
482     ACE_UPDATE_RENDER_CONTEXT(ForegroundColor, color);
483 }
484 
ResetImageFill()485 void ImageModelNG::ResetImageFill()
486 {
487     ACE_RESET_PAINT_PROPERTY_WITH_FLAG(ImageRenderProperty, SvgFillColor, PROPERTY_UPDATE_RENDER);
488     ACE_RESET_RENDER_CONTEXT(RenderContext, ForegroundColor);
489 }
490 
ResetImageFill(FrameNode * frameNode)491 void ImageModelNG::ResetImageFill(FrameNode* frameNode)
492 {
493     ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(ImageRenderProperty, SvgFillColor, PROPERTY_UPDATE_RENDER, frameNode);
494     ACE_RESET_NODE_RENDER_CONTEXT(RenderContext, ForegroundColor, frameNode);
495 }
496 
SetImageInterpolation(ImageInterpolation interpolation)497 void ImageModelNG::SetImageInterpolation(ImageInterpolation interpolation)
498 {
499     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, ImageInterpolation, interpolation);
500 }
501 
SetImageRepeat(ImageRepeat imageRepeat)502 void ImageModelNG::SetImageRepeat(ImageRepeat imageRepeat)
503 {
504     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, ImageRepeat, imageRepeat);
505 }
506 
SetImageRenderMode(ImageRenderMode imageRenderMode)507 void ImageModelNG::SetImageRenderMode(ImageRenderMode imageRenderMode)
508 {
509     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, ImageRenderMode, imageRenderMode);
510 }
511 
IsSrcSvgImage()512 bool ImageModelNG::IsSrcSvgImage()
513 {
514     return false;
515 }
516 
SetAutoResize(bool autoResize)517 void ImageModelNG::SetAutoResize(bool autoResize)
518 {
519     ACE_UPDATE_LAYOUT_PROPERTY(ImageLayoutProperty, AutoResize, autoResize);
520 }
521 
SetSyncMode(bool syncMode)522 void ImageModelNG::SetSyncMode(bool syncMode)
523 {
524     auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<ImagePattern>();
525     CHECK_NULL_VOID(pattern);
526     pattern->SetSyncLoad(syncMode);
527 }
528 
SetColorFilterMatrix(const std::vector<float> & matrix)529 void ImageModelNG::SetColorFilterMatrix(const std::vector<float>& matrix)
530 {
531     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, ColorFilter, matrix);
532     ACE_RESET_PAINT_PROPERTY(ImageRenderProperty, DrawingColorFilter);
533 }
534 
SetDrawingColorFilter(RefPtr<DrawingColorFilter> & colorFilter)535 void ImageModelNG::SetDrawingColorFilter(RefPtr<DrawingColorFilter>& colorFilter)
536 {
537     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, DrawingColorFilter, colorFilter);
538     ACE_RESET_PAINT_PROPERTY(ImageRenderProperty, ColorFilter);
539 }
540 
SetDraggable(bool draggable)541 void ImageModelNG::SetDraggable(bool draggable)
542 {
543     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
544     CHECK_NULL_VOID(frameNode);
545     auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
546     CHECK_NULL_VOID(gestureHub);
547     if (draggable) {
548         if (!frameNode->IsDraggable()) {
549             gestureHub->InitDragDropEvent();
550         }
551     } else {
552         gestureHub->RemoveDragEvent();
553     }
554     CHECK_NULL_VOID(frameNode);
555     frameNode->SetCustomerDraggable(draggable);
556 }
557 
SetOnDragStart(OnDragStartFunc && onDragStart)558 void ImageModelNG::SetOnDragStart(OnDragStartFunc&& onDragStart)
559 {
560 #ifndef ACE_UNITTEST
561     auto dragStart = [dragStartFunc = std::move(onDragStart)](
562                          const RefPtr<OHOS::Ace::DragEvent>& event, const std::string& extraParams) -> DragDropInfo {
563         auto dragInfo = dragStartFunc(event, extraParams);
564         DragDropInfo info;
565         info.extraInfo = dragInfo.extraInfo;
566         info.pixelMap = dragInfo.pixelMap;
567         info.customNode = AceType::DynamicCast<UINode>(dragInfo.node);
568         return info;
569     };
570     ViewAbstract::SetOnDragStart(std::move(dragStart));
571 #endif
572 }
573 
SetOnDragEnter(OnDragDropFunc && onDragEnter)574 void ImageModelNG::SetOnDragEnter(OnDragDropFunc&& onDragEnter) {}
575 
SetOnDragLeave(OnDragDropFunc && onDragLeave)576 void ImageModelNG::SetOnDragLeave(OnDragDropFunc&& onDragLeave) {}
577 
SetOnDragMove(OnDragDropFunc && onDragMove)578 void ImageModelNG::SetOnDragMove(OnDragDropFunc&& onDragMove) {}
579 
SetOnDrop(OnDragDropFunc && onDrop)580 void ImageModelNG::SetOnDrop(OnDragDropFunc&& onDrop) {}
581 
SetCopyOption(const CopyOptions & copyOption)582 void ImageModelNG::SetCopyOption(const CopyOptions& copyOption)
583 {
584     auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<ImagePattern>();
585     CHECK_NULL_VOID(pattern);
586     pattern->SetCopyOption(copyOption);
587 }
588 
UpdateDragItemInfo(DragItemInfo & itemInfo)589 bool ImageModelNG::UpdateDragItemInfo(DragItemInfo& itemInfo)
590 {
591     return false;
592 }
593 
InitImage(FrameNode * frameNode,std::string & src)594 void ImageModelNG::InitImage(FrameNode* frameNode, std::string& src)
595 {
596     std::string bundleName;
597     std::string moduleName;
598     RefPtr<OHOS::Ace::PixelMap> pixMapPtr;
599     auto srcInfo = CreateSourceInfo(src, pixMapPtr, bundleName, moduleName);
600     srcInfo.SetIsUriPureNumber(false);
601     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageSourceInfo, srcInfo, frameNode);
602 }
603 
SetPixelMap(FrameNode * frameNode,void * drawableDescriptor)604 void ImageModelNG::SetPixelMap(FrameNode* frameNode, void* drawableDescriptor)
605 {
606 #ifndef ACE_UNITTEST
607     CHECK_NULL_VOID(drawableDescriptor);
608     RefPtr<PixelMap> pixelMapPtr = PixelMap::GetFromDrawable(drawableDescriptor);
609     auto srcInfo = CreateSourceInfo("", pixelMapPtr, "", "");
610     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageSourceInfo, srcInfo, frameNode);
611 #endif
612 }
613 
SetPixelMapArray(FrameNode * frameNode,void * animatedDrawableDescriptor)614 void ImageModelNG::SetPixelMapArray(FrameNode* frameNode, void* animatedDrawableDescriptor)
615 {
616 #ifndef ACE_UNITTEST
617     CHECK_NULL_VOID(animatedDrawableDescriptor);
618     std::vector<RefPtr<PixelMap>> pixelMaps;
619     int32_t duration = -1;
620     int32_t iterations = 1;
621     if (!PixelMap::GetPxielMapListFromAnimatedDrawable(animatedDrawableDescriptor, pixelMaps, duration, iterations)) {
622         return;
623     }
624     std::vector<ImageProperties> images;
625     for (int32_t i = 0; i < static_cast<int32_t>(pixelMaps.size()); i++) {
626         ImageProperties image;
627         image.pixelMap = pixelMaps[i];
628         images.push_back(image);
629     }
630 
631     if (frameNode->GetChildren().empty()) {
632         auto imageNode = FrameNode::CreateFrameNode(V2::IMAGE_ETS_TAG, -1, AceType::MakeRefPtr<ImagePattern>());
633         CHECK_NULL_VOID(imageNode);
634         auto imageLayoutProperty = AceType::DynamicCast<ImageLayoutProperty>(imageNode->GetLayoutProperty());
635         CHECK_NULL_VOID(imageLayoutProperty);
636         imageLayoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT);
637         frameNode->GetLayoutProperty()->UpdateAlignment(Alignment::TOP_LEFT);
638         frameNode->AddChild(imageNode);
639     }
640 
641     auto pattern = AceType::DynamicCast<ImagePattern>(frameNode->GetPattern());
642     CHECK_NULL_VOID(pattern);
643 
644     pattern->StopAnimation();
645     pattern->SetImageType(ImageType::ANIMATED_DRAWABLE);
646     pattern->SetImages(std::move(images));
647     pattern->SetDuration(duration);
648     pattern->SetIteration(iterations);
649     pattern->StartAnimation();
650 #endif
651 }
652 
SetResource(FrameNode * frameNode,void * resource)653 void ImageModelNG::SetResource(FrameNode* frameNode, void* resource)
654 {
655     auto res = reinterpret_cast<ArkUI_Resource*>(resource);
656     CHECK_NULL_VOID(res);
657     RefPtr<PixelMap> pixMapPtr;
658     auto srcInfo = CreateSourceInfo(res->src, pixMapPtr, res->bundleName, res->moduleName);
659     srcInfo.SetIsUriPureNumber(res->resId == -1);
660     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageSourceInfo, srcInfo, frameNode);
661 }
662 
SetDrawingColorFilter(FrameNode * frameNode,RefPtr<DrawingColorFilter> & colorFilter)663 void ImageModelNG::SetDrawingColorFilter(FrameNode* frameNode, RefPtr<DrawingColorFilter>& colorFilter)
664 {
665     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, DrawingColorFilter, colorFilter, frameNode);
666     ACE_RESET_NODE_PAINT_PROPERTY(ImageRenderProperty, ColorFilter, frameNode);
667 }
668 
SetCopyOption(FrameNode * frameNode,CopyOptions copyOption)669 void ImageModelNG::SetCopyOption(FrameNode* frameNode, CopyOptions copyOption)
670 {
671     auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<ImagePattern>(frameNode);
672     CHECK_NULL_VOID(pattern);
673     pattern->SetCopyOption(copyOption);
674 }
675 
SetAutoResize(FrameNode * frameNode,bool autoResize)676 void ImageModelNG::SetAutoResize(FrameNode* frameNode, bool autoResize)
677 {
678     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, AutoResize, autoResize, frameNode);
679 }
680 
ResetAutoResize(FrameNode * frameNode)681 void ImageModelNG::ResetAutoResize(FrameNode* frameNode)
682 {
683     CHECK_NULL_VOID(frameNode);
684     auto imagePattern = frameNode->GetPattern<ImagePattern>();
685     CHECK_NULL_VOID(imagePattern);
686     auto defaultAutoResize = imagePattern->GetDefaultAutoResize();
687     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, AutoResize, defaultAutoResize, frameNode);
688 }
689 
SetResizableSlice(const ImageResizableSlice & slice)690 void ImageModelNG::SetResizableSlice(const ImageResizableSlice& slice)
691 {
692     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, ImageResizableSlice, slice);
693 }
694 
SetResizableSlice(FrameNode * frameNode,const ImageResizableSlice & slice)695 void ImageModelNG::SetResizableSlice(FrameNode* frameNode, const ImageResizableSlice& slice)
696 {
697     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, ImageResizableSlice, slice, frameNode);
698 }
699 
SetResizableLattice(const RefPtr<DrawingLattice> & lattice)700 void ImageModelNG::SetResizableLattice(const RefPtr<DrawingLattice>& lattice)
701 {
702     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, ImageResizableLattice, lattice);
703 }
704 
SetResizableLattice(FrameNode * frameNode,const RefPtr<DrawingLattice> & lattice)705 void ImageModelNG::SetResizableLattice(FrameNode* frameNode, const RefPtr<DrawingLattice>& lattice)
706 {
707     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, ImageResizableLattice, lattice, frameNode);
708 }
709 
ResetResizableLattice()710 void ImageModelNG::ResetResizableLattice()
711 {
712     ACE_UPDATE_PAINT_PROPERTY(ImageRenderProperty, ImageResizableLattice, nullptr);
713 }
714 
ResetResizableLattice(FrameNode * frameNode)715 void ImageModelNG::ResetResizableLattice(FrameNode* frameNode)
716 {
717     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, ImageResizableLattice, nullptr, frameNode);
718 }
719 
SetImageRepeat(FrameNode * frameNode,ImageRepeat imageRepeat)720 void ImageModelNG::SetImageRepeat(FrameNode* frameNode, ImageRepeat imageRepeat)
721 {
722     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, ImageRepeat, imageRepeat, frameNode);
723 }
724 
SetImageRenderMode(FrameNode * frameNode,ImageRenderMode imageRenderMode)725 void ImageModelNG::SetImageRenderMode(FrameNode* frameNode, ImageRenderMode imageRenderMode)
726 {
727     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, ImageRenderMode, imageRenderMode, frameNode);
728 }
729 
SetImageMatrix(FrameNode * frameNode,const Matrix4 & value)730 void ImageModelNG::SetImageMatrix(FrameNode* frameNode, const Matrix4& value)
731 {
732     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, ImageMatrix, value, frameNode);
733 }
734 
SetImageFit(FrameNode * frameNode,ImageFit value)735 void ImageModelNG::SetImageFit(FrameNode* frameNode, ImageFit value)
736 {
737     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageFit, value, frameNode);
738     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, ImageFit, value, frameNode);
739 }
740 
SetFitOriginSize(FrameNode * frameNode,bool value)741 void ImageModelNG::SetFitOriginSize(FrameNode* frameNode, bool value)
742 {
743     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, FitOriginalSize, value, frameNode);
744 }
745 
SetSyncMode(FrameNode * frameNode,bool syncMode)746 void ImageModelNG::SetSyncMode(FrameNode* frameNode, bool syncMode)
747 {
748     auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<ImagePattern>(frameNode);
749     CHECK_NULL_VOID(pattern);
750     pattern->SetSyncLoad(syncMode);
751 }
752 
SetImageSourceSize(FrameNode * frameNode,const std::pair<Dimension,Dimension> & size)753 void ImageModelNG::SetImageSourceSize(FrameNode* frameNode, const std::pair<Dimension, Dimension>& size)
754 {
755     SizeF sourceSize =
756         SizeF(static_cast<float>(size.first.ConvertToPx()), static_cast<float>(size.second.ConvertToPx()));
757     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, SourceSize, sourceSize, frameNode);
758 }
759 
SetMatchTextDirection(FrameNode * frameNode,bool value)760 void ImageModelNG::SetMatchTextDirection(FrameNode* frameNode, bool value)
761 {
762     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, MatchTextDirection, value, frameNode);
763 }
764 
SetImageFill(FrameNode * frameNode,const Color & color)765 void ImageModelNG::SetImageFill(FrameNode* frameNode, const Color& color)
766 {
767     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, SvgFillColor, color, frameNode);
768     ACE_UPDATE_NODE_RENDER_CONTEXT(ForegroundColor, color, frameNode);
769 }
770 
SetAlt(FrameNode * frameNode,const ImageSourceInfo & src)771 void ImageModelNG::SetAlt(FrameNode* frameNode, const ImageSourceInfo& src)
772 {
773     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, Alt, src, frameNode);
774 }
775 
SetAltResource(FrameNode * frameNode,void * resource)776 void ImageModelNG::SetAltResource(FrameNode* frameNode, void* resource)
777 {
778     CHECK_NULL_VOID(frameNode);
779     auto res = reinterpret_cast<ArkUI_Resource*>(resource);
780     CHECK_NULL_VOID(res);
781     RefPtr<PixelMap> pixMapPtr = nullptr;
782     auto srcInfo = CreateSourceInfo(res->src, pixMapPtr, res->bundleName, res->moduleName);
783     srcInfo.SetIsUriPureNumber(res->resId == -1);
784     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, Alt, srcInfo, frameNode);
785 }
786 
SetAltPixelMap(FrameNode * frameNode,void * pixelMap)787 void ImageModelNG::SetAltPixelMap(FrameNode* frameNode, void* pixelMap)
788 {
789     CHECK_NULL_VOID(frameNode);
790     CHECK_NULL_VOID(pixelMap);
791 #ifndef ACE_UNITTEST
792     RefPtr<PixelMap> pixelMapPtr = PixelMap::GetFromDrawable(pixelMap);
793     auto srcInfo = CreateSourceInfo("", pixelMapPtr, "", "");
794     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, Alt, srcInfo, frameNode);
795 #endif
796 }
797 
SetImageInterpolation(FrameNode * frameNode,ImageInterpolation interpolation)798 void ImageModelNG::SetImageInterpolation(FrameNode* frameNode, ImageInterpolation interpolation)
799 {
800     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, ImageInterpolation, interpolation, frameNode);
801 }
802 
ResetImageInterpolation(FrameNode * frameNode)803 void ImageModelNG::ResetImageInterpolation(FrameNode* frameNode)
804 {
805     CHECK_NULL_VOID(frameNode);
806     auto imagePattern = frameNode->GetPattern<ImagePattern>();
807     CHECK_NULL_VOID(imagePattern);
808     auto defaultInterpolation = imagePattern->GetDefaultInterpolation();
809     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, ImageInterpolation, defaultInterpolation, frameNode);
810 }
811 
SetColorFilterMatrix(FrameNode * frameNode,const std::vector<float> & matrix)812 void ImageModelNG::SetColorFilterMatrix(FrameNode* frameNode, const std::vector<float>& matrix)
813 {
814     ACE_UPDATE_NODE_PAINT_PROPERTY(ImageRenderProperty, ColorFilter, matrix, frameNode);
815     ACE_RESET_NODE_PAINT_PROPERTY(ImageRenderProperty, DrawingColorFilter, frameNode);
816 }
817 
SetDraggable(FrameNode * frameNode,bool draggable)818 void ImageModelNG::SetDraggable(FrameNode* frameNode, bool draggable)
819 {
820     auto gestureHub = frameNode->GetOrCreateGestureEventHub();
821     CHECK_NULL_VOID(gestureHub);
822     if (draggable) {
823         if (!frameNode->IsDraggable()) {
824             gestureHub->InitDragDropEvent();
825         }
826     } else {
827         gestureHub->RemoveDragEvent();
828     }
829     frameNode->SetCustomerDraggable(draggable);
830 }
831 
EnableAnalyzer(bool isEnableAnalyzer)832 void ImageModelNG::EnableAnalyzer(bool isEnableAnalyzer)
833 {
834     auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<ImagePattern>();
835     CHECK_NULL_VOID(pattern);
836     pattern->EnableAnalyzer(isEnableAnalyzer);
837 }
838 
SetImageAnalyzerConfig(const ImageAnalyzerConfig & config)839 void ImageModelNG::SetImageAnalyzerConfig(const ImageAnalyzerConfig& config)
840 {
841     auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<ImagePattern>();
842     CHECK_NULL_VOID(pattern);
843     pattern->SetImageAnalyzerConfig(config);
844 }
845 
SetImageAnalyzerConfig(void * config)846 void ImageModelNG::SetImageAnalyzerConfig(void* config)
847 {
848     auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<ImagePattern>();
849     CHECK_NULL_VOID(pattern);
850     pattern->SetImageAnalyzerConfig(config);
851 }
852 
SetImageAIOptions(void * options)853 void ImageModelNG::SetImageAIOptions(void* options)
854 {
855     auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<ImagePattern>();
856     CHECK_NULL_VOID(pattern);
857     pattern->SetImageAIOptions(options);
858 }
859 
IsSrcSvgImage(FrameNode * frameNode)860 bool ImageModelNG::IsSrcSvgImage(FrameNode* frameNode)
861 {
862     return false;
863 }
864 
SetOnComplete(FrameNode * frameNode,std::function<void (const LoadImageSuccessEvent & info)> && callback)865 void ImageModelNG::SetOnComplete(
866     FrameNode* frameNode, std::function<void(const LoadImageSuccessEvent& info)>&& callback)
867 {
868     CHECK_NULL_VOID(frameNode);
869     auto eventHub = frameNode->GetEventHub<ImageEventHub>();
870     CHECK_NULL_VOID(eventHub);
871     eventHub->SetOnComplete(std::move(callback));
872 }
873 
SetOnError(FrameNode * frameNode,std::function<void (const LoadImageFailEvent & info)> && callback)874 void ImageModelNG::SetOnError(FrameNode* frameNode, std::function<void(const LoadImageFailEvent& info)>&& callback)
875 {
876     CHECK_NULL_VOID(frameNode);
877     auto eventHub = frameNode->GetEventHub<ImageEventHub>();
878     CHECK_NULL_VOID(eventHub);
879     eventHub->SetOnError(std::move(callback));
880 }
881 
SetOnSvgPlayFinish(FrameNode * frameNode,std::function<void ()> && callback)882 void ImageModelNG::SetOnSvgPlayFinish(FrameNode* frameNode, std::function<void()>&& callback)
883 {
884     CHECK_NULL_VOID(frameNode);
885     auto eventHub = frameNode->GetEventHub<ImageEventHub>();
886     CHECK_NULL_VOID(eventHub);
887     eventHub->SetOnFinish(std::move(callback));
888 }
889 
SetOnDownloadProgress(FrameNode * frameNode,std::function<void (const uint32_t & dlNow,const uint32_t & dlTotal)> && callback)890 void ImageModelNG::SetOnDownloadProgress(
891     FrameNode* frameNode, std::function<void(const uint32_t& dlNow, const uint32_t& dlTotal)>&& callback)
892 {
893     CHECK_NULL_VOID(frameNode);
894     auto imagePattern = frameNode->GetPattern<ImagePattern>();
895     CHECK_NULL_VOID(imagePattern);
896     imagePattern->SetOnProgressCallback(std::move(callback));
897 }
898 
GetSrc(FrameNode * frameNode)899 ImageSourceInfo ImageModelNG::GetSrc(FrameNode* frameNode)
900 {
901     ImageSourceInfo defaultImageSourceInfo;
902     CHECK_NULL_RETURN(frameNode, defaultImageSourceInfo);
903     auto layoutProperty = frameNode->GetLayoutProperty<ImageLayoutProperty>();
904     CHECK_NULL_RETURN(layoutProperty, defaultImageSourceInfo);
905     return layoutProperty->GetImageSourceInfo().value_or(defaultImageSourceInfo);
906 }
907 
GetObjectFit(FrameNode * frameNode)908 ImageFit ImageModelNG::GetObjectFit(FrameNode* frameNode)
909 {
910     CHECK_NULL_RETURN(frameNode, ImageFit::COVER);
911     auto layoutProperty = frameNode->GetLayoutProperty<ImageLayoutProperty>();
912     CHECK_NULL_RETURN(layoutProperty, ImageFit::COVER);
913     return layoutProperty->GetImageFit().value_or(ImageFit::COVER);
914 }
915 
GetInterpolation(FrameNode * frameNode)916 ImageInterpolation ImageModelNG::GetInterpolation(FrameNode* frameNode)
917 {
918     CHECK_NULL_RETURN(frameNode, ImageInterpolation::NONE);
919     auto imagePattern = frameNode->GetPattern<ImagePattern>();
920     CHECK_NULL_RETURN(imagePattern, ImageInterpolation::NONE);
921     auto defaultInterpolation = imagePattern->GetDefaultInterpolation();
922     auto paintProperty = frameNode->GetPaintProperty<ImageRenderProperty>();
923     CHECK_NULL_RETURN(paintProperty, defaultInterpolation);
924     CHECK_NULL_RETURN(paintProperty->GetImagePaintStyle(), defaultInterpolation);
925     return paintProperty->GetImagePaintStyle()->GetImageInterpolation().value_or(defaultInterpolation);
926 }
927 
GetObjectRepeat(FrameNode * frameNode)928 ImageRepeat ImageModelNG::GetObjectRepeat(FrameNode* frameNode)
929 {
930     CHECK_NULL_RETURN(frameNode, ImageRepeat::NO_REPEAT);
931     auto paintProperty = frameNode->GetPaintProperty<ImageRenderProperty>();
932     CHECK_NULL_RETURN(paintProperty, ImageRepeat::NO_REPEAT);
933     CHECK_NULL_RETURN(paintProperty->GetImagePaintStyle(), ImageRepeat::NO_REPEAT);
934     return paintProperty->GetImagePaintStyle()->GetImageRepeat().value_or(ImageRepeat::NO_REPEAT);
935 }
936 
GetColorFilter(FrameNode * frameNode)937 std::vector<float> ImageModelNG::GetColorFilter(FrameNode* frameNode)
938 {
939     CHECK_NULL_RETURN(frameNode, DEFAULT_COLOR_FILTER);
940     auto paintProperty = frameNode->GetPaintProperty<ImageRenderProperty>();
941     CHECK_NULL_RETURN(paintProperty, DEFAULT_COLOR_FILTER);
942     CHECK_NULL_RETURN(paintProperty->GetImagePaintStyle(), DEFAULT_COLOR_FILTER);
943     return paintProperty->GetImagePaintStyle()->GetColorFilter().value_or(DEFAULT_COLOR_FILTER);
944 }
945 
GetDrawingColorFilter(FrameNode * frameNode)946 RefPtr<DrawingColorFilter> ImageModelNG::GetDrawingColorFilter(FrameNode* frameNode)
947 {
948     CHECK_NULL_RETURN(frameNode, nullptr);
949     auto paintProperty = frameNode->GetPaintProperty<ImageRenderProperty>();
950     CHECK_NULL_RETURN(paintProperty, nullptr);
951     CHECK_NULL_RETURN(paintProperty->GetImagePaintStyle(), nullptr);
952     return paintProperty->GetImagePaintStyle()->GetDrawingColorFilter().value_or(nullptr);
953 }
954 
GetAutoResize(FrameNode * frameNode)955 bool ImageModelNG::GetAutoResize(FrameNode* frameNode)
956 {
957     CHECK_NULL_RETURN(frameNode, true);
958     auto imagePattern = frameNode->GetPattern<ImagePattern>();
959     CHECK_NULL_RETURN(imagePattern, true);
960     auto defaultAutoResize = imagePattern->GetDefaultAutoResize();
961     auto layoutProperty = frameNode->GetLayoutProperty<ImageLayoutProperty>();
962     CHECK_NULL_RETURN(layoutProperty, defaultAutoResize);
963     CHECK_NULL_RETURN(layoutProperty->GetImageSizeStyle(), defaultAutoResize);
964     return layoutProperty->GetImageSizeStyle()->GetAutoResize().value_or(defaultAutoResize);
965 }
966 
GetAlt(FrameNode * frameNode)967 ImageSourceInfo ImageModelNG::GetAlt(FrameNode* frameNode)
968 {
969     ImageSourceInfo defaultImageSourceInfo;
970     CHECK_NULL_RETURN(frameNode, defaultImageSourceInfo);
971     auto layoutProperty = frameNode->GetLayoutProperty<ImageLayoutProperty>();
972     CHECK_NULL_RETURN(layoutProperty, defaultImageSourceInfo);
973     return layoutProperty->GetAlt().value_or(defaultImageSourceInfo);
974 }
975 
GetFitOriginalSize(FrameNode * frameNode)976 bool ImageModelNG::GetFitOriginalSize(FrameNode* frameNode)
977 {
978     CHECK_NULL_RETURN(frameNode, false);
979     auto layoutProperty = frameNode->GetLayoutProperty<ImageLayoutProperty>();
980     CHECK_NULL_RETURN(layoutProperty, false);
981     return layoutProperty->GetImageSizeStyle()->GetFitOriginalSize().value_or(false);
982 }
983 
GetFillColor(FrameNode * frameNode)984 uint32_t ImageModelNG::GetFillColor(FrameNode* frameNode)
985 {
986     uint32_t errorCode = -1;
987     CHECK_NULL_RETURN(frameNode, errorCode);
988     auto paintProperty = frameNode->GetPaintProperty<ImageRenderProperty>();
989     CHECK_NULL_RETURN(paintProperty, errorCode);
990     CHECK_NULL_RETURN(paintProperty->GetImagePaintStyle(), errorCode);
991     Color color = paintProperty->GetImagePaintStyle()->GetSvgFillColor().value_or(Color());
992     return color.GetValue();
993 }
994 
GetDraggable(FrameNode * frameNode)995 bool ImageModelNG::GetDraggable(FrameNode* frameNode)
996 {
997     CHECK_NULL_RETURN(frameNode, false);
998     return frameNode->IsDraggable();
999 }
1000 
GetImageRenderMode(FrameNode * frameNode)1001 ImageRenderMode ImageModelNG::GetImageRenderMode(FrameNode* frameNode)
1002 {
1003     CHECK_NULL_RETURN(frameNode, ImageRenderMode::ORIGINAL);
1004     auto paintProperty = frameNode->GetPaintProperty<ImageRenderProperty>();
1005     CHECK_NULL_RETURN(paintProperty, ImageRenderMode::ORIGINAL);
1006     CHECK_NULL_RETURN(paintProperty->GetImagePaintStyle(), ImageRenderMode::ORIGINAL);
1007     return paintProperty->GetImagePaintStyle()->GetImageRenderMode().value_or(ImageRenderMode::ORIGINAL);
1008 }
1009 
GetIsAnimation()1010 bool ImageModelNG::GetIsAnimation()
1011 {
1012     auto pattern = GetImagePattern();
1013     CHECK_NULL_RETURN(pattern, false);
1014     return pattern->GetIsAnimation();
1015 }
1016 
GetImagePattern()1017 ImagePattern* ImageModelNG::GetImagePattern()
1018 {
1019     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1020     CHECK_NULL_RETURN(frameNode, nullptr);
1021     return frameNode->GetPatternPtr<ImagePattern>();
1022 }
1023 
GetResizableSlice(FrameNode * frameNode)1024 ImageResizableSlice ImageModelNG::GetResizableSlice(FrameNode* frameNode)
1025 {
1026     ImageResizableSlice resizable;
1027     CHECK_NULL_RETURN(frameNode, resizable);
1028     auto renderProperty = frameNode->GetPaintProperty<ImageRenderProperty>();
1029     CHECK_NULL_RETURN(renderProperty, resizable);
1030     return renderProperty->GetImageResizableSlice().value_or(resizable);
1031 }
1032 
EnableAnalyzer(FrameNode * frameNode,bool isEnableAnalyzer)1033 void ImageModelNG::EnableAnalyzer(FrameNode* frameNode, bool isEnableAnalyzer)
1034 {
1035     CHECK_NULL_VOID(frameNode);
1036     auto imagePattern = frameNode->GetPattern<ImagePattern>();
1037     CHECK_NULL_VOID(imagePattern);
1038     imagePattern->EnableAnalyzer(isEnableAnalyzer);
1039 }
1040 
SetImageAnalyzerConfig(FrameNode * frameNode,void * config)1041 void ImageModelNG::SetImageAnalyzerConfig(FrameNode* frameNode, void* config)
1042 {
1043     CHECK_NULL_VOID(frameNode);
1044     auto imagePattern = frameNode->GetPattern<ImagePattern>();
1045     CHECK_NULL_VOID(imagePattern);
1046     imagePattern->SetImageAnalyzerConfig(config);
1047 }
1048 
ResetImageSrc(FrameNode * frameNode)1049 void ImageModelNG::ResetImageSrc(FrameNode* frameNode)
1050 {
1051     CHECK_NULL_VOID(frameNode);
1052     ImageSourceInfo sourceInfo("");
1053     sourceInfo.SetIsFromReset(true);
1054     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageSourceInfo, sourceInfo, frameNode);
1055     auto pattern = frameNode->GetPattern<ImagePattern>();
1056     CHECK_NULL_VOID(pattern);
1057     pattern->ResetImage();
1058     if (pattern->GetImageType() == ImageType::ANIMATED_DRAWABLE) {
1059         if (pattern->GetHasSizeChanged()) {
1060             pattern->ResetPictureSize();
1061         }
1062         pattern->StopAnimation();
1063         pattern->ResetImages();
1064         if (!frameNode->GetChildren().empty()) {
1065             auto imageFrameNode = AceType::DynamicCast<FrameNode>(frameNode->GetChildren().front());
1066             ACE_RESET_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageSourceInfo, imageFrameNode);
1067             frameNode->RemoveChild(imageFrameNode);
1068         }
1069         pattern->SetImageType(ImageType::BASE);
1070     }
1071 }
1072 
ResetImageAlt(FrameNode * frameNode)1073 void ImageModelNG::ResetImageAlt(FrameNode* frameNode)
1074 {
1075     CHECK_NULL_VOID(frameNode);
1076     ImageSourceInfo sourceInfo("");
1077     sourceInfo.SetIsFromReset(true);
1078     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, Alt, sourceInfo, frameNode);
1079     auto pattern = frameNode->GetPattern<ImagePattern>();
1080     CHECK_NULL_VOID(pattern);
1081     pattern->ResetAltImage();
1082 }
1083 
SetOrientation(ImageRotateOrientation orientation)1084 void ImageModelNG::SetOrientation(ImageRotateOrientation orientation)
1085 {
1086     ACE_UPDATE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageRotateOrientation, orientation);
1087     auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<ImagePattern>();
1088     CHECK_NULL_VOID(pattern);
1089     pattern->SetOrientation(orientation);
1090 }
1091 
SetOrientation(FrameNode * frameNode,ImageRotateOrientation orientation)1092 void ImageModelNG::SetOrientation(FrameNode* frameNode, ImageRotateOrientation orientation)
1093 {
1094     ACE_UPDATE_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageRotateOrientation, orientation, frameNode);
1095     auto pattern = frameNode->GetPattern<ImagePattern>();
1096     CHECK_NULL_VOID(pattern);
1097     pattern->SetOrientation(orientation);
1098 }
1099 } // namespace OHOS::Ace::NG
1100 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_IMAGE_IMAGE_MODEL_NG_CPP
1101