Clean up related to wheelEvent names
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 15 Mar 2015 22:47:08 +0000 (22:47 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 15 Mar 2015 22:47:08 +0000 (22:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142713

Reviewed by Anders Carlsson.

Add EventNames::isWheelEventType() and use it in places that test for the
two wheel event names.

Source/WebCore:

* dom/Document.cpp:
(WebCore::Document::didAddWheelEventHandler):
(WebCore::Document::didRemoveWheelEventHandler):
* dom/Document.h: No need for exports (I grepped). Pass the Node*, which
will be used in a later patch.
* dom/EventNames.h:
(WebCore::EventNames::isWheelEventType):
* dom/Node.cpp:
(WebCore::Node::didMoveToNewDocument):
(WebCore::tryAddEventListener):
(WebCore::tryRemoveEventListener):
(WebCore::Node::defaultEventHandler):
* html/shadow/MediaControlsApple.cpp:
(WebCore::MediaControlsAppleEventListener::handleEvent):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::addEventListener):
(WebCore::DOMWindow::removeEventListener):
* page/ios/FrameIOS.mm:
(WebCore::ancestorRespondingToScrollWheelEvents): Remove dead code.

Source/WebKit2:

* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::handleEvent):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181514 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/EventNames.h
Source/WebCore/dom/Node.cpp
Source/WebCore/history/CachedFrame.cpp
Source/WebCore/html/shadow/MediaControlsApple.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/ios/FrameIOS.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Plugins/PluginView.cpp

index 76b35ea..0852e18 100644 (file)
@@ -1,5 +1,35 @@
 2015-03-15  Simon Fraser  <simon.fraser@apple.com>
 
+        Clean up related to wheelEvent names
+        https://bugs.webkit.org/show_bug.cgi?id=142713
+
+        Reviewed by Anders Carlsson.
+
+        Add EventNames::isWheelEventType() and use it in places that test for the
+        two wheel event names.
+
+        * dom/Document.cpp:
+        (WebCore::Document::didAddWheelEventHandler):
+        (WebCore::Document::didRemoveWheelEventHandler):
+        * dom/Document.h: No need for exports (I grepped). Pass the Node*, which
+        will be used in a later patch.
+        * dom/EventNames.h:
+        (WebCore::EventNames::isWheelEventType):
+        * dom/Node.cpp:
+        (WebCore::Node::didMoveToNewDocument):
+        (WebCore::tryAddEventListener):
+        (WebCore::tryRemoveEventListener):
+        (WebCore::Node::defaultEventHandler):
+        * html/shadow/MediaControlsApple.cpp:
+        (WebCore::MediaControlsAppleEventListener::handleEvent):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::addEventListener):
+        (WebCore::DOMWindow::removeEventListener):
+        * page/ios/FrameIOS.mm:
+        (WebCore::ancestorRespondingToScrollWheelEvents): Remove dead code.
+
+2015-03-15  Simon Fraser  <simon.fraser@apple.com>
+
         Remove a redundant repaint when a layer becomes composited
         https://bugs.webkit.org/show_bug.cgi?id=142711
 
index 933a493..ec242f7 100644 (file)
@@ -5995,25 +5995,25 @@ static void wheelEventHandlerCountChanged(Document* document)
     scrollingCoordinator->frameViewWheelEventHandlerCountChanged(frameView);
 }
 
-void Document::didAddWheelEventHandler()
+void Document::didAddWheelEventHandler(Node&)
 {
     ++m_wheelEventHandlerCount;
     wheelEventHandlerCountChanged(this);
 }
 
-void Document::didRemoveWheelEventHandler()
+void Document::didRemoveWheelEventHandler(Node&)
 {
     ASSERT(m_wheelEventHandlerCount > 0);
     --m_wheelEventHandlerCount;
     wheelEventHandlerCountChanged(this);
 }
 
