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