Mercurial > projects > dwt-mac
comparison dwt/browser/WebBrowser.d @ 0:380af2bdd8e5
Upload of whole dwt tree
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sat, 09 Aug 2008 17:00:02 +0200 |
parents | |
children | f565d3a95c0a |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:380af2bdd8e5 |
---|---|
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 * | |
11 * Port to the D Programming language: | |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | |
13 *******************************************************************************/ | |
14 module dwt.browser.WebBrowser; | |
15 | |
16 import dwt.DWT; | |
17 import dwt.browser.Browser; | |
18 import dwt.browser.CloseWindowListener; | |
19 import dwt.browser.LocationListener; | |
20 import dwt.browser.OpenWindowListener; | |
21 import dwt.browser.ProgressListener; | |
22 import dwt.browser.StatusTextListener; | |
23 import dwt.browser.TitleListener; | |
24 import dwt.browser.VisibilityWindowListener; | |
25 import dwt.dwthelper.utils; | |
26 import dwt.dwthelper.Runnable; | |
27 import dwt.dwthelper.System; | |
28 import dwt.widgets.Composite; | |
29 | |
30 abstract class WebBrowser { | |
31 Browser browser; | |
32 CloseWindowListener[] closeWindowListeners = new CloseWindowListener[0]; | |
33 LocationListener[] locationListeners = new LocationListener[0]; | |
34 OpenWindowListener[] openWindowListeners = new OpenWindowListener[0]; | |
35 ProgressListener[] progressListeners = new ProgressListener[0]; | |
36 StatusTextListener[] statusTextListeners = new StatusTextListener[0]; | |
37 TitleListener[] titleListeners = new TitleListener[0]; | |
38 VisibilityWindowListener[] visibilityWindowListeners = new VisibilityWindowListener[0]; | |
39 | |
40 static Runnable MozillaClearSessions; | |
41 static Runnable NativeClearSessions; | |
42 | |
43 /* Key Mappings */ | |
44 static const int[][] KeyTable = [ | |
45 /* Keyboard and Mouse Masks */ | |
46 [18, DWT.ALT], | |
47 [16, DWT.SHIFT], | |
48 [17, DWT.CONTROL], | |
49 [224, DWT.COMMAND], | |
50 | |
51 /* Literal Keys */ | |
52 [65, 'a'], | |
53 [66, 'b'], | |
54 [67, 'c'], | |
55 [68, 'd'], | |
56 [69, 'e'], | |
57 [70, 'f'], | |
58 [71, 'g'], | |
59 [72, 'h'], | |
60 [73, 'i'], | |
61 [74, 'j'], | |
62 [75, 'k'], | |
63 [76, 'l'], | |
64 [77, 'm'], | |
65 [78, 'n'], | |
66 [79, 'o'], | |
67 [80, 'p'], | |
68 [81, 'q'], | |
69 [82, 'r'], | |
70 [83, 's'], | |
71 [84, 't'], | |
72 [85, 'u'], | |
73 [86, 'v'], | |
74 [87, 'w'], | |
75 [88, 'x'], | |
76 [89, 'y'], | |
77 [90, 'z'], | |
78 [48, '0'], | |
79 [49, '1'], | |
80 [50, '2'], | |
81 [51, '3'], | |
82 [52, '4'], | |
83 [53, '5'], | |
84 [54, '6'], | |
85 [55, '7'], | |
86 [56, '8'], | |
87 [57, '9'], | |
88 [32, ' '], | |
89 [59, ';'], | |
90 [61, '='], | |
91 [188, ','], | |
92 [190, '.'], | |
93 [191, '/'], | |
94 [219, '['], | |
95 [221, ']'], | |
96 [222, '\''], | |
97 [192, '`'], | |
98 [220, '\\'], | |
99 [108, '|'], | |
100 | |
101 /* Non-Numeric Keypad Keys */ | |
102 [37, DWT.ARROW_LEFT], | |
103 [39, DWT.ARROW_RIGHT], | |
104 [38, DWT.ARROW_UP], | |
105 [40, DWT.ARROW_DOWN], | |
106 [45, DWT.INSERT], | |
107 [36, DWT.HOME], | |
108 [35, DWT.END], | |
109 [46, DWT.DEL], | |
110 [33, DWT.PAGE_UP], | |
111 [34, DWT.PAGE_DOWN], | |
112 | |
113 /* Virtual and Ascii Keys */ | |
114 [8, DWT.BS], | |
115 [13, DWT.CR], | |
116 [9, DWT.TAB], | |
117 [27, DWT.ESC], | |
118 [12, DWT.DEL], | |
119 | |
120 /* Functions Keys */ | |
121 [112, DWT.F1], | |
122 [113, DWT.F2], | |
123 [114, DWT.F3], | |
124 [115, DWT.F4], | |
125 [116, DWT.F5], | |
126 [117, DWT.F6], | |
127 [118, DWT.F7], | |
128 [119, DWT.F8], | |
129 [120, DWT.F9], | |
130 [121, DWT.F10], | |
131 [122, DWT.F11], | |
132 [123, DWT.F12], | |
133 [124, DWT.F13], | |
134 [125, DWT.F14], | |
135 [126, DWT.F15], | |
136 [127, 0], | |
137 [128, 0], | |
138 [129, 0], | |
139 [130, 0], | |
140 [131, 0], | |
141 [132, 0], | |
142 [133, 0], | |
143 [134, 0], | |
144 [135, 0], | |
145 | |
146 /* Numeric Keypad Keys */ | |
147 [96, DWT.KEYPAD_0], | |
148 [97, DWT.KEYPAD_1], | |
149 [98, DWT.KEYPAD_2], | |
150 [99, DWT.KEYPAD_3], | |
151 [100, DWT.KEYPAD_4], | |
152 [101, DWT.KEYPAD_5], | |
153 [102, DWT.KEYPAD_6], | |
154 [103, DWT.KEYPAD_7], | |
155 [104, DWT.KEYPAD_8], | |
156 [105, DWT.KEYPAD_9], | |
157 [14, DWT.KEYPAD_CR], | |
158 [107, DWT.KEYPAD_ADD], | |
159 [109, DWT.KEYPAD_SUBTRACT], | |
160 [106, DWT.KEYPAD_MULTIPLY], | |
161 [111, DWT.KEYPAD_DIVIDE], | |
162 [110, DWT.KEYPAD_DECIMAL], | |
163 | |
164 /* Other keys */ | |
165 [20, DWT.CAPS_LOCK], | |
166 [144, DWT.NUM_LOCK], | |
167 [145, DWT.SCROLL_LOCK], | |
168 [44, DWT.PRINT_SCREEN], | |
169 [6, DWT.HELP], | |
170 [19, DWT.PAUSE], | |
171 [3, DWT.BREAK], | |
172 | |
173 /* Safari-specific */ | |
174 [186, ';'], | |
175 [187, '='], | |
176 [189, '-'] | |
177 , ]; | |
178 | |
179 public void addCloseWindowListener (CloseWindowListener listener) { | |
180 CloseWindowListener[] newCloseWindowListeners = new CloseWindowListener[closeWindowListeners.length + 1]; | |
181 System.arraycopy(closeWindowListeners, 0, newCloseWindowListeners, 0, closeWindowListeners.length); | |
182 closeWindowListeners = newCloseWindowListeners; | |
183 closeWindowListeners[closeWindowListeners.length - 1] = listener; | |
184 } | |
185 | |
186 public void addLocationListener (LocationListener listener) { | |
187 LocationListener[] newLocationListeners = new LocationListener[locationListeners.length + 1]; | |
188 System.arraycopy(locationListeners, 0, newLocationListeners, 0, locationListeners.length); | |
189 locationListeners = newLocationListeners; | |
190 locationListeners[locationListeners.length - 1] = listener; | |
191 } | |
192 | |
193 public void addOpenWindowListener (OpenWindowListener listener) { | |
194 OpenWindowListener[] newOpenWindowListeners = new OpenWindowListener[openWindowListeners.length + 1]; | |
195 System.arraycopy(openWindowListeners, 0, newOpenWindowListeners, 0, openWindowListeners.length); | |
196 openWindowListeners = newOpenWindowListeners; | |
197 openWindowListeners[openWindowListeners.length - 1] = listener; | |
198 } | |
199 | |
200 public void addProgressListener (ProgressListener listener) { | |
201 ProgressListener[] newProgressListeners = new ProgressListener[progressListeners.length + 1]; | |
202 System.arraycopy(progressListeners, 0, newProgressListeners, 0, progressListeners.length); | |
203 progressListeners = newProgressListeners; | |
204 progressListeners[progressListeners.length - 1] = listener; | |
205 } | |
206 | |
207 public void addStatusTextListener (StatusTextListener listener) { | |
208 StatusTextListener[] newStatusTextListeners = new StatusTextListener[statusTextListeners.length + 1]; | |
209 System.arraycopy(statusTextListeners, 0, newStatusTextListeners, 0, statusTextListeners.length); | |
210 statusTextListeners = newStatusTextListeners; | |
211 statusTextListeners[statusTextListeners.length - 1] = listener; | |
212 } | |
213 | |
214 public void addTitleListener (TitleListener listener) { | |
215 TitleListener[] newTitleListeners = new TitleListener[titleListeners.length + 1]; | |
216 System.arraycopy(titleListeners, 0, newTitleListeners, 0, titleListeners.length); | |
217 titleListeners = newTitleListeners; | |
218 titleListeners[titleListeners.length - 1] = listener; | |
219 } | |
220 | |
221 public void addVisibilityWindowListener (VisibilityWindowListener listener) { | |
222 VisibilityWindowListener[] newVisibilityWindowListeners = new VisibilityWindowListener[visibilityWindowListeners.length + 1]; | |
223 System.arraycopy(visibilityWindowListeners, 0, newVisibilityWindowListeners, 0, visibilityWindowListeners.length); | |
224 visibilityWindowListeners = newVisibilityWindowListeners; | |
225 visibilityWindowListeners[visibilityWindowListeners.length - 1] = listener; | |
226 } | |
227 | |
228 public abstract bool back (); | |
229 | |
230 public static void clearSessions () { | |
231 if (NativeClearSessions !is null) | |
232 NativeClearSessions.run(); | |
233 if (MozillaClearSessions !is null) | |
234 MozillaClearSessions.run(); | |
235 } | |
236 | |
237 public abstract void create (Composite parent, int style); | |
238 | |
239 public abstract bool execute (String script); | |
240 | |
241 public abstract bool forward (); | |
242 | |
243 public abstract String getText (); | |
244 | |
245 public abstract String getUrl (); | |
246 | |
247 public Object getWebBrowser () { | |
248 return null; | |
249 } | |
250 | |
251 public abstract bool isBackEnabled (); | |
252 | |
253 public bool isFocusControl () { | |
254 return false; | |
255 } | |
256 | |
257 public abstract bool isForwardEnabled (); | |
258 | |
259 public abstract void refresh (); | |
260 | |
261 public void removeCloseWindowListener (CloseWindowListener listener) { | |
262 if (closeWindowListeners.length is 0) | |
263 return; | |
264 int index = -1; | |
265 for (int i = 0; i < closeWindowListeners.length; i++) { | |
266 if (listener is closeWindowListeners[i]) { | |
267 index = i; | |
268 break; | |
269 } | |
270 } | |
271 if (index is -1) | |
272 return; | |
273 if (closeWindowListeners.length is 1) { | |
274 closeWindowListeners = new CloseWindowListener[0]; | |
275 return; | |
276 } | |
277 CloseWindowListener[] newCloseWindowListeners = new CloseWindowListener[closeWindowListeners.length - 1]; | |
278 System.arraycopy(closeWindowListeners, 0, newCloseWindowListeners, 0, index); | |
279 System.arraycopy(closeWindowListeners, index + 1, newCloseWindowListeners, index, closeWindowListeners.length - index - 1); | |
280 closeWindowListeners = newCloseWindowListeners; | |
281 } | |
282 | |
283 public void removeLocationListener (LocationListener listener) { | |
284 if (locationListeners.length is 0) | |
285 return; | |
286 int index = -1; | |
287 for (int i = 0; i < locationListeners.length; i++) { | |
288 if (listener is locationListeners[i]) { | |
289 index = i; | |
290 break; | |
291 } | |
292 } | |
293 if (index is -1) | |
294 return; | |
295 if (locationListeners.length is 1) { | |
296 locationListeners = new LocationListener[0]; | |
297 return; | |
298 } | |
299 LocationListener[] newLocationListeners = new LocationListener[locationListeners.length - 1]; | |
300 System.arraycopy(locationListeners, 0, newLocationListeners, 0, index); | |
301 System.arraycopy(locationListeners, index + 1, newLocationListeners, index, locationListeners.length - index - 1); | |
302 locationListeners = newLocationListeners; | |
303 } | |
304 | |
305 public void removeOpenWindowListener (OpenWindowListener listener) { | |
306 if (openWindowListeners.length is 0) | |
307 return; | |
308 int index = -1; | |
309 for (int i = 0; i < openWindowListeners.length; i++) { | |
310 if (listener is openWindowListeners[i]) { | |
311 index = i; | |
312 break; | |
313 } | |
314 } | |
315 if (index is -1) | |
316 return; | |
317 if (openWindowListeners.length is 1) { | |
318 openWindowListeners = new OpenWindowListener[0]; | |
319 return; | |
320 } | |
321 OpenWindowListener[] newOpenWindowListeners = new OpenWindowListener[openWindowListeners.length - 1]; | |
322 System.arraycopy(openWindowListeners, 0, newOpenWindowListeners, 0, index); | |
323 System.arraycopy(openWindowListeners, index + 1, newOpenWindowListeners, index, openWindowListeners.length - index - 1); | |
324 openWindowListeners = newOpenWindowListeners; | |
325 } | |
326 | |
327 public void removeProgressListener (ProgressListener listener) { | |
328 if (progressListeners.length is 0) | |
329 return; | |
330 int index = -1; | |
331 for (int i = 0; i < progressListeners.length; i++) { | |
332 if (listener is progressListeners[i]) { | |
333 index = i; | |
334 break; | |
335 } | |
336 } | |
337 if (index is -1) | |
338 return; | |
339 if (progressListeners.length is 1) { | |
340 progressListeners = new ProgressListener[0]; | |
341 return; | |
342 } | |
343 ProgressListener[] newProgressListeners = new ProgressListener[progressListeners.length - 1]; | |
344 System.arraycopy(progressListeners, 0, newProgressListeners, 0, index); | |
345 System.arraycopy(progressListeners, index + 1, newProgressListeners, index, progressListeners.length - index - 1); | |
346 progressListeners = newProgressListeners; | |
347 } | |
348 | |
349 public void removeStatusTextListener (StatusTextListener listener) { | |
350 if (statusTextListeners.length is 0) | |
351 return; | |
352 int index = -1; | |
353 for (int i = 0; i < statusTextListeners.length; i++) { | |
354 if (listener is statusTextListeners[i]) { | |
355 index = i; | |
356 break; | |
357 } | |
358 } | |
359 if (index is -1) | |
360 return; | |
361 if (statusTextListeners.length is 1) { | |
362 statusTextListeners = new StatusTextListener[0]; | |
363 return; | |
364 } | |
365 StatusTextListener[] newStatusTextListeners = new StatusTextListener[statusTextListeners.length - 1]; | |
366 System.arraycopy(statusTextListeners, 0, newStatusTextListeners, 0, index); | |
367 System.arraycopy(statusTextListeners, index + 1, newStatusTextListeners, index, statusTextListeners.length - index - 1); | |
368 statusTextListeners = newStatusTextListeners; | |
369 } | |
370 | |
371 public void removeTitleListener (TitleListener listener) { | |
372 if (titleListeners.length is 0) | |
373 return; | |
374 int index = -1; | |
375 for (int i = 0; i < titleListeners.length; i++) { | |
376 if (listener is titleListeners[i]) { | |
377 index = i; | |
378 break; | |
379 } | |
380 } | |
381 if (index is -1) | |
382 return; | |
383 if (titleListeners.length is 1) { | |
384 titleListeners = new TitleListener[0]; | |
385 return; | |
386 } | |
387 TitleListener[] newTitleListeners = new TitleListener[titleListeners.length - 1]; | |
388 System.arraycopy(titleListeners, 0, newTitleListeners, 0, index); | |
389 System.arraycopy(titleListeners, index + 1, newTitleListeners, index, titleListeners.length - index - 1); | |
390 titleListeners = newTitleListeners; | |
391 } | |
392 | |
393 public void removeVisibilityWindowListener (VisibilityWindowListener listener) { | |
394 if (visibilityWindowListeners.length is 0) | |
395 return; | |
396 int index = -1; | |
397 for (int i = 0; i < visibilityWindowListeners.length; i++) { | |
398 if (listener is visibilityWindowListeners[i]) { | |
399 index = i; | |
400 break; | |
401 } | |
402 } | |
403 if (index is -1) | |
404 return; | |
405 if (visibilityWindowListeners.length is 1) { | |
406 visibilityWindowListeners = new VisibilityWindowListener[0]; | |
407 return; | |
408 } | |
409 VisibilityWindowListener[] newVisibilityWindowListeners = new VisibilityWindowListener[visibilityWindowListeners.length - 1]; | |
410 System.arraycopy(visibilityWindowListeners, 0, newVisibilityWindowListeners, 0, index); | |
411 System.arraycopy(visibilityWindowListeners, index + 1, newVisibilityWindowListeners, index, visibilityWindowListeners.length - index - 1); | |
412 visibilityWindowListeners = newVisibilityWindowListeners; | |
413 } | |
414 | |
415 public void setBrowser (Browser browser) { | |
416 this.browser = browser; | |
417 } | |
418 | |
419 public abstract bool setText (String html); | |
420 | |
421 public abstract bool setUrl (String url); | |
422 | |
423 public abstract void stop (); | |
424 | |
425 int translateKey (int key) { | |
426 for (int i = 0; i < KeyTable.length; i++) { | |
427 if (KeyTable[i][0] is key) | |
428 return KeyTable[i][1]; | |
429 } | |
430 return 0; | |
431 } | |
432 } |