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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_BUTTON_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_BUTTON_H 18 19 #include <variant> 20 21 #include "core/components/button/button_component.h" 22 #include "core/components/text/text_component.h" 23 #include "core/components/touch_listener/touch_listener_component.h" 24 #include "core/components_ng/pattern/button/button_request_data.h" 25 #include "core/event/ace_event_handler.h" 26 #include "frameworks/bridge/declarative_frontend/engine/bindings_defines.h" 27 #include "frameworks/bridge/declarative_frontend/jsview/js_container_base.h" 28 29 namespace OHOS::Ace::Framework { 30 class JSButton : public JSContainerBase { 31 public: 32 static void SetFontSize(const JSCallbackInfo& info); 33 static void SetFontWeight(const std::string& value); 34 static void SetFontStyle(int32_t value); 35 static void SetFontFamily(const JSCallbackInfo& info); 36 static void SetTextColor(const JSCallbackInfo& info); 37 static void SetType(const JSCallbackInfo& info); 38 static void SetStateEffect(const JSCallbackInfo& info); 39 static void SetLableStyle(const JSCallbackInfo& info); 40 static void SetButtonStyle(const JSCallbackInfo& info); 41 static void SetControlSize(const JSCallbackInfo& info); 42 static void JsBackgroundColor(const JSCallbackInfo& info); 43 static void JsRadius(const JSCallbackInfo& info); 44 static void JsBorder(const JSCallbackInfo& info); 45 static void JsWidth(const JSCallbackInfo& info); 46 static void JsHeight(const JSCallbackInfo& info); 47 static void JsAspectRatio(const JSCallbackInfo& info); 48 static void JsOnClick(const JSCallbackInfo& info); 49 static void JsSize(const JSCallbackInfo& info); 50 static void JsRemoteMessage(const JSCallbackInfo& info); 51 static void JsPadding(const JSCallbackInfo& info); 52 static void SetRole(const JSCallbackInfo& info); 53 static void JSBind(BindingTarget globalObj); 54 static void CreateWithChild(const JSCallbackInfo& info); 55 static void CreateWithLabel(const JSCallbackInfo& info); 56 static constexpr char TYPE[] = "type"; 57 static constexpr char STATE_EFFECT[] = "stateEffect"; 58 static constexpr char BUTTON_STYLE[] = "buttonStyle"; 59 static constexpr char CONTROL_SIZE[] = "controlSize"; 60 static constexpr char ROLE[] = "role"; 61 62 private: 63 static void HandleDifferentRadius(const JSRef<JSVal>& args); 64 static void GetFontContent(JSRef<JSVal>& font, ButtonParameters& buttonParameters); 65 static void CompleteParameters(ButtonParameters& buttonParameters); 66 static CalcDimension GetSizeValue(const JSCallbackInfo& info); 67 static NG::PaddingProperty GetNewPadding(const JSCallbackInfo& info); 68 static Edge GetOldPadding(const JSCallbackInfo& info); 69 static NG::PaddingProperty SetPaddings(const std::optional<CalcDimension>& top, 70 const std::optional<CalcDimension>& bottom, const std::optional<CalcDimension>& left, 71 const std::optional<CalcDimension>& right); 72 static CreateWithPara ParseCreatePara(const JSCallbackInfo& info, bool hasLabel); 73 static void ParseButtonRole(const JSRef<JSObject>& optionObj, CreateWithPara& param); 74 static bool isLabelButton_; 75 }; 76 } // namespace OHOS::Ace::Framework 77 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_BUTTON_H 78