nsXBLEventHandler.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsXBLEventHandler_h__
  6. #define nsXBLEventHandler_h__
  7. #include "mozilla/Attributes.h"
  8. #include "nsCOMPtr.h"
  9. #include "nsIDOMEventListener.h"
  10. #include "nsTArray.h"
  11. class nsIAtom;
  12. class nsIDOMKeyEvent;
  13. class nsXBLPrototypeHandler;
  14. namespace mozilla {
  15. namespace dom {
  16. struct IgnoreModifierState;
  17. } // namespace dom
  18. } // namespace mozilla
  19. class nsXBLEventHandler : public nsIDOMEventListener
  20. {
  21. public:
  22. explicit nsXBLEventHandler(nsXBLPrototypeHandler* aHandler);
  23. NS_DECL_ISUPPORTS
  24. NS_DECL_NSIDOMEVENTLISTENER
  25. protected:
  26. virtual ~nsXBLEventHandler();
  27. nsXBLPrototypeHandler* mProtoHandler;
  28. private:
  29. nsXBLEventHandler();
  30. virtual bool EventMatched(nsIDOMEvent* aEvent)
  31. {
  32. return true;
  33. }
  34. };
  35. class nsXBLMouseEventHandler : public nsXBLEventHandler
  36. {
  37. public:
  38. explicit nsXBLMouseEventHandler(nsXBLPrototypeHandler* aHandler);
  39. virtual ~nsXBLMouseEventHandler();
  40. private:
  41. bool EventMatched(nsIDOMEvent* aEvent) override;
  42. };
  43. class nsXBLKeyEventHandler : public nsIDOMEventListener
  44. {
  45. typedef mozilla::dom::IgnoreModifierState IgnoreModifierState;
  46. public:
  47. nsXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase, uint8_t aType);
  48. NS_DECL_ISUPPORTS
  49. NS_DECL_NSIDOMEVENTLISTENER
  50. void AddProtoHandler(nsXBLPrototypeHandler* aProtoHandler)
  51. {
  52. mProtoHandlers.AppendElement(aProtoHandler);
  53. }
  54. bool Matches(nsIAtom* aEventType, uint8_t aPhase, uint8_t aType) const
  55. {
  56. return (mEventType == aEventType && mPhase == aPhase && mType == aType);
  57. }
  58. void GetEventName(nsAString& aString) const
  59. {
  60. mEventType->ToString(aString);
  61. }
  62. uint8_t GetPhase() const
  63. {
  64. return mPhase;
  65. }
  66. uint8_t GetType() const
  67. {
  68. return mType;
  69. }
  70. void SetIsBoundToChrome(bool aIsBoundToChrome)
  71. {
  72. mIsBoundToChrome = aIsBoundToChrome;
  73. }
  74. void SetUsingContentXBLScope(bool aUsingContentXBLScope)
  75. {
  76. mUsingContentXBLScope = aUsingContentXBLScope;
  77. }
  78. private:
  79. nsXBLKeyEventHandler();
  80. virtual ~nsXBLKeyEventHandler();
  81. bool ExecuteMatchedHandlers(nsIDOMKeyEvent* aEvent, uint32_t aCharCode,
  82. const IgnoreModifierState& aIgnoreModifierState);
  83. nsTArray<nsXBLPrototypeHandler*> mProtoHandlers;
  84. nsCOMPtr<nsIAtom> mEventType;
  85. uint8_t mPhase;
  86. uint8_t mType;
  87. bool mIsBoundToChrome;
  88. bool mUsingContentXBLScope;
  89. };
  90. already_AddRefed<nsXBLEventHandler>
  91. NS_NewXBLEventHandler(nsXBLPrototypeHandler* aHandler,
  92. nsIAtom* aEventType);
  93. #endif