nsWindowUtilGTK.cpp
Go to the documentation of this file.
1 /* vim: set fileencoding=utf-8 shiftwidth=2 : */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
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/
9  *
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
13  * License.
14  *
15  * The Original Code is toolkit/components/systray
16  *
17  * The Initial Developer of the Original Code is
18  * Mook <mook.moz+cvs.mozilla.org@gmail.com>.
19  * Portions created by the Initial Developer are Copyright (C) 2007
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  * Brad Peterson <b_peterson@yahoo.com>
24  * Daniel Glazman <daniel.glazman@disruptive-innovations.com>
25  * Matthew Gertner <matthew@allpeers.com>
26  *
27  * Alternatively, the contents of this file may be used under the terms of
28  * either the GNU General Public License Version 2 or later (the "GPL"), or
29  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30  * in which case the provisions of the GPL or the LGPL are applicable instead
31  * of those above. If you wish to allow use of your version of this file only
32  * under the terms of either the GPL or the LGPL, and not to allow others to
33  * use your version of this file under the terms of the MPL, indicate your
34  * decision by deleting the provisions above and replace them with the notice
35  * and other provisions required by the GPL or the LGPL. If you do not delete
36  * the provisions above, a recipient may use your version of this file under
37  * the terms of any one of the MPL, the GPL or the LGPL.
38  *
39  * ***** END LICENSE BLOCK ***** */
40 
41 #include "nsWindowUtilGTK.h"
42 #include <nsComponentManagerUtils.h>
43 #include <nsIInterfaceRequestor.h>
44 #include <nsIInterfaceRequestorUtils.h>
45 #include <nsIWebNavigation.h>
46 #include <nsIDocShellTreeItem.h>
47 #include <nsIDocShellTreeOwner.h>
48 #include <nsIXULWindow.h>
49 #include <nsIWindowUtil.h>
50 #include <nsIDocShell.h>
51 #include <nsIBaseWindow.h>
52 
54 
56  :mGDKWindow(NULL)
57 {
58 }
59 
60 nsWindowUtil::~nsWindowUtil()
61 {
62  if (mGDKWindow && !gdk_window_is_visible(mGDKWindow)) {
63  gdk_window_show_unraised(mGDKWindow);
64  }
65 }
66 
67 /* readonly attribute boolean hidden; */
68 NS_IMETHODIMP nsWindowUtil::GetHidden(PRBool *aHidden)
69 {
70  NS_ENSURE_ARG(aHidden);
71  if (!mGDKWindow) return NS_ERROR_NOT_INITIALIZED;
72 
73  gboolean isVisible = gdk_window_is_visible(mGDKWindow);
74  *aHidden = isVisible ? PR_FALSE : PR_TRUE;
75  return NS_OK;
76 }
77 
78 /* void init (in nsIDOMWindow win, in nsIBaseWindow baseWindow); */
79 NS_IMETHODIMP nsWindowUtil::Init(nsIDOMWindow *aDOMWindow)
80 {
81  #if DEBUG
82  NS_WARNING("nsWindowUtil::Init()");
83  printf( "nsWindowUtil::Init: %08x\n",
84  reinterpret_cast<PRUint32>(aDOMWindow) );
85  #endif
86  NS_ENSURE_ARG(aDOMWindow);
87  if (mDOMWindow) {
88  return NS_ERROR_ALREADY_INITIALIZED;
89  }
90  mDOMWindow = aDOMWindow;
91 
92  nsresult rv;
93 
94  nsCOMPtr<nsIDocShell> docShell;
95  rv = GetDocShell(getter_AddRefs(docShell));
96  NS_ENSURE_SUCCESS(rv, rv);
97  nsCOMPtr<nsIBaseWindow> baseWindow( do_QueryInterface(docShell, &rv) );
98  NS_ENSURE_SUCCESS(rv, rv);
99  nativeWindow theNativeWindow;
100  rv = baseWindow->GetParentNativeWindow( &theNativeWindow );
101  NS_ENSURE_SUCCESS(rv, rv);
102 
103  GdkWindow *gdkWindow = nsnull;
104  gdkWindow = reinterpret_cast<GdkWindow*>(theNativeWindow);
105  NS_ENSURE_TRUE(gdkWindow, NS_ERROR_UNEXPECTED);
106  NS_ENSURE_TRUE(GDK_IS_WINDOW(gdkWindow), NS_ERROR_INVALID_ARG);
107 
108  // need to get top level window to hide :/
109 
110  mGDKWindow = gdk_window_get_toplevel(gdkWindow);
111  NS_ENSURE_TRUE(mGDKWindow, NS_ERROR_UNEXPECTED);
112 
113  return NS_OK;
114 }
115 
116 /* readonly attribute nsIXULWindow xulWindow */
117 NS_IMETHODIMP
118 nsWindowUtil::GetXulWindow(nsIXULWindow **_retval)
119 {
120  NS_ENSURE_STATE(mDOMWindow);
121 
122  nsresult rv;
123  nsCOMPtr<nsIInterfaceRequestor>
124  requestor(do_QueryInterface(mDOMWindow, &rv));
125  NS_ENSURE_SUCCESS(rv, rv);
126 
127  nsCOMPtr<nsIWebNavigation> nav;
128  rv = requestor->GetInterface(NS_GET_IID(nsIWebNavigation),
129  getter_AddRefs(nav));
130  NS_ENSURE_SUCCESS(rv, rv);
131 
132  nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(nav, &rv));
133  NS_ENSURE_SUCCESS(rv, rv);
134 
135  nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
136  rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
137  NS_ENSURE_SUCCESS(rv, rv);
138 
139  requestor = do_QueryInterface(treeOwner, &rv);
140  NS_ENSURE_SUCCESS(rv, rv);
141 
142  return requestor->GetInterface(NS_GET_IID(nsIXULWindow), (void **) _retval);
143 }
144 
145 /* readonly attribute nsIDocShell docShell */
146 NS_IMETHODIMP
147 nsWindowUtil::GetDocShell(nsIDocShell **_retval)
148 {
149  nsresult rv;
150  nsCOMPtr<nsIXULWindow> xulWindow;
151  rv = GetXulWindow(getter_AddRefs(xulWindow));
152  NS_ENSURE_SUCCESS(rv, rv);
153 
154  return xulWindow->GetDocShell(_retval);
155 }
156 
157 /* void minimize (); */
158 NS_IMETHODIMP nsWindowUtil::Minimize()
159 {
160  if (!mGDKWindow) {
161  NS_WARNING("nsWindowUtil::Minimize:: not initialized");
162  return NS_ERROR_NOT_INITIALIZED;
163  }
164  #if DEBUG
165  printf( "nsWindowUtil::Minimize(%08x)\n",
166  reinterpret_cast<PRUint32>(mGDKWindow) );
167  #endif
168  NS_ENSURE_TRUE(GDK_IS_WINDOW(mGDKWindow), NS_ERROR_UNEXPECTED);
169  #if DEBUG
170  printf( " -> hiding\n");
171  #endif
172  gdk_window_hide(mGDKWindow);
173  return NS_OK;
174 }
175 
176 /* void watch (); */
177 NS_IMETHODIMP nsWindowUtil::Watch()
178 {
179  #if DEBUG
180  NS_WARNING("nsWindowUtil::Watch() not implemented");
181  printf( "this=%08x cast=%08x\n",
182  reinterpret_cast<PRUint32>(this),
183  reinterpret_cast<PRUint32>(dynamic_cast<nsIWindowUtil*>(this)) );
184  #endif
185  return NS_ERROR_NOT_IMPLEMENTED;
186 }
187 
188 /* void unwatch (); */
189 NS_IMETHODIMP nsWindowUtil::Unwatch()
190 {
191  #if DEBUG
192  NS_WARNING("nsWindowUtil::Unwatch() not implemented");
193  #endif
194  return NS_ERROR_NOT_IMPLEMENTED;
195 }
196 
return NS_OK
readonly attribute nsIXULWindow xulWindow
function isVisible(element)
readonly attribute nsIDocShell docShell
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
const nsIDOMWindow
const nsIWebNavigation
Definition: browser.js:71
function Init()
nsCOMPtr< nsIDOMWindow > mDOMWindow
GdkWindow * mGDKWindow