+void wxWebViewWebKit::ClearSelection()
+{
+ WebKitDOMDocument* doc;
+ WebKitDOMDOMWindow* win;
+ WebKitDOMDOMSelection* sel;
+
+ doc = webkit_web_view_get_dom_document(m_web_view);
+ win = webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc));
+ 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
+{
+ WebKitDOMDocument* doc;
+ WebKitDOMHTMLElement* body;
+
+ doc = webkit_web_view_get_dom_document(m_web_view);
+ 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);
+}
+
+void wxWebViewWebKit::RunScript(const wxString& javascript)
+{
+ webkit_web_view_execute_script(m_web_view,
+ javascript.mb_str(wxConvUTF8));
+}
+
+void wxWebViewWebKit::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
+{
+ m_handlerList.push_back(handler);
+}
+
+void wxWebViewWebKit::EnableContextMenu(bool enable)
+{
+#if !WEBKIT_CHECK_VERSION(1, 10, 0) //If we are using an older version
+ g_object_set(webkit_web_view_get_settings(m_web_view),
+ "enable-default-context-menu", enable, NULL);
+#endif
+ wxWebView::EnableContextMenu(enable);
+}
+
+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;
+ }
+ 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;
+}