Use is<>() / downcast<>() for Event classes
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Oct 2014 22:29:14 +0000 (22:29 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Oct 2014 22:29:14 +0000 (22:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137284

Reviewed by Andreas Kling.

Use is<>() / downcast<>() for Event classes.

Source/WebCore:

No new tests, no behavior change.

* bindings/js/JSErrorHandler.cpp:
(WebCore::JSErrorHandler::handleEvent):
* bindings/js/JSEventListener.cpp:
(WebCore::JSEventListener::handleEvent):
* dom/BeforeTextInsertedEvent.h:
* dom/BeforeUnloadEvent.h:
* dom/ErrorEvent.h:
* dom/Event.h:
* dom/EventContext.cpp:
(WebCore::MouseOrFocusEventContext::handleLocalEvents):
* dom/FocusEvent.h:
* dom/KeyboardEvent.cpp:
(WebCore::findKeyboardEvent):
* dom/KeyboardEvent.h:
* dom/MouseEvent.cpp:
(WebCore::SimulatedMouseEvent::SimulatedMouseEvent):
* dom/MouseEvent.h:
* dom/Node.cpp:
(WebCore::Node::defaultEventHandler):
* dom/TextEvent.h:
* dom/UIEvent.h:
* dom/WheelEvent.h:
* html/HTMLAnchorElement.cpp:
(WebCore::appendServerMapMousePosition):
(WebCore::HTMLAnchorElement::defaultEventHandler):
(WebCore::HTMLAnchorElement::eventType):
(WebCore::isEnterKeyKeydownEvent):
(WebCore::isLinkClick):
* html/HTMLButtonElement.cpp:
(WebCore::HTMLButtonElement::defaultEventHandler):
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::submitImplicitly):
* html/HTMLFormElement.h:
* html/HTMLFrameSetElement.cpp:
(WebCore::HTMLFrameSetElement::defaultEventHandler):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::willDispatchEvent):
(WebCore::HTMLInputElement::defaultEventHandler):
* html/HTMLPlugInImageElement.cpp:
(WebCore::HTMLPlugInImageElement::defaultEventHandler):
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::menuListDefaultEventHandler):
(WebCore::HTMLSelectElement::listBoxDefaultEventHandler):
(WebCore::HTMLSelectElement::defaultEventHandler):
* html/HTMLSummaryElement.cpp:
(WebCore::HTMLSummaryElement::defaultEventHandler):
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::defaultEventHandler):
* html/ImageDocument.cpp:
(WebCore::ImageEventListener::handleEvent):
* html/ImageInputType.cpp:
(WebCore::ImageInputType::handleDOMActivateEvent):
* html/InputType.cpp:
(WebCore::InputType::shouldSubmitImplicitly):
* html/InputType.h:
* html/MediaDocument.cpp:
(WebCore::MediaDocument::defaultEventHandler):
* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::shouldSubmitImplicitly):
* html/TextFieldInputType.h:
* html/shadow/MediaControlElementTypes.cpp:
(WebCore::MediaControlVolumeSliderElement::defaultEventHandler):
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlPanelElement::defaultEventHandler):
(WebCore::MediaControlVolumeSliderContainerElement::defaultEventHandler):
(WebCore::MediaControlTimelineElement::defaultEventHandler):
* html/shadow/MediaControls.cpp:
(WebCore::MediaControls::containsRelatedTarget):
* html/shadow/MediaControlsApple.cpp:
(WebCore::MediaControlsAppleEventListener::handleEvent):
* html/shadow/SliderThumbElement.cpp:
(WebCore::SliderThumbElement::defaultEventHandler):
* html/shadow/SpinButtonElement.cpp:
(WebCore::SpinButtonElement::defaultEventHandler):
(WebCore::SpinButtonElement::forwardEvent):
* html/shadow/TextControlInnerElements.cpp:
(WebCore::SearchFieldResultsButtonElement::defaultEventHandler):
(WebCore::SearchFieldCancelButtonElement::defaultEventHandler):
* inspector/InspectorFrontendHost.cpp:
(WebCore::InspectorFrontendHost::dispatchEventAsContextMenuEvent):
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::maybeCreateContextMenu):
* page/EventHandler.cpp:
(WebCore::EventHandler::handleTextInputEvent):
* rendering/RenderEmbeddedObject.cpp:
(WebCore::RenderEmbeddedObject::isInUnavailablePluginIndicator):
(WebCore::RenderEmbeddedObject::handleUnavailablePluginIndicatorEvent):
* rendering/RenderEmbeddedObject.h:
* rendering/RenderSnapshottedPlugIn.cpp:
(WebCore::RenderSnapshottedPlugIn::handleEvent):

Source/WebKit2:

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

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

48 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSErrorHandler.cpp
Source/WebCore/bindings/js/JSEventListener.cpp
Source/WebCore/dom/BeforeTextInsertedEvent.h
Source/WebCore/dom/BeforeUnloadEvent.h
Source/WebCore/dom/ErrorEvent.h
Source/WebCore/dom/Event.h
Source/WebCore/dom/EventContext.cpp
Source/WebCore/dom/EventDispatcher.cpp
Source/WebCore/dom/FocusEvent.h
Source/WebCore/dom/KeyboardEvent.cpp
Source/WebCore/dom/KeyboardEvent.h
Source/WebCore/dom/MouseEvent.cpp
Source/WebCore/dom/MouseEvent.h
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/TextEvent.h
Source/WebCore/dom/TouchEvent.h
Source/WebCore/dom/UIEvent.h
Source/WebCore/dom/WheelEvent.h
Source/WebCore/html/HTMLAnchorElement.cpp
Source/WebCore/html/HTMLButtonElement.cpp
Source/WebCore/html/HTMLFrameSetElement.cpp
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLPlugInImageElement.cpp
Source/WebCore/html/HTMLSelectElement.cpp
Source/WebCore/html/HTMLSelectElement.h
Source/WebCore/html/HTMLSummaryElement.cpp
Source/WebCore/html/HTMLTextAreaElement.cpp
Source/WebCore/html/ImageDocument.cpp
Source/WebCore/html/ImageInputType.cpp
Source/WebCore/html/InputType.cpp
Source/WebCore/html/MediaDocument.cpp
Source/WebCore/html/TextFieldInputType.cpp
Source/WebCore/html/shadow/MediaControlElementTypes.cpp
Source/WebCore/html/shadow/MediaControlElements.cpp
Source/WebCore/html/shadow/MediaControls.cpp
Source/WebCore/html/shadow/MediaControlsApple.cpp
Source/WebCore/html/shadow/SliderThumbElement.cpp
Source/WebCore/html/shadow/SpinButtonElement.cpp
Source/WebCore/html/shadow/TextControlInnerElements.cpp
Source/WebCore/inspector/InspectorFrontendHost.cpp
Source/WebCore/page/ContextMenuController.cpp
Source/WebCore/page/EventHandler.cpp
Source/WebCore/rendering/RenderEmbeddedObject.cpp
Source/WebCore/rendering/RenderEmbeddedObject.h
Source/WebCore/rendering/RenderSnapshottedPlugIn.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Plugins/PluginView.cpp

