| 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 #include "core/page/scrolling/TopDocumentRootScrollerController.h" | 5 #include "core/page/scrolling/TopDocumentRootScrollerController.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/Element.h" | 8 #include "core/dom/Element.h" |
| 9 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
| 10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| 11 #include "core/html/HTMLFrameOwnerElement.h" |
| 11 #include "core/page/ChromeClient.h" | 12 #include "core/page/ChromeClient.h" |
| 12 #include "core/page/scrolling/OverscrollController.h" | 13 #include "core/page/scrolling/OverscrollController.h" |
| 13 #include "core/page/scrolling/ViewportScrollCallback.h" | 14 #include "core/page/scrolling/ViewportScrollCallback.h" |
| 14 #include "platform/scroll/ScrollableArea.h" | 15 #include "platform/scroll/ScrollableArea.h" |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 18 // static | 19 // static |
| 19 TopDocumentRootScrollerController* TopDocumentRootScrollerController::create( | 20 TopDocumentRootScrollerController* TopDocumentRootScrollerController::create( |
| 20 Document& document) | 21 Document& document) |
| 21 { | 22 { |
| 22 return new TopDocumentRootScrollerController(document); | 23 return new TopDocumentRootScrollerController(document); |
| 23 } | 24 } |
| 24 | 25 |
| 25 TopDocumentRootScrollerController::TopDocumentRootScrollerController( | 26 TopDocumentRootScrollerController::TopDocumentRootScrollerController( |
| 26 Document& document) | 27 Document& document) |
| 27 : RootScrollerController(document) | 28 : RootScrollerController(document) |
| 28 { | 29 { |
| 29 } | 30 } |
| 30 | 31 |
| 31 DEFINE_TRACE(TopDocumentRootScrollerController) | 32 DEFINE_TRACE(TopDocumentRootScrollerController) |
| 32 { | 33 { |
| 33 visitor->trace(m_viewportApplyScroll); | 34 visitor->trace(m_viewportApplyScroll); |
| 34 visitor->trace(m_currentViewportApplyScrollHost); | 35 visitor->trace(m_globalRootScroller); |
| 35 RootScrollerController::trace(visitor); | 36 RootScrollerController::trace(visitor); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void TopDocumentRootScrollerController::updateEffectiveRootScroller() | 39 void TopDocumentRootScrollerController::globalRootScrollerMayHaveChanged() |
| 39 { | 40 { |
| 40 RootScrollerController::updateEffectiveRootScroller(); | 41 updateGlobalRootScroller(); |
| 41 setViewportApplyScrollOnRootScroller(); | |
| 42 } | 42 } |
| 43 | 43 |
| 44 void TopDocumentRootScrollerController::setViewportApplyScrollOnRootScroller() | 44 Element* TopDocumentRootScrollerController::findGlobalRootScrollerElement() |
| 45 { | 45 { |
| 46 if (!m_viewportApplyScroll || !effectiveRootScroller()) | 46 Element* element = effectiveRootScroller(); |
| 47 |
| 48 while (element && element->isFrameOwnerElement()) { |
| 49 HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(element); |
| 50 DCHECK(frameOwner); |
| 51 |
| 52 Document* iframeDocument = frameOwner->contentDocument(); |
| 53 if (!iframeDocument) |
| 54 return element; |
| 55 |
| 56 DCHECK(iframeDocument->rootScrollerController()); |
| 57 element = |
| 58 iframeDocument->rootScrollerController()->effectiveRootScroller(); |
| 59 } |
| 60 |
| 61 return element; |
| 62 } |
| 63 |
| 64 void TopDocumentRootScrollerController::updateGlobalRootScroller() |
| 65 { |
| 66 Element* target = findGlobalRootScrollerElement(); |
| 67 |
| 68 if (!m_viewportApplyScroll || !target) |
| 47 return; | 69 return; |
| 48 | 70 |
| 49 ScrollableArea* targetScroller = | 71 ScrollableArea* targetScroller = |
| 50 scrollableAreaFor(*effectiveRootScroller()); | 72 scrollableAreaFor(*target); |
| 51 | 73 |
| 52 if (!targetScroller) | 74 if (!targetScroller) |
| 53 return; | 75 return; |
| 54 | 76 |
| 55 if (m_currentViewportApplyScrollHost) | 77 if (m_globalRootScroller) |
| 56 m_currentViewportApplyScrollHost->removeApplyScroll(); | 78 m_globalRootScroller->removeApplyScroll(); |
| 57 | 79 |
| 58 // Use disable-native-scroll since the ViewportScrollCallback needs to | 80 // Use disable-native-scroll since the ViewportScrollCallback needs to |
| 59 // apply scroll actions both before (TopControls) and after (overscroll) | 81 // apply scroll actions both before (TopControls) and after (overscroll) |
| 60 // scrolling the element so it will apply scroll to the element itself. | 82 // scrolling the element so it will apply scroll to the element itself. |
| 61 effectiveRootScroller()->setApplyScroll( | 83 target->setApplyScroll(m_viewportApplyScroll, "disable-native-scroll"); |
| 62 m_viewportApplyScroll, "disable-native-scroll"); | |
| 63 | 84 |
| 64 m_currentViewportApplyScrollHost = effectiveRootScroller(); | 85 m_globalRootScroller = target; |
| 65 | 86 |
| 66 // Ideally, scroll customization would pass the current element to scroll to | 87 // Ideally, scroll customization would pass the current element to scroll to |
| 67 // the apply scroll callback but this doesn't happen today so we set it | 88 // the apply scroll callback but this doesn't happen today so we set it |
| 68 // through a back door here. This is also needed by the | 89 // through a back door here. This is also needed by the |
| 69 // ViewportScrollCallback to swap the target into the layout viewport | 90 // ViewportScrollCallback to swap the target into the layout viewport |
| 70 // in RootFrameViewport. | 91 // in RootFrameViewport. |
| 71 m_viewportApplyScroll->setScroller(targetScroller); | 92 m_viewportApplyScroll->setScroller(targetScroller); |
| 72 } | 93 } |
| 73 | 94 |
| 74 void TopDocumentRootScrollerController::didUpdateCompositing() | 95 void TopDocumentRootScrollerController::didUpdateCompositing() |
| (...skipping 14 matching lines...) Expand all Loading... |
| 89 return; | 110 return; |
| 90 | 111 |
| 91 RootFrameViewport* rootFrameViewport = frameView->getRootFrameViewport(); | 112 RootFrameViewport* rootFrameViewport = frameView->getRootFrameViewport(); |
| 92 DCHECK(rootFrameViewport); | 113 DCHECK(rootFrameViewport); |
| 93 | 114 |
| 94 m_viewportApplyScroll = ViewportScrollCallback::create( | 115 m_viewportApplyScroll = ViewportScrollCallback::create( |
| 95 &frameHost->topControls(), | 116 &frameHost->topControls(), |
| 96 &frameHost->overscrollController(), | 117 &frameHost->overscrollController(), |
| 97 *rootFrameViewport); | 118 *rootFrameViewport); |
| 98 | 119 |
| 99 updateEffectiveRootScroller(); | 120 updateGlobalRootScroller(); |
| 100 } | 121 } |
| 101 | 122 |
| 102 bool TopDocumentRootScrollerController::isViewportScrollCallback( | 123 bool TopDocumentRootScrollerController::isViewportScrollCallback( |
| 103 const ScrollStateCallback* callback) const | 124 const ScrollStateCallback* callback) const |
| 104 { | 125 { |
| 105 if (!callback) | 126 if (!callback) |
| 106 return false; | 127 return false; |
| 107 | 128 |
| 108 return callback == m_viewportApplyScroll.get(); | 129 return callback == m_viewportApplyScroll.get(); |
| 109 } | 130 } |
| 110 | 131 |
| 132 GraphicsLayer* TopDocumentRootScrollerController::rootScrollerLayer() |
| 133 { |
| 134 if (!m_globalRootScroller) |
| 135 return nullptr; |
| 136 |
| 137 ScrollableArea* area = scrollableAreaFor(*m_globalRootScroller); |
| 138 |
| 139 if (!area) |
| 140 return nullptr; |
| 141 |
| 142 GraphicsLayer* graphicsLayer = area->layerForScrolling(); |
| 143 |
| 144 // TODO(bokan): We should assert graphicsLayer here and |
| 145 // RootScrollerController should do whatever needs to happen to ensure |
| 146 // the root scroller gets composited. |
| 147 |
| 148 return graphicsLayer; |
| 149 } |
| 150 |
| 111 } // namespace blink | 151 } // namespace blink |
| OLD | NEW |