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 FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_TEXTAREA_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_TEXTAREA_H
18 
19 #include "core/components/text_field/text_field_component.h"
20 #include "core/components/text_field/textfield_theme.h"
21 #include "core/components/theme/theme_manager.h"
22 #include "frameworks/bridge/common/dom/dom_input.h"
23 #include "frameworks/bridge/common/dom/dom_node.h"
24 #include "frameworks/bridge/common/dom/dom_type.h"
25 
26 namespace OHOS::Ace::Framework {
27 
28 class DOMTextarea final : public DOMNode {
29     DECLARE_ACE_TYPE(DOMTextarea, DOMNode);
30 
31 public:
32     using DOMTextareaMap = std::unordered_map<std::string, void (*)(const std::string&, DOMTextarea&)>;
33 
34     DOMTextarea(NodeId nodeId, const std::string& nodeName);
35     ~DOMTextarea() override = default;
36 
37     void InitializeStyle() override;
38     void OnRequestFocus(bool shouldFocus) override;
39 
GetSpecializedComponent()40     RefPtr<Component> GetSpecializedComponent() override
41     {
42         return textAreaChild_;
43     }
44 
SetInputOptions(const std::vector<InputOption> & inputOptions)45     void SetInputOptions(const std::vector<InputOption>& inputOptions)
46     {
47         inputOptions_ = inputOptions;
48     }
49 
50 protected:
51     bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override;
52     bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override;
53     bool AddSpecializedEvent(int32_t pageId, const std::string& event) override;
54     void CallSpecializedMethod(const std::string& method, const std::string& args) override;
55     void PrepareSpecializedComponent() override;
56     void ResetInitializedStyle() override;
57 
58 private:
59     void UpdateDecoration();
60 
61     bool hasBoxRadius_ = false;
62     RefPtr<TextFieldComponent> textAreaChild_;
63     TextStyle textStyle_;
64 
65     // Callback id for when text is changed.
66     EventMarker onTextChange_;
67     Radius defaultRadius_;
68 
69     std::vector<InputOption> inputOptions_;
70 };
71 
72 } // namespace OHOS::Ace::Framework
73 
74 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_TEXTAREA_H
75