| 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/frame/PageScaleConstraintsSet.h" | 11 #include "core/frame/PageScaleConstraintsSet.h" |
| 12 #include "core/frame/VisualViewport.h" | 12 #include "core/frame/VisualViewport.h" |
| 13 #include "core/html/HTMLFrameOwnerElement.h" | 13 #include "core/html/HTMLFrameOwnerElement.h" |
| 14 #include "core/layout/LayoutView.h" | 14 #include "core/layout/LayoutView.h" |
| 15 #include "core/layout/compositing/PaintLayerCompositor.h" | 15 #include "core/layout/compositing/PaintLayerCompositor.h" |
| 16 #include "core/page/ChromeClient.h" | 16 #include "core/page/ChromeClient.h" |
| 17 #include "core/page/Page.h" | 17 #include "core/page/Page.h" |
| 18 #include "core/page/scrolling/OverscrollController.h" | 18 #include "core/page/scrolling/OverscrollController.h" |
| 19 #include "core/page/scrolling/RootScrollerUtil.h" | 19 #include "core/page/scrolling/RootScrollerUtil.h" |
| 20 #include "core/page/scrolling/ViewportScrollCallback.h" | 20 #include "core/page/scrolling/ViewportScrollCallback.h" |
| 21 #include "core/paint/PaintLayer.h" | 21 #include "core/paint/PaintLayer.h" |
| 22 #include "platform/scroll/ScrollableArea.h" | 22 #include "platform/scroll/ScrollableArea.h" |
| 23 | 23 |
| 24 namespace blink { | 24 namespace blink { |
| 25 | 25 |
| 26 // static | 26 // static |
| 27 TopDocumentRootScrollerController* TopDocumentRootScrollerController::create( | 27 TopDocumentRootScrollerController* TopDocumentRootScrollerController::create( |
| 28 FrameHost& host) { | 28 Page& page) { |
| 29 return new TopDocumentRootScrollerController(host); | 29 return new TopDocumentRootScrollerController(page); |
| 30 } | 30 } |
| 31 | 31 |
| 32 TopDocumentRootScrollerController::TopDocumentRootScrollerController( | 32 TopDocumentRootScrollerController::TopDocumentRootScrollerController(Page& page) |
| 33 FrameHost& host) | 33 : m_page(&page) {} |
| 34 : m_frameHost(&host) {} | |
| 35 | 34 |
| 36 DEFINE_TRACE(TopDocumentRootScrollerController) { | 35 DEFINE_TRACE(TopDocumentRootScrollerController) { |
| 37 visitor->trace(m_viewportApplyScroll); | 36 visitor->trace(m_viewportApplyScroll); |
| 38 visitor->trace(m_globalRootScroller); | 37 visitor->trace(m_globalRootScroller); |
| 39 visitor->trace(m_frameHost); | 38 visitor->trace(m_page); |
| 40 } | 39 } |
| 41 | 40 |
| 42 void TopDocumentRootScrollerController::didChangeRootScroller() { | 41 void TopDocumentRootScrollerController::didChangeRootScroller() { |
| 43 recomputeGlobalRootScroller(); | 42 recomputeGlobalRootScroller(); |
| 44 } | 43 } |
| 45 | 44 |
| 46 void TopDocumentRootScrollerController::mainFrameViewResized() { | 45 void TopDocumentRootScrollerController::mainFrameViewResized() { |
| 47 Element* rootScroller = globalRootScroller(); | 46 Element* rootScroller = globalRootScroller(); |
| 48 | 47 |
| 49 ScrollableArea* area = | 48 ScrollableArea* area = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 63 } | 62 } |
| 64 | 63 |
| 65 ScrollableArea* TopDocumentRootScrollerController::rootScrollerArea() const { | 64 ScrollableArea* TopDocumentRootScrollerController::rootScrollerArea() const { |
| 66 return RootScrollerUtil::scrollableAreaForRootScroller(globalRootScroller()); | 65 return RootScrollerUtil::scrollableAreaForRootScroller(globalRootScroller()); |
| 67 } | 66 } |
| 68 | 67 |
| 69 IntSize TopDocumentRootScrollerController::rootScrollerVisibleArea() const { | 68 IntSize TopDocumentRootScrollerController::rootScrollerVisibleArea() const { |
| 70 if (!topDocument() || !topDocument()->view()) | 69 if (!topDocument() || !topDocument()->view()) |
| 71 return IntSize(); | 70 return IntSize(); |
| 72 | 71 |
| 73 float minimumPageScale = m_frameHost->page() | 72 float minimumPageScale = |
| 74 .pageScaleConstraintsSet() | 73 m_page->pageScaleConstraintsSet().finalConstraints().minimumScale; |
| 75 .finalConstraints() | |
| 76 .minimumScale; | |
| 77 int browserControlsAdjustment = | 74 int browserControlsAdjustment = |
| 78 ceilf(m_frameHost->visualViewport().browserControlsAdjustment() / | 75 ceilf(m_page->frameHost().visualViewport().browserControlsAdjustment() / |
| 79 minimumPageScale); | 76 minimumPageScale); |
| 80 | 77 |
| 81 return topDocument()->view()->visibleContentSize(ExcludeScrollbars) + | 78 return topDocument()->view()->visibleContentSize(ExcludeScrollbars) + |
| 82 IntSize(0, browserControlsAdjustment); | 79 IntSize(0, browserControlsAdjustment); |
| 83 } | 80 } |
| 84 | 81 |
| 85 Element* TopDocumentRootScrollerController::findGlobalRootScrollerElement() { | 82 Element* TopDocumentRootScrollerController::findGlobalRootScrollerElement() { |
| 86 if (!topDocument()) | 83 if (!topDocument()) |
| 87 return nullptr; | 84 return nullptr; |
| 88 | 85 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 158 |
| 162 // The scrollers may need to stop using their own scrollbars as Android | 159 // The scrollers may need to stop using their own scrollbars as Android |
| 163 // Chrome's VisualViewport provides the scrollbars for the root scroller. | 160 // Chrome's VisualViewport provides the scrollbars for the root scroller. |
| 164 if (oldRootScrollerArea) | 161 if (oldRootScrollerArea) |
| 165 oldRootScrollerArea->didChangeGlobalRootScroller(); | 162 oldRootScrollerArea->didChangeGlobalRootScroller(); |
| 166 | 163 |
| 167 targetScroller->didChangeGlobalRootScroller(); | 164 targetScroller->didChangeGlobalRootScroller(); |
| 168 } | 165 } |
| 169 | 166 |
| 170 Document* TopDocumentRootScrollerController::topDocument() const { | 167 Document* TopDocumentRootScrollerController::topDocument() const { |
| 171 if (!m_frameHost) | 168 if (!m_page || !m_page->mainFrame() || !m_page->mainFrame()->isLocalFrame()) |
| 172 return nullptr; | 169 return nullptr; |
| 173 | 170 |
| 174 if (!m_frameHost->page().mainFrame() || | 171 return toLocalFrame(m_page->mainFrame())->document(); |
| 175 !m_frameHost->page().mainFrame()->isLocalFrame()) | |
| 176 return nullptr; | |
| 177 | |
| 178 return toLocalFrame(m_frameHost->page().mainFrame())->document(); | |
| 179 } | 172 } |
| 180 | 173 |
| 181 void TopDocumentRootScrollerController:: | 174 void TopDocumentRootScrollerController:: |
| 182 setNeedsCompositingInputsUpdateOnGlobalRootScroller() { | 175 setNeedsCompositingInputsUpdateOnGlobalRootScroller() { |
| 183 if (!m_globalRootScroller) | 176 if (!m_globalRootScroller) |
| 184 return; | 177 return; |
| 185 | 178 |
| 186 PaintLayer* layer = m_globalRootScroller->document() | 179 PaintLayer* layer = m_globalRootScroller->document() |
| 187 .rootScrollerController() | 180 .rootScrollerController() |
| 188 .rootScrollerPaintLayer(); | 181 .rootScrollerPaintLayer(); |
| 189 | 182 |
| 190 if (layer) | 183 if (layer) |
| 191 layer->setNeedsCompositingInputsUpdate(); | 184 layer->setNeedsCompositingInputsUpdate(); |
| 192 | 185 |
| 193 if (LayoutView* view = m_globalRootScroller->document().layoutView()) { | 186 if (LayoutView* view = m_globalRootScroller->document().layoutView()) { |
| 194 view->compositor()->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); | 187 view->compositor()->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); |
| 195 } | 188 } |
| 196 } | 189 } |
| 197 | 190 |
| 198 void TopDocumentRootScrollerController::didUpdateCompositing() { | 191 void TopDocumentRootScrollerController::didUpdateCompositing() { |
| 199 if (!m_frameHost) | 192 if (!m_page) |
| 200 return; | 193 return; |
| 201 | 194 |
| 202 // Let the compositor-side counterpart know about this change. | 195 // Let the compositor-side counterpart know about this change. |
| 203 m_frameHost->page().chromeClient().registerViewportLayers(); | 196 m_page->chromeClient().registerViewportLayers(); |
| 204 } | 197 } |
| 205 | 198 |
| 206 void TopDocumentRootScrollerController::didDisposeScrollableArea( | 199 void TopDocumentRootScrollerController::didDisposeScrollableArea( |
| 207 ScrollableArea& area) { | 200 ScrollableArea& area) { |
| 208 if (!topDocument() || !topDocument()->view()) | 201 if (!topDocument() || !topDocument()->view()) |
| 209 return; | 202 return; |
| 210 | 203 |
| 211 // If the document is tearing down, we may no longer have a layoutViewport to | 204 // If the document is tearing down, we may no longer have a layoutViewport to |
| 212 // fallback to. | 205 // fallback to. |
| 213 if (topDocument()->lifecycle().state() >= DocumentLifecycle::Stopping) | 206 if (topDocument()->lifecycle().state() >= DocumentLifecycle::Stopping) |
| 214 return; | 207 return; |
| 215 | 208 |
| 216 FrameView* frameView = topDocument()->view(); | 209 FrameView* frameView = topDocument()->view(); |
| 217 | 210 |
| 218 RootFrameViewport* rfv = frameView->getRootFrameViewport(); | 211 RootFrameViewport* rfv = frameView->getRootFrameViewport(); |
| 219 | 212 |
| 220 if (&area == &rfv->layoutViewport()) { | 213 if (&area == &rfv->layoutViewport()) { |
| 221 DCHECK(frameView->layoutViewportScrollableArea()); | 214 DCHECK(frameView->layoutViewportScrollableArea()); |
| 222 rfv->setLayoutViewport(*frameView->layoutViewportScrollableArea()); | 215 rfv->setLayoutViewport(*frameView->layoutViewportScrollableArea()); |
| 223 } | 216 } |
| 224 } | 217 } |
| 225 | 218 |
| 226 void TopDocumentRootScrollerController::initializeViewportScrollCallback( | 219 void TopDocumentRootScrollerController::initializeViewportScrollCallback( |
| 227 RootFrameViewport& rootFrameViewport) { | 220 RootFrameViewport& rootFrameViewport) { |
| 228 DCHECK(m_frameHost); | 221 DCHECK(m_page); |
| 229 m_viewportApplyScroll = ViewportScrollCallback::create( | 222 m_viewportApplyScroll = ViewportScrollCallback::create( |
| 230 &m_frameHost->page().browserControls(), | 223 &m_page->browserControls(), &m_page->frameHost().overscrollController(), |
| 231 &m_frameHost->overscrollController(), rootFrameViewport); | 224 rootFrameViewport); |
| 232 | 225 |
| 233 recomputeGlobalRootScroller(); | 226 recomputeGlobalRootScroller(); |
| 234 } | 227 } |
| 235 | 228 |
| 236 bool TopDocumentRootScrollerController::isViewportScrollCallback( | 229 bool TopDocumentRootScrollerController::isViewportScrollCallback( |
| 237 const ScrollStateCallback* callback) const { | 230 const ScrollStateCallback* callback) const { |
| 238 if (!callback) | 231 if (!callback) |
| 239 return false; | 232 return false; |
| 240 | 233 |
| 241 return callback == m_viewportApplyScroll.get(); | 234 return callback == m_viewportApplyScroll.get(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 259 | 252 |
| 260 PaintLayer* TopDocumentRootScrollerController::rootScrollerPaintLayer() const { | 253 PaintLayer* TopDocumentRootScrollerController::rootScrollerPaintLayer() const { |
| 261 return RootScrollerUtil::paintLayerForRootScroller(m_globalRootScroller); | 254 return RootScrollerUtil::paintLayerForRootScroller(m_globalRootScroller); |
| 262 } | 255 } |
| 263 | 256 |
| 264 Element* TopDocumentRootScrollerController::globalRootScroller() const { | 257 Element* TopDocumentRootScrollerController::globalRootScroller() const { |
| 265 return m_globalRootScroller.get(); | 258 return m_globalRootScroller.get(); |
| 266 } | 259 } |
| 267 | 260 |
| 268 } // namespace blink | 261 } // namespace blink |
| OLD | NEW |