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 "webkit/webkit.h"
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
30 wxgtk_webview_webkit_load_status(GtkWidget
* widget
,
32 wxWebViewWebKit
*webKitCtrl
)
34 if (!webKitCtrl
->m_ready
) return;
36 wxString url
= webKitCtrl
->GetCurrentURL();
38 WebKitLoadStatus status
;
39 g_object_get(G_OBJECT(widget
), "load-status", &status
, NULL
);
41 wxString target
; // TODO: get target (if possible)
43 if (status
== WEBKIT_LOAD_FINISHED
)
45 webKitCtrl
->m_busy
= false;
46 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_LOADED
,
50 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
51 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
53 else if (status
== WEBKIT_LOAD_COMMITTED
)
55 webKitCtrl
->m_busy
= true;
56 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
60 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
61 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
66 wxgtk_webview_webkit_navigation(WebKitWebView
*,
67 WebKitWebFrame
*frame
,
68 WebKitNetworkRequest
*request
,
69 WebKitWebNavigationAction
*,
70 WebKitWebPolicyDecision
*policy_decision
,
71 wxWebViewWebKit
*webKitCtrl
)
73 if(webKitCtrl
->m_guard
)
75 webKitCtrl
->m_guard
= false;
76 //We set this to make sure that we don't try to load the page again from
77 //the resource request callback
78 webKitCtrl
->m_vfsurl
= webkit_network_request_get_uri(request
);
79 webkit_web_policy_decision_use(policy_decision
);
83 webKitCtrl
->m_busy
= true;
85 const gchar
* uri
= webkit_network_request_get_uri(request
);
87 wxString target
= webkit_web_frame_get_name (frame
);
88 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
90 wxString( uri
, wxConvUTF8
),
94 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
95 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
97 if (thisEvent
.IsVetoed())
99 webKitCtrl
->m_busy
= false;
100 webkit_web_policy_decision_ignore(policy_decision
);
105 wxString wxuri
= uri
;
106 wxSharedPtr
<wxWebHandler
> handler
;
107 wxVector
<wxSharedPtr
<wxWebHandler
> > hanlders
= webKitCtrl
->GetHandlers();
108 //We are not vetoed so see if we match one of the additional handlers
109 for(wxVector
<wxSharedPtr
<wxWebHandler
> >::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 wxWebNavigationError 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 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_ERROR
,
263 webKitWindow
->GetId(),
267 thisEvent
.SetString(description
);
268 thisEvent
.SetInt(type
);
270 if (webKitWindow
&& webKitWindow
->GetEventHandler())
272 webKitWindow
->GetEventHandler()->ProcessEvent(thisEvent
);
279 wxgtk_webview_webkit_new_window(WebKitWebView
*,
280 WebKitWebFrame
*frame
,
281 WebKitNetworkRequest
*request
,
282 WebKitWebNavigationAction
*,
283 WebKitWebPolicyDecision
*policy_decision
,
284 wxWebViewWebKit
*webKitCtrl
)
286 const gchar
* uri
= webkit_network_request_get_uri(request
);
288 wxString target
= webkit_web_frame_get_name (frame
);
289 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
291 wxString( uri
, wxConvUTF8
),
295 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
296 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
298 //We always want the user to handle this themselves
299 webkit_web_policy_decision_ignore(policy_decision
);
304 wxgtk_webview_webkit_title_changed(WebKitWebView
*,
307 wxWebViewWebKit
*webKitCtrl
)
309 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
311 webKitCtrl
->GetCurrentURL(),
314 thisEvent
.SetString(wxString(title
, wxConvUTF8
));
316 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
317 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
322 wxgtk_webview_webkit_resource_req(WebKitWebView
*,
325 WebKitNetworkRequest
*request
,
326 WebKitNetworkResponse
*,
327 wxWebViewWebKit
*webKitCtrl
)
329 wxString uri
= webkit_network_request_get_uri(request
);
331 wxSharedPtr
<wxWebHandler
> handler
;
332 wxVector
<wxSharedPtr
<wxWebHandler
> > hanlders
= webKitCtrl
->GetHandlers();
334 //We are not vetoed so see if we match one of the additional handlers
335 for(wxVector
<wxSharedPtr
<wxWebHandler
> >::iterator it
= hanlders
.begin();
336 it
!= hanlders
.end(); ++it
)
338 if(uri
.substr(0, (*it
)->GetName().length()) == (*it
)->GetName())
343 //If we found a handler we can then use it to load the file directly
347 //If it is requsting the page itself then return as we have already
348 //loaded it from the archive
349 if(webKitCtrl
->m_vfsurl
== uri
)
352 wxFSFile
* file
= handler
->GetFile(uri
);
355 //We redirect to a temp file for now, small things could be loaded
356 //using the data scheme
357 size_t size
= file
->GetStream()->GetLength();
358 char *buffer
= new char[size
];
360 wxString path
= wxFileName::CreateTempFileName("wxwebview_", &tempfile
);
361 //We can then stream from the archive to the temp file
362 file
->GetStream()->Read(buffer
, size
);
363 tempfile
.Write(buffer
, size
);
366 //Then we can redirect the call
367 webkit_network_request_set_uri(request
, "file://" + path
);
375 //-----------------------------------------------------------------------------
377 //-----------------------------------------------------------------------------
379 wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewWebKit
, wxWebView
);
381 bool wxWebViewWebKit::Create(wxWindow
*parent
,
387 const wxString
& name
)
393 if (!PreCreation( parent
, pos
, size
) ||
394 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
396 wxFAIL_MSG( wxT("wxWebViewWebKit creation failed") );
400 GtkWidget
*scrolled_window
= gtk_scrolled_window_new (NULL
, NULL
);
401 web_view
= webkit_web_view_new ();
402 g_object_ref(web_view
); // TODO: check memory management
404 m_widget
= scrolled_window
;
405 g_object_ref(m_widget
); // TODO: check memory management
407 /* Place the WebKitWebView in the GtkScrolledWindow */
408 gtk_container_add (GTK_CONTAINER (scrolled_window
), web_view
);
409 gtk_widget_show(m_widget
);
410 gtk_widget_show(web_view
);
412 g_signal_connect_after(web_view
, "notify::load-status",
413 G_CALLBACK(wxgtk_webview_webkit_load_status
),
415 g_signal_connect_after(web_view
, "navigation-policy-decision-requested",
416 G_CALLBACK(wxgtk_webview_webkit_navigation
),
418 g_signal_connect_after(web_view
, "load-error",
419 G_CALLBACK(wxgtk_webview_webkit_error
),
422 g_signal_connect_after(web_view
, "new-window-policy-decision-requested",
423 G_CALLBACK(wxgtk_webview_webkit_new_window
), this);
425 g_signal_connect_after(web_view
, "title-changed",
426 G_CALLBACK(wxgtk_webview_webkit_title_changed
), this);
428 g_signal_connect_after(web_view
, "resource-request-starting",
429 G_CALLBACK(wxgtk_webview_webkit_resource_req
), this);
431 m_parent
->DoAddChild( this );
436 webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view
), url
);
438 //Get the initial history limit so we can enable and disable it later
439 WebKitWebBackForwardList
* history
;
440 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
441 m_historyLimit
= webkit_web_back_forward_list_get_limit(history
);
448 bool wxWebViewWebKit::Enable( bool enable
)
450 if (!wxControl::Enable(enable
))
453 gtk_widget_set_sensitive(GTK_BIN(m_widget
)->child
, enable
);
456 // GTKFixSensitivity();
462 wxWebViewWebKit::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
464 GdkWindow
* window
= gtk_widget_get_parent_window(m_widget
);
468 void wxWebViewWebKit::ZoomIn()
470 webkit_web_view_zoom_in (WEBKIT_WEB_VIEW(web_view
));
473 void wxWebViewWebKit::ZoomOut()
475 webkit_web_view_zoom_out (WEBKIT_WEB_VIEW(web_view
));
478 void wxWebViewWebKit::SetWebkitZoom(float level
)
480 webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW(web_view
), level
);
483 float wxWebViewWebKit::GetWebkitZoom()
485 return webkit_web_view_get_zoom_level (WEBKIT_WEB_VIEW(web_view
));
488 void wxWebViewWebKit::Stop()
490 webkit_web_view_stop_loading (WEBKIT_WEB_VIEW(web_view
));
493 void wxWebViewWebKit::Reload(wxWebViewReloadFlags flags
)
495 if (flags
& wxWEB_VIEW_RELOAD_NO_CACHE
)
497 webkit_web_view_reload_bypass_cache (WEBKIT_WEB_VIEW(web_view
));
501 webkit_web_view_reload (WEBKIT_WEB_VIEW(web_view
));
505 void wxWebViewWebKit::LoadUrl(const wxString
& url
)
507 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view
), wxGTK_CONV(url
));
511 void wxWebViewWebKit::GoBack()
513 webkit_web_view_go_back (WEBKIT_WEB_VIEW(web_view
));
516 void wxWebViewWebKit::GoForward()
518 webkit_web_view_go_forward (WEBKIT_WEB_VIEW(web_view
));
522 bool wxWebViewWebKit::CanGoBack()
524 return webkit_web_view_can_go_back (WEBKIT_WEB_VIEW(web_view
));
528 bool wxWebViewWebKit::CanGoForward()
530 return webkit_web_view_can_go_forward (WEBKIT_WEB_VIEW(web_view
));
533 void wxWebViewWebKit::ClearHistory()
535 WebKitWebBackForwardList
* history
;
536 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
537 webkit_web_back_forward_list_clear(history
);
540 void wxWebViewWebKit::EnableHistory(bool enable
)
542 WebKitWebBackForwardList
* history
;
543 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
546 webkit_web_back_forward_list_set_limit(history
, m_historyLimit
);
550 webkit_web_back_forward_list_set_limit(history
, 0);
554 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewWebKit::GetBackwardHistory()
556 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > backhist
;
557 WebKitWebBackForwardList
* history
;
558 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
559 GList
* list
= webkit_web_back_forward_list_get_back_list_with_limit(history
,
561 //We need to iterate in reverse to get the order we desire
562 for(int i
= g_list_length(list
) - 1; i
>= 0 ; i
--)
564 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
565 wxWebHistoryItem
* wxitem
= new wxWebHistoryItem(
566 webkit_web_history_item_get_uri(gtkitem
),
567 webkit_web_history_item_get_title(gtkitem
));
568 wxitem
->m_histItem
= gtkitem
;
569 wxSharedPtr
<wxWebHistoryItem
> item(wxitem
);
570 backhist
.push_back(item
);
575 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewWebKit::GetForwardHistory()
577 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > forwardhist
;
578 WebKitWebBackForwardList
* history
;
579 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
580 GList
* list
= webkit_web_back_forward_list_get_forward_list_with_limit(history
,
582 for(guint i
= 0; i
< g_list_length(list
); i
++)
584 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
585 wxWebHistoryItem
* wxitem
= new wxWebHistoryItem(
586 webkit_web_history_item_get_uri(gtkitem
),
587 webkit_web_history_item_get_title(gtkitem
));
588 wxitem
->m_histItem
= gtkitem
;
589 wxSharedPtr
<wxWebHistoryItem
> item(wxitem
);
590 forwardhist
.push_back(item
);
595 void wxWebViewWebKit::LoadHistoryItem(wxSharedPtr
<wxWebHistoryItem
> item
)
597 WebKitWebHistoryItem
* gtkitem
= item
->m_histItem
;
600 WebKitWebBackForwardList
* history
;
601 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
602 webkit_web_back_forward_list_go_to_item(WEBKIT_WEB_BACK_FORWARD_LIST(history
),
603 WEBKIT_WEB_HISTORY_ITEM(gtkitem
));
607 bool wxWebViewWebKit::CanCut()
609 return webkit_web_view_can_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
612 bool wxWebViewWebKit::CanCopy()
614 return webkit_web_view_can_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
617 bool wxWebViewWebKit::CanPaste()
619 return webkit_web_view_can_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
622 void wxWebViewWebKit::Cut()
624 webkit_web_view_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
627 void wxWebViewWebKit::Copy()
629 webkit_web_view_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
632 void wxWebViewWebKit::Paste()
634 webkit_web_view_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
637 bool wxWebViewWebKit::CanUndo()
639 return webkit_web_view_can_undo(WEBKIT_WEB_VIEW(web_view
));
642 bool wxWebViewWebKit::CanRedo()
644 return webkit_web_view_can_redo(WEBKIT_WEB_VIEW(web_view
));
647 void wxWebViewWebKit::Undo()
649 webkit_web_view_undo(WEBKIT_WEB_VIEW(web_view
));
652 void wxWebViewWebKit::Redo()
654 webkit_web_view_redo(WEBKIT_WEB_VIEW(web_view
));
657 wxString
wxWebViewWebKit::GetCurrentURL()
659 // FIXME: check which encoding the web kit control uses instead of
660 // assuming UTF8 (here and elsewhere too)
661 return wxString::FromUTF8(webkit_web_view_get_uri(
662 WEBKIT_WEB_VIEW(web_view
)));
666 wxString
wxWebViewWebKit::GetCurrentTitle()
668 return wxString::FromUTF8(webkit_web_view_get_title(
669 WEBKIT_WEB_VIEW(web_view
)));
673 wxString
wxWebViewWebKit::GetPageSource()
675 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
676 WEBKIT_WEB_VIEW(web_view
));
677 WebKitWebDataSource
* src
= webkit_web_frame_get_data_source (frame
);
679 // TODO: check encoding with
681 // webkit_web_data_source_get_encoding(WebKitWebDataSource *data_source);
682 return wxString(webkit_web_data_source_get_data (src
)->str
, wxConvUTF8
);
686 wxWebViewZoom
wxWebViewWebKit::GetZoom()
688 float zoom
= GetWebkitZoom();
690 // arbitrary way to map float zoom to our common zoom enum
693 return wxWEB_VIEW_ZOOM_TINY
;
695 else if (zoom
> 0.65 && zoom
<= 0.90)
697 return wxWEB_VIEW_ZOOM_SMALL
;
699 else if (zoom
> 0.90 && zoom
<= 1.15)
701 return wxWEB_VIEW_ZOOM_MEDIUM
;
703 else if (zoom
> 1.15 && zoom
<= 1.45)
705 return wxWEB_VIEW_ZOOM_LARGE
;
707 else if (zoom
> 1.45)
709 return wxWEB_VIEW_ZOOM_LARGEST
;
712 // to shut up compilers, this can never be reached logically
714 return wxWEB_VIEW_ZOOM_MEDIUM
;
718 void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom
)
720 // arbitrary way to map our common zoom enum to float zoom
723 case wxWEB_VIEW_ZOOM_TINY
:
727 case wxWEB_VIEW_ZOOM_SMALL
:
731 case wxWEB_VIEW_ZOOM_MEDIUM
:
735 case wxWEB_VIEW_ZOOM_LARGE
:
739 case wxWEB_VIEW_ZOOM_LARGEST
:
748 void wxWebViewWebKit::SetZoomType(wxWebViewZoomType type
)
750 webkit_web_view_set_full_content_zoom(WEBKIT_WEB_VIEW(web_view
),
751 (type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
?
755 wxWebViewZoomType
wxWebViewWebKit::GetZoomType() const
757 gboolean fczoom
= webkit_web_view_get_full_content_zoom(
758 WEBKIT_WEB_VIEW(web_view
));
760 if (fczoom
) return wxWEB_VIEW_ZOOM_TYPE_LAYOUT
;
761 else return wxWEB_VIEW_ZOOM_TYPE_TEXT
;
764 bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType
) const
766 // this port supports all zoom types
770 void wxWebViewWebKit::SetPage(const wxString
& html
, const wxString
& baseUri
)
772 webkit_web_view_load_string (WEBKIT_WEB_VIEW(web_view
),
773 html
.mb_str(wxConvUTF8
),
776 baseUri
.mb_str(wxConvUTF8
));
779 void wxWebViewWebKit::Print()
781 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
782 WEBKIT_WEB_VIEW(web_view
));
783 webkit_web_frame_print (frame
);
785 // GtkPrintOperationResult webkit_web_frame_print_full
786 // (WebKitWebFrame *frame,
787 // GtkPrintOperation *operation,
788 // GtkPrintOperationAction action,
794 bool wxWebViewWebKit::IsBusy()
798 // This code looks nice but returns true after a page was cancelled
800 WebKitLoadStatus status = webkit_web_view_get_load_status
801 (WEBKIT_WEB_VIEW(web_view));
804 #if WEBKIT_CHECK_VERSION(1,1,16)
805 // WEBKIT_LOAD_FAILED is new in webkit 1.1.16
806 if (status == WEBKIT_LOAD_FAILED)
811 if (status == WEBKIT_LOAD_FINISHED)
820 void wxWebViewWebKit::SetEditable(bool enable
)
822 webkit_web_view_set_editable(WEBKIT_WEB_VIEW(web_view
), enable
);
825 bool wxWebViewWebKit::IsEditable()
827 return webkit_web_view_get_editable(WEBKIT_WEB_VIEW(web_view
));
830 void wxWebViewWebKit::DeleteSelection()
832 webkit_web_view_delete_selection(WEBKIT_WEB_VIEW(web_view
));
835 bool wxWebViewWebKit::HasSelection()
837 return webkit_web_view_has_selection(WEBKIT_WEB_VIEW(web_view
));
840 void wxWebViewWebKit::SelectAll()
842 webkit_web_view_select_all(WEBKIT_WEB_VIEW(web_view
));
845 wxString
wxWebViewWebKit::GetSelectedText()
847 WebKitDOMDocument
* doc
;
848 WebKitDOMDOMWindow
* win
;
849 WebKitDOMDOMSelection
* sel
;
850 WebKitDOMRange
* range
;
852 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
853 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
854 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
855 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
857 return wxString(webkit_dom_range_get_text(WEBKIT_DOM_RANGE(range
)),
861 wxString
wxWebViewWebKit::GetSelectedSource()
863 WebKitDOMDocument
* doc
;
864 WebKitDOMDOMWindow
* win
;
865 WebKitDOMDOMSelection
* sel
;
866 WebKitDOMRange
* range
;
867 WebKitDOMElement
* div
;
868 WebKitDOMDocumentFragment
* clone
;
869 WebKitDOMHTMLElement
* html
;
871 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
872 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
873 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
874 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
876 div
= webkit_dom_document_create_element(WEBKIT_DOM_DOCUMENT(doc
), "div", NULL
);
878 clone
= webkit_dom_range_clone_contents(WEBKIT_DOM_RANGE(range
), NULL
);
879 webkit_dom_node_append_child(&div
->parent_instance
, &clone
->parent_instance
, NULL
);
880 html
= (WebKitDOMHTMLElement
*)div
;
882 return wxString(webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(html
)),
886 void wxWebViewWebKit::ClearSelection()
888 WebKitDOMDocument
* doc
;
889 WebKitDOMDOMWindow
* win
;
890 WebKitDOMDOMSelection
* sel
;
892 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
893 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
894 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
895 webkit_dom_dom_selection_remove_all_ranges(WEBKIT_DOM_DOM_SELECTION(sel
));
899 wxString
wxWebViewWebKit::GetPageText()
901 WebKitDOMDocument
* doc
;
902 WebKitDOMHTMLElement
* body
;
904 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
905 body
= webkit_dom_document_get_body(WEBKIT_DOM_DOCUMENT(doc
));
906 return wxString(webkit_dom_html_element_get_inner_text(WEBKIT_DOM_HTML_ELEMENT(body
)),
910 void wxWebViewWebKit::RunScript(const wxString
& javascript
)
912 webkit_web_view_execute_script(WEBKIT_WEB_VIEW(web_view
),
913 javascript
.mb_str(wxConvUTF8
));
916 void wxWebViewWebKit::RegisterHandler(wxSharedPtr
<wxWebHandler
> handler
)
918 m_handlerList
.push_back(handler
);
923 wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
925 return GetDefaultAttributesFromGTKWidget(webkit_web_view_new
);
929 #endif // wxHAVE_WEB_BACKEND_GTK_WEBKIT