2015-05-03 22:32:37 +03: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 15:12:37 +04: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 09:02:20 +04:00
|
|
|
|
|
|
|
#ifndef nsXBLWindowKeyHandler_h__
|
|
|
|
#define nsXBLWindowKeyHandler_h__
|
|
|
|
|
2016-04-22 20:12:54 +03:00
|
|
|
#include "mozilla/EventForwards.h"
|
2017-06-16 01:06:00 +03:00
|
|
|
#include "mozilla/layers/KeyboardMap.h"
|
2007-01-09 10:33:18 +03:00
|
|
|
#include "nsWeakPtr.h"
|
2011-06-25 03:12:34 +04:00
|
|
|
#include "nsIDOMEventListener.h"
|
2000-09-22 09:02:20 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
class nsAtom;
|
2007-01-09 10:33:18 +03:00
|
|
|
class nsIDOMElement;
|
2008-09-16 05:37:13 +04:00
|
|
|
class nsIDOMKeyEvent;
|
2007-01-09 10:33:18 +03:00
|
|
|
class nsXBLPrototypeHandler;
|
2000-09-22 09:02:20 +04:00
|
|
|
|
2013-04-14 22:27:33 +04:00
|
|
|
namespace mozilla {
|
2016-03-16 04:58:28 +03:00
|
|
|
class EventListenerManager;
|
2017-06-06 02:24:35 +03:00
|
|
|
struct IgnoreModifierState;
|
2013-04-14 22:27:33 +04:00
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
class EventTarget;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-04-14 22:27:33 +04:00
|
|
|
|
2011-06-25 03:12:34 +04:00
|
|
|
class nsXBLWindowKeyHandler : public nsIDOMEventListener
|
2000-09-22 09:02:20 +04:00
|
|
|
{
|
2016-03-16 04:58:28 +03:00
|
|
|
typedef mozilla::EventListenerManager EventListenerManager;
|
2017-06-06 02:24:35 +03:00
|
|
|
typedef mozilla::IgnoreModifierState IgnoreModifierState;
|
2017-06-06 02:29:04 +03:00
|
|
|
typedef mozilla::layers::KeyboardMap KeyboardMap;
|
2014-12-12 15:17:37 +03:00
|
|
|
|
2000-09-22 09:02:20 +04:00
|
|
|
public:
|
2013-04-14 22:27:33 +04:00
|
|
|
nsXBLWindowKeyHandler(nsIDOMElement* aElement, mozilla::dom::EventTarget* aTarget);
|
2003-09-11 16:25:06 +04:00
|
|
|
|
2016-03-16 04:58:28 +03:00
|
|
|
void InstallKeyboardEventListenersTo(
|
|
|
|
EventListenerManager* aEventListenerManager);
|
|
|
|
void RemoveKeyboardEventListenersFrom(
|
|
|
|
EventListenerManager* aEventListenerManager);
|
|
|
|
|
2017-06-06 02:29:04 +03:00
|
|
|
static KeyboardMap CollectKeyboardShortcuts();
|
|
|
|
|
2000-09-22 09:02:20 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2011-06-25 03:12:34 +04:00
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
2000-09-22 09:02:20 +04:00
|
|
|
|
|
|
|
protected:
|
2014-06-23 23:56:07 +04:00
|
|
|
virtual ~nsXBLWindowKeyHandler();
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult WalkHandlers(nsIDOMKeyEvent* aKeyEvent, nsAtom* aEventType);
|
2000-09-22 09:02:20 +04:00
|
|
|
|
2007-01-09 10:33:18 +03:00
|
|
|
// walk the handlers, looking for one to handle the event
|
2014-03-18 19:16:47 +04:00
|
|
|
bool WalkHandlersInternal(nsIDOMKeyEvent* aKeyEvent,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aEventType,
|
2014-03-18 19:16:47 +04:00
|
|
|
nsXBLPrototypeHandler* aHandler,
|
2015-03-12 18:03:08 +03:00
|
|
|
bool aExecute,
|
|
|
|
bool* aOutReservedForChrome = nullptr);
|
2000-09-22 09:02:20 +04:00
|
|
|
|
2014-12-12 15:17:37 +03:00
|
|
|
// walk the handlers for aEvent, aCharCode and aIgnoreModifierState. Execute
|
|
|
|
// it if aExecute = true.
|
2017-10-03 01:05:19 +03:00
|
|
|
bool WalkHandlersAndExecute(nsIDOMKeyEvent* aKeyEvent, nsAtom* aEventType,
|
2014-03-18 19:16:47 +04:00
|
|
|
nsXBLPrototypeHandler* aHandler,
|
2014-12-12 15:17:37 +03:00
|
|
|
uint32_t aCharCode,
|
|
|
|
const IgnoreModifierState& aIgnoreModifierState,
|
2015-03-12 18:03:08 +03:00
|
|
|
bool aExecute,
|
|
|
|
bool* aOutReservedForChrome = nullptr);
|
2014-03-18 19:16:47 +04:00
|
|
|
|
2016-03-16 04:58:28 +03:00
|
|
|
// HandleEvent function for the capturing phase in the default event group.
|
|
|
|
void HandleEventOnCaptureInDefaultEventGroup(nsIDOMKeyEvent* aEvent);
|
|
|
|
// HandleEvent function for the capturing phase in the system event group.
|
|
|
|
void HandleEventOnCaptureInSystemEventGroup(nsIDOMKeyEvent* aEvent);
|
2014-03-18 19:16:47 +04:00
|
|
|
|
2015-03-12 18:03:08 +03: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.
|
|
|
|
bool HasHandlerForEvent(nsIDOMKeyEvent* aEvent,
|
|
|
|
bool* aOutReservedForChrome = nullptr);
|
2008-04-15 08:16:24 +04:00
|
|
|
|
2016-04-22 20:12:54 +03:00
|
|
|
// Returns event type for matching between aWidgetKeyboardEvent and
|
|
|
|
// shortcut key handlers. This is used for calling WalkHandlers(),
|
|
|
|
// WalkHandlersInternal() and WalkHandlersAndExecute().
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* ConvertEventToDOMEventType(
|
2016-04-22 20:12:54 +03:00
|
|
|
const mozilla::WidgetKeyboardEvent& aWidgetKeyboardEvent) const;
|
|
|
|
|
2017-06-06 02:29:04 +03:00
|
|
|
// lazily load the special doc info for loading handlers
|
|
|
|
static void EnsureSpecialDocInfo();
|
|
|
|
|
2003-02-28 04:04:45 +03:00
|
|
|
// lazily load the handlers. Overridden to handle being attached
|
|
|
|
// to a particular element rather than the document
|
2014-01-23 07:18:51 +04:00
|
|
|
nsresult EnsureHandlers();
|
2007-01-09 10:33:18 +03:00
|
|
|
|
2014-01-23 07:18:51 +04:00
|
|
|
// Is an HTML editable element focused
|
|
|
|
bool IsHTMLEditableFieldFocused();
|
2007-01-09 10:33:18 +03:00
|
|
|
|
|
|
|
// Returns the element which was passed as a parameter to the constructor,
|
2014-03-18 19:16:47 +04: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 05:25:22 +03: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 17:16:21 +03: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 10:33:18 +03:00
|
|
|
// Using weak pointer to the DOM Element.
|
|
|
|
nsWeakPtr mWeakPtrForElement;
|
2013-04-14 22:27:33 +04:00
|
|
|
mozilla::dom::EventTarget* mTarget; // weak ref
|
2007-01-09 10:33:18 +03:00
|
|
|
|
|
|
|
// these are not owning references; the prototype handlers are owned
|
|
|
|
// by the prototype bindings which are owned by the docinfo.
|
|
|
|
nsXBLPrototypeHandler* mHandler; // platform bindings
|
|
|
|
nsXBLPrototypeHandler* mUserHandler; // user-specific bindings
|
|
|
|
|
2017-06-06 02:29:04 +03:00
|
|
|
// holds reference count to document info about bindings
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sRefCnt;
|
2000-09-22 09:02:20 +04:00
|
|
|
};
|
|
|
|
|
2013-04-14 22:27:33 +04:00
|
|
|
already_AddRefed<nsXBLWindowKeyHandler>
|
2000-09-22 09:02:20 +04:00
|
|
|
NS_NewXBLWindowKeyHandler(nsIDOMElement* aElement,
|
2013-04-14 22:27:33 +04:00
|
|
|
mozilla::dom::EventTarget* aTarget);
|
2000-09-22 09:02:20 +04:00
|
|
|
|
|
|
|
#endif
|