From 7ca24831df9b0076ff000555da57d2e3db040aa4 Mon Sep 17 00:00:00 2001 From: Scott Talbert Date: Sat, 4 Mar 2017 21:09:02 -0500 Subject: [PATCH] WIP patch to convert webview to webkit2gtk This is a temporary patch for Fedora to switch to webkit2gtk for now. This is not the final implementation. --- configure.in | 2 +- include/wx/gtk/webview_webkit.h | 12 +- src/gtk/webview_webkit.cpp | 435 +++++++++++++++++++++++----------------- 3 files changed, 263 insertions(+), 186 deletions(-) diff --git a/configure.in b/configure.in index c88523a..6925887 100644 --- a/configure.in +++ b/configure.in @@ -7244,7 +7244,7 @@ if test "$wxUSE_WEBVIEW" = "yes"; then if test "$wxUSE_GTK" = 1; then webkitgtk=webkit-1.0 if test "$WXGTK3" = 1; then - webkitgtk=webkitgtk-3.0 + webkitgtk=webkit2gtk-4.0 fi PKG_CHECK_MODULES([WEBKIT], [$webkitgtk >= 1.3.1], diff --git a/include/wx/gtk/webview_webkit.h b/include/wx/gtk/webview_webkit.h index e1a01bf..e2c9f33 100644 --- a/include/wx/gtk/webview_webkit.h +++ b/include/wx/gtk/webview_webkit.h @@ -134,6 +134,12 @@ public: //create-web-view signal and so we need to send a new window event bool m_creating; + //variables used for Find() + int m_findFlags; + wxString m_findText; + int m_findPosition; + int m_findCount; + protected: virtual void DoSetPage(const wxString& html, const wxString& baseUrl); @@ -157,12 +163,6 @@ private: wxVector > m_handlerList; - //variables used for Find() - int m_findFlags; - wxString m_findText; - int m_findPosition; - int m_findCount; - wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit); }; diff --git a/src/gtk/webview_webkit.cpp b/src/gtk/webview_webkit.cpp index e592331..315949d 100644 --- a/src/gtk/webview_webkit.cpp +++ b/src/gtk/webview_webkit.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/gtk/webview_webkit.cpp +// Name: src/gtk/webview_webkit2.cpp // Purpose: GTK WebKit backend for web view component // Author: Marianne Gagnon, Robert Roebling // Copyright: (c) 2010 Marianne Gagnon, 1998 Robert Roebling @@ -18,7 +18,7 @@ #include "wx/filesys.h" #include "wx/base64.h" #include "wx/log.h" -#include +#include // ---------------------------------------------------------------------------- // GTK callbacks @@ -28,36 +28,16 @@ extern "C" { static void -wxgtk_webview_webkit_load_status(GtkWidget* widget, - GParamSpec*, - wxWebViewWebKit *webKitCtrl) +wxgtk_webview_webkit_load_changed(GtkWidget *, + WebKitLoadEvent load_event, + wxWebViewWebKit *webKitCtrl) { wxString url = webKitCtrl->GetCurrentURL(); - WebKitLoadStatus status; - g_object_get(G_OBJECT(widget), "load-status", &status, NULL); - wxString target; // TODO: get target (if possible) - if (status == WEBKIT_LOAD_FINISHED) + if (load_event == WEBKIT_LOAD_FINISHED) { - WebKitWebBackForwardList* hist = webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(widget)); - WebKitWebHistoryItem* item = webkit_web_back_forward_list_get_current_item(hist); - //We have to check if we are actually storing history - //If the item isn't added we add it ourselves, it isn't added otherwise - //with a custom scheme. - if(!item || (WEBKIT_IS_WEB_HISTORY_ITEM(item) && - webkit_web_history_item_get_uri(item) != url)) - { - WebKitWebHistoryItem* - newitem = webkit_web_history_item_new_with_data - ( - url.utf8_str(), - webKitCtrl->GetCurrentTitle().utf8_str() - ); - webkit_web_back_forward_list_add_item(hist, newitem); - } - webKitCtrl->m_busy = false; wxWebViewEvent event(wxEVT_WEBVIEW_LOADED, webKitCtrl->GetId(), @@ -66,7 +46,7 @@ wxgtk_webview_webkit_load_status(GtkWidget* widget, if (webKitCtrl && webKitCtrl->GetEventHandler()) webKitCtrl->GetEventHandler()->ProcessEvent(event); } - else if (status == WEBKIT_LOAD_COMMITTED) + else if (load_event == WEBKIT_LOAD_COMMITTED) { webKitCtrl->m_busy = true; wxWebViewEvent event(wxEVT_WEBVIEW_NAVIGATED, @@ -79,15 +59,15 @@ wxgtk_webview_webkit_load_status(GtkWidget* widget, } static gboolean -wxgtk_webview_webkit_navigation(WebKitWebView *, - WebKitWebFrame *frame, - WebKitNetworkRequest *request, - WebKitWebNavigationAction *, - WebKitWebPolicyDecision *policy_decision, +wxgtk_webview_webkit_navigation(WebKitWebView *web_view, + WebKitPolicyDecision *decision, wxWebViewWebKit *webKitCtrl) { - const gchar* uri = webkit_network_request_get_uri(request); - wxString target = webkit_web_frame_get_name (frame); + WebKitNavigationPolicyDecision* navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION(decision); + WebKitNavigationAction* action = webkit_navigation_policy_decision_get_navigation_action(navigation_decision); + WebKitURIRequest* request = webkit_navigation_action_get_request(action); + const gchar* uri = webkit_uri_request_get_uri(request); + wxString target = webkit_navigation_policy_decision_get_frame_name(navigation_decision); //If m_creating is true then we are the result of a new window //and so we need to send the event and veto the load @@ -102,7 +82,7 @@ wxgtk_webview_webkit_navigation(WebKitWebView *, if(webKitCtrl && webKitCtrl->GetEventHandler()) webKitCtrl->GetEventHandler()->ProcessEvent(event); - webkit_web_policy_decision_ignore(policy_decision); + webkit_policy_decision_ignore(decision); return TRUE; } @@ -111,8 +91,8 @@ wxgtk_webview_webkit_navigation(WebKitWebView *, webKitCtrl->m_guard = false; //We set this to make sure that we don't try to load the page again from //the resource request callback - webKitCtrl->m_vfsurl = webkit_network_request_get_uri(request); - webkit_web_policy_decision_use(policy_decision); + webKitCtrl->m_vfsurl = webkit_web_view_get_uri(web_view); + webkit_policy_decision_use(decision); return FALSE; } @@ -129,17 +109,17 @@ wxgtk_webview_webkit_navigation(WebKitWebView *, if (!event.IsAllowed()) { webKitCtrl->m_busy = false; - webkit_web_policy_decision_ignore(policy_decision); + webkit_policy_decision_ignore(decision); return TRUE; } else { wxString wxuri = uri; wxSharedPtr handler; - wxVector > hanlders = webKitCtrl->GetHandlers(); + wxVector > handlers = webKitCtrl->GetHandlers(); //We are not vetoed so see if we match one of the additional handlers - for(wxVector >::iterator it = hanlders.begin(); - it != hanlders.end(); ++it) + for(wxVector >::iterator it = handlers.begin(); + it != handlers.end(); ++it) { if(wxuri.substr(0, (*it)->GetName().length()) == (*it)->GetName()) { @@ -157,7 +137,7 @@ wxgtk_webview_webkit_navigation(WebKitWebView *, webKitCtrl->SetPage(*file->GetStream(), wxuri); } //We need to throw some sort of error here if file is NULL - webkit_web_policy_decision_ignore(policy_decision); + webkit_policy_decision_ignore(decision); return TRUE; } return FALSE; @@ -165,16 +145,15 @@ wxgtk_webview_webkit_navigation(WebKitWebView *, } static gboolean -wxgtk_webview_webkit_error(WebKitWebView*, - WebKitWebFrame*, - gchar *uri, - gpointer web_error, - wxWebViewWebKit* webKitWindow) +wxgtk_webview_webkit_load_failed(WebKitWebView *, + WebKitLoadEvent, + gchar *uri, + GError *error, + wxWebViewWebKit* webKitWindow) { webKitWindow->m_busy = false; wxWebViewNavigationError type = wxWEBVIEW_NAV_ERR_OTHER; - GError* error = (GError*)web_error; wxString description(error->message, wxConvUTF8); if (strcmp(g_quark_to_string(error->domain), "soup_http_error_quark") == 0) @@ -306,16 +285,15 @@ wxgtk_webview_webkit_error(WebKitWebView*, } static gboolean -wxgtk_webview_webkit_new_window(WebKitWebView*, - WebKitWebFrame *frame, - WebKitNetworkRequest *request, - WebKitWebNavigationAction*, - WebKitWebPolicyDecision *policy_decision, +wxgtk_webview_webkit_new_window(WebKitPolicyDecision *decision, wxWebViewWebKit *webKitCtrl) { - const gchar* uri = webkit_network_request_get_uri(request); + WebKitNavigationPolicyDecision* navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION(decision); + WebKitNavigationAction* action = webkit_navigation_policy_decision_get_navigation_action(navigation_decision); + WebKitURIRequest* request = webkit_navigation_action_get_request(action); + const gchar* uri = webkit_uri_request_get_uri(request); - wxString target = webkit_web_frame_get_name (frame); + wxString target = webkit_navigation_policy_decision_get_frame_name(navigation_decision); wxWebViewEvent event(wxEVT_WEBVIEW_NEWWINDOW, webKitCtrl->GetId(), wxString( uri, wxConvUTF8 ), @@ -325,16 +303,35 @@ wxgtk_webview_webkit_new_window(WebKitWebView*, webKitCtrl->GetEventHandler()->ProcessEvent(event); //We always want the user to handle this themselves - webkit_web_policy_decision_ignore(policy_decision); + webkit_policy_decision_ignore(decision); return TRUE; } +static gboolean +wxgtk_webview_webkit_decide_policy(WebKitWebView *web_view, + WebKitPolicyDecision *decision, + WebKitPolicyDecisionType type, + wxWebViewWebKit *webKitCtrl) +{ + switch (type) + { + case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: + return wxgtk_webview_webkit_navigation(web_view, decision, webKitCtrl); + case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION: + return wxgtk_webview_webkit_new_window(decision, webKitCtrl); + default: + return FALSE; + } +} + static void -wxgtk_webview_webkit_title_changed(WebKitWebView*, - WebKitWebFrame*, - gchar *title, +wxgtk_webview_webkit_title_changed(GtkWidget* widget, + GParamSpec *, wxWebViewWebKit *webKitCtrl) { + gchar *title; + g_object_get(G_OBJECT(widget), "title", &title, NULL); + wxWebViewEvent event(wxEVT_WEBVIEW_TITLE_CHANGED, webKitCtrl->GetId(), webKitCtrl->GetCurrentURL(), @@ -344,24 +341,23 @@ wxgtk_webview_webkit_title_changed(WebKitWebView*, if (webKitCtrl && webKitCtrl->GetEventHandler()) webKitCtrl->GetEventHandler()->ProcessEvent(event); + g_free(title); } static void wxgtk_webview_webkit_resource_req(WebKitWebView *, - WebKitWebFrame *, WebKitWebResource *, - WebKitNetworkRequest *request, - WebKitNetworkResponse *, + WebKitURIRequest *request, wxWebViewWebKit *webKitCtrl) { - wxString uri = webkit_network_request_get_uri(request); + wxString uri = webkit_uri_request_get_uri(request); wxSharedPtr handler; - wxVector > hanlders = webKitCtrl->GetHandlers(); + wxVector > handlers = webKitCtrl->GetHandlers(); //We are not vetoed so see if we match one of the additional handlers - for(wxVector >::iterator it = hanlders.begin(); - it != hanlders.end(); ++it) + for(wxVector >::iterator it = handlers.begin(); + it != handlers.end(); ++it) { if(uri.substr(0, (*it)->GetName().length()) == (*it)->GetName()) { @@ -389,19 +385,17 @@ wxgtk_webview_webkit_resource_req(WebKitWebView *, wxString mime = file->GetMimeType(); wxString path = "data:" + mime + ";base64," + data; //Then we can redirect the call - webkit_network_request_set_uri(request, path.utf8_str()); + webkit_uri_request_set_uri(request, path.utf8_str()); } } } -#if WEBKIT_CHECK_VERSION(1, 10, 0) - static gboolean wxgtk_webview_webkit_context_menu(WebKitWebView *, - GtkWidget *, + WebKitContextMenu *, + GdkEvent *, WebKitHitTestResult *, - gboolean, wxWebViewWebKit *webKitCtrl) { if(webKitCtrl->IsContextMenuEnabled()) @@ -410,11 +404,9 @@ wxgtk_webview_webkit_context_menu(WebKitWebView *, return TRUE; } -#endif - static WebKitWebView* wxgtk_webview_webkit_create_webview(WebKitWebView *web_view, - WebKitWebFrame*, + WebKitNavigationAction *, wxWebViewWebKit *webKitCtrl) { //As we do not know the uri being loaded at this point allow the load to @@ -423,6 +415,30 @@ wxgtk_webview_webkit_create_webview(WebKitWebView *web_view, return web_view; } +static void +wxgtk_webview_webkit_counted_matches(WebKitFindController *, + guint match_count, + wxWebViewWebKit *webKitCtrl) +{ + std::cerr << "BLAH counted_matches: " << match_count << std::endl; + webKitCtrl->m_findCount = match_count; +} + +static void +wxgtk_webview_webkit_failed_to_find_text(WebKitFindController *, + wxWebViewWebKit *) +{ + std::cerr << "BLAH failed_to_find_text" << std::endl; +} + +static void +wxgtk_webview_webkit_found_text(WebKitFindController *, + guint match_count, + wxWebViewWebKit *) +{ + std::cerr << "BLAH found_text: " << match_count << std::endl; +} + } // extern "C" //----------------------------------------------------------------------------- @@ -464,30 +480,33 @@ bool wxWebViewWebKit::Create(wxWindow *parent, GTKCreateScrolledWindowWith(GTK_WIDGET(m_web_view)); g_object_ref(m_widget); - g_signal_connect_after(m_web_view, "navigation-policy-decision-requested", - G_CALLBACK(wxgtk_webview_webkit_navigation), - this); - g_signal_connect_after(m_web_view, "load-error", - G_CALLBACK(wxgtk_webview_webkit_error), + g_signal_connect_after(m_web_view, "decide-policy", + G_CALLBACK(wxgtk_webview_webkit_decide_policy), this); - g_signal_connect_after(m_web_view, "new-window-policy-decision-requested", - G_CALLBACK(wxgtk_webview_webkit_new_window), this); + g_signal_connect_after(m_web_view, "load-failed", + G_CALLBACK(wxgtk_webview_webkit_load_failed), this); - g_signal_connect_after(m_web_view, "title-changed", + g_signal_connect_after(m_web_view, "notify::title", G_CALLBACK(wxgtk_webview_webkit_title_changed), this); - g_signal_connect_after(m_web_view, "resource-request-starting", + g_signal_connect_after(m_web_view, "resource-load-started", G_CALLBACK(wxgtk_webview_webkit_resource_req), this); - -#if WEBKIT_CHECK_VERSION(1, 10, 0) - g_signal_connect_after(m_web_view, "context-menu", + + g_signal_connect_after(m_web_view, "context-menu", G_CALLBACK(wxgtk_webview_webkit_context_menu), this); -#endif - - g_signal_connect_after(m_web_view, "create-web-view", + + g_signal_connect_after(m_web_view, "create", G_CALLBACK(wxgtk_webview_webkit_create_webview), this); + WebKitFindController* findctrl = webkit_web_view_get_find_controller(m_web_view); + g_signal_connect_after(findctrl, "counted-matches", + G_CALLBACK(wxgtk_webview_webkit_counted_matches), this); + g_signal_connect_after(findctrl, "failed-to-find-text", + G_CALLBACK(wxgtk_webview_webkit_failed_to_find_text), this); + g_signal_connect_after(findctrl, "found-text", + G_CALLBACK(wxgtk_webview_webkit_found_text), this); + m_parent->DoAddChild( this ); PostCreation(size); @@ -495,14 +514,9 @@ bool wxWebViewWebKit::Create(wxWindow *parent, /* Open a webpage */ webkit_web_view_load_uri(m_web_view, url.utf8_str()); - //Get the initial history limit so we can enable and disable it later - WebKitWebBackForwardList* history; - history = webkit_web_view_get_back_forward_list(m_web_view); - m_historyLimit = webkit_web_back_forward_list_get_limit(history); - // last to avoid getting signal too early - g_signal_connect_after(m_web_view, "notify::load-status", - G_CALLBACK(wxgtk_webview_webkit_load_status), + g_signal_connect_after(m_web_view, "load-changed", + G_CALLBACK(wxgtk_webview_webkit_load_changed), this); return true; @@ -536,12 +550,12 @@ wxWebViewWebKit::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const void wxWebViewWebKit::ZoomIn() { - webkit_web_view_zoom_in(m_web_view); + SetWebkitZoom(GetWebkitZoom() + 0.1); } void wxWebViewWebKit::ZoomOut() { - webkit_web_view_zoom_out(m_web_view); + SetWebkitZoom(GetWebkitZoom() - 0.1); } void wxWebViewWebKit::SetWebkitZoom(float level) @@ -601,39 +615,28 @@ bool wxWebViewWebKit::CanGoForward() const void wxWebViewWebKit::ClearHistory() { - WebKitWebBackForwardList* history; - history = webkit_web_view_get_back_forward_list(m_web_view); - webkit_web_back_forward_list_clear(history); + // In WebKit2GTK+, the BackForwardList can't be cleared so do nothing. } -void wxWebViewWebKit::EnableHistory(bool enable) +void wxWebViewWebKit::EnableHistory(bool) { - WebKitWebBackForwardList* history; - history = webkit_web_view_get_back_forward_list(m_web_view); - if(enable) - { - webkit_web_back_forward_list_set_limit(history, m_historyLimit); - } - else - { - webkit_web_back_forward_list_set_limit(history, 0); - } + // In WebKit2GTK+, history can't be disabled so do nothing here. } wxVector > wxWebViewWebKit::GetBackwardHistory() { wxVector > backhist; - WebKitWebBackForwardList* history; + WebKitBackForwardList* history; history = webkit_web_view_get_back_forward_list(m_web_view); - GList* list = webkit_web_back_forward_list_get_back_list_with_limit(history, - m_historyLimit); + GList* list = webkit_back_forward_list_get_back_list_with_limit(history, + m_historyLimit); //We need to iterate in reverse to get the order we desire for(int i = g_list_length(list) - 1; i >= 0 ; i--) { - WebKitWebHistoryItem* gtkitem = (WebKitWebHistoryItem*)g_list_nth_data(list, i); + WebKitBackForwardListItem* gtkitem = (WebKitBackForwardListItem*)g_list_nth_data(list, i); wxWebViewHistoryItem* wxitem = new wxWebViewHistoryItem( - webkit_web_history_item_get_uri(gtkitem), - webkit_web_history_item_get_title(gtkitem)); + webkit_back_forward_list_item_get_uri(gtkitem), + webkit_back_forward_list_item_get_title(gtkitem)); wxitem->m_histItem = gtkitem; wxSharedPtr item(wxitem); backhist.push_back(item); @@ -644,16 +647,16 @@ wxVector > wxWebViewWebKit::GetBackwardHistory wxVector > wxWebViewWebKit::GetForwardHistory() { wxVector > forwardhist; - WebKitWebBackForwardList* history; + WebKitBackForwardList* history; history = webkit_web_view_get_back_forward_list(m_web_view); - GList* list = webkit_web_back_forward_list_get_forward_list_with_limit(history, - m_historyLimit); + GList* list = webkit_back_forward_list_get_forward_list_with_limit(history, + m_historyLimit); for(guint i = 0; i < g_list_length(list); i++) { - WebKitWebHistoryItem* gtkitem = (WebKitWebHistoryItem*)g_list_nth_data(list, i); + WebKitBackForwardListItem* gtkitem = (WebKitBackForwardListItem*)g_list_nth_data(list, i); wxWebViewHistoryItem* wxitem = new wxWebViewHistoryItem( - webkit_web_history_item_get_uri(gtkitem), - webkit_web_history_item_get_title(gtkitem)); + webkit_back_forward_list_item_get_uri(gtkitem), + webkit_back_forward_list_item_get_title(gtkitem)); wxitem->m_histItem = gtkitem; wxSharedPtr item(wxitem); forwardhist.push_back(item); @@ -663,62 +666,72 @@ wxVector > wxWebViewWebKit::GetForwardHistory( void wxWebViewWebKit::LoadHistoryItem(wxSharedPtr item) { - WebKitWebHistoryItem* gtkitem = (WebKitWebHistoryItem*)item->m_histItem; + WebKitBackForwardListItem* gtkitem = (WebKitBackForwardListItem*)item->m_histItem; if(gtkitem) { - webkit_web_view_go_to_back_forward_item(m_web_view, - WEBKIT_WEB_HISTORY_ITEM(gtkitem)); + webkit_web_view_go_to_back_forward_list_item(m_web_view, + WEBKIT_BACK_FORWARD_LIST_ITEM(gtkitem)); } } bool wxWebViewWebKit::CanCut() const { - return webkit_web_view_can_cut_clipboard(m_web_view); + // Cannot be determined without making an async call, so just return true + return true; } bool wxWebViewWebKit::CanCopy() const { - return webkit_web_view_can_copy_clipboard(m_web_view); + // Cannot be determined without making an async call, so just return true + return true; } bool wxWebViewWebKit::CanPaste() const { - return webkit_web_view_can_paste_clipboard(m_web_view); + // Cannot be determined without making an async call, so just return true + return true; } void wxWebViewWebKit::Cut() { - webkit_web_view_cut_clipboard(m_web_view); + webkit_web_view_execute_editing_command(m_web_view, + WEBKIT_EDITING_COMMAND_CUT); } void wxWebViewWebKit::Copy() { - webkit_web_view_copy_clipboard(m_web_view); + webkit_web_view_execute_editing_command(m_web_view, + WEBKIT_EDITING_COMMAND_COPY); } void wxWebViewWebKit::Paste() { - webkit_web_view_paste_clipboard(m_web_view); + webkit_web_view_execute_editing_command(m_web_view, + WEBKIT_EDITING_COMMAND_PASTE); } bool wxWebViewWebKit::CanUndo() const { - return webkit_web_view_can_undo(m_web_view); + // Cannot be determined without making an async call, so just return true + return true; } bool wxWebViewWebKit::CanRedo() const { - return webkit_web_view_can_redo(m_web_view); + // Cannot be determined without making an async call, so just return true + return true; } void wxWebViewWebKit::Undo() { - webkit_web_view_undo(m_web_view); + webkit_web_view_execute_editing_command(m_web_view, + WEBKIT_EDITING_COMMAND_UNDO); } void wxWebViewWebKit::Redo() { - webkit_web_view_redo(m_web_view); + webkit_web_view_execute_editing_command(m_web_view, + WEBKIT_EDITING_COMMAND_REDO); } wxString wxWebViewWebKit::GetCurrentURL() const @@ -737,6 +750,7 @@ wxString wxWebViewWebKit::GetCurrentTitle() const wxString wxWebViewWebKit::GetPageSource() const { +/* TODO: webkit_web_resource_get_data() async WebKitWebFrame* frame = webkit_web_view_get_main_frame(m_web_view); WebKitWebDataSource* src = webkit_web_frame_get_data_source (frame); @@ -744,6 +758,8 @@ wxString wxWebViewWebKit::GetPageSource() const // const gchar* // webkit_web_data_source_get_encoding(WebKitWebDataSource *data_source); return wxString(webkit_web_data_source_get_data (src)->str, wxConvUTF8); +*/ + return wxString(""); } @@ -811,17 +827,19 @@ void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom) void wxWebViewWebKit::SetZoomType(wxWebViewZoomType type) { - webkit_web_view_set_full_content_zoom(m_web_view, - (type == wxWEBVIEW_ZOOM_TYPE_LAYOUT ? - TRUE : FALSE)); + WebKitSettings* settings = webkit_web_view_get_settings(m_web_view); + webkit_settings_set_zoom_text_only(settings, + (type == wxWEBVIEW_ZOOM_TYPE_TEXT ? + TRUE : FALSE)); } wxWebViewZoomType wxWebViewWebKit::GetZoomType() const { - gboolean fczoom = webkit_web_view_get_full_content_zoom(m_web_view); + WebKitSettings* settings = webkit_web_view_get_settings(m_web_view); + gboolean tozoom = webkit_settings_get_zoom_text_only(settings); - if (fczoom) return wxWEBVIEW_ZOOM_TYPE_LAYOUT; - else return wxWEBVIEW_ZOOM_TYPE_TEXT; + if (tozoom) return wxWEBVIEW_ZOOM_TYPE_TEXT; + else return wxWEBVIEW_ZOOM_TYPE_LAYOUT; } bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType) const @@ -832,24 +850,16 @@ bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType) const void wxWebViewWebKit::DoSetPage(const wxString& html, const wxString& baseUri) { - webkit_web_view_load_string (m_web_view, - html.mb_str(wxConvUTF8), - "text/html", - "UTF-8", - baseUri.mb_str(wxConvUTF8)); + webkit_web_view_load_html(m_web_view, + html.mb_str(wxConvUTF8), + baseUri.mb_str(wxConvUTF8)); } void wxWebViewWebKit::Print() { - WebKitWebFrame* frame = webkit_web_view_get_main_frame(m_web_view); - webkit_web_frame_print (frame); - - // GtkPrintOperationResult webkit_web_frame_print_full - // (WebKitWebFrame *frame, - // GtkPrintOperation *operation, - // GtkPrintOperationAction action, - // GError **error); - + WebKitPrintOperation* printop = webkit_print_operation_new(m_web_view); + webkit_print_operation_run_dialog(printop, NULL); + g_object_unref(printop); } @@ -886,26 +896,35 @@ void wxWebViewWebKit::SetEditable(bool enable) bool wxWebViewWebKit::IsEditable() const { - return webkit_web_view_get_editable(m_web_view); + gboolean editable; + g_object_get(m_web_view, "editable", &editable, NULL); + return editable; } void wxWebViewWebKit::DeleteSelection() { +/* TODO webkit_web_view_delete_selection(m_web_view); +*/ } bool wxWebViewWebKit::HasSelection() const { +/* TODO return webkit_web_view_has_selection(m_web_view); +*/ + return false; } void wxWebViewWebKit::SelectAll() { - webkit_web_view_select_all(m_web_view); + webkit_web_view_execute_editing_command(m_web_view, + WEBKIT_EDITING_COMMAND_SELECT_ALL); } wxString wxWebViewWebKit::GetSelectedText() const { +/* TODO: what to do about this? WebKitDOMDocument* doc; WebKitDOMDOMWindow* win; WebKitDOMDOMSelection* sel; @@ -918,10 +937,13 @@ wxString wxWebViewWebKit::GetSelectedText() const 0, NULL); return wxString(webkit_dom_range_get_text(WEBKIT_DOM_RANGE(range)), wxConvUTF8); +*/ + return wxString(""); } wxString wxWebViewWebKit::GetSelectedSource() const { +/* TODO: what to do? WebKitDOMDocument* doc; WebKitDOMDOMWindow* win; WebKitDOMDOMSelection* sel; @@ -943,10 +965,13 @@ wxString wxWebViewWebKit::GetSelectedSource() const return wxString(webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(html)), wxConvUTF8); +*/ + return wxString(""); } void wxWebViewWebKit::ClearSelection() { +/* TODO: ??? WebKitDOMDocument* doc; WebKitDOMDOMWindow* win; WebKitDOMDOMSelection* sel; @@ -956,10 +981,12 @@ void wxWebViewWebKit::ClearSelection() sel = webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win)); webkit_dom_dom_selection_remove_all_ranges(WEBKIT_DOM_DOM_SELECTION(sel)); +*/ } wxString wxWebViewWebKit::GetPageText() const { +/* TODO WebKitDOMDocument* doc; WebKitDOMHTMLElement* body; @@ -967,12 +994,17 @@ wxString wxWebViewWebKit::GetPageText() const body = webkit_dom_document_get_body(WEBKIT_DOM_DOCUMENT(doc)); return wxString(webkit_dom_html_element_get_inner_text(WEBKIT_DOM_HTML_ELEMENT(body)), wxConvUTF8); +*/ + return wxString(""); } void wxWebViewWebKit::RunScript(const wxString& javascript) { - webkit_web_view_execute_script(m_web_view, - javascript.mb_str(wxConvUTF8)); + webkit_web_view_run_javascript(m_web_view, + javascript.mb_str(wxConvUTF8), + NULL, + NULL, + NULL); } void wxWebViewWebKit::RegisterHandler(wxSharedPtr handler) @@ -991,14 +1023,15 @@ void wxWebViewWebKit::EnableContextMenu(bool enable) long wxWebViewWebKit::Find(const wxString& text, int flags) { + WebKitFindController* findctrl = webkit_web_view_get_find_controller(m_web_view); bool newSearch = false; if(text != m_findText || (flags & wxWEBVIEW_FIND_MATCH_CASE) != (m_findFlags & wxWEBVIEW_FIND_MATCH_CASE)) { newSearch = true; //If it is a new search we need to clear existing highlights - webkit_web_view_unmark_text_matches(m_web_view); - webkit_web_view_set_highlight_text_matches(m_web_view, false); + //webkit_web_view_unmark_text_matches(m_web_view); + //webkit_web_view_set_highlight_text_matches(m_web_view, false); } m_findFlags = flags; @@ -1007,27 +1040,53 @@ long wxWebViewWebKit::Find(const wxString& text, int flags) //If the search string is empty then we clear any selection and highlight if(text == "") { - webkit_web_view_unmark_text_matches(m_web_view); - webkit_web_view_set_highlight_text_matches(m_web_view, false); - ClearSelection(); + webkit_find_controller_search_finish(findctrl); return wxNOT_FOUND; } bool wrap = false, matchCase = false, forward = true; + guint32 options = WEBKIT_FIND_OPTIONS_NONE; if(flags & wxWEBVIEW_FIND_WRAP) + { wrap = true; + options |= WEBKIT_FIND_OPTIONS_WRAP_AROUND; + } if(flags & wxWEBVIEW_FIND_MATCH_CASE) + { matchCase = true; + } + else + { + options |= WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE; + } if(flags & wxWEBVIEW_FIND_BACKWARDS) + { forward = false; + options |= WEBKIT_FIND_OPTIONS_BACKWARDS; + } if(newSearch) { - //Initially we mark the matches to know how many we have - m_findCount = webkit_web_view_mark_text_matches(m_web_view, wxGTK_CONV(text), matchCase, 0); + ////Initially we mark the matches to know how many we have + //m_findCount = webkit_web_view_mark_text_matches(m_web_view, wxGTK_CONV(text), matchCase, 0); //In this case we return early to match IE behaviour m_findPosition = -1; - return m_findCount; + //return m_findCount; + if(flags & wxWEBVIEW_FIND_HIGHLIGHT_RESULT) + { + webkit_find_controller_search(findctrl, + wxGTK_CONV(text), + options, + G_MAXUINT); + } + else + { + webkit_find_controller_count_matches(findctrl, + wxGTK_CONV(text), + options, + G_MAXUINT); + } + return G_MAXUINT; } else { @@ -1041,17 +1100,36 @@ long wxWebViewWebKit::Find(const wxString& text, int flags) m_findPosition -= m_findCount; } - //Highlight them if needed - bool highlight = flags & wxWEBVIEW_FIND_HIGHLIGHT_RESULT ? true : false; - webkit_web_view_set_highlight_text_matches(m_web_view, highlight); - - if(!webkit_web_view_search_text(m_web_view, wxGTK_CONV(text), matchCase, forward, wrap)) + if(forward) { - m_findPosition = -1; - ClearSelection(); - return wxNOT_FOUND; + webkit_find_controller_search_next(findctrl); + if(m_findPosition == m_findCount && !wrap) + { + return wxNOT_FOUND; + } } - wxLogMessage(wxString::Format("Returning %d", m_findPosition)); + else + { + webkit_find_controller_search_previous(findctrl); + if(m_findPosition == -1 && !wrap) + { + return wxNOT_FOUND; + } + } + + //Highlight them if needed + //bool highlight = flags & wxWEBVIEW_FIND_HIGHLIGHT_RESULT ? true : false; + //webkit_web_view_set_highlight_text_matches(m_web_view, highlight); + + //if(!webkit_web_view_search_text(m_web_view, wxGTK_CONV(text), matchCase, forward, wrap)) + //{ + // m_findPosition = -1; + // ClearSelection(); + // return wxNOT_FOUND; + //} + + + return newSearch ? m_findCount : m_findPosition; } @@ -1070,5 +1148,4 @@ wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) return GetDefaultAttributesFromGTKWidget(webkit_web_view_new()); } - #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT -- 2.9.3