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/RootScrollerUtil.h" | 5 #include "core/page/scrolling/RootScrollerUtil.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/FrameView.h" | 9 #include "core/frame/FrameView.h" |
| 10 #include "core/layout/LayoutBox.h" |
10 #include "core/layout/LayoutBoxModelObject.h" | 11 #include "core/layout/LayoutBoxModelObject.h" |
| 12 #include "core/layout/LayoutView.h" |
11 #include "core/paint/PaintLayerScrollableArea.h" | 13 #include "core/paint/PaintLayerScrollableArea.h" |
12 | 14 |
13 namespace blink { | 15 namespace blink { |
14 | 16 |
15 namespace RootScrollerUtil { | 17 namespace RootScrollerUtil { |
16 | 18 |
17 ScrollableArea* scrollableAreaFor(const Element& element) { | 19 ScrollableArea* scrollableAreaForRootScroller(const Element& element) { |
18 if (&element == element.document().documentElement()) { | 20 if (&element == element.document().documentElement()) { |
19 if (!element.document().view()) | 21 if (!element.document().view()) |
20 return nullptr; | 22 return nullptr; |
21 | 23 |
22 // For a FrameView, we use the layoutViewport rather than the | 24 // For a FrameView, we use the layoutViewport rather than the |
23 // getScrollableArea() since that could be the RootFrameViewport. The | 25 // getScrollableArea() since that could be the RootFrameViewport. The |
24 // rootScroller's ScrollableArea will be swapped in as the layout viewport | 26 // rootScroller's ScrollableArea will be swapped in as the layout viewport |
25 // in RootFrameViewport so we need to ensure we get the layout viewport. | 27 // in RootFrameViewport so we need to ensure we get the layout viewport. |
26 return element.document().view()->layoutViewportScrollableArea(); | 28 return element.document().view()->layoutViewportScrollableArea(); |
27 } | 29 } |
28 | 30 |
29 if (!element.layoutObject() || !element.layoutObject()->isBox()) | 31 if (!element.layoutObject() || !element.layoutObject()->isBox()) |
30 return nullptr; | 32 return nullptr; |
31 | 33 |
32 return static_cast<PaintInvalidationCapableScrollableArea*>( | 34 return static_cast<PaintInvalidationCapableScrollableArea*>( |
33 toLayoutBoxModelObject(element.layoutObject())->getScrollableArea()); | 35 toLayoutBoxModelObject(element.layoutObject())->getScrollableArea()); |
34 } | 36 } |
35 | 37 |
| 38 PaintLayer* paintLayerForRootScroller(const Element* element) { |
| 39 if (!element || !element->layoutObject()) |
| 40 return nullptr; |
| 41 |
| 42 DCHECK(element->layoutObject()->isBox()); |
| 43 LayoutBox* box = toLayoutBox(element->layoutObject()); |
| 44 |
| 45 // If the root scroller is the <html> element we do a bit of a fake out |
| 46 // because while <html> has a PaintLayer, scrolling for it is handled by the |
| 47 // #document's PaintLayer (i.e. the PaintLayerCompositor's root layer). The |
| 48 // reason the root scroller is the <html> layer and not #document is because |
| 49 // the latter is a Node but not an Element. |
| 50 if (element->isSameNode(element->document().documentElement())) { |
| 51 if (!box->view()) |
| 52 return nullptr; |
| 53 return box->view()->layer(); |
| 54 } |
| 55 |
| 56 return box->layer(); |
| 57 } |
| 58 |
36 } // namespace RootScrollerUtil | 59 } // namespace RootScrollerUtil |
37 | 60 |
38 } // namespace blink | 61 } // namespace blink |
OLD | NEW |