| 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; | 16 class ScrollableArea; |
| 17 class ScrollStateCallback; | 17 class ScrollStateCallback; |
| 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 |
| 20 // scroller causes top controls movement, overscroll effects and prevents | 20 // scroller causes top controls movement, overscroll effects and prevents |
| 21 // chaining 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 scrolling actions. The | 28 // element we're using internally to apply viewport scrolling actions. The |
| 29 // effective root scroller will only be null during document initialization. | 29 // effective root scroller will only be null during document initialization. |
| 30 // Both these elements are from this controller's associated Document. The final |
| 31 // "global" root scroller, the one whose scrolling hides top controls, may be in |
| 32 // a different frame. |
| 30 // | 33 // |
| 31 // If the currently set m_rootScroller is a valid element to become the root | 34 // If the currently set m_rootScroller is a valid element to become the root |
| 32 // scroller, it will be promoted to the effective root scroller. If it is not | 35 // scroller, it will be promoted to the effective root scroller. If it is not |
| 33 // valid, the effective root scroller will fall back to a default Element (see | 36 // valid, the effective root scroller will fall back to a default Element (see |
| 34 // defaultEffectiveRootScroller()). The rules for what makes an element a valid | 37 // defaultEffectiveRootScroller()). The rules for what makes an element a valid |
| 35 // root scroller are set in isValidRootScroller(). The validity of the current | 38 // root scroller are set in isValidRootScroller(). The validity of the current |
| 36 // root scroller is re-checked after each layout. | 39 // root scroller is re-checked after each layout. |
| 37 class CORE_EXPORT RootScrollerController | 40 class CORE_EXPORT RootScrollerController |
| 38 : public GarbageCollected<RootScrollerController> { | 41 : public GarbageCollected<RootScrollerController> { |
| 39 public: | 42 public: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 70 // This class needs to be informed of changes to compositing so that it can | 73 // This class needs to be informed of changes to compositing so that it can |
| 71 // update the compositor when the effective root scroller changes. | 74 // update the compositor when the effective root scroller changes. |
| 72 virtual void didUpdateCompositing(); | 75 virtual void didUpdateCompositing(); |
| 73 | 76 |
| 74 // This class needs to be informed when the document has been attached to a | 77 // 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. | 78 // FrameView so that we can initialize the viewport scroll callback. |
| 76 virtual void didAttachDocument(); | 79 virtual void didAttachDocument(); |
| 77 | 80 |
| 78 // Returns the GraphicsLayer for the current effective root scroller | 81 // Returns the GraphicsLayer for the current effective root scroller |
| 79 // element. | 82 // element. |
| 80 GraphicsLayer* rootScrollerLayer(); | 83 virtual GraphicsLayer* rootScrollerLayer(); |
| 81 | 84 |
| 82 // Returns true if the given ScrollStateCallback is the ViewportScrollCallba
ck managed | 85 // Returns true if the given ScrollStateCallback is the |
| 83 // by this class. | 86 // ViewportScrollCallback managed by this class. |
| 84 // TODO(bokan): Temporarily needed to allow ScrollCustomization to | 87 // TODO(bokan): Temporarily needed to allow ScrollCustomization to |
| 85 // differentiate between real custom callback and the built-in viewport | 88 // differentiate between real custom callback and the built-in viewport |
| 86 // apply scroll. crbug.com/623079. | 89 // apply scroll. crbug.com/623079. |
| 87 virtual bool isViewportScrollCallback(const ScrollStateCallback*) const; | 90 virtual bool isViewportScrollCallback(const ScrollStateCallback*) const; |
| 88 | 91 |
| 89 protected: | 92 protected: |
| 90 RootScrollerController(Document&); | 93 RootScrollerController(Document&); |
| 91 | 94 |
| 92 // Ensures the effective root scroller is currently valid and replaces it | 95 // Called when the root scroller of any descendant frames changes. This |
| 93 // with the default if not. | 96 // will only ever be called on the top document's RootScrollerController. |
| 94 virtual void updateEffectiveRootScroller(); | 97 virtual void globalRootScrollerMayHaveChanged(); |
| 95 | 98 |
| 96 // Returns the ScrollableArea to use to scroll the given Element. | 99 // Returns the ScrollableArea to use to scroll the given Element. |
| 97 ScrollableArea* scrollableAreaFor(const Element&) const; | 100 ScrollableArea* scrollableAreaFor(const Element&) const; |
| 98 | 101 |
| 99 // The owning Document whose root scroller this object manages. | 102 // The owning Document whose root scroller this object manages. |
| 100 WeakMember<Document> m_document; | 103 WeakMember<Document> m_document; |
| 101 | 104 |
| 102 private: | 105 private: |
| 103 | 106 |
| 107 // Ensures the effective root scroller is currently valid and replaces it |
| 108 // with the default if not. |
| 109 void recomputeEffectiveRootScroller(); |
| 110 |
| 104 // Determines whether the given element meets the criteria to become the | 111 // Determines whether the given element meets the criteria to become the |
| 105 // effective root scroller. | 112 // effective root scroller. |
| 106 bool isValidRootScroller(const Element&) const; | 113 bool isValidRootScroller(const Element&) const; |
| 107 | 114 |
| 108 // Returns the Element that should be used if the currently set | 115 // Returns the Element that should be used if the currently set |
| 109 // m_rootScroller isn't valid to be a root scroller. | 116 // m_rootScroller isn't valid to be a root scroller. |
| 110 Element* defaultEffectiveRootScroller(); | 117 Element* defaultEffectiveRootScroller(); |
| 111 | 118 |
| 112 // The Element that was set from script as rootScroller. Depending on its | 119 // The Element that was set from script as rootScroller for this Document. |
| 113 // validity to be the root scroller (e.g. a display: none element isn't a | 120 // Depending on its validity to be the root scroller (e.g. a display: none |
| 114 // valid root scroller), this may not actually be the Element being used as | 121 // element isn't a valid root scroller), this may not actually be the |
| 115 // the root scroller. | 122 // Element being used as the root scroller. |
| 116 WeakMember<Element> m_rootScroller; | 123 WeakMember<Element> m_rootScroller; |
| 117 | 124 |
| 118 // The element currently being used as the root scroller. If | 125 // The element currently being used as the root scroller in this Document. |
| 119 // m_viewportApplyScroll has been set, this element is guaranteed to have it | 126 // If the m_rootScroller is valid this will point to it. Otherwise, it'll |
| 120 // set as its applyScroll callback. This can be nullptr during | 127 // use a default Element. |
| 121 // initialization and will not be set until m_viewportApplyScroll is | |
| 122 // provided. | |
| 123 WeakMember<Element> m_effectiveRootScroller; | 128 WeakMember<Element> m_effectiveRootScroller; |
| 124 }; | 129 }; |
| 125 | 130 |
| 126 } // namespace blink | 131 } // namespace blink |
| 127 | 132 |
| 128 #endif // RootScrollerController_h | 133 #endif // RootScrollerController_h |
| OLD | NEW |