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_CALENDAR_CALENDAR_ELEMENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_CALENDAR_ELEMENT_H 18 19 #include "core/components/calendar/calendar_component.h" 20 #include "core/components/text/text_element.h" 21 #include "core/pipeline/base/composed_element.h" 22 #include "core/pipeline/base/render_element.h" 23 24 namespace OHOS::Ace { 25 26 class CalendarElement : public ComposedElement, public FocusGroup { 27 DECLARE_ACE_TYPE(CalendarElement, ComposedElement, FocusGroup); 28 29 public: CalendarElement(const ComposeId & id)30 explicit CalendarElement(const ComposeId& id) : ComposedElement(id) {} 31 ~CalendarElement() override = default; 32 33 void PerformBuild() override; RequestNextFocus(bool vertical,bool reverse,const Rect & rect)34 bool RequestNextFocus(bool vertical, bool reverse, const Rect& rect) override 35 { 36 return false; 37 } 38 OnFocus()39 void OnFocus() override 40 { 41 FocusGroup::OnFocus(); 42 if (calendarController_) { 43 calendarController_->NotifyFocusChanged(true); 44 } 45 } 46 OnBlur()47 void OnBlur() override 48 { 49 FocusGroup::OnBlur(); 50 if (calendarController_) { 51 calendarController_->NotifyFocusChanged(false); 52 } 53 } 54 55 void BuildCardCalendar(const RefPtr<CalendarComponent>& calendar, const RefPtr<Element>& element); 56 57 private: 58 void UpdateAttr(const RefPtr<CalendarComponent>& calendar); 59 void SetArrowImage(const RefPtr<Element>& element, bool isLeft); 60 void RegisterChangeEndListener(const RefPtr<CalendarComponent>& calendar, const RefPtr<Element>& element); 61 RefPtr<TextElement> GetTextElement(const RefPtr<Element>& flex); 62 63 RefPtr<CalendarController> calendarController_; 64 RefPtr<RenderSwiper> renderSwiper_; 65 std::function<void(const std::string&)> dateEvent_; 66 }; 67 68 class CalendarMonthElement : public RenderElement, public FocusNode { 69 DECLARE_ACE_TYPE(CalendarMonthElement, RenderElement, FocusNode); 70 71 public: 72 CalendarMonthElement() = default; 73 ~CalendarMonthElement() override = default; 74 75 void Update() override; 76 bool OnKeyEvent(const KeyEvent& keyEvent) override; 77 void OnFocus() override; 78 void OnBlur() override; 79 80 private: 81 bool RequestNextFocus(bool vertical, bool reverse, const Rect& rect); 82 }; 83 84 } // namespace OHOS::Ace 85 86 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_CALENDAR_ELEMENT_H 87