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"
|
2007-01-09 07:33:18 +00:00
|
|
|
#include "nsWeakPtr.h"
|
2011-06-24 23:12:34 +00:00
|
|
|
#include "nsIDOMEventListener.h"
|
2000-09-22 05:02:20 +00:00
|
|
|
|
|
|
|
class nsIAtom;
|
2007-01-09 07:33:18 +00:00
|
|
|
class nsIDOMElement;
|
2008-09-16 01:37:13 +00:00
|
|
|
class nsIDOMKeyEvent;
|
2007-01-09 07:33:18 +00:00
|
|
|
class nsXBLSpecialDocInfo;
|
|
|
|
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;
|
2013-04-14 18:27:33 +00:00
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
class EventTarget;
|
2014-12-12 12:17:37 +00:00
|
|
|
struct IgnoreModifierState;
|
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
|
2000-09-22 05:02:20 +00:00
|
|
|
{
|
2014-12-12 12:17:37 +00:00
|
|
|
typedef mozilla::dom::IgnoreModifierState IgnoreModifierState;
|
2016-03-16 01:58:28 +00:00
|
|
|
typedef mozilla::EventListenerManager EventListenerManager;
|
2014-12-12 12:17:37 +00:00
|
|
|
|
2000-09-22 05:02:20 +00:00
|
|
|
public:
|
2013-04-14 18:27:33 +00:00
|
|
|
nsXBLWindowKeyHandler(nsIDOMElement* 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);
|
|
|
|
|
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();
|
|
|
|
|
2008-09-16 01:37:13 +00:00
|
|
|
nsresult WalkHandlers(nsIDOMKeyEvent* aKeyEvent, nsIAtom* aEventType);
|
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
|
2014-03-18 15:16:47 +00:00
|
|
|
bool WalkHandlersInternal(nsIDOMKeyEvent* aKeyEvent,
|
|
|
|
nsIAtom* aEventType,
|
|
|
|
nsXBLPrototypeHandler* aHandler,
|
2015-03-12 15:03:08 +00:00
|
|
|
bool aExecute,
|
|
|
|
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.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool WalkHandlersAndExecute(nsIDOMKeyEvent* aKeyEvent, nsIAtom* aEventType,
|
2014-03-18 15:16:47 +00:00
|
|
|
nsXBLPrototypeHandler* aHandler,
|
2014-12-12 12:17:37 +00:00
|
|
|
uint32_t aCharCode,
|
|
|
|
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.
|
|
|
|
void HandleEventOnCaptureInDefaultEventGroup(nsIDOMKeyEvent* aEvent);
|
|
|
|
// HandleEvent function for the capturing phase in the system event group.
|
|
|
|
void HandleEventOnCaptureInSystemEventGroup(nsIDOMKeyEvent* 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.
|
|
|
|
bool HasHandlerForEvent(nsIDOMKeyEvent* aEvent,
|
|
|
|
bool* aOutReservedForChrome = nullptr);
|
2008-04-15 04:16:24 +00:00
|
|
|
|
2016-04-22 17:12:54 +00:00
|
|
|
// Returns event type for matching between aWidgetKeyboardEvent and
|
|
|
|
// shortcut key handlers. This is used for calling WalkHandlers(),
|
|
|
|
// WalkHandlersInternal() and WalkHandlersAndExecute().
|
|
|
|
nsIAtom* ConvertEventToDOMEventType(
|
|
|
|
const mozilla::WidgetKeyboardEvent& aWidgetKeyboardEvent) const;
|
|
|
|
|
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
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// holds document info about bindings
|
|
|
|
static nsXBLSpecialDocInfo* sXBLSpecialDocInfo;
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t sRefCnt;
|
2000-09-22 05:02:20 +00:00
|
|
|
};
|
|
|
|
|
2013-04-14 18:27:33 +00:00
|
|
|
already_AddRefed<nsXBLWindowKeyHandler>
|
2000-09-22 05:02:20 +00:00
|
|
|
NS_NewXBLWindowKeyHandler(nsIDOMElement* aElement,
|
2013-04-14 18:27:33 +00:00
|
|
|
mozilla::dom::EventTarget* aTarget);
|
2000-09-22 05:02:20 +00:00
|
|
|
|
|
|
|
#endif
|