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" | 13 #include "core/layout/compositing/PaintLayerCompositor.h" |
| 14 #include "core/page/scrolling/RootScrollerUtil.h" |
| 15 #include "core/page/scrolling/TopDocumentRootScrollerController.h" |
14 #include "core/paint/PaintLayer.h" | 16 #include "core/paint/PaintLayer.h" |
15 #include "core/paint/PaintLayerScrollableArea.h" | 17 #include "core/paint/PaintLayerScrollableArea.h" |
16 #include "platform/graphics/GraphicsLayer.h" | 18 #include "platform/graphics/GraphicsLayer.h" |
17 #include "platform/scroll/ScrollableArea.h" | 19 #include "platform/scroll/ScrollableArea.h" |
18 | 20 |
19 namespace blink { | 21 namespace blink { |
20 | 22 |
21 class RootFrameViewport; | 23 class RootFrameViewport; |
22 | 24 |
23 namespace { | 25 namespace { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 Element* RootScrollerController::effectiveRootScroller() const | 81 Element* RootScrollerController::effectiveRootScroller() const |
80 { | 82 { |
81 return m_effectiveRootScroller; | 83 return m_effectiveRootScroller; |
82 } | 84 } |
83 | 85 |
84 void RootScrollerController::didUpdateLayout() | 86 void RootScrollerController::didUpdateLayout() |
85 { | 87 { |
86 recomputeEffectiveRootScroller(); | 88 recomputeEffectiveRootScroller(); |
87 } | 89 } |
88 | 90 |
89 void RootScrollerController::globalRootScrollerMayHaveChanged() | |
90 { | |
91 } | |
92 | |
93 void RootScrollerController::recomputeEffectiveRootScroller() | 91 void RootScrollerController::recomputeEffectiveRootScroller() |
94 { | 92 { |
95 bool rootScrollerValid = | 93 bool rootScrollerValid = |
96 m_rootScroller && isValidRootScroller(*m_rootScroller); | 94 m_rootScroller && isValidRootScroller(*m_rootScroller); |
97 | 95 |
98 Element* newEffectiveRootScroller = rootScrollerValid | 96 Element* newEffectiveRootScroller = rootScrollerValid |
99 ? m_rootScroller.get() | 97 ? m_rootScroller.get() |
100 : defaultEffectiveRootScroller(); | 98 : defaultEffectiveRootScroller(); |
101 | 99 |
102 if (m_effectiveRootScroller == newEffectiveRootScroller) | 100 if (m_effectiveRootScroller == newEffectiveRootScroller) |
103 return; | 101 return; |
104 | 102 |
105 PaintLayer* oldRootScrollerLayer = rootScrollerPaintLayer(); | 103 PaintLayer* oldRootScrollerLayer = rootScrollerPaintLayer(); |
106 | 104 |
107 m_effectiveRootScroller = newEffectiveRootScroller; | 105 m_effectiveRootScroller = newEffectiveRootScroller; |
108 | 106 |
109 // This change affects both the old and new layers. | 107 // This change affects both the old and new layers. |
110 if (oldRootScrollerLayer) | 108 if (oldRootScrollerLayer) |
111 oldRootScrollerLayer->setNeedsCompositingInputsUpdate(); | 109 oldRootScrollerLayer->setNeedsCompositingInputsUpdate(); |
112 if (rootScrollerPaintLayer()) | 110 if (rootScrollerPaintLayer()) |
113 rootScrollerPaintLayer()->setNeedsCompositingInputsUpdate(); | 111 rootScrollerPaintLayer()->setNeedsCompositingInputsUpdate(); |
114 | 112 |
115 // The above may not be enough as we need to update existing ancestor | 113 // The above may not be enough as we need to update existing ancestor |
116 // GraphicsLayers. This will force us to rebuild the GraphicsLayer tree. | 114 // GraphicsLayers. This will force us to rebuild the GraphicsLayer tree. |
117 if (LayoutView* layoutView = m_document->layoutView()) { | 115 if (LayoutView* layoutView = m_document->layoutView()) { |
118 layoutView->compositor() | 116 layoutView->compositor() |
119 ->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); | 117 ->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); |
120 } | 118 } |
121 | 119 |
122 m_document->topDocument().rootScrollerController() | 120 if (FrameHost* frameHost = m_document->frameHost()) |
123 ->globalRootScrollerMayHaveChanged(); | 121 frameHost->globalRootScrollerController().didChangeRootScroller(); |
124 } | |
125 | |
126 ScrollableArea* RootScrollerController::scrollableAreaFor( | |
127 const Element& element) const | |
128 { | |
129 if (!element.layoutObject() || !element.layoutObject()->isBox()) | |
130 return nullptr; | |
131 | |
132 LayoutBox* box = toLayoutBox(element.layoutObject()); | |
133 | |
134 // For a FrameView, we use the layoutViewport rather than the | |
135 // getScrollableArea() since that could be the RootFrameViewport. The | |
136 // rootScroller's ScrollableArea will be swapped in as the layout viewport | |
137 // in RootFrameViewport so we need to ensure we get the layout viewport. | |
138 if (box->isDocumentElement()) | |
139 return element.document().view()->layoutViewportScrollableArea(); | |
140 | |
141 return static_cast<PaintInvalidationCapableScrollableArea*>( | |
142 box->getScrollableArea()); | |
143 } | 122 } |
144 | 123 |
145 bool RootScrollerController::isValidRootScroller(const Element& element) const | 124 bool RootScrollerController::isValidRootScroller(const Element& element) const |
146 { | 125 { |
147 if (!element.layoutObject()) | 126 if (!element.layoutObject()) |
148 return false; | 127 return false; |
149 | 128 |
150 if (!scrollableAreaFor(element)) | 129 if (!RootScrollerUtil::scrollableAreaFor(element)) |
151 return false; | 130 return false; |
152 | 131 |
153 if (!fillsViewport(element)) | 132 if (!fillsViewport(element)) |
154 return false; | 133 return false; |
155 | 134 |
156 return true; | 135 return true; |
157 } | 136 } |
158 | 137 |
159 void RootScrollerController::didUpdateCompositing() | |
160 { | |
161 } | |
162 | |
163 void RootScrollerController::didAttachDocument() | |
164 { | |
165 } | |
166 | |
167 GraphicsLayer* RootScrollerController::rootScrollerLayer() | |
168 { | |
169 NOTREACHED(); | |
170 return nullptr; | |
171 } | |
172 | |
173 bool RootScrollerController::isViewportScrollCallback( | |
174 const ScrollStateCallback* callback) const | |
175 { | |
176 // TopDocumentRootScrollerController must override this method to actually | |
177 // do the comparison. | |
178 DCHECK(!m_document->isInMainFrame()); | |
179 | |
180 // If we don't have a local owner we must be in a remote iframe. | |
181 // RootScrollerController doesn't yet work in OOPIF and in any case we have | |
182 // no way to get at the ViewportScrollCallback so just return false. | |
183 // TODO(bokan): Make document.rootScroller work in OOPIF. crbug.com/642378. | |
184 if (!m_document->localOwner()) | |
185 return false; | |
186 | |
187 RootScrollerController* topDocumentController = | |
188 m_document->topDocument().rootScrollerController(); | |
189 return topDocumentController->isViewportScrollCallback(callback); | |
190 } | |
191 | |
192 PaintLayer* RootScrollerController::rootScrollerPaintLayer() const | 138 PaintLayer* RootScrollerController::rootScrollerPaintLayer() const |
193 { | 139 { |
194 if (!m_effectiveRootScroller | 140 if (!m_effectiveRootScroller |
195 || !m_effectiveRootScroller->layoutObject() | 141 || !m_effectiveRootScroller->layoutObject() |
196 || !m_effectiveRootScroller->layoutObject()->isBox()) | 142 || !m_effectiveRootScroller->layoutObject()->isBox()) |
197 return nullptr; | 143 return nullptr; |
198 | 144 |
199 LayoutBox* box = toLayoutBox(m_effectiveRootScroller->layoutObject()); | 145 LayoutBox* box = toLayoutBox(m_effectiveRootScroller->layoutObject()); |
200 PaintLayer* layer = box->layer(); | 146 PaintLayer* layer = box->layer(); |
201 | 147 |
202 // If the root scroller is the <html> element we do a bit of a fake out beca
use | 148 // 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 | 149 // 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 | 150 // 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 | 151 // scroller is the <html> layer and not #document is because the latter is a
Node |
206 // but not an Element. | 152 // but not an Element. |
207 if (m_effectiveRootScroller->isSameNode(m_document->documentElement())) | 153 if (m_effectiveRootScroller->isSameNode(m_document->documentElement())) |
208 return layer->compositor()->rootLayer(); | 154 return layer->compositor()->rootLayer(); |
209 | 155 |
210 return layer; | 156 return layer; |
211 } | 157 } |
212 | 158 |
213 Element* RootScrollerController::defaultEffectiveRootScroller() | 159 Element* RootScrollerController::defaultEffectiveRootScroller() |
214 { | 160 { |
215 DCHECK(m_document); | 161 DCHECK(m_document); |
216 return m_document->documentElement(); | 162 return m_document->documentElement(); |
217 } | 163 } |
218 | 164 |
219 } // namespace blink | 165 } // namespace blink |
OLD | NEW |