Bumping gaia.json for 1 gaia revision(s) a=gaia-bump
[gecko.git] / widget / MiscEvents.h
blob4fb96bb4edd222a50203824927b9f247bb4df052
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 "nsIAtom.h"
14 #include "nsITransferable.h"
16 namespace mozilla {
18 /******************************************************************************
19 * mozilla::WidgetContentCommandEvent
20 ******************************************************************************/
22 class WidgetContentCommandEvent : public WidgetGUIEvent
24 public:
25 virtual WidgetContentCommandEvent* AsContentCommandEvent() MOZ_OVERRIDE
27 return this;
30 WidgetContentCommandEvent(bool aIsTrusted, uint32_t aMessage,
31 nsIWidget* aWidget,
32 bool aOnlyEnabledCheck = false)
33 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eContentCommandEventClass)
34 , mOnlyEnabledCheck(aOnlyEnabledCheck)
35 , mSucceeded(false)
36 , mIsEnabled(false)
40 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
42 // This event isn't an internal event of any DOM event.
43 NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
44 "WidgetQueryContentEvent needs to support Duplicate()");
45 MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
46 return nullptr;
49 // NS_CONTENT_COMMAND_PASTE_TRANSFERABLE
50 nsCOMPtr<nsITransferable> mTransferable; // [in]
52 // NS_CONTENT_COMMAND_SCROLL
53 // for mScroll.mUnit
54 enum
56 eCmdScrollUnit_Line,
57 eCmdScrollUnit_Page,
58 eCmdScrollUnit_Whole
61 struct ScrollInfo
63 ScrollInfo() :
64 mAmount(0), mUnit(eCmdScrollUnit_Line), mIsHorizontal(false)
68 int32_t mAmount; // [in]
69 uint8_t mUnit; // [in]
70 bool mIsHorizontal; // [in]
71 } mScroll;
73 bool mOnlyEnabledCheck; // [in]
75 bool mSucceeded; // [out]
76 bool mIsEnabled; // [out]
78 void AssignContentCommandEventData(const WidgetContentCommandEvent& aEvent,
79 bool aCopyTargets)
81 AssignGUIEventData(aEvent, aCopyTargets);
83 mScroll = aEvent.mScroll;
84 mOnlyEnabledCheck = aEvent.mOnlyEnabledCheck;
85 mSucceeded = aEvent.mSucceeded;
86 mIsEnabled = aEvent.mIsEnabled;
90 /******************************************************************************
91 * mozilla::WidgetCommandEvent
93 * This sends a command to chrome. If you want to request what is performed
94 * in focused content, you should use WidgetContentCommandEvent instead.
96 * XXX Should be |WidgetChromeCommandEvent|?
97 ******************************************************************************/
99 class WidgetCommandEvent : public WidgetGUIEvent
101 public:
102 virtual WidgetCommandEvent* AsCommandEvent() MOZ_OVERRIDE { return this; }
104 WidgetCommandEvent(bool aIsTrusted, nsIAtom* aEventType,
105 nsIAtom* aCommand, nsIWidget* aWidget)
106 : WidgetGUIEvent(aIsTrusted, NS_USER_DEFINED_EVENT, aWidget,
107 eCommandEventClass)
108 , command(aCommand)
110 userType = aEventType;
113 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
115 MOZ_ASSERT(mClass == eCommandEventClass,
116 "Duplicate() must be overridden by sub class");
117 // Not copying widget, it is a weak reference.
118 WidgetCommandEvent* result =
119 new WidgetCommandEvent(false, userType, command, nullptr);
120 result->AssignCommandEventData(*this, true);
121 result->mFlags = mFlags;
122 return result;
125 nsCOMPtr<nsIAtom> command;
127 // XXX Not tested by test_assign_event_data.html
128 void AssignCommandEventData(const WidgetCommandEvent& aEvent,
129 bool aCopyTargets)
131 AssignGUIEventData(aEvent, aCopyTargets);
133 // command must have been initialized with the constructor.
137 /******************************************************************************
138 * mozilla::WidgetPluginEvent
140 * This event delivers only a native event to focused plugin.
141 ******************************************************************************/
143 class WidgetPluginEvent : public WidgetGUIEvent
145 public:
146 virtual WidgetPluginEvent* AsPluginEvent() MOZ_OVERRIDE { return this; }
148 WidgetPluginEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget)
149 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, ePluginEventClass)
150 , retargetToFocusedDocument(false)
154 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
156 // NOTE: PluginEvent has to be dispatched to nsIFrame::HandleEvent().
157 // So, this event needs to support Duplicate().
158 MOZ_ASSERT(mClass == ePluginEventClass,
159 "Duplicate() must be overridden by sub class");
160 // Not copying widget, it is a weak reference.
161 WidgetPluginEvent* result = new WidgetPluginEvent(false, message, nullptr);
162 result->AssignPluginEventData(*this, true);
163 result->mFlags = mFlags;
164 return result;
167 // If true, this event needs to be retargeted to focused document.
168 // Otherwise, never retargeted. Defaults to false.
169 bool retargetToFocusedDocument;
171 void AssignPluginEventData(const WidgetPluginEvent& aEvent,
172 bool aCopyTargets)
174 AssignGUIEventData(aEvent, aCopyTargets);
176 retargetToFocusedDocument = aEvent.retargetToFocusedDocument;
180 } // namespace mozilla
182 #endif // mozilla_MiscEvents_h__