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
,
103 nsIWidget
* aWidget
, const WidgetEventTime
* aTime
= nullptr)
104 : WidgetGUIEvent(aIsTrusted
, eUnidentifiedEvent
, aWidget
,
105 eCommandEventClass
, aTime
),
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 const WidgetEventTime
* aTime
= nullptr)
117 : WidgetCommandEvent(aIsTrusted
, nsGkAtoms::onAppCommand
, aCommand
,
121 * Constructor to initialize as internal event of dom::CommandEvent.
124 : WidgetCommandEvent(false, nullptr, nullptr, nullptr, nullptr) {}
126 virtual WidgetEvent
* Duplicate() const override
{
127 MOZ_ASSERT(mClass
== eCommandEventClass
,
128 "Duplicate() must be overridden by sub class");
129 // Not copying widget, it is a weak reference.
130 WidgetCommandEvent
* result
= new WidgetCommandEvent(
131 false, mSpecifiedEventType
, mCommand
, nullptr, this);
132 result
->AssignCommandEventData(*this, true);
133 result
->mFlags
= mFlags
;
137 RefPtr
<nsAtom
> mCommand
;
139 // XXX Not tested by test_assign_event_data.html
140 void AssignCommandEventData(const WidgetCommandEvent
& aEvent
,
142 AssignGUIEventData(aEvent
, aCopyTargets
);
144 // mCommand must have been initialized with the constructor.
148 } // namespace mozilla
150 #endif // mozilla_MiscEvents_h__