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) : frame_(frame) { | 31 ScrollManager::ScrollManager(LocalFrame& frame) : 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 (scroll_state.deltaX() || scroll_state.deltaY()) | 190 if (scroll_state.deltaX() || scroll_state.deltaY()) |
190 frame_->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); | 191 frame_->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); |
191 | 192 |
192 if (current_scroll_chain_.empty()) | 193 if (current_scroll_chain_.empty()) |
193 RecomputeScrollChain(start_node, current_scroll_chain_); | 194 RecomputeScrollChain(start_node, current_scroll_chain_); |
194 scroll_state.SetScrollChain(current_scroll_chain_); | 195 scroll_state.SetScrollChain(current_scroll_chain_); |
195 | 196 |
196 scroll_state.distributeToScrollChainDescendant(); | 197 scroll_state.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 stored in | |
203 // its layer or the reason NonFastScrollableRegion from the compositor | |
204 // side. Here we record scrolls that occurred on main thread due to a | |
205 // non-composited scroller. | |
206 if (!scroll_gesture_handling_node_->GetLayoutObject() || !frame_->View()) | |
207 return 0; | |
208 | |
209 uint32_t non_composited_main_thread_scrolling_reasons = 0; | |
210 | |
211 for (auto* cur_box = | |
212 scroll_gesture_handling_node_->GetLayoutObject()->EnclosingBox(); | |
213 cur_box; cur_box = cur_box->ContainingBlock()) { | |
214 PaintLayerScrollableArea* scrollable_area = cur_box->GetScrollableArea(); | |
215 | |
216 if (!scrollable_area || !scrollable_area->ScrollsOverflow()) | |
217 continue; | |
218 | |
219 DCHECK(!scrollable_area->UsesCompositedScrolling() || | |
220 !scrollable_area->GetNonCompositedMainThreadScrollingReasons()); | |
221 non_composited_main_thread_scrolling_reasons |= | |
222 scrollable_area->GetNonCompositedMainThreadScrollingReasons(); | |
223 } | |
flackr
2017/04/11 19:35:35
What is the state when we handle these events? If
flackr
2017/04/11 20:13:03
It looks like recomputing the scroll chain actuall
| |
224 | |
225 return non_composited_main_thread_scrolling_reasons; | |
226 } | |
227 | |
228 void ScrollManager::RecordNonCompositedMainThreadScrollingReasons( | |
229 const WebGestureDevice device) { | |
230 if (device != kWebGestureDeviceTouchpad && | |
231 device != kWebGestureDeviceTouchscreen) { | |
232 return; | |
233 } | |
234 | |
235 uint32_t reasons = ComputeNonCompositedMainThreadScrollingReasons(); | |
236 if (!reasons) | |
237 return; | |
238 DCHECK(MainThreadScrollingReason::HasNonCompositedScrollReasons(reasons)); | |
239 | |
240 uint32_t main_thread_scrolling_reason_enum_max = | |
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 == kWebGestureDeviceTouchscreen) { | |
247 DEFINE_STATIC_LOCAL(EnumerationHistogram, touch_histogram, | |
248 ("Renderer4.MainThreadGestureScrollReason", | |
249 main_thread_scrolling_reason_enum_max)); | |
250 touch_histogram.Count(i + 1); | |
251 } else { | |
252 DEFINE_STATIC_LOCAL(EnumerationHistogram, wheel_histogram, | |
253 ("Renderer4.MainThreadWheelScrollReason", | |
254 main_thread_scrolling_reason_enum_max)); | |
flackr
2017/04/11 20:13:03
I notice the device in this case is only kWebGestu
yigu
2017/04/11 21:28:10
Mouse wheel scrolling uses kWebGestureDeviceTouchp
| |
255 wheel_histogram.Count(i + 1); | |
256 } | |
257 } | |
258 } | |
259 } | |
260 | |
199 WebInputEventResult ScrollManager::HandleGestureScrollBegin( | 261 WebInputEventResult ScrollManager::HandleGestureScrollBegin( |
200 const WebGestureEvent& gesture_event) { | 262 const WebGestureEvent& gesture_event) { |
201 Document* document = frame_->GetDocument(); | 263 Document* document = frame_->GetDocument(); |
202 | 264 |
203 if (document->GetLayoutViewItem().IsNull()) | 265 if (document->GetLayoutViewItem().IsNull()) |
204 return WebInputEventResult::kNotHandled; | 266 return WebInputEventResult::kNotHandled; |
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 (scroll_gesture_handling_node_ && | 271 while (scroll_gesture_handling_node_ && |
210 !scroll_gesture_handling_node_->GetLayoutObject()) | 272 !scroll_gesture_handling_node_->GetLayoutObject()) |
211 scroll_gesture_handling_node_ = | 273 scroll_gesture_handling_node_ = |
212 scroll_gesture_handling_node_->ParentOrShadowHostNode(); | 274 scroll_gesture_handling_node_->ParentOrShadowHostNode(); |
213 | 275 |
214 if (!scroll_gesture_handling_node_) | 276 if (!scroll_gesture_handling_node_) |
215 scroll_gesture_handling_node_ = frame_->GetDocument()->documentElement(); | 277 scroll_gesture_handling_node_ = frame_->GetDocument()->documentElement(); |
216 | 278 |
217 if (!scroll_gesture_handling_node_ || | 279 if (!scroll_gesture_handling_node_ || |
218 !scroll_gesture_handling_node_->GetLayoutObject()) | 280 !scroll_gesture_handling_node_->GetLayoutObject()) |
219 return WebInputEventResult::kNotHandled; | 281 return WebInputEventResult::kNotHandled; |
220 | 282 |
221 PassScrollGestureEvent(gesture_event, | 283 PassScrollGestureEvent(gesture_event, |
222 scroll_gesture_handling_node_->GetLayoutObject()); | 284 scroll_gesture_handling_node_->GetLayoutObject()); |
223 | 285 |
286 RecordNonCompositedMainThreadScrollingReasons(gesture_event.source_device); | |
287 | |
224 current_scroll_chain_.clear(); | 288 current_scroll_chain_.clear(); |
225 std::unique_ptr<ScrollStateData> scroll_state_data = | 289 std::unique_ptr<ScrollStateData> scroll_state_data = |
226 WTF::MakeUnique<ScrollStateData>(); | 290 WTF::MakeUnique<ScrollStateData>(); |
227 IntPoint position = FlooredIntPoint(gesture_event.PositionInRootFrame()); | 291 IntPoint position = FlooredIntPoint(gesture_event.PositionInRootFrame()); |
228 scroll_state_data->position_x = position.X(); | 292 scroll_state_data->position_x = position.X(); |
229 scroll_state_data->position_y = position.Y(); | 293 scroll_state_data->position_y = position.Y(); |
230 scroll_state_data->is_beginning = true; | 294 scroll_state_data->is_beginning = true; |
231 scroll_state_data->from_user_input = true; | 295 scroll_state_data->from_user_input = true; |
232 scroll_state_data->is_direct_manipulation = | 296 scroll_state_data->is_direct_manipulation = |
233 gesture_event.source_device == kWebGestureDeviceTouchscreen; | 297 gesture_event.source_device == kWebGestureDeviceTouchscreen; |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 &should_update_capture)) { | 630 &should_update_capture)) { |
567 if (should_update_capture) | 631 if (should_update_capture) |
568 scrollbar_handling_scroll_gesture_ = scrollbar; | 632 scrollbar_handling_scroll_gesture_ = scrollbar; |
569 return true; | 633 return true; |
570 } | 634 } |
571 } | 635 } |
572 return false; | 636 return false; |
573 } | 637 } |
574 | 638 |
575 } // namespace blink | 639 } // namespace blink |
OLD | NEW |