• 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_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_IMAGE_IMAGE_MODEL_NG_H
18 
19 #include "core/components/common/layout/constants.h"
20 #include "core/components/declaration/image/image_animator_declaration.h"
21 #include "core/components_ng/base/frame_node.h"
22 #include "core/components_ng/pattern/image/image_model.h"
23 #include "core/components_ng/pattern/image/image_pattern.h"
24 
25 namespace OHOS::Ace::NG {
26 // ImageModel is essentially the same class as ImageView
27 // there should be only one left in the final implementation
28 
29 class ACE_EXPORT ImageModelNG : public OHOS::Ace::ImageModel {
30 public:
31     void Create(const ImageInfoConfig& imageInfoConfig, RefPtr<PixelMap>& pixMap) override;
32     void CreateWithResourceObj(ImageResourceType resourceType, const RefPtr<ResourceObject>& resObject) override;
33     void ResetImage() override;
34     void CreateAnimation(const std::vector<ImageProperties>& imageList, int32_t duration, int32_t iteration) override;
35     bool GetIsAnimation() override;
36     void SetAlt(const ImageSourceInfo& src) override;
37     void SetBorder(const Border& border) override;
38     void SetBackBorder() override;
39     void SetBorderRadius(const Dimension& value) override;
40     void SetBorderRadius(const std::optional<Dimension>& radiusTopLeft, const std::optional<Dimension>& radiusTopRight,
41         const std::optional<Dimension>& radiusBottomLeft, const std::optional<Dimension>& radiusBottomRight) override;
42     void SetBorderRadius(const NG::BorderRadiusProperty& borderRadius) override;
43     void SetBlur(double blur) override;
44     void SetImageFit(ImageFit value) override;
45     void SetImageMatrix(const Matrix4& value) override;
46     void SetMatchTextDirection(bool value) override;
47     void SetFitOriginSize(bool value) override;
48     void SetOnComplete(std::function<void(const LoadImageSuccessEvent& info)>&& callback) override;
49     void SetOnError(std::function<void(const LoadImageFailEvent& info)>&& callback) override;
50     void SetSvgAnimatorFinishEvent(std::function<void()>&& callback) override;
51     void SetImageSourceSize(const std::pair<Dimension, Dimension>& size) override;
52     void SetImageFill(const Color& color) override;
53     void ResetImageFill() override;
54     void SetImageInterpolation(ImageInterpolation interpolation) override;
55     void SetImageRepeat(ImageRepeat imageRepeat) override;
56     void SetImageRenderMode(ImageRenderMode imageRenderMode) override;
57     bool IsSrcSvgImage() override;
58     void SetAutoResize(bool autoResize) override;
59     void SetSyncMode(bool syncMode) override;
60     void SetColorFilterMatrix(const std::vector<float>& matrix) override;
61     void SetDrawingColorFilter(RefPtr<DrawingColorFilter>& colorFilter) override;
62     void SetDraggable(bool draggable) override;
63     void SetOnDragStart(OnDragStartFunc&& onDragStart) override;
64     void SetOnDragEnter(OnDragDropFunc&& onDragEnter) override;
65     void SetOnDragLeave(OnDragDropFunc&& onDragLeave) override;
66     void SetOnDragMove(OnDragDropFunc&& onDragMove) override;
67     void SetOnDrop(OnDragDropFunc&& onDrop) override;
68     void SetCopyOption(const CopyOptions& copyOption) override;
69     void SetSmoothEdge(float value) override;
70     void SetDynamicRangeMode(DynamicRangeMode dynamicRangeMode) override;
71     void SetHdrBrightness(float hdrBrightness) override;
72     void SetEnhancedImageQuality(AIImageQuality imageQuality) override;
73     void SetOrientation(ImageRotateOrientation orientation) override;
74     bool UpdateDragItemInfo(DragItemInfo& itemInfo) override;
75     void EnableAnalyzer(bool isEnableAnalyzer) override;
76     void SetImageAnalyzerConfig(const ImageAnalyzerConfig& config) override;
77     void SetImageAnalyzerConfig(void* config) override;
78     void SetImageAIOptions(void* options) override;
79     void SetResizableSlice(ImageResizableSlice& slice) override;
80     void SetResizableLattice(const RefPtr<DrawingLattice>& lattice) override;
81     void ResetResizableLattice() override;
82     void SetImageFillSetByUser(bool value) override;
83     static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId, const std::string& src, RefPtr<PixelMap>& pixMap,
84         const std::string& bundleName, const std::string& moduleName, bool isUriPureNumber = false);
85     static void InitImage(FrameNode* frameNode, std::string& src);
86     static void ResetImage(FrameNode* frameNode);
87     static void SetInitialSrc(FrameNode* frameNode, const std::string& src, const std::string& bundleName,
88         const std::string& moduleName, bool isUriPureNumber = false);
89     static void SetInitialPixelMap(FrameNode* frameNode, RefPtr<PixelMap>& pixMap);
90     static void SetSmoothEdge(FrameNode* frameNode, float value);
91     static void SetCopyOption(FrameNode* frameNode, CopyOptions copyOption);
92     static void SetAutoResize(FrameNode* frameNode, bool autoResize);
93     static void ResetAutoResize(FrameNode* frameNode);
94     static void SetImageRepeat(FrameNode* frameNode, ImageRepeat imageRepeat);
95     static void SetImageRenderMode(FrameNode* frameNode, ImageRenderMode imageRenderMode);
96     static void SetOrientation(FrameNode* frameNode, ImageRotateOrientation orientation);
97     static void SetSyncMode(FrameNode* frameNode, bool syncMode);
98     static void SetImageMatrix(FrameNode* frameNode, const Matrix4& value);
99     static void SetImageFit(FrameNode* frameNode, ImageFit value);
100     static void SetDrawingColorFilter(FrameNode* frameNode, RefPtr<DrawingColorFilter>& colorFilter);
101     static void SetFitOriginSize(FrameNode* framNode, bool value);
102     static void SetImageSourceSize(FrameNode* frameNode, const std::pair<Dimension, Dimension>& size);
103     static void SetMatchTextDirection(FrameNode* frameNode, bool value);
104     static void SetImageFill(FrameNode* frameNode, const Color& color);
105     static void ResetImageFill(FrameNode* frameNode);
106     static void SetAlt(FrameNode* frameNode, const ImageSourceInfo& src);
107     static void SetImageInterpolation(FrameNode* frameNode, ImageInterpolation interpolation);
108     static void ResetImageInterpolation(FrameNode* frameNode);
109     static void SetColorFilterMatrix(FrameNode* frameNode, const std::vector<float>& matrix);
110     static void SetDraggable(FrameNode* frameNode, bool draggable);
111     static void SetBackBorder(FrameNode* frameNode);
112     static void SetBorderRadius(FrameNode* frameNode, const Dimension& value);
113     static void SetBorderRadius(FrameNode* frameNode, const std::optional<Dimension>& radiusTopLeft,
114         const std::optional<Dimension>& radiusTopRight, const std::optional<Dimension>& radiusBottomLeft,
115         const std::optional<Dimension>& radiusBottomRight);
116     static void SetBorderRadius(FrameNode* frameNode, const NG::BorderRadiusProperty& borderRadius);
117     static void ResetBackBorder(FrameNode* frameNode);
118     static bool IsSrcSvgImage(FrameNode* frameNode);
119     static void SetOnComplete(FrameNode* frameNode, std::function<void(const LoadImageSuccessEvent& info)>&& callback);
120     static void SetOnError(FrameNode* frameNode, std::function<void(const LoadImageFailEvent& info)>&& callback);
121     static void SetOnSvgPlayFinish(FrameNode* frameNode, std::function<void()>&& callback);
122     static void SetOnDownloadProgress(
123         FrameNode* frameNode, std::function<void(const uint32_t& dlNow, const uint32_t& dlTotal)>&& callback);
124     static ImageSourceInfo GetSrc(FrameNode* frameNode);
125     static ImageFit GetObjectFit(FrameNode* frameNode);
126     static ImageRotateOrientation GetOrientation(FrameNode* frameNode);
127     static std::pair<CalcDimension, CalcDimension> GetImageSourceSize(FrameNode* frameNode);
128     static float GetHdrBrightness(FrameNode* frameNode);
129     static DynamicRangeMode GetDynamicRangeMode(FrameNode* frameNode);
130     static bool GetEnableAnalyzer(FrameNode* frameNode);
131     static CopyOptions GetCopyOption(FrameNode* frameNode);
132     static bool GetMatchTextDirection(FrameNode* frameNode);
133     static Matrix4 GetImageMatrix(FrameNode* frameNode);
134     static ImageInterpolation GetInterpolation(FrameNode* frameNode);
135     static ImageRepeat GetObjectRepeat(FrameNode* frameNode);
136     static std::vector<float> GetColorFilter(FrameNode* frameNode);
137     static bool GetAutoResize(FrameNode* frameNode);
138     static bool GetSyncLoad(FrameNode* frameNode);
139     static ImageSourceInfo GetAlt(FrameNode* frameNode);
140     static bool GetDraggable(FrameNode* frameNode);
141     static ImageRenderMode GetImageRenderMode(FrameNode* frameNode);
142     static void SetResizableSlice(FrameNode* frameNode, ImageResizableSlice& slice);
143     static void SetResizableLattice(FrameNode* frameNode, const RefPtr<DrawingLattice>& lattice);
144     static void ResetResizableLattice(FrameNode* frameNode);
145     static ImageResizableSlice GetResizableSlice(FrameNode* frameNode);
146     static void SetDynamicRangeMode(FrameNode* frameNode, DynamicRangeMode dynamicRangeMode);
147     static void SetHdrBrightness(FrameNode* frameNode, float hdrBrightness);
148     static void SetEnhancedImageQuality(FrameNode* frameNode, AIImageQuality imageQuality);
149     static bool GetFitOriginalSize(FrameNode* frameNode);
150     static uint32_t GetFillColor(FrameNode* frameNode);
151     static void SetPixelMap(FrameNode* frameNode, void* drawableDescriptor);
152     static void SetPixelMapArray(FrameNode* frameNode, void* animatedDrawableDescriptor);
153     static void SetResource(FrameNode* frameNode, void* resource);
154     static void EnableAnalyzer(FrameNode* frameNode, bool isEnableAnalyzer);
155     static void SetImageAnalyzerConfig(FrameNode* frameNode, void* config);
156     static RefPtr<DrawingColorFilter> GetDrawingColorFilter(FrameNode* frameNode);
157     static void ResetImageSrc(FrameNode* frameNode);
158     static void ResetImageAlt(FrameNode* frameNode);
159     static void SetAltPixelMap(FrameNode* frameNode, void* pixelMap);
160     static void SetAltResource(FrameNode* frameNode, void* resource);
161     static void CreateWithResourceObj(
162         FrameNode* frameNode, ImageResourceType resourceType, const RefPtr<ResourceObject>& resObject);
163 
164 private:
165     ImagePattern* GetImagePattern();
166 };
167 } // namespace OHOS::Ace::NG
168 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_IMAGE_IMAGE_MODEL_NG_H
169