|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* vim:expandtab:shiftwidth=4:tabstop=4: |
|
3 */ |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #ifndef __nsWindow_h__ |
|
9 #define __nsWindow_h__ |
|
10 |
|
11 #include <QPointF> |
|
12 |
|
13 #include "nsAutoPtr.h" |
|
14 #include "nsBaseWidget.h" |
|
15 #include "mozilla/EventForwards.h" |
|
16 |
|
17 #include "nsWeakReference.h" |
|
18 |
|
19 #include "nsGkAtoms.h" |
|
20 #include "nsIIdleServiceInternal.h" |
|
21 #include "nsIRunnable.h" |
|
22 #include "nsThreadUtils.h" |
|
23 |
|
24 #ifdef MOZ_LOGGING |
|
25 |
|
26 // make sure that logging is enabled before including prlog.h |
|
27 #define FORCE_PR_LOG |
|
28 |
|
29 #include "prlog.h" |
|
30 #include "nsTArray.h" |
|
31 |
|
32 extern PRLogModuleInfo *gWidgetLog; |
|
33 extern PRLogModuleInfo *gWidgetFocusLog; |
|
34 extern PRLogModuleInfo *gWidgetIMLog; |
|
35 extern PRLogModuleInfo *gWidgetDrawLog; |
|
36 |
|
37 #define LOG(args) PR_LOG(gWidgetLog, 4, args) |
|
38 #define LOGFOCUS(args) PR_LOG(gWidgetFocusLog, 4, args) |
|
39 #define LOGIM(args) PR_LOG(gWidgetIMLog, 4, args) |
|
40 #define LOGDRAW(args) PR_LOG(gWidgetDrawLog, 4, args) |
|
41 |
|
42 #else |
|
43 |
|
44 #ifdef DEBUG_WIDGETS |
|
45 |
|
46 #define PR_LOG2(_args) \ |
|
47 PR_BEGIN_MACRO \ |
|
48 qDebug _args; \ |
|
49 PR_END_MACRO |
|
50 |
|
51 #define LOG(args) PR_LOG2(args) |
|
52 #define LOGFOCUS(args) PR_LOG2(args) |
|
53 #define LOGIM(args) PR_LOG2(args) |
|
54 #define LOGDRAW(args) PR_LOG2(args) |
|
55 |
|
56 #else |
|
57 |
|
58 #define LOG(args) |
|
59 #define LOGFOCUS(args) |
|
60 #define LOGIM(args) |
|
61 #define LOGDRAW(args) |
|
62 |
|
63 #endif |
|
64 |
|
65 #endif /* MOZ_LOGGING */ |
|
66 |
|
67 class nsIdleService; |
|
68 class QCloseEvent; |
|
69 class QFocusEvent; |
|
70 class QHideEvent; |
|
71 class QKeyEvent; |
|
72 class QMouseEvent; |
|
73 class QMoveEvent; |
|
74 class QResizeEvent; |
|
75 class QShowEvent; |
|
76 class QTabletEvent; |
|
77 class QTouchEvent; |
|
78 class QWheelEvent; |
|
79 |
|
80 namespace mozilla { |
|
81 namespace widget { |
|
82 class MozQWidget; |
|
83 class nsWindow : public nsBaseWidget, |
|
84 public nsSupportsWeakReference |
|
85 { |
|
86 public: |
|
87 nsWindow(); |
|
88 virtual ~nsWindow(); |
|
89 |
|
90 NS_DECL_ISUPPORTS_INHERITED |
|
91 |
|
92 // |
|
93 // nsIWidget |
|
94 // |
|
95 NS_IMETHOD Create(nsIWidget *aParent, |
|
96 nsNativeWidget aNativeParent, |
|
97 const nsIntRect &aRect, |
|
98 nsDeviceContext *aContext, |
|
99 nsWidgetInitData *aInitData); |
|
100 NS_IMETHOD Destroy(void); |
|
101 |
|
102 NS_IMETHOD Show(bool aState); |
|
103 virtual bool IsVisible() const; |
|
104 NS_IMETHOD ConstrainPosition(bool aAllowSlop, |
|
105 int32_t *aX, |
|
106 int32_t *aY); |
|
107 NS_IMETHOD Move(double aX, |
|
108 double aY); |
|
109 NS_IMETHOD Resize(double aWidth, |
|
110 double aHeight, |
|
111 bool aRepaint); |
|
112 NS_IMETHOD Resize(double aX, |
|
113 double aY, |
|
114 double aWidth, |
|
115 double aHeight, |
|
116 bool aRepaint); |
|
117 NS_IMETHOD Enable(bool aState); |
|
118 // Some of the nsIWidget methods |
|
119 virtual bool IsEnabled() const; |
|
120 NS_IMETHOD SetFocus(bool aRaise = false); |
|
121 NS_IMETHOD ConfigureChildren(const nsTArray<nsIWidget::Configuration>&); |
|
122 NS_IMETHOD Invalidate(const nsIntRect &aRect); |
|
123 virtual void* GetNativeData(uint32_t aDataType); |
|
124 NS_IMETHOD SetTitle(const nsAString& aTitle); |
|
125 NS_IMETHOD SetCursor(nsCursor aCursor); |
|
126 NS_IMETHOD SetCursor(imgIContainer* aCursor, |
|
127 uint32_t aHotspotX, uint32_t aHotspotY) |
|
128 { |
|
129 return NS_OK; |
|
130 } |
|
131 virtual nsIntPoint WidgetToScreenOffset(); |
|
132 NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent, |
|
133 nsEventStatus& aStatus); |
|
134 NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener, |
|
135 bool aDoCapture) |
|
136 { |
|
137 return NS_ERROR_NOT_IMPLEMENTED; |
|
138 } |
|
139 NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent); |
|
140 |
|
141 NS_IMETHOD MakeFullScreen(bool aFullScreen); |
|
142 virtual mozilla::layers::LayerManager* |
|
143 GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr, |
|
144 LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE, |
|
145 LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT, |
|
146 bool* aAllowRetaining = nullptr); |
|
147 |
|
148 NS_IMETHOD_(void) SetInputContext(const InputContext& aContext, |
|
149 const InputContextAction& aAction); |
|
150 NS_IMETHOD_(InputContext) GetInputContext(); |
|
151 |
|
152 virtual uint32_t GetGLFrameBufferFormat() MOZ_OVERRIDE; |
|
153 |
|
154 // Widget notifications |
|
155 virtual void OnPaint(); |
|
156 virtual nsEventStatus focusInEvent(QFocusEvent* aEvent); |
|
157 virtual nsEventStatus focusOutEvent(QFocusEvent* aEvent); |
|
158 virtual nsEventStatus hideEvent(QHideEvent* aEvent); |
|
159 virtual nsEventStatus showEvent(QShowEvent* aEvent); |
|
160 virtual nsEventStatus keyPressEvent(QKeyEvent* aEvent); |
|
161 virtual nsEventStatus keyReleaseEvent(QKeyEvent* aEvent); |
|
162 virtual nsEventStatus mouseDoubleClickEvent(QMouseEvent* aEvent); |
|
163 virtual nsEventStatus mouseMoveEvent(QMouseEvent* aEvent); |
|
164 virtual nsEventStatus mousePressEvent(QMouseEvent* aEvent); |
|
165 virtual nsEventStatus mouseReleaseEvent(QMouseEvent* aEvent); |
|
166 virtual nsEventStatus moveEvent(QMoveEvent* aEvent); |
|
167 virtual nsEventStatus resizeEvent(QResizeEvent* aEvent); |
|
168 virtual nsEventStatus touchEvent(QTouchEvent* aEvent); |
|
169 virtual nsEventStatus wheelEvent(QWheelEvent* aEvent); |
|
170 virtual nsEventStatus tabletEvent(QTabletEvent* event); |
|
171 |
|
172 protected: |
|
173 nsWindow* mParent; |
|
174 bool mVisible; |
|
175 InputContext mInputContext; |
|
176 nsCOMPtr<nsIIdleServiceInternal> mIdleService; |
|
177 MozQWidget* mWidget; |
|
178 |
|
179 private: |
|
180 void InitButtonEvent(mozilla::WidgetMouseEvent& event, |
|
181 QMouseEvent* aEvent, |
|
182 int aClickCount = 1); |
|
183 |
|
184 // event handling code |
|
185 nsEventStatus DispatchEvent(mozilla::WidgetGUIEvent* aEvent); |
|
186 void DispatchActivateEvent(void); |
|
187 void DispatchDeactivateEvent(void); |
|
188 void DispatchActivateEventOnTopLevelWindow(void); |
|
189 void DispatchDeactivateEventOnTopLevelWindow(void); |
|
190 void DispatchResizeEvent(nsIntRect &aRect, nsEventStatus &aStatus); |
|
191 |
|
192 // Remember the last sizemode so that we can restore it when |
|
193 // leaving fullscreen |
|
194 nsSizeMode mLastSizeMode; |
|
195 // is this widget enabled? |
|
196 bool mEnabled; |
|
197 |
|
198 // Call this function when the users activity is the direct cause of an |
|
199 // event (like a keypress or mouse click). |
|
200 void UserActivity(); |
|
201 MozQWidget* createQWidget(MozQWidget* parent, |
|
202 nsWidgetInitData* aInitData); |
|
203 |
|
204 public: |
|
205 // Old QtWidget only |
|
206 NS_IMETHOD SetParent(nsIWidget* aNewParent); |
|
207 virtual nsIWidget *GetParent(void); |
|
208 virtual float GetDPI(); |
|
209 NS_IMETHOD SetModal(bool aModal); |
|
210 NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, |
|
211 nsIWidget *aWidget, |
|
212 bool aActivate); |
|
213 NS_IMETHOD SetSizeMode(int32_t aMode); |
|
214 NS_IMETHOD GetScreenBounds(nsIntRect &aRect); |
|
215 NS_IMETHOD SetHasTransparentBackground(bool aTransparent); |
|
216 NS_IMETHOD GetHasTransparentBackground(bool& aTransparent); |
|
217 NS_IMETHOD HideWindowChrome(bool aShouldHide); |
|
218 NS_IMETHOD SetIcon(const nsAString& aIconSpec); |
|
219 NS_IMETHOD CaptureMouse(bool aCapture); |
|
220 NS_IMETHOD SetWindowClass(const nsAString& xulWinType); |
|
221 NS_IMETHOD GetAttention(int32_t aCycleCount); |
|
222 NS_IMETHOD_(bool) HasGLContext(); |
|
223 |
|
224 // |
|
225 // utility methods |
|
226 // |
|
227 void QWidgetDestroyed(); |
|
228 // called when we are destroyed |
|
229 void OnDestroy(void); |
|
230 // called to check and see if a widget's dimensions are sane |
|
231 bool AreBoundsSane(void); |
|
232 private: |
|
233 // Is this a toplevel window? |
|
234 bool mIsTopLevel; |
|
235 // Has this widget been destroyed yet? |
|
236 bool mIsDestroyed; |
|
237 // This flag tracks if we're hidden or shown. |
|
238 bool mIsShown; |
|
239 // Has anyone set an x/y location for this widget yet? Toplevels |
|
240 // shouldn't be automatically set to 0,0 for first show. |
|
241 bool mPlaced; |
|
242 /** |
|
243 * Event handlers (proxied from the actual qwidget). |
|
244 * They follow normal Qt widget semantics. |
|
245 */ |
|
246 void Initialize(MozQWidget *widget); |
|
247 virtual nsEventStatus OnCloseEvent(QCloseEvent *); |
|
248 void NativeResize(int32_t aWidth, |
|
249 int32_t aHeight, |
|
250 bool aRepaint); |
|
251 void NativeResize(int32_t aX, |
|
252 int32_t aY, |
|
253 int32_t aWidth, |
|
254 int32_t aHeight, |
|
255 bool aRepaint); |
|
256 void NativeShow (bool aAction); |
|
257 |
|
258 private: |
|
259 typedef struct { |
|
260 QPointF pos; |
|
261 Qt::KeyboardModifiers modifiers; |
|
262 bool needDispatch; |
|
263 } MozCachedMoveEvent; |
|
264 |
|
265 bool CheckForRollup(double aMouseX, double aMouseY, bool aIsWheel); |
|
266 void* SetupPluginPort(void); |
|
267 nsresult SetWindowIconList(const nsTArray<nsCString> &aIconList); |
|
268 void SetDefaultIcon(void); |
|
269 |
|
270 nsEventStatus DispatchCommandEvent(nsIAtom* aCommand); |
|
271 nsEventStatus DispatchContentCommandEvent(int32_t aMsg); |
|
272 void SetSoftwareKeyboardState(bool aOpen, const InputContextAction& aAction); |
|
273 void ClearCachedResources(); |
|
274 |
|
275 uint32_t mActivatePending : 1; |
|
276 int32_t mSizeState; |
|
277 |
|
278 bool mIsTransparent; |
|
279 |
|
280 // all of our DND stuff |
|
281 // this is the last window that had a drag event happen on it. |
|
282 void InitDragEvent(mozilla::WidgetMouseEvent& aEvent); |
|
283 |
|
284 // this is everything we need to be able to fire motion events |
|
285 // repeatedly |
|
286 uint32_t mKeyDownFlags[8]; |
|
287 |
|
288 /* Helper methods for DOM Key Down event suppression. */ |
|
289 uint32_t* GetFlagWord32(uint32_t aKeyCode, uint32_t* aMask) { |
|
290 /* Mozilla DOM Virtual Key Code is from 0 to 224. */ |
|
291 NS_ASSERTION((aKeyCode <= 0xFF), "Invalid DOM Key Code"); |
|
292 aKeyCode &= 0xFF; |
|
293 |
|
294 /* 32 = 2^5 = 0x20 */ |
|
295 *aMask = uint32_t(1) << (aKeyCode & 0x1F); |
|
296 return &mKeyDownFlags[(aKeyCode >> 5)]; |
|
297 } |
|
298 |
|
299 bool IsKeyDown(uint32_t aKeyCode) { |
|
300 uint32_t mask; |
|
301 uint32_t* flag = GetFlagWord32(aKeyCode, &mask); |
|
302 return ((*flag) & mask) != 0; |
|
303 } |
|
304 |
|
305 void SetKeyDownFlag(uint32_t aKeyCode) { |
|
306 uint32_t mask; |
|
307 uint32_t* flag = GetFlagWord32(aKeyCode, &mask); |
|
308 *flag |= mask; |
|
309 } |
|
310 |
|
311 void ClearKeyDownFlag(uint32_t aKeyCode) { |
|
312 uint32_t mask; |
|
313 uint32_t* flag = GetFlagWord32(aKeyCode, &mask); |
|
314 *flag &= ~mask; |
|
315 } |
|
316 int32_t mQCursor; |
|
317 |
|
318 |
|
319 void ProcessMotionEvent(); |
|
320 |
|
321 void DispatchMotionToMainThread() { |
|
322 if (!mTimerStarted) { |
|
323 nsCOMPtr<nsIRunnable> event = |
|
324 NS_NewRunnableMethod(this, &nsWindow::ProcessMotionEvent); |
|
325 NS_DispatchToMainThread(event); |
|
326 mTimerStarted = true; |
|
327 } |
|
328 } |
|
329 |
|
330 bool mNeedsResize; |
|
331 bool mNeedsMove; |
|
332 bool mListenForResizes; |
|
333 bool mNeedsShow; |
|
334 MozCachedMoveEvent mMoveEvent; |
|
335 bool mTimerStarted; |
|
336 }; |
|
337 |
|
338 }} |
|
339 |
|
340 #endif /* __nsWindow_h__ */ |