• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef OHOS_ACELITE_INPUT_BUTTON_COMPONENT_H
16 #define OHOS_ACELITE_INPUT_BUTTON_COMPONENT_H
17 #include "component.h"
18 #include "key_parser.h"
19 #include "non_copyable.h"
20 #include "ui_label_button.h"
21 #ifdef FEATURE_EXTRA_TEXT_X_SUPPORT
22 #include "ui_label_button_x.h"
23 #define UI_LABEL_BUTTON_TYPE_WRAPPER UILabelButtonX
24 #else
25 #define UI_LABEL_BUTTON_TYPE_WRAPPER UILabelButton
26 #endif // FEATURE_EXTRA_TEXT_X_SUPPORT
27 
28 namespace OHOS {
29 namespace ACELite {
30 class InputButtonComponent final : public Component {
31 public:
32     ACE_DISALLOW_COPY_AND_MOVE(InputButtonComponent);
33     InputButtonComponent() = delete;
InputButtonComponent(jerry_value_t options,jerry_value_t children,AppStyleManager * manager)34     InputButtonComponent(jerry_value_t options, jerry_value_t children, AppStyleManager *manager)
35         : Component(options, children, manager),
36           options_(options),
37           clickListener_(nullptr),
38           pressedBackGroundColorValue_(-1),
39           normalBackGroundImg_(nullptr),
40           pressedBackGroundImg_(nullptr),
41           textValue_(nullptr),
42           fontFamily_(nullptr),
43           fontSize_(DEFAULT_FONT_SIZE)
44     {
45         uint8_t pressedOpacityValue = 255;
46         pressedOpacityValue_ = pressedOpacityValue;
47         SetComponentName(K_INPUT);
48     }
~InputButtonComponent()49     ~InputButtonComponent() override {};
50     bool CreateNativeViews() override;
51     void ReleaseNativeViews() override;
52     bool SetPrivateAttribute(uint16_t attrKeyId, jerry_value_t attrValue) override;
53     bool ApplyPrivateStyle(const AppStyleItem *style) override;
54     void PostRender() override;
55     void PostUpdate(uint16_t attrKeyId) override;
56 
57 protected:
GetComponentRootView()58     UIView *GetComponentRootView() const override
59     {
60         return const_cast<UI_LABEL_BUTTON_TYPE_WRAPPER *>(&button_);
61     }
62 
63 private:
64     bool SetTextAlign(const AppStyleItem *style);
65     bool SetFontSize(const AppStyleItem *style);
66     void DealEvent();
67     bool SetBackgroundColor(const AppStyleItem &style);
68     bool SetColor(const AppStyleItem &style);
69     bool HandleImage(const AppStyleItem &style);
70     jerry_value_t options_;
71     UI_LABEL_BUTTON_TYPE_WRAPPER button_;
72     ViewOnClickListener *clickListener_;
73     int32_t pressedBackGroundColorValue_;
74     uint8_t pressedOpacityValue_;
75     char *normalBackGroundImg_;
76     char *pressedBackGroundImg_;
77     char *textValue_;
78     char *fontFamily_;
79     uint8_t fontSize_;
80 };
81 } // namespace ACELite
82 } // namespace OHOS
83 #endif // OHOS_ACELITE_INPUT_BUTTON_COMPONENT_H
84