static void search_bar_find (ESearchBar *search_bar, gboolean search_forward) { EWebView *web_view; GtkWidget *widget; gboolean case_sensitive; gboolean wrapped = FALSE; gboolean success; gchar *text; guint matches; web_view = e_search_bar_get_web_view (search_bar); case_sensitive = e_search_bar_get_case_sensitive (search_bar); text = e_search_bar_get_text (search_bar); if (text == NULL || *text == '\0') { e_search_bar_clear (search_bar); g_free (text); return; } webkit_web_view_unmark_text_matches ( WEBKIT_WEB_VIEW (web_view)); matches = webkit_web_view_mark_text_matches ( WEBKIT_WEB_VIEW (web_view), text, case_sensitive, 0); webkit_web_view_set_highlight_text_matches ( WEBKIT_WEB_VIEW (web_view), TRUE); search_bar_update_matches (search_bar, matches); success = webkit_web_view_search_text ( WEBKIT_WEB_VIEW (web_view), text, case_sensitive, search_forward, FALSE); if (!success) wrapped = webkit_web_view_search_text ( WEBKIT_WEB_VIEW (web_view), text, case_sensitive, search_forward, TRUE); g_free (search_bar->priv->active_search); search_bar->priv->active_search = text; gtk_widget_set_sensitive (search_bar->priv->next_button, matches != 0); gtk_widget_set_sensitive (search_bar->priv->prev_button, matches != 0); g_object_notify (G_OBJECT (search_bar), "active-search"); /* Update wrapped label visibility. */ widget = search_bar->priv->wrapped_next_box; if (wrapped && search_forward) gtk_widget_show (widget); else gtk_widget_hide (widget); widget = search_bar->priv->wrapped_prev_box; if (wrapped && !search_forward) gtk_widget_show (widget); else gtk_widget_hide (widget); }
long wxWebViewWebKit::Find(const wxString& text, int flags) { 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); } 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 & wxWEBVIEW_FIND_WRAP) wrap = true; if(flags & wxWEBVIEW_FIND_MATCH_CASE) matchCase = true; if(flags & wxWEBVIEW_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 & 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; }
static void searchText(WebKitWebView* webView, gchar* searchString) { webkit_web_view_unmark_text_matches(webView); webkit_web_view_search_text(webView, searchString, false, true, true); webkit_web_view_mark_text_matches(webView, searchString, false, 0); webkit_web_view_set_highlight_text_matches(webView, true); }