Commit ca895452 authored by akling@apple.com's avatar akling@apple.com

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.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156397 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 682b8c11
2013-09-25 Andreas Kling <akling@apple.com>
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.
2013-09-25 Allan Sandfeld Jensen <allan.jensen@digia.com>
[Qt] Fix build with !ENABLE(BLOB) after r156330
......@@ -86,6 +86,7 @@
#include "Text.h"
#include "TextIterator.h"
#include "VoidCallback.h"
#include "WheelEvent.h"
#include "XMLNSNames.h"
#include "XMLNames.h"
#include "htmlediting.h"
......@@ -239,6 +240,11 @@ bool Element::shouldUseInputMethod()
return isContentEditable(UserSelectAllIsAlwaysNonEditable);
}
bool Element::dispatchWheelEvent(const PlatformWheelEvent& event)
{
return EventDispatcher::dispatchEvent(this, WheelEventDispatchMediator::create(event, document().defaultView()));
}
bool Element::dispatchKeyEvent(const PlatformKeyboardEvent& event)
{
return EventDispatcher::dispatchEvent(this, KeyboardEventDispatchMediator::create(KeyboardEvent::create(event, document().defaultView())));
......@@ -583,8 +589,8 @@ void Element::scrollByUnits(int units, ScrollGranularity granularity)
direction = ScrollUp;
units = -units;
}
Node* stopNode = this;
toRenderBox(renderer())->scroll(direction, granularity, units, &stopNode);
Element* stopElement = this;
toRenderBox(renderer())->scroll(direction, granularity, units, &stopElement);
}
void Element::scrollByLines(int lines)
......
......@@ -43,6 +43,7 @@ class ElementRareData;
class HTMLDocument;
class IntSize;
class Locale;
class PlatformWheelEvent;
class PseudoElement;
class RenderElement;
class RenderRegion;
......@@ -534,6 +535,7 @@ public:
IntSize savedLayerScrollOffset() const;
void setSavedLayerScrollOffset(const IntSize&);
bool dispatchWheelEvent(const PlatformWheelEvent&);
bool dispatchKeyEvent(const PlatformKeyboardEvent&);
void dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions = SendNoEvents, SimulatedClickVisualOptions = ShowPressedLook);
void dispatchFocusInEvent(const AtomicString& eventType, PassRefPtr<Element> oldFocusedElement);
......
......@@ -2151,11 +2151,6 @@ bool Node::dispatchBeforeLoadEvent(const String& sourceURL)
return !beforeLoadEvent->defaultPrevented();
}
bool Node::dispatchWheelEvent(const PlatformWheelEvent& event)
{
return EventDispatcher::dispatchEvent(this, WheelEventDispatchMediator::create(event, document().defaultView()));
}
void Node::dispatchInputEvent()
{
dispatchScopedEvent(Event::create(eventNames().inputEvent, true, false));
......
......@@ -72,7 +72,6 @@ class NodeListsNodeData;
class NodeRareData;
class PlatformKeyboardEvent;
class PlatformMouseEvent;
class PlatformWheelEvent;
class QualifiedName;
class RadioNodeList;
class RegisteredEventListener;
......@@ -549,7 +548,6 @@ public:
void dispatchSubtreeModifiedEvent();
bool dispatchDOMActivateEvent(int detail, PassRefPtr<Event> underlyingEvent);
bool dispatchWheelEvent(const PlatformWheelEvent&);
bool dispatchMouseEvent(const PlatformMouseEvent&, const AtomicString& eventType, int clickCount = 0, Node* relatedTarget = 0);
#if ENABLE(GESTURE_EVENTS)
bool dispatchGestureEvent(const PlatformGestureEvent&);
......
......@@ -272,7 +272,7 @@ static inline ScrollGranularity wheelGranularityToScrollGranularity(unsigned del
}
}
static inline bool scrollNode(float delta, ScrollGranularity granularity, ScrollDirection positiveDirection, ScrollDirection negativeDirection, Node* node, Node** stopNode)
static inline bool scrollNode(float delta, ScrollGranularity granularity, ScrollDirection positiveDirection, ScrollDirection negativeDirection, Node* node, Element** stopElement)
{
if (!delta)
return false;
......@@ -280,7 +280,7 @@ static inline bool scrollNode(float delta, ScrollGranularity granularity, Scroll
return false;
RenderBox* enclosingBox = node->renderer()->enclosingBox();
float absDelta = delta > 0 ? delta : -delta;
return enclosingBox->scroll(delta < 0 ? negativeDirection : positiveDirection, granularity, absDelta, stopNode);
return enclosingBox->scroll(delta < 0 ? negativeDirection : positiveDirection, granularity, absDelta, stopElement);
}
static inline bool shouldGesturesTriggerActive()
......@@ -405,8 +405,8 @@ void EventHandler::clear()
m_mousePressed = false;
m_capturesDragging = false;
m_capturingMouseEventsNode = 0;
m_latchedWheelEventNode = 0;
m_previousWheelScrolledNode = 0;
m_latchedWheelEventElement = nullptr;
m_previousWheelScrolledElement = nullptr;
#if ENABLE(TOUCH_EVENTS)
m_originatingTouchPointTargets.clear();
m_originatingTouchPointDocument.clear();
......@@ -415,7 +415,7 @@ void EventHandler::clear()
#if ENABLE(GESTURE_EVENTS)
m_scrollGestureHandlingNode = 0;
m_lastHitTestResultOverWidget = false;
m_previousGestureScrolledNode = 0;
m_previousGestureScrolledElement = nullptr;
m_scrollbarHandlingScrollGesture = 0;
#endif
m_maxMouseMovedDuration = 0;
......@@ -2476,25 +2476,24 @@ bool EventHandler::handleWheelEvent(const PlatformWheelEvent& e)
HitTestResult result(vPoint);
doc->renderView()->hitTest(request, result);
bool useLatchedWheelEventNode = e.useLatchedEventNode();
bool useLatchedWheelEventElement = e.useLatchedEventElement();
// FIXME: This code should use Element* instead of Node*.
Node* node = result.innerElement();
Element* element = result.innerElement();
bool isOverWidget;
if (useLatchedWheelEventNode) {
if (!m_latchedWheelEventNode) {
m_latchedWheelEventNode = node;
if (useLatchedWheelEventElement) {
if (!m_latchedWheelEventElement) {
m_latchedWheelEventElement = element;
m_widgetIsLatched = result.isOverWidget();
} else
node = m_latchedWheelEventNode.get();
element = m_latchedWheelEventElement.get();
isOverWidget = m_widgetIsLatched;
} else {
if (m_latchedWheelEventNode)
m_latchedWheelEventNode = 0;
if (m_previousWheelScrolledNode)
m_previousWheelScrolledNode = 0;
if (m_latchedWheelEventElement)
m_latchedWheelEventElement = nullptr;
if (m_previousWheelScrolledElement)
m_previousWheelScrolledElement = nullptr;
isOverWidget = result.isOverWidget();
}
......@@ -2522,9 +2521,9 @@ bool EventHandler::handleWheelEvent(const PlatformWheelEvent& e)
recordWheelEventDelta(event);
if (node) {
if (element) {
// Figure out which view to send the event to.
RenderObject* target = node->renderer();
RenderElement* target = element->renderer();
if (isOverWidget && target && target->isWidget()) {
Widget* widget = toRenderWidget(target)->widget();
......@@ -2534,7 +2533,7 @@ bool EventHandler::handleWheelEvent(const PlatformWheelEvent& e)
}
}
if (node && !node->dispatchWheelEvent(event)) {
if (!element->dispatchWheelEvent(event)) {
m_isHandlingWheelEvent = false;
return true;
}
......@@ -2553,7 +2552,7 @@ void EventHandler::defaultWheelEventHandler(Node* startNode, WheelEvent* wheelEv
if (!startNode || !wheelEvent)
return;
Node* stopNode = m_previousWheelScrolledNode.get();
Element* stopElement = m_previousWheelScrolledElement.get();
ScrollGranularity granularity = wheelGranularityToScrollGranularity(wheelEvent->deltaMode());
DominantScrollGestureDirection dominantDirection = DominantScrollDirectionNone;
......@@ -2563,14 +2562,14 @@ void EventHandler::defaultWheelEventHandler(Node* startNode, WheelEvent* wheelEv
// 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).
if (dominantDirection != DominantScrollDirectionVertical && scrollNode(wheelEvent->deltaX(), granularity, ScrollRight, ScrollLeft, startNode, &stopNode))
if (dominantDirection != DominantScrollDirectionVertical && scrollNode(wheelEvent->deltaX(), granularity, ScrollRight, ScrollLeft, startNode, &stopElement))
wheelEvent->setDefaultHandled();
if (dominantDirection != DominantScrollDirectionHorizontal && scrollNode(wheelEvent->deltaY(), granularity, ScrollDown, ScrollUp, startNode, &stopNode))
if (dominantDirection != DominantScrollDirectionHorizontal && scrollNode(wheelEvent->deltaY(), granularity, ScrollDown, ScrollUp, startNode, &stopElement))
wheelEvent->setDefaultHandled();
if (!m_latchedWheelEventNode)
m_previousWheelScrolledNode = stopNode;
if (!m_latchedWheelEventElement)
m_previousWheelScrolledElement = stopElement;
}
#if ENABLE(GESTURE_EVENTS)
......@@ -2808,7 +2807,7 @@ bool EventHandler::handleGestureScrollBegin(const PlatformGestureEvent& gestureE
m_lastHitTestResultOverWidget = result.isOverWidget();
m_scrollGestureHandlingNode = result.innerNode();
m_previousGestureScrolledNode = 0;
m_previousGestureScrolledElement = nullptr;
Node* node = m_scrollGestureHandlingNode.get();
if (node)
......@@ -2841,18 +2840,18 @@ bool EventHandler::handleGestureScrollUpdate(const PlatformGestureEvent& gesture
if (passGestureEventToWidgetIfPossible(gestureEvent, renderer))
return true;
Node* stopNode = 0;
Element* stopElement = 0;
bool scrollShouldNotPropagate = gestureEvent.type() == PlatformEvent::GestureScrollUpdateWithoutPropagation;
if (scrollShouldNotPropagate)
stopNode = m_previousGestureScrolledNode.get();
stopElement = m_previousGestureScrolledElement.get();
// First try to scroll the closest scrollable RenderBox ancestor of |node|.
ScrollGranularity granularity = ScrollByPixel;
bool horizontalScroll = scrollNode(delta.width(), granularity, ScrollLeft, ScrollRight, node, &stopNode);
bool verticalScroll = scrollNode(delta.height(), granularity, ScrollUp, ScrollDown, node, &stopNode);
bool horizontalScroll = scrollNode(delta.width(), granularity, ScrollLeft, ScrollRight, node, &stopElement);
bool verticalScroll = scrollNode(delta.height(), granularity, ScrollUp, ScrollDown, node, &stopElement);
if (scrollShouldNotPropagate)
m_previousGestureScrolledNode = stopNode;
m_previousGestureScrolledElement = stopElement;
if (horizontalScroll || verticalScroll) {
setFrameWasScrolledByUser();
......@@ -2891,7 +2890,7 @@ bool EventHandler::sendScrollEventToView(const PlatformGestureEvent& gestureEven
void EventHandler::clearGestureScrollNodes()
{
m_scrollGestureHandlingNode = 0;
m_previousGestureScrolledNode = 0;
m_previousGestureScrolledElement = nullptr;
}
bool EventHandler::isScrollbarHandlingGestures() const
......
......@@ -476,11 +476,11 @@ private:
PlatformMouseEvent m_mouseDown;
Deque<FloatSize> m_recentWheelEventDeltas;
RefPtr<Node> m_latchedWheelEventNode;
RefPtr<Element> m_latchedWheelEventElement;
bool m_inTrackingScrollGesturePhase;
bool m_widgetIsLatched;
RefPtr<Node> m_previousWheelScrolledNode;
RefPtr<Element> m_previousWheelScrolledElement;
#if PLATFORM(MAC)
NSView *m_mouseDownView;
......@@ -498,7 +498,7 @@ private:
#if ENABLE(GESTURE_EVENTS)
RefPtr<Node> m_scrollGestureHandlingNode;
bool m_lastHitTestResultOverWidget;
RefPtr<Node> m_previousGestureScrolledNode;
RefPtr<Element> m_previousGestureScrolledElement;
RefPtr<Scrollbar> m_scrollbarHandlingScrollGesture;
#endif
......
......@@ -148,9 +148,9 @@ namespace WebCore {
unsigned scrollCount() const { return m_scrollCount; }
float unacceleratedScrollingDeltaX() const { return m_unacceleratedScrollingDeltaX; }
float unacceleratedScrollingDeltaY() const { return m_unacceleratedScrollingDeltaY; }
bool useLatchedEventNode() const { return m_momentumPhase == PlatformWheelEventPhaseBegan || m_momentumPhase == PlatformWheelEventPhaseChanged; }
bool useLatchedEventElement() const { return m_momentumPhase == PlatformWheelEventPhaseBegan || m_momentumPhase == PlatformWheelEventPhaseChanged; }
#else
bool useLatchedEventNode() const { return false; }
bool useLatchedEventElement() const { return false; }
#endif
#if PLATFORM(WIN)
......
......@@ -746,25 +746,25 @@ int RenderBox::instrinsicScrollbarLogicalWidth() const
return 0;
}
bool RenderBox::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier, Node** stopNode)
bool RenderBox::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier, Element** stopElement)
{
RenderLayer* l = layer();
if (l && l->scroll(direction, granularity, multiplier)) {
if (stopNode)
*stopNode = element();
if (stopElement)
*stopElement = element();
return true;
}
if (stopNode && *stopNode && *stopNode == element())
if (stopElement && *stopElement && *stopElement == element())
return true;
RenderBlock* b = containingBlock();
if (b && !b->isRenderView())
return b->scroll(direction, granularity, multiplier, stopNode);
return b->scroll(direction, granularity, multiplier, stopElement);
return false;
}
bool RenderBox::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Node** stopNode)
bool RenderBox::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Element** stopElement)
{
bool scrolled = false;
......@@ -779,18 +779,18 @@ bool RenderBox::logicalScroll(ScrollLogicalDirection direction, ScrollGranularit
scrolled = true;
if (scrolled) {
if (stopNode)
*stopNode = element();
if (stopElement)
*stopElement = element();
return true;
}
}
if (stopNode && *stopNode && *stopNode == element())
if (stopElement && *stopElement && *stopElement == element())
return true;
RenderBlock* b = containingBlock();
if (b && !b->isRenderView())
return b->logicalScroll(direction, granularity, multiplier, stopNode);
return b->logicalScroll(direction, granularity, multiplier, stopElement);
return false;
}
......
......@@ -447,8 +447,8 @@ public:
int horizontalScrollbarHeight() const;
int instrinsicScrollbarLogicalWidth() const;
int scrollbarLogicalHeight() const { return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0);
virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0);
bool canBeScrolledAndHasScrollableArea() const;
virtual bool canBeProgramaticallyScrolled() const;
virtual void autoscroll(const IntPoint&);
......
......@@ -569,7 +569,7 @@ bool RenderEmbeddedObject::nodeAtPoint(const HitTestRequest& request, HitTestRes
return true;
}
bool RenderEmbeddedObject::scroll(ScrollDirection direction, ScrollGranularity granularity, float, Node**)
bool RenderEmbeddedObject::scroll(ScrollDirection direction, ScrollGranularity granularity, float, Element**)
{
if (!widget() || !widget()->isPluginViewBase())
return false;
......@@ -577,10 +577,10 @@ bool RenderEmbeddedObject::scroll(ScrollDirection direction, ScrollGranularity g
return toPluginViewBase(widget())->scroll(direction, granularity);
}
bool RenderEmbeddedObject::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Node** stopNode)
bool RenderEmbeddedObject::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Element** stopElement)
{
// Plugins don't expose a writing direction, so assuming horizontal LTR.
return scroll(logicalToPhysical(direction, true, false), granularity, multiplier, stopNode);
return scroll(logicalToPhysical(direction, true, false), granularity, multiplier, stopElement);
}
......
......@@ -90,8 +90,8 @@ private:
virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE FINAL;
virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier, Node** stopNode) OVERRIDE FINAL;
virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier, Node** stopNode) OVERRIDE FINAL;
virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier, Element** stopElement) OVERRIDE FINAL;
virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier, Element** stopElement) OVERRIDE FINAL;
void setUnavailablePluginIndicatorIsPressed(bool);
bool isInUnavailablePluginIndicator(MouseEvent*) const;
......
......@@ -594,12 +594,12 @@ bool RenderListBox::listIndexIsVisible(int index)
return index >= m_indexOffset && index < m_indexOffset + numVisibleItems();
}
bool RenderListBox::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier, Node**)
bool RenderListBox::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier, Element**)
{
return ScrollableArea::scroll(direction, granularity, multiplier);
}
bool RenderListBox::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Node**)
bool RenderListBox::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Element**)
{
return ScrollableArea::scroll(logicalToPhysical(direction, style()->isHorizontalWritingMode(), style()->isFlippedBlocksWritingMode()), granularity, multiplier);
}
......
......@@ -74,8 +74,8 @@ private:
virtual bool isPointInOverflowControl(HitTestResult&, const LayoutPoint& locationInContainer, const LayoutPoint& accumulatedOffset);
virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0) OVERRIDE;
virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0) OVERRIDE;
virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE;
virtual void computePreferredLogicalWidths() OVERRIDE;
......
......@@ -447,7 +447,7 @@ void RenderTextControlSingleLine::setScrollTop(int newTop)
innerTextElement()->setScrollTop(newTop);
}
bool RenderTextControlSingleLine::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier, Node** stopNode)
bool RenderTextControlSingleLine::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier, Element** stopElement)
{
RenderBox* renderer = innerTextElement()->renderBox();
if (!renderer)
......@@ -455,15 +455,15 @@ bool RenderTextControlSingleLine::scroll(ScrollDirection direction, ScrollGranul
RenderLayer* layer = renderer->layer();
if (layer && layer->scroll(direction, granularity, multiplier))
return true;
return RenderBlock::scroll(direction, granularity, multiplier, stopNode);
return RenderBlock::scroll(direction, granularity, multiplier, stopElement);
}
bool RenderTextControlSingleLine::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Node** stopNode)
bool RenderTextControlSingleLine::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity, float multiplier, Element** stopElement)
{
RenderLayer* layer = innerTextElement()->renderBox()->layer();
if (layer && layer->scroll(logicalToPhysical(direction, style()->isHorizontalWritingMode(), style()->isFlippedBlocksWritingMode()), granularity, multiplier))
return true;
return RenderBlock::logicalScroll(direction, granularity, multiplier, stopNode);
return RenderBlock::logicalScroll(direction, granularity, multiplier, stopElement);
}
HTMLInputElement& RenderTextControlSingleLine::inputElement() const
......
......@@ -68,8 +68,8 @@ private:
virtual int scrollHeight() const OVERRIDE;
virtual void setScrollLeft(int) OVERRIDE;
virtual void setScrollTop(int) OVERRIDE;
virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0) OVERRIDE;
virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0) OVERRIDE;
virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0) OVERRIDE FINAL;
virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0) OVERRIDE FINAL;
int textBlockWidth() const;
virtual float getAvgCharWidth(AtomicString family) OVERRIDE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment