2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2000-09-22 05:02:20 +00:00
|
|
|
|
|
|
|
#ifndef nsXBLWindowKeyHandler_h__
|
|
|
|
#define nsXBLWindowKeyHandler_h__
|
|
|
|
|
2016-04-22 17:12:54 +00:00
|
|
|
#include "mozilla/EventForwards.h"
|
2017-06-15 22:06:00 +00:00
|
|
|
#include "mozilla/layers/KeyboardMap.h"
|
2011-06-24 23:12:34 +00:00
|
|
|
#include "nsIDOMEventListener.h"
|
2018-10-31 20:39:03 +00:00
|
|
|
#include "nsIWeakReferenceUtils.h"
|
2000-09-22 05:02:20 +00:00
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
class nsAtom;
|
2007-01-09 07:33:18 +00:00
|
|
|
class nsXBLPrototypeHandler;
|
2000-09-22 05:02:20 +00:00
|
|
|
|
2013-04-14 18:27:33 +00:00
|
|
|
namespace mozilla {
|
2016-03-16 01:58:28 +00:00
|
|
|
class EventListenerManager;
|
2017-11-09 23:42:39 +00:00
|
|
|
class WidgetKeyboardEvent;
|
2017-06-05 23:24:35 +00:00
|
|
|
struct IgnoreModifierState;
|
2013-04-14 18:27:33 +00:00
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
class EventTarget;
|
2018-02-09 16:17:09 +00:00
|
|
|
class KeyboardEvent;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-04-14 18:27:33 +00:00
|
|
|
|
2011-06-24 23:12:34 +00:00
|
|
|
class nsXBLWindowKeyHandler : public nsIDOMEventListener {
|
2016-03-16 01:58:28 +00:00
|
|
|
typedef mozilla::EventListenerManager EventListenerManager;
|
2017-06-05 23:24:35 +00:00
|
|
|
typedef mozilla::IgnoreModifierState IgnoreModifierState;
|
2017-06-05 23:29:04 +00:00
|
|
|
typedef mozilla::layers::KeyboardMap KeyboardMap;
|
2018-02-09 16:17:09 +00:00
|
|
|
typedef mozilla::dom::KeyboardEvent KeyboardEvent;
|
2014-12-12 12:17:37 +00:00
|
|
|
|
2000-09-22 05:02:20 +00:00
|
|
|
public:
|
2018-04-27 03:37:34 +00:00
|
|
|
nsXBLWindowKeyHandler(mozilla::dom::Element* aElement,
|
|
|
|
mozilla::dom::EventTarget* aTarget);
|
2003-09-11 12:25:06 +00:00
|
|
|
|
2016-03-16 01:58:28 +00:00
|
|
|
void InstallKeyboardEventListenersTo(
|
|
|
|
EventListenerManager* aEventListenerManager);
|
|
|
|
void RemoveKeyboardEventListenersFrom(
|
|
|
|
EventListenerManager* aEventListenerManager);
|
|
|
|
|
2017-06-05 23:29:04 +00:00
|
|
|
static KeyboardMap CollectKeyboardShortcuts();
|
|
|
|
|
2000-09-22 05:02:20 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
2011-06-24 23:12:34 +00:00
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
2000-09-22 05:02:20 +00:00
|
|
|
|
|
|
|
protected:
|
2014-06-23 19:56:07 +00:00
|
|
|
virtual ~nsXBLWindowKeyHandler();
|
|
|
|
|
2019-03-12 01:57:42 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2018-10-15 19:19:30 +00:00
|
|
|
nsresult WalkHandlers(KeyboardEvent* aKeyEvent);
|
2000-09-22 05:02:20 +00:00
|
|
|
|
2007-01-09 07:33:18 +00:00
|
|
|
// walk the handlers, looking for one to handle the event
|
2019-03-12 01:57:42 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2018-02-09 16:17:09 +00:00
|
|
|
bool WalkHandlersInternal(KeyboardEvent* aKeyEvent, bool aExecute,
|
2015-03-12 15:03:08 +00:00
|
|
|
bool* aOutReservedForChrome = nullptr);
|
2000-09-22 05:02:20 +00:00
|
|
|
|
2014-12-12 12:17:37 +00:00
|
|
|
// walk the handlers for aEvent, aCharCode and aIgnoreModifierState. Execute
|
|
|
|
// it if aExecute = true.
|
2019-03-12 01:57:42 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2018-10-15 19:19:30 +00:00
|
|
|
bool WalkHandlersAndExecute(KeyboardEvent* aKeyEvent, uint32_t aCharCode,
|
2014-12-12 12:17:37 +00:00
|
|
|
const IgnoreModifierState& aIgnoreModifierState,
|
2015-03-12 15:03:08 +00:00
|
|
|
bool aExecute,
|
|
|
|
bool* aOutReservedForChrome = nullptr);
|
2014-03-18 15:16:47 +00:00
|
|
|
|
2016-03-16 01:58:28 +00:00
|
|
|
// HandleEvent function for the capturing phase in the default event group.
|
2019-03-12 01:57:42 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2018-02-09 16:17:09 +00:00
|
|
|
void HandleEventOnCaptureInDefaultEventGroup(KeyboardEvent* aEvent);
|
2016-03-16 01:58:28 +00:00
|
|
|
// HandleEvent function for the capturing phase in the system event group.
|
2019-03-12 01:57:42 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2018-02-09 16:17:09 +00:00
|
|
|
void HandleEventOnCaptureInSystemEventGroup(KeyboardEvent* aEvent);
|
2014-03-18 15:16:47 +00:00
|
|
|
|
2015-03-12 15:03:08 +00:00
|
|
|
// Check if any handler would handle the given event. Optionally returns
|
|
|
|
// whether the command handler for the event is marked with the "reserved"
|
|
|
|
// attribute.
|
2019-03-12 01:57:42 +00:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2018-02-09 16:17:09 +00:00
|
|
|
bool HasHandlerForEvent(KeyboardEvent* aEvent,
|
2015-03-12 15:03:08 +00:00
|
|
|
bool* aOutReservedForChrome = nullptr);
|
2008-04-15 04:16:24 +00:00
|
|
|
|
2017-11-09 23:42:39 +00:00
|
|
|
// Returns true if the key would be reserved for the given handler. A reserved
|
|
|
|
// key is not sent to a content process or single-process equivalent.
|
|
|
|
bool IsReservedKey(mozilla::WidgetKeyboardEvent* aKeyEvent,
|
|
|
|
nsXBLPrototypeHandler* aHandler);
|
|
|
|
|
2003-02-28 01:04:45 +00:00
|
|
|
// lazily load the handlers. Overridden to handle being attached
|
|
|
|
// to a particular element rather than the document
|
2014-01-23 03:18:51 +00:00
|
|
|
nsresult EnsureHandlers();
|
2007-01-09 07:33:18 +00:00
|
|
|
|
2014-01-23 03:18:51 +00:00
|
|
|
// Is an HTML editable element focused
|
|
|
|
bool IsHTMLEditableFieldFocused();
|
2007-01-09 07:33:18 +00:00
|
|
|
|
|
|
|
// Returns the element which was passed as a parameter to the constructor,
|
2014-03-18 15:16:47 +00:00
|
|
|
// unless the element has been removed from the document. Optionally returns
|
|
|
|
// whether the disabled attribute is set on the element (assuming the element
|
|
|
|
// is non-null).
|
|
|
|
already_AddRefed<mozilla::dom::Element> GetElement(
|
|
|
|
bool* aIsDisabled = nullptr);
|
2016-03-18 02:25:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GetElementForHandler() retrieves an element for the handler. The element
|
|
|
|
* may be a command element or a key element.
|
|
|
|
*
|
|
|
|
* @param aHandler The handler.
|
|
|
|
* @param aElementForHandler Must not be nullptr. The element is returned to
|
|
|
|
* this.
|
|
|
|
* @return true if the handler is valid. Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool GetElementForHandler(nsXBLPrototypeHandler* aHandler,
|
|
|
|
mozilla::dom::Element** aElementForHandler);
|
|
|
|
|
2016-03-19 14:16:21 +00:00
|
|
|
/**
|
|
|
|
* IsExecutableElement() returns true if aElement is executable.
|
|
|
|
* Otherwise, false. aElement should be a command element or a key element.
|
|
|
|
*/
|
|
|
|
bool IsExecutableElement(mozilla::dom::Element* aElement) const;
|
|
|
|
|
2007-01-09 07:33:18 +00:00
|
|
|
// Using weak pointer to the DOM Element.
|
|
|
|
nsWeakPtr mWeakPtrForElement;
|
2013-04-14 18:27:33 +00:00
|
|
|
mozilla::dom::EventTarget* mTarget; // weak ref
|
2007-01-09 07:33:18 +00:00
|
|
|
|
|
|
|
nsXBLPrototypeHandler* mHandler; // platform bindings
|
2000-09-22 05:02:20 +00:00
|
|
|
};
|
|
|
|
|
2013-04-14 18:27:33 +00:00
|
|
|
already_AddRefed<nsXBLWindowKeyHandler> NS_NewXBLWindowKeyHandler(
|
|
|
|
mozilla::dom::Element* aElement, mozilla::dom::EventTarget* aTarget);
|
2000-09-22 05:02:20 +00:00
|
|
|
|
|
|
|
#endif
|