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