• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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_PATTERN_CALENDAR_CALENDAR_MONTH_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CALENDAR_CALENDAR_MONTH_PATTERN_H
18 
19 #include <optional>
20 
21 #include "base/geometry/axis.h"
22 #include "base/memory/referenced.h"
23 #include "core/components/calendar/calendar_data_adapter.h"
24 #include "core/components/picker/picker_data.h"
25 #include "core/components/common/layout/constants.h"
26 #include "core/components_ng/pattern/calendar/calendar_event_hub.h"
27 #include "core/components_ng/pattern/calendar/calendar_layout_algorithm.h"
28 #include "core/components_ng/pattern/calendar/calendar_paint_property.h"
29 #include "core/components_ng/pattern/pattern.h"
30 #include "core/components_ng/render/paint_property.h"
31 
32 namespace OHOS::Ace::NG {
33 
34 class CalendarMonthPattern : public Pattern {
35     DECLARE_ACE_TYPE(CalendarMonthPattern, Pattern);
36 
37 public:
38     CalendarMonthPattern() = default;
39     ~CalendarMonthPattern() override;
40 
CreatePaintProperty()41     RefPtr<PaintProperty> CreatePaintProperty() override
42     {
43         return MakeRefPtr<CalendarPaintProperty>();
44     }
45 
CreateEventHub()46     RefPtr<EventHub> CreateEventHub() override
47     {
48         return MakeRefPtr<CalendarEventHub>();
49     }
50 
CreateLayoutAlgorithm()51     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
52     {
53         return MakeRefPtr<CalendarLayoutAlgorithm>();
54     }
55 
56     RefPtr<NodePaintMethod> CreateNodePaintMethod() override;
57 
GetMonthData()58     const ObtainedMonth& GetMonthData() const
59     {
60         return obtainedMonth_;
61     }
62 
SetMonthData(const ObtainedMonth & obtainedMonth,MonthState monthState)63     void SetMonthData(const ObtainedMonth& obtainedMonth, MonthState monthState)
64     {
65         obtainedMonth_ = obtainedMonth;
66         monthState_ = monthState;
67     }
68 
GetCalendarDay()69     const CalendarDay& GetCalendarDay() const
70     {
71         return calendarDay_;
72     }
73 
74     void SetCalendarDay(const CalendarDay& calendarDay);
75 
SetStartDate(const PickerDate & startDate)76     void SetStartDate(const PickerDate& startDate)
77     {
78         startDate_ = startDate;
79     }
80 
SetEndDate(const PickerDate & endDate)81     void SetEndDate(const PickerDate& endDate)
82     {
83         endDate_ = endDate;
84     }
85 
SetMarkToday(bool markToday)86     void SetMarkToday(bool markToday)
87     {
88         markToday_ = markToday;
89     }
90 
SetDisabledDateRange(const std::vector<std::pair<PickerDate,PickerDate>> & disabledDateRange)91     void SetDisabledDateRange(const std::vector<std::pair<PickerDate, PickerDate>>& disabledDateRange)
92     {
93         disabledDateRange_ = disabledDateRange;
94     }
95 
IsCalendarDialog()96     bool IsCalendarDialog() const
97     {
98         return isCalendarDialog_;
99     }
100 
SetCalendarDialogFlag(bool isCalendarDialog)101     void SetCalendarDialogFlag(bool isCalendarDialog)
102     {
103         isCalendarDialog_ = isCalendarDialog;
104     }
105 
SetHoverState(bool state)106     void SetHoverState(bool state)
107     {
108         hoverState_ = state;
109     }
110 
GetHoverState()111     bool GetHoverState() const
112     {
113         return hoverState_;
114     }
115 
UpdateColRowSpace()116     void UpdateColRowSpace()
117     {
118         SetColRowSpace();
119     }
120 
SetIsFirstEnter(bool isFirstEnter)121     void SetIsFirstEnter(bool isFirstEnter)
122     {
123         isFirstEnter_ = isFirstEnter;
124     }
125 
126     void InitCurrentVirtualNode();
127 
128     void ClearCalendarVirtualNode();
129 
130     void ClearFocusCalendarDay();
131 
132     void BeforeSyncGeometryProperties(const DirtySwapConfig& config) override;
133 
134     Dimension GetDaySize(const RefPtr<CalendarTheme>& theme);
135 
136     bool IsLargeSize(const RefPtr<CalendarTheme>& theme);
137 
138     void InitFoldState();
139 
140     void FireIsFoldStatusChanged();
141 
142 private:
143     void OnAttachToFrameNode() override;
144     void OnColorConfigurationUpdate() override;
145     void OnLanguageConfigurationUpdate() override;
146     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
147     void OnModifyDone() override;
148     void OnClick(Offset& localLocation, const ObtainedMonth& obtainedMonth);
149     void OnTouchEvent(const Offset& localLocation, bool isPressed);
150     void OnHoverEvent(const Offset& localLocation, bool state);
151     void InitClickEvent();
152     void InitTouchEvent();
153     void InitHoverEvent();
154     void SetColRowSpace();
155     int32_t JudgeArea(const Offset& offset);
156     RefPtr<FrameNode> AddButtonNodeIntoVirtual(const CalendarDay& calendarDay);
157     void UpdateAccessibilityButtonNode(RefPtr<FrameNode> frameNode, int32_t index);
158     void UpdateButtonNodeWithoutTheme(RefPtr<FrameNode> frameNode, int32_t index);
159     void ModifyAccessibilityVirtualNode(const ObtainedMonth& currentData);
160     void ChangeVirtualNodeContent(const CalendarDay& calendarDay);
161     bool InitCalendarVirtualNode();
162     void InitVirtualButtonClickEvent(RefPtr<FrameNode> frameNode, int32_t index);
163     void SetVirtualNodeUserSelected(int32_t index);
164     void FireModifyAccessibilityVirtualNode(const ObtainedMonth& currentData);
165     void InitAccessibilityHoverEvent();
166     void HandleAccessibilityHoverEvent(bool state, AccessibilityHoverInfo& info);
167     void SetCalendarAccessibilityLevel(const std::string& level);
168     void InitializeCalendarAccessibility();
169     void ChangeVirtualNodeState(const CalendarDay& calendarDay);
170     void SetLineNodeSize(RefPtr<FrameNode> lineNode);
171     void SetFocusNode(int32_t index, bool isDeviceOrientation = false);
172     float GetWidth(const RefPtr<FrameNode>& host);
173     bool IsDateInRange(const CalendarDay& day);
174     std::string GetDayStr(int32_t index);
175     bool isCalendarDialog_ = false;
176     bool hoverState_ = false;
177     bool isOnHover_ = false;
178     bool isFirstEnter_ = false;
179     int32_t selectedIndex_ = 0;
180     double margin_ = 0;
181     RefPtr<FrameNode> lineNode_;
182     double dayHeight_ = 0;
183     double dayWidth_ = 0;
184     double colSpace_ = 0;
185     DeviceOrientation deviceOrientation_ = DeviceOrientation::ORIENTATION_UNDEFINED;
186     std::string selectedTxt_;
187     std::string disabledDesc_;
188     FoldStatus currentFoldStatus_ = FoldStatus::UNKNOWN;
189     std::vector<RefPtr<AccessibilityProperty>> accessibilityPropertyVec_;
190     std::vector<RefPtr<FrameNode>> buttonAccessibilityNodeVec_;
191     std::shared_ptr<AccessibilitySAObserverCallback> accessibilitySAObserverCallback_;
192     bool isInitVirtualNode_ = false;
193     CalendarDay calendarDay_;
194     PickerDate startDate_;
195     PickerDate endDate_;
196     bool markToday_ = false;
197     std::vector<std::pair<PickerDate, PickerDate>> disabledDateRange_;
198     CalendarDay focusedCalendarDay_;
199     ObtainedMonth obtainedMonth_;
200     MonthState monthState_ = MonthState::CUR_MONTH;
201     RefPtr<ClickEvent> clickListener_;
202     RefPtr<TouchEventImpl> touchListener_;
203     RefPtr<InputEvent> hoverListener_;
204 
205     ACE_DISALLOW_COPY_AND_MOVE(CalendarMonthPattern);
206 };
207 } // namespace OHOS::Ace::NG
208 
209 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CALENDAR_CALENDAR_MONTH_PATTERN_H