Bug 920425 part.2 Implement mozilla::WidgetEvent::As*Event() methods r=roc

This commit is contained in:
Masayuki Nakano 2013-10-18 15:10:20 +09:00
parent 93a8575635
commit 113d2cb05c
8 changed files with 157 additions and 37 deletions

View File

@ -16,6 +16,8 @@ namespace mozilla {
class InternalMutationEvent : public WidgetEvent
{
public:
virtual InternalMutationEvent* AsMutationEvent() MOZ_OVERRIDE { return this; }
InternalMutationEvent(bool aIsTrusted, uint32_t aMessage) :
WidgetEvent(aIsTrusted, aMessage, NS_MUTATION_EVENT),
mAttrChange(0)

View File

@ -622,7 +622,7 @@ public:
mFlags.mBubbles = true;
}
~WidgetEvent()
virtual ~WidgetEvent()
{
MOZ_COUNT_DTOR(WidgetEvent);
}
@ -676,6 +676,20 @@ public:
* Utils for checking event types
*/
/**
* As*Event() returns the pointer of the instance only when the instance is
* the class or one of its derived class.
*/
#define NS_ROOT_EVENT_CLASS(aPrefix, aName)
#define NS_EVENT_CLASS(aPrefix, aName) \
virtual aPrefix##aName* As##aName(); \
const aPrefix##aName* As##aName() const;
#include "mozilla/EventClassList.h"
#undef NS_EVENT_CLASS
#undef NS_ROOT_EVENT_CLASS
/**
* Returns true if the event is WidgetInputEvent or inherits it.
*/
@ -805,6 +819,8 @@ protected:
}
public:
virtual WidgetGUIEvent* AsGUIEvent() MOZ_OVERRIDE { return this; }
WidgetGUIEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
WidgetEvent(aIsTrusted, aMessage, NS_GUI_EVENT),
widget(aWidget), pluginEvent(nullptr)
@ -892,6 +908,8 @@ protected:
}
public:
virtual WidgetInputEvent* AsInputEvent() MOZ_OVERRIDE { return this; }
WidgetInputEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_INPUT_EVENT),
modifiers(0)
@ -1006,6 +1024,8 @@ protected:
}
public:
virtual InternalUIEvent* AsUIEvent() MOZ_OVERRIDE { return this; }
InternalUIEvent(bool aIsTrusted, uint32_t aMessage, int32_t aDetail) :
WidgetGUIEvent(aIsTrusted, aMessage, nullptr, NS_UI_EVENT),
detail(aDetail)

View File

