Introduce Event::hasInterface to make uses of interfaceName more readable
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Oct 2011 22:56:39 +0000 (22:56 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Oct 2011 22:56:39 +0000 (22:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=70652

Reviewed by Eric Seidel.

Source/WebCore:

Eric felt that this approach would be more readable because it requires
less syntax at each callsite.

* bindings/js/JSErrorHandler.cpp:
(WebCore::JSErrorHandler::handleEvent):
* bindings/objc/DOMEvents.mm:
(kitClass):
* bindings/v8/V8WindowErrorHandler.cpp:
(WebCore::V8WindowErrorHandler::callListenerFunction):
* bindings/v8/V8WorkerContextErrorHandler.cpp:
(WebCore::V8WorkerContextErrorHandler::callListenerFunction):
* dom/Event.cpp:
(WebCore::Event::hasInterface):
* dom/Event.h:
* dom/EventDispatcher.cpp:
(WebCore::EventDispatcher::determineDispatchBehavior):
* dom/Node.cpp:
(WebCore::Node::defaultEventHandler):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::defaultEventHandler):
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::defaultEventHandler):
* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::forwardEvent):
(WebCore::TextFieldInputType::shouldSubmitImplicitly):
* inspector/InspectorDOMStorageResource.cpp:
(WebCore::InspectorDOMStorageResource::handleEvent):

Source/WebKit/chromium:

Update call sites to the new interface.

* src/WebDOMEvent.cpp:
(WebKit::WebDOMEvent::isMutationEvent):
(WebKit::WebDOMEvent::isTextEvent):
(WebKit::WebDOMEvent::isCompositionEvent):
(WebKit::WebDOMEvent::isMessageEvent):
(WebKit::WebDOMEvent::isWheelEvent):
(WebKit::WebDOMEvent::isOverflowEvent):
(WebKit::WebDOMEvent::isPageTransitionEvent):
(WebKit::WebDOMEvent::isPopStateEvent):
(WebKit::WebDOMEvent::isProgressEvent):
(WebKit::WebDOMEvent::isXMLHttpRequestProgressEvent):
(WebKit::WebDOMEvent::isWebKitAnimationEvent):
(WebKit::WebDOMEvent::isWebKitTransitionEvent):
(WebKit::WebDOMEvent::isBeforeLoadEvent):
* src/WebPluginContainerImpl.cpp:
(WebKit::WebPluginContainerImpl::handleEvent):

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

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSErrorHandler.cpp
Source/WebCore/bindings/objc/DOMEvents.mm
Source/WebCore/bindings/v8/V8WindowErrorHandler.cpp
Source/WebCore/bindings/v8/V8WorkerContextErrorHandler.cpp
Source/WebCore/dom/Event.cpp
Source/WebCore/dom/Event.h
Source/WebCore/dom/EventDispatcher.cpp
Source/WebCore/dom/Node.cpp
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLTextAreaElement.cpp
Source/WebCore/html/TextFieldInputType.cpp
Source/WebCore/inspector/InspectorDOMStorageResource.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/WebDOMEvent.cpp
Source/WebKit/chromium/src/WebPluginContainerImpl.cpp

index 31ef433..e4ec7aa 100755 (executable)
@@ -1,3 +1,38 @@
+2011-10-21  Adam Barth  <abarth@webkit.org>
+
+        Introduce Event::hasInterface to make uses of interfaceName more readable
+        https://bugs.webkit.org/show_bug.cgi?id=70652
+
+        Reviewed by Eric Seidel.
+
+        Eric felt that this approach would be more readable because it requires
+        less syntax at each callsite.
+
+        * bindings/js/JSErrorHandler.cpp:
+        (WebCore::JSErrorHandler::handleEvent):
+        * bindings/objc/DOMEvents.mm:
+        (kitClass):
+        * bindings/v8/V8WindowErrorHandler.cpp:
+        (WebCore::V8WindowErrorHandler::callListenerFunction):
+        * bindings/v8/V8WorkerContextErrorHandler.cpp:
+        (WebCore::V8WorkerContextErrorHandler::callListenerFunction):
+        * dom/Event.cpp:
+        (WebCore::Event::hasInterface):
+        * dom/Event.h:
+        * dom/EventDispatcher.cpp:
+        (WebCore::EventDispatcher::determineDispatchBehavior):
+        * dom/Node.cpp:
+        (WebCore::Node::defaultEventHandler):
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::defaultEventHandler):
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::defaultEventHandler):
+        * html/TextFieldInputType.cpp:
+        (WebCore::TextFieldInputType::forwardEvent):
+        (WebCore::TextFieldInputType::shouldSubmitImplicitly):
+        * inspector/InspectorDOMStorageResource.cpp:
+        (WebCore::InspectorDOMStorageResource::handleEvent):
+
 2011-10-21  Adam Klein  <adamk@chromium.org>
 
         [MutationObservers] Implement basic subtree observation
