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
{
30 virtual WidgetContentCommandEvent
* AsContentCommandEvent() override
{
34 WidgetContentCommandEvent(bool aIsTrusted
, EventMessage aMessage
,
35 nsIWidget
* aWidget
, bool aOnlyEnabledCheck
= false)
36 : WidgetGUIEvent(aIsTrusted
, aMessage
, aWidget
,
37 eContentCommandEventClass
),
38 mOnlyEnabledCheck(aOnlyEnabledCheck
),
42 virtual WidgetEvent
* Duplicate() const override
{
43 // This event isn't an internal event of any DOM event.
44 NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
45 "WidgetQueryContentEvent needs to support Duplicate()");
46 MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
50 // eContentCommandPasteTransferable
51 nsCOMPtr
<nsITransferable
> mTransferable
; // [in]
53 // eContentCommandScroll
55 enum { eCmdScrollUnit_Line
, eCmdScrollUnit_Page
, eCmdScrollUnit_Whole
};
59 : mAmount(0), mUnit(eCmdScrollUnit_Line
), mIsHorizontal(false) {}
61 int32_t mAmount
; // [in]
62 uint8_t mUnit
; // [in]
63 bool mIsHorizontal
; // [in]
66 bool mOnlyEnabledCheck
; // [in]
68 bool mSucceeded
; // [out]
69 bool mIsEnabled
; // [out]
71 void AssignContentCommandEventData(const WidgetContentCommandEvent
& aEvent
,
73 AssignGUIEventData(aEvent
, aCopyTargets
);
75 mScroll
= aEvent
.mScroll
;
76 mOnlyEnabledCheck
= aEvent
.mOnlyEnabledCheck
;
77 mSucceeded
= aEvent
.mSucceeded
;
78 mIsEnabled
= aEvent
.mIsEnabled
;
82 /******************************************************************************
83 * mozilla::WidgetCommandEvent
85 * This sends a command to chrome. If you want to request what is performed
86 * in focused content, you should use WidgetContentCommandEvent instead.
88 * XXX Should be |WidgetChromeCommandEvent|?
89 ******************************************************************************/
91 class WidgetCommandEvent
: public WidgetGUIEvent
{
93 virtual WidgetCommandEvent
* AsCommandEvent() override
{ return this; }
96 WidgetCommandEvent(bool aIsTrusted
, nsAtom
* aEventType
, nsAtom
* aCommand
,
98 : WidgetGUIEvent(aIsTrusted
, eUnidentifiedEvent
, aWidget
,
101 mSpecifiedEventType
= aEventType
;
106 * Constructor to initialize an app command. This is the only case to
107 * initialize this class as a command in C++ stack.
109 WidgetCommandEvent(bool aIsTrusted
, nsAtom
* aCommand
, nsIWidget
* aWidget
)
110 : WidgetCommandEvent(aIsTrusted
, nsGkAtoms::onAppCommand
, aCommand
,
114 * Constructor to initialize as internal event of dom::CommandEvent.
116 WidgetCommandEvent() : WidgetCommandEvent(false, nullptr, nullptr, nullptr) {}
118 virtual WidgetEvent
* Duplicate() const override
{
119 MOZ_ASSERT(mClass
== eCommandEventClass
,
120 "Duplicate() must be overridden by sub class");
121 // Not copying widget, it is a weak reference.
122 WidgetCommandEvent
* result
=
123 new WidgetCommandEvent(false, mSpecifiedEventType
, mCommand
, nullptr);
124 result
->AssignCommandEventData(*this, true);
125 result
->mFlags
= mFlags
;
129 RefPtr
<nsAtom
> mCommand
;
131 // XXX Not tested by test_assign_event_data.html
132 void AssignCommandEventData(const WidgetCommandEvent
& aEvent
,
134 AssignGUIEventData(aEvent
, aCopyTargets
);
136 // mCommand must have been initialized with the constructor.
140 } // namespace mozilla
142 #endif // mozilla_MiscEvents_h__