Chromium Code Reviews| Index: third_party/WebKit/Source/core/input/EventHandler.cpp |
| diff --git a/third_party/WebKit/Source/core/input/EventHandler.cpp b/third_party/WebKit/Source/core/input/EventHandler.cpp |
| index 79223c9c4ca417c9f27fca8e78c7ab01ab1f8aab..c6862b252e9c9e0edcf455c26a303db200b54879 100644 |
| --- a/third_party/WebKit/Source/core/input/EventHandler.cpp |
| +++ b/third_party/WebKit/Source/core/input/EventHandler.cpp |
| @@ -602,11 +602,46 @@ void EventHandler::stopAutoscroll() |
| controller->stopAutoscroll(); |
| } |
| -ScrollResultOneDimensional EventHandler::scroll(ScrollDirection direction, ScrollGranularity granularity, Node* startNode, Node** stopNode, float delta) |
| +ScrollResult EventHandler::physicalScroll(ScrollGranularity granularity, const FloatSize& delta, Node* startNode, Node** stopNode) |
| { |
| - if (!delta) |
| - return ScrollResultOneDimensional(false); |
| + if (delta.isZero()) |
| + return ScrollResult(); |
| + |
| + Node* node = startNode; |
| + ASSERT(node && node->layoutObject()); |
| + |
| + m_frame->document()->updateLayoutIgnorePendingStylesheets(); |
|
tdresser
2016/02/29 14:53:43
Why was this not needed before, but needed now?
bokan
2016/03/01 05:56:24
It was there before too, just before we enter the
|
| + |
| + ScrollResult result; |
| + |
| + LayoutBox* curBox = node->layoutObject()->enclosingBox(); |
| + while (curBox && !curBox->isLayoutView()) { |
| + // If we're at the stopNode, we should try to scroll it but we shouldn't bubble past it |
|
tdresser
2016/02/29 14:53:43
Missing period.
bokan
2016/03/01 05:56:24
Done.
|
| + bool shouldStopBubbling = stopNode && *stopNode && curBox->node() == *stopNode; |
| + result = curBox->scroll(granularity, delta); |
| + |
| + if (result.didScroll() && stopNode) |
| + *stopNode = curBox->node(); |
| + |
| + if (result.didScroll() || shouldStopBubbling) { |
| + setFrameWasScrolledByUser(); |
| + if (!result.didScroll()) { |
| + // TODO(bokan): We should probably add a "shouldPropagate" bit |
| + // on the result instead rather than lying to the caller. |
|
tdresser
2016/02/29 14:53:43
instead rather -> rather
bokan
2016/03/01 05:56:24
Done.
|
| + result.didScrollX = true; |
| + result.didScrollY = true; |
| + } |
| + return result; |
| + } |
| + |
| + curBox = curBox->containingBlock(); |
| + } |
| + |
| + return result; |
| +} |
| +bool EventHandler::logicalScroll(ScrollDirection direction, ScrollGranularity granularity, Node* startNode) |
| +{ |
| Node* node = startNode; |
| if (!node) |
| @@ -616,7 +651,7 @@ ScrollResultOneDimensional EventHandler::scroll(ScrollDirection direction, Scrol |
| node = m_mousePressNode.get(); |
| if (!node || !node->layoutObject()) |
| - return ScrollResultOneDimensional(false, delta); |
| + return false; |
| m_frame->document()->updateLayoutIgnorePendingStylesheets(); |
| @@ -625,23 +660,17 @@ ScrollResultOneDimensional EventHandler::scroll(ScrollDirection direction, Scrol |
| ScrollDirectionPhysical physicalDirection = toPhysicalDirection( |
| direction, curBox->isHorizontalWritingMode(), curBox->style()->isFlippedBlocksWritingMode()); |
| - // If we're at the stopNode, we should try to scroll it but we shouldn't bubble past it |
| - bool shouldStopBubbling = stopNode && *stopNode && curBox->node() == *stopNode; |
| - ScrollResultOneDimensional result = curBox->scroll(physicalDirection, granularity, delta); |
| + ScrollResult result = curBox->scroll(granularity, toScrollDelta(physicalDirection, 1)); |
| - if (result.didScroll && stopNode) |
| - *stopNode = curBox->node(); |
| - |
| - if (result.didScroll || shouldStopBubbling) { |
| + if (result.didScroll()) { |
| setFrameWasScrolledByUser(); |
| - result.didScroll = true; |
| - return result; |
| + return true; |
| } |
| curBox = curBox->containingBlock(); |
| } |
| - return ScrollResultOneDimensional(false, delta); |
| + return false; |
| } |
| void EventHandler::customizedScroll(const Node& startNode, ScrollState& scrollState) |
| @@ -659,20 +688,22 @@ void EventHandler::customizedScroll(const Node& startNode, ScrollState& scrollSt |
| scrollState.distributeToScrollChainDescendant(); |
| } |
| +// TODO(bokan): This should be merged with logicalScroll assuming |
| +// defaultSpaceEventHandler's bubbling scroll can be done crossing frames. |
| bool EventHandler::bubblingScroll(ScrollDirection direction, ScrollGranularity granularity, Node* startingNode) |
| { |
| // The layout needs to be up to date to determine if we can scroll. We may be |
| // here because of an onLoad event, in which case the final layout hasn't been performed yet. |
| m_frame->document()->updateLayoutIgnorePendingStylesheets(); |
| // FIXME: enable scroll customization in this case. See crbug.com/410974. |
| - if (scroll(direction, granularity, startingNode).didScroll) |
| + if (logicalScroll(direction, granularity, startingNode)) |
| return true; |
| LocalFrame* frame = m_frame; |
| FrameView* view = frame->view(); |
| if (view) { |
| ScrollDirectionPhysical physicalDirection = |
| toPhysicalDirection(direction, view->isVerticalDocument(), view->isFlippedDocument()); |
| - if (view->scrollableArea()->userScroll(physicalDirection, granularity).didScroll) { |
| + if (view->scrollableArea()->userScroll(granularity, toScrollDelta(physicalDirection, 1)).didScroll()) { |
| setFrameWasScrolledByUser(); |
| return true; |
| } |
| @@ -1754,16 +1785,9 @@ ScrollResult scrollAreaWithWheelEvent(const PlatformWheelEvent& event, Scrollabl |
| deltaY = deltaY > 0 ? 1 : -1; |
| } |
| - // Positive delta is up and left. |
| - ScrollResultOneDimensional resultY = scrollableArea.userScroll(ScrollUp, granularity, deltaY); |
| - ScrollResultOneDimensional resultX = scrollableArea.userScroll(ScrollLeft, granularity, deltaX); |
| - |
| - ScrollResult result; |
| - result.didScrollY = resultY.didScroll; |
| - result.didScrollX = resultX.didScroll; |
| - result.unusedScrollDeltaY = resultY.unusedScrollDelta; |
| - result.unusedScrollDeltaX = resultX.unusedScrollDelta; |
| - return result; |
| + // On a wheel event, positive delta is meant to scroll up and left, which |
| + // is the opposite of deltas in the scrolling system. |
| + return scrollableArea.userScroll(granularity, FloatSize(-deltaX, -deltaY)); |
| } |
| } // namespace |
| @@ -1852,16 +1876,20 @@ void EventHandler::defaultWheelEventHandler(Node* startNode, WheelEvent* wheelEv |
| Node* stopNode = m_previousWheelScrolledNode.get(); |
| ScrollGranularity granularity = wheelGranularityToScrollGranularity(wheelEvent); |
| - // Break up into two scrolls if we need to. Diagonal movement on |
| - // a MacBook pro is an example of a 2-dimensional mouse wheel event (where both deltaX and deltaY can be set). |
| + // Diagonal movement on a MacBook pro is an example of a 2-dimensional |
| + // mouse wheel event (where both deltaX and deltaY can be set). |
| + FloatSize delta; |
| + |
| + if (wheelEvent->getRailsMode() != Event::RailsModeVertical) |
| + delta.setWidth(wheelEvent->deltaX()); |
| + |
| + if (wheelEvent->getRailsMode() != Event::RailsModeHorizontal) |
| + delta.setHeight(wheelEvent->deltaY()); |
| // FIXME: enable scroll customization in this case. See crbug.com/410974. |
| - if (wheelEvent->getRailsMode() != Event::RailsModeVertical |
| - && scroll(ScrollRightIgnoringWritingMode, granularity, startNode, &stopNode, wheelEvent->deltaX()).didScroll) |
| - wheelEvent->setDefaultHandled(); |
| + ScrollResult result = physicalScroll(granularity, delta, startNode, &stopNode); |
| - if (wheelEvent->getRailsMode() != Event::RailsModeHorizontal |
| - && scroll(ScrollDownIgnoringWritingMode, granularity, startNode, &stopNode, wheelEvent->deltaY()).didScroll) |
| + if (result.didScroll()) |
| wheelEvent->setDefaultHandled(); |
| m_previousWheelScrolledNode = stopNode; |
| @@ -2356,6 +2384,9 @@ WebInputEventResult EventHandler::handleGestureScrollUpdate(const PlatformGestur |
| { |
| ASSERT(gestureEvent.type() == PlatformEvent::GestureScrollUpdate); |
| + // TODO(bokan): This delta is specific to the event which is positive up and |
| + // to the left. Since we're passing it into a bunch of scrolling code below, |
| + // it should probably be inverted here. |
| FloatSize delta(gestureEvent.deltaX(), gestureEvent.deltaY()); |
| if (delta.isZero()) |
| return WebInputEventResult::NotHandled; |
| @@ -2372,8 +2403,6 @@ WebInputEventResult EventHandler::handleGestureScrollUpdate(const PlatformGestur |
| RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); |
| - Node* stopNode = nullptr; |
| - |
| // Try to send the event to the correct view. |
| WebInputEventResult result = passScrollGestureEventToWidget(gestureEvent, layoutObject); |
| if (result != WebInputEventResult::NotHandled) { |
| @@ -2415,22 +2444,19 @@ WebInputEventResult EventHandler::handleGestureScrollUpdate(const PlatformGestur |
| scrolled = scrollState->deltaX() != gestureEvent.deltaX() |
| || scrollState->deltaY() != gestureEvent.deltaY(); |
| } else { |
| + Node* stopNode = nullptr; |
| if (gestureEvent.preventPropagation()) |
| stopNode = m_previousGestureScrolledNode.get(); |
| - // First try to scroll the closest scrollable LayoutBox ancestor of |node|. |
| - ScrollResultOneDimensional result = scroll(ScrollLeftIgnoringWritingMode, granularity, node, &stopNode, delta.width()); |
| - bool horizontalScroll = result.didScroll; |
| - if (!gestureEvent.preventPropagation()) |
| - stopNode = nullptr; |
| - result = scroll(ScrollUpIgnoringWritingMode, granularity, node, &stopNode, delta.height()); |
| - bool verticalScroll = result.didScroll; |
| - scrolled = horizontalScroll || verticalScroll; |
| + // Scale by -1 because the delta is the GestureEvent delta (see TODO at top of function). |
| + ScrollResult result = physicalScroll(granularity, delta.scaledBy(-1), node, &stopNode); |
| + |
| + scrolled = result.didScroll(); |
| if (gestureEvent.preventPropagation()) |
| m_previousGestureScrolledNode = stopNode; |
| - resetOverscroll(horizontalScroll, verticalScroll); |
| + resetOverscroll(result.didScrollX, result.didScrollY); |
| } |
| if (scrolled) { |
| setFrameWasScrolledByUser(); |
| @@ -3408,7 +3434,7 @@ void EventHandler::defaultSpaceEventHandler(KeyboardEvent* event) |
| ScrollDirection direction = event->shiftKey() ? ScrollBlockDirectionBackward : ScrollBlockDirectionForward; |
| // FIXME: enable scroll customization in this case. See crbug.com/410974. |
| - if (scroll(direction, ScrollByPage).didScroll) { |
| + if (logicalScroll(direction, ScrollByPage)) { |
| event->setDefaultHandled(); |
| return; |
| } |
| @@ -3420,7 +3446,7 @@ void EventHandler::defaultSpaceEventHandler(KeyboardEvent* event) |
| ScrollDirectionPhysical physicalDirection = |
| toPhysicalDirection(direction, view->isVerticalDocument(), view->isFlippedDocument()); |
| - if (view->scrollableArea()->userScroll(physicalDirection, ScrollByPage).didScroll) |
| + if (view->scrollableArea()->userScroll(ScrollByPage, toScrollDelta(physicalDirection, 1)).didScroll()) |
| event->setDefaultHandled(); |
| } |