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