MiscEvents.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* -*- Mode: C++; tab-width: 2; 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 mozilla_MiscEvents_h__
  6. #define mozilla_MiscEvents_h__
  7. #include <stdint.h>
  8. #include "mozilla/BasicEvents.h"
  9. #include "nsCOMPtr.h"
  10. #include "nsIAtom.h"
  11. #include "nsITransferable.h"
  12. namespace mozilla {
  13. namespace dom {
  14. class PBrowserParent;
  15. class PBrowserChild;
  16. } // namespace dom
  17. /******************************************************************************
  18. * mozilla::WidgetContentCommandEvent
  19. ******************************************************************************/
  20. class WidgetContentCommandEvent : public WidgetGUIEvent
  21. {
  22. public:
  23. virtual WidgetContentCommandEvent* AsContentCommandEvent() override
  24. {
  25. return this;
  26. }
  27. WidgetContentCommandEvent(bool aIsTrusted, EventMessage aMessage,
  28. nsIWidget* aWidget,
  29. bool aOnlyEnabledCheck = false)
  30. : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eContentCommandEventClass)
  31. , mOnlyEnabledCheck(aOnlyEnabledCheck)
  32. , mSucceeded(false)
  33. , mIsEnabled(false)
  34. {
  35. }
  36. virtual WidgetEvent* Duplicate() const override
  37. {
  38. // This event isn't an internal event of any DOM event.
  39. NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
  40. "WidgetQueryContentEvent needs to support Duplicate()");
  41. MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
  42. return nullptr;
  43. }
  44. // eContentCommandPasteTransferable
  45. nsCOMPtr<nsITransferable> mTransferable; // [in]
  46. // eContentCommandScroll
  47. // for mScroll.mUnit
  48. enum
  49. {
  50. eCmdScrollUnit_Line,
  51. eCmdScrollUnit_Page,
  52. eCmdScrollUnit_Whole
  53. };
  54. struct ScrollInfo
  55. {
  56. ScrollInfo() :
  57. mAmount(0), mUnit(eCmdScrollUnit_Line), mIsHorizontal(false)
  58. {
  59. }
  60. int32_t mAmount; // [in]
  61. uint8_t mUnit; // [in]
  62. bool mIsHorizontal; // [in]
  63. } mScroll;
  64. bool mOnlyEnabledCheck; // [in]
  65. bool mSucceeded; // [out]
  66. bool mIsEnabled; // [out]
  67. void AssignContentCommandEventData(const WidgetContentCommandEvent& aEvent,
  68. bool aCopyTargets)
  69. {
  70. AssignGUIEventData(aEvent, aCopyTargets);
  71. mScroll = aEvent.mScroll;
  72. mOnlyEnabledCheck = aEvent.mOnlyEnabledCheck;
  73. mSucceeded = aEvent.mSucceeded;
  74. mIsEnabled = aEvent.mIsEnabled;
  75. }
  76. };
  77. /******************************************************************************
  78. * mozilla::WidgetCommandEvent
  79. *
  80. * This sends a command to chrome. If you want to request what is performed
  81. * in focused content, you should use WidgetContentCommandEvent instead.
  82. *
  83. * XXX Should be |WidgetChromeCommandEvent|?
  84. ******************************************************************************/
  85. class WidgetCommandEvent : public WidgetGUIEvent
  86. {
  87. public:
  88. virtual WidgetCommandEvent* AsCommandEvent() override { return this; }
  89. WidgetCommandEvent(bool aIsTrusted, nsIAtom* aEventType,
  90. nsIAtom* aCommand, nsIWidget* aWidget)
  91. : WidgetGUIEvent(aIsTrusted, eUnidentifiedEvent, aWidget,
  92. eCommandEventClass)
  93. , mCommand(aCommand)
  94. {
  95. mSpecifiedEventType = aEventType;
  96. }
  97. virtual WidgetEvent* Duplicate() const override
  98. {
  99. MOZ_ASSERT(mClass == eCommandEventClass,
  100. "Duplicate() must be overridden by sub class");
  101. // Not copying widget, it is a weak reference.
  102. WidgetCommandEvent* result =
  103. new WidgetCommandEvent(false, mSpecifiedEventType, mCommand, nullptr);
  104. result->AssignCommandEventData(*this, true);
  105. result->mFlags = mFlags;
  106. return result;
  107. }
  108. nsCOMPtr<nsIAtom> mCommand;
  109. // XXX Not tested by test_assign_event_data.html
  110. void AssignCommandEventData(const WidgetCommandEvent& aEvent,
  111. bool aCopyTargets)
  112. {
  113. AssignGUIEventData(aEvent, aCopyTargets);
  114. // mCommand must have been initialized with the constructor.
  115. }
  116. };
  117. /******************************************************************************
  118. * mozilla::WidgetPluginEvent
  119. *
  120. * This event delivers only a native event to focused plugin.
  121. ******************************************************************************/
  122. class WidgetPluginEvent : public WidgetGUIEvent
  123. {
  124. private:
  125. friend class dom::PBrowserParent;
  126. friend class dom::PBrowserChild;
  127. public:
  128. virtual WidgetPluginEvent* AsPluginEvent() override { return this; }
  129. WidgetPluginEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
  130. : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, ePluginEventClass)
  131. , mRetargetToFocusedDocument(false)
  132. {
  133. }
  134. virtual WidgetEvent* Duplicate() const override
  135. {
  136. // NOTE: PluginEvent has to be dispatched to nsIFrame::HandleEvent().
  137. // So, this event needs to support Duplicate().
  138. MOZ_ASSERT(mClass == ePluginEventClass,
  139. "Duplicate() must be overridden by sub class");
  140. // Not copying widget, it is a weak reference.
  141. WidgetPluginEvent* result = new WidgetPluginEvent(false, mMessage, nullptr);
  142. result->AssignPluginEventData(*this, true);
  143. result->mFlags = mFlags;
  144. return result;
  145. }
  146. // If true, this event needs to be retargeted to focused document.
  147. // Otherwise, never retargeted. Defaults to false.
  148. bool mRetargetToFocusedDocument;
  149. void AssignPluginEventData(const WidgetPluginEvent& aEvent,
  150. bool aCopyTargets)
  151. {
  152. AssignGUIEventData(aEvent, aCopyTargets);
  153. mRetargetToFocusedDocument = aEvent.mRetargetToFocusedDocument;
  154. }
  155. protected:
  156. WidgetPluginEvent()
  157. {
  158. }
  159. };
  160. } // namespace mozilla
  161. #endif // mozilla_MiscEvents_h__