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 nsXBLEventHandler_h__ michael@0: #define nsXBLEventHandler_h__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIDOMEventListener.h" michael@0: #include "nsTArray.h" michael@0: michael@0: class nsIAtom; michael@0: class nsIDOMKeyEvent; michael@0: class nsXBLPrototypeHandler; michael@0: michael@0: class nsXBLEventHandler : public nsIDOMEventListener michael@0: { michael@0: public: michael@0: nsXBLEventHandler(nsXBLPrototypeHandler* aHandler); michael@0: virtual ~nsXBLEventHandler(); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: NS_DECL_NSIDOMEVENTLISTENER michael@0: michael@0: protected: michael@0: nsXBLPrototypeHandler* mProtoHandler; michael@0: michael@0: private: michael@0: nsXBLEventHandler(); michael@0: virtual bool EventMatched(nsIDOMEvent* aEvent) michael@0: { michael@0: return true; michael@0: } michael@0: }; michael@0: michael@0: class nsXBLMouseEventHandler : public nsXBLEventHandler michael@0: { michael@0: public: michael@0: nsXBLMouseEventHandler(nsXBLPrototypeHandler* aHandler); michael@0: virtual ~nsXBLMouseEventHandler(); michael@0: michael@0: private: michael@0: bool EventMatched(nsIDOMEvent* aEvent) MOZ_OVERRIDE; michael@0: }; michael@0: michael@0: class nsXBLKeyEventHandler : public nsIDOMEventListener michael@0: { michael@0: public: michael@0: nsXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase, uint8_t aType); michael@0: virtual ~nsXBLKeyEventHandler(); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: NS_DECL_NSIDOMEVENTLISTENER michael@0: michael@0: void AddProtoHandler(nsXBLPrototypeHandler* aProtoHandler) michael@0: { michael@0: mProtoHandlers.AppendElement(aProtoHandler); michael@0: } michael@0: michael@0: bool Matches(nsIAtom* aEventType, uint8_t aPhase, uint8_t aType) const michael@0: { michael@0: return (mEventType == aEventType && mPhase == aPhase && mType == aType); michael@0: } michael@0: michael@0: void GetEventName(nsAString& aString) const michael@0: { michael@0: mEventType->ToString(aString); michael@0: } michael@0: michael@0: uint8_t GetPhase() const michael@0: { michael@0: return mPhase; michael@0: } michael@0: michael@0: uint8_t GetType() const michael@0: { michael@0: return mType; michael@0: } michael@0: michael@0: void SetIsBoundToChrome(bool aIsBoundToChrome) michael@0: { michael@0: mIsBoundToChrome = aIsBoundToChrome; michael@0: } michael@0: michael@0: void SetUsingXBLScope(bool aUsingXBLScope) michael@0: { michael@0: mUsingXBLScope = aUsingXBLScope; michael@0: } michael@0: michael@0: private: michael@0: nsXBLKeyEventHandler(); michael@0: bool ExecuteMatchedHandlers(nsIDOMKeyEvent* aEvent, uint32_t aCharCode, michael@0: bool aIgnoreShiftKey); michael@0: michael@0: nsTArray mProtoHandlers; michael@0: nsCOMPtr mEventType; michael@0: uint8_t mPhase; michael@0: uint8_t mType; michael@0: bool mIsBoundToChrome; michael@0: bool mUsingXBLScope; michael@0: }; michael@0: michael@0: nsresult michael@0: NS_NewXBLEventHandler(nsXBLPrototypeHandler* aHandler, michael@0: nsIAtom* aEventType, michael@0: nsXBLEventHandler** aResult); michael@0: michael@0: nsresult michael@0: NS_NewXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase, michael@0: uint8_t aType, nsXBLKeyEventHandler** aResult); michael@0: michael@0: #endif