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/. */
6 #ifndef mozilla_MiscEvents_h__
7 #define mozilla_MiscEvents_h__
11 #include "mozilla/BasicEvents.h"
14 #include "nsGkAtoms.h"
15 #include "nsITransferable.h"
24 /******************************************************************************
25 * mozilla::WidgetContentCommandEvent
26 ******************************************************************************/
28 class WidgetContentCommandEvent
: public WidgetGUIEvent
31 virtual WidgetContentCommandEvent
* AsContentCommandEvent() override
36 WidgetContentCommandEvent(bool aIsTrusted
, EventMessage aMessage
,
38 bool aOnlyEnabledCheck
= false)
39 : WidgetGUIEvent(aIsTrusted
, aMessage
, aWidget
, eContentCommandEventClass
)
40 , mOnlyEnabledCheck(aOnlyEnabledCheck
)
46 virtual WidgetEvent
* Duplicate() const override
48 // This event isn't an internal event of any DOM event.
49 NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
50 "WidgetQueryContentEvent needs to support Duplicate()");
51 MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
55 // eContentCommandPasteTransferable
56 nsCOMPtr
<nsITransferable
> mTransferable
; // [in]
58 // eContentCommandScroll
70 mAmount(0), mUnit(eCmdScrollUnit_Line
), mIsHorizontal(false)
74 int32_t mAmount
; // [in]
75 uint8_t mUnit
; // [in]
76 bool mIsHorizontal
; // [in]
79 bool mOnlyEnabledCheck
; // [in]
81 bool mSucceeded
; // [out]
82 bool mIsEnabled
; // [out]
84 void AssignContentCommandEventData(const WidgetContentCommandEvent
& aEvent
,
87 AssignGUIEventData(aEvent
, aCopyTargets
);
89 mScroll
= aEvent
.mScroll
;
90 mOnlyEnabledCheck
= aEvent
.mOnlyEnabledCheck
;
91 mSucceeded
= aEvent
.mSucceeded
;
92 mIsEnabled
= aEvent
.mIsEnabled
;
96 /******************************************************************************
97 * mozilla::WidgetCommandEvent
99 * This sends a command to chrome. If you want to request what is performed
100 * in focused content, you should use WidgetContentCommandEvent instead.
102 * XXX Should be |WidgetChromeCommandEvent|?
103 ******************************************************************************/
105 class WidgetCommandEvent
: public WidgetGUIEvent
108 virtual WidgetCommandEvent
* AsCommandEvent() override
{ return this; }
111 WidgetCommandEvent(bool aIsTrusted
, nsAtom
* aEventType
,
112 nsAtom
* aCommand
, nsIWidget
* aWidget
)
113 : WidgetGUIEvent(aIsTrusted
, eUnidentifiedEvent
, aWidget
,
117 mSpecifiedEventType
= aEventType
;
122 * Constructor to initialize an app command. This is the only case to
123 * initialize this class as a command in C++ stack.
125 WidgetCommandEvent(bool aIsTrusted
, nsAtom
* aCommand
, nsIWidget
* aWidget
)
126 : WidgetCommandEvent(aIsTrusted
, nsGkAtoms::onAppCommand
,
132 * Constructor to initialize as internal event of dom::CommandEvent.
135 : WidgetCommandEvent(false, nullptr, nullptr, nullptr)
139 virtual WidgetEvent
* Duplicate() const override
141 MOZ_ASSERT(mClass
== eCommandEventClass
,
142 "Duplicate() must be overridden by sub class");
143 // Not copying widget, it is a weak reference.
144 WidgetCommandEvent
* result
=
145 new WidgetCommandEvent(false, mSpecifiedEventType
, mCommand
, nullptr);
146 result
->AssignCommandEventData(*this, true);
147 result
->mFlags
= mFlags
;
151 RefPtr
<nsAtom
> mCommand
;
153 // XXX Not tested by test_assign_event_data.html
154 void AssignCommandEventData(const WidgetCommandEvent
& aEvent
,
157 AssignGUIEventData(aEvent
, aCopyTargets
);
159 // mCommand must have been initialized with the constructor.
163 /******************************************************************************
164 * mozilla::WidgetPluginEvent
166 * This event delivers only a native event to focused plugin.
167 ******************************************************************************/
169 class WidgetPluginEvent
: public WidgetGUIEvent
172 friend class dom::PBrowserParent
;
173 friend class dom::PBrowserChild
;
176 virtual WidgetPluginEvent
* AsPluginEvent() override
{ return this; }
178 WidgetPluginEvent(bool aIsTrusted
, EventMessage aMessage
, nsIWidget
* aWidget
)
179 : WidgetGUIEvent(aIsTrusted
, aMessage
, aWidget
, ePluginEventClass
)
180 , mRetargetToFocusedDocument(false)
184 virtual WidgetEvent
* Duplicate() const override
186 // NOTE: PluginEvent has to be dispatched to nsIFrame::HandleEvent().
187 // So, this event needs to support Duplicate().
188 MOZ_ASSERT(mClass
== ePluginEventClass
,
189 "Duplicate() must be overridden by sub class");
190 // Not copying widget, it is a weak reference.
191 WidgetPluginEvent
* result
= new WidgetPluginEvent(false, mMessage
, nullptr);
192 result
->AssignPluginEventData(*this, true);
193 result
->mFlags
= mFlags
;
197 // If true, this event needs to be retargeted to focused document.
198 // Otherwise, never retargeted. Defaults to false.
199 bool mRetargetToFocusedDocument
;
201 void AssignPluginEventData(const WidgetPluginEvent
& aEvent
,
204 AssignGUIEventData(aEvent
, aCopyTargets
);
206 mRetargetToFocusedDocument
= aEvent
.mRetargetToFocusedDocument
;
211 : mRetargetToFocusedDocument(false)
216 } // namespace mozilla
218 #endif // mozilla_MiscEvents_h__