OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ViewportScrollCallback_h | 5 #ifndef ViewportScrollCallback_h |
6 #define ViewportScrollCallback_h | 6 #define ViewportScrollCallback_h |
7 | 7 |
8 #include "core/page/scrolling/ScrollStateCallback.h" | 8 #include "core/page/scrolling/ScrollStateCallback.h" |
9 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
10 #include "platform/scroll/ScrollTypes.h" | 10 #include "platform/scroll/ScrollTypes.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
| 14 class FloatSize; |
14 class ScrollableArea; | 15 class ScrollableArea; |
15 class ScrollState; | 16 class ScrollState; |
| 17 class TopControls; |
| 18 class OverscrollController; |
| 19 class RootFrameViewport; |
16 | 20 |
17 // ViewportScrollCallback is an interface that's used by the | 21 // ViewportScrollCallback is a ScrollStateCallback, meaning that it's applied |
18 // RootScrollerController to apply scrolls to the designated rootScroller | 22 // during the applyScroll step of ScrollCustomization. It implements viewport |
19 // element. It is a ScrollStateCallback, meaning that it's applied during the | 23 // actions like moving top controls and showing overscroll glow as well as |
20 // applyScroll step of ScrollCustomization and child classes must implement | 24 // scrolling the Element. |
21 // handleEvent in order to actually do the scrolling as well as any possible | |
22 // associated actions. | |
23 // | 25 // |
24 // ScrollCustomization generally relies on using the nativeApplyScroll to | 26 // ScrollCustomization generally relies on using the nativeApplyScroll to |
25 // scroll the element; however, the rootScroller may need to execute actions | 27 // scroll the element; however, the rootScroller may need to execute actions |
26 // both before and after the native scroll which is currently unsupported. | 28 // both before and after the native scroll which is currently unsupported. |
27 // Because of this, the ViewportScrollCallback can scroll the Element directly. | 29 // Because of this, the ViewportScrollCallback can scroll the Element directly. |
28 // This is accomplished by descendant classes implementing the setScroller | 30 // This is accomplished by passing the ScrollableArea directly using |
29 // method which RootScrollerController will call to fill the callback with the | 31 // setScroller() which RootScrollerController will call to set the appropriate |
30 // appropriate ScrollableArea to use. | 32 // ScrollableArea to use. |
31 class ViewportScrollCallback : public ScrollStateCallback { | 33 class ViewportScrollCallback : public ScrollStateCallback { |
32 public: | 34 public: |
33 virtual ~ViewportScrollCallback() {} | 35 // The TopControls and OverscrollController are given to the |
| 36 // ViewportScrollCallback but are not owned or kept alive by it. |
| 37 static ViewportScrollCallback* create( |
| 38 TopControls* topControls, |
| 39 OverscrollController* overscrollController, |
| 40 RootFrameViewport& rootFrameViewport) |
| 41 { |
| 42 return new ViewportScrollCallback( |
| 43 topControls, overscrollController, rootFrameViewport); |
| 44 } |
34 | 45 |
35 virtual void setScroller(ScrollableArea*) = 0; | 46 virtual ~ViewportScrollCallback(); |
36 | 47 |
37 DEFINE_INLINE_VIRTUAL_TRACE() { | 48 void handleEvent(ScrollState*) override; |
38 ScrollStateCallback::trace(visitor); | 49 void setScroller(ScrollableArea*); |
39 } | 50 |
40 protected: | 51 DECLARE_VIRTUAL_TRACE(); |
41 ScrollResult performNativeScroll(ScrollState&, ScrollableArea&); | 52 |
| 53 private: |
| 54 // ViewportScrollCallback does not assume ownership of TopControls or of |
| 55 // OverscrollController. |
| 56 ViewportScrollCallback(TopControls*, OverscrollController*, RootFrameViewpor
t&); |
| 57 |
| 58 bool shouldScrollTopControls(const FloatSize&, ScrollGranularity) const; |
| 59 bool scrollTopControls(ScrollState&); |
| 60 |
| 61 ScrollResult performNativeScroll(ScrollState&); |
| 62 |
| 63 WeakMember<TopControls> m_topControls; |
| 64 WeakMember<OverscrollController> m_overscrollController; |
| 65 WeakMember<RootFrameViewport> m_rootFrameViewport; |
42 }; | 66 }; |
43 | 67 |
44 } // namespace blink | 68 } // namespace blink |
45 | 69 |
46 #endif // ViewportScrollCallback_h | 70 #endif // ViewportScrollCallback_h |
OLD | NEW |