1 /* 2 * Copyright (c) 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_SWIPER_INDICATOR_SWIPER_ARROW_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SWIPER_INDICATOR_SWIPER_ARROW_PATTERN_H 18 19 #include "base/memory/ace_type.h" 20 #include "base/utils/utils.h" 21 #include "core/components_ng/base/frame_node.h" 22 #include "core/components_ng/pattern/button/button_pattern.h" 23 #include "core/components_ng/pattern/pattern.h" 24 #include "core/components_ng/pattern/swiper/swiper_pattern.h" 25 #include "core/components_ng/pattern/swiper_indicator/indicator_common/swiper_arrow_layout_algorithm.h" 26 #include "core/components_ng/pattern/swiper_indicator/indicator_common/swiper_arrow_layout_property.h" 27 28 namespace OHOS::Ace::NG { 29 class SwiperArrowPattern : public Pattern { 30 DECLARE_ACE_TYPE(SwiperArrowPattern, Pattern); 31 32 public: 33 SwiperArrowPattern() = default; 34 ~SwiperArrowPattern() override = default; CreateLayoutProperty()35 RefPtr<LayoutProperty> CreateLayoutProperty() override 36 { 37 return MakeRefPtr<SwiperArrowLayoutProperty>(); 38 } 39 CreateLayoutAlgorithm()40 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 41 { 42 return MakeRefPtr<SwiperArrowLayoutAlgorithm>(); 43 } 44 GetSwiperNode()45 RefPtr<FrameNode> GetSwiperNode() const 46 { 47 auto host = GetHost(); 48 CHECK_NULL_RETURN(host, nullptr); 49 auto swiperNode = host->GetParent(); 50 CHECK_NULL_RETURN(swiperNode, nullptr); 51 return DynamicCast<FrameNode>(swiperNode); 52 } 53 GetFocusPattern()54 FocusPattern GetFocusPattern() const override 55 { 56 auto pipelineContext = PipelineBase::GetCurrentContext(); 57 CHECK_NULL_RETURN(pipelineContext, FocusPattern()); 58 auto swiperTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>(); 59 CHECK_NULL_RETURN(swiperTheme, FocusPattern()); 60 FocusPaintParam paintParam; 61 paintParam.SetPaintColor(swiperTheme->GetFocusedColor()); 62 paintParam.SetPaintWidth(swiperTheme->GetFocusedBorderWidth()); 63 return { FocusType::NODE, true, FocusStyleType::INNER_BORDER, paintParam }; 64 } 65 GetSwiperArrowLayoutProperty()66 RefPtr<SwiperArrowLayoutProperty> GetSwiperArrowLayoutProperty() const 67 { 68 auto host = GetHost(); 69 CHECK_NULL_RETURN(host, nullptr); 70 auto swiperArrowLayoutProperty = host->GetLayoutProperty<SwiperArrowLayoutProperty>(); 71 CHECK_NULL_RETURN(swiperArrowLayoutProperty, nullptr); 72 return swiperArrowLayoutProperty; 73 } 74 75 void ButtonOnHover(RefPtr<FrameNode> buttonNode, bool isHovered); 76 void SetButtonVisible(bool visible); 77 void DumpAdvanceInfo() override; 78 void DumpAdvanceInfo(std::unique_ptr<JsonValue>& json) override; 79 void SetLayoutDisplayCount(int32_t displayCount); 80 81 private: 82 std::tuple<bool, bool, bool> CheckHoverStatus(); 83 void OnModifyDone() override; 84 void InitNavigationArrow(); 85 void InitSwiperChangeEvent(const RefPtr<SwiperEventHub>& swiperEventHub); 86 void InitEvent(); 87 void UpdateButtonNode(int32_t index); 88 void ButtonTouchEvent(RefPtr<FrameNode> buttonNode, TouchType touchType); 89 void ButtonClickEvent(); 90 void UpdateArrowContent(); 91 void InitOnKeyEvent(); 92 bool OnKeyEvent(const KeyEvent& event); 93 void OnClick() const; 94 void InitAccessibilityText(); 95 int32_t TotalCount() const; 96 RefPtr<SwiperPattern> GetSwiperPattern() const; 97 98 RefPtr<ClickEvent> buttonClickListener_; 99 RefPtr<ClickEvent> arrowClickListener_; 100 RefPtr<TouchEventImpl> buttonTouchListener_; 101 RefPtr<InputEvent> buttonOnHoverListener_; 102 std::shared_ptr<ChangeEvent> swiperChangeEvent_; 103 104 int32_t index_ = 0; 105 int32_t displayCount_ = 1; 106 bool isFirstCreate_ = true; 107 Color hoverBeginColor_ = Color::TRANSPARENT; 108 Color backgroundColor_ = Color::TRANSPARENT; 109 bool isTouch_ = false; 110 bool isHover_ = false; 111 bool isVisible_ = false; 112 bool hoverOnClickFlag_ = false; 113 ACE_DISALLOW_COPY_AND_MOVE(SwiperArrowPattern); 114 void UpdateArrowContentByImage(RefPtr<FrameNode>& buttonNode, 115 RefPtr<SwiperArrowLayoutProperty>& swiperArrowLayoutProperty); 116 void UpdateArrowContentBySymbol(RefPtr<FrameNode>& buttonNode, 117 RefPtr<SwiperArrowLayoutProperty>& swiperArrowLayoutProperty); 118 }; 119 } // namespace OHOS::Ace::NG 120 121 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SWIPER_INDICATOR_SWIPER_ARROW_PATTERN_H 122