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/RootScrollerController.h" | 5 #include "core/page/scrolling/RootScrollerController.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/layout/LayoutBox.h" | 11 #include "core/layout/LayoutBox.h" |
12 #include "core/layout/api/LayoutViewItem.h" | 12 #include "core/layout/api/LayoutViewItem.h" |
| 13 #include "core/layout/compositing/PaintLayerCompositor.h" |
| 14 #include "core/paint/PaintLayer.h" |
13 #include "core/paint/PaintLayerScrollableArea.h" | 15 #include "core/paint/PaintLayerScrollableArea.h" |
14 #include "platform/graphics/GraphicsLayer.h" | 16 #include "platform/graphics/GraphicsLayer.h" |
15 #include "platform/scroll/ScrollableArea.h" | 17 #include "platform/scroll/ScrollableArea.h" |
16 | 18 |
17 namespace blink { | 19 namespace blink { |
18 | 20 |
19 class RootFrameViewport; | 21 class RootFrameViewport; |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 bool rootScrollerValid = | 95 bool rootScrollerValid = |
94 m_rootScroller && isValidRootScroller(*m_rootScroller); | 96 m_rootScroller && isValidRootScroller(*m_rootScroller); |
95 | 97 |
96 Element* newEffectiveRootScroller = rootScrollerValid | 98 Element* newEffectiveRootScroller = rootScrollerValid |
97 ? m_rootScroller.get() | 99 ? m_rootScroller.get() |
98 : defaultEffectiveRootScroller(); | 100 : defaultEffectiveRootScroller(); |
99 | 101 |
100 if (m_effectiveRootScroller == newEffectiveRootScroller) | 102 if (m_effectiveRootScroller == newEffectiveRootScroller) |
101 return; | 103 return; |
102 | 104 |
| 105 PaintLayer* oldRootScrollerLayer = rootScrollerPaintLayer(); |
| 106 |
103 m_effectiveRootScroller = newEffectiveRootScroller; | 107 m_effectiveRootScroller = newEffectiveRootScroller; |
104 | 108 |
| 109 // This change affects both the old and new layers. |
| 110 if (oldRootScrollerLayer) |
| 111 oldRootScrollerLayer->setNeedsCompositingInputsUpdate(); |
| 112 if (rootScrollerPaintLayer()) |
| 113 rootScrollerPaintLayer()->setNeedsCompositingInputsUpdate(); |
| 114 |
| 115 // The above may not be enough as we need to update existing ancestor |
| 116 // GraphicsLayers. This will force us to rebuild the GraphicsLayer tree. |
| 117 if (LayoutView* layoutView = m_document->layoutView()) { |
| 118 layoutView->compositor() |
| 119 ->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); |
| 120 } |
| 121 |
105 m_document->topDocument().rootScrollerController() | 122 m_document->topDocument().rootScrollerController() |
106 ->globalRootScrollerMayHaveChanged(); | 123 ->globalRootScrollerMayHaveChanged(); |
107 } | 124 } |
108 | 125 |
109 ScrollableArea* RootScrollerController::scrollableAreaFor( | 126 ScrollableArea* RootScrollerController::scrollableAreaFor( |
110 const Element& element) const | 127 const Element& element) const |
111 { | 128 { |
112 if (!element.layoutObject() || !element.layoutObject()->isBox()) | 129 if (!element.layoutObject() || !element.layoutObject()->isBox()) |
113 return nullptr; | 130 return nullptr; |
114 | 131 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // no way to get at the ViewportScrollCallback so just return false. | 182 // no way to get at the ViewportScrollCallback so just return false. |
166 // TODO(bokan): Make document.rootScroller work in OOPIF. crbug.com/642378. | 183 // TODO(bokan): Make document.rootScroller work in OOPIF. crbug.com/642378. |
167 if (!m_document->localOwner()) | 184 if (!m_document->localOwner()) |
168 return false; | 185 return false; |
169 | 186 |
170 RootScrollerController* topDocumentController = | 187 RootScrollerController* topDocumentController = |
171 m_document->topDocument().rootScrollerController(); | 188 m_document->topDocument().rootScrollerController(); |
172 return topDocumentController->isViewportScrollCallback(callback); | 189 return topDocumentController->isViewportScrollCallback(callback); |
173 } | 190 } |
174 | 191 |
| 192 PaintLayer* RootScrollerController::rootScrollerPaintLayer() const |
| 193 { |
| 194 if (!m_effectiveRootScroller |
| 195 || !m_effectiveRootScroller->layoutObject() |
| 196 || !m_effectiveRootScroller->layoutObject()->isBox()) |
| 197 return nullptr; |
| 198 |
| 199 LayoutBox* box = toLayoutBox(m_effectiveRootScroller->layoutObject()); |
| 200 PaintLayer* layer = box->layer(); |
| 201 |
| 202 // If the root scroller is the <html> element we do a bit of a fake out beca
use |
| 203 // while <html> has a PaintLayer, scrolling for it is handled by the #docume
nt's |
| 204 // PaintLayer (i.e. the PaintLayerCompositor's root layer). The reason the r
oot |
| 205 // scroller is the <html> layer and not #document is because the latter is a
Node |
| 206 // but not an Element. |
| 207 if (m_effectiveRootScroller->isSameNode(m_document->documentElement())) |
| 208 return layer->compositor()->rootLayer(); |
| 209 |
| 210 return layer; |
| 211 } |
| 212 |
175 Element* RootScrollerController::defaultEffectiveRootScroller() | 213 Element* RootScrollerController::defaultEffectiveRootScroller() |
176 { | 214 { |
177 DCHECK(m_document); | 215 DCHECK(m_document); |
178 return m_document->documentElement(); | 216 return m_document->documentElement(); |
179 } | 217 } |
180 | 218 |
181 } // namespace blink | 219 } // namespace blink |
OLD | NEW |