Mercurial > projects > dwt-mac
diff 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 |
line wrap: on
line diff
--- a/dwt/browser/Safari.d Fri Jan 16 12:49:08 2009 +0100 +++ b/dwt/browser/Safari.d Fri Jan 16 23:35:40 2009 +0100 @@ -7,6 +7,9 @@ * * Contributors: * IBM Corporation - initial API and implementation + * + * Port to the D programming language: + * Jacob Carlborg <doob@me.com> *******************************************************************************/ module dwt.browser.Safari; @@ -16,7 +19,6 @@ import dwt.graphics.Point; import dwt.graphics.Rectangle; import dwt.internal.C; -import dwt.internal.Callback; import dwt.internal.Compatibility; import dwt.internal.cocoa.DOMDocument; import dwt.internal.cocoa.DOMKeyboardEvent; @@ -57,13 +59,26 @@ import dwt.widgets.Shell; import dwt.widgets.Widget; -class Safari extends WebBrowser { +import dwt.browser.Browser; +import dwt.browser.LocationEvent; +import dwt.browser.ProgressEvent; +import dwt.browser.ProgressListener; +import dwt.browser.StatusTextEvent; +import dwt.browser.TitleEvent; +import dwt.browser.TitleListener; +import dwt.browser.WebBrowser; +import dwt.browser.WindowEvent; +import Carbon = dwt.internal.c.Carbon; +import dwt.internal.objc.cocoa.Cocoa; +import objc = dwt.internal.objc.runtime; + +class Safari : WebBrowser { WebView webView; - SWTWebViewDelegate delegate; + SWTWebViewDelegate delegate_; bool changingLocation; String lastHoveredLinkURL; String html; - int /*long*/ identifier; + objc.id identifier; int resourceCount; String url = ""; //$NON-NLS-1$ Point location; @@ -74,36 +89,34 @@ // bool doit; static bool Initialized; - // the following Callbacks are never freed - static Callback Callback3, Callback4, Callback5, Callback6, Callback7; - static final int MIN_SIZE = 16; - static final int MAX_PROGRESS = 100; - static final String WebElementLinkURLKey = "WebElementLinkURL"; //$NON-NLS-1$ - static final String AGENT_STRING = "Safari/unknown"; //$NON-NLS-1$ - static final String URI_FROMMEMORY = "file:///"; //$NON-NLS-1$ - static final String PROTOCOL_FILE = "file://"; //$NON-NLS-1$ - static final String PROTOCOL_HTTP = "http://"; //$NON-NLS-1$ - static final String ABOUT_BLANK = "about:blank"; //$NON-NLS-1$ - static final String ADD_WIDGET_KEY = "dwt.internal.addWidget"; //$NON-NLS-1$ - static final String SAFARI_EVENTS_FIX_KEY = "dwt.internal.safariEventsFix"; //$NON-NLS-1$ - static final String DWT_OBJECT = "DWT_OBJECT"; //$NON-NLS-1$ + static const int MIN_SIZE = 16; + static const int MAX_PROGRESS = 100; + static const String WebElementLinkURLKey = "WebElementLinkURL"; //$NON-NLS-1$ + static const String AGENT_STRING = "Safari/unknown"; //$NON-NLS-1$ + static const String URI_FROMMEMORY = "file:///"; //$NON-NLS-1$ + static const String PROTOCOL_FILE = "file://"; //$NON-NLS-1$ + static const String PROTOCOL_HTTP = "http://"; //$NON-NLS-1$ + static const String ABOUT_BLANK = "about:blank"; //$NON-NLS-1$ + static const String ADD_WIDGET_KEY = "dwt.internal.addWidget"; //$NON-NLS-1$ + static const String SAFARI_EVENTS_FIX_KEY = "dwt.internal.safariEventsFix"; //$NON-NLS-1$ + static const String DWT_OBJECT = "DWT_OBJECT"; //$NON-NLS-1$ /* event strings */ - static final String DOMEVENT_KEYUP = "keyup"; //$NON-NLS-1$ - static final String DOMEVENT_KEYDOWN = "keydown"; //$NON-NLS-1$ - static final String DOMEVENT_MOUSEDOWN = "mousedown"; //$NON-NLS-1$ - static final String DOMEVENT_MOUSEUP = "mouseup"; //$NON-NLS-1$ - static final String DOMEVENT_MOUSEMOVE = "mousemove"; //$NON-NLS-1$ - static final String DOMEVENT_MOUSEWHEEL = "mousewheel"; //$NON-NLS-1$ + static const String DOMEVENT_KEYUP = "keyup"; //$NON-NLS-1$ + static const String DOMEVENT_KEYDOWN = "keydown"; //$NON-NLS-1$ + static const String DOMEVENT_MOUSEDOWN = "mousedown"; //$NON-NLS-1$ + static const String DOMEVENT_MOUSEUP = "mouseup"; //$NON-NLS-1$ + static const String DOMEVENT_MOUSEMOVE = "mousemove"; //$NON-NLS-1$ + static const String DOMEVENT_MOUSEWHEEL = "mousewheel"; //$NON-NLS-1$ - static { - NativeClearSessions = new Runnable() { + static this () { + NativeClearSessions = new class () Runnable { public void run() { NSHTTPCookieStorage storage = NSHTTPCookieStorage.sharedHTTPCookieStorage(); NSArray cookies = storage.cookies(); - int /*long*/ count = cookies.count(); - for (int i = 0; i < count; i++) { + NSUInteger count = cookies.count(); + for (NSUInteger i = 0; i < count; i++) { NSHTTPCookie cookie = new NSHTTPCookie(cookies.objectAtIndex(i)); if (cookie.isSessionOnly()) { storage.deleteCookie(cookie); @@ -115,31 +128,20 @@ public void create (Composite parent, int style) { String className = "SWTWebViewDelegate"; //$NON-NLS-1$ - if (OS.objc_lookUpClass(className) is 0) { - Class safariClass = this.getClass(); - Callback3 = new Callback(safariClass, "browserProc", 3); //$NON-NLS-1$ - int /*long*/ proc3 = Callback3.getAddress(); - if (proc3 is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); - Callback4 = new Callback(safariClass, "browserProc", 4); //$NON-NLS-1$ - int /*long*/ proc4 = Callback4.getAddress(); - if (proc4 is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); - Callback5 = new Callback(safariClass, "browserProc", 5); //$NON-NLS-1$ - int /*long*/ proc5 = Callback5.getAddress(); - if (proc5 is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); - Callback6 = new Callback(safariClass, "browserProc", 6); //$NON-NLS-1$ - int /*long*/ proc6 = Callback6.getAddress(); - if (proc6 is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); - Callback7 = new Callback(safariClass, "browserProc", 7); //$NON-NLS-1$ - int /*long*/ proc7 = Callback7.getAddress(); - if (proc7 is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); - int /*long*/ setFrameProc = OS.webView_setFrame_CALLBACK(proc4); - if (setFrameProc is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); + if (OS.objc_lookUpClass(className) is null) { + Class safariClass = this.classinfo; + objc.IMP proc3;// = cast(objc.IMP) &browserProc3; + objc.IMP proc4;// = cast(objc.IMP) &browserProc4; + objc.IMP proc5;// = cast(objc.IMP) &browserProc5; + objc.IMP proc6;// = cast(objc.IMP) &browserProc6; + objc.IMP proc7;// = cast(objc.IMP) &browserProc7; + objc.IMP setFrameProc = OS.webView_setFrame_CALLBACK(proc4); String types = "*"; //$NON-NLS-1$ - int size = C.PTR_SIZEOF, align = C.PTR_SIZEOF is 4 ? 2 : 3; + size_t size = C.PTR_SIZEOF, align_ = C.PTR_SIZEOF is 4 ? 2 : 3; - int /*long*/ cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0); - OS.class_addIvar(cls, DWT_OBJECT, size, (byte)align, types); + objc.Class cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSObject, className, 0); + OS.class_addIvar(cls, DWT_OBJECT, size, cast(byte)align_, types); OS.class_addMethod(cls, OS.sel_webView_didChangeLocationWithinPageForFrame_, proc4, "@:@@"); //$NON-NLS-1$ OS.class_addMethod(cls, OS.sel_webView_didFailProvisionalLoadWithError_forFrame_, proc5, "@:@@@"); //$NON-NLS-1$ OS.class_addMethod(cls, OS.sel_webView_didFinishLoadForFrame_, proc4, "@:@@"); //$NON-NLS-1$ @@ -180,26 +182,26 @@ * Override the default event mechanism to not send key events so * that the browser can send them by listening to the DOM instead. */ - browser.setData(SAFARI_EVENTS_FIX_KEY); + browser.setData(new ArrayWrapperString(SAFARI_EVENTS_FIX_KEY)); - WebView webView = (WebView)new WebView().alloc(); + WebView webView = cast(WebView)(new WebView()).alloc(); if (webView is null) DWT.error(DWT.ERROR_NO_HANDLES); webView.initWithFrame(browser.view.frame(), null, null); webView.setAutoresizingMask(OS.NSViewWidthSizable | OS.NSViewHeightSizable); - final SWTWebViewDelegate delegate = (SWTWebViewDelegate)new SWTWebViewDelegate().alloc().init(); + final SWTWebViewDelegate delegate_ = cast(SWTWebViewDelegate)(new SWTWebViewDelegate()).alloc().init(); Display display = browser.getDisplay(); - display.setData(ADD_WIDGET_KEY, new Object[] {delegate, browser}); - this.delegate = delegate; + display.setData(ADD_WIDGET_KEY, new ArrayWrapperObject([cast(Object) delegate_, browser])); + this.delegate_ = delegate_; this.webView = webView; browser.view.addSubview(webView); final NSNotificationCenter notificationCenter = NSNotificationCenter.defaultCenter(); - Listener listener = new Listener() { + Listener listener = new class () Listener { public void handleEvent(Event e) { switch (e.type) { case DWT.FocusIn: - Safari.this.webView.window().makeFirstResponder(Safari.this.webView); + this.outer.webView.window().makeFirstResponder(this.outer.webView); break; case DWT.Dispose: { /* make this handler run after other dispose listeners */ @@ -211,23 +213,24 @@ browser.notifyListeners (e.type, e); e.type = DWT.NONE; - e.display.setData(ADD_WIDGET_KEY, new Object[] {delegate, null}); + e.display.setData(ADD_WIDGET_KEY, new ArrayWrapperObject([delegate_, null])); - Safari.this.webView.setFrameLoadDelegate(null); - Safari.this.webView.setResourceLoadDelegate(null); - Safari.this.webView.setUIDelegate(null); - Safari.this.webView.setPolicyDelegate(null); - Safari.this.webView.setDownloadDelegate(null); - notificationCenter.removeObserver(delegate); + this.outer.webView.setFrameLoadDelegate(null); + this.outer.webView.setResourceLoadDelegate(null); + this.outer.webView.setUIDelegate(null); + this.outer.webView.setPolicyDelegate(null); + this.outer.webView.setDownloadDelegate(null); + notificationCenter.removeObserver(delegate_); - Safari.this.webView.release(); - Safari.this.webView = null; - Safari.this.delegate.release(); - Safari.this.delegate = null; + this.outer.webView.release(); + this.outer.webView = null; + this.outer.delegate_.release(); + this.outer.delegate_ = null; html = null; lastHoveredLinkURL = null; break; } + default: } } }; @@ -236,12 +239,12 @@ browser.addListener(DWT.KeyDown, listener); browser.addListener(DWT.FocusIn, listener); - webView.setFrameLoadDelegate(delegate); - webView.setResourceLoadDelegate(delegate); - webView.setUIDelegate(delegate); - notificationCenter.addObserver(delegate, OS.sel_handleNotification_, null, webView); - webView.setPolicyDelegate(delegate); - webView.setDownloadDelegate(delegate); + webView.setFrameLoadDelegate(delegate_); + webView.setResourceLoadDelegate(delegate_); + webView.setUIDelegate(delegate_); + notificationCenter.addObserver(delegate_, OS.sel_handleNotification_, null, webView); + webView.setPolicyDelegate(delegate_); + webView.setDownloadDelegate(delegate_); webView.setApplicationNameForUserAgent(NSString.stringWith(AGENT_STRING)); if (!Initialized) { @@ -256,10 +259,10 @@ return webView.goBack(); } -static int /*long*/ browserProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) { +static objc.id browserProc3(objc.id id, objc.SEL sel, objc.id arg0) { Widget widget = Display.getCurrent().findWidget(id); - if (widget is null) return 0; - Safari safari = (Safari)((Browser)widget).webBrowser; + if (widget is null) return null; + Safari safari = cast(Safari)(cast(Browser)widget).webBrowser; if (sel is OS.sel_handleNotification_) { safari.handleNotification(arg0); } else if (sel is OS.sel_webViewShow_) { @@ -273,13 +276,13 @@ } else if (sel is OS.sel_handleEvent_) { safari.handleEvent(arg0); } - return 0; + return null; } -static int /*long*/ browserProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1) { +static objc.id browserProc4(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1) { Widget widget = Display.getCurrent().findWidget(id); - if (widget is null) return 0; - Safari safari = (Safari)((Browser)widget).webBrowser; + if (widget is null) return null; + Safari safari = cast(Safari)(cast(Browser)widget).webBrowser; if (sel is OS.sel_webView_didChangeLocationWithinPageForFrame_) { safari.webView_didChangeLocationWithinPageForFrame(arg0, arg1); } else if (sel is OS.sel_webView_didFinishLoadForFrame_) { @@ -293,13 +296,13 @@ } else if (sel is OS.sel_webView_createWebViewWithRequest_) { return safari.webView_createWebViewWithRequest(arg0, arg1); } else if (sel is OS.sel_webView_setStatusBarVisible_) { - safari.webView_setStatusBarVisible(arg0, arg1 !is 0); + safari.webView_setStatusBarVisible(arg0, arg1 !is null); } else if (sel is OS.sel_webView_setResizable_) { - safari.webView_setResizable(arg0, arg1 !is 0); + safari.webView_setResizable(arg0, arg1 !is null); } else if (sel is OS.sel_webView_setStatusText_) { safari.webView_setStatusText(arg0, arg1); } else if (sel is OS.sel_webView_setToolbarsVisible_) { - safari.webView_setToolbarsVisible(arg0, arg1 !is 0); + safari.webView_setToolbarsVisible(arg0, arg1 !is null); } else if (sel is OS.sel_webView_runJavaScriptAlertPanelWithMessage_) { safari.webView_runJavaScriptAlertPanelWithMessage(arg0, arg1); } else if (sel is OS.sel_webView_runJavaScriptConfirmPanelWithMessage_) { @@ -311,13 +314,13 @@ } else if (sel is OS.sel_webView_printFrameView_) { safari.webView_printFrameView(arg0, arg1); } - return 0; + return null; } -static int /*long*/ browserProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2) { +static objc.id browserProc5(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1, objc.id arg2) { Widget widget = Display.getCurrent().findWidget(id); - if (widget is null) return 0; - Safari safari = (Safari)((Browser)widget).webBrowser; + if (widget is null) return null; + Safari safari = cast(Safari)(cast(Browser)widget).webBrowser; if (sel is OS.sel_webView_didFailProvisionalLoadWithError_forFrame_) { safari.webView_didFailProvisionalLoadWithError_forFrame(arg0, arg1, arg2); } else if (sel is OS.sel_webView_didReceiveTitle_forFrame_) { @@ -333,23 +336,23 @@ } else if (sel is OS.sel_webView_unableToImplementPolicyWithError_frame_) { safari.webView_unableToImplementPolicyWithError_frame(arg0, arg1, arg2); } - return 0; + return null; } -static int /*long*/ browserProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2, int /*long*/ arg3) { +static objc.id browserProc6(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1, objc.id arg2, objc.id arg3) { Widget widget = Display.getCurrent().findWidget(id); - if (widget is null) return 0; - Safari safari = (Safari)((Browser)widget).webBrowser; + if (widget is null) return null; + Safari safari = cast(Safari)(cast(Browser)widget).webBrowser; if (sel is OS.sel_webView_resource_didFailLoadingWithError_fromDataSource_) { safari.webView_resource_didFailLoadingWithError_fromDataSource(arg0, arg1, arg2, arg3); } - return 0; + return null; } -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) { +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) { Widget widget = Display.getCurrent().findWidget(id); - if (widget is null) return 0; - Safari safari = (Safari)((Browser)widget).webBrowser; + if (widget is null) return null; + Safari safari = cast(Safari)(cast(Browser)widget).webBrowser; if (sel is OS.sel_webView_resource_willSendRequest_redirectResponse_fromDataSource_) { return safari.webView_resource_willSendRequest_redirectResponse_fromDataSource(arg0, arg1, arg2, arg3, arg4); } else if (sel is OS.sel_webView_decidePolicyForMIMEType_request_frame_decisionListener_) { @@ -359,7 +362,7 @@ } else if (sel is OS.sel_webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener_) { safari.webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener(arg0, arg1, arg2, arg3, arg4); } - return 0; + return null; } public bool execute(String script) { @@ -428,15 +431,15 @@ html = null; if (url.indexOf('/') is 0) { - url = PROTOCOL_FILE + url; + url = PROTOCOL_FILE ~ url; } else if (url.indexOf(':') is -1) { - url = PROTOCOL_HTTP + url; + url = PROTOCOL_HTTP ~ url; } NSString str = NSString.stringWith(url); NSString unescapedStr = NSString.stringWith("%#"); //$NON-NLS-1$ - int /*long*/ ptr = OS.CFURLCreateStringByAddingPercentEscapes(0, str.id, unescapedStr.id, 0, OS.kCFStringEncodingUTF8); - NSString escapedString = new NSString(ptr); + Carbon.CFStringRef ptr = OS.CFURLCreateStringByAddingPercentEscapes(null, cast(Carbon.CFStringRef) str.id, cast(Carbon.CFStringRef) unescapedStr.id, null, OS.kCFStringEncodingUTF8); + NSString escapedString = new NSString(cast(objc.id) ptr); NSURL inURL = NSURL.URLWithString(escapedString); OS.CFRelease(ptr); NSURLRequest request = NSURLRequest.requestWithURL(inURL); @@ -452,13 +455,13 @@ /* WebFrameLoadDelegate */ -void webView_didChangeLocationWithinPageForFrame(int /*long*/ sender, int /*long*/ frameID) { +void webView_didChangeLocationWithinPageForFrame(objc.id sender, objc.id frameID) { WebFrame frame = new WebFrame(frameID); WebDataSource dataSource = frame.dataSource(); NSURLRequest request = dataSource.request(); NSURL url = request.URL(); NSString s = url.absoluteString(); - int length = (int)/*64*/s.length(); + NSUInteger length = s.length(); if (length is 0) return; String url2 = s.getString(); /* @@ -489,7 +492,7 @@ } } -void webView_didFailProvisionalLoadWithError_forFrame(int /*long*/ sender, int /*long*/ error, int /*long*/ frame) { +void webView_didFailProvisionalLoadWithError_forFrame(objc.id sender, objc.id error, objc.id frame) { if (frame is webView.mainFrame().id) { /* * Feature on Safari. The identifier is used here as a marker for the events @@ -504,11 +507,11 @@ * when the top frame has either finished loading (didFinishLoadForFrame * event) or failed (didFailProvisionalLoadWithError). */ - identifier = 0; + identifier = null; } NSError nserror = new NSError(error); - int /*long*/ errorCode = nserror.code(); + NSInteger errorCode = nserror.code(); if (errorCode <= OS.NSURLErrorBadURL) { NSString description = nserror.localizedDescription(); if (description !is null) { @@ -516,15 +519,15 @@ String urlString = null; NSDictionary info = nserror.userInfo(); if (info !is null) { - NSString key = new NSString(OS.NSErrorFailingURLStringKey()); + NSString key = new NSString(OS.NSErrorFailingURLStringKey_); id id = info.valueForKey(key); if (id !is null) { NSString url = new NSString(id); urlString = url.getString(); } } - String message = urlString !is null ? urlString + "\n\n" : ""; //$NON-NLS-1$ //$NON-NLS-2$ - message += Compatibility.getMessage ("DWT_Page_Load_Failed", new Object[] {descriptionString}); //$NON-NLS-1$ + String message = urlString !is null ? urlString ~ "\n\n" : ""; //$NON-NLS-1$ //$NON-NLS-2$ + message ~= Compatibility.getMessage ("DWT_Page_Load_Failed", [new ArrayWrapperString(descriptionString)]); //$NON-NLS-1$ MessageBox messageBox = new MessageBox(browser.getShell(), DWT.OK | DWT.ICON_ERROR); messageBox.setMessage(message); messageBox.open(); @@ -532,7 +535,7 @@ } } -void webView_didFinishLoadForFrame(int /*long*/ sender, int /*long*/ frameID) { +void webView_didFinishLoadForFrame(objc.id sender, objc.id frameID) { hookDOMMouseListeners(frameID); if (frameID is webView.mainFrame().id) { hookDOMKeyListeners(frameID); @@ -563,7 +566,19 @@ * so that the Browser does not crash if this is attempted. */ display.asyncExec( - new Runnable() { + new class (display, browser, listener) Runnable { + + Display display; + Browser browser; + TitleListener listener; + + this (Display display, Browser browser, TitleListener listener) + { + this.display = display; + this.browser = browser; + this.listener = listener; + } + public void run() { if (!display.isDisposed() && !browser.isDisposed()) { listener.changed(newEvent); @@ -591,7 +606,19 @@ * selection of the ProgressBar. */ display.asyncExec( - new Runnable() { + new class (display, browser, listener) Runnable { + + Display display; + Browser browser; + ProgressListener listener; + + this (Display display, Browser browser, ProgressListener listener) + { + this.display = display; + this.browser = browser; + this.listener = listener; + } + public void run() { if (!display.isDisposed() && !browser.isDisposed()) { listener.completed(progress); @@ -613,39 +640,39 @@ * when the top frame has either finished loading (didFinishLoadForFrame * event) or failed (didFailProvisionalLoadWithError). */ - identifier = 0; + identifier = null; } } -void hookDOMKeyListeners(int /*long*/ frameID) { +void hookDOMKeyListeners(objc.id frameID) { WebFrame frame = new WebFrame(frameID); - DOMDocument document = frame.DOMDocument(); + DOMDocument document = frame.DOMDocument_(); NSString type = NSString.stringWith(DOMEVENT_KEYDOWN); - document.addEventListener(type, delegate, false); + document.addEventListener(type, delegate_, false); type = NSString.stringWith(DOMEVENT_KEYUP); - document.addEventListener(type, delegate, false); + document.addEventListener(type, delegate_, false); } -void hookDOMMouseListeners(int /*long*/ frameID) { +void hookDOMMouseListeners(objc.id frameID) { WebFrame frame = new WebFrame(frameID); - DOMDocument document = frame.DOMDocument(); + DOMDocument document = frame.DOMDocument_(); NSString type = NSString.stringWith(DOMEVENT_MOUSEDOWN); - document.addEventListener(type, delegate, false); + document.addEventListener(type, delegate_, false); type = NSString.stringWith(DOMEVENT_MOUSEUP); - document.addEventListener(type, delegate, false); + document.addEventListener(type, delegate_, false); type = NSString.stringWith(DOMEVENT_MOUSEMOVE); - document.addEventListener(type, delegate, false); + document.addEventListener(type, delegate_, false); type = NSString.stringWith(DOMEVENT_MOUSEWHEEL); - document.addEventListener(type, delegate, false); + document.addEventListener(type, delegate_, false); } -void webView_didReceiveTitle_forFrame(int /*long*/ sender, int /*long*/ titleID, int /*long*/ frameID) { +void webView_didReceiveTitle_forFrame(objc.id sender, objc.id titleID, objc.id frameID) { if (frameID is webView.mainFrame().id) { NSString title = new NSString(titleID); String newTitle = title.getString(); @@ -659,7 +686,7 @@ } } -void webView_didStartProvisionalLoadForFrame(int /*long*/ sender, int /*long*/ frameID) { +void webView_didStartProvisionalLoadForFrame(objc.id sender, objc.id frameID) { /* * This code is intentionally commented. WebFrameLoadDelegate:didStartProvisionalLoadForFrame is * called before WebResourceLoadDelegate:willSendRequest and @@ -672,13 +699,13 @@ // } } -void webView_didCommitLoadForFrame(int /*long*/ sender, int /*long*/ frameID) { +void webView_didCommitLoadForFrame(objc.id sender, objc.id frameID) { WebFrame frame = new WebFrame(frameID); WebDataSource dataSource = frame.dataSource(); NSURLRequest request = dataSource.request(); NSURL url = request.URL(); NSString s = url.absoluteString(); - int length = (int)/*64*/s.length(); + NSUInteger length = s.length(); if (length is 0) return; String url2 = s.getString(); /* @@ -711,7 +738,19 @@ * selection of the ProgressBar. */ display.asyncExec( - new Runnable() { + new class (display, browser, listener) Runnable { + + Display display; + Browser browser; + ProgressListener listener; + + this (Display display, Browser browser, ProgressListener listener) + { + this.display = display; + this.browser = browser; + this.listener = listener; + } + public void run() { if (!display.isDisposed() && !browser.isDisposed()) listener.changed(progress); @@ -740,7 +779,7 @@ /* WebResourceLoadDelegate */ -void webView_resource_didFinishLoadingFromDataSource(int /*long*/ sender, int /*long*/ identifier, int /*long*/ dataSource) { +void webView_resource_didFinishLoadingFromDataSource(objc.id sender, objc.id identifier, objc.id dataSource) { /* * Feature on Safari. The identifier is used here as a marker for the events * related to the top frame and the URL changes related to that top frame as @@ -758,7 +797,7 @@ //if (this.identifier is identifier) this.identifier = 0; } -void webView_resource_didFailLoadingWithError_fromDataSource(int /*long*/ sender, int /*long*/ identifier, int /*long*/ error, int /*long*/ dataSource) { +void webView_resource_didFailLoadingWithError_fromDataSource(objc.id sender, objc.id identifier, objc.id error, objc.id dataSource) { /* * Feature on Safari. The identifier is used here as a marker for the events * related to the top frame and the URL changes related to that top frame as @@ -776,7 +815,7 @@ //if (this.identifier is identifier) this.identifier = 0; } -int /*long*/ webView_identifierForInitialRequest_fromDataSource(int /*long*/ sender, int /*long*/ request, int /*long*/ dataSourceID) { +objc.id webView_identifierForInitialRequest_fromDataSource(objc.id sender, objc.id request, objc.id dataSourceID) { final Display display = browser.getDisplay(); final ProgressEvent progress = new ProgressEvent(browser); progress.display = display; @@ -795,7 +834,19 @@ * selection of the ProgressBar. */ display.asyncExec( - new Runnable() { + new class (display, browser, listener) Runnable { + + Display display; + Browser browser; + ProgressListener listener; + + this (Display display, Browser browser, ProgressListener listener) + { + this.display = display; + this.browser = browser; + this.listener = listener; + } + public void run() { if (!display.isDisposed() && !browser.isDisposed()) listener.changed(progress); @@ -805,7 +856,7 @@ } NSNumber identifier = NSNumber.numberWithInt(resourceCount++); - if (this.identifier is 0) { + if (this.identifier is null) { WebDataSource dataSource = new WebDataSource(dataSourceID); WebFrame frame = dataSource.webFrame(); if (frame.id is webView.mainFrame().id) this.identifier = identifier.id; @@ -814,18 +865,18 @@ } -int /*long*/ webView_resource_willSendRequest_redirectResponse_fromDataSource(int /*long*/ sender, int /*long*/ identifier, int /*long*/ request, int /*long*/ redirectResponse, int /*long*/ dataSource) { +objc.id webView_resource_willSendRequest_redirectResponse_fromDataSource(objc.id sender, objc.id identifier, objc.id request, objc.id redirectResponse, objc.id dataSource) { return request; } /* handleNotification */ -void handleNotification(int /*long*/ notification) { +void handleNotification(objc.id notification) { } /* UIDelegate */ -int /*long*/ webView_createWebViewWithRequest(int /*long*/ sender, int /*long*/ request) { +objc.id webView_createWebViewWithRequest(objc.id sender, objc.id request) { WindowEvent newEvent = new WindowEvent(browser); newEvent.display = browser.getDisplay(); newEvent.widget = browser; @@ -837,20 +888,20 @@ } WebView result = null; Browser browser = null; - if (newEvent.browser !is null && newEvent.browser.webBrowser instanceof Safari) { + if (newEvent.browser !is null && cast(Safari) newEvent.browser.webBrowser) { browser = newEvent.browser; } if (browser !is null && !browser.isDisposed()) { - result = ((Safari)browser.webBrowser).webView; - if (request !is 0) { + result = (cast(Safari)browser.webBrowser).webView; + if (request !is null) { WebFrame mainFrame = webView.mainFrame(); mainFrame.loadRequest(new NSURLRequest(request)); } } - return result !is null ? result.id : 0; + return result !is null ? result.id : null; } -void webViewShow(int /*long*/ sender) { +void webViewShow(objc.id sender) { /* * Feature on WebKit. The Safari WebKit expects the application * to create a new Window using the Objective C Cocoa API in response @@ -890,22 +941,22 @@ size = null; } -void webView_setFrame(int /*long*/ sender, int /*long*/ frame) { +void webView_setFrame(objc.id sender, objc.id frame) { NSRect rect = NSRect(); - OS.memmove(rect, frame, NSRect.sizeof); + OS.memmove(&rect, frame, NSRect.sizeof); /* convert to DWT system coordinates */ Rectangle bounds = browser.getDisplay().getBounds(); - location = new Point((int)rect.x, bounds.height - (int)rect.y - (int)rect.height); - size = new Point((int)rect.width, (int)rect.height); + location = new Point(cast(int)rect.x, bounds.height - cast(int)rect.y - cast(int)rect.height); + size = new Point(cast(int)rect.width, cast(int)rect.height); } -void webViewFocus(int /*long*/ sender) { +void webViewFocus(objc.id sender) { } -void webViewUnfocus(int /*long*/ sender) { +void webViewUnfocus(objc.id sender) { } -void webView_runJavaScriptAlertPanelWithMessage(int /*long*/ sender, int /*long*/ messageID) { +void webView_runJavaScriptAlertPanelWithMessage(objc.id sender, objc.id messageID) { NSString message = new NSString(messageID); String text = message.getString(); @@ -915,17 +966,17 @@ messageBox.open(); } -int webView_runJavaScriptConfirmPanelWithMessage(int /*long*/ sender, int /*long*/ messageID) { +objc.id webView_runJavaScriptConfirmPanelWithMessage(objc.id sender, objc.id messageID) { NSString message = new NSString(messageID); String text = message.getString(); MessageBox messageBox = new MessageBox(browser.getShell(), DWT.OK | DWT.CANCEL | DWT.ICON_QUESTION); messageBox.setText("Javascript"); //$NON-NLS-1$ messageBox.setMessage(text); - return messageBox.open() is DWT.OK ? 1 : 0; + return messageBox.open() is DWT.OK ? cast(objc.id) 1 : null; } -void webView_runOpenPanelForFileButtonWithResultListener(int /*long*/ sender, int /*long*/ resultListenerID) { +void webView_runOpenPanelForFileButtonWithResultListener(objc.id sender, objc.id resultListenerID) { FileDialog dialog = new FileDialog(browser.getShell(), DWT.NONE); String result = dialog.open(); WebOpenPanelResultListener resultListener = new WebOpenPanelResultListener(resultListenerID); @@ -936,7 +987,7 @@ resultListener.chooseFilename(NSString.stringWith(result)); } -void webViewClose(int /*long*/ sender) { +void webViewClose(objc.id sender) { Shell parent = browser.getShell(); WindowEvent newEvent = new WindowEvent(browser); newEvent.display = browser.getDisplay(); @@ -961,32 +1012,32 @@ parent.setSize(pt.x, pt.y); } -int /*long*/ webView_contextMenuItemsForElement_defaultMenuItems(int /*long*/ sender, int /*long*/ element, int /*long*/ defaultMenuItems) { +objc.id webView_contextMenuItemsForElement_defaultMenuItems(objc.id sender, objc.id element, objc.id defaultMenuItems) { Point pt = browser.getDisplay().getCursorLocation(); Event event = new Event(); event.x = pt.x; event.y = pt.y; browser.notifyListeners(DWT.MenuDetect, event); Menu menu = browser.getMenu(); - if (!event.doit) return 0; + if (!event.doit) return null; if (menu !is null && !menu.isDisposed()) { if (event.x !is pt.x || event.y !is pt.y) { menu.setLocation(event.x, event.y); } menu.setVisible(true); - return 0; + return null; } return defaultMenuItems; } -void webView_setStatusBarVisible(int /*long*/ sender, bool visible) { +void webView_setStatusBarVisible(objc.id sender, bool visible) { /* Note. Webkit only emits the notification when the status bar should be hidden. */ statusBar = visible; } -void webView_setStatusText(int /*long*/ sender, int /*long*/ textID) { +void webView_setStatusText(objc.id sender, objc.id textID) { NSString text = new NSString(textID); - int length = (int)/*64*/text.length(); + NSUInteger length = text.length(); if (length is 0) return; StatusTextEvent statusText = new StatusTextEvent(browser); @@ -998,16 +1049,16 @@ } } -void webView_setResizable(int /*long*/ sender, bool visible) { +void webView_setResizable(objc.id sender, bool visible) { } -void webView_setToolbarsVisible(int /*long*/ sender, bool visible) { +void webView_setToolbarsVisible(objc.id sender, bool visible) { /* Note. Webkit only emits the notification when the tool bar should be hidden. */ toolBar = visible; } -void webView_mouseDidMoveOverElement_modifierFlags (int /*long*/ sender, int /*long*/ elementInformationID, int /*long*/ modifierFlags) { - if (elementInformationID is 0) return; +void webView_mouseDidMoveOverElement_modifierFlags (objc.id sender, objc.id elementInformationID, objc.id modifierFlags) { + if (elementInformationID is null) return; NSString key = NSString.stringWith(WebElementLinkURLKey); NSDictionary elementInformation = new NSDictionary(elementInformationID); @@ -1026,8 +1077,8 @@ return; } - NSString url = new NSURL(value.id).absoluteString(); - int length = (int)/*64*/url.length(); + NSString url = (new NSURL(value.id)).absoluteString(); + NSUInteger length = url.length(); String urlString; if (length is 0) { urlString = ""; //$NON-NLS-1$ @@ -1046,7 +1097,7 @@ } } -void webView_printFrameView (int /*long*/ sender, int /*long*/ frameViewID) { +void webView_printFrameView (objc.id sender, objc.id frameViewID) { WebFrameView view = new WebFrameView(frameViewID); bool viewPrint = view.documentViewShouldHandlePrint(); if (viewPrint) { @@ -1060,7 +1111,7 @@ /* PolicyDelegate */ -void webView_decidePolicyForMIMEType_request_frame_decisionListener(int /*long*/ sender, int /*long*/ type, int /*long*/ request, int /*long*/ frame, int /*long*/ listenerID) { +void webView_decidePolicyForMIMEType_request_frame_decisionListener(objc.id sender, objc.id type, objc.id request, objc.id frame, objc.id listenerID) { bool canShow = WebView.canShowMIMEType(new NSString(type)); WebPolicyDecisionListener listener = new WebPolicyDecisionListener(listenerID); if (canShow) { @@ -1070,8 +1121,8 @@ } } -void webView_decidePolicyForNavigationAction_request_frame_decisionListener(int /*long*/ sender, int /*long*/ actionInformation, int /*long*/ request, int /*long*/ frame, int /*long*/ listenerID) { - NSURL url = new NSURLRequest(request).URL(); +void webView_decidePolicyForNavigationAction_request_frame_decisionListener(objc.id sender, objc.id actionInformation, objc.id request, objc.id frame, objc.id listenerID) { + NSURL url = (new NSURLRequest(request)).URL(); WebPolicyDecisionListener listener = new WebPolicyDecisionListener(listenerID); if (url is null) { /* indicates that a URL with an invalid format was specified */ @@ -1110,17 +1161,17 @@ } } -void webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener(int /*long*/ sender, int /*long*/ actionInformation, int /*long*/ request, int /*long*/ frameName, int /*long*/ listenerID) { +void webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener(objc.id sender, objc.id actionInformation, objc.id request, objc.id frameName, objc.id listenerID) { WebPolicyDecisionListener listener = new WebPolicyDecisionListener(listenerID); listener.use(); } -void webView_unableToImplementPolicyWithError_frame(int /*long*/ sender, int /*long*/ error, int /*long*/ frame) { +void webView_unableToImplementPolicyWithError_frame(objc.id sender, objc.id error, objc.id frame) { } /* WebDownload */ -void download_decideDestinationWithSuggestedFilename(int /*long*/ downloadId, int /*long*/ filename) { +void download_decideDestinationWithSuggestedFilename(objc.id downloadId, objc.id filename) { NSString string = new NSString(filename); String name = string.getString(); FileDialog dialog = new FileDialog(browser.getShell(), DWT.SAVE); @@ -1138,7 +1189,7 @@ /* DOMEventListener */ -void handleEvent(int /*long*/ evtId) { +void handleEvent(objc.id evtId) { NSString string = new NSString(OS.objc_msgSend(evtId, OS.sel_type)); String type = string.getString(); @@ -1160,7 +1211,7 @@ keyEvent.type = DWT.KeyUp; } keyEvent.keyCode = translateKey(keyCode); - keyEvent.character = (char)charCode; + keyEvent.character = cast(char)charCode; keyEvent.stateMask = (alt ? DWT.ALT : 0) | (ctrl ? DWT.CTRL : 0) | (shift ? DWT.SHIFT : 0) | (meta ? DWT.COMMAND : 0); browser.notifyListeners(keyEvent.type, keyEvent); if (!keyEvent.doit) { @@ -1219,6 +1270,7 @@ case 3: mouseEvent.stateMask |= DWT.BUTTON3; break; case 4: mouseEvent.stateMask |= DWT.BUTTON4; break; case 5: mouseEvent.stateMask |= DWT.BUTTON5; break; + default: } } else if (DOMEVENT_MOUSEMOVE.equals (type)) { /*