From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/events/KeyEventHandler.h | 176 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 dom/events/KeyEventHandler.h (limited to 'dom/events/KeyEventHandler.h') diff --git a/dom/events/KeyEventHandler.h b/dom/events/KeyEventHandler.h new file mode 100644 index 0000000000..5d444cf322 --- /dev/null +++ b/dom/events/KeyEventHandler.h @@ -0,0 +1,176 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_KeyEventHandler_h_ +#define mozilla_KeyEventHandler_h_ + +#include "mozilla/EventForwards.h" +#include "mozilla/MemoryReporting.h" +#include "nsAtom.h" +#include "nsString.h" +#include "nsCOMPtr.h" +#include "nsIController.h" +#include "nsIWeakReference.h" +#include "nsCycleCollectionParticipant.h" +#include "js/TypeDecls.h" +#include "mozilla/ShortcutKeys.h" + +namespace mozilla { + +namespace layers { +class KeyboardShortcut; +} // namespace layers + +struct IgnoreModifierState; + +namespace dom { +class Event; +class UIEvent; +class Element; +class EventTarget; +class KeyboardEvent; +class Element; +} // namespace dom + +// Values of the reserved attribute. When unset, the default value depends on +// the permissions.default.shortcuts preference. +enum ReservedKey : uint8_t { + ReservedKey_False = 0, + ReservedKey_True = 1, + ReservedKey_Unset = 2, +}; + +class KeyEventHandler final { + public: + // This constructor is used only by XUL key handlers (e.g., ) + explicit KeyEventHandler(dom::Element* aHandlerElement, + ReservedKey aReserved); + + // This constructor is used for keyboard handlers for browser, editor, input + // and textarea elements. + explicit KeyEventHandler(ShortcutKeyData* aKeyData); + + ~KeyEventHandler(); + + /** + * Try and convert this XBL handler into an APZ KeyboardShortcut for handling + * key events on the compositor thread. This only works for XBL handlers that + * represent scroll commands. + * + * @param aOut the converted KeyboardShortcut, must be non null + * @return whether the handler was converted into a KeyboardShortcut + */ + bool TryConvertToKeyboardShortcut(layers::KeyboardShortcut* aOut) const; + + bool EventTypeEquals(nsAtom* aEventType) const { + return mEventName == aEventType; + } + + // if aCharCode is not zero, it is used instead of the charCode of + // aKeyEventHandler. + bool KeyEventMatched(dom::KeyboardEvent* aDomKeyboardEvent, + uint32_t aCharCode, + const IgnoreModifierState& aIgnoreModifierState); + + /** + * Check whether the handler element is disabled. Note that this requires + * a QI to getting GetHandlerELement(). Therefore, this should not be used + * first in multiple checks. + */ + bool KeyElementIsDisabled() const; + + already_AddRefed GetHandlerElement() const; + + ReservedKey GetIsReserved() { return mReserved; } + + KeyEventHandler* GetNextHandler() { return mNextHandler; } + void SetNextHandler(KeyEventHandler* aHandler) { mNextHandler = aHandler; } + + MOZ_CAN_RUN_SCRIPT + nsresult ExecuteHandler(dom::EventTarget* aTarget, dom::Event* aEvent); + + size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; + + void GetCommand(nsAString& aCommand) const; + + public: + static uint32_t gRefCnt; + + protected: + void Init() { ++gRefCnt; } + + already_AddRefed GetController(dom::EventTarget* aTarget); + + inline int32_t GetMatchingKeyCode(const nsAString& aKeyName); + void ConstructPrototype(dom::Element* aKeyElement, + const char16_t* aEvent = nullptr, + const char16_t* aCommand = nullptr, + const char16_t* aKeyCode = nullptr, + const char16_t* aCharCode = nullptr, + const char16_t* aModifiers = nullptr); + void BuildModifiers(nsAString& aModifiers); + + void ReportKeyConflict(const char16_t* aKey, const char16_t* aModifiers, + dom::Element* aKeyElement, const char* aMessageName); + void GetEventType(nsAString& aEvent); + bool ModifiersMatchMask(dom::UIEvent* aEvent, + const IgnoreModifierState& aIgnoreModifierState); + MOZ_CAN_RUN_SCRIPT + nsresult DispatchXBLCommand(dom::EventTarget* aTarget, dom::Event* aEvent); + MOZ_CAN_RUN_SCRIPT + nsresult DispatchXULKeyCommand(dom::Event* aEvent); + + Modifiers GetModifiers() const; + Modifiers GetModifiersMask() const; + + static int32_t KeyToMask(uint32_t aKey); + static int32_t AccelKeyMask(); + + static const int32_t cShift; + static const int32_t cAlt; + static const int32_t cControl; + static const int32_t cMeta; + static const int32_t cOS; + + static const int32_t cShiftMask; + static const int32_t cAltMask; + static const int32_t cControlMask; + static const int32_t cMetaMask; + static const int32_t cOSMask; + + static const int32_t cAllModifiers; + + protected: + union { + nsIWeakReference* + mHandlerElement; // For XUL element handlers. [STRONG] + char16_t* mCommand; // For built-in shortcuts the command to execute. + }; + + // The following four values make up 32 bits. + bool mIsXULKey; // This handler is either for a XUL element or it is + // a command dispatcher. + uint8_t mMisc; // Miscellaneous extra information. For key events, + // stores whether or not we're a key code or char code. + // For mouse events, stores the clickCount. + + ReservedKey mReserved; // is reserved for chrome. Not used by handlers. + + int32_t mKeyMask; // Which modifier keys this event handler expects to have + // down in order to be matched. + + // The primary filter information for mouse/key events. + int32_t mDetail; // For key events, contains a charcode or keycode. For + // mouse events, stores the button info. + + // Prototype handlers are chained. We own the next handler in the chain. + KeyEventHandler* mNextHandler; + RefPtr mEventName; // The type of the event, e.g., "keypress" +}; + +} // namespace mozilla + +#endif -- cgit v1.2.3