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/input/ScrollManager.h" | 5 #include "core/input/ScrollManager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include "core/dom/DOMNodeIds.h" | 8 #include "core/dom/DOMNodeIds.h" |
9 #include "core/events/GestureEvent.h" | 9 #include "core/events/GestureEvent.h" |
10 #include "core/frame/BrowserControls.h" | 10 #include "core/frame/BrowserControls.h" |
11 #include "core/frame/FrameView.h" | 11 #include "core/frame/FrameView.h" |
12 #include "core/html/HTMLFrameOwnerElement.h" | 12 #include "core/html/HTMLFrameOwnerElement.h" |
13 #include "core/input/EventHandler.h" | 13 #include "core/input/EventHandler.h" |
14 #include "core/input/EventHandlingUtil.h" | 14 #include "core/input/EventHandlingUtil.h" |
15 #include "core/layout/LayoutBlock.h" | 15 #include "core/layout/LayoutBlock.h" |
16 #include "core/layout/LayoutPart.h" | 16 #include "core/layout/LayoutPart.h" |
17 #include "core/layout/api/LayoutViewItem.h" | 17 #include "core/layout/api/LayoutViewItem.h" |
18 #include "core/loader/DocumentLoader.h" | 18 #include "core/loader/DocumentLoader.h" |
19 #include "core/page/AutoscrollController.h" | 19 #include "core/page/AutoscrollController.h" |
20 #include "core/page/Page.h" | 20 #include "core/page/Page.h" |
21 #include "core/page/scrolling/OverscrollController.h" | 21 #include "core/page/scrolling/OverscrollController.h" |
22 #include "core/page/scrolling/RootScrollerController.h" | 22 #include "core/page/scrolling/RootScrollerController.h" |
23 #include "core/page/scrolling/ScrollState.h" | 23 #include "core/page/scrolling/ScrollState.h" |
24 #include "core/paint/PaintLayer.h" | 24 #include "core/paint/PaintLayer.h" |
25 #include "platform/Histogram.h" | |
25 #include "platform/RuntimeEnabledFeatures.h" | 26 #include "platform/RuntimeEnabledFeatures.h" |
26 #include "wtf/PtrUtil.h" | 27 #include "wtf/PtrUtil.h" |
27 | 28 |
28 namespace blink { | 29 namespace blink { |
29 | 30 |
30 ScrollManager::ScrollManager(LocalFrame& frame) : m_frame(frame) { | 31 ScrollManager::ScrollManager(LocalFrame& frame) : m_frame(frame) { |
31 clear(); | 32 clear(); |
32 } | 33 } |
33 | 34 |
34 void ScrollManager::clear() { | 35 void ScrollManager::clear() { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 if (scrollState.deltaX() || scrollState.deltaY()) | 190 if (scrollState.deltaX() || scrollState.deltaY()) |
190 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 191 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
191 | 192 |
192 if (m_currentScrollChain.empty()) | 193 if (m_currentScrollChain.empty()) |
193 recomputeScrollChain(startNode, m_currentScrollChain); | 194 recomputeScrollChain(startNode, m_currentScrollChain); |
194 scrollState.setScrollChain(m_currentScrollChain); | 195 scrollState.setScrollChain(m_currentScrollChain); |
195 | 196 |
196 scrollState.distributeToScrollChainDescendant(); | 197 scrollState.distributeToScrollChainDescendant(); |
197 } | 198 } |
198 | 199 |
200 uint32_t ScrollManager::computeNonCompositedMainThreadScrollingReasons() { | |
201 if (!m_scrollGestureHandlingNode->layoutObject()) | |
202 return 0; | |
203 uint32_t reasons = 0; | |
204 LayoutBox* curBox = | |
205 m_scrollGestureHandlingNode->layoutObject()->enclosingBox(); | |
206 while (curBox) { | |
207 if (auto* scrollableArea = curBox->getScrollableArea()) { | |
208 if (scrollableArea->isScrollable()) { | |
bokan
2017/03/28 15:30:15
On second look, I don't think this is enough. If w
tdresser
2017/03/28 17:10:22
Can you describe with a bit more detail how we'd i
bokan
2017/03/28 18:23:02
We do this walk up the containingBlock chain until
tdresser
2017/03/28 19:25:14
Thanks. Yeah, considering that bucket separately S
| |
209 reasons = scrollableArea->getNonCompositedMainThreadScrollingReasons(); | |
210 break; | |
211 } | |
212 } | |
213 curBox = curBox->containingBlock(); | |
214 } | |
215 return reasons; | |
216 } | |
217 | |
218 void ScrollManager::recordNonCompositedMainThreadScrollingReasons( | |
219 const WebGestureDevice device) { | |
220 if (device != WebGestureDeviceTouchpad && | |
221 device != WebGestureDeviceTouchscreen) { | |
222 return; | |
223 } | |
224 | |
225 uint32_t reasons = computeNonCompositedMainThreadScrollingReasons(); | |
226 if (!reasons) | |
227 return; | |
228 | |
229 uint32_t mainThreadScrollingReasonEnumMax = | |
230 MainThreadScrollingReason::kMainThreadScrollingReasonCount + 1; | |
231 for (uint32_t i = 0; | |
232 i < MainThreadScrollingReason::kMainThreadScrollingReasonCount; ++i) { | |
233 unsigned val = 1 << i; | |
234 if (reasons & val) { | |
235 if (device == WebGestureDeviceTouchscreen) { | |
236 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchHistogram, | |
237 ("Renderer4.MainThreadGestureScrollReason", | |
238 mainThreadScrollingReasonEnumMax)); | |
239 touchHistogram.count(i + 1); | |
240 } else { | |
241 DEFINE_STATIC_LOCAL(EnumerationHistogram, wheelHistogram, | |
242 ("Renderer4.MainThreadWheelScrollReason", | |
243 mainThreadScrollingReasonEnumMax)); | |
244 wheelHistogram.count(i + 1); | |
245 } | |
246 } | |
247 } | |
248 } | |
249 | |
199 WebInputEventResult ScrollManager::handleGestureScrollBegin( | 250 WebInputEventResult ScrollManager::handleGestureScrollBegin( |
200 const WebGestureEvent& gestureEvent) { | 251 const WebGestureEvent& gestureEvent) { |
201 Document* document = m_frame->document(); | 252 Document* document = m_frame->document(); |
202 | 253 |
203 if (document->layoutViewItem().isNull()) | 254 if (document->layoutViewItem().isNull()) |
204 return WebInputEventResult::NotHandled; | 255 return WebInputEventResult::NotHandled; |
205 | 256 |
206 // If there's no layoutObject on the node, send the event to the nearest | 257 // If there's no layoutObject on the node, send the event to the nearest |
207 // ancestor with a layoutObject. Needed for <option> and <optgroup> elements | 258 // ancestor with a layoutObject. Needed for <option> and <optgroup> elements |
208 // so we can touch scroll <select>s | 259 // so we can touch scroll <select>s |
209 while (m_scrollGestureHandlingNode && | 260 while (m_scrollGestureHandlingNode && |
210 !m_scrollGestureHandlingNode->layoutObject()) | 261 !m_scrollGestureHandlingNode->layoutObject()) |
211 m_scrollGestureHandlingNode = | 262 m_scrollGestureHandlingNode = |
212 m_scrollGestureHandlingNode->parentOrShadowHostNode(); | 263 m_scrollGestureHandlingNode->parentOrShadowHostNode(); |
213 | 264 |
214 if (!m_scrollGestureHandlingNode) | 265 if (!m_scrollGestureHandlingNode) |
215 m_scrollGestureHandlingNode = m_frame->document()->documentElement(); | 266 m_scrollGestureHandlingNode = m_frame->document()->documentElement(); |
216 | 267 |
217 if (!m_scrollGestureHandlingNode || | 268 if (!m_scrollGestureHandlingNode || |
218 !m_scrollGestureHandlingNode->layoutObject()) | 269 !m_scrollGestureHandlingNode->layoutObject()) |
219 return WebInputEventResult::NotHandled; | 270 return WebInputEventResult::NotHandled; |
220 | 271 |
221 passScrollGestureEvent(gestureEvent, | 272 passScrollGestureEvent(gestureEvent, |
222 m_scrollGestureHandlingNode->layoutObject()); | 273 m_scrollGestureHandlingNode->layoutObject()); |
223 | 274 |
275 recordNonCompositedMainThreadScrollingReasons(gestureEvent.sourceDevice); | |
276 | |
224 m_currentScrollChain.clear(); | 277 m_currentScrollChain.clear(); |
225 std::unique_ptr<ScrollStateData> scrollStateData = | 278 std::unique_ptr<ScrollStateData> scrollStateData = |
226 WTF::makeUnique<ScrollStateData>(); | 279 WTF::makeUnique<ScrollStateData>(); |
227 IntPoint position = flooredIntPoint(gestureEvent.positionInRootFrame()); | 280 IntPoint position = flooredIntPoint(gestureEvent.positionInRootFrame()); |
228 scrollStateData->position_x = position.x(); | 281 scrollStateData->position_x = position.x(); |
229 scrollStateData->position_y = position.y(); | 282 scrollStateData->position_y = position.y(); |
230 scrollStateData->is_beginning = true; | 283 scrollStateData->is_beginning = true; |
231 scrollStateData->from_user_input = true; | 284 scrollStateData->from_user_input = true; |
232 scrollStateData->is_direct_manipulation = | 285 scrollStateData->is_direct_manipulation = |
233 gestureEvent.sourceDevice == WebGestureDeviceTouchscreen; | 286 gestureEvent.sourceDevice == WebGestureDeviceTouchscreen; |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 if (scrollbar->gestureEvent(targetedEvent.event(), &shouldUpdateCapture)) { | 606 if (scrollbar->gestureEvent(targetedEvent.event(), &shouldUpdateCapture)) { |
554 if (shouldUpdateCapture) | 607 if (shouldUpdateCapture) |
555 m_scrollbarHandlingScrollGesture = scrollbar; | 608 m_scrollbarHandlingScrollGesture = scrollbar; |
556 return true; | 609 return true; |
557 } | 610 } |
558 } | 611 } |
559 return false; | 612 return false; |
560 } | 613 } |
561 | 614 |
562 } // namespace blink | 615 } // namespace blink |
OLD | NEW |