mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1034103 part.2 editor shouldn't accept all events which are created with incorrect event interface r=smaug
This commit is contained in:
parent
c0156080b3
commit
2c8d8a4b82
@ -5227,43 +5227,62 @@ nsEditor::IsAcceptableInputEvent(nsIDOMEvent* aEvent)
|
||||
// If the event is trusted, the event should always cause input.
|
||||
NS_ENSURE_TRUE(aEvent, false);
|
||||
|
||||
// If this is mouse event but this editor doesn't have focus, we shouldn't
|
||||
// handle it.
|
||||
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aEvent);
|
||||
if (mouseEvent) {
|
||||
WidgetEvent* widgetEvent = aEvent->GetInternalNSEvent();
|
||||
if (NS_WARN_IF(!widgetEvent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If this is dispatched by using cordinates but this editor doesn't have
|
||||
// focus, we shouldn't handle it.
|
||||
if (widgetEvent->IsUsingCoordinates()) {
|
||||
nsCOMPtr<nsIContent> focusedContent = GetFocusedContent();
|
||||
if (!focusedContent) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
nsAutoString eventType;
|
||||
aEvent->GetType(eventType);
|
||||
// If composition event or text event isn't dispatched via widget,
|
||||
// we need to ignore them since they cannot be managed by TextComposition.
|
||||
// E.g., the event was created by chrome JS.
|
||||
// Note that if we allow to handle such events, editor may be confused by
|
||||
// strange event order.
|
||||
if (eventType.EqualsLiteral("text") ||
|
||||
eventType.EqualsLiteral("compositionstart") ||
|
||||
eventType.EqualsLiteral("compositionend")) {
|
||||
WidgetGUIEvent* widgetGUIEvent =
|
||||
aEvent->GetInternalNSEvent()->AsGUIEvent();
|
||||
if (!widgetGUIEvent || !widgetGUIEvent->widget) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isTrusted;
|
||||
nsresult rv = aEvent->GetIsTrusted(&isTrusted);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
if (isTrusted) {
|
||||
// If composition event or text event isn't dispatched via widget,
|
||||
// we need to ignore them since they cannot be managed by TextComposition.
|
||||
// E.g., the event was created by chrome JS.
|
||||
// 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->message) {
|
||||
case NS_USER_DEFINED_EVENT:
|
||||
// If events are not created with proper event interface, their message
|
||||
// are initialized with NS_USER_DEFINED_EVENT. Let's ignore such event.
|
||||
return false;
|
||||
case NS_TEXT_TEXT:
|
||||
// Don't allow text events whose internal event are not
|
||||
// WidgetTextEvent.
|
||||
widgetGUIEvent = aEvent->GetInternalNSEvent()->AsTextEvent();
|
||||
needsWidget = true;
|
||||
break;
|
||||
case NS_COMPOSITION_START:
|
||||
case NS_COMPOSITION_END:
|
||||
case NS_COMPOSITION_UPDATE:
|
||||
// Don't allow composition events whose internal event are not
|
||||
// WidgetCompositionEvent.
|
||||
widgetGUIEvent = aEvent->GetInternalNSEvent()->AsCompositionEvent();
|
||||
needsWidget = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (needsWidget &&
|
||||
(!widgetGUIEvent || !widgetGUIEvent->widget)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Accept all trusted events.
|
||||
if (widgetEvent->mFlags.mIsTrusted) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Ignore untrusted mouse event.
|
||||
// XXX Why are we handling other untrusted input events?
|
||||
if (mouseEvent) {
|
||||
if (widgetEvent->AsMouseEventBase()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user