@ -26,6 +26,11 @@ namespace mozilla {
class InternalScriptErrorEvent : public WidgetEvent
{
public:
virtual InternalScriptErrorEvent* AsScriptErrorEvent() MOZ_OVERRIDE
{
return this;
}
InternalScriptErrorEvent(bool aIsTrusted, uint32_t aMessage) :
WidgetEvent(aIsTrusted, aMessage, NS_SCRIPT_ERROR_EVENT),
lineNr(0), errorMsg(nullptr), fileName(nullptr)
@ -58,6 +63,11 @@ public:
class InternalScrollPortEvent : public WidgetGUIEvent
{
public:
virtual InternalScrollPortEvent* AsScrollPortEvent() MOZ_OVERRIDE
{
return this;
}
enum orientType
{
vertical = 0,
@ -90,6 +100,11 @@ public:
class InternalScrollAreaEvent : public WidgetGUIEvent
{
public:
virtual InternalScrollAreaEvent* AsScrollAreaEvent() MOZ_OVERRIDE
{
return this;
}
InternalScrollAreaEvent(bool aIsTrusted, uint32_t aMessage,
nsIWidget* aWidget) :
WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_SCROLLAREA_EVENT)
@ -117,6 +132,8 @@ public:
class InternalFormEvent : public WidgetEvent
{
public:
virtual InternalFormEvent* AsFormEvent() MOZ_OVERRIDE { return this; }
InternalFormEvent(bool aIsTrusted, uint32_t aMessage) :
WidgetEvent(aIsTrusted, aMessage, NS_FORM_EVENT),
originator(nullptr)
@ -140,6 +157,11 @@ public:
class InternalClipboardEvent : public WidgetEvent
{
public:
virtual InternalClipboardEvent* AsClipboardEvent() MOZ_OVERRIDE
{
return this;
}
InternalClipboardEvent(bool aIsTrusted, uint32_t aMessage) :
WidgetEvent(aIsTrusted, aMessage, NS_CLIPBOARD_EVENT)
{
@ -163,6 +185,8 @@ public:
class InternalFocusEvent : public InternalUIEvent
{
public:
virtual InternalFocusEvent* AsFocusEvent() MOZ_OVERRIDE { return this; }
InternalFocusEvent(bool aIsTrusted, uint32_t aMessage) :
InternalUIEvent(aIsTrusted, aMessage, NS_FOCUS_EVENT, 0),
fromRaise(false), isRefocus(false)
@ -192,6 +216,11 @@ public:
class InternalTransitionEvent : public WidgetEvent
{
public:
virtual InternalTransitionEvent* AsTransitionEvent() MOZ_OVERRIDE
{
return this;
}
InternalTransitionEvent(bool aIsTrusted, uint32_t aMessage,
const nsAString& aPropertyName, float aElapsedTime,
const nsAString& aPseudoElement) :
@ -222,6 +251,11 @@ public:
class InternalAnimationEvent : public WidgetEvent
{
public:
virtual InternalAnimationEvent* AsAnimationEvent() MOZ_OVERRIDE
{
return this;
}
InternalAnimationEvent(bool aIsTrusted, uint32_t aMessage,
const nsAString& aAnimationName, float aElapsedTime,
const nsAString& aPseudoElement) :

View File

@ -22,6 +22,11 @@ namespace mozilla {
class WidgetContentCommandEvent : public WidgetGUIEvent
{
public:
virtual WidgetContentCommandEvent* AsContentCommandEvent() MOZ_OVERRIDE
{
return this;
}
WidgetContentCommandEvent(bool aIsTrusted, uint32_t aMessage,
nsIWidget* aWidget,
bool aOnlyEnabledCheck = false) :
@ -72,6 +77,8 @@ public:
class WidgetCommandEvent : public WidgetGUIEvent
{
public:
virtual WidgetCommandEvent* AsCommandEvent() MOZ_OVERRIDE { return this; }
WidgetCommandEvent(bool aIsTrusted, nsIAtom* aEventType,
nsIAtom* aCommand, nsIWidget* aWidget) :
WidgetGUIEvent(aIsTrusted, NS_USER_DEFINED_EVENT, aWidget,
@ -102,6 +109,8 @@ public:
class WidgetPluginEvent : public WidgetGUIEvent
{
public:
virtual WidgetPluginEvent* AsPluginEvent() MOZ_OVERRIDE { return this; }
WidgetPluginEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_PLUGIN_EVENT),
retargetToFocusedDocument(false)

View File

@ -46,7 +46,7 @@ private:
friend class dom::PBrowserParent;
friend class dom::PBrowserChild;
public:
protected:
WidgetMouseEventBase()
{
}
@ -59,6 +59,9 @@ public:
{
}
public:
virtual WidgetMouseEventBase* AsMouseEventBase() MOZ_OVERRIDE { return this; }
/// The possible related target
nsCOMPtr<nsISupports> relatedTarget;
@ -136,11 +139,11 @@ public:
eTopLevel
};
protected:
WidgetMouseEvent()
{
}
protected:
WidgetMouseEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget,
nsEventStructType aStructType, reasonType aReason) :
WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, aStructType),
@ -162,6 +165,7 @@ protected:
}
public:
virtual WidgetMouseEvent* AsMouseEvent() MOZ_OVERRIDE { return this; }
WidgetMouseEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget,
reasonType aReason, contextType aContext = eNormal) :
@ -187,7 +191,8 @@ public:
}
#ifdef DEBUG
~WidgetMouseEvent() {
virtual ~WidgetMouseEvent()
{
NS_WARN_IF_FALSE(message != NS_CONTEXTMENU ||
button ==
((context == eNormal) ? eRightButton : eLeftButton),
@ -225,6 +230,8 @@ public:
class WidgetDragEvent : public WidgetMouseEvent
{
public:
virtual WidgetDragEvent* AsDragEvent() MOZ_OVERRIDE { return this; }
WidgetDragEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
WidgetMouseEvent(aIsTrusted, aMessage, aWidget, NS_DRAG_EVENT, eReal),
userCancelled(false)
@ -268,6 +275,11 @@ private:
}
public:
virtual WidgetMouseScrollEvent* AsMouseScrollEvent() MOZ_OVERRIDE
{
return this;
}
WidgetMouseScrollEvent(bool aIsTrusted, uint32_t aMessage,
nsIWidget* aWidget) :
WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, NS_MOUSE_SCROLL_EVENT),
@ -312,6 +324,8 @@ private:
}
public:
virtual WidgetWheelEvent* AsWheelEvent() MOZ_OVERRIDE { return this; }
WidgetWheelEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, NS_WHEEL_EVENT),
deltaX(0.0), deltaY(0.0), deltaZ(0.0),

View File

@ -70,11 +70,13 @@ private:
friend class dom::PBrowserParent;
friend class dom::PBrowserChild;
public:
WidgetKeyboardEvent()
{
}
public:
virtual WidgetKeyboardEvent* AsKeyboardEvent() MOZ_OVERRIDE { return this; }
WidgetKeyboardEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
WidgetInputEvent(aIsTrusted, aMessage, aWidget, NS_KEY_EVENT),
keyCode(0), charCode(0),
@ -314,6 +316,8 @@ public:
uint32_t seqno;
public:
virtual WidgetTextEvent* AsTextEvent() MOZ_OVERRIDE { return this; }
WidgetTextEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_TEXT_EVENT),
rangeCount(0), rangeArray(nullptr), isChar(false)
@ -363,6 +367,11 @@ public:
uint32_t seqno;
public:
virtual WidgetCompositionEvent* AsCompositionEvent() MOZ_OVERRIDE
{
return this;
}
WidgetCompositionEvent(bool aIsTrusted, uint32_t aMessage,
nsIWidget* aWidget) :
WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_COMPOSITION_EVENT)
@ -403,6 +412,11 @@ private:
}
public:
virtual WidgetQueryContentEvent* AsQueryContentEvent() MOZ_OVERRIDE
{
return this;
}
WidgetQueryContentEvent(bool aIsTrusted, uint32_t aMessage,
nsIWidget* aWidget) :
WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_QUERY_CONTENT_EVENT),
@ -513,6 +527,11 @@ public:
uint32_t seqno;
public:
virtual WidgetSelectionEvent* AsSelectionEvent() MOZ_OVERRIDE
{
return this;
}
WidgetSelectionEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_SELECTION_EVENT),
mExpandToClusterBoundary(true), mSucceeded(false)

View File

@ -31,6 +31,11 @@ namespace mozilla {
class WidgetGestureNotifyEvent : public WidgetGUIEvent
{
public:
virtual WidgetGestureNotifyEvent* AsGestureNotifyEvent() MOZ_OVERRIDE
{
return this;
}
WidgetGestureNotifyEvent(bool aIsTrusted, uint32_t aMessage,
nsIWidget *aWidget) :
WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_GESTURENOTIFY_EVENT),
@ -67,6 +72,11 @@ public:
class WidgetSimpleGestureEvent : public WidgetMouseEventBase
{
public:
virtual WidgetSimpleGestureEvent* AsSimpleGestureEvent() MOZ_OVERRIDE
{
return this;
}
WidgetSimpleGestureEvent(bool aIsTrusted, uint32_t aMessage,
nsIWidget* aWidget, uint32_t aDirection,
double aDelta) :
@ -114,6 +124,8 @@ public:
class WidgetTouchEvent : public WidgetInputEvent
{
public:
virtual WidgetTouchEvent* AsTouchEvent() MOZ_OVERRIDE { return this; }
WidgetTouchEvent()
{
}
@ -134,7 +146,7 @@ public:
MOZ_COUNT_CTOR(WidgetTouchEvent);
}
~WidgetTouchEvent()
virtual ~WidgetTouchEvent()
{
MOZ_COUNT_DTOR(WidgetTouchEvent);
}

View File

@ -4,11 +4,38 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/BasicEvents.h"
#include "mozilla/ContentEvents.h"
#include "mozilla/MiscEvents.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/MutationEvent.h"
#include "mozilla/TextEvents.h"
#include "mozilla/TouchEvents.h"
namespace mozilla {
/******************************************************************************
* As*Event() implementation
******************************************************************************/
#define NS_ROOT_EVENT_CLASS(aPrefix, aName)
#define NS_EVENT_CLASS(aPrefix, aName) \
aPrefix##aName* \
WidgetEvent::As##aName() \
{ \
return nullptr; \
} \
\
const aPrefix##aName* \
WidgetEvent::As##aName() const \
{ \
return const_cast<WidgetEvent*>(this)->As##aName(); \
}
#include "mozilla/EventClassList.h"
#undef NS_EVENT_CLASS
#undef NS_ROOT_EVENT_CLASS
/******************************************************************************
* mozilla::WidgetEvent
*
@ -18,26 +45,13 @@ namespace mozilla {
bool
WidgetEvent::IsInputDerivedEvent() const
{
switch (eventStructType) {
case NS_INPUT_EVENT:
case NS_MOUSE_EVENT:
case NS_KEY_EVENT:
case NS_TOUCH_EVENT:
case NS_DRAG_EVENT:
case NS_MOUSE_SCROLL_EVENT:
case NS_WHEEL_EVENT:
case NS_SIMPLE_GESTURE_EVENT:
return true;
default:
return false;
}
return AsInputEvent() != nullptr;
}
bool
WidgetEvent::IsMouseDerivedEvent() const
{
return eventStructType == NS_MOUSE_EVENT ||
eventStructType == NS_DRAG_EVENT;
return AsMouseEvent() != nullptr;
}
bool
@ -155,33 +169,31 @@ WidgetEvent::HasPluginActivationEventMessage() const
bool
WidgetEvent::IsLeftClickEvent() const
{
return eventStructType == NS_MOUSE_EVENT &&
message == NS_MOUSE_CLICK &&
static_cast<const WidgetMouseEvent*>(this)->button ==
WidgetMouseEvent::eLeftButton;
const WidgetMouseEvent* mouseEvent = AsMouseEvent();
return mouseEvent && message == NS_MOUSE_CLICK &&
mouseEvent->button == WidgetMouseEvent::eLeftButton;
}
bool
WidgetEvent::IsContextMenuKeyEvent() const
{
return eventStructType == NS_MOUSE_EVENT &&
message == NS_CONTEXTMENU &&
static_cast<const WidgetMouseEvent*>(this)->context ==
WidgetMouseEvent::eContextMenuKey;
const WidgetMouseEvent* mouseEvent = AsMouseEvent();
return mouseEvent && message == NS_CONTEXTMENU &&
mouseEvent->context == WidgetMouseEvent::eContextMenuKey;
}
bool
WidgetEvent::IsRetargetedNativeEventDelivererForPlugin() const
{
return IsNativeEventDelivererForPlugin() &&
static_cast<const WidgetPluginEvent*>(this)->retargetToFocusedDocument;
const WidgetPluginEvent* pluginEvent = AsPluginEvent();
return pluginEvent && pluginEvent->retargetToFocusedDocument;
}
bool
WidgetEvent::IsNonRetargetedNativeEventDelivererForPlugin() const
{
return IsNativeEventDelivererForPlugin() &&
!static_cast<const WidgetPluginEvent*>(this)->retargetToFocusedDocument;
const WidgetPluginEvent* pluginEvent = AsPluginEvent();
return pluginEvent && !pluginEvent->retargetToFocusedDocument;
}
bool
@ -228,14 +240,12 @@ WidgetEvent::IsAllowedToDispatchDOMEvent() const
// DOM events.
// Synthesized button up events also do not cause DOM events because they
// do not have a reliable refPoint.
return static_cast<const WidgetMouseEvent*>(this)->reason ==
WidgetMouseEvent::eReal;
return AsMouseEvent()->reason == WidgetMouseEvent::eReal;
case NS_WHEEL_EVENT: {
// wheel event whose all delta values are zero by user pref applied, it
// shouldn't cause a DOM event.
const WidgetWheelEvent* wheelEvent =
static_cast<const WidgetWheelEvent*>(this);
const WidgetWheelEvent* wheelEvent = AsWheelEvent();
return wheelEvent->deltaX != 0.0 || wheelEvent->deltaY != 0.0 ||
wheelEvent->deltaZ != 0.0;
}