| 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/compositing/CompositedLayerMapping.h" | 12 #include "core/layout/compositing/CompositedLayerMapping.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 m_effectiveRootScroller = newEffectiveRootScroller; | 103 m_effectiveRootScroller = newEffectiveRootScroller; |
| 106 | 104 |
| 107 if (PaintLayer* layer = rootScrollerPaintLayer()) | 105 if (PaintLayer* layer = rootScrollerPaintLayer()) |
| 108 layer->setNeedsCompositingInputsUpdate(); | 106 layer->setNeedsCompositingInputsUpdate(); |
| 109 | 107 |
| 110 m_document->topDocument().rootScrollerController() | 108 if (FrameHost* frameHost = m_document->frameHost()) |
| 111 ->globalRootScrollerMayHaveChanged(); | 109 frameHost->globalRootScrollerController().didChangeRootScroller(); |
| 112 } | |
| 113 | |
| 114 ScrollableArea* RootScrollerController::scrollableAreaFor( | |
| 115 const Element& element) const | |
| 116 { | |
| 117 if (!element.layoutObject() || !element.layoutObject()->isBox()) | |
| 118 return nullptr; | |
| 119 | |
| 120 LayoutBox* box = toLayoutBox(element.layoutObject()); | |
| 121 | |
| 122 // For a FrameView, we use the layoutViewport rather than the | |
| 123 // getScrollableArea() since that could be the RootFrameViewport. The | |
| 124 // rootScroller's ScrollableArea will be swapped in as the layout viewport | |
| 125 // in RootFrameViewport so we need to ensure we get the layout viewport. | |
| 126 if (box->isDocumentElement()) | |
| 127 return element.document().view()->layoutViewportScrollableArea(); | |
| 128 | |
| 129 return static_cast<PaintInvalidationCapableScrollableArea*>( | |
| 130 box->getScrollableArea()); | |
| 131 } | 110 } |
| 132 | 111 |
| 133 bool RootScrollerController::isValidRootScroller(const Element& element) const | 112 bool RootScrollerController::isValidRootScroller(const Element& element) const |
| 134 { | 113 { |
| 135 if (!element.layoutObject()) | 114 if (!element.layoutObject()) |
| 136 return false; | 115 return false; |
| 137 | 116 |
| 138 if (!scrollableAreaFor(element)) | 117 if (!RootScrollerUtil::scrollableAreaFor(element)) |
| 139 return false; | 118 return false; |
| 140 | 119 |
| 141 if (!fillsViewport(element)) | 120 if (!fillsViewport(element)) |
| 142 return false; | 121 return false; |
| 143 | 122 |
| 144 return true; | 123 return true; |
| 145 } | 124 } |
| 146 | 125 |
| 147 void RootScrollerController::didUpdateCompositing() | |
| 148 { | |
| 149 } | |
| 150 | |
| 151 void RootScrollerController::didAttachDocument() | |
| 152 { | |
| 153 } | |
| 154 | |
| 155 GraphicsLayer* RootScrollerController::rootScrollerLayer() | |
| 156 { | |
| 157 NOTREACHED(); | |
| 158 return nullptr; | |
| 159 } | |
| 160 | |
| 161 bool RootScrollerController::isViewportScrollCallback( | |
| 162 const ScrollStateCallback* callback) const | |
| 163 { | |
| 164 // TopDocumentRootScrollerController must override this method to actually | |
| 165 // do the comparison. | |
| 166 DCHECK(!m_document->isInMainFrame()); | |
| 167 | |
| 168 RootScrollerController* topDocumentController = | |
| 169 m_document->topDocument().rootScrollerController(); | |
| 170 return topDocumentController->isViewportScrollCallback(callback); | |
| 171 } | |
| 172 | |
| 173 PaintLayer* RootScrollerController::rootScrollerPaintLayer() const | 126 PaintLayer* RootScrollerController::rootScrollerPaintLayer() const |
| 174 { | 127 { |
| 175 if (!m_effectiveRootScroller) | 128 if (!m_effectiveRootScroller) |
| 176 return nullptr; | 129 return nullptr; |
| 177 | 130 |
| 178 LayoutBox* box = toLayoutBox(m_effectiveRootScroller->layoutObject()); | 131 LayoutBox* box = toLayoutBox(m_effectiveRootScroller->layoutObject()); |
| 179 if (!box) | 132 if (!box) |
| 180 return nullptr; | 133 return nullptr; |
| 181 | 134 |
| 182 PaintLayer* layer = box->layer(); | 135 PaintLayer* layer = box->layer(); |
| 183 | 136 |
| 184 // If the root scroller is the <html> element we do a bit of a fake out beca
use | 137 // If the root scroller is the <html> element we do a bit of a fake out beca
use |
| 185 // while <html> has a PaintLayer, scrolling for it is handled by the #docume
nt's | 138 // while <html> has a PaintLayer, scrolling for it is handled by the #docume
nt's |
| 186 // PaintLayer (i.e. the PaintLayerCompositor's root layer). The reason the r
oot | 139 // PaintLayer (i.e. the PaintLayerCompositor's root layer). The reason the r
oot |
| 187 // scroller is the <html> layer and not #document is because the latter is a
Node | 140 // scroller is the <html> layer and not #document is because the latter is a
Node |
| 188 // but not an Element. | 141 // but not an Element. |
| 189 if (m_effectiveRootScroller->isSameNode(m_document->documentElement())) | 142 if (m_effectiveRootScroller->isSameNode(m_document->documentElement())) |
| 190 return layer->compositor()->rootLayer(); | 143 return layer->compositor()->rootLayer(); |
| 191 | 144 |
| 192 return layer; | 145 return layer; |
| 193 } | 146 } |
| 194 | 147 |
| 195 Element* RootScrollerController::defaultEffectiveRootScroller() | 148 Element* RootScrollerController::defaultEffectiveRootScroller() |
| 196 { | 149 { |
| 197 DCHECK(m_document); | 150 DCHECK(m_document); |
| 198 return m_document->documentElement(); | 151 return m_document->documentElement(); |
| 199 } | 152 } |
| 200 | 153 |
| 201 } // namespace blink | 154 } // namespace blink |
| OLD | NEW |