Bug 1735754 [wpt PR 31232] - Make the higher-order comparisons in the structured...
[gecko.git] / widget / MiscEvents.h
blobea82c2c8d7523951e1aa67591cc29f6eaa9bd224
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__
9 #include <stdint.h>
11 #include "mozilla/BasicEvents.h"
12 #include "mozilla/Maybe.h"
13 #include "nsCOMPtr.h"
14 #include "nsAtom.h"
15 #include "nsGkAtoms.h"
16 #include "nsITransferable.h"
17 #include "nsString.h"
19 namespace mozilla {
21 namespace dom {
22 class PBrowserParent;
23 class PBrowserChild;
24 } // namespace dom
26 /******************************************************************************
27 * mozilla::WidgetContentCommandEvent
28 ******************************************************************************/
30 class WidgetContentCommandEvent : public WidgetGUIEvent {
31 public:
32 virtual WidgetContentCommandEvent* AsContentCommandEvent() override {
33 return this;
36 WidgetContentCommandEvent(bool aIsTrusted, EventMessage aMessage,
37 nsIWidget* aWidget, bool aOnlyEnabledCheck = false)
38 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget,
39 eContentCommandEventClass),
40 mOnlyEnabledCheck(aOnlyEnabledCheck),
41 mSucceeded(false),
42 mIsEnabled(false) {}
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()");
49 return nullptr;
52 // eContentCommandInsertText
53 mozilla::Maybe<nsString> mString; // [in]
55 // eContentCommandPasteTransferable
56 nsCOMPtr<nsITransferable> mTransferable; // [in]
58 // eContentCommandScroll
59 // for mScroll.mUnit
60 enum { eCmdScrollUnit_Line, eCmdScrollUnit_Page, eCmdScrollUnit_Whole };
62 struct ScrollInfo {
63 ScrollInfo()
64 : mAmount(0), mUnit(eCmdScrollUnit_Line), mIsHorizontal(false) {}
66 int32_t mAmount; // [in]
67 uint8_t mUnit; // [in]
68 bool mIsHorizontal; // [in]
69 } mScroll;
71 bool mOnlyEnabledCheck; // [in]
73 bool mSucceeded; // [out]
74 bool mIsEnabled; // [out]
76 void AssignContentCommandEventData(const WidgetContentCommandEvent& aEvent,
77 bool aCopyTargets) {
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 {
98 public:
99 virtual WidgetCommandEvent* AsCommandEvent() override { return this; }
101 protected:
102 WidgetCommandEvent(bool aIsTrusted, nsAtom* aEventType, nsAtom* aCommand,
103 nsIWidget* aWidget)
104 : WidgetGUIEvent(aIsTrusted, eUnidentifiedEvent, aWidget,
105 eCommandEventClass),
106 mCommand(aCommand) {
107 mSpecifiedEventType = aEventType;
110 public:
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,
117 aWidget) {}
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;
132 return result;
135 RefPtr<nsAtom> mCommand;
137 // XXX Not tested by test_assign_event_data.html
138 void AssignCommandEventData(const WidgetCommandEvent& aEvent,
139 bool aCopyTargets) {
140 AssignGUIEventData(aEvent, aCopyTargets);
142 // mCommand must have been initialized with the constructor.
146 } // namespace mozilla
148 #endif // mozilla_MiscEvents_h__