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
*view
,
67 WebKitWebFrame
*frame
,
68 WebKitNetworkRequest
*request
,
69 WebKitWebNavigationAction
*,
70 WebKitWebPolicyDecision
*policy_decision
,
71 wxWebViewWebKit
*webKitCtrl
)
73 webKitCtrl
->m_busy
= true;
75 const gchar
* uri
= webkit_network_request_get_uri(request
);
77 wxString target
= webkit_web_frame_get_name (frame
);
78 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
80 wxString( uri
, wxConvUTF8
),
84 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
85 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
87 if (thisEvent
.IsVetoed())
89 webKitCtrl
->m_busy
= false;
90 webkit_web_policy_decision_ignore(policy_decision
);
96 wxWebHandler
*handler
= NULL
;
97 wxVector
<wxWebHandler
*> hanlders
= webKitCtrl
->GetHandlers();
98 //We are not vetoed so see if we match one of the additional handlers
99 for(wxVector
<wxWebHandler
*>::iterator it
= hanlders
.begin();
100 it
!= hanlders
.end(); ++it
)
102 if(wxuri
.substr(0, (*it
)->GetName().length()) == (*it
)->GetName())
107 //If we found a handler we can then use it to load the file directly
111 wxFSFile
* file
= handler
->GetFile(wxuri
);
112 g_signal_handlers_block_by_func(view
,
113 (gpointer
)wxgtk_webview_webkit_navigation
,
115 webKitCtrl
->SetPage(*file
->GetStream(), wxuri
);
116 g_signal_handlers_unblock_by_func(view
,
117 (gpointer
)wxgtk_webview_webkit_navigation
,
125 wxgtk_webview_webkit_error(WebKitWebView
*,
129 wxWebViewWebKit
* webKitWindow
)
131 webKitWindow
->m_busy
= false;
132 wxWebNavigationError type
= wxWEB_NAV_ERR_OTHER
;
134 GError
* error
= (GError
*)web_error
;
135 wxString
description(error
->message
, wxConvUTF8
);
137 if (strcmp(g_quark_to_string(error
->domain
), "soup_http_error_quark") == 0)
141 case SOUP_STATUS_CANCELLED
:
142 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
145 case SOUP_STATUS_CANT_RESOLVE
:
146 case SOUP_STATUS_NOT_FOUND
:
147 type
= wxWEB_NAV_ERR_NOT_FOUND
;
150 case SOUP_STATUS_CANT_RESOLVE_PROXY
:
151 case SOUP_STATUS_CANT_CONNECT
:
152 case SOUP_STATUS_CANT_CONNECT_PROXY
:
153 case SOUP_STATUS_SSL_FAILED
:
154 case SOUP_STATUS_IO_ERROR
:
155 type
= wxWEB_NAV_ERR_CONNECTION
;
158 case SOUP_STATUS_MALFORMED
:
159 //case SOUP_STATUS_TOO_MANY_REDIRECTS:
160 type
= wxWEB_NAV_ERR_REQUEST
;
163 //case SOUP_STATUS_NO_CONTENT:
164 //case SOUP_STATUS_RESET_CONTENT:
166 case SOUP_STATUS_BAD_REQUEST
:
167 type
= wxWEB_NAV_ERR_REQUEST
;
170 case SOUP_STATUS_UNAUTHORIZED
:
171 case SOUP_STATUS_FORBIDDEN
:
172 type
= wxWEB_NAV_ERR_AUTH
;
175 case SOUP_STATUS_METHOD_NOT_ALLOWED
:
176 case SOUP_STATUS_NOT_ACCEPTABLE
:
177 type
= wxWEB_NAV_ERR_SECURITY
;
180 case SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED
:
181 type
= wxWEB_NAV_ERR_AUTH
;
184 case SOUP_STATUS_REQUEST_TIMEOUT
:
185 type
= wxWEB_NAV_ERR_CONNECTION
;
188 //case SOUP_STATUS_PAYMENT_REQUIRED:
189 case SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE
:
190 case SOUP_STATUS_REQUEST_URI_TOO_LONG
:
191 case SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE
:
192 type
= wxWEB_NAV_ERR_REQUEST
;
195 case SOUP_STATUS_BAD_GATEWAY
:
196 case SOUP_STATUS_SERVICE_UNAVAILABLE
:
197 case SOUP_STATUS_GATEWAY_TIMEOUT
:
198 type
= wxWEB_NAV_ERR_CONNECTION
;
201 case SOUP_STATUS_HTTP_VERSION_NOT_SUPPORTED
:
202 type
= wxWEB_NAV_ERR_REQUEST
;
204 //case SOUP_STATUS_INSUFFICIENT_STORAGE:
205 //case SOUP_STATUS_NOT_EXTENDED:
208 else if (strcmp(g_quark_to_string(error
->domain
),
209 "webkit-network-error-quark") == 0)
213 //WEBKIT_NETWORK_ERROR_FAILED:
214 //WEBKIT_NETWORK_ERROR_TRANSPORT:
216 case WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL
:
217 type
= wxWEB_NAV_ERR_REQUEST
;
220 case WEBKIT_NETWORK_ERROR_CANCELLED
:
221 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
224 case WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST
:
225 type
= wxWEB_NAV_ERR_NOT_FOUND
;
229 else if (strcmp(g_quark_to_string(error
->domain
),
230 "webkit-policy-error-quark") == 0)
234 //case WEBKIT_POLICY_ERROR_FAILED:
235 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_MIME_TYPE:
236 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_URL:
237 //case WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE:
238 case WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT
:
239 type
= wxWEB_NAV_ERR_SECURITY
;
244 webkit_plugin_error_quark
247 printf("Error domain %s\n", g_quark_to_string(error->domain));
251 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_ERROR
,
252 webKitWindow
->GetId(),
256 thisEvent
.SetString(description
);
257 thisEvent
.SetInt(type
);
259 if (webKitWindow
&& webKitWindow
->GetEventHandler())
261 webKitWindow
->GetEventHandler()->ProcessEvent(thisEvent
);
268 wxgtk_webview_webkit_new_window(WebKitWebView
*,
269 WebKitWebFrame
*frame
,
270 WebKitNetworkRequest
*request
,
271 WebKitWebNavigationAction
*,
272 WebKitWebPolicyDecision
*policy_decision
,
273 wxWebViewWebKit
*webKitCtrl
)
275 const gchar
* uri
= webkit_network_request_get_uri(request
);
277 wxString target
= webkit_web_frame_get_name (frame
);
278 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
280 wxString( uri
, wxConvUTF8
),
284 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
285 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
287 //We always want the user to handle this themselves
288 webkit_web_policy_decision_ignore(policy_decision
);
293 wxgtk_webview_webkit_title_changed(WebKitWebView
*,
296 wxWebViewWebKit
*webKitCtrl
)
298 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
300 webKitCtrl
->GetCurrentURL(),
303 thisEvent
.SetString(wxString(title
, wxConvUTF8
));
305 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
306 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
312 //-----------------------------------------------------------------------------
314 //-----------------------------------------------------------------------------
316 wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewWebKit
, wxWebView
);
318 bool wxWebViewWebKit::Create(wxWindow
*parent
,
324 const wxString
& name
)
329 if (!PreCreation( parent
, pos
, size
) ||
330 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
332 wxFAIL_MSG( wxT("wxWebViewWebKit creation failed") );
336 GtkWidget
*scrolled_window
= gtk_scrolled_window_new (NULL
, NULL
);
337 web_view
= webkit_web_view_new ();
338 g_object_ref(web_view
); // TODO: check memory management
340 m_widget
= scrolled_window
;
341 g_object_ref(m_widget
); // TODO: check memory management
343 /* Place the WebKitWebView in the GtkScrolledWindow */
344 gtk_container_add (GTK_CONTAINER (scrolled_window
), web_view
);
345 gtk_widget_show(m_widget
);
346 gtk_widget_show(web_view
);
348 g_signal_connect_after(web_view
, "notify::load-status",
349 G_CALLBACK(wxgtk_webview_webkit_load_status
),
351 g_signal_connect_after(web_view
, "navigation-policy-decision-requested",
352 G_CALLBACK(wxgtk_webview_webkit_navigation
),
354 g_signal_connect_after(web_view
, "load-error",
355 G_CALLBACK(wxgtk_webview_webkit_error
),
358 g_signal_connect_after(web_view
, "new-window-policy-decision-requested",
359 G_CALLBACK(wxgtk_webview_webkit_new_window
), this);
361 g_signal_connect_after(web_view
, "title-changed",
362 G_CALLBACK(wxgtk_webview_webkit_title_changed
), this);
364 m_parent
->DoAddChild( this );
369 webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view
), url
);
371 //Get the initial history limit so we can enable and disable it later
372 WebKitWebBackForwardList
* history
;
373 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
374 m_historyLimit
= webkit_web_back_forward_list_get_limit(history
);
381 bool wxWebViewWebKit::Enable( bool enable
)
383 if (!wxControl::Enable(enable
))
386 gtk_widget_set_sensitive(GTK_BIN(m_widget
)->child
, enable
);
389 // GTKFixSensitivity();
395 wxWebViewWebKit::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
397 GdkWindow
* window
= gtk_widget_get_parent_window(m_widget
);
401 void wxWebViewWebKit::ZoomIn()
403 webkit_web_view_zoom_in (WEBKIT_WEB_VIEW(web_view
));
406 void wxWebViewWebKit::ZoomOut()
408 webkit_web_view_zoom_out (WEBKIT_WEB_VIEW(web_view
));
411 void wxWebViewWebKit::SetWebkitZoom(float level
)
413 webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW(web_view
), level
);
416 float wxWebViewWebKit::GetWebkitZoom()
418 return webkit_web_view_get_zoom_level (WEBKIT_WEB_VIEW(web_view
));
421 void wxWebViewWebKit::Stop()
423 webkit_web_view_stop_loading (WEBKIT_WEB_VIEW(web_view
));
426 void wxWebViewWebKit::Reload(wxWebViewReloadFlags flags
)
428 if (flags
& wxWEB_VIEW_RELOAD_NO_CACHE
)
430 webkit_web_view_reload_bypass_cache (WEBKIT_WEB_VIEW(web_view
));
434 webkit_web_view_reload (WEBKIT_WEB_VIEW(web_view
));
438 void wxWebViewWebKit::LoadUrl(const wxString
& url
)
440 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view
), wxGTK_CONV(url
));
444 void wxWebViewWebKit::GoBack()
446 webkit_web_view_go_back (WEBKIT_WEB_VIEW(web_view
));
449 void wxWebViewWebKit::GoForward()
451 webkit_web_view_go_forward (WEBKIT_WEB_VIEW(web_view
));
455 bool wxWebViewWebKit::CanGoBack()
457 return webkit_web_view_can_go_back (WEBKIT_WEB_VIEW(web_view
));
461 bool wxWebViewWebKit::CanGoForward()
463 return webkit_web_view_can_go_forward (WEBKIT_WEB_VIEW(web_view
));
466 void wxWebViewWebKit::ClearHistory()
468 WebKitWebBackForwardList
* history
;
469 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
470 webkit_web_back_forward_list_clear(history
);
473 void wxWebViewWebKit::EnableHistory(bool enable
)
475 WebKitWebBackForwardList
* history
;
476 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
479 webkit_web_back_forward_list_set_limit(history
, m_historyLimit
);
483 webkit_web_back_forward_list_set_limit(history
, 0);
487 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewWebKit::GetBackwardHistory()
489 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > backhist
;
490 WebKitWebBackForwardList
* history
;
491 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
492 GList
* list
= webkit_web_back_forward_list_get_back_list_with_limit(history
,
494 //We need to iterate in reverse to get the order we desire
495 for(int i
= g_list_length(list
) - 1; i
>= 0 ; i
--)
497 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
498 wxWebHistoryItem
* wxitem
= new wxWebHistoryItem(
499 webkit_web_history_item_get_uri(gtkitem
),
500 webkit_web_history_item_get_title(gtkitem
));
501 wxitem
->m_histItem
= gtkitem
;
502 wxSharedPtr
<wxWebHistoryItem
> item(wxitem
);
503 backhist
.push_back(item
);
508 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewWebKit::GetForwardHistory()
510 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > forwardhist
;
511 WebKitWebBackForwardList
* history
;
512 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
513 GList
* list
= webkit_web_back_forward_list_get_forward_list_with_limit(history
,
515 for(guint i
= 0; i
< g_list_length(list
); i
++)
517 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
518 wxWebHistoryItem
* wxitem
= new wxWebHistoryItem(
519 webkit_web_history_item_get_uri(gtkitem
),
520 webkit_web_history_item_get_title(gtkitem
));
521 wxitem
->m_histItem
= gtkitem
;
522 wxSharedPtr
<wxWebHistoryItem
> item(wxitem
);
523 forwardhist
.push_back(item
);
528 void wxWebViewWebKit::LoadHistoryItem(wxSharedPtr
<wxWebHistoryItem
> item
)
530 WebKitWebHistoryItem
* gtkitem
= item
->m_histItem
;
533 WebKitWebBackForwardList
* history
;
534 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
535 webkit_web_back_forward_list_go_to_item(WEBKIT_WEB_BACK_FORWARD_LIST(history
),
536 WEBKIT_WEB_HISTORY_ITEM(gtkitem
));
540 bool wxWebViewWebKit::CanCut()
542 return webkit_web_view_can_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
545 bool wxWebViewWebKit::CanCopy()
547 return webkit_web_view_can_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
550 bool wxWebViewWebKit::CanPaste()
552 return webkit_web_view_can_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
555 void wxWebViewWebKit::Cut()
557 webkit_web_view_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
560 void wxWebViewWebKit::Copy()
562 webkit_web_view_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
565 void wxWebViewWebKit::Paste()
567 webkit_web_view_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
570 bool wxWebViewWebKit::CanUndo()
572 return webkit_web_view_can_undo(WEBKIT_WEB_VIEW(web_view
));
575 bool wxWebViewWebKit::CanRedo()
577 return webkit_web_view_can_redo(WEBKIT_WEB_VIEW(web_view
));
580 void wxWebViewWebKit::Undo()
582 webkit_web_view_undo(WEBKIT_WEB_VIEW(web_view
));
585 void wxWebViewWebKit::Redo()
587 webkit_web_view_redo(WEBKIT_WEB_VIEW(web_view
));
590 wxString
wxWebViewWebKit::GetCurrentURL()
592 // FIXME: check which encoding the web kit control uses instead of
593 // assuming UTF8 (here and elsewhere too)
594 return wxString::FromUTF8(webkit_web_view_get_uri(
595 WEBKIT_WEB_VIEW(web_view
)));
599 wxString
wxWebViewWebKit::GetCurrentTitle()
601 return wxString::FromUTF8(webkit_web_view_get_title(
602 WEBKIT_WEB_VIEW(web_view
)));
606 wxString
wxWebViewWebKit::GetPageSource()
608 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
609 WEBKIT_WEB_VIEW(web_view
));
610 WebKitWebDataSource
* src
= webkit_web_frame_get_data_source (frame
);
612 // TODO: check encoding with
614 // webkit_web_data_source_get_encoding(WebKitWebDataSource *data_source);
615 return wxString(webkit_web_data_source_get_data (src
)->str
, wxConvUTF8
);
619 wxWebViewZoom
wxWebViewWebKit::GetZoom()
621 float zoom
= GetWebkitZoom();
623 // arbitrary way to map float zoom to our common zoom enum
626 return wxWEB_VIEW_ZOOM_TINY
;
628 else if (zoom
> 0.65 && zoom
<= 0.90)
630 return wxWEB_VIEW_ZOOM_SMALL
;
632 else if (zoom
> 0.90 && zoom
<= 1.15)
634 return wxWEB_VIEW_ZOOM_MEDIUM
;
636 else if (zoom
> 1.15 && zoom
<= 1.45)
638 return wxWEB_VIEW_ZOOM_LARGE
;
640 else if (zoom
> 1.45)
642 return wxWEB_VIEW_ZOOM_LARGEST
;
645 // to shut up compilers, this can never be reached logically
647 return wxWEB_VIEW_ZOOM_MEDIUM
;
651 void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom
)
653 // arbitrary way to map our common zoom enum to float zoom
656 case wxWEB_VIEW_ZOOM_TINY
:
660 case wxWEB_VIEW_ZOOM_SMALL
:
664 case wxWEB_VIEW_ZOOM_MEDIUM
:
668 case wxWEB_VIEW_ZOOM_LARGE
:
672 case wxWEB_VIEW_ZOOM_LARGEST
:
681 void wxWebViewWebKit::SetZoomType(wxWebViewZoomType type
)
683 webkit_web_view_set_full_content_zoom(WEBKIT_WEB_VIEW(web_view
),
684 (type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
?
688 wxWebViewZoomType
wxWebViewWebKit::GetZoomType() const
690 gboolean fczoom
= webkit_web_view_get_full_content_zoom(
691 WEBKIT_WEB_VIEW(web_view
));
693 if (fczoom
) return wxWEB_VIEW_ZOOM_TYPE_LAYOUT
;
694 else return wxWEB_VIEW_ZOOM_TYPE_TEXT
;
697 bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType
) const
699 // this port supports all zoom types
703 void wxWebViewWebKit::SetPage(const wxString
& html
, const wxString
& baseUri
)
705 webkit_web_view_load_string (WEBKIT_WEB_VIEW(web_view
),
706 html
.mb_str(wxConvUTF8
),
709 baseUri
.mb_str(wxConvUTF8
));
712 void wxWebViewWebKit::Print()
714 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
715 WEBKIT_WEB_VIEW(web_view
));
716 webkit_web_frame_print (frame
);
718 // GtkPrintOperationResult webkit_web_frame_print_full
719 // (WebKitWebFrame *frame,
720 // GtkPrintOperation *operation,
721 // GtkPrintOperationAction action,
727 bool wxWebViewWebKit::IsBusy()
731 // This code looks nice but returns true after a page was cancelled
733 WebKitLoadStatus status = webkit_web_view_get_load_status
734 (WEBKIT_WEB_VIEW(web_view));
737 #if WEBKIT_CHECK_VERSION(1,1,16)
738 // WEBKIT_LOAD_FAILED is new in webkit 1.1.16
739 if (status == WEBKIT_LOAD_FAILED)
744 if (status == WEBKIT_LOAD_FINISHED)
753 void wxWebViewWebKit::SetEditable(bool enable
)
755 webkit_web_view_set_editable(WEBKIT_WEB_VIEW(web_view
), enable
);
758 bool wxWebViewWebKit::IsEditable()
760 return webkit_web_view_get_editable(WEBKIT_WEB_VIEW(web_view
));
763 void wxWebViewWebKit::DeleteSelection()
765 webkit_web_view_delete_selection(WEBKIT_WEB_VIEW(web_view
));
768 bool wxWebViewWebKit::HasSelection()
770 return webkit_web_view_has_selection(WEBKIT_WEB_VIEW(web_view
));
773 void wxWebViewWebKit::SelectAll()
775 webkit_web_view_select_all(WEBKIT_WEB_VIEW(web_view
));
778 wxString
wxWebViewWebKit::GetSelectedText()
780 WebKitDOMDocument
* doc
;
781 WebKitDOMDOMWindow
* win
;
782 WebKitDOMDOMSelection
* sel
;
783 WebKitDOMRange
* range
;
785 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
786 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
787 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
788 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
790 return wxString(webkit_dom_range_get_text(WEBKIT_DOM_RANGE(range
)),
794 wxString
wxWebViewWebKit::GetSelectedSource()
796 WebKitDOMDocument
* doc
;
797 WebKitDOMDOMWindow
* win
;
798 WebKitDOMDOMSelection
* sel
;
799 WebKitDOMRange
* range
;
800 WebKitDOMElement
* div
;
801 WebKitDOMDocumentFragment
* clone
;
802 WebKitDOMHTMLElement
* html
;
804 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
805 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
806 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
807 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
809 div
= webkit_dom_document_create_element(WEBKIT_DOM_DOCUMENT(doc
), "div", NULL
);
811 clone
= webkit_dom_range_clone_contents(WEBKIT_DOM_RANGE(range
), NULL
);
812 webkit_dom_node_append_child(&div
->parent_instance
, &clone
->parent_instance
, NULL
);
813 html
= (WebKitDOMHTMLElement
*)div
;
815 return wxString(webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(html
)),
819 void wxWebViewWebKit::ClearSelection()
821 WebKitDOMDocument
* doc
;
822 WebKitDOMDOMWindow
* win
;
823 WebKitDOMDOMSelection
* sel
;
825 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
826 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
827 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
828 webkit_dom_dom_selection_remove_all_ranges(WEBKIT_DOM_DOM_SELECTION(sel
));
832 wxString
wxWebViewWebKit::GetPageText()
834 WebKitDOMDocument
* doc
;
835 WebKitDOMHTMLElement
* body
;
837 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
838 body
= webkit_dom_document_get_body(WEBKIT_DOM_DOCUMENT(doc
));
839 return wxString(webkit_dom_html_element_get_inner_text(WEBKIT_DOM_HTML_ELEMENT(body
)),
843 void wxWebViewWebKit::RunScript(const wxString
& javascript
)
845 webkit_web_view_execute_script(WEBKIT_WEB_VIEW(web_view
),
846 javascript
.mb_str(wxConvUTF8
));
849 void wxWebViewWebKit::RegisterHandler(wxWebHandler
* handler
)
851 m_handlerList
.push_back(handler
);
856 wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
858 return GetDefaultAttributesFromGTKWidget(webkit_web_view_new
);
862 #endif // wxHAVE_WEB_BACKEND_GTK_WEBKIT