Chromium Code Reviews| 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/Histogram.h" |
| 26 #include "platform/RuntimeEnabledFeatures.h" | 26 #include "platform/RuntimeEnabledFeatures.h" |
| 27 #include "platform/scroll/ScrollerSize.h" | |
| 27 #include "wtf/PtrUtil.h" | 28 #include "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 Loading... | |
| 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) { | |
|
bokan
2017/04/18 19:24:39
Style guide (https://google.github.io/styleguide/c
yigu
2017/04/19 20:53:06
Done.
| |
| 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. | |
| 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 = cur_box->VisualOverflowRect().Width().ToInt() * | |
|
bokan
2017/04/18 19:24:39
Are we looking to record the size of the scroller'
yigu
2017/04/19 20:53:05
I think we should record the size of the scroller'
| |
| 226 cur_box->VisualOverflowRect().Height().ToInt(); | |
| 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) { | |
| 248 DCHECK_GT(scroller_size, 0); | |
|
bokan
2017/04/18 19:24:39
This can only fail if scroller_size < 0. IMO, just
yigu
2017/04/19 20:53:05
I was thinking that we should crash it if we have
| |
| 249 if (device == kWebGestureDeviceTouchpad) { | |
| 250 DEFINE_STATIC_LOCAL(CustomCountHistogram, size_histogram_wheel, | |
| 251 ("Event.Scroll.ScrollerSize.OnScroll_Wheel", 1, | |
| 252 kMaxScrollerSize, kBucketNum)); | |
| 253 size_histogram_wheel.Count(scroller_size); | |
| 254 } else { | |
| 255 DEFINE_STATIC_LOCAL(CustomCountHistogram, size_histogram_touch, | |
| 256 ("Event.Scroll.ScrollerSize.OnScroll_Touch", 1, | |
| 257 kMaxScrollerSize, kBucketNum)); | |
| 258 size_histogram_touch.Count(scroller_size); | |
| 259 } | |
| 260 } | |
| 239 | 261 |
| 240 uint32_t main_thread_scrolling_reason_enum_max = | 262 if (non_composited_main_thread_scrolling_reasons) { |
| 241 MainThreadScrollingReason::kMainThreadScrollingReasonCount + 1; | 263 DCHECK(MainThreadScrollingReason::HasNonCompositedScrollReasons( |
| 242 for (uint32_t i = MainThreadScrollingReason::kNonCompositedReasonsFirst; | 264 non_composited_main_thread_scrolling_reasons)); |
| 243 i <= MainThreadScrollingReason::kNonCompositedReasonsLast; ++i) { | 265 uint32_t main_thread_scrolling_reason_enum_max = |
| 244 unsigned val = 1 << i; | 266 MainThreadScrollingReason::kMainThreadScrollingReasonCount + 1; |
| 245 if (reasons & val) { | 267 for (uint32_t i = MainThreadScrollingReason::kNonCompositedReasonsFirst; |
| 246 if (device == kWebGestureDeviceTouchscreen) { | 268 i <= MainThreadScrollingReason::kNonCompositedReasonsLast; ++i) { |
| 247 DEFINE_STATIC_LOCAL(EnumerationHistogram, touch_histogram, | 269 unsigned val = 1 << i; |
| 248 ("Renderer4.MainThreadGestureScrollReason", | 270 if (non_composited_main_thread_scrolling_reasons & val) { |
| 249 main_thread_scrolling_reason_enum_max)); | 271 if (device == kWebGestureDeviceTouchscreen) { |
| 250 touch_histogram.Count(i + 1); | 272 DEFINE_STATIC_LOCAL(EnumerationHistogram, touch_histogram, |
| 251 } else { | 273 ("Renderer4.MainThreadGestureScrollReason", |
| 252 DEFINE_STATIC_LOCAL(EnumerationHistogram, wheel_histogram, | 274 main_thread_scrolling_reason_enum_max)); |
| 253 ("Renderer4.MainThreadWheelScrollReason", | 275 touch_histogram.Count(i + 1); |
| 254 main_thread_scrolling_reason_enum_max)); | 276 } else { |
| 255 wheel_histogram.Count(i + 1); | 277 DEFINE_STATIC_LOCAL(EnumerationHistogram, wheel_histogram, |
| 278 ("Renderer4.MainThreadWheelScrollReason", | |
| 279 main_thread_scrolling_reason_enum_max)); | |
| 280 wheel_histogram.Count(i + 1); | |
| 281 } | |
| 256 } | 282 } |
| 257 } | 283 } |
| 258 } | 284 } |
| 259 } | 285 } |
| 260 | 286 |
| 261 WebInputEventResult ScrollManager::HandleGestureScrollBegin( | 287 WebInputEventResult ScrollManager::HandleGestureScrollBegin( |
| 262 const WebGestureEvent& gesture_event) { | 288 const WebGestureEvent& gesture_event) { |
| 263 Document* document = frame_->GetDocument(); | 289 Document* document = frame_->GetDocument(); |
| 264 | 290 |
| 265 if (document->GetLayoutViewItem().IsNull()) | 291 if (document->GetLayoutViewItem().IsNull()) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 276 if (!scroll_gesture_handling_node_) | 302 if (!scroll_gesture_handling_node_) |
| 277 scroll_gesture_handling_node_ = frame_->GetDocument()->documentElement(); | 303 scroll_gesture_handling_node_ = frame_->GetDocument()->documentElement(); |
| 278 | 304 |
| 279 if (!scroll_gesture_handling_node_ || | 305 if (!scroll_gesture_handling_node_ || |
| 280 !scroll_gesture_handling_node_->GetLayoutObject()) | 306 !scroll_gesture_handling_node_->GetLayoutObject()) |
| 281 return WebInputEventResult::kNotHandled; | 307 return WebInputEventResult::kNotHandled; |
| 282 | 308 |
| 283 PassScrollGestureEvent(gesture_event, | 309 PassScrollGestureEvent(gesture_event, |
| 284 scroll_gesture_handling_node_->GetLayoutObject()); | 310 scroll_gesture_handling_node_->GetLayoutObject()); |
| 285 | 311 |
| 286 RecordNonCompositedMainThreadScrollingReasons(gesture_event.source_device); | 312 RecordScrollRelatedMetrics(gesture_event.source_device); |
| 287 | 313 |
| 288 current_scroll_chain_.clear(); | 314 current_scroll_chain_.clear(); |
| 289 std::unique_ptr<ScrollStateData> scroll_state_data = | 315 std::unique_ptr<ScrollStateData> scroll_state_data = |
| 290 WTF::MakeUnique<ScrollStateData>(); | 316 WTF::MakeUnique<ScrollStateData>(); |
| 291 IntPoint position = FlooredIntPoint(gesture_event.PositionInRootFrame()); | 317 IntPoint position = FlooredIntPoint(gesture_event.PositionInRootFrame()); |
| 292 scroll_state_data->position_x = position.X(); | 318 scroll_state_data->position_x = position.X(); |
| 293 scroll_state_data->position_y = position.Y(); | 319 scroll_state_data->position_y = position.Y(); |
| 294 scroll_state_data->is_beginning = true; | 320 scroll_state_data->is_beginning = true; |
| 295 scroll_state_data->from_user_input = true; | 321 scroll_state_data->from_user_input = true; |
| 296 scroll_state_data->is_direct_manipulation = | 322 scroll_state_data->is_direct_manipulation = |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 &should_update_capture)) { | 653 &should_update_capture)) { |
| 628 if (should_update_capture) | 654 if (should_update_capture) |
| 629 scrollbar_handling_scroll_gesture_ = scrollbar; | 655 scrollbar_handling_scroll_gesture_ = scrollbar; |
| 630 return true; | 656 return true; |
| 631 } | 657 } |
| 632 } | 658 } |
| 633 return false; | 659 return false; |
| 634 } | 660 } |
| 635 | 661 |
| 636 } // namespace blink | 662 } // namespace blink |
| OLD | NEW |