1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Robert O'Callahan <roc+moz@cs.cmu.edu>
24 * Dean Tessman <dean_tessman@hotmail.com>
25 * Makoto Kato <m_kato@ga2.so-net.ne.jp>
26 * Dainis Jonitis <Dainis_Jonitis@swh-t.lv>
27 * Masayuki Nakano <masayuki@d-toybox.com>
28 * Ningjie Chen <chenn@email.uc.edu>
29 * Jim Mathies <jmathies@mozilla.com>.
30 * Mats Palmgren <matspal@gmail.com>
32 * Alternatively, the contents of this file may be used under the terms of
33 * either the GNU General Public License Version 2 or later (the "GPL"), or
34 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
35 * in which case the provisions of the GPL or the LGPL are applicable instead
36 * of those above. If you wish to allow use of your version of this file only
37 * under the terms of either the GPL or the LGPL, and not to allow others to
38 * use your version of this file under the terms of the MPL, indicate your
39 * decision by deleting the provisions above and replace them with the notice
40 * and other provisions required by the GPL or the LGPL. If you do not delete
41 * the provisions above, a recipient may use your version of this file under
42 * the terms of any one of the MPL, the GPL or the LGPL.
44 * ***** END LICENSE BLOCK ***** */
50 * nsWindow - Native window management and event handling.
53 #include "nsAutoPtr.h"
54 #include "nsBaseWidget.h"
56 #include "nsIdleService.h"
57 #include "nsToolkit.h"
60 #include "gfxWindowsSurface.h"
61 #include "nsWindowDbg.h"
64 #include "mozilla/TimeStamp.h"
66 #ifdef CAIRO_HAS_D2D_SURFACE
67 #include "gfxD2DSurface.h"
71 #include "nsWinGesture.h"
75 #include "nsWindowCE.h"
78 #include "WindowHook.h"
79 #include "TaskbarWindowPreview.h"
83 #include "nsAccessible.h"
87 #include "nsUXThemeData.h"
88 #endif // !defined(WINCE)
90 * Forward class definitions
93 class nsNativeDragTarget
;
94 class nsIRollupListener
;
99 * Native WIN32 window wrapper.
102 class nsWindow
: public nsBaseWidget
104 typedef mozilla::TimeStamp TimeStamp
;
105 typedef mozilla::widget::WindowHook WindowHook
;
106 #if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_WIN7
107 typedef mozilla::widget::TaskbarWindowPreview TaskbarWindowPreview
;
113 NS_DECL_ISUPPORTS_INHERITED
115 friend class nsWindowGfx
;
118 * nsIWidget interface
120 NS_IMETHOD
Create(nsIWidget
*aParent
,
121 nsNativeWidget aNativeParent
,
122 const nsIntRect
&aRect
,
123 EVENT_CALLBACK aHandleEventFunction
,
124 nsIDeviceContext
*aContext
,
125 nsIAppShell
*aAppShell
= nsnull
,
126 nsIToolkit
*aToolkit
= nsnull
,
127 nsWidgetInitData
*aInitData
= nsnull
);
128 NS_IMETHOD
Destroy();
129 NS_IMETHOD
SetParent(nsIWidget
*aNewParent
);
130 virtual nsIWidget
* GetParent(void);
131 virtual float GetDPI();
132 NS_IMETHOD
Show(PRBool bState
);
133 NS_IMETHOD
IsVisible(PRBool
& aState
);
134 NS_IMETHOD
ConstrainPosition(PRBool aAllowSlop
, PRInt32
*aX
, PRInt32
*aY
);
135 NS_IMETHOD
Move(PRInt32 aX
, PRInt32 aY
);
136 NS_IMETHOD
Resize(PRInt32 aWidth
, PRInt32 aHeight
, PRBool aRepaint
);
137 NS_IMETHOD
Resize(PRInt32 aX
, PRInt32 aY
, PRInt32 aWidth
, PRInt32 aHeight
, PRBool aRepaint
);
138 NS_IMETHOD
ResizeClient(PRInt32 aX
, PRInt32 aY
, PRInt32 aWidth
, PRInt32 aHeight
, PRBool aRepaint
);
140 NS_IMETHOD
BeginResizeDrag(nsGUIEvent
* aEvent
, PRInt32 aHorizontal
, PRInt32 aVertical
);
142 NS_IMETHOD
PlaceBehind(nsTopLevelWidgetZPlacement aPlacement
, nsIWidget
*aWidget
, PRBool aActivate
);
143 NS_IMETHOD
SetSizeMode(PRInt32 aMode
);
144 NS_IMETHOD
Enable(PRBool aState
);
145 NS_IMETHOD
IsEnabled(PRBool
*aState
);
146 NS_IMETHOD
SetFocus(PRBool aRaise
);
147 NS_IMETHOD
GetBounds(nsIntRect
&aRect
);
148 NS_IMETHOD
GetScreenBounds(nsIntRect
&aRect
);
149 NS_IMETHOD
GetClientBounds(nsIntRect
&aRect
);
150 virtual nsIntPoint
GetClientOffset();
151 NS_IMETHOD
SetBackgroundColor(const nscolor
&aColor
);
152 NS_IMETHOD
SetCursor(imgIContainer
* aCursor
,
153 PRUint32 aHotspotX
, PRUint32 aHotspotY
);
154 NS_IMETHOD
SetCursor(nsCursor aCursor
);
155 virtual nsresult
ConfigureChildren(const nsTArray
<Configuration
>& aConfigurations
);
156 NS_IMETHOD
MakeFullScreen(PRBool aFullScreen
);
157 NS_IMETHOD
HideWindowChrome(PRBool aShouldHide
);
158 NS_IMETHOD
Invalidate(PRBool aIsSynchronous
);
159 NS_IMETHOD
Invalidate(const nsIntRect
& aRect
, PRBool aIsSynchronous
);
161 virtual void* GetNativeData(PRUint32 aDataType
);
162 virtual void FreeNativeData(void * data
, PRUint32 aDataType
);
163 NS_IMETHOD
SetTitle(const nsAString
& aTitle
);
164 NS_IMETHOD
SetIcon(const nsAString
& aIconSpec
);
165 virtual nsIntPoint
WidgetToScreenOffset();
166 virtual nsIntSize
ClientToWindowSize(const nsIntSize
& aClientSize
);
167 NS_IMETHOD
DispatchEvent(nsGUIEvent
* event
, nsEventStatus
& aStatus
);
168 NS_IMETHOD
EnableDragDrop(PRBool aEnable
);
169 NS_IMETHOD
CaptureMouse(PRBool aCapture
);
170 NS_IMETHOD
CaptureRollupEvents(nsIRollupListener
* aListener
, nsIMenuRollup
* aMenuRollup
,
171 PRBool aDoCapture
, PRBool aConsumeRollupEvent
);
172 NS_IMETHOD
GetAttention(PRInt32 aCycleCount
);
173 virtual PRBool
HasPendingInputEvent();
174 virtual LayerManager
* GetLayerManager(LayerManagerPersistence aPersistence
= LAYER_MANAGER_CURRENT
, bool* aAllowRetaining
= nsnull
);
175 gfxASurface
*GetThebesSurface();
176 NS_IMETHOD
OnDefaultButtonLoaded(const nsIntRect
&aButtonRect
);
177 NS_IMETHOD
OverrideSystemMouseScrollSpeed(PRInt32 aOriginalDelta
, PRBool aIsHorizontal
, PRInt32
&aOverriddenDelta
);
179 virtual nsresult
SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout
,
180 PRInt32 aNativeKeyCode
,
181 PRUint32 aModifierFlags
,
182 const nsAString
& aCharacters
,
183 const nsAString
& aUnmodifiedCharacters
);
184 virtual nsresult
SynthesizeNativeMouseEvent(nsIntPoint aPoint
,
185 PRUint32 aNativeMessage
,
186 PRUint32 aModifierFlags
);
187 NS_IMETHOD
ResetInputState();
188 NS_IMETHOD
SetIMEOpenState(PRBool aState
);
189 NS_IMETHOD
GetIMEOpenState(PRBool
* aState
);
190 NS_IMETHOD
SetInputMode(const IMEContext
& aContext
);
191 NS_IMETHOD
GetInputMode(IMEContext
& aContext
);
192 NS_IMETHOD
CancelIMEComposition();
193 NS_IMETHOD
GetToggledKeyState(PRUint32 aKeyCode
, PRBool
* aLEDState
);
194 NS_IMETHOD
RegisterTouchWindow();
195 NS_IMETHOD
UnregisterTouchWindow();
197 virtual void SetTransparencyMode(nsTransparencyMode aMode
);
198 virtual nsTransparencyMode
GetTransparencyMode();
199 virtual void UpdateTransparentRegion(const nsIntRegion
& aTransparentRegion
);
202 NS_IMETHOD
OnIMEFocusChange(PRBool aFocus
);
203 NS_IMETHOD
OnIMETextChange(PRUint32 aStart
, PRUint32 aOldEnd
, PRUint32 aNewEnd
);
204 NS_IMETHOD
OnIMESelectionChange(void);
205 #endif // NS_ENABLE_TSF
206 NS_IMETHOD
GetNonClientMargins(nsIntMargin
&margins
);
207 NS_IMETHOD
SetNonClientMargins(nsIntMargin
&margins
);
208 void SetDrawsInTitlebar(PRBool aState
);
211 * Statics used in other classes
213 static PRInt32
GetWindowsVersion();
218 void InitEvent(nsGUIEvent
& event
, nsIntPoint
* aPoint
= nsnull
);
219 virtual PRBool
DispatchMouseEvent(PRUint32 aEventType
, WPARAM wParam
,
221 PRBool aIsContextMenuKey
= PR_FALSE
,
222 PRInt16 aButton
= nsMouseEvent::eLeftButton
,
223 PRUint16 aInputSource
= nsIDOMNSMouseEvent::MOZ_SOURCE_MOUSE
);
224 virtual PRBool
DispatchWindowEvent(nsGUIEvent
* event
);
225 virtual PRBool
DispatchWindowEvent(nsGUIEvent
*event
, nsEventStatus
&aStatus
);
226 virtual PRBool
DispatchKeyEvent(PRUint32 aEventType
, WORD aCharCode
,
227 const nsTArray
<nsAlternativeCharCode
>* aAlternativeChars
,
228 UINT aVirtualCharCode
, const MSG
*aMsg
,
229 const nsModifierKeyState
&aModKeyState
,
230 PRUint32 aFlags
= 0);
231 void DispatchPendingEvents();
232 PRBool
DispatchPluginEvent(UINT aMessage
,
235 PRBool aDispatchPendingEvents
);
237 void SuppressBlurEvents(PRBool aSuppress
); // Called from nsFilePicker
238 PRBool
BlurEventsSuppressed();
240 nsAccessible
* DispatchAccessibleEvent(PRUint32 aEventType
);
241 nsAccessible
* GetRootAccessible();
242 #endif // ACCESSIBILITY
247 static void GlobalMsgWindowProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
248 nsWindow
* GetTopLevelWindow(PRBool aStopOnDialogOrPopup
);
249 static HWND
GetTopLevelHWND(HWND aWnd
, PRBool aStopOnDialogOrPopup
= PR_FALSE
);
250 HWND
GetWindowHandle() { return mWnd
; }
251 WNDPROC
GetPrevWindowProc() { return mPrevWndProc
; }
252 static nsWindow
* GetNSWindowPtr(HWND aWnd
);
253 WindowHook
& GetWindowHook() { return mWindowHook
; }
254 nsWindow
* GetParentWindow(PRBool aIncludeOwner
);
255 // Get an array of all nsWindow*s on the main thread.
256 typedef void (WindowEnumCallback
)(nsWindow
*);
257 static void EnumAllWindows(WindowEnumCallback aCallback
);
262 virtual PRBool
AutoErase(HDC dc
);
263 nsIntPoint
* GetLastPoint() { return &mLastPoint
; }
264 // needed in nsIMM32Handler.cpp
265 PRBool
PluginHasFocus() { return mIMEContext
.mStatus
== nsIWidget::IME_STATUS_PLUGIN
; }
266 PRBool
IsTopLevelWidget() { return mIsTopWidgetWindow
; }
268 * Start allowing Direct3D9 to be used by widgets when GetLayerManager is
271 * @param aReinitialize Call GetLayerManager on widgets to ensure D3D9 is
272 * initialized, this is usually called when this function
273 * is triggered by timeout and not user/web interaction.
275 static void StartAllowingD3D9(bool aReinitialize
);
277 #if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_WIN7
278 PRBool
HasTaskbarIconBeenCreated() { return mHasTaskbarIconBeenCreated
; }
279 // Called when either the nsWindow or an nsITaskbarTabPreview receives the noticiation that this window
280 // has its icon placed on the taskbar.
281 void SetHasTaskbarIconBeenCreated(PRBool created
= PR_TRUE
) { mHasTaskbarIconBeenCreated
= created
; }
283 // Getter/setter for the nsITaskbarWindowPreview for this nsWindow
284 already_AddRefed
<nsITaskbarWindowPreview
> GetTaskbarPreview() {
285 nsCOMPtr
<nsITaskbarWindowPreview
> preview(do_QueryReferent(mTaskbarPreview
));
286 return preview
.forget();
288 void SetTaskbarPreview(nsITaskbarWindowPreview
*preview
) { mTaskbarPreview
= do_GetWeakReference(preview
); }
291 NS_IMETHOD
ReparentNativeWidget(nsIWidget
* aNewParent
);
294 // A magic number to identify the FAKETRACKPOINTSCROLLABLE window created
295 // when the trackpoint hack is enabled.
296 enum { eFakeTrackPointScrollableID
= 0x46545053 };
301 static LRESULT CALLBACK
WindowProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
302 static LRESULT CALLBACK
WindowProcInternal(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
304 static BOOL CALLBACK
BroadcastMsgToChildren(HWND aWnd
, LPARAM aMsg
);
305 static BOOL CALLBACK
BroadcastMsg(HWND aTopWindow
, LPARAM aMsg
);
306 static BOOL CALLBACK
DispatchStarvedPaints(HWND aTopWindow
, LPARAM aMsg
);
308 static BOOL CALLBACK
RegisterTouchForDescendants(HWND aTopWindow
, LPARAM aMsg
);
309 static BOOL CALLBACK
UnregisterTouchForDescendants(HWND aTopWindow
, LPARAM aMsg
);
311 static LRESULT CALLBACK
MozSpecialMsgFilter(int code
, WPARAM wParam
, LPARAM lParam
);
312 static LRESULT CALLBACK
MozSpecialWndProc(int code
, WPARAM wParam
, LPARAM lParam
);
313 static LRESULT CALLBACK
MozSpecialMouseProc(int code
, WPARAM wParam
, LPARAM lParam
);
314 static VOID CALLBACK
HookTimerForPopups( HWND hwnd
, UINT uMsg
, UINT idEvent
, DWORD dwTime
);
315 static BOOL CALLBACK
ClearResourcesCallback(HWND aChild
, LPARAM aParam
);
316 static BOOL CALLBACK
EnumAllChildWindProc(HWND aWnd
, LPARAM aParam
);
317 static BOOL CALLBACK
EnumAllThreadWindowProc(HWND aWnd
, LPARAM aParam
);
318 static void AllowD3D9Callback(nsWindow
*aWindow
);
319 static void AllowD3D9WithReinitializeCallback(nsWindow
*aWindow
);
320 static BOOL CALLBACK
FindOurWindowAtPointCallback(HWND aHWND
, LPARAM aLPARAM
);
325 static BOOL
SetNSWindowPtr(HWND aWnd
, nsWindow
* ptr
);
326 LPARAM
lParamToScreen(LPARAM lParam
);
327 LPARAM
lParamToClient(LPARAM lParam
);
328 virtual void SubclassWindow(BOOL bState
);
329 PRBool
CanTakeFocus();
330 PRBool
UpdateNonClientMargins(PRInt32 aSizeMode
= -1, PRBool aReflowWindow
= PR_TRUE
);
331 void UpdateGetWindowInfoCaptionStatus(PRBool aActiveCaption
);
333 void InvalidateNonClientRegion();
334 HRGN
ExcludeNonClientFromPaintRegion(HRGN aRegion
);
336 static void InitInputWorkaroundPrefDefaults();
338 static PRBool
GetInputWorkaroundPref(const char* aPrefName
, PRBool aValueIfAutomatic
);
339 static PRBool
UseTrackPointHack();
340 static void PerformElantechSwipeGestureHack(UINT
& aVirtualKeyCode
, nsModifierKeyState
& aModKeyState
);
341 static void GetMainWindowClass(nsAString
& aClass
);
342 PRBool
HasGlass() const {
343 return mTransparencyMode
== eTransparencyGlass
||
344 mTransparencyMode
== eTransparencyBorderlessGlass
;
346 static PRBool
IsOurProcessWindow(HWND aHWND
);
347 static HWND
FindOurProcessWindow(HWND aHWND
);
348 static HWND
FindOurWindowAtPoint(const POINT
& aPoint
);
351 * Event processing helpers
353 PRBool
DispatchPluginEvent(const MSG
&aMsg
);
354 PRBool
DispatchFocusToTopLevelWindow(PRUint32 aEventType
);
355 PRBool
DispatchFocus(PRUint32 aEventType
);
356 PRBool
DispatchStandardEvent(PRUint32 aMsg
);
357 PRBool
DispatchCommandEvent(PRUint32 aEventCommand
);
358 void RelayMouseEvent(UINT aMsg
, WPARAM wParam
, LPARAM lParam
);
359 static void RemoveNextCharMessage(HWND aWnd
);
360 void RemoveMessageAndDispatchPluginEvent(UINT aFirstMsg
, UINT aLastMsg
);
361 static MSG
InitMSG(UINT aMessage
, WPARAM wParam
, LPARAM lParam
);
362 virtual PRBool
ProcessMessage(UINT msg
, WPARAM
&wParam
,
363 LPARAM
&lParam
, LRESULT
*aRetValue
);
364 PRBool
ProcessMessageForPlugin(const MSG
&aMsg
,
365 LRESULT
*aRetValue
, PRBool
&aCallDefWndProc
);
366 LRESULT
ProcessCharMessage(const MSG
&aMsg
,
367 PRBool
*aEventDispatched
);
368 LRESULT
ProcessKeyUpMessage(const MSG
&aMsg
,
369 PRBool
*aEventDispatched
);
370 LRESULT
ProcessKeyDownMessage(const MSG
&aMsg
,
371 PRBool
*aEventDispatched
);
372 static PRBool
EventIsInsideWindow(UINT Msg
, nsWindow
* aWindow
);
373 // Convert nsEventStatus value to a windows boolean
374 static PRBool
ConvertStatus(nsEventStatus aStatus
);
375 static void PostSleepWakeNotification(const char* aNotification
);
376 PRBool
HandleScrollingPlugins(UINT aMsg
, WPARAM aWParam
,
380 PRBool
& aQuitProcessing
);
381 PRInt32
ClientMarginHitTestPoint(PRInt32 mx
, PRInt32 my
);
382 static WORD
GetScanCode(LPARAM aLParam
)
384 return (aLParam
>> 16) & 0xFF;
386 static PRBool
IsExtendedScanCode(LPARAM aLParam
)
388 return (aLParam
& 0x1000000) != 0;
390 static PRBool
IsRedirectedKeyDownMessage(const MSG
&aMsg
);
391 static void ForgetRedirectedKeyDownMessage()
393 sRedirectedKeyDown
.message
= WM_NULL
;
399 virtual void OnDestroy();
400 virtual PRBool
OnMove(PRInt32 aX
, PRInt32 aY
);
401 virtual PRBool
OnResize(nsIntRect
&aWindowRect
);
402 LRESULT
OnChar(const MSG
&aMsg
,
403 nsModifierKeyState
&aModKeyState
,
404 PRBool
*aEventDispatched
,
405 PRUint32 aFlags
= 0);
406 LRESULT
OnKeyDown(const MSG
&aMsg
,
407 nsModifierKeyState
&aModKeyState
,
408 PRBool
*aEventDispatched
,
409 nsFakeCharMessage
* aFakeCharMessage
);
410 LRESULT
OnKeyUp(const MSG
&aMsg
,
411 nsModifierKeyState
&aModKeyState
,
412 PRBool
*aEventDispatched
);
413 LRESULT
OnCharRaw(UINT charCode
, UINT aScanCode
,
414 nsModifierKeyState
&aModKeyState
,
416 const MSG
*aMsg
= nsnull
,
417 PRBool
*aEventDispatched
= nsnull
);
418 virtual PRBool
OnScroll(UINT aMsg
, WPARAM aWParam
, LPARAM aLParam
);
419 PRBool
OnGesture(WPARAM wParam
, LPARAM lParam
);
420 #if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_WIN7
421 PRBool
OnTouch(WPARAM wParam
, LPARAM lParam
);
423 PRBool
OnHotKey(WPARAM wParam
, LPARAM lParam
);
424 BOOL
OnInputLangChange(HKL aHKL
);
425 void OnSettingsChange(WPARAM wParam
, LPARAM lParam
);
426 PRBool
OnPaint(HDC aDC
, PRUint32 aNestingLevel
);
427 void OnWindowPosChanged(WINDOWPOS
*wp
, PRBool
& aResult
);
428 PRBool
OnMouseWheel(UINT msg
, WPARAM wParam
, LPARAM lParam
,
429 PRBool
& result
, PRBool
& getWheelInfo
,
432 void OnWindowPosChanging(LPWINDOWPOS
& info
);
433 #endif // !defined(WINCE)
436 * Function that registers when the user has been active (used for detecting
437 * when the user is idle).
441 PRInt32
GetHeight(PRInt32 aProposedHeight
);
442 void GetWindowClass(nsString
& aWindowClass
);
443 void GetWindowPopupClass(nsString
& aWindowClass
);
444 virtual DWORD
WindowStyle();
445 DWORD
WindowExStyle();
447 void RegisterWindowClass(const nsString
& aClassName
,
452 * XP and Vista theming support for windows with rounded edges
454 void ClearThemeRegion();
455 void SetThemeRegion();
460 static void ScheduleHookTimer(HWND aWnd
, UINT aMsgId
);
461 static void RegisterSpecialDropdownHooks();
462 static void UnregisterSpecialDropdownHooks();
463 static BOOL
DealWithPopups(HWND inWnd
, UINT inMsg
, WPARAM inWParam
, LPARAM inLParam
, LRESULT
* outResult
);
466 * Window transparency helpers
470 void SetWindowTranslucencyInner(nsTransparencyMode aMode
);
471 nsTransparencyMode
GetWindowTranslucencyInner() const { return mTransparencyMode
; }
472 void ResizeTranslucentWindow(PRInt32 aNewWidth
, PRInt32 aNewHeight
, PRBool force
= PR_FALSE
);
473 nsresult
UpdateTranslucentWindow();
474 void SetupTranslucentWindowMemoryBitmap(nsTransparencyMode aMode
);
480 static bool IsAsyncResponseEvent(UINT aMsg
, LRESULT
& aResult
);
481 void IPCWindowProcHandler(UINT
& msg
, WPARAM
& wParam
, LPARAM
& lParam
);
487 UINT
MapFromNativeToDOM(UINT aNativeKeyCode
);
489 static PRBool
IsTopLevelMouseExit(HWND aWnd
);
490 static void SetupKeyModifiersSequence(nsTArray
<KeyPair
>* aArray
, PRUint32 aModifiers
);
491 nsresult
SetWindowClipRegion(const nsTArray
<nsIntRect
>& aRects
,
492 PRBool aIntersectWithExisting
);
493 nsIntRegion
GetRegionToPaint(PRBool aForceFullRepaint
,
494 PAINTSTRUCT ps
, HDC aDC
);
496 static void ActivateOtherWindowHelper(HWND aWnd
);
497 static PRUint16
GetMouseInputSource();
500 static STDMETHODIMP_(LRESULT
) LresultFromObject(REFIID riid
, WPARAM wParam
, LPUNKNOWN pAcc
);
501 #endif // ACCESSIBILITY
502 void ClearCachedResources();
504 nsPopupType
PopupType() { return mPopupType
; }
507 nsCOMPtr
<nsIWidget
> mParent
;
509 nsIntPoint mLastPoint
;
511 WNDPROC mPrevWndProc
;
513 PRPackedBool mIsTopWidgetWindow
;
514 PRPackedBool mInDtor
;
515 PRPackedBool mIsVisible
;
516 PRPackedBool mUnicodeWidget
;
517 PRPackedBool mPainting
;
518 PRPackedBool mTouchWindow
;
519 PRPackedBool mDisplayPanFeedback
;
520 PRPackedBool mHideChrome
;
522 PRPackedBool mFullscreenMode
;
523 PRPackedBool mMousePresent
;
524 PRUint32 mBlurSuppressLevel
;
526 DWORD_PTR mOldExStyle
;
528 IMEContext mIMEContext
;
529 nsNativeDragTarget
* mNativeDragTarget
;
530 HKL mLastKeyboardLayout
;
531 nsPopupType mPopupType
;
532 nsSizeMode mOldSizeMode
;
533 WindowHook mWindowHook
;
534 DWORD mAssumeWheelIsZoomUntil
;
535 static PRUint32 sInstanceCount
;
536 static TriStateBool sCanQuit
;
537 static nsWindow
* sCurrentWindow
;
538 static BOOL sIsOleInitialized
;
539 static HCURSOR sHCursor
;
540 static imgIContainer
* sCursorImgContainer
;
541 static PRBool sSwitchKeyboardLayout
;
542 static PRBool sJustGotDeactivate
;
543 static PRBool sJustGotActivate
;
544 static PRBool sIsInMouseCapture
;
545 static int sTrimOnMinimize
;
546 static PRBool sDefaultTrackPointHack
;
547 static const char* sDefaultMainWindowClass
;
548 static PRBool sUseElantechGestureHacks
;
549 static bool sAllowD3D9
;
551 static PRUint32 sOOPPPluginFocusEvent
;
554 // Non-client margin settings
555 // Pre-calculated outward offset applied to default frames
556 nsIntMargin mNonClientOffset
;
557 // Margins set by the owner
558 nsIntMargin mNonClientMargins
;
560 // Indicates custom frames are enabled
561 PRPackedBool mCustomNonClient
;
562 // Cached copy of L&F's resize border
563 PRInt32 mHorResizeMargin
;
564 PRInt32 mVertResizeMargin
;
565 // Height of the caption plus border
566 PRInt32 mCaptionHeight
;
568 nsCOMPtr
<nsIdleService
> mIdleService
;
570 // Hook Data Memebers for Dropdowns. sProcessHook Tells the
571 // hook methods whether they should be processing the hook
573 static HHOOK sMsgFilterHook
;
574 static HHOOK sCallProcHook
;
575 static HHOOK sCallMouseHook
;
576 static PRPackedBool sProcessHook
;
577 static UINT sRollupMsgId
;
578 static HWND sRollupMsgWnd
;
579 static UINT sHookTimerId
;
582 static nsIWidget
* sRollupWidget
;
583 static PRBool sRollupConsumeEvent
;
584 static nsIRollupListener
* sRollupListener
;
585 static nsIMenuRollup
* sMenuRollup
;
587 // Mouse Clicks - static variable definitions for figuring
589 static POINT sLastMousePoint
;
590 static POINT sLastMouseMovePoint
;
591 static LONG sLastMouseDownTime
;
592 static LONG sLastClickCount
;
593 static BYTE sLastMouseButton
;
596 HDC mPaintDC
; // only set during painting
598 #ifdef CAIRO_HAS_D2D_SURFACE
599 nsRefPtr
<gfxD2DSurface
> mD2DWindowSurface
; // Surface for this window.
604 // Use layered windows to support full 256 level alpha translucency
605 nsRefPtr
<gfxASurface
> mTransparentSurface
;
607 nsTransparencyMode mTransparencyMode
;
608 #if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN
609 nsIntRegion mPossiblyTransparentRegion
;
610 MARGINS mGlassMargins
;
611 #endif // #if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN
614 // Win7 Gesture processing and management
616 nsWinGesture mGesture
;
617 #endif // !defined(WINCE)
619 #if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_WIN7
620 // Weak ref to the nsITaskbarWindowPreview associated with this window
621 nsWeakPtr mTaskbarPreview
;
622 // True if the taskbar (possibly through the tab preview) tells us that the
623 // icon has been created on the taskbar.
624 PRBool mHasTaskbarIconBeenCreated
;
627 // The point in time at which the last paint completed. We use this to avoid
628 // painting too rapidly in response to frequent input events.
629 TimeStamp mLastPaintEndTime
;
631 #if defined(WINCE_HAVE_SOFTKB)
632 static PRBool sSoftKeyboardState
;
633 #endif // defined(WINCE_HAVE_SOFTKB)
636 static BOOL sIsAccessibilityOn
;
637 static HINSTANCE sAccLib
;
638 static LPFNLRESULTFROMOBJECT sLresultFromObject
;
639 #endif // ACCESSIBILITY
641 // sRedirectedKeyDown is WM_KEYDOWN message or WM_SYSKEYDOWN message which
642 // was reirected to SendInput() API by OnKeyDown().
643 static MSG sRedirectedKeyDown
;
645 // If a window receives WM_KEYDOWN message or WM_SYSKEYDOWM message which is
646 // redirected message, OnKeyDowm() prevents to dispatch NS_KEY_DOWN event
647 // because it has been dispatched before the message was redirected.
648 // However, in some cases, ProcessKeyDownMessage() doesn't call OnKeyDown().
649 // Then, ProcessKeyDownMessage() needs to forget the redirected message and
650 // remove WM_CHAR message or WM_SYSCHAR message for the redirected keydown
651 // message. AutoForgetRedirectedKeyDownMessage struct is a helper struct
652 // for doing that. This must be created in stack.
653 struct AutoForgetRedirectedKeyDownMessage
655 AutoForgetRedirectedKeyDownMessage(nsWindow
* aWindow
, const MSG
&aMsg
) :
656 mCancel(!nsWindow::IsRedirectedKeyDownMessage(aMsg
)),
657 mWindow(aWindow
), mMsg(aMsg
)
661 ~AutoForgetRedirectedKeyDownMessage()
666 // Prevent unnecessary keypress event
667 if (!mWindow
->mOnDestroyCalled
) {
668 nsWindow::RemoveNextCharMessage(mWindow
->mWnd
);
670 // Foreget the redirected message
671 nsWindow::ForgetRedirectedKeyDownMessage();
675 nsRefPtr
<nsWindow
> mWindow
;
682 * A child window is a window with different style.
684 class ChildWindow
: public nsWindow
{
690 virtual DWORD
WindowStyle();