michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsXBLWindowKeyHandler_h__ michael@0: #define nsXBLWindowKeyHandler_h__ michael@0: michael@0: #include "nsWeakPtr.h" michael@0: #include "nsIDOMEventListener.h" michael@0: michael@0: class nsIAtom; michael@0: class nsIDOMElement; michael@0: class nsIDOMKeyEvent; michael@0: class nsXBLSpecialDocInfo; michael@0: class nsXBLPrototypeHandler; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class Element; michael@0: class EventTarget; michael@0: } michael@0: } michael@0: michael@0: class nsXBLWindowKeyHandler : public nsIDOMEventListener michael@0: { michael@0: public: michael@0: nsXBLWindowKeyHandler(nsIDOMElement* aElement, mozilla::dom::EventTarget* aTarget); michael@0: virtual ~nsXBLWindowKeyHandler(); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIDOMEVENTLISTENER michael@0: michael@0: protected: michael@0: nsresult WalkHandlers(nsIDOMKeyEvent* aKeyEvent, nsIAtom* aEventType); michael@0: michael@0: // walk the handlers, looking for one to handle the event michael@0: bool WalkHandlersInternal(nsIDOMKeyEvent* aKeyEvent, michael@0: nsIAtom* aEventType, michael@0: nsXBLPrototypeHandler* aHandler, michael@0: bool aExecute); michael@0: michael@0: // walk the handlers for aEvent, aCharCode and aIgnoreShiftKey. Execute it michael@0: // if aExecute = true. michael@0: bool WalkHandlersAndExecute(nsIDOMKeyEvent* aKeyEvent, nsIAtom* aEventType, michael@0: nsXBLPrototypeHandler* aHandler, michael@0: uint32_t aCharCode, bool aIgnoreShiftKey, michael@0: bool aExecute); michael@0: michael@0: // HandleEvent function for the capturing phase. michael@0: void HandleEventOnCapture(nsIDOMKeyEvent* aEvent); michael@0: michael@0: // Check if any handler would handle the given event. michael@0: bool HasHandlerForEvent(nsIDOMKeyEvent* aEvent); michael@0: michael@0: // lazily load the handlers. Overridden to handle being attached michael@0: // to a particular element rather than the document michael@0: nsresult EnsureHandlers(); michael@0: michael@0: // check if the given handler cares about the given key event michael@0: bool EventMatched(nsXBLPrototypeHandler* inHandler, nsIAtom* inEventType, michael@0: nsIDOMKeyEvent* inEvent, uint32_t aCharCode, michael@0: bool aIgnoreShiftKey); michael@0: michael@0: // Is an HTML editable element focused michael@0: bool IsHTMLEditableFieldFocused(); michael@0: michael@0: // Returns the element which was passed as a parameter to the constructor, michael@0: // unless the element has been removed from the document. Optionally returns michael@0: // whether the disabled attribute is set on the element (assuming the element michael@0: // is non-null). michael@0: already_AddRefed GetElement(bool* aIsDisabled = nullptr); michael@0: // Using weak pointer to the DOM Element. michael@0: nsWeakPtr mWeakPtrForElement; michael@0: mozilla::dom::EventTarget* mTarget; // weak ref michael@0: michael@0: // these are not owning references; the prototype handlers are owned michael@0: // by the prototype bindings which are owned by the docinfo. michael@0: nsXBLPrototypeHandler* mHandler; // platform bindings michael@0: nsXBLPrototypeHandler* mUserHandler; // user-specific bindings michael@0: michael@0: // holds document info about bindings michael@0: static nsXBLSpecialDocInfo* sXBLSpecialDocInfo; michael@0: static uint32_t sRefCnt; michael@0: }; michael@0: michael@0: already_AddRefed michael@0: NS_NewXBLWindowKeyHandler(nsIDOMElement* aElement, michael@0: mozilla::dom::EventTarget* aTarget); michael@0: michael@0: #endif