1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/webview_webkit.cpp
3 // Purpose: GTK WebKit backend for web view component
4 // Author: Marianne Gagnon, Robert Roebling
6 // Copyright: (c) 2010 Marianne Gagnon, 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_WEBVIEW_WEBKIT
15 #include "wx/stockitem.h"
16 #include "wx/gtk/webview_webkit.h"
17 #include "wx/gtk/control.h"
18 #include "wx/gtk/private.h"
19 #include "wx/filesys.h"
20 #include "wx/base64.h"
21 #include "webkit/webkit.h"
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
31 wxgtk_webview_webkit_load_status(GtkWidget
* widget
,
33 wxWebViewWebKit
*webKitCtrl
)
35 if (!webKitCtrl
->m_ready
) return;
37 wxString url
= webKitCtrl
->GetCurrentURL();
39 WebKitLoadStatus status
;
40 g_object_get(G_OBJECT(widget
), "load-status", &status
, NULL
);
42 wxString target
; // TODO: get target (if possible)
44 if (status
== WEBKIT_LOAD_FINISHED
)
46 webKitCtrl
->m_busy
= false;
47 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_LOADED
,
51 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
52 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
54 else if (status
== WEBKIT_LOAD_COMMITTED
)
56 webKitCtrl
->m_busy
= true;
57 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
61 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
62 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
67 wxgtk_webview_webkit_navigation(WebKitWebView
*,
68 WebKitWebFrame
*frame
,
69 WebKitNetworkRequest
*request
,
70 WebKitWebNavigationAction
*,
71 WebKitWebPolicyDecision
*policy_decision
,
72 wxWebViewWebKit
*webKitCtrl
)
74 if(webKitCtrl
->m_guard
)
76 webKitCtrl
->m_guard
= false;
77 //We set this to make sure that we don't try to load the page again from
78 //the resource request callback
79 webKitCtrl
->m_vfsurl
= webkit_network_request_get_uri(request
);
80 webkit_web_policy_decision_use(policy_decision
);
84 webKitCtrl
->m_busy
= true;
86 const gchar
* uri
= webkit_network_request_get_uri(request
);
88 wxString target
= webkit_web_frame_get_name (frame
);
89 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
91 wxString( uri
, wxConvUTF8
),
95 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
96 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
100 webKitCtrl
->m_busy
= false;
101 webkit_web_policy_decision_ignore(policy_decision
);
106 wxString wxuri
= uri
;
107 wxSharedPtr
<wxWebViewHandler
> handler
;
108 wxVector
<wxSharedPtr
<wxWebViewHandler
> > hanlders
= webKitCtrl
->GetHandlers();
109 //We are not vetoed so see if we match one of the additional handlers
110 for(wxVector
<wxSharedPtr
<wxWebViewHandler
> >::iterator it
= hanlders
.begin();
111 it
!= hanlders
.end(); ++it
)
113 if(wxuri
.substr(0, (*it
)->GetName().length()) == (*it
)->GetName())
118 //If we found a handler we can then use it to load the file directly
122 webKitCtrl
->m_guard
= true;
123 wxFSFile
* file
= handler
->GetFile(wxuri
);
126 webKitCtrl
->SetPage(*file
->GetStream(), wxuri
);
128 //We need to throw some sort of error here if file is NULL
129 webkit_web_policy_decision_ignore(policy_decision
);
137 wxgtk_webview_webkit_error(WebKitWebView
*,
141 wxWebViewWebKit
* webKitWindow
)
143 webKitWindow
->m_busy
= false;
144 wxWebViewNavigationError type
= wxWEB_NAV_ERR_OTHER
;
146 GError
* error
= (GError
*)web_error
;
147 wxString
description(error
->message
, wxConvUTF8
);
149 if (strcmp(g_quark_to_string(error
->domain
), "soup_http_error_quark") == 0)
153 case SOUP_STATUS_CANCELLED
:
154 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
157 case SOUP_STATUS_CANT_RESOLVE
:
158 case SOUP_STATUS_NOT_FOUND
:
159 type
= wxWEB_NAV_ERR_NOT_FOUND
;
162 case SOUP_STATUS_CANT_RESOLVE_PROXY
:
163 case SOUP_STATUS_CANT_CONNECT
:
164 case SOUP_STATUS_CANT_CONNECT_PROXY
:
165 case SOUP_STATUS_SSL_FAILED
:
166 case SOUP_STATUS_IO_ERROR
:
167 type
= wxWEB_NAV_ERR_CONNECTION
;
170 case SOUP_STATUS_MALFORMED
:
171 //case SOUP_STATUS_TOO_MANY_REDIRECTS:
172 type
= wxWEB_NAV_ERR_REQUEST
;
175 //case SOUP_STATUS_NO_CONTENT:
176 //case SOUP_STATUS_RESET_CONTENT:
178 case SOUP_STATUS_BAD_REQUEST
:
179 type
= wxWEB_NAV_ERR_REQUEST
;
182 case SOUP_STATUS_UNAUTHORIZED
:
183 case SOUP_STATUS_FORBIDDEN
:
184 type
= wxWEB_NAV_ERR_AUTH
;
187 case SOUP_STATUS_METHOD_NOT_ALLOWED
:
188 case SOUP_STATUS_NOT_ACCEPTABLE
:
189 type
= wxWEB_NAV_ERR_SECURITY
;
192 case SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED
:
193 type
= wxWEB_NAV_ERR_AUTH
;
196 case SOUP_STATUS_REQUEST_TIMEOUT
:
197 type
= wxWEB_NAV_ERR_CONNECTION
;
200 //case SOUP_STATUS_PAYMENT_REQUIRED:
201 case SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE
:
202 case SOUP_STATUS_REQUEST_URI_TOO_LONG
:
203 case SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE
:
204 type
= wxWEB_NAV_ERR_REQUEST
;
207 case SOUP_STATUS_BAD_GATEWAY
:
208 case SOUP_STATUS_SERVICE_UNAVAILABLE
:
209 case SOUP_STATUS_GATEWAY_TIMEOUT
:
210 type
= wxWEB_NAV_ERR_CONNECTION
;
213 case SOUP_STATUS_HTTP_VERSION_NOT_SUPPORTED
:
214 type
= wxWEB_NAV_ERR_REQUEST
;
216 //case SOUP_STATUS_INSUFFICIENT_STORAGE:
217 //case SOUP_STATUS_NOT_EXTENDED:
220 else if (strcmp(g_quark_to_string(error
->domain
),
221 "webkit-network-error-quark") == 0)
225 //WEBKIT_NETWORK_ERROR_FAILED:
226 //WEBKIT_NETWORK_ERROR_TRANSPORT:
228 case WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL
:
229 type
= wxWEB_NAV_ERR_REQUEST
;
232 case WEBKIT_NETWORK_ERROR_CANCELLED
:
233 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
236 case WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST
:
237 type
= wxWEB_NAV_ERR_NOT_FOUND
;
241 else if (strcmp(g_quark_to_string(error
->domain
),
242 "webkit-policy-error-quark") == 0)
246 //case WEBKIT_POLICY_ERROR_FAILED:
247 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_MIME_TYPE:
248 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_URL:
249 //case WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE:
250 case WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT
:
251 type
= wxWEB_NAV_ERR_SECURITY
;
256 webkit_plugin_error_quark
259 printf("Error domain %s\n", g_quark_to_string(error->domain));
263 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_ERROR
,
264 webKitWindow
->GetId(),
266 event
.SetString(description
);
269 if (webKitWindow
&& webKitWindow
->GetEventHandler())
271 webKitWindow
->GetEventHandler()->ProcessEvent(event
);
278 wxgtk_webview_webkit_new_window(WebKitWebView
*,
279 WebKitWebFrame
*frame
,
280 WebKitNetworkRequest
*request
,
281 WebKitWebNavigationAction
*,
282 WebKitWebPolicyDecision
*policy_decision
,
283 wxWebViewWebKit
*webKitCtrl
)
285 const gchar
* uri
= webkit_network_request_get_uri(request
);
287 wxString target
= webkit_web_frame_get_name (frame
);
288 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
290 wxString( uri
, wxConvUTF8
),
294 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
295 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
297 //We always want the user to handle this themselves
298 webkit_web_policy_decision_ignore(policy_decision
);
303 wxgtk_webview_webkit_title_changed(WebKitWebView
*,
306 wxWebViewWebKit
*webKitCtrl
)
308 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
310 webKitCtrl
->GetCurrentURL(),
312 event
.SetString(wxString(title
, wxConvUTF8
));
314 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
315 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
320 wxgtk_webview_webkit_resource_req(WebKitWebView
*,
323 WebKitNetworkRequest
*request
,
324 WebKitNetworkResponse
*,
325 wxWebViewWebKit
*webKitCtrl
)
327 wxString uri
= webkit_network_request_get_uri(request
);
329 wxSharedPtr
<wxWebViewHandler
> handler
;
330 wxVector
<wxSharedPtr
<wxWebViewHandler
> > hanlders
= webKitCtrl
->GetHandlers();
332 //We are not vetoed so see if we match one of the additional handlers
333 for(wxVector
<wxSharedPtr
<wxWebViewHandler
> >::iterator it
= hanlders
.begin();
334 it
!= hanlders
.end(); ++it
)
336 if(uri
.substr(0, (*it
)->GetName().length()) == (*it
)->GetName())
341 //If we found a handler we can then use it to load the file directly
345 //If it is requsting the page itself then return as we have already
346 //loaded it from the archive
347 if(webKitCtrl
->m_vfsurl
== uri
)
350 wxFSFile
* file
= handler
->GetFile(uri
);
353 //We load the data into a data url to save it being written out again
354 size_t size
= file
->GetStream()->GetLength();
355 char *buffer
= new char[size
];
356 file
->GetStream()->Read(buffer
, size
);
357 wxString data
= wxBase64Encode(buffer
, size
);
359 wxString mime
= file
->GetMimeType();
360 wxString path
= "data:" + mime
+ ";base64," + data
;
361 //Then we can redirect the call
362 webkit_network_request_set_uri(request
, path
);
370 //-----------------------------------------------------------------------------
372 //-----------------------------------------------------------------------------
374 wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewWebKit
, wxWebView
);
376 bool wxWebViewWebKit::Create(wxWindow
*parent
,
382 const wxString
& name
)
388 if (!PreCreation( parent
, pos
, size
) ||
389 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
391 wxFAIL_MSG( wxT("wxWebViewWebKit creation failed") );
395 GtkWidget
*scrolled_window
= gtk_scrolled_window_new (NULL
, NULL
);
396 web_view
= webkit_web_view_new ();
397 g_object_ref(web_view
); // TODO: check memory management
399 m_widget
= scrolled_window
;
400 g_object_ref(m_widget
); // TODO: check memory management
402 /* Place the WebKitWebView in the GtkScrolledWindow */
403 gtk_container_add (GTK_CONTAINER (scrolled_window
), web_view
);
404 gtk_widget_show(m_widget
);
405 gtk_widget_show(web_view
);
407 g_signal_connect_after(web_view
, "notify::load-status",
408 G_CALLBACK(wxgtk_webview_webkit_load_status
),
410 g_signal_connect_after(web_view
, "navigation-policy-decision-requested",
411 G_CALLBACK(wxgtk_webview_webkit_navigation
),
413 g_signal_connect_after(web_view
, "load-error",
414 G_CALLBACK(wxgtk_webview_webkit_error
),
417 g_signal_connect_after(web_view
, "new-window-policy-decision-requested",
418 G_CALLBACK(wxgtk_webview_webkit_new_window
), this);
420 g_signal_connect_after(web_view
, "title-changed",
421 G_CALLBACK(wxgtk_webview_webkit_title_changed
), this);
423 g_signal_connect_after(web_view
, "resource-request-starting",
424 G_CALLBACK(wxgtk_webview_webkit_resource_req
), this);
426 m_parent
->DoAddChild( this );
431 webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view
), url
);
433 //Get the initial history limit so we can enable and disable it later
434 WebKitWebBackForwardList
* history
;
435 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
436 m_historyLimit
= webkit_web_back_forward_list_get_limit(history
);
443 bool wxWebViewWebKit::Enable( bool enable
)
445 if (!wxControl::Enable(enable
))
448 gtk_widget_set_sensitive(GTK_BIN(m_widget
)->child
, enable
);
451 // GTKFixSensitivity();
457 wxWebViewWebKit::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
459 GdkWindow
* window
= gtk_widget_get_parent_window(m_widget
);
463 void wxWebViewWebKit::ZoomIn()
465 webkit_web_view_zoom_in (WEBKIT_WEB_VIEW(web_view
));
468 void wxWebViewWebKit::ZoomOut()
470 webkit_web_view_zoom_out (WEBKIT_WEB_VIEW(web_view
));
473 void wxWebViewWebKit::SetWebkitZoom(float level
)
475 webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW(web_view
), level
);
478 float wxWebViewWebKit::GetWebkitZoom()
480 return webkit_web_view_get_zoom_level (WEBKIT_WEB_VIEW(web_view
));
483 void wxWebViewWebKit::Stop()
485 webkit_web_view_stop_loading (WEBKIT_WEB_VIEW(web_view
));
488 void wxWebViewWebKit::Reload(wxWebViewReloadFlags flags
)
490 if (flags
& wxWEB_VIEW_RELOAD_NO_CACHE
)
492 webkit_web_view_reload_bypass_cache (WEBKIT_WEB_VIEW(web_view
));
496 webkit_web_view_reload (WEBKIT_WEB_VIEW(web_view
));
500 void wxWebViewWebKit::LoadUrl(const wxString
& url
)
502 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view
), wxGTK_CONV(url
));
506 void wxWebViewWebKit::GoBack()
508 webkit_web_view_go_back (WEBKIT_WEB_VIEW(web_view
));
511 void wxWebViewWebKit::GoForward()
513 webkit_web_view_go_forward (WEBKIT_WEB_VIEW(web_view
));
517 bool wxWebViewWebKit::CanGoBack()
519 return webkit_web_view_can_go_back (WEBKIT_WEB_VIEW(web_view
));
523 bool wxWebViewWebKit::CanGoForward()
525 return webkit_web_view_can_go_forward (WEBKIT_WEB_VIEW(web_view
));
528 void wxWebViewWebKit::ClearHistory()
530 WebKitWebBackForwardList
* history
;
531 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
532 webkit_web_back_forward_list_clear(history
);
535 void wxWebViewWebKit::EnableHistory(bool enable
)
537 WebKitWebBackForwardList
* history
;
538 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
541 webkit_web_back_forward_list_set_limit(history
, m_historyLimit
);
545 webkit_web_back_forward_list_set_limit(history
, 0);
549 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewWebKit::GetBackwardHistory()
551 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > backhist
;
552 WebKitWebBackForwardList
* history
;
553 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
554 GList
* list
= webkit_web_back_forward_list_get_back_list_with_limit(history
,
556 //We need to iterate in reverse to get the order we desire
557 for(int i
= g_list_length(list
) - 1; i
>= 0 ; i
--)
559 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
560 wxWebViewHistoryItem
* wxitem
= new wxWebViewHistoryItem(
561 webkit_web_history_item_get_uri(gtkitem
),
562 webkit_web_history_item_get_title(gtkitem
));
563 wxitem
->m_histItem
= gtkitem
;
564 wxSharedPtr
<wxWebViewHistoryItem
> item(wxitem
);
565 backhist
.push_back(item
);
570 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewWebKit::GetForwardHistory()
572 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > forwardhist
;
573 WebKitWebBackForwardList
* history
;
574 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
575 GList
* list
= webkit_web_back_forward_list_get_forward_list_with_limit(history
,
577 for(guint i
= 0; i
< g_list_length(list
); i
++)
579 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
580 wxWebViewHistoryItem
* wxitem
= new wxWebViewHistoryItem(
581 webkit_web_history_item_get_uri(gtkitem
),
582 webkit_web_history_item_get_title(gtkitem
));
583 wxitem
->m_histItem
= gtkitem
;
584 wxSharedPtr
<wxWebViewHistoryItem
> item(wxitem
);
585 forwardhist
.push_back(item
);
590 void wxWebViewWebKit::LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
)
592 WebKitWebHistoryItem
* gtkitem
= item
->m_histItem
;
595 WebKitWebBackForwardList
* history
;
596 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
597 webkit_web_view_go_to_back_forward_item(WEBKIT_WEB_VIEW(web_view
),
598 WEBKIT_WEB_HISTORY_ITEM(gtkitem
));
602 bool wxWebViewWebKit::CanCut()
604 return webkit_web_view_can_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
607 bool wxWebViewWebKit::CanCopy()
609 return webkit_web_view_can_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
612 bool wxWebViewWebKit::CanPaste()
614 return webkit_web_view_can_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
617 void wxWebViewWebKit::Cut()
619 webkit_web_view_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
622 void wxWebViewWebKit::Copy()
624 webkit_web_view_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
627 void wxWebViewWebKit::Paste()
629 webkit_web_view_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
632 bool wxWebViewWebKit::CanUndo()
634 return webkit_web_view_can_undo(WEBKIT_WEB_VIEW(web_view
));
637 bool wxWebViewWebKit::CanRedo()
639 return webkit_web_view_can_redo(WEBKIT_WEB_VIEW(web_view
));
642 void wxWebViewWebKit::Undo()
644 webkit_web_view_undo(WEBKIT_WEB_VIEW(web_view
));
647 void wxWebViewWebKit::Redo()
649 webkit_web_view_redo(WEBKIT_WEB_VIEW(web_view
));
652 wxString
wxWebViewWebKit::GetCurrentURL()
654 // FIXME: check which encoding the web kit control uses instead of
655 // assuming UTF8 (here and elsewhere too)
656 return wxString::FromUTF8(webkit_web_view_get_uri(
657 WEBKIT_WEB_VIEW(web_view
)));
661 wxString
wxWebViewWebKit::GetCurrentTitle()
663 return wxString::FromUTF8(webkit_web_view_get_title(
664 WEBKIT_WEB_VIEW(web_view
)));
668 wxString
wxWebViewWebKit::GetPageSource()
670 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
671 WEBKIT_WEB_VIEW(web_view
));
672 WebKitWebDataSource
* src
= webkit_web_frame_get_data_source (frame
);
674 // TODO: check encoding with
676 // webkit_web_data_source_get_encoding(WebKitWebDataSource *data_source);
677 return wxString(webkit_web_data_source_get_data (src
)->str
, wxConvUTF8
);
681 wxWebViewZoom
wxWebViewWebKit::GetZoom()
683 float zoom
= GetWebkitZoom();
685 // arbitrary way to map float zoom to our common zoom enum
688 return wxWEB_VIEW_ZOOM_TINY
;
690 else if (zoom
> 0.65 && zoom
<= 0.90)
692 return wxWEB_VIEW_ZOOM_SMALL
;
694 else if (zoom
> 0.90 && zoom
<= 1.15)
696 return wxWEB_VIEW_ZOOM_MEDIUM
;
698 else if (zoom
> 1.15 && zoom
<= 1.45)
700 return wxWEB_VIEW_ZOOM_LARGE
;
702 else if (zoom
> 1.45)
704 return wxWEB_VIEW_ZOOM_LARGEST
;
707 // to shut up compilers, this can never be reached logically
709 return wxWEB_VIEW_ZOOM_MEDIUM
;
713 void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom
)
715 // arbitrary way to map our common zoom enum to float zoom
718 case wxWEB_VIEW_ZOOM_TINY
:
722 case wxWEB_VIEW_ZOOM_SMALL
:
726 case wxWEB_VIEW_ZOOM_MEDIUM
:
730 case wxWEB_VIEW_ZOOM_LARGE
:
734 case wxWEB_VIEW_ZOOM_LARGEST
:
743 void wxWebViewWebKit::SetZoomType(wxWebViewZoomType type
)
745 webkit_web_view_set_full_content_zoom(WEBKIT_WEB_VIEW(web_view
),
746 (type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
?
750 wxWebViewZoomType
wxWebViewWebKit::GetZoomType() const
752 gboolean fczoom
= webkit_web_view_get_full_content_zoom(
753 WEBKIT_WEB_VIEW(web_view
));
755 if (fczoom
) return wxWEB_VIEW_ZOOM_TYPE_LAYOUT
;
756 else return wxWEB_VIEW_ZOOM_TYPE_TEXT
;
759 bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType
) const
761 // this port supports all zoom types
765 void wxWebViewWebKit::SetPage(const wxString
& html
, const wxString
& baseUri
)
767 webkit_web_view_load_string (WEBKIT_WEB_VIEW(web_view
),
768 html
.mb_str(wxConvUTF8
),
771 baseUri
.mb_str(wxConvUTF8
));
774 void wxWebViewWebKit::Print()
776 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
777 WEBKIT_WEB_VIEW(web_view
));
778 webkit_web_frame_print (frame
);
780 // GtkPrintOperationResult webkit_web_frame_print_full
781 // (WebKitWebFrame *frame,
782 // GtkPrintOperation *operation,
783 // GtkPrintOperationAction action,
789 bool wxWebViewWebKit::IsBusy()
793 // This code looks nice but returns true after a page was cancelled
795 WebKitLoadStatus status = webkit_web_view_get_load_status
796 (WEBKIT_WEB_VIEW(web_view));
799 #if WEBKIT_CHECK_VERSION(1,1,16)
800 // WEBKIT_LOAD_FAILED is new in webkit 1.1.16
801 if (status == WEBKIT_LOAD_FAILED)
806 if (status == WEBKIT_LOAD_FINISHED)
815 void wxWebViewWebKit::SetEditable(bool enable
)
817 webkit_web_view_set_editable(WEBKIT_WEB_VIEW(web_view
), enable
);
820 bool wxWebViewWebKit::IsEditable()
822 return webkit_web_view_get_editable(WEBKIT_WEB_VIEW(web_view
));
825 void wxWebViewWebKit::DeleteSelection()
827 webkit_web_view_delete_selection(WEBKIT_WEB_VIEW(web_view
));
830 bool wxWebViewWebKit::HasSelection()
832 return webkit_web_view_has_selection(WEBKIT_WEB_VIEW(web_view
));
835 void wxWebViewWebKit::SelectAll()
837 webkit_web_view_select_all(WEBKIT_WEB_VIEW(web_view
));
840 wxString
wxWebViewWebKit::GetSelectedText()
842 WebKitDOMDocument
* doc
;
843 WebKitDOMDOMWindow
* win
;
844 WebKitDOMDOMSelection
* sel
;
845 WebKitDOMRange
* range
;
847 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
848 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
849 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
850 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
852 return wxString(webkit_dom_range_get_text(WEBKIT_DOM_RANGE(range
)),
856 wxString
wxWebViewWebKit::GetSelectedSource()
858 WebKitDOMDocument
* doc
;
859 WebKitDOMDOMWindow
* win
;
860 WebKitDOMDOMSelection
* sel
;
861 WebKitDOMRange
* range
;
862 WebKitDOMElement
* div
;
863 WebKitDOMDocumentFragment
* clone
;
864 WebKitDOMHTMLElement
* html
;
866 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
867 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
868 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
869 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
871 div
= webkit_dom_document_create_element(WEBKIT_DOM_DOCUMENT(doc
), "div", NULL
);
873 clone
= webkit_dom_range_clone_contents(WEBKIT_DOM_RANGE(range
), NULL
);
874 webkit_dom_node_append_child(&div
->parent_instance
, &clone
->parent_instance
, NULL
);
875 html
= (WebKitDOMHTMLElement
*)div
;
877 return wxString(webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(html
)),
881 void wxWebViewWebKit::ClearSelection()
883 WebKitDOMDocument
* doc
;
884 WebKitDOMDOMWindow
* win
;
885 WebKitDOMDOMSelection
* sel
;
887 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
888 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
889 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
890 webkit_dom_dom_selection_remove_all_ranges(WEBKIT_DOM_DOM_SELECTION(sel
));
894 wxString
wxWebViewWebKit::GetPageText()
896 WebKitDOMDocument
* doc
;
897 WebKitDOMHTMLElement
* body
;
899 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
900 body
= webkit_dom_document_get_body(WEBKIT_DOM_DOCUMENT(doc
));
901 return wxString(webkit_dom_html_element_get_inner_text(WEBKIT_DOM_HTML_ELEMENT(body
)),
905 void wxWebViewWebKit::RunScript(const wxString
& javascript
)
907 webkit_web_view_execute_script(WEBKIT_WEB_VIEW(web_view
),
908 javascript
.mb_str(wxConvUTF8
));
911 void wxWebViewWebKit::RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
)
913 m_handlerList
.push_back(handler
);
918 wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
920 return GetDefaultAttributesFromGTKWidget(webkit_web_view_new
);
924 #endif // wxHAVE_WEB_BACKEND_GTK_WEBKIT