-void Document::didAddTouchEventHandler(Node* handler)
+void Document::didAddTouchEventHandler(Node& handler)
 {
 #if ENABLE(TOUCH_EVENTS)
     if (!m_touchEventTargets.get())
         m_touchEventTargets = std::make_unique<TouchEventTargetSet>();
-    m_touchEventTargets->add(handler);
+    m_touchEventTargets->add(&handler);
     if (Document* parent = parentDocument()) {
         parent->didAddTouchEventHandler(this);
         return;
@@ -6027,13 +6027,13 @@ void Document::didAddTouchEventHandler(Node* handler)
 #endif
 }
 
-void Document::didRemoveTouchEventHandler(Node* handler)
+void Document::didRemoveTouchEventHandler(Node& handler)
 {
 #if ENABLE(TOUCH_EVENTS)
     if (!m_touchEventTargets.get())
         return;
     ASSERT(m_touchEventTargets->contains(handler));
-    m_touchEventTargets->remove(handler);
+    m_touchEventTargets->remove(&handler);
     if (Document* parent = parentDocument()) {
         parent->didRemoveTouchEventHandler(this);
         return;
index 040650b..43c8f03 100644 (file)
@@ -1122,8 +1122,8 @@ public:
     void initDNSPrefetch();
 
     unsigned wheelEventHandlerCount() const { return m_wheelEventHandlerCount; }
-    WEBCORE_EXPORT void didAddWheelEventHandler();
-    WEBCORE_EXPORT void didRemoveWheelEventHandler();
+    void didAddWheelEventHandler(Node&);
+    void didRemoveWheelEventHandler(Node&);
 
     double lastHandledUserGestureTimestamp() const { return m_lastHandledUserGestureTimestamp; }
     void updateLastHandledUserGestureTimestamp();
@@ -1134,8 +1134,8 @@ public:
     bool hasTouchEventHandlers() const { return false; }
 #endif
 
-    void didAddTouchEventHandler(Node*);
-    void didRemoveTouchEventHandler(Node*);
+    void didAddTouchEventHandler(Node&);
+    void didRemoveTouchEventHandler(Node&);
 
 #if ENABLE(TOUCH_EVENTS)
     void didRemoveEventTargetNode(Node*);
index 760e7d5..7b20bb8 100644 (file)
@@ -264,6 +264,7 @@ public:
 
     // FIXME: Inelegant to call these both event names and event types.
     // We should choose one term and stick to it.
+    bool isWheelEventType(const AtomicString& eventType) const;
     bool isGestureEventType(const AtomicString& eventType) const;
     bool isTouchEventType(const AtomicString& eventType) const;
 #if ENABLE(GAMEPAD)
@@ -299,6 +300,12 @@ inline bool EventNames::isTouchEventType(const AtomicString& eventType) const
         || eventType == touchcancelEvent;
 }
 
+inline bool EventNames::isWheelEventType(const AtomicString& eventType) const
+{
+    return eventType == wheelEvent
+        || eventType == mousewheelEvent;
+}
+
 inline std::array<std::reference_wrapper<const AtomicString>, 4> EventNames::touchEventNames() const
 {
     return { { touchstartEvent, touchmoveEvent, touchendEvent, touchcancelEvent } };
index 126db21..19cfbc4 100644 (file)
@@ -1712,19 +1712,19 @@ void Node::didMoveToNewDocument(Document* oldDocument)
             cache->remove(this);
     }
 
-    unsigned numWheelEventHandlers = getEventListeners(eventNames().mousewheelEvent).size()
-        + getEventListeners(eventNames().wheelEvent).size();
+    unsigned numWheelEventHandlers = getEventListeners(eventNames().mousewheelEvent).size() + getEventListeners(eventNames().wheelEvent).size();
     for (unsigned i = 0; i < numWheelEventHandlers; ++i) {
-        oldDocument->didRemoveWheelEventHandler();
-        document().didAddWheelEventHandler();
+        oldDocument->didRemoveWheelEventHandler(*this);
+        document().didAddWheelEventHandler(*this);
     }
 
     unsigned numTouchEventHandlers = 0;
     for (auto& name : eventNames().touchEventNames())
         numTouchEventHandlers += getEventListeners(name).size();
+
     for (unsigned i = 0; i < numTouchEventHandlers; ++i) {
-        oldDocument->didRemoveTouchEventHandler(this);
-        document().didAddTouchEventHandler(this);
+        oldDocument->didRemoveTouchEventHandler(*this);
+        document().didAddTouchEventHandler(*this);
     }
 
     if (auto* registry = mutationObserverRegistry()) {
@@ -1746,10 +1746,10 @@ static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve
         return false;
 
     targetNode->document().addListenerTypeIfNeeded(eventType);
-    if (eventType == eventNames().wheelEvent || eventType == eventNames().mousewheelEvent)
-        targetNode->document().didAddWheelEventHandler();
+    if (eventNames().isWheelEventType(eventType))
+        targetNode->document().didAddWheelEventHandler(*targetNode);
     else if (eventNames().isTouchEventType(eventType))
-        targetNode->document().didAddTouchEventHandler(targetNode);
+        targetNode->document().didAddTouchEventHandler(*targetNode);
 
 #if PLATFORM(IOS)
     if (targetNode == &targetNode->document() && eventType == eventNames().scrollEvent)
@@ -1788,10 +1788,10 @@ static inline bool tryRemoveEventListener(Node* targetNode, const AtomicString&
 
     // FIXME: Notify Document that the listener has vanished. We need to keep track of a number of
     // listeners for each type, not just a bool - see https://bugs.webkit.org/show_bug.cgi?id=33861
-    if (eventType == eventNames().wheelEvent || eventType == eventNames().mousewheelEvent)
-        targetNode->document().didRemoveWheelEventHandler();
+    if (eventNames().isWheelEventType(eventType))
+        targetNode->document().didRemoveWheelEventHandler(*targetNode);
     else if (eventNames().isTouchEventType(eventType))
-        targetNode->document().didRemoveTouchEventHandler(targetNode);
+        targetNode->document().didRemoveTouchEventHandler(*targetNode);
 
 #if PLATFORM(IOS)
     if (targetNode == &targetNode->document() && eventType == eventNames().scrollEvent)
@@ -2086,8 +2086,7 @@ void Node::defaultEventHandler(Event* event)
             }
         }
 #endif
-    } else if ((eventType == eventNames().wheelEvent || eventType == eventNames().mousewheelEvent) && is<WheelEvent>(*event)) {
-
+    } else if (eventNames().isWheelEventType(eventType) && is<WheelEvent>(*event)) {
         // If we don't have a renderer, send the wheel event to the first node we find with a renderer.
         // This is needed for <option> and <optgroup> elements so that <select>s get a wheel scroll.
         Node* startNode = this;
index e65ce6e..014d631 100644 (file)
@@ -116,6 +116,7 @@ void CachedFrameBase::restore()
 
         if (DOMWindow* domWindow = m_document->domWindow()) {
             // FIXME: Add SCROLL_LISTENER to the list of event types on Document, and use m_document->hasListenerType(). See <rdar://problem/9615482>.
+            // FIXME: Can use Document::hasListenerType() now.
             if (domWindow->scrollEventListenerCount() && frame.page())
                 frame.page()->chrome().client().setNeedsScrollNotifications(&frame, true);
         }
index 01e3f6f..8fdba0d 100644 (file)
@@ -588,7 +588,7 @@ void MediaControlsAppleEventListener::handleEvent(ScriptExecutionContext*, Event
 {
     if (event->type() == eventNames().clickEvent)
         m_mediaControls->handleClickEvent(event);
-    else if ((event->type() == eventNames().wheelEvent || event->type() == eventNames().mousewheelEvent) && is<WheelEvent>(*event)) {
+    else if (eventNames().isWheelEventType(event->type()) && is<WheelEvent>(*event)) {
         WheelEvent& wheelEvent = downcast<WheelEvent>(*event);
         if (m_mediaControls->shouldClosedCaptionsContainerPreventPageScrolling(wheelEvent.wheelDeltaY()))
             wheelEvent.preventDefault();
index d9963b2..0e89ae3 100644 (file)
@@ -1697,10 +1697,10 @@ bool DOMWindow::addEventListener(const AtomicString& eventType, PassRefPtr<Event
 
     if (Document* document = this->document()) {
         document->addListenerTypeIfNeeded(eventType);
-        if (eventType == eventNames().wheelEvent || eventType == eventNames().mousewheelEvent)
-            document->didAddWheelEventHandler();
+        if (eventNames().isWheelEventType(eventType))
+            document->didAddWheelEventHandler(*document);
         else if (eventNames().isTouchEventType(eventType))
-            document->didAddTouchEventHandler(document);
+            document->didAddTouchEventHandler(*document);
         else if (eventType == eventNames().storageEvent)
             didAddStorageEventListener(this);
     }
@@ -1788,10 +1788,10 @@ bool DOMWindow::removeEventListener(const AtomicString& eventType, EventListener
         return false;
 
     if (Document* document = this->document()) {
-        if (eventType == eventNames().wheelEvent || eventType == eventNames().mousewheelEvent)
-            document->didRemoveWheelEventHandler();
+        if (eventNames().isWheelEventType(eventType))
+            document->didRemoveWheelEventHandler(*document);
         else if (eventNames().isTouchEventType(eventType))
-            document->didRemoveTouchEventHandler(document);
+            document->didRemoveTouchEventHandler(*document);
     }
 
     if (eventType == eventNames().unloadEvent)
index 0d93cbd..fea89d9 100644 (file)
@@ -273,8 +273,6 @@ CGRect Frame::renderRectForPoint(CGPoint point, bool* isReplaced, float* fontSiz
     return CGRectZero;
 }
 
-#define ALLOW_SCROLL_LISTENERS 0
-
 static Node* ancestorRespondingToScrollWheelEvents(const HitTestResult& hitTestResult, Node* terminationNode, IntRect* nodeBounds)
 {
     if (nodeBounds)
@@ -282,13 +280,6 @@ static Node* ancestorRespondingToScrollWheelEvents(const HitTestResult& hitTestR
 
     Node* scrollingAncestor = nullptr;
     for (Node* node = hitTestResult.innerNode(); node && node != terminationNode && !node->hasTagName(HTMLNames::bodyTag); node = node->parentNode()) {
-#if ALLOW_SCROLL_LISTENERS
-        if (node->willRespondToMouseWheelEvents()) {
-            scrollingAncestor = node;
-            continue;
-        }
-#endif
-
         RenderObject* renderer = node->renderer();
         if (!renderer)
             continue;
index eacbb9d..3c640a2 100644 (file)
@@ -1,3 +1,16 @@
+2015-03-15  Simon Fraser  <simon.fraser@apple.com>
+
+        Clean up related to wheelEvent names
+        https://bugs.webkit.org/show_bug.cgi?id=142713
+
+        Reviewed by Anders Carlsson.
+
+        Add EventNames::isWheelEventType() and use it in places that test for the
+        two wheel event names.
+
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::PluginView::handleEvent):
+
 2015-03-15  Dan Bernstein  <mitz@apple.com>
 
         [iOS] Presenting a modal sheet on top of a WKWebView causes it to lose focused, active state
index 59397cb..d2e2a53 100644 (file)
@@ -919,7 +919,7 @@ void PluginView::handleEvent(Event* event)
         didHandleEvent = m_plugin->handleMouseEvent(static_cast<const WebMouseEvent&>(*currentEvent));
         if (event->type() != eventNames().mousemoveEvent)
             pluginDidReceiveUserInteraction();
-    } else if ((event->type() == eventNames().wheelEvent || event->type() == eventNames().mousewheelEvent)
+    } else if (eventNames().isWheelEventType(event->type())
         && currentEvent->type() == WebEvent::Wheel && m_plugin->wantsWheelEvents()) {
         didHandleEvent = m_plugin->handleWheelEvent(static_cast<const WebWheelEvent&>(*currentEvent));
         pluginDidReceiveUserInteraction();