| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef RootScroller_h | |
| 6 #define RootScroller_h | |
| 7 | |
| 8 #include "core/CoreExport.h" | |
| 9 #include "platform/heap/Handle.h" | |
| 10 | |
| 11 namespace blink { | |
| 12 | |
| 13 class Document; | |
| 14 class Element; | |
| 15 class OverscrollController; | |
| 16 class TopControls; | |
| 17 class ViewportScrollCallback; | |
| 18 | |
| 19 // Manages the root scroller associated with a given document. The root scroller | |
| 20 // causes top controls movement, overscroll effects and prevents chaining | |
| 21 // scrolls up further in the DOM. It can be set from script using | |
| 22 // document.setRootScroller. | |
| 23 // | |
| 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 | |
| 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 | |
| 28 // element we're using internally to apply viewport scroll actions. i.e It's the | |
| 29 // element with the ViewportScrollCallback set as its apply-scroll callback. | |
| 30 // The effective root scroller will only be null during document initialization. | |
| 31 // | |
| 32 // If the root scroller element is a valid element to become the root scroller, | |
| 33 // it will be promoted to the effective root scroller. If it is not valid, the | |
| 34 // effective root scroller will fall back to a default Element (see | |
| 35 // defaultEffectiveRootScroller()). The rules for what makes an element a valid | |
| 36 // root scroller are set in isValidRootScroller(). The validity of the current | |
| 37 // root scroller is re-checked after each layout. | |
| 38 class CORE_EXPORT RootScroller : public GarbageCollected<RootScroller> { | |
| 39 public: | |
| 40 // Creates a RootScroller for the given document. An optional | |
| 41 // ViewportScrollCallback can be provided. If it is, RootScroller will | |
| 42 // ensure that the effectiveRootScroller element always has this set as the | |
| 43 // apply scroll callback. | |
| 44 static RootScroller* create( | |
| 45 Document& document, | |
| 46 ViewportScrollCallback* applyScrollCallback) | |
| 47 { | |
| 48 return new RootScroller(document, applyScrollCallback); | |
| 49 } | |
| 50 | |
| 51 // Creates an apply scroll callback that handles viewport actions like | |
| 52 // TopControls movement and Overscroll. | |
| 53 static ViewportScrollCallback* createViewportApplyScroll( | |
| 54 TopControls&, OverscrollController&); | |
| 55 | |
| 56 DECLARE_TRACE(); | |
| 57 | |
| 58 // Sets the element that will be used as the root scroller. This can be | |
| 59 // nullptr, in which case we'll use the default element (documentElement) as | |
| 60 // the effective root scroller. | |
| 61 void set(Element*); | |
| 62 | |
| 63 // Returns the element currently set as the root scroller from script. This | |
| 64 // differs from the effective root scroller since the set Element may not | |
| 65 // currently be a valid root scroller. e.g. If the page sets an Element | |
| 66 // with `display: none`, get() will return that element, even though the | |
| 67 // effective root scroller will remain the element returned by | |
| 68 // defaultEffectiveRootScroller(). | |
| 69 Element* get() const; | |
| 70 | |
| 71 // This returns the Element that's actually being used to control viewport | |
| 72 // actions right now. This is different from get() if a root scroller hasn't | |
| 73 // been set, or if the set root scroller isn't currently a valid scroller. | |
| 74 Element* effectiveRootScroller() const; | |
| 75 | |
| 76 // This class needs to be informed of changes in layout so that it can | |
| 77 // determine if the current root scroller is still valid or if it must be | |
| 78 // replaced by the defualt root scroller. | |
| 79 void didUpdateLayout(); | |
| 80 | |
| 81 private: | |
| 82 RootScroller(Document&, ViewportScrollCallback*); | |
| 83 | |
| 84 Element* defaultEffectiveRootScroller(); | |
| 85 | |
| 86 // Ensures the effective root scroller is currently valid and replaces it | |
| 87 // with the default if not. | |
| 88 void updateEffectiveRootScroller(); | |
| 89 void moveViewportApplyScroll(Element* target); | |
| 90 | |
| 91 WeakMember<Document> m_document; | |
| 92 Member<ViewportScrollCallback> m_viewportApplyScroll; | |
| 93 | |
| 94 WeakMember<Element> m_rootScroller; | |
| 95 WeakMember<Element> m_effectiveRootScroller; | |
| 96 }; | |
| 97 | |
| 98 } // namespace blink | |
| 99 | |
| 100 #endif // RootScroller_h | |
| OLD | NEW |