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 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_LOADED
,
51 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
52 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
54 else if (status
== WEBKIT_LOAD_COMMITTED
)
56 webKitCtrl
->m_busy
= true;
57 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
61 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
62 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
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 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
91 wxString( uri
, wxConvUTF8
),
95 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
96 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
98 if (thisEvent
.IsVetoed())
100 webKitCtrl
->m_busy
= false;
101 webkit_web_policy_decision_ignore(policy_decision
);
106 wxString wxuri
= uri
;
107 wxSharedPtr
<wxWebHandler
> handler
;
108 wxVector
<wxSharedPtr
<wxWebHandler
> > hanlders
= webKitCtrl
->GetHandlers();
109 //We are not vetoed so see if we match one of the additional handlers
110 for(wxVector
<wxSharedPtr
<wxWebHandler
> >::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 wxWebNavigationError 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 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_ERROR
,
264 webKitWindow
->GetId(),
268 thisEvent
.SetString(description
);
269 thisEvent
.SetInt(type
);
271 if (webKitWindow
&& webKitWindow
->GetEventHandler())
273 webKitWindow
->GetEventHandler()->ProcessEvent(thisEvent
);
280 wxgtk_webview_webkit_new_window(WebKitWebView
*,
281 WebKitWebFrame
*frame
,
282 WebKitNetworkRequest
*request
,
283 WebKitWebNavigationAction
*,
284 WebKitWebPolicyDecision
*policy_decision
,
285 wxWebViewWebKit
*webKitCtrl
)
287 const gchar
* uri
= webkit_network_request_get_uri(request
);
289 wxString target
= webkit_web_frame_get_name (frame
);
290 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
292 wxString( uri
, wxConvUTF8
),
296 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
297 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
299 //We always want the user to handle this themselves
300 webkit_web_policy_decision_ignore(policy_decision
);
305 wxgtk_webview_webkit_title_changed(WebKitWebView
*,
308 wxWebViewWebKit
*webKitCtrl
)
310 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
312 webKitCtrl
->GetCurrentURL(),
315 thisEvent
.SetString(wxString(title
, wxConvUTF8
));
317 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
318 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
323 wxgtk_webview_webkit_resource_req(WebKitWebView
*,
326 WebKitNetworkRequest
*request
,
327 WebKitNetworkResponse
*,
328 wxWebViewWebKit
*webKitCtrl
)
330 wxString uri
= webkit_network_request_get_uri(request
);
332 wxSharedPtr
<wxWebHandler
> handler
;
333 wxVector
<wxSharedPtr
<wxWebHandler
> > hanlders
= webKitCtrl
->GetHandlers();
335 //We are not vetoed so see if we match one of the additional handlers
336 for(wxVector
<wxSharedPtr
<wxWebHandler
> >::iterator it
= hanlders
.begin();
337 it
!= hanlders
.end(); ++it
)
339 if(uri
.substr(0, (*it
)->GetName().length()) == (*it
)->GetName())
344 //If we found a handler we can then use it to load the file directly
348 //If it is requsting the page itself then return as we have already
349 //loaded it from the archive
350 if(webKitCtrl
->m_vfsurl
== uri
)
353 wxFSFile
* file
= handler
->GetFile(uri
);
356 //We load the data into a data url to save it being written out again
357 size_t size
= file
->GetStream()->GetLength();
358 char *buffer
= new char[size
];
359 file
->GetStream()->Read(buffer
, size
);
360 wxString data
= wxBase64Encode(buffer
, size
);
362 wxString mime
= file
->GetMimeType();
363 wxString path
= "data:" + mime
+ ";base64," + data
;
364 //Then we can redirect the call
365 webkit_network_request_set_uri(request
, path
);
373 //-----------------------------------------------------------------------------
375 //-----------------------------------------------------------------------------
377 wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewWebKit
, wxWebView
);
379 bool wxWebViewWebKit::Create(wxWindow
*parent
,
385 const wxString
& name
)
391 if (!PreCreation( parent
, pos
, size
) ||
392 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
394 wxFAIL_MSG( wxT("wxWebViewWebKit creation failed") );
398 GtkWidget
*scrolled_window
= gtk_scrolled_window_new (NULL
, NULL
);
399 web_view
= webkit_web_view_new ();
400 g_object_ref(web_view
); // TODO: check memory management
402 m_widget
= scrolled_window
;
403 g_object_ref(m_widget
); // TODO: check memory management
405 /* Place the WebKitWebView in the GtkScrolledWindow */
406 gtk_container_add (GTK_CONTAINER (scrolled_window
), web_view
);
407 gtk_widget_show(m_widget
);
408 gtk_widget_show(web_view
);
410 g_signal_connect_after(web_view
, "notify::load-status",
411 G_CALLBACK(wxgtk_webview_webkit_load_status
),
413 g_signal_connect_after(web_view
, "navigation-policy-decision-requested",
414 G_CALLBACK(wxgtk_webview_webkit_navigation
),
416 g_signal_connect_after(web_view
, "load-error",
417 G_CALLBACK(wxgtk_webview_webkit_error
),
420 g_signal_connect_after(web_view
, "new-window-policy-decision-requested",
421 G_CALLBACK(wxgtk_webview_webkit_new_window
), this);
423 g_signal_connect_after(web_view
, "title-changed",
424 G_CALLBACK(wxgtk_webview_webkit_title_changed
), this);
426 g_signal_connect_after(web_view
, "resource-request-starting",
427 G_CALLBACK(wxgtk_webview_webkit_resource_req
), this);
429 m_parent
->DoAddChild( this );
434 webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view
), url
);
436 //Get the initial history limit so we can enable and disable it later
437 WebKitWebBackForwardList
* history
;
438 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
439 m_historyLimit
= webkit_web_back_forward_list_get_limit(history
);
446 bool wxWebViewWebKit::Enable( bool enable
)
448 if (!wxControl::Enable(enable
))
451 gtk_widget_set_sensitive(GTK_BIN(m_widget
)->child
, enable
);
454 // GTKFixSensitivity();
460 wxWebViewWebKit::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
462 GdkWindow
* window
= gtk_widget_get_parent_window(m_widget
);
466 void wxWebViewWebKit::ZoomIn()
468 webkit_web_view_zoom_in (WEBKIT_WEB_VIEW(web_view
));
471 void wxWebViewWebKit::ZoomOut()
473 webkit_web_view_zoom_out (WEBKIT_WEB_VIEW(web_view
));
476 void wxWebViewWebKit::SetWebkitZoom(float level
)
478 webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW(web_view
), level
);
481 float wxWebViewWebKit::GetWebkitZoom()
483 return webkit_web_view_get_zoom_level (WEBKIT_WEB_VIEW(web_view
));
486 void wxWebViewWebKit::Stop()
488 webkit_web_view_stop_loading (WEBKIT_WEB_VIEW(web_view
));
491 void wxWebViewWebKit::Reload(wxWebViewReloadFlags flags
)
493 if (flags
& wxWEB_VIEW_RELOAD_NO_CACHE
)
495 webkit_web_view_reload_bypass_cache (WEBKIT_WEB_VIEW(web_view
));
499 webkit_web_view_reload (WEBKIT_WEB_VIEW(web_view
));
503 void wxWebViewWebKit::LoadUrl(const wxString
& url
)
505 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view
), wxGTK_CONV(url
));
509 void wxWebViewWebKit::GoBack()
511 webkit_web_view_go_back (WEBKIT_WEB_VIEW(web_view
));
514 void wxWebViewWebKit::GoForward()
516 webkit_web_view_go_forward (WEBKIT_WEB_VIEW(web_view
));
520 bool wxWebViewWebKit::CanGoBack()
522 return webkit_web_view_can_go_back (WEBKIT_WEB_VIEW(web_view
));
526 bool wxWebViewWebKit::CanGoForward()
528 return webkit_web_view_can_go_forward (WEBKIT_WEB_VIEW(web_view
));
531 void wxWebViewWebKit::ClearHistory()
533 WebKitWebBackForwardList
* history
;
534 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
535 webkit_web_back_forward_list_clear(history
);
538 void wxWebViewWebKit::EnableHistory(bool enable
)
540 WebKitWebBackForwardList
* history
;
541 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
544 webkit_web_back_forward_list_set_limit(history
, m_historyLimit
);
548 webkit_web_back_forward_list_set_limit(history
, 0);
552 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewWebKit::GetBackwardHistory()
554 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > backhist
;
555 WebKitWebBackForwardList
* history
;
556 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
557 GList
* list
= webkit_web_back_forward_list_get_back_list_with_limit(history
,
559 //We need to iterate in reverse to get the order we desire
560 for(int i
= g_list_length(list
) - 1; i
>= 0 ; i
--)
562 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
563 wxWebHistoryItem
* wxitem
= new wxWebHistoryItem(
564 webkit_web_history_item_get_uri(gtkitem
),
565 webkit_web_history_item_get_title(gtkitem
));
566 wxitem
->m_histItem
= gtkitem
;
567 wxSharedPtr
<wxWebHistoryItem
> item(wxitem
);
568 backhist
.push_back(item
);
573 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewWebKit::GetForwardHistory()
575 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > forwardhist
;
576 WebKitWebBackForwardList
* history
;
577 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
578 GList
* list
= webkit_web_back_forward_list_get_forward_list_with_limit(history
,
580 for(guint i
= 0; i
< g_list_length(list
); i
++)
582 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
583 wxWebHistoryItem
* wxitem
= new wxWebHistoryItem(
584 webkit_web_history_item_get_uri(gtkitem
),
585 webkit_web_history_item_get_title(gtkitem
));
586 wxitem
->m_histItem
= gtkitem
;
587 wxSharedPtr
<wxWebHistoryItem
> item(wxitem
);
588 forwardhist
.push_back(item
);
593 void wxWebViewWebKit::LoadHistoryItem(wxSharedPtr
<wxWebHistoryItem
> item
)
595 WebKitWebHistoryItem
* gtkitem
= item
->m_histItem
;
598 WebKitWebBackForwardList
* history
;
599 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
600 webkit_web_back_forward_list_go_to_item(WEBKIT_WEB_BACK_FORWARD_LIST(history
),
601 WEBKIT_WEB_HISTORY_ITEM(gtkitem
));
605 bool wxWebViewWebKit::CanCut()
607 return webkit_web_view_can_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
610 bool wxWebViewWebKit::CanCopy()
612 return webkit_web_view_can_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
615 bool wxWebViewWebKit::CanPaste()
617 return webkit_web_view_can_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
620 void wxWebViewWebKit::Cut()
622 webkit_web_view_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
625 void wxWebViewWebKit::Copy()
627 webkit_web_view_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
630 void wxWebViewWebKit::Paste()
632 webkit_web_view_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
635 bool wxWebViewWebKit::CanUndo()
637 return webkit_web_view_can_undo(WEBKIT_WEB_VIEW(web_view
));
640 bool wxWebViewWebKit::CanRedo()
642 return webkit_web_view_can_redo(WEBKIT_WEB_VIEW(web_view
));
645 void wxWebViewWebKit::Undo()
647 webkit_web_view_undo(WEBKIT_WEB_VIEW(web_view
));
650 void wxWebViewWebKit::Redo()
652 webkit_web_view_redo(WEBKIT_WEB_VIEW(web_view
));
655 wxString
wxWebViewWebKit::GetCurrentURL()
657 // FIXME: check which encoding the web kit control uses instead of
658 // assuming UTF8 (here and elsewhere too)
659 return wxString::FromUTF8(webkit_web_view_get_uri(
660 WEBKIT_WEB_VIEW(web_view
)));
664 wxString
wxWebViewWebKit::GetCurrentTitle()
666 return wxString::FromUTF8(webkit_web_view_get_title(
667 WEBKIT_WEB_VIEW(web_view
)));
671 wxString
wxWebViewWebKit::GetPageSource()
673 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
674 WEBKIT_WEB_VIEW(web_view
));
675 WebKitWebDataSource
* src
= webkit_web_frame_get_data_source (frame
);
677 // TODO: check encoding with
679 // webkit_web_data_source_get_encoding(WebKitWebDataSource *data_source);
680 return wxString(webkit_web_data_source_get_data (src
)->str
, wxConvUTF8
);
684 wxWebViewZoom
wxWebViewWebKit::GetZoom()
686 float zoom
= GetWebkitZoom();
688 // arbitrary way to map float zoom to our common zoom enum
691 return wxWEB_VIEW_ZOOM_TINY
;
693 else if (zoom
> 0.65 && zoom
<= 0.90)
695 return wxWEB_VIEW_ZOOM_SMALL
;
697 else if (zoom
> 0.90 && zoom
<= 1.15)
699 return wxWEB_VIEW_ZOOM_MEDIUM
;
701 else if (zoom
> 1.15 && zoom
<= 1.45)
703 return wxWEB_VIEW_ZOOM_LARGE
;
705 else if (zoom
> 1.45)
707 return wxWEB_VIEW_ZOOM_LARGEST
;
710 // to shut up compilers, this can never be reached logically
712 return wxWEB_VIEW_ZOOM_MEDIUM
;
716 void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom
)
718 // arbitrary way to map our common zoom enum to float zoom
721 case wxWEB_VIEW_ZOOM_TINY
:
725 case wxWEB_VIEW_ZOOM_SMALL
:
729 case wxWEB_VIEW_ZOOM_MEDIUM
:
733 case wxWEB_VIEW_ZOOM_LARGE
:
737 case wxWEB_VIEW_ZOOM_LARGEST
:
746 void wxWebViewWebKit::SetZoomType(wxWebViewZoomType type
)
748 webkit_web_view_set_full_content_zoom(WEBKIT_WEB_VIEW(web_view
),
749 (type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
?
753 wxWebViewZoomType
wxWebViewWebKit::GetZoomType() const
755 gboolean fczoom
= webkit_web_view_get_full_content_zoom(
756 WEBKIT_WEB_VIEW(web_view
));
758 if (fczoom
) return wxWEB_VIEW_ZOOM_TYPE_LAYOUT
;
759 else return wxWEB_VIEW_ZOOM_TYPE_TEXT
;
762 bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType
) const
764 // this port supports all zoom types
768 void wxWebViewWebKit::SetPage(const wxString
& html
, const wxString
& baseUri
)
770 webkit_web_view_load_string (WEBKIT_WEB_VIEW(web_view
),
771 html
.mb_str(wxConvUTF8
),
774 baseUri
.mb_str(wxConvUTF8
));
777 void wxWebViewWebKit::Print()
779 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
780 WEBKIT_WEB_VIEW(web_view
));
781 webkit_web_frame_print (frame
);
783 // GtkPrintOperationResult webkit_web_frame_print_full
784 // (WebKitWebFrame *frame,
785 // GtkPrintOperation *operation,
786 // GtkPrintOperationAction action,
792 bool wxWebViewWebKit::IsBusy()
796 // This code looks nice but returns true after a page was cancelled
798 WebKitLoadStatus status = webkit_web_view_get_load_status
799 (WEBKIT_WEB_VIEW(web_view));
802 #if WEBKIT_CHECK_VERSION(1,1,16)
803 // WEBKIT_LOAD_FAILED is new in webkit 1.1.16
804 if (status == WEBKIT_LOAD_FAILED)
809 if (status == WEBKIT_LOAD_FINISHED)
818 void wxWebViewWebKit::SetEditable(bool enable
)
820 webkit_web_view_set_editable(WEBKIT_WEB_VIEW(web_view
), enable
);
823 bool wxWebViewWebKit::IsEditable()
825 return webkit_web_view_get_editable(WEBKIT_WEB_VIEW(web_view
));
828 void wxWebViewWebKit::DeleteSelection()
830 webkit_web_view_delete_selection(WEBKIT_WEB_VIEW(web_view
));
833 bool wxWebViewWebKit::HasSelection()
835 return webkit_web_view_has_selection(WEBKIT_WEB_VIEW(web_view
));
838 void wxWebViewWebKit::SelectAll()
840 webkit_web_view_select_all(WEBKIT_WEB_VIEW(web_view
));
843 wxString
wxWebViewWebKit::GetSelectedText()
845 WebKitDOMDocument
* doc
;
846 WebKitDOMDOMWindow
* win
;
847 WebKitDOMDOMSelection
* sel
;
848 WebKitDOMRange
* range
;
850 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
851 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
852 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
853 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
855 return wxString(webkit_dom_range_get_text(WEBKIT_DOM_RANGE(range
)),
859 wxString
wxWebViewWebKit::GetSelectedSource()
861 WebKitDOMDocument
* doc
;
862 WebKitDOMDOMWindow
* win
;
863 WebKitDOMDOMSelection
* sel
;
864 WebKitDOMRange
* range
;
865 WebKitDOMElement
* div
;
866 WebKitDOMDocumentFragment
* clone
;
867 WebKitDOMHTMLElement
* html
;
869 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
870 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
871 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
872 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
874 div
= webkit_dom_document_create_element(WEBKIT_DOM_DOCUMENT(doc
), "div", NULL
);
876 clone
= webkit_dom_range_clone_contents(WEBKIT_DOM_RANGE(range
), NULL
);
877 webkit_dom_node_append_child(&div
->parent_instance
, &clone
->parent_instance
, NULL
);
878 html
= (WebKitDOMHTMLElement
*)div
;
880 return wxString(webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(html
)),
884 void wxWebViewWebKit::ClearSelection()
886 WebKitDOMDocument
* doc
;
887 WebKitDOMDOMWindow
* win
;
888 WebKitDOMDOMSelection
* sel
;
890 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
891 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
892 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
893 webkit_dom_dom_selection_remove_all_ranges(WEBKIT_DOM_DOM_SELECTION(sel
));
897 wxString
wxWebViewWebKit::GetPageText()
899 WebKitDOMDocument
* doc
;
900 WebKitDOMHTMLElement
* body
;
902 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
903 body
= webkit_dom_document_get_body(WEBKIT_DOM_DOCUMENT(doc
));
904 return wxString(webkit_dom_html_element_get_inner_text(WEBKIT_DOM_HTML_ELEMENT(body
)),
908 void wxWebViewWebKit::RunScript(const wxString
& javascript
)
910 webkit_web_view_execute_script(WEBKIT_WEB_VIEW(web_view
),
911 javascript
.mb_str(wxConvUTF8
));
914 void wxWebViewWebKit::RegisterHandler(wxSharedPtr
<wxWebHandler
> handler
)
916 m_handlerList
.push_back(handler
);
921 wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
923 return GetDefaultAttributesFromGTKWidget(webkit_web_view_new
);
927 #endif // wxHAVE_WEB_BACKEND_GTK_WEBKIT