dom/xbl/nsXBLEventHandler.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xbl/nsXBLEventHandler.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,116 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsXBLEventHandler_h__
    1.10 +#define nsXBLEventHandler_h__
    1.11 +
    1.12 +#include "mozilla/Attributes.h"
    1.13 +#include "nsCOMPtr.h"
    1.14 +#include "nsIDOMEventListener.h"
    1.15 +#include "nsTArray.h"
    1.16 +
    1.17 +class nsIAtom;
    1.18 +class nsIDOMKeyEvent;
    1.19 +class nsXBLPrototypeHandler;
    1.20 +
    1.21 +class nsXBLEventHandler : public nsIDOMEventListener
    1.22 +{
    1.23 +public:
    1.24 +  nsXBLEventHandler(nsXBLPrototypeHandler* aHandler);
    1.25 +  virtual ~nsXBLEventHandler();
    1.26 +
    1.27 +  NS_DECL_ISUPPORTS
    1.28 +
    1.29 +  NS_DECL_NSIDOMEVENTLISTENER
    1.30 +
    1.31 +protected:
    1.32 +  nsXBLPrototypeHandler* mProtoHandler;
    1.33 +
    1.34 +private:
    1.35 +  nsXBLEventHandler();
    1.36 +  virtual bool EventMatched(nsIDOMEvent* aEvent)
    1.37 +  {
    1.38 +    return true;
    1.39 +  }
    1.40 +};
    1.41 +
    1.42 +class nsXBLMouseEventHandler : public nsXBLEventHandler
    1.43 +{
    1.44 +public:
    1.45 +  nsXBLMouseEventHandler(nsXBLPrototypeHandler* aHandler);
    1.46 +  virtual ~nsXBLMouseEventHandler();
    1.47 +
    1.48 +private:
    1.49 +  bool EventMatched(nsIDOMEvent* aEvent) MOZ_OVERRIDE;
    1.50 +};
    1.51 +
    1.52 +class nsXBLKeyEventHandler : public nsIDOMEventListener
    1.53 +{
    1.54 +public:
    1.55 +  nsXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase, uint8_t aType);
    1.56 +  virtual ~nsXBLKeyEventHandler();
    1.57 +
    1.58 +  NS_DECL_ISUPPORTS
    1.59 +
    1.60 +  NS_DECL_NSIDOMEVENTLISTENER
    1.61 +
    1.62 +  void AddProtoHandler(nsXBLPrototypeHandler* aProtoHandler)
    1.63 +  {
    1.64 +    mProtoHandlers.AppendElement(aProtoHandler);
    1.65 +  }
    1.66 +
    1.67 +  bool Matches(nsIAtom* aEventType, uint8_t aPhase, uint8_t aType) const
    1.68 +  {
    1.69 +    return (mEventType == aEventType && mPhase == aPhase && mType == aType);
    1.70 +  }
    1.71 +
    1.72 +  void GetEventName(nsAString& aString) const
    1.73 +  {
    1.74 +    mEventType->ToString(aString);
    1.75 +  }
    1.76 +
    1.77 +  uint8_t GetPhase() const
    1.78 +  {
    1.79 +    return mPhase;
    1.80 +  }
    1.81 +
    1.82 +  uint8_t GetType() const
    1.83 +  {
    1.84 +    return mType;
    1.85 +  }
    1.86 +
    1.87 +  void SetIsBoundToChrome(bool aIsBoundToChrome)
    1.88 +  {
    1.89 +    mIsBoundToChrome = aIsBoundToChrome;
    1.90 +  }
    1.91 +
    1.92 +  void SetUsingXBLScope(bool aUsingXBLScope)
    1.93 +  {
    1.94 +    mUsingXBLScope = aUsingXBLScope;
    1.95 +  }
    1.96 +
    1.97 +private:
    1.98 +  nsXBLKeyEventHandler();
    1.99 +  bool ExecuteMatchedHandlers(nsIDOMKeyEvent* aEvent, uint32_t aCharCode,
   1.100 +                                bool aIgnoreShiftKey);
   1.101 +
   1.102 +  nsTArray<nsXBLPrototypeHandler*> mProtoHandlers;
   1.103 +  nsCOMPtr<nsIAtom> mEventType;
   1.104 +  uint8_t mPhase;
   1.105 +  uint8_t mType;
   1.106 +  bool mIsBoundToChrome;
   1.107 +  bool mUsingXBLScope;
   1.108 +};
   1.109 +
   1.110 +nsresult
   1.111 +NS_NewXBLEventHandler(nsXBLPrototypeHandler* aHandler,
   1.112 +                      nsIAtom* aEventType,
   1.113 +                      nsXBLEventHandler** aResult);
   1.114 +
   1.115 +nsresult
   1.116 +NS_NewXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase,
   1.117 +                         uint8_t aType, nsXBLKeyEventHandler** aResult);
   1.118 +
   1.119 +#endif

mercurial