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->frameHost().page().mainFrame() || |
173 !m_frameHost->page().mainFrame()->isLocalFrame()) | 174 !m_page->frameHost().page().mainFrame()->isLocalFrame()) |
174 return nullptr; | 175 return nullptr; |
175 | 176 |
176 return toLocalFrame(m_frameHost->page().mainFrame())->document(); | 177 return toLocalFrame(m_page->frameHost().page().mainFrame())->document(); |
joelhockey
2017/03/08 04:36:00
I think these references of m_page->frameHost.page
sashab
2017/03/08 05:02:37
Oh yeah, great catch! Fixed here and below, thanks
| |
177 } | 178 } |
178 | 179 |
179 void TopDocumentRootScrollerController:: | 180 void TopDocumentRootScrollerController:: |
180 setNeedsCompositingInputsUpdateOnGlobalRootScroller() { | 181 setNeedsCompositingInputsUpdateOnGlobalRootScroller() { |
181 if (!m_globalRootScroller) | 182 if (!m_globalRootScroller) |
182 return; | 183 return; |
183 | 184 |
184 PaintLayer* layer = m_globalRootScroller->document() | 185 PaintLayer* layer = m_globalRootScroller->document() |
185 .rootScrollerController() | 186 .rootScrollerController() |
186 .rootScrollerPaintLayer(); | 187 .rootScrollerPaintLayer(); |
187 | 188 |
188 if (layer) | 189 if (layer) |
189 layer->setNeedsCompositingInputsUpdate(); | 190 layer->setNeedsCompositingInputsUpdate(); |
190 | 191 |
191 if (LayoutView* view = m_globalRootScroller->document().layoutView()) { | 192 if (LayoutView* view = m_globalRootScroller->document().layoutView()) { |
192 view->compositor()->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); | 193 view->compositor()->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); |
193 } | 194 } |
194 } | 195 } |
195 | 196 |
196 void TopDocumentRootScrollerController::didUpdateCompositing() { | 197 void TopDocumentRootScrollerController::didUpdateCompositing() { |
197 if (!m_frameHost) | 198 if (!m_page) |
198 return; | 199 return; |
199 | 200 |
200 // Let the compositor-side counterpart know about this change. | 201 // Let the compositor-side counterpart know about this change. |
201 m_frameHost->page().chromeClient().registerViewportLayers(); | 202 m_page->frameHost().page().chromeClient().registerViewportLayers(); |
202 } | 203 } |
203 | 204 |
204 void TopDocumentRootScrollerController::didDisposeScrollableArea( | 205 void TopDocumentRootScrollerController::didDisposeScrollableArea( |
205 ScrollableArea& area) { | 206 ScrollableArea& area) { |
206 if (!topDocument() || !topDocument()->view()) | 207 if (!topDocument() || !topDocument()->view()) |
207 return; | 208 return; |
208 | 209 |
209 // If the document is tearing down, we may no longer have a layoutViewport to | 210 // If the document is tearing down, we may no longer have a layoutViewport to |
210 // fallback to. | 211 // fallback to. |
211 if (topDocument()->lifecycle().state() >= DocumentLifecycle::Stopping) | 212 if (topDocument()->lifecycle().state() >= DocumentLifecycle::Stopping) |
212 return; | 213 return; |
213 | 214 |
214 FrameView* frameView = topDocument()->view(); | 215 FrameView* frameView = topDocument()->view(); |
215 | 216 |
216 RootFrameViewport* rfv = frameView->getRootFrameViewport(); | 217 RootFrameViewport* rfv = frameView->getRootFrameViewport(); |
217 | 218 |
218 if (&area == &rfv->layoutViewport()) { | 219 if (&area == &rfv->layoutViewport()) { |
219 DCHECK(frameView->layoutViewportScrollableArea()); | 220 DCHECK(frameView->layoutViewportScrollableArea()); |
220 rfv->setLayoutViewport(*frameView->layoutViewportScrollableArea()); | 221 rfv->setLayoutViewport(*frameView->layoutViewportScrollableArea()); |
221 } | 222 } |
222 } | 223 } |
223 | 224 |
224 void TopDocumentRootScrollerController::initializeViewportScrollCallback( | 225 void TopDocumentRootScrollerController::initializeViewportScrollCallback( |
225 RootFrameViewport& rootFrameViewport) { | 226 RootFrameViewport& rootFrameViewport) { |
226 DCHECK(m_frameHost); | 227 DCHECK(m_page); |
227 m_viewportApplyScroll = ViewportScrollCallback::create( | 228 m_viewportApplyScroll = ViewportScrollCallback::create( |
228 &m_frameHost->browserControls(), &m_frameHost->overscrollController(), | 229 &m_page->frameHost().browserControls(), |
229 rootFrameViewport); | 230 &m_page->frameHost().overscrollController(), rootFrameViewport); |
230 | 231 |
231 recomputeGlobalRootScroller(); | 232 recomputeGlobalRootScroller(); |
232 } | 233 } |
233 | 234 |
234 bool TopDocumentRootScrollerController::isViewportScrollCallback( | 235 bool TopDocumentRootScrollerController::isViewportScrollCallback( |
235 const ScrollStateCallback* callback) const { | 236 const ScrollStateCallback* callback) const { |
236 if (!callback) | 237 if (!callback) |
237 return false; | 238 return false; |
238 | 239 |
239 return callback == m_viewportApplyScroll.get(); | 240 return callback == m_viewportApplyScroll.get(); |
(...skipping 17 matching lines...) Expand all Loading... | |
257 | 258 |
258 PaintLayer* TopDocumentRootScrollerController::rootScrollerPaintLayer() const { | 259 PaintLayer* TopDocumentRootScrollerController::rootScrollerPaintLayer() const { |
259 return RootScrollerUtil::paintLayerForRootScroller(m_globalRootScroller); | 260 return RootScrollerUtil::paintLayerForRootScroller(m_globalRootScroller); |
260 } | 261 } |
261 | 262 |
262 Element* TopDocumentRootScrollerController::globalRootScroller() const { | 263 Element* TopDocumentRootScrollerController::globalRootScroller() const { |
263 return m_globalRootScroller.get(); | 264 return m_globalRootScroller.get(); |
264 } | 265 } |
265 | 266 |
266 } // namespace blink | 267 } // namespace blink |
OLD | NEW |