Bug 1436508 part 5. Switch xbl from nsIDOMKeyEvent to KeyboardEvent. r=masayuki

MozReview-Commit-ID: COqUWh5xjfH
This commit is contained in:
Boris Zbarsky 2018-02-09 11:17:09 -05:00
Родитель 69a93469da
Коммит 696520edca
9 изменённых файлов: 69 добавлений и 56 удалений

Просмотреть файл

@ -35,6 +35,7 @@ class EventMessageAutoOverride;
// ExtendableEvent is a ServiceWorker event that is not
// autogenerated since it has some extra methods.
class ExtendableEvent;
class KeyboardEvent;
class TimeEvent;
class WantsPopupControlCheck;
#define GENERATED_EVENT(EventClass_) class EventClass_;
@ -119,6 +120,12 @@ public:
return nullptr;
}
// KeyboardEvent has all sorts of non-autogeneratable bits so far.
virtual KeyboardEvent* AsKeyboardEvent()
{
return nullptr;
}
// nsIDOMEvent Interface
NS_DECL_NSIDOMEVENT

Просмотреть файл

@ -32,6 +32,11 @@ public:
// Forward to base class
NS_FORWARD_TO_UIEVENT
virtual KeyboardEvent* AsKeyboardEvent() override
{
return this;
}
static already_AddRefed<KeyboardEvent> Constructor(
const GlobalObject& aGlobal,
const nsAString& aType,

Просмотреть файл

@ -36,6 +36,7 @@ public:
// Forward to Event
NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION
using Event::GetCurrentTarget; // Because the forwarding thing shadows it.
NS_IMETHOD DuplicatePrivateData() override;
NS_IMETHOD_(void) Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType) override;
NS_IMETHOD_(bool) Deserialize(const IPC::Message* aMsg, PickleIterator* aIter) override;
@ -121,6 +122,7 @@ protected:
#define NS_FORWARD_TO_UIEVENT \
NS_FORWARD_NSIDOMUIEVENT(UIEvent::) \
NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION \
using Event::GetCurrentTarget; /* Forwarding shadows */ \
NS_IMETHOD DuplicatePrivateData() override \
{ \
return UIEvent::DuplicatePrivateData(); \

Просмотреть файл

@ -7,12 +7,12 @@
#include "nsCOMPtr.h"
#include "nsAtom.h"
#include "nsIDOMEventListener.h"
#include "nsIDOMKeyEvent.h"
#include "nsIDOMMouseEvent.h"
#include "nsXBLPrototypeHandler.h"
#include "nsContentUtils.h"
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
#include "mozilla/dom/EventTarget.h"
#include "mozilla/dom/KeyboardEvent.h"
#include "mozilla/TextEvents.h"
using namespace mozilla;
@ -86,12 +86,12 @@ NS_IMPL_ISUPPORTS(nsXBLKeyEventHandler, nsIDOMEventListener)
bool
nsXBLKeyEventHandler::ExecuteMatchedHandlers(
nsIDOMKeyEvent* aKeyEvent,
KeyboardEvent* aKeyEvent,
uint32_t aCharCode,
const IgnoreModifierState& aIgnoreModifierState)
{
WidgetEvent* event = aKeyEvent->AsEvent()->WidgetEventPtr();
nsCOMPtr<EventTarget> target = aKeyEvent->AsEvent()->InternalDOMEvent()->GetCurrentTarget();
WidgetEvent* event = aKeyEvent->WidgetEventPtr();
nsCOMPtr<EventTarget> target = aKeyEvent->GetCurrentTarget();
bool executed = false;
for (uint32_t i = 0; i < mProtoHandlers.Length(); ++i) {
@ -101,7 +101,7 @@ nsXBLKeyEventHandler::ExecuteMatchedHandlers(
(hasAllowUntrustedAttr && handler->AllowUntrustedEvents()) ||
(!hasAllowUntrustedAttr && !mIsBoundToChrome && !mUsingContentXBLScope)) &&
handler->KeyEventMatched(aKeyEvent, aCharCode, aIgnoreModifierState)) {
handler->ExecuteHandler(target, aKeyEvent->AsEvent());
handler->ExecuteHandler(target, aKeyEvent);
executed = true;
}
}
@ -136,9 +136,10 @@ nsXBLKeyEventHandler::HandleEvent(nsIDOMEvent* aEvent)
return NS_OK;
}
nsCOMPtr<nsIDOMKeyEvent> key(do_QueryInterface(aEvent));
if (!key)
RefPtr<KeyboardEvent> key = aEvent->InternalDOMEvent()->AsKeyboardEvent();
if (!key) {
return NS_OK;
}
WidgetKeyboardEvent* nativeKeyboardEvent =
aEvent->WidgetEventPtr()->AsKeyboardEvent();

