• 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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FOCUSABLE_FOCUSABLE_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FOCUSABLE_FOCUSABLE_COMPONENT_H
18 
19 #include <string>
20 
21 #include "core/components/box/box_component.h"
22 #include "core/components/box/render_box.h"
23 #include "core/components/declaration/common/controllers.h"
24 #include "core/components/focusable/focusable_element.h"
25 #include "core/event/ace_event_handler.h"
26 #include "core/pipeline/base/sole_child_component.h"
27 
28 namespace OHOS::Ace {
29 
30 class ACE_EXPORT FocusableComponent final : public SoleChildComponent {
31     DECLARE_ACE_TYPE(FocusableComponent, SoleChildComponent);
32 
33 public:
FocusableComponent()34     FocusableComponent()
35     {
36         focusableController_ = AceType::MakeRefPtr<FocusableController>();
37     }
FocusableComponent(const RefPtr<Component> & child)38     explicit FocusableComponent(const RefPtr<Component>& child) : SoleChildComponent(child)
39     {
40         focusableController_ = AceType::MakeRefPtr<FocusableController>();
41     }
42     ~FocusableComponent() override = default;
43 
CreateElement()44     RefPtr<Element> CreateElement() override
45     {
46         return MakeRefPtr<FocusableElement>();
47     }
48 
CreateRenderNode()49     RefPtr<RenderNode> CreateRenderNode() override
50     {
51         return RenderBox::Create();
52     }
53 
GetOnClickId()54     const EventMarker& GetOnClickId() const
55     {
56         return onClickId_;
57     }
SetOnClickId(const EventMarker & onClickId)58     void SetOnClickId(const EventMarker& onClickId)
59     {
60         onClickId_ = onClickId;
61     }
62 
GetOnFocusId()63     const EventMarker& GetOnFocusId() const
64     {
65         return onFocusId_;
66     }
SetOnFocusId(const EventMarker & onFocusId)67     void SetOnFocusId(const EventMarker& onFocusId)
68     {
69         onFocusId_ = onFocusId;
70     }
71 
GetOnBlurId()72     const EventMarker& GetOnBlurId() const
73     {
74         return onBlurId_;
75     }
SetOnBlurId(const EventMarker & onBlurId)76     void SetOnBlurId(const EventMarker& onBlurId)
77     {
78         onBlurId_ = onBlurId;
79     }
80 
GetOnFocusMove()81     std::function<void(int)> GetOnFocusMove() const
82     {
83         return onFocusMove_;
84     }
SetOnFocusMove(const std::function<void (int)> & onFocusMove)85     void SetOnFocusMove(const std::function<void(int)>& onFocusMove)
86     {
87         onFocusMove_ = onFocusMove;
88     }
89 
GetOnFocus()90     std::function<void()> GetOnFocus() const
91     {
92         return onFocus_;
93     }
SetOnFocus(const std::function<void ()> & onFocus)94     void SetOnFocus(const std::function<void()>& onFocus)
95     {
96         onFocus_ = onFocus;
97     }
98 
GetOnBlur()99     std::function<void()> GetOnBlur() const
100     {
101         return onBlur_;
102     }
SetOnBlur(const std::function<void ()> & onBlur)103     void SetOnBlur(const std::function<void()>& onBlur)
104     {
105         onBlur_ = onBlur;
106     }
107 
GetOnKeyId()108     const EventMarker& GetOnKeyId() const
109     {
110         return onKeyId_;
111     }
SetOnKeyId(const EventMarker & onKeyId)112     void SetOnKeyId(const EventMarker& onKeyId)
113     {
114         onKeyId_ = onKeyId;
115     }
116 
GetOnDeleteId()117     const EventMarker& GetOnDeleteId() const
118     {
119         return onDeleteId_;
120     }
SetOnDeleteId(const EventMarker & onDeleteId)121     void SetOnDeleteId(const EventMarker& onDeleteId)
122     {
123         onDeleteId_ = onDeleteId;
124     }
125 
GetBoxStyle()126     RefPtr<BoxComponent> GetBoxStyle() const
127     {
128         return boxStyle_;
129     }
SetBoxStyle(const RefPtr<BoxComponent> & boxStyle)130     void SetBoxStyle(const RefPtr<BoxComponent>& boxStyle)
131     {
132         boxStyle_ = boxStyle;
133     }
134 
GetFocusedBoxStyle()135     RefPtr<BoxComponent> GetFocusedBoxStyle() const
136     {
137         return focusedBoxStyle_;
138     }
SetFocusedBoxStyle(const RefPtr<BoxComponent> & boxStyle)139     void SetFocusedBoxStyle(const RefPtr<BoxComponent>& boxStyle)
140     {
141         focusedBoxStyle_ = boxStyle;
142     }
143 
GetAutoFocused()144     bool GetAutoFocused() const
145     {
146         return autoFocused_;
147     }
SetAutoFocused(bool autoFocused)148     void SetAutoFocused(bool autoFocused)
149     {
150         autoFocused_ = autoFocused;
151     }
IsFocusNode()152     bool IsFocusNode() const
153     {
154         return focusNode_;
155     }
SetFocusNode(bool focusNode)156     void SetFocusNode(bool focusNode)
157     {
158         focusNode_ = focusNode;
159     }
160 
IsFocusable()161     bool IsFocusable() const
162     {
163         return focusable_;
164     }
SetFocusable(bool focusable)165     void SetFocusable(bool focusable)
166     {
167         focusable_ = focusable;
168     }
169 
CanShow()170     bool CanShow() const
171     {
172         return show_;
173     }
SetShow(bool show)174     void SetShow(bool show)
175     {
176         show_ = show;
177     }
178 
GetFocusableController()179     RefPtr<FocusableController> GetFocusableController() const
180     {
181         return focusableController_;
182     }
183 
IsDeleteDisabled()184     bool IsDeleteDisabled() {
185         return deleteDisabled_;
186     }
SetDeleteDisabled(bool deleteDisabled)187     void SetDeleteDisabled(bool deleteDisabled) {
188         deleteDisabled_ = deleteDisabled;
189     }
190 
191 private:
192     EventMarker onClickId_;
193     EventMarker onFocusId_;
194     EventMarker onBlurId_;
195     EventMarker onKeyId_;
196     EventMarker onDeleteId_;
197 
198     RefPtr<BoxComponent> boxStyle_;
199     RefPtr<BoxComponent> focusedBoxStyle_;
200     RefPtr<FocusableController> focusableController_;
201 
202     bool autoFocused_ { false };
203     bool focusNode_ { false };
204     bool focusable_ { false };
205     bool show_ { true };
206     bool deleteDisabled_ { false };
207 
208     std::function<void(int)> onFocusMove_;
209     std::function<void()> onFocus_;
210     std::function<void()> onBlur_;
211 };
212 
213 } // namespace OHOS::Ace
214 
215 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FOCUSABLE_FOCUSABLE_COMPONENT_H
216