comparison dwt/browser/WindowCreator2.d @ 278:93409d9838c5

Commit more browser/xpcom updates, including still uncoverted source.
author John Reimer<terminal.node@gmail.com>
date Thu, 31 Jul 2008 19:17:51 -0700
parents
children 44258e0b6687
comparison
equal deleted inserted replaced
277:687f261028b8 278:93409d9838c5
1 /*******************************************************************************
2 * Copyright (c) 2003, 2007 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * John Reimer <terminal.node@gmail.com>
12 *******************************************************************************/
13 module dwt.browser.WindowCreator2;
14
15 import dwt.dwthelper.utils;
16
17 import dwt.internal.Platform;
18
19 import dwt.internal.mozilla.XPCOM;
20 import dwt.internal.mozilla.nsIBaseWindow;
21 import dwt.internal.mozilla.nsID;
22 import dwt.internal.mozilla.nsISupports;
23 import dwt.internal.mozilla.nsIURI;
24 import dwt.internal.mozilla.nsIWebBrowser;
25 import dwt.internal.mozilla.nsIWebBrowserChrome;
26 import dwt.internal.mozilla.nsIWindowCreator;
27
28 import dwt.DWT;
29 import dwt.graphics.Point;
30 import dwt.layout.FillLayout;
31 import dwt.widgets.Shell;
32
33 class WindowCreator2 {
34 XPCOMObject supports;
35 XPCOMObject windowCreator;
36 XPCOMObject windowCreator2;
37 int refCount = 0;
38
39 WindowCreator2 () {
40 createCOMInterfaces ();
41 }
42
43 int AddRef () {
44 refCount++;
45 return refCount;
46 }
47
48 void createCOMInterfaces () {
49 /* Create each of the interfaces that this object implements */
50 supports = new XPCOMObject (new int[] {2, 0, 0}) {
51 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);}
52 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();}
53 public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
54 };
55
56 windowCreator = new XPCOMObject (new int[] {2, 0, 0, 3}) {
57 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);}
58 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();}
59 public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
60 public int /*long*/ method3 (int /*long*/[] args) {return CreateChromeWindow (args[0], (int)/*64*/args[1], args[2]);}
61 };
62
63 windowCreator2 = new XPCOMObject (new int[] {2, 0, 0, 3, 6}) {
64 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);}
65 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();}
66 public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
67 public int /*long*/ method3 (int /*long*/[] args) {return CreateChromeWindow (args[0], (int)/*64*/args[1], args[2]);}
68 public int /*long*/ method4 (int /*long*/[] args) {return CreateChromeWindow2 (args[0], (int)/*64*/args[1], (int)/*64*/args[2], args[3], args[4], args[5]);}
69 };
70 }
71
72 void disposeCOMInterfaces () {
73 if (supports !is null) {
74 supports.dispose ();
75 supports = null;
76 }
77 if (windowCreator !is null) {
78 windowCreator.dispose ();
79 windowCreator = null;
80 }
81
82 if (windowCreator2 !is null) {
83 windowCreator2.dispose ();
84 windowCreator2 = null;
85 }
86 }
87
88 int /*long*/ getAddress () {
89 return windowCreator.getAddress ();
90 }
91
92 int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) {
93 if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE;
94 nsID guid = new nsID ();
95 XPCOM.memmove (guid, riid, nsID.sizeof);
96
97 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) {
98 XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF);
99 AddRef ();
100 return XPCOM.NS_OK;
101 }
102 if (guid.Equals (nsIWindowCreator.NS_IWINDOWCREATOR_IID)) {
103 XPCOM.memmove (ppvObject, new int /*long*/[] {windowCreator.getAddress ()}, C.PTR_SIZEOF);
104 AddRef ();
105 return XPCOM.NS_OK;
106 }
107 if (guid.Equals (nsIWindowCreator2.NS_IWINDOWCREATOR2_IID)) {
108 XPCOM.memmove (ppvObject, new int /*long*/[] {windowCreator2.getAddress ()}, C.PTR_SIZEOF);
109 AddRef ();
110 return XPCOM.NS_OK;
111 }
112
113 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF);
114 return XPCOM.NS_ERROR_NO_INTERFACE;
115 }
116
117 int Release () {
118 refCount--;
119 if (refCount is 0) disposeCOMInterfaces ();
120 return refCount;
121 }
122
123 /* nsIWindowCreator */
124
125 int CreateChromeWindow (int /*long*/ parent, int chromeFlags, int /*long*/ _retval) {
126 return CreateChromeWindow2 (parent, chromeFlags, 0, 0, 0, _retval);
127 }
128
129 /* nsIWindowCreator2 */
130
131 int CreateChromeWindow2 (int /*long*/ parent, int chromeFlags, int contextFlags, int /*long*/ uri, int /*long*/ cancel, int /*long*/ _retval) {
132 if (parent is 0 && (chromeFlags & nsIWebBrowserChrome.CHROME_OPENAS_CHROME) is 0) {
133 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
134 }
135 Browser src = null;
136 if (parent !is 0) {
137 nsIWebBrowserChrome browserChromeParent = new nsIWebBrowserChrome (parent);
138 int /*long*/[] aWebBrowser = new int /*long*/[1];
139 int rc = browserChromeParent.GetWebBrowser (aWebBrowser);
140 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
141 if (aWebBrowser[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE);
142
143 nsIWebBrowser webBrowser = new nsIWebBrowser (aWebBrowser[0]);
144 int /*long*/[] result = new int /*long*/[1];
145 rc = webBrowser.QueryInterface (nsIBaseWindow.NS_IBASEWINDOW_IID, result);
146 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
147 if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE);
148 webBrowser.Release ();
149
150 nsIBaseWindow baseWindow = new nsIBaseWindow (result[0]);
151 result[0] = 0;
152 int /*long*/[] aParentNativeWindow = new int /*long*/[1];
153 rc = baseWindow.GetParentNativeWindow (aParentNativeWindow);
154 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
155 if (aParentNativeWindow[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE);
156 baseWindow.Release ();
157
158 src = Mozilla.findBrowser (aParentNativeWindow[0]);
159 }
160 final Browser browser;
161 bool doit = true;
162 if ((chromeFlags & nsIWebBrowserChrome.CHROME_OPENAS_CHROME) !is 0) {
163 /*
164 * Mozilla will request a new Browser in a modal window in order to emulate a native
165 * dialog that is not available to it (eg.- a print dialog on Linux). For this
166 * reason modal requests are handled here so that the user is not exposed to them.
167 */
168 int style = DWT.DIALOG_TRIM;
169 if ((chromeFlags & nsIWebBrowserChrome.CHROME_MODAL) !is 0) style |= DWT.APPLICATION_MODAL;
170 final Shell shell = src is null ?
171 new Shell (style) :
172 new Shell (src.getShell(), style);
173 shell.setLayout (new FillLayout ());
174 browser = new Browser (shell, src is null ? DWT.MOZILLA : src.getStyle () & DWT.MOZILLA);
175 browser.addVisibilityWindowListener (new VisibilityWindowListener () {
176 public void hide (WindowEvent event) {
177 }
178 public void show (WindowEvent event) {
179 if (event.location !is null) shell.setLocation (event.location);
180 if (event.size !is null) {
181 Point size = event.size;
182 shell.setSize (shell.computeSize (size.x, size.y));
183 }
184 shell.open ();
185 }
186 });
187 browser.addCloseWindowListener (new CloseWindowListener () {
188 public void close (WindowEvent event) {
189 shell.close ();
190 }
191 });
192 if (uri !is 0) {
193 nsIURI location = new nsIURI (uri);
194 int /*long*/ aSpec = XPCOM.nsEmbedCString_new ();
195 if (location.GetSpec (aSpec) is XPCOM.NS_OK) {
196 int length = XPCOM.nsEmbedCString_Length (aSpec);
197 if (length > 0) {
198 int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec);
199 byte[] dest = new byte[length];
200 XPCOM.memmove (dest, buffer, length);
201 browser.setUrl (new String (dest));
202 }
203 }
204 XPCOM.nsEmbedCString_delete (aSpec);
205 }
206 } else {
207 WindowEvent event = new WindowEvent (src);
208 event.display = src.getDisplay ();
209 event.widget = src;
210 event.required = true;
211 for (int i = 0; i < src.webBrowser.openWindowListeners.length; i++) {
212 src.webBrowser.openWindowListeners[i].open (event);
213 }
214 browser = event.browser;
215
216 /* Ensure that the Browser provided by the client is valid for use */
217 doit = browser !is null && !browser.isDisposed ();
218 if (doit) {
219 String platform = Platform.PLATFORM;
220 bool isMozillaNativePlatform = platform.equals ("gtk") || platform.equals ("motif"); //$NON-NLS-1$ //$NON-NLS-2$
221 doit = isMozillaNativePlatform || (browser.getStyle () & DWT.MOZILLA) !is 0;
222 }
223 }
224 if (doit) {
225 Mozilla mozilla = (Mozilla)browser.webBrowser;
226 mozilla.isChild = true;
227 int /*long*/ chromePtr = mozilla.webBrowserChrome.getAddress ();
228 nsIWebBrowserChrome webBrowserChrome = new nsIWebBrowserChrome (chromePtr);
229 webBrowserChrome.SetChromeFlags (chromeFlags);
230 webBrowserChrome.AddRef ();
231 XPCOM.memmove (_retval, new int /*long*/[] {chromePtr}, C.PTR_SIZEOF);
232 } else {
233 if (cancel !is 0) {
234 C.memmove (cancel, new int[] {1}, 4); /* PRBool */
235 }
236 }
237 return doit ? XPCOM.NS_OK : XPCOM.NS_ERROR_NOT_IMPLEMENTED;
238 }
239 }