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_DRAG_BAR_RENDER_DRAG_BAR_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DRAG_BAR_RENDER_DRAG_BAR_H
18 
19 #include "core/animation/animator.h"
20 #include "core/gestures/click_recognizer.h"
21 #include "core/gestures/raw_recognizer.h"
22 #include "core/pipeline/base/render_node.h"
23 
24 namespace OHOS::Ace {
25 
26 class RenderDragBar : public RenderNode {
27     DECLARE_ACE_TYPE(RenderDragBar, RenderNode);
28 
29 public:
30     using ClickArrowCallback = std::function<void()>;
31 
32     static RefPtr<RenderNode> Create();
33     void Update(const RefPtr<Component>& component) override;
34     void PerformLayout() override;
35     void ShowArrow(bool show);
36     void ShowInPanelMode(PanelMode mode);
37     void UpdateDrawPoint();
38     void AnimateToStatusBarPadding(int32_t duration);
39     void SetStatusBarHeight(double height);
40     void HandleClick(const Offset& clickPosition);
41     void HandleTouchDown(const Offset& downPoint);
42     void HandleTouchMove(const Offset& movePoint);
43     void HandleTouchUp();
44 
45     void OnMouseHoverEnterTest() override;
46     void OnMouseHoverExitTest() override;
47     void OnPaintFinish() override;
48     void OnStatusChanged(RenderStatus renderStatus) override;
49 
GetPanelMode()50     PanelMode GetPanelMode() const
51     {
52         return showMode_;
53     }
54 
HasClickArrowCallback()55     bool HasClickArrowCallback() const
56     {
57         return (clickArrowCallback_ != nullptr);
58     }
59 
SetClickArrowCallback(const ClickArrowCallback & callback)60     void SetClickArrowCallback(const ClickArrowCallback& callback)
61     {
62         clickArrowCallback_ = callback;
63     }
64 
SetFullScreenMode(bool fullScreenMode)65     void SetFullScreenMode(bool fullScreenMode)
66     {
67         fullScreenMode_ = fullScreenMode;
68     }
69 
GetStatusBarHeight()70     double GetStatusBarHeight() const
71     {
72         return statusBarHeight_.Value();
73     }
74 
75 protected:
76     void OnTouchTestHit(
77         const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override;
78 
79     Offset iconOffset_;
80     Offset barLeftPoint_;
81     Offset barCenterPoint_;
82     Offset barRightPoint_;
83     Color barColor_ = Color(0xffb3b3b3);
84     double barWidth_ = 4.0;
85     double scaleX_ = 1.0;
86     double scaleY_ = 1.0;
87     double opacity_ = 1.0;
88     uint8_t alpha_ = UINT8_MAX;
89     PanelMode showMode_ = PanelMode::HALF;
90     bool hasDragBar_ = true;
91 
92     Offset dragOffset_;
93     Offset downPoint_;
94     double dragRangeX_ = 0.0;
95     double dragRangeY_ = 0.0;
96     double scaleIcon_ = 1.0;
97     double scaleWidth_ = 1.0;
98 
99 private:
100     void InitializeRecognizer();
101     void DoStyleAnimation(const Offset& left, const Offset& center, const Offset& right);
102     void FadingOut();
103     void Stretching();
104 
105     Rect imgTouchRegion_;
106     ClickArrowCallback clickArrowCallback_;
107     Dimension hotRegionHeight_ = 0.0_vp;  // height in vp
108     Dimension statusBarHeight_ = 0.0_vp;  // height in vp
109     RenderStatus renderStatus_ = RenderStatus::DEFAULT;
110     bool fullScreenMode_ = false;
111 
112     RefPtr<ClickRecognizer> clickDetector_;
113     RefPtr<RawRecognizer> touchDetector_;
114     RefPtr<Animator> animator_;
115     RefPtr<Animator> barTouchController_;
116     RefPtr<Animator> barRangeController_;
117     RefPtr<Animator> barStyleController_;
118 };
119 
120 } // namespace OHOS::Ace
121 
122 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DRAG_BAR_RENDER_DRAG_BAR_H
123