• 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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_IMAGE_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_IMAGE_H
18 
19 #include "base/image/image_defines.h"
20 #include "bridge/declarative_frontend/jsview/js_interactable_view.h"
21 #include "bridge/declarative_frontend/jsview/js_utils.h"
22 #include "bridge/declarative_frontend/jsview/js_view_abstract.h"
23 #include "core/components/image/image_event.h"
24 
25 namespace OHOS::Ace::Framework {
26 
27 JSRef<JSVal> LoadImageSuccEventToJSValue(const LoadImageSuccessEvent& eventInfo);
28 JSRef<JSVal> LoadImageFailEventToJSValue(const LoadImageFailEvent& eventInfo);
29 
30 class JSImage : public JSViewAbstract, public JSInteractableView {
31 public:
32     static void Create(const JSCallbackInfo& info);
33     static void CreateImage(const JSCallbackInfo& info, bool isImageSpan = false);
34     static void CreateImageAnimation(std::vector<RefPtr<PixelMap>>& pixelMaps, int32_t duration, int32_t iterations);
35     static void CheckIsCard(std::string& src, const JSRef<JSVal>& jsValue);
36     static bool CheckResetImage(const bool& srcValid, const JSCallbackInfo& info);
37     static void HandleLoadImageSuccess(const BaseEventInfo& param);
38     static void HandleLoadImageFail(const BaseEventInfo& param);
39     static void SetAlt(const JSCallbackInfo& args);
40     static void SetMatchTextDirection(bool value);
41     static void SetFitOriginalSize(bool value);
42     static void SetSourceSize(const JSCallbackInfo& info);
43     static void SetObjectFit(const JSCallbackInfo& args);
44     static void SetImageMatrix(const JSCallbackInfo& args);
45     static void SetDefaultImageMatrix();
46     static void SetImageFill(const JSCallbackInfo& info);
47     static bool ParseColorContent(const JSRef<JSVal>& jsValue);
48     static void SetImageInterpolation(int32_t imageInterpolation);
49     static void SetImageRenderMode(const JSCallbackInfo& info);
50     static void SetImageRepeat(int32_t imageRepeat);
51     static void JSBind(BindingTarget globalObj);
52     static void OnComplete(const JSCallbackInfo& args);
53     static void OnError(const JSCallbackInfo& args);
54     static void OnFinish(const JSCallbackInfo& info);
55     static void SetSyncLoad(const JSCallbackInfo& info);
56     static void SetColorFilter(const JSCallbackInfo& info);
57     static void SetSmoothEdge(const JSCallbackInfo& info);
58     static void SetDynamicRangeMode(const JSCallbackInfo& info);
59     static void SetHdrBrightness(const JSCallbackInfo& info);
60     static void SetEnhancedImageQuality(const JSCallbackInfo& info);
61     static void SetOrientation(const JSCallbackInfo& info);
62 
63     static void JsBorder(const JSCallbackInfo& info);
64     static void JsBorderRadius(const JSCallbackInfo& info);
65     static void SetLeftBorderWidth(const CalcDimension& value);
66     static void SetTopBorderWidth(const CalcDimension& value);
67     static void SetRightBorderWidth(const CalcDimension& value);
68     static void SetBottomBorderWidth(const CalcDimension& value);
69     static void SetBorderRadius(const CalcDimension& value);
70     static void ParseBorderRadius(const JSRef<JSVal>& args);
71     static void JsOpacity(const JSCallbackInfo& info);
72     static void JsBlur(const JSCallbackInfo& info);
73     static void JsTransition(const JSCallbackInfo& info);
74     static void JsSetDraggable(const JSCallbackInfo& info);
75     static void JsOnDragStart(const JSCallbackInfo& info);
76     static void SetCopyOption(const JSCallbackInfo& info);
77 
78     static void EnableAnalyzer(bool isEnableAnalyzer);
79     static void AnalyzerConfig(const JSCallbackInfo& info);
80     static void ParseResizableSlice(const JSRef<JSObject>& info);
81     static void ParseResizableLattice(const JSRef<JSObject>& info);
82     static void JsImageResizable(const JSCallbackInfo& info);
83     static bool IsDrawable(const JSRef<JSVal>& jsValue);
84     static ImageType ParseImageType(const JSRef<JSVal>& jsValue);
85 
86 protected:
87     static void SetBorder(const Border& border);
88     static void SetAutoResize(bool autoResize);
89     static void UpdateSliceResult(const JSRef<JSObject>& sliceObj, ImageResizableSlice& sliceResult);
90     static void ParseImageAIOptions(const JSCallbackInfo& info);
91 };
92 
93 class JSColorFilter : public AceType {
94     DECLARE_ACE_TYPE(JSColorFilter, AceType);
95 
96 public:
97     JSColorFilter() = default;
98     ~JSColorFilter() override = default;
99     static void ConstructorCallback(const JSCallbackInfo& info);
100     static void DestructorCallback(JSColorFilter* obj);
101 
SetColorFilterMatrix(const std::vector<float> && matrix)102     void SetColorFilterMatrix(const std::vector<float>&& matrix)
103     {
104         colorfiltermatrix_ = std::move(matrix);
105     }
106 
GetColorFilterMatrix()107     const std::vector<float>& GetColorFilterMatrix() const
108     {
109         return colorfiltermatrix_;
110     }
111 
112 private:
113     std::vector<float> colorfiltermatrix_;
114 };
115 
116 } // namespace OHOS::Ace::Framework
117 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_IMAGE_H
118