Bug 1477919 [wpt PR 12154] - url: DecodeURLEscapeSequences() should not apply UTF...
[gecko.git] / widget / MiscEvents.h
blob7817492c01b24e7b90bc27a0292bcea0814c1363
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 "nsCOMPtr.h"
13 #include "nsAtom.h"
14 #include "nsGkAtoms.h"
15 #include "nsITransferable.h"
17 namespace mozilla {
19 namespace dom {
20 class PBrowserParent;
21 class PBrowserChild;
22 } // namespace dom
24 /******************************************************************************
25 * mozilla::WidgetContentCommandEvent
26 ******************************************************************************/
28 class WidgetContentCommandEvent : public WidgetGUIEvent
30 public:
31 virtual WidgetContentCommandEvent* AsContentCommandEvent() override
33 return this;
36 WidgetContentCommandEvent(bool aIsTrusted, EventMessage aMessage,
37 nsIWidget* aWidget,
38 bool aOnlyEnabledCheck = false)
39 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eContentCommandEventClass)
40 , mOnlyEnabledCheck(aOnlyEnabledCheck)
41 , mSucceeded(false)
42 , mIsEnabled(false)
46 virtual WidgetEvent* Duplicate() const override
48 // This event isn't an internal event of any DOM event.
49 NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
50 "WidgetQueryContentEvent needs to support Duplicate()");
51 MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
52 return nullptr;
55 // eContentCommandPasteTransferable
56 nsCOMPtr<nsITransferable> mTransferable; // [in]
58 // eContentCommandScroll
59 // for mScroll.mUnit
60 enum
62 eCmdScrollUnit_Line,
63 eCmdScrollUnit_Page,
64 eCmdScrollUnit_Whole
67 struct ScrollInfo
69 ScrollInfo() :
70 mAmount(0), mUnit(eCmdScrollUnit_Line), mIsHorizontal(false)
74 int32_t mAmount; // [in]
75 uint8_t mUnit; // [in]
76 bool mIsHorizontal; // [in]
77 } mScroll;
79 bool mOnlyEnabledCheck; // [in]
81 bool mSucceeded; // [out]
82 bool mIsEnabled; // [out]
84 void AssignContentCommandEventData(const WidgetContentCommandEvent& aEvent,
85 bool aCopyTargets)
87 AssignGUIEventData(aEvent, aCopyTargets);
89 mScroll = aEvent.mScroll;
90 mOnlyEnabledCheck = aEvent.mOnlyEnabledCheck;
91 mSucceeded = aEvent.mSucceeded;
92 mIsEnabled = aEvent.mIsEnabled;
96 /******************************************************************************
97 * mozilla::WidgetCommandEvent
99 * This sends a command to chrome. If you want to request what is performed
100 * in focused content, you should use WidgetContentCommandEvent instead.
102 * XXX Should be |WidgetChromeCommandEvent|?
103 ******************************************************************************/
105 class WidgetCommandEvent : public WidgetGUIEvent
107 public:
108 virtual WidgetCommandEvent* AsCommandEvent() override { return this; }
110 protected:
111 WidgetCommandEvent(bool aIsTrusted, nsAtom* aEventType,
112 nsAtom* aCommand, nsIWidget* aWidget)
113 : WidgetGUIEvent(aIsTrusted, eUnidentifiedEvent, aWidget,
114 eCommandEventClass)
115 , mCommand(aCommand)
117 mSpecifiedEventType = aEventType;
120 public:
122 * Constructor to initialize an app command. This is the only case to
123 * initialize this class as a command in C++ stack.
125 WidgetCommandEvent(bool aIsTrusted, nsAtom* aCommand, nsIWidget* aWidget)
126 : WidgetCommandEvent(aIsTrusted, nsGkAtoms::onAppCommand,
127 aCommand, aWidget)
132 * Constructor to initialize as internal event of dom::CommandEvent.
134 WidgetCommandEvent()
135 : WidgetCommandEvent(false, nullptr, nullptr, nullptr)
139 virtual WidgetEvent* Duplicate() const override
141 MOZ_ASSERT(mClass == eCommandEventClass,
142 "Duplicate() must be overridden by sub class");
143 // Not copying widget, it is a weak reference.
144 WidgetCommandEvent* result =
145 new WidgetCommandEvent(false, mSpecifiedEventType, mCommand, nullptr);
146 result->AssignCommandEventData(*this, true);
147 result->mFlags = mFlags;
148 return result;
151 RefPtr<nsAtom> mCommand;
153 // XXX Not tested by test_assign_event_data.html
154 void AssignCommandEventData(const WidgetCommandEvent& aEvent,
155 bool aCopyTargets)
157 AssignGUIEventData(aEvent, aCopyTargets);
159 // mCommand must have been initialized with the constructor.
163 /******************************************************************************
164 * mozilla::WidgetPluginEvent
166 * This event delivers only a native event to focused plugin.
167 ******************************************************************************/
169 class WidgetPluginEvent : public WidgetGUIEvent
171 private:
172 friend class dom::PBrowserParent;
173 friend class dom::PBrowserChild;
175 public:
176 virtual WidgetPluginEvent* AsPluginEvent() override { return this; }
178 WidgetPluginEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
179 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, ePluginEventClass)
180 , mRetargetToFocusedDocument(false)
184 virtual WidgetEvent* Duplicate() const override
186 // NOTE: PluginEvent has to be dispatched to nsIFrame::HandleEvent().
187 // So, this event needs to support Duplicate().
188 MOZ_ASSERT(mClass == ePluginEventClass,
189 "Duplicate() must be overridden by sub class");
190 // Not copying widget, it is a weak reference.
191 WidgetPluginEvent* result = new WidgetPluginEvent(false, mMessage, nullptr);
192 result->AssignPluginEventData(*this, true);
193 result->mFlags = mFlags;
194 return result;
197 // If true, this event needs to be retargeted to focused document.
198 // Otherwise, never retargeted. Defaults to false.
199 bool mRetargetToFocusedDocument;
201 void AssignPluginEventData(const WidgetPluginEvent& aEvent,
202 bool aCopyTargets)
204 AssignGUIEventData(aEvent, aCopyTargets);
206 mRetargetToFocusedDocument = aEvent.mRetargetToFocusedDocument;
209 protected:
210 WidgetPluginEvent()
211 : mRetargetToFocusedDocument(false)
216 } // namespace mozilla
218 #endif // mozilla_MiscEvents_h__