41 #include "nsStringGlue.h"
42 #include "nsIBaseWindow.h"
43 #include "nsIDocShell.h"
44 #include "nsIDocShellTreeItem.h"
45 #include "nsIDocShellTreeOwner.h"
46 #include "nsIDOMAbstractView.h"
47 #include "nsIDOMDocument.h"
48 #include "nsIDOMDocumentEvent.h"
49 #include "nsIDOMDocumentView.h"
50 #include "nsIDOMEventTarget.h"
51 #include "nsIDOMMouseEvent.h"
52 #include "nsIDOMWindow.h"
53 #include "nsIInterfaceRequestor.h"
54 #include "nsIWebNavigation.h"
55 #include "nsIXULWindow.h"
57 #define S_PROPINST TEXT("_NS_WINDOWUTIL_INST")
58 #define S_PROPPROC TEXT("_NS_WINDOWUTIL_PROC")
60 #define MK_ENSURE_NATIVE(res) \
62 NS_ENSURE_TRUE(0 != res || 0 == ::GetLastError(), \
63 ::GetLastError() + MK_ERROR_OFFSET); \
66 #define MK_ERROR_OFFSET (0xD0000000 + (__LINE__ * 0x10000))
75 nsWindowUtil::~nsWindowUtil()
92 rv = GetDocShell(getter_AddRefs(docShell));
93 NS_ENSURE_SUCCESS(rv, rv);
95 nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(docShell, &rv));
96 NS_ENSURE_SUCCESS(rv, rv);
98 nativeWindow theNativeWindow;
99 rv = baseWindow->GetParentNativeWindow( &theNativeWindow );
100 NS_ENSURE_SUCCESS(rv, rv);
102 mWnd =
reinterpret_cast<HWND
>(theNativeWindow);
103 NS_ENSURE_TRUE(
mWnd, NS_ERROR_UNEXPECTED);
110 nsWindowUtil::GetXulWindow(nsIXULWindow **_retval)
115 nsCOMPtr<nsIInterfaceRequestor>
116 requestor(do_QueryInterface(
mDOMWindow, &rv));
117 NS_ENSURE_SUCCESS(rv, rv);
119 nsCOMPtr<nsIWebNavigation> nav;
121 getter_AddRefs(nav));
122 NS_ENSURE_SUCCESS(rv, rv);
124 nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(nav, &rv));
125 NS_ENSURE_SUCCESS(rv, rv);
127 nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
128 rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
129 NS_ENSURE_SUCCESS(rv, rv);
131 requestor = do_QueryInterface(treeOwner, &rv);
132 NS_ENSURE_SUCCESS(rv, rv);
134 return requestor->GetInterface(NS_GET_IID(nsIXULWindow), (
void **) _retval);
139 nsWindowUtil::GetDocShell(nsIDocShell **_retval)
143 rv = GetXulWindow(getter_AddRefs(xulWindow));
144 NS_ENSURE_SUCCESS(rv, rv);
146 return xulWindow->GetDocShell(_retval);
151 nsWindowUtil::Minimize()
153 ::ShowWindow(
mWnd, SW_MINIMIZE);
159 nsWindowUtil::GetHidden(PRBool* _retval)
161 NS_ENSURE_STATE(
mWnd);
163 if (::IsWindowVisible(
mWnd))
173 nsWindowUtil::Watch()
175 NS_ENSURE_STATE(
mWnd);
181 return NS_ERROR_ALREADY_INITIALIZED;
183 mOldProc = (WNDPROC)::GetWindowLongPtr(
mWnd, GWLP_WNDPROC);
195 nsWindowUtil::Unwatch()
197 return NS_ERROR_NOT_IMPLEMENTED;
211 if (
self &&
self->mOldProc &&
self->mDOMWindow) {
220 proc = DefWindowProc;
231 nsAutoString typeArg;
233 POINT clientPos = { 0, 0};
234 POINT screenPos = { 0, 0};
238 case WM_NCLBUTTONDOWN:
242 typeArg = NS_LITERAL_STRING(
"minimizing");
245 typeArg = NS_LITERAL_STRING(
"maximizing");
248 typeArg = NS_LITERAL_STRING(
"closing");
253 clientPos.
x = screenPos.
x = LOWORD(lParam);
254 clientPos.
y = screenPos.
y = LOWORD(lParam);
255 ::ClientToScreen(hwnd, &screenPos);
258 switch (LOWORD(wParam)) {
262 typeArg = NS_LITERAL_STRING(
"activating");
271 typeArg = NS_LITERAL_STRING(
"minimizing");
291 typeArg = NS_LITERAL_STRING(
"closing");
303 PRBool ctrlArg = PR_FALSE;
304 PRBool altArg = PR_FALSE;
305 PRBool shiftArg = PR_FALSE;
309 if (::GetKeyState(VK_CONTROL) & 0x8000)
311 if (::GetKeyState(VK_MENU) & 0x8000)
313 if (::GetKeyState(VK_SHIFT) & 0x8000)
320 nsCOMPtr<nsIDOMEventTarget>
eventTarget(do_QueryInterface(
self->mDOMWindow, &rv));
321 NS_ENSURE_SUCCESS(rv, rv);
323 nsCOMPtr<nsIDOMDocument> document;
324 rv =
self->mDOMWindow->GetDocument(getter_AddRefs(document));
325 NS_ENSURE_SUCCESS(rv, rv);
327 nsCOMPtr<nsIDOMDocumentEvent> documentEvent(do_QueryInterface(document, &rv));
328 NS_ENSURE_SUCCESS(rv, rv);
330 nsCOMPtr<nsIDOMDocumentView> documentView(do_QueryInterface(document, &rv));
331 NS_ENSURE_SUCCESS(rv, rv);
333 nsCOMPtr<nsIDOMAbstractView> abstractView;
334 rv = documentView->GetDefaultView(getter_AddRefs(abstractView));
335 NS_ENSURE_SUCCESS(rv, rv);
337 nsCOMPtr<nsIDOMEvent>
event;
338 rv = documentEvent->CreateEvent(NS_LITERAL_STRING(
"mouseevent"), getter_AddRefs(event));
339 NS_ENSURE_SUCCESS(rv, rv);
341 nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(event, &rv));
342 NS_ENSURE_SUCCESS(rv, rv);
344 rv = mouseEvent->InitMouseEvent(typeArg, PR_TRUE, PR_TRUE, abstractView,
345 1, screenPos.
x, screenPos.
y, clientPos.
x, clientPos.
y, ctrlArg, altArg,
346 shiftArg, PR_FALSE, 0, nsnull);
347 NS_ENSURE_SUCCESS(rv, rv);
349 rv = eventTarget->DispatchEvent(mouseEvent, &ret);
350 NS_ENSURE_SUCCESS(rv, rv);
357 return CallWindowProc(proc, hwnd, uMsg, wParam, lParam);
readonly attribute nsIXULWindow xulWindow
readonly attribute nsIDocShell docShell
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
#define MK_ENSURE_NATIVE(res)
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
nsCOMPtr< nsIDOMWindow > mDOMWindow