X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/34326da778583ca8eab95f2e41738da2852a5a16..88932ec82d048d006cdc81bd309f5e59aee799ac:/src/gtk/webview_webkit.cpp diff --git a/src/gtk/webview_webkit.cpp b/src/gtk/webview_webkit.cpp index 52f755b0f3..3e9008503f 100644 --- a/src/gtk/webview_webkit.cpp +++ b/src/gtk/webview_webkit.cpp @@ -18,6 +18,7 @@ #include "wx/gtk/private.h" #include "wx/filesys.h" #include "wx/base64.h" +#include "wx/log.h" #include // ---------------------------------------------------------------------------- @@ -385,6 +386,11 @@ wxgtk_webview_webkit_resource_req(WebKitWebView *, wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewWebKit, wxWebView); +wxWebViewWebKit::wxWebViewWebKit() +{ + m_web_view = NULL; +} + bool wxWebViewWebKit::Create(wxWindow *parent, wxWindowID id, const wxString &url, @@ -395,6 +401,11 @@ bool wxWebViewWebKit::Create(wxWindow *parent, { m_busy = false; m_guard = false; + FindClear(); + + // We currently unconditionally impose scrolling in both directions as it's + // necessary to show arbitrary pages. + style |= wxHSCROLL | wxVSCROLL; if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) @@ -403,13 +414,9 @@ bool wxWebViewWebKit::Create(wxWindow *parent, return false; } - m_widget = gtk_scrolled_window_new(NULL, NULL); - g_object_ref(m_widget); m_web_view = WEBKIT_WEB_VIEW(webkit_web_view_new()); - - /* Place the WebKitWebView in the GtkScrolledWindow */ - gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_web_view)); - gtk_widget_show(GTK_WIDGET(m_web_view)); + 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), @@ -447,12 +454,18 @@ bool wxWebViewWebKit::Create(wxWindow *parent, return true; } +wxWebViewWebKit::~wxWebViewWebKit() +{ + if (m_web_view) + GTKDisconnect(m_web_view); +} + bool wxWebViewWebKit::Enable( bool enable ) { if (!wxControl::Enable(enable)) return false; - gtk_widget_set_sensitive(GTK_BIN(m_widget)->child, enable); + gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(m_widget)), enable); //if (enable) // GTKFixSensitivity(); @@ -763,7 +776,7 @@ bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType) const return true; } -void wxWebViewWebKit::SetPage(const wxString& html, const wxString& baseUri) +void wxWebViewWebKit::DoSetPage(const wxString& html, const wxString& baseUri) { webkit_web_view_load_string (m_web_view, html.mb_str(wxConvUTF8), @@ -913,11 +926,85 @@ void wxWebViewWebKit::RegisterHandler(wxSharedPtr handler) m_handlerList.push_back(handler); } +long wxWebViewWebKit::Find(const wxString& text, int flags) +{ + bool newSearch = false; + if(text != m_findText || + (flags & wxWEB_VIEW_FIND_MATCH_CASE) != (m_findFlags & wxWEB_VIEW_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); + } + + m_findFlags = flags; + m_findText = text; + + //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(); + return wxNOT_FOUND; + } + + bool wrap = false, matchCase = false, forward = true; + if(flags & wxWEB_VIEW_FIND_WRAP) + wrap = true; + if(flags & wxWEB_VIEW_FIND_MATCH_CASE) + matchCase = true; + if(flags & wxWEB_VIEW_FIND_BACKWARDS) + forward = false; + + 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); + //In this case we return early to match IE behaviour + m_findPosition = -1; + return m_findCount; + } + else + { + if(forward) + m_findPosition++; + else + m_findPosition--; + if(m_findPosition < 0) + m_findPosition += m_findCount; + if(m_findPosition > m_findCount) + m_findPosition -= m_findCount; + } + + //Highlight them if needed + bool highlight = flags & wxWEB_VIEW_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; + } + wxLogMessage(wxString::Format("Returning %d", m_findPosition)); + return newSearch ? m_findCount : m_findPosition; +} + +void wxWebViewWebKit::FindClear() +{ + m_findCount = 0; + m_findFlags = 0; + m_findText = ""; + m_findPosition = -1; +} + // static wxVisualAttributes wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) { - return GetDefaultAttributesFromGTKWidget(webkit_web_view_new); + return GetDefaultAttributesFromGTKWidget(webkit_web_view_new()); }