Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: third_party/WebKit/Source/core/input/ScrollManager.cpp

Issue 2773893003: Record size of scroller that user scrolls (Closed)
Patch Set: nit Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/Histogram.h"
26 #include "platform/RuntimeEnabledFeatures.h" 26 #include "platform/RuntimeEnabledFeatures.h"
27 #include "platform/scroll/ScrollerSizeMetrics.h"
27 #include "platform/wtf/PtrUtil.h" 28 #include "platform/wtf/PtrUtil.h"
28 29
29 namespace blink { 30 namespace blink {
30 31
31 ScrollManager::ScrollManager(LocalFrame& frame) : frame_(frame) { 32 ScrollManager::ScrollManager(LocalFrame& frame) : frame_(frame) {
32 Clear(); 33 Clear();
33 } 34 }
34 35
35 void ScrollManager::Clear() { 36 void ScrollManager::Clear() {
36 last_gesture_scroll_over_frame_view_base_ = false; 37 last_gesture_scroll_over_frame_view_base_ = false;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 if (scroll_state.deltaX() || scroll_state.deltaY()) 191 if (scroll_state.deltaX() || scroll_state.deltaY())
191 frame_->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); 192 frame_->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
192 193
193 if (current_scroll_chain_.empty()) 194 if (current_scroll_chain_.empty())
194 RecomputeScrollChain(start_node, current_scroll_chain_); 195 RecomputeScrollChain(start_node, current_scroll_chain_);
195 scroll_state.SetScrollChain(current_scroll_chain_); 196 scroll_state.SetScrollChain(current_scroll_chain_);
196 197
197 scroll_state.distributeToScrollChainDescendant(); 198 scroll_state.distributeToScrollChainDescendant();
198 } 199 }
199 200
200 uint32_t ScrollManager::ComputeNonCompositedMainThreadScrollingReasons() { 201 void ScrollManager::ComputeScrollRelatedMetrics(
202 uint32_t* non_composited_main_thread_scrolling_reasons,
203 int* scroller_size) {
201 // When scrolling on the main thread, the scrollableArea may or may not be 204 // 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 205 // composited. Either way, we have recorded either the reasons stored in
203 // its layer or the reason NonFastScrollableRegion from the compositor 206 // its layer or the reason NonFastScrollableRegion from the compositor
204 // side. Here we record scrolls that occurred on main thread due to a 207 // side. Here we record scrolls that occurred on main thread due to a
205 // non-composited scroller. 208 // non-composited scroller.
206 if (!scroll_gesture_handling_node_->GetLayoutObject() || !frame_->View()) 209 if (!scroll_gesture_handling_node_->GetLayoutObject())
207 return 0; 210 return;
208 211
209 uint32_t non_composited_main_thread_scrolling_reasons = 0; 212 // When recording the size of the scroller, we only need to record the
213 // fisrt scrollable area that we find during the walk up.
flackr 2017/04/21 00:56:35 nit: s/fisrt/first
yigu 2017/04/21 12:20:33 Done.
214 bool set_scroller_size = false;
210 215
211 for (auto* cur_box = 216 for (auto* cur_box =
212 scroll_gesture_handling_node_->GetLayoutObject()->EnclosingBox(); 217 scroll_gesture_handling_node_->GetLayoutObject()->EnclosingBox();
213 cur_box; cur_box = cur_box->ContainingBlock()) { 218 cur_box; cur_box = cur_box->ContainingBlock()) {
214 PaintLayerScrollableArea* scrollable_area = cur_box->GetScrollableArea(); 219 PaintLayerScrollableArea* scrollable_area = cur_box->GetScrollableArea();
215 220
216 if (!scrollable_area || !scrollable_area->ScrollsOverflow()) 221 if (!scrollable_area || !scrollable_area->ScrollsOverflow())
217 continue; 222 continue;
218 223
224 if (!set_scroller_size && !cur_box->Layer()->IsRootLayer()) {
225 *scroller_size = scrollable_area->VisibleContentRect().Width() *
226 scrollable_area->VisibleContentRect().Height();
227 set_scroller_size = true;
228 }
229
219 DCHECK(!scrollable_area->UsesCompositedScrolling() || 230 DCHECK(!scrollable_area->UsesCompositedScrolling() ||
220 !scrollable_area->GetNonCompositedMainThreadScrollingReasons()); 231 !scrollable_area->GetNonCompositedMainThreadScrollingReasons());
221 non_composited_main_thread_scrolling_reasons |= 232 *non_composited_main_thread_scrolling_reasons |=
222 scrollable_area->GetNonCompositedMainThreadScrollingReasons(); 233 scrollable_area->GetNonCompositedMainThreadScrollingReasons();
223 } 234 }
224
225 return non_composited_main_thread_scrolling_reasons;
226 } 235 }
227 236
228 void ScrollManager::RecordNonCompositedMainThreadScrollingReasons( 237 void ScrollManager::RecordScrollRelatedMetrics(const WebGestureDevice device) {
229 const WebGestureDevice device) {
230 if (device != kWebGestureDeviceTouchpad && 238 if (device != kWebGestureDeviceTouchpad &&
231 device != kWebGestureDeviceTouchscreen) { 239 device != kWebGestureDeviceTouchscreen) {
232 return; 240 return;
233 } 241 }
234 242
235 uint32_t reasons = ComputeNonCompositedMainThreadScrollingReasons(); 243 int scroller_size = 0;
236 if (!reasons) 244 uint32_t non_composited_main_thread_scrolling_reasons = 0;
237 return; 245 ComputeScrollRelatedMetrics(&non_composited_main_thread_scrolling_reasons,
238 DCHECK(MainThreadScrollingReason::HasNonCompositedScrollReasons(reasons)); 246 &scroller_size);
247 if (scroller_size > 0) {
flackr 2017/04/21 00:56:35 Nit: While clearly a silly case, you might miss a
yigu 2017/04/21 12:20:33 Done.
248 if (device == kWebGestureDeviceTouchpad) {
249 DEFINE_STATIC_LOCAL(
250 CustomCountHistogram, size_histogram_wheel,
251 ("Event.Scroll.ScrollerSize.OnScroll_Wheel", 1,
252 kScrollerSizeLargestBucket, kScrollerSizeBucketCount));
253 size_histogram_wheel.Count(scroller_size);
254 } else {
255 DEFINE_STATIC_LOCAL(
256 CustomCountHistogram, size_histogram_touch,
257 ("Event.Scroll.ScrollerSize.OnScroll_Touch", 1,
258 kScrollerSizeLargestBucket, kScrollerSizeBucketCount));
259 size_histogram_touch.Count(scroller_size);
260 }
261 }
239 262
240 uint32_t main_thread_scrolling_reason_enum_max = 263 if (non_composited_main_thread_scrolling_reasons) {
241 MainThreadScrollingReason::kMainThreadScrollingReasonCount + 1; 264 DCHECK(MainThreadScrollingReason::HasNonCompositedScrollReasons(
242 for (uint32_t i = MainThreadScrollingReason::kNonCompositedReasonsFirst; 265 non_composited_main_thread_scrolling_reasons));
243 i <= MainThreadScrollingReason::kNonCompositedReasonsLast; ++i) { 266 uint32_t main_thread_scrolling_reason_enum_max =
244 unsigned val = 1 << i; 267 MainThreadScrollingReason::kMainThreadScrollingReasonCount + 1;
245 if (reasons & val) { 268 for (uint32_t i = MainThreadScrollingReason::kNonCompositedReasonsFirst;
246 if (device == kWebGestureDeviceTouchscreen) { 269 i <= MainThreadScrollingReason::kNonCompositedReasonsLast; ++i) {
247 DEFINE_STATIC_LOCAL(EnumerationHistogram, touch_histogram, 270 unsigned val = 1 << i;
248 ("Renderer4.MainThreadGestureScrollReason", 271 if (non_composited_main_thread_scrolling_reasons & val) {
249 main_thread_scrolling_reason_enum_max)); 272 if (device == kWebGestureDeviceTouchscreen) {
250 touch_histogram.Count(i + 1); 273 DEFINE_STATIC_LOCAL(EnumerationHistogram, touch_histogram,
251 } else { 274 ("Renderer4.MainThreadGestureScrollReason",
252 DEFINE_STATIC_LOCAL(EnumerationHistogram, wheel_histogram, 275 main_thread_scrolling_reason_enum_max));
253 ("Renderer4.MainThreadWheelScrollReason", 276 touch_histogram.Count(i + 1);
254 main_thread_scrolling_reason_enum_max)); 277 } else {
255 wheel_histogram.Count(i + 1); 278 DEFINE_STATIC_LOCAL(EnumerationHistogram, wheel_histogram,
279 ("Renderer4.MainThreadWheelScrollReason",
280 main_thread_scrolling_reason_enum_max));
281 wheel_histogram.Count(i + 1);
282 }
256 } 283 }
257 } 284 }
258 } 285 }
259 } 286 }
260 287
261 WebInputEventResult ScrollManager::HandleGestureScrollBegin( 288 WebInputEventResult ScrollManager::HandleGestureScrollBegin(
262 const WebGestureEvent& gesture_event) { 289 const WebGestureEvent& gesture_event) {
263 Document* document = frame_->GetDocument(); 290 Document* document = frame_->GetDocument();
264 291
265 if (document->GetLayoutViewItem().IsNull()) 292 if (document->GetLayoutViewItem().IsNull())
(...skipping 10 matching lines...) Expand all
276 if (!scroll_gesture_handling_node_) 303 if (!scroll_gesture_handling_node_)
277 scroll_gesture_handling_node_ = frame_->GetDocument()->documentElement(); 304 scroll_gesture_handling_node_ = frame_->GetDocument()->documentElement();
278 305
279 if (!scroll_gesture_handling_node_ || 306 if (!scroll_gesture_handling_node_ ||
280 !scroll_gesture_handling_node_->GetLayoutObject()) 307 !scroll_gesture_handling_node_->GetLayoutObject())
281 return WebInputEventResult::kNotHandled; 308 return WebInputEventResult::kNotHandled;
282 309
283 PassScrollGestureEvent(gesture_event, 310 PassScrollGestureEvent(gesture_event,
284 scroll_gesture_handling_node_->GetLayoutObject()); 311 scroll_gesture_handling_node_->GetLayoutObject());
285 312
286 RecordNonCompositedMainThreadScrollingReasons(gesture_event.source_device); 313 RecordScrollRelatedMetrics(gesture_event.source_device);
287 314
288 current_scroll_chain_.clear(); 315 current_scroll_chain_.clear();
289 std::unique_ptr<ScrollStateData> scroll_state_data = 316 std::unique_ptr<ScrollStateData> scroll_state_data =
290 WTF::MakeUnique<ScrollStateData>(); 317 WTF::MakeUnique<ScrollStateData>();
291 IntPoint position = FlooredIntPoint(gesture_event.PositionInRootFrame()); 318 IntPoint position = FlooredIntPoint(gesture_event.PositionInRootFrame());
292 scroll_state_data->position_x = position.X(); 319 scroll_state_data->position_x = position.X();
293 scroll_state_data->position_y = position.Y(); 320 scroll_state_data->position_y = position.Y();
294 scroll_state_data->is_beginning = true; 321 scroll_state_data->is_beginning = true;
295 scroll_state_data->from_user_input = true; 322 scroll_state_data->from_user_input = true;
296 scroll_state_data->is_direct_manipulation = 323 scroll_state_data->is_direct_manipulation =
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 &should_update_capture)) { 654 &should_update_capture)) {
628 if (should_update_capture) 655 if (should_update_capture)
629 scrollbar_handling_scroll_gesture_ = scrollbar; 656 scrollbar_handling_scroll_gesture_ = scrollbar;
630 return true; 657 return true;
631 } 658 }
632 } 659 }
633 return false; 660 return false;
634 } 661 }
635 662
636 } // namespace blink 663 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698