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 && 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 WebKitWebBackForwardList
* hist
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(widget
));
47 WebKitWebHistoryItem
* item
= webkit_web_back_forward_list_get_current_item(hist
);
48 //We have to check if we are actually storing history
49 //If the item isn't added we add it ourselves, it isn't added otherwise
50 //with a custom scheme.
51 if(WEBKIT_IS_WEB_HISTORY_ITEM(item
) && webkit_web_history_item_get_uri(item
) != url
)
54 newitem
= webkit_web_history_item_new_with_data
57 webKitCtrl
->GetCurrentTitle().utf8_str()
59 webkit_web_back_forward_list_add_item(hist
, newitem
);
62 webKitCtrl
->m_busy
= false;
63 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_LOADED
,
67 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
68 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
70 else if (status
== WEBKIT_LOAD_COMMITTED
)
72 webKitCtrl
->m_busy
= true;
73 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
77 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
78 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
83 wxgtk_webview_webkit_navigation(WebKitWebView
*,
84 WebKitWebFrame
*frame
,
85 WebKitNetworkRequest
*request
,
86 WebKitWebNavigationAction
*,
87 WebKitWebPolicyDecision
*policy_decision
,
88 wxWebViewWebKit
*webKitCtrl
)
90 if(webKitCtrl
->m_guard
)
92 webKitCtrl
->m_guard
= false;
93 //We set this to make sure that we don't try to load the page again from
94 //the resource request callback
95 webKitCtrl
->m_vfsurl
= webkit_network_request_get_uri(request
);
96 webkit_web_policy_decision_use(policy_decision
);
100 webKitCtrl
->m_busy
= true;
102 const gchar
* uri
= webkit_network_request_get_uri(request
);
104 wxString target
= webkit_web_frame_get_name (frame
);
105 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
107 wxString( uri
, wxConvUTF8
),
110 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
111 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
113 if (!event
.IsAllowed())
115 webKitCtrl
->m_busy
= false;
116 webkit_web_policy_decision_ignore(policy_decision
);
121 wxString wxuri
= uri
;
122 wxSharedPtr
<wxWebViewHandler
> handler
;
123 wxVector
<wxSharedPtr
<wxWebViewHandler
> > hanlders
= webKitCtrl
->GetHandlers();
124 //We are not vetoed so see if we match one of the additional handlers
125 for(wxVector
<wxSharedPtr
<wxWebViewHandler
> >::iterator it
= hanlders
.begin();
126 it
!= hanlders
.end(); ++it
)
128 if(wxuri
.substr(0, (*it
)->GetName().length()) == (*it
)->GetName())
133 //If we found a handler we can then use it to load the file directly
137 webKitCtrl
->m_guard
= true;
138 wxFSFile
* file
= handler
->GetFile(wxuri
);
141 webKitCtrl
->SetPage(*file
->GetStream(), wxuri
);
143 //We need to throw some sort of error here if file is NULL
144 webkit_web_policy_decision_ignore(policy_decision
);
152 wxgtk_webview_webkit_error(WebKitWebView
*,
156 wxWebViewWebKit
* webKitWindow
)
158 webKitWindow
->m_busy
= false;
159 wxWebViewNavigationError type
= wxWEB_NAV_ERR_OTHER
;
161 GError
* error
= (GError
*)web_error
;
162 wxString
description(error
->message
, wxConvUTF8
);
164 if (strcmp(g_quark_to_string(error
->domain
), "soup_http_error_quark") == 0)
168 case SOUP_STATUS_CANCELLED
:
169 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
172 case SOUP_STATUS_CANT_RESOLVE
:
173 case SOUP_STATUS_NOT_FOUND
:
174 type
= wxWEB_NAV_ERR_NOT_FOUND
;
177 case SOUP_STATUS_CANT_RESOLVE_PROXY
:
178 case SOUP_STATUS_CANT_CONNECT
:
179 case SOUP_STATUS_CANT_CONNECT_PROXY
:
180 case SOUP_STATUS_SSL_FAILED
:
181 case SOUP_STATUS_IO_ERROR
:
182 type
= wxWEB_NAV_ERR_CONNECTION
;
185 case SOUP_STATUS_MALFORMED
:
186 //case SOUP_STATUS_TOO_MANY_REDIRECTS:
187 type
= wxWEB_NAV_ERR_REQUEST
;
190 //case SOUP_STATUS_NO_CONTENT:
191 //case SOUP_STATUS_RESET_CONTENT:
193 case SOUP_STATUS_BAD_REQUEST
:
194 type
= wxWEB_NAV_ERR_REQUEST
;
197 case SOUP_STATUS_UNAUTHORIZED
:
198 case SOUP_STATUS_FORBIDDEN
:
199 type
= wxWEB_NAV_ERR_AUTH
;
202 case SOUP_STATUS_METHOD_NOT_ALLOWED
:
203 case SOUP_STATUS_NOT_ACCEPTABLE
:
204 type
= wxWEB_NAV_ERR_SECURITY
;
207 case SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED
:
208 type
= wxWEB_NAV_ERR_AUTH
;
211 case SOUP_STATUS_REQUEST_TIMEOUT
:
212 type
= wxWEB_NAV_ERR_CONNECTION
;
215 //case SOUP_STATUS_PAYMENT_REQUIRED:
216 case SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE
:
217 case SOUP_STATUS_REQUEST_URI_TOO_LONG
:
218 case SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE
:
219 type
= wxWEB_NAV_ERR_REQUEST
;
222 case SOUP_STATUS_BAD_GATEWAY
:
223 case SOUP_STATUS_SERVICE_UNAVAILABLE
:
224 case SOUP_STATUS_GATEWAY_TIMEOUT
:
225 type
= wxWEB_NAV_ERR_CONNECTION
;
228 case SOUP_STATUS_HTTP_VERSION_NOT_SUPPORTED
:
229 type
= wxWEB_NAV_ERR_REQUEST
;
231 //case SOUP_STATUS_INSUFFICIENT_STORAGE:
232 //case SOUP_STATUS_NOT_EXTENDED:
235 else if (strcmp(g_quark_to_string(error
->domain
),
236 "webkit-network-error-quark") == 0)
240 //WEBKIT_NETWORK_ERROR_FAILED:
241 //WEBKIT_NETWORK_ERROR_TRANSPORT:
243 case WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL
:
244 type
= wxWEB_NAV_ERR_REQUEST
;
247 case WEBKIT_NETWORK_ERROR_CANCELLED
:
248 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
251 case WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST
:
252 type
= wxWEB_NAV_ERR_NOT_FOUND
;
256 else if (strcmp(g_quark_to_string(error
->domain
),
257 "webkit-policy-error-quark") == 0)
261 //case WEBKIT_POLICY_ERROR_FAILED:
262 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_MIME_TYPE:
263 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_URL:
264 //case WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE:
265 case WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT
:
266 type
= wxWEB_NAV_ERR_SECURITY
;
271 webkit_plugin_error_quark
274 printf("Error domain %s\n", g_quark_to_string(error->domain));
278 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_ERROR
,
279 webKitWindow
->GetId(),
281 event
.SetString(description
);
284 if (webKitWindow
&& webKitWindow
->GetEventHandler())
286 webKitWindow
->GetEventHandler()->ProcessEvent(event
);
293 wxgtk_webview_webkit_new_window(WebKitWebView
*,
294 WebKitWebFrame
*frame
,
295 WebKitNetworkRequest
*request
,
296 WebKitWebNavigationAction
*,
297 WebKitWebPolicyDecision
*policy_decision
,
298 wxWebViewWebKit
*webKitCtrl
)
300 const gchar
* uri
= webkit_network_request_get_uri(request
);
302 wxString target
= webkit_web_frame_get_name (frame
);
303 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
305 wxString( uri
, wxConvUTF8
),
308 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
309 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
311 //We always want the user to handle this themselves
312 webkit_web_policy_decision_ignore(policy_decision
);
317 wxgtk_webview_webkit_title_changed(WebKitWebView
*,
320 wxWebViewWebKit
*webKitCtrl
)
322 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
324 webKitCtrl
->GetCurrentURL(),
326 event
.SetString(wxString(title
, wxConvUTF8
));
328 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
329 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
334 wxgtk_webview_webkit_resource_req(WebKitWebView
*,
337 WebKitNetworkRequest
*request
,
338 WebKitNetworkResponse
*,
339 wxWebViewWebKit
*webKitCtrl
)
341 wxString uri
= webkit_network_request_get_uri(request
);
343 wxSharedPtr
<wxWebViewHandler
> handler
;
344 wxVector
<wxSharedPtr
<wxWebViewHandler
> > hanlders
= webKitCtrl
->GetHandlers();
346 //We are not vetoed so see if we match one of the additional handlers
347 for(wxVector
<wxSharedPtr
<wxWebViewHandler
> >::iterator it
= hanlders
.begin();
348 it
!= hanlders
.end(); ++it
)
350 if(uri
.substr(0, (*it
)->GetName().length()) == (*it
)->GetName())
355 //If we found a handler we can then use it to load the file directly
359 //If it is requsting the page itself then return as we have already
360 //loaded it from the archive
361 if(webKitCtrl
->m_vfsurl
== uri
)
364 wxFSFile
* file
= handler
->GetFile(uri
);
367 //We load the data into a data url to save it being written out again
368 size_t size
= file
->GetStream()->GetLength();
369 char *buffer
= new char[size
];
370 file
->GetStream()->Read(buffer
, size
);
371 wxString data
= wxBase64Encode(buffer
, size
);
373 wxString mime
= file
->GetMimeType();
374 wxString path
= "data:" + mime
+ ";base64," + data
;
375 //Then we can redirect the call
376 webkit_network_request_set_uri(request
, path
.utf8_str());
384 //-----------------------------------------------------------------------------
386 //-----------------------------------------------------------------------------
388 wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewWebKit
, wxWebView
);
390 bool wxWebViewWebKit::Create(wxWindow
*parent
,
396 const wxString
& name
)
402 if (!PreCreation( parent
, pos
, size
) ||
403 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
405 wxFAIL_MSG( wxT("wxWebViewWebKit creation failed") );
409 GtkWidget
*scrolled_window
= gtk_scrolled_window_new (NULL
, NULL
);
410 web_view
= webkit_web_view_new ();
411 g_object_ref(web_view
); // TODO: check memory management
413 m_widget
= scrolled_window
;
414 g_object_ref(m_widget
); // TODO: check memory management
416 /* Place the WebKitWebView in the GtkScrolledWindow */
417 gtk_container_add (GTK_CONTAINER (scrolled_window
), web_view
);
418 gtk_widget_show(m_widget
);
419 gtk_widget_show(web_view
);
421 g_signal_connect_after(web_view
, "notify::load-status",
422 G_CALLBACK(wxgtk_webview_webkit_load_status
),
424 g_signal_connect_after(web_view
, "navigation-policy-decision-requested",
425 G_CALLBACK(wxgtk_webview_webkit_navigation
),
427 g_signal_connect_after(web_view
, "load-error",
428 G_CALLBACK(wxgtk_webview_webkit_error
),
431 g_signal_connect_after(web_view
, "new-window-policy-decision-requested",
432 G_CALLBACK(wxgtk_webview_webkit_new_window
), this);
434 g_signal_connect_after(web_view
, "title-changed",
435 G_CALLBACK(wxgtk_webview_webkit_title_changed
), this);
437 g_signal_connect_after(web_view
, "resource-request-starting",
438 G_CALLBACK(wxgtk_webview_webkit_resource_req
), this);
440 m_parent
->DoAddChild( this );
445 webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view
), url
.utf8_str());
447 //Get the initial history limit so we can enable and disable it later
448 WebKitWebBackForwardList
* history
;
449 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
450 m_historyLimit
= webkit_web_back_forward_list_get_limit(history
);
457 bool wxWebViewWebKit::Enable( bool enable
)
459 if (!wxControl::Enable(enable
))
462 gtk_widget_set_sensitive(GTK_BIN(m_widget
)->child
, enable
);
465 // GTKFixSensitivity();
471 wxWebViewWebKit::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
473 GdkWindow
* window
= gtk_widget_get_parent_window(m_widget
);
477 void wxWebViewWebKit::ZoomIn()
479 webkit_web_view_zoom_in (WEBKIT_WEB_VIEW(web_view
));
482 void wxWebViewWebKit::ZoomOut()
484 webkit_web_view_zoom_out (WEBKIT_WEB_VIEW(web_view
));
487 void wxWebViewWebKit::SetWebkitZoom(float level
)
489 webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW(web_view
), level
);
492 float wxWebViewWebKit::GetWebkitZoom() const
494 return webkit_web_view_get_zoom_level (WEBKIT_WEB_VIEW(web_view
));
497 void wxWebViewWebKit::Stop()
499 webkit_web_view_stop_loading (WEBKIT_WEB_VIEW(web_view
));
502 void wxWebViewWebKit::Reload(wxWebViewReloadFlags flags
)
504 if (flags
& wxWEB_VIEW_RELOAD_NO_CACHE
)
506 webkit_web_view_reload_bypass_cache (WEBKIT_WEB_VIEW(web_view
));
510 webkit_web_view_reload (WEBKIT_WEB_VIEW(web_view
));
514 void wxWebViewWebKit::LoadURL(const wxString
& url
)
516 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view
), wxGTK_CONV(url
));
520 void wxWebViewWebKit::GoBack()
522 webkit_web_view_go_back (WEBKIT_WEB_VIEW(web_view
));
525 void wxWebViewWebKit::GoForward()
527 webkit_web_view_go_forward (WEBKIT_WEB_VIEW(web_view
));
531 bool wxWebViewWebKit::CanGoBack() const
533 return webkit_web_view_can_go_back (WEBKIT_WEB_VIEW(web_view
));
537 bool wxWebViewWebKit::CanGoForward() const
539 return webkit_web_view_can_go_forward (WEBKIT_WEB_VIEW(web_view
));
542 void wxWebViewWebKit::ClearHistory()
544 WebKitWebBackForwardList
* history
;
545 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
546 webkit_web_back_forward_list_clear(history
);
549 void wxWebViewWebKit::EnableHistory(bool enable
)
551 WebKitWebBackForwardList
* history
;
552 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
555 webkit_web_back_forward_list_set_limit(history
, m_historyLimit
);
559 webkit_web_back_forward_list_set_limit(history
, 0);
563 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewWebKit::GetBackwardHistory()
565 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > backhist
;
566 WebKitWebBackForwardList
* history
;
567 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
568 GList
* list
= webkit_web_back_forward_list_get_back_list_with_limit(history
,
570 //We need to iterate in reverse to get the order we desire
571 for(int i
= g_list_length(list
) - 1; i
>= 0 ; i
--)
573 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
574 wxWebViewHistoryItem
* wxitem
= new wxWebViewHistoryItem(
575 webkit_web_history_item_get_uri(gtkitem
),
576 webkit_web_history_item_get_title(gtkitem
));
577 wxitem
->m_histItem
= gtkitem
;
578 wxSharedPtr
<wxWebViewHistoryItem
> item(wxitem
);
579 backhist
.push_back(item
);
584 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewWebKit::GetForwardHistory()
586 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > forwardhist
;
587 WebKitWebBackForwardList
* history
;
588 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
589 GList
* list
= webkit_web_back_forward_list_get_forward_list_with_limit(history
,
591 for(guint i
= 0; i
< g_list_length(list
); i
++)
593 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
594 wxWebViewHistoryItem
* wxitem
= new wxWebViewHistoryItem(
595 webkit_web_history_item_get_uri(gtkitem
),
596 webkit_web_history_item_get_title(gtkitem
));
597 wxitem
->m_histItem
= gtkitem
;
598 wxSharedPtr
<wxWebViewHistoryItem
> item(wxitem
);
599 forwardhist
.push_back(item
);
604 void wxWebViewWebKit::LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
)
606 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)item
->m_histItem
;
609 webkit_web_view_go_to_back_forward_item(WEBKIT_WEB_VIEW(web_view
),
610 WEBKIT_WEB_HISTORY_ITEM(gtkitem
));
614 bool wxWebViewWebKit::CanCut() const
616 return webkit_web_view_can_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
619 bool wxWebViewWebKit::CanCopy() const
621 return webkit_web_view_can_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
624 bool wxWebViewWebKit::CanPaste() const
626 return webkit_web_view_can_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
629 void wxWebViewWebKit::Cut()
631 webkit_web_view_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
634 void wxWebViewWebKit::Copy()
636 webkit_web_view_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
639 void wxWebViewWebKit::Paste()
641 webkit_web_view_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
644 bool wxWebViewWebKit::CanUndo() const
646 return webkit_web_view_can_undo(WEBKIT_WEB_VIEW(web_view
));
649 bool wxWebViewWebKit::CanRedo() const
651 return webkit_web_view_can_redo(WEBKIT_WEB_VIEW(web_view
));
654 void wxWebViewWebKit::Undo()
656 webkit_web_view_undo(WEBKIT_WEB_VIEW(web_view
));
659 void wxWebViewWebKit::Redo()
661 webkit_web_view_redo(WEBKIT_WEB_VIEW(web_view
));
664 wxString
wxWebViewWebKit::GetCurrentURL() const
666 // FIXME: check which encoding the web kit control uses instead of
667 // assuming UTF8 (here and elsewhere too)
668 return wxString::FromUTF8(webkit_web_view_get_uri(
669 WEBKIT_WEB_VIEW(web_view
)));
673 wxString
wxWebViewWebKit::GetCurrentTitle() const
675 return wxString::FromUTF8(webkit_web_view_get_title(
676 WEBKIT_WEB_VIEW(web_view
)));
680 wxString
wxWebViewWebKit::GetPageSource() const
682 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
683 WEBKIT_WEB_VIEW(web_view
));
684 WebKitWebDataSource
* src
= webkit_web_frame_get_data_source (frame
);
686 // TODO: check encoding with
688 // webkit_web_data_source_get_encoding(WebKitWebDataSource *data_source);
689 return wxString(webkit_web_data_source_get_data (src
)->str
, wxConvUTF8
);
693 wxWebViewZoom
wxWebViewWebKit::GetZoom() const
695 float zoom
= GetWebkitZoom();
697 // arbitrary way to map float zoom to our common zoom enum
700 return wxWEB_VIEW_ZOOM_TINY
;
702 else if (zoom
> 0.65 && zoom
<= 0.90)
704 return wxWEB_VIEW_ZOOM_SMALL
;
706 else if (zoom
> 0.90 && zoom
<= 1.15)
708 return wxWEB_VIEW_ZOOM_MEDIUM
;
710 else if (zoom
> 1.15 && zoom
<= 1.45)
712 return wxWEB_VIEW_ZOOM_LARGE
;
714 else if (zoom
> 1.45)
716 return wxWEB_VIEW_ZOOM_LARGEST
;
719 // to shut up compilers, this can never be reached logically
721 return wxWEB_VIEW_ZOOM_MEDIUM
;
725 void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom
)
727 // arbitrary way to map our common zoom enum to float zoom
730 case wxWEB_VIEW_ZOOM_TINY
:
734 case wxWEB_VIEW_ZOOM_SMALL
:
738 case wxWEB_VIEW_ZOOM_MEDIUM
:
742 case wxWEB_VIEW_ZOOM_LARGE
:
746 case wxWEB_VIEW_ZOOM_LARGEST
:
755 void wxWebViewWebKit::SetZoomType(wxWebViewZoomType type
)
757 webkit_web_view_set_full_content_zoom(WEBKIT_WEB_VIEW(web_view
),
758 (type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
?
762 wxWebViewZoomType
wxWebViewWebKit::GetZoomType() const
764 gboolean fczoom
= webkit_web_view_get_full_content_zoom(
765 WEBKIT_WEB_VIEW(web_view
));
767 if (fczoom
) return wxWEB_VIEW_ZOOM_TYPE_LAYOUT
;
768 else return wxWEB_VIEW_ZOOM_TYPE_TEXT
;
771 bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType
) const
773 // this port supports all zoom types
777 void wxWebViewWebKit::SetPage(const wxString
& html
, const wxString
& baseUri
)
779 webkit_web_view_load_string (WEBKIT_WEB_VIEW(web_view
),
780 html
.mb_str(wxConvUTF8
),
783 baseUri
.mb_str(wxConvUTF8
));
786 void wxWebViewWebKit::Print()
788 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
789 WEBKIT_WEB_VIEW(web_view
));
790 webkit_web_frame_print (frame
);
792 // GtkPrintOperationResult webkit_web_frame_print_full
793 // (WebKitWebFrame *frame,
794 // GtkPrintOperation *operation,
795 // GtkPrintOperationAction action,
801 bool wxWebViewWebKit::IsBusy() const
805 // This code looks nice but returns true after a page was cancelled
807 WebKitLoadStatus status = webkit_web_view_get_load_status
808 (WEBKIT_WEB_VIEW(web_view));
811 #if WEBKIT_CHECK_VERSION(1,1,16)
812 // WEBKIT_LOAD_FAILED is new in webkit 1.1.16
813 if (status == WEBKIT_LOAD_FAILED)
818 if (status == WEBKIT_LOAD_FINISHED)
827 void wxWebViewWebKit::SetEditable(bool enable
)
829 webkit_web_view_set_editable(WEBKIT_WEB_VIEW(web_view
), enable
);
832 bool wxWebViewWebKit::IsEditable() const
834 return webkit_web_view_get_editable(WEBKIT_WEB_VIEW(web_view
));
837 void wxWebViewWebKit::DeleteSelection()
839 webkit_web_view_delete_selection(WEBKIT_WEB_VIEW(web_view
));
842 bool wxWebViewWebKit::HasSelection() const
844 return webkit_web_view_has_selection(WEBKIT_WEB_VIEW(web_view
));
847 void wxWebViewWebKit::SelectAll()
849 webkit_web_view_select_all(WEBKIT_WEB_VIEW(web_view
));
852 wxString
wxWebViewWebKit::GetSelectedText() const
854 WebKitDOMDocument
* doc
;
855 WebKitDOMDOMWindow
* win
;
856 WebKitDOMDOMSelection
* sel
;
857 WebKitDOMRange
* range
;
859 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
860 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
861 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
862 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
864 return wxString(webkit_dom_range_get_text(WEBKIT_DOM_RANGE(range
)),
868 wxString
wxWebViewWebKit::GetSelectedSource() const
870 WebKitDOMDocument
* doc
;
871 WebKitDOMDOMWindow
* win
;
872 WebKitDOMDOMSelection
* sel
;
873 WebKitDOMRange
* range
;
874 WebKitDOMElement
* div
;
875 WebKitDOMDocumentFragment
* clone
;
876 WebKitDOMHTMLElement
* html
;
878 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
879 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
880 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
881 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
883 div
= webkit_dom_document_create_element(WEBKIT_DOM_DOCUMENT(doc
), "div", NULL
);
885 clone
= webkit_dom_range_clone_contents(WEBKIT_DOM_RANGE(range
), NULL
);
886 webkit_dom_node_append_child(&div
->parent_instance
, &clone
->parent_instance
, NULL
);
887 html
= (WebKitDOMHTMLElement
*)div
;
889 return wxString(webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(html
)),
893 void wxWebViewWebKit::ClearSelection()
895 WebKitDOMDocument
* doc
;
896 WebKitDOMDOMWindow
* win
;
897 WebKitDOMDOMSelection
* sel
;
899 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
900 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
901 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
902 webkit_dom_dom_selection_remove_all_ranges(WEBKIT_DOM_DOM_SELECTION(sel
));
906 wxString
wxWebViewWebKit::GetPageText() const
908 WebKitDOMDocument
* doc
;
909 WebKitDOMHTMLElement
* body
;
911 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
912 body
= webkit_dom_document_get_body(WEBKIT_DOM_DOCUMENT(doc
));
913 return wxString(webkit_dom_html_element_get_inner_text(WEBKIT_DOM_HTML_ELEMENT(body
)),
917 void wxWebViewWebKit::RunScript(const wxString
& javascript
)
919 webkit_web_view_execute_script(WEBKIT_WEB_VIEW(web_view
),
920 javascript
.mb_str(wxConvUTF8
));
923 void wxWebViewWebKit::RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
)
925 m_handlerList
.push_back(handler
);
930 wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
932 return GetDefaultAttributesFromGTKWidget(webkit_web_view_new
);
936 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT