Chromium Code Reviews| 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 = | 72 float minimumPageScale = m_page->frameHost() |
| 74 m_frameHost->pageScaleConstraintsSet().finalConstraints().minimumScale; | 73 .pageScaleConstraintsSet() |
| 74 .finalConstraints() | |
| 75 .minimumScale; | |
| 75 int browserControlsAdjustment = | 76 int browserControlsAdjustment = |
| 76 ceilf(m_frameHost->visualViewport().browserControlsAdjustment() / | 77 ceilf(m_page->frameHost().visualViewport().browserControlsAdjustment() / |
| 77 minimumPageScale); | 78 minimumPageScale); |
| 78 | 79 |
| 79 return topDocument()->view()->visibleContentSize(ExcludeScrollbars) + | 80 return topDocument()->view()->visibleContentSize(ExcludeScrollbars) + |
| 80 IntSize(0, browserControlsAdjustment); | 81 IntSize(0, browserControlsAdjustment); |
| 81 } | 82 } |
| 82 | 83 |
| 83 Element* TopDocumentRootScrollerController::findGlobalRootScrollerElement() { | 84 Element* TopDocumentRootScrollerController::findGlobalRootScrollerElement() { |
| 84 if (!topDocument()) | 85 if (!topDocument()) |
| 85 return nullptr; | 86 return nullptr; |
| 86 | 87 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 | 160 |
| 160 // The scrollers may need to stop using their own scrollbars as Android | 161 // The scrollers may need to stop using their own scrollbars as Android |
| 161 // Chrome's VisualViewport provides the scrollbars for the root scroller. | 162 // Chrome's VisualViewport provides the scrollbars for the root scroller. |
| 162 if (oldRootScrollerArea) | 163 if (oldRootScrollerArea) |
| 163 oldRootScrollerArea->didChangeGlobalRootScroller(); | 164 oldRootScrollerArea->didChangeGlobalRootScroller(); |
| 164 | 165 |
| 165 targetScroller->didChangeGlobalRootScroller(); | 166 targetScroller->didChangeGlobalRootScroller(); |
| 166 } | 167 } |
| 167 | 168 |
| 168 Document* TopDocumentRootScrollerController::topDocument() const { | 169 Document* TopDocumentRootScrollerController::topDocument() const { |
| 169 if (!m_frameHost) | 170 if (!m_page) |
| 170 return nullptr; | 171 return nullptr; |
| 171 | 172 |
| 172 if (!m_frameHost->page().mainFrame() || | 173 if (!m_page->mainFrame() || !m_page->mainFrame()->isLocalFrame()) |
| 173 !m_frameHost->page().mainFrame()->isLocalFrame()) | |
| 174 return nullptr; | 174 return nullptr; |
|
joelhockey
2017/03/08 06:02:52
It would make a lot of sense to combine the 2 if-s
sashab
2017/03/08 23:39:31
Thanks, good idea! Combined them.
I tried a terna
| |
| 175 | 175 |
| 176 return toLocalFrame(m_frameHost->page().mainFrame())->document(); | 176 return toLocalFrame(m_page->mainFrame())->document(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void TopDocumentRootScrollerController:: | 179 void TopDocumentRootScrollerController:: |
| 180 setNeedsCompositingInputsUpdateOnGlobalRootScroller() { | 180 setNeedsCompositingInputsUpdateOnGlobalRootScroller() { |
| 181 if (!m_globalRootScroller) | 181 if (!m_globalRootScroller) |
| 182 return; | 182 return; |
| 183 | 183 |
| 184 PaintLayer* layer = m_globalRootScroller->document() | 184 PaintLayer* layer = m_globalRootScroller->document() |
| 185 .rootScrollerController() | 185 .rootScrollerController() |
| 186 .rootScrollerPaintLayer(); | 186 .rootScrollerPaintLayer(); |
| 187 | 187 |
| 188 if (layer) | 188 if (layer) |
| 189 layer->setNeedsCompositingInputsUpdate(); | 189 layer->setNeedsCompositingInputsUpdate(); |
| 190 | 190 |
| 191 if (LayoutView* view = m_globalRootScroller->document().layoutView()) { | 191 if (LayoutView* view = m_globalRootScroller->document().layoutView()) { |
| 192 view->compositor()->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); | 192 view->compositor()->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 | 195 |
| 196 void TopDocumentRootScrollerController::didUpdateCompositing() { | 196 void TopDocumentRootScrollerController::didUpdateCompositing() { |
| 197 if (!m_frameHost) | 197 if (!m_page) |
| 198 return; | 198 return; |
| 199 | 199 |
| 200 // Let the compositor-side counterpart know about this change. | 200 // Let the compositor-side counterpart know about this change. |
| 201 m_frameHost->page().chromeClient().registerViewportLayers(); | 201 m_page->chromeClient().registerViewportLayers(); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void TopDocumentRootScrollerController::didDisposeScrollableArea( | 204 void TopDocumentRootScrollerController::didDisposeScrollableArea( |
| 205 ScrollableArea& area) { | 205 ScrollableArea& area) { |
| 206 if (!topDocument() || !topDocument()->view()) | 206 if (!topDocument() || !topDocument()->view()) |
| 207 return; | 207 return; |
| 208 | 208 |
| 209 // If the document is tearing down, we may no longer have a layoutViewport to | 209 // If the document is tearing down, we may no longer have a layoutViewport to |
| 210 // fallback to. | 210 // fallback to. |
| 211 if (topDocument()->lifecycle().state() >= DocumentLifecycle::Stopping) | 211 if (topDocument()->lifecycle().state() >= DocumentLifecycle::Stopping) |
| 212 return; | 212 return; |
| 213 | 213 |
| 214 FrameView* frameView = topDocument()->view(); | 214 FrameView* frameView = topDocument()->view(); |
| 215 | 215 |
| 216 RootFrameViewport* rfv = frameView->getRootFrameViewport(); | 216 RootFrameViewport* rfv = frameView->getRootFrameViewport(); |
| 217 | 217 |
| 218 if (&area == &rfv->layoutViewport()) { | 218 if (&area == &rfv->layoutViewport()) { |
| 219 DCHECK(frameView->layoutViewportScrollableArea()); | 219 DCHECK(frameView->layoutViewportScrollableArea()); |
| 220 rfv->setLayoutViewport(*frameView->layoutViewportScrollableArea()); | 220 rfv->setLayoutViewport(*frameView->layoutViewportScrollableArea()); |
| 221 } | 221 } |
| 222 } | 222 } |
| 223 | 223 |
| 224 void TopDocumentRootScrollerController::initializeViewportScrollCallback( | 224 void TopDocumentRootScrollerController::initializeViewportScrollCallback( |
| 225 RootFrameViewport& rootFrameViewport) { | 225 RootFrameViewport& rootFrameViewport) { |
| 226 DCHECK(m_frameHost); | 226 DCHECK(m_page); |
| 227 m_viewportApplyScroll = ViewportScrollCallback::create( | 227 m_viewportApplyScroll = ViewportScrollCallback::create( |
| 228 &m_frameHost->browserControls(), &m_frameHost->overscrollController(), | 228 &m_page->frameHost().browserControls(), |
| 229 rootFrameViewport); | 229 &m_page->frameHost().overscrollController(), rootFrameViewport); |
| 230 | 230 |
| 231 recomputeGlobalRootScroller(); | 231 recomputeGlobalRootScroller(); |
| 232 } | 232 } |
| 233 | 233 |
| 234 bool TopDocumentRootScrollerController::isViewportScrollCallback( | 234 bool TopDocumentRootScrollerController::isViewportScrollCallback( |
| 235 const ScrollStateCallback* callback) const { | 235 const ScrollStateCallback* callback) const { |
| 236 if (!callback) | 236 if (!callback) |
| 237 return false; | 237 return false; |
| 238 | 238 |
| 239 return callback == m_viewportApplyScroll.get(); | 239 return callback == m_viewportApplyScroll.get(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 257 | 257 |
| 258 PaintLayer* TopDocumentRootScrollerController::rootScrollerPaintLayer() const { | 258 PaintLayer* TopDocumentRootScrollerController::rootScrollerPaintLayer() const { |
| 259 return RootScrollerUtil::paintLayerForRootScroller(m_globalRootScroller); | 259 return RootScrollerUtil::paintLayerForRootScroller(m_globalRootScroller); |
| 260 } | 260 } |
| 261 | 261 |
| 262 Element* TopDocumentRootScrollerController::globalRootScroller() const { | 262 Element* TopDocumentRootScrollerController::globalRootScroller() const { |
| 263 return m_globalRootScroller.get(); | 263 return m_globalRootScroller.get(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 } // namespace blink | 266 } // namespace blink |
| OLD | NEW |