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" |
11 #include "core/html/HTMLFrameOwnerElement.h" | 11 #include "core/html/HTMLFrameOwnerElement.h" |
12 #include "core/page/ChromeClient.h" | 12 #include "core/page/ChromeClient.h" |
13 #include "core/page/Page.h" | |
13 #include "core/page/scrolling/OverscrollController.h" | 14 #include "core/page/scrolling/OverscrollController.h" |
15 #include "core/page/scrolling/RootScrollerUtil.h" | |
14 #include "core/page/scrolling/ViewportScrollCallback.h" | 16 #include "core/page/scrolling/ViewportScrollCallback.h" |
15 #include "platform/scroll/ScrollableArea.h" | 17 #include "platform/scroll/ScrollableArea.h" |
16 | 18 |
17 namespace blink { | 19 namespace blink { |
18 | 20 |
19 // static | 21 // static |
20 TopDocumentRootScrollerController* TopDocumentRootScrollerController::create( | 22 TopDocumentRootScrollerController* TopDocumentRootScrollerController::create( |
21 Document& document) | 23 FrameHost& host) |
22 { | 24 { |
23 return new TopDocumentRootScrollerController(document); | 25 return new TopDocumentRootScrollerController(host); |
24 } | 26 } |
25 | 27 |
26 TopDocumentRootScrollerController::TopDocumentRootScrollerController( | 28 TopDocumentRootScrollerController::TopDocumentRootScrollerController( |
27 Document& document) | 29 FrameHost& host) |
28 : RootScrollerController(document) | 30 : m_frameHost(&host) |
29 { | 31 { |
30 } | 32 } |
31 | 33 |
32 DEFINE_TRACE(TopDocumentRootScrollerController) | 34 DEFINE_TRACE(TopDocumentRootScrollerController) |
33 { | 35 { |
34 visitor->trace(m_viewportApplyScroll); | 36 visitor->trace(m_viewportApplyScroll); |
35 visitor->trace(m_globalRootScroller); | 37 visitor->trace(m_globalRootScroller); |
36 RootScrollerController::trace(visitor); | 38 visitor->trace(m_frameHost); |
37 } | 39 } |
38 | 40 |
39 void TopDocumentRootScrollerController::globalRootScrollerMayHaveChanged() | 41 void TopDocumentRootScrollerController::didChangeRootScroller() |
40 { | 42 { |
41 updateGlobalRootScroller(); | 43 recomputeGlobalRootScroller(); |
42 } | 44 } |
43 | 45 |
44 Element* TopDocumentRootScrollerController::findGlobalRootScrollerElement() | 46 Element* TopDocumentRootScrollerController::findGlobalRootScrollerElement() |
45 { | 47 { |
46 Element* element = effectiveRootScroller(); | 48 if (!topDocument()) |
49 return nullptr; | |
50 | |
51 DCHECK(topDocument()->rootScrollerController()); | |
52 Element* element = | |
53 topDocument()->rootScrollerController()->effectiveRootScroller(); | |
47 | 54 |
48 while (element && element->isFrameOwnerElement()) { | 55 while (element && element->isFrameOwnerElement()) { |
49 HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(element); | 56 HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(element); |
50 DCHECK(frameOwner); | 57 DCHECK(frameOwner); |
51 | 58 |
52 Document* iframeDocument = frameOwner->contentDocument(); | 59 Document* iframeDocument = frameOwner->contentDocument(); |
53 if (!iframeDocument) | 60 if (!iframeDocument) |
54 return element; | 61 return element; |
55 | 62 |
56 DCHECK(iframeDocument->rootScrollerController()); | 63 DCHECK(iframeDocument->rootScrollerController()); |
57 element = | 64 element = |
58 iframeDocument->rootScrollerController()->effectiveRootScroller(); | 65 iframeDocument->rootScrollerController()->effectiveRootScroller(); |
59 } | 66 } |
60 | 67 |
61 return element; | 68 return element; |
62 } | 69 } |
63 | 70 |
64 void TopDocumentRootScrollerController::updateGlobalRootScroller() | 71 void TopDocumentRootScrollerController::recomputeGlobalRootScroller() |
65 { | 72 { |
73 if (!m_viewportApplyScroll) | |
74 return; | |
75 | |
66 Element* target = findGlobalRootScrollerElement(); | 76 Element* target = findGlobalRootScrollerElement(); |
67 | 77 if (!target) |
68 if (!m_viewportApplyScroll || !target) | |
69 return; | 78 return; |
70 | 79 |
71 ScrollableArea* targetScroller = | 80 ScrollableArea* targetScroller = |
72 scrollableAreaFor(*target); | 81 RootScrollerUtil::scrollableAreaFor(*target); |
73 | 82 |
74 if (!targetScroller) | 83 if (!targetScroller) |
75 return; | 84 return; |
76 | 85 |
77 if (m_globalRootScroller) | 86 if (m_globalRootScroller) |
78 m_globalRootScroller->removeApplyScroll(); | 87 m_globalRootScroller->removeApplyScroll(); |
79 | 88 |
80 // Use disable-native-scroll since the ViewportScrollCallback needs to | 89 // Use disable-native-scroll since the ViewportScrollCallback needs to |
81 // apply scroll actions both before (TopControls) and after (overscroll) | 90 // apply scroll actions both before (TopControls) and after (overscroll) |
82 // scrolling the element so it will apply scroll to the element itself. | 91 // scrolling the element so it will apply scroll to the element itself. |
83 target->setApplyScroll(m_viewportApplyScroll, "disable-native-scroll"); | 92 target->setApplyScroll(m_viewportApplyScroll, "disable-native-scroll"); |
84 | 93 |
85 m_globalRootScroller = target; | 94 m_globalRootScroller = target; |
86 | 95 |
87 // Ideally, scroll customization would pass the current element to scroll to | 96 // Ideally, scroll customization would pass the current element to scroll to |
88 // the apply scroll callback but this doesn't happen today so we set it | 97 // the apply scroll callback but this doesn't happen today so we set it |
89 // through a back door here. This is also needed by the | 98 // through a back door here. This is also needed by the |
90 // ViewportScrollCallback to swap the target into the layout viewport | 99 // ViewportScrollCallback to swap the target into the layout viewport |
91 // in RootFrameViewport. | 100 // in RootFrameViewport. |
92 m_viewportApplyScroll->setScroller(targetScroller); | 101 m_viewportApplyScroll->setScroller(targetScroller); |
93 } | 102 } |
94 | 103 |
104 Document* TopDocumentRootScrollerController::topDocument() const | |
105 { | |
106 if (!m_frameHost) | |
107 return nullptr; | |
108 | |
109 if (!m_frameHost->page().mainFrame() | |
110 || !m_frameHost->page().mainFrame()->isLocalFrame()) | |
111 return nullptr; | |
112 | |
113 return toLocalFrame(m_frameHost->page().mainFrame())->document(); | |
114 } | |
115 | |
95 void TopDocumentRootScrollerController::didUpdateCompositing() | 116 void TopDocumentRootScrollerController::didUpdateCompositing() |
96 { | 117 { |
97 RootScrollerController::didUpdateCompositing(); | 118 if (!m_frameHost) |
119 return; | |
98 | 120 |
99 // Let the compositor-side counterpart know about this change. | 121 // Let the compositor-side counterpart know about this change. |
100 if (FrameHost* frameHost = m_document->frameHost()) | 122 m_frameHost->chromeClient().registerViewportLayers(); |
101 frameHost->chromeClient().registerViewportLayers(); | |
102 } | 123 } |
103 | 124 |
104 void TopDocumentRootScrollerController::didAttachDocument() | 125 void TopDocumentRootScrollerController::initializeViewportScrollCallback( |
126 RootFrameViewport& rfv) | |
tdresser
2016/08/30 15:05:30
Might as well write out the whole:
rootFrameViewpo
bokan
2016/08/30 16:13:39
Done.
| |
105 { | 127 { |
106 FrameHost* frameHost = m_document->frameHost(); | 128 DCHECK(m_frameHost); |
107 FrameView* frameView = m_document->view(); | 129 m_viewportApplyScroll = ViewportScrollCallback::create( |
130 &m_frameHost->topControls(), | |
131 &m_frameHost->overscrollController(), | |
132 rfv); | |
108 | 133 |
109 if (!frameHost || !frameView) | 134 recomputeGlobalRootScroller(); |
110 return; | |
111 | |
112 RootFrameViewport* rootFrameViewport = frameView->getRootFrameViewport(); | |
113 DCHECK(rootFrameViewport); | |
114 | |
115 m_viewportApplyScroll = ViewportScrollCallback::create( | |
116 &frameHost->topControls(), | |
117 &frameHost->overscrollController(), | |
118 *rootFrameViewport); | |
119 | |
120 updateGlobalRootScroller(); | |
121 } | 135 } |
122 | 136 |
123 bool TopDocumentRootScrollerController::isViewportScrollCallback( | 137 bool TopDocumentRootScrollerController::isViewportScrollCallback( |
124 const ScrollStateCallback* callback) const | 138 const ScrollStateCallback* callback) const |
125 { | 139 { |
126 if (!callback) | 140 if (!callback) |
127 return false; | 141 return false; |
128 | 142 |
129 return callback == m_viewportApplyScroll.get(); | 143 return callback == m_viewportApplyScroll.get(); |
130 } | 144 } |
131 | 145 |
132 GraphicsLayer* TopDocumentRootScrollerController::rootScrollerLayer() | 146 GraphicsLayer* TopDocumentRootScrollerController::rootScrollerLayer() |
133 { | 147 { |
134 if (!m_globalRootScroller) | 148 if (!m_globalRootScroller) |
135 return nullptr; | 149 return nullptr; |
136 | 150 |
137 ScrollableArea* area = scrollableAreaFor(*m_globalRootScroller); | 151 ScrollableArea* area = |
152 RootScrollerUtil::scrollableAreaFor(*m_globalRootScroller); | |
138 | 153 |
139 if (!area) | 154 if (!area) |
140 return nullptr; | 155 return nullptr; |
141 | 156 |
142 GraphicsLayer* graphicsLayer = area->layerForScrolling(); | 157 GraphicsLayer* graphicsLayer = area->layerForScrolling(); |
143 | 158 |
144 // TODO(bokan): We should assert graphicsLayer here and | 159 // TODO(bokan): We should assert graphicsLayer here and |
145 // RootScrollerController should do whatever needs to happen to ensure | 160 // RootScrollerController should do whatever needs to happen to ensure |
146 // the root scroller gets composited. | 161 // the root scroller gets composited. |
147 | 162 |
148 return graphicsLayer; | 163 return graphicsLayer; |
149 } | 164 } |
150 | 165 |
151 } // namespace blink | 166 } // namespace blink |
OLD | NEW |