index 603342f..01ec6b7 100644 (file)
@@ -53,7 +53,7 @@ JSErrorHandler::~JSErrorHandler()
 
 void JSErrorHandler::handleEvent(ScriptExecutionContext* scriptExecutionContext, Event* event)
 {
-    if (event->interfaceName() != eventNames().interfaceForErrorEvent)
+    if (!event->hasInterface(eventNames().interfaceForErrorEvent))
         return JSEventListener::handleEvent(scriptExecutionContext, event);
 
     ASSERT(scriptExecutionContext);
index 2e2bae2..d7ba17f 100644 (file)
 #import "DOMSVGZoomEvent.h"
 #endif
 
+using WebCore::eventNames;
+
 Class kitClass(WebCore::Event* impl)
 {
-    AtomicString desiredInterface = impl->interfaceName();
-
     if (impl->isUIEvent()) {
         if (impl->isKeyboardEvent())
             return [DOMKeyboardEvent class];
         if (impl->isMouseEvent())
             return [DOMMouseEvent class];
-        if (desiredInterface == WebCore::eventNames().interfaceForTextEvent)
+        if (impl->hasInterface(eventNames().interfaceForTextEvent))
             return [DOMTextEvent class];
-        if (desiredInterface == WebCore::eventNames().interfaceForWheelEvent)
+        if (impl->hasInterface(eventNames().interfaceForWheelEvent))
             return [DOMWheelEvent class];        
 #if ENABLE(SVG_DOM_OBJC_BINDINGS)
-        if (desiredInterface == WebCore::eventNames().interfaceForSVGZoomEvent)
+        if (impl->hasInterface(eventNames().interfaceForSVGZoomEvent))
             return [DOMSVGZoomEvent class];
 #endif
         return [DOMUIEvent class];
     }
-    if (desiredInterface == WebCore::eventNames().interfaceForMutationEvent)
+    if (impl->hasInterface(eventNames().interfaceForMutationEvent))
         return [DOMMutationEvent class];
-    if (desiredInterface == WebCore::eventNames().interfaceForOverflowEvent)
+    if (impl->hasInterface(eventNames().interfaceForOverflowEvent))
         return [DOMOverflowEvent class];
-    if (desiredInterface == WebCore::eventNames().interfaceForMessageEvent)
+    if (impl->hasInterface(eventNames().interfaceForMessageEvent))
         return [DOMMessageEvent class];
-    if (desiredInterface == WebCore::eventNames().interfaceForProgressEvent || desiredInterface == WebCore::eventNames().interfaceForXMLHttpRequestProgressEvent)
+    if (impl->hasInterface(eventNames().interfaceForProgressEvent) || impl->hasInterface(eventNames().interfaceForXMLHttpRequestProgressEvent))
         return [DOMProgressEvent class];
-    if (desiredInterface == WebCore::eventNames().interfaceForBeforeLoadEvent)
+    if (impl->hasInterface(eventNames().interfaceForBeforeLoadEvent))
         return [DOMBeforeLoadEvent class];
     return [DOMEvent class];
 }
index deb8e4c..0761b0f 100644 (file)
@@ -45,7 +45,7 @@ V8WindowErrorHandler::V8WindowErrorHandler(v8::Local<v8::Object> listener, bool
 
 v8::Local<v8::Value> V8WindowErrorHandler::callListenerFunction(ScriptExecutionContext* context, v8::Handle<v8::Value> jsEvent, Event* event)
 {
-    if (event->interfaceName() != eventNames().interfaceForErrorEvent)
+    if (!event->hasInterface(eventNames().interfaceForErrorEvent))
         return V8EventListener::callListenerFunction(context, jsEvent, event);
 
     ErrorEvent* errorEvent = static_cast<ErrorEvent*>(event);
index 75071ee..d02278e 100644 (file)
@@ -47,7 +47,7 @@ V8WorkerContextErrorHandler::V8WorkerContextErrorHandler(v8::Local<v8::Object> l
 
 v8::Local<v8::Value> V8WorkerContextErrorHandler::callListenerFunction(ScriptExecutionContext* context, v8::Handle<v8::Value> jsEvent, Event* event)
 {
-    ASSERT(event->interfaceName() == eventNames().interfaceForErrorEvent);
+    ASSERT(event->hasInterface(eventNames().interfaceForErrorEvent));
     v8::Local<v8::Object> listener = getListenerObject(context);
     v8::Local<v8::Value> returnValue;
     if (!listener.IsEmpty() && listener->IsFunction()) {
index f775c99..9121e4f 100644 (file)
@@ -102,6 +102,11 @@ const AtomicString& Event::interfaceName() const
     return eventNames().interfaceForEvent;
 }
 
+bool Event::hasInterface(const AtomicString& name) const
+{
+    return interfaceName() == name;
+}
+
 bool Event::isUIEvent() const
 {
     return false;
index ea6f822..8005b63 100644 (file)
@@ -113,6 +113,7 @@ namespace WebCore {
         Clipboard* clipboardData() const { return isClipboardEvent() ? clipboard() : 0; }
 
         virtual const AtomicString& interfaceName() const;
+        bool hasInterface(const AtomicString&) const;
 
         // These events are general classes of events.
         virtual bool isUIEvent() const;
index 9df8f79..c8640c9 100644 (file)
@@ -396,7 +396,7 @@ EventDispatchBehavior EventDispatcher::determineDispatchBehavior(Event* event, N
 
     // Per XBL 2.0 spec, mutation events should never cross shadow DOM boundary:
     // http://dev.w3.org/2006/xbl2/#event-flow-and-targeting-across-shadow-s
-    if (event->interfaceName() == eventNames().interfaceForMutationEvent)
+    if (event->hasInterface(eventNames().interfaceForMutationEvent))
         return StayInsideShadowDOM;
 
     // WebKit never allowed selectstart event to cross the the shadow DOM boundary.
index b7bfaa5..5ce6967 100644 (file)
@@ -2889,7 +2889,7 @@ void Node::defaultEventHandler(Event* event)
                 page->contextMenuController()->handleContextMenuEvent(event);
 #endif
     } else if (eventType == eventNames().textInputEvent) {
-        if (event->interfaceName() == eventNames().interfaceForTextEvent)
+        if (event->hasInterface(eventNames().interfaceForTextEvent))
             if (Frame* frame = document()->frame())
                 frame->eventHandler()->defaultTextInputEventHandler(static_cast<TextEvent*>(event));
 #if ENABLE(PAN_SCROLLING)
@@ -2909,7 +2909,7 @@ void Node::defaultEventHandler(Event* event)
             }
         }
 #endif
-    } else if (eventType == eventNames().mousewheelEvent && event->interfaceName() == eventNames().interfaceForWheelEvent) {
+    } else if (eventType == eventNames().mousewheelEvent && event->hasInterface(eventNames().interfaceForWheelEvent)) {
         WheelEvent* wheelEvent = static_cast<WheelEvent*>(event);
         
         // If we don't have a renderer, send the wheel event to the first node we find with a renderer.
index 24707db..ef72d43 100644 (file)
@@ -1269,7 +1269,7 @@ void HTMLInputElement::defaultEventHandler(Event* evt)
     if (evt->isBeforeTextInsertedEvent())
         m_inputType->handleBeforeTextInsertedEvent(static_cast<BeforeTextInsertedEvent*>(evt));
 
-    if (evt->interfaceName() == eventNames().interfaceForWheelEvent) {
+    if (evt->hasInterface(eventNames().interfaceForWheelEvent)) {
         m_inputType->handleWheelEvent(static_cast<WheelEvent*>(evt));
         if (evt->defaultHandled())
             return;
index 30506b5..e312330 100644 (file)
@@ -211,7 +211,7 @@ void HTMLTextAreaElement::updateFocusAppearance(bool restorePreviousSelection)
 
 void HTMLTextAreaElement::defaultEventHandler(Event* event)
 {
-    if (renderer() && (event->isMouseEvent() || event->isDragEvent() || event->interfaceName() == eventNames().interfaceForWheelEvent || event->type() == eventNames().blurEvent))
+    if (renderer() && (event->isMouseEvent() || event->isDragEvent() || event->hasInterface(eventNames().interfaceForWheelEvent) || event->type() == eventNames().blurEvent))
         forwardEvent(event);
     else if (renderer() && event->isBeforeTextInsertedEvent())
         handleBeforeTextInsertedEvent(static_cast<BeforeTextInsertedEvent*>(event));
index 073936a..c43eabc 100644 (file)
@@ -142,7 +142,7 @@ void TextFieldInputType::handleWheelEventForSpinButton(WheelEvent* event)
 
 void TextFieldInputType::forwardEvent(Event* event)
 {
-    if (element()->renderer() && (event->isMouseEvent() || event->isDragEvent() || event->interfaceName() == eventNames().interfaceForWheelEvent || event->type() == eventNames().blurEvent || event->type() == eventNames().focusEvent)) {
+    if (element()->renderer() && (event->isMouseEvent() || event->isDragEvent() || event->hasInterface(eventNames().interfaceForWheelEvent) || event->type() == eventNames().blurEvent || event->type() == eventNames().focusEvent)) {
         RenderTextControlSingleLine* renderTextControl = toRenderTextControlSingleLine(element()->renderer());
         if (event->type() == eventNames().blurEvent) {
             if (RenderBox* innerTextRenderer = innerTextElement()->renderBox()) {
@@ -160,7 +160,7 @@ void TextFieldInputType::forwardEvent(Event* event)
 
 bool TextFieldInputType::shouldSubmitImplicitly(Event* event)
 {
-    return (event->type() == eventNames().textInputEvent && event->interfaceName() == eventNames().interfaceForTextEvent && static_cast<TextEvent*>(event)->data() == "\n") || InputType::shouldSubmitImplicitly(event);
+    return (event->type() == eventNames().textInputEvent && event->hasInterface(eventNames().interfaceForTextEvent) && static_cast<TextEvent*>(event)->data() == "\n") || InputType::shouldSubmitImplicitly(event);
 }
 
 RenderObject* TextFieldInputType::createRenderer(RenderArena* arena, RenderStyle*) const
index 4370249..327d7bf 100644 (file)
@@ -102,7 +102,7 @@ void InspectorDOMStorageResource::startReportingChangesToFrontend()
 void InspectorDOMStorageResource::handleEvent(ScriptExecutionContext*, Event* event)
 {
     ASSERT(m_frontend);
-    if (event->type() != eventNames().storageEvent || event->interfaceName() != eventNames().interfaceForStorageEvent)
+    if (event->type() != eventNames().storageEvent || event->hasInterface(eventNames().interfaceForStorageEvent))
         return;
 
     StorageEvent* storageEvent = static_cast<StorageEvent*>(event);
index f805c48..e135d36 100644 (file)
@@ -1,5 +1,31 @@
 2011-10-21  Adam Barth  <abarth@webkit.org>
 
+        Introduce Event::hasInterface to make uses of interfaceName more readable
+        https://bugs.webkit.org/show_bug.cgi?id=70652
+
+        Reviewed by Eric Seidel.
+
+        Update call sites to the new interface.
+
+        * src/WebDOMEvent.cpp:
+        (WebKit::WebDOMEvent::isMutationEvent):
+        (WebKit::WebDOMEvent::isTextEvent):
+        (WebKit::WebDOMEvent::isCompositionEvent):
+        (WebKit::WebDOMEvent::isMessageEvent):
+        (WebKit::WebDOMEvent::isWheelEvent):
+        (WebKit::WebDOMEvent::isOverflowEvent):
+        (WebKit::WebDOMEvent::isPageTransitionEvent):
+        (WebKit::WebDOMEvent::isPopStateEvent):
+        (WebKit::WebDOMEvent::isProgressEvent):
+        (WebKit::WebDOMEvent::isXMLHttpRequestProgressEvent):
+        (WebKit::WebDOMEvent::isWebKitAnimationEvent):
+        (WebKit::WebDOMEvent::isWebKitTransitionEvent):
+        (WebKit::WebDOMEvent::isBeforeLoadEvent):
+        * src/WebPluginContainerImpl.cpp:
+        (WebKit::WebPluginContainerImpl::handleEvent):
+
+2011-10-21  Adam Barth  <abarth@webkit.org>
+
         Event.h has too many virtual isMumbleEvent() functions
         https://bugs.webkit.org/show_bug.cgi?id=70636
 
index 548961a..136f2f4 100644 (file)
@@ -36,6 +36,8 @@
 #include "Node.h"
 #include <wtf/PassRefPtr.h>
 
+using WebCore::eventNames;
+
 namespace WebKit {
 
 class WebDOMEventPrivate : public WebCore::Event {
@@ -124,19 +126,19 @@ bool WebDOMEvent::isKeyboardEvent() const
 bool WebDOMEvent::isMutationEvent() const
 {
     ASSERT(m_private);
-    return m_private->interfaceName() == WebCore::eventNames().interfaceForMutationEvent;
+    return m_private->hasInterface(WebCore::eventNames().interfaceForMutationEvent);
 }
 
 bool WebDOMEvent::isTextEvent() const
 {
     ASSERT(m_private);
-    return m_private->interfaceName() == WebCore::eventNames().interfaceForTextEvent;
+    return m_private->hasInterface(eventNames().interfaceForTextEvent);
 }
 
 bool WebDOMEvent::isCompositionEvent() const
 {
     ASSERT(m_private);
-    return m_private->interfaceName() == WebCore::eventNames().interfaceForCompositionEvent;
+    return m_private->hasInterface(eventNames().interfaceForCompositionEvent);
 }
 
 bool WebDOMEvent::isDragEvent() const
@@ -154,13 +156,13 @@ bool WebDOMEvent::isClipboardEvent() const
 bool WebDOMEvent::isMessageEvent() const
 {
     ASSERT(m_private);
-    return m_private->interfaceName() == WebCore::eventNames().interfaceForMessageEvent;
+    return m_private->hasInterface(eventNames().interfaceForMessageEvent);
 }
 
 bool WebDOMEvent::isWheelEvent() const
 {
     ASSERT(m_private);
-    return m_private->interfaceName() == WebCore::eventNames().interfaceForWheelEvent;
+    return m_private->hasInterface(eventNames().interfaceForWheelEvent);
 }
 
 bool WebDOMEvent::isBeforeTextInsertedEvent() const
@@ -172,49 +174,49 @@ bool WebDOMEvent::isBeforeTextInsertedEvent() const
 bool WebDOMEvent::isOverflowEvent() const
 {
     ASSERT(m_private);
-    return m_private->interfaceName() == WebCore::eventNames().interfaceForOverflowEvent;
+    return m_private->hasInterface(eventNames().interfaceForOverflowEvent);
 }
 
 bool WebDOMEvent::isPageTransitionEvent() const
 {
     ASSERT(m_private);
-    return m_private->interfaceName() == WebCore::eventNames().interfaceForPageTransitionEvent;
+    return m_private->hasInterface(eventNames().interfaceForPageTransitionEvent);
 }
 
 bool WebDOMEvent::isPopStateEvent() const
 {
     ASSERT(m_private);
-    return m_private->interfaceName() == WebCore::eventNames().interfaceForPopStateEvent;
+    return m_private->hasInterface(eventNames().interfaceForPopStateEvent);
 }
 
 bool WebDOMEvent::isProgressEvent() const
 {
     ASSERT(m_private);
-    return m_private->interfaceName() == WebCore::eventNames().interfaceForProgressEvent;
+    return m_private->hasInterface(eventNames().interfaceForProgressEvent);
 }
 
 bool WebDOMEvent::isXMLHttpRequestProgressEvent() const
 {
     ASSERT(m_private);
-    return m_private->interfaceName() == WebCore::eventNames().interfaceForXMLHttpRequestProgressEvent;
+    return m_private->hasInterface(eventNames().interfaceForXMLHttpRequestProgressEvent);
 }
 
 bool WebDOMEvent::isWebKitAnimationEvent() const
 {
     ASSERT(m_private);
-    return m_private->interfaceName() == WebCore::eventNames().interfaceForWebKitAnimationEvent;
+    return m_private->hasInterface(eventNames().interfaceForWebKitAnimationEvent);
 }
 
 bool WebDOMEvent::isWebKitTransitionEvent() const
 {
     ASSERT(m_private);
-    return m_private->interfaceName() == WebCore::eventNames().interfaceForWebKitTransitionEvent;
+    return m_private->hasInterface(eventNames().interfaceForWebKitTransitionEvent);
 }
 
 bool WebDOMEvent::isBeforeLoadEvent() const
 {
     ASSERT(m_private);
-    return m_private->interfaceName() == WebCore::eventNames().interfaceForBeforeLoadEvent;
+    return m_private->hasInterface(eventNames().interfaceForBeforeLoadEvent);
 }
 
 } // namespace WebKit
index 2b31449..c8f4f7b 100644 (file)
@@ -186,7 +186,7 @@ void WebPluginContainerImpl::handleEvent(Event* event)
     // where mozilla behaves differently than the spec.
     if (event->isMouseEvent())
         handleMouseEvent(static_cast<MouseEvent*>(event));
-    else if (event->interfaceName() == eventNames().interfaceForWheelEvent)
+    else if (event->hasInterface(eventNames().interfaceForWheelEvent))
         handleWheelEvent(static_cast<WheelEvent*>(event));
     else if (event->isKeyboardEvent())
         handleKeyboardEvent(static_cast<KeyboardEvent*>(event));