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 // When scrolling on the main thread, the scrollableArea may or may not be | |
202 // composited. Either way, we have recorded either the reasons that | |
bokan
2017/04/06 21:45:09
nit: "reasons that stored" -> "reasons stored"
yigu
2017/04/07 16:35:32
Done.
| |
203 // stored in its layer or the reason NonFastScrollableRegion from the | |
204 // compositor side. Here we record scrolls that occurred on main thread | |
205 // due to a non-composited scroller. | |
206 if (!m_scrollGestureHandlingNode->layoutObject() || !m_frame->view()) | |
207 return 0; | |
208 | |
209 uint32_t nonCompositedMainThreadScrollingReasons = 0; | |
210 | |
211 for (auto* curBox = | |
212 m_scrollGestureHandlingNode->layoutObject()->enclosingBox(); | |
213 curBox; curBox = curBox->containingBlock()) { | |
214 PaintLayerScrollableArea* scrollableArea = curBox->getScrollableArea(); | |
215 | |
216 if (!scrollableArea || !scrollableArea->scrollsOverflow()) | |
217 continue; | |
218 | |
219 DCHECK(!scrollableArea->usesCompositedScrolling() || | |
220 !nonCompositedMainThreadScrollingReasons); | |
221 nonCompositedMainThreadScrollingReasons = | |
bokan
2017/04/06 21:45:09
this should be |=, right?
yigu
2017/04/07 16:35:32
Done.
| |
222 scrollableArea->getNonCompositedMainThreadScrollingReasons(); | |
223 } | |
224 | |
225 return nonCompositedMainThreadScrollingReasons; | |
226 } | |
227 | |
228 void ScrollManager::recordNonCompositedMainThreadScrollingReasons( | |
229 const WebGestureDevice device) { | |
230 if (device != WebGestureDeviceTouchpad && | |
231 device != WebGestureDeviceTouchscreen) { | |
232 return; | |
233 } | |
234 | |
235 uint32_t reasons = computeNonCompositedMainThreadScrollingReasons(); | |
236 if (!reasons) | |
237 return; | |
238 DCHECK(MainThreadScrollingReason::NonCompositedScrollReasons(reasons)); | |
bokan
2017/04/06 21:45:09
It wouldn't hurt to DCHECK that we don't have any
yigu
2017/04/07 16:35:32
Current DCHECK guarantees that the reason doesn't
bokan
2017/04/07 17:39:03
Ah, my bad, I didn't pay close enough attention to
| |
239 | |
240 uint32_t mainThreadScrollingReasonEnumMax = | |
bokan
2017/04/06 21:45:10
unused
yigu
2017/04/07 16:35:32
It's used in DEFINE_STATIC_LOCAL.
bokan
2017/04/07 17:39:03
Doh
| |
241 MainThreadScrollingReason::kMainThreadScrollingReasonCount + 1; | |
242 for (uint32_t i = MainThreadScrollingReason::kNonCompositedReasonsFirst; | |
243 i <= MainThreadScrollingReason::kNonCompositedReasonsLast; ++i) { | |
244 unsigned val = 1 << i; | |
245 if (reasons & val) { | |
246 if (device == WebGestureDeviceTouchscreen) { | |
247 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchHistogram, | |
248 ("Renderer4.MainThreadGestureScrollReason", | |
249 mainThreadScrollingReasonEnumMax)); | |
250 touchHistogram.count(i + 1); | |
251 } else { | |
252 DEFINE_STATIC_LOCAL(EnumerationHistogram, wheelHistogram, | |
253 ("Renderer4.MainThreadWheelScrollReason", | |
254 mainThreadScrollingReasonEnumMax)); | |
255 wheelHistogram.count(i + 1); | |
256 } | |
257 } | |
258 } | |
259 } | |
260 | |
199 WebInputEventResult ScrollManager::handleGestureScrollBegin( | 261 WebInputEventResult ScrollManager::handleGestureScrollBegin( |
200 const WebGestureEvent& gestureEvent) { | 262 const WebGestureEvent& gestureEvent) { |
201 Document* document = m_frame->document(); | 263 Document* document = m_frame->document(); |
202 | 264 |
203 if (document->layoutViewItem().isNull()) | 265 if (document->layoutViewItem().isNull()) |
204 return WebInputEventResult::NotHandled; | 266 return WebInputEventResult::NotHandled; |
205 | 267 |
206 // If there's no layoutObject on the node, send the event to the nearest | 268 // 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 | 269 // ancestor with a layoutObject. Needed for <option> and <optgroup> elements |
208 // so we can touch scroll <select>s | 270 // so we can touch scroll <select>s |
209 while (m_scrollGestureHandlingNode && | 271 while (m_scrollGestureHandlingNode && |
210 !m_scrollGestureHandlingNode->layoutObject()) | 272 !m_scrollGestureHandlingNode->layoutObject()) |
211 m_scrollGestureHandlingNode = | 273 m_scrollGestureHandlingNode = |
212 m_scrollGestureHandlingNode->parentOrShadowHostNode(); | 274 m_scrollGestureHandlingNode->parentOrShadowHostNode(); |
213 | 275 |
214 if (!m_scrollGestureHandlingNode) | 276 if (!m_scrollGestureHandlingNode) |
215 m_scrollGestureHandlingNode = m_frame->document()->documentElement(); | 277 m_scrollGestureHandlingNode = m_frame->document()->documentElement(); |
216 | 278 |
217 if (!m_scrollGestureHandlingNode || | 279 if (!m_scrollGestureHandlingNode || |
218 !m_scrollGestureHandlingNode->layoutObject()) | 280 !m_scrollGestureHandlingNode->layoutObject()) |
219 return WebInputEventResult::NotHandled; | 281 return WebInputEventResult::NotHandled; |
220 | 282 |
221 passScrollGestureEvent(gestureEvent, | 283 passScrollGestureEvent(gestureEvent, |
222 m_scrollGestureHandlingNode->layoutObject()); | 284 m_scrollGestureHandlingNode->layoutObject()); |
223 | 285 |
286 recordNonCompositedMainThreadScrollingReasons(gestureEvent.sourceDevice); | |
287 | |
224 m_currentScrollChain.clear(); | 288 m_currentScrollChain.clear(); |
225 std::unique_ptr<ScrollStateData> scrollStateData = | 289 std::unique_ptr<ScrollStateData> scrollStateData = |
226 WTF::makeUnique<ScrollStateData>(); | 290 WTF::makeUnique<ScrollStateData>(); |
227 IntPoint position = flooredIntPoint(gestureEvent.positionInRootFrame()); | 291 IntPoint position = flooredIntPoint(gestureEvent.positionInRootFrame()); |
228 scrollStateData->position_x = position.x(); | 292 scrollStateData->position_x = position.x(); |
229 scrollStateData->position_y = position.y(); | 293 scrollStateData->position_y = position.y(); |
230 scrollStateData->is_beginning = true; | 294 scrollStateData->is_beginning = true; |
231 scrollStateData->from_user_input = true; | 295 scrollStateData->from_user_input = true; |
232 scrollStateData->is_direct_manipulation = | 296 scrollStateData->is_direct_manipulation = |
233 gestureEvent.sourceDevice == WebGestureDeviceTouchscreen; | 297 gestureEvent.sourceDevice == WebGestureDeviceTouchscreen; |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 if (scrollbar->gestureEvent(targetedEvent.event(), &shouldUpdateCapture)) { | 624 if (scrollbar->gestureEvent(targetedEvent.event(), &shouldUpdateCapture)) { |
561 if (shouldUpdateCapture) | 625 if (shouldUpdateCapture) |
562 m_scrollbarHandlingScrollGesture = scrollbar; | 626 m_scrollbarHandlingScrollGesture = scrollbar; |
563 return true; | 627 return true; |
564 } | 628 } |
565 } | 629 } |
566 return false; | 630 return false; |
567 } | 631 } |
568 | 632 |
569 } // namespace blink | 633 } // namespace blink |
OLD | NEW |