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
),
94 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
95 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
97 if (!event
.IsAllowed())
99 webKitCtrl
->m_busy
= false;
100 webkit_web_policy_decision_ignore(policy_decision
);
105 wxString wxuri
= uri
;
106 wxSharedPtr
<wxWebViewHandler
> handler
;
107 wxVector
<wxSharedPtr
<wxWebViewHandler
> > hanlders
= webKitCtrl
->GetHandlers();
108 //We are not vetoed so see if we match one of the additional handlers
109 for(wxVector
<wxSharedPtr
<wxWebViewHandler
> >::iterator it
= hanlders
.begin();
110 it
!= hanlders
.end(); ++it
)
112 if(wxuri
.substr(0, (*it
)->GetName().length()) == (*it
)->GetName())
117 //If we found a handler we can then use it to load the file directly
121 webKitCtrl
->m_guard
= true;
122 wxFSFile
* file
= handler
->GetFile(wxuri
);
125 webKitCtrl
->SetPage(*file
->GetStream(), wxuri
);
127 //We need to throw some sort of error here if file is NULL
128 webkit_web_policy_decision_ignore(policy_decision
);
136 wxgtk_webview_webkit_error(WebKitWebView
*,
140 wxWebViewWebKit
* webKitWindow
)
142 webKitWindow
->m_busy
= false;
143 wxWebViewNavigationError type
= wxWEB_NAV_ERR_OTHER
;
145 GError
* error
= (GError
*)web_error
;
146 wxString
description(error
->message
, wxConvUTF8
);
148 if (strcmp(g_quark_to_string(error
->domain
), "soup_http_error_quark") == 0)
152 case SOUP_STATUS_CANCELLED
:
153 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
156 case SOUP_STATUS_CANT_RESOLVE
:
157 case SOUP_STATUS_NOT_FOUND
:
158 type
= wxWEB_NAV_ERR_NOT_FOUND
;
161 case SOUP_STATUS_CANT_RESOLVE_PROXY
:
162 case SOUP_STATUS_CANT_CONNECT
:
163 case SOUP_STATUS_CANT_CONNECT_PROXY
:
164 case SOUP_STATUS_SSL_FAILED
:
165 case SOUP_STATUS_IO_ERROR
:
166 type
= wxWEB_NAV_ERR_CONNECTION
;
169 case SOUP_STATUS_MALFORMED
:
170 //case SOUP_STATUS_TOO_MANY_REDIRECTS:
171 type
= wxWEB_NAV_ERR_REQUEST
;
174 //case SOUP_STATUS_NO_CONTENT:
175 //case SOUP_STATUS_RESET_CONTENT:
177 case SOUP_STATUS_BAD_REQUEST
:
178 type
= wxWEB_NAV_ERR_REQUEST
;
181 case SOUP_STATUS_UNAUTHORIZED
:
182 case SOUP_STATUS_FORBIDDEN
:
183 type
= wxWEB_NAV_ERR_AUTH
;
186 case SOUP_STATUS_METHOD_NOT_ALLOWED
:
187 case SOUP_STATUS_NOT_ACCEPTABLE
:
188 type
= wxWEB_NAV_ERR_SECURITY
;
191 case SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED
:
192 type
= wxWEB_NAV_ERR_AUTH
;
195 case SOUP_STATUS_REQUEST_TIMEOUT
:
196 type
= wxWEB_NAV_ERR_CONNECTION
;
199 //case SOUP_STATUS_PAYMENT_REQUIRED:
200 case SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE
:
201 case SOUP_STATUS_REQUEST_URI_TOO_LONG
:
202 case SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE
:
203 type
= wxWEB_NAV_ERR_REQUEST
;
206 case SOUP_STATUS_BAD_GATEWAY
:
207 case SOUP_STATUS_SERVICE_UNAVAILABLE
:
208 case SOUP_STATUS_GATEWAY_TIMEOUT
:
209 type
= wxWEB_NAV_ERR_CONNECTION
;
212 case SOUP_STATUS_HTTP_VERSION_NOT_SUPPORTED
:
213 type
= wxWEB_NAV_ERR_REQUEST
;
215 //case SOUP_STATUS_INSUFFICIENT_STORAGE:
216 //case SOUP_STATUS_NOT_EXTENDED:
219 else if (strcmp(g_quark_to_string(error
->domain
),
220 "webkit-network-error-quark") == 0)
224 //WEBKIT_NETWORK_ERROR_FAILED:
225 //WEBKIT_NETWORK_ERROR_TRANSPORT:
227 case WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL
:
228 type
= wxWEB_NAV_ERR_REQUEST
;
231 case WEBKIT_NETWORK_ERROR_CANCELLED
:
232 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
235 case WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST
:
236 type
= wxWEB_NAV_ERR_NOT_FOUND
;
240 else if (strcmp(g_quark_to_string(error
->domain
),
241 "webkit-policy-error-quark") == 0)
245 //case WEBKIT_POLICY_ERROR_FAILED:
246 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_MIME_TYPE:
247 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_URL:
248 //case WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE:
249 case WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT
:
250 type
= wxWEB_NAV_ERR_SECURITY
;
255 webkit_plugin_error_quark
258 printf("Error domain %s\n", g_quark_to_string(error->domain));
262 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_ERROR
,
263 webKitWindow
->GetId(),
265 event
.SetString(description
);
268 if (webKitWindow
&& webKitWindow
->GetEventHandler())
270 webKitWindow
->GetEventHandler()->ProcessEvent(event
);
277 wxgtk_webview_webkit_new_window(WebKitWebView
*,
278 WebKitWebFrame
*frame
,
279 WebKitNetworkRequest
*request
,
280 WebKitWebNavigationAction
*,
281 WebKitWebPolicyDecision
*policy_decision
,
282 wxWebViewWebKit
*webKitCtrl
)
284 const gchar
* uri
= webkit_network_request_get_uri(request
);
286 wxString target
= webkit_web_frame_get_name (frame
);
287 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
289 wxString( uri
, wxConvUTF8
),
292 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
293 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
295 //We always want the user to handle this themselves
296 webkit_web_policy_decision_ignore(policy_decision
);
301 wxgtk_webview_webkit_title_changed(WebKitWebView
*,
304 wxWebViewWebKit
*webKitCtrl
)
306 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
308 webKitCtrl
->GetCurrentURL(),
310 event
.SetString(wxString(title
, wxConvUTF8
));
312 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
313 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
318 wxgtk_webview_webkit_resource_req(WebKitWebView
*,
321 WebKitNetworkRequest
*request
,
322 WebKitNetworkResponse
*,
323 wxWebViewWebKit
*webKitCtrl
)
325 wxString uri
= webkit_network_request_get_uri(request
);
327 wxSharedPtr
<wxWebViewHandler
> handler
;
328 wxVector
<wxSharedPtr
<wxWebViewHandler
> > hanlders
= webKitCtrl
->GetHandlers();
330 //We are not vetoed so see if we match one of the additional handlers
331 for(wxVector
<wxSharedPtr
<wxWebViewHandler
> >::iterator it
= hanlders
.begin();
332 it
!= hanlders
.end(); ++it
)
334 if(uri
.substr(0, (*it
)->GetName().length()) == (*it
)->GetName())
339 //If we found a handler we can then use it to load the file directly
343 //If it is requsting the page itself then return as we have already
344 //loaded it from the archive
345 if(webKitCtrl
->m_vfsurl
== uri
)
348 wxFSFile
* file
= handler
->GetFile(uri
);
351 //We load the data into a data url to save it being written out again
352 size_t size
= file
->GetStream()->GetLength();
353 char *buffer
= new char[size
];
354 file
->GetStream()->Read(buffer
, size
);
355 wxString data
= wxBase64Encode(buffer
, size
);
357 wxString mime
= file
->GetMimeType();
358 wxString path
= "data:" + mime
+ ";base64," + data
;
359 //Then we can redirect the call
360 webkit_network_request_set_uri(request
, path
);
368 //-----------------------------------------------------------------------------
370 //-----------------------------------------------------------------------------
372 wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewWebKit
, wxWebView
);
374 bool wxWebViewWebKit::Create(wxWindow
*parent
,
380 const wxString
& name
)
386 if (!PreCreation( parent
, pos
, size
) ||
387 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
389 wxFAIL_MSG( wxT("wxWebViewWebKit creation failed") );
393 GtkWidget
*scrolled_window
= gtk_scrolled_window_new (NULL
, NULL
);
394 web_view
= webkit_web_view_new ();
395 g_object_ref(web_view
); // TODO: check memory management
397 m_widget
= scrolled_window
;
398 g_object_ref(m_widget
); // TODO: check memory management
400 /* Place the WebKitWebView in the GtkScrolledWindow */
401 gtk_container_add (GTK_CONTAINER (scrolled_window
), web_view
);
402 gtk_widget_show(m_widget
);
403 gtk_widget_show(web_view
);
405 g_signal_connect_after(web_view
, "notify::load-status",
406 G_CALLBACK(wxgtk_webview_webkit_load_status
),
408 g_signal_connect_after(web_view
, "navigation-policy-decision-requested",
409 G_CALLBACK(wxgtk_webview_webkit_navigation
),
411 g_signal_connect_after(web_view
, "load-error",
412 G_CALLBACK(wxgtk_webview_webkit_error
),
415 g_signal_connect_after(web_view
, "new-window-policy-decision-requested",
416 G_CALLBACK(wxgtk_webview_webkit_new_window
), this);
418 g_signal_connect_after(web_view
, "title-changed",
419 G_CALLBACK(wxgtk_webview_webkit_title_changed
), this);
421 g_signal_connect_after(web_view
, "resource-request-starting",
422 G_CALLBACK(wxgtk_webview_webkit_resource_req
), this);
424 m_parent
->DoAddChild( this );
429 webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view
), url
);
431 //Get the initial history limit so we can enable and disable it later
432 WebKitWebBackForwardList
* history
;
433 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
434 m_historyLimit
= webkit_web_back_forward_list_get_limit(history
);
441 bool wxWebViewWebKit::Enable( bool enable
)
443 if (!wxControl::Enable(enable
))
446 gtk_widget_set_sensitive(GTK_BIN(m_widget
)->child
, enable
);
449 // GTKFixSensitivity();
455 wxWebViewWebKit::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
457 GdkWindow
* window
= gtk_widget_get_parent_window(m_widget
);
461 void wxWebViewWebKit::ZoomIn()
463 webkit_web_view_zoom_in (WEBKIT_WEB_VIEW(web_view
));
466 void wxWebViewWebKit::ZoomOut()
468 webkit_web_view_zoom_out (WEBKIT_WEB_VIEW(web_view
));
471 void wxWebViewWebKit::SetWebkitZoom(float level
)
473 webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW(web_view
), level
);
476 float wxWebViewWebKit::GetWebkitZoom() const
478 return webkit_web_view_get_zoom_level (WEBKIT_WEB_VIEW(web_view
));
481 void wxWebViewWebKit::Stop()
483 webkit_web_view_stop_loading (WEBKIT_WEB_VIEW(web_view
));
486 void wxWebViewWebKit::Reload(wxWebViewReloadFlags flags
)
488 if (flags
& wxWEB_VIEW_RELOAD_NO_CACHE
)
490 webkit_web_view_reload_bypass_cache (WEBKIT_WEB_VIEW(web_view
));
494 webkit_web_view_reload (WEBKIT_WEB_VIEW(web_view
));
498 void wxWebViewWebKit::LoadURL(const wxString
& url
)
500 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view
), wxGTK_CONV(url
));
504 void wxWebViewWebKit::GoBack()
506 webkit_web_view_go_back (WEBKIT_WEB_VIEW(web_view
));
509 void wxWebViewWebKit::GoForward()
511 webkit_web_view_go_forward (WEBKIT_WEB_VIEW(web_view
));
515 bool wxWebViewWebKit::CanGoBack() const
517 return webkit_web_view_can_go_back (WEBKIT_WEB_VIEW(web_view
));
521 bool wxWebViewWebKit::CanGoForward() const
523 return webkit_web_view_can_go_forward (WEBKIT_WEB_VIEW(web_view
));
526 void wxWebViewWebKit::ClearHistory()
528 WebKitWebBackForwardList
* history
;
529 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
530 webkit_web_back_forward_list_clear(history
);
533 void wxWebViewWebKit::EnableHistory(bool enable
)
535 WebKitWebBackForwardList
* history
;
536 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
539 webkit_web_back_forward_list_set_limit(history
, m_historyLimit
);
543 webkit_web_back_forward_list_set_limit(history
, 0);
547 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewWebKit::GetBackwardHistory()
549 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > backhist
;
550 WebKitWebBackForwardList
* history
;
551 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
552 GList
* list
= webkit_web_back_forward_list_get_back_list_with_limit(history
,
554 //We need to iterate in reverse to get the order we desire
555 for(int i
= g_list_length(list
) - 1; i
>= 0 ; i
--)
557 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
558 wxWebViewHistoryItem
* wxitem
= new wxWebViewHistoryItem(
559 webkit_web_history_item_get_uri(gtkitem
),
560 webkit_web_history_item_get_title(gtkitem
));
561 wxitem
->m_histItem
= gtkitem
;
562 wxSharedPtr
<wxWebViewHistoryItem
> item(wxitem
);
563 backhist
.push_back(item
);
568 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewWebKit::GetForwardHistory()
570 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > forwardhist
;
571 WebKitWebBackForwardList
* history
;
572 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
573 GList
* list
= webkit_web_back_forward_list_get_forward_list_with_limit(history
,
575 for(guint i
= 0; i
< g_list_length(list
); i
++)
577 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
578 wxWebViewHistoryItem
* wxitem
= new wxWebViewHistoryItem(
579 webkit_web_history_item_get_uri(gtkitem
),
580 webkit_web_history_item_get_title(gtkitem
));
581 wxitem
->m_histItem
= gtkitem
;
582 wxSharedPtr
<wxWebViewHistoryItem
> item(wxitem
);
583 forwardhist
.push_back(item
);
588 void wxWebViewWebKit::LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
)
590 WebKitWebHistoryItem
* gtkitem
= item
->m_histItem
;
593 WebKitWebBackForwardList
* history
;
594 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
595 webkit_web_view_go_to_back_forward_item(WEBKIT_WEB_VIEW(web_view
),
596 WEBKIT_WEB_HISTORY_ITEM(gtkitem
));
600 bool wxWebViewWebKit::CanCut() const
602 return webkit_web_view_can_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
605 bool wxWebViewWebKit::CanCopy() const
607 return webkit_web_view_can_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
610 bool wxWebViewWebKit::CanPaste() const
612 return webkit_web_view_can_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
615 void wxWebViewWebKit::Cut()
617 webkit_web_view_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
620 void wxWebViewWebKit::Copy()
622 webkit_web_view_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
625 void wxWebViewWebKit::Paste()
627 webkit_web_view_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
630 bool wxWebViewWebKit::CanUndo() const
632 return webkit_web_view_can_undo(WEBKIT_WEB_VIEW(web_view
));
635 bool wxWebViewWebKit::CanRedo() const
637 return webkit_web_view_can_redo(WEBKIT_WEB_VIEW(web_view
));
640 void wxWebViewWebKit::Undo()
642 webkit_web_view_undo(WEBKIT_WEB_VIEW(web_view
));
645 void wxWebViewWebKit::Redo()
647 webkit_web_view_redo(WEBKIT_WEB_VIEW(web_view
));
650 wxString
wxWebViewWebKit::GetCurrentURL() const
652 // FIXME: check which encoding the web kit control uses instead of
653 // assuming UTF8 (here and elsewhere too)
654 return wxString::FromUTF8(webkit_web_view_get_uri(
655 WEBKIT_WEB_VIEW(web_view
)));
659 wxString
wxWebViewWebKit::GetCurrentTitle() const
661 return wxString::FromUTF8(webkit_web_view_get_title(
662 WEBKIT_WEB_VIEW(web_view
)));
666 wxString
wxWebViewWebKit::GetPageSource() const
668 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
669 WEBKIT_WEB_VIEW(web_view
));
670 WebKitWebDataSource
* src
= webkit_web_frame_get_data_source (frame
);
672 // TODO: check encoding with
674 // webkit_web_data_source_get_encoding(WebKitWebDataSource *data_source);
675 return wxString(webkit_web_data_source_get_data (src
)->str
, wxConvUTF8
);
679 wxWebViewZoom
wxWebViewWebKit::GetZoom() const
681 float zoom
= GetWebkitZoom();
683 // arbitrary way to map float zoom to our common zoom enum
686 return wxWEB_VIEW_ZOOM_TINY
;
688 else if (zoom
> 0.65 && zoom
<= 0.90)
690 return wxWEB_VIEW_ZOOM_SMALL
;
692 else if (zoom
> 0.90 && zoom
<= 1.15)
694 return wxWEB_VIEW_ZOOM_MEDIUM
;
696 else if (zoom
> 1.15 && zoom
<= 1.45)
698 return wxWEB_VIEW_ZOOM_LARGE
;
700 else if (zoom
> 1.45)
702 return wxWEB_VIEW_ZOOM_LARGEST
;
705 // to shut up compilers, this can never be reached logically
707 return wxWEB_VIEW_ZOOM_MEDIUM
;
711 void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom
)
713 // arbitrary way to map our common zoom enum to float zoom
716 case wxWEB_VIEW_ZOOM_TINY
:
720 case wxWEB_VIEW_ZOOM_SMALL
:
724 case wxWEB_VIEW_ZOOM_MEDIUM
:
728 case wxWEB_VIEW_ZOOM_LARGE
:
732 case wxWEB_VIEW_ZOOM_LARGEST
:
741 void wxWebViewWebKit::SetZoomType(wxWebViewZoomType type
)
743 webkit_web_view_set_full_content_zoom(WEBKIT_WEB_VIEW(web_view
),
744 (type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
?
748 wxWebViewZoomType
wxWebViewWebKit::GetZoomType() const
750 gboolean fczoom
= webkit_web_view_get_full_content_zoom(
751 WEBKIT_WEB_VIEW(web_view
));
753 if (fczoom
) return wxWEB_VIEW_ZOOM_TYPE_LAYOUT
;
754 else return wxWEB_VIEW_ZOOM_TYPE_TEXT
;
757 bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType
) const
759 // this port supports all zoom types
763 void wxWebViewWebKit::SetPage(const wxString
& html
, const wxString
& baseUri
)
765 webkit_web_view_load_string (WEBKIT_WEB_VIEW(web_view
),
766 html
.mb_str(wxConvUTF8
),
769 baseUri
.mb_str(wxConvUTF8
));
772 void wxWebViewWebKit::Print()
774 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
775 WEBKIT_WEB_VIEW(web_view
));
776 webkit_web_frame_print (frame
);
778 // GtkPrintOperationResult webkit_web_frame_print_full
779 // (WebKitWebFrame *frame,
780 // GtkPrintOperation *operation,
781 // GtkPrintOperationAction action,
787 bool wxWebViewWebKit::IsBusy() const
791 // This code looks nice but returns true after a page was cancelled
793 WebKitLoadStatus status = webkit_web_view_get_load_status
794 (WEBKIT_WEB_VIEW(web_view));
797 #if WEBKIT_CHECK_VERSION(1,1,16)
798 // WEBKIT_LOAD_FAILED is new in webkit 1.1.16
799 if (status == WEBKIT_LOAD_FAILED)
804 if (status == WEBKIT_LOAD_FINISHED)
813 void wxWebViewWebKit::SetEditable(bool enable
)
815 webkit_web_view_set_editable(WEBKIT_WEB_VIEW(web_view
), enable
);
818 bool wxWebViewWebKit::IsEditable() const
820 return webkit_web_view_get_editable(WEBKIT_WEB_VIEW(web_view
));
823 void wxWebViewWebKit::DeleteSelection()
825 webkit_web_view_delete_selection(WEBKIT_WEB_VIEW(web_view
));
828 bool wxWebViewWebKit::HasSelection() const
830 return webkit_web_view_has_selection(WEBKIT_WEB_VIEW(web_view
));
833 void wxWebViewWebKit::SelectAll()
835 webkit_web_view_select_all(WEBKIT_WEB_VIEW(web_view
));
838 wxString
wxWebViewWebKit::GetSelectedText() const
840 WebKitDOMDocument
* doc
;
841 WebKitDOMDOMWindow
* win
;
842 WebKitDOMDOMSelection
* sel
;
843 WebKitDOMRange
* range
;
845 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
846 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
847 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
848 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
850 return wxString(webkit_dom_range_get_text(WEBKIT_DOM_RANGE(range
)),
854 wxString
wxWebViewWebKit::GetSelectedSource() const
856 WebKitDOMDocument
* doc
;
857 WebKitDOMDOMWindow
* win
;
858 WebKitDOMDOMSelection
* sel
;
859 WebKitDOMRange
* range
;
860 WebKitDOMElement
* div
;
861 WebKitDOMDocumentFragment
* clone
;
862 WebKitDOMHTMLElement
* html
;
864 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
865 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
866 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
867 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
869 div
= webkit_dom_document_create_element(WEBKIT_DOM_DOCUMENT(doc
), "div", NULL
);
871 clone
= webkit_dom_range_clone_contents(WEBKIT_DOM_RANGE(range
), NULL
);
872 webkit_dom_node_append_child(&div
->parent_instance
, &clone
->parent_instance
, NULL
);
873 html
= (WebKitDOMHTMLElement
*)div
;
875 return wxString(webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(html
)),
879 void wxWebViewWebKit::ClearSelection()
881 WebKitDOMDocument
* doc
;
882 WebKitDOMDOMWindow
* win
;
883 WebKitDOMDOMSelection
* sel
;
885 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
886 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
887 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
888 webkit_dom_dom_selection_remove_all_ranges(WEBKIT_DOM_DOM_SELECTION(sel
));
892 wxString
wxWebViewWebKit::GetPageText() const
894 WebKitDOMDocument
* doc
;
895 WebKitDOMHTMLElement
* body
;
897 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
898 body
= webkit_dom_document_get_body(WEBKIT_DOM_DOCUMENT(doc
));
899 return wxString(webkit_dom_html_element_get_inner_text(WEBKIT_DOM_HTML_ELEMENT(body
)),
903 void wxWebViewWebKit::RunScript(const wxString
& javascript
)
905 webkit_web_view_execute_script(WEBKIT_WEB_VIEW(web_view
),
906 javascript
.mb_str(wxConvUTF8
));
909 void wxWebViewWebKit::RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
)
911 m_handlerList
.push_back(handler
);
916 wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
918 return GetDefaultAttributesFromGTKWidget(webkit_web_view_new
);
922 #endif // wxHAVE_WEB_BACKEND_GTK_WEBKIT