• 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/declaration/image/image_animator_declaration.h"
20 #include "core/components_ng/base/frame_node.h"
21 #include "core/components_ng/pattern/image/image_model.h"
22 #include "core/components_ng/pattern/image/image_pattern.h"
23 
24 namespace OHOS::Ace::NG {
25 
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 ResetImage() override;
33     void CreateAnimation(const std::vector<ImageProperties>& imageList, int32_t duration, int32_t iteration) override;
34     bool GetIsAnimation() override;
35     void SetAlt(const ImageSourceInfo& src) override;
36     void SetBorder(const Border& border) override;
37     void SetBackBorder() override;
38     void SetBorderRadius(const Dimension& value) override;
39     void SetBorderRadius(const std::optional<Dimension>& radiusTopLeft,
40         const std::optional<Dimension>& radiusTopRight, const std::optional<Dimension>& radiusBottomLeft,
41         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 SetMatchTextDirection(bool value) override;
46     void SetFitOriginSize(bool value) override;
47     void SetOnComplete(std::function<void(const LoadImageSuccessEvent& info)>&& callback) override;
48     void SetOnError(std::function<void(const LoadImageFailEvent& info)>&& callback) override;
49     void SetSvgAnimatorFinishEvent(std::function<void()>&& callback) override;
50     void SetImageSourceSize(const std::pair<Dimension, Dimension>& size) override;
51     void SetImageFill(const Color& color) override;
52     void SetImageInterpolation(ImageInterpolation interpolation) override;
53     void SetImageRepeat(ImageRepeat imageRepeat) override;
54     void SetImageRenderMode(ImageRenderMode imageRenderMode) override;
55     bool IsSrcSvgImage() override;
56     void SetAutoResize(bool autoResize) override;
57     void SetSyncMode(bool syncMode) override;
58     void SetColorFilterMatrix(const std::vector<float> &matrix) override;
59     void SetDrawingColorFilter(RefPtr<DrawingColorFilter> &colorFilter) override;
60     void SetDraggable(bool draggable) override;
61     void SetOnDragStart(OnDragStartFunc &&onDragStart) override;
62     void SetOnDragEnter(OnDragDropFunc &&onDragEnter) override;
63     void SetOnDragLeave(OnDragDropFunc &&onDragLeave) override;
64     void SetOnDragMove(OnDragDropFunc &&onDragMove) override;
65     void SetOnDrop(OnDragDropFunc &&onDrop) override;
66     void SetCopyOption(const CopyOptions &copyOption) override;
67     void SetSmoothEdge(float value) override;
68     void SetDynamicRangeMode(DynamicRangeMode dynamicRangeMode) override;
69     void SetEnhancedImageQuality(AIImageQuality imageQuality) override;
70     bool UpdateDragItemInfo(DragItemInfo &itemInfo) override;
71     void EnableAnalyzer(bool isEnableAnalyzer) override;
72     void SetImageAnalyzerConfig(const ImageAnalyzerConfig& config) override;
73     void SetImageAnalyzerConfig(void* config) override;
74     void SetImageAIOptions(void* options) override;
75     void SetResizableSlice(const ImageResizableSlice& slice) override;
76     void SetResizableLattice(const RefPtr<DrawingLattice>& lattice) override;
77     void ResetResizableLattice() override;
78     static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId, const std::string& src, RefPtr<PixelMap>& pixMap,
79         const std::string& bundleName, const std::string& moduleName, bool isUriPureNumber = false);
80     static void InitImage(FrameNode *frameNode, std::string& src);
81     static void SetDraggableForFrameNode(RefPtr<FrameNode> frameNode);
82     static void ResetImage(FrameNode* frameNode);
83     static void SetInitialSrc(FrameNode* frameNode, const std::string& src, const std::string& bundleName,
84         const std::string& moduleName, bool isUriPureNumber = false);
85     static void SetInitialPixelMap(FrameNode* frameNode, RefPtr<PixelMap>& pixMap);
86     static void SetSmoothEdge(FrameNode *frameNode, float value);
87     static void SetCopyOption(FrameNode *frameNode, CopyOptions copyOption);
88     static void SetAutoResize(FrameNode *frameNode, bool autoResize);
89     static void ResetAutoResize(FrameNode *frameNode);
90     static void SetImageRepeat(FrameNode *frameNode, ImageRepeat imageRepeat);
91     static void SetImageRenderMode(FrameNode *frameNode, ImageRenderMode imageRenderMode);
92     static void SetSyncMode(FrameNode *frameNode, bool syncMode);
93     static void SetImageFit(FrameNode *frameNode, ImageFit value);
94     static void SetDrawingColorFilter(FrameNode *frameNode, RefPtr<DrawingColorFilter> &colorFilter);
95     static void SetFitOriginSize(FrameNode *framNode, bool value);
96     static void SetImageSourceSize(FrameNode *frameNode, const std::pair<Dimension, Dimension> &size);
97     static void SetMatchTextDirection(FrameNode *frameNode, bool value);
98     static void SetImageFill(FrameNode *frameNode, const Color &color);
99     static void SetAlt(FrameNode *frameNode, const ImageSourceInfo &src);
100     static void SetImageInterpolation(FrameNode *frameNode, ImageInterpolation interpolation);
101     static void ResetImageInterpolation(FrameNode *frameNode);
102     static void SetColorFilterMatrix(FrameNode *frameNode, const std::vector<float> &matrix);
103     static void SetDraggable(FrameNode *frameNode, bool draggable);
104     static void SetBackBorder(FrameNode *frameNode);
105     static void SetBorderRadius(FrameNode* frameNode, const Dimension& value);
106     static void SetBorderRadius(FrameNode* frameNode, const std::optional<Dimension>& radiusTopLeft,
107         const std::optional<Dimension>& radiusTopRight, const std::optional<Dimension>& radiusBottomLeft,
108         const std::optional<Dimension>& radiusBottomRight);
109     static void SetBorderRadius(FrameNode* frameNode, const NG::BorderRadiusProperty& borderRadius);
110     static void ResetBackBorder(FrameNode *frameNode);
111     static bool IsSrcSvgImage(FrameNode* frameNode);
112     static void SetOnComplete(FrameNode* frameNode, std::function<void(const LoadImageSuccessEvent& info)>&& callback);
113     static void SetOnError(FrameNode* frameNode, std::function<void(const LoadImageFailEvent& info)>&& callback);
114     static void SetOnSvgPlayFinish(FrameNode* frameNode, std::function<void()>&& callback);
115     static void SetOnDownloadProgress(FrameNode* frameNode,
116         std::function<void(const uint32_t& dlNow, const uint32_t& dlTotal)>&& callback);
117     static ImageSourceInfo GetSrc(FrameNode* frameNode);
118     static ImageFit GetObjectFit(FrameNode* frameNode);
119     static ImageInterpolation GetInterpolation(FrameNode* frameNode);
120     static ImageRepeat GetObjectRepeat(FrameNode* frameNode);
121     static std::vector<float> GetColorFilter(FrameNode* frameNode);
122     static bool GetAutoResize(FrameNode* frameNode);
123     static ImageSourceInfo GetAlt(FrameNode* frameNode);
124     static bool GetDraggable(FrameNode* frameNode);
125     static ImageRenderMode GetImageRenderMode(FrameNode* frameNode);
126     static void SetResizableSlice(FrameNode* frameNode, const ImageResizableSlice& slice);
127     static void SetResizableLattice(FrameNode* frameNode, const RefPtr<DrawingLattice>& lattice);
128     static void ResetResizableLattice(FrameNode *frameNode);
129     static ImageResizableSlice GetResizableSlice(FrameNode *frameNode);
130     static bool GetFitOriginalSize(FrameNode *frameNode);
131     static uint32_t GetFillColor(FrameNode *frameNode);
132     static void SetPixelMap(FrameNode* frameNode, void* drawableDescriptor);
133     static void SetPixelMapArray(FrameNode* frameNode, void* animatedDrawableDescriptor);
134     static void SetResource(FrameNode* frameNode, void* resource);
135     static void SetDynamicRangeMode(FrameNode* frameNode, DynamicRangeMode dynamicRangeMode);
136     static void SetEnhancedImageQuality(FrameNode* frameNode, AIImageQuality imageQuality);
137     static void EnableAnalyzer(FrameNode* frameNode, bool isEnableAnalyzer);
138     static void SetImageAnalyzerConfig(FrameNode* frameNode, void* config);
139     static RefPtr<DrawingColorFilter> GetDrawingColorFilter(FrameNode* frameNode);
140     static void ResetImageSrc(FrameNode* frameNode);
141     static void ResetImageAlt(FrameNode* frameNode);
142     static void SetAltPixelMap(FrameNode* frameNode, void* pixelMap);
143     static void SetAltResource(FrameNode* frameNode, void* resource);
144 
145 private:
146     ImagePattern* GetImagePattern();
147 };
148 
149 } // namespace OHOS::Ace::NG
150 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_IMAGE_IMAGE_MODEL_NG_H
151