Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: third_party/WebKit/Source/core/page/scrolling/RootScrollerController.h

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

Powered by Google App Engine
This is Rietveld 408576698