1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim:expandtab:shiftwidth=4:tabstop=4:
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/. */
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"
26 // make sure that logging is enabled before including prlog.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)
46 #define PR_LOG2(_args) \
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)
59 #define LOGFOCUS(args)
65 #endif /* MOZ_LOGGING */
83 class nsWindow
: public nsBaseWidget
,
84 public nsSupportsWeakReference
89 NS_DECL_ISUPPORTS_INHERITED
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
,
106 NS_IMETHOD
Move(double aX
,
108 NS_IMETHOD
Resize(double aWidth
,
111 NS_IMETHOD
Resize(double aX
,
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
)
130 virtual nsIntPoint
WidgetToScreenOffset();
131 NS_IMETHOD
DispatchEvent(mozilla::WidgetGUIEvent
* aEvent
,
132 nsEventStatus
& aStatus
);
133 NS_IMETHOD
CaptureRollupEvents(nsIRollupListener
*aListener
,
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
);
178 InputContext mInputContext
;
179 nsCOMPtr
<nsIIdleServiceInternal
> mIdleService
;
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?
197 // Call this function when the users activity is the direct cause of an
198 // event (like a keypress or mouse click).
200 MozQWidget
* createQWidget(MozQWidget
* parent
,
201 nsWidgetInitData
* aInitData
);
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
,
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();
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);
232 // Is this a toplevel window?
234 // Has this widget been destroyed yet?
236 // This flag tracks if we're hidden or shown.
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.
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
,
250 void NativeResize(int32_t aX
,
255 void NativeShow (bool aAction
);
260 Qt::KeyboardModifiers modifiers
;
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;
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
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");
293 /* 32 = 2^5 = 0x20 */
294 *aMask
= uint32_t(1) << (aKeyCode
& 0x1F);
295 return &mKeyDownFlags
[(aKeyCode
>> 5)];
298 bool IsKeyDown(uint32_t aKeyCode
) {
300 uint32_t* flag
= GetFlagWord32(aKeyCode
, &mask
);
301 return ((*flag
) & mask
) != 0;
304 void SetKeyDownFlag(uint32_t aKeyCode
) {
306 uint32_t* flag
= GetFlagWord32(aKeyCode
, &mask
);
310 void ClearKeyDownFlag(uint32_t aKeyCode
) {
312 uint32_t* flag
= GetFlagWord32(aKeyCode
, &mask
);
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;
331 bool mListenForResizes
;
333 MozCachedMoveEvent mMoveEvent
;
339 #endif /* __nsWindow_h__ */