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 "webkit/webkit.h"
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
29 wxgtk_webview_webkit_load_status(GtkWidget
* widget
,
31 wxWebViewWebKit
*webKitCtrl
)
33 if (!webKitCtrl
->m_ready
) return;
35 wxString url
= webKitCtrl
->GetCurrentURL();
37 WebKitLoadStatus status
;
38 g_object_get(G_OBJECT(widget
), "load-status", &status
, NULL
);
40 wxString target
; // TODO: get target (if possible)
42 if (status
== WEBKIT_LOAD_FINISHED
)
44 webKitCtrl
->m_busy
= false;
45 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_LOADED
,
49 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
50 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
52 else if (status
== WEBKIT_LOAD_COMMITTED
)
54 webKitCtrl
->m_busy
= true;
55 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
59 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
60 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
65 wxgtk_webview_webkit_navigation(WebKitWebView
*,
66 WebKitWebFrame
*frame
,
67 WebKitNetworkRequest
*request
,
68 WebKitWebNavigationAction
*,
69 WebKitWebPolicyDecision
*policy_decision
,
70 wxWebViewWebKit
*webKitCtrl
)
72 webKitCtrl
->m_busy
= true;
74 const gchar
* uri
= webkit_network_request_get_uri(request
);
76 wxString target
= webkit_web_frame_get_name (frame
);
77 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
79 wxString( uri
, wxConvUTF8
),
83 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
84 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
86 if (thisEvent
.IsVetoed())
88 webKitCtrl
->m_busy
= false;
89 webkit_web_policy_decision_ignore(policy_decision
);
99 wxgtk_webview_webkit_error(WebKitWebView
*,
103 wxWebViewWebKit
* webKitWindow
)
105 webKitWindow
->m_busy
= false;
106 wxWebNavigationError type
= wxWEB_NAV_ERR_OTHER
;
108 GError
* error
= (GError
*)web_error
;
109 wxString
description(error
->message
, wxConvUTF8
);
111 if (strcmp(g_quark_to_string(error
->domain
), "soup_http_error_quark") == 0)
115 case SOUP_STATUS_CANCELLED
:
116 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
119 case SOUP_STATUS_CANT_RESOLVE
:
120 case SOUP_STATUS_NOT_FOUND
:
121 type
= wxWEB_NAV_ERR_NOT_FOUND
;
124 case SOUP_STATUS_CANT_RESOLVE_PROXY
:
125 case SOUP_STATUS_CANT_CONNECT
:
126 case SOUP_STATUS_CANT_CONNECT_PROXY
:
127 case SOUP_STATUS_SSL_FAILED
:
128 case SOUP_STATUS_IO_ERROR
:
129 type
= wxWEB_NAV_ERR_CONNECTION
;
132 case SOUP_STATUS_MALFORMED
:
133 //case SOUP_STATUS_TOO_MANY_REDIRECTS:
134 type
= wxWEB_NAV_ERR_REQUEST
;
137 //case SOUP_STATUS_NO_CONTENT:
138 //case SOUP_STATUS_RESET_CONTENT:
140 case SOUP_STATUS_BAD_REQUEST
:
141 type
= wxWEB_NAV_ERR_REQUEST
;
144 case SOUP_STATUS_UNAUTHORIZED
:
145 case SOUP_STATUS_FORBIDDEN
:
146 type
= wxWEB_NAV_ERR_AUTH
;
149 case SOUP_STATUS_METHOD_NOT_ALLOWED
:
150 case SOUP_STATUS_NOT_ACCEPTABLE
:
151 type
= wxWEB_NAV_ERR_SECURITY
;
154 case SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED
:
155 type
= wxWEB_NAV_ERR_AUTH
;
158 case SOUP_STATUS_REQUEST_TIMEOUT
:
159 type
= wxWEB_NAV_ERR_CONNECTION
;
162 //case SOUP_STATUS_PAYMENT_REQUIRED:
163 case SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE
:
164 case SOUP_STATUS_REQUEST_URI_TOO_LONG
:
165 case SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE
:
166 type
= wxWEB_NAV_ERR_REQUEST
;
169 case SOUP_STATUS_BAD_GATEWAY
:
170 case SOUP_STATUS_SERVICE_UNAVAILABLE
:
171 case SOUP_STATUS_GATEWAY_TIMEOUT
:
172 type
= wxWEB_NAV_ERR_CONNECTION
;
175 case SOUP_STATUS_HTTP_VERSION_NOT_SUPPORTED
:
176 type
= wxWEB_NAV_ERR_REQUEST
;
178 //case SOUP_STATUS_INSUFFICIENT_STORAGE:
179 //case SOUP_STATUS_NOT_EXTENDED:
182 else if (strcmp(g_quark_to_string(error
->domain
),
183 "webkit-network-error-quark") == 0)
187 //WEBKIT_NETWORK_ERROR_FAILED:
188 //WEBKIT_NETWORK_ERROR_TRANSPORT:
190 case WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL
:
191 type
= wxWEB_NAV_ERR_REQUEST
;
194 case WEBKIT_NETWORK_ERROR_CANCELLED
:
195 type
= wxWEB_NAV_ERR_USER_CANCELLED
;
198 case WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST
:
199 type
= wxWEB_NAV_ERR_NOT_FOUND
;
203 else if (strcmp(g_quark_to_string(error
->domain
),
204 "webkit-policy-error-quark") == 0)
208 //case WEBKIT_POLICY_ERROR_FAILED:
209 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_MIME_TYPE:
210 //case WEBKIT_POLICY_ERROR_CANNOT_SHOW_URL:
211 //case WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE:
212 case WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT
:
213 type
= wxWEB_NAV_ERR_SECURITY
;
218 webkit_plugin_error_quark
221 printf("Error domain %s\n", g_quark_to_string(error->domain));
225 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_ERROR
,
226 webKitWindow
->GetId(),
230 thisEvent
.SetString(description
);
231 thisEvent
.SetInt(type
);
233 if (webKitWindow
&& webKitWindow
->GetEventHandler())
235 webKitWindow
->GetEventHandler()->ProcessEvent(thisEvent
);
242 wxgtk_webview_webkit_new_window(WebKitWebView
*,
243 WebKitWebFrame
*frame
,
244 WebKitNetworkRequest
*request
,
245 WebKitWebNavigationAction
*,
246 WebKitWebPolicyDecision
*policy_decision
,
247 wxWebViewWebKit
*webKitCtrl
)
249 const gchar
* uri
= webkit_network_request_get_uri(request
);
251 wxString target
= webkit_web_frame_get_name (frame
);
252 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
254 wxString( uri
, wxConvUTF8
),
258 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
259 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
261 //We always want the user to handle this themselves
262 webkit_web_policy_decision_ignore(policy_decision
);
267 wxgtk_webview_webkit_title_changed(WebKitWebView
*webView
,
268 WebKitWebFrame
*frame
,
270 wxWebViewWebKit
*webKitCtrl
)
272 wxWebNavigationEvent
thisEvent(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
274 webKitCtrl
->GetCurrentURL(),
277 thisEvent
.SetString(wxString(title
, wxConvUTF8
));
279 if (webKitCtrl
&& webKitCtrl
->GetEventHandler())
280 webKitCtrl
->GetEventHandler()->ProcessEvent(thisEvent
);
286 //-----------------------------------------------------------------------------
288 //-----------------------------------------------------------------------------
290 //IMPLEMENT_DYNAMIC_CLASS(wxWebViewWebKit, wxControl)
292 bool wxWebViewWebKit::Create(wxWindow
*parent
,
298 const wxString
& name
)
303 if (!PreCreation( parent
, pos
, size
) ||
304 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
306 wxFAIL_MSG( wxT("wxWebViewWebKit creation failed") );
310 GtkWidget
*scrolled_window
= gtk_scrolled_window_new (NULL
, NULL
);
311 web_view
= webkit_web_view_new ();
312 g_object_ref(web_view
); // TODO: check memory management
314 m_widget
= scrolled_window
;
315 g_object_ref(m_widget
); // TODO: check memory management
317 /* Place the WebKitWebView in the GtkScrolledWindow */
318 gtk_container_add (GTK_CONTAINER (scrolled_window
), web_view
);
319 gtk_widget_show(m_widget
);
320 gtk_widget_show(web_view
);
322 g_signal_connect_after(web_view
, "notify::load-status",
323 G_CALLBACK(wxgtk_webview_webkit_load_status
),
325 g_signal_connect_after(web_view
, "navigation-policy-decision-requested",
326 G_CALLBACK(wxgtk_webview_webkit_navigation
),
328 g_signal_connect_after(web_view
, "load-error",
329 G_CALLBACK(wxgtk_webview_webkit_error
),
332 g_signal_connect_after(web_view
, "new-window-policy-decision-requested",
333 G_CALLBACK(wxgtk_webview_webkit_new_window
), this);
335 g_signal_connect_after(web_view
, "title-changed",
336 G_CALLBACK(wxgtk_webview_webkit_title_changed
), this);
338 m_parent
->DoAddChild( this );
343 webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view
), url
);
345 //Get the initial history limit so we can enable and disable it later
346 WebKitWebBackForwardList
* history
;
347 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
348 m_historyLimit
= webkit_web_back_forward_list_get_limit(history
);
355 bool wxWebViewWebKit::Enable( bool enable
)
357 if (!wxControl::Enable(enable
))
360 gtk_widget_set_sensitive(GTK_BIN(m_widget
)->child
, enable
);
363 // GTKFixSensitivity();
369 wxWebViewWebKit::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
371 GdkWindow
* window
= gtk_widget_get_parent_window(m_widget
);
375 void wxWebViewWebKit::ZoomIn()
377 webkit_web_view_zoom_in (WEBKIT_WEB_VIEW(web_view
));
380 void wxWebViewWebKit::ZoomOut()
382 webkit_web_view_zoom_out (WEBKIT_WEB_VIEW(web_view
));
385 void wxWebViewWebKit::SetWebkitZoom(float level
)
387 webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW(web_view
), level
);
390 float wxWebViewWebKit::GetWebkitZoom()
392 return webkit_web_view_get_zoom_level (WEBKIT_WEB_VIEW(web_view
));
395 void wxWebViewWebKit::Stop()
397 webkit_web_view_stop_loading (WEBKIT_WEB_VIEW(web_view
));
400 void wxWebViewWebKit::Reload(wxWebViewReloadFlags flags
)
402 if (flags
& wxWEB_VIEW_RELOAD_NO_CACHE
)
404 webkit_web_view_reload_bypass_cache (WEBKIT_WEB_VIEW(web_view
));
408 webkit_web_view_reload (WEBKIT_WEB_VIEW(web_view
));
412 void wxWebViewWebKit::LoadUrl(const wxString
& url
)
414 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view
), wxGTK_CONV(url
));
418 void wxWebViewWebKit::GoBack()
420 webkit_web_view_go_back (WEBKIT_WEB_VIEW(web_view
));
423 void wxWebViewWebKit::GoForward()
425 webkit_web_view_go_forward (WEBKIT_WEB_VIEW(web_view
));
429 bool wxWebViewWebKit::CanGoBack()
431 return webkit_web_view_can_go_back (WEBKIT_WEB_VIEW(web_view
));
435 bool wxWebViewWebKit::CanGoForward()
437 return webkit_web_view_can_go_forward (WEBKIT_WEB_VIEW(web_view
));
440 void wxWebViewWebKit::ClearHistory()
442 WebKitWebBackForwardList
* history
;
443 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
444 webkit_web_back_forward_list_clear(history
);
447 void wxWebViewWebKit::EnableHistory(bool enable
)
449 WebKitWebBackForwardList
* history
;
450 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
453 webkit_web_back_forward_list_set_limit(history
, m_historyLimit
);
457 webkit_web_back_forward_list_set_limit(history
, 0);
461 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewWebKit::GetBackwardHistory()
463 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > backhist
;
464 WebKitWebBackForwardList
* history
;
465 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
466 GList
* list
= webkit_web_back_forward_list_get_back_list_with_limit(history
,
468 //We need to iterate in reverse to get the order we desire
469 for(int i
= g_list_length(list
) - 1; i
>= 0 ; i
--)
471 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
472 wxWebHistoryItem
* wxitem
= new wxWebHistoryItem(
473 webkit_web_history_item_get_uri(gtkitem
),
474 webkit_web_history_item_get_title(gtkitem
));
475 wxitem
->m_histItem
= gtkitem
;
476 wxSharedPtr
<wxWebHistoryItem
> item(wxitem
);
477 backhist
.push_back(item
);
482 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > wxWebViewWebKit::GetForwardHistory()
484 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > forwardhist
;
485 WebKitWebBackForwardList
* history
;
486 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
487 GList
* list
= webkit_web_back_forward_list_get_forward_list_with_limit(history
,
489 for(guint i
= 0; i
< g_list_length(list
); i
++)
491 WebKitWebHistoryItem
* gtkitem
= (WebKitWebHistoryItem
*)g_list_nth_data(list
, i
);
492 wxWebHistoryItem
* wxitem
= new wxWebHistoryItem(
493 webkit_web_history_item_get_uri(gtkitem
),
494 webkit_web_history_item_get_title(gtkitem
));
495 wxitem
->m_histItem
= gtkitem
;
496 wxSharedPtr
<wxWebHistoryItem
> item(wxitem
);
497 forwardhist
.push_back(item
);
502 void wxWebViewWebKit::LoadHistoryItem(wxSharedPtr
<wxWebHistoryItem
> item
)
504 WebKitWebHistoryItem
* gtkitem
= item
->m_histItem
;
507 WebKitWebBackForwardList
* history
;
508 history
= webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view
));
509 webkit_web_back_forward_list_go_to_item(WEBKIT_WEB_BACK_FORWARD_LIST(history
),
510 WEBKIT_WEB_HISTORY_ITEM(gtkitem
));
514 bool wxWebViewWebKit::CanCut()
516 return webkit_web_view_can_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
519 bool wxWebViewWebKit::CanCopy()
521 return webkit_web_view_can_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
524 bool wxWebViewWebKit::CanPaste()
526 return webkit_web_view_can_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
529 void wxWebViewWebKit::Cut()
531 webkit_web_view_cut_clipboard(WEBKIT_WEB_VIEW(web_view
));
534 void wxWebViewWebKit::Copy()
536 webkit_web_view_copy_clipboard(WEBKIT_WEB_VIEW(web_view
));
539 void wxWebViewWebKit::Paste()
541 webkit_web_view_paste_clipboard(WEBKIT_WEB_VIEW(web_view
));
544 bool wxWebViewWebKit::CanUndo()
546 return webkit_web_view_can_undo(WEBKIT_WEB_VIEW(web_view
));
549 bool wxWebViewWebKit::CanRedo()
551 return webkit_web_view_can_redo(WEBKIT_WEB_VIEW(web_view
));
554 void wxWebViewWebKit::Undo()
556 webkit_web_view_undo(WEBKIT_WEB_VIEW(web_view
));
559 void wxWebViewWebKit::Redo()
561 webkit_web_view_redo(WEBKIT_WEB_VIEW(web_view
));
564 wxString
wxWebViewWebKit::GetCurrentURL()
566 // FIXME: check which encoding the web kit control uses instead of
567 // assuming UTF8 (here and elsewhere too)
568 return wxString::FromUTF8(webkit_web_view_get_uri(
569 WEBKIT_WEB_VIEW(web_view
)));
573 wxString
wxWebViewWebKit::GetCurrentTitle()
575 return wxString::FromUTF8(webkit_web_view_get_title(
576 WEBKIT_WEB_VIEW(web_view
)));
580 wxString
wxWebViewWebKit::GetPageSource()
582 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
583 WEBKIT_WEB_VIEW(web_view
));
584 WebKitWebDataSource
* src
= webkit_web_frame_get_data_source (frame
);
586 // TODO: check encoding with
588 // webkit_web_data_source_get_encoding(WebKitWebDataSource *data_source);
589 return wxString(webkit_web_data_source_get_data (src
)->str
, wxConvUTF8
);
593 wxWebViewZoom
wxWebViewWebKit::GetZoom()
595 float zoom
= GetWebkitZoom();
597 // arbitrary way to map float zoom to our common zoom enum
600 return wxWEB_VIEW_ZOOM_TINY
;
602 else if (zoom
> 0.65 && zoom
<= 0.90)
604 return wxWEB_VIEW_ZOOM_SMALL
;
606 else if (zoom
> 0.90 && zoom
<= 1.15)
608 return wxWEB_VIEW_ZOOM_MEDIUM
;
610 else if (zoom
> 1.15 && zoom
<= 1.45)
612 return wxWEB_VIEW_ZOOM_LARGE
;
614 else if (zoom
> 1.45)
616 return wxWEB_VIEW_ZOOM_LARGEST
;
619 // to shut up compilers, this can never be reached logically
621 return wxWEB_VIEW_ZOOM_MEDIUM
;
625 void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom
)
627 // arbitrary way to map our common zoom enum to float zoom
630 case wxWEB_VIEW_ZOOM_TINY
:
634 case wxWEB_VIEW_ZOOM_SMALL
:
638 case wxWEB_VIEW_ZOOM_MEDIUM
:
642 case wxWEB_VIEW_ZOOM_LARGE
:
646 case wxWEB_VIEW_ZOOM_LARGEST
:
655 void wxWebViewWebKit::SetZoomType(wxWebViewZoomType type
)
657 webkit_web_view_set_full_content_zoom(WEBKIT_WEB_VIEW(web_view
),
658 (type
== wxWEB_VIEW_ZOOM_TYPE_LAYOUT
?
662 wxWebViewZoomType
wxWebViewWebKit::GetZoomType() const
664 gboolean fczoom
= webkit_web_view_get_full_content_zoom(
665 WEBKIT_WEB_VIEW(web_view
));
667 if (fczoom
) return wxWEB_VIEW_ZOOM_TYPE_LAYOUT
;
668 else return wxWEB_VIEW_ZOOM_TYPE_TEXT
;
671 bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType
) const
673 // this port supports all zoom types
677 void wxWebViewWebKit::SetPage(const wxString
& html
, const wxString
& baseUri
)
679 webkit_web_view_load_string (WEBKIT_WEB_VIEW(web_view
),
680 html
.mb_str(wxConvUTF8
),
683 baseUri
.mb_str(wxConvUTF8
));
686 void wxWebViewWebKit::Print()
688 WebKitWebFrame
* frame
= webkit_web_view_get_main_frame(
689 WEBKIT_WEB_VIEW(web_view
));
690 webkit_web_frame_print (frame
);
692 // GtkPrintOperationResult webkit_web_frame_print_full
693 // (WebKitWebFrame *frame,
694 // GtkPrintOperation *operation,
695 // GtkPrintOperationAction action,
701 bool wxWebViewWebKit::IsBusy()
705 // This code looks nice but returns true after a page was cancelled
707 WebKitLoadStatus status = webkit_web_view_get_load_status
708 (WEBKIT_WEB_VIEW(web_view));
711 #if WEBKIT_CHECK_VERSION(1,1,16)
712 // WEBKIT_LOAD_FAILED is new in webkit 1.1.16
713 if (status == WEBKIT_LOAD_FAILED)
718 if (status == WEBKIT_LOAD_FINISHED)
727 void wxWebViewWebKit::SetEditable(bool enable
)
729 webkit_web_view_set_editable(WEBKIT_WEB_VIEW(web_view
), enable
);
732 bool wxWebViewWebKit::IsEditable()
734 return webkit_web_view_get_editable(WEBKIT_WEB_VIEW(web_view
));
737 void wxWebViewWebKit::DeleteSelection()
739 webkit_web_view_delete_selection(WEBKIT_WEB_VIEW(web_view
));
742 bool wxWebViewWebKit::HasSelection()
744 return webkit_web_view_has_selection(WEBKIT_WEB_VIEW(web_view
));
747 void wxWebViewWebKit::SelectAll()
749 webkit_web_view_select_all(WEBKIT_WEB_VIEW(web_view
));
752 wxString
wxWebViewWebKit::GetSelectedText()
754 WebKitDOMDocument
* doc
;
755 WebKitDOMDOMWindow
* win
;
756 WebKitDOMDOMSelection
* sel
;
757 WebKitDOMRange
* range
;
759 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
760 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
761 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
762 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
764 return wxString(webkit_dom_range_get_text(WEBKIT_DOM_RANGE(range
)),
768 wxString
wxWebViewWebKit::GetSelectedSource()
770 WebKitDOMDocument
* doc
;
771 WebKitDOMDOMWindow
* win
;
772 WebKitDOMDOMSelection
* sel
;
773 WebKitDOMRange
* range
;
774 WebKitDOMElement
* div
;
775 WebKitDOMDocumentFragment
* clone
;
776 WebKitDOMHTMLElement
* html
;
778 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
779 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
780 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
781 range
= webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel
),
783 div
= webkit_dom_document_create_element(WEBKIT_DOM_DOCUMENT(doc
), "div", NULL
);
785 clone
= webkit_dom_range_clone_contents(WEBKIT_DOM_RANGE(range
), NULL
);
786 webkit_dom_node_append_child(&div
->parent_instance
, &clone
->parent_instance
, NULL
);
787 html
= (WebKitDOMHTMLElement
*)div
;
789 return wxString(webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(html
)),
793 void wxWebViewWebKit::ClearSelection()
795 WebKitDOMDocument
* doc
;
796 WebKitDOMDOMWindow
* win
;
797 WebKitDOMDOMSelection
* sel
;
799 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
800 win
= webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc
));
801 sel
= webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win
));
802 webkit_dom_dom_selection_remove_all_ranges(WEBKIT_DOM_DOM_SELECTION(sel
));
806 wxString
wxWebViewWebKit::GetPageText()
808 WebKitDOMDocument
* doc
;
809 WebKitDOMHTMLElement
* body
;
811 doc
= webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view
));
812 body
= webkit_dom_document_get_body(WEBKIT_DOM_DOCUMENT(doc
));
813 return wxString(webkit_dom_html_element_get_inner_text(WEBKIT_DOM_HTML_ELEMENT(body
)),
817 void wxWebViewWebKit::RunScript(const wxString
& javascript
)
819 webkit_web_view_execute_script(WEBKIT_WEB_VIEW(web_view
),
820 javascript
.mb_str(wxConvUTF8
));
825 wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
827 return GetDefaultAttributesFromGTKWidget(webkit_web_view_new
);
831 #endif // wxHAVE_WEB_BACKEND_GTK_WEBKIT