• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #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 
27 // ImageModel is essentially the same class as ImageView
28 // there should be only one left in the final implementation
29 
30 class ACE_EXPORT ImageModelNG : public OHOS::Ace::ImageModel {
31 public:
32     void Create(const ImageInfoConfig& imageInfoConfig, RefPtr<PixelMap>& pixMap) 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,
41         const std::optional<Dimension>& radiusTopRight, const std::optional<Dimension>& radiusBottomLeft,
42         const std::optional<Dimension>& radiusBottomRight) override;
43     void SetBorderRadius(const NG::BorderRadiusProperty& borderRadius) override;
44     void SetBlur(double blur) override;
45     void SetImageFit(ImageFit value) override;
46     void SetImageMatrix(const Matrix4 &value) override;
47     void SetMatchTextDirection(bool value) override;
48     void SetFitOriginSize(bool value) override;
49     void SetOnComplete(std::function<void(const LoadImageSuccessEvent& info)>&& callback) override;
50     void SetOnError(std::function<void(const LoadImageFailEvent& info)>&& callback) override;
51     void SetSvgAnimatorFinishEvent(std::function<void()>&& callback) override;
52     void SetImageSourceSize(const std::pair<Dimension, Dimension>& size) override;
53     void SetImageFill(const Color& color) override;
54     void ResetImageFill() override;
55     void SetImageInterpolation(ImageInterpolation interpolation) override;
56     void SetImageRepeat(ImageRepeat imageRepeat) override;
57     void SetImageRenderMode(ImageRenderMode imageRenderMode) override;
58     bool IsSrcSvgImage() override;
59     void SetAutoResize(bool autoResize) override;
60     void SetSyncMode(bool syncMode) override;
61     void SetColorFilterMatrix(const std::vector<float> &matrix) override;
62     void SetDrawingColorFilter(RefPtr<DrawingColorFilter> &colorFilter) override;
63     void SetDraggable(bool draggable) override;
64     void SetOnDragStart(OnDragStartFunc &&onDragStart) override;
65     void SetOnDragEnter(OnDragDropFunc &&onDragEnter) override;
66     void SetOnDragLeave(OnDragDropFunc &&onDragLeave) override;
67     void SetOnDragMove(OnDragDropFunc &&onDragMove) override;
68     void SetOnDrop(OnDragDropFunc &&onDrop) override;
69     void SetCopyOption(const CopyOptions &copyOption) override;
70     void SetSmoothEdge(float value) override;
71     void SetDynamicRangeMode(DynamicRangeMode dynamicRangeMode) 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(const ImageResizableSlice& slice) override;
80     void SetResizableLattice(const RefPtr<DrawingLattice>& lattice) override;
81     void ResetResizableLattice() override;
82     static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId, const std::string& src, RefPtr<PixelMap>& pixMap,
83         const std::string& bundleName, const std::string& moduleName, bool isUriPureNumber = false);
84     static void InitImage(FrameNode *frameNode, std::string& src);
85     static void SetDraggableForFrameNode(RefPtr<FrameNode> frameNode);
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(FrameNode* frameNode,
123         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 ImageInterpolation GetInterpolation(FrameNode* frameNode);
127     static ImageRepeat GetObjectRepeat(FrameNode* frameNode);
128     static std::vector<float> GetColorFilter(FrameNode* frameNode);
129     static bool GetAutoResize(FrameNode* frameNode);
130     static ImageSourceInfo GetAlt(FrameNode* frameNode);
131     static bool GetDraggable(FrameNode* frameNode);
132     static ImageRenderMode GetImageRenderMode(FrameNode* frameNode);
133     static void SetResizableSlice(FrameNode* frameNode, const ImageResizableSlice& slice);
134     static void SetResizableLattice(FrameNode* frameNode, const RefPtr<DrawingLattice>& lattice);
135     static void ResetResizableLattice(FrameNode *frameNode);
136     static ImageResizableSlice GetResizableSlice(FrameNode *frameNode);
137     static bool GetFitOriginalSize(FrameNode *frameNode);
138     static uint32_t GetFillColor(FrameNode *frameNode);
139     static void SetPixelMap(FrameNode* frameNode, void* drawableDescriptor);
140     static void SetPixelMapArray(FrameNode* frameNode, void* animatedDrawableDescriptor);
141     static void SetResource(FrameNode* frameNode, void* resource);
142     static void SetDynamicRangeMode(FrameNode* frameNode, DynamicRangeMode dynamicRangeMode);
143     static void SetEnhancedImageQuality(FrameNode* frameNode, AIImageQuality imageQuality);
144     static void EnableAnalyzer(FrameNode* frameNode, bool isEnableAnalyzer);
145     static void SetImageAnalyzerConfig(FrameNode* frameNode, void* config);
146     static RefPtr<DrawingColorFilter> GetDrawingColorFilter(FrameNode* frameNode);
147     static void ResetImageSrc(FrameNode* frameNode);
148     static void ResetImageAlt(FrameNode* frameNode);
149     static void SetAltPixelMap(FrameNode* frameNode, void* pixelMap);
150     static void SetAltResource(FrameNode* frameNode, void* resource);
151 
152 private:
153     ImagePattern* GetImagePattern();
154 };
155 
156 } // namespace OHOS::Ace::NG
157 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_IMAGE_IMAGE_MODEL_NG_H
158