e.display.setData(ADD_WIDGET_KEY, new Object[] {new Integer(webViewHandle), null}); WebKit.objc_msgSend(notificationCenter, WebKit.S_removeObserver_name_object, delegate, 0, webView); WebKit.objc_msgSend(delegate, WebKit.S_release);
WebKit.objc_msgSend(webView, WebKit.S_setFrameLoadDelegate, 0); WebKit.objc_msgSend(webView, WebKit.S_setResourceLoadDelegate, 0); WebKit.objc_msgSend(webView, WebKit.S_setUIDelegate, 0); WebKit.objc_msgSend(webView, WebKit.S_setPolicyDelegate, 0); WebKit.objc_msgSend(notificationCenter, WebKit.S_removeObserver, delegate);  WebKit.objc_msgSend(delegate, WebKit.S_release);
		public void handleEvent(Event e) {			switch (e.type) {				case SWT.Dispose: {					Shell shell = getShell();					shell.removeListener(SWT.Resize, this);					shell.removeListener(SWT.Show, this);					shell.removeListener(SWT.Hide, this);					Control c = Browser.this;					do {						c.removeListener(SWT.Show, this);						c.removeListener(SWT.Hide, this);						c = c.getParent();					} while (c != shell);					e.display.setData(ADD_WIDGET_KEY, new Object[] {new Integer(webViewHandle), null});					WebKit.objc_msgSend(notificationCenter, WebKit.S_removeObserver_name_object, delegate, 0, webView);					WebKit.objc_msgSend(delegate, WebKit.S_release);					break;				}				case SWT.Hide: {					/*					* Bug on Safari. The web view cannot be obscured by other views above it.					* This problem is specified in the apple documentation for HiWebViewCreate.					* The workaround is to hook Hide and Show events on the browser's parents					* and set its size to 0 in Hide and to restore its size in Show.					*/					CGRect bounds = new CGRect();					OS.HIViewSetFrame(webViewHandle, bounds);					break;				}				case SWT.Show: {					if (!added && e.widget == getShell()) {						/*						* Bug in Safari. The WebView must be added after the top window is visible						* or it eats mouse events from the top window. A second issue is that the WebView 						* does not receive mouse and key events when it is added to a visible top window. 						* It is assumed that Safari hooks its own event listener when the top window 						* emits the kEventWindowShown event. The workaround to the first problem is to add						* the WebView to the HIView after the top window is visible. The workaround to the second						* problem is to send a fake kEventWindowShown event to the top window after the WebView						* has been added to the HIView (after the top window is visible) to give Safari a chance						* to hook events.						* 						* Note. SWT.Show is sent before the Shell is actually visible. The workaround is to						* add the WebView to the HiView from an asyncExec, after this notification has returned and						* made the Shell visible.						* Note. Because the Shell is already visible when WebView is added to the HiView and the real						* kEventWindowShow event has therefore been sent already, we need to send a fake kEventWindowShown						* event so that Safari can hook its events.						*/						final Shell shell = getShell();						getDisplay().asyncExec(new Runnable() { 							public void run() {								if (isDisposed() || shell.isDisposed()) return;								if (added || !shell.isVisible()) return;								added = true;								OS.HIViewAddSubview(handle, webViewHandle);								OS.HIViewSetVisible(webViewHandle, true);								int[] showEvent = new int[1];								OS.CreateEvent(0, OS.kEventClassWindow, OS.kEventWindowShown, 0.0, OS.kEventAttributeUserEvent, showEvent);								OS.SetEventParameter(showEvent[0], OS.kEventParamDirectObject, OS.typeWindowRef, 4, new int[] {OS.GetControlOwner(handle)});								OS.SendEventToEventTarget(showEvent[0], OS.GetWindowEventTarget(OS.GetControlOwner(handle)));								if (showEvent[0] != 0) OS.ReleaseEvent(showEvent[0]);								CGRect bounds = new CGRect();								OS.HIViewGetFrame(handle, bounds);								/* 								* Note.  Setting negative width or height causes Safari to always								* display incorrectly even if further resize events are correct.								*/								if (bounds.width < 0) bounds.width = 0;								if (bounds.height < 0) bounds.height = 0;								OS.HIViewSetFrame(webViewHandle, bounds);														}						});					}					/*					* Bug on Safari. The web view cannot be obscured by other views above it.					* This problem is specified in the apple documentation for HiWebViewCreate.					* The workaround is to hook Hide and Show events on the browser's parents					* and set its size to 0 in Hide and to restore its size in Show.					*/					CGRect bounds = new CGRect();					OS.HIViewGetFrame(handle, bounds);					OS.HIViewSetFrame(webViewHandle, bounds);					break;				}				case SWT.Resize: {					System.out.println("Browser Resize");					/*					* Bug on Safari. Resizing the height of a Shell containing a Browser at					* a fixed location causes the Browser to redraw at a wrong location.					* The web view is a HIView container that internally hosts					* a Cocoa NSView that uses a coordinates system with the origin at the					* bottom left corner of a window instead of the coordinates system used					* in Carbon that starts at the top left corner. The workaround is to					* reposition the web view every time the Shell of the Browser is resized.					* 					* Feature on Safari. The HIView ignores the call to update its position					* because it believes it has not changed. The workaround is to force					* it to reposition by changing its size and setting it back to the					* original value.					* 					*/					/* If the widget is hidden, leave its size to 0,0 as set in the SWT.Hide callback */					if (!isVisible()) break;					CGRect bounds = new CGRect();					OS.HIViewGetFrame(handle, bounds);					/* 					* Note.  Setting negative width or height causes Safari to always					* display incorrectly even if further resize events are correct.					*/					if (bounds.width < 0) bounds.width = 0;					if (bounds.height < 0) bounds.height = 0;					OS.HIViewSetFrame(webViewHandle, bounds);					/*					* Bug on Webkit. Resizing a Cocoa WebView in a Carbon window does not					* redraw the new area of the WebView. The workaround is to call Display.update.					* That call invokes UpdateControls on the Carbon window and that causes the					* Cocoa view to redraw correctly.					*/					e.display.update();					break;				}			}		}