index ac8eb26..132c9aa 100644 (file)
@@ -1,3 +1,105 @@
+2014-10-01  Christophe Dumez  <cdumez@apple.com>
+
+        Use is<>() / downcast<>() for Event classes
+        https://bugs.webkit.org/show_bug.cgi?id=137284
+
+        Reviewed by Andreas Kling.
+
+        Use is<>() / downcast<>() for Event classes.
+
+        No new tests, no behavior change.
+
+        * bindings/js/JSErrorHandler.cpp:
+        (WebCore::JSErrorHandler::handleEvent):
+        * bindings/js/JSEventListener.cpp:
+        (WebCore::JSEventListener::handleEvent):
+        * dom/BeforeTextInsertedEvent.h:
+        * dom/BeforeUnloadEvent.h:
+        * dom/ErrorEvent.h:
+        * dom/Event.h:
+        * dom/EventContext.cpp:
+        (WebCore::MouseOrFocusEventContext::handleLocalEvents):
+        * dom/FocusEvent.h:
+        * dom/KeyboardEvent.cpp:
+        (WebCore::findKeyboardEvent):
+        * dom/KeyboardEvent.h:
+        * dom/MouseEvent.cpp:
+        (WebCore::SimulatedMouseEvent::SimulatedMouseEvent):
+        * dom/MouseEvent.h:
+        * dom/Node.cpp:
+        (WebCore::Node::defaultEventHandler):
+        * dom/TextEvent.h:
+        * dom/UIEvent.h:
+        * dom/WheelEvent.h:
+        * html/HTMLAnchorElement.cpp:
+        (WebCore::appendServerMapMousePosition):
+        (WebCore::HTMLAnchorElement::defaultEventHandler):
+        (WebCore::HTMLAnchorElement::eventType):
+        (WebCore::isEnterKeyKeydownEvent):
+        (WebCore::isLinkClick):
+        * html/HTMLButtonElement.cpp:
+        (WebCore::HTMLButtonElement::defaultEventHandler):
+        * html/HTMLFormElement.cpp:
+        (WebCore::HTMLFormElement::submitImplicitly):
+        * html/HTMLFormElement.h:
+        * html/HTMLFrameSetElement.cpp:
+        (WebCore::HTMLFrameSetElement::defaultEventHandler):
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::willDispatchEvent):
+        (WebCore::HTMLInputElement::defaultEventHandler):
+        * html/HTMLPlugInImageElement.cpp:
+        (WebCore::HTMLPlugInImageElement::defaultEventHandler):
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::menuListDefaultEventHandler):
+        (WebCore::HTMLSelectElement::listBoxDefaultEventHandler):
+        (WebCore::HTMLSelectElement::defaultEventHandler):
+        * html/HTMLSummaryElement.cpp:
+        (WebCore::HTMLSummaryElement::defaultEventHandler):
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::defaultEventHandler):
+        * html/ImageDocument.cpp:
+        (WebCore::ImageEventListener::handleEvent):
+        * html/ImageInputType.cpp:
+        (WebCore::ImageInputType::handleDOMActivateEvent):
+        * html/InputType.cpp:
+        (WebCore::InputType::shouldSubmitImplicitly):
+        * html/InputType.h:
+        * html/MediaDocument.cpp:
+        (WebCore::MediaDocument::defaultEventHandler):
+        * html/TextFieldInputType.cpp:
+        (WebCore::TextFieldInputType::shouldSubmitImplicitly):
+        * html/TextFieldInputType.h:
+        * html/shadow/MediaControlElementTypes.cpp:
+        (WebCore::MediaControlVolumeSliderElement::defaultEventHandler):
+        * html/shadow/MediaControlElements.cpp:
+        (WebCore::MediaControlPanelElement::defaultEventHandler):
+        (WebCore::MediaControlVolumeSliderContainerElement::defaultEventHandler):
+        (WebCore::MediaControlTimelineElement::defaultEventHandler):
+        * html/shadow/MediaControls.cpp:
+        (WebCore::MediaControls::containsRelatedTarget):
+        * html/shadow/MediaControlsApple.cpp:
+        (WebCore::MediaControlsAppleEventListener::handleEvent):
+        * html/shadow/SliderThumbElement.cpp:
+        (WebCore::SliderThumbElement::defaultEventHandler):
+        * html/shadow/SpinButtonElement.cpp:
+        (WebCore::SpinButtonElement::defaultEventHandler):
+        (WebCore::SpinButtonElement::forwardEvent):
+        * html/shadow/TextControlInnerElements.cpp:
+        (WebCore::SearchFieldResultsButtonElement::defaultEventHandler):
+        (WebCore::SearchFieldCancelButtonElement::defaultEventHandler):
+        * inspector/InspectorFrontendHost.cpp:
+        (WebCore::InspectorFrontendHost::dispatchEventAsContextMenuEvent):
+        * page/ContextMenuController.cpp:
+        (WebCore::ContextMenuController::maybeCreateContextMenu):
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::handleTextInputEvent):
+        * rendering/RenderEmbeddedObject.cpp:
+        (WebCore::RenderEmbeddedObject::isInUnavailablePluginIndicator):
+        (WebCore::RenderEmbeddedObject::handleUnavailablePluginIndicatorEvent):
+        * rendering/RenderEmbeddedObject.h:
+        * rendering/RenderSnapshottedPlugIn.cpp:
+        (WebCore::RenderSnapshottedPlugIn::handleEvent):
+
 2014-10-01  Zan Dobersek  <zdobersek@igalia.com>
 
         [TexMap] Sprinkle range-based for-loops in GraphicsLayerTextureMapper, TextureMapperLayer
index ea51f79..54be24b 100644 (file)
@@ -59,14 +59,14 @@ JSErrorHandler::~JSErrorHandler()
 void JSErrorHandler::handleEvent(ScriptExecutionContext* scriptExecutionContext, Event* event)
 {
 
-    if (event->eventInterface() != ErrorEventInterfaceType)
+    if (!is<ErrorEvent>(event))
         return JSEventListener::handleEvent(scriptExecutionContext, event);
 
     ASSERT(scriptExecutionContext);
     if (!scriptExecutionContext)
         return;
 
-    ErrorEvent* errorEvent = toErrorEvent(event);
+    ErrorEvent& errorEvent = downcast<ErrorEvent>(*event);
 
     JSLockHolder lock(scriptExecutionContext->vm());
 
@@ -90,10 +90,10 @@ void JSErrorHandler::handleEvent(ScriptExecutionContext* scriptExecutionContext,
         globalObject->setCurrentEvent(event);
 
         MarkedArgumentBuffer args;
-        args.append(jsStringWithCache(exec, errorEvent->message()));
-        args.append(jsStringWithCache(exec, errorEvent->filename()));
-        args.append(jsNumber(errorEvent->lineno()));
-        args.append(jsNumber(errorEvent->colno()));
+        args.append(jsStringWithCache(exec, errorEvent.message()));
+        args.append(jsStringWithCache(exec, errorEvent.filename()));
+        args.append(jsNumber(errorEvent.lineno()));
+        args.append(jsNumber(errorEvent.colno()));
 
         VM& vm = globalObject->vm();
         VMEntryScope entryScope(vm, vm.entryScope ? vm.entryScope->globalObject() : globalObject);
index 5c76b6d..4ac5e19 100644 (file)
@@ -141,8 +141,8 @@ void JSEventListener::handleEvent(ScriptExecutionContext* scriptExecutionContext
             event->target()->uncaughtExceptionInEventHandler();
             reportException(exec, exception);
         } else {
-            if (!retval.isUndefinedOrNull() && event->isBeforeUnloadEvent())
-                toBeforeUnloadEvent(event)->setReturnValue(retval.toString(exec)->value(exec));
+            if (!retval.isUndefinedOrNull() && is<BeforeUnloadEvent>(event))
+                downcast<BeforeUnloadEvent>(*event).setReturnValue(retval.toString(exec)->value(exec));
             if (m_isAttribute) {
                 if (retval.isFalse())
                     event->preventDefault();
index bbe4115..7542035 100644 (file)
@@ -51,8 +51,8 @@ private:
     String m_text;
 };
 
-EVENT_TYPE_CASTS(BeforeTextInsertedEvent)
+} // namespace WebCore
 
-} // namespace
+SPECIALIZE_TYPE_TRAITS_EVENT(BeforeTextInsertedEvent)
 
 #endif
index ef72b73..5876696 100644 (file)
@@ -51,8 +51,8 @@ private:
     String m_returnValue;
 };
 
-EVENT_TYPE_CASTS(BeforeUnloadEvent)
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_EVENT(BeforeUnloadEvent)
+
 #endif // BeforeUnloadEvent_h
index b58e79c..c8dfd31 100644 (file)
@@ -81,8 +81,8 @@ private:
     unsigned m_columnNumber;
 };
 
-EVENT_TYPE_CASTS(ErrorEvent)
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_EVENT(ErrorEvent)
+
 #endif // ErrorEvent_h
index 1be5ebb..67f426e 100644 (file)
@@ -30,6 +30,7 @@
 #include <wtf/HashMap.h>
 #include <wtf/ListHashSet.h>
 #include <wtf/RefCounted.h>
+#include <wtf/TypeCasts.h>
 #include <wtf/text/AtomicString.h>
 
 namespace WebCore {
@@ -205,10 +206,11 @@ private:
     RefPtr<Event> m_underlyingEvent;
 };
 
-#define EVENT_TYPE_CASTS(ToValueTypeName) \
-    TYPE_CASTS_BASE(ToValueTypeName, Event, event, event->is##ToValueTypeName(), event.is##ToValueTypeName())
-
-
 } // namespace WebCore
 
+#define SPECIALIZE_TYPE_TRAITS_EVENT(ToValueTypeName) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \
+    static bool isType(const WebCore::Event& event) { return event.is##ToValueTypeName(); } \
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // Event_h
index bfca9d3..6dffc6f 100644 (file)
@@ -76,12 +76,12 @@ MouseOrFocusEventContext::~MouseOrFocusEventContext()
 
 void MouseOrFocusEventContext::handleLocalEvents(Event& event) const
 {
-    ASSERT(event.isMouseEvent() || event.isFocusEvent());
+    ASSERT(is<MouseEvent>(event) || is<FocusEvent>(event));
     if (m_relatedTarget) {
-        if (event.isMouseEvent())
-            toMouseEvent(event).setRelatedTarget(m_relatedTarget.get());
-        else if (event.isFocusEvent())
-            toFocusEvent(event).setRelatedTarget(m_relatedTarget.get());
+        if (is<MouseEvent>(event))
+            downcast<MouseEvent>(event).setRelatedTarget(m_relatedTarget.get());
+        else if (is<FocusEvent>(event))
+            downcast<FocusEvent>(event).setRelatedTarget(m_relatedTarget.get());
     }
     EventContext::handleLocalEvents(event);
 }
@@ -111,8 +111,8 @@ void TouchEventContext::handleLocalEvents(Event& event) const
     checkReachability(m_targetTouches.get());
     checkReachability(m_changedTouches.get());
 #endif
-    ASSERT(event.isTouchEvent());
-    TouchEvent& touchEvent = toTouchEvent(event);
+    ASSERT(is<TouchEvent>(event));
+    TouchEvent& touchEvent = downcast<TouchEvent>(event);
     touchEvent.setTouches(m_touches);
     touchEvent.setTargetTouches(m_targetTouches);
     touchEvent.setChangedTouches(m_changedTouches);
index c6e25ed..f7798d3 100644 (file)
@@ -342,8 +342,8 @@ bool EventDispatcher::dispatchEvent(Node* origin, PassRefPtr<Event> prpEvent)
     if (EventTarget* relatedTarget = event->relatedTarget())
         eventPath.setRelatedTarget(*node, *relatedTarget);
 #if ENABLE(TOUCH_EVENTS) && !PLATFORM(IOS)
-    if (event->isTouchEvent()) {
-        if (!eventPath.updateTouchLists(*toTouchEvent(event.get())))
+    if (is<TouchEvent>(*event)) {
+        if (!eventPath.updateTouchLists(downcast<TouchEvent>(*event)))
             return true;
     }
 #endif
index 91c887e..b966866 100644 (file)
@@ -70,8 +70,8 @@ private:
     RefPtr<EventTarget> m_relatedTarget;
 };
 
-EVENT_TYPE_CASTS(FocusEvent)
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_EVENT(FocusEvent)
+
 #endif // FocusEvent_h
index f9d829d..b403140 100644 (file)
@@ -220,9 +220,9 @@ int KeyboardEvent::which() const
 KeyboardEvent* findKeyboardEvent(Event* event)
 {
     for (Event* e = event; e; e = e->underlyingEvent())
-        if (e->isKeyboardEvent())
-            return toKeyboardEvent(e);
-    return 0;
+        if (is<KeyboardEvent>(e))
+            return downcast<KeyboardEvent>(e);
+    return nullptr;
 }
 
 } // namespace WebCore
