]>
Commit | Line | Data |
---|---|---|
61b98a2d | 1 | ///////////////////////////////////////////////////////////////////////////// |
8290e3cd | 2 | // Name: src/gtk/webview_webkit.cpp |
61b98a2d SL |
3 | // Purpose: GTK WebKit backend for web view component |
4 | // Author: Marianne Gagnon, Robert Roebling | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 2010 Marianne Gagnon, 1998 Robert Roebling | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | // For compilers that support precompilation, includes "wx.h". | |
11 | #include "wx/wxprec.h" | |
12 | ||
ea179539 | 13 | #if wxUSE_WEBVIEW_WEBKIT |
61b98a2d SL |
14 | |
15 | #include "wx/stockitem.h" | |
8290e3cd | 16 | #include "wx/gtk/webview_webkit.h" |
61b98a2d SL |
17 | #include "wx/gtk/control.h" |
18 | #include "wx/gtk/private.h" | |
19 | #include "webkit/webkit.h" | |
20 | ||
21 | // ---------------------------------------------------------------------------- | |
22 | // GTK callbacks | |
23 | // ---------------------------------------------------------------------------- | |
24 | ||
25 | extern "C" | |
26 | { | |
27 | ||
28 | static void | |
d363c7db SL |
29 | wxgtk_webview_webkit_load_status(GtkWidget* widget, |
30 | GParamSpec*, | |
31 | wxWebViewWebKit *webKitCtrl) | |
61b98a2d SL |
32 | { |
33 | if (!webKitCtrl->m_ready) return; | |
34 | ||
35 | wxString url = webKitCtrl->GetCurrentURL(); | |
36 | ||
37 | WebKitLoadStatus status; | |
38 | g_object_get(G_OBJECT(widget), "load-status", &status, NULL); | |
39 | ||
40 | wxString target; // TODO: get target (if possible) | |
41 | ||
42 | if (status == WEBKIT_LOAD_FINISHED) | |
43 | { | |
44 | webKitCtrl->m_busy = false; | |
45 | wxWebNavigationEvent thisEvent(wxEVT_COMMAND_WEB_VIEW_LOADED, | |
46 | webKitCtrl->GetId(), | |
47 | url, target, false); | |
48 | ||
49 | if (webKitCtrl && webKitCtrl->GetEventHandler()) | |
50 | webKitCtrl->GetEventHandler()->ProcessEvent(thisEvent); | |
51 | } | |
52 | else if (status == WEBKIT_LOAD_COMMITTED) | |
53 | { | |
54 | webKitCtrl->m_busy = true; | |
55 | wxWebNavigationEvent thisEvent(wxEVT_COMMAND_WEB_VIEW_NAVIGATED, | |
56 | webKitCtrl->GetId(), | |
57 | url, target, false); | |
58 | ||
59 | if (webKitCtrl && webKitCtrl->GetEventHandler()) | |
60 | webKitCtrl->GetEventHandler()->ProcessEvent(thisEvent); | |
61 | } | |
62 | } | |
63 | ||
780f7262 SL |
64 | static gboolean |
65 | wxgtk_webview_webkit_navigation(WebKitWebView*, | |
66 | WebKitWebFrame *frame, | |
67 | WebKitNetworkRequest *request, | |
153530af | 68 | WebKitWebNavigationAction *, |
780f7262 SL |
69 | WebKitWebPolicyDecision *policy_decision, |
70 | wxWebViewWebKit *webKitCtrl) | |
61b98a2d SL |
71 | { |
72 | webKitCtrl->m_busy = true; | |
73 | ||
74 | const gchar* uri = webkit_network_request_get_uri(request); | |
75 | ||
76 | wxString target = webkit_web_frame_get_name (frame); | |
77 | wxWebNavigationEvent thisEvent(wxEVT_COMMAND_WEB_VIEW_NAVIGATING, | |
78 | webKitCtrl->GetId(), | |
79 | wxString( uri, wxConvUTF8 ), | |
80 | target, | |
81 | true); | |
82 | ||
83 | if (webKitCtrl && webKitCtrl->GetEventHandler()) | |
84 | webKitCtrl->GetEventHandler()->ProcessEvent(thisEvent); | |
85 | ||
86 | if (thisEvent.IsVetoed()) | |
87 | { | |
88 | webKitCtrl->m_busy = false; | |
780f7262 SL |
89 | webkit_web_policy_decision_ignore(policy_decision); |
90 | return TRUE; | |
61b98a2d SL |
91 | } |
92 | else | |
93 | { | |
780f7262 | 94 | return FALSE; |
61b98a2d SL |
95 | } |
96 | } | |
97 | ||
98 | static gboolean | |
d363c7db SL |
99 | wxgtk_webview_webkit_error(WebKitWebView*, |
100 | WebKitWebFrame*, | |
101 | gchar *uri, | |
102 | gpointer web_error, | |
103 | wxWebViewWebKit* webKitWindow) | |
61b98a2d SL |
104 | { |
105 | webKitWindow->m_busy = false; | |
106 | wxWebNavigationError type = wxWEB_NAV_ERR_OTHER; | |
107 | ||
108 | GError* error = (GError*)web_error; | |
109 | wxString description(error->message, wxConvUTF8); | |
110 | ||
111 | if (strcmp(g_quark_to_string(error->domain), "soup_http_error_quark") == 0) | |
112 | { | |
113 | switch (error->code) | |
114 | { | |
115 | case SOUP_STATUS_CANCELLED: | |
116 | type = wxWEB_NAV_ERR_USER_CANCELLED; | |
117 | break; | |
118 | ||
119 | case SOUP_STATUS_CANT_RESOLVE: | |
120 | case SOUP_STATUS_NOT_FOUND: | |
121 | type = wxWEB_NAV_ERR_NOT_FOUND; | |
122 | break; | |
123 | ||
124 | case SOUP_STATUS_CANT_RESOLVE_PROXY: | |
125 | case SOUP_STATUS_CANT_CONNECT: | |
126 | case SOUP_STATUS_CANT_CONNECT_PROXY: | |
127 | case SOUP_STATUS_SSL_FAILED: | |
128 | case SOUP_STATUS_IO_ERROR: | |
129 | type = wxWEB_NAV_ERR_CONNECTION; | |
130 | break; | |
131 | ||
132 | case SOUP_STATUS_MALFORMED: | |
133 | //case SOUP_STATUS_TOO_MANY_REDIRECTS: | |
134 | type = wxWEB_NAV_ERR_REQUEST; | |
135 | break; | |
136 | ||
137 | //case SOUP_STATUS_NO_CONTENT: | |
138 | //case SOUP_STATUS_RESET_CONTENT: | |
139 | ||
140 | case SOUP_STATUS_BAD_REQUEST: | |
141 | type = wxWEB_NAV_ERR_REQUEST; | |
142 | break; | |
143 | ||
144 | case SOUP_STATUS_UNAUTHORIZED: | |
145 | case SOUP_STATUS_FORBIDDEN: | |
146 | type = wxWEB_NAV_ERR_AUTH; | |
147 | break; | |
148 | ||
149 | case SOUP_STATUS_METHOD_NOT_ALLOWED: | |
150 | case SOUP_STATUS_NOT_ACCEPTABLE: | |
151 | type = wxWEB_NAV_ERR_SECURITY; | |
152 | break; | |
153 | ||
154 | case SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED: | |
155 | type = wxWEB_NAV_ERR_AUTH; | |
156 | break; | |
157 | ||
158 | case SOUP_STATUS_REQUEST_TIMEOUT: | |
159 | type = wxWEB_NAV_ERR_CONNECTION; | |
160 | break; | |
161 | ||
162 | //case SOUP_STATUS_PAYMENT_REQUIRED: | |
163 | case SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE: | |
164 | case SOUP_STATUS_REQUEST_URI_TOO_LONG: | |
165 | case SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE: | |
166 | type = wxWEB_NAV_ERR_REQUEST; | |
167 | break; | |
168 | ||
169 | case SOUP_STATUS_BAD_GATEWAY: | |
170 | case SOUP_STATUS_SERVICE_UNAVAILABLE: | |
171 | case SOUP_STATUS_GATEWAY_TIMEOUT: | |
172 | type = wxWEB_NAV_ERR_CONNECTION; | |
173 | break; | |
174 | ||
175 | case SOUP_STATUS_HTTP_VERSION_NOT_SUPPORTED: | |
176 | type = wxWEB_NAV_ERR_REQUEST; | |
177 | break; | |
178 | //case SOUP_STATUS_INSUFFICIENT_STORAGE: | |
179 | //case SOUP_STATUS_NOT_EXTENDED: | |
180 | } | |
181 | } | |
182 | else if (strcmp(g_quark_to_string(error->domain), | |
183 | "webkit-network-error-quark") == 0) | |
184 | { | |
185 | switch (error->code) | |
186 | { | |
187 | //WEBKIT_NETWORK_ERROR_FAILED: | |
188 | //WEBKIT_NETWORK_ERROR_TRANSPORT: | |
189 | ||
190 | case WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL: | |
191 | type = wxWEB_NAV_ERR_REQUEST; | |
192 | break; | |
193 | ||
194 | case WEBKIT_NETWORK_ERROR_CANCELLED: | |
195 | type = wxWEB_NAV_ERR_USER_CANCELLED; | |
196 | break; | |
197 | ||
198 | case WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST: | |
199 | type = wxWEB_NAV_ERR_NOT_FOUND; | |
200 | break; | |
201 | } | |
202 | } | |
203 | else if (strcmp(g_quark_to_string(error->domain), | |
204 | "webkit-policy-error-quark") == 0) | |
205 | { | |
206 | switch (error->code) | |
207 | { | |
208 | //case WEBKIT_POLICY_ERROR_FAILED: | |
209 | //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_MIME_TYPE: | |
210 | //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_URL: | |
211 | //case WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE: | |
212 | case WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT: | |
213 | type = wxWEB_NAV_ERR_SECURITY; | |
214 | break; | |
215 | } | |
216 | } | |
217 | /* | |
218 | webkit_plugin_error_quark | |
219 | else | |
220 | { | |
221 | printf("Error domain %s\n", g_quark_to_string(error->domain)); | |
222 | } | |
223 | */ | |
224 | ||
225 | wxWebNavigationEvent thisEvent(wxEVT_COMMAND_WEB_VIEW_ERROR, | |
226 | webKitWindow->GetId(), | |
227 | uri, | |
228 | wxEmptyString, | |
229 | false); | |
230 | thisEvent.SetString(description); | |
231 | thisEvent.SetInt(type); | |
232 | ||
233 | if (webKitWindow && webKitWindow->GetEventHandler()) | |
234 | { | |
235 | webKitWindow->GetEventHandler()->ProcessEvent(thisEvent); | |
236 | } | |
237 | ||
238 | return FALSE; | |
239 | } | |
240 | ||
0016bf1d | 241 | static gboolean |
d363c7db SL |
242 | wxgtk_webview_webkit_new_window(WebKitWebView*, |
243 | WebKitWebFrame *frame, | |
244 | WebKitNetworkRequest *request, | |
245 | WebKitWebNavigationAction*, | |
246 | WebKitWebPolicyDecision *policy_decision, | |
247 | wxWebViewWebKit *webKitCtrl) | |
0016bf1d SL |
248 | { |
249 | const gchar* uri = webkit_network_request_get_uri(request); | |
250 | ||
251 | wxString target = webkit_web_frame_get_name (frame); | |
252 | wxWebNavigationEvent thisEvent(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, | |
253 | webKitCtrl->GetId(), | |
254 | wxString( uri, wxConvUTF8 ), | |
255 | target, | |
256 | true); | |
257 | ||
258 | if (webKitCtrl && webKitCtrl->GetEventHandler()) | |
259 | webKitCtrl->GetEventHandler()->ProcessEvent(thisEvent); | |
260 | ||
75b3bb61 SL |
261 | //We always want the user to handle this themselves |
262 | webkit_web_policy_decision_ignore(policy_decision); | |
0016bf1d SL |
263 | return TRUE; |
264 | } | |
61b98a2d | 265 | |
153530af SL |
266 | static void |
267 | wxgtk_webview_webkit_title_changed(WebKitWebView *webView, | |
268 | WebKitWebFrame *frame, | |
269 | gchar *title, | |
270 | wxWebViewWebKit *webKitCtrl) | |
271 | { | |
272 | wxWebNavigationEvent thisEvent(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, | |
273 | webKitCtrl->GetId(), | |
274 | webKitCtrl->GetCurrentURL(), | |
275 | "", | |
276 | true); | |
277 | thisEvent.SetString(wxString(title, wxConvUTF8)); | |
278 | ||
279 | if (webKitCtrl && webKitCtrl->GetEventHandler()) | |
280 | webKitCtrl->GetEventHandler()->ProcessEvent(thisEvent); | |
281 | ||
282 | } | |
283 | ||
61b98a2d SL |
284 | } // extern "C" |
285 | ||
286 | //----------------------------------------------------------------------------- | |
b64b4e70 | 287 | // wxWebViewWebKit |
61b98a2d SL |
288 | //----------------------------------------------------------------------------- |
289 | ||
b64b4e70 | 290 | //IMPLEMENT_DYNAMIC_CLASS(wxWebViewWebKit, wxControl) |
61b98a2d | 291 | |
b64b4e70 | 292 | bool wxWebViewWebKit::Create(wxWindow *parent, |
61b98a2d SL |
293 | wxWindowID id, |
294 | const wxString &url, | |
295 | const wxPoint& pos, | |
296 | const wxSize& size, | |
297 | long style, | |
298 | const wxString& name) | |
299 | { | |
300 | m_ready = false; | |
301 | m_busy = false; | |
302 | ||
303 | if (!PreCreation( parent, pos, size ) || | |
304 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
305 | { | |
b64b4e70 | 306 | wxFAIL_MSG( wxT("wxWebViewWebKit creation failed") ); |
61b98a2d SL |
307 | return false; |
308 | } | |
309 | ||
310 | GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL); | |
311 | web_view = webkit_web_view_new (); | |
312 | g_object_ref(web_view); // TODO: check memory management | |
313 | ||
314 | m_widget = scrolled_window; | |
315 | g_object_ref(m_widget); // TODO: check memory management | |
316 | ||
317 | /* Place the WebKitWebView in the GtkScrolledWindow */ | |
318 | gtk_container_add (GTK_CONTAINER (scrolled_window), web_view); | |
319 | gtk_widget_show(m_widget); | |
320 | gtk_widget_show(web_view); | |
321 | ||
322 | g_signal_connect_after(web_view, "notify::load-status", | |
d363c7db | 323 | G_CALLBACK(wxgtk_webview_webkit_load_status), |
61b98a2d | 324 | this); |
780f7262 SL |
325 | g_signal_connect_after(web_view, "navigation-policy-decision-requested", |
326 | G_CALLBACK(wxgtk_webview_webkit_navigation), | |
61b98a2d SL |
327 | this); |
328 | g_signal_connect_after(web_view, "load-error", | |
d363c7db | 329 | G_CALLBACK(wxgtk_webview_webkit_error), |
61b98a2d SL |
330 | this); |
331 | ||
0016bf1d | 332 | g_signal_connect_after(web_view, "new-window-policy-decision-requested", |
d363c7db | 333 | G_CALLBACK(wxgtk_webview_webkit_new_window), this); |
61b98a2d | 334 | |
153530af SL |
335 | g_signal_connect_after(web_view, "title-changed", |
336 | G_CALLBACK(wxgtk_webview_webkit_title_changed), this); | |
337 | ||
61b98a2d SL |
338 | m_parent->DoAddChild( this ); |
339 | ||
340 | PostCreation(size); | |
341 | ||
342 | /* Open a webpage */ | |
343 | webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), url); | |
344 | ||
152a5808 SL |
345 | //Get the initial history limit so we can enable and disable it later |
346 | WebKitWebBackForwardList* history; | |
347 | history = webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view)); | |
348 | m_historyLimit = webkit_web_back_forward_list_get_limit(history); | |
349 | ||
61b98a2d SL |
350 | m_ready = true; |
351 | ||
352 | return true; | |
353 | } | |
354 | ||
b64b4e70 | 355 | bool wxWebViewWebKit::Enable( bool enable ) |
61b98a2d SL |
356 | { |
357 | if (!wxControl::Enable(enable)) | |
358 | return false; | |
359 | ||
360 | gtk_widget_set_sensitive(GTK_BIN(m_widget)->child, enable); | |
361 | ||
362 | //if (enable) | |
363 | // GTKFixSensitivity(); | |
364 | ||
365 | return true; | |
366 | } | |
367 | ||
368 | GdkWindow* | |
b64b4e70 | 369 | wxWebViewWebKit::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const |
61b98a2d SL |
370 | { |
371 | GdkWindow* window = gtk_widget_get_parent_window(m_widget); | |
372 | return window; | |
373 | } | |
374 | ||
b64b4e70 | 375 | void wxWebViewWebKit::ZoomIn() |
61b98a2d SL |
376 | { |
377 | webkit_web_view_zoom_in (WEBKIT_WEB_VIEW(web_view)); | |
378 | } | |
379 | ||
b64b4e70 | 380 | void wxWebViewWebKit::ZoomOut() |
61b98a2d SL |
381 | { |
382 | webkit_web_view_zoom_out (WEBKIT_WEB_VIEW(web_view)); | |
383 | } | |
384 | ||
b64b4e70 | 385 | void wxWebViewWebKit::SetWebkitZoom(float level) |
61b98a2d SL |
386 | { |
387 | webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW(web_view), level); | |
388 | } | |
389 | ||
b64b4e70 | 390 | float wxWebViewWebKit::GetWebkitZoom() |
61b98a2d SL |
391 | { |
392 | return webkit_web_view_get_zoom_level (WEBKIT_WEB_VIEW(web_view)); | |
393 | } | |
394 | ||
b64b4e70 | 395 | void wxWebViewWebKit::Stop() |
61b98a2d SL |
396 | { |
397 | webkit_web_view_stop_loading (WEBKIT_WEB_VIEW(web_view)); | |
398 | } | |
399 | ||
b64b4e70 | 400 | void wxWebViewWebKit::Reload(wxWebViewReloadFlags flags) |
61b98a2d SL |
401 | { |
402 | if (flags & wxWEB_VIEW_RELOAD_NO_CACHE) | |
403 | { | |
404 | webkit_web_view_reload_bypass_cache (WEBKIT_WEB_VIEW(web_view)); | |
405 | } | |
406 | else | |
407 | { | |
408 | webkit_web_view_reload (WEBKIT_WEB_VIEW(web_view)); | |
409 | } | |
410 | } | |
411 | ||
b64b4e70 | 412 | void wxWebViewWebKit::LoadUrl(const wxString& url) |
61b98a2d | 413 | { |
b5374b5c | 414 | webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view), wxGTK_CONV(url)); |
61b98a2d SL |
415 | } |
416 | ||
417 | ||
b64b4e70 | 418 | void wxWebViewWebKit::GoBack() |
61b98a2d SL |
419 | { |
420 | webkit_web_view_go_back (WEBKIT_WEB_VIEW(web_view)); | |
421 | } | |
422 | ||
b64b4e70 | 423 | void wxWebViewWebKit::GoForward() |
61b98a2d SL |
424 | { |
425 | webkit_web_view_go_forward (WEBKIT_WEB_VIEW(web_view)); | |
426 | } | |
427 | ||
428 | ||
b64b4e70 | 429 | bool wxWebViewWebKit::CanGoBack() |
61b98a2d SL |
430 | { |
431 | return webkit_web_view_can_go_back (WEBKIT_WEB_VIEW(web_view)); | |
432 | } | |
433 | ||
434 | ||
b64b4e70 | 435 | bool wxWebViewWebKit::CanGoForward() |
61b98a2d SL |
436 | { |
437 | return webkit_web_view_can_go_forward (WEBKIT_WEB_VIEW(web_view)); | |
438 | } | |
439 | ||
152a5808 SL |
440 | void wxWebViewWebKit::ClearHistory() |
441 | { | |
442 | WebKitWebBackForwardList* history; | |
443 | history = webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view)); | |
444 | webkit_web_back_forward_list_clear(history); | |
445 | } | |
446 | ||
447 | void wxWebViewWebKit::EnableHistory(bool enable) | |
448 | { | |
449 | WebKitWebBackForwardList* history; | |
450 | history = webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view)); | |
451 | if(enable) | |
452 | { | |
453 | webkit_web_back_forward_list_set_limit(history, m_historyLimit); | |
454 | } | |
455 | else | |
456 | { | |
457 | webkit_web_back_forward_list_set_limit(history, 0); | |
458 | } | |
459 | } | |
61b98a2d | 460 | |
19fc1a2f SL |
461 | wxVector<wxSharedPtr<wxWebHistoryItem> > wxWebViewWebKit::GetBackwardHistory() |
462 | { | |
463 | wxVector<wxSharedPtr<wxWebHistoryItem> > backhist; | |
464 | WebKitWebBackForwardList* history; | |
465 | history = webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view)); | |
466 | GList* list = webkit_web_back_forward_list_get_back_list_with_limit(history, | |
467 | m_historyLimit); | |
468 | //We need to iterate in reverse to get the order we desire | |
469 | for(int i = g_list_length(list) - 1; i >= 0 ; i--) | |
470 | { | |
471 | WebKitWebHistoryItem* gtkitem = (WebKitWebHistoryItem*)g_list_nth_data(list, i); | |
472 | wxSharedPtr<wxWebHistoryItem> item(new wxWebHistoryItem( | |
473 | webkit_web_history_item_get_uri(gtkitem), | |
474 | webkit_web_history_item_get_title(gtkitem))); | |
475 | backhist.push_back(item); | |
476 | m_historyMap[item] = gtkitem; | |
477 | } | |
478 | return backhist; | |
479 | } | |
480 | ||
481 | wxVector<wxSharedPtr<wxWebHistoryItem> > wxWebViewWebKit::GetForwardHistory() | |
482 | { | |
483 | wxVector<wxSharedPtr<wxWebHistoryItem> > forwardhist; | |
484 | WebKitWebBackForwardList* history; | |
485 | history = webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view)); | |
486 | GList* list = webkit_web_back_forward_list_get_forward_list_with_limit(history, | |
487 | m_historyLimit); | |
488 | for(guint i = 0; i < g_list_length(list); i++) | |
489 | { | |
490 | WebKitWebHistoryItem* gtkitem = (WebKitWebHistoryItem*)g_list_nth_data(list, i); | |
491 | wxSharedPtr<wxWebHistoryItem> item(new wxWebHistoryItem( | |
492 | webkit_web_history_item_get_uri(gtkitem), | |
493 | webkit_web_history_item_get_title(gtkitem))); | |
494 | forwardhist.push_back(item); | |
495 | m_historyMap[item] = gtkitem; | |
496 | } | |
497 | return forwardhist; | |
498 | } | |
499 | ||
500 | void wxWebViewWebKit::LoadHistoryItem(wxSharedPtr<wxWebHistoryItem> item) | |
501 | { | |
502 | WebKitWebHistoryItem* gtkitem = m_historyMap[item]; | |
503 | if(gtkitem) | |
504 | { | |
505 | WebKitWebBackForwardList* history; | |
506 | history = webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view)); | |
507 | webkit_web_back_forward_list_go_to_item(history, gtkitem); | |
508 | } | |
509 | } | |
510 | ||
ae26e17b SL |
511 | bool wxWebViewWebKit::CanCut() |
512 | { | |
513 | return webkit_web_view_can_cut_clipboard(WEBKIT_WEB_VIEW(web_view)); | |
514 | } | |
515 | ||
516 | bool wxWebViewWebKit::CanCopy() | |
517 | { | |
518 | return webkit_web_view_can_copy_clipboard(WEBKIT_WEB_VIEW(web_view)); | |
519 | } | |
520 | ||
521 | bool wxWebViewWebKit::CanPaste() | |
522 | { | |
523 | return webkit_web_view_can_paste_clipboard(WEBKIT_WEB_VIEW(web_view)); | |
524 | } | |
525 | ||
526 | void wxWebViewWebKit::Cut() | |
527 | { | |
528 | webkit_web_view_cut_clipboard(WEBKIT_WEB_VIEW(web_view)); | |
529 | } | |
530 | ||
531 | void wxWebViewWebKit::Copy() | |
532 | { | |
533 | webkit_web_view_copy_clipboard(WEBKIT_WEB_VIEW(web_view)); | |
534 | } | |
535 | ||
536 | void wxWebViewWebKit::Paste() | |
537 | { | |
538 | webkit_web_view_paste_clipboard(WEBKIT_WEB_VIEW(web_view)); | |
539 | } | |
540 | ||
97e49559 SL |
541 | bool wxWebViewWebKit::CanUndo() |
542 | { | |
543 | return webkit_web_view_can_undo(WEBKIT_WEB_VIEW(web_view)); | |
544 | } | |
545 | ||
546 | bool wxWebViewWebKit::CanRedo() | |
547 | { | |
548 | return webkit_web_view_can_redo(WEBKIT_WEB_VIEW(web_view)); | |
549 | } | |
550 | ||
551 | void wxWebViewWebKit::Undo() | |
552 | { | |
553 | webkit_web_view_undo(WEBKIT_WEB_VIEW(web_view)); | |
554 | } | |
555 | ||
556 | void wxWebViewWebKit::Redo() | |
557 | { | |
558 | webkit_web_view_redo(WEBKIT_WEB_VIEW(web_view)); | |
559 | } | |
560 | ||
b64b4e70 | 561 | wxString wxWebViewWebKit::GetCurrentURL() |
61b98a2d SL |
562 | { |
563 | // FIXME: check which encoding the web kit control uses instead of | |
564 | // assuming UTF8 (here and elsewhere too) | |
565 | return wxString::FromUTF8(webkit_web_view_get_uri( | |
566 | WEBKIT_WEB_VIEW(web_view))); | |
567 | } | |
568 | ||
569 | ||
b64b4e70 | 570 | wxString wxWebViewWebKit::GetCurrentTitle() |
61b98a2d SL |
571 | { |
572 | return wxString::FromUTF8(webkit_web_view_get_title( | |
573 | WEBKIT_WEB_VIEW(web_view))); | |
574 | } | |
575 | ||
576 | ||
b64b4e70 | 577 | wxString wxWebViewWebKit::GetPageSource() |
61b98a2d SL |
578 | { |
579 | WebKitWebFrame* frame = webkit_web_view_get_main_frame( | |
580 | WEBKIT_WEB_VIEW(web_view)); | |
581 | WebKitWebDataSource* src = webkit_web_frame_get_data_source (frame); | |
582 | ||
583 | // TODO: check encoding with | |
584 | // const gchar* | |
585 | // webkit_web_data_source_get_encoding(WebKitWebDataSource *data_source); | |
586 | return wxString(webkit_web_data_source_get_data (src)->str, wxConvUTF8); | |
587 | } | |
588 | ||
589 | ||
b64b4e70 | 590 | wxWebViewZoom wxWebViewWebKit::GetZoom() |
61b98a2d SL |
591 | { |
592 | float zoom = GetWebkitZoom(); | |
593 | ||
594 | // arbitrary way to map float zoom to our common zoom enum | |
595 | if (zoom <= 0.65) | |
596 | { | |
597 | return wxWEB_VIEW_ZOOM_TINY; | |
598 | } | |
599 | else if (zoom > 0.65 && zoom <= 0.90) | |
600 | { | |
601 | return wxWEB_VIEW_ZOOM_SMALL; | |
602 | } | |
603 | else if (zoom > 0.90 && zoom <= 1.15) | |
604 | { | |
605 | return wxWEB_VIEW_ZOOM_MEDIUM; | |
606 | } | |
607 | else if (zoom > 1.15 && zoom <= 1.45) | |
608 | { | |
609 | return wxWEB_VIEW_ZOOM_LARGE; | |
610 | } | |
611 | else if (zoom > 1.45) | |
612 | { | |
613 | return wxWEB_VIEW_ZOOM_LARGEST; | |
614 | } | |
615 | ||
616 | // to shut up compilers, this can never be reached logically | |
617 | wxASSERT(false); | |
618 | return wxWEB_VIEW_ZOOM_MEDIUM; | |
619 | } | |
620 | ||
621 | ||
b64b4e70 | 622 | void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom) |
61b98a2d SL |
623 | { |
624 | // arbitrary way to map our common zoom enum to float zoom | |
625 | switch (zoom) | |
626 | { | |
627 | case wxWEB_VIEW_ZOOM_TINY: | |
628 | SetWebkitZoom(0.6f); | |
629 | break; | |
630 | ||
631 | case wxWEB_VIEW_ZOOM_SMALL: | |
632 | SetWebkitZoom(0.8f); | |
633 | break; | |
634 | ||
635 | case wxWEB_VIEW_ZOOM_MEDIUM: | |
636 | SetWebkitZoom(1.0f); | |
637 | break; | |
638 | ||
639 | case wxWEB_VIEW_ZOOM_LARGE: | |
640 | SetWebkitZoom(1.3); | |
641 | break; | |
642 | ||
643 | case wxWEB_VIEW_ZOOM_LARGEST: | |
644 | SetWebkitZoom(1.6); | |
645 | break; | |
646 | ||
647 | default: | |
648 | wxASSERT(false); | |
649 | } | |
650 | } | |
651 | ||
b64b4e70 | 652 | void wxWebViewWebKit::SetZoomType(wxWebViewZoomType type) |
61b98a2d SL |
653 | { |
654 | webkit_web_view_set_full_content_zoom(WEBKIT_WEB_VIEW(web_view), | |
655 | (type == wxWEB_VIEW_ZOOM_TYPE_LAYOUT ? | |
656 | TRUE : FALSE)); | |
657 | } | |
658 | ||
b64b4e70 | 659 | wxWebViewZoomType wxWebViewWebKit::GetZoomType() const |
61b98a2d SL |
660 | { |
661 | gboolean fczoom = webkit_web_view_get_full_content_zoom( | |
662 | WEBKIT_WEB_VIEW(web_view)); | |
663 | ||
664 | if (fczoom) return wxWEB_VIEW_ZOOM_TYPE_LAYOUT; | |
665 | else return wxWEB_VIEW_ZOOM_TYPE_TEXT; | |
666 | } | |
667 | ||
b64b4e70 | 668 | bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType) const |
61b98a2d SL |
669 | { |
670 | // this port supports all zoom types | |
671 | return true; | |
672 | } | |
673 | ||
b64b4e70 | 674 | void wxWebViewWebKit::SetPage(const wxString& html, const wxString& baseUri) |
61b98a2d SL |
675 | { |
676 | webkit_web_view_load_string (WEBKIT_WEB_VIEW(web_view), | |
677 | html.mb_str(wxConvUTF8), | |
678 | "text/html", | |
679 | "UTF-8", | |
680 | baseUri.mb_str(wxConvUTF8)); | |
681 | } | |
682 | ||
b64b4e70 | 683 | void wxWebViewWebKit::Print() |
61b98a2d SL |
684 | { |
685 | WebKitWebFrame* frame = webkit_web_view_get_main_frame( | |
686 | WEBKIT_WEB_VIEW(web_view)); | |
687 | webkit_web_frame_print (frame); | |
688 | ||
689 | // GtkPrintOperationResult webkit_web_frame_print_full | |
690 | // (WebKitWebFrame *frame, | |
691 | // GtkPrintOperation *operation, | |
692 | // GtkPrintOperationAction action, | |
693 | // GError **error); | |
694 | ||
695 | } | |
696 | ||
697 | ||
b64b4e70 | 698 | bool wxWebViewWebKit::IsBusy() |
61b98a2d SL |
699 | { |
700 | return m_busy; | |
701 | ||
702 | // This code looks nice but returns true after a page was cancelled | |
703 | /* | |
704 | WebKitLoadStatus status = webkit_web_view_get_load_status | |
705 | (WEBKIT_WEB_VIEW(web_view)); | |
706 | ||
707 | ||
708 | #if WEBKIT_CHECK_VERSION(1,1,16) | |
709 | // WEBKIT_LOAD_FAILED is new in webkit 1.1.16 | |
710 | if (status == WEBKIT_LOAD_FAILED) | |
711 | { | |
712 | return false; | |
713 | } | |
714 | #endif | |
715 | if (status == WEBKIT_LOAD_FINISHED) | |
716 | { | |
717 | return false; | |
718 | } | |
719 | ||
720 | return true; | |
721 | */ | |
722 | } | |
723 | ||
c7cbe308 SL |
724 | void wxWebViewWebKit::SetEditable(bool enable) |
725 | { | |
726 | webkit_web_view_set_editable(WEBKIT_WEB_VIEW(web_view), enable); | |
727 | } | |
728 | ||
729 | bool wxWebViewWebKit::IsEditable() | |
730 | { | |
731 | return webkit_web_view_get_editable(WEBKIT_WEB_VIEW(web_view)); | |
732 | } | |
733 | ||
63a65070 SL |
734 | void wxWebViewWebKit::DeleteSelection() |
735 | { | |
736 | webkit_web_view_delete_selection(WEBKIT_WEB_VIEW(web_view)); | |
737 | } | |
738 | ||
739 | bool wxWebViewWebKit::HasSelection() | |
740 | { | |
741 | return webkit_web_view_has_selection(WEBKIT_WEB_VIEW(web_view)); | |
742 | } | |
743 | ||
744 | void wxWebViewWebKit::SelectAll() | |
745 | { | |
746 | webkit_web_view_select_all(WEBKIT_WEB_VIEW(web_view)); | |
747 | } | |
748 | ||
c9355a3d SL |
749 | wxString wxWebViewWebKit::GetSelectedText() |
750 | { | |
751 | WebKitDOMDocument* doc; | |
752 | WebKitDOMDOMWindow* win; | |
753 | WebKitDOMDOMSelection* sel; | |
754 | WebKitDOMRange* range; | |
755 | ||
756 | doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view)); | |
757 | win = webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc)); | |
758 | sel = webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win)); | |
759 | range = webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel), | |
760 | 0, NULL); | |
761 | return wxString(webkit_dom_range_get_text(WEBKIT_DOM_RANGE(range)), | |
762 | wxConvUTF8); | |
763 | } | |
63a65070 | 764 | |
97ba4d81 | 765 | wxString wxWebViewWebKit::GetSelectedSource() |
0fe8a1b6 SL |
766 | { |
767 | WebKitDOMDocument* doc; | |
768 | WebKitDOMDOMWindow* win; | |
769 | WebKitDOMDOMSelection* sel; | |
770 | WebKitDOMRange* range; | |
771 | WebKitDOMElement* div; | |
772 | WebKitDOMDocumentFragment* clone; | |
773 | WebKitDOMHTMLElement* html; | |
774 | ||
775 | doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view)); | |
776 | win = webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc)); | |
777 | sel = webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win)); | |
778 | range = webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel), | |
779 | 0, NULL); | |
780 | div = webkit_dom_document_create_element(WEBKIT_DOM_DOCUMENT(doc), "div", NULL); | |
781 | ||
782 | clone = webkit_dom_range_clone_contents(WEBKIT_DOM_RANGE(range), NULL); | |
783 | webkit_dom_node_append_child(&div->parent_instance, &clone->parent_instance, NULL); | |
784 | html = (WebKitDOMHTMLElement*)div; | |
785 | ||
786 | return wxString(webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(html)), | |
787 | wxConvUTF8); | |
788 | } | |
789 | ||
41933aa5 SL |
790 | void wxWebViewWebKit::ClearSelection() |
791 | { | |
792 | WebKitDOMDocument* doc; | |
793 | WebKitDOMDOMWindow* win; | |
794 | WebKitDOMDOMSelection* sel; | |
795 | ||
796 | doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view)); | |
797 | win = webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc)); | |
798 | sel = webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win)); | |
799 | webkit_dom_dom_selection_remove_all_ranges(WEBKIT_DOM_DOM_SELECTION(sel)); | |
800 | ||
801 | } | |
802 | ||
241b769f SL |
803 | wxString wxWebViewWebKit::GetPageText() |
804 | { | |
805 | WebKitDOMDocument* doc; | |
806 | WebKitDOMHTMLElement* body; | |
807 | ||
808 | doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view)); | |
809 | body = webkit_dom_document_get_body(WEBKIT_DOM_DOCUMENT(doc)); | |
810 | return wxString(webkit_dom_html_element_get_inner_text(WEBKIT_DOM_HTML_ELEMENT(body)), | |
811 | wxConvUTF8); | |
812 | } | |
813 | ||
c9ccc09c SL |
814 | void wxWebViewWebKit::RunScript(const wxString& javascript) |
815 | { | |
816 | webkit_web_view_execute_script(WEBKIT_WEB_VIEW(web_view), | |
817 | javascript.mb_str(wxConvUTF8)); | |
818 | } | |
819 | ||
61b98a2d SL |
820 | // static |
821 | wxVisualAttributes | |
b64b4e70 | 822 | wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) |
61b98a2d SL |
823 | { |
824 | return GetDefaultAttributesFromGTKWidget(webkit_web_view_new); | |
825 | } | |
826 | ||
827 | ||
828 | #endif // wxHAVE_WEB_BACKEND_GTK_WEBKIT |