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 and eContentCommandReplaceText
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 // eContentCommandReplaceText
73 // Replacement source string. If not matched, failed
74 nsString mReplaceSrcString
; // [in]
75 // Start offset of selection
76 uint32_t mOffset
= 0; // [in]
77 // false if selection is end of replaced string
78 bool mPreventSetSelection
= false; // [in]
81 // If set to true, the event checks whether the command is enabled in the
82 // process or not without executing the command. I.e., if it's in the parent
83 // process when a remote process has focus, mIsEnabled may be different from
84 // the latest state of the command in the remote process.
85 bool mOnlyEnabledCheck
; // [in]
87 bool mSucceeded
; // [out]
89 // If the command is enabled, set to true. Otherwise, false. This is set
90 // synchronously in the process. If it's in the parent process when a remote
91 // process has focus, this returns the command state in the parent process
92 // which may be different from the remote process.
93 // XXX When mOnlyEnabledCheck is set to true, this may be always set to true
94 // even when the command is disabled in the parent process.
95 bool mIsEnabled
; // [out]
97 void AssignContentCommandEventData(const WidgetContentCommandEvent
& aEvent
,
99 AssignGUIEventData(aEvent
, aCopyTargets
);
101 mString
= aEvent
.mString
;
102 mScroll
= aEvent
.mScroll
;
103 mSelection
= aEvent
.mSelection
;
104 mOnlyEnabledCheck
= aEvent
.mOnlyEnabledCheck
;
105 mSucceeded
= aEvent
.mSucceeded
;
106 mIsEnabled
= aEvent
.mIsEnabled
;
110 /******************************************************************************
111 * mozilla::WidgetCommandEvent
113 * This sends a command to chrome. If you want to request what is performed
114 * in focused content, you should use WidgetContentCommandEvent instead.
116 * XXX Should be |WidgetChromeCommandEvent|?
117 ******************************************************************************/
119 class WidgetCommandEvent
: public WidgetGUIEvent
{
121 virtual WidgetCommandEvent
* AsCommandEvent() override
{ return this; }
124 WidgetCommandEvent(bool aIsTrusted
, nsAtom
* aEventType
, nsAtom
* aCommand
,
125 nsIWidget
* aWidget
, const WidgetEventTime
* aTime
= nullptr)
126 : WidgetGUIEvent(aIsTrusted
, eUnidentifiedEvent
, aWidget
,
127 eCommandEventClass
, aTime
),
129 mSpecifiedEventType
= aEventType
;
134 * Constructor to initialize an app command. This is the only case to
135 * initialize this class as a command in C++ stack.
137 WidgetCommandEvent(bool aIsTrusted
, nsAtom
* aCommand
, nsIWidget
* aWidget
,
138 const WidgetEventTime
* aTime
= nullptr)
139 : WidgetCommandEvent(aIsTrusted
, nsGkAtoms::onAppCommand
, aCommand
,
143 * Constructor to initialize as internal event of dom::CommandEvent.
146 : WidgetCommandEvent(false, nullptr, nullptr, nullptr, nullptr) {}
148 virtual WidgetEvent
* Duplicate() const override
{
149 MOZ_ASSERT(mClass
== eCommandEventClass
,
150 "Duplicate() must be overridden by sub class");
151 // Not copying widget, it is a weak reference.
152 WidgetCommandEvent
* result
= new WidgetCommandEvent(
153 false, mSpecifiedEventType
, mCommand
, nullptr, this);
154 result
->AssignCommandEventData(*this, true);
155 result
->mFlags
= mFlags
;
159 RefPtr
<nsAtom
> mCommand
;
161 // XXX Not tested by test_assign_event_data.html
162 void AssignCommandEventData(const WidgetCommandEvent
& aEvent
,
164 AssignGUIEventData(aEvent
, aCopyTargets
);
166 // mCommand must have been initialized with the constructor.
170 } // namespace mozilla
172 #endif // mozilla_MiscEvents_h__