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