index 8687b1f..ab94577 100644 (file)
@@ -119,10 +119,10 @@ private:
 #endif
 };
 
-EVENT_TYPE_CASTS(KeyboardEvent)
-
 KeyboardEvent* findKeyboardEvent(Event*);
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_EVENT(KeyboardEvent)
+
 #endif // KeyboardEvent_h
index a9afe60..58d3d60 100644 (file)
@@ -276,10 +276,10 @@ SimulatedMouseEvent::SimulatedMouseEvent(const AtomicString& eventType, PassRefP
     }
     setUnderlyingEvent(underlyingEvent);
 
-    if (this->underlyingEvent() && this->underlyingEvent()->isMouseEvent()) {
-        MouseEvent* mouseEvent = toMouseEvent(this->underlyingEvent());
-        m_screenLocation = mouseEvent->screenLocation();
-        initCoordinates(mouseEvent->clientLocation());
+    if (this->underlyingEvent() && is<MouseEvent>(this->underlyingEvent())) {
+        MouseEvent& mouseEvent = downcast<MouseEvent>(*this->underlyingEvent());
+        m_screenLocation = mouseEvent.screenLocation();
+        initCoordinates(mouseEvent.clientLocation());
     } else if (target) {
         m_screenLocation = target->screenRect().center();
         initCoordinates(LayoutPoint(target->clientRect().center()));
index 6dc76c8..afc7bdf 100644 (file)
@@ -132,8 +132,8 @@ private:
     SimulatedMouseEvent(const AtomicString& eventType, PassRefPtr<AbstractView>, PassRefPtr<Event> underlyingEvent, Element* target);
 };
 
-EVENT_TYPE_CASTS(MouseEvent)
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_EVENT(MouseEvent)
+
 #endif // MouseEvent_h
index f8c33d6..56c76c0 100644 (file)
@@ -2032,8 +2032,8 @@ void Node::dispatchScopedEvent(PassRefPtr<Event> event)
 bool Node::dispatchEvent(PassRefPtr<Event> event)
 {
 #if ENABLE(TOUCH_EVENTS) && !PLATFORM(IOS)
-    if (event->isTouchEvent())
-        return dispatchTouchEvent(adoptRef(toTouchEvent(event.leakRef())));
+    if (is<TouchEvent>(event.get()))
+        return dispatchTouchEvent(adoptRef(downcast<TouchEvent>(event.leakRef())));
 #endif
     return EventDispatcher::dispatchEvent(this, event);
 }
@@ -2100,11 +2100,12 @@ void Node::defaultEventHandler(Event* event)
         return;
     const AtomicString& eventType = event->type();
     if (eventType == eventNames().keydownEvent || eventType == eventNames().keypressEvent) {
-        if (event->isKeyboardEvent())
+        if (is<KeyboardEvent>(event)) {
             if (Frame* frame = document().frame())
-                frame->eventHandler().defaultKeyboardEventHandler(toKeyboardEvent(event));
+                frame->eventHandler().defaultKeyboardEventHandler(downcast<KeyboardEvent>(event));
+        }
     } else if (eventType == eventNames().clickEvent) {
-        int detail = event->isUIEvent() ? toUIEvent(event)->detail() : 0;
+        int detail = is<UIEvent>(event) ? downcast<UIEvent>(*event).detail() : 0;
         if (dispatchDOMActivateEvent(detail, event))
             event->setDefaultHandled();
 #if ENABLE(CONTEXT_MENUS)
@@ -2114,12 +2115,13 @@ void Node::defaultEventHandler(Event* event)
                 page->contextMenuController().handleContextMenuEvent(event);
 #endif
     } else if (eventType == eventNames().textInputEvent) {
-        if (event->eventInterface() == TextEventInterfaceType)
+        if (is<TextEvent>(event)) {
             if (Frame* frame = document().frame())
-                frame->eventHandler().defaultTextInputEventHandler(toTextEvent(event));
+                frame->eventHandler().defaultTextInputEventHandler(downcast<TextEvent>(event));
+        }
 #if ENABLE(PAN_SCROLLING)
-    } else if (eventType == eventNames().mousedownEvent && event->isMouseEvent()) {
-        if (toMouseEvent(event)->button() == MiddleButton) {
+    } else if (eventType == eventNames().mousedownEvent && is<MouseEvent>(event)) {
+        if (downcast<MouseEvent>(*event).button() == MiddleButton) {
             if (enclosingLinkEventParentOrSelf())
                 return;
 
@@ -2133,7 +2135,7 @@ void Node::defaultEventHandler(Event* event)
             }
         }
 #endif
-    } else if ((eventType == eventNames().wheelEvent || eventType == eventNames().mousewheelEvent) && event->eventInterface() == WheelEventInterfaceType) {
+    } else if ((eventType == eventNames().wheelEvent || eventType == eventNames().mousewheelEvent) && 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.
@@ -2143,16 +2145,16 @@ void Node::defaultEventHandler(Event* event)
         
         if (startNode && startNode->renderer())
             if (Frame* frame = document().frame())
-                frame->eventHandler().defaultWheelEventHandler(startNode, toWheelEvent(event));
+                frame->eventHandler().defaultWheelEventHandler(startNode, downcast<WheelEvent>(event));
 #if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS)
-    } else if (event->eventInterface() == TouchEventInterfaceType && eventNames().isTouchEventType(eventType)) {
+    } else if (is<TouchEvent>(event) && eventNames().isTouchEventType(eventType)) {
         RenderObject* renderer = this->renderer();
         while (renderer && (!renderer->isBox() || !toRenderBox(renderer)->canBeScrolledAndHasScrollableArea()))
             renderer = renderer->parent();
 
         if (renderer && renderer->node()) {
             if (Frame* frame = document().frame())
-                frame->eventHandler().defaultTouchEventHandler(renderer->node(), toTouchEvent(event));
+                frame->eventHandler().defaultTouchEventHandler(renderer->node(), downcast<TouchEvent>(event));
         }
 #endif
     } else if (event->type() == eventNames().webkitEditableContentChangedEvent) {
index c556e15..88d061f 100644 (file)
@@ -87,8 +87,8 @@ namespace WebCore {
         Vector<DictationAlternative> m_dictationAlternatives;
     };
 
-EVENT_TYPE_CASTS(TextEvent)
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_EVENT(TextEvent)
+
 #endif // TextEvent_h
index ada0e87..3a688b6 100644 (file)
@@ -86,10 +86,10 @@ private:
     RefPtr<TouchList> m_changedTouches;
 };
 
-EVENT_TYPE_CASTS(TouchEvent)
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_EVENT(TouchEvent)
+
 #endif // ENABLE(TOUCH_EVENTS)
 
 #endif // TouchEvent_h
index d31ebbc..aba8759 100644 (file)
@@ -85,8 +85,8 @@ private:
     int m_detail;
 };
 
-EVENT_TYPE_CASTS(UIEvent)
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_EVENT(UIEvent)
+
 #endif // UIEvent_h
index de3bdd8..6705d4a 100644 (file)
@@ -114,8 +114,8 @@ private:
     bool m_initializedWithPlatformWheelEvent;
 };
 
-EVENT_TYPE_CASTS(WheelEvent)
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_EVENT(WheelEvent)
+
 #endif // WheelEvent_h
