Mercurial > projects > dwt-mac
comparison dwt/browser/Safari.d @ 126:38807a925e24
Fixed compile errors, support for SWT language files
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Fri, 16 Jan 2009 23:35:40 +0100 |
parents | 5583f8eeee6c |
children |
comparison
equal
deleted
inserted
replaced
125:5583f8eeee6c | 126:38807a925e24 |
---|---|
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | |
11 * Port to the D programming language: | |
12 * Jacob Carlborg <doob@me.com> | |
10 *******************************************************************************/ | 13 *******************************************************************************/ |
11 module dwt.browser.Safari; | 14 module dwt.browser.Safari; |
12 | 15 |
13 import dwt.dwthelper.utils; | 16 import dwt.dwthelper.utils; |
14 | 17 |
15 import dwt.DWT; | 18 import dwt.DWT; |
16 import dwt.graphics.Point; | 19 import dwt.graphics.Point; |
17 import dwt.graphics.Rectangle; | 20 import dwt.graphics.Rectangle; |
18 import dwt.internal.C; | 21 import dwt.internal.C; |
19 import dwt.internal.Callback; | |
20 import dwt.internal.Compatibility; | 22 import dwt.internal.Compatibility; |
21 import dwt.internal.cocoa.DOMDocument; | 23 import dwt.internal.cocoa.DOMDocument; |
22 import dwt.internal.cocoa.DOMKeyboardEvent; | 24 import dwt.internal.cocoa.DOMKeyboardEvent; |
23 import dwt.internal.cocoa.DOMMouseEvent; | 25 import dwt.internal.cocoa.DOMMouseEvent; |
24 import dwt.internal.cocoa.DOMWheelEvent; | 26 import dwt.internal.cocoa.DOMWheelEvent; |
55 import dwt.widgets.Menu; | 57 import dwt.widgets.Menu; |
56 import dwt.widgets.MessageBox; | 58 import dwt.widgets.MessageBox; |
57 import dwt.widgets.Shell; | 59 import dwt.widgets.Shell; |
58 import dwt.widgets.Widget; | 60 import dwt.widgets.Widget; |
59 | 61 |
60 class Safari extends WebBrowser { | 62 import dwt.browser.Browser; |
63 import dwt.browser.LocationEvent; | |
64 import dwt.browser.ProgressEvent; | |
65 import dwt.browser.ProgressListener; | |
66 import dwt.browser.StatusTextEvent; | |
67 import dwt.browser.TitleEvent; | |
68 import dwt.browser.TitleListener; | |
69 import dwt.browser.WebBrowser; | |
70 import dwt.browser.WindowEvent; | |
71 import Carbon = dwt.internal.c.Carbon; | |
72 import dwt.internal.objc.cocoa.Cocoa; | |
73 import objc = dwt.internal.objc.runtime; | |
74 | |
75 class Safari : WebBrowser { | |
61 WebView webView; | 76 WebView webView; |
62 SWTWebViewDelegate delegate; | 77 SWTWebViewDelegate delegate_; |
63 bool changingLocation; | 78 bool changingLocation; |
64 String lastHoveredLinkURL; | 79 String lastHoveredLinkURL; |
65 String html; | 80 String html; |
66 int /*long*/ identifier; | 81 objc.id identifier; |
67 int resourceCount; | 82 int resourceCount; |
68 String url = ""; //$NON-NLS-1$ | 83 String url = ""; //$NON-NLS-1$ |
69 Point location; | 84 Point location; |
70 Point size; | 85 Point size; |
71 bool statusBar = true, toolBar = true, ignoreDispose; | 86 bool statusBar = true, toolBar = true, ignoreDispose; |
72 int lastMouseMoveX, lastMouseMoveY; | 87 int lastMouseMoveX, lastMouseMoveY; |
73 //TEMPORARY CODE | 88 //TEMPORARY CODE |
74 // bool doit; | 89 // bool doit; |
75 | 90 |
76 static bool Initialized; | 91 static bool Initialized; |
77 // the following Callbacks are never freed | 92 |
78 static Callback Callback3, Callback4, Callback5, Callback6, Callback7; | 93 static const int MIN_SIZE = 16; |
79 | 94 static const int MAX_PROGRESS = 100; |
80 static final int MIN_SIZE = 16; | 95 static const String WebElementLinkURLKey = "WebElementLinkURL"; //$NON-NLS-1$ |
81 static final int MAX_PROGRESS = 100; | 96 static const String AGENT_STRING = "Safari/unknown"; //$NON-NLS-1$ |
82 static final String WebElementLinkURLKey = "WebElementLinkURL"; //$NON-NLS-1$ | 97 static const String URI_FROMMEMORY = "file:///"; //$NON-NLS-1$ |
83 static final String AGENT_STRING = "Safari/unknown"; //$NON-NLS-1$ | 98 static const String PROTOCOL_FILE = "file://"; //$NON-NLS-1$ |
84 static final String URI_FROMMEMORY = "file:///"; //$NON-NLS-1$ | 99 static const String PROTOCOL_HTTP = "http://"; //$NON-NLS-1$ |
85 static final String PROTOCOL_FILE = "file://"; //$NON-NLS-1$ | 100 static const String ABOUT_BLANK = "about:blank"; //$NON-NLS-1$ |
86 static final String PROTOCOL_HTTP = "http://"; //$NON-NLS-1$ | 101 static const String ADD_WIDGET_KEY = "dwt.internal.addWidget"; //$NON-NLS-1$ |
87 static final String ABOUT_BLANK = "about:blank"; //$NON-NLS-1$ | 102 static const String SAFARI_EVENTS_FIX_KEY = "dwt.internal.safariEventsFix"; //$NON-NLS-1$ |
88 static final String ADD_WIDGET_KEY = "dwt.internal.addWidget"; //$NON-NLS-1$ | 103 static const String DWT_OBJECT = "DWT_OBJECT"; //$NON-NLS-1$ |
89 static final String SAFARI_EVENTS_FIX_KEY = "dwt.internal.safariEventsFix"; //$NON-NLS-1$ | |
90 static final String DWT_OBJECT = "DWT_OBJECT"; //$NON-NLS-1$ | |
91 | 104 |
92 /* event strings */ | 105 /* event strings */ |
93 static final String DOMEVENT_KEYUP = "keyup"; //$NON-NLS-1$ | 106 static const String DOMEVENT_KEYUP = "keyup"; //$NON-NLS-1$ |
94 static final String DOMEVENT_KEYDOWN = "keydown"; //$NON-NLS-1$ | 107 static const String DOMEVENT_KEYDOWN = "keydown"; //$NON-NLS-1$ |
95 static final String DOMEVENT_MOUSEDOWN = "mousedown"; //$NON-NLS-1$ | 108 static const String DOMEVENT_MOUSEDOWN = "mousedown"; //$NON-NLS-1$ |
96 static final String DOMEVENT_MOUSEUP = "mouseup"; //$NON-NLS-1$ | 109 static const String DOMEVENT_MOUSEUP = "mouseup"; //$NON-NLS-1$ |
97 static final String DOMEVENT_MOUSEMOVE = "mousemove"; //$NON-NLS-1$ | 110 static const String DOMEVENT_MOUSEMOVE = "mousemove"; //$NON-NLS-1$ |
98 static final String DOMEVENT_MOUSEWHEEL = "mousewheel"; //$NON-NLS-1$ | 111 static const String DOMEVENT_MOUSEWHEEL = "mousewheel"; //$NON-NLS-1$ |
99 | 112 |
100 static { | 113 static this () { |
101 NativeClearSessions = new Runnable() { | 114 NativeClearSessions = new class () Runnable { |
102 public void run() { | 115 public void run() { |
103 NSHTTPCookieStorage storage = NSHTTPCookieStorage.sharedHTTPCookieStorage(); | 116 NSHTTPCookieStorage storage = NSHTTPCookieStorage.sharedHTTPCookieStorage(); |
104 NSArray cookies = storage.cookies(); | 117 NSArray cookies = storage.cookies(); |
105 int /*long*/ count = cookies.count(); | 118 NSUInteger count = cookies.count(); |
106 for (int i = 0; i < count; i++) { | 119 for (NSUInteger i = 0; i < count; i++) { |
107 NSHTTPCookie cookie = new NSHTTPCookie(cookies.objectAtIndex(i)); | 120 NSHTTPCookie cookie = new NSHTTPCookie(cookies.objectAtIndex(i)); |
108 if (cookie.isSessionOnly()) { | 121 if (cookie.isSessionOnly()) { |
109 storage.deleteCookie(cookie); | 122 storage.deleteCookie(cookie); |
110 } | 123 } |
111 } | 124 } |
113 }; | 126 }; |
114 } | 127 } |
115 | 128 |
116 public void create (Composite parent, int style) { | 129 public void create (Composite parent, int style) { |
117 String className = "SWTWebViewDelegate"; //$NON-NLS-1$ | 130 String className = "SWTWebViewDelegate"; //$NON-NLS-1$ |
118 if (OS.objc_lookUpClass(className) is 0) { | 131 if (OS.objc_lookUpClass(className) is null) { |
119 Class safariClass = this.getClass(); | 132 Class safariClass = this.classinfo; |
120 Callback3 = new Callback(safariClass, "browserProc", 3); //$NON-NLS-1$ | 133 objc.IMP proc3;// = cast(objc.IMP) &browserProc3; |
121 int /*long*/ proc3 = Callback3.getAddress(); | 134 objc.IMP proc4;// = cast(objc.IMP) &browserProc4; |
122 if (proc3 is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); | 135 objc.IMP proc5;// = cast(objc.IMP) &browserProc5; |
123 Callback4 = new Callback(safariClass, "browserProc", 4); //$NON-NLS-1$ | 136 objc.IMP proc6;// = cast(objc.IMP) &browserProc6; |
124 int /*long*/ proc4 = Callback4.getAddress(); | 137 objc.IMP proc7;// = cast(objc.IMP) &browserProc7; |
125 if (proc4 is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); | 138 objc.IMP setFrameProc = OS.webView_setFrame_CALLBACK(proc4); |
126 Callback5 = new Callback(safariClass, "browserProc", 5); //$NON-NLS-1$ | |
127 int /*long*/ proc5 = Callback5.getAddress(); | |
128 if (proc5 is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); | |
129 Callback6 = new Callback(safariClass, "browserProc", 6); //$NON-NLS-1$ | |
130 int /*long*/ proc6 = Callback6.getAddress(); | |
131 if (proc6 is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); | |
132 Callback7 = new Callback(safariClass, "browserProc", 7); //$NON-NLS-1$ | |
133 int /*long*/ proc7 = Callback7.getAddress(); | |
134 if (proc7 is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); | |
135 int /*long*/ setFrameProc = OS.webView_setFrame_CALLBACK(proc4); | |
136 if (setFrameProc is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); | |
137 | 139 |
138 String types = "*"; //$NON-NLS-1$ | 140 String types = "*"; //$NON-NLS-1$ |
139 int size = C.PTR_SIZEOF, align = C.PTR_SIZEOF is 4 ? 2 : 3; | 141 size_t size = C.PTR_SIZEOF, align_ = C.PTR_SIZEOF is 4 ? 2 : 3; |
140 | 142 |
141 int /*long*/ cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0); | 143 objc.Class cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSObject, className, 0); |
142 OS.class_addIvar(cls, DWT_OBJECT, size, (byte)align, types); | 144 OS.class_addIvar(cls, DWT_OBJECT, size, cast(byte)align_, types); |
143 OS.class_addMethod(cls, OS.sel_webView_didChangeLocationWithinPageForFrame_, proc4, "@:@@"); //$NON-NLS-1$ | 145 OS.class_addMethod(cls, OS.sel_webView_didChangeLocationWithinPageForFrame_, proc4, "@:@@"); //$NON-NLS-1$ |
144 OS.class_addMethod(cls, OS.sel_webView_didFailProvisionalLoadWithError_forFrame_, proc5, "@:@@@"); //$NON-NLS-1$ | 146 OS.class_addMethod(cls, OS.sel_webView_didFailProvisionalLoadWithError_forFrame_, proc5, "@:@@@"); //$NON-NLS-1$ |
145 OS.class_addMethod(cls, OS.sel_webView_didFinishLoadForFrame_, proc4, "@:@@"); //$NON-NLS-1$ | 147 OS.class_addMethod(cls, OS.sel_webView_didFinishLoadForFrame_, proc4, "@:@@"); //$NON-NLS-1$ |
146 OS.class_addMethod(cls, OS.sel_webView_didReceiveTitle_forFrame_, proc5, "@:@@@"); //$NON-NLS-1$ | 148 OS.class_addMethod(cls, OS.sel_webView_didReceiveTitle_forFrame_, proc5, "@:@@@"); //$NON-NLS-1$ |
147 OS.class_addMethod(cls, OS.sel_webView_didStartProvisionalLoadForFrame_, proc4, "@:@@"); //$NON-NLS-1$ | 149 OS.class_addMethod(cls, OS.sel_webView_didStartProvisionalLoadForFrame_, proc4, "@:@@"); //$NON-NLS-1$ |
178 | 180 |
179 /* | 181 /* |
180 * Override the default event mechanism to not send key events so | 182 * Override the default event mechanism to not send key events so |
181 * that the browser can send them by listening to the DOM instead. | 183 * that the browser can send them by listening to the DOM instead. |
182 */ | 184 */ |
183 browser.setData(SAFARI_EVENTS_FIX_KEY); | 185 browser.setData(new ArrayWrapperString(SAFARI_EVENTS_FIX_KEY)); |
184 | 186 |
185 WebView webView = (WebView)new WebView().alloc(); | 187 WebView webView = cast(WebView)(new WebView()).alloc(); |
186 if (webView is null) DWT.error(DWT.ERROR_NO_HANDLES); | 188 if (webView is null) DWT.error(DWT.ERROR_NO_HANDLES); |
187 webView.initWithFrame(browser.view.frame(), null, null); | 189 webView.initWithFrame(browser.view.frame(), null, null); |
188 webView.setAutoresizingMask(OS.NSViewWidthSizable | OS.NSViewHeightSizable); | 190 webView.setAutoresizingMask(OS.NSViewWidthSizable | OS.NSViewHeightSizable); |
189 final SWTWebViewDelegate delegate = (SWTWebViewDelegate)new SWTWebViewDelegate().alloc().init(); | 191 final SWTWebViewDelegate delegate_ = cast(SWTWebViewDelegate)(new SWTWebViewDelegate()).alloc().init(); |
190 Display display = browser.getDisplay(); | 192 Display display = browser.getDisplay(); |
191 display.setData(ADD_WIDGET_KEY, new Object[] {delegate, browser}); | 193 display.setData(ADD_WIDGET_KEY, new ArrayWrapperObject([cast(Object) delegate_, browser])); |
192 this.delegate = delegate; | 194 this.delegate_ = delegate_; |
193 this.webView = webView; | 195 this.webView = webView; |
194 browser.view.addSubview(webView); | 196 browser.view.addSubview(webView); |
195 | 197 |
196 final NSNotificationCenter notificationCenter = NSNotificationCenter.defaultCenter(); | 198 final NSNotificationCenter notificationCenter = NSNotificationCenter.defaultCenter(); |
197 | 199 |
198 Listener listener = new Listener() { | 200 Listener listener = new class () Listener { |
199 public void handleEvent(Event e) { | 201 public void handleEvent(Event e) { |
200 switch (e.type) { | 202 switch (e.type) { |
201 case DWT.FocusIn: | 203 case DWT.FocusIn: |
202 Safari.this.webView.window().makeFirstResponder(Safari.this.webView); | 204 this.outer.webView.window().makeFirstResponder(this.outer.webView); |
203 break; | 205 break; |
204 case DWT.Dispose: { | 206 case DWT.Dispose: { |
205 /* make this handler run after other dispose listeners */ | 207 /* make this handler run after other dispose listeners */ |
206 if (ignoreDispose) { | 208 if (ignoreDispose) { |
207 ignoreDispose = false; | 209 ignoreDispose = false; |
209 } | 211 } |
210 ignoreDispose = true; | 212 ignoreDispose = true; |
211 browser.notifyListeners (e.type, e); | 213 browser.notifyListeners (e.type, e); |
212 e.type = DWT.NONE; | 214 e.type = DWT.NONE; |
213 | 215 |
214 e.display.setData(ADD_WIDGET_KEY, new Object[] {delegate, null}); | 216 e.display.setData(ADD_WIDGET_KEY, new ArrayWrapperObject([delegate_, null])); |
215 | 217 |
216 Safari.this.webView.setFrameLoadDelegate(null); | 218 this.outer.webView.setFrameLoadDelegate(null); |
217 Safari.this.webView.setResourceLoadDelegate(null); | 219 this.outer.webView.setResourceLoadDelegate(null); |
218 Safari.this.webView.setUIDelegate(null); | 220 this.outer.webView.setUIDelegate(null); |
219 Safari.this.webView.setPolicyDelegate(null); | 221 this.outer.webView.setPolicyDelegate(null); |
220 Safari.this.webView.setDownloadDelegate(null); | 222 this.outer.webView.setDownloadDelegate(null); |
221 notificationCenter.removeObserver(delegate); | 223 notificationCenter.removeObserver(delegate_); |
222 | 224 |
223 Safari.this.webView.release(); | 225 this.outer.webView.release(); |
224 Safari.this.webView = null; | 226 this.outer.webView = null; |
225 Safari.this.delegate.release(); | 227 this.outer.delegate_.release(); |
226 Safari.this.delegate = null; | 228 this.outer.delegate_ = null; |
227 html = null; | 229 html = null; |
228 lastHoveredLinkURL = null; | 230 lastHoveredLinkURL = null; |
229 break; | 231 break; |
230 } | 232 } |
233 default: | |
231 } | 234 } |
232 } | 235 } |
233 }; | 236 }; |
234 browser.addListener(DWT.Dispose, listener); | 237 browser.addListener(DWT.Dispose, listener); |
235 /* Needed to be able to tab into the browser */ | 238 /* Needed to be able to tab into the browser */ |
236 browser.addListener(DWT.KeyDown, listener); | 239 browser.addListener(DWT.KeyDown, listener); |
237 browser.addListener(DWT.FocusIn, listener); | 240 browser.addListener(DWT.FocusIn, listener); |
238 | 241 |
239 webView.setFrameLoadDelegate(delegate); | 242 webView.setFrameLoadDelegate(delegate_); |
240 webView.setResourceLoadDelegate(delegate); | 243 webView.setResourceLoadDelegate(delegate_); |
241 webView.setUIDelegate(delegate); | 244 webView.setUIDelegate(delegate_); |
242 notificationCenter.addObserver(delegate, OS.sel_handleNotification_, null, webView); | 245 notificationCenter.addObserver(delegate_, OS.sel_handleNotification_, null, webView); |
243 webView.setPolicyDelegate(delegate); | 246 webView.setPolicyDelegate(delegate_); |
244 webView.setDownloadDelegate(delegate); | 247 webView.setDownloadDelegate(delegate_); |
245 webView.setApplicationNameForUserAgent(NSString.stringWith(AGENT_STRING)); | 248 webView.setApplicationNameForUserAgent(NSString.stringWith(AGENT_STRING)); |
246 | 249 |
247 if (!Initialized) { | 250 if (!Initialized) { |
248 Initialized = true; | 251 Initialized = true; |
249 /* disable applets */ | 252 /* disable applets */ |
254 public bool back() { | 257 public bool back() { |
255 html = null; | 258 html = null; |
256 return webView.goBack(); | 259 return webView.goBack(); |
257 } | 260 } |
258 | 261 |
259 static int /*long*/ browserProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) { | 262 static objc.id browserProc3(objc.id id, objc.SEL sel, objc.id arg0) { |
260 Widget widget = Display.getCurrent().findWidget(id); | 263 Widget widget = Display.getCurrent().findWidget(id); |
261 if (widget is null) return 0; | 264 if (widget is null) return null; |
262 Safari safari = (Safari)((Browser)widget).webBrowser; | 265 Safari safari = cast(Safari)(cast(Browser)widget).webBrowser; |
263 if (sel is OS.sel_handleNotification_) { | 266 if (sel is OS.sel_handleNotification_) { |
264 safari.handleNotification(arg0); | 267 safari.handleNotification(arg0); |
265 } else if (sel is OS.sel_webViewShow_) { | 268 } else if (sel is OS.sel_webViewShow_) { |
266 safari.webViewShow(arg0); | 269 safari.webViewShow(arg0); |
267 } else if (sel is OS.sel_webViewClose_) { | 270 } else if (sel is OS.sel_webViewClose_) { |
271 } else if (sel is OS.sel_webViewUnfocus_) { | 274 } else if (sel is OS.sel_webViewUnfocus_) { |
272 safari.webViewUnfocus(arg0); | 275 safari.webViewUnfocus(arg0); |
273 } else if (sel is OS.sel_handleEvent_) { | 276 } else if (sel is OS.sel_handleEvent_) { |
274 safari.handleEvent(arg0); | 277 safari.handleEvent(arg0); |
275 } | 278 } |
276 return 0; | 279 return null; |
277 } | 280 } |
278 | 281 |
279 static int /*long*/ browserProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1) { | 282 static objc.id browserProc4(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1) { |
280 Widget widget = Display.getCurrent().findWidget(id); | 283 Widget widget = Display.getCurrent().findWidget(id); |
281 if (widget is null) return 0; | 284 if (widget is null) return null; |
282 Safari safari = (Safari)((Browser)widget).webBrowser; | 285 Safari safari = cast(Safari)(cast(Browser)widget).webBrowser; |
283 if (sel is OS.sel_webView_didChangeLocationWithinPageForFrame_) { | 286 if (sel is OS.sel_webView_didChangeLocationWithinPageForFrame_) { |
284 safari.webView_didChangeLocationWithinPageForFrame(arg0, arg1); | 287 safari.webView_didChangeLocationWithinPageForFrame(arg0, arg1); |
285 } else if (sel is OS.sel_webView_didFinishLoadForFrame_) { | 288 } else if (sel is OS.sel_webView_didFinishLoadForFrame_) { |
286 safari.webView_didFinishLoadForFrame(arg0, arg1); | 289 safari.webView_didFinishLoadForFrame(arg0, arg1); |
287 } else if (sel is OS.sel_webView_didStartProvisionalLoadForFrame_) { | 290 } else if (sel is OS.sel_webView_didStartProvisionalLoadForFrame_) { |
291 } else if (sel is OS.sel_webView_setFrame_) { | 294 } else if (sel is OS.sel_webView_setFrame_) { |
292 safari.webView_setFrame(arg0, arg1); | 295 safari.webView_setFrame(arg0, arg1); |
293 } else if (sel is OS.sel_webView_createWebViewWithRequest_) { | 296 } else if (sel is OS.sel_webView_createWebViewWithRequest_) { |
294 return safari.webView_createWebViewWithRequest(arg0, arg1); | 297 return safari.webView_createWebViewWithRequest(arg0, arg1); |
295 } else if (sel is OS.sel_webView_setStatusBarVisible_) { | 298 } else if (sel is OS.sel_webView_setStatusBarVisible_) { |
296 safari.webView_setStatusBarVisible(arg0, arg1 !is 0); | 299 safari.webView_setStatusBarVisible(arg0, arg1 !is null); |
297 } else if (sel is OS.sel_webView_setResizable_) { | 300 } else if (sel is OS.sel_webView_setResizable_) { |
298 safari.webView_setResizable(arg0, arg1 !is 0); | 301 safari.webView_setResizable(arg0, arg1 !is null); |
299 } else if (sel is OS.sel_webView_setStatusText_) { | 302 } else if (sel is OS.sel_webView_setStatusText_) { |
300 safari.webView_setStatusText(arg0, arg1); | 303 safari.webView_setStatusText(arg0, arg1); |
301 } else if (sel is OS.sel_webView_setToolbarsVisible_) { | 304 } else if (sel is OS.sel_webView_setToolbarsVisible_) { |
302 safari.webView_setToolbarsVisible(arg0, arg1 !is 0); | 305 safari.webView_setToolbarsVisible(arg0, arg1 !is null); |
303 } else if (sel is OS.sel_webView_runJavaScriptAlertPanelWithMessage_) { | 306 } else if (sel is OS.sel_webView_runJavaScriptAlertPanelWithMessage_) { |
304 safari.webView_runJavaScriptAlertPanelWithMessage(arg0, arg1); | 307 safari.webView_runJavaScriptAlertPanelWithMessage(arg0, arg1); |
305 } else if (sel is OS.sel_webView_runJavaScriptConfirmPanelWithMessage_) { | 308 } else if (sel is OS.sel_webView_runJavaScriptConfirmPanelWithMessage_) { |
306 return safari.webView_runJavaScriptConfirmPanelWithMessage(arg0, arg1); | 309 return safari.webView_runJavaScriptConfirmPanelWithMessage(arg0, arg1); |
307 } else if (sel is OS.sel_webView_runOpenPanelForFileButtonWithResultListener_) { | 310 } else if (sel is OS.sel_webView_runOpenPanelForFileButtonWithResultListener_) { |
309 } else if (sel is OS.sel_download_decideDestinationWithSuggestedFilename_) { | 312 } else if (sel is OS.sel_download_decideDestinationWithSuggestedFilename_) { |
310 safari.download_decideDestinationWithSuggestedFilename(arg0, arg1); | 313 safari.download_decideDestinationWithSuggestedFilename(arg0, arg1); |
311 } else if (sel is OS.sel_webView_printFrameView_) { | 314 } else if (sel is OS.sel_webView_printFrameView_) { |
312 safari.webView_printFrameView(arg0, arg1); | 315 safari.webView_printFrameView(arg0, arg1); |
313 } | 316 } |
314 return 0; | 317 return null; |
315 } | 318 } |
316 | 319 |
317 static int /*long*/ browserProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2) { | 320 static objc.id browserProc5(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1, objc.id arg2) { |
318 Widget widget = Display.getCurrent().findWidget(id); | 321 Widget widget = Display.getCurrent().findWidget(id); |
319 if (widget is null) return 0; | 322 if (widget is null) return null; |
320 Safari safari = (Safari)((Browser)widget).webBrowser; | 323 Safari safari = cast(Safari)(cast(Browser)widget).webBrowser; |
321 if (sel is OS.sel_webView_didFailProvisionalLoadWithError_forFrame_) { | 324 if (sel is OS.sel_webView_didFailProvisionalLoadWithError_forFrame_) { |
322 safari.webView_didFailProvisionalLoadWithError_forFrame(arg0, arg1, arg2); | 325 safari.webView_didFailProvisionalLoadWithError_forFrame(arg0, arg1, arg2); |
323 } else if (sel is OS.sel_webView_didReceiveTitle_forFrame_) { | 326 } else if (sel is OS.sel_webView_didReceiveTitle_forFrame_) { |
324 safari.webView_didReceiveTitle_forFrame(arg0, arg1, arg2); | 327 safari.webView_didReceiveTitle_forFrame(arg0, arg1, arg2); |
325 } else if (sel is OS.sel_webView_resource_didFinishLoadingFromDataSource_) { | 328 } else if (sel is OS.sel_webView_resource_didFinishLoadingFromDataSource_) { |
331 } else if (sel is OS.sel_webView_mouseDidMoveOverElement_modifierFlags_) { | 334 } else if (sel is OS.sel_webView_mouseDidMoveOverElement_modifierFlags_) { |
332 safari.webView_mouseDidMoveOverElement_modifierFlags(arg0, arg1, arg2); | 335 safari.webView_mouseDidMoveOverElement_modifierFlags(arg0, arg1, arg2); |
333 } else if (sel is OS.sel_webView_unableToImplementPolicyWithError_frame_) { | 336 } else if (sel is OS.sel_webView_unableToImplementPolicyWithError_frame_) { |
334 safari.webView_unableToImplementPolicyWithError_frame(arg0, arg1, arg2); | 337 safari.webView_unableToImplementPolicyWithError_frame(arg0, arg1, arg2); |
335 } | 338 } |
336 return 0; | 339 return null; |
337 } | 340 } |
338 | 341 |
339 static int /*long*/ browserProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2, int /*long*/ arg3) { | 342 static objc.id browserProc6(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1, objc.id arg2, objc.id arg3) { |
340 Widget widget = Display.getCurrent().findWidget(id); | 343 Widget widget = Display.getCurrent().findWidget(id); |
341 if (widget is null) return 0; | 344 if (widget is null) return null; |
342 Safari safari = (Safari)((Browser)widget).webBrowser; | 345 Safari safari = cast(Safari)(cast(Browser)widget).webBrowser; |
343 if (sel is OS.sel_webView_resource_didFailLoadingWithError_fromDataSource_) { | 346 if (sel is OS.sel_webView_resource_didFailLoadingWithError_fromDataSource_) { |
344 safari.webView_resource_didFailLoadingWithError_fromDataSource(arg0, arg1, arg2, arg3); | 347 safari.webView_resource_didFailLoadingWithError_fromDataSource(arg0, arg1, arg2, arg3); |
345 } | 348 } |
346 return 0; | 349 return null; |
347 } | 350 } |
348 | 351 |
349 static int /*long*/ browserProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2, int /*long*/ arg3, int /*long*/ arg4) { | 352 static objc.id browserProc7(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1, objc.id arg2, objc.id arg3, objc.id arg4) { |
350 Widget widget = Display.getCurrent().findWidget(id); | 353 Widget widget = Display.getCurrent().findWidget(id); |
351 if (widget is null) return 0; | 354 if (widget is null) return null; |
352 Safari safari = (Safari)((Browser)widget).webBrowser; | 355 Safari safari = cast(Safari)(cast(Browser)widget).webBrowser; |
353 if (sel is OS.sel_webView_resource_willSendRequest_redirectResponse_fromDataSource_) { | 356 if (sel is OS.sel_webView_resource_willSendRequest_redirectResponse_fromDataSource_) { |
354 return safari.webView_resource_willSendRequest_redirectResponse_fromDataSource(arg0, arg1, arg2, arg3, arg4); | 357 return safari.webView_resource_willSendRequest_redirectResponse_fromDataSource(arg0, arg1, arg2, arg3, arg4); |
355 } else if (sel is OS.sel_webView_decidePolicyForMIMEType_request_frame_decisionListener_) { | 358 } else if (sel is OS.sel_webView_decidePolicyForMIMEType_request_frame_decisionListener_) { |
356 safari.webView_decidePolicyForMIMEType_request_frame_decisionListener(arg0, arg1, arg2, arg3, arg4); | 359 safari.webView_decidePolicyForMIMEType_request_frame_decisionListener(arg0, arg1, arg2, arg3, arg4); |
357 } else if (sel is OS.sel_webView_decidePolicyForNavigationAction_request_frame_decisionListener_) { | 360 } else if (sel is OS.sel_webView_decidePolicyForNavigationAction_request_frame_decisionListener_) { |
358 safari.webView_decidePolicyForNavigationAction_request_frame_decisionListener(arg0, arg1, arg2, arg3, arg4); | 361 safari.webView_decidePolicyForNavigationAction_request_frame_decisionListener(arg0, arg1, arg2, arg3, arg4); |
359 } else if (sel is OS.sel_webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener_) { | 362 } else if (sel is OS.sel_webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener_) { |
360 safari.webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener(arg0, arg1, arg2, arg3, arg4); | 363 safari.webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener(arg0, arg1, arg2, arg3, arg4); |
361 } | 364 } |
362 return 0; | 365 return null; |
363 } | 366 } |
364 | 367 |
365 public bool execute(String script) { | 368 public bool execute(String script) { |
366 return webView.stringByEvaluatingJavaScriptFromString(NSString.stringWith(script)) !is null; | 369 return webView.stringByEvaluatingJavaScriptFromString(NSString.stringWith(script)) !is null; |
367 } | 370 } |
426 | 429 |
427 public bool setUrl(String url) { | 430 public bool setUrl(String url) { |
428 html = null; | 431 html = null; |
429 | 432 |
430 if (url.indexOf('/') is 0) { | 433 if (url.indexOf('/') is 0) { |
431 url = PROTOCOL_FILE + url; | 434 url = PROTOCOL_FILE ~ url; |
432 } else if (url.indexOf(':') is -1) { | 435 } else if (url.indexOf(':') is -1) { |
433 url = PROTOCOL_HTTP + url; | 436 url = PROTOCOL_HTTP ~ url; |
434 } | 437 } |
435 | 438 |
436 NSString str = NSString.stringWith(url); | 439 NSString str = NSString.stringWith(url); |
437 NSString unescapedStr = NSString.stringWith("%#"); //$NON-NLS-1$ | 440 NSString unescapedStr = NSString.stringWith("%#"); //$NON-NLS-1$ |
438 int /*long*/ ptr = OS.CFURLCreateStringByAddingPercentEscapes(0, str.id, unescapedStr.id, 0, OS.kCFStringEncodingUTF8); | 441 Carbon.CFStringRef ptr = OS.CFURLCreateStringByAddingPercentEscapes(null, cast(Carbon.CFStringRef) str.id, cast(Carbon.CFStringRef) unescapedStr.id, null, OS.kCFStringEncodingUTF8); |
439 NSString escapedString = new NSString(ptr); | 442 NSString escapedString = new NSString(cast(objc.id) ptr); |
440 NSURL inURL = NSURL.URLWithString(escapedString); | 443 NSURL inURL = NSURL.URLWithString(escapedString); |
441 OS.CFRelease(ptr); | 444 OS.CFRelease(ptr); |
442 NSURLRequest request = NSURLRequest.requestWithURL(inURL); | 445 NSURLRequest request = NSURLRequest.requestWithURL(inURL); |
443 WebFrame mainFrame = webView.mainFrame(); | 446 WebFrame mainFrame = webView.mainFrame(); |
444 mainFrame.loadRequest(request); | 447 mainFrame.loadRequest(request); |
450 webView.stopLoading(null); | 453 webView.stopLoading(null); |
451 } | 454 } |
452 | 455 |
453 /* WebFrameLoadDelegate */ | 456 /* WebFrameLoadDelegate */ |
454 | 457 |
455 void webView_didChangeLocationWithinPageForFrame(int /*long*/ sender, int /*long*/ frameID) { | 458 void webView_didChangeLocationWithinPageForFrame(objc.id sender, objc.id frameID) { |
456 WebFrame frame = new WebFrame(frameID); | 459 WebFrame frame = new WebFrame(frameID); |
457 WebDataSource dataSource = frame.dataSource(); | 460 WebDataSource dataSource = frame.dataSource(); |
458 NSURLRequest request = dataSource.request(); | 461 NSURLRequest request = dataSource.request(); |
459 NSURL url = request.URL(); | 462 NSURL url = request.URL(); |
460 NSString s = url.absoluteString(); | 463 NSString s = url.absoluteString(); |
461 int length = (int)/*64*/s.length(); | 464 NSUInteger length = s.length(); |
462 if (length is 0) return; | 465 if (length is 0) return; |
463 String url2 = s.getString(); | 466 String url2 = s.getString(); |
464 /* | 467 /* |
465 * If the URI indicates that the page is being rendered from memory | 468 * If the URI indicates that the page is being rendered from memory |
466 * (via setText()) then set it to about:blank to be consistent with IE. | 469 * (via setText()) then set it to about:blank to be consistent with IE. |
487 for (int i = 0; i < locationListeners.length; i++) { | 490 for (int i = 0; i < locationListeners.length; i++) { |
488 locationListeners[i].changed(location); | 491 locationListeners[i].changed(location); |
489 } | 492 } |
490 } | 493 } |
491 | 494 |
492 void webView_didFailProvisionalLoadWithError_forFrame(int /*long*/ sender, int /*long*/ error, int /*long*/ frame) { | 495 void webView_didFailProvisionalLoadWithError_forFrame(objc.id sender, objc.id error, objc.id frame) { |
493 if (frame is webView.mainFrame().id) { | 496 if (frame is webView.mainFrame().id) { |
494 /* | 497 /* |
495 * Feature on Safari. The identifier is used here as a marker for the events | 498 * Feature on Safari. The identifier is used here as a marker for the events |
496 * related to the top frame and the URL changes related to that top frame as | 499 * related to the top frame and the URL changes related to that top frame as |
497 * they should appear on the location bar of a browser. It is expected to reset | 500 * they should appear on the location bar of a browser. It is expected to reset |
502 * events in this interval, causing the Browser widget to send unwanted | 505 * events in this interval, causing the Browser widget to send unwanted |
503 * Location.changing events. For this reason, the identifier is reset to 0 | 506 * Location.changing events. For this reason, the identifier is reset to 0 |
504 * when the top frame has either finished loading (didFinishLoadForFrame | 507 * when the top frame has either finished loading (didFinishLoadForFrame |
505 * event) or failed (didFailProvisionalLoadWithError). | 508 * event) or failed (didFailProvisionalLoadWithError). |
506 */ | 509 */ |
507 identifier = 0; | 510 identifier = null; |
508 } | 511 } |
509 | 512 |
510 NSError nserror = new NSError(error); | 513 NSError nserror = new NSError(error); |
511 int /*long*/ errorCode = nserror.code(); | 514 NSInteger errorCode = nserror.code(); |
512 if (errorCode <= OS.NSURLErrorBadURL) { | 515 if (errorCode <= OS.NSURLErrorBadURL) { |
513 NSString description = nserror.localizedDescription(); | 516 NSString description = nserror.localizedDescription(); |
514 if (description !is null) { | 517 if (description !is null) { |
515 String descriptionString = description.getString(); | 518 String descriptionString = description.getString(); |
516 String urlString = null; | 519 String urlString = null; |
517 NSDictionary info = nserror.userInfo(); | 520 NSDictionary info = nserror.userInfo(); |
518 if (info !is null) { | 521 if (info !is null) { |
519 NSString key = new NSString(OS.NSErrorFailingURLStringKey()); | 522 NSString key = new NSString(OS.NSErrorFailingURLStringKey_); |
520 id id = info.valueForKey(key); | 523 id id = info.valueForKey(key); |
521 if (id !is null) { | 524 if (id !is null) { |
522 NSString url = new NSString(id); | 525 NSString url = new NSString(id); |
523 urlString = url.getString(); | 526 urlString = url.getString(); |
524 } | 527 } |
525 } | 528 } |
526 String message = urlString !is null ? urlString + "\n\n" : ""; //$NON-NLS-1$ //$NON-NLS-2$ | 529 String message = urlString !is null ? urlString ~ "\n\n" : ""; //$NON-NLS-1$ //$NON-NLS-2$ |
527 message += Compatibility.getMessage ("DWT_Page_Load_Failed", new Object[] {descriptionString}); //$NON-NLS-1$ | 530 message ~= Compatibility.getMessage ("DWT_Page_Load_Failed", [new ArrayWrapperString(descriptionString)]); //$NON-NLS-1$ |
528 MessageBox messageBox = new MessageBox(browser.getShell(), DWT.OK | DWT.ICON_ERROR); | 531 MessageBox messageBox = new MessageBox(browser.getShell(), DWT.OK | DWT.ICON_ERROR); |
529 messageBox.setMessage(message); | 532 messageBox.setMessage(message); |
530 messageBox.open(); | 533 messageBox.open(); |
531 } | 534 } |
532 } | 535 } |
533 } | 536 } |
534 | 537 |
535 void webView_didFinishLoadForFrame(int /*long*/ sender, int /*long*/ frameID) { | 538 void webView_didFinishLoadForFrame(objc.id sender, objc.id frameID) { |
536 hookDOMMouseListeners(frameID); | 539 hookDOMMouseListeners(frameID); |
537 if (frameID is webView.mainFrame().id) { | 540 if (frameID is webView.mainFrame().id) { |
538 hookDOMKeyListeners(frameID); | 541 hookDOMKeyListeners(frameID); |
539 | 542 |
540 final Display display = browser.getDisplay(); | 543 final Display display = browser.getDisplay(); |
561 * delegate callback breaks the WebKit (stop loading or | 564 * delegate callback breaks the WebKit (stop loading or |
562 * crash). The workaround is to invoke Display.asyncExec() | 565 * crash). The workaround is to invoke Display.asyncExec() |
563 * so that the Browser does not crash if this is attempted. | 566 * so that the Browser does not crash if this is attempted. |
564 */ | 567 */ |
565 display.asyncExec( | 568 display.asyncExec( |
566 new Runnable() { | 569 new class (display, browser, listener) Runnable { |
570 | |
571 Display display; | |
572 Browser browser; | |
573 TitleListener listener; | |
574 | |
575 this (Display display, Browser browser, TitleListener listener) | |
576 { | |
577 this.display = display; | |
578 this.browser = browser; | |
579 this.listener = listener; | |
580 } | |
581 | |
567 public void run() { | 582 public void run() { |
568 if (!display.isDisposed() && !browser.isDisposed()) { | 583 if (!display.isDisposed() && !browser.isDisposed()) { |
569 listener.changed(newEvent); | 584 listener.changed(newEvent); |
570 } | 585 } |
571 } | 586 } |
589 * The workaround is to invoke Display.asyncExec() so that | 604 * The workaround is to invoke Display.asyncExec() so that |
590 * the Browser does not crash when the user updates the | 605 * the Browser does not crash when the user updates the |
591 * selection of the ProgressBar. | 606 * selection of the ProgressBar. |
592 */ | 607 */ |
593 display.asyncExec( | 608 display.asyncExec( |
594 new Runnable() { | 609 new class (display, browser, listener) Runnable { |
610 | |
611 Display display; | |
612 Browser browser; | |
613 ProgressListener listener; | |
614 | |
615 this (Display display, Browser browser, ProgressListener listener) | |
616 { | |
617 this.display = display; | |
618 this.browser = browser; | |
619 this.listener = listener; | |
620 } | |
621 | |
595 public void run() { | 622 public void run() { |
596 if (!display.isDisposed() && !browser.isDisposed()) { | 623 if (!display.isDisposed() && !browser.isDisposed()) { |
597 listener.completed(progress); | 624 listener.completed(progress); |
598 } | 625 } |
599 } | 626 } |
611 * events in this interval, causing the Browser widget to send unwanted | 638 * events in this interval, causing the Browser widget to send unwanted |
612 * Location.changing events. For this reason, the identifier is reset to 0 | 639 * Location.changing events. For this reason, the identifier is reset to 0 |
613 * when the top frame has either finished loading (didFinishLoadForFrame | 640 * when the top frame has either finished loading (didFinishLoadForFrame |
614 * event) or failed (didFailProvisionalLoadWithError). | 641 * event) or failed (didFailProvisionalLoadWithError). |
615 */ | 642 */ |
616 identifier = 0; | 643 identifier = null; |
617 } | 644 } |
618 } | 645 } |
619 | 646 |
620 void hookDOMKeyListeners(int /*long*/ frameID) { | 647 void hookDOMKeyListeners(objc.id frameID) { |
621 WebFrame frame = new WebFrame(frameID); | 648 WebFrame frame = new WebFrame(frameID); |
622 DOMDocument document = frame.DOMDocument(); | 649 DOMDocument document = frame.DOMDocument_(); |
623 | 650 |
624 NSString type = NSString.stringWith(DOMEVENT_KEYDOWN); | 651 NSString type = NSString.stringWith(DOMEVENT_KEYDOWN); |
625 document.addEventListener(type, delegate, false); | 652 document.addEventListener(type, delegate_, false); |
626 | 653 |
627 type = NSString.stringWith(DOMEVENT_KEYUP); | 654 type = NSString.stringWith(DOMEVENT_KEYUP); |
628 document.addEventListener(type, delegate, false); | 655 document.addEventListener(type, delegate_, false); |
629 } | 656 } |
630 | 657 |
631 void hookDOMMouseListeners(int /*long*/ frameID) { | 658 void hookDOMMouseListeners(objc.id frameID) { |
632 WebFrame frame = new WebFrame(frameID); | 659 WebFrame frame = new WebFrame(frameID); |
633 DOMDocument document = frame.DOMDocument(); | 660 DOMDocument document = frame.DOMDocument_(); |
634 | 661 |
635 NSString type = NSString.stringWith(DOMEVENT_MOUSEDOWN); | 662 NSString type = NSString.stringWith(DOMEVENT_MOUSEDOWN); |
636 document.addEventListener(type, delegate, false); | 663 document.addEventListener(type, delegate_, false); |
637 | 664 |
638 type = NSString.stringWith(DOMEVENT_MOUSEUP); | 665 type = NSString.stringWith(DOMEVENT_MOUSEUP); |
639 document.addEventListener(type, delegate, false); | 666 document.addEventListener(type, delegate_, false); |
640 | 667 |
641 type = NSString.stringWith(DOMEVENT_MOUSEMOVE); | 668 type = NSString.stringWith(DOMEVENT_MOUSEMOVE); |
642 document.addEventListener(type, delegate, false); | 669 document.addEventListener(type, delegate_, false); |
643 | 670 |
644 type = NSString.stringWith(DOMEVENT_MOUSEWHEEL); | 671 type = NSString.stringWith(DOMEVENT_MOUSEWHEEL); |
645 document.addEventListener(type, delegate, false); | 672 document.addEventListener(type, delegate_, false); |
646 } | 673 } |
647 | 674 |
648 void webView_didReceiveTitle_forFrame(int /*long*/ sender, int /*long*/ titleID, int /*long*/ frameID) { | 675 void webView_didReceiveTitle_forFrame(objc.id sender, objc.id titleID, objc.id frameID) { |
649 if (frameID is webView.mainFrame().id) { | 676 if (frameID is webView.mainFrame().id) { |
650 NSString title = new NSString(titleID); | 677 NSString title = new NSString(titleID); |
651 String newTitle = title.getString(); | 678 String newTitle = title.getString(); |
652 TitleEvent newEvent = new TitleEvent(browser); | 679 TitleEvent newEvent = new TitleEvent(browser); |
653 newEvent.display = browser.getDisplay(); | 680 newEvent.display = browser.getDisplay(); |
657 titleListeners[i].changed(newEvent); | 684 titleListeners[i].changed(newEvent); |
658 } | 685 } |
659 } | 686 } |
660 } | 687 } |
661 | 688 |
662 void webView_didStartProvisionalLoadForFrame(int /*long*/ sender, int /*long*/ frameID) { | 689 void webView_didStartProvisionalLoadForFrame(objc.id sender, objc.id frameID) { |
663 /* | 690 /* |
664 * This code is intentionally commented. WebFrameLoadDelegate:didStartProvisionalLoadForFrame is | 691 * This code is intentionally commented. WebFrameLoadDelegate:didStartProvisionalLoadForFrame is |
665 * called before WebResourceLoadDelegate:willSendRequest and | 692 * called before WebResourceLoadDelegate:willSendRequest and |
666 * WebFrameLoadDelegate:didCommitLoadForFrame. The resource count is reset when didCommitLoadForFrame | 693 * WebFrameLoadDelegate:didCommitLoadForFrame. The resource count is reset when didCommitLoadForFrame |
667 * is received for the top frame. | 694 * is received for the top frame. |
670 // /* reset resource status variables */ | 697 // /* reset resource status variables */ |
671 // resourceCount= 0; | 698 // resourceCount= 0; |
672 // } | 699 // } |
673 } | 700 } |
674 | 701 |
675 void webView_didCommitLoadForFrame(int /*long*/ sender, int /*long*/ frameID) { | 702 void webView_didCommitLoadForFrame(objc.id sender, objc.id frameID) { |
676 WebFrame frame = new WebFrame(frameID); | 703 WebFrame frame = new WebFrame(frameID); |
677 WebDataSource dataSource = frame.dataSource(); | 704 WebDataSource dataSource = frame.dataSource(); |
678 NSURLRequest request = dataSource.request(); | 705 NSURLRequest request = dataSource.request(); |
679 NSURL url = request.URL(); | 706 NSURL url = request.URL(); |
680 NSString s = url.absoluteString(); | 707 NSString s = url.absoluteString(); |
681 int length = (int)/*64*/s.length(); | 708 NSUInteger length = s.length(); |
682 if (length is 0) return; | 709 if (length is 0) return; |
683 String url2 = s.getString(); | 710 String url2 = s.getString(); |
684 /* | 711 /* |
685 * If the URI indicates that the page is being rendered from memory | 712 * If the URI indicates that the page is being rendered from memory |
686 * (via setText()) then set it to about:blank to be consistent with IE. | 713 * (via setText()) then set it to about:blank to be consistent with IE. |
709 * The workaround is to invoke Display.asyncexec so that | 736 * The workaround is to invoke Display.asyncexec so that |
710 * the Browser does not crash when the user updates the | 737 * the Browser does not crash when the user updates the |
711 * selection of the ProgressBar. | 738 * selection of the ProgressBar. |
712 */ | 739 */ |
713 display.asyncExec( | 740 display.asyncExec( |
714 new Runnable() { | 741 new class (display, browser, listener) Runnable { |
742 | |
743 Display display; | |
744 Browser browser; | |
745 ProgressListener listener; | |
746 | |
747 this (Display display, Browser browser, ProgressListener listener) | |
748 { | |
749 this.display = display; | |
750 this.browser = browser; | |
751 this.listener = listener; | |
752 } | |
753 | |
715 public void run() { | 754 public void run() { |
716 if (!display.isDisposed() && !browser.isDisposed()) | 755 if (!display.isDisposed() && !browser.isDisposed()) |
717 listener.changed(progress); | 756 listener.changed(progress); |
718 } | 757 } |
719 } | 758 } |
738 } | 777 } |
739 } | 778 } |
740 | 779 |
741 /* WebResourceLoadDelegate */ | 780 /* WebResourceLoadDelegate */ |
742 | 781 |
743 void webView_resource_didFinishLoadingFromDataSource(int /*long*/ sender, int /*long*/ identifier, int /*long*/ dataSource) { | 782 void webView_resource_didFinishLoadingFromDataSource(objc.id sender, objc.id identifier, objc.id dataSource) { |
744 /* | 783 /* |
745 * Feature on Safari. The identifier is used here as a marker for the events | 784 * Feature on Safari. The identifier is used here as a marker for the events |
746 * related to the top frame and the URL changes related to that top frame as | 785 * related to the top frame and the URL changes related to that top frame as |
747 * they should appear on the location bar of a browser. It is expected to reset | 786 * they should appear on the location bar of a browser. It is expected to reset |
748 * the identifier to 0 when the event didFinishLoadingFromDataSource related to | 787 * the identifier to 0 when the event didFinishLoadingFromDataSource related to |
756 */ | 795 */ |
757 // this code is intentionally commented | 796 // this code is intentionally commented |
758 //if (this.identifier is identifier) this.identifier = 0; | 797 //if (this.identifier is identifier) this.identifier = 0; |
759 } | 798 } |
760 | 799 |
761 void webView_resource_didFailLoadingWithError_fromDataSource(int /*long*/ sender, int /*long*/ identifier, int /*long*/ error, int /*long*/ dataSource) { | 800 void webView_resource_didFailLoadingWithError_fromDataSource(objc.id sender, objc.id identifier, objc.id error, objc.id dataSource) { |
762 /* | 801 /* |
763 * Feature on Safari. The identifier is used here as a marker for the events | 802 * Feature on Safari. The identifier is used here as a marker for the events |
764 * related to the top frame and the URL changes related to that top frame as | 803 * related to the top frame and the URL changes related to that top frame as |
765 * they should appear on the location bar of a browser. It is expected to reset | 804 * they should appear on the location bar of a browser. It is expected to reset |
766 * the identifier to 0 when the event didFinishLoadingFromDataSource related to | 805 * the identifier to 0 when the event didFinishLoadingFromDataSource related to |
774 */ | 813 */ |
775 // this code is intentionally commented | 814 // this code is intentionally commented |
776 //if (this.identifier is identifier) this.identifier = 0; | 815 //if (this.identifier is identifier) this.identifier = 0; |
777 } | 816 } |
778 | 817 |
779 int /*long*/ webView_identifierForInitialRequest_fromDataSource(int /*long*/ sender, int /*long*/ request, int /*long*/ dataSourceID) { | 818 objc.id webView_identifierForInitialRequest_fromDataSource(objc.id sender, objc.id request, objc.id dataSourceID) { |
780 final Display display = browser.getDisplay(); | 819 final Display display = browser.getDisplay(); |
781 final ProgressEvent progress = new ProgressEvent(browser); | 820 final ProgressEvent progress = new ProgressEvent(browser); |
782 progress.display = display; | 821 progress.display = display; |
783 progress.widget = browser; | 822 progress.widget = browser; |
784 progress.current = resourceCount; | 823 progress.current = resourceCount; |
793 * The workaround is to invoke Display.asyncexec so that | 832 * The workaround is to invoke Display.asyncexec so that |
794 * the Browser does not crash when the user updates the | 833 * the Browser does not crash when the user updates the |
795 * selection of the ProgressBar. | 834 * selection of the ProgressBar. |
796 */ | 835 */ |
797 display.asyncExec( | 836 display.asyncExec( |
798 new Runnable() { | 837 new class (display, browser, listener) Runnable { |
838 | |
839 Display display; | |
840 Browser browser; | |
841 ProgressListener listener; | |
842 | |
843 this (Display display, Browser browser, ProgressListener listener) | |
844 { | |
845 this.display = display; | |
846 this.browser = browser; | |
847 this.listener = listener; | |
848 } | |
849 | |
799 public void run() { | 850 public void run() { |
800 if (!display.isDisposed() && !browser.isDisposed()) | 851 if (!display.isDisposed() && !browser.isDisposed()) |
801 listener.changed(progress); | 852 listener.changed(progress); |
802 } | 853 } |
803 } | 854 } |
804 ); | 855 ); |
805 } | 856 } |
806 | 857 |
807 NSNumber identifier = NSNumber.numberWithInt(resourceCount++); | 858 NSNumber identifier = NSNumber.numberWithInt(resourceCount++); |
808 if (this.identifier is 0) { | 859 if (this.identifier is null) { |
809 WebDataSource dataSource = new WebDataSource(dataSourceID); | 860 WebDataSource dataSource = new WebDataSource(dataSourceID); |
810 WebFrame frame = dataSource.webFrame(); | 861 WebFrame frame = dataSource.webFrame(); |
811 if (frame.id is webView.mainFrame().id) this.identifier = identifier.id; | 862 if (frame.id is webView.mainFrame().id) this.identifier = identifier.id; |
812 } | 863 } |
813 return identifier.id; | 864 return identifier.id; |
814 | 865 |
815 } | 866 } |
816 | 867 |
817 int /*long*/ webView_resource_willSendRequest_redirectResponse_fromDataSource(int /*long*/ sender, int /*long*/ identifier, int /*long*/ request, int /*long*/ redirectResponse, int /*long*/ dataSource) { | 868 objc.id webView_resource_willSendRequest_redirectResponse_fromDataSource(objc.id sender, objc.id identifier, objc.id request, objc.id redirectResponse, objc.id dataSource) { |
818 return request; | 869 return request; |
819 } | 870 } |
820 | 871 |
821 /* handleNotification */ | 872 /* handleNotification */ |
822 | 873 |
823 void handleNotification(int /*long*/ notification) { | 874 void handleNotification(objc.id notification) { |
824 } | 875 } |
825 | 876 |
826 /* UIDelegate */ | 877 /* UIDelegate */ |
827 | 878 |
828 int /*long*/ webView_createWebViewWithRequest(int /*long*/ sender, int /*long*/ request) { | 879 objc.id webView_createWebViewWithRequest(objc.id sender, objc.id request) { |
829 WindowEvent newEvent = new WindowEvent(browser); | 880 WindowEvent newEvent = new WindowEvent(browser); |
830 newEvent.display = browser.getDisplay(); | 881 newEvent.display = browser.getDisplay(); |
831 newEvent.widget = browser; | 882 newEvent.widget = browser; |
832 newEvent.required = true; | 883 newEvent.required = true; |
833 if (openWindowListeners !is null) { | 884 if (openWindowListeners !is null) { |
835 openWindowListeners[i].open(newEvent); | 886 openWindowListeners[i].open(newEvent); |
836 } | 887 } |
837 } | 888 } |
838 WebView result = null; | 889 WebView result = null; |
839 Browser browser = null; | 890 Browser browser = null; |
840 if (newEvent.browser !is null && newEvent.browser.webBrowser instanceof Safari) { | 891 if (newEvent.browser !is null && cast(Safari) newEvent.browser.webBrowser) { |
841 browser = newEvent.browser; | 892 browser = newEvent.browser; |
842 } | 893 } |
843 if (browser !is null && !browser.isDisposed()) { | 894 if (browser !is null && !browser.isDisposed()) { |
844 result = ((Safari)browser.webBrowser).webView; | 895 result = (cast(Safari)browser.webBrowser).webView; |
845 if (request !is 0) { | 896 if (request !is null) { |
846 WebFrame mainFrame = webView.mainFrame(); | 897 WebFrame mainFrame = webView.mainFrame(); |
847 mainFrame.loadRequest(new NSURLRequest(request)); | 898 mainFrame.loadRequest(new NSURLRequest(request)); |
848 } | 899 } |
849 } | 900 } |
850 return result !is null ? result.id : 0; | 901 return result !is null ? result.id : null; |
851 } | 902 } |
852 | 903 |
853 void webViewShow(int /*long*/ sender) { | 904 void webViewShow(objc.id sender) { |
854 /* | 905 /* |
855 * Feature on WebKit. The Safari WebKit expects the application | 906 * Feature on WebKit. The Safari WebKit expects the application |
856 * to create a new Window using the Objective C Cocoa API in response | 907 * to create a new Window using the Objective C Cocoa API in response |
857 * to UIDelegate.createWebViewWithRequest. The application is then | 908 * to UIDelegate.createWebViewWithRequest. The application is then |
858 * expected to use Objective C Cocoa API to make this window visible | 909 * expected to use Objective C Cocoa API to make this window visible |
888 } | 939 } |
889 location = null; | 940 location = null; |
890 size = null; | 941 size = null; |
891 } | 942 } |
892 | 943 |
893 void webView_setFrame(int /*long*/ sender, int /*long*/ frame) { | 944 void webView_setFrame(objc.id sender, objc.id frame) { |
894 NSRect rect = NSRect(); | 945 NSRect rect = NSRect(); |
895 OS.memmove(rect, frame, NSRect.sizeof); | 946 OS.memmove(&rect, frame, NSRect.sizeof); |
896 /* convert to DWT system coordinates */ | 947 /* convert to DWT system coordinates */ |
897 Rectangle bounds = browser.getDisplay().getBounds(); | 948 Rectangle bounds = browser.getDisplay().getBounds(); |
898 location = new Point((int)rect.x, bounds.height - (int)rect.y - (int)rect.height); | 949 location = new Point(cast(int)rect.x, bounds.height - cast(int)rect.y - cast(int)rect.height); |
899 size = new Point((int)rect.width, (int)rect.height); | 950 size = new Point(cast(int)rect.width, cast(int)rect.height); |
900 } | 951 } |
901 | 952 |
902 void webViewFocus(int /*long*/ sender) { | 953 void webViewFocus(objc.id sender) { |
903 } | 954 } |
904 | 955 |
905 void webViewUnfocus(int /*long*/ sender) { | 956 void webViewUnfocus(objc.id sender) { |
906 } | 957 } |
907 | 958 |
908 void webView_runJavaScriptAlertPanelWithMessage(int /*long*/ sender, int /*long*/ messageID) { | 959 void webView_runJavaScriptAlertPanelWithMessage(objc.id sender, objc.id messageID) { |
909 NSString message = new NSString(messageID); | 960 NSString message = new NSString(messageID); |
910 String text = message.getString(); | 961 String text = message.getString(); |
911 | 962 |
912 MessageBox messageBox = new MessageBox(browser.getShell(), DWT.OK | DWT.ICON_WARNING); | 963 MessageBox messageBox = new MessageBox(browser.getShell(), DWT.OK | DWT.ICON_WARNING); |
913 messageBox.setText("Javascript"); //$NON-NLS-1$ | 964 messageBox.setText("Javascript"); //$NON-NLS-1$ |
914 messageBox.setMessage(text); | 965 messageBox.setMessage(text); |
915 messageBox.open(); | 966 messageBox.open(); |
916 } | 967 } |
917 | 968 |
918 int webView_runJavaScriptConfirmPanelWithMessage(int /*long*/ sender, int /*long*/ messageID) { | 969 objc.id webView_runJavaScriptConfirmPanelWithMessage(objc.id sender, objc.id messageID) { |
919 NSString message = new NSString(messageID); | 970 NSString message = new NSString(messageID); |
920 String text = message.getString(); | 971 String text = message.getString(); |
921 | 972 |
922 MessageBox messageBox = new MessageBox(browser.getShell(), DWT.OK | DWT.CANCEL | DWT.ICON_QUESTION); | 973 MessageBox messageBox = new MessageBox(browser.getShell(), DWT.OK | DWT.CANCEL | DWT.ICON_QUESTION); |
923 messageBox.setText("Javascript"); //$NON-NLS-1$ | 974 messageBox.setText("Javascript"); //$NON-NLS-1$ |
924 messageBox.setMessage(text); | 975 messageBox.setMessage(text); |
925 return messageBox.open() is DWT.OK ? 1 : 0; | 976 return messageBox.open() is DWT.OK ? cast(objc.id) 1 : null; |
926 } | 977 } |
927 | 978 |
928 void webView_runOpenPanelForFileButtonWithResultListener(int /*long*/ sender, int /*long*/ resultListenerID) { | 979 void webView_runOpenPanelForFileButtonWithResultListener(objc.id sender, objc.id resultListenerID) { |
929 FileDialog dialog = new FileDialog(browser.getShell(), DWT.NONE); | 980 FileDialog dialog = new FileDialog(browser.getShell(), DWT.NONE); |
930 String result = dialog.open(); | 981 String result = dialog.open(); |
931 WebOpenPanelResultListener resultListener = new WebOpenPanelResultListener(resultListenerID); | 982 WebOpenPanelResultListener resultListener = new WebOpenPanelResultListener(resultListenerID); |
932 if (result is null) { | 983 if (result is null) { |
933 resultListener.cancel(); | 984 resultListener.cancel(); |
934 return; | 985 return; |
935 } | 986 } |
936 resultListener.chooseFilename(NSString.stringWith(result)); | 987 resultListener.chooseFilename(NSString.stringWith(result)); |
937 } | 988 } |
938 | 989 |
939 void webViewClose(int /*long*/ sender) { | 990 void webViewClose(objc.id sender) { |
940 Shell parent = browser.getShell(); | 991 Shell parent = browser.getShell(); |
941 WindowEvent newEvent = new WindowEvent(browser); | 992 WindowEvent newEvent = new WindowEvent(browser); |
942 newEvent.display = browser.getDisplay(); | 993 newEvent.display = browser.getDisplay(); |
943 newEvent.widget = browser; | 994 newEvent.widget = browser; |
944 for (int i = 0; i < closeWindowListeners.length; i++) { | 995 for (int i = 0; i < closeWindowListeners.length; i++) { |
959 Point pt = parent.getSize(); | 1010 Point pt = parent.getSize(); |
960 parent.setSize(pt.x+1, pt.y); | 1011 parent.setSize(pt.x+1, pt.y); |
961 parent.setSize(pt.x, pt.y); | 1012 parent.setSize(pt.x, pt.y); |
962 } | 1013 } |
963 | 1014 |
964 int /*long*/ webView_contextMenuItemsForElement_defaultMenuItems(int /*long*/ sender, int /*long*/ element, int /*long*/ defaultMenuItems) { | 1015 objc.id webView_contextMenuItemsForElement_defaultMenuItems(objc.id sender, objc.id element, objc.id defaultMenuItems) { |
965 Point pt = browser.getDisplay().getCursorLocation(); | 1016 Point pt = browser.getDisplay().getCursorLocation(); |
966 Event event = new Event(); | 1017 Event event = new Event(); |
967 event.x = pt.x; | 1018 event.x = pt.x; |
968 event.y = pt.y; | 1019 event.y = pt.y; |
969 browser.notifyListeners(DWT.MenuDetect, event); | 1020 browser.notifyListeners(DWT.MenuDetect, event); |
970 Menu menu = browser.getMenu(); | 1021 Menu menu = browser.getMenu(); |
971 if (!event.doit) return 0; | 1022 if (!event.doit) return null; |
972 if (menu !is null && !menu.isDisposed()) { | 1023 if (menu !is null && !menu.isDisposed()) { |
973 if (event.x !is pt.x || event.y !is pt.y) { | 1024 if (event.x !is pt.x || event.y !is pt.y) { |
974 menu.setLocation(event.x, event.y); | 1025 menu.setLocation(event.x, event.y); |
975 } | 1026 } |
976 menu.setVisible(true); | 1027 menu.setVisible(true); |
977 return 0; | 1028 return null; |
978 } | 1029 } |
979 return defaultMenuItems; | 1030 return defaultMenuItems; |
980 } | 1031 } |
981 | 1032 |
982 void webView_setStatusBarVisible(int /*long*/ sender, bool visible) { | 1033 void webView_setStatusBarVisible(objc.id sender, bool visible) { |
983 /* Note. Webkit only emits the notification when the status bar should be hidden. */ | 1034 /* Note. Webkit only emits the notification when the status bar should be hidden. */ |
984 statusBar = visible; | 1035 statusBar = visible; |
985 } | 1036 } |
986 | 1037 |
987 void webView_setStatusText(int /*long*/ sender, int /*long*/ textID) { | 1038 void webView_setStatusText(objc.id sender, objc.id textID) { |
988 NSString text = new NSString(textID); | 1039 NSString text = new NSString(textID); |
989 int length = (int)/*64*/text.length(); | 1040 NSUInteger length = text.length(); |
990 if (length is 0) return; | 1041 if (length is 0) return; |
991 | 1042 |
992 StatusTextEvent statusText = new StatusTextEvent(browser); | 1043 StatusTextEvent statusText = new StatusTextEvent(browser); |
993 statusText.display = browser.getDisplay(); | 1044 statusText.display = browser.getDisplay(); |
994 statusText.widget = browser; | 1045 statusText.widget = browser; |
996 for (int i = 0; i < statusTextListeners.length; i++) { | 1047 for (int i = 0; i < statusTextListeners.length; i++) { |
997 statusTextListeners[i].changed(statusText); | 1048 statusTextListeners[i].changed(statusText); |
998 } | 1049 } |
999 } | 1050 } |
1000 | 1051 |
1001 void webView_setResizable(int /*long*/ sender, bool visible) { | 1052 void webView_setResizable(objc.id sender, bool visible) { |
1002 } | 1053 } |
1003 | 1054 |
1004 void webView_setToolbarsVisible(int /*long*/ sender, bool visible) { | 1055 void webView_setToolbarsVisible(objc.id sender, bool visible) { |
1005 /* Note. Webkit only emits the notification when the tool bar should be hidden. */ | 1056 /* Note. Webkit only emits the notification when the tool bar should be hidden. */ |
1006 toolBar = visible; | 1057 toolBar = visible; |
1007 } | 1058 } |
1008 | 1059 |
1009 void webView_mouseDidMoveOverElement_modifierFlags (int /*long*/ sender, int /*long*/ elementInformationID, int /*long*/ modifierFlags) { | 1060 void webView_mouseDidMoveOverElement_modifierFlags (objc.id sender, objc.id elementInformationID, objc.id modifierFlags) { |
1010 if (elementInformationID is 0) return; | 1061 if (elementInformationID is null) return; |
1011 | 1062 |
1012 NSString key = NSString.stringWith(WebElementLinkURLKey); | 1063 NSString key = NSString.stringWith(WebElementLinkURLKey); |
1013 NSDictionary elementInformation = new NSDictionary(elementInformationID); | 1064 NSDictionary elementInformation = new NSDictionary(elementInformationID); |
1014 id value = elementInformation.valueForKey(key); | 1065 id value = elementInformation.valueForKey(key); |
1015 if (value is null) { | 1066 if (value is null) { |
1024 statusTextListeners[i].changed(statusText); | 1075 statusTextListeners[i].changed(statusText); |
1025 } | 1076 } |
1026 return; | 1077 return; |
1027 } | 1078 } |
1028 | 1079 |
1029 NSString url = new NSURL(value.id).absoluteString(); | 1080 NSString url = (new NSURL(value.id)).absoluteString(); |
1030 int length = (int)/*64*/url.length(); | 1081 NSUInteger length = url.length(); |
1031 String urlString; | 1082 String urlString; |
1032 if (length is 0) { | 1083 if (length is 0) { |
1033 urlString = ""; //$NON-NLS-1$ | 1084 urlString = ""; //$NON-NLS-1$ |
1034 } else { | 1085 } else { |
1035 urlString = url.getString(); | 1086 urlString = url.getString(); |
1044 for (int i = 0; i < statusTextListeners.length; i++) { | 1095 for (int i = 0; i < statusTextListeners.length; i++) { |
1045 statusTextListeners[i].changed(statusText); | 1096 statusTextListeners[i].changed(statusText); |
1046 } | 1097 } |
1047 } | 1098 } |
1048 | 1099 |
1049 void webView_printFrameView (int /*long*/ sender, int /*long*/ frameViewID) { | 1100 void webView_printFrameView (objc.id sender, objc.id frameViewID) { |
1050 WebFrameView view = new WebFrameView(frameViewID); | 1101 WebFrameView view = new WebFrameView(frameViewID); |
1051 bool viewPrint = view.documentViewShouldHandlePrint(); | 1102 bool viewPrint = view.documentViewShouldHandlePrint(); |
1052 if (viewPrint) { | 1103 if (viewPrint) { |
1053 view.printDocumentView(); | 1104 view.printDocumentView(); |
1054 return; | 1105 return; |
1058 if (operation !is null) operation.runOperation(); | 1109 if (operation !is null) operation.runOperation(); |
1059 } | 1110 } |
1060 | 1111 |
1061 /* PolicyDelegate */ | 1112 /* PolicyDelegate */ |
1062 | 1113 |
1063 void webView_decidePolicyForMIMEType_request_frame_decisionListener(int /*long*/ sender, int /*long*/ type, int /*long*/ request, int /*long*/ frame, int /*long*/ listenerID) { | 1114 void webView_decidePolicyForMIMEType_request_frame_decisionListener(objc.id sender, objc.id type, objc.id request, objc.id frame, objc.id listenerID) { |
1064 bool canShow = WebView.canShowMIMEType(new NSString(type)); | 1115 bool canShow = WebView.canShowMIMEType(new NSString(type)); |
1065 WebPolicyDecisionListener listener = new WebPolicyDecisionListener(listenerID); | 1116 WebPolicyDecisionListener listener = new WebPolicyDecisionListener(listenerID); |
1066 if (canShow) { | 1117 if (canShow) { |
1067 listener.use(); | 1118 listener.use(); |
1068 } else { | 1119 } else { |
1069 listener.download(); | 1120 listener.download(); |
1070 } | 1121 } |
1071 } | 1122 } |
1072 | 1123 |
1073 void webView_decidePolicyForNavigationAction_request_frame_decisionListener(int /*long*/ sender, int /*long*/ actionInformation, int /*long*/ request, int /*long*/ frame, int /*long*/ listenerID) { | 1124 void webView_decidePolicyForNavigationAction_request_frame_decisionListener(objc.id sender, objc.id actionInformation, objc.id request, objc.id frame, objc.id listenerID) { |
1074 NSURL url = new NSURLRequest(request).URL(); | 1125 NSURL url = (new NSURLRequest(request)).URL(); |
1075 WebPolicyDecisionListener listener = new WebPolicyDecisionListener(listenerID); | 1126 WebPolicyDecisionListener listener = new WebPolicyDecisionListener(listenerID); |
1076 if (url is null) { | 1127 if (url is null) { |
1077 /* indicates that a URL with an invalid format was specified */ | 1128 /* indicates that a URL with an invalid format was specified */ |
1078 listener.ignore(); | 1129 listener.ignore(); |
1079 return; | 1130 return; |
1108 this.html = null; | 1159 this.html = null; |
1109 _setText(html); | 1160 _setText(html); |
1110 } | 1161 } |
1111 } | 1162 } |
1112 | 1163 |
1113 void webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener(int /*long*/ sender, int /*long*/ actionInformation, int /*long*/ request, int /*long*/ frameName, int /*long*/ listenerID) { | 1164 void webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener(objc.id sender, objc.id actionInformation, objc.id request, objc.id frameName, objc.id listenerID) { |
1114 WebPolicyDecisionListener listener = new WebPolicyDecisionListener(listenerID); | 1165 WebPolicyDecisionListener listener = new WebPolicyDecisionListener(listenerID); |
1115 listener.use(); | 1166 listener.use(); |
1116 } | 1167 } |
1117 | 1168 |
1118 void webView_unableToImplementPolicyWithError_frame(int /*long*/ sender, int /*long*/ error, int /*long*/ frame) { | 1169 void webView_unableToImplementPolicyWithError_frame(objc.id sender, objc.id error, objc.id frame) { |
1119 } | 1170 } |
1120 | 1171 |
1121 /* WebDownload */ | 1172 /* WebDownload */ |
1122 | 1173 |
1123 void download_decideDestinationWithSuggestedFilename(int /*long*/ downloadId, int /*long*/ filename) { | 1174 void download_decideDestinationWithSuggestedFilename(objc.id downloadId, objc.id filename) { |
1124 NSString string = new NSString(filename); | 1175 NSString string = new NSString(filename); |
1125 String name = string.getString(); | 1176 String name = string.getString(); |
1126 FileDialog dialog = new FileDialog(browser.getShell(), DWT.SAVE); | 1177 FileDialog dialog = new FileDialog(browser.getShell(), DWT.SAVE); |
1127 dialog.setText(DWT.getMessage ("DWT_FileDownload")); //$NON-NLS-1$ | 1178 dialog.setText(DWT.getMessage ("DWT_FileDownload")); //$NON-NLS-1$ |
1128 dialog.setFileName(name); | 1179 dialog.setFileName(name); |
1136 download.setDestination(NSString.stringWith(path), true); | 1187 download.setDestination(NSString.stringWith(path), true); |
1137 } | 1188 } |
1138 | 1189 |
1139 /* DOMEventListener */ | 1190 /* DOMEventListener */ |
1140 | 1191 |
1141 void handleEvent(int /*long*/ evtId) { | 1192 void handleEvent(objc.id evtId) { |
1142 NSString string = new NSString(OS.objc_msgSend(evtId, OS.sel_type)); | 1193 NSString string = new NSString(OS.objc_msgSend(evtId, OS.sel_type)); |
1143 String type = string.getString(); | 1194 String type = string.getString(); |
1144 | 1195 |
1145 if (DOMEVENT_KEYDOWN.equals(type) || DOMEVENT_KEYUP.equals(type)) { | 1196 if (DOMEVENT_KEYDOWN.equals(type) || DOMEVENT_KEYUP.equals(type)) { |
1146 DOMKeyboardEvent event = new DOMKeyboardEvent(evtId); | 1197 DOMKeyboardEvent event = new DOMKeyboardEvent(evtId); |
1158 keyEvent.type = DWT.KeyDown; | 1209 keyEvent.type = DWT.KeyDown; |
1159 } else { | 1210 } else { |
1160 keyEvent.type = DWT.KeyUp; | 1211 keyEvent.type = DWT.KeyUp; |
1161 } | 1212 } |
1162 keyEvent.keyCode = translateKey(keyCode); | 1213 keyEvent.keyCode = translateKey(keyCode); |
1163 keyEvent.character = (char)charCode; | 1214 keyEvent.character = cast(char)charCode; |
1164 keyEvent.stateMask = (alt ? DWT.ALT : 0) | (ctrl ? DWT.CTRL : 0) | (shift ? DWT.SHIFT : 0) | (meta ? DWT.COMMAND : 0); | 1215 keyEvent.stateMask = (alt ? DWT.ALT : 0) | (ctrl ? DWT.CTRL : 0) | (shift ? DWT.SHIFT : 0) | (meta ? DWT.COMMAND : 0); |
1165 browser.notifyListeners(keyEvent.type, keyEvent); | 1216 browser.notifyListeners(keyEvent.type, keyEvent); |
1166 if (!keyEvent.doit) { | 1217 if (!keyEvent.doit) { |
1167 event.preventDefault(); | 1218 event.preventDefault(); |
1168 } | 1219 } |
1217 case 1: mouseEvent.stateMask |= DWT.BUTTON1; break; | 1268 case 1: mouseEvent.stateMask |= DWT.BUTTON1; break; |
1218 case 2: mouseEvent.stateMask |= DWT.BUTTON2; break; | 1269 case 2: mouseEvent.stateMask |= DWT.BUTTON2; break; |
1219 case 3: mouseEvent.stateMask |= DWT.BUTTON3; break; | 1270 case 3: mouseEvent.stateMask |= DWT.BUTTON3; break; |
1220 case 4: mouseEvent.stateMask |= DWT.BUTTON4; break; | 1271 case 4: mouseEvent.stateMask |= DWT.BUTTON4; break; |
1221 case 5: mouseEvent.stateMask |= DWT.BUTTON5; break; | 1272 case 5: mouseEvent.stateMask |= DWT.BUTTON5; break; |
1273 default: | |
1222 } | 1274 } |
1223 } else if (DOMEVENT_MOUSEMOVE.equals (type)) { | 1275 } else if (DOMEVENT_MOUSEMOVE.equals (type)) { |
1224 /* | 1276 /* |
1225 * Bug in Safari. Spurious and redundant mousemove events are received in | 1277 * Bug in Safari. Spurious and redundant mousemove events are received in |
1226 * various contexts, including following every MouseUp. The workaround is | 1278 * various contexts, including following every MouseUp. The workaround is |