diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-03-11 11:32:04 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-03-18 13:40:17 +0000 |
commit | 31ccca0778db85c159634478b4ec7997f6704860 (patch) | |
tree | 3d33fc3afd9d5ec95541e1bbe074a9cf8da12a0e /chromium/third_party/blink/renderer/core/input/scroll_manager.cc | |
parent | 248b70b82a40964d5594eb04feca0fa36716185d (diff) | |
download | qtwebengine-chromium-31ccca0778db85c159634478b4ec7997f6704860.tar.gz |
BASELINE: Update Chromium to 80.0.3987.136
Change-Id: I98e1649aafae85ba3a83e67af00bb27ef301db7b
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/core/input/scroll_manager.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/core/input/scroll_manager.cc | 130 |
1 files changed, 57 insertions, 73 deletions
diff --git a/chromium/third_party/blink/renderer/core/input/scroll_manager.cc b/chromium/third_party/blink/renderer/core/input/scroll_manager.cc index 3135f698168..b9945841fef 100644 --- a/chromium/third_party/blink/renderer/core/input/scroll_manager.cc +++ b/chromium/third_party/blink/renderer/core/input/scroll_manager.cc @@ -28,11 +28,11 @@ #include "third_party/blink/renderer/core/page/scrolling/root_scroller_controller.h" #include "third_party/blink/renderer/core/page/scrolling/scroll_state.h" #include "third_party/blink/renderer/core/page/scrolling/scrolling_coordinator.h" -#include "third_party/blink/renderer/core/page/scrolling/snap_coordinator.h" #include "third_party/blink/renderer/core/paint/paint_layer.h" #include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h" #include "third_party/blink/renderer/core/scroll/scroll_animator_base.h" #include "third_party/blink/renderer/core/scroll/scroll_customization.h" +#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/instrumentation/histogram.h" #include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h" @@ -63,16 +63,6 @@ cc::SnapFlingController::GestureScrollUpdateInfo GetGestureScrollUpdateInfo( WebGestureEvent::InertialPhaseState::kMomentum, .event_time = event.TimeStamp()}; } - -ScrollableArea* ScrollableAreaForSnapping(LayoutBox* layout_box) { - if (!layout_box) - return nullptr; - - return layout_box->IsLayoutView() - ? layout_box->GetFrameView()->GetScrollableArea() - : layout_box->GetScrollableArea(); -} - } // namespace ScrollManager::ScrollManager(LocalFrame& frame) : frame_(frame) { @@ -271,7 +261,8 @@ bool ScrollManager::LogicalScroll(ScrollDirection direction, Deque<DOMNodeId> scroll_chain; std::unique_ptr<ScrollStateData> scroll_state_data = std::make_unique<ScrollStateData>(); - ScrollState* scroll_state = ScrollState::Create(std::move(scroll_state_data)); + auto* scroll_state = + MakeGarbageCollected<ScrollState>(std::move(scroll_state_data)); RecomputeScrollChain(*node, *scroll_state, scroll_chain); while (!scroll_chain.IsEmpty()) { @@ -285,24 +276,9 @@ bool ScrollManager::LogicalScroll(ScrollDirection direction, ToPhysicalDirection(direction, box->IsHorizontalWritingMode(), box->Style()->IsFlippedBlocksWritingMode()); - ScrollableArea* scrollable_area = nullptr; - - // The global root scroller must be scrolled by the RootFrameViewport. - if (box->IsGlobalRootScroller()) { - LocalFrame& main_frame = frame_->LocalFrameRoot(); - // The local root must be the main frame if we have the global root - // scroller since it can't yet be set on OOPIFs. - DCHECK(main_frame.IsMainFrame()); - - scrollable_area = main_frame.View()->GetScrollableArea(); - } else { - scrollable_area = box->GetScrollableArea(); - } - + ScrollableArea* scrollable_area = ScrollableArea::GetForScrolling(box); DCHECK(scrollable_area); - SnapCoordinator& snap_coordinator = - frame_->GetDocument()->GetSnapCoordinator(); ScrollOffset delta = ToScrollDelta(physical_direction, 1); delta.Scale(scrollable_area->ScrollStep(granularity, kHorizontalScrollbar), scrollable_area->ScrollStep(granularity, kVerticalScrollbar)); @@ -312,12 +288,12 @@ bool ScrollManager::LogicalScroll(ScrollDirection direction, // scroll with intended end position only. switch (granularity) { case ScrollGranularity::kScrollByLine: { - if (snap_coordinator.SnapForDirection(*box, delta)) + if (scrollable_area->SnapForDirection(delta)) return true; break; } case ScrollGranularity::kScrollByPage: { - if (snap_coordinator.SnapForEndAndDirection(*box, delta)) + if (scrollable_area->SnapForEndAndDirection(delta)) return true; break; } @@ -327,7 +303,7 @@ bool ScrollManager::LogicalScroll(ScrollDirection direction, physical_direction == kScrollRight; bool scrolled_y = physical_direction == kScrollUp || physical_direction == kScrollDown; - if (snap_coordinator.SnapForEndPosition(*box, end_position, scrolled_x, + if (scrollable_area->SnapForEndPosition(end_position, scrolled_x, scrolled_y)) return true; break; @@ -498,7 +474,8 @@ WebInputEventResult ScrollManager::HandleGestureScrollBegin( gesture_event.SourceDevice() == WebGestureDevice::kTouchscreen; scroll_state_data->delta_consumed_for_scroll_sequence = delta_consumed_for_scroll_sequence_; - ScrollState* scroll_state = ScrollState::Create(std::move(scroll_state_data)); + auto* scroll_state = + MakeGarbageCollected<ScrollState>(std::move(scroll_state_data)); // For middle click autoscroll, only scrollable area for // |scroll_gesture_handling_node_| should receive and handle all scroll // events. It should not bubble up to the ancestor. @@ -626,7 +603,8 @@ WebInputEventResult ScrollManager::HandleGestureScrollUpdate( scroll_state_data->from_user_input = true; scroll_state_data->delta_consumed_for_scroll_sequence = delta_consumed_for_scroll_sequence_; - ScrollState* scroll_state = ScrollState::Create(std::move(scroll_state_data)); + auto* scroll_state = + MakeGarbageCollected<ScrollState>(std::move(scroll_state_data)); if (previous_gesture_scrolled_node_) { // The ScrollState needs to know what the current // native scrolling element is, so that for an @@ -682,7 +660,6 @@ WebInputEventResult ScrollManager::HandleGestureScrollEnd( const WebGestureEvent& gesture_event) { TRACE_EVENT0("input", "ScrollManager::handleGestureScrollEnd"); Node* node = scroll_gesture_handling_node_; - bool snap_at_gesture_scroll_end = false; if (node && node->GetLayoutObject()) { // If the GSE is for a scrollable area that has an in-progress animation, @@ -716,32 +693,37 @@ WebInputEventResult ScrollManager::HandleGestureScrollEnd( gesture_event.SourceDevice() == WebGestureDevice::kTouchscreen; scroll_state_data->delta_consumed_for_scroll_sequence = delta_consumed_for_scroll_sequence_; - ScrollState* scroll_state = - ScrollState::Create(std::move(scroll_state_data)); + auto* scroll_state = + MakeGarbageCollected<ScrollState>(std::move(scroll_state_data)); CustomizedScroll(*scroll_state); - snap_at_gesture_scroll_end = SnapAtGestureScrollEnd(gesture_event); + // We add a callback to set the hover state dirty and send a scroll end + // event when the scroll ends without snap or the snap point is the same as + // the scroll position. + base::ScopedClosureRunner callback(WTF::Bind( + [](WeakPersistent<LocalFrame> local_frame, + WeakPersistent<ScrollManager> scroll_manager) { + if (RuntimeEnabledFeatures::UpdateHoverAtBeginFrameEnabled() && + local_frame) { + local_frame->GetEventHandler().MarkHoverStateDirty(); + } + + Node* scroll_end_target = scroll_manager->GetScrollEventTarget(); + if (RuntimeEnabledFeatures::OverscrollCustomizationEnabled() && + scroll_end_target) { + scroll_end_target->GetDocument().EnqueueScrollEndEventForNode( + scroll_end_target); + } + }, + WrapWeakPersistent(&(frame_->LocalFrameRoot())), + WrapWeakPersistent(this))); + + SnapAtGestureScrollEnd(gesture_event, std::move(callback)); NotifyScrollPhaseEndForCustomizedScroll(); - - if (RuntimeEnabledFeatures::OverscrollCustomizationEnabled() && - !snap_at_gesture_scroll_end) { - if (Node* scroll_end_target = GetScrollEventTarget()) { - scroll_end_target->GetDocument().EnqueueScrollEndEventForNode( - scroll_end_target); - } - } } ClearGestureScrollState(); - // If we are performing a snap at the scrollend gesture, we should update - // hover state dirty at the end of the programmatic scroll animation caused - // by the snap, and we should avoid marking the hover state dirty here. - if (!snap_at_gesture_scroll_end && - RuntimeEnabledFeatures::UpdateHoverAtBeginFrameEnabled()) { - frame_->LocalFrameRoot().GetEventHandler().MarkHoverStateDirty(); - } - return WebInputEventResult::kNotHandled; } @@ -755,14 +737,15 @@ ScrollOffset GetScrollDirection(FloatSize delta) { return delta.ShrunkTo(FloatSize(1, 1)).ExpandedTo(FloatSize(-1, -1)); } -bool ScrollManager::SnapAtGestureScrollEnd(const WebGestureEvent& end_event) { +bool ScrollManager::SnapAtGestureScrollEnd( + const WebGestureEvent& end_event, + base::ScopedClosureRunner on_finish) { if (!previous_gesture_scrolled_node_ || (!did_scroll_x_for_scroll_gesture_ && !did_scroll_y_for_scroll_gesture_)) return false; - SnapCoordinator& snap_coordinator = - frame_->GetDocument()->GetSnapCoordinator(); - LayoutBox* layout_box = LayoutBoxForSnapping(); - if (!layout_box) + ScrollableArea* scrollable_area = + ScrollableArea::GetForScrolling(LayoutBoxForSnapping()); + if (!scrollable_area) return false; bool is_mouse_wheel = @@ -786,23 +769,22 @@ bool ScrollManager::SnapAtGestureScrollEnd(const WebGestureEvent& end_event) { // limit the miscalculation to 1px. ScrollOffset scroll_direction = GetScrollDirection(last_scroll_delta_for_scroll_gesture_); - return snap_coordinator.SnapForDirection(*layout_box, scroll_direction); + return scrollable_area->SnapForDirection(scroll_direction, + std::move(on_finish)); } - return snap_coordinator.SnapAtCurrentPosition( - *layout_box, did_scroll_x_for_scroll_gesture_, - did_scroll_y_for_scroll_gesture_); + return scrollable_area->SnapAtCurrentPosition( + did_scroll_x_for_scroll_gesture_, did_scroll_y_for_scroll_gesture_, + std::move(on_finish)); } -bool ScrollManager::GetSnapFlingInfo( +bool ScrollManager::GetSnapFlingInfoAndSetSnapTarget( const gfx::Vector2dF& natural_displacement, gfx::Vector2dF* out_initial_position, gfx::Vector2dF* out_target_position) const { - SnapCoordinator& snap_coordinator = - frame_->GetDocument()->GetSnapCoordinator(); - LayoutBox* layout_box = LayoutBoxForSnapping(); - ScrollableArea* scrollable_area = ScrollableAreaForSnapping(layout_box); - if (!layout_box || !scrollable_area) + ScrollableArea* scrollable_area = + ScrollableArea::GetForScrolling(LayoutBoxForSnapping()); + if (!scrollable_area) return false; FloatPoint current_position = scrollable_area->ScrollPosition(); @@ -812,7 +794,7 @@ bool ScrollManager::GetSnapFlingInfo( gfx::ScrollOffset(*out_initial_position), gfx::ScrollOffset(natural_displacement)); base::Optional<FloatPoint> snap_end = - snap_coordinator.GetSnapPosition(*layout_box, *strategy); + scrollable_area->GetSnapPositionAndSetTarget(*strategy); if (!snap_end.has_value()) return false; *out_target_position = gfx::Vector2dF(snap_end.value()); @@ -822,7 +804,7 @@ bool ScrollManager::GetSnapFlingInfo( gfx::Vector2dF ScrollManager::ScrollByForSnapFling( const gfx::Vector2dF& delta) { ScrollableArea* scrollable_area = - ScrollableAreaForSnapping(LayoutBoxForSnapping()); + ScrollableArea::GetForScrolling(LayoutBoxForSnapping()); if (!scrollable_area) return gfx::Vector2dF(); @@ -838,7 +820,8 @@ gfx::Vector2dF ScrollManager::ScrollByForSnapFling( static_cast<double>(ScrollGranularity::kScrollByPrecisePixel); scroll_state_data->delta_consumed_for_scroll_sequence = delta_consumed_for_scroll_sequence_; - ScrollState* scroll_state = ScrollState::Create(std::move(scroll_state_data)); + auto* scroll_state = + MakeGarbageCollected<ScrollState>(std::move(scroll_state_data)); scroll_state->SetCurrentNativeScrollingNode(previous_gesture_scrolled_node_); CustomizedScroll(*scroll_state); @@ -865,7 +848,8 @@ void ScrollManager::ScrollEndForSnapFling() { scroll_state_data->from_user_input = true; scroll_state_data->delta_consumed_for_scroll_sequence = delta_consumed_for_scroll_sequence_; - ScrollState* scroll_state = ScrollState::Create(std::move(scroll_state_data)); + auto* scroll_state = + MakeGarbageCollected<ScrollState>(std::move(scroll_state_data)); CustomizedScroll(*scroll_state); NotifyScrollPhaseEndForCustomizedScroll(); ClearGestureScrollState(); @@ -1038,7 +1022,7 @@ Node* ScrollManager::NodeTargetForScrollableAreaElementId( Page* page = frame_->GetPage(); DCHECK(page); ScrollableArea* scrollable_area = nullptr; - if (page->GetVisualViewport().GetCompositorElementId() == element_id) { + if (page->GetVisualViewport().GetScrollElementId() == element_id) { // If the element_id is the visual viewport, redirect to the // root LocalFrameView's scrollable area (i.e. the RootFrameViewport). scrollable_area = frame_->LocalFrameRoot().View()->GetScrollableArea(); |