1 /* 2 * Copyright (c) 2021 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 "core/components/image/image_component.h" 20 #include "core/components/image/image_event.h" 21 #include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h" 22 #include "frameworks/bridge/declarative_frontend/jsview/js_utils.h" 23 #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h" 24 #if !defined(WINDOWS_PLATFORM) and !defined(MAC_PLATFORM) 25 #include "napi/native_api.h" 26 #include "native_engine/native_engine.h" 27 #endif 28 29 #ifdef USE_QUICKJS_ENGINE 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 #include "third_party/quickjs/quickjs.h" 34 #ifdef __cplusplus 35 } 36 #endif 37 #endif 38 39 namespace OHOS::Ace::Framework { 40 class JSImage : public JSViewAbstract, public JSInteractableView { 41 public: 42 static void Create(const JSCallbackInfo& info); 43 static void HandleLoadImageSuccess(const BaseEventInfo& param); 44 static void HandleLoadImageFail(const BaseEventInfo& param); 45 static void SetAlt(const JSCallbackInfo& args); 46 static void SetMatchTextDirection(bool value); 47 static void SetFitOriginalSize(bool value); 48 static void SetSourceSize(const JSCallbackInfo& info); 49 static void SetObjectFit(int32_t value); 50 static void SetImageFill(const JSCallbackInfo& info); 51 static void SetImageInterpolation(int32_t imageInterpolation); 52 static void SetImageRenderMode(int32_t imageRenderMode); 53 static void SetImageRepeat(int32_t imageRepeat); 54 static void JSBind(BindingTarget globalObj); 55 static void OnComplete(const JSCallbackInfo& args); 56 static void OnError(const JSCallbackInfo& args); 57 static void OnFinish(const JSCallbackInfo& info); 58 static void SetSyncLoad(const JSCallbackInfo& info); 59 60 static void JsPadding(const JSCallbackInfo& info); 61 static void JsMargin(const JSCallbackInfo& info); 62 static void ParseMarginOrPadding(const JSCallbackInfo& info, bool isMargin); 63 static void JsBorder(const JSCallbackInfo& info); 64 static void JsBorderRadius(const JSCallbackInfo& info); 65 static void SetLeftBorderWidth(const Dimension& value); 66 static void SetTopBorderWidth(const Dimension& value); 67 static void SetRightBorderWidth(const Dimension& value); 68 static void SetBottomBorderWidth(const Dimension& value); 69 static void SetBorderRadius(const Dimension& value); 70 static void JsOpacity(const JSCallbackInfo& info); 71 static void JsTransition(const JSCallbackInfo& info); 72 73 protected: 74 /** 75 * box properties setter 76 */ 77 static RefPtr<Decoration> GetFrontDecoration(); 78 static const Border& GetBorder(); 79 static BorderEdge GetLeftBorderEdge(); 80 static BorderEdge GetTopBorderEdge(); 81 static BorderEdge GetRightBorderEdge(); 82 static BorderEdge GetBottomBorderEdge(); 83 static void SetBorderEdge(const BorderEdge& edge); 84 static void SetLeftBorderEdge(const BorderEdge& edge); 85 static void SetTopBorderEdge(const BorderEdge& edge); 86 static void SetRightBorderEdge(const BorderEdge& edge); 87 static void SetBottomBorderEdge(const BorderEdge& edge); 88 static void SetBorder(const Border& border); 89 static void SetWidth(const Dimension& width); 90 static void SetHeight(const Dimension& height); 91 static void SetMarginTop(const std::string& value); 92 static void SetMarginBottom(const std::string& value); 93 static void SetMarginLeft(const std::string& value); 94 static void SetMarginRight(const std::string& value); 95 static void SetMargin(const std::string& value); 96 static void SetPaddingTop(const std::string& value); 97 static void SetPaddingBottom(const std::string& value); 98 static void SetPaddingLeft(const std::string& value); 99 static void SetPaddingRight(const std::string& value); 100 static void SetPadding(const std::string& value); 101 static void SetBackgroundColor(const Color& color); 102 static void SetLeftBorderColor(const Color& color); 103 static void SetTopBorderColor(const Color& color); 104 static void SetRightBorderColor(const Color& color); 105 static void SetBottomBorderColor(const Color& color); 106 static void SetAutoResize(bool autoResize); 107 108 }; 109 110 } // namespace OHOS::Ace::Framework 111 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_IMAGE_H 112