Fix badcast in event::isGestureEvent
Bug: 11676314
Cherry pick https://codereview.chromium.org/35153013.
Change-Id: I141d6fe56410e2c44631b17e537f52ab7a75d3d6
diff --git a/Source/core/dom/Event.cpp b/Source/core/dom/Event.cpp
index 1b714f7..f066f56 100644
--- a/Source/core/dom/Event.cpp
+++ b/Source/core/dom/Event.cpp
@@ -138,6 +138,11 @@
return false;
}
+bool Event::isGestureEvent() const
+{
+ return false;
+}
+
bool Event::isDragEvent() const
{
return false;
diff --git a/Source/core/dom/Event.h b/Source/core/dom/Event.h
index 7875b1e..3d4695f 100644
--- a/Source/core/dom/Event.h
+++ b/Source/core/dom/Event.h
@@ -126,6 +126,7 @@
virtual bool isFocusEvent() const;
virtual bool isKeyboardEvent() const;
virtual bool isTouchEvent() const;
+ virtual bool isGestureEvent() const;
// Drag events are a subset of mouse events.
virtual bool isDragEvent() const;
diff --git a/Source/core/dom/GestureEvent.cpp b/Source/core/dom/GestureEvent.cpp
index a4f5cf8..735036e 100644
--- a/Source/core/dom/GestureEvent.cpp
+++ b/Source/core/dom/GestureEvent.cpp
@@ -90,6 +90,11 @@
return UIEvent::interfaceName();
}
+bool GestureEvent::isGestureEvent() const
+{
+ return true;
+}
+
GestureEvent::GestureEvent()
: m_deltaX(0)
, m_deltaY(0)
@@ -110,7 +115,7 @@
GestureEvent* GestureEventDispatchMediator::event() const
{
- return static_cast<GestureEvent*>(EventDispatchMediator::event());
+ return toGestureEvent(EventDispatchMediator::event());
}
bool GestureEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
diff --git a/Source/core/dom/GestureEvent.h b/Source/core/dom/GestureEvent.h
index a0d6f2e..b630ae9 100644
--- a/Source/core/dom/GestureEvent.h
+++ b/Source/core/dom/GestureEvent.h
@@ -41,6 +41,8 @@
void initGestureEvent(const AtomicString& type, PassRefPtr<AbstractView>, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, float deltaX, float deltaY);
+ virtual bool isGestureEvent() const OVERRIDE;
+
virtual const AtomicString& interfaceName() const;
float deltaX() const { return m_deltaX; }
@@ -69,6 +71,12 @@
virtual bool dispatchEvent(EventDispatcher*) const OVERRIDE;
};
+inline GestureEvent* toGestureEvent(Event* event)
+{
+ ASSERT(event && event->isGestureEvent());
+ return static_cast<GestureEvent*>(event);
+}
+
} // namespace WebCore
#endif // GestureEvent_h
diff --git a/Source/web/WebPluginContainerImpl.cpp b/Source/web/WebPluginContainerImpl.cpp
index 65d50f5..e242410 100644
--- a/Source/web/WebPluginContainerImpl.cpp
+++ b/Source/web/WebPluginContainerImpl.cpp
@@ -194,8 +194,8 @@
handleKeyboardEvent(toKeyboardEvent(event));
else if (eventNames().isTouchEventType(event->type()))
handleTouchEvent(static_cast<TouchEvent*>(event));
- else if (eventNames().isGestureEventType(event->type()))
- handleGestureEvent(static_cast<GestureEvent*>(event));
+ else if (event->isGestureEvent())
+ handleGestureEvent(toGestureEvent(event));
// FIXME: it would be cleaner if Widget::handleEvent returned true/false and
// HTMLPluginElement called setDefaultHandled or defaultEventHandler.