Mercurial > projects > dwt-mac
annotate dwt/browser/Browser.d @ 156:969e7de37c3d default tip
Fixes to get dwt to work with dmd and ldc
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Wed, 08 Jul 2009 21:56:44 +0200 |
parents | 5583f8eeee6c |
children |
rev | line source |
---|---|
125 | 1 /******************************************************************************* |
2 * Copyright (c) 2003, 2007 IBM Corporation and others. | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
3 * All rights reserved. This program and the accompanying materials |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
5 * which accompanies this distribution, and is available at |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
6 * http://www.eclipse.org/legal/epl-v10.html |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
7 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
8 * Contributors: |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
9 * IBM Corporation - initial API and implementation |
13
f565d3a95c0a
Ported dwt.internal
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
0
diff
changeset
|
10 * Port to the D programming language: |
125 | 11 * John Reimer <terminal.node@gmail.com> |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
12 *******************************************************************************/ |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
13 module dwt.browser.Browser; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
14 |
125 | 15 import dwt.dwthelper.utils; |
16 | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
17 import tango.core.Thread; |
125 | 18 import tango.io.Stdout; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
19 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
20 import dwt.DWT; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
21 import dwt.DWTError; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
22 import dwt.DWTException; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
23 import dwt.widgets.Composite; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
24 import dwt.widgets.Display; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
25 import dwt.widgets.Widget; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
26 |
125 | 27 import dwt.browser.Mozilla; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
28 import dwt.browser.WebBrowser; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
29 import dwt.browser.CloseWindowListener; |
125 | 30 import dwt.browser.LocationListener; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
31 import dwt.browser.OpenWindowListener; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
32 import dwt.browser.ProgressListener; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
33 import dwt.browser.StatusTextListener; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
34 import dwt.browser.TitleListener; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
35 import dwt.browser.VisibilityWindowListener; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
36 /** |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
37 * Instances of this class implement the browser user interface |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
38 * metaphor. It allows the user to visualize and navigate through |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
39 * HTML documents. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
40 * <p> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
41 * Note that although this class is a subclass of <code>Composite</code>, |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
42 * it does not make sense to set a layout on it. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
43 * </p> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
44 * <dl> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
45 * <dt><b>Styles:</b></dt> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
46 * <dd>MOZILLA</dd> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
47 * <dt><b>Events:</b></dt> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
48 * <dd>CloseWindowListener, LocationListener, OpenWindowListener, ProgressListener, StatusTextListener, TitleListener, VisibilityWindowListener</dd> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
49 * </dl> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
50 * <p> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
51 * IMPORTANT: This class is <em>not</em> intended to be subclassed. |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
52 * </p> |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
53 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
54 * @since 3.0 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
55 */ |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
56 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
57 public class Browser : Composite { |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
58 WebBrowser webBrowser; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
59 int userStyle; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
60 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
61 static final String PACKAGE_PREFIX = "dwt.browser."; //$NON-NLS-1$ |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
62 static final String NO_INPUT_METHOD = "dwt.internal.gtk.noInputMethod"; //$NON-NLS-1$ |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
63 |
125 | 64 /** |
65 * Constructs a new instance of this class given its parent | |
66 * and a style value describing its behavior and appearance. | |
67 * <p> | |
68 * The style value is either one of the style constants defined in | |
69 * class <code>DWT</code> which is applicable to instances of this | |
70 * class, or must be built by <em>bitwise OR</em>'ing together | |
71 * (that is, using the <code>int</code> "|" operator) two or more | |
72 * of those <code>DWT</code> style constants. The class description | |
73 * lists the style constants that are applicable to the class. | |
74 * Style bits are also inherited from superclasses. | |
75 * </p> | |
76 * | |
77 * @param parent a widget which will be the parent of the new instance (cannot be null) | |
78 * @param style the style of widget to construct | |
79 * | |
80 * @exception IllegalArgumentException <ul> | |
81 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
82 * </ul> | |
83 * @exception DWTException <ul> | |
84 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
85 * </ul> | |
86 * @exception DWTError <ul> | |
87 * <li>ERROR_NO_HANDLES if a handle could not be obtained for browser creation</li> | |
88 * </ul> | |
89 * | |
90 * @see Widget#getStyle | |
91 * | |
92 * @since 3.0 | |
93 */ | |
94 public this (Composite parent, int style) { | |
95 super (checkParent (parent), checkStyle (style)); | |
96 userStyle = style; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
97 |
125 | 98 String platform = DWT.getPlatform (); |
99 Display display = parent.getDisplay (); | |
100 if ("gtk" == platform) display.setData (NO_INPUT_METHOD, null); //$NON-NLS-1$ | |
101 /* | |
102 String className = null; | |
103 if ((style & DWT.MOZILLA) !is 0) { | |
104 className = "dwt.browser.Mozilla"; //$NON-NLS-1$ | |
105 } else { | |
106 dispose(); | |
107 DWT.error(DWT.ERROR_NO_HANDLES); | |
108 } | |
109 */ | |
110 webBrowser = new Mozilla; | |
111 if (webBrowser is null) { | |
112 dispose (); | |
113 DWT.error (DWT.ERROR_NO_HANDLES); | |
114 } | |
115 | |
116 webBrowser.setBrowser (this); | |
117 webBrowser.create (parent, style); | |
118 } | |
119 | |
120 static Composite checkParent (Composite parent) { | |
121 String platform = DWT.getPlatform (); | |
122 if (!("gtk" == platform)) return parent; //$NON-NLS-1$ | |
123 | |
124 /* | |
125 * Note. Mozilla provides all IM support needed for text input in web pages. | |
126 * If DWT creates another input method context for the widget it will cause | |
127 * indeterminate results to happen (hangs and crashes). The fix is to prevent | |
128 * DWT from creating an input method context for the Browser widget. | |
129 */ | |
130 if (parent !is null && !parent.isDisposed ()) { | |
131 Display display = parent.getDisplay (); | |
132 if (display !is null) { | |
133 if (display.getThread () is Thread.getThis ()) { | |
134 display.setData (NO_INPUT_METHOD, stringcast("true")); //$NON-NLS-1$ | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
135 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
136 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
137 } |
125 | 138 return parent; |
139 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
140 |
125 | 141 static int checkStyle(int style) { |
142 String platform = DWT.getPlatform (); | |
143 if ((style & DWT.MOZILLA) !is 0) { | |
144 if ("carbon" == platform) return style | DWT.EMBEDDED; //$NON-NLS-1$ | |
145 if ("motif" == platform) return style | DWT.EMBEDDED; //$NON-NLS-1$ | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
146 return style; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
147 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
148 |
125 | 149 if ("win32" == platform) { //$NON-NLS-1$ |
150 /* | |
151 * For IE on win32 the border is supplied by the embedded browser, so remove | |
152 * the style so that the parent Composite will not draw a second border. | |
153 */ | |
154 return style & ~DWT.BORDER; | |
155 } else if ("motif" == platform) { //$NON-NLS-1$ | |
156 return style | DWT.EMBEDDED; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
157 } |
125 | 158 return style; |
159 } | |
160 | |
161 /** | |
162 * Clears all session cookies from all current Browser instances. | |
163 * | |
164 * @since 3.2 | |
165 */ | |
166 public static void clearSessions () { | |
167 WebBrowser.clearSessions (); | |
168 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
169 |
125 | 170 /** |
171 * Adds the listener to the collection of listeners who will be | |
172 * notified when the window hosting the receiver should be closed. | |
173 * <p> | |
174 * This notification occurs when a javascript command such as | |
175 * <code>window.close</code> gets executed by a <code>Browser</code>. | |
176 * </p> | |
177 * | |
178 * @param listener the listener which should be notified | |
179 * | |
180 * @exception IllegalArgumentException <ul> | |
181 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
182 * </ul> | |
183 * | |
184 * @exception DWTException <ul> | |
185 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
186 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
187 * </ul> | |
188 * | |
189 * @since 3.0 | |
190 */ | |
191 public void addCloseWindowListener (CloseWindowListener listener) { | |
192 checkWidget(); | |
193 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
194 webBrowser.addCloseWindowListener (listener); | |
195 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
196 |
125 | 197 /** |
198 * Adds the listener to the collection of listeners who will be | |
199 * notified when the current location has changed or is about to change. | |
200 * <p> | |
201 * This notification typically occurs when the application navigates | |
202 * to a new location with {@link #setUrl(String)} or when the user | |
203 * activates a hyperlink. | |
204 * </p> | |
205 * | |
206 * @param listener the listener which should be notified | |
207 * | |
208 * @exception IllegalArgumentException <ul> | |
209 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
210 * </ul> | |
211 * | |
212 * @exception DWTException <ul> | |
213 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
214 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
215 * </ul> | |
216 * | |
217 * @since 3.0 | |
218 */ | |
219 public void addLocationListener (LocationListener listener) { | |
220 checkWidget(); | |
221 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
222 webBrowser.addLocationListener (listener); | |
223 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
224 |
125 | 225 /** |
226 * Adds the listener to the collection of listeners who will be | |
227 * notified when a new window needs to be created. | |
228 * <p> | |
229 * This notification occurs when a javascript command such as | |
230 * <code>window.open</code> gets executed by a <code>Browser</code>. | |
231 * </p> | |
232 * | |
233 * @param listener the listener which should be notified | |
234 * | |
235 * @exception IllegalArgumentException <ul> | |
236 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
237 * </ul> | |
238 * | |
239 * @exception DWTException <ul> | |
240 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
241 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
242 * </ul> | |
243 * | |
244 * @since 3.0 | |
245 */ | |
246 public void addOpenWindowListener (OpenWindowListener listener) { | |
247 checkWidget(); | |
248 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
249 webBrowser.addOpenWindowListener (listener); | |
250 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
251 |
125 | 252 /** |
253 * Adds the listener to the collection of listeners who will be | |
254 * notified when a progress is made during the loading of the current | |
255 * URL or when the loading of the current URL has been completed. | |
256 * | |
257 * @param listener the listener which should be notified | |
258 * | |
259 * @exception IllegalArgumentException <ul> | |
260 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
261 * </ul> | |
262 * | |
263 * @exception DWTException <ul> | |
264 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
265 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
266 * </ul> | |
267 * | |
268 * @since 3.0 | |
269 */ | |
270 public void addProgressListener (ProgressListener listener) { | |
271 checkWidget(); | |
272 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
273 webBrowser.addProgressListener (listener); | |
274 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
275 |
125 | 276 /** |
277 * Adds the listener to the collection of listeners who will be | |
278 * notified when the status text is changed. | |
279 * <p> | |
280 * The status text is typically displayed in the status bar of | |
281 * a browser application. | |
282 * </p> | |
283 * | |
284 * @param listener the listener which should be notified | |
285 * | |
286 * @exception IllegalArgumentException <ul> | |
287 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
288 * </ul> | |
289 * | |
290 * @exception DWTException <ul> | |
291 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
292 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
293 * </ul> | |
294 * | |
295 * @since 3.0 | |
296 */ | |
297 public void addStatusTextListener (StatusTextListener listener) { | |
298 checkWidget(); | |
299 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
300 webBrowser.addStatusTextListener (listener); | |
301 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
302 |
125 | 303 /** |
304 * Adds the listener to the collection of listeners who will be | |
305 * notified when the title of the current document is available | |
306 * or has changed. | |
307 * | |
308 * @param listener the listener which should be notified | |
309 * | |
310 * @exception IllegalArgumentException <ul> | |
311 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
312 * </ul> | |
313 * | |
314 * @exception DWTException <ul> | |
315 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
316 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
317 * </ul> | |
318 * | |
319 * @since 3.0 | |
320 */ | |
321 public void addTitleListener (TitleListener listener) { | |
322 checkWidget(); | |
323 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
324 webBrowser.addTitleListener (listener); | |
325 } | |
326 | |
327 /** | |
328 * Adds the listener to the collection of listeners who will be | |
329 * notified when a window hosting the receiver needs to be displayed | |
330 * or hidden. | |
331 * | |
332 * @param listener the listener which should be notified | |
333 * | |
334 * @exception IllegalArgumentException <ul> | |
335 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
336 * </ul> | |
337 * | |
338 * @exception DWTException <ul> | |
339 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
340 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
341 * </ul> | |
342 * | |
343 * @since 3.0 | |
344 */ | |
345 public void addVisibilityWindowListener (VisibilityWindowListener listener) { | |
346 checkWidget(); | |
347 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
348 webBrowser.addVisibilityWindowListener (listener); | |
349 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
350 |
125 | 351 /** |
352 * Navigate to the previous session history item. | |
353 * | |
354 * @return <code>true</code> if the operation was successful and <code>false</code> otherwise | |
355 * | |
356 * @exception DWTException <ul> | |
357 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
358 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
359 * </ul> | |
360 * | |
361 * @see #forward | |
362 * | |
363 * @since 3.0 | |
364 */ | |
365 public bool back () { | |
366 checkWidget(); | |
367 return webBrowser.back (); | |
368 } | |
369 | |
370 protected void checkSubclass () { | |
371 String name = this.classinfo.name; | |
372 name = name.substring(0, name.lastIndexOf('.')); | |
373 int index = name.lastIndexOf('.'); | |
374 if (!name.substring (0, index + 1).equals (PACKAGE_PREFIX)) { | |
375 Stdout ("name: ")(name.substring(0, index + 1))(" == " )(PACKAGE_PREFIX).newline; | |
376 DWT.error (DWT.ERROR_INVALID_SUBCLASS); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
377 } |
125 | 378 } |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
379 |
125 | 380 /** |
381 * Execute the specified script. | |
382 * | |
383 * <p> | |
384 * Execute a script containing javascript commands in the context of the current document. | |
385 * | |
386 * @param script the script with javascript commands | |
387 * | |
388 * @return <code>true</code> if the operation was successful and <code>false</code> otherwise | |
389 * | |
390 * @exception IllegalArgumentException <ul> | |
391 * <li>ERROR_NULL_ARGUMENT - if the script is null</li> | |
392 * </ul> | |
393 * | |
394 * @exception DWTException <ul> | |
395 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
396 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
397 * </ul> | |
398 * | |
399 * @since 3.1 | |
400 */ | |
401 public bool execute (String script) { | |
402 checkWidget(); | |
403 if (script is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
404 return webBrowser.execute (script); | |
405 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
406 |
125 | 407 /** |
408 * Navigate to the next session history item. | |
409 * | |
410 * @return <code>true</code> if the operation was successful and <code>false</code> otherwise | |
411 * | |
412 * @exception DWTException <ul> | |
413 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
414 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
415 * </ul> | |
416 * | |
417 * @see #back | |
418 * | |
419 * @since 3.0 | |
420 */ | |
421 public bool forward () { | |
422 checkWidget(); | |
423 return webBrowser.forward (); | |
424 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
425 |
125 | 426 public int getStyle () { |
427 /* | |
428 * If DWT.BORDER was specified at creation time then getStyle() should answer | |
429 * it even though it is removed for IE on win32 in checkStyle(). | |
430 */ | |
431 return super.getStyle () | (userStyle & DWT.BORDER); | |
432 } | |
433 | |
434 /** | |
435 * Returns a string with HTML that represents the content of the current page. | |
436 * | |
437 * @return HTML representing the current page or an empty <code>String</code> | |
438 * if this is empty | |
439 * | |
440 * @exception DWTException <ul> | |
441 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
442 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
443 * </ul> | |
444 * | |
445 * @since 3.4 | |
446 */ | |
447 public String getText () { | |
448 checkWidget(); | |
449 return webBrowser.getText (); | |
45 | 450 } |
451 | |
452 /** | |
125 | 453 * Returns the current URL. |
454 * | |
455 * @return the current URL or an empty <code>String</code> if there is no current URL | |
45 | 456 * |
125 | 457 * @exception DWTException <ul> |
458 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
459 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
460 * </ul> | |
461 * | |
462 * @see #setUrl | |
45 | 463 * |
125 | 464 * @since 3.0 |
45 | 465 */ |
125 | 466 public String getUrl () { |
45 | 467 checkWidget(); |
125 | 468 return webBrowser.getUrl (); |
469 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
470 |
125 | 471 /** |
472 * Returns the JavaXPCOM <code>nsIWebBrowser</code> for the receiver, or <code>null</code> | |
473 * if it is not available. In order for an <code>nsIWebBrowser</code> to be returned all | |
474 * of the following must be true: <ul> | |
475 * <li>the receiver's style must be <code>DWT.MOZILLA</code></li> | |
476 * <li>the classes from JavaXPCOM >= 1.8.1.2 must be resolvable at runtime</li> | |
477 * <li>the version of the underlying XULRunner must be >= 1.8.1.2</li> | |
478 * </ul> | |
479 * | |
480 * @return the receiver's JavaXPCOM <code>nsIWebBrowser</code> or <code>null</code> | |
481 * | |
482 * @since 3.3 | |
483 */ | |
484 public Object getWebBrowser () { | |
485 checkWidget(); | |
486 return webBrowser.getWebBrowser (); | |
487 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
488 |
125 | 489 /** |
490 * Returns <code>true</code> if the receiver can navigate to the | |
491 * previous session history item, and <code>false</code> otherwise. | |
492 * | |
493 * @return the receiver's back command enabled state | |
494 * | |
495 * @exception DWTException <ul> | |
496 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
497 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
498 * </ul> | |
499 * | |
500 * @see #back | |
501 */ | |
502 public bool isBackEnabled () { | |
503 checkWidget(); | |
504 return webBrowser.isBackEnabled (); | |
505 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
506 |
125 | 507 public bool isFocusControl () { |
508 checkWidget(); | |
509 if (webBrowser.isFocusControl ()) return true; | |
510 return super.isFocusControl (); | |
511 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
512 |
125 | 513 /** |
514 * Returns <code>true</code> if the receiver can navigate to the | |
515 * next session history item, and <code>false</code> otherwise. | |
516 * | |
517 * @return the receiver's forward command enabled state | |
518 * | |
519 * @exception DWTException <ul> | |
520 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
521 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
522 * </ul> | |
523 * | |
524 * @see #forward | |
525 */ | |
526 public bool isForwardEnabled () { | |
527 checkWidget(); | |
528 return webBrowser.isForwardEnabled (); | |
529 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
530 |
125 | 531 /** |
532 * Refresh the current page. | |
533 * | |
534 * @exception DWTException <ul> | |
535 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
536 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
537 * </ul> | |
538 * | |
539 * @since 3.0 | |
540 */ | |
541 public void refresh () { | |
542 checkWidget(); | |
543 webBrowser.refresh (); | |
544 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
545 |
125 | 546 /** |
547 * Removes the listener from the collection of listeners who will | |
548 * be notified when the window hosting the receiver should be closed. | |
549 * | |
550 * @param listener the listener which should no longer be notified | |
551 * | |
552 * @exception IllegalArgumentException <ul> | |
553 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
554 * </ul> | |
555 * | |
556 * @exception DWTException <ul> | |
557 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
558 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
559 * </ul> | |
560 * | |
561 * @since 3.0 | |
562 */ | |
563 public void removeCloseWindowListener (CloseWindowListener listener) { | |
564 checkWidget(); | |
565 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
566 webBrowser.removeCloseWindowListener (listener); | |
567 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
568 |
125 | 569 /** |
570 * Removes the listener from the collection of listeners who will | |
571 * be notified when the current location is changed or about to be changed. | |
572 * | |
573 * @param listener the listener which should no longer be notified | |
574 * | |
575 * @exception IllegalArgumentException <ul> | |
576 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
577 * </ul> | |
578 * | |
579 * @exception DWTException <ul> | |
580 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
581 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
582 * </ul> | |
583 * | |
584 * @since 3.0 | |
585 */ | |
586 public void removeLocationListener (LocationListener listener) { | |
587 checkWidget(); | |
588 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
589 webBrowser.removeLocationListener (listener); | |
590 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
591 |
125 | 592 /** |
593 * Removes the listener from the collection of listeners who will | |
594 * be notified when a new window needs to be created. | |
595 * | |
596 * @param listener the listener which should no longer be notified | |
597 * | |
598 * @exception IllegalArgumentException <ul> | |
599 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
600 * </ul> | |
601 * | |
602 * @exception DWTException <ul> | |
603 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
604 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
605 * </ul> | |
606 * | |
607 * @since 3.0 | |
608 */ | |
609 public void removeOpenWindowListener (OpenWindowListener listener) { | |
610 checkWidget(); | |
611 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
612 webBrowser.removeOpenWindowListener (listener); | |
613 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
614 |
125 | 615 /** |
616 * Removes the listener from the collection of listeners who will | |
617 * be notified when a progress is made during the loading of the current | |
618 * URL or when the loading of the current URL has been completed. | |
619 * | |
620 * @param listener the listener which should no longer be notified | |
621 * | |
622 * @exception IllegalArgumentException <ul> | |
623 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
624 * </ul> | |
625 * | |
626 * @exception DWTException <ul> | |
627 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
628 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
629 * </ul> | |
630 * | |
631 * @since 3.0 | |
632 */ | |
633 public void removeProgressListener (ProgressListener listener) { | |
634 checkWidget(); | |
635 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
636 webBrowser.removeProgressListener (listener); | |
637 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
638 |
125 | 639 /** |
640 * Removes the listener from the collection of listeners who will | |
641 * be notified when the status text is changed. | |
642 * | |
643 * @param listener the listener which should no longer be notified | |
644 * | |
645 * @exception IllegalArgumentException <ul> | |
646 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
647 * </ul> | |
648 * | |
649 * @exception DWTException <ul> | |
650 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
651 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
652 * </ul> | |
653 * | |
654 * @since 3.0 | |
655 */ | |
656 public void removeStatusTextListener (StatusTextListener listener) { | |
657 checkWidget(); | |
658 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
659 webBrowser.removeStatusTextListener (listener); | |
660 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
661 |
125 | 662 /** |
663 * Removes the listener from the collection of listeners who will | |
664 * be notified when the title of the current document is available | |
665 * or has changed. | |
666 * | |
667 * @param listener the listener which should no longer be notified | |
668 * | |
669 * @exception IllegalArgumentException <ul> | |
670 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
671 * </ul> | |
672 * | |
673 * @exception DWTException <ul> | |
674 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
675 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
676 * </ul> | |
677 * | |
678 * @since 3.0 | |
679 */ | |
680 public void removeTitleListener (TitleListener listener) { | |
681 checkWidget(); | |
682 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
683 webBrowser.removeTitleListener (listener); | |
684 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
685 |
125 | 686 /** |
687 * Removes the listener from the collection of listeners who will | |
688 * be notified when a window hosting the receiver needs to be displayed | |
689 * or hidden. | |
690 * | |
691 * @param listener the listener which should no longer be notified | |
692 * | |
693 * @exception IllegalArgumentException <ul> | |
694 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
695 * </ul> | |
696 * | |
697 * @exception DWTException <ul> | |
698 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
699 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
700 * </ul> | |
701 * | |
702 * @since 3.0 | |
703 */ | |
704 public void removeVisibilityWindowListener (VisibilityWindowListener listener) { | |
705 checkWidget(); | |
706 if (listener is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
707 webBrowser.removeVisibilityWindowListener (listener); | |
708 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
709 |
125 | 710 /** |
711 * Renders HTML. | |
712 * | |
713 * <p> | |
714 * The html parameter is Unicode encoded since it is a java <code>String</code>. | |
715 * As a result, the HTML meta tag charset should not be set. The charset is implied | |
716 * by the <code>String</code> itself. | |
717 * | |
718 * @param html the HTML content to be rendered | |
719 * | |
720 * @return true if the operation was successful and false otherwise. | |
721 * | |
722 * @exception IllegalArgumentException <ul> | |
723 * <li>ERROR_NULL_ARGUMENT - if the html is null</li> | |
724 * </ul> | |
725 * | |
726 * @exception DWTException <ul> | |
727 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
728 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
729 * </ul> | |
730 * | |
731 * @see #setUrl | |
732 * | |
733 * @since 3.0 | |
734 */ | |
735 public bool setText (String html) { | |
736 checkWidget(); | |
737 if (html is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
738 return webBrowser.setText (html); | |
739 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
740 |
125 | 741 /** |
742 * Loads a URL. | |
743 * | |
744 * @param url the URL to be loaded | |
745 * | |
746 * @return true if the operation was successful and false otherwise. | |
747 * | |
748 * @exception IllegalArgumentException <ul> | |
749 * <li>ERROR_NULL_ARGUMENT - if the url is null</li> | |
750 * </ul> | |
751 * | |
752 * @exception DWTException <ul> | |
753 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
754 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
755 * </ul> | |
756 * | |
757 * @see #getUrl | |
758 * | |
759 * @since 3.0 | |
760 */ | |
761 public bool setUrl (String url) { | |
762 checkWidget(); | |
763 if (url is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
764 return webBrowser.setUrl (url); | |
765 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
766 |
125 | 767 /** |
768 * Stop any loading and rendering activity. | |
769 * | |
770 * @exception DWTException <ul> | |
771 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> | |
772 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> | |
773 * </ul> | |
774 * | |
775 * @since 3.0 | |
776 */ | |
777 public void stop () { | |
778 checkWidget(); | |
779 webBrowser.stop (); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
780 } |
125 | 781 } |