void ScrollingTree::setOrClearLatchedNode(const PlatformWheelEvent& wheelEvent, ScrollingNodeID nodeID) { if (wheelEvent.shouldConsiderLatching()) setLatchedNode(nodeID); else if (wheelEvent.shouldResetLatching()) clearLatchedNode(); }
bool ScrollingTree::shouldHandleWheelEventSynchronously(const PlatformWheelEvent& wheelEvent) { // This method is invoked by the event handling thread MutexLocker lock(m_mutex); if (m_hasWheelEventHandlers) return true; bool shouldSetLatch = wheelEvent.shouldConsiderLatching(); if (hasLatchedNode() && !shouldSetLatch) return false; if (shouldSetLatch) m_latchedNode = 0; if (!m_nonFastScrollableRegion.isEmpty()) { // FIXME: This is not correct for non-default scroll origins. FloatPoint position = wheelEvent.position(); position.moveBy(m_mainFrameScrollPosition); if (m_nonFastScrollableRegion.contains(roundedIntPoint(position))) return true; } return false; }
void EventDispatcher::wheelEvent(uint64_t pageID, const WebWheelEvent& wheelEvent, bool canGoBack, bool canGoForward) { #if ENABLE(THREADED_SCROLLING) MutexLocker locker(m_scrollingTreesMutex); if (ScrollingTree* scrollingTree = m_scrollingTrees.get(pageID)) { PlatformWheelEvent platformWheelEvent = platform(wheelEvent); // FIXME: It's pretty horrible that we're updating the back/forward state here. // WebCore should always know the current state and know when it changes so the // scrolling tree can be notified. // We only need to do this at the beginning of the gesture. if (platformWheelEvent.phase() == PlatformWheelEventPhaseBegan) ScrollingThread::dispatch(bind(&ScrollingTree::updateBackForwardState, scrollingTree, canGoBack, canGoForward)); ScrollingTree::EventResult result = scrollingTree->tryToHandleWheelEvent(platformWheelEvent); if (result == ScrollingTree::DidHandleEvent || result == ScrollingTree::DidNotHandleEvent) { sendDidReceiveEvent(pageID, wheelEvent, result == ScrollingTree::DidHandleEvent); return; } } #else UNUSED_PARAM(canGoBack); UNUSED_PARAM(canGoForward); #endif RunLoop::main()->dispatch(bind(&EventDispatcher::dispatchWheelEvent, this, pageID, wheelEvent)); }
void ScrollAnimator::handleWheelEvent(PlatformWheelEvent& e) { Scrollbar* horizontalScrollbar = m_scrollableArea->horizontalScrollbar(); Scrollbar* verticalScrollbar = m_scrollableArea->verticalScrollbar(); // Accept the event if we have a scrollbar in that direction and can still // scroll any further. float deltaX = horizontalScrollbar ? e.deltaX() : 0; float deltaY = verticalScrollbar ? e.deltaY() : 0; IntSize maxForwardScrollDelta = m_scrollableArea->maximumScrollPosition() - m_scrollableArea->scrollPosition(); IntSize maxBackwardScrollDelta = m_scrollableArea->scrollPosition() - m_scrollableArea->minimumScrollPosition(); if ((deltaX < 0 && maxForwardScrollDelta.width() > 0) || (deltaX > 0 && maxBackwardScrollDelta.width() > 0) || (deltaY < 0 && maxForwardScrollDelta.height() > 0) || (deltaY > 0 && maxBackwardScrollDelta.height() > 0)) { e.accept(); if (e.granularity() == ScrollByPageWheelEvent) { ASSERT(!e.deltaX()); bool negative = deltaY < 0; deltaY = max(max(static_cast<float>(m_scrollableArea->visibleHeight()) * Scrollbar::minFractionToStepWhenPaging(), static_cast<float>(m_scrollableArea->visibleHeight() - Scrollbar::maxOverlapBetweenPages())), 1.0f); if (negative) deltaY = -deltaY; } if (deltaY) scroll(VerticalScrollbar, ScrollByPixel, verticalScrollbar->pixelStep(), -deltaY); if (deltaX) scroll(HorizontalScrollbar, ScrollByPixel, horizontalScrollbar->pixelStep(), -deltaX); } }
void ScrollView::wheelEvent(PlatformWheelEvent& e) { // We don't allow mouse wheeling to happen in a ScrollView that has had its scrollbars explicitly disabled. #if PLATFORM(WX) if (!canHaveScrollbars()) { #else if (!canHaveScrollbars() || platformWidget()) { #endif return; } // Accept the event if we have a scrollbar in that direction and can still // scroll any further. float deltaX = m_horizontalScrollbar ? e.deltaX() : 0; float deltaY = m_verticalScrollbar ? e.deltaY() : 0; IntSize maxForwardScrollDelta = maximumScrollPosition() - scrollPosition(); IntSize maxBackwardScrollDelta = scrollPosition() - minimumScrollPosition(); if ((deltaX < 0 && maxForwardScrollDelta.width() > 0) || (deltaX > 0 && maxBackwardScrollDelta.width() >0) || (deltaY < 0 && maxForwardScrollDelta.height() > 0) || (deltaY > 0 && maxBackwardScrollDelta.height() > 0)) { e.accept(); if (e.granularity() == ScrollByPageWheelEvent) { ASSERT(!e.deltaX()); bool negative = deltaY < 0; deltaY = max(max(static_cast<float>(visibleHeight()) * Scrollbar::minFractionToStepWhenPaging(), static_cast<float>(visibleHeight() - Scrollbar::maxOverlapBetweenPages())), 1.0f); if (negative) deltaY = -deltaY; } if (deltaY) m_verticalScrollbar->scroll(ScrollUp, ScrollByPixel, deltaY); if (deltaX) m_horizontalScrollbar->scroll(ScrollLeft, ScrollByPixel, deltaX); } } void ScrollView::setFrameRect(const IntRect& newRect) { IntRect oldRect = frameRect(); if (newRect == oldRect) return; Widget::setFrameRect(newRect); if (platformWidget()) return; if (newRect.width() != oldRect.width() || newRect.height() != oldRect.height()) { updateScrollbars(m_scrollOffset); if (!m_useFixedLayout) contentsResized(); } frameRectsChanged(); }
bool ScrollAnimator::handleWheelEvent(const PlatformWheelEvent& e) { #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) if (!m_scrollController.processWheelEventForScrollSnap(e)) return false; #endif #if PLATFORM(COCOA) // Events in the PlatformWheelEventPhaseMayBegin phase have no deltas, and therefore never passes through the scroll handling logic below. // This causes us to return with an 'unhandled' return state, even though this event was successfully processed. // // We receive at least one PlatformWheelEventPhaseMayBegin when starting main-thread scrolling (see FrameView::wheelEvent), which can // fool the scrolling thread into attempting to handle the scroll, unless we treat the event as handled here. if (e.phase() == PlatformWheelEventPhaseMayBegin) return true; #endif Scrollbar* horizontalScrollbar = m_scrollableArea.horizontalScrollbar(); Scrollbar* verticalScrollbar = m_scrollableArea.verticalScrollbar(); // Accept the event if we have a scrollbar in that direction and can still // scroll any further. float deltaX = horizontalScrollbar ? e.deltaX() : 0; float deltaY = verticalScrollbar ? e.deltaY() : 0; bool handled = false; ScrollGranularity granularity = ScrollByPixel; IntSize maxForwardScrollDelta = m_scrollableArea.maximumScrollPosition() - m_scrollableArea.scrollPosition(); IntSize maxBackwardScrollDelta = m_scrollableArea.scrollPosition() - m_scrollableArea.minimumScrollPosition(); if ((deltaX < 0 && maxForwardScrollDelta.width() > 0) || (deltaX > 0 && maxBackwardScrollDelta.width() > 0) || (deltaY < 0 && maxForwardScrollDelta.height() > 0) || (deltaY > 0 && maxBackwardScrollDelta.height() > 0)) { handled = true; if (deltaY) { if (e.granularity() == ScrollByPageWheelEvent) { bool negative = deltaY < 0; deltaY = Scrollbar::pageStepDelta(m_scrollableArea.visibleHeight()); if (negative) deltaY = -deltaY; } scroll(VerticalScrollbar, granularity, verticalScrollbar->pixelStep(), -deltaY); } if (deltaX) { if (e.granularity() == ScrollByPageWheelEvent) { bool negative = deltaX < 0; deltaX = Scrollbar::pageStepDelta(m_scrollableArea.visibleWidth()); if (negative) deltaX = -deltaX; } scroll(HorizontalScrollbar, granularity, horizontalScrollbar->pixelStep(), -deltaX); } } return handled; }
WheelEventDispatchMediator::WheelEventDispatchMediator(const PlatformWheelEvent& event, PassRefPtr<AbstractView> view) { if (!(event.deltaX() || event.deltaY())) return; setEvent(WheelEvent::create(FloatPoint(event.wheelTicksX(), event.wheelTicksY()), FloatPoint(event.deltaX(), event.deltaY()), granularity(event), view, IntPoint(event.globalX(), event.globalY()), IntPoint(event.x(), event.y()), event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), event.webkitDirectionInvertedFromDevice())); }
static PlatformWheelEvent constructRelativeWheelEvent(const PlatformWheelEvent& e, FramelessScrollView* parent, FramelessScrollView* child) { IntPoint pos = parent->convertSelfToChild(child, e.position()); // FIXME: This is a horrible hack since PlatformWheelEvent has no setters for x/y. PlatformWheelEvent relativeEvent = e; IntPoint& relativePos = const_cast<IntPoint&>(relativeEvent.position()); relativePos.setX(pos.x()); relativePos.setY(pos.y()); return relativeEvent; }
void ScrollView::wheelEvent(PlatformWheelEvent& e) { // Determine how much we want to scroll. If we can move at all, we will accept the event. IntSize maxScrollDelta = maximumScroll(); if ((e.deltaX() < 0 && maxScrollDelta.width() > 0) || (e.deltaX() > 0 && scrollOffset().width() > 0) || (e.deltaY() < 0 && maxScrollDelta.height() > 0) || (e.deltaY() > 0 && scrollOffset().height() > 0)) { e.accept(); scrollBy(-e.deltaX() * LINE_STEP, -e.deltaY() * LINE_STEP); } }
WheelEvent::WheelEvent(const PlatformWheelEvent& event, DOMWindow* view) : MouseEvent(eventNames().wheelEvent, true, true, event.timestamp(), view, 0, event.globalPosition(), event.position() #if ENABLE(POINTER_LOCK) , { } #endif , event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), 0, 0, 0, 0, 0, false) , m_wheelDelta(event.wheelTicksX() * TickMultiplier, event.wheelTicksY() * TickMultiplier) , m_deltaX(-event.deltaX()) , m_deltaY(-event.deltaY()) , m_deltaMode(determineDeltaMode(event)) , m_wheelEvent(event) , m_initializedWithPlatformWheelEvent(true) { }
bool ScrollAnimator::handleWheelEvent(const PlatformWheelEvent& e) { bool canScrollX = m_scrollableArea->userInputScrollable(HorizontalScrollbar); bool canScrollY = m_scrollableArea->userInputScrollable(VerticalScrollbar); // Accept the event if we are scrollable in that direction and can still // scroll any further. float deltaX = canScrollX ? e.deltaX() : 0; float deltaY = canScrollY ? e.deltaY() : 0; bool handled = false; #if !OS(MACOSX) ScrollGranularity granularity = e.hasPreciseScrollingDeltas() ? ScrollByPrecisePixel : ScrollByPixel; #else ScrollGranularity granularity = ScrollByPixel; #endif IntSize maxForwardScrollDelta = m_scrollableArea->maximumScrollPosition() - m_scrollableArea->scrollPosition(); IntSize maxBackwardScrollDelta = m_scrollableArea->scrollPosition() - m_scrollableArea->minimumScrollPosition(); if ((deltaX < 0 && maxForwardScrollDelta.width() > 0) || (deltaX > 0 && maxBackwardScrollDelta.width() > 0) || (deltaY < 0 && maxForwardScrollDelta.height() > 0) || (deltaY > 0 && maxBackwardScrollDelta.height() > 0)) { handled = true; if (deltaY) { if (e.granularity() == ScrollByPageWheelEvent) { bool negative = deltaY < 0; deltaY = m_scrollableArea->pageStep(VerticalScrollbar); if (negative) deltaY = -deltaY; } scroll(VerticalScrollbar, granularity, m_scrollableArea->pixelStep(VerticalScrollbar), -deltaY); } if (deltaX) { if (e.granularity() == ScrollByPageWheelEvent) { bool negative = deltaX < 0; deltaX = m_scrollableArea->pageStep(HorizontalScrollbar); if (negative) deltaX = -deltaX; } scroll(HorizontalScrollbar, granularity, m_scrollableArea->pixelStep(HorizontalScrollbar), -deltaX); } } return handled; }
bool ScrollAnimator::handleWheelEvent(const PlatformWheelEvent& e) { Scrollbar* horizontalScrollbar = m_scrollableArea->horizontalScrollbar(); Scrollbar* verticalScrollbar = m_scrollableArea->verticalScrollbar(); // Accept the event if we have a scrollbar in that direction and can still // scroll any further. float deltaX = horizontalScrollbar ? e.deltaX() : 0; float deltaY = verticalScrollbar ? e.deltaY() : 0; bool handled = false; #if PLATFORM(CHROMIUM) && !OS(DARWIN) ScrollGranularity granularity = e.hasPreciseScrollingDeltas() ? ScrollByPrecisePixel : ScrollByPixel; #else ScrollGranularity granularity = ScrollByPixel; #endif IntSize maxForwardScrollDelta = m_scrollableArea->maximumScrollPosition() - m_scrollableArea->scrollPosition(); IntSize maxBackwardScrollDelta = m_scrollableArea->scrollPosition() - m_scrollableArea->minimumScrollPosition(); if ((deltaX < 0 && maxForwardScrollDelta.width() > 0) || (deltaX > 0 && maxBackwardScrollDelta.width() > 0) || (deltaY < 0 && maxForwardScrollDelta.height() > 0) || (deltaY > 0 && maxBackwardScrollDelta.height() > 0)) { handled = true; if (deltaY) { if (e.granularity() == ScrollByPageWheelEvent) { bool negative = deltaY < 0; deltaY = max(max(static_cast<float>(m_scrollableArea->visibleHeight()) * Scrollbar::minFractionToStepWhenPaging(), static_cast<float>(m_scrollableArea->visibleHeight() - Scrollbar::maxOverlapBetweenPages())), 1.0f); if (negative) deltaY = -deltaY; } scroll(VerticalScrollbar, granularity, verticalScrollbar->pixelStep(), -deltaY); } if (deltaX) { if (e.granularity() == ScrollByPageWheelEvent) { bool negative = deltaX < 0; deltaX = max(max(static_cast<float>(m_scrollableArea->visibleWidth()) * Scrollbar::minFractionToStepWhenPaging(), static_cast<float>(m_scrollableArea->visibleWidth() - Scrollbar::maxOverlapBetweenPages())), 1.0f); if (negative) deltaX = -deltaX; } scroll(HorizontalScrollbar, granularity, horizontalScrollbar->pixelStep(), -deltaX); } } return handled; }
bool ScrollingTree::willWheelEventStartSwipeGesture(const PlatformWheelEvent& wheelEvent) { if (wheelEvent.phase() != PlatformWheelEventPhaseBegan) return false; if (!wheelEvent.deltaX()) return false; MutexLocker lock(m_swipeStateMutex); if (wheelEvent.deltaX() > 0 && m_mainFramePinnedToTheLeft && m_canGoBack) return true; if (wheelEvent.deltaX() < 0 && m_mainFramePinnedToTheRight && m_canGoForward) return true; return false; }
// GTK+ must scroll horizontally if the mouse pointer is on top of the // horizontal scrollbar while scrolling with the wheel; we need to // add the deltas and ticks here so that this behavior is consistent // for styled scrollbars. bool EventHandler::shouldTurnVerticalTicksIntoHorizontal(const HitTestResult& result, const PlatformWheelEvent& event) const { FrameView* view = m_frame.view(); Scrollbar* scrollbar = view ? view->scrollbarAtPoint(event.position()) : nullptr; if (!scrollbar) scrollbar = result.scrollbar(); return scrollbar && scrollbar->orientation() == HorizontalScrollbar; }
bool ScrollingTree::willWheelEventStartSwipeGesture(const PlatformWheelEvent& wheelEvent) { if (wheelEvent.phase() != PlatformWheelEventPhaseBegan) return false; MutexLocker lock(m_swipeStateMutex); if (wheelEvent.deltaX() > 0 && m_mainFramePinnedToTheLeft && !m_rubberBandsAtLeft) return true; if (wheelEvent.deltaX() < 0 && m_mainFramePinnedToTheRight && !m_rubberBandsAtRight) return true; if (wheelEvent.deltaY() > 0 && m_mainFramePinnedToTheTop && !m_rubberBandsAtTop) return true; if (wheelEvent.deltaY() < 0 && m_mainFramePinnedToTheBottom && !m_rubberBandsAtBottom) return true; return false; }
ScrollResult ScrollableArea::handleWheel(const PlatformWheelEvent& wheelEvent) { // Wheel events which do not scroll are used to trigger zooming. if (!wheelEvent.canScroll()) return ScrollResult(); cancelProgrammaticScrollAnimation(); return scrollAnimator()->handleWheelEvent(wheelEvent); }
bool ScrollableArea::handleWheelEvent(const PlatformWheelEvent& wheelEvent) { // ctrl+wheel events are used to trigger zooming, not scrolling. if (wheelEvent.modifiers() & PlatformEvent::CtrlKey) return false; cancelProgrammaticScrollAnimation(); return scrollAnimator()->handleWheelEvent(wheelEvent); }
bool PopupListBox::handleWheelEvent(const PlatformWheelEvent& event) { if (!isPointInBounds(event.position())) { abandon(); return true; } ScrollableArea::handleWheelEvent(event); return true; }
void ScrollView::wheelEvent(PlatformWheelEvent& e) { // We don't allow mouse wheeling to happen in a ScrollView that has had its scrollbars explicitly disabled. #if PLATFORM(WX) if (!canHaveScrollbars()) { #else if (!canHaveScrollbars() || platformWidget()) { #endif return; } // Determine how much we want to scroll. If we can move at all, we will accept the event. IntSize maxScrollDelta = maximumScrollPosition() - scrollPosition(); if ((e.deltaX() < 0 && maxScrollDelta.width() > 0) || (e.deltaX() > 0 && scrollOffset().width() > 0) || (e.deltaY() < 0 && maxScrollDelta.height() > 0) || (e.deltaY() > 0 && scrollOffset().height() > 0)) { e.accept(); float deltaX = e.deltaX(); float deltaY = e.deltaY(); if (e.granularity() == ScrollByPageWheelEvent) { ASSERT(deltaX == 0); bool negative = deltaY < 0; deltaY = max(max(static_cast<float>(visibleHeight()) * Scrollbar::minFractionToStepWhenPaging(), static_cast<float>(visibleHeight() - Scrollbar::maxOverlapBetweenPages())), 1.0f); if (negative) deltaY = -deltaY; } // Should we fall back on scrollBy() if there is no scrollbar for a non-zero delta? if (deltaY && m_verticalScrollbar) m_verticalScrollbar->scroll(ScrollUp, ScrollByPixel, deltaY); if (deltaX && m_horizontalScrollbar) m_horizontalScrollbar->scroll(ScrollLeft, ScrollByPixel, deltaX); } } void ScrollView::setFrameRect(const IntRect& newRect) { IntRect oldRect = frameRect(); if (newRect == oldRect) return; Widget::setFrameRect(newRect); if (platformWidget()) return; if (newRect.width() != oldRect.width() || newRect.height() != oldRect.height()) { updateScrollbars(m_scrollOffset); if (!m_useFixedLayout) contentsResized(); } frameRectsChanged(); }
void EventDispatcher::wheelEvent(uint64_t pageID, const WebWheelEvent& wheelEvent, bool canRubberBandAtLeft, bool canRubberBandAtRight, bool canRubberBandAtTop, bool canRubberBandAtBottom) { PlatformWheelEvent platformWheelEvent = platform(wheelEvent); #if PLATFORM(COCOA) switch (wheelEvent.phase()) { case PlatformWheelEventPhaseBegan: m_recentWheelEventDeltaTracker->beginTrackingDeltas(); break; case PlatformWheelEventPhaseEnded: m_recentWheelEventDeltaTracker->endTrackingDeltas(); break; default: break; } if (m_recentWheelEventDeltaTracker->isTrackingDeltas()) { m_recentWheelEventDeltaTracker->recordWheelEventDelta(platformWheelEvent); DominantScrollGestureDirection dominantDirection = DominantScrollGestureDirection::None; dominantDirection = m_recentWheelEventDeltaTracker->dominantScrollGestureDirection(); // Workaround for scrolling issues <rdar://problem/14758615>. if (dominantDirection == DominantScrollGestureDirection::Vertical && platformWheelEvent.deltaX()) platformWheelEvent = platformWheelEvent.copyIgnoringHorizontalDelta(); else if (dominantDirection == DominantScrollGestureDirection::Horizontal && platformWheelEvent.deltaY()) platformWheelEvent = platformWheelEvent.copyIgnoringVerticalDelta(); } #endif #if ENABLE(ASYNC_SCROLLING) MutexLocker locker(m_scrollingTreesMutex); if (ThreadedScrollingTree* scrollingTree = m_scrollingTrees.get(pageID)) { // FIXME: It's pretty horrible that we're updating the back/forward state here. // WebCore should always know the current state and know when it changes so the // scrolling tree can be notified. // We only need to do this at the beginning of the gesture. if (platformWheelEvent.phase() == PlatformWheelEventPhaseBegan) ScrollingThread::dispatch(bind(&ThreadedScrollingTree::setCanRubberBandState, scrollingTree, canRubberBandAtLeft, canRubberBandAtRight, canRubberBandAtTop, canRubberBandAtBottom)); ScrollingTree::EventResult result = scrollingTree->tryToHandleWheelEvent(platformWheelEvent); if (result == ScrollingTree::DidHandleEvent || result == ScrollingTree::DidNotHandleEvent) { sendDidReceiveEvent(pageID, wheelEvent, result == ScrollingTree::DidHandleEvent); return; } } #else UNUSED_PARAM(canRubberBandAtLeft); UNUSED_PARAM(canRubberBandAtRight); UNUSED_PARAM(canRubberBandAtTop); UNUSED_PARAM(canRubberBandAtBottom); #endif RunLoop::main().dispatch(bind(&EventDispatcher::dispatchWheelEvent, this, pageID, wheelEvent)); }
void ScrollView::wheelEvent(PlatformWheelEvent& e) { // We don't allow mouse wheeling to happen in a ScrollView that has had its scrollbars explicitly disabled. #if PLATFORM(WX) if (!canHaveScrollbars()) { #else if (!canHaveScrollbars() || platformWidget()) { #endif return; } // Determine how much we want to scroll. If we can move at all, we will accept the event. IntSize maxScrollDelta = maximumScrollPosition() - scrollPosition(); if ((e.deltaX() < 0 && maxScrollDelta.width() > 0) || (e.deltaX() > 0 && scrollOffset().width() > 0) || (e.deltaY() < 0 && maxScrollDelta.height() > 0) || (e.deltaY() > 0 && scrollOffset().height() > 0)) { e.accept(); float deltaX = e.deltaX(); float deltaY = e.deltaY(); if (e.granularity() == ScrollByPageWheelEvent) { ASSERT(deltaX == 0); bool negative = deltaY < 0; deltaY = max(max<int>(visibleHeight() * Scrollbar::minFractionToStepWhenPaging(), visibleHeight() - Scrollbar::maxOverlapBetweenPages()), 1); if (negative) deltaY = -deltaY; } scrollBy(IntSize(-deltaX, -deltaY)); } } void ScrollView::setFrameRect(const IntRect& newRect) { IntRect oldRect = frameRect(); if (newRect == oldRect) return; Widget::setFrameRect(newRect); if (platformWidget()) return; if (newRect.width() != oldRect.width() || newRect.height() != oldRect.height()) { updateScrollbars(m_scrollOffset); contentsResized(); } frameRectsChanged(); }
ScrollingTree::EventResult ScrollingTree::tryToHandleWheelEvent(const PlatformWheelEvent& wheelEvent) { { MutexLocker lock(m_mutex); if (m_hasWheelEventHandlers) return SendToMainThread; if (!m_nonFastScrollableRegion.isEmpty()) { // FIXME: This is not correct for non-default scroll origins. IntPoint position = wheelEvent.position(); position.moveBy(m_mainFrameScrollPosition); if (m_nonFastScrollableRegion.contains(position)) return SendToMainThread; } } if (willWheelEventStartSwipeGesture(wheelEvent)) return DidNotHandleEvent; ScrollingThread::dispatch(bind(&ScrollingTree::handleWheelEvent, this, wheelEvent)); return DidHandleEvent; }
ScrollResult RootFrameViewport::handleWheel(const PlatformWheelEvent& event) { updateScrollAnimator(); ScrollableArea& primary = !m_invertScrollOrder ? layoutViewport() : visualViewport(); ScrollableArea& secondary = !m_invertScrollOrder ? visualViewport() : layoutViewport(); ScrollResult viewScrollResult = primary.handleWheel(event); // The visual viewport will only accept pixel scrolls. if (!event.canScroll() || event.granularity() == ScrollByPageWheelEvent) return viewScrollResult; // TODO(sataya.m) : The delta in PlatformWheelEvent is negative when scrolling the // wheel towards the user, so negate it to get the scroll delta that should be applied // to the page. unusedScrollDelta computed in the ScrollResult is also negative. Say // there is WheelEvent({0, -10} and page scroll by 2px and unusedScrollDelta computed // is {0, -8}. Due to which we have to negate the unusedScrollDelta to obtain the expected // animation.Please address http://crbug.com/504389. DoublePoint oldOffset = secondary.scrollPositionDouble(); DoublePoint locationDelta; if (viewScrollResult.didScroll()) { locationDelta = -DoublePoint(viewScrollResult.unusedScrollDeltaX, viewScrollResult.unusedScrollDeltaY); } else { if (event.railsMode() != PlatformEvent::RailsModeVertical) locationDelta.setX(-event.deltaX()); if (event.railsMode() != PlatformEvent::RailsModeHorizontal) locationDelta.setY(-event.deltaY()); } DoublePoint targetPosition = secondary.clampScrollPosition( secondary.scrollPositionDouble() + toDoubleSize(locationDelta)); secondary.setScrollPosition(targetPosition, UserScroll); DoublePoint usedLocationDelta(secondary.scrollPositionDouble() - oldOffset); bool didScrollX = viewScrollResult.didScrollX || usedLocationDelta.x(); bool didScrollY = viewScrollResult.didScrollY || usedLocationDelta.y(); return ScrollResult(didScrollX, didScrollY, -viewScrollResult.unusedScrollDeltaX - usedLocationDelta.x(), -viewScrollResult.unusedScrollDeltaY - usedLocationDelta.y()); }
WheelEventDispatchMediator::WheelEventDispatchMediator(const PlatformWheelEvent& event, PassRefPtr<AbstractView> view) { if (!(event.deltaX() || event.deltaY())) return; setEvent(WheelEvent::create(FloatPoint(event.wheelTicksX(), event.wheelTicksY()), FloatPoint(event.deltaX(), event.deltaY()), deltaMode(event), view, event.globalPosition(), event.position(), event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), event.directionInvertedFromDevice())); }
inline static unsigned deltaMode(const PlatformWheelEvent& event) { return event.granularity() == ScrollByPageWheelEvent ? WheelEvent::DOM_DELTA_PAGE : WheelEvent::DOM_DELTA_PIXEL; }
void EventTargetNode::dispatchWheelEvent(PlatformWheelEvent& e) { ASSERT(!eventDispatchForbidden()); if (e.deltaX() == 0 && e.deltaY() == 0) return; FrameView* view = document()->view(); if (!view) return; IntPoint pos = view->windowToContents(e.pos()); // Convert the deltas from pixels to lines if we have a pixel scroll event. float deltaX = e.deltaX(); float deltaY = e.deltaY(); // FIXME: Should we do anything with a ScrollByPageWheelEvent here? // It will be treated like a line scroll of 1 right now. if (e.granularity() == ScrollByPixelWheelEvent) { deltaX /= cMouseWheelPixelsPerLineStep; deltaY /= cMouseWheelPixelsPerLineStep; } RefPtr<WheelEvent> we = WheelEvent::create(e.deltaX(), e.deltaY(), document()->defaultView(), e.globalX(), e.globalY(), pos.x(), pos.y(), e.ctrlKey(), e.altKey(), e.shiftKey(), e.metaKey()); ExceptionCode ec = 0; if (!dispatchEvent(we.release(), ec)) e.accept(); }
inline static WheelEvent::Granularity granularity(const PlatformWheelEvent& event) { return event.granularity() == ScrollByPageWheelEvent ? WheelEvent::Page : WheelEvent::Pixel; }
PassRefPtrWillBeRawPtr<WheelEvent> WheelEvent::create(const PlatformWheelEvent& event, PassRefPtrWillBeRawPtr<AbstractView> view) { return adoptRefWillBeNoop(new WheelEvent(FloatPoint(event.wheelTicksX(), event.wheelTicksY()), FloatPoint(event.deltaX(), event.deltaY()), convertDeltaMode(event), view, event.globalPosition(), event.position(), event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), MouseEvent::platformModifiersToButtons(event.modifiers()), event.canScroll(), event.hasPreciseScrollingDeltas(), static_cast<Event::RailsMode>(event.railsMode()))); }
void EventTargetNode::dispatchWheelEvent(PlatformWheelEvent& e) { assert(!eventDispatchForbidden()); if (e.delta() == 0) return; FrameView* view = document()->view(); if (!view) return; IntPoint pos = view->viewportToContents(e.pos()); RefPtr<WheelEvent> we = new WheelEvent(e.isHorizontal(), e.delta(), document()->defaultView(), e.globalX(), e.globalY(), pos.x(), pos.y(), e.ctrlKey(), e.altKey(), e.shiftKey(), e.metaKey()); ExceptionCode ec = 0; if (!dispatchEvent(we, ec, true)) e.accept(); }
void EventTargetNode::dispatchWheelEvent(PlatformWheelEvent& e) { ASSERT(!eventDispatchForbidden()); if (e.deltaX() == 0 && e.deltaY() == 0) return; FrameView* view = document()->view(); if (!view) return; IntPoint pos = view->windowToContents(e.pos()); RefPtr<WheelEvent> we = WheelEvent::create(e.deltaX(), e.deltaY(), document()->defaultView(), e.globalX(), e.globalY(), pos.x(), pos.y(), e.ctrlKey(), e.altKey(), e.shiftKey(), e.metaKey()); ExceptionCode ec = 0; if (!dispatchEvent(we.release(), ec, true)) e.accept(); }