• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CHECKBOX_CHECKBOX_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CHECKBOX_CHECKBOX_PATTERN_H
18 
19 #include "base/geometry/axis.h"
20 #include "base/memory/referenced.h"
21 #include "base/utils/utils.h"
22 #include "core/components/common/layout/constants.h"
23 #include "core/components_ng/base/inspector_filter.h"
24 #include "core/components_ng/event/event_hub.h"
25 #include "core/components_ng/pattern/toggle/toggle_model_ng.h"
26 #include "core/components_ng/pattern/checkbox/checkbox_accessibility_property.h"
27 #include "core/components_ng/pattern/checkbox/checkbox_event_hub.h"
28 #include "core/components_ng/pattern/checkbox/checkbox_layout_algorithm.h"
29 #include "core/components_ng/pattern/checkbox/checkbox_model_ng.h"
30 #include "core/components_ng/pattern/checkbox/checkbox_paint_method.h"
31 #include "core/components_ng/pattern/checkbox/checkbox_paint_property.h"
32 #include "core/components_ng/pattern/pattern.h"
33 #include "core/components_ng/pattern/picker/picker_type_define.h"
34 
35 namespace OHOS::Ace::NG {
36 class CheckBoxGroupPaintProperty;
37 class CheckBoxPattern : public Pattern {
38     DECLARE_ACE_TYPE(CheckBoxPattern, Pattern);
39 
40 public:
41     CheckBoxPattern() = default;
42     ~CheckBoxPattern() override = default;
43 
IsAtomicNode()44     bool IsAtomicNode() const override
45     {
46         return true;
47     }
48 
CreatePaintProperty()49     RefPtr<PaintProperty> CreatePaintProperty() override
50     {
51         return MakeRefPtr<CheckBoxPaintProperty>();
52     }
53 
CreateLayoutAlgorithm()54     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
55     {
56         return MakeRefPtr<CheckBoxLayoutAlgorithm>();
57     }
58 
59     RefPtr<NodePaintMethod> CreateNodePaintMethod() override;
60 
61     bool OnDirtyLayoutWrapperSwap(
62         const RefPtr<LayoutWrapper>& dirty, bool /*skipMeasure*/, bool /*skipLayout*/) override;
63 
CreateEventHub()64     RefPtr<EventHub> CreateEventHub() override
65     {
66         return MakeRefPtr<CheckBoxEventHub>();
67     }
68 
CreateAccessibilityProperty()69     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
70     {
71         return MakeRefPtr<CheckBoxAccessibilityProperty>();
72     }
73 
GetPreName()74     const std::optional<std::string>& GetPreName()
75     {
76         return preName_;
77     }
78 
GetPreGroup()79     const std::optional<std::string>& GetPreGroup()
80     {
81         return preGroup_;
82     }
83 
GetPrePageId()84     int32_t GetPrePageId() const
85     {
86         return prePageId_;
87     }
88 
SetPreName(const std::string & name)89     void SetPreName(const std::string& name)
90     {
91         preName_ = name;
92     }
93 
SetPreGroup(const std::string & group)94     void SetPreGroup(const std::string& group)
95     {
96         preGroup_ = group;
97     }
98 
SetPrePageId(int32_t pageId)99     void SetPrePageId(int32_t pageId)
100     {
101         prePageId_ = pageId;
102     }
103 
104     void MarkIsSelected(bool isSelected);
SetLastSelect(bool select)105     void SetLastSelect(bool select)
106     {
107         lastSelect_ = select;
108     }
109 
110     void SetBuilderFunc(CheckBoxMakeCallback&& makeFunc);
111 
GetContentModifierNode()112     RefPtr<FrameNode> GetContentModifierNode()
113     {
114         return contentModifierNode_;
115     }
116 
117     void SetToggleBuilderFunc(SwitchMakeCallback&& toggleMakeFunc);
118 
UseContentModifier()119     bool UseContentModifier()
120     {
121         return contentModifierNode_ != nullptr;
122     }
123 
124     void SetCheckBoxSelect(bool value);
125 
SetIsUserSetResponseRegion(bool isUserSetResponseRegion)126     void SetIsUserSetResponseRegion(bool isUserSetResponseRegion)
127     {
128         isUserSetResponseRegion_ = isUserSetResponseRegion;
129     }
130 
SetIndicatorBuilder(const std::optional<std::function<void ()>> & buildFunc)131     void SetIndicatorBuilder(const std::optional<std::function<void()>>& buildFunc)
132     {
133         builder_ = buildFunc;
134     }
135 
136     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
137 
138     void ToTreeJson(std::unique_ptr<JsonValue>& json, const InspectorConfig& config) const override;
139 
SetOriginalCheckboxStyle(OriginalCheckBoxStyle style)140     void SetOriginalCheckboxStyle(OriginalCheckBoxStyle style)
141     {
142         originalStyle_ = style;
143     }
144 
GetOriginalCheckboxStyle()145     OriginalCheckBoxStyle GetOriginalCheckboxStyle()
146     {
147         return originalStyle_;
148     }
149 
150     FocusPattern GetFocusPattern() const override;
151     void UpdateUIStatus(bool check);
152 
153     std::string ProvideRestoreInfo() override;
154     void OnRestoreInfo(const std::string& restoreInfo) override;
155     void OnColorConfigurationUpdate() override;
156     void OnAttachToMainTree() override;
157     void StartCustomNodeAnimation(bool select);
158     RefPtr<GroupManager> GetGroupManager();
159 
SaveCheckboxSettingData(const CheckboxSettingData & checkboxSettingData)160     void SaveCheckboxSettingData(const CheckboxSettingData& checkboxSettingData)
161     {
162         checkboxSettingData_ = checkboxSettingData;
163     }
164 
165     bool OnThemeScopeUpdate(int32_t themeScopeId) override;
166 
167 private:
168     void OnAttachToFrameNode() override;
169     void OnDetachFromFrameNode(FrameNode* frameNode) override;
170     void OnModifyDone() override;
171     void OnAfterModifyDone() override;
172     void InitClickEvent();
173     void InitTouchEvent();
174     void InitMouseEvent();
175     void InitFocusEvent();
176     void OnClick();
177     void OnTouchDown();
178     void OnTouchUp();
179     void HandleMouseEvent(bool isHover);
180     void HandleFocusEvent();
181     void HandleBlurEvent();
182     void AddIsFocusActiveUpdateEvent();
183     void RemoveIsFocusActiveUpdateEvent();
184     void OnIsFocusActiveUpdate(bool isFocusAcitve);
185     void CheckPageNode();
186     void LoadBuilder();
187     void UpdateIndicator();
188     void SetBuilderNodeHidden();
189     void StartEnterAnimation();
190     void StartExitAnimation();
191     void UpdateState();
192     void UpdateUnSelect();
193     void CheckBoxGroupIsTrue();
194     void SetPrePageIdToLastPageId();
195     // Init key event
196     void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub);
197     bool IsSquareStyleBox();
198     bool OnKeyEvent(const KeyEvent& event);
199     void GetInnerFocusPaintRect(RoundRect& paintRect);
200     void AddHotZoneRect();
201     void RemoveLastHotZoneRect() const;
202     void SetAccessibilityAction();
203     void UpdateSelectStatus(bool isSelected);
204     void ChangeSelfStatusAndNotify(const RefPtr<CheckBoxPaintProperty>& paintProperty);
205     void ChangeGroupStatusAndNotify(const RefPtr<FrameNode>& checkBoxGroupNode, const std::vector<std::string>& vec,
206         bool haveCheckBoxSelected, bool isAllCheckBoxSelected);
207     std::string GetGroupNameWithNavId();
208     void FireBuilder();
209     RefPtr<FrameNode> BuildContentModifierNode();
210     void InitCheckBoxStatusByGroup(RefPtr<FrameNode> checkBoxGroupNode,
211         const RefPtr<CheckBoxGroupPaintProperty>& groupPaintProperty, const std::list<RefPtr<FrameNode>>& list);
212     void UpdateCheckBoxGroupStatus(RefPtr<FrameNode> checkBoxGroupNode, const std::list<RefPtr<FrameNode>>& list);
213     void UpdatePaintPropertyBySettingData(RefPtr<CheckBoxPaintProperty> paintProp);
214 
215     CheckboxSettingData checkboxSettingData_;
216 
217     std::optional<CheckBoxMakeCallback> makeFunc_;
218     std::optional<SwitchMakeCallback> toggleMakeFunc_;
219     RefPtr<FrameNode> contentModifierNode_;
220     std::optional<std::string> preName_;
221     std::optional<std::string> preGroup_;
222     int32_t prePageId_ = 0;
223     bool lastSelect_ = false;
224     std::optional<std::string> currentNavId_ = std::nullopt;
225 
226     RefPtr<ClickEvent> clickListener_;
227     RefPtr<TouchEventImpl> touchListener_;
228     RefPtr<InputEvent> mouseEvent_;
229     bool isTouch_ = false;
230     bool isHover_ = false;
231     bool isFirstCreated_ = true;
232     bool isUserSetResponseRegion_ = false;
233     bool focusEventInitialized_ = false;
234     UIStatus uiStatus_ = UIStatus::UNSELECTED;
235     Dimension hotZoneHorizontalPadding_;
236     Dimension hotZoneVerticalPadding_;
237     OffsetF offset_;
238     SizeF size_;
239     OffsetF hotZoneOffset_;
240     SizeF hotZoneSize_;
241     TouchHoverAnimationType touchHoverType_ = TouchHoverAnimationType::NONE;
242     OriginalCheckBoxStyle originalStyle_ = OriginalCheckBoxStyle::CIRCULAR_STYLE;
243     RefPtr<FrameNode> builderNode_;
244     std::optional<std::function<void()>> builder_;
245     std::function<void(bool)> isFocusActiveUpdateEvent_;
246 
247     RefPtr<CheckBoxPaintMethod> paintMethod_;
248     WeakPtr<GroupManager> groupManager_;
249     ACE_DISALLOW_COPY_AND_MOVE(CheckBoxPattern);
250 };
251 } // namespace OHOS::Ace::NG
252 
253 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CHECKBOX_CHECKBOX_PATTERN_H
254