index 5c5335f..915e2aa 100644 (file)
@@ -152,7 +152,7 @@ bool HTMLAnchorElement::isKeyboardFocusable(KeyboardEvent* event) const
 
 static void appendServerMapMousePosition(StringBuilder& url, Event* event)
 {
-    if (!event->isMouseEvent())
+    if (!is<MouseEvent>(event))
         return;
 
     ASSERT(event->target());
@@ -170,7 +170,7 @@ static void appendServerMapMousePosition(StringBuilder& url, Event* event)
     RenderImage& renderer = toRenderImage(*imageElement.renderer());
 
     // FIXME: This should probably pass true for useTransforms.
-    FloatPoint absolutePosition = renderer.absoluteToLocal(FloatPoint(toMouseEvent(event)->pageX(), toMouseEvent(event)->pageY()));
+    FloatPoint absolutePosition = renderer.absoluteToLocal(FloatPoint(downcast<MouseEvent>(*event).pageX(), downcast<MouseEvent>(*event).pageY()));
     int x = absolutePosition.x();
     int y = absolutePosition.y();
     url.append('?');
@@ -196,9 +196,9 @@ void HTMLAnchorElement::defaultEventHandler(Event* event)
         if (hasEditableStyle()) {
             // This keeps track of the editable block that the selection was in (if it was in one) just before the link was clicked
             // for the LiveWhenNotFocused editable link behavior
-            if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && toMouseEvent(event)->button() != RightButton && document().frame()) {
+            if (event->type() == eventNames().mousedownEvent && is<MouseEvent>(event) && downcast<MouseEvent>(*event).button() != RightButton && document().frame()) {
                 setRootEditableElementForSelectionOnMouseDown(document().frame()->selection().selection().rootEditableElement());
-                m_wasShiftKeyDownOnMouseDown = toMouseEvent(event)->shiftKey();
+                m_wasShiftKeyDownOnMouseDown = downcast<MouseEvent>(*event).shiftKey();
             } else if (event->type() == eventNames().mouseoverEvent) {
                 // These are cleared on mouseover and not mouseout because their values are needed for drag events,
                 // but drag events happen after mouse out events.
@@ -555,9 +555,9 @@ void HTMLAnchorElement::handleClick(Event* event)
 
 HTMLAnchorElement::EventType HTMLAnchorElement::eventType(Event* event)
 {
-    if (!event->isMouseEvent())
+    if (!is<MouseEvent>(event))
         return NonMouseEvent;
-    return toMouseEvent(event)->shiftKey() ? MouseEventWithShiftKey : MouseEventWithoutShiftKey;
+    return downcast<MouseEvent>(*event).shiftKey() ? MouseEventWithShiftKey : MouseEventWithoutShiftKey;
 }
 
 bool HTMLAnchorElement::treatLinkAsLiveForEventType(EventType eventType) const
@@ -592,12 +592,12 @@ bool HTMLAnchorElement::treatLinkAsLiveForEventType(EventType eventType) const
 
 bool isEnterKeyKeydownEvent(Event* event)
 {
-    return event->type() == eventNames().keydownEvent && event->isKeyboardEvent() && toKeyboardEvent(event)->keyIdentifier() == "Enter";
+    return event->type() == eventNames().keydownEvent && is<KeyboardEvent>(event) && downcast<KeyboardEvent>(*event).keyIdentifier() == "Enter";
 }
 
 bool isLinkClick(Event* event)
 {
-    return event->type() == eventNames().clickEvent && (!event->isMouseEvent() || toMouseEvent(event)->button() != RightButton);
+    return event->type() == eventNames().clickEvent && (!is<MouseEvent>(event) || downcast<MouseEvent>(*event).button() != RightButton);
 }
 
 bool shouldProhibitLinks(Element* element)
index 92e26a7..4529f8b 100644 (file)
@@ -123,28 +123,29 @@ void HTMLButtonElement::defaultEventHandler(Event* event)
         }
     }
 
-    if (event->isKeyboardEvent()) {
-        if (event->type() == eventNames().keydownEvent && toKeyboardEvent(event)->keyIdentifier() == "U+0020") {
+    if (is<KeyboardEvent>(event)) {
+        KeyboardEvent& keyboardEvent = downcast<KeyboardEvent>(*event);
+        if (keyboardEvent.type() == eventNames().keydownEvent && keyboardEvent.keyIdentifier() == "U+0020") {
             setActive(true, true);
             // No setDefaultHandled() - IE dispatches a keypress in this case.
             return;
         }
-        if (event->type() == eventNames().keypressEvent) {
-            switch (toKeyboardEvent(event)->charCode()) {
+        if (keyboardEvent.type() == eventNames().keypressEvent) {
+            switch (keyboardEvent.charCode()) {
                 case '\r':
-                    dispatchSimulatedClick(event);
-                    event->setDefaultHandled();
+                    dispatchSimulatedClick(&keyboardEvent);
+                    keyboardEvent.setDefaultHandled();
                     return;
                 case ' ':
                     // Prevent scrolling down the page.
-                    event->setDefaultHandled();
+                    keyboardEvent.setDefaultHandled();
                     return;
             }
         }
-        if (event->type() == eventNames().keyupEvent && toKeyboardEvent(event)->keyIdentifier() == "U+0020") {
+        if (keyboardEvent.type() == eventNames().keyupEvent && keyboardEvent.keyIdentifier() == "U+0020") {
             if (active())
-                dispatchSimulatedClick(event);
-            event->setDefaultHandled();
+                dispatchSimulatedClick(&keyboardEvent);
+            keyboardEvent.setDefaultHandled();
             return;
         }
     }
index 4d07bfc..35ea52c 100644 (file)
@@ -187,15 +187,15 @@ void HTMLFrameSetElement::willAttachRenderers()
         m_noresize = containingFrameSet->noResize();
 }
 
-void HTMLFrameSetElement::defaultEventHandler(Event* evt)
+void HTMLFrameSetElement::defaultEventHandler(Event* event)
 {
-    if (evt->isMouseEvent() && !m_noresize && renderer() && renderer()->isFrameSet()) {
-        if (toRenderFrameSet(renderer())->userResize(toMouseEvent(evt))) {
-            evt->setDefaultHandled();
+    if (is<MouseEvent>(event) && !m_noresize && renderer() && renderer()->isFrameSet()) {
+        if (toRenderFrameSet(renderer())->userResize(downcast<MouseEvent>(event))) {
+            event->setDefaultHandled();
             return;
         }
     }
-    HTMLElement::defaultEventHandler(evt);
+    HTMLElement::defaultEventHandler(event);
 }
 
 bool HTMLFrameSetElement::willRecalcStyle(Style::Change)
index 439a0a1..eaf2654 100644 (file)
@@ -1032,7 +1032,7 @@ void HTMLInputElement::willDispatchEvent(Event& event, InputElementClickState& s
 {
     if (event.type() == eventNames().textInputEvent && m_inputType->shouldSubmitImplicitly(&event))
         event.stopPropagation();
-    if (event.type() == eventNames().clickEvent && event.isMouseEvent() && toMouseEvent(&event)->button() == LeftButton) {
+    if (event.type() == eventNames().clickEvent && is<MouseEvent>(event) && downcast<MouseEvent>(event).button() == LeftButton) {
         m_inputType->willDispatchClick(state);
         state.stateful = true;
     }
@@ -1045,22 +1045,22 @@ void HTMLInputElement::didDispatchClickEvent(Event& event, const InputElementCli
 
 void HTMLInputElement::defaultEventHandler(Event* evt)
 {
-    if (evt->isMouseEvent() && evt->type() == eventNames().clickEvent && toMouseEvent(evt)->button() == LeftButton) {
-        m_inputType->handleClickEvent(toMouseEvent(evt));
+    if (is<MouseEvent>(evt) && evt->type() == eventNames().clickEvent && downcast<MouseEvent>(*evt).button() == LeftButton) {
+        m_inputType->handleClickEvent(downcast<MouseEvent>(evt));
         if (evt->defaultHandled())
             return;
     }
 
 #if ENABLE(TOUCH_EVENTS)
-    if (evt->isTouchEvent()) {
-        m_inputType->handleTouchEvent(toTouchEvent(evt));
+    if (is<TouchEvent>(evt)) {
+        m_inputType->handleTouchEvent(downcast<TouchEvent>(evt));
         if (evt->defaultHandled())
             return;
     }
 #endif
 
-    if (evt->isKeyboardEvent() && evt->type() == eventNames().keydownEvent) {
-        m_inputType->handleKeydownEvent(toKeyboardEvent(evt));
+    if (is<KeyboardEvent>(evt) && evt->type() == eventNames().keydownEvent) {
+        m_inputType->handleKeydownEvent(downcast<KeyboardEvent>(evt));
         if (evt->defaultHandled())
             return;
     }
@@ -1086,16 +1086,17 @@ void HTMLInputElement::defaultEventHandler(Event* evt)
 
     // Use key press event here since sending simulated mouse events
     // on key down blocks the proper sending of the key press event.
-    if (evt->isKeyboardEvent() && evt->type() == eventNames().keypressEvent) {
-        m_inputType->handleKeypressEvent(toKeyboardEvent(evt));
-        if (evt->defaultHandled())
-            return;
-    }
-
-    if (evt->isKeyboardEvent() && evt->type() == eventNames().keyupEvent) {
-        m_inputType->handleKeyupEvent(toKeyboardEvent(evt));
-        if (evt->defaultHandled())
-            return;
+    if (is<KeyboardEvent>(evt)) {
+        KeyboardEvent& keyboardEvent = downcast<KeyboardEvent>(*evt);
+        if (keyboardEvent.type() == eventNames().keypressEvent) {
+            m_inputType->handleKeypressEvent(&keyboardEvent);
+            if (keyboardEvent.defaultHandled())
+                return;
+        } else if (keyboardEvent.type() == eventNames().keyupEvent) {
+            m_inputType->handleKeyupEvent(&keyboardEvent);
+            if (keyboardEvent.defaultHandled())
+                return;
+        }
     }
 
     if (m_inputType->shouldSubmitImplicitly(evt)) {
@@ -1117,11 +1118,11 @@ void HTMLInputElement::defaultEventHandler(Event* evt)
         return;
     }
 
-    if (evt->isBeforeTextInsertedEvent())
-        m_inputType->handleBeforeTextInsertedEvent(toBeforeTextInsertedEvent(evt));
+    if (is<BeforeTextInsertedEvent>(evt))
+        m_inputType->handleBeforeTextInsertedEvent(downcast<BeforeTextInsertedEvent>(evt));
 
-    if (evt->isMouseEvent() && evt->type() == eventNames().mousedownEvent) {
-        m_inputType->handleMouseDownEvent(toMouseEvent(evt));
+    if (is<MouseEvent>(evt) && evt->type() == eventNames().mousedownEvent) {
+        m_inputType->handleMouseDownEvent(downcast<MouseEvent>(evt));
         if (evt->defaultHandled())
             return;
     }
index 3690e9c..3b86884 100644 (file)
@@ -747,11 +747,11 @@ void HTMLPlugInImageElement::defaultEventHandler(Event* event)
 {
     RenderElement* r = renderer();
     if (r && r->isEmbeddedObject()) {
-        if (isPlugInImageElement() && displayState() == WaitingForSnapshot && event->isMouseEvent() && event->type() == eventNames().clickEvent) {
-            MouseEvent* mouseEvent = toMouseEvent(event);
-            if (mouseEvent->button() == LeftButton) {
-                userDidClickSnapshot(mouseEvent, true);
-                event->setDefaultHandled();
+        if (displayState() == WaitingForSnapshot && is<MouseEvent>(event) && event->type() == eventNames().clickEvent) {
+            MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
+            if (mouseEvent.button() == LeftButton) {
+                userDidClickSnapshot(&mouseEvent, true);
+                mouseEvent.setDefaultHandled();
                 return;
             }
         }
index ecc87e2..f9648db 100644 (file)
@@ -1146,10 +1146,11 @@ void HTMLSelectElement::menuListDefaultEventHandler(Event* event)
     RefPtr<RenderTheme> renderTheme = page ? &page->theme() : RenderTheme::defaultTheme();
 
     if (event->type() == eventNames().keydownEvent) {
-        if (!event->isKeyboardEvent())
+        if (!is<KeyboardEvent>(event))
             return;
 
-        if (platformHandleKeydownEvent(toKeyboardEvent(event)))
+        KeyboardEvent& keyboardEvent = downcast<KeyboardEvent>(*event);
+        if (platformHandleKeydownEvent(&keyboardEvent))
             return;
 
         // When using spatial navigation, we want to be able to navigate away
@@ -1160,7 +1161,7 @@ void HTMLSelectElement::menuListDefaultEventHandler(Event* event)
                 return;
         }
 
-        const String& keyIdentifier = toKeyboardEvent(event)->keyIdentifier();
+        const String& keyIdentifier = keyboardEvent.keyIdentifier();
         bool handled = true;
         const Vector<HTMLElement*>& listItems = this->listItems();
         int listIndex = optionToListIndex(selectedIndex());
@@ -1192,22 +1193,23 @@ void HTMLSelectElement::menuListDefaultEventHandler(Event* event)
             selectOption(listToOptionIndex(listIndex), DeselectOtherOptions | DispatchChangeEvent | UserDriven);
 
         if (handled)
-            event->setDefaultHandled();
+            keyboardEvent.setDefaultHandled();
     }
 
     // Use key press event here since sending simulated mouse events
     // on key down blocks the proper sending of the key press event.
     if (event->type() == eventNames().keypressEvent) {
-        if (!event->isKeyboardEvent())
+        if (!is<KeyboardEvent>(event))
             return;
 
-        int keyCode = toKeyboardEvent(event)->keyCode();
+        KeyboardEvent& keyboardEvent = downcast<KeyboardEvent>(*event);
+        int keyCode = keyboardEvent.keyCode();
         bool handled = false;
 
         if (keyCode == ' ' && isSpatialNavigationEnabled(document().frame())) {
             // Use space to toggle arrow key handling for selection change or spatial navigation.
             m_activeSelectionState = !m_activeSelectionState;
-            event->setDefaultHandled();
+            keyboardEvent.setDefaultHandled();
             return;
         }
 
@@ -1246,17 +1248,17 @@ void HTMLSelectElement::menuListDefaultEventHandler(Event* event)
                 handled = true;
             } else if (keyCode == '\r') {
                 if (form())
-                    form()->submitImplicitly(event, false);
+                    form()->submitImplicitly(&keyboardEvent, false);
                 dispatchChangeEventForMenuList();
                 handled = true;
             }
         }
 
         if (handled)
-            event->setDefaultHandled();
+            keyboardEvent.setDefaultHandled();
     }
 
-    if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && toMouseEvent(event)->button() == LeftButton) {
+    if (event->type() == eventNames().mousedownEvent && is<MouseEvent>(event) && downcast<MouseEvent>(*event).button() == LeftButton) {
         focus();
 #if !PLATFORM(IOS)
         if (renderer() && renderer()->isMenuList()) {
@@ -1336,35 +1338,35 @@ void HTMLSelectElement::listBoxDefaultEventHandler(Event* event)
 {
     const Vector<HTMLElement*>& listItems = this->listItems();
 
-    if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && toMouseEvent(event)->button() == LeftButton) {
+    if (event->type() == eventNames().mousedownEvent && is<MouseEvent>(event) && downcast<MouseEvent>(*event).button() == LeftButton) {
         focus();
         // Calling focus() may remove or change our renderer, in which case we don't want to handle the event further.
         if (!renderer() || !renderer()->isListBox())
             return;
 
         // Convert to coords relative to the list box if needed.
-        MouseEvent* mouseEvent = toMouseEvent(event);
-        IntPoint localOffset = roundedIntPoint(renderer()->absoluteToLocal(mouseEvent->absoluteLocation(), UseTransforms));
+        MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
+        IntPoint localOffset = roundedIntPoint(renderer()->absoluteToLocal(mouseEvent.absoluteLocation(), UseTransforms));
         int listIndex = toRenderListBox(renderer())->listIndexAtOffset(toIntSize(localOffset));
         if (listIndex >= 0) {
             if (!isDisabledFormControl()) {
 #if PLATFORM(COCOA)
-                updateSelectedState(listIndex, mouseEvent->metaKey(), mouseEvent->shiftKey());
+                updateSelectedState(listIndex, mouseEvent.metaKey(), mouseEvent.shiftKey());
 #else
-                updateSelectedState(listIndex, mouseEvent->ctrlKey(), mouseEvent->shiftKey());
+                updateSelectedState(listIndex, mouseEvent.ctrlKey(), mouseEvent.shiftKey());
 #endif
             }
             if (Frame* frame = document().frame())
                 frame->eventHandler().setMouseDownMayStartAutoscroll();
 
-            event->setDefaultHandled();
+            mouseEvent.setDefaultHandled();
         }
-    } else if (event->type() == eventNames().mousemoveEvent && event->isMouseEvent() && !toRenderBox(renderer())->canBeScrolledAndHasScrollableArea()) {
-        MouseEvent* mouseEvent = toMouseEvent(event);
-        if (mouseEvent->button() != LeftButton || !mouseEvent->buttonDown())
+    } else if (event->type() == eventNames().mousemoveEvent && is<MouseEvent>(event) && !toRenderBox(renderer())->canBeScrolledAndHasScrollableArea()) {
+        MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
+        if (mouseEvent.button() != LeftButton || !mouseEvent.buttonDown())
             return;
 
-        IntPoint localOffset = roundedIntPoint(renderer()->absoluteToLocal(mouseEvent->absoluteLocation(), UseTransforms));
+        IntPoint localOffset = roundedIntPoint(renderer()->absoluteToLocal(mouseEvent.absoluteLocation(), UseTransforms));
         int listIndex = toRenderListBox(renderer())->listIndexAtOffset(toIntSize(localOffset));
         if (listIndex >= 0) {
             if (!isDisabledFormControl()) {
@@ -1381,9 +1383,9 @@ void HTMLSelectElement::listBoxDefaultEventHandler(Event* event)
                     updateListBoxSelection(true);
                 }
             }
-            event->setDefaultHandled();
+            mouseEvent.setDefaultHandled();
         }
-    } else if (event->type() == eventNames().mouseupEvent && event->isMouseEvent() && toMouseEvent(event)->button() == LeftButton && document().frame()->eventHandler().autoscrollRenderer() != renderer()) {
+    } else if (event->type() == eventNames().mouseupEvent && is<MouseEvent>(event) && downcast<MouseEvent>(*event).button() == LeftButton && document().frame()->eventHandler().autoscrollRenderer() != renderer()) {
         // This click or drag event was not over any of the options.
         if (m_lastOnChangeSelection.isEmpty())
             return;
@@ -1392,9 +1394,11 @@ void HTMLSelectElement::listBoxDefaultEventHandler(Event* event)
         // timer stops.
         listBoxOnChange();
     } else if (event->type() == eventNames().keydownEvent) {
-        if (!event->isKeyboardEvent())
+        if (!is<KeyboardEvent>(event))
             return;
-        const String& keyIdentifier = toKeyboardEvent(event)->keyIdentifier();
+
+        KeyboardEvent& keyboardEvent = downcast<KeyboardEvent>(*event);
+        const String& keyIdentifier = keyboardEvent.keyIdentifier();
 
         bool handled = false;
         int endIndex = 0;
@@ -1456,15 +1460,15 @@ void HTMLSelectElement::listBoxDefaultEventHandler(Event* event)
 #if PLATFORM(COCOA)
             m_allowsNonContiguousSelection = m_multiple && isSpatialNavigationEnabled(document().frame());
 #else
-            m_allowsNonContiguousSelection = m_multiple && (isSpatialNavigationEnabled(document().frame()) || toKeyboardEvent(event)->ctrlKey());
+            m_allowsNonContiguousSelection = m_multiple && (isSpatialNavigationEnabled(document().frame()) || keyboardEvent.ctrlKey());
 #endif
-            bool selectNewItem = toKeyboardEvent(event)->shiftKey() || !m_allowsNonContiguousSelection;
+            bool selectNewItem = keyboardEvent.shiftKey() || !m_allowsNonContiguousSelection;
 
             if (selectNewItem)
                 m_activeSelectionState = true;
             // If the anchor is unitialized, or if we're going to deselect all
             // other options, then set the anchor index equal to the end index.
-            bool deselectOthers = !m_multiple || (!toKeyboardEvent(event)->shiftKey() && selectNewItem);
+            bool deselectOthers = !m_multiple || (!keyboardEvent.shiftKey() && selectNewItem);
             if (m_activeSelectionAnchorIndex < 0 || deselectOthers) {
                 if (deselectOthers)
                     deselectItemsWithoutValidation();
@@ -1478,17 +1482,18 @@ void HTMLSelectElement::listBoxDefaultEventHandler(Event* event)
             } else
                 scrollToSelection();
 
-            event->setDefaultHandled();
+            keyboardEvent.setDefaultHandled();
         }
     } else if (event->type() == eventNames().keypressEvent) {
-        if (!event->isKeyboardEvent())
+        if (!is<KeyboardEvent>(event))
             return;
-        int keyCode = toKeyboardEvent(event)->keyCode();
+        KeyboardEvent& keyboardEvent = downcast<KeyboardEvent>(*event);
+        int keyCode = keyboardEvent.keyCode();
 
         if (keyCode == '\r') {
             if (form())
-                form()->submitImplicitly(event, false);
-            event->setDefaultHandled();
+                form()->submitImplicitly(&keyboardEvent, false);
+            keyboardEvent.setDefaultHandled();
         } else if (m_multiple && keyCode == ' ' && m_allowsNonContiguousSelection) {
             // Use space to toggle selection change.
             m_activeSelectionState = !m_activeSelectionState;
@@ -1497,7 +1502,7 @@ void HTMLSelectElement::listBoxDefaultEventHandler(Event* event)
             ASSERT(is<HTMLOptionElement>(*listItems[m_activeSelectionEndIndex]));
             updateSelectedState(m_activeSelectionEndIndex, true /*multi*/, false /*shift*/);
             listBoxOnChange();
-            event->setDefaultHandled();
+            keyboardEvent.setDefaultHandled();
         }
     }
 }
@@ -1523,9 +1528,9 @@ void HTMLSelectElement::defaultEventHandler(Event* event)
     if (event->defaultHandled())
         return;
 
-    if (event->type() == eventNames().keypressEvent && event->isKeyboardEvent()) {
-        KeyboardEvent* keyboardEvent = toKeyboardEvent(event);
-        if (!keyboardEvent->ctrlKey() && !keyboardEvent->altKey() && !keyboardEvent->metaKey() && u_isprint(keyboardEvent->charCode())) {
+    if (event->type() == eventNames().keypressEvent && is<KeyboardEvent>(event)) {
+        KeyboardEvent& keyboardEvent = downcast<KeyboardEvent>(*event);
+        if (!keyboardEvent.ctrlKey() && !keyboardEvent.altKey() && !keyboardEvent.metaKey() && u_isprint(keyboardEvent.charCode())) {
             typeAheadFind(keyboardEvent);
             event->setDefaultHandled();
             return;
@@ -1565,9 +1570,9 @@ String HTMLSelectElement::optionAtIndex(int index) const
     return downcast<HTMLOptionElement>(*element).textIndentedToRespectGroupLabel();
 }
 
-void HTMLSelectElement::typeAheadFind(KeyboardEvent* event)
+void HTMLSelectElement::typeAheadFind(KeyboardEvent& event)
 {
-    int index = m_typeAhead.handleEvent(event, TypeAhead::MatchPrefix | TypeAhead::CycleFirstChar);
+    int index = m_typeAhead.handleEvent(&event, TypeAhead::MatchPrefix | TypeAhead::CycleFirstChar);
     if (index < 0)
         return;
     selectOption(listToOptionIndex(index), DeselectOtherOptions | DispatchChangeEvent | UserDriven);
index 27fefd6..da7f15a 100644 (file)
@@ -151,7 +151,7 @@ private:
     void recalcListItems(bool updateSelectedStates = true) const;
 
     void deselectItems(HTMLOptionElement* excludeElement = 0);
-    void typeAheadFind(KeyboardEvent*);
+    void typeAheadFind(KeyboardEvent&);
     void saveLastSelection();
 
     virtual InsertionNotificationRequest insertedInto(ContainerNode&) override;
index ec6c3a2..112d2fd 100644 (file)
@@ -126,28 +126,29 @@ void HTMLSummaryElement::defaultEventHandler(Event* event)
             return;
         }
 
-        if (event->isKeyboardEvent()) {
-            if (event->type() == eventNames().keydownEvent && toKeyboardEvent(event)->keyIdentifier() == "U+0020") {
+        if (is<KeyboardEvent>(event)) {
+            KeyboardEvent& keyboardEvent = downcast<KeyboardEvent>(*event);
+            if (keyboardEvent.type() == eventNames().keydownEvent && keyboardEvent.keyIdentifier() == "U+0020") {
                 setActive(true, true);
                 // No setDefaultHandled() - IE dispatches a keypress in this case.
                 return;
             }
-            if (event->type() == eventNames().keypressEvent) {
-                switch (toKeyboardEvent(event)->charCode()) {
+            if (keyboardEvent.type() == eventNames().keypressEvent) {
+                switch (keyboardEvent.charCode()) {
                 case '\r':
                     dispatchSimulatedClick(event);
-                    event->setDefaultHandled();
+                    keyboardEvent.setDefaultHandled();
                     return;
                 case ' ':
                     // Prevent scrolling down the page.
-                    event->setDefaultHandled();
+                    keyboardEvent.setDefaultHandled();
                     return;
                 }
             }
-            if (event->type() == eventNames().keyupEvent && toKeyboardEvent(event)->keyIdentifier() == "U+0020") {
+            if (keyboardEvent.type() == eventNames().keyupEvent && keyboardEvent.keyIdentifier() == "U+0020") {
                 if (active())
                     dispatchSimulatedClick(event);
-                event->setDefaultHandled();
+                keyboardEvent.setDefaultHandled();
                 return;
             }
         }
index 2a4c5c5..35fae12 100644 (file)
@@ -270,8 +270,8 @@ void HTMLTextAreaElement::defaultEventHandler(Event* event)
 {
     if (renderer() && (event->isMouseEvent() || event->isDragEvent() || event->eventInterface() == WheelEventInterfaceType || event->type() == eventNames().blurEvent))
         forwardEvent(event);
-    else if (renderer() && event->isBeforeTextInsertedEvent())
-        handleBeforeTextInsertedEvent(toBeforeTextInsertedEvent(event));
+    else if (renderer() && is<BeforeTextInsertedEvent>(event))
+        handleBeforeTextInsertedEvent(downcast<BeforeTextInsertedEvent>(event));
 
     HTMLTextFormControlElement::defaultEventHandler(event);
 }
index 1ebec77..cc9bdc9 100644 (file)
@@ -398,8 +398,8 @@ void ImageEventListener::handleEvent(ScriptExecutionContext*, Event* event)
 {
     if (event->type() == eventNames().resizeEvent)
         m_document.windowSizeChanged();
-    else if (event->type() == eventNames().clickEvent && event->isMouseEvent()) {
-        MouseEvent& mouseEvent = toMouseEvent(*event);
+    else if (event->type() == eventNames().clickEvent && is<MouseEvent>(event)) {
+        MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
         m_document.imageClicked(mouseEvent.x(), mouseEvent.y());
     }
 }
index d0e25be..289a9ed 100644 (file)
@@ -89,8 +89,8 @@ void ImageInputType::handleDOMActivateEvent(Event* event)
     m_clickLocation = IntPoint();
     if (event->underlyingEvent()) {
         Event& underlyingEvent = *event->underlyingEvent();
-        if (underlyingEvent.isMouseEvent()) {
-            MouseEvent& mouseEvent = toMouseEvent(underlyingEvent);
+        if (is<MouseEvent>(underlyingEvent)) {
+            MouseEvent& mouseEvent = downcast<MouseEvent>(underlyingEvent);
             if (!mouseEvent.isSimulated())
                 m_clickLocation = IntPoint(mouseEvent.offsetX(), mouseEvent.offsetY());
         }
index 157026d..3b227ab 100644 (file)
@@ -471,7 +471,7 @@ void InputType::forwardEvent(Event*)
 
 bool InputType::shouldSubmitImplicitly(Event* event)
 {
-    return event->isKeyboardEvent() && event->type() == eventNames().keypressEvent && toKeyboardEvent(event)->charCode() == '\r';
+    return is<KeyboardEvent>(event) && event->type() == eventNames().keypressEvent && downcast<KeyboardEvent>(*event).charCode() == '\r';
 }
 
 PassRefPtr<HTMLFormElement> InputType::formForSubmission() const
index 9f07fa3..7da9bb8 100644 (file)
@@ -204,19 +204,19 @@ void MediaDocument::defaultEventHandler(Event* event)
     if (!is<ContainerNode>(targetNode))
         return;
     ContainerNode& targetContainer = downcast<ContainerNode>(*targetNode);
-    if (event->type() == eventNames().keydownEvent && event->isKeyboardEvent()) {
+    if (event->type() == eventNames().keydownEvent && is<KeyboardEvent>(event)) {
         HTMLVideoElement* video = descendentVideoElement(targetContainer);
         if (!video)
             return;
 
-        KeyboardEvent* keyboardEvent = toKeyboardEvent(event);
-        if (keyboardEvent->keyIdentifier() == "U+0020") { // space
+        KeyboardEvent& keyboardEvent = downcast<KeyboardEvent>(*event);
+        if (keyboardEvent.keyIdentifier() == "U+0020") { // space
             if (video->paused()) {
                 if (video->canPlay())
                     video->play();
             } else
                 video->pause();
-            event->setDefaultHandled();
+            keyboardEvent.setDefaultHandled();
         }
     }
 }
index e150149..7a9fe14 100644 (file)
@@ -206,7 +206,8 @@ void TextFieldInputType::handleBlurEvent()
 
 bool TextFieldInputType::shouldSubmitImplicitly(Event* event)
 {
-    return (event->type() == eventNames().textInputEvent && event->eventInterface() == TextEventInterfaceType && toTextEvent(event)->data() == "\n") || InputType::shouldSubmitImplicitly(event);
+    return (event->type() == eventNames().textInputEvent && is<TextEvent>(event) && downcast<TextEvent>(*event).data() == "\n")
+        || InputType::shouldSubmitImplicitly(event);
 }
 
 RenderPtr<RenderElement> TextFieldInputType::createInputRenderer(PassRef<RenderStyle> style)
index 9e83e62..263863b 100644 (file)
@@ -196,7 +196,7 @@ MediaControlVolumeSliderElement::MediaControlVolumeSliderElement(Document& docum
 void MediaControlVolumeSliderElement::defaultEventHandler(Event* event)
 {
     // Left button is 0. Rejects mouse events not from left button.
-    if (event->isMouseEvent() && toMouseEvent(event)->button())
+    if (is<MouseEvent>(event) && downcast<MouseEvent>(*event).button())
         return;
 
     if (!renderer())
index d5a456b..32f3a53 100644 (file)
@@ -221,8 +221,8 @@ void MediaControlPanelElement::defaultEventHandler(Event* event)
 {
     MediaControlDivElement::defaultEventHandler(event);
 
-    if (event->isMouseEvent()) {
-        LayoutPoint location = toMouseEvent(event)->absoluteLocation();
+    if (is<MouseEvent>(event)) {
+        LayoutPoint location = downcast<MouseEvent>(*event).absoluteLocation();
         if (event->type() == eventNames().mousedownEvent && event->target() == this) {
             startDrag(location);
             event->setDefaultHandled();
@@ -337,12 +337,12 @@ RenderPtr<RenderElement> MediaControlVolumeSliderContainerElement::createElement
 
 void MediaControlVolumeSliderContainerElement::defaultEventHandler(Event* event)
 {
-    if (!event->isMouseEvent() || event->type() != eventNames().mouseoutEvent)
+    if (!is<MouseEvent>(event) || event->type() != eventNames().mouseoutEvent)
         return;
 
     // Poor man's mouseleave event detection.
-    MouseEvent* mouseEvent = toMouseEvent(event);
-    EventTarget* relatedTarget = mouseEvent->relatedTarget();
+    MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
+    EventTarget* relatedTarget = mouseEvent.relatedTarget();
     if (!relatedTarget || !relatedTarget->toNode())
         return;
 
@@ -851,7 +851,7 @@ PassRefPtr<MediaControlTimelineElement> MediaControlTimelineElement::create(Docu
 void MediaControlTimelineElement::defaultEventHandler(Event* event)
 {
     // Left button is 0. Rejects mouse events not from left button.
-    if (event->isMouseEvent() && toMouseEvent(event)->button())
+    if (is<MouseEvent>(event) && downcast<MouseEvent>(*event).button())
         return;
 
     if (!renderer())
index fa1bebf..4d3ecf8 100644 (file)
@@ -366,9 +366,9 @@ void MediaControls::stopHideFullscreenControlsTimer()
 
 bool MediaControls::containsRelatedTarget(Event* event)
 {
-    if (!event->isMouseEvent())
+    if (!is<MouseEvent>(event))
         return false;
-    EventTarget* relatedTarget = toMouseEvent(event)->relatedTarget();
+    EventTarget* relatedTarget = downcast<MouseEvent>(*event).relatedTarget();
     if (!relatedTarget)
         return false;
     return contains(relatedTarget->toNode());
index 1196a71..8c84da7 100644 (file)
@@ -588,10 +588,10 @@ void MediaControlsAppleEventListener::handleEvent(ScriptExecutionContext*, Event
 {
     if (event->type() == eventNames().clickEvent)
         m_mediaControls->handleClickEvent(event);
-    else if ((event->type() == eventNames().wheelEvent || event->type() == eventNames().mousewheelEvent) && event->eventInterface() == WheelEventInterfaceType) {
-        WheelEvent* wheelEvent = toWheelEvent(event);
-        if (m_mediaControls->shouldClosedCaptionsContainerPreventPageScrolling(wheelEvent->wheelDeltaY()))
-            event->preventDefault();
+    else if ((event->type() == eventNames().wheelEvent || event->type() == eventNames().mousewheelEvent) && is<WheelEvent>(event)) {
+        WheelEvent& wheelEvent = downcast<WheelEvent>(*event);
+        if (m_mediaControls->shouldClosedCaptionsContainerPreventPageScrolling(wheelEvent.wheelDeltaY()))
+            wheelEvent.preventDefault();
     }
 }
 
index 81c2068..22be63b 100644 (file)
@@ -333,7 +333,7 @@ void SliderThumbElement::stopDragging()
 #if !PLATFORM(IOS)
 void SliderThumbElement::defaultEventHandler(Event* event)
 {
-    if (!event->isMouseEvent()) {
+    if (!is<MouseEvent>(event)) {
         HTMLDivElement::defaultEventHandler(event);
         return;
     }
@@ -347,9 +347,9 @@ void SliderThumbElement::defaultEventHandler(Event* event)
         return;
     }
 
-    MouseEvent* mouseEvent = toMouseEvent(event);
-    bool isLeftButton = mouseEvent->button() == LeftButton;
-    const AtomicString& eventType = event->type();
+    MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
+    bool isLeftButton = mouseEvent.button() == LeftButton;
+    const AtomicString& eventType = mouseEvent.type();
 
     // We intentionally do not call event->setDefaultHandled() here because
     // MediaControlTimelineElement::defaultEventHandler() wants to handle these
@@ -362,11 +362,11 @@ void SliderThumbElement::defaultEventHandler(Event* event)
         return;
     } else if (eventType == eventNames().mousemoveEvent) {
         if (m_inDragMode)
-            setPositionFromPoint(mouseEvent->absoluteLocation());
+            setPositionFromPoint(mouseEvent.absoluteLocation());
         return;
     }
 
-    HTMLDivElement::defaultEventHandler(event);
+    HTMLDivElement::defaultEventHandler(&mouseEvent);
 }
 #endif
 
index 503b35b..38a40a4 100644 (file)
@@ -67,7 +67,7 @@ void SpinButtonElement::willDetachRenderers()
 
 void SpinButtonElement::defaultEventHandler(Event* event)
 {
-    if (!event->isMouseEvent()) {
+    if (!is<MouseEvent>(event)) {
         if (!event->defaultHandled())
             HTMLDivElement::defaultEventHandler(event);
         return;
@@ -86,9 +86,9 @@ void SpinButtonElement::defaultEventHandler(Event* event)
         return;
     }
 
-    MouseEvent* mouseEvent = toMouseEvent(event);
-    IntPoint local = roundedIntPoint(box->absoluteToLocal(mouseEvent->absoluteLocation(), UseTransforms));
-    if (mouseEvent->type() == eventNames().mousedownEvent && mouseEvent->button() == LeftButton) {
+    MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
+    IntPoint local = roundedIntPoint(box->absoluteToLocal(mouseEvent.absoluteLocation(), UseTransforms));
+    if (mouseEvent.type() == eventNames().mousedownEvent && mouseEvent.button() == LeftButton) {
         if (box->pixelSnappedBorderBoxRect().contains(local)) {
             // The following functions of HTMLInputElement may run JavaScript
             // code which detaches this shadow node. We need to take a reference
@@ -107,11 +107,11 @@ void SpinButtonElement::defaultEventHandler(Event* event)
                     doStepAction(m_upDownState == Up ? 1 : -1);
                 }
             }
-            event->setDefaultHandled();
+            mouseEvent.setDefaultHandled();
         }
-    } else if (mouseEvent->type() == eventNames().mouseupEvent && mouseEvent->button() == LeftButton)
+    } else if (mouseEvent.type() == eventNames().mouseupEvent && mouseEvent.button() == LeftButton)
         stopRepeatingTimer();
-    else if (event->type() == eventNames().mousemoveEvent) {
+    else if (mouseEvent.type() == eventNames().mousemoveEvent) {
         if (box->pixelSnappedBorderBoxRect().contains(local)) {
             if (!m_capturing) {
                 if (Frame* frame = document().frame()) {
@@ -131,8 +131,8 @@ void SpinButtonElement::defaultEventHandler(Event* event)
         }
     }
 
-    if (!event->defaultHandled())
-        HTMLDivElement::defaultEventHandler(event);
+    if (!mouseEvent.defaultHandled())
+        HTMLDivElement::defaultEventHandler(&mouseEvent);
 }
 
 void SpinButtonElement::willOpenPopup()
@@ -146,7 +146,7 @@ void SpinButtonElement::forwardEvent(Event* event)
     if (!renderBox())
         return;
 
-    if (event->eventInterface() != WheelEventInterfaceType)
+    if (!is<WheelEvent>(event))
         return;
 
     if (!m_spinButtonOwner)
@@ -155,7 +155,7 @@ void SpinButtonElement::forwardEvent(Event* event)
     if (!m_spinButtonOwner->shouldSpinButtonRespondToWheelEvents())
         return;
 
-    doStepAction(toWheelEvent(event)->wheelDeltaY());
+    doStepAction(downcast<WheelEvent>(*event).wheelDeltaY());
     event->setDefaultHandled();
 }
 
index 192f8e0..7b2953d 100644 (file)
@@ -142,7 +142,7 @@ void SearchFieldResultsButtonElement::defaultEventHandler(Event* event)
 {
     // On mousedown, bring up a menu, if needed
     HTMLInputElement* input = downcast<HTMLInputElement>(shadowHost());
-    if (input && event->type() == eventNames().mousedownEvent && event->isMouseEvent() && toMouseEvent(event)->button() == LeftButton) {
+    if (input && event->type() == eventNames().mousedownEvent && is<MouseEvent>(event) && downcast<MouseEvent>(*event).button() == LeftButton) {
         input->focus();
         input->select();
 #if !PLATFORM(IOS)
@@ -199,7 +199,7 @@ void SearchFieldCancelButtonElement::defaultEventHandler(Event* event)
         return;
     }
 
-    if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && toMouseEvent(event)->button() == LeftButton) {
+    if (event->type() == eventNames().mousedownEvent && is<MouseEvent>(event) && downcast<MouseEvent>(*event).button() == LeftButton) {
         if (renderer() && renderer()->visibleToHitTesting()) {
             if (Frame* frame = document().frame()) {
                 frame->eventHandler().setCapturingMouseEventsElement(this);
@@ -210,7 +210,7 @@ void SearchFieldCancelButtonElement::defaultEventHandler(Event* event)
         input->select();
         event->setDefaultHandled();
     }
-    if (event->type() == eventNames().mouseupEvent && event->isMouseEvent() && toMouseEvent(event)->button() == LeftButton) {
+    if (event->type() == eventNames().mouseupEvent && is<MouseEvent>(event) && downcast<MouseEvent>(*event).button() == LeftButton) {
         if (m_capturing) {
             if (Frame* frame = document().frame()) {
                 frame->eventHandler().setCapturingMouseEventsElement(nullptr);
index 8569096..033aac8 100644 (file)
@@ -284,12 +284,12 @@ void InspectorFrontendHost::showContextMenu(Event* event, const Vector<ContextMe
 void InspectorFrontendHost::dispatchEventAsContextMenuEvent(Event* event)
 {
 #if ENABLE(CONTEXT_MENUS) && USE(ACCESSIBILITY_CONTEXT_MENUS)
-    if (!event || !event->isMouseEvent())
+    if (!event || !is<MouseEvent>(event))
         return;
 
     Frame* frame = event->target()->toNode()->document().frame();
-    MouseEvent* mouseEvent = toMouseEvent(event);
-    IntPoint mousePoint = IntPoint(mouseEvent->clientX(), mouseEvent->clientY());
+    MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
+    IntPoint mousePoint = IntPoint(mouseEvent.clientX(), mouseEvent.clientY());
 
     m_frontendPage->contextMenuController().showContextMenuAt(frame, mousePoint);
 #else
index a3f5907..76e881c 100644 (file)
@@ -150,10 +150,10 @@ std::unique_ptr<ContextMenu> ContextMenuController::maybeCreateContextMenu(Event
 {
     ASSERT(event);
     
-    if (!event->isMouseEvent())
+    if (!is<MouseEvent>(event))
         return nullptr;
 
-    MouseEvent& mouseEvent = toMouseEvent(*event);
+    MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
     HitTestResult result(mouseEvent.absoluteLocation());
 
     Node* node = event->target()->toNode();
index 33a9a53..38cfa72 100644 (file)
@@ -3523,7 +3523,7 @@ bool EventHandler::handleTextInputEvent(const String& text, Event* underlyingEve
 {
     // Platforms should differentiate real commands like selectAll from text input in disguise (like insertNewline),
     // and avoid dispatching text input events from keydown default handlers.
-    ASSERT(!underlyingEvent || !underlyingEvent->isKeyboardEvent() || toKeyboardEvent(underlyingEvent)->type() == eventNames().keypressEvent);
+    ASSERT(!underlyingEvent || !is<KeyboardEvent>(underlyingEvent) || downcast<KeyboardEvent>(*underlyingEvent).type() == eventNames().keypressEvent);
 
     EventTarget* target;
     if (underlyingEvent)
index 149060a..b464cc7 100644 (file)
@@ -590,9 +590,9 @@ bool RenderEmbeddedObject::isInUnavailablePluginIndicator(const FloatPoint& poin
         && indicatorRect.contains(point);
 }
 
-bool RenderEmbeddedObject::isInUnavailablePluginIndicator(MouseEvent* event) const
+bool RenderEmbeddedObject::isInUnavailablePluginIndicator(const MouseEvent& event) const
 {
-    return isInUnavailablePluginIndicator(absoluteToLocal(event->absoluteLocation(), UseTransforms));
+    return isInUnavailablePluginIndicator(absoluteToLocal(event.absoluteLocation(), UseTransforms));
 }
 
 void RenderEmbeddedObject::handleUnavailablePluginIndicatorEvent(Event* event)
@@ -600,21 +600,21 @@ void RenderEmbeddedObject::handleUnavailablePluginIndicatorEvent(Event* event)
     if (!shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason))
         return;
 
-    if (!event->isMouseEvent())
+    if (!is<MouseEvent>(event))
         return;
 
-    MouseEvent* mouseEvent = toMouseEvent(event);
+    MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
     HTMLPlugInElement& element = downcast<HTMLPlugInElement>(frameOwnerElement());
-    if (event->type() == eventNames().mousedownEvent && toMouseEvent(event)->button() == LeftButton) {
+    if (mouseEvent.type() == eventNames().mousedownEvent && mouseEvent.button() == LeftButton) {
         m_mouseDownWasInUnavailablePluginIndicator = isInUnavailablePluginIndicator(mouseEvent);
         if (m_mouseDownWasInUnavailablePluginIndicator) {
             frame().eventHandler().setCapturingMouseEventsElement(&element);
             element.setIsCapturingMouseEvents(true);
             setUnavailablePluginIndicatorIsPressed(true);
         }
-        event->setDefaultHandled();
+        mouseEvent.setDefaultHandled();
     }
-    if (event->type() == eventNames().mouseupEvent && toMouseEvent(event)->button() == LeftButton) {
+    if (mouseEvent.type() == eventNames().mouseupEvent && mouseEvent.button() == LeftButton) {
         if (m_unavailablePluginIndicatorIsPressed) {
             frame().eventHandler().setCapturingMouseEventsElement(nullptr);
             element.setIsCapturingMouseEvents(false);
@@ -627,9 +627,9 @@ void RenderEmbeddedObject::handleUnavailablePluginIndicatorEvent(Event* event)
         m_mouseDownWasInUnavailablePluginIndicator = false;
         event->setDefaultHandled();
     }
-    if (event->type() == eventNames().mousemoveEvent) {
+    if (mouseEvent.type() == eventNames().mousemoveEvent) {
         setUnavailablePluginIndicatorIsPressed(m_mouseDownWasInUnavailablePluginIndicator && isInUnavailablePluginIndicator(mouseEvent));
-        event->setDefaultHandled();
+        mouseEvent.setDefaultHandled();
     }
 }
 
index 4d342d7..2bfbec1 100644 (file)
@@ -84,7 +84,7 @@ private:
     virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier, Element** stopElement) override final;
 
     void setUnavailablePluginIndicatorIsPressed(bool);
-    bool isInUnavailablePluginIndicator(MouseEvent*) const;
+    bool isInUnavailablePluginIndicator(const MouseEvent&) const;
     bool isInUnavailablePluginIndicator(const FloatPoint&) const;
     bool getReplacementTextGeometry(const LayoutPoint& accumulatedOffset, FloatRect& contentRect, FloatRect& indicatorRect, FloatRect& replacementTextRect, FloatRect& arrowRect, Font&, TextRun&, float& textWidth) const;
     LayoutRect unavailablePluginIndicatorBounds(const LayoutPoint&) const;
index de3726d..870a541 100644 (file)
@@ -155,10 +155,10 @@ CursorDirective RenderSnapshottedPlugIn::getCursor(const LayoutPoint& point, Cur
 
 void RenderSnapshottedPlugIn::handleEvent(Event* event)
 {
-    if (!event->isMouseEvent())
+    if (!is<MouseEvent>(event))
         return;
 
-    MouseEvent* mouseEvent = toMouseEvent(event);
+    MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
 
     // If we're a snapshotted plugin, we want to make sure we activate on
     // clicks even if the page is preventing our default behaviour. Otherwise
@@ -168,20 +168,20 @@ void RenderSnapshottedPlugIn::handleEvent(Event* event)
     // event. The code below is not completely foolproof, but the worst that
     // could happen is that a snapshotted plugin restarts.
 
-    if (event->type() == eventNames().mouseoutEvent)
+    if (mouseEvent.type() == eventNames().mouseoutEvent)
         m_isPotentialMouseActivation = false;
 
-    if (mouseEvent->button() != LeftButton)
+    if (mouseEvent.button() != LeftButton)
         return;
 
-    if (event->type() == eventNames().clickEvent || (m_isPotentialMouseActivation && event->type() == eventNames().mouseupEvent)) {
+    if (mouseEvent.type() == eventNames().clickEvent || (m_isPotentialMouseActivation && mouseEvent.type() == eventNames().mouseupEvent)) {
         m_isPotentialMouseActivation = false;
-        bool clickWasOnOverlay = plugInImageElement().partOfSnapshotOverlay(event->target()->toNode());
-        plugInImageElement().userDidClickSnapshot(mouseEvent, !clickWasOnOverlay);
-        event->setDefaultHandled();
-    } else if (event->type() == eventNames().mousedownEvent) {
+        bool clickWasOnOverlay = plugInImageElement().partOfSnapshotOverlay(mouseEvent.target()->toNode());
+        plugInImageElement().userDidClickSnapshot(&mouseEvent, !clickWasOnOverlay);
+        mouseEvent.setDefaultHandled();
+    } else if (mouseEvent.type() == eventNames().mousedownEvent) {
         m_isPotentialMouseActivation = true;
-        event->setDefaultHandled();
+        mouseEvent.setDefaultHandled();
     }
 }
 
index 0e73c02..fae9ed5 100644 (file)
@@ -1,3 +1,15 @@
+2014-10-01  Christophe Dumez  <cdumez@apple.com>
+
+        Use is<>() / downcast<>() for Event classes
+        https://bugs.webkit.org/show_bug.cgi?id=137284
+
+        Reviewed by Andreas Kling.
+
+        Use is<>() / downcast<>() for Event classes.
+
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::PluginView::handleEvent):
+
 2014-10-01  Joseph Pecoraro  <pecoraro@apple.com>
 
         [iOS] <select> with <optgroup> may change initial selected option when assisted
index f67518b..e493292 100644 (file)
@@ -892,8 +892,8 @@ void PluginView::handleEvent(Event* event)
 
     const WebEvent* currentEvent = WebPage::currentEvent();
     std::unique_ptr<WebEvent> simulatedWebEvent;
-    if (event->isMouseEvent() && toMouseEvent(event)->isSimulated()) {
-        simulatedWebEvent = createWebEvent(toMouseEvent(event));
+    if (is<MouseEvent>(event) && downcast<MouseEvent>(*event).isSimulated()) {
+        simulatedWebEvent = createWebEvent(downcast<MouseEvent>(event));
         currentEvent = simulatedWebEvent.get();
     }
     if (!currentEvent)