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 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
)
53 WebKitWebHistoryItem
* newitem
= webkit_web_history_item_new_with_data(url
, webKitCtrl
->GetCurrentTitle());
54 webkit_web_back_forward_list_add_item(hist
, newitem
);
57 webKitCtrl
->m_busy
= false;
58 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_LOADED
,
62 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
63 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
65 else if (status
== WEBKIT_LOAD_COMMITTED
)
67 webKitCtrl
->m_busy
= true;
68 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
72 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
73 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
78 wxgtk_webview_webkit_navigation(WebKitWebView
*,
79 WebKitWebFrame
*frame
,
80 WebKitNetworkRequest
*request
,
81 WebKitWebNavigationAction
*,
82 WebKitWebPolicyDecision
*policy_decision
,
83 wxWebViewWebKit
*webKitCtrl
)
85 if(webKitCtrl
->m_guard
)
87 webKitCtrl
->m_guard
= false;
88 //We set this to make sure that we don't try to load the page again from
89 //the resource request callback
90 webKitCtrl
->m_vfsurl
= webkit_network_request_get_uri(request
);
91 webkit_web_policy_decision_use(policy_decision
);
95 webKitCtrl
->m_busy
= true;
97 const gchar
* uri
= webkit_network_request_get_uri(request
);
99 wxString target
= webkit_web_frame_get_name (frame
);
100 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
102 wxString( uri
, wxConvUTF8
),
105 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
106 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
108 if (!event
.IsAllowed())
110 webKitCtrl
->m_busy
= false;
111 webkit_web_policy_decision_ignore(policy_decision
);
116 wxString wxuri
= uri
;
117 wxSharedPtr
<wxWebViewHandler
> handler
;
118 wxVector
<wxSharedPtr
<wxWebViewHandler
> > hanlders
= webKitCtrl
->GetHandlers();
119 //We are not vetoed so see if we match one of the additional handlers
120 for(wxVector
<wxSharedPtr
<wxWebViewHandler
> >::iterator it
= hanlders
.begin();
121 it
!= hanlders
.end(); ++it
)
123 if(wxuri
.substr(0, (*it
)->GetName().length()) == (*it
)->GetName())
128 //If we found a handler we can then use it to load the file directly
132 webKitCtrl
->m_guard
= true;
133 wxFSFile
* file
= handler
->GetFile(wxuri
);
136 webKitCtrl
->SetPage(*file
->GetStream(), wxuri
);
138 //We need to throw some sort of error here if file is NULL
139 webkit_web_policy_decision_ignore(policy_decision
);
147 wxgtk_webview_webkit_error(WebKitWebView
*,
151 wxWebViewWebKit
* webKitWindow
)
153 webKitWindow
->m_busy
= false;
154 wxWebViewNavigationError type
= wxWEB_NAV_ERR_OTHER
;
156 GError
* error
= (GError
*)web_error
;
157 wxString
description(error
->message
, wxConvUTF8
);
159 if (strcmp(g_quark_to_string(error
->domain
), "soup_http_error_quark") == 0)
163 case SOUP_STATUS_CANCELLED
:
164 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
167 case SOUP_STATUS_CANT_RESOLVE
:
168 case SOUP_STATUS_NOT_FOUND
:
169 type
= wxWEB_NAV_ERR_NOT_FOUND
;
172 case SOUP_STATUS_CANT_RESOLVE_PROXY
:
173 case SOUP_STATUS_CANT_CONNECT
:
174 case SOUP_STATUS_CANT_CONNECT_PROXY
:
175 case SOUP_STATUS_SSL_FAILED
:
176 case SOUP_STATUS_IO_ERROR
:
177 type
= wxWEB_NAV_ERR_CONNECTION
;
180 case SOUP_STATUS_MALFORMED
:
181 //case SOUP_STATUS_TOO_MANY_REDIRECTS:
182 type
= wxWEB_NAV_ERR_REQUEST
;
185 //case SOUP_STATUS_NO_CONTENT:
186 //case SOUP_STATUS_RESET_CONTENT:
188 case SOUP_STATUS_BAD_REQUEST
:
189 type
= wxWEB_NAV_ERR_REQUEST
;
192 case SOUP_STATUS_UNAUTHORIZED
:
193 case SOUP_STATUS_FORBIDDEN
:
194 type
= wxWEB_NAV_ERR_AUTH
;
197 case SOUP_STATUS_METHOD_NOT_ALLOWED
:
198 case SOUP_STATUS_NOT_ACCEPTABLE
:
199 type
= wxWEB_NAV_ERR_SECURITY
;
202 case SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED
:
203 type
= wxWEB_NAV_ERR_AUTH
;
206 case SOUP_STATUS_REQUEST_TIMEOUT
:
207 type
= wxWEB_NAV_ERR_CONNECTION
;
210 //case SOUP_STATUS_PAYMENT_REQUIRED:
211 case SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE
:
212 case SOUP_STATUS_REQUEST_URI_TOO_LONG
:
213 case SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE
:
214 type
= wxWEB_NAV_ERR_REQUEST
;
217 case SOUP_STATUS_BAD_GATEWAY
:
218 case SOUP_STATUS_SERVICE_UNAVAILABLE
:
219 case SOUP_STATUS_GATEWAY_TIMEOUT
:
220 type
= wxWEB_NAV_ERR_CONNECTION
;
223 case SOUP_STATUS_HTTP_VERSION_NOT_SUPPORTED
:
224 type
= wxWEB_NAV_ERR_REQUEST
;
226 //case SOUP_STATUS_INSUFFICIENT_STORAGE:
227 //case SOUP_STATUS_NOT_EXTENDED:
230 else if (strcmp(g_quark_to_string(error
->domain
),
231 "webkit-network-error-quark") == 0)
235 //WEBKIT_NETWORK_ERROR_FAILED:
236 //WEBKIT_NETWORK_ERROR_TRANSPORT:
238 case WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL
:
239 type
= wxWEB_NAV_ERR_REQUEST
;
242 case WEBKIT_NETWORK_ERROR_CANCELLED
:
243 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
246 case WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST
:
247 type
= wxWEB_NAV_ERR_NOT_FOUND
;
251 else if (strcmp(g_quark_to_string(error
->domain
),
252 "webkit-policy-error-quark") == 0)
256 //case WEBKIT_POLICY_ERROR_FAILED:
257 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_MIME_TYPE:
258 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_URL:
259 //case WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE:
260 case WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT
:
261 type
= wxWEB_NAV_ERR_SECURITY
;
266 webkit_plugin_error_quark
269 printf("Error domain %s\n", g_quark_to_string(error->domain));
273 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_ERROR
,
274 webKitWindow
->GetId(),
276 event
.SetString(description
);
279 if (webKitWindow
&& webKitWindow
->GetEventHandler())
281 webKitWindow
->GetEventHandler()->ProcessEvent(event
);
288 wxgtk_webview_webkit_new_window(WebKitWebView
*,
289 WebKitWebFrame
*frame
,
290 WebKitNetworkRequest
*request
,
291 WebKitWebNavigationAction
*,
292 WebKitWebPolicyDecision
*policy_decision
,
293 wxWebViewWebKit
*webKitCtrl
)
295 const gchar
* uri
= webkit_network_request_get_uri(request
);
297 wxString target
= webkit_web_frame_get_name (frame
);
298 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
300 wxString( uri
, wxConvUTF8
),
303 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
304 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
306 //We always want the user to handle this themselves
307 webkit_web_policy_decision_ignore(policy_decision
);
312 wxgtk_webview_webkit_title_changed(WebKitWebView
*,
315 wxWebViewWebKit
*webKitCtrl
)
317 wxWebViewEvent
event(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
319 webKitCtrl
->GetCurrentURL(),
321 event
.SetString(wxString(title
, wxConvUTF8
));
323 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
324 webKitCtrl
->GetEventHandler()->ProcessEvent(event
);
329 wxgtk_webview_webkit_resource_req(WebKitWebView
*,
332 WebKitNetworkRequest
*request
,
333 WebKitNetworkResponse
*,
334 wxWebViewWebKit
*webKitCtrl
)
336 wxString uri
= webkit_network_request_get_uri(request
);
338 wxSharedPtr
<wxWebViewHandler
> handler
;
339 wxVector
<wxSharedPtr
<wxWebViewHandler
> > hanlders
= webKitCtrl
->GetHandlers();
341 //We are not vetoed so see if we match one of the additional handlers
342 for(wxVector
<wxSharedPtr
<wxWebViewHandler
> >::iterator it
= hanlders
.begin();
343 it
!= hanlders
.end(); ++it
)
345 if(uri
.substr(0, (*it
)->GetName().length()) == (*it
)->GetName())
350 //If we found a handler we can then use it to load the file directly
354 //If it is requsting the page itself then return as we have already
355 //loaded it from the archive
356 if(webKitCtrl
->m_vfsurl
== uri
)
359 wxFSFile
* file
= handler
->GetFile(uri
);
362 //We load the data into a data url to save it being written out again
363 size_t size
= file
->GetStream()->GetLength();
364 char *buffer
= new char[size
];
365 file
->GetStream()->Read(buffer
, size
);
366 wxString data
= wxBase64Encode(buffer
, size
);
368 wxString mime
= file
->GetMimeType();
369 wxString path
= "data:" + mime
+ ";base64," + data
;
370 //Then we can redirect the call
371 webkit_network_request_set_uri(request
, path
);
379 //-----------------------------------------------------------------------------
381 //-----------------------------------------------------------------------------
383 wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewWebKit
, wxWebView
);
385 bool wxWebViewWebKit::Create(wxWindow
*parent
,
391 const wxString
& name
)
397 if (!PreCreation( parent
, pos
, size
) ||
398 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
400 wxFAIL_MSG( wxT("wxWebViewWebKit creation failed") );
404 GtkWidget
*scrolled_window
= gtk_scrolled_window_new (NULL
, NULL
);
405 web_view
= webkit_web_view_new ();
406 g_object_ref(web_view
); // TODO: check memory management
408 m_widget
= scrolled_window
;
409 g_object_ref(m_widget
); // TODO: check memory management
411 /* Place the WebKitWebView in the GtkScrolledWindow */
412 gtk_container_add (GTK_CONTAINER (scrolled_window
), web_view
);
413 gtk_widget_show(m_widget
);
414 gtk_widget_show(web_view
);
416 g_signal_connect_after(web_view
, "notify::load-status",
417 G_CALLBACK(wxgtk_webview_webkit_load_status
),
419 g_signal_connect_after(web_view
, "navigation-policy-decision-requested",
420 G_CALLBACK(wxgtk_webview_webkit_navigation
),
422 g_signal_connect_after(web_view
, "load-error",
423 G_CALLBACK(wxgtk_webview_webkit_error
),
426 g_signal_connect_after(web_view
, "new-window-policy-decision-requested",
427 G_CALLBACK(wxgtk_webview_webkit_new_window
), this);
429 g_signal_connect_after(web_view
, "title-changed",
430 G_CALLBACK(wxgtk_webview_webkit_title_changed
), this);
432 g_signal_connect_after(web_view
, "resource-request-starting",
433 G_CALLBACK(wxgtk_webview_webkit_resource_req
), this);
435 m_parent
->DoAddChild( this );
440 webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view
), url
);
442 //Get the initial history limit so we can enable and disable it later
443 WebKitWebBackForwardList
* history
;
444 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
445 m_historyLimit
= webkit_web_back_forward_list_get_limit(history
);
452 bool wxWebViewWebKit::Enable( bool enable
)
454 if (!wxControl::Enable(enable
))
457 gtk_widget_set_sensitive(GTK_BIN(m_widget
)->child
, enable
);
460 // GTKFixSensitivity();
466 wxWebViewWebKit::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
468 GdkWindow
* window
= gtk_widget_get_parent_window(m_widget
);
472 void wxWebViewWebKit::ZoomIn()
474 webkit_web_view_zoom_in (WEBKIT_WEB_VIEW(web_view
));
477 void wxWebViewWebKit::ZoomOut()
479 webkit_web_view_zoom_out (WEBKIT_WEB_VIEW(web_view
));
482 void wxWebViewWebKit::SetWebkitZoom(float level
)
484 webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW(web_view
), level
);
487 float wxWebViewWebKit::GetWebkitZoom() const
489 return webkit_web_view_get_zoom_level (WEBKIT_WEB_VIEW(web_view
));
492 void wxWebViewWebKit::Stop()
494 webkit_web_view_stop_loading (WEBKIT_WEB_VIEW(web_view
));
497 void wxWebViewWebKit::Reload(wxWebViewReloadFlags flags
)
499 if (flags
& wxWEB_VIEW_RELOAD_NO_CACHE
)
501 webkit_web_view_reload_bypass_cache (WEBKIT_WEB_VIEW(web_view
));
505 webkit_web_view_reload (WEBKIT_WEB_VIEW(web_view
));
509 void wxWebViewWebKit::LoadURL(const wxString
& url
)
511 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view
), wxGTK_CONV(url
));
515 void wxWebViewWebKit::GoBack()
517 webkit_web_view_go_back (WEBKIT_WEB_VIEW(web_view
));
520 void wxWebViewWebKit::GoForward()
522 webkit_web_view_go_forward (WEBKIT_WEB_VIEW(web_view
));
526 bool wxWebViewWebKit::CanGoBack() const
528 return webkit_web_view_can_go_back (WEBKIT_WEB_VIEW(web_view
));
532 bool wxWebViewWebKit::CanGoForward() const
534 return webkit_web_view_can_go_forward (WEBKIT_WEB_VIEW(web_view
));
537 void wxWebViewWebKit::ClearHistory()
539 WebKitWebBackForwardList
* history
;
540 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
541 webkit_web_back_forward_list_clear(history
);
544 void wxWebViewWebKit::EnableHistory(bool enable
)
546 WebKitWebBackForwardList
* history
;
547 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
550 webkit_web_back_forward_list_set_limit(history
, m_historyLimit
);
554 webkit_web_back_forward_list_set_limit(history
, 0);
558 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewWebKit::GetBackwardHistory()
560 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > backhist
;
561 WebKitWebBackForwardList
* history
;
562 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
563 GList
* list
= webkit_web_back_forward_list_get_back_list_with_limit(history
,
565 //We need to iterate in reverse to get the order we desire
566 for(int i
= g_list_length(list
) - 1; i
>= 0 ; i
--)
568 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
569 wxWebViewHistoryItem
* wxitem
= new wxWebViewHistoryItem(
570 webkit_web_history_item_get_uri(gtkitem
),
571 webkit_web_history_item_get_title(gtkitem
));
572 wxitem
->m_histItem
= gtkitem
;
573 wxSharedPtr
<wxWebViewHistoryItem
> item(wxitem
);
574 backhist
.push_back(item
);
579 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > wxWebViewWebKit::GetForwardHistory()
581 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > forwardhist
;
582 WebKitWebBackForwardList
* history
;
583 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
584 GList
* list
= webkit_web_back_forward_list_get_forward_list_with_limit(history
,
586 for(guint i
= 0; i
< g_list_length(list
); i
++)
588 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
589 wxWebViewHistoryItem
* wxitem
= new wxWebViewHistoryItem(
590 webkit_web_history_item_get_uri(gtkitem
),
591 webkit_web_history_item_get_title(gtkitem
));
592 wxitem
->m_histItem
= gtkitem
;
593 wxSharedPtr
<wxWebViewHistoryItem
> item(wxitem
);
594 forwardhist
.push_back(item
);
599 void wxWebViewWebKit::LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
)
601 WebKitWebHistoryItem
* gtkitem
= item
->m_histItem
;
604 WebKitWebBackForwardList
* history
;
605 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
606 webkit_web_view_go_to_back_forward_item(WEBKIT_WEB_VIEW(web_view
),
607 WEBKIT_WEB_HISTORY_ITEM(gtkitem
));
611 bool wxWebViewWebKit::CanCut() const
613 return webkit_web_view_can_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
616 bool wxWebViewWebKit::CanCopy() const
618 return webkit_web_view_can_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
621 bool wxWebViewWebKit::CanPaste() const
623 return webkit_web_view_can_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
626 void wxWebViewWebKit::Cut()
628 webkit_web_view_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
631 void wxWebViewWebKit::Copy()
633 webkit_web_view_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
636 void wxWebViewWebKit::Paste()
638 webkit_web_view_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
641 bool wxWebViewWebKit::CanUndo() const
643 return webkit_web_view_can_undo(WEBKIT_WEB_VIEW(web_view
));
646 bool wxWebViewWebKit::CanRedo() const
648 return webkit_web_view_can_redo(WEBKIT_WEB_VIEW(web_view
));
651 void wxWebViewWebKit::Undo()
653 webkit_web_view_undo(WEBKIT_WEB_VIEW(web_view
));
656 void wxWebViewWebKit::Redo()
658 webkit_web_view_redo(WEBKIT_WEB_VIEW(web_view
));
661 wxString
wxWebViewWebKit::GetCurrentURL() const
663 // FIXME: check which encoding the web kit control uses instead of
664 // assuming UTF8 (here and elsewhere too)
665 return wxString::FromUTF8(webkit_web_view_get_uri(
666 WEBKIT_WEB_VIEW(web_view
)));
670 wxString
wxWebViewWebKit::GetCurrentTitle() const
672 return wxString::FromUTF8(webkit_web_view_get_title(
673 WEBKIT_WEB_VIEW(web_view
)));
677 wxString
wxWebViewWebKit::GetPageSource() const
679 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
680 WEBKIT_WEB_VIEW(web_view
));
681 WebKitWebDataSource
* src
= webkit_web_frame_get_data_source (frame
);
683 // TODO: check encoding with
685 // webkit_web_data_source_get_encoding(WebKitWebDataSource *data_source);
686 return wxString(webkit_web_data_source_get_data (src
)->str
, wxConvUTF8
);
690 wxWebViewZoom
wxWebViewWebKit::GetZoom() const
692 float zoom
= GetWebkitZoom();
694 // arbitrary way to map float zoom to our common zoom enum
697 return wxWEB_VIEW_ZOOM_TINY
;
699 else if (zoom
> 0.65 && zoom
<= 0.90)
701 return wxWEB_VIEW_ZOOM_SMALL
;
703 else if (zoom
> 0.90 && zoom
<= 1.15)
705 return wxWEB_VIEW_ZOOM_MEDIUM
;
707 else if (zoom
> 1.15 && zoom
<= 1.45)
709 return wxWEB_VIEW_ZOOM_LARGE
;
711 else if (zoom
> 1.45)
713 return wxWEB_VIEW_ZOOM_LARGEST
;
716 // to shut up compilers, this can never be reached logically
718 return wxWEB_VIEW_ZOOM_MEDIUM
;
722 void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom
)
724 // arbitrary way to map our common zoom enum to float zoom
727 case wxWEB_VIEW_ZOOM_TINY
:
731 case wxWEB_VIEW_ZOOM_SMALL
:
735 case wxWEB_VIEW_ZOOM_MEDIUM
:
739 case wxWEB_VIEW_ZOOM_LARGE
:
743 case wxWEB_VIEW_ZOOM_LARGEST
:
752 void wxWebViewWebKit::SetZoomType(wxWebViewZoomType type
)
754 webkit_web_view_set_full_content_zoom(WEBKIT_WEB_VIEW(web_view
),
755 (type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
?
759 wxWebViewZoomType
wxWebViewWebKit::GetZoomType() const
761 gboolean fczoom
= webkit_web_view_get_full_content_zoom(
762 WEBKIT_WEB_VIEW(web_view
));
764 if (fczoom
) return wxWEB_VIEW_ZOOM_TYPE_LAYOUT
;
765 else return wxWEB_VIEW_ZOOM_TYPE_TEXT
;
768 bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType
) const
770 // this port supports all zoom types
774 void wxWebViewWebKit::SetPage(const wxString
& html
, const wxString
& baseUri
)
776 webkit_web_view_load_string (WEBKIT_WEB_VIEW(web_view
),
777 html
.mb_str(wxConvUTF8
),
780 baseUri
.mb_str(wxConvUTF8
));
783 void wxWebViewWebKit::Print()
785 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
786 WEBKIT_WEB_VIEW(web_view
));
787 webkit_web_frame_print (frame
);
789 // GtkPrintOperationResult webkit_web_frame_print_full
790 // (WebKitWebFrame *frame,
791 // GtkPrintOperation *operation,
792 // GtkPrintOperationAction action,
798 bool wxWebViewWebKit::IsBusy() const
802 // This code looks nice but returns true after a page was cancelled
804 WebKitLoadStatus status = webkit_web_view_get_load_status
805 (WEBKIT_WEB_VIEW(web_view));
808 #if WEBKIT_CHECK_VERSION(1,1,16)
809 // WEBKIT_LOAD_FAILED is new in webkit 1.1.16
810 if (status == WEBKIT_LOAD_FAILED)
815 if (status == WEBKIT_LOAD_FINISHED)
824 void wxWebViewWebKit::SetEditable(bool enable
)
826 webkit_web_view_set_editable(WEBKIT_WEB_VIEW(web_view
), enable
);
829 bool wxWebViewWebKit::IsEditable() const
831 return webkit_web_view_get_editable(WEBKIT_WEB_VIEW(web_view
));
834 void wxWebViewWebKit::DeleteSelection()
836 webkit_web_view_delete_selection(WEBKIT_WEB_VIEW(web_view
));
839 bool wxWebViewWebKit::HasSelection() const
841 return webkit_web_view_has_selection(WEBKIT_WEB_VIEW(web_view
));
844 void wxWebViewWebKit::SelectAll()
846 webkit_web_view_select_all(WEBKIT_WEB_VIEW(web_view
));
849 wxString
wxWebViewWebKit::GetSelectedText() const
851 WebKitDOMDocument
* doc
;
852 WebKitDOMDOMWindow
* win
;
853 WebKitDOMDOMSelection
* sel
;
854 WebKitDOMRange
* range
;
856 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
857 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
858 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
859 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
861 return wxString(webkit_dom_range_get_text(WEBKIT_DOM_RANGE(range
)),
865 wxString
wxWebViewWebKit::GetSelectedSource() const
867 WebKitDOMDocument
* doc
;
868 WebKitDOMDOMWindow
* win
;
869 WebKitDOMDOMSelection
* sel
;
870 WebKitDOMRange
* range
;
871 WebKitDOMElement
* div
;
872 WebKitDOMDocumentFragment
* clone
;
873 WebKitDOMHTMLElement
* html
;
875 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
876 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
877 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
878 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
880 div
= webkit_dom_document_create_element(WEBKIT_DOM_DOCUMENT(doc
), "div", NULL
);
882 clone
= webkit_dom_range_clone_contents(WEBKIT_DOM_RANGE(range
), NULL
);
883 webkit_dom_node_append_child(&div
->parent_instance
, &clone
->parent_instance
, NULL
);
884 html
= (WebKitDOMHTMLElement
*)div
;
886 return wxString(webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(html
)),
890 void wxWebViewWebKit::ClearSelection()
892 WebKitDOMDocument
* doc
;
893 WebKitDOMDOMWindow
* win
;
894 WebKitDOMDOMSelection
* sel
;
896 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
897 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
898 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
899 webkit_dom_dom_selection_remove_all_ranges(WEBKIT_DOM_DOM_SELECTION(sel
));
903 wxString
wxWebViewWebKit::GetPageText() const
905 WebKitDOMDocument
* doc
;
906 WebKitDOMHTMLElement
* body
;
908 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
909 body
= webkit_dom_document_get_body(WEBKIT_DOM_DOCUMENT(doc
));
910 return wxString(webkit_dom_html_element_get_inner_text(WEBKIT_DOM_HTML_ELEMENT(body
)),
914 void wxWebViewWebKit::RunScript(const wxString
& javascript
)
916 webkit_web_view_execute_script(WEBKIT_WEB_VIEW(web_view
),
917 javascript
.mb_str(wxConvUTF8
));
920 void wxWebViewWebKit::RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
)
922 m_handlerList
.push_back(handler
);
927 wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
929 return GetDefaultAttributesFromGTKWidget(webkit_web_view_new
);
933 #endif // wxHAVE_WEB_BACKEND_GTK_WEBKIT