Issue #12 Part 2: Stop using nsIDOMEvent in IsAcceptableInputEvent.

This commit is contained in:
wolfbeast 2018-06-26 13:53:12 +02:00 committed by Roy Tam
commit 550c8977c1
9 changed files with 87 additions and 54 deletions

View file

@ -5092,19 +5092,16 @@ EditorBase::IsActiveInDOMWindow()
}
bool
EditorBase::IsAcceptableInputEvent(nsIDOMEvent* aEvent)
EditorBase::IsAcceptableInputEvent(WidgetGUIEvent* aGUIEvent)
{
// If the event is trusted, the event should always cause input.
NS_ENSURE_TRUE(aEvent, false);
WidgetEvent* widgetEvent = aEvent->WidgetEventPtr();
if (NS_WARN_IF(!widgetEvent)) {
if (NS_WARN_IF(!aGUIEvent)) {
return false;
}
// If this is dispatched by using cordinates but this editor doesn't have
// focus, we shouldn't handle it.
if (widgetEvent->IsUsingCoordinates()) {
if (aGUIEvent->IsUsingCoordinates()) {
nsCOMPtr<nsIContent> focusedContent = GetFocusedContent();
if (!focusedContent) {
return false;
@ -5117,8 +5114,7 @@ EditorBase::IsAcceptableInputEvent(nsIDOMEvent* aEvent)
// Note that if we allow to handle such events, editor may be confused by
// strange event order.
bool needsWidget = false;
WidgetGUIEvent* widgetGUIEvent = nullptr;
switch (widgetEvent->mMessage) {
switch (aGUIEvent->mMessage) {
case eUnidentifiedEvent:
// If events are not created with proper event interface, their message
// are initialized with eUnidentifiedEvent. Let's ignore such event.
@ -5130,25 +5126,26 @@ EditorBase::IsAcceptableInputEvent(nsIDOMEvent* aEvent)
case eCompositionCommitAsIs:
// Don't allow composition events whose internal event are not
// WidgetCompositionEvent.
widgetGUIEvent = aEvent->WidgetEventPtr()->AsCompositionEvent();
if (!aGUIEvent->AsCompositionEvent()) {
return false;
}
needsWidget = true;
break;
default:
break;
}
if (needsWidget &&
(!widgetGUIEvent || !widgetGUIEvent->mWidget)) {
if (needsWidget && !aGUIEvent->mWidget) {
return false;
}
// Accept all trusted events.
if (widgetEvent->IsTrusted()) {
if (aGUIEvent->IsTrusted()) {
return true;
}
// Ignore untrusted mouse event.
// XXX Why are we handling other untrusted input events?
if (widgetEvent->AsMouseEventBase()) {
if (aGUIEvent->AsMouseEventBase()) {
return false;
}