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 #include "core/animation/animator.h" 17 #include "core/animation/friction_motion.h" 18 #include "core/components/common/properties/scroll_bar.h" 19 #include "core/components/scroll_bar/scroll_bar_component.h" 20 #include "core/gestures/drag_recognizer.h" 21 #include "core/pipeline/base/render_node.h" 22 23 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLL_BAR_RENDER_SCROLL_BAR_H 24 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLL_BAR_RENDER_SCROLL_BAR_H 25 26 namespace OHOS::Ace { 27 28 class RenderScrollBar : public RenderNode { 29 DECLARE_ACE_TYPE(RenderScrollBar, RenderNode); 30 31 public: 32 RenderScrollBar() = default; 33 ~RenderScrollBar() override; 34 35 static RefPtr<RenderNode> Create(); 36 void Update(const RefPtr<Component>& component) override; 37 void PerformLayout() override; 38 void OnPaintFinish() override; 39 GetTouchRectList()40 const std::vector<Rect>& GetTouchRectList() override 41 { 42 touchRectList_.clear(); 43 touchRectList_.emplace_back(childRect_); 44 return touchRectList_; 45 } 46 SupportOpacity()47 bool SupportOpacity() override 48 { 49 return true; 50 } 51 GetAxis()52 Axis GetAxis() const 53 { 54 return axis_; 55 } 56 GetDisplayMode()57 DisplayMode GetDisplayMode() const 58 { 59 return displayMode_; 60 } 61 SetChildPosition(const Offset & childPosition)62 void SetChildPosition(const Offset& childPosition) 63 { 64 childPosition_ = childPosition; 65 } 66 67 void StartAnimator(); 68 void StopAnimator(); 69 70 protected: 71 int32_t opacity_ = 0; 72 DisplayMode displayMode_ = DisplayMode::AUTO; 73 74 private: 75 void InitRecognizer(); 76 void OnTouchTestHit( 77 const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override; 78 void HandleDragStart(const DragStartInfo& info); 79 void HandleDragUpdate(const DragUpdateInfo& info); 80 void HandleDragFinish(); 81 82 void InitOpacity(); 83 void InitAnimator(); 84 void InitChildPosition(); 85 void UpdateDisplayOpacity(int32_t opacity); 86 87 bool isAxisChanged_ = true; 88 bool touchInBarRegion_ = true; 89 Offset childPosition_; 90 Rect childRect_; 91 Axis axis_ = Axis::VERTICAL; 92 RefPtr<DragRecognizer> dragRecognizer_; 93 RefPtr<ScrollBarProxy> proxy_; 94 95 // When display mode is auto and there is no operation, start opacity animation from show to hide. 96 RefPtr<Animator> disappearAnimator_; 97 }; 98 99 } // namespace OHOS::Ace 100 101 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLL_BAR_RENDER_SCROLL_BAR_H 102