Bug 964718 Don't dispatch DOM event if internal event doesn't need that. Otherwise, implement Duplicate() method r=smaug

This commit is contained in:
Masayuki Nakano 2014-03-27 22:53:19 +09:00
parent 142d55ee85
commit 5c2e9920b9
4 changed files with 52 additions and 6 deletions

View File

@ -38,6 +38,8 @@ public:
virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
{
// This event isn't an internal event of any DOM event.
NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
"WidgetQueryContentEvent needs to support Duplicate()");
MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
return nullptr;
}
@ -149,14 +151,28 @@ public:
virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
{
// This event isn't an internal event of any DOM event.
MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
return nullptr;
// NOTE: PluginEvent has to be dispatched to nsIFrame::HandleEvent().
// So, this event needs to support Duplicate().
MOZ_ASSERT(eventStructType == NS_PLUGIN_EVENT,
"Duplicate() must be overridden by sub class");
// Not copying widget, it is a weak reference.
WidgetPluginEvent* result = new WidgetPluginEvent(false, message, nullptr);
result->AssignPluginEventData(*this, true);
result->mFlags = mFlags;
return result;
}
// If true, this event needs to be retargeted to focused document.
// Otherwise, never retargeted. Defaults to false.
bool retargetToFocusedDocument;
void AssignPluginEventData(const WidgetPluginEvent& aEvent,
bool aCopyTargets)
{
AssignGUIEventData(aEvent, aCopyTargets);
retargetToFocusedDocument = aEvent.retargetToFocusedDocument;
}
};
} // namespace mozilla

View File

@ -338,6 +338,8 @@ public:
virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
{
// This event isn't an internal event of any DOM event.
NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
"WidgetQueryContentEvent needs to support Duplicate()");
MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
return nullptr;
}
@ -469,6 +471,8 @@ public:
virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
{
// This event isn't an internal event of any DOM event.
NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
"WidgetSelectionEvent needs to support Duplicate()");
MOZ_CRASH("WidgetSelectionEvent doesn't support Duplicate()");
return nullptr;
}

View File

@ -45,9 +45,19 @@ public:
virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
{
// This event isn't an internal event of any DOM event.
MOZ_CRASH("WidgetGestureNotifyEvent doesn't support Duplicate()");
return nullptr;
// XXX Looks like this event is handled only in PostHandleEvent() of
// EventStateManager. Therefore, it might be possible to handle this
// in PreHandleEvent() and not to dispatch as a DOM event into the DOM
// tree like ContentQueryEvent. Then, this event doesn't need to
// support Duplicate().
MOZ_ASSERT(eventStructType == NS_GESTURENOTIFY_EVENT,
"Duplicate() must be overridden by sub class");
// Not copying widget, it is a weak reference.
WidgetGestureNotifyEvent* result =
new WidgetGestureNotifyEvent(false, message, nullptr);
result->AssignGestureNotifyEventData(*this, true);
result->mFlags = mFlags;
return result;
}
enum ePanDirection
@ -60,6 +70,15 @@ public:
ePanDirection panDirection;
bool displayPanFeedback;
void AssignGestureNotifyEventData(const WidgetGestureNotifyEvent& aEvent,
bool aCopyTargets)
{
AssignGUIEventData(aEvent, aCopyTargets);
panDirection = aEvent.panDirection;
displayPanFeedback = aEvent.displayPanFeedback;
}
};
/******************************************************************************

View File

@ -232,6 +232,13 @@ WidgetEvent::IsAllowedToDispatchDOMEvent() const
wheelEvent->deltaZ != 0.0;
}
// Following events are handled in EventStateManager, so, we don't need to
// dispatch DOM event for them into the DOM tree.
case NS_QUERY_CONTENT_EVENT:
case NS_SELECTION_EVENT:
case NS_CONTENT_COMMAND_EVENT:
return false;
default:
return true;
}