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"
12 #include "mozilla/Maybe.h"
15 #include "nsGkAtoms.h"
16 #include "nsITransferable.h"
26 /******************************************************************************
27 * mozilla::WidgetContentCommandEvent
28 ******************************************************************************/
30 class WidgetContentCommandEvent
: public WidgetGUIEvent
{
32 virtual WidgetContentCommandEvent
* AsContentCommandEvent() override
{
36 WidgetContentCommandEvent(bool aIsTrusted
, EventMessage aMessage
,
37 nsIWidget
* aWidget
, bool aOnlyEnabledCheck
= false)
38 : WidgetGUIEvent(aIsTrusted
, aMessage
, aWidget
,
39 eContentCommandEventClass
),
40 mOnlyEnabledCheck(aOnlyEnabledCheck
),
44 virtual WidgetEvent
* Duplicate() const override
{
45 // This event isn't an internal event of any DOM event.
46 NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
47 "WidgetQueryContentEvent needs to support Duplicate()");
48 MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
52 // eContentCommandInsertText
53 mozilla::Maybe
<nsString
> mString
; // [in]
55 // eContentCommandPasteTransferable
56 nsCOMPtr
<nsITransferable
> mTransferable
; // [in]
58 // eContentCommandScroll
60 enum { eCmdScrollUnit_Line
, eCmdScrollUnit_Page
, eCmdScrollUnit_Whole
};
64 : mAmount(0), mUnit(eCmdScrollUnit_Line
), mIsHorizontal(false) {}
66 int32_t mAmount
; // [in]
67 uint8_t mUnit
; // [in]
68 bool mIsHorizontal
; // [in]
71 bool mOnlyEnabledCheck
; // [in]
73 bool mSucceeded
; // [out]
74 bool mIsEnabled
; // [out]
76 void AssignContentCommandEventData(const WidgetContentCommandEvent
& aEvent
,
78 AssignGUIEventData(aEvent
, aCopyTargets
);
80 mString
= aEvent
.mString
;
81 mScroll
= aEvent
.mScroll
;
82 mOnlyEnabledCheck
= aEvent
.mOnlyEnabledCheck
;
83 mSucceeded
= aEvent
.mSucceeded
;
84 mIsEnabled
= aEvent
.mIsEnabled
;
88 /******************************************************************************
89 * mozilla::WidgetCommandEvent
91 * This sends a command to chrome. If you want to request what is performed
92 * in focused content, you should use WidgetContentCommandEvent instead.
94 * XXX Should be |WidgetChromeCommandEvent|?
95 ******************************************************************************/
97 class WidgetCommandEvent
: public WidgetGUIEvent
{
99 virtual WidgetCommandEvent
* AsCommandEvent() override
{ return this; }
102 WidgetCommandEvent(bool aIsTrusted
, nsAtom
* aEventType
, nsAtom
* aCommand
,
104 : WidgetGUIEvent(aIsTrusted
, eUnidentifiedEvent
, aWidget
,
107 mSpecifiedEventType
= aEventType
;
112 * Constructor to initialize an app command. This is the only case to
113 * initialize this class as a command in C++ stack.
115 WidgetCommandEvent(bool aIsTrusted
, nsAtom
* aCommand
, nsIWidget
* aWidget
)
116 : WidgetCommandEvent(aIsTrusted
, nsGkAtoms::onAppCommand
, aCommand
,
120 * Constructor to initialize as internal event of dom::CommandEvent.
122 WidgetCommandEvent() : WidgetCommandEvent(false, nullptr, nullptr, nullptr) {}
124 virtual WidgetEvent
* Duplicate() const override
{
125 MOZ_ASSERT(mClass
== eCommandEventClass
,
126 "Duplicate() must be overridden by sub class");
127 // Not copying widget, it is a weak reference.
128 WidgetCommandEvent
* result
=
129 new WidgetCommandEvent(false, mSpecifiedEventType
, mCommand
, nullptr);
130 result
->AssignCommandEventData(*this, true);
131 result
->mFlags
= mFlags
;
135 RefPtr
<nsAtom
> mCommand
;
137 // XXX Not tested by test_assign_event_data.html
138 void AssignCommandEventData(const WidgetCommandEvent
& aEvent
,
140 AssignGUIEventData(aEvent
, aCopyTargets
);
142 // mCommand must have been initialized with the constructor.
146 } // namespace mozilla
148 #endif // mozilla_MiscEvents_h__