Просмотреть файл

@ -13,11 +13,13 @@
#include "nsTArray.h"
class nsAtom;
class nsIDOMKeyEvent;
class nsXBLPrototypeHandler;
namespace mozilla {
struct IgnoreModifierState;
namespace dom {
class KeyboardEvent;
} // namespace dom
} // namespace mozilla
class nsXBLEventHandler : public nsIDOMEventListener
@ -101,7 +103,7 @@ private:
nsXBLKeyEventHandler();
virtual ~nsXBLKeyEventHandler();
bool ExecuteMatchedHandlers(nsIDOMKeyEvent* aEvent, uint32_t aCharCode,
bool ExecuteMatchedHandlers(mozilla::dom::KeyboardEvent* aEvent, uint32_t aCharCode,
const IgnoreModifierState& aIgnoreModifierState);
nsTArray<nsXBLPrototypeHandler*> mProtoHandlers;

Просмотреть файл

@ -15,7 +15,6 @@
#include "nsGlobalWindowCommands.h"
#include "nsIContent.h"
#include "nsAtom.h"
#include "nsIDOMKeyEvent.h"
#include "nsIDOMMouseEvent.h"
#include "nsNameSpaceManager.h"
#include "nsIDocument.h"
@ -50,6 +49,7 @@
#include "mozilla/dom/Element.h"
#include "mozilla/dom/EventHandlerBinding.h"
#include "mozilla/dom/HTMLTextAreaElement.h"
#include "mozilla/dom/KeyboardEvent.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/layers/KeyboardMap.h"
#include "xpcpublic.h"
@ -586,7 +586,7 @@ nsXBLPrototypeHandler::DispatchXULKeyCommand(nsIDOMEvent* aEvent)
aEvent->PreventDefault();
// Copy the modifiers from the key event.
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aEvent);
RefPtr<KeyboardEvent> keyEvent = aEvent->InternalDOMEvent()->AsKeyboardEvent();
if (!keyEvent) {
NS_ERROR("Trying to execute a key handler for a non-key event!");
return NS_ERROR_FAILURE;
@ -594,14 +594,10 @@ nsXBLPrototypeHandler::DispatchXULKeyCommand(nsIDOMEvent* aEvent)
// XXX We should use mozilla::Modifiers for supporting all modifiers.
bool isAlt = false;
bool isControl = false;
bool isShift = false;
bool isMeta = false;
keyEvent->GetAltKey(&isAlt);
keyEvent->GetCtrlKey(&isControl);
keyEvent->GetShiftKey(&isShift);
keyEvent->GetMetaKey(&isMeta);
bool isAlt = keyEvent->AltKey();
bool isControl = keyEvent->CtrlKey();
bool isShift = keyEvent->ShiftKey();
bool isMeta = keyEvent->MetaKey();
nsContentUtils::DispatchXULCommand(handlerElement, true,
nullptr, nullptr,
@ -710,7 +706,7 @@ nsXBLPrototypeHandler::GetController(EventTarget* aTarget)
bool
nsXBLPrototypeHandler::KeyEventMatched(
nsIDOMKeyEvent* aKeyEvent,
KeyboardEvent* aKeyEvent,
uint32_t aCharCode,
const IgnoreModifierState& aIgnoreModifierState)
{
@ -722,18 +718,19 @@ nsXBLPrototypeHandler::KeyEventMatched(
if (aCharCode)
code = aCharCode;
else
aKeyEvent->GetCharCode(&code);
code = aKeyEvent->CharCode();
if (IS_IN_BMP(code))
code = ToLowerCase(char16_t(code));
}
else
aKeyEvent->GetKeyCode(&code);
code = aKeyEvent->KeyCode();
if (code != uint32_t(mDetail))
return false;
}
return ModifiersMatchMask(aKeyEvent, aIgnoreModifierState);
return ModifiersMatchMask(static_cast<nsIDOMKeyEvent*>(aKeyEvent),
aIgnoreModifierState);
}
bool

Просмотреть файл

@ -21,7 +21,6 @@
class nsIDOMEvent;
class nsIContent;
class nsIDOMUIEvent;
class nsIDOMKeyEvent;
class nsIDOMMouseEvent;
class nsIObjectInputStream;
class nsIObjectOutputStream;
@ -34,6 +33,7 @@ struct IgnoreModifierState;
namespace dom {
class AutoJSAPI;
class EventTarget;
class KeyboardEvent;
} // namespace dom
namespace layers {
@ -113,7 +113,7 @@ public:
}
// if aCharCode is not zero, it is used instead of the charCode of aKeyEvent.
bool KeyEventMatched(nsIDOMKeyEvent* aKeyEvent,
bool KeyEventMatched(mozilla::dom::KeyboardEvent* aKeyEvent,
uint32_t aCharCode,
const IgnoreModifierState& aIgnoreModifierState);

Просмотреть файл

@ -9,7 +9,6 @@
#include "nsXBLWindowKeyHandler.h"
#include "nsIContent.h"
#include "nsAtom.h"
#include "nsIDOMKeyEvent.h"
#include "nsXBLService.h"
#include "nsIServiceManager.h"
#include "nsGkAtoms.h"
@ -34,6 +33,7 @@
#include "mozilla/TextEvents.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/KeyboardEvent.h"
#include "mozilla/layers/KeyboardMap.h"
using namespace mozilla;
@ -267,19 +267,16 @@ nsXBLWindowKeyHandler::EnsureHandlers()
}
nsresult
nsXBLWindowKeyHandler::WalkHandlers(nsIDOMKeyEvent* aKeyEvent, nsAtom* aEventType)
nsXBLWindowKeyHandler::WalkHandlers(KeyboardEvent* aKeyEvent, nsAtom* aEventType)
{
bool prevent;
aKeyEvent->AsEvent()->GetDefaultPrevented(&prevent);
if (prevent)
if (aKeyEvent->DefaultPrevented()) {
return NS_OK;
}
bool trustedEvent = false;
// Don't process the event if it was not dispatched from a trusted source
aKeyEvent->AsEvent()->GetIsTrusted(&trustedEvent);
if (!trustedEvent)
if (!aKeyEvent->IsTrusted()) {
return NS_OK;
}
nsresult rv = EnsureHandlers();
NS_ENSURE_SUCCESS(rv, rv);
@ -289,9 +286,9 @@ nsXBLWindowKeyHandler::WalkHandlers(nsIDOMKeyEvent* aKeyEvent, nsAtom* aEventTyp
if (!el) {
if (mUserHandler) {
WalkHandlersInternal(aKeyEvent, aEventType, mUserHandler, true);
aKeyEvent->AsEvent()->GetDefaultPrevented(&prevent);
if (prevent)
if (aKeyEvent->DefaultPrevented()) {
return NS_OK; // Handled by the user bindings. Our work here is done.
}
}
}
@ -491,7 +488,8 @@ nsXBLWindowKeyHandler::ConvertEventToDOMEventType(
NS_IMETHODIMP
nsXBLWindowKeyHandler::HandleEvent(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMKeyEvent> keyEvent(do_QueryInterface(aEvent));
RefPtr<KeyboardEvent> keyEvent =
aEvent->InternalDOMEvent()->AsKeyboardEvent();
NS_ENSURE_TRUE(keyEvent, NS_ERROR_INVALID_ARG);
uint16_t eventPhase;
@ -544,10 +542,10 @@ nsXBLWindowKeyHandler::HandleEvent(nsIDOMEvent* aEvent)
void
nsXBLWindowKeyHandler::HandleEventOnCaptureInDefaultEventGroup(
nsIDOMKeyEvent* aEvent)
KeyboardEvent* aEvent)
{
WidgetKeyboardEvent* widgetKeyboardEvent =
aEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent();
aEvent->WidgetEventPtr()->AsKeyboardEvent();
if (widgetKeyboardEvent->IsReservedByChrome()) {
return;
@ -561,10 +559,10 @@ nsXBLWindowKeyHandler::HandleEventOnCaptureInDefaultEventGroup(
void
nsXBLWindowKeyHandler::HandleEventOnCaptureInSystemEventGroup(
nsIDOMKeyEvent* aEvent)
KeyboardEvent* aEvent)
{
WidgetKeyboardEvent* widgetEvent =
aEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent();
aEvent->WidgetEventPtr()->AsKeyboardEvent();
// If the event won't be sent to remote process, this listener needs to do
// nothing.
@ -645,14 +643,14 @@ nsXBLWindowKeyHandler::IsHTMLEditableFieldFocused()
// for that event was found.
//
bool
nsXBLWindowKeyHandler::WalkHandlersInternal(nsIDOMKeyEvent* aKeyEvent,
nsXBLWindowKeyHandler::WalkHandlersInternal(KeyboardEvent* aKeyEvent,
nsAtom* aEventType,
nsXBLPrototypeHandler* aHandler,
bool aExecute,
bool* aOutReservedForChrome)
{
WidgetKeyboardEvent* nativeKeyboardEvent =
aKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent();
aKeyEvent->WidgetEventPtr()->AsKeyboardEvent();
MOZ_ASSERT(nativeKeyboardEvent);
AutoShortcutKeyCandidateArray shortcutKeys;
@ -679,7 +677,7 @@ nsXBLWindowKeyHandler::WalkHandlersInternal(nsIDOMKeyEvent* aKeyEvent,
bool
nsXBLWindowKeyHandler::WalkHandlersAndExecute(
nsIDOMKeyEvent* aKeyEvent,
KeyboardEvent* aKeyEvent,
nsAtom* aEventType,
nsXBLPrototypeHandler* aFirstHandler,
uint32_t aCharCode,
@ -692,7 +690,7 @@ nsXBLWindowKeyHandler::WalkHandlersAndExecute(
}
WidgetKeyboardEvent* widgetKeyboardEvent =
aKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent();
aKeyEvent->WidgetEventPtr()->AsKeyboardEvent();
if (NS_WARN_IF(!widgetKeyboardEvent)) {
return false;
}
@ -701,7 +699,7 @@ nsXBLWindowKeyHandler::WalkHandlersAndExecute(
for (nsXBLPrototypeHandler* handler = aFirstHandler;
handler;
handler = handler->GetNextHandler()) {
bool stopped = aKeyEvent->AsEvent()->IsDispatchStopped();
bool stopped = aKeyEvent->IsDispatchStopped();
if (stopped) {
// The event is finished, don't execute any more handlers
return false;
@ -805,7 +803,7 @@ nsXBLWindowKeyHandler::WalkHandlersAndExecute(
// XXX Do we execute only one handler even if the handler neither stops
// propagation nor prevents default of the event?
nsresult rv = handler->ExecuteHandler(target, aKeyEvent->AsEvent());
nsresult rv = handler->ExecuteHandler(target, aKeyEvent);
if (NS_SUCCEEDED(rv)) {
return true;
}
@ -847,11 +845,11 @@ nsXBLWindowKeyHandler::IsReservedKey(WidgetKeyboardEvent* aKeyEvent,
}
bool
nsXBLWindowKeyHandler::HasHandlerForEvent(nsIDOMKeyEvent* aEvent,
nsXBLWindowKeyHandler::HasHandlerForEvent(KeyboardEvent* aEvent,
bool* aOutReservedForChrome)
{
WidgetKeyboardEvent* widgetKeyboardEvent =
aEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent();
aEvent->WidgetEventPtr()->AsKeyboardEvent();
if (NS_WARN_IF(!widgetKeyboardEvent) || !widgetKeyboardEvent->IsTrusted()) {
return false;
}

Просмотреть файл

@ -14,7 +14,6 @@
class nsAtom;
class nsIDOMElement;
class nsIDOMKeyEvent;
class nsXBLPrototypeHandler;
namespace mozilla {
@ -24,6 +23,7 @@ struct IgnoreModifierState;
namespace dom {
class Element;
class EventTarget;
class KeyboardEvent;
} // namespace dom
} // namespace mozilla
@ -32,6 +32,7 @@ class nsXBLWindowKeyHandler : public nsIDOMEventListener
typedef mozilla::EventListenerManager EventListenerManager;
typedef mozilla::IgnoreModifierState IgnoreModifierState;
typedef mozilla::layers::KeyboardMap KeyboardMap;
typedef mozilla::dom::KeyboardEvent KeyboardEvent;
public:
nsXBLWindowKeyHandler(nsIDOMElement* aElement, mozilla::dom::EventTarget* aTarget);
@ -49,10 +50,10 @@ public:
protected:
virtual ~nsXBLWindowKeyHandler();
nsresult WalkHandlers(nsIDOMKeyEvent* aKeyEvent, nsAtom* aEventType);
nsresult WalkHandlers(KeyboardEvent* aKeyEvent, nsAtom* aEventType);
// walk the handlers, looking for one to handle the event
bool WalkHandlersInternal(nsIDOMKeyEvent* aKeyEvent,
bool WalkHandlersInternal(KeyboardEvent* aKeyEvent,
nsAtom* aEventType,
nsXBLPrototypeHandler* aHandler,
bool aExecute,
@ -60,7 +61,7 @@ protected:
// walk the handlers for aEvent, aCharCode and aIgnoreModifierState. Execute
// it if aExecute = true.
bool WalkHandlersAndExecute(nsIDOMKeyEvent* aKeyEvent, nsAtom* aEventType,
bool WalkHandlersAndExecute(KeyboardEvent* aKeyEvent, nsAtom* aEventType,
nsXBLPrototypeHandler* aHandler,
uint32_t aCharCode,
const IgnoreModifierState& aIgnoreModifierState,
@ -68,14 +69,14 @@ protected:
bool* aOutReservedForChrome = nullptr);
// HandleEvent function for the capturing phase in the default event group.
void HandleEventOnCaptureInDefaultEventGroup(nsIDOMKeyEvent* aEvent);
void HandleEventOnCaptureInDefaultEventGroup(KeyboardEvent* aEvent);
// HandleEvent function for the capturing phase in the system event group.
void HandleEventOnCaptureInSystemEventGroup(nsIDOMKeyEvent* aEvent);
void HandleEventOnCaptureInSystemEventGroup(KeyboardEvent* aEvent);
// Check if any handler would handle the given event. Optionally returns
// whether the command handler for the event is marked with the "reserved"
// attribute.
bool HasHandlerForEvent(nsIDOMKeyEvent* aEvent,
bool HasHandlerForEvent(KeyboardEvent* aEvent,
bool* aOutReservedForChrome = nullptr);
// Returns true if the key would be reserved for the given handler. A reserved