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 RootScrollerController_h | 5 #ifndef RootScrollerController_h |
6 #define RootScrollerController_h | 6 #define RootScrollerController_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
13 class Document; | 13 class Document; |
14 class Element; | 14 class Element; |
15 class GraphicsLayer; | 15 class GraphicsLayer; |
16 class ScrollableArea; | |
17 class ScrollStateCallback; | 16 class ScrollStateCallback; |
| 17 class ViewportScrollCallback; |
18 | 18 |
19 // Manages the root scroller associated with a given document. The root | 19 // Manages the root scroller associated with a given document. The root scroller |
20 // scroller causes top controls movement, overscroll effects and prevents | 20 // causes top controls movement, overscroll effects and prevents chaining |
21 // chaining scrolls up further in the DOM. It can be set from script using | 21 // scrolls up further in the DOM. It can be set from script using |
22 // document.setRootScroller. | 22 // document.setRootScroller. |
23 // | 23 // |
24 // There are two notions of a root scroller in this class: m_rootScroller and | 24 // There are two notions of a root scroller in this class: m_rootScroller and |
25 // m_effectiveRootScroller. The former is the Element that was set as the root | 25 // m_effectiveRootScroller. The former is the Element that was set as the root |
26 // scroller using document.setRootScroller. If the page didn't set a root | 26 // scroller using document.setRootScroller. If the page didn't set a root |
27 // scroller this will be nullptr. The "effective" root scroller is the current | 27 // scroller this will be nullptr. The "effective" root scroller is the current |
28 // element we're using internally to apply viewport scrolling actions. The | 28 // element we're using internally to apply viewport scroll actions. i.e It's the |
29 // effective root scroller will only be null during document initialization. | 29 // element with the ViewportScrollCallback set as its apply-scroll callback. |
| 30 // The effective root scroller will only be null during document initialization. |
30 // | 31 // |
31 // If the currently set m_rootScroller is a valid element to become the root | 32 // If the root scroller element is a valid element to become the root scroller, |
32 // scroller, it will be promoted to the effective root scroller. If it is not | 33 // it will be promoted to the effective root scroller. If it is not valid, the |
33 // valid, the effective root scroller will fall back to a default Element (see | 34 // effective root scroller will fall back to a default Element (see |
34 // defaultEffectiveRootScroller()). The rules for what makes an element a valid | 35 // defaultEffectiveRootScroller()). The rules for what makes an element a valid |
35 // root scroller are set in isValidRootScroller(). The validity of the current | 36 // root scroller are set in isValidRootScroller(). The validity of the current |
36 // root scroller is re-checked after each layout. | 37 // root scroller is re-checked after each layout. |
37 class CORE_EXPORT RootScrollerController | 38 class CORE_EXPORT RootScrollerController |
38 : public GarbageCollected<RootScrollerController> { | 39 : public GarbageCollected<RootScrollerController> { |
39 public: | 40 public: |
40 // Creates a RootScrollerController for the given document. Note, instances | 41 // Creates a RootScrollerController for the given document. You should use |
41 // of this class need to be made aware of lifecycle events, see the | 42 // setViewportScrollCallback to provide this class with a scroll callback |
42 // didUpdateLayout, didUpdateCompositing, etc. type methods below. | 43 // that RootScrollerController will keep applied to the current RootScroller |
43 static RootScrollerController* create(Document&); | 44 // so that special actions can occur on scrolling. |
| 45 static RootScrollerController* create(Document& document) |
| 46 { |
| 47 return new RootScrollerController(document); |
| 48 } |
44 | 49 |
45 DECLARE_VIRTUAL_TRACE(); | 50 DECLARE_TRACE(); |
46 | 51 |
47 // Sets the element that will be used as the root scroller. This can be | 52 // Sets the element that will be used as the root scroller. This can be |
48 // nullptr, in which case we'll use the default element (documentElement) as | 53 // nullptr, in which case we'll use the default element (documentElement) as |
49 // the effective root scroller. | 54 // the effective root scroller. |
50 void set(Element*); | 55 void set(Element*); |
51 | 56 |
52 // Returns the element currently set as the root scroller from script. This | 57 // Returns the element currently set as the root scroller from script. This |
53 // differs from the effective root scroller since the set Element may not | 58 // differs from the effective root scroller since the set Element may not |
54 // currently be a valid root scroller. e.g. If the page sets an Element | 59 // currently be a valid root scroller. e.g. If the page sets an Element |
55 // with `display: none`, get() will return that element, even though the | 60 // with `display: none`, get() will return that element, even though the |
56 // effective root scroller will remain the element returned by | 61 // effective root scroller will remain the element returned by |
57 // defaultEffectiveRootScroller(). | 62 // defaultEffectiveRootScroller(). |
58 Element* get() const; | 63 Element* get() const; |
59 | 64 |
60 // This returns the Element that's actually being used to control viewport | 65 // This returns the Element that's actually being used to control viewport |
61 // actions right now. This is different from get() if a root scroller hasn't | 66 // actions right now. This is different from get() if a root scroller hasn't |
62 // been set, or if the set root scroller isn't currently a valid scroller. | 67 // been set, or if the set root scroller isn't currently a valid scroller. |
63 Element* effectiveRootScroller() const; | 68 Element* effectiveRootScroller() const; |
64 | 69 |
65 // This class needs to be informed of changes in layout so that it can | 70 // This class needs to be informed of changes in layout so that it can |
66 // determine if the current root scroller is still valid or if it must be | 71 // determine if the current root scroller is still valid or if it must be |
67 // replaced by the defualt root scroller. | 72 // replaced by the defualt root scroller. |
68 void didUpdateLayout(); | 73 void didUpdateLayout(); |
69 | 74 |
70 // This class needs to be informed of changes to compositing so that it can | 75 // This class needs to be informed of changes to compositing so that it can |
71 // update the compositor when the effective root scroller changes. | 76 // update the compositor when the effective root scroller changes. |
72 virtual void didUpdateCompositing(); | 77 void didUpdateCompositing(); |
73 | 78 |
74 // This class needs to be informed when the document has been attached to a | 79 // This class needs to be informed when the document has been attached to a |
75 // FrameView so that we can initialize the viewport scroll callback. | 80 // FrameView so that we can initialize the viewport scroll callback. |
76 virtual void didAttachDocument(); | 81 void didAttachDocument(); |
77 | 82 |
78 // Returns the GraphicsLayer for the current effective root scroller | |
79 // element. | |
80 GraphicsLayer* rootScrollerLayer(); | 83 GraphicsLayer* rootScrollerLayer(); |
81 | 84 |
82 // Returns true if the given ScrollStateCallback is the ViewportScrollCallba
ck managed | |
83 // by this class. | |
84 // TODO(bokan): Temporarily needed to allow ScrollCustomization to | 85 // TODO(bokan): Temporarily needed to allow ScrollCustomization to |
85 // differentiate between real custom callback and the built-in viewport | 86 // differentiate between real custom callback and the built-in viewport |
86 // apply scroll. crbug.com/623079. | 87 // apply scroll. |
87 virtual bool isViewportScrollCallback(const ScrollStateCallback*) const; | 88 bool isViewportScrollCallback(const ScrollStateCallback*) const; |
88 | 89 |
89 protected: | 90 private: |
90 RootScrollerController(Document&); | 91 RootScrollerController(Document&); |
91 | 92 |
| 93 Element* defaultEffectiveRootScroller(); |
| 94 |
92 // Ensures the effective root scroller is currently valid and replaces it | 95 // Ensures the effective root scroller is currently valid and replaces it |
93 // with the default if not. | 96 // with the default if not. |
94 virtual void updateEffectiveRootScroller(); | 97 void updateEffectiveRootScroller(); |
95 | 98 |
96 // Returns the ScrollableArea to use to scroll the given Element. | 99 // Called only from the top Document's RootScrollerController. Ensures that |
97 ScrollableArea* scrollableAreaFor(const Element&) const; | 100 // the element that should be used as the root scroller on the page has the |
| 101 // m_viewportApplyScroll callback set on it. |
| 102 void setViewportApplyScrollOnRootScroller(); |
98 | 103 |
99 // The owning Document whose root scroller this object manages. | |
100 WeakMember<Document> m_document; | 104 WeakMember<Document> m_document; |
| 105 Member<ViewportScrollCallback> m_viewportApplyScroll; |
101 | 106 |
102 private: | |
103 | |
104 // Determines whether the given element meets the criteria to become the | |
105 // effective root scroller. | |
106 bool isValidRootScroller(const Element&) const; | |
107 | |
108 // Returns the Element that should be used if the currently set | |
109 // m_rootScroller isn't valid to be a root scroller. | |
110 Element* defaultEffectiveRootScroller(); | |
111 | |
112 // The Element that was set from script as rootScroller. Depending on its | |
113 // validity to be the root scroller (e.g. a display: none element isn't a | |
114 // valid root scroller), this may not actually be the Element being used as | |
115 // the root scroller. | |
116 WeakMember<Element> m_rootScroller; | 107 WeakMember<Element> m_rootScroller; |
117 | 108 |
118 // The element currently being used as the root scroller. If | 109 // The element currently being used as the root scroller. If |
119 // m_viewportApplyScroll has been set, this element is guaranteed to have it | 110 // m_viewportApplyScroll has been set, this element is guaranteed to have it |
120 // set as its applyScroll callback. This can be nullptr during | 111 // set as its applyScroll callback. This can be nullptr during |
121 // initialization and will not be set until m_viewportApplyScroll is | 112 // initialization and will not be set until m_viewportApplyScroll is |
122 // provided. | 113 // provided. |
123 WeakMember<Element> m_effectiveRootScroller; | 114 WeakMember<Element> m_effectiveRootScroller; |
| 115 |
| 116 // Tracks which element currently has the m_viewportApplyScroll set to it. |
| 117 // This will only ever be set on the top Document's RootScrollerController. |
| 118 WeakMember<Element> m_currentViewportApplyScrollHost; |
124 }; | 119 }; |
125 | 120 |
126 } // namespace blink | 121 } // namespace blink |
127 | 122 |
128 #endif // RootScrollerController_h | 123 #endif // RootScrollerController_h |
OLD | NEW |