| 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" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 DEFINE_TRACE(TopDocumentRootScrollerController) { | 34 DEFINE_TRACE(TopDocumentRootScrollerController) { |
| 35 visitor->trace(m_viewportApplyScroll); | 35 visitor->trace(m_viewportApplyScroll); |
| 36 visitor->trace(m_globalRootScroller); | 36 visitor->trace(m_globalRootScroller); |
| 37 visitor->trace(m_frameHost); | 37 visitor->trace(m_frameHost); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void TopDocumentRootScrollerController::didChangeRootScroller() { | 40 void TopDocumentRootScrollerController::didChangeRootScroller() { |
| 41 recomputeGlobalRootScroller(); | 41 recomputeGlobalRootScroller(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void TopDocumentRootScrollerController::mainFrameViewResized() { |
| 45 Element* rootScroller = globalRootScroller(); |
| 46 if (!rootScroller) |
| 47 return; |
| 48 |
| 49 ScrollableArea* area = |
| 50 RootScrollerUtil::scrollableAreaForRootScroller(*rootScroller); |
| 51 |
| 52 if (!area) |
| 53 return; |
| 54 |
| 55 if (PaintLayer* layer = area->layer()) { |
| 56 layer->setNeedsCompositingInputsUpdate(); |
| 57 |
| 58 // This is needed if the root scroller is an iframe, since the iframe |
| 59 // doesn't have a scrolling/clip layer, its PLC has a container layer that |
| 60 // needs to be resized instead. |
| 61 layer->compositor()->frameViewDidChangeSize(); |
| 62 } |
| 63 } |
| 64 |
| 44 Element* TopDocumentRootScrollerController::findGlobalRootScrollerElement() { | 65 Element* TopDocumentRootScrollerController::findGlobalRootScrollerElement() { |
| 45 if (!topDocument()) | 66 if (!topDocument()) |
| 46 return nullptr; | 67 return nullptr; |
| 47 | 68 |
| 48 DCHECK(topDocument()->rootScrollerController()); | 69 DCHECK(topDocument()->rootScrollerController()); |
| 49 Element* element = | 70 Element* element = |
| 50 topDocument()->rootScrollerController()->effectiveRootScroller(); | 71 topDocument()->rootScrollerController()->effectiveRootScroller(); |
| 51 | 72 |
| 52 while (element && element->isFrameOwnerElement()) { | 73 while (element && element->isFrameOwnerElement()) { |
| 53 HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(element); | 74 HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(element); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 65 } | 86 } |
| 66 | 87 |
| 67 void TopDocumentRootScrollerController::recomputeGlobalRootScroller() { | 88 void TopDocumentRootScrollerController::recomputeGlobalRootScroller() { |
| 68 if (!m_viewportApplyScroll) | 89 if (!m_viewportApplyScroll) |
| 69 return; | 90 return; |
| 70 | 91 |
| 71 Element* target = findGlobalRootScrollerElement(); | 92 Element* target = findGlobalRootScrollerElement(); |
| 72 if (!target || target == m_globalRootScroller) | 93 if (!target || target == m_globalRootScroller) |
| 73 return; | 94 return; |
| 74 | 95 |
| 75 ScrollableArea* targetScroller = RootScrollerUtil::scrollableAreaFor(*target); | 96 ScrollableArea* targetScroller = |
| 97 RootScrollerUtil::scrollableAreaForRootScroller(*target); |
| 76 | 98 |
| 77 if (!targetScroller) | 99 if (!targetScroller) |
| 78 return; | 100 return; |
| 79 | 101 |
| 80 if (m_globalRootScroller) | 102 if (m_globalRootScroller) |
| 81 m_globalRootScroller->removeApplyScroll(); | 103 m_globalRootScroller->removeApplyScroll(); |
| 82 | 104 |
| 83 // Use disable-native-scroll since the ViewportScrollCallback needs to | 105 // Use disable-native-scroll since the ViewportScrollCallback needs to |
| 84 // apply scroll actions both before (BrowserControls) and after (overscroll) | 106 // apply scroll actions both before (BrowserControls) and after (overscroll) |
| 85 // scrolling the element so it will apply scroll to the element itself. | 107 // scrolling the element so it will apply scroll to the element itself. |
| 86 target->setApplyScroll(m_viewportApplyScroll, "disable-native-scroll"); | 108 target->setApplyScroll(m_viewportApplyScroll, "disable-native-scroll"); |
| 87 | 109 |
| 88 // A change in global root scroller requires a compositing inputs update to | 110 // A change in global root scroller requires a compositing inputs update to |
| 89 // the new and old global root scroller since it might change how the | 111 // the new and old global root scroller since it might change how the |
| 90 // ancestor layers are clipped. e.g. An iframe that's the global root | 112 // ancestor layers are clipped. e.g. An iframe that's the global root |
| 91 // scroller clips its layers like the root frame. Normally this is set | 113 // scroller clips its layers like the root frame. Normally this is set |
| 92 // when the local effective root scroller changes but the global root | 114 // when the local effective root scroller changes but the global root |
| 93 // scroller can change because the parent's effective root scroller | 115 // scroller can change because the parent's effective root scroller |
| 94 // changes. | 116 // changes. |
| 95 setNeedsCompositingInputsUpdateOnGlobalRootScroller(); | 117 setNeedsCompositingInputsUpdateOnGlobalRootScroller(); |
| 96 | 118 |
| 97 ScrollableArea* oldRootScrollerArea = | 119 ScrollableArea* oldRootScrollerArea = |
| 98 m_globalRootScroller | 120 m_globalRootScroller ? RootScrollerUtil::scrollableAreaForRootScroller( |
| 99 ? RootScrollerUtil::scrollableAreaFor(*m_globalRootScroller.get()) | 121 *m_globalRootScroller.get()) |
| 100 : nullptr; | 122 : nullptr; |
| 101 | 123 |
| 102 m_globalRootScroller = target; | 124 m_globalRootScroller = target; |
| 103 | 125 |
| 104 setNeedsCompositingInputsUpdateOnGlobalRootScroller(); | 126 setNeedsCompositingInputsUpdateOnGlobalRootScroller(); |
| 105 | 127 |
| 106 // Ideally, scroll customization would pass the current element to scroll to | 128 // Ideally, scroll customization would pass the current element to scroll to |
| 107 // the apply scroll callback but this doesn't happen today so we set it | 129 // the apply scroll callback but this doesn't happen today so we set it |
| 108 // through a back door here. This is also needed by the | 130 // through a back door here. This is also needed by the |
| 109 // ViewportScrollCallback to swap the target into the layout viewport | 131 // ViewportScrollCallback to swap the target into the layout viewport |
| 110 // in RootFrameViewport. | 132 // in RootFrameViewport. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 return false; | 192 return false; |
| 171 | 193 |
| 172 return callback == m_viewportApplyScroll.get(); | 194 return callback == m_viewportApplyScroll.get(); |
| 173 } | 195 } |
| 174 | 196 |
| 175 GraphicsLayer* TopDocumentRootScrollerController::rootScrollerLayer() const { | 197 GraphicsLayer* TopDocumentRootScrollerController::rootScrollerLayer() const { |
| 176 if (!m_globalRootScroller) | 198 if (!m_globalRootScroller) |
| 177 return nullptr; | 199 return nullptr; |
| 178 | 200 |
| 179 ScrollableArea* area = | 201 ScrollableArea* area = |
| 180 RootScrollerUtil::scrollableAreaFor(*m_globalRootScroller); | 202 RootScrollerUtil::scrollableAreaForRootScroller(*m_globalRootScroller); |
| 181 | 203 |
| 182 if (!area) | 204 if (!area) |
| 183 return nullptr; | 205 return nullptr; |
| 184 | 206 |
| 185 GraphicsLayer* graphicsLayer = area->layerForScrolling(); | 207 GraphicsLayer* graphicsLayer = area->layerForScrolling(); |
| 186 | 208 |
| 187 // TODO(bokan): We should assert graphicsLayer here and | 209 // TODO(bokan): We should assert graphicsLayer here and |
| 188 // RootScrollerController should do whatever needs to happen to ensure | 210 // RootScrollerController should do whatever needs to happen to ensure |
| 189 // the root scroller gets composited. | 211 // the root scroller gets composited. |
| 190 | 212 |
| 191 return graphicsLayer; | 213 return graphicsLayer; |
| 192 } | 214 } |
| 193 | 215 |
| 216 PaintLayer* TopDocumentRootScrollerController::rootScrollerPaintLayer() const { |
| 217 return RootScrollerUtil::paintLayerForRootScroller(m_globalRootScroller); |
| 218 } |
| 219 |
| 194 Element* TopDocumentRootScrollerController::globalRootScroller() const { | 220 Element* TopDocumentRootScrollerController::globalRootScroller() const { |
| 195 return m_globalRootScroller.get(); | 221 return m_globalRootScroller.get(); |
| 196 } | 222 } |
| 197 | 223 |
| 198 } // namespace blink | 224 } // namespace blink |
| OLD | NEW |