Chromium Code Reviews| Index: third_party/WebKit/Source/core/input/ScrollManager.cpp |
| diff --git a/third_party/WebKit/Source/core/input/ScrollManager.cpp b/third_party/WebKit/Source/core/input/ScrollManager.cpp |
| index 027fda047274c5d43aaeb37fd3f4c7b69e9ce803..5bff0c7c0de53dc9652777ffbf91f21f1a6144b7 100644 |
| --- a/third_party/WebKit/Source/core/input/ScrollManager.cpp |
| +++ b/third_party/WebKit/Source/core/input/ScrollManager.cpp |
| @@ -80,7 +80,9 @@ AutoscrollController* ScrollManager::GetAutoscrollController() const { |
| } |
| void ScrollManager::RecomputeScrollChain(const Node& start_node, |
| + const ScrollState& scroll_state, |
| std::deque<int>& scroll_chain) { |
| + DCHECK(!scroll_chain.size()); |
| scroll_chain.clear(); |
| DCHECK(start_node.GetLayoutObject()); |
| @@ -105,7 +107,8 @@ void ScrollManager::RecomputeScrollChain(const Node& start_node, |
| } |
| if (cur_element) { |
| - scroll_chain.push_front(DOMNodeIds::IdForNode(cur_element)); |
| + if (CanScroll(scroll_state, cur_element)) |
|
bokan
2017/06/19 21:43:17
Do we have to do this after we've added our first
sahel
2017/06/22 16:34:20
Once scroll latching is enabled, we can get rid of
bokan
2017/06/22 21:44:37
Right, but I don't mean making the chain just one
sahel
2017/06/23 18:22:03
When scroll latching is off, there will be one GSB
bokan
2017/06/23 18:56:44
Right, thanks for the explanation.
|
| + scroll_chain.push_front(DOMNodeIds::IdForNode(cur_element)); |
| if (IsViewportScrollingElement(*cur_element) || |
| cur_element == document_element) |
| break; |
| @@ -115,6 +118,42 @@ void ScrollManager::RecomputeScrollChain(const Node& start_node, |
| } |
| } |
| +bool ScrollManager::CanScroll(const ScrollState& scroll_state, |
| + const Element* current_element) { |
| + const double delta_x = scroll_state.isBeginning() ? scroll_state.deltaXHint() |
| + : scroll_state.deltaX(); |
| + const double delta_y = scroll_state.isBeginning() ? scroll_state.deltaYHint() |
| + : scroll_state.deltaY(); |
| + if (!delta_x && !delta_y) |
| + return true; |
| + |
| + if (scroll_state.ignoreDeltaHints()) { |
| + DCHECK(scroll_state.isBeginning()); |
| + return true; |
| + } |
| + |
| + DCHECK(current_element); |
|
bokan
2017/06/19 21:43:17
Rather than DCHECK, just pass the Element by const
sahel
2017/06/22 16:34:18
Done.
|
| + |
| + if (IsViewportScrollingElement(*current_element)) |
| + return true; |
| + |
| + if (current_element == frame_->GetDocument()->documentElement()) |
| + return true; |
| + |
| + ScrollableArea* scrollable_area = |
| + current_element->GetLayoutBox() |
| + ? current_element->GetLayoutBox()->GetScrollableArea() |
| + : nullptr; |
| + if (!scrollable_area) |
| + return false; |
| + |
| + ScrollOffset current_offset = scrollable_area->GetScrollOffset(); |
| + ScrollOffset target_offset = current_offset + ScrollOffset(delta_x, delta_y); |
| + ScrollOffset clamped_offset = |
| + scrollable_area->ClampScrollOffset(target_offset); |
| + return clamped_offset != current_offset; |
| +} |
| + |
| bool ScrollManager::LogicalScroll(ScrollDirection direction, |
| ScrollGranularity granularity, |
| Node* start_node, |
| @@ -184,16 +223,14 @@ void ScrollManager::SetFrameWasScrolledByUser() { |
| document_loader->GetInitialScrollState().was_scrolled_by_user = true; |
| } |
| -void ScrollManager::CustomizedScroll(const Node& start_node, |
| - ScrollState& scroll_state) { |
| +void ScrollManager::CustomizedScroll(ScrollState& scroll_state) { |
| if (scroll_state.FullyConsumed()) |
| return; |
| if (scroll_state.deltaX() || scroll_state.deltaY()) |
| frame_->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); |
| - if (current_scroll_chain_.empty()) |
| - RecomputeScrollChain(start_node, current_scroll_chain_); |
| + DCHECK(!current_scroll_chain_.empty()); |
| scroll_state.SetScrollChain(current_scroll_chain_); |
| scroll_state.distributeToScrollChainDescendant(); |
| @@ -318,6 +355,10 @@ WebInputEventResult ScrollManager::HandleGestureScrollBegin( |
| IntPoint position = FlooredIntPoint(gesture_event.PositionInRootFrame()); |
| scroll_state_data->position_x = position.X(); |
| scroll_state_data->position_y = position.Y(); |
| + scroll_state_data->delta_x_hint = -gesture_event.DeltaXInRootFrame(); |
| + scroll_state_data->delta_y_hint = -gesture_event.DeltaYInRootFrame(); |
| + scroll_state_data->ignore_delta_hints = |
| + gesture_event.data.scroll_begin.ignore_delta_hints; |
| scroll_state_data->is_beginning = true; |
| scroll_state_data->from_user_input = true; |
| scroll_state_data->is_direct_manipulation = |
| @@ -325,7 +366,12 @@ WebInputEventResult ScrollManager::HandleGestureScrollBegin( |
| scroll_state_data->delta_consumed_for_scroll_sequence = |
| delta_consumed_for_scroll_sequence_; |
| ScrollState* scroll_state = ScrollState::Create(std::move(scroll_state_data)); |
| - CustomizedScroll(*scroll_gesture_handling_node_.Get(), *scroll_state); |
| + RecomputeScrollChain(*scroll_gesture_handling_node_.Get(), *scroll_state, |
| + current_scroll_chain_); |
| + if (current_scroll_chain_.empty()) { |
|
bokan
2017/06/19 21:43:17
Nit: no {}
sahel
2017/06/22 16:34:18
Done.
|
| + return WebInputEventResult::kNotHandled; |
| + } |
| + CustomizedScroll(*scroll_state); |
| if (gesture_event.source_device == kWebGestureDeviceTouchscreen) |
| UseCounter::Count(frame_->GetDocument(), WebFeature::kScrollByTouch); |
| @@ -394,7 +440,11 @@ WebInputEventResult ScrollManager::HandleGestureScrollUpdate( |
| scroll_state->SetCurrentNativeScrollingElement( |
| previous_gesture_scrolled_element_); |
| } |
| - CustomizedScroll(*node, *scroll_state); |
| + |
| + if (current_scroll_chain_.empty()) |
|
bokan
2017/06/19 21:43:17
We can early out before creating and initializing
sahel
2017/06/22 16:34:19
Done.
|
| + return WebInputEventResult::kNotHandled; |
| + |
| + CustomizedScroll(*scroll_state); |
| previous_gesture_scrolled_element_ = |
| scroll_state->CurrentNativeScrollingElement(); |
| delta_consumed_for_scroll_sequence_ = |
| @@ -435,7 +485,8 @@ WebInputEventResult ScrollManager::HandleGestureScrollEnd( |
| delta_consumed_for_scroll_sequence_; |
| ScrollState* scroll_state = |
| ScrollState::Create(std::move(scroll_state_data)); |
| - CustomizedScroll(*node, *scroll_state); |
| + if (!current_scroll_chain_.empty()) |
|
bokan
2017/06/19 21:43:17
We should skip the scroll_state_data initializatio
sahel
2017/06/22 16:34:18
Done.
|
| + CustomizedScroll(*scroll_state); |
| } |
| ClearGestureScrollState(); |