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