• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_PICKER_PICKER_BASE_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_BASE_COMPONENT_H
18 
19 #include "base/utils/system_properties.h"
20 #include "core/accessibility/accessibility_manager.h"
21 #include "core/common/container.h"
22 #include "core/components/checkable/checkable_component.h"
23 #include "core/components/common/rotation/rotation_controller.h"
24 #include "core/components/dialog/dialog_component.h"
25 #include "core/components/picker/picker_animation_controller.h"
26 #include "core/components/picker/picker_column_component.h"
27 #include "core/components/picker/picker_data.h"
28 #include "core/components/stack/stack_element.h"
29 #include "core/components/text/text_component.h"
30 #include "core/event/back_end_event_manager.h"
31 #include "core/pipeline/base/sole_child_component.h"
32 #include "core/components_v2/common/common_def.h"
33 
34 namespace OHOS::Ace {
35 
36 class ACE_EXPORT DatePickerChangeEvent : public BaseEventInfo {
37     DECLARE_RELATIONSHIP_OF_CLASSES(DatePickerChangeEvent, BaseEventInfo);
38 
39 public:
DatePickerChangeEvent(const std::string & str)40     explicit DatePickerChangeEvent(const std::string& str) : BaseEventInfo
41         ("DatePickerChangeEvent"), selectedStr_(str) {}
42     ~DatePickerChangeEvent() = default;
43 
GetSelectedStr()44     const std::string& GetSelectedStr() const
45     {
46         return selectedStr_;
47     }
48 
49 private:
50     std::string selectedStr_;
51 };
52 
53 class ACE_EXPORT PickerBaseComponent : public SoleChildComponent {
54     DECLARE_ACE_TYPE(PickerBaseComponent, SoleChildComponent);
55 
56 public:
PickerBaseComponent()57     PickerBaseComponent() : rotationController_(AceType::MakeRefPtr<RotationController>()) {}
58     ~PickerBaseComponent() override = default;
59 
60     RefPtr<RenderNode> CreateRenderNode() override;
61     RefPtr<Element> CreateElement() override;
62 
63     void Initialize(const RefPtr<AccessibilityManager>& accessibilityManager, const RefPtr<ThemeManager>& themeManager);
64 
SetDialogName(const std::string & dialogName)65     void SetDialogName(const std::string& dialogName)
66     {
67         dialogInsprctorTag_ = dialogName;
68     }
69 
GetDialogName()70     const std::string& GetDialogName()
71     {
72         return dialogInsprctorTag_;
73     }
74 
GetHasTitle()75     bool GetHasTitle() const
76     {
77         return hasTitle_;
78     }
SetHasTitle(bool value)79     void SetHasTitle(bool value)
80     {
81         hasTitle_ = (!subsidiary_ && value);
82     }
83 
GetHasLunar()84     bool GetHasLunar() const
85     {
86         return hasLunar_;
87     }
SetHasLunar(bool value)88     void SetHasLunar(bool value)
89     {
90         hasLunar_ = SystemProperties::GetDeviceType() == DeviceType::PHONE && value;
91     }
92 
GetHasButtons()93     bool GetHasButtons() const
94     {
95         return hasButtons_;
96     }
SetHasButtons(bool value)97     void SetHasButtons(bool value)
98     {
99         hasButtons_ = (!subsidiary_ && value);
100     }
101 
GetHasTriangle()102     bool GetHasTriangle() const
103     {
104         return hasTriangle_;
105     }
SetHasTriangle(bool value)106     void SetHasTriangle(bool value)
107     {
108         hasTriangle_ = value;
109     }
110 
GetIsDialog()111     bool GetIsDialog() const
112     {
113         return isDialog_;
114     }
SetIsDialog(bool value)115     void SetIsDialog(bool value)
116     {
117         isDialog_ = value;
118     }
119 
GetIsCreateDialogComponent()120     bool GetIsCreateDialogComponent() const
121     {
122         return isCreateDialogComponent_;
123     }
SetIsCreateDialogComponent(bool value)124     void SetIsCreateDialogComponent(bool value)
125     {
126         isCreateDialogComponent_ = value;
127     }
128 
GetSubsidiary()129     bool GetSubsidiary() const
130     {
131         return subsidiary_;
132     }
SetSubsidiary(bool value)133     void SetSubsidiary(bool value)
134     {
135         subsidiary_ = value;
136     }
137 
GetMasterHasLunar()138     bool GetMasterHasLunar() const
139     {
140         return masterHasLunar_;
141     }
SetMasterHasLunar(bool value)142     void SetMasterHasLunar(bool value)
143     {
144         masterHasLunar_ = value;
145     }
146 
GetOnChange()147     const EventMarker& GetOnChange() const
148     {
149         return onChange_;
150     }
SetOnChange(const EventMarker & value)151     void SetOnChange(const EventMarker& value)
152     {
153         onChange_ = value;
154     }
155 
GetOnColumnChange()156     const EventMarker& GetOnColumnChange() const
157     {
158         return onColumnChange_;
159     }
SetOnColumnChange(const EventMarker & value)160     void SetOnColumnChange(const EventMarker& value)
161     {
162         onColumnChange_ = value;
163     }
164 
GetOnCancel()165     const EventMarker& GetOnCancel() const
166     {
167         return onCancel_;
168     }
SetOnCancel(const EventMarker & value)169     void SetOnCancel(const EventMarker& value)
170     {
171         onCancel_ = value;
172     }
173 
GetDialogAcceptEvent()174     const EventMarker& GetDialogAcceptEvent() const
175     {
176         return OnDialogAccept_;
177     }
SetDialogAcceptEvent(const EventMarker & value)178     void SetDialogAcceptEvent(const EventMarker& value)
179     {
180         OnDialogAccept_ = value;
181     }
182 
GetDialogCancelEvent()183     const EventMarker& GetDialogCancelEvent() const
184     {
185         return OnDialogCancel_;
186     }
SetDialogCancelEvent(const EventMarker & value)187     void SetDialogCancelEvent(const EventMarker& value)
188     {
189         OnDialogCancel_ = value;
190     }
191 
GetDialogChangeEvent()192     const EventMarker& GetDialogChangeEvent() const
193     {
194         return OnDialogChange_;
195     }
SetDialogChangeEvent(const EventMarker & value)196     void SetDialogChangeEvent(const EventMarker& value)
197     {
198         OnDialogChange_ = value;
199     }
200 
GetDialogEnterSelectedAreaEvent()201     const EventMarker& GetDialogEnterSelectedAreaEvent() const
202     {
203         return OnDialogEnterSelectedArea_;
204     }
SetDialogEnterSelectedAreaEvent(const EventMarker & value)205     void SetDialogEnterSelectedAreaEvent(const EventMarker& value)
206     {
207         OnDialogEnterSelectedArea_ = value;
208     }
209 
210     void ClearColumns();
211 
212     void AppendColumn(const RefPtr<PickerColumnComponent>& column);
213 
214     RefPtr<PickerColumnComponent> GetColumn(const std::string& tag) const;
215 
GetColumnCount()216     virtual uint32_t GetColumnCount() const
217     {
218         return columns_.size();
219     }
220 
221     void RemoveColumn(const std::string& tag);
222 
223     void SetFinishCallback(const ColumnFinishCallback& value);
224 
225     void SetChangeCallback(const ColumnChangeCallback& value);
226 
GetTheme()227     const RefPtr<PickerTheme>& GetTheme() const
228     {
229         return theme_;
230     }
SetTheme(const RefPtr<PickerTheme> & value)231     void SetTheme(const RefPtr<PickerTheme>& value)
232     {
233         theme_ = value;
234     }
235 
236 
GetAnimationController()237     const RefPtr<PickerAnimationController>& GetAnimationController() const
238     {
239         return animationController_;
240     }
241 
SetAnimationController(const RefPtr<PickerAnimationController> & value)242     void SetAnimationController(const RefPtr<PickerAnimationController>& value)
243     {
244         animationController_ = value;
245     }
246 
GetTitle()247     const RefPtr<TextComponent>& GetTitle() const
248     {
249         return title_;
250     }
251 
GetLunar()252     const RefPtr<CheckboxComponent>& GetLunar() const
253     {
254         return lunar_;
255     }
256 
GetNodeId()257     int32_t GetNodeId() const
258     {
259         return nodeId_;
260     }
261 
SetNodeId(int32_t value)262     void SetNodeId(int32_t value)
263     {
264         if (!GetIsDialog()) {
265             nodeId_ = value;
266         }
267     }
268 
GetColumnHeight()269     const Dimension& GetColumnHeight() const
270     {
271         return columnHeight_;
272     }
SetColumnHeight(const Dimension & value)273     void SetColumnHeight(const Dimension& value)
274     {
275         columnHeight_ = value;
276     }
277 
GetDefaultHeight()278     bool GetDefaultHeight() const
279     {
280         return defaultHeight_;
281     }
282 
SetDefaultHeight(bool value)283     void SetDefaultHeight(bool value)
284     {
285         defaultHeight_ = value;
286     }
287 
GetStack()288     const RefPtr<StackElement>& GetStack()
289     {
290         return stack_;
291     }
292 
293     void ShowDialog(const RefPtr<StackElement>& stack, bool disableTouchEvent = true);
294     bool HideDialog();
295     void OpenDialog(const DialogProperties& properties);
296     void CloseDialog();
297 
IsDialogShowed()298     bool IsDialogShowed()
299     {
300         return dialogShowed_;
301     }
302 
GetLunarAccessibility()303     const RefPtr<AccessibilityNode>& GetLunarAccessibility() const
304     {
305         return lunarAccessibility_;
306     }
307 
GetSwitchAccessibility()308     const RefPtr<AccessibilityNode>& GetSwitchAccessibility() const
309     {
310         return switchAccessibility_;
311     }
312 
GetTitleAccessibility()313     const RefPtr<AccessibilityNode>& GetTitleAccessibility() const
314     {
315         return titleAccessibility_;
316     }
317 
GetCancelAccessibility()318     const RefPtr<AccessibilityNode>& GetCancelAccessibility() const
319     {
320         return cancelAccessibility_;
321     }
322 
GetOkAccessibility()323     const RefPtr<AccessibilityNode>& GetOkAccessibility() const
324     {
325         return okAccessibility_;
326     }
327 
328     // used for inspector node in PC preview
GetPickerDialogAccessibility()329     const RefPtr<AccessibilityNode>& GetPickerDialogAccessibility() const
330     {
331         return rootAccessibility_;
332     }
333 
SubsidiaryShowed()334     virtual bool SubsidiaryShowed() const
335     {
336         return false;
337     }
338 
NeedRtlColumnOrder()339     virtual bool NeedRtlColumnOrder() const
340     {
341         return true;
342     }
343 
IsShowLunar()344     virtual bool IsShowLunar() const
345     {
346         return false;
347     }
348 
349     virtual void OnTitleBuilding();
350 
OnColumnsCreating()351     virtual void OnColumnsCreating() {}
352 
OnColumnsBuilding()353     virtual void OnColumnsBuilding() {}
354 
355     virtual std::string GetSelectedObject(bool isColumnChange,
356         const std::string& changeColumnTag, int32_t status = -1) const
357     {
358         return "{}";
359     }
360 
OnSelectedSaving()361     virtual void OnSelectedSaving() {}
362 
OnDataLinking(const std::string & tag,bool isAdd,uint32_t index,std::vector<std::string> & resultTags)363     virtual void OnDataLinking(const std::string& tag, bool isAdd, uint32_t index, std::vector<std::string>& resultTags)
364     {}
365 
OnLunarCallback(bool checked,std::vector<std::string> & resultTags)366     virtual void OnLunarCallback(bool checked, std::vector<std::string>& resultTags) {}
OnTriangleCallback(bool value)367     virtual void OnTriangleCallback(bool value) {}
OnAnimationPlaying()368     virtual void OnAnimationPlaying() {}
369 
GetRotationController()370     const RefPtr<RotationController>& GetRotationController() const
371     {
372         return rotationController_;
373     }
374 
GetOnCancelClickId()375     const EventMarker& GetOnCancelClickId() const
376     {
377         return onCancelClickId_;
378     }
379 
GetOnOkClickId()380     const EventMarker& GetOnOkClickId() const
381     {
382         return onOkClickId_;
383     }
384 
385     // used for inspector node in PC preview
SetPickerBaseId(const int32_t nodeId)386     void SetPickerBaseId(const int32_t nodeId)
387     {
388         pickerId_ = nodeId;
389     }
390 
391     // used for inspector node in PC preview
GetPickerBaseId()392     int32_t GetPickerBaseId() const
393     {
394         return pickerId_;
395     }
396 
397     ACE_DEFINE_COMPONENT_EVENT(OnTextCancel, void(void));
398     ACE_DEFINE_COMPONENT_EVENT(OnTextAccept, void(const std::string&, double));
399     ACE_DEFINE_COMPONENT_EVENT(OnTextChange, void(const std::string&, double));
400 
401     void SetNeedVibrate(bool needVibrate);
402 
GetNeedVibrate()403     bool GetNeedVibrate()
404     {
405         return needVibrate_;
406     }
407 
GetHasBackgroundColor()408     bool GetHasBackgroundColor() const
409     {
410         return hasBackgroundColor_;
411     }
SetHasBackgroundColor(bool value)412     void SetHasBackgroundColor(bool value)
413     {
414         hasBackgroundColor_ = value;
415     }
416 
417     static const char PICKER_YEAR_COLUMN[];
418     static const char PICKER_MONTH_COLUMN[];
419     static const char PICKER_DAY_COLUMN[];
420     static const char PICKER_HOUR_COLUMN[];
421     static const char PICKER_MINUTE_COLUMN[];
422     static const char PICKER_SECOND_COLUMN[];
423     static const char PICKER_TEXT_COLUMN[];
424     static const char PICKER_MONTHDAY_COLUMN[];
425     static const char PICKER_AMPM_COLUMN[];
426 
427 private:
428     void InitializeTitle(std::list<RefPtr<Component>>& outChildren);
429 
430     void InitializeColumns(
431         std::list<RefPtr<Component>>& outChildren, const RefPtr<AccessibilityManager>& accessibilityManager);
432 
433     void InitializeChildAccessibility(const RefPtr<AccessibilityManager>& accessibilityManager);
434 
435     void ClearAccessibilityNodes();
436 
437     RefPtr<Component> GenerateAccessibilityComposed(
438         const std::string& name, const RefPtr<Component>& child, RefPtr<AccessibilityNode>& node);
439 
440     void InitializeLunar(std::list<RefPtr<Component>>& outChildren, const RefPtr<ThemeManager>& themeManager);
441 
442     void InitializeButtons(std::list<RefPtr<Component>>& outChildren, const RefPtr<ThemeManager>& themeManager);
443 
444     void InitializeContainer(const std::list<RefPtr<Component>>& outChildren);
445 
446     bool dialogShowed_ = false;
447     bool hasTitle_ = false;
448     bool hasLunar_ = false;
449     bool hasButtons_ = false;
450     bool hasTriangle_ = false;
451     bool isDialog_ = true;
452     bool subsidiary_ = false;
453     bool masterHasLunar_ = false;
454     bool needVibrate_ = true;
455     bool isCreateDialogComponent_ = false;
456     bool hasBackgroundColor_ = false;
457     int32_t nodeId_ = -1; // default of dialog's node id.
458     // used for inspector node in PC preview
459     int32_t pickerId_ = -1;
460 
461     RefPtr<PickerTheme> theme_;
462     RefPtr<StackElement> stack_;
463 
464     RefPtr<TextComponent> title_ = AceType::MakeRefPtr<TextComponent>("");
465     RefPtr<CheckboxComponent> lunar_;
466     std::vector<RefPtr<PickerColumnComponent>> columns_;
467     WeakPtr<AccessibilityManager> accessibilityManager_;
468     int32_t rootAccessibilityId_ = -1;
469     RefPtr<AccessibilityNode> rootAccessibility_;
470     RefPtr<AccessibilityNode> titleAccessibility_;
471     RefPtr<AccessibilityNode> lunarAccessibility_;
472     RefPtr<AccessibilityNode> switchAccessibility_;
473     RefPtr<AccessibilityNode> cancelAccessibility_;
474     RefPtr<AccessibilityNode> okAccessibility_;
475 
476     EventMarker onChange_;
477     EventMarker onColumnChange_;
478     EventMarker onCancel_;
479     EventMarker onOkClickId_ = BackEndEventManager<void()>::GetInstance().GetAvailableMarker();
480     EventMarker onCancelClickId_ = BackEndEventManager<void()>::GetInstance().GetAvailableMarker();
481     EventMarker OnDialogAccept_;
482     EventMarker OnDialogCancel_;
483     EventMarker OnDialogChange_;
484     EventMarker OnDialogEnterSelectedArea_;
485 
486     Dimension columnHeight_;
487     bool defaultHeight_ = false;
488 
489     RefPtr<RotationController> rotationController_;
490 
491     RefPtr<PickerAnimationController> animationController_;
492     RefPtr<DialogComponent> dialogComponent_;
493     std::string dialogInsprctorTag_;
494 };
495 
496 } // namespace OHOS::Ace
497 
498 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_BASE_COMPONENT_H
499