Mercurial > projects > dwt-mac
annotate dwt/browser/Safari.d @ 46:cfa563df4fdd
Updated Widget and Display to 3.514
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Fri, 05 Dec 2008 16:00:41 +0100 |
parents | d8635bb48c7c |
children | 5583f8eeee6c |
rev | line source |
---|---|
45 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
3 * All rights reserved. This program and the accompanying materials |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
5 * which accompanies this distribution, and is available at |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
6 * http://www.eclipse.org/legal/epl-v10.html |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
7 * |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
8 * Contributors: |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
9 * IBM Corporation - initial API and implementation |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
10 *******************************************************************************/ |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
11 module dwt.browser.Safari; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
12 |
45 | 13 import dwt.dwthelper.utils; |
14 | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
15 import dwt.DWT; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
16 import dwt.graphics.Point; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
17 import dwt.graphics.Rectangle; |
45 | 18 import dwt.internal.C; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
19 import dwt.internal.Callback; |
45 | 20 import dwt.internal.Compatibility; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
21 import dwt.internal.cocoa.DOMDocument; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
22 import dwt.internal.cocoa.DOMKeyboardEvent; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
23 import dwt.internal.cocoa.DOMMouseEvent; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
24 import dwt.internal.cocoa.DOMWheelEvent; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
25 import dwt.internal.cocoa.NSArray; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
26 import dwt.internal.cocoa.NSDictionary; |
45 | 27 import dwt.internal.cocoa.NSError; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
28 import dwt.internal.cocoa.NSHTTPCookie; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
29 import dwt.internal.cocoa.NSHTTPCookieStorage; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
30 import dwt.internal.cocoa.NSNotificationCenter; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
31 import dwt.internal.cocoa.NSNumber; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
32 import dwt.internal.cocoa.NSPrintInfo; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
33 import dwt.internal.cocoa.NSPrintOperation; |
45 | 34 import dwt.internal.cocoa.NSRect; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
35 import dwt.internal.cocoa.NSString; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
36 import dwt.internal.cocoa.NSURL; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
37 import dwt.internal.cocoa.NSURLDownload; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
38 import dwt.internal.cocoa.NSURLRequest; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
39 import dwt.internal.cocoa.OS; |
35
7d135fe0caf2
Ported dwt.graphics.Cursor and dwt.widgets.MenuItem
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
13
diff
changeset
|
40 import dwt.internal.cocoa.SWTWebViewDelegate; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
41 import dwt.internal.cocoa.WebDataSource; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
42 import dwt.internal.cocoa.WebDocumentRepresentation; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
43 import dwt.internal.cocoa.WebFrame; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
44 import dwt.internal.cocoa.WebFrameView; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
45 import dwt.internal.cocoa.WebOpenPanelResultListener; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
46 import dwt.internal.cocoa.WebPolicyDecisionListener; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
47 import dwt.internal.cocoa.WebPreferences; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
48 import dwt.internal.cocoa.WebView; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
49 import dwt.internal.cocoa.id; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
50 import dwt.widgets.Composite; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
51 import dwt.widgets.Display; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
52 import dwt.widgets.Event; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
53 import dwt.widgets.FileDialog; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
54 import dwt.widgets.Listener; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
55 import dwt.widgets.Menu; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
56 import dwt.widgets.MessageBox; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
57 import dwt.widgets.Shell; |
45 | 58 import dwt.widgets.Widget; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
59 |
45 | 60 class Safari extends WebBrowser { |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
61 WebView webView; |
45 | 62 SWTWebViewDelegate delegate; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
63 bool changingLocation; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
64 String lastHoveredLinkURL; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
65 String html; |
45 | 66 int /*long*/ identifier; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
67 int resourceCount; |
45 | 68 String url = ""; //$NON-NLS-1$ |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
69 Point location; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
70 Point size; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
71 bool statusBar = true, toolBar = true, ignoreDispose; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
72 int lastMouseMoveX, lastMouseMoveY; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
73 //TEMPORARY CODE |
45 | 74 // bool doit; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
75 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
76 static bool Initialized; |
45 | 77 // the following Callbacks are never freed |
78 static Callback Callback3, Callback4, Callback5, Callback6, Callback7; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
79 |
45 | 80 static final int MIN_SIZE = 16; |
81 static final int MAX_PROGRESS = 100; | |
82 static final String WebElementLinkURLKey = "WebElementLinkURL"; //$NON-NLS-1$ | |
83 static final String AGENT_STRING = "Safari/unknown"; //$NON-NLS-1$ | |
84 static final String URI_FROMMEMORY = "file:///"; //$NON-NLS-1$ | |
85 static final String PROTOCOL_FILE = "file://"; //$NON-NLS-1$ | |
86 static final String PROTOCOL_HTTP = "http://"; //$NON-NLS-1$ | |
87 static final String ABOUT_BLANK = "about:blank"; //$NON-NLS-1$ | |
88 static final String ADD_WIDGET_KEY = "dwt.internal.addWidget"; //$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$ | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
91 |
45 | 92 /* event strings */ |
93 static final String DOMEVENT_KEYUP = "keyup"; //$NON-NLS-1$ | |
94 static final String DOMEVENT_KEYDOWN = "keydown"; //$NON-NLS-1$ | |
95 static final String DOMEVENT_MOUSEDOWN = "mousedown"; //$NON-NLS-1$ | |
96 static final String DOMEVENT_MOUSEUP = "mouseup"; //$NON-NLS-1$ | |
97 static final String DOMEVENT_MOUSEMOVE = "mousemove"; //$NON-NLS-1$ | |
98 static final String DOMEVENT_MOUSEWHEEL = "mousewheel"; //$NON-NLS-1$ | |
99 | |
100 static { | |
101 NativeClearSessions = new Runnable() { | |
102 public void run() { | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
103 NSHTTPCookieStorage storage = NSHTTPCookieStorage.sharedHTTPCookieStorage(); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
104 NSArray cookies = storage.cookies(); |
45 | 105 int /*long*/ count = cookies.count(); |
106 for (int i = 0; i < count; i++) { | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
107 NSHTTPCookie cookie = new NSHTTPCookie(cookies.objectAtIndex(i)); |
45 | 108 if (cookie.isSessionOnly()) { |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
109 storage.deleteCookie(cookie); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
110 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
111 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
112 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
113 }; |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
114 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
115 |
45 | 116 public void create (Composite parent, int style) { |
117 String className = "SWTWebViewDelegate"; //$NON-NLS-1$ | |
118 if (OS.objc_lookUpClass(className) is 0) { | |
119 Class safariClass = this.getClass(); | |
120 Callback3 = new Callback(safariClass, "browserProc", 3); //$NON-NLS-1$ | |
121 int /*long*/ proc3 = Callback3.getAddress(); | |
122 if (proc3 is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); | |
123 Callback4 = new Callback(safariClass, "browserProc", 4); //$NON-NLS-1$ | |
124 int /*long*/ proc4 = Callback4.getAddress(); | |
125 if (proc4 is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); | |
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); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
137 |
45 | 138 String types = "*"; //$NON-NLS-1$ |
139 int size = C.PTR_SIZEOF, align = C.PTR_SIZEOF is 4 ? 2 : 3; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
140 |
45 | 141 int /*long*/ cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0); |
142 OS.class_addIvar(cls, DWT_OBJECT, size, (byte)align, types); | |
143 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$ | |
145 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$ | |
147 OS.class_addMethod(cls, OS.sel_webView_didStartProvisionalLoadForFrame_, proc4, "@:@@"); //$NON-NLS-1$ | |
148 OS.class_addMethod(cls, OS.sel_webView_didCommitLoadForFrame_, proc4, "@:@@"); //$NON-NLS-1$ | |
149 OS.class_addMethod(cls, OS.sel_webView_resource_didFinishLoadingFromDataSource_, proc5, "@:@@@"); //$NON-NLS-1$ | |
150 OS.class_addMethod(cls, OS.sel_webView_resource_didFailLoadingWithError_fromDataSource_, proc6, "@:@@@@"); //$NON-NLS-1$ | |
151 OS.class_addMethod(cls, OS.sel_webView_identifierForInitialRequest_fromDataSource_, proc5, "@:@@@"); //$NON-NLS-1$ | |
152 OS.class_addMethod(cls, OS.sel_webView_resource_willSendRequest_redirectResponse_fromDataSource_, proc7, "@:@@@@@"); //$NON-NLS-1$ | |
153 OS.class_addMethod(cls, OS.sel_handleNotification_, proc3, "@:@"); //$NON-NLS-1$ | |
154 OS.class_addMethod(cls, OS.sel_webView_createWebViewWithRequest_, proc4, "@:@@"); //$NON-NLS-1$ | |
155 OS.class_addMethod(cls, OS.sel_webViewShow_, proc3, "@:@"); //$NON-NLS-1$ | |
156 OS.class_addMethod(cls, OS.sel_webViewClose_, proc3, "@:@"); //$NON-NLS-1$ | |
157 OS.class_addMethod(cls, OS.sel_webView_contextMenuItemsForElement_defaultMenuItems_, proc5, "@:@@@"); //$NON-NLS-1$ | |
158 OS.class_addMethod(cls, OS.sel_webView_setStatusBarVisible_, proc4, "@:@B"); //$NON-NLS-1$ | |
159 OS.class_addMethod(cls, OS.sel_webView_setResizable_, proc4, "@:@B"); //$NON-NLS-1$ | |
160 OS.class_addMethod(cls, OS.sel_webView_setToolbarsVisible_, proc4, "@:@B"); //$NON-NLS-1$ | |
161 OS.class_addMethod(cls, OS.sel_webView_setStatusText_, proc4, "@:@@"); //$NON-NLS-1$ | |
162 OS.class_addMethod(cls, OS.sel_webViewFocus_, proc3, "@:@"); //$NON-NLS-1$ | |
163 OS.class_addMethod(cls, OS.sel_webViewUnfocus_, proc3, "@:@"); //$NON-NLS-1$ | |
164 OS.class_addMethod(cls, OS.sel_webView_runJavaScriptAlertPanelWithMessage_, proc4, "@:@@"); //$NON-NLS-1$ | |
165 OS.class_addMethod(cls, OS.sel_webView_runJavaScriptConfirmPanelWithMessage_, proc4, "@:@@"); //$NON-NLS-1$ | |
166 OS.class_addMethod(cls, OS.sel_webView_runOpenPanelForFileButtonWithResultListener_, proc4, "@:@@"); //$NON-NLS-1$ | |
167 OS.class_addMethod(cls, OS.sel_webView_mouseDidMoveOverElement_modifierFlags_, proc5, "@:@@I"); //$NON-NLS-1$ | |
168 OS.class_addMethod(cls, OS.sel_webView_printFrameView_, proc4, "@:@@"); //$NON-NLS-1$ | |
169 OS.class_addMethod(cls, OS.sel_webView_decidePolicyForMIMEType_request_frame_decisionListener_, proc7, "@:@@@@@"); //$NON-NLS-1$ | |
170 OS.class_addMethod(cls, OS.sel_webView_decidePolicyForNavigationAction_request_frame_decisionListener_, proc7, "@:@@@@@"); //$NON-NLS-1$ | |
171 OS.class_addMethod(cls, OS.sel_webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener_, proc7, "@:@@@@@"); //$NON-NLS-1$ | |
172 OS.class_addMethod(cls, OS.sel_webView_unableToImplementPolicyWithError_frame_, proc5, "@:@@@"); //$NON-NLS-1$ | |
173 OS.class_addMethod(cls, OS.sel_download_decideDestinationWithSuggestedFilename_, proc4, "@:@@"); //$NON-NLS-1$ | |
174 OS.class_addMethod(cls, OS.sel_handleEvent_, proc3, "@:@"); //$NON-NLS-1$ | |
175 OS.class_addMethod(cls, OS.sel_webView_setFrame_, setFrameProc, "@:@{NSRect}"); //$NON-NLS-1$ | |
176 OS.objc_registerClassPair(cls); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
177 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
178 |
45 | 179 /* |
180 * Override the default event mechanism to not send key events so | |
181 * that the browser can send them by listening to the DOM instead. | |
182 */ | |
183 browser.setData(SAFARI_EVENTS_FIX_KEY); | |
184 | |
185 WebView webView = (WebView)new WebView().alloc(); | |
186 if (webView is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
187 webView.initWithFrame(browser.view.frame(), null, null); | |
188 webView.setAutoresizingMask(OS.NSViewWidthSizable | OS.NSViewHeightSizable); | |
189 final SWTWebViewDelegate delegate = (SWTWebViewDelegate)new SWTWebViewDelegate().alloc().init(); | |
190 Display display = browser.getDisplay(); | |
191 display.setData(ADD_WIDGET_KEY, new Object[] {delegate, browser}); | |
192 this.delegate = delegate; | |
193 this.webView = webView; | |
194 browser.view.addSubview(webView); | |
195 | |
196 final NSNotificationCenter notificationCenter = NSNotificationCenter.defaultCenter(); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
197 |
45 | 198 Listener listener = new Listener() { |
199 public void handleEvent(Event e) { | |
200 switch (e.type) { | |
201 case DWT.FocusIn: | |
202 Safari.this.webView.window().makeFirstResponder(Safari.this.webView); | |
203 break; | |
204 case DWT.Dispose: { | |
205 /* make this handler run after other dispose listeners */ | |
206 if (ignoreDispose) { | |
207 ignoreDispose = false; | |
208 break; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
209 } |
45 | 210 ignoreDispose = true; |
211 browser.notifyListeners (e.type, e); | |
212 e.type = DWT.NONE; | |
213 | |
214 e.display.setData(ADD_WIDGET_KEY, new Object[] {delegate, null}); | |
215 | |
216 Safari.this.webView.setFrameLoadDelegate(null); | |
217 Safari.this.webView.setResourceLoadDelegate(null); | |
218 Safari.this.webView.setUIDelegate(null); | |
219 Safari.this.webView.setPolicyDelegate(null); | |
220 Safari.this.webView.setDownloadDelegate(null); | |
221 notificationCenter.removeObserver(delegate); | |
222 | |
223 Safari.this.webView.release(); | |
224 Safari.this.webView = null; | |
225 Safari.this.delegate.release(); | |
226 Safari.this.delegate = null; | |
227 html = null; | |
228 lastHoveredLinkURL = null; | |
229 break; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
230 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
231 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
232 } |
45 | 233 }; |
234 browser.addListener(DWT.Dispose, listener); | |
235 /* Needed to be able to tab into the browser */ | |
236 browser.addListener(DWT.KeyDown, listener); | |
237 browser.addListener(DWT.FocusIn, listener); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
238 |
45 | 239 webView.setFrameLoadDelegate(delegate); |
240 webView.setResourceLoadDelegate(delegate); | |
241 webView.setUIDelegate(delegate); | |
242 notificationCenter.addObserver(delegate, OS.sel_handleNotification_, null, webView); | |
243 webView.setPolicyDelegate(delegate); | |
244 webView.setDownloadDelegate(delegate); | |
245 webView.setApplicationNameForUserAgent(NSString.stringWith(AGENT_STRING)); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
246 |
45 | 247 if (!Initialized) { |
248 Initialized = true; | |
249 /* disable applets */ | |
250 WebPreferences.standardPreferences().setJavaEnabled(false); | |
251 } | |
252 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
253 |
45 | 254 public bool back() { |
255 html = null; | |
256 return webView.goBack(); | |
257 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
258 |
45 | 259 static int /*long*/ browserProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) { |
260 Widget widget = Display.getCurrent().findWidget(id); | |
261 if (widget is null) return 0; | |
262 Safari safari = (Safari)((Browser)widget).webBrowser; | |
263 if (sel is OS.sel_handleNotification_) { | |
264 safari.handleNotification(arg0); | |
265 } else if (sel is OS.sel_webViewShow_) { | |
266 safari.webViewShow(arg0); | |
267 } else if (sel is OS.sel_webViewClose_) { | |
268 safari.webViewClose(arg0); | |
269 } else if (sel is OS.sel_webViewFocus_) { | |
270 safari.webViewFocus(arg0); | |
271 } else if (sel is OS.sel_webViewUnfocus_) { | |
272 safari.webViewUnfocus(arg0); | |
273 } else if (sel is OS.sel_handleEvent_) { | |
274 safari.handleEvent(arg0); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
275 } |
45 | 276 return 0; |
277 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
278 |
45 | 279 static int /*long*/ browserProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1) { |
280 Widget widget = Display.getCurrent().findWidget(id); | |
281 if (widget is null) return 0; | |
282 Safari safari = (Safari)((Browser)widget).webBrowser; | |
283 if (sel is OS.sel_webView_didChangeLocationWithinPageForFrame_) { | |
284 safari.webView_didChangeLocationWithinPageForFrame(arg0, arg1); | |
285 } else if (sel is OS.sel_webView_didFinishLoadForFrame_) { | |
286 safari.webView_didFinishLoadForFrame(arg0, arg1); | |
287 } else if (sel is OS.sel_webView_didStartProvisionalLoadForFrame_) { | |
288 safari.webView_didStartProvisionalLoadForFrame(arg0, arg1); | |
289 } else if (sel is OS.sel_webView_didCommitLoadForFrame_) { | |
290 safari.webView_didCommitLoadForFrame(arg0, arg1); | |
291 } else if (sel is OS.sel_webView_setFrame_) { | |
292 safari.webView_setFrame(arg0, arg1); | |
293 } else if (sel is OS.sel_webView_createWebViewWithRequest_) { | |
294 return safari.webView_createWebViewWithRequest(arg0, arg1); | |
295 } else if (sel is OS.sel_webView_setStatusBarVisible_) { | |
296 safari.webView_setStatusBarVisible(arg0, arg1 !is 0); | |
297 } else if (sel is OS.sel_webView_setResizable_) { | |
298 safari.webView_setResizable(arg0, arg1 !is 0); | |
299 } else if (sel is OS.sel_webView_setStatusText_) { | |
300 safari.webView_setStatusText(arg0, arg1); | |
301 } else if (sel is OS.sel_webView_setToolbarsVisible_) { | |
302 safari.webView_setToolbarsVisible(arg0, arg1 !is 0); | |
303 } else if (sel is OS.sel_webView_runJavaScriptAlertPanelWithMessage_) { | |
304 safari.webView_runJavaScriptAlertPanelWithMessage(arg0, arg1); | |
305 } else if (sel is OS.sel_webView_runJavaScriptConfirmPanelWithMessage_) { | |
306 return safari.webView_runJavaScriptConfirmPanelWithMessage(arg0, arg1); | |
307 } else if (sel is OS.sel_webView_runOpenPanelForFileButtonWithResultListener_) { | |
308 safari.webView_runOpenPanelForFileButtonWithResultListener(arg0, arg1); | |
309 } else if (sel is OS.sel_download_decideDestinationWithSuggestedFilename_) { | |
310 safari.download_decideDestinationWithSuggestedFilename(arg0, arg1); | |
311 } else if (sel is OS.sel_webView_printFrameView_) { | |
312 safari.webView_printFrameView(arg0, arg1); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
313 } |
45 | 314 return 0; |
315 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
316 |
45 | 317 static int /*long*/ browserProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2) { |
318 Widget widget = Display.getCurrent().findWidget(id); | |
319 if (widget is null) return 0; | |
320 Safari safari = (Safari)((Browser)widget).webBrowser; | |
321 if (sel is OS.sel_webView_didFailProvisionalLoadWithError_forFrame_) { | |
322 safari.webView_didFailProvisionalLoadWithError_forFrame(arg0, arg1, arg2); | |
323 } else if (sel is OS.sel_webView_didReceiveTitle_forFrame_) { | |
324 safari.webView_didReceiveTitle_forFrame(arg0, arg1, arg2); | |
325 } else if (sel is OS.sel_webView_resource_didFinishLoadingFromDataSource_) { | |
326 safari.webView_resource_didFinishLoadingFromDataSource(arg0, arg1, arg2); | |
327 } else if (sel is OS.sel_webView_identifierForInitialRequest_fromDataSource_) { | |
328 return safari.webView_identifierForInitialRequest_fromDataSource(arg0, arg1, arg2); | |
329 } else if (sel is OS.sel_webView_contextMenuItemsForElement_defaultMenuItems_) { | |
330 return safari.webView_contextMenuItemsForElement_defaultMenuItems(arg0, arg1, arg2); | |
331 } else if (sel is OS.sel_webView_mouseDidMoveOverElement_modifierFlags_) { | |
332 safari.webView_mouseDidMoveOverElement_modifierFlags(arg0, arg1, arg2); | |
333 } else if (sel is OS.sel_webView_unableToImplementPolicyWithError_frame_) { | |
334 safari.webView_unableToImplementPolicyWithError_frame(arg0, arg1, arg2); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
335 } |
45 | 336 return 0; |
337 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
338 |
45 | 339 static int /*long*/ browserProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2, int /*long*/ arg3) { |
340 Widget widget = Display.getCurrent().findWidget(id); | |
341 if (widget is null) return 0; | |
342 Safari safari = (Safari)((Browser)widget).webBrowser; | |
343 if (sel is OS.sel_webView_resource_didFailLoadingWithError_fromDataSource_) { | |
344 safari.webView_resource_didFailLoadingWithError_fromDataSource(arg0, arg1, arg2, arg3); | |
345 } | |
346 return 0; | |
347 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
348 |
45 | 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) { |
350 Widget widget = Display.getCurrent().findWidget(id); | |
351 if (widget is null) return 0; | |
352 Safari safari = (Safari)((Browser)widget).webBrowser; | |
353 if (sel is OS.sel_webView_resource_willSendRequest_redirectResponse_fromDataSource_) { | |
354 return safari.webView_resource_willSendRequest_redirectResponse_fromDataSource(arg0, arg1, arg2, arg3, arg4); | |
355 } else if (sel is OS.sel_webView_decidePolicyForMIMEType_request_frame_decisionListener_) { | |
356 safari.webView_decidePolicyForMIMEType_request_frame_decisionListener(arg0, arg1, arg2, arg3, arg4); | |
357 } else if (sel is OS.sel_webView_decidePolicyForNavigationAction_request_frame_decisionListener_) { | |
358 safari.webView_decidePolicyForNavigationAction_request_frame_decisionListener(arg0, arg1, arg2, arg3, arg4); | |
359 } else if (sel is OS.sel_webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener_) { | |
360 safari.webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener(arg0, arg1, arg2, arg3, arg4); | |
361 } | |
362 return 0; | |
363 } | |
364 | |
365 public bool execute(String script) { | |
366 return webView.stringByEvaluatingJavaScriptFromString(NSString.stringWith(script)) !is null; | |
367 } | |
368 | |
369 public bool forward() { | |
370 html = null; | |
371 return webView.goForward(); | |
372 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
373 |
45 | 374 public String getBrowserType () { |
375 return "safari"; //$NON-NLS-1$ | |
376 } | |
377 | |
378 public String getText() { | |
379 WebFrame mainFrame = webView.mainFrame(); | |
380 WebDataSource dataSource = mainFrame.dataSource(); | |
381 if (dataSource is null) return ""; //$NON-NLS-1$ | |
382 WebDocumentRepresentation representation = dataSource.representation(); | |
383 if (representation is null) return ""; //$NON-NLS-1$ | |
384 NSString source = representation.documentSource(); | |
385 if (source is null) return ""; //$NON-NLS-1$ | |
386 return source.getString(); | |
387 } | |
388 | |
389 public String getUrl() { | |
390 return url; | |
391 } | |
392 | |
393 public bool isBackEnabled() { | |
394 return webView.canGoBack(); | |
395 } | |
396 | |
397 public bool isForwardEnabled() { | |
398 return webView.canGoForward(); | |
399 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
400 |
45 | 401 public void refresh() { |
402 webView.reload(null); | |
403 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
404 |
45 | 405 public bool setText(String html) { |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
406 /* |
45 | 407 * Bug in Safari. The web view segment faults in some circumstances |
408 * when the text changes during the location changing callback. The | |
409 * fix is to defer the work until the callback is done. | |
410 */ | |
411 if (changingLocation) { | |
412 this.html = html; | |
413 } else { | |
414 _setText(html); | |
415 } | |
416 return true; | |
417 } | |
418 | |
419 void _setText(String html) { | |
420 NSString string = NSString.stringWith(html); | |
421 NSString URLString = NSString.stringWith(URI_FROMMEMORY); | |
422 NSURL URL = NSURL.URLWithString(URLString); | |
423 WebFrame mainFrame = webView.mainFrame(); | |
424 mainFrame.loadHTMLString(string, URL); | |
425 } | |
426 | |
427 public bool setUrl(String url) { | |
428 html = null; | |
429 | |
430 if (url.indexOf('/') is 0) { | |
431 url = PROTOCOL_FILE + url; | |
432 } else if (url.indexOf(':') is -1) { | |
433 url = PROTOCOL_HTTP + url; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
434 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
435 |
45 | 436 NSString str = NSString.stringWith(url); |
437 NSString unescapedStr = NSString.stringWith("%#"); //$NON-NLS-1$ | |
438 int /*long*/ ptr = OS.CFURLCreateStringByAddingPercentEscapes(0, str.id, unescapedStr.id, 0, OS.kCFStringEncodingUTF8); | |
439 NSString escapedString = new NSString(ptr); | |
440 NSURL inURL = NSURL.URLWithString(escapedString); | |
441 OS.CFRelease(ptr); | |
442 NSURLRequest request = NSURLRequest.requestWithURL(inURL); | |
443 WebFrame mainFrame = webView.mainFrame(); | |
444 mainFrame.loadRequest(request); | |
445 return true; | |
446 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
447 |
45 | 448 public void stop() { |
449 html = null; | |
450 webView.stopLoading(null); | |
451 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
452 |
45 | 453 /* WebFrameLoadDelegate */ |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
454 |
45 | 455 void webView_didChangeLocationWithinPageForFrame(int /*long*/ sender, int /*long*/ frameID) { |
456 WebFrame frame = new WebFrame(frameID); | |
457 WebDataSource dataSource = frame.dataSource(); | |
458 NSURLRequest request = dataSource.request(); | |
459 NSURL url = request.URL(); | |
460 NSString s = url.absoluteString(); | |
461 int length = (int)/*64*/s.length(); | |
462 if (length is 0) return; | |
463 String url2 = s.getString(); | |
464 /* | |
465 * 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. | |
467 */ | |
468 if (url2.equals (URI_FROMMEMORY)) url2 = ABOUT_BLANK; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
469 |
45 | 470 final Display display = browser.getDisplay(); |
471 bool top = frameID is webView.mainFrame().id; | |
472 if (top) { | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
473 StatusTextEvent statusText = new StatusTextEvent(browser); |
45 | 474 statusText.display = display; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
475 statusText.widget = browser; |
45 | 476 statusText.text = url2; |
477 for (int i = 0; i < statusTextListeners.length; i++) { | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
478 statusTextListeners[i].changed(statusText); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
479 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
480 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
481 |
45 | 482 LocationEvent location = new LocationEvent(browser); |
483 location.display = display; | |
484 location.widget = browser; | |
485 location.location = url2; | |
486 location.top = top; | |
487 for (int i = 0; i < locationListeners.length; i++) { | |
488 locationListeners[i].changed(location); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
489 } |
45 | 490 } |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
491 |
45 | 492 void webView_didFailProvisionalLoadWithError_forFrame(int /*long*/ sender, int /*long*/ error, int /*long*/ frame) { |
493 if (frame is webView.mainFrame().id) { | |
494 /* | |
495 * 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 | |
497 * they should appear on the location bar of a browser. It is expected to reset | |
498 * the identifier to 0 when the event didFinishLoadingFromDataSource related to | |
499 * the identifierForInitialRequest event is received. However, Safari fires | |
500 * the didFinishLoadingFromDataSource event before the entire content of the | |
501 * top frame is loaded. It is possible to receive multiple willSendRequest | |
502 * events in this interval, causing the Browser widget to send unwanted | |
503 * Location.changing events. For this reason, the identifier is reset to 0 | |
504 * when the top frame has either finished loading (didFinishLoadForFrame | |
505 * event) or failed (didFailProvisionalLoadWithError). | |
506 */ | |
507 identifier = 0; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
508 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
509 |
45 | 510 NSError nserror = new NSError(error); |
511 int /*long*/ errorCode = nserror.code(); | |
512 if (errorCode <= OS.NSURLErrorBadURL) { | |
513 NSString description = nserror.localizedDescription(); | |
514 if (description !is null) { | |
515 String descriptionString = description.getString(); | |
516 String urlString = null; | |
517 NSDictionary info = nserror.userInfo(); | |
518 if (info !is null) { | |
519 NSString key = new NSString(OS.NSErrorFailingURLStringKey()); | |
520 id id = info.valueForKey(key); | |
521 if (id !is null) { | |
522 NSString url = new NSString(id); | |
523 urlString = url.getString(); | |
524 } | |
525 } | |
526 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$ | |
528 MessageBox messageBox = new MessageBox(browser.getShell(), DWT.OK | DWT.ICON_ERROR); | |
529 messageBox.setMessage(message); | |
530 messageBox.open(); | |
531 } | |
532 } | |
533 } | |
534 | |
535 void webView_didFinishLoadForFrame(int /*long*/ sender, int /*long*/ frameID) { | |
536 hookDOMMouseListeners(frameID); | |
537 if (frameID is webView.mainFrame().id) { | |
538 hookDOMKeyListeners(frameID); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
539 |
45 | 540 final Display display = browser.getDisplay(); |
541 /* | |
542 * To be consistent with other platforms a title event should be fired when a | |
543 * page has completed loading. A page with a <title> tag will do this | |
544 * automatically when the didReceiveTitle callback is received. However a page | |
545 * without a <title> tag will not do this by default, so fire the event | |
546 * here with the page's url as the title. | |
547 */ | |
548 WebFrame frame = new WebFrame(frameID); | |
549 WebDataSource dataSource = frame.dataSource(); | |
550 if (dataSource !is null) { | |
551 NSString title = dataSource.pageTitle(); | |
552 if (title is null) { /* page has no title */ | |
553 final TitleEvent newEvent = new TitleEvent(browser); | |
554 newEvent.display = display; | |
555 newEvent.widget = browser; | |
556 newEvent.title = url; | |
557 for (int i = 0; i < titleListeners.length; i++) { | |
558 final TitleListener listener = titleListeners[i]; | |
559 /* | |
560 * Note on WebKit. Running the event loop from a Browser | |
561 * delegate callback breaks the WebKit (stop loading or | |
562 * crash). The workaround is to invoke Display.asyncExec() | |
563 * so that the Browser does not crash if this is attempted. | |
564 */ | |
565 display.asyncExec( | |
566 new Runnable() { | |
567 public void run() { | |
568 if (!display.isDisposed() && !browser.isDisposed()) { | |
569 listener.changed(newEvent); | |
570 } | |
571 } | |
572 } | |
573 ); | |
574 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
575 } |
45 | 576 } |
577 final ProgressEvent progress = new ProgressEvent(browser); | |
578 progress.display = display; | |
579 progress.widget = browser; | |
580 progress.current = MAX_PROGRESS; | |
581 progress.total = MAX_PROGRESS; | |
582 for (int i = 0; i < progressListeners.length; i++) { | |
583 final ProgressListener listener = progressListeners[i]; | |
584 /* | |
585 * Note on WebKit. Running the event loop from a Browser | |
586 * delegate callback breaks the WebKit (stop loading or | |
587 * crash). The ProgressBar widget currently touches the | |
588 * event loop every time the method setSelection is called. | |
589 * The workaround is to invoke Display.asyncExec() so that | |
590 * the Browser does not crash when the user updates the | |
591 * selection of the ProgressBar. | |
592 */ | |
593 display.asyncExec( | |
594 new Runnable() { | |
595 public void run() { | |
596 if (!display.isDisposed() && !browser.isDisposed()) { | |
597 listener.completed(progress); | |
598 } | |
599 } | |
600 } | |
601 ); | |
602 } | |
603 /* | |
604 * Feature on Safari. The identifier is used here as a marker for the events | |
605 * related to the top frame and the URL changes related to that top frame as | |
606 * they should appear on the location bar of a browser. It is expected to reset | |
607 * the identifier to 0 when the event didFinishLoadingFromDataSource related to | |
608 * the identifierForInitialRequest event is received. However, Safari fires | |
609 * the didFinishLoadingFromDataSource event before the entire content of the | |
610 * top frame is loaded. It is possible to receive multiple willSendRequest | |
611 * events in this interval, causing the Browser widget to send unwanted | |
612 * Location.changing events. For this reason, the identifier is reset to 0 | |
613 * when the top frame has either finished loading (didFinishLoadForFrame | |
614 * event) or failed (didFailProvisionalLoadWithError). | |
615 */ | |
616 identifier = 0; | |
617 } | |
618 } | |
619 | |
620 void hookDOMKeyListeners(int /*long*/ frameID) { | |
621 WebFrame frame = new WebFrame(frameID); | |
622 DOMDocument document = frame.DOMDocument(); | |
623 | |
624 NSString type = NSString.stringWith(DOMEVENT_KEYDOWN); | |
625 document.addEventListener(type, delegate, false); | |
626 | |
627 type = NSString.stringWith(DOMEVENT_KEYUP); | |
628 document.addEventListener(type, delegate, false); | |
629 } | |
630 | |
631 void hookDOMMouseListeners(int /*long*/ frameID) { | |
632 WebFrame frame = new WebFrame(frameID); | |
633 DOMDocument document = frame.DOMDocument(); | |
634 | |
635 NSString type = NSString.stringWith(DOMEVENT_MOUSEDOWN); | |
636 document.addEventListener(type, delegate, false); | |
637 | |
638 type = NSString.stringWith(DOMEVENT_MOUSEUP); | |
639 document.addEventListener(type, delegate, false); | |
640 | |
641 type = NSString.stringWith(DOMEVENT_MOUSEMOVE); | |
642 document.addEventListener(type, delegate, false); | |
643 | |
644 type = NSString.stringWith(DOMEVENT_MOUSEWHEEL); | |
645 document.addEventListener(type, delegate, false); | |
646 } | |
647 | |
648 void webView_didReceiveTitle_forFrame(int /*long*/ sender, int /*long*/ titleID, int /*long*/ frameID) { | |
649 if (frameID is webView.mainFrame().id) { | |
650 NSString title = new NSString(titleID); | |
651 String newTitle = title.getString(); | |
652 TitleEvent newEvent = new TitleEvent(browser); | |
653 newEvent.display = browser.getDisplay(); | |
654 newEvent.widget = browser; | |
655 newEvent.title = newTitle; | |
656 for (int i = 0; i < titleListeners.length; i++) { | |
657 titleListeners[i].changed(newEvent); | |
658 } | |
659 } | |
660 } | |
661 | |
662 void webView_didStartProvisionalLoadForFrame(int /*long*/ sender, int /*long*/ frameID) { | |
663 /* | |
664 * This code is intentionally commented. WebFrameLoadDelegate:didStartProvisionalLoadForFrame is | |
665 * called before WebResourceLoadDelegate:willSendRequest and | |
666 * WebFrameLoadDelegate:didCommitLoadForFrame. The resource count is reset when didCommitLoadForFrame | |
667 * is received for the top frame. | |
668 */ | |
669 // if (frameID is webView.mainFrame().id) { | |
670 // /* reset resource status variables */ | |
671 // resourceCount= 0; | |
672 // } | |
673 } | |
674 | |
675 void webView_didCommitLoadForFrame(int /*long*/ sender, int /*long*/ frameID) { | |
676 WebFrame frame = new WebFrame(frameID); | |
677 WebDataSource dataSource = frame.dataSource(); | |
678 NSURLRequest request = dataSource.request(); | |
679 NSURL url = request.URL(); | |
680 NSString s = url.absoluteString(); | |
681 int length = (int)/*64*/s.length(); | |
682 if (length is 0) return; | |
683 String url2 = s.getString(); | |
684 /* | |
685 * 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. | |
687 */ | |
688 if (url2.equals (URI_FROMMEMORY)) url2 = ABOUT_BLANK; | |
689 | |
690 final Display display = browser.getDisplay(); | |
691 bool top = frameID is webView.mainFrame().id; | |
692 if (top) { | |
693 /* reset resource status variables */ | |
694 resourceCount = 0; | |
695 this.url = url2; | |
696 | |
697 final ProgressEvent progress = new ProgressEvent(browser); | |
698 progress.display = display; | |
699 progress.widget = browser; | |
700 progress.current = 1; | |
701 progress.total = MAX_PROGRESS; | |
702 for (int i = 0; i < progressListeners.length; i++) { | |
703 final ProgressListener listener = progressListeners[i]; | |
704 /* | |
705 * Note on WebKit. Running the event loop from a Browser | |
706 * delegate callback breaks the WebKit (stop loading or | |
707 * crash). The widget ProgressBar currently touches the | |
708 * event loop every time the method setSelection is called. | |
709 * The workaround is to invoke Display.asyncexec so that | |
710 * the Browser does not crash when the user updates the | |
711 * selection of the ProgressBar. | |
712 */ | |
713 display.asyncExec( | |
714 new Runnable() { | |
715 public void run() { | |
716 if (!display.isDisposed() && !browser.isDisposed()) | |
717 listener.changed(progress); | |
718 } | |
719 } | |
720 ); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
721 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
722 |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
723 StatusTextEvent statusText = new StatusTextEvent(browser); |
45 | 724 statusText.display = display; |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
725 statusText.widget = browser; |
45 | 726 statusText.text = url2; |
727 for (int i = 0; i < statusTextListeners.length; i++) { | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
728 statusTextListeners[i].changed(statusText); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
729 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
730 } |
45 | 731 LocationEvent location = new LocationEvent(browser); |
732 location.display = display; | |
733 location.widget = browser; | |
734 location.location = url2; | |
735 location.top = top; | |
736 for (int i = 0; i < locationListeners.length; i++) { | |
737 locationListeners[i].changed(location); | |
738 } | |
739 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
740 |
45 | 741 /* WebResourceLoadDelegate */ |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
742 |
45 | 743 void webView_resource_didFinishLoadingFromDataSource(int /*long*/ sender, int /*long*/ identifier, int /*long*/ dataSource) { |
744 /* | |
745 * 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 | |
747 * 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 | |
749 * the identifierForInitialRequest event is received. However, Safari fires | |
750 * the didFinishLoadingFromDataSource event before the entire content of the | |
751 * top frame is loaded. It is possible to receive multiple willSendRequest | |
752 * events in this interval, causing the Browser widget to send unwanted | |
753 * Location.changing events. For this reason, the identifier is reset to 0 | |
754 * when the top frame has either finished loading (didFinishLoadForFrame | |
755 * event) or failed (didFailProvisionalLoadWithError). | |
756 */ | |
757 // this code is intentionally commented | |
758 //if (this.identifier is identifier) this.identifier = 0; | |
759 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
760 |
45 | 761 void webView_resource_didFailLoadingWithError_fromDataSource(int /*long*/ sender, int /*long*/ identifier, int /*long*/ error, int /*long*/ dataSource) { |
762 /* | |
763 * 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 | |
765 * 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 | |
767 * the identifierForInitialRequest event is received. However, Safari fires | |
768 * the didFinishLoadingFromDataSource event before the entire content of the | |
769 * top frame is loaded. It is possible to receive multiple willSendRequest | |
770 * events in this interval, causing the Browser widget to send unwanted | |
771 * Location.changing events. For this reason, the identifier is reset to 0 | |
772 * when the top frame has either finished loading (didFinishLoadForFrame | |
773 * event) or failed (didFailProvisionalLoadWithError). | |
774 */ | |
775 // this code is intentionally commented | |
776 //if (this.identifier is identifier) this.identifier = 0; | |
777 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
778 |
45 | 779 int /*long*/ webView_identifierForInitialRequest_fromDataSource(int /*long*/ sender, int /*long*/ request, int /*long*/ dataSourceID) { |
780 final Display display = browser.getDisplay(); | |
781 final ProgressEvent progress = new ProgressEvent(browser); | |
782 progress.display = display; | |
783 progress.widget = browser; | |
784 progress.current = resourceCount; | |
785 progress.total = Math.max(resourceCount, MAX_PROGRESS); | |
786 for (int i = 0; i < progressListeners.length; i++) { | |
787 final ProgressListener listener = progressListeners[i]; | |
788 /* | |
789 * Note on WebKit. Running the event loop from a Browser | |
790 * delegate callback breaks the WebKit (stop loading or | |
791 * crash). The widget ProgressBar currently touches the | |
792 * event loop every time the method setSelection is called. | |
793 * The workaround is to invoke Display.asyncexec so that | |
794 * the Browser does not crash when the user updates the | |
795 * selection of the ProgressBar. | |
796 */ | |
797 display.asyncExec( | |
798 new Runnable() { | |
799 public void run() { | |
800 if (!display.isDisposed() && !browser.isDisposed()) | |
801 listener.changed(progress); | |
802 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
803 } |
45 | 804 ); |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
805 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
806 |
45 | 807 NSNumber identifier = NSNumber.numberWithInt(resourceCount++); |
808 if (this.identifier is 0) { | |
809 WebDataSource dataSource = new WebDataSource(dataSourceID); | |
810 WebFrame frame = dataSource.webFrame(); | |
811 if (frame.id is webView.mainFrame().id) this.identifier = identifier.id; | |
812 } | |
813 return identifier.id; | |
814 | |
815 } | |
816 | |
817 int /*long*/ webView_resource_willSendRequest_redirectResponse_fromDataSource(int /*long*/ sender, int /*long*/ identifier, int /*long*/ request, int /*long*/ redirectResponse, int /*long*/ dataSource) { | |
818 return request; | |
819 } | |
820 | |
821 /* handleNotification */ | |
822 | |
823 void handleNotification(int /*long*/ notification) { | |
824 } | |
825 | |
826 /* UIDelegate */ | |
827 | |
828 int /*long*/ webView_createWebViewWithRequest(int /*long*/ sender, int /*long*/ request) { | |
829 WindowEvent newEvent = new WindowEvent(browser); | |
830 newEvent.display = browser.getDisplay(); | |
831 newEvent.widget = browser; | |
832 newEvent.required = true; | |
833 if (openWindowListeners !is null) { | |
834 for (int i = 0; i < openWindowListeners.length; i++) { | |
835 openWindowListeners[i].open(newEvent); | |
836 } | |
837 } | |
838 WebView result = null; | |
839 Browser browser = null; | |
840 if (newEvent.browser !is null && newEvent.browser.webBrowser instanceof Safari) { | |
841 browser = newEvent.browser; | |
842 } | |
843 if (browser !is null && !browser.isDisposed()) { | |
844 result = ((Safari)browser.webBrowser).webView; | |
845 if (request !is 0) { | |
846 WebFrame mainFrame = webView.mainFrame(); | |
847 mainFrame.loadRequest(new NSURLRequest(request)); | |
848 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
849 } |
45 | 850 return result !is null ? result.id : 0; |
851 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
852 |
45 | 853 void webViewShow(int /*long*/ sender) { |
854 /* | |
855 * Feature on WebKit. The Safari WebKit expects the application | |
856 * to create a new Window using the Objective C Cocoa API in response | |
857 * to UIDelegate.createWebViewWithRequest. The application is then | |
858 * expected to use Objective C Cocoa API to make this window visible | |
859 * when receiving the UIDelegate.webViewShow message. For some reason, | |
860 * a window created with the Carbon API hosting the new browser instance | |
861 * does not redraw until it has been resized. The fix is to increase the | |
862 * size of the Shell and restore it to its initial size. | |
863 */ | |
864 Shell parent = browser.getShell(); | |
865 Point pt = parent.getSize(); | |
866 parent.setSize(pt.x+1, pt.y); | |
867 parent.setSize(pt.x, pt.y); | |
868 WindowEvent newEvent = new WindowEvent(browser); | |
869 newEvent.display = browser.getDisplay(); | |
870 newEvent.widget = browser; | |
871 if (location !is null) newEvent.location = location; | |
872 if (size !is null) newEvent.size = size; | |
873 /* | |
874 * Feature in Safari. Safari's tool bar contains | |
875 * the address bar. The address bar is displayed | |
876 * if the tool bar is displayed. There is no separate | |
877 * notification for the address bar. | |
878 * Feature in Safari. The menu bar is always | |
879 * displayed. There is no notification to hide | |
880 * the menu bar. | |
881 */ | |
882 newEvent.addressBar = toolBar; | |
883 newEvent.menuBar = true; | |
884 newEvent.statusBar = statusBar; | |
885 newEvent.toolBar = toolBar; | |
886 for (int i = 0; i < visibilityWindowListeners.length; i++) { | |
887 visibilityWindowListeners[i].show(newEvent); | |
888 } | |
889 location = null; | |
890 size = null; | |
891 } | |
892 | |
893 void webView_setFrame(int /*long*/ sender, int /*long*/ frame) { | |
46
cfa563df4fdd
Updated Widget and Display to 3.514
Jacob Carlborg <doob@me.com>
parents:
45
diff
changeset
|
894 NSRect rect = NSRect(); |
45 | 895 OS.memmove(rect, frame, NSRect.sizeof); |
896 /* convert to DWT system coordinates */ | |
897 Rectangle bounds = browser.getDisplay().getBounds(); | |
898 location = new Point((int)rect.x, bounds.height - (int)rect.y - (int)rect.height); | |
899 size = new Point((int)rect.width, (int)rect.height); | |
900 } | |
901 | |
902 void webViewFocus(int /*long*/ sender) { | |
903 } | |
904 | |
905 void webViewUnfocus(int /*long*/ sender) { | |
906 } | |
907 | |
908 void webView_runJavaScriptAlertPanelWithMessage(int /*long*/ sender, int /*long*/ messageID) { | |
909 NSString message = new NSString(messageID); | |
910 String text = message.getString(); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
911 |
45 | 912 MessageBox messageBox = new MessageBox(browser.getShell(), DWT.OK | DWT.ICON_WARNING); |
913 messageBox.setText("Javascript"); //$NON-NLS-1$ | |
914 messageBox.setMessage(text); | |
915 messageBox.open(); | |
916 } | |
917 | |
918 int webView_runJavaScriptConfirmPanelWithMessage(int /*long*/ sender, int /*long*/ messageID) { | |
919 NSString message = new NSString(messageID); | |
920 String text = message.getString(); | |
921 | |
922 MessageBox messageBox = new MessageBox(browser.getShell(), DWT.OK | DWT.CANCEL | DWT.ICON_QUESTION); | |
923 messageBox.setText("Javascript"); //$NON-NLS-1$ | |
924 messageBox.setMessage(text); | |
925 return messageBox.open() is DWT.OK ? 1 : 0; | |
926 } | |
927 | |
928 void webView_runOpenPanelForFileButtonWithResultListener(int /*long*/ sender, int /*long*/ resultListenerID) { | |
929 FileDialog dialog = new FileDialog(browser.getShell(), DWT.NONE); | |
930 String result = dialog.open(); | |
931 WebOpenPanelResultListener resultListener = new WebOpenPanelResultListener(resultListenerID); | |
932 if (result is null) { | |
933 resultListener.cancel(); | |
934 return; | |
935 } | |
936 resultListener.chooseFilename(NSString.stringWith(result)); | |
937 } | |
938 | |
939 void webViewClose(int /*long*/ sender) { | |
940 Shell parent = browser.getShell(); | |
941 WindowEvent newEvent = new WindowEvent(browser); | |
942 newEvent.display = browser.getDisplay(); | |
943 newEvent.widget = browser; | |
944 for (int i = 0; i < closeWindowListeners.length; i++) { | |
945 closeWindowListeners[i].close(newEvent); | |
946 } | |
947 browser.dispose(); | |
948 if (parent.isDisposed()) return; | |
949 /* | |
950 * Feature on WebKit. The Safari WebKit expects the application | |
951 * to create a new Window using the Objective C Cocoa API in response | |
952 * to UIDelegate.createWebViewWithRequest. The application is then | |
953 * expected to use Objective C Cocoa API to make this window visible | |
954 * when receiving the UIDelegate.webViewShow message. For some reason, | |
955 * a window created with the Carbon API hosting the new browser instance | |
956 * does not redraw until it has been resized. The fix is to increase the | |
957 * size of the Shell and restore it to its initial size. | |
958 */ | |
959 Point pt = parent.getSize(); | |
960 parent.setSize(pt.x+1, pt.y); | |
961 parent.setSize(pt.x, pt.y); | |
962 } | |
963 | |
964 int /*long*/ webView_contextMenuItemsForElement_defaultMenuItems(int /*long*/ sender, int /*long*/ element, int /*long*/ defaultMenuItems) { | |
965 Point pt = browser.getDisplay().getCursorLocation(); | |
966 Event event = new Event(); | |
967 event.x = pt.x; | |
968 event.y = pt.y; | |
969 browser.notifyListeners(DWT.MenuDetect, event); | |
970 Menu menu = browser.getMenu(); | |
971 if (!event.doit) return 0; | |
972 if (menu !is null && !menu.isDisposed()) { | |
973 if (event.x !is pt.x || event.y !is pt.y) { | |
974 menu.setLocation(event.x, event.y); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
975 } |
45 | 976 menu.setVisible(true); |
977 return 0; | |
978 } | |
979 return defaultMenuItems; | |
980 } | |
981 | |
982 void webView_setStatusBarVisible(int /*long*/ sender, bool visible) { | |
983 /* Note. Webkit only emits the notification when the status bar should be hidden. */ | |
984 statusBar = visible; | |
985 } | |
986 | |
987 void webView_setStatusText(int /*long*/ sender, int /*long*/ textID) { | |
988 NSString text = new NSString(textID); | |
989 int length = (int)/*64*/text.length(); | |
990 if (length is 0) return; | |
991 | |
992 StatusTextEvent statusText = new StatusTextEvent(browser); | |
993 statusText.display = browser.getDisplay(); | |
994 statusText.widget = browser; | |
995 statusText.text = text.getString(); | |
996 for (int i = 0; i < statusTextListeners.length; i++) { | |
997 statusTextListeners[i].changed(statusText); | |
998 } | |
999 } | |
1000 | |
1001 void webView_setResizable(int /*long*/ sender, bool visible) { | |
1002 } | |
1003 | |
1004 void webView_setToolbarsVisible(int /*long*/ sender, bool visible) { | |
1005 /* Note. Webkit only emits the notification when the tool bar should be hidden. */ | |
1006 toolBar = visible; | |
1007 } | |
1008 | |
1009 void webView_mouseDidMoveOverElement_modifierFlags (int /*long*/ sender, int /*long*/ elementInformationID, int /*long*/ modifierFlags) { | |
1010 if (elementInformationID is 0) return; | |
1011 | |
1012 NSString key = NSString.stringWith(WebElementLinkURLKey); | |
1013 NSDictionary elementInformation = new NSDictionary(elementInformationID); | |
1014 id value = elementInformation.valueForKey(key); | |
1015 if (value is null) { | |
1016 /* not currently over a link */ | |
1017 if (lastHoveredLinkURL is null) return; | |
1018 lastHoveredLinkURL = null; | |
1019 StatusTextEvent statusText = new StatusTextEvent(browser); | |
1020 statusText.display = browser.getDisplay(); | |
1021 statusText.widget = browser; | |
1022 statusText.text = ""; //$NON-NLS-1$ | |
1023 for (int i = 0; i < statusTextListeners.length; i++) { | |
1024 statusTextListeners[i].changed(statusText); | |
1025 } | |
1026 return; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1027 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1028 |
45 | 1029 NSString url = new NSURL(value.id).absoluteString(); |
1030 int length = (int)/*64*/url.length(); | |
1031 String urlString; | |
1032 if (length is 0) { | |
1033 urlString = ""; //$NON-NLS-1$ | |
1034 } else { | |
1035 urlString = url.getString(); | |
1036 } | |
1037 if (urlString.equals(lastHoveredLinkURL)) return; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1038 |
45 | 1039 lastHoveredLinkURL = urlString; |
1040 StatusTextEvent statusText = new StatusTextEvent(browser); | |
1041 statusText.display = browser.getDisplay(); | |
1042 statusText.widget = browser; | |
1043 statusText.text = urlString; | |
1044 for (int i = 0; i < statusTextListeners.length; i++) { | |
1045 statusTextListeners[i].changed(statusText); | |
1046 } | |
1047 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1048 |
45 | 1049 void webView_printFrameView (int /*long*/ sender, int /*long*/ frameViewID) { |
1050 WebFrameView view = new WebFrameView(frameViewID); | |
1051 bool viewPrint = view.documentViewShouldHandlePrint(); | |
1052 if (viewPrint) { | |
1053 view.printDocumentView(); | |
1054 return; | |
1055 } | |
1056 NSPrintInfo info = NSPrintInfo.sharedPrintInfo(); | |
1057 NSPrintOperation operation = view.printOperationWithPrintInfo(info); | |
1058 if (operation !is null) operation.runOperation(); | |
1059 } | |
1060 | |
1061 /* PolicyDelegate */ | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1062 |
45 | 1063 void webView_decidePolicyForMIMEType_request_frame_decisionListener(int /*long*/ sender, int /*long*/ type, int /*long*/ request, int /*long*/ frame, int /*long*/ listenerID) { |
1064 bool canShow = WebView.canShowMIMEType(new NSString(type)); | |
1065 WebPolicyDecisionListener listener = new WebPolicyDecisionListener(listenerID); | |
1066 if (canShow) { | |
1067 listener.use(); | |
1068 } else { | |
1069 listener.download(); | |
1070 } | |
1071 } | |
1072 | |
1073 void webView_decidePolicyForNavigationAction_request_frame_decisionListener(int /*long*/ sender, int /*long*/ actionInformation, int /*long*/ request, int /*long*/ frame, int /*long*/ listenerID) { | |
1074 NSURL url = new NSURLRequest(request).URL(); | |
1075 WebPolicyDecisionListener listener = new WebPolicyDecisionListener(listenerID); | |
1076 if (url is null) { | |
1077 /* indicates that a URL with an invalid format was specified */ | |
1078 listener.ignore(); | |
1079 return; | |
1080 } | |
1081 NSString s = url.absoluteString(); | |
1082 String url2 = s.getString(); | |
1083 /* | |
1084 * If the URI indicates that the page is being rendered from memory | |
1085 * (via setText()) then set it to about:blank to be consistent with IE. | |
1086 */ | |
1087 if (url2.equals (URI_FROMMEMORY)) url2 = ABOUT_BLANK; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1088 |
45 | 1089 LocationEvent newEvent = new LocationEvent(browser); |
1090 newEvent.display = browser.getDisplay(); | |
1091 newEvent.widget = browser; | |
1092 newEvent.location = url2; | |
1093 newEvent.doit = true; | |
1094 if (locationListeners !is null) { | |
1095 changingLocation = true; | |
1096 for (int i = 0; i < locationListeners.length; i++) { | |
1097 locationListeners[i].changing(newEvent); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1098 } |
45 | 1099 changingLocation = false; |
1100 } | |
1101 if (newEvent.doit) { | |
1102 listener.use(); | |
1103 } else { | |
1104 listener.ignore(); | |
1105 } | |
1106 if (html !is null && !browser.isDisposed()) { | |
1107 String html = this.html; | |
1108 this.html = null; | |
1109 _setText(html); | |
1110 } | |
1111 } | |
1112 | |
1113 void webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener(int /*long*/ sender, int /*long*/ actionInformation, int /*long*/ request, int /*long*/ frameName, int /*long*/ listenerID) { | |
1114 WebPolicyDecisionListener listener = new WebPolicyDecisionListener(listenerID); | |
1115 listener.use(); | |
1116 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1117 |
45 | 1118 void webView_unableToImplementPolicyWithError_frame(int /*long*/ sender, int /*long*/ error, int /*long*/ frame) { |
1119 } | |
1120 | |
1121 /* WebDownload */ | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1122 |
45 | 1123 void download_decideDestinationWithSuggestedFilename(int /*long*/ downloadId, int /*long*/ filename) { |
1124 NSString string = new NSString(filename); | |
1125 String name = string.getString(); | |
1126 FileDialog dialog = new FileDialog(browser.getShell(), DWT.SAVE); | |
1127 dialog.setText(DWT.getMessage ("DWT_FileDownload")); //$NON-NLS-1$ | |
1128 dialog.setFileName(name); | |
1129 String path = dialog.open(); | |
1130 NSURLDownload download = new NSURLDownload(downloadId); | |
1131 if (path is null) { | |
1132 /* cancel pressed */ | |
1133 download.cancel(); | |
1134 return; | |
1135 } | |
1136 download.setDestination(NSString.stringWith(path), true); | |
1137 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1138 |
45 | 1139 /* DOMEventListener */ |
1140 | |
1141 void handleEvent(int /*long*/ evtId) { | |
1142 NSString string = new NSString(OS.objc_msgSend(evtId, OS.sel_type)); | |
1143 String type = string.getString(); | |
1144 | |
1145 if (DOMEVENT_KEYDOWN.equals(type) || DOMEVENT_KEYUP.equals(type)) { | |
1146 DOMKeyboardEvent event = new DOMKeyboardEvent(evtId); | |
1147 | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1148 bool ctrl = event.ctrlKey(); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1149 bool shift = event.shiftKey(); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1150 bool alt = event.altKey(); |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1151 bool meta = event.metaKey(); |
45 | 1152 int keyCode = event.keyCode(); |
1153 int charCode = event.charCode(); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1154 |
45 | 1155 Event keyEvent = new Event(); |
1156 keyEvent.widget = browser; | |
1157 if (DOMEVENT_KEYDOWN.equals(type)) { | |
1158 keyEvent.type = DWT.KeyDown; | |
1159 } else { | |
1160 keyEvent.type = DWT.KeyUp; | |
1161 } | |
1162 keyEvent.keyCode = translateKey(keyCode); | |
1163 keyEvent.character = (char)charCode; | |
1164 keyEvent.stateMask = (alt ? DWT.ALT : 0) | (ctrl ? DWT.CTRL : 0) | (shift ? DWT.SHIFT : 0) | (meta ? DWT.COMMAND : 0); | |
1165 browser.notifyListeners(keyEvent.type, keyEvent); | |
1166 if (!keyEvent.doit) { | |
1167 event.preventDefault(); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1168 } |
45 | 1169 return; |
1170 } | |
1171 | |
1172 if (DOMEVENT_MOUSEWHEEL.equals(type)) { | |
1173 DOMWheelEvent event = new DOMWheelEvent(evtId); | |
1174 int clientX = event.clientX(); | |
1175 int clientY = event.clientY(); | |
1176 int delta = event.wheelDelta(); | |
1177 bool ctrl = event.ctrlKey(); | |
1178 bool shift = event.shiftKey(); | |
1179 bool alt = event.altKey(); | |
1180 bool meta = event.metaKey(); | |
1181 Event mouseEvent = new Event(); | |
1182 mouseEvent.type = DWT.MouseWheel; | |
1183 mouseEvent.widget = browser; | |
1184 mouseEvent.x = clientX; mouseEvent.y = clientY; | |
1185 mouseEvent.count = delta / 120; | |
1186 mouseEvent.stateMask = (alt ? DWT.ALT : 0) | (ctrl ? DWT.CTRL : 0) | (shift ? DWT.SHIFT : 0) | (meta ? DWT.COMMAND : 0); | |
1187 browser.notifyListeners (mouseEvent.type, mouseEvent); | |
1188 return; | |
1189 } | |
1190 | |
1191 /* mouse event */ | |
1192 | |
1193 DOMMouseEvent event = new DOMMouseEvent(evtId); | |
1194 | |
1195 int clientX = event.clientX(); | |
1196 int clientY = event.clientY(); | |
1197 int detail = event.detail(); | |
1198 int button = event.button(); | |
1199 bool ctrl = event.ctrlKey(); | |
1200 bool shift = event.shiftKey(); | |
1201 bool alt = event.altKey(); | |
1202 bool meta = event.metaKey(); | |
1203 | |
1204 Event mouseEvent = new Event (); | |
1205 mouseEvent.widget = browser; | |
1206 mouseEvent.x = clientX; mouseEvent.y = clientY; | |
1207 mouseEvent.stateMask = (alt ? DWT.ALT : 0) | (ctrl ? DWT.CTRL : 0) | (shift ? DWT.SHIFT : 0) | (meta ? DWT.COMMAND : 0); | |
1208 if (DOMEVENT_MOUSEDOWN.equals (type)) { | |
1209 mouseEvent.type = DWT.MouseDown; | |
1210 mouseEvent.button = button + 1; | |
1211 mouseEvent.count = detail; | |
1212 } else if (DOMEVENT_MOUSEUP.equals (type)) { | |
1213 mouseEvent.type = DWT.MouseUp; | |
1214 mouseEvent.button = button + 1; | |
1215 mouseEvent.count = detail; | |
1216 switch (mouseEvent.button) { | |
1217 case 1: mouseEvent.stateMask |= DWT.BUTTON1; break; | |
1218 case 2: mouseEvent.stateMask |= DWT.BUTTON2; break; | |
1219 case 3: mouseEvent.stateMask |= DWT.BUTTON3; break; | |
1220 case 4: mouseEvent.stateMask |= DWT.BUTTON4; break; | |
1221 case 5: mouseEvent.stateMask |= DWT.BUTTON5; break; | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1222 } |
45 | 1223 } else if (DOMEVENT_MOUSEMOVE.equals (type)) { |
1224 /* | |
1225 * Bug in Safari. Spurious and redundant mousemove events are received in | |
1226 * various contexts, including following every MouseUp. The workaround is | |
1227 * to not fire MouseMove events whose x and y values match the last MouseMove | |
1228 */ | |
1229 if (mouseEvent.x is lastMouseMoveX && mouseEvent.y is lastMouseMoveY) return; | |
1230 mouseEvent.type = DWT.MouseMove; | |
1231 lastMouseMoveX = mouseEvent.x; lastMouseMoveY = mouseEvent.y; | |
1232 } | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1233 |
45 | 1234 browser.notifyListeners (mouseEvent.type, mouseEvent); |
1235 if (detail is 2 && DOMEVENT_MOUSEDOWN.equals (type)) { | |
1236 mouseEvent = new Event (); | |
1237 mouseEvent.widget = browser; | |
1238 mouseEvent.x = clientX; mouseEvent.y = clientY; | |
1239 mouseEvent.stateMask = (alt ? DWT.ALT : 0) | (ctrl ? DWT.CTRL : 0) | (shift ? DWT.SHIFT : 0) | (meta ? DWT.COMMAND : 0); | |
1240 mouseEvent.type = DWT.MouseDoubleClick; | |
1241 mouseEvent.button = button + 1; | |
1242 mouseEvent.count = detail; | |
1243 browser.notifyListeners (mouseEvent.type, mouseEvent); | |
0
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1244 } |
380af2bdd8e5
Upload of whole dwt tree
Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
parents:
diff
changeset
|
1245 } |
45 | 1246 } |