Changeset 156397 in webkit


Ignore:
Timestamp:
Sep 25, 2013 8:40:58 AM (11 years ago)
Author:
akling@apple.com
Message:

Move wheel event dispatch from Node to Element.
<https://webkit.org/b/121908>

Reviewed by Anders Carlsson.

Wheel events are only ever dispatched on Elements, so move the logic out of Node.

Had to make RenderBox::scroll() and friends return a stopElement instead of a
stopNode (out argument) to make this work, though it was only ever returning
Elements there anyway.

Location:
trunk/Source/WebCore
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r156394 r156397  
     12013-09-25  Andreas Kling  <akling@apple.com>
     2
     3        Move wheel event dispatch from Node to Element.
     4        <https://webkit.org/b/121908>
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Wheel events are only ever dispatched on Elements, so move the logic out of Node.
     9
     10        Had to make RenderBox::scroll() and friends return a stopElement instead of a
     11        stopNode (out argument) to make this work, though it was only ever returning
     12        Elements there anyway.
     13
    1142013-09-25  Allan Sandfeld Jensen  <allan.jensen@digia.com>
    215
  • trunk/Source/WebCore/dom/Element.cpp

    r156372 r156397  
    8787#include "TextIterator.h"
    8888#include "VoidCallback.h"
     89#include "WheelEvent.h"
    8990#include "XMLNSNames.h"
    9091#include "XMLNames.h"
     
    238239{
    239240    return isContentEditable(UserSelectAllIsAlwaysNonEditable);
     241}
     242
     243bool Element::dispatchWheelEvent(const PlatformWheelEvent& event)
     244{
     245    return EventDispatcher::dispatchEvent(this, WheelEventDispatchMediator::create(event, document().defaultView()));
    240246}
    241247
     
    584590        units = -units;
    585591    }
    586     Node* stopNode = this;
    587     toRenderBox(renderer())->scroll(direction, granularity, units, &stopNode);
     592    Element* stopElement = this;
     593    toRenderBox(renderer())->scroll(direction, granularity, units, &stopElement);
    588594}
    589595
  • trunk/Source/WebCore/dom/Element.h

    r156372 r156397  
    4444class IntSize;
    4545class Locale;
     46class PlatformWheelEvent;
    4647class PseudoElement;
    4748class RenderElement;
     
    535536    void setSavedLayerScrollOffset(const IntSize&);
    536537
     538    bool dispatchWheelEvent(const PlatformWheelEvent&);
    537539    bool dispatchKeyEvent(const PlatformKeyboardEvent&);
    538540    void dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions = SendNoEvents, SimulatedClickVisualOptions = ShowPressedLook);
  • trunk/Source/WebCore/dom/Node.cpp

    r156372 r156397  
    21522152}
    21532153
    2154 bool Node::dispatchWheelEvent(const PlatformWheelEvent& event)
    2155 {
    2156     return EventDispatcher::dispatchEvent(this, WheelEventDispatchMediator::create(event, document().defaultView()));
    2157 }
    2158 
    21592154void Node::dispatchInputEvent()
    21602155{
  • trunk/Source/WebCore/dom/Node.h

    r156372 r156397  
    7373class PlatformKeyboardEvent;
    7474class PlatformMouseEvent;
    75 class PlatformWheelEvent;
    7675class QualifiedName;
    7776class RadioNodeList;
     
    550549    bool dispatchDOMActivateEvent(int detail, PassRefPtr<Event> underlyingEvent);
    551550
    552     bool dispatchWheelEvent(const PlatformWheelEvent&);
    553551    bool dispatchMouseEvent(const PlatformMouseEvent&, const AtomicString& eventType, int clickCount = 0, Node* relatedTarget = 0);
    554552#if ENABLE(GESTURE_EVENTS)
  • trunk/Source/WebCore/page/EventHandler.cpp

    r156390 r156397  
    273273}
    274274
    275 static inline bool scrollNode(float delta, ScrollGranularity granularity, ScrollDirection positiveDirection, ScrollDirection negativeDirection, Node* node, Node** stopNode)
     275static inline bool scrollNode(float delta, ScrollGranularity granularity, ScrollDirection positiveDirection, ScrollDirection negativeDirection, Node* node, Element** stopElement)
    276276{
    277277    if (!delta)
     
    281281    RenderBox* enclosingBox = node->renderer()->enclosingBox();
    282282    float absDelta = delta > 0 ? delta : -delta;
    283     return enclosingBox->scroll(delta < 0 ? negativeDirection : positiveDirection, granularity, absDelta, stopNode);
     283    return enclosingBox->scroll(delta < 0 ? negativeDirection : positiveDirection, granularity, absDelta, stopElement);
    284284}
    285285
     
    406406    m_capturesDragging = false;
    407407    m_capturingMouseEventsNode = 0;
    408     m_latchedWheelEventNode = 0;
    409     m_previousWheelScrolledNode = 0;
     408    m_latchedWheelEventElement = nullptr;
     409    m_previousWheelScrolledElement = nullptr;
    410410#if ENABLE(TOUCH_EVENTS)
    411411    m_originatingTouchPointTargets.clear();
     
    416416    m_scrollGestureHandlingNode = 0;
    417417    m_lastHitTestResultOverWidget = false;
    418     m_previousGestureScrolledNode = 0;
     418    m_previousGestureScrolledElement = nullptr;
    419419    m_scrollbarHandlingScrollGesture = 0;
    420420#endif
     
    24772477    doc->renderView()->hitTest(request, result);
    24782478
    2479     bool useLatchedWheelEventNode = e.useLatchedEventNode();
    2480 
    2481     // FIXME: This code should use Element* instead of Node*.
    2482     Node* node = result.innerElement();
     2479    bool useLatchedWheelEventElement = e.useLatchedEventElement();
     2480
     2481    Element* element = result.innerElement();
    24832482
    24842483    bool isOverWidget;
    2485     if (useLatchedWheelEventNode) {
    2486         if (!m_latchedWheelEventNode) {
    2487             m_latchedWheelEventNode = node;
     2484    if (useLatchedWheelEventElement) {
     2485        if (!m_latchedWheelEventElement) {
     2486            m_latchedWheelEventElement = element;
    24882487            m_widgetIsLatched = result.isOverWidget();
    24892488        } else
    2490             node = m_latchedWheelEventNode.get();
     2489            element = m_latchedWheelEventElement.get();
    24912490
    24922491        isOverWidget = m_widgetIsLatched;
    24932492    } else {
    2494         if (m_latchedWheelEventNode)
    2495             m_latchedWheelEventNode = 0;
    2496         if (m_previousWheelScrolledNode)
    2497             m_previousWheelScrolledNode = 0;
     2493        if (m_latchedWheelEventElement)
     2494            m_latchedWheelEventElement = nullptr;
     2495        if (m_previousWheelScrolledElement)
     2496            m_previousWheelScrolledElement = nullptr;
    24982497
    24992498        isOverWidget = result.isOverWidget();
     
    25232522    recordWheelEventDelta(event);
    25242523
    2525     if (node) {
     2524    if (element) {
    25262525        // Figure out which view to send the event to.
    2527         RenderObject* target = node->renderer();
     2526        RenderElement* target = element->renderer();
    25282527       
    25292528        if (isOverWidget && target && target->isWidget()) {
     
    25352534        }
    25362535
    2537         if (node && !node->dispatchWheelEvent(event)) {
     2536        if (!element->dispatchWheelEvent(event)) {
    25382537            m_isHandlingWheelEvent = false;
    25392538            return true;
     
    25542553        return;
    25552554   
    2556     Node* stopNode = m_previousWheelScrolledNode.get();
     2555    Element* stopElement = m_previousWheelScrolledElement.get();
    25572556    ScrollGranularity granularity = wheelGranularityToScrollGranularity(wheelEvent->deltaMode());
    25582557   
     
    25642563    // Break up into two scrolls if we need to.  Diagonal movement on
    25652564    // a MacBook pro is an example of a 2-dimensional mouse wheel event (where both deltaX and deltaY can be set).
    2566     if (dominantDirection != DominantScrollDirectionVertical && scrollNode(wheelEvent->deltaX(), granularity, ScrollRight, ScrollLeft, startNode, &stopNode))
     2565    if (dominantDirection != DominantScrollDirectionVertical && scrollNode(wheelEvent->deltaX(), granularity, ScrollRight, ScrollLeft, startNode, &stopElement))
    25672566        wheelEvent->setDefaultHandled();
    25682567   
    2569     if (dominantDirection != DominantScrollDirectionHorizontal && scrollNode(wheelEvent->deltaY(), granularity, ScrollDown, ScrollUp, startNode, &stopNode))
     2568    if (dominantDirection != DominantScrollDirectionHorizontal && scrollNode(wheelEvent->deltaY(), granularity, ScrollDown, ScrollUp, startNode, &stopElement))
    25702569        wheelEvent->setDefaultHandled();
    25712570   
    2572     if (!m_latchedWheelEventNode)
    2573         m_previousWheelScrolledNode = stopNode;
     2571    if (!m_latchedWheelEventElement)
     2572        m_previousWheelScrolledElement = stopElement;
    25742573}
    25752574
     
    28092808    m_lastHitTestResultOverWidget = result.isOverWidget();
    28102809    m_scrollGestureHandlingNode = result.innerNode();
    2811     m_previousGestureScrolledNode = 0;
     2810    m_previousGestureScrolledElement = nullptr;
    28122811
    28132812    Node* node = m_scrollGestureHandlingNode.get();
     
    28422841        return true;
    28432842
    2844     Node* stopNode = 0;
     2843    Element* stopElement = 0;
    28452844    bool scrollShouldNotPropagate = gestureEvent.type() == PlatformEvent::GestureScrollUpdateWithoutPropagation;
    28462845    if (scrollShouldNotPropagate)
    2847         stopNode = m_previousGestureScrolledNode.get();
     2846        stopElement = m_previousGestureScrolledElement.get();
    28482847
    28492848    // First try to scroll the closest scrollable RenderBox ancestor of |node|.
    28502849    ScrollGranularity granularity = ScrollByPixel;
    2851     bool horizontalScroll = scrollNode(delta.width(), granularity, ScrollLeft, ScrollRight, node, &stopNode);
    2852     bool verticalScroll = scrollNode(delta.height(), granularity, ScrollUp, ScrollDown, node, &stopNode);
     2850    bool horizontalScroll = scrollNode(delta.width(), granularity, ScrollLeft, ScrollRight, node, &stopElement);
     2851    bool verticalScroll = scrollNode(delta.height(), granularity, ScrollUp, ScrollDown, node, &stopElement);
    28532852
    28542853    if (scrollShouldNotPropagate)
    2855         m_previousGestureScrolledNode = stopNode;
     2854        m_previousGestureScrolledElement = stopElement;
    28562855
    28572856    if (horizontalScroll || verticalScroll) {
     
    28922891{
    28932892    m_scrollGestureHandlingNode = 0;
    2894     m_previousGestureScrolledNode = 0;
     2893    m_previousGestureScrolledElement = nullptr;
    28952894}
    28962895
  • trunk/Source/WebCore/page/EventHandler.h

    r155548 r156397  
    477477
    478478    Deque<FloatSize> m_recentWheelEventDeltas;
    479     RefPtr<Node> m_latchedWheelEventNode;
     479    RefPtr<Element> m_latchedWheelEventElement;
    480480    bool m_inTrackingScrollGesturePhase;
    481481    bool m_widgetIsLatched;
    482482
    483     RefPtr<Node> m_previousWheelScrolledNode;
     483    RefPtr<Element> m_previousWheelScrolledElement;
    484484
    485485#if PLATFORM(MAC)
     
    499499    RefPtr<Node> m_scrollGestureHandlingNode;
    500500    bool m_lastHitTestResultOverWidget;
    501     RefPtr<Node> m_previousGestureScrolledNode;
     501    RefPtr<Element> m_previousGestureScrolledElement;
    502502    RefPtr<Scrollbar> m_scrollbarHandlingScrollGesture;
    503503#endif
  • trunk/Source/WebCore/platform/PlatformWheelEvent.h

    r153483 r156397  
    149149        float unacceleratedScrollingDeltaX() const { return m_unacceleratedScrollingDeltaX; }
    150150        float unacceleratedScrollingDeltaY() const { return m_unacceleratedScrollingDeltaY; }
    151         bool useLatchedEventNode() const { return m_momentumPhase == PlatformWheelEventPhaseBegan || m_momentumPhase == PlatformWheelEventPhaseChanged; }
     151        bool useLatchedEventElement() const { return m_momentumPhase == PlatformWheelEventPhaseBegan || m_momentumPhase == PlatformWheelEventPhaseChanged; }
    152152#else
    153         bool useLatchedEventNode() const { return false; }
     153        bool useLatchedEventElement() const { return false; }
    154154#endif
    155155
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r156310 r156397  
    747747}
    748748
    749 bool RenderBox::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier, Node** stopNode)
     749bool RenderBox::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier, Element** stopElement)
    750750{
    751751    RenderLayer* l = layer();
    752752    if (l && l->scroll(direction, granularity, multiplier)) {
    753         if (stopNode)
    754             *stopNode = element();
     753        if (stopElement)
     754            *stopElement = element();
    755755        return true;
    756756    }
    757757
    758     if (stopNode && *stopNode && *stopNode == element())
     758    if (stopElement && *stopElement && *stopElement == element())
    759759        return true;
    760760
    761761    RenderBlock* b = containingBlock();
    762762    if (b && !b->isRenderView())
    763         return b->scroll(direction, granularity, multiplier, stopNode);
     763        return b->scroll(direction, granularity, multiplier, stopElement);
    764764    return false;
    765765}
    766766
    767 bool RenderBox::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Node** stopNode)
     767bool RenderBox::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Element** stopElement)
    768768{
    769769    bool scrolled = false;
     
    780780       
    781781        if (scrolled) {
    782             if (stopNode)
    783                 *stopNode = element();
     782            if (stopElement)
     783                *stopElement = element();
    784784            return true;
    785785        }
    786786    }
    787787
    788     if (stopNode && *stopNode && *stopNode == element())
     788    if (stopElement && *stopElement && *stopElement == element())
    789789        return true;
    790790
    791791    RenderBlock* b = containingBlock();
    792792    if (b && !b->isRenderView())
    793         return b->logicalScroll(direction, granularity, multiplier, stopNode);
     793        return b->logicalScroll(direction, granularity, multiplier, stopElement);
    794794    return false;
    795795}
  • trunk/Source/WebCore/rendering/RenderBox.h

    r155374 r156397  
    448448    int instrinsicScrollbarLogicalWidth() const;
    449449    int scrollbarLogicalHeight() const { return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
    450     virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
    451     virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
     450    virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0);
     451    virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0);
    452452    bool canBeScrolledAndHasScrollableArea() const;
    453453    virtual bool canBeProgramaticallyScrolled() const;
  • trunk/Source/WebCore/rendering/RenderEmbeddedObject.cpp

    r156278 r156397  
    570570}
    571571
    572 bool RenderEmbeddedObject::scroll(ScrollDirection direction, ScrollGranularity granularity, float, Node**)
     572bool RenderEmbeddedObject::scroll(ScrollDirection direction, ScrollGranularity granularity, float, Element**)
    573573{
    574574    if (!widget() || !widget()->isPluginViewBase())
     
    578578}
    579579
    580 bool RenderEmbeddedObject::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Node** stopNode)
     580bool RenderEmbeddedObject::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Element** stopElement)
    581581{
    582582    // Plugins don't expose a writing direction, so assuming horizontal LTR.
    583     return scroll(logicalToPhysical(direction, true, false), granularity, multiplier, stopNode);
     583    return scroll(logicalToPhysical(direction, true, false), granularity, multiplier, stopElement);
    584584}
    585585
  • trunk/Source/WebCore/rendering/RenderEmbeddedObject.h

    r156278 r156397  
    9191    virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE FINAL;
    9292
    93     virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier, Node** stopNode) OVERRIDE FINAL;
    94     virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier, Node** stopNode) OVERRIDE FINAL;
     93    virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier, Element** stopElement) OVERRIDE FINAL;
     94    virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier, Element** stopElement) OVERRIDE FINAL;
    9595
    9696    void setUnavailablePluginIndicatorIsPressed(bool);
  • trunk/Source/WebCore/rendering/RenderListBox.cpp

    r156155 r156397  
    595595}
    596596
    597 bool RenderListBox::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier, Node**)
     597bool RenderListBox::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier, Element**)
    598598{
    599599    return ScrollableArea::scroll(direction, granularity, multiplier);
    600600}
    601601
    602 bool RenderListBox::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Node**)
     602bool RenderListBox::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Element**)
    603603{
    604604    return ScrollableArea::scroll(logicalToPhysical(direction, style()->isHorizontalWritingMode(), style()->isFlippedBlocksWritingMode()), granularity, multiplier);
  • trunk/Source/WebCore/rendering/RenderListBox.h

    r155669 r156397  
    7575    virtual bool isPointInOverflowControl(HitTestResult&, const LayoutPoint& locationInContainer, const LayoutPoint& accumulatedOffset);
    7676
    77     virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
    78     virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
     77    virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0) OVERRIDE;
     78    virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0) OVERRIDE;
    7979
    8080    virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE;
  • trunk/Source/WebCore/rendering/RenderTextControlSingleLine.cpp

    r156314 r156397  
    448448}
    449449
    450 bool RenderTextControlSingleLine::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier, Node** stopNode)
     450bool RenderTextControlSingleLine::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier, Element** stopElement)
    451451{
    452452    RenderBox* renderer = innerTextElement()->renderBox();
     
    456456    if (layer && layer->scroll(direction, granularity, multiplier))
    457457        return true;
    458     return RenderBlock::scroll(direction, granularity, multiplier, stopNode);
    459 }
    460 
    461 bool RenderTextControlSingleLine::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Node** stopNode)
     458    return RenderBlock::scroll(direction, granularity, multiplier, stopElement);
     459}
     460
     461bool RenderTextControlSingleLine::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Element** stopElement)
    462462{
    463463    RenderLayer* layer = innerTextElement()->renderBox()->layer();
    464464    if (layer && layer->scroll(logicalToPhysical(direction, style()->isHorizontalWritingMode(), style()->isFlippedBlocksWritingMode()), granularity, multiplier))
    465465        return true;
    466     return RenderBlock::logicalScroll(direction, granularity, multiplier, stopNode);
     466    return RenderBlock::logicalScroll(direction, granularity, multiplier, stopElement);
    467467}
    468468
  • trunk/Source/WebCore/rendering/RenderTextControlSingleLine.h

    r156314 r156397  
    6969    virtual void setScrollLeft(int) OVERRIDE;
    7070    virtual void setScrollTop(int) OVERRIDE;
    71     virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0) OVERRIDE;
    72     virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0) OVERRIDE;
     71    virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0) OVERRIDE FINAL;
     72    virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0) OVERRIDE FINAL;
    7373
    7474    int textBlockWidth() const;
Note: See TracChangeset for help on using the changeset viewer.