Line data Source code
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/. */
5 :
6 : #ifndef mozilla_MiscEvents_h__
7 : #define mozilla_MiscEvents_h__
8 :
9 : #include <stdint.h>
10 :
11 : #include "mozilla/BasicEvents.h"
12 : #include "nsCOMPtr.h"
13 : #include "nsIAtom.h"
14 : #include "nsITransferable.h"
15 :
16 : namespace mozilla {
17 :
18 : namespace dom {
19 : class PBrowserParent;
20 : class PBrowserChild;
21 : } // namespace dom
22 :
23 : /******************************************************************************
24 : * mozilla::WidgetContentCommandEvent
25 : ******************************************************************************/
26 :
27 0 : class WidgetContentCommandEvent : public WidgetGUIEvent
28 : {
29 : public:
30 0 : virtual WidgetContentCommandEvent* AsContentCommandEvent() override
31 : {
32 0 : return this;
33 : }
34 :
35 0 : WidgetContentCommandEvent(bool aIsTrusted, EventMessage aMessage,
36 : nsIWidget* aWidget,
37 : bool aOnlyEnabledCheck = false)
38 0 : : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eContentCommandEventClass)
39 : , mOnlyEnabledCheck(aOnlyEnabledCheck)
40 : , mSucceeded(false)
41 0 : , mIsEnabled(false)
42 : {
43 0 : }
44 :
45 0 : virtual WidgetEvent* Duplicate() const override
46 : {
47 : // This event isn't an internal event of any DOM event.
48 0 : NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
49 : "WidgetQueryContentEvent needs to support Duplicate()");
50 0 : MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
51 : return nullptr;
52 : }
53 :
54 : // eContentCommandPasteTransferable
55 : nsCOMPtr<nsITransferable> mTransferable; // [in]
56 :
57 : // eContentCommandScroll
58 : // for mScroll.mUnit
59 : enum
60 : {
61 : eCmdScrollUnit_Line,
62 : eCmdScrollUnit_Page,
63 : eCmdScrollUnit_Whole
64 : };
65 :
66 : struct ScrollInfo
67 : {
68 0 : ScrollInfo() :
69 0 : mAmount(0), mUnit(eCmdScrollUnit_Line), mIsHorizontal(false)
70 : {
71 0 : }
72 :
73 : int32_t mAmount; // [in]
74 : uint8_t mUnit; // [in]
75 : bool mIsHorizontal; // [in]
76 : } mScroll;
77 :
78 : bool mOnlyEnabledCheck; // [in]
79 :
80 : bool mSucceeded; // [out]
81 : bool mIsEnabled; // [out]
82 :
83 : void AssignContentCommandEventData(const WidgetContentCommandEvent& aEvent,
84 : bool aCopyTargets)
85 : {
86 : AssignGUIEventData(aEvent, aCopyTargets);
87 :
88 : mScroll = aEvent.mScroll;
89 : mOnlyEnabledCheck = aEvent.mOnlyEnabledCheck;
90 : mSucceeded = aEvent.mSucceeded;
91 : mIsEnabled = aEvent.mIsEnabled;
92 : }
93 : };
94 :
95 : /******************************************************************************
96 : * mozilla::WidgetCommandEvent
97 : *
98 : * This sends a command to chrome. If you want to request what is performed
99 : * in focused content, you should use WidgetContentCommandEvent instead.
100 : *
101 : * XXX Should be |WidgetChromeCommandEvent|?
102 : ******************************************************************************/
103 :
104 0 : class WidgetCommandEvent : public WidgetGUIEvent
105 : {
106 : public:
107 0 : virtual WidgetCommandEvent* AsCommandEvent() override { return this; }
108 :
109 0 : WidgetCommandEvent(bool aIsTrusted, nsIAtom* aEventType,
110 : nsIAtom* aCommand, nsIWidget* aWidget)
111 0 : : WidgetGUIEvent(aIsTrusted, eUnidentifiedEvent, aWidget,
112 : eCommandEventClass)
113 0 : , mCommand(aCommand)
114 : {
115 0 : mSpecifiedEventType = aEventType;
116 0 : }
117 :
118 0 : virtual WidgetEvent* Duplicate() const override
119 : {
120 0 : MOZ_ASSERT(mClass == eCommandEventClass,
121 : "Duplicate() must be overridden by sub class");
122 : // Not copying widget, it is a weak reference.
123 : WidgetCommandEvent* result =
124 0 : new WidgetCommandEvent(false, mSpecifiedEventType, mCommand, nullptr);
125 0 : result->AssignCommandEventData(*this, true);
126 0 : result->mFlags = mFlags;
127 0 : return result;
128 : }
129 :
130 : nsCOMPtr<nsIAtom> mCommand;
131 :
132 : // XXX Not tested by test_assign_event_data.html
133 0 : void AssignCommandEventData(const WidgetCommandEvent& aEvent,
134 : bool aCopyTargets)
135 : {
136 0 : AssignGUIEventData(aEvent, aCopyTargets);
137 :
138 : // mCommand must have been initialized with the constructor.
139 0 : }
140 : };
141 :
142 : /******************************************************************************
143 : * mozilla::WidgetPluginEvent
144 : *
145 : * This event delivers only a native event to focused plugin.
146 : ******************************************************************************/
147 :
148 0 : class WidgetPluginEvent : public WidgetGUIEvent
149 : {
150 : private:
151 : friend class dom::PBrowserParent;
152 : friend class dom::PBrowserChild;
153 :
154 : public:
155 0 : virtual WidgetPluginEvent* AsPluginEvent() override { return this; }
156 :
157 0 : WidgetPluginEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
158 0 : : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, ePluginEventClass)
159 0 : , mRetargetToFocusedDocument(false)
160 : {
161 0 : }
162 :
163 0 : virtual WidgetEvent* Duplicate() const override
164 : {
165 : // NOTE: PluginEvent has to be dispatched to nsIFrame::HandleEvent().
166 : // So, this event needs to support Duplicate().
167 0 : MOZ_ASSERT(mClass == ePluginEventClass,
168 : "Duplicate() must be overridden by sub class");
169 : // Not copying widget, it is a weak reference.
170 0 : WidgetPluginEvent* result = new WidgetPluginEvent(false, mMessage, nullptr);
171 0 : result->AssignPluginEventData(*this, true);
172 0 : result->mFlags = mFlags;
173 0 : return result;
174 : }
175 :
176 : // If true, this event needs to be retargeted to focused document.
177 : // Otherwise, never retargeted. Defaults to false.
178 : bool mRetargetToFocusedDocument;
179 :
180 0 : void AssignPluginEventData(const WidgetPluginEvent& aEvent,
181 : bool aCopyTargets)
182 : {
183 0 : AssignGUIEventData(aEvent, aCopyTargets);
184 :
185 0 : mRetargetToFocusedDocument = aEvent.mRetargetToFocusedDocument;
186 0 : }
187 :
188 : protected:
189 0 : WidgetPluginEvent()
190 0 : {
191 0 : }
192 : };
193 :
194 : } // namespace mozilla
195 :
196 : #endif // mozilla_MiscEvents_h__
|