• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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_PATTERNS_CALENDAR_PICKER_CALENDAR_DIALOG_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CALENDAR_PICKER_CALENDAR_DIALOG_PATTERN_H
18 
19 #include <optional>
20 
21 #include "core/components/calendar/calendar_data_adapter.h"
22 #include "core/components_ng/pattern/calendar/calendar_pattern.h"
23 #include "core/components_ng/pattern/calendar_picker/calendar_dialog_layout_algorithm.h"
24 #include "core/components_ng/pattern/calendar_picker/calendar_type_define.h"
25 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
26 #include "core/components_ng/pattern/pattern.h"
27 #include "core/components_ng/pattern/swiper/swiper_pattern.h"
28 
29 namespace OHOS::Ace::NG {
30 class CalendarDialogPattern : public LinearLayoutPattern {
31     DECLARE_ACE_TYPE(CalendarDialogPattern, LinearLayoutPattern);
32 
33 public:
CalendarDialogPattern()34     CalendarDialogPattern() : LinearLayoutPattern(true) {};
35     ~CalendarDialogPattern() override = default;
36 
IsAtomicNode()37     bool IsAtomicNode() const override
38     {
39         return true;
40     }
41 
SetEntryNode(const WeakPtr<FrameNode> & node)42     void SetEntryNode(const WeakPtr<FrameNode>& node)
43     {
44         entryNode_ = node;
45     }
46 
GetDialogOffset()47     const OffsetF GetDialogOffset() const
48     {
49         return dialogOffset_;
50     }
51 
CreateLayoutAlgorithm()52     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
53     {
54         return MakeRefPtr<CalendarDialogLayoutAlgorithm>();
55     }
56 
SetDialogOffset(const OffsetF & offset)57     void SetDialogOffset(const OffsetF& offset)
58     {
59         dialogOffset_ = offset;
60     }
61 
OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper> & dirty,bool,bool)62     bool OnDirtyLayoutWrapperSwap(
63         const RefPtr<LayoutWrapper>& dirty, bool /* skipMeasure */, bool /* skipLayout */) override
64     {
65         if (isFirstAddhotZoneRect_) {
66             AddHotZoneRect();
67             isFirstAddhotZoneRect_ = false;
68         }
69         return true;
70     }
71 
72     void HandleClickEvent(const GestureEvent& info);
73 
74     FocusPattern GetFocusPattern() const override;
75 
SetHoverState(bool state)76     void SetHoverState(bool state)
77     {
78         hoverState_ = state;
79     }
80 
GetHoverState()81     bool GetHoverState() const
82     {
83         return hoverState_;
84     }
85 
86     void GetCalendarMonthData(int32_t year, int32_t month, ObtainedMonth& calendarMonthData);
87     CalendarMonth GetNextMonth(const CalendarMonth& calendarMonth);
88     CalendarMonth GetLastMonth(const CalendarMonth& calendarMonth);
89     void SetOptionsButtonUpdateColorFlags(size_t index, bool isUpdate);
90 
SetCurrentButtonInfo(const std::vector<ButtonInfo> & buttonInfos)91     void SetCurrentButtonInfo(const std::vector<ButtonInfo>& buttonInfos)
92     {
93         currentButtonInfos_ = buttonInfos;
94     }
95 
SetCurrentSettingData(const CalendarSettingData & settingData)96     void SetCurrentSettingData(const CalendarSettingData& settingData)
97     {
98         currentSettingData_ = settingData;
99     }
100 
101     void OnColorConfigurationUpdate() override;
102     void OnLanguageConfigurationUpdate() override;
103 
104     void UpdateCaretInfoToController();
105 
HasSurfaceChangedCallback()106     bool HasSurfaceChangedCallback()
107     {
108         return surfaceChangedCallbackId_.has_value();
109     }
110 
UpdateSurfaceChangedCallbackId(int32_t id)111     void UpdateSurfaceChangedCallbackId(int32_t id)
112     {
113         surfaceChangedCallbackId_ = id;
114     }
115 
116     void HandleSurfaceChanged(int32_t newWidth, int32_t newHeight, int32_t prevWidth, int32_t prevHeight);
117 
118     void InitSurfaceChangedCallback();
SetTitleNode(RefPtr<FrameNode> & titleNode)119     inline void SetTitleNode(RefPtr<FrameNode>& titleNode)
120     {
121         titleNode_ = titleNode;
122     }
123 
124     bool CanReportChangeEvent(const PickerDate& pickerDate);
125 
126     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
127 
128 private:
129     void OnModifyDone() override;
130     void InitClickEvent();
131     void InitOnKeyEvent();
132     void InitOnTouchEvent();
133     void InitTitleArrowsEvent();
134     void InitEntryChangeEvent();
135     void InitHoverEvent();
136     void AddHotZoneRect();
137     bool HandleKeyEvent(const KeyEvent& event);
138     void GetInnerFocusPaintRect(RoundRect& paintRect);
139     void PaintFocusState();
140     void HandleTitleArrowsClickEvent(int32_t nodeIndex);
141     void HandleEntryChange(const std::string& info);
142     void HandleEntryLayoutChange();
143     void ClearCalendarFocusedState();
144     bool HandleCalendarNodeKeyEvent(const KeyEvent& event);
145     bool ActClick(int32_t focusAreaID, int32_t focusAreaChildID);
146     void PaintCurrentMonthFocusState();
147     void PaintNonCurrentMonthFocusState(int32_t focusedDayIndex);
148     void ChangeEntryState();
149     void FocusedLastFocusedDay();
150     int32_t GetIndexByFocusedDay();
151     bool HandleTabKeyEvent(const KeyEvent& event);
152     void FireChangeByKeyEvent(PickerDate& selectedDay);
153     bool IsIndexInCurrentMonth(int32_t focusedDayIndex, const ObtainedMonth& currentMonthData);
154     bool IsInEntryRegion(const Offset& globalLocation);
155     void HandleEntryNodeHoverEvent(bool state, const Offset& globalLocation);
156     void HandleEntryNodeTouchEvent(bool isPressed, const Offset& globalLocation);
157     void UpdateDialogBackgroundColor();
158     void UpdateTitleArrowsColor();
159     void UpdateOptionsButtonColor();
160     void OnEnterKeyEvent(const KeyEvent& event);
161     void UpdateTitleArrowsImage();
162     void UpdateImage(const RefPtr<FrameNode>& buttonNode, const InternalResource::ResourceId& resourceId);
163     void UpdateOptionsButton();
164     void UpdateCalendarLayout();
165     void UpdateNonCurrentMonthFocusedDay(int32_t focusedDayIndex);
166     void PaintMonthFocusState(int32_t focusedDayIndex);
167 
168     RefPtr<FrameNode> GetCalendarFrameNode();
169     RefPtr<CalendarPattern> GetCalendarPattern();
170     RefPtr<FrameNode> GetSwiperFrameNode();
171     RefPtr<SwiperPattern> GetSwiperPattern();
172 
173     void UpdateSwiperNode(const ObtainedMonth& monthData, bool isPrev);
174     void UpdateSwiperNodeFocusedDay(const CalendarDay& focusedDay, bool isPrev);
175 
176     int32_t focusAreaID_ = 0;
177     int32_t focusAreaIDWithoutWeek_ = 0;
178     int32_t focusAreaChildID_ = 0;
179     CalendarDay focusedDay_ = { .day = -1 };
180     bool isFirstAddhotZoneRect_ = true;
181     bool isFocused_ = false;
182     bool isCalendarFirstFocused_ = false;
183     bool hoverState_ = false;
184     std::vector<bool> updateColorFlags = {true, true, true, true};
185     OffsetF dialogOffset_;
186     WeakPtr<FrameNode> entryNode_ = nullptr;
187     std::map<int32_t, RefPtr<ClickEvent>> clickEvents_;
188     RefPtr<TouchEventImpl> touchListener_ = nullptr;
189     RefPtr<InputEvent> hoverListener_ = nullptr;
190     ACE_DISALLOW_COPY_AND_MOVE(CalendarDialogPattern);
191     bool hasTabKeyDown_ = false;
192     std::vector<ButtonInfo> currentButtonInfos_;
193     CalendarSettingData currentSettingData_;
194     std::optional<int32_t> surfaceChangedCallbackId_;
195     PickerDate reportedPickerDate_;
196     WeakPtr<FrameNode> titleNode_;
197 };
198 } // namespace OHOS::Ace::NG
199 
200 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CALENDAR_PICKER_CALENDAR_DIALOG_PATTERN_H
201