Bug 1468402 - Part 3: Add test for subgrids in the grid list. r=pbro
[gecko.git] / widget / MiscEvents.h
blob9d21d1bca5766defc03c7ac8a1999194f7158681
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 {
29 public:
30 virtual WidgetContentCommandEvent* AsContentCommandEvent() override {
31 return this;
34 WidgetContentCommandEvent(bool aIsTrusted, EventMessage aMessage,
35 nsIWidget* aWidget, bool aOnlyEnabledCheck = false)
36 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget,
37 eContentCommandEventClass),
38 mOnlyEnabledCheck(aOnlyEnabledCheck),
39 mSucceeded(false),
40 mIsEnabled(false) {}
42 virtual WidgetEvent* Duplicate() const override {
43 // This event isn't an internal event of any DOM event.
44 NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
45 "WidgetQueryContentEvent needs to support Duplicate()");
46 MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
47 return nullptr;
50 // eContentCommandPasteTransferable
51 nsCOMPtr<nsITransferable> mTransferable; // [in]
53 // eContentCommandScroll
54 // for mScroll.mUnit
55 enum { eCmdScrollUnit_Line, eCmdScrollUnit_Page, eCmdScrollUnit_Whole };
57 struct ScrollInfo {
58 ScrollInfo()
59 : mAmount(0), mUnit(eCmdScrollUnit_Line), mIsHorizontal(false) {}
61 int32_t mAmount; // [in]
62 uint8_t mUnit; // [in]
63 bool mIsHorizontal; // [in]
64 } mScroll;
66 bool mOnlyEnabledCheck; // [in]
68 bool mSucceeded; // [out]
69 bool mIsEnabled; // [out]
71 void AssignContentCommandEventData(const WidgetContentCommandEvent& aEvent,
72 bool aCopyTargets) {
73 AssignGUIEventData(aEvent, aCopyTargets);
75 mScroll = aEvent.mScroll;
76 mOnlyEnabledCheck = aEvent.mOnlyEnabledCheck;
77 mSucceeded = aEvent.mSucceeded;
78 mIsEnabled = aEvent.mIsEnabled;
82 /******************************************************************************
83 * mozilla::WidgetCommandEvent
85 * This sends a command to chrome. If you want to request what is performed
86 * in focused content, you should use WidgetContentCommandEvent instead.
88 * XXX Should be |WidgetChromeCommandEvent|?
89 ******************************************************************************/
91 class WidgetCommandEvent : public WidgetGUIEvent {
92 public:
93 virtual WidgetCommandEvent* AsCommandEvent() override { return this; }
95 protected:
96 WidgetCommandEvent(bool aIsTrusted, nsAtom* aEventType, nsAtom* aCommand,
97 nsIWidget* aWidget)
98 : WidgetGUIEvent(aIsTrusted, eUnidentifiedEvent, aWidget,
99 eCommandEventClass),
100 mCommand(aCommand) {
101 mSpecifiedEventType = aEventType;
104 public:
106 * Constructor to initialize an app command. This is the only case to
107 * initialize this class as a command in C++ stack.
109 WidgetCommandEvent(bool aIsTrusted, nsAtom* aCommand, nsIWidget* aWidget)
110 : WidgetCommandEvent(aIsTrusted, nsGkAtoms::onAppCommand, aCommand,
111 aWidget) {}
114 * Constructor to initialize as internal event of dom::CommandEvent.
116 WidgetCommandEvent() : WidgetCommandEvent(false, nullptr, nullptr, nullptr) {}
118 virtual WidgetEvent* Duplicate() const override {
119 MOZ_ASSERT(mClass == eCommandEventClass,
120 "Duplicate() must be overridden by sub class");
121 // Not copying widget, it is a weak reference.
122 WidgetCommandEvent* result =
123 new WidgetCommandEvent(false, mSpecifiedEventType, mCommand, nullptr);
124 result->AssignCommandEventData(*this, true);
125 result->mFlags = mFlags;
126 return result;
129 RefPtr<nsAtom> mCommand;
131 // XXX Not tested by test_assign_event_data.html
132 void AssignCommandEventData(const WidgetCommandEvent& aEvent,
133 bool aCopyTargets) {
134 AssignGUIEventData(aEvent, aCopyTargets);
136 // mCommand must have been initialized with the constructor.
140 /******************************************************************************
141 * mozilla::WidgetPluginEvent
143 * This event delivers only a native event to focused plugin.
144 ******************************************************************************/
146 class WidgetPluginEvent : public WidgetGUIEvent {
147 private:
148 friend class dom::PBrowserParent;
149 friend class dom::PBrowserChild;
151 public:
152 virtual WidgetPluginEvent* AsPluginEvent() override { return this; }
154 WidgetPluginEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
155 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, ePluginEventClass),
156 mRetargetToFocusedDocument(false) {}
158 virtual WidgetEvent* Duplicate() const override {
159 // NOTE: PluginEvent has to be dispatched to nsIFrame::HandleEvent().
160 // So, this event needs to support Duplicate().
161 MOZ_ASSERT(mClass == ePluginEventClass,
162 "Duplicate() must be overridden by sub class");
163 // Not copying widget, it is a weak reference.
164 WidgetPluginEvent* result = new WidgetPluginEvent(false, mMessage, nullptr);
165 result->AssignPluginEventData(*this, true);
166 result->mFlags = mFlags;
167 return result;
170 // If true, this event needs to be retargeted to focused document.
171 // Otherwise, never retargeted. Defaults to false.
172 bool mRetargetToFocusedDocument;
174 void AssignPluginEventData(const WidgetPluginEvent& aEvent,
175 bool aCopyTargets) {
176 AssignGUIEventData(aEvent, aCopyTargets);
178 mRetargetToFocusedDocument = aEvent.mRetargetToFocusedDocument;
181 protected:
182 WidgetPluginEvent() : mRetargetToFocusedDocument(false) {}
185 } // namespace mozilla
187 #endif // mozilla_MiscEvents_h__