• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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_SLIDER_SLIDER_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SLIDER_SLIDER_PATTERN_H
18 
19 #include <cstddef>
20 
21 #include "core/components_ng/pattern/pattern.h"
22 #include "core/components_ng/pattern/slider/slider_event_hub.h"
23 #include "core/components_ng/pattern/slider/slider_layout_algorithm.h"
24 #include "core/components_ng/pattern/slider/slider_layout_property.h"
25 #include "core/components_ng/pattern/slider/slider_paint_method.h"
26 #include "core/components_ng/pattern/slider/slider_paint_property.h"
27 
28 namespace OHOS::Ace::NG {
29 class SliderPattern : public Pattern {
30     DECLARE_ACE_TYPE(SliderPattern, Pattern);
31 
32 public:
33     SliderPattern() = default;
34     ~SliderPattern() override = default;
35 
CreateNodePaintMethod()36     RefPtr<NodePaintMethod> CreateNodePaintMethod() override
37     {
38         auto visibility = GetLayoutProperty<LayoutProperty>()->GetVisibility().value_or(VisibleType::VISIBLE);
39         if (visibility == VisibleType::GONE) {
40             return MakeRefPtr<NodePaintMethod>();
41         }
42 
43         auto paintParameters = UpdateContentParameters();
44         if (!sliderContentModifier_) {
45             sliderContentModifier_ = AceType::MakeRefPtr<SliderContentModifier>(paintParameters);
46         }
47         SliderPaintMethod::TipParameters tipParameters { bubbleSize_, bubbleOffset_, textOffset_, bubbleFlag_ };
48         if (!sliderTipModifier_ && bubbleFlag_) {
49             sliderTipModifier_ = AceType::MakeRefPtr<SliderTipModifier>();
50         }
51         return MakeRefPtr<SliderPaintMethod>(sliderContentModifier_, paintParameters, sliderLength_, borderBlank_,
52             sliderTipModifier_, paragraph_, tipParameters);
53     }
54 
CreateLayoutProperty()55     RefPtr<LayoutProperty> CreateLayoutProperty() override
56     {
57         return MakeRefPtr<SliderLayoutProperty>();
58     }
59 
CreatePaintProperty()60     RefPtr<PaintProperty> CreatePaintProperty() override
61     {
62         return MakeRefPtr<SliderPaintProperty>();
63     }
64 
CreateLayoutAlgorithm()65     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
66     {
67         return MakeRefPtr<SliderLayoutAlgorithm>();
68     }
69 
70     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override;
71 
CreateEventHub()72     RefPtr<EventHub> CreateEventHub() override
73     {
74         return MakeRefPtr<SliderEventHub>();
75     }
76 
GetFocusPattern()77     FocusPattern GetFocusPattern() const override
78     {
79         return { FocusType::NODE, true, FocusStyleType::CUSTOM_REGION };
80     }
81 
82 private:
83     void OnModifyDone() override;
84     void CancelExceptionValue(float& min, float& max, float& step);
85     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, bool skipMeasure, bool skipLayout) override;
86 
87     void CreateParagraphFunc();
88     void CreateParagraphAndLayout(
89         const TextStyle& textStyle, const std::string& content, const LayoutConstraintF& contentConstraint);
90     bool CreateParagraph(const TextStyle& textStyle, std::string content);
91     void UpdateCircleCenterOffset();
92     void UpdateTipsValue();
93     void UpdateBubbleSizeAndLayout();
94     void UpdateBubble();
95     void InitializeBubble();
96 
97     void UpdateMarkDirtyNode(const PropertyChangeFlag& Flag);
98     Axis GetDirection() const;
99 
100     void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub);
101     void HandleTouchEvent(const TouchEventInfo& info);
102     void InitClickEvent(const RefPtr<GestureEventHub>& gestureHub);
103     void HandleClickEvent();
104     void InitMouseEvent(const RefPtr<InputEventHub>& inputEventHub);
105     void HandleMouseEvent(const MouseInfo& info);
106     void HandleHoverEvent(bool isHover);
107     void InitPanEvent(const RefPtr<GestureEventHub>& gestureHub);
108     void HandlingGestureEvent(const GestureEvent& info);
109     void HandledGestureEvent();
110 
111     void UpdateValueByLocalLocation(const std::optional<Offset>& localLocation);
112     void FireChangeEvent(int32_t mode);
113 
114     void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub);
115     void GetInnerFocusPaintRect(RoundRect& paintRect);
116     void GetOutsetInnerFocusPaintRect(RoundRect& paintRect);
117     void GetInsetInnerFocusPaintRect(RoundRect& paintRect);
118     bool OnKeyEvent(const KeyEvent& event);
119     void PaintFocusState();
120     bool MoveStep(int32_t stepCount);
121 
122     void OpenTranslateAnimation();
123     void CloseTranslateAnimation();
124     SliderContentModifier::Parameters UpdateContentParameters();
125     void GetSelectPosition(SliderContentModifier::Parameters& parameters, float centerWidth, const OffsetF& offset);
126     void GetBackgroundPosition(SliderContentModifier::Parameters& parameters, float centerWidth, const OffsetF& offset);
127     void GetCirclePosition(SliderContentModifier::Parameters& parameters, float centerWidth, const OffsetF& offset);
128 
129     Axis direction_ = Axis::HORIZONTAL;
130     enum SliderChangeMode { Begin = 0, Moving = 1, End = 2, Click = 3 };
131     float value_ = 0.0f;
132     bool showTips_ = false;
133     bool hotFlag_ = false;
134     bool valueChangeFlag_ = false;
135     bool mouseHoverFlag_ = false;
136     bool mousePressedFlag_ = false;
137 
138     float stepRatio_ = 1.0f / 100.0f;
139     float valueRatio_ = 0.0f;
140     float sliderLength_ = 0.0f;
141     float borderBlank_ = 0.0f;
142     float hotBlockShadowWidth_ = 0.0f;
143     OffsetF circleCenter_ = { 0, 0 };
144 
145     float trackThickness_ = 0.0f;
146     float blockDiameter_ = 0.0f;
147     float blockHotSize_ = 0.0f;
148 
149     RefPtr<TouchEventImpl> touchEvent_;
150     RefPtr<ClickEvent> clickListener_;
151     RefPtr<PanEvent> panEvent_;
152     RefPtr<InputEvent> mouseEvent_;
153     RefPtr<InputEvent> hoverEvent_;
154 
155     RefPtr<SliderContentModifier> sliderContentModifier_;
156     // tip Parameters
157     bool bubbleFlag_ = false;
158     RefPtr<Paragraph> paragraph_;
159     SizeF bubbleSize_;
160     OffsetF bubbleOffset_;
161     OffsetF textOffset_;
162     RefPtr<SliderTipModifier> sliderTipModifier_;
163     ACE_DISALLOW_COPY_AND_MOVE(SliderPattern);
164 };
165 } // namespace OHOS::Ace::NG
166 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SLIDER_SLIDER_PATTERN_H
167