[evolution/wip/webkit2] Merge EContentEditorFindController into EContentEditor



commit 623bd3524a9b8a9afb278ca330510ccf9235ea28
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jun 8 14:06:44 2016 +0200

    Merge EContentEditorFindController into EContentEditor
    
    Plus few other changes/fixes around the EContentEditor interface.

 e-util/Makefile.am                                 |    2 -
 e-util/e-content-editor-enums.h                    |   23 ++
 e-util/e-content-editor-find-controller.c          |  190 -----------
 e-util/e-content-editor-find-controller.h          |   98 ------
 e-util/e-content-editor.c                          |  194 +++++++++--
 e-util/e-content-editor.h                          |   58 +++-
 e-util/e-html-editor-dialog.h                      |    2 +-
 e-util/e-html-editor-find-dialog.c                 |   90 ++----
 e-util/e-html-editor-replace-dialog.c              |  156 ++++------
 e-util/e-html-editor-spell-check-dialog.c          |   23 +-
 e-util/e-util.h                                    |    1 -
 modules/webkit-content-editor/Makefile.am          |    4 +-
 .../e-webkit-content-editor-find-controller.c      |  354 --------------------
 .../e-webkit-content-editor-find-controller.h      |   62 ----
 .../e-webkit-content-editor.c                      |  247 +++++++++++---
 15 files changed, 529 insertions(+), 975 deletions(-)
---
diff --git a/e-util/Makefile.am b/e-util/Makefile.am
index 721e6b0..526fce4 100644
--- a/e-util/Makefile.am
+++ b/e-util/Makefile.am
@@ -173,7 +173,6 @@ evolution_util_include_HEADERS =  \
        e-conflict-search-selector.h \
        e-contact-store.h \
        e-content-editor.h \
-       e-content-editor-find-controller.h \
        e-content-editor-enums.h \
        e-content-request.h \
        e-data-capture.h \
@@ -448,7 +447,6 @@ libevolution_util_la_SOURCES = \
        e-conflict-search-selector.c \
        e-contact-store.c \
        e-content-editor.c \
-       e-content-editor-find-controller.c \
        e-content-request.c \
        e-data-capture.c \
        e-dateedit.c \
diff --git a/e-util/e-content-editor-enums.h b/e-util/e-content-editor-enums.h
index 8286040..6a60a51 100644
--- a/e-util/e-content-editor-enums.h
+++ b/e-util/e-content-editor-enums.h
@@ -275,6 +275,29 @@ typedef enum {
        E_CONTENT_EDITOR_UNIT_PERCENTAGE
 } EContentEditorUnit;
 
+/**
+ * EContentEditorCommand:
+ * @E_CONTENT_EDITOR_FIND_NEXT: Search for the next occurrence of the text.
+ *    This is the default. It's mutually exclusive with @E_CONTENT_EDITOR_FIND_PREVIOUS.
+ * @E_CONTENT_EDITOR_FIND_PREVIOUS: Search for the previous occurrence of the text.
+ *    It's mutually exclusive with @E_CONTENT_EDITOR_FIND_NEXT.
+ * @E_CONTENT_EDITOR_FIND_MODE_BACKWARDS: The search mode is backwards. If not set,
+ *    then the mode is forward.
+ * @E_CONTENT_EDITOR_FIND_CASE_INSENSITIVE: Search case insensitively.
+ * @E_CONTENT_EDITOR_FIND_WRAP_AROUND: Wrap around when searching.
+ *
+ * Flags to use to modify behaviour of the search for the text.
+ *
+ * Since: 3.22
+ **/
+typedef enum {
+       E_CONTENT_EDITOR_FIND_NEXT              = (1 << 0),
+       E_CONTENT_EDITOR_FIND_PREVIOUS          = (1 << 1),
+       E_CONTENT_EDITOR_FIND_MODE_BACKWARDS    = (1 << 2),
+       E_CONTENT_EDITOR_FIND_CASE_INSENSITIVE  = (1 << 3),
+       E_CONTENT_EDITOR_FIND_WRAP_AROUND       = (1 << 4)
+} EContentEditorFindFlags;
+
 G_END_DECLS
 
 #endif /* E_CONTENT_EDITOR_ENUMS_H */
diff --git a/e-util/e-content-editor.c b/e-util/e-content-editor.c
index 230ebe7..95dee91 100644
--- a/e-util/e-content-editor.c
+++ b/e-util/e-content-editor.c
@@ -25,16 +25,16 @@
 #include <libedataserver/libedataserver.h>
 
 #include "e-content-editor.h"
-#include "e-marshal.h"
 
 G_DEFINE_INTERFACE (EContentEditor, e_content_editor, GTK_TYPE_WIDGET);
 
 enum {
-       CONTEXT_MENU_REQUESTED,
+       LOAD_FINISHED,
        PASTE_CLIPBOARD,
        PASTE_PRIMARY_CLIPBOARD,
-       LOAD_FINISHED,
-
+       CONTEXT_MENU_REQUESTED,
+       FIND_DONE,
+       REPLACE_ALL_DONE,
        LAST_SIGNAL
 };
 
@@ -417,16 +417,16 @@ e_content_editor_default_init (EContentEditorInterface *iface)
        /**
         * EContentEditor:paste-clipboard
         *
-        * Emitted when user presses middle button on EWebKitContentEditor.
+        * Emitted when user presses middle button on EContentEditor.
         */
        signals[PASTE_CLIPBOARD] = g_signal_new (
                "paste-clipboard",
                E_TYPE_CONTENT_EDITOR,
                G_SIGNAL_RUN_LAST,
                G_STRUCT_OFFSET (EContentEditorInterface, paste_clipboard),
-               NULL, NULL,
-               g_cclosure_marshal_VOID__VOID,
-               G_TYPE_NONE, 0);
+               g_signal_accumulator_true_handled, NULL,
+               NULL,
+               G_TYPE_BOOLEAN, 0);
 
        /**
         * EContentEditor:paste-primary-clipboard
@@ -438,9 +438,9 @@ e_content_editor_default_init (EContentEditorInterface *iface)
                E_TYPE_CONTENT_EDITOR,
                G_SIGNAL_RUN_LAST,
                G_STRUCT_OFFSET (EContentEditorInterface, paste_primary_clipboard),
-               NULL, NULL,
-               g_cclosure_marshal_VOID__VOID,
-               G_TYPE_NONE, 0);
+               g_signal_accumulator_true_handled, NULL,
+               NULL,
+               G_TYPE_BOOLEAN, 0);
 
        /**
         * EContentEditor:is-ready
@@ -453,7 +453,7 @@ e_content_editor_default_init (EContentEditorInterface *iface)
                G_SIGNAL_RUN_LAST,
                G_STRUCT_OFFSET (EContentEditorInterface, load_finished),
                NULL, NULL,
-               g_cclosure_marshal_VOID__VOID,
+               NULL,
                G_TYPE_NONE, 0);
 
        /**
@@ -467,24 +467,40 @@ e_content_editor_default_init (EContentEditorInterface *iface)
                G_SIGNAL_RUN_LAST,
                G_STRUCT_OFFSET (EContentEditorInterface, context_menu_requested),
                g_signal_accumulator_true_handled, NULL,
-               e_marshal_BOOLEAN__INT_BOXED,
+               NULL,
                G_TYPE_BOOLEAN, 2,
                G_TYPE_INT,
                GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
-}
 
-EContentEditorFindController *
-e_content_editor_get_find_controller (EContentEditor *editor)
-{
-       EContentEditorInterface *iface;
-
-       g_return_val_if_fail (E_IS_CONTENT_EDITOR (editor), NULL);
-
-       iface = E_CONTENT_EDITOR_GET_IFACE (editor);
-       g_return_val_if_fail (iface != NULL, NULL);
-       g_return_val_if_fail (iface->get_find_controller != NULL, NULL);
+       /**
+        * EContentEditor::find-done
+        *
+        * Emitted when the call to e_content_editor_find() is done.
+        **/
+       signals[FIND_DONE] = g_signal_new (
+               "find-done",
+               E_TYPE_CONTENT_EDITOR,
+               G_SIGNAL_RUN_LAST,
+               G_STRUCT_OFFSET (EContentEditorInterface, find_done),
+               NULL, NULL,
+               NULL,
+               G_TYPE_NONE, 1,
+               G_TYPE_UINT);
 
-       return iface->get_find_controller (editor);
+       /**
+        * EContentEditor::replace-all-done
+        *
+        * Emitted when the call to e_content_editor_replace_all() is done.
+        **/
+       signals[REPLACE_ALL_DONE] = g_signal_new (
+               "replace-all-done",
+               E_TYPE_CONTENT_EDITOR,
+               G_SIGNAL_RUN_LAST,
+               G_STRUCT_OFFSET (EContentEditorInterface, replace_all_done),
+               NULL, NULL,
+               NULL,
+               G_TYPE_NONE, 1,
+               G_TYPE_UINT);
 }
 
 void
@@ -1083,7 +1099,37 @@ e_content_editor_selection_unlink (EContentEditor *editor)
 }
 
 /**
- * e_content_editor_replace:
+ * e_content_editor_find:
+ * @editor: an #EContentEditor
+ * @flags: a bit-OR of #EContentEditorFindFlags flags
+ * @text: a text to find
+ *
+ * Searches the content of the @editor for the occurrence of the @text.
+ * The @flags modify the behaviour of the search. The found text,
+ * if any, is supposed to be selected.
+ *
+ * Once the search is done, the "find-done" signal should be
+ * emitted, by using e_content_editor_emit_find_done().
+ **/
+void
+e_content_editor_find (EContentEditor *editor,
+                      guint32 flags,
+                      const gchar *text)
+{
+       EContentEditorInterface *iface;
+
+       g_return_if_fail (E_IS_CONTENT_EDITOR (editor));
+       g_return_if_fail (text != NULL);
+
+       iface = E_CONTENT_EDITOR_GET_IFACE (editor);
+       g_return_if_fail (iface != NULL);
+       g_return_if_fail (iface->find != NULL);
+
+       iface->find (editor, flags, text);
+}
+
+/**
+ * e_content_editor_selection_replace:
  * @editor: an #EContentEditor
  * @replacement: a string to replace current selection with
  *
@@ -1106,6 +1152,39 @@ e_content_editor_selection_replace (EContentEditor *editor,
 }
 
 /**
+ * e_content_editor_replace_all:
+ * @editor: an #EContentEditor
+ * @flags: a bit-OR of #EContentEditorFindFlags flags
+ * @find_text: a text to find
+ * @replace_with: a text to replace the found text with
+ *
+ * Searches the content of the @editor for all the occurrences of
+ * the @find_text and replaces them with the @replace_with.
+ * The @flags modify the behaviour of the search.
+ *
+ * Once the replace is done, the "replace-all-done" signal should be
+ * emitted, by using e_content_editor_emit_replace_all_done().
+ **/
+void
+e_content_editor_replace_all (EContentEditor *editor,
+                             guint32 flags,
+                             const gchar *find_text,
+                             const gchar *replace_with)
+{
+       EContentEditorInterface *iface;
+
+       g_return_if_fail (E_IS_CONTENT_EDITOR (editor));
+       g_return_if_fail (find_text != NULL);
+       g_return_if_fail (replace_with != NULL);
+
+       iface = E_CONTENT_EDITOR_GET_IFACE (editor);
+       g_return_if_fail (iface != NULL);
+       g_return_if_fail (iface->replace_all != NULL);
+
+       iface->replace_all (editor, flags, find_text, replace_with);
+}
+
+/**
  * e_content_editor_selection_save:
  * @editor: an #EContentEditor
  *
@@ -3455,3 +3534,66 @@ e_content_editor_on_find_dialog_close (EContentEditor *editor)
        iface->on_find_dialog_close (editor);
 }
 
+void
+e_content_editor_emit_load_finished (EContentEditor *editor)
+{
+       g_return_if_fail (E_IS_CONTENT_EDITOR (editor));
+
+       g_signal_emit (editor, signals[LOAD_FINISHED], 0);
+}
+
+gboolean
+e_content_editor_emit_paste_clipboard (EContentEditor *editor)
+{
+       gboolean handled = FALSE;
+
+       g_return_val_if_fail (E_IS_CONTENT_EDITOR (editor), FALSE);
+
+       g_signal_emit (editor, signals[PASTE_CLIPBOARD], 0, &handled);
+
+       return handled;
+}
+
+gboolean
+e_content_editor_emit_paste_primary_clipboard (EContentEditor *editor)
+{
+       gboolean handled = FALSE;
+
+       g_return_val_if_fail (E_IS_CONTENT_EDITOR (editor), FALSE);
+
+       g_signal_emit (editor, signals[PASTE_PRIMARY_CLIPBOARD], 0, &handled);
+
+       return handled;
+}
+
+gboolean
+e_content_editor_emit_context_menu_requested (EContentEditor *editor,
+                                             EContentEditorNodeFlags flags,
+                                             GdkEvent *event)
+{
+       gboolean handled = FALSE;
+
+       g_return_val_if_fail (E_IS_CONTENT_EDITOR (editor), FALSE);
+
+       g_signal_emit (editor, signals[CONTEXT_MENU_REQUESTED], 0, flags, event, &handled);
+
+       return handled;
+}
+
+void
+e_content_editor_emit_find_done (EContentEditor *editor,
+                                guint match_count)
+{
+       g_return_if_fail (E_IS_CONTENT_EDITOR (editor));
+
+       g_signal_emit (editor, signals[FIND_DONE], 0, match_count);
+}
+
+void
+e_content_editor_emit_replace_all_done (EContentEditor *editor,
+                                       guint replaced_count)
+{
+       g_return_if_fail (E_IS_CONTENT_EDITOR (editor));
+
+       g_signal_emit (editor, signals[REPLACE_ALL_DONE], 0, replaced_count);
+}
diff --git a/e-util/e-content-editor.h b/e-util/e-content-editor.h
index eca62c5..600088d 100644
--- a/e-util/e-content-editor.h
+++ b/e-util/e-content-editor.h
@@ -22,15 +22,13 @@
 #define E_CONTENT_EDITOR_H
 
 #include <glib-object.h>
+#include <gtk/gtk.h>
 
 #include <camel/camel.h>
 
-#include "e-content-editor-find-controller.h"
-#include "e-content-editor-enums.h"
-
+#include <e-util/e-content-editor-enums.h>
 #include <e-util/e-emoticon.h>
 #include <e-util/e-spell-checker.h>
-#include <gtk/gtk.h>
 
 G_BEGIN_DECLS
 
@@ -45,9 +43,6 @@ typedef struct {
 struct _EContentEditorInterface {
        GTypeInterface parent_interface;
 
-       EContentEditorFindController *
-                       (*get_find_controller)          (EContentEditor *editor);
-
        void            (*insert_content)               (EContentEditor *editor,
                                                         const gchar *content,
                                                         EContentEditorInsertContentFlags flags);
@@ -140,9 +135,18 @@ struct _EContentEditorInterface {
 
        void            (*selection_unlink)             (EContentEditor *editor);
 
+       void            (*find)                         (EContentEditor *editor,
+                                                        guint32 flags,
+                                                        const gchar *text);
+
        void            (*selection_replace)            (EContentEditor *editor,
                                                         const gchar *replacement);
 
+       void            (*replace_all)                  (EContentEditor *editor,
+                                                        guint32 flags,
+                                                        const gchar *find_text,
+                                                        const gchar *replace_with);
+
        void            (*selection_save)               (EContentEditor *editor);
 
        void            (*selection_restore)            (EContentEditor *editor);
@@ -521,20 +525,17 @@ struct _EContentEditorInterface {
 
        /* Signals */
        void            (*load_finished)                (EContentEditor *editor);
-
-       void            (*paste_clipboard)              (EContentEditor *editor);
-
-       void            (*paste_primary_clipboard)      (EContentEditor *editor);
-
+       gboolean        (*paste_clipboard)              (EContentEditor *editor);
+       gboolean        (*paste_primary_clipboard)      (EContentEditor *editor);
        gboolean        (*context_menu_requested)       (EContentEditor *editor,
                                                         EContentEditorNodeFlags flags,
                                                         GdkEvent *event);
+       void            (*find_done)                    (EContentEditor *editor,
+                                                        guint match_count);
+       void            (*replace_all_done)             (EContentEditor *editor,
+                                                        guint replaced_count);
 };
 
-EContentEditorFindController *
-               e_content_editor_get_find_controller
-                                               (EContentEditor *editor);
-
 void           e_content_editor_insert_content (EContentEditor *editor,
                                                 const gchar *content,
                                                 EContentEditorInsertContentFlags flags);
@@ -645,10 +646,19 @@ void              e_content_editor_selection_create_link
 void           e_content_editor_selection_unlink
                                                (EContentEditor *editor);
 
+void           e_content_editor_find           (EContentEditor *editor,
+                                                guint32 flags,
+                                                const gchar *text);
+
 void           e_content_editor_selection_replace
                                                (EContentEditor *editor,
                                                 const gchar *replacement);
 
+void           e_content_editor_replace_all    (EContentEditor *editor,
+                                                guint32 flags,
+                                                const gchar *find_text,
+                                                const gchar *replace_with);
+
 void           e_content_editor_selection_save (EContentEditor *editor);
 
 void           e_content_editor_selection_restore
@@ -1124,6 +1134,22 @@ void             e_content_editor_on_find_dialog_open
 void           e_content_editor_on_find_dialog_close
                                                (EContentEditor *editor);
 
+void           e_content_editor_emit_load_finished
+                                               (EContentEditor *editor);
+gboolean       e_content_editor_emit_paste_clipboard
+                                               (EContentEditor *editor);
+gboolean       e_content_editor_emit_paste_primary_clipboard
+                                               (EContentEditor *editor);
+gboolean       e_content_editor_emit_context_menu_requested
+                                               (EContentEditor *editor,
+                                                EContentEditorNodeFlags flags,
+                                                GdkEvent *event);
+void           e_content_editor_emit_find_done (EContentEditor *editor,
+                                                guint match_count);
+void           e_content_editor_emit_replace_all_done
+                                               (EContentEditor *editor,
+                                                guint replaced_count);
+
 G_END_DECLS
 
 #endif /* E_CONTENT_EDITOR_H */
diff --git a/e-util/e-html-editor-dialog.h b/e-util/e-html-editor-dialog.h
index d111569..f1f5700 100644
--- a/e-util/e-html-editor-dialog.h
+++ b/e-util/e-html-editor-dialog.h
@@ -62,7 +62,7 @@ struct _EHTMLEditorDialogClass {
        GtkWindowClass parent_class;
 };
 
-#if 0
+#if 0 /* FIXME WK2 */
 struct _EContentEditorDialogInterface {
        GTypeInterface parent_interface;
 
diff --git a/e-util/e-html-editor-find-dialog.c b/e-util/e-html-editor-find-dialog.c
index e134d21..f1ad2f2 100644
--- a/e-util/e-html-editor-find-dialog.c
+++ b/e-util/e-html-editor-find-dialog.c
@@ -42,9 +42,8 @@ struct _EHTMLEditorFindDialogPrivate {
 
        GtkWidget *result_label;
 
-       EContentEditorFindController *find_controller;
-       gulong found_text_handler_id;
-       gulong failed_to_find_text_handler_id;
+       EContentEditor *cnt_editor;
+       gulong find_done_handler_id;
 };
 
 G_DEFINE_TYPE (
@@ -62,15 +61,9 @@ reset_dialog (EHTMLEditorFindDialog *dialog)
 static void
 html_editor_find_dialog_hide (GtkWidget *widget)
 {
-       EContentEditor *cnt_editor;
-       EHTMLEditor *editor;
        EHTMLEditorFindDialog *dialog = E_HTML_EDITOR_FIND_DIALOG (widget);
 
-       editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
-       cnt_editor = e_html_editor_get_content_editor (editor);
-
-       e_content_editor_find_controller_search_finish (dialog->priv->find_controller);
-       e_content_editor_on_find_dialog_close (cnt_editor);
+       e_content_editor_on_find_dialog_close (dialog->priv->cnt_editor);
 
        /* Chain up to parent's implementation */
        GTK_WIDGET_CLASS (e_html_editor_find_dialog_parent_class)->hide (widget);
@@ -79,58 +72,50 @@ html_editor_find_dialog_hide (GtkWidget *widget)
 static void
 html_editor_find_dialog_show (GtkWidget *widget)
 {
-       EContentEditor *cnt_editor;
-       EHTMLEditor *editor;
        EHTMLEditorFindDialog *dialog = E_HTML_EDITOR_FIND_DIALOG (widget);
 
-       editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
-       cnt_editor = e_html_editor_get_content_editor (editor);
-
-       e_content_editor_on_find_dialog_open (cnt_editor);
-
        reset_dialog (dialog);
        gtk_widget_grab_focus (dialog->priv->entry);
 
+       e_content_editor_on_find_dialog_open (dialog->priv->cnt_editor);
+
        /* Chain up to parent's implementation */
        GTK_WIDGET_CLASS (e_html_editor_find_dialog_parent_class)->show (widget);
 }
 
 static void
-content_editor_find_controller_found_text_cb (EContentEditorFindController *find_controller,
-                                              guint match_count,
-                                              EHTMLEditorFindDialog *dialog)
+content_editor_find_done_cb (EContentEditor *cnt_editor,
+                            guint match_count,
+                            EHTMLEditorFindDialog *dialog)
 {
-       gtk_widget_hide (dialog->priv->result_label);
-       gtk_widget_set_sensitive (dialog->priv->find_button, TRUE);
-}
+       if (match_count) {
+               gtk_widget_hide (dialog->priv->result_label);
+       } else {
+               gtk_label_set_label (GTK_LABEL (dialog->priv->result_label), _("No match found"));
+               gtk_widget_show (dialog->priv->result_label);
+       }
 
-static void
-content_editor_find_controller_failed_to_found_text_cb (EContentEditorFindController *find_controller,
-                                                        EHTMLEditorFindDialog *dialog)
-{
-       gtk_label_set_label (
-               GTK_LABEL (dialog->priv->result_label), N_("No match found"));
-       gtk_widget_show (dialog->priv->result_label);
+       gtk_widget_set_sensitive (dialog->priv->find_button, match_count > 0);
 }
 
 static void
 html_editor_find_dialog_find_cb (EHTMLEditorFindDialog *dialog)
 {
-       guint32 flags = 0;
+       guint32 flags = E_CONTENT_EDITOR_FIND_NEXT;
+
+       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->backwards)))
+               flags |= E_CONTENT_EDITOR_FIND_MODE_BACKWARDS;
 
        if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->case_sensitive)))
                flags |= E_CONTENT_EDITOR_FIND_CASE_INSENSITIVE;
 
-       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->backwards)))
-               flags |= E_CONTENT_EDITOR_FIND_BACKWARDS;
-
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->wrap_search)))
                flags |= E_CONTENT_EDITOR_FIND_WRAP_AROUND;
 
-       e_content_editor_find_controller_search (
-               dialog->priv->find_controller,
-               gtk_entry_get_text (GTK_ENTRY (dialog->priv->entry)),
-               flags);
+       e_content_editor_find (
+               dialog->priv->cnt_editor,
+               flags,
+               gtk_entry_get_text (GTK_ENTRY (dialog->priv->entry)));
 }
 
 static gboolean
@@ -157,18 +142,11 @@ html_editor_find_dialog_dispose (GObject *object)
 
        priv = E_HTML_EDITOR_FIND_DIALOG_GET_PRIVATE (object);
 
-       if (priv->found_text_handler_id > 0) {
-               g_signal_handler_disconnect (
-                       priv->find_controller,
-                       priv->found_text_handler_id);
-               priv->found_text_handler_id = 0;
-       }
-
-       if (priv->failed_to_find_text_handler_id > 0) {
+       if (priv->find_done_handler_id > 0) {
                g_signal_handler_disconnect (
-                       priv->find_controller,
-                       priv->failed_to_find_text_handler_id);
-               priv->failed_to_find_text_handler_id = 0;
+                       priv->cnt_editor,
+                       priv->find_done_handler_id);
+               priv->find_done_handler_id = 0;
        }
 
        /* Chain up to parent's dispose() method. */
@@ -181,24 +159,18 @@ html_editor_find_dialog_constructed (GObject *object)
        EHTMLEditor *editor;
        EHTMLEditorFindDialog *dialog;
        EContentEditor *cnt_editor;
-       EContentEditorFindController *find_controller;
 
        dialog = E_HTML_EDITOR_FIND_DIALOG (object);
        dialog->priv = E_HTML_EDITOR_FIND_DIALOG_GET_PRIVATE (dialog);
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        cnt_editor = e_html_editor_get_content_editor (editor);
-       find_controller = e_content_editor_get_find_controller (cnt_editor);
-
-       dialog->priv->found_text_handler_id = g_signal_connect (
-               find_controller, "found-text",
-               G_CALLBACK (content_editor_find_controller_found_text_cb), dialog);
 
-       dialog->priv->failed_to_find_text_handler_id = g_signal_connect (
-               find_controller, "failed-to-find-text",
-               G_CALLBACK (content_editor_find_controller_failed_to_found_text_cb), dialog);
+       dialog->priv->find_done_handler_id = g_signal_connect (
+               cnt_editor, "find-done",
+               G_CALLBACK (content_editor_find_done_cb), dialog);
 
-       dialog->priv->find_controller = find_controller;
+       dialog->priv->cnt_editor = cnt_editor;
 
        G_OBJECT_CLASS (e_html_editor_find_dialog_parent_class)->constructed (object);
 }
diff --git a/e-util/e-html-editor-replace-dialog.c b/e-util/e-html-editor-replace-dialog.c
index b846711..c1ee2de 100644
--- a/e-util/e-html-editor-replace-dialog.c
+++ b/e-util/e-html-editor-replace-dialog.c
@@ -23,7 +23,6 @@
 #endif
 
 #include "e-html-editor-replace-dialog.h"
-#include "e-content-editor-find-controller.h"
 
 #include <glib/gi18n-lib.h>
 
@@ -50,12 +49,9 @@ struct _EHTMLEditorReplaceDialogPrivate {
        GtkWidget *replace_button;
        GtkWidget *replace_all_button;
 
-       EHTMLEditor *editor;
-
-       EContentEditorFindController *find_controller;
-       gulong found_text_handler_id;
-       gulong failed_to_find_text_handler_id;
-       gulong replace_all_finished_handler_id;
+       EContentEditor *cnt_editor;
+       gulong find_done_handler_id;
+       gulong replace_all_done_handler_id;
 };
 
 enum {
@@ -64,77 +60,76 @@ enum {
 };
 
 static void
-content_editor_find_controller_found_text_cb (EContentEditorFindController *find_controller,
-                                              guint match_count,
-                                              EHTMLEditorReplaceDialog *dialog)
+content_editor_find_done_cb (EContentEditor *cnt_editor,
+                            guint match_count,
+                            EHTMLEditorReplaceDialog *dialog)
 {
-       gtk_widget_hide (dialog->priv->result_label);
-}
-
-static void
-content_editor_find_controller_failed_to_found_text_cb (EContentEditorFindController *find_controller,
-                                                        EHTMLEditorReplaceDialog *dialog)
-{
-       gtk_label_set_label (
-               GTK_LABEL (dialog->priv->result_label), N_("No match found"));
-       gtk_widget_show (dialog->priv->result_label);
+       if (match_count) {
+               gtk_widget_hide (dialog->priv->result_label);
+       } else {
+               gtk_label_set_label (GTK_LABEL (dialog->priv->result_label), _("No match found"));
+               gtk_widget_show (dialog->priv->result_label);
+       }
 }
 
 static void
 replace_occurance (EHTMLEditorReplaceDialog *dialog)
 {
-       EContentEditor *cnt_editor;
-
-       cnt_editor = e_html_editor_get_content_editor (dialog->priv->editor);
-
        gtk_widget_hide (dialog->priv->result_label);
 
        e_content_editor_selection_replace (
-               cnt_editor,
+               dialog->priv->cnt_editor,
                gtk_entry_get_text (GTK_ENTRY (dialog->priv->replace_entry)));
 }
 
 static void
-content_editor_find_controller_replace_all_finished_cb (EContentEditorFindController *find_controller,
-                                                        guint match_count,
-                                                        EHTMLEditorReplaceDialog *dialog)
+content_editor_replace_all_done_cb (EContentEditor *cnt_editor,
+                                   guint replaced_count,
+                                   EHTMLEditorReplaceDialog *dialog)
 {
        gchar *result;
 
        result = g_strdup_printf (ngettext("%d occurrence replaced",
                                           "%d occurrences replaced",
-                                          match_count),
-                                match_count);
+                                          replaced_count),
+                                replaced_count);
 
        gtk_label_set_label (GTK_LABEL (dialog->priv->result_label), result);
        gtk_widget_show (dialog->priv->result_label);
        g_free (result);
 }
 
-static void
-search (EHTMLEditorReplaceDialog *dialog)
+static guint32
+replace_dialog_get_find_flags (EHTMLEditorReplaceDialog *dialog)
 {
-       guint32 flags = 0;
+       guint32 flags = E_CONTENT_EDITOR_FIND_NEXT;
+
+       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->backwards)))
+               flags |= E_CONTENT_EDITOR_FIND_MODE_BACKWARDS;
 
        if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->case_sensitive)))
                flags |= E_CONTENT_EDITOR_FIND_CASE_INSENSITIVE;
 
-       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->backwards)))
-               flags |= E_CONTENT_EDITOR_FIND_BACKWARDS;
-
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->wrap)))
                flags |= E_CONTENT_EDITOR_FIND_WRAP_AROUND;
 
-       e_content_editor_find_controller_search (
-               dialog->priv->find_controller,
-               gtk_entry_get_text (GTK_ENTRY (dialog->priv->search_entry)),
-               flags);
+       return flags;
+}
+
+static void
+search (EHTMLEditorReplaceDialog *dialog)
+{
+
+       e_content_editor_find (
+               dialog->priv->cnt_editor,
+               replace_dialog_get_find_flags (dialog),
+               gtk_entry_get_text (GTK_ENTRY (dialog->priv->search_entry)));
 }
 
 static void
 html_editor_replace_dialog_skip_cb (EHTMLEditorReplaceDialog *dialog)
 {
-       e_content_editor_find_controller_search_next (dialog->priv->find_controller);
+       search (dialog);
 }
 
 static void
@@ -143,28 +138,17 @@ html_editor_replace_dialog_replace_cb (EHTMLEditorReplaceDialog *dialog)
        replace_occurance (dialog);
 
        /* Jump to next matching word */
-       e_content_editor_find_controller_search_next (dialog->priv->find_controller);
+       search (dialog);
 }
 
 static void
 html_editor_replace_dialog_replace_all_cb (EHTMLEditorReplaceDialog *dialog)
 {
-       guint32 flags = 0;
-
-       if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->case_sensitive)))
-               flags |= E_CONTENT_EDITOR_FIND_CASE_INSENSITIVE;
-
-       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->backwards)))
-               flags |= E_CONTENT_EDITOR_FIND_BACKWARDS;
-
-       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->wrap)))
-               flags |= E_CONTENT_EDITOR_FIND_WRAP_AROUND;
-
-       e_content_editor_find_controller_replace_all (
-               dialog->priv->find_controller,
+       e_content_editor_replace_all (
+               dialog->priv->cnt_editor,
+               replace_dialog_get_find_flags (dialog),
                gtk_entry_get_text (GTK_ENTRY (dialog->priv->search_entry)),
-               gtk_entry_get_text (GTK_ENTRY (dialog->priv->replace_entry)),
-               flags);
+               gtk_entry_get_text (GTK_ENTRY (dialog->priv->replace_entry)));
 }
 
 static void
@@ -185,14 +169,9 @@ html_editor_replace_dialog_entry_changed (EHTMLEditorReplaceDialog *dialog)
 static void
 html_editor_replace_dialog_show (GtkWidget *widget)
 {
-       EContentEditor *cnt_editor;
-       EHTMLEditor *editor;
        EHTMLEditorReplaceDialog *dialog = E_HTML_EDITOR_REPLACE_DIALOG (widget);
 
-       editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
-       cnt_editor = e_html_editor_get_content_editor (editor);
-
-       e_content_editor_on_replace_dialog_open (cnt_editor);
+       e_content_editor_on_replace_dialog_open (dialog->priv->cnt_editor);
 
        gtk_widget_grab_focus (dialog->priv->search_entry);
        gtk_widget_hide (dialog->priv->result_label);
@@ -204,15 +183,9 @@ html_editor_replace_dialog_show (GtkWidget *widget)
 static void
 html_editor_replace_dialog_hide (GtkWidget *widget)
 {
-       EContentEditor *cnt_editor;
-       EHTMLEditor *editor;
        EHTMLEditorReplaceDialog *dialog = E_HTML_EDITOR_REPLACE_DIALOG (widget);
 
-       editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
-       cnt_editor = e_html_editor_get_content_editor (editor);
-
-       e_content_editor_find_controller_search_finish (dialog->priv->find_controller);
-       e_content_editor_on_spell_check_dialog_close (cnt_editor);
+       e_content_editor_on_replace_dialog_close (dialog->priv->cnt_editor);
 
        /* Chain up to parent implementation */
        GTK_WIDGET_CLASS (e_html_editor_replace_dialog_parent_class)->hide (widget);
@@ -224,28 +197,22 @@ html_editor_replace_dialog_constructed (GObject *object)
        EContentEditor *cnt_editor;
        EHTMLEditor *editor;
        EHTMLEditorReplaceDialog *dialog;
-       EContentEditorFindController *find_controller;
 
        dialog = E_HTML_EDITOR_REPLACE_DIALOG (object);
        dialog->priv = E_HTML_EDITOR_REPLACE_DIALOG_GET_PRIVATE (dialog);
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        cnt_editor = e_html_editor_get_content_editor (editor);
-       find_controller = e_content_editor_get_find_controller (cnt_editor);
-
-       dialog->priv->found_text_handler_id = g_signal_connect (
-               find_controller, "found-text",
-               G_CALLBACK (content_editor_find_controller_found_text_cb), dialog);
 
-       dialog->priv->failed_to_find_text_handler_id = g_signal_connect (
-               find_controller, "failed-to-find-text",
-               G_CALLBACK (content_editor_find_controller_failed_to_found_text_cb), dialog);
+       dialog->priv->find_done_handler_id = g_signal_connect (
+               cnt_editor, "find-done",
+               G_CALLBACK (content_editor_find_done_cb), dialog);
 
-       dialog->priv->replace_all_finished_handler_id = g_signal_connect (
-               find_controller, "replace-all-finished",
-               G_CALLBACK (content_editor_find_controller_replace_all_finished_cb), dialog);
+       dialog->priv->replace_all_done_handler_id = g_signal_connect (
+               cnt_editor, "replace-all-done",
+               G_CALLBACK (content_editor_replace_all_done_cb), dialog);
 
-       dialog->priv->find_controller = find_controller;
+       dialog->priv->cnt_editor = cnt_editor;
 
        G_OBJECT_CLASS (e_html_editor_replace_dialog_parent_class)->constructed (object);
 }
@@ -257,25 +224,18 @@ html_editor_replace_dialog_dispose (GObject *object)
 
        priv = E_HTML_EDITOR_REPLACE_DIALOG_GET_PRIVATE (object);
 
-       if (priv->found_text_handler_id > 0) {
-               g_signal_handler_disconnect (
-                       priv->find_controller,
-                       priv->found_text_handler_id);
-               priv->found_text_handler_id = 0;
-       }
-
-       if (priv->failed_to_find_text_handler_id > 0) {
+       if (priv->find_done_handler_id > 0) {
                g_signal_handler_disconnect (
-                       priv->find_controller,
-                       priv->failed_to_find_text_handler_id);
-               priv->failed_to_find_text_handler_id = 0;
+                       priv->cnt_editor,
+                       priv->find_done_handler_id);
+               priv->find_done_handler_id = 0;
        }
 
-       if (priv->replace_all_finished_handler_id > 0) {
+       if (priv->replace_all_done_handler_id > 0) {
                g_signal_handler_disconnect (
-                       priv->find_controller,
-                       priv->replace_all_finished_handler_id);
-               priv->replace_all_finished_handler_id = 0;
+                       priv->cnt_editor,
+                       priv->replace_all_done_handler_id);
+               priv->replace_all_done_handler_id = 0;
        }
 
        /* Chain up to parent's dispose() method. */
diff --git a/e-util/e-html-editor-spell-check-dialog.c b/e-util/e-html-editor-spell-check-dialog.c
index 510caea..e67da4a 100644
--- a/e-util/e-html-editor-spell-check-dialog.c
+++ b/e-util/e-html-editor-spell-check-dialog.c
@@ -221,7 +221,6 @@ html_editor_spell_check_dialog_replace_all (EHTMLEditorSpellCheckDialog *dialog)
 {
        EHTMLEditor *editor;
        EContentEditor *cnt_editor;
-       EContentEditorFindController *find_controller;
        GtkTreeModel *model;
        GtkTreeSelection *selection;
        GtkTreeIter iter;
@@ -235,14 +234,13 @@ html_editor_spell_check_dialog_replace_all (EHTMLEditorSpellCheckDialog *dialog)
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        cnt_editor = e_html_editor_get_content_editor (editor);
-       find_controller = e_content_editor_get_find_controller (cnt_editor);
 
-       e_content_editor_find_controller_replace_all (
-               find_controller,
-               dialog->priv->word,
-               replacement,
+       e_content_editor_replace_all (
+               cnt_editor,
                E_CONTENT_EDITOR_FIND_CASE_INSENSITIVE |
-               E_CONTENT_EDITOR_FIND_WRAP_AROUND);
+               E_CONTENT_EDITOR_FIND_WRAP_AROUND,
+               dialog->priv->word,
+               replacement);
 
        g_idle_add (html_editor_spell_check_dialog_next_idle_cb, g_object_ref (dialog));
 }
@@ -302,8 +300,15 @@ html_editor_spell_check_dialog_show (GtkWidget *widget)
 
        /* Select the first word or quit */
        if (html_editor_spell_check_dialog_next (dialog)) {
-               GTK_WIDGET_CLASS (e_html_editor_spell_check_dialog_parent_class)->
-                       show (widget);
+               EHTMLEditor *editor;
+               EContentEditor *cnt_editor;
+
+               editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
+               cnt_editor = e_html_editor_get_content_editor (editor);
+
+               e_content_editor_on_spell_check_dialog_open (cnt_editor);
+
+               GTK_WIDGET_CLASS (e_html_editor_spell_check_dialog_parent_class)->show (widget);
        }
 }
 
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 1e7b4fd..f531219 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -86,7 +86,6 @@
 #include <e-util/e-conflict-search-selector.h>
 #include <e-util/e-contact-store.h>
 #include <e-util/e-content-editor.h>
-#include <e-util/e-content-editor-find-controller.h>
 #include <e-util/e-content-editor-enums.h>
 #include <e-util/e-content-request.h>
 #include <e-util/e-data-capture.h>
diff --git a/modules/webkit-content-editor/Makefile.am b/modules/webkit-content-editor/Makefile.am
index ef7ea31..9e07957 100644
--- a/modules/webkit-content-editor/Makefile.am
+++ b/modules/webkit-content-editor/Makefile.am
@@ -17,9 +17,7 @@ module_webkit_content_editor_la_SOURCES = \
        e-webkit-editor-extension.c                     \
        e-webkit-editor-extension.h                     \
        e-webkit-content-editor.c                       \
-       e-webkit-content-editor.h                       \
-       e-webkit-content-editor-find-controller.c       \
-       e-webkit-content-editor-find-controller.h
+       e-webkit-content-editor.h
 
 module_webkit_content_editor_la_LIBADD = \
        $(top_builddir)/e-util/libevolution-util.la     \
diff --git a/modules/webkit-content-editor/e-webkit-content-editor.c 
b/modules/webkit-content-editor/e-webkit-content-editor.c
index e4dc946..a384265 100644
--- a/modules/webkit-content-editor/e-webkit-content-editor.c
+++ b/modules/webkit-content-editor/e-webkit-content-editor.c
@@ -19,7 +19,6 @@
 #endif
 
 #include "e-webkit-content-editor.h"
-#include "e-webkit-content-editor-find-controller.h"
 
 #include "web-extension/e-html-editor-web-extension-names.h"
 
@@ -64,16 +63,12 @@ enum {
 };
 
 enum {
-       POPUP_EVENT,
        COPY_CLIPBOARD,
        CUT_CLIPBOARD,
-       PASTE_CLIPBOARD,
-       PASTE_PRIMARY_CLIPBOARD,
-
        LAST_SIGNAL
 };
 
-static guint signals[LAST_SIGNAL] = { 0 };
+static guint signals[LAST_SIGNAL];
 
 struct _EWebKitContentEditorPrivate {
        GDBusProxy *web_extension;
@@ -130,10 +125,16 @@ struct _EWebKitContentEditorPrivate {
        EContentEditorContentFlags content_flags;
 
        ESpellChecker *spell_checker;
-       EContentEditorFindController *find_controller;
 
        gulong owner_change_primary_clipboard_cb_id;
        gulong owner_change_clipboard_cb_id;
+
+       WebKitFindController *find_controller; /* not referenced; set to non-NULL only if the search is in 
progress */
+       gboolean performing_replace_all;
+       guint replaced_count;
+       gchar *replace_with;
+       gulong found_text_handler_id;
+       gulong failed_to_find_text_handler_id;
 };
 
 static const GdkRGBA black = { 0, 0, 0, 1 };
@@ -446,7 +447,8 @@ web_extension_proxy_created_cb (GDBusProxy *proxy,
        dispatch_pending_operations (wk_editor);
 
        if (wk_editor->priv->emit_load_finished_when_extension_is_ready) {
-               g_signal_emit_by_name (E_CONTENT_EDITOR (wk_editor), "load-finished", 0);
+               e_content_editor_emit_load_finished (E_CONTENT_EDITOR (wk_editor));
+
                wk_editor->priv->emit_load_finished_when_extension_is_ready = FALSE;
        }
 }
@@ -612,16 +614,6 @@ webkit_content_editor_set_format_int (EWebKitContentEditor *wk_editor,
                NULL);
 }
 
-static EContentEditorFindController *
-webkit_content_editor_get_find_controller (EContentEditor *editor)
-{
-       EWebKitContentEditor *wk_editor;
-
-       wk_editor = E_WEBKIT_CONTENT_EDITOR (editor);
-
-       return wk_editor->priv->find_controller;
-}
-
 static void
 webkit_content_editor_set_format_string (EWebKitContentEditor *wk_editor,
                                          const gchar *format_name,
@@ -1783,16 +1775,13 @@ webkit_content_editor_copy (EContentEditor *editor)
 static void
 webkit_content_editor_paste (EContentEditor *editor)
 {
-       EWebKitContentEditor *wk_editor;
-       gboolean handled = FALSE;
+       gboolean handled;
 
-       wk_editor = E_WEBKIT_CONTENT_EDITOR (editor);
-
-       g_signal_emit_by_name (editor, "paste-clipboard", editor, &handled);
+       handled = e_content_editor_emit_paste_clipboard (editor);
 
        if (!handled)
                webkit_web_view_execute_editing_command (
-                       WEBKIT_WEB_VIEW (wk_editor), WEBKIT_EDITING_COMMAND_PASTE);
+                       WEBKIT_WEB_VIEW (editor), WEBKIT_EDITING_COMMAND_PASTE);
 
        /* FIXME
        e_html_editor_view_force_spell_check (view) */
@@ -2122,6 +2111,143 @@ webkit_content_editor_replace_caret_word (EContentEditor *editor,
 }
 
 static void
+webkit_content_editor_finish_search (EWebKitContentEditor *wk_editor)
+{
+       g_return_if_fail (E_IS_WEBKIT_CONTENT_EDITOR (wk_editor));
+
+       if (!wk_editor->priv->find_controller)
+               return;
+
+       webkit_find_controller_search_finish (wk_editor->priv->find_controller);
+
+       wk_editor->priv->performing_replace_all = FALSE;
+       wk_editor->priv->replaced_count = 0;
+       g_free (wk_editor->priv->replace_with);
+       wk_editor->priv->replace_with = NULL;
+
+       if (wk_editor->priv->found_text_handler_id) {
+               g_signal_handler_disconnect (wk_editor->priv->find_controller, 
wk_editor->priv->found_text_handler_id);
+               wk_editor->priv->found_text_handler_id = 0;
+       }
+
+       if (wk_editor->priv->failed_to_find_text_handler_id) {
+               g_signal_handler_disconnect (wk_editor->priv->find_controller, 
wk_editor->priv->failed_to_find_text_handler_id);
+               wk_editor->priv->failed_to_find_text_handler_id = 0;
+       }
+
+       wk_editor->priv->find_controller = NULL;
+}
+
+static guint32 /* WebKitFindOptions */
+find_flags_to_webkit_find_options (guint32 flags /* EContentEditorFindFlags */)
+{
+       guint32 options = 0;
+
+       if (flags & E_CONTENT_EDITOR_FIND_CASE_INSENSITIVE)
+               options |= WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE;
+
+       if (flags & E_CONTENT_EDITOR_FIND_WRAP_AROUND)
+               options |= WEBKIT_FIND_OPTIONS_WRAP_AROUND;
+
+       if (flags & E_CONTENT_EDITOR_FIND_MODE_BACKWARDS)
+               options |= WEBKIT_FIND_OPTIONS_BACKWARDS;
+
+       return options;
+}
+
+static void
+webkit_find_controller_found_text_cb (WebKitFindController *find_controller,
+                                      guint match_count,
+                                      EWebKitContentEditor *wk_editor)
+{
+       if (wk_editor->priv->performing_replace_all) {
+               if (!wk_editor->priv->replaced_count)
+                       wk_editor->priv->replaced_count = match_count;
+
+               /* Repeatedly search for 'word', then replace selection by
+                * 'replacement'. Repeat until there's at least one occurrence of
+                * 'word' in the document */
+               e_content_editor_insert_content (
+                       E_CONTENT_EDITOR (wk_editor),
+                       wk_editor->priv->replace_with,
+                       E_CONTENT_EDITOR_INSERT_TEXT_PLAIN);
+
+               webkit_find_controller_search_next (find_controller);
+       } else {
+               e_content_editor_emit_find_done (E_CONTENT_EDITOR (wk_editor), match_count);
+       }
+}
+
+static void
+webkit_find_controller_failed_to_find_text_cb (WebKitFindController *find_controller,
+                                               EWebKitContentEditor *wk_editor)
+{
+       if (wk_editor->priv->performing_replace_all) {
+               guint replaced_count = wk_editor->priv->replaced_count;
+
+               webkit_content_editor_finish_search (wk_editor);
+               e_content_editor_emit_replace_all_done (E_CONTENT_EDITOR (wk_editor), replaced_count);
+       } else {
+               e_content_editor_emit_find_done (E_CONTENT_EDITOR (wk_editor), 0);
+       }
+}
+
+static void
+webkit_content_editor_prepare_find_controller (EWebKitContentEditor *wk_editor)
+{
+       g_return_if_fail (E_IS_WEBKIT_CONTENT_EDITOR (wk_editor));
+       g_return_if_fail (wk_editor->priv->find_controller == NULL);
+
+       wk_editor->priv->find_controller = webkit_web_view_get_find_controller (WEBKIT_WEB_VIEW (wk_editor));
+
+       wk_editor->priv->found_text_handler_id = g_signal_connect (
+               wk_editor->priv->find_controller, "found-text",
+               G_CALLBACK (webkit_find_controller_found_text_cb), wk_editor);
+
+       wk_editor->priv->failed_to_find_text_handler_id = g_signal_connect (
+               wk_editor->priv->find_controller, "failed-to-find-text",
+               G_CALLBACK (webkit_find_controller_failed_to_find_text_cb), wk_editor);
+
+       wk_editor->priv->performing_replace_all = FALSE;
+       wk_editor->priv->replaced_count = 0;
+       g_free (wk_editor->priv->replace_with);
+       wk_editor->priv->replace_with = NULL;
+}
+
+static void
+webkit_content_editor_find (EContentEditor *editor,
+                           guint32 flags,
+                           const gchar *text)
+{
+       EWebKitContentEditor *wk_editor;
+       guint32 wk_options;
+       gboolean needs_init;
+
+       g_return_if_fail (E_IS_WEBKIT_CONTENT_EDITOR (editor));
+       g_return_if_fail (text != NULL);
+
+       wk_editor = E_WEBKIT_CONTENT_EDITOR (editor);
+
+       wk_options = find_flags_to_webkit_find_options (flags);
+
+       needs_init = !wk_editor->priv->find_controller;
+       if (needs_init) {
+               webkit_content_editor_prepare_find_controller (wk_editor);
+       } else {
+               needs_init = wk_options != webkit_find_controller_get_options 
(wk_editor->priv->find_controller) ||
+                       g_strcmp0 (text, webkit_find_controller_get_search_text 
(wk_editor->priv->find_controller)) != 0;
+       }
+
+       if (needs_init) {
+               webkit_find_controller_search (wk_editor->priv->find_controller, text, wk_options, G_MAXUINT);
+       } else if ((flags & E_CONTENT_EDITOR_FIND_PREVIOUS) != 0) {
+               webkit_find_controller_search_previous (wk_editor->priv->find_controller);
+       } else {
+               webkit_find_controller_search_next (wk_editor->priv->find_controller);
+       }
+}
+
+static void
 webkit_content_editor_selection_replace (EContentEditor *editor,
                                          const gchar *replacement)
 {
@@ -2143,6 +2269,34 @@ webkit_content_editor_selection_replace (EContentEditor *editor,
 }
 
 static void
+webkit_content_editor_replace_all (EContentEditor *editor,
+                                  guint32 flags,
+                                  const gchar *find_text,
+                                  const gchar *replace_with)
+{
+       EWebKitContentEditor *wk_editor;
+       guint32 wk_options;
+
+       g_return_if_fail (E_IS_WEBKIT_CONTENT_EDITOR (editor));
+       g_return_if_fail (find_text != NULL);
+       g_return_if_fail (replace_with != NULL);
+
+       wk_editor = E_WEBKIT_CONTENT_EDITOR (editor);
+       wk_options = find_flags_to_webkit_find_options (flags);
+
+       if (!wk_editor->priv->find_controller)
+               webkit_content_editor_prepare_find_controller (wk_editor);
+
+       g_free (wk_editor->priv->replace_with);
+       wk_editor->priv->replace_with = g_strdup (replace_with);
+
+       wk_editor->priv->performing_replace_all = TRUE;
+       wk_editor->priv->replaced_count = 0;
+
+       webkit_find_controller_search (wk_editor->priv->find_controller, find_text, wk_options, G_MAXUINT);
+}
+
+static void
 webkit_content_editor_selection_save (EContentEditor *editor)
 {
        EWebKitContentEditor *wk_editor;
@@ -4751,6 +4905,8 @@ webkit_content_editor_on_table_dialog_close (EContentEditor *editor)
 
        webkit_content_editor_call_simple_extension_function (
                wk_editor, "EHTMLEditorTableDialogSaveHistoryOnExit");
+
+       webkit_content_editor_finish_search (E_WEBKIT_CONTENT_EDITOR (editor));
 }
 
 static void
@@ -4761,6 +4917,7 @@ webkit_content_editor_on_spell_check_dialog_open (EContentEditor *editor)
 static void
 webkit_content_editor_on_spell_check_dialog_close (EContentEditor *editor)
 {
+       webkit_content_editor_finish_search (E_WEBKIT_CONTENT_EDITOR (editor));
 }
 
 static gchar *
@@ -4825,6 +4982,7 @@ webkit_content_editor_on_replace_dialog_open (EContentEditor *editor)
 static void
 webkit_content_editor_on_replace_dialog_close (EContentEditor *editor)
 {
+       webkit_content_editor_finish_search (E_WEBKIT_CONTENT_EDITOR (editor));
 }
 
 static void
@@ -4835,6 +4993,7 @@ webkit_content_editor_on_find_dialog_open (EContentEditor *editor)
 static void
 webkit_content_editor_on_find_dialog_close (EContentEditor *editor)
 {
+       webkit_content_editor_finish_search (E_WEBKIT_CONTENT_EDITOR (editor));
 }
 
 static void
@@ -4851,11 +5010,6 @@ webkit_content_editor_constructed (GObject *object)
        wk_editor = E_WEBKIT_CONTENT_EDITOR (object);
        web_view = WEBKIT_WEB_VIEW (wk_editor);
 
-       wk_editor->priv->find_controller = g_object_new (
-               E_TYPE_WEBKIT_CONTENT_EDITOR_FIND_CONTROLLER,
-               "webkit-content-editor", wk_editor,
-               NULL);
-
        /* Give spell check languages to WebKit */
        languages = e_spell_checker_list_active_languages (wk_editor->priv->spell_checker, NULL);
 
@@ -4991,8 +5145,9 @@ webkit_content_editor_dispose (GObject *object)
                priv->owner_change_primary_clipboard_cb_id = 0;
        }
 
+       webkit_content_editor_finish_search (E_WEBKIT_CONTENT_EDITOR (object));
+
        g_clear_object (&priv->web_extension);
-       g_clear_object (&priv->find_controller);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (e_webkit_content_editor_parent_class)->dispose (object);
@@ -5353,7 +5508,7 @@ webkit_content_editor_load_changed_cb (EWebKitContentEditor *wk_editor,
                return;
 
        if (wk_editor->priv->web_extension)
-               g_signal_emit_by_name (E_CONTENT_EDITOR (wk_editor), "load-finished", 0);
+               e_content_editor_emit_load_finished (E_CONTENT_EDITOR (wk_editor));
        else
                wk_editor->priv->emit_load_finished_when_extension_is_ready = TRUE;
 
@@ -5590,19 +5745,14 @@ webkit_content_editor_context_menu_cb (EWebKitContentEditor *wk_editor,
 {
        GVariant *result;
        EContentEditorNodeFlags flags = 0;
-       gboolean handled = FALSE;
+       gboolean handled;
 
        webkit_context_menu_remove_all (context_menu);
 
        if ((result = webkit_context_menu_get_user_data (context_menu)))
                flags = g_variant_get_int32 (result);
 
-       g_signal_emit_by_name (
-               E_CONTENT_EDITOR (wk_editor),
-               "context-menu-requested",
-               flags,
-               event,
-               &handled);
+       handled = e_content_editor_emit_context_menu_requested (E_CONTENT_EDITOR (wk_editor), flags, event);
 
        return handled;
 }
@@ -5629,8 +5779,7 @@ webkit_content_editor_button_press_event (GtkWidget *widget,
                /* Remember, that we are pasting primary clipboard to return
                 * correct value in e_html_editor_view_is_pasting_content_from_itself. */
                wk_editor->priv->pasting_primary_clipboard = TRUE;
-               g_signal_emit_by_name (E_CONTENT_EDITOR (widget), "paste-primary-clipboard", 0);
-               event_handled = TRUE;
+               event_handled = e_content_editor_emit_paste_primary_clipboard (E_CONTENT_EDITOR (widget));
        } else {
                event_handled = FALSE;
        }
@@ -5752,21 +5901,6 @@ e_webkit_content_editor_class_init (EWebKitContentEditorClass *class)
                object_class, PROP_UNDERLINE, "underline");
        g_object_class_override_property (
                object_class, PROP_SPELL_CHECKER, "spell-checker");
-
-       /**
-        * EWebkitContentEditor:popup-event
-        *
-        * Emitted whenever a context menu is requested.
-        */
-       signals[POPUP_EVENT] = g_signal_new (
-               "popup-event",
-               G_TYPE_FROM_CLASS (class),
-               G_SIGNAL_RUN_LAST,
-               G_STRUCT_OFFSET (EWebKitContentEditorClass, popup_event),
-               g_signal_accumulator_true_handled, NULL,
-               e_marshal_BOOLEAN__BOXED,
-               G_TYPE_BOOLEAN, 1,
-               GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
 }
 
 static void
@@ -5875,7 +6009,6 @@ e_webkit_content_editor_init (EWebKitContentEditor *wk_editor)
 static void
 e_webkit_content_editor_content_editor_init (EContentEditorInterface *iface)
 {
-       iface->get_find_controller = webkit_content_editor_get_find_controller;
        iface->insert_content = webkit_content_editor_insert_content;
        iface->get_content = webkit_content_editor_get_content;
        iface->insert_image = webkit_content_editor_insert_image;
@@ -5912,7 +6045,9 @@ e_webkit_content_editor_content_editor_init (EContentEditorInterface *iface)
        iface->selection_unindent = webkit_content_editor_selection_unindent;
 //     iface->create_link = webkit_content_editor_create_link;
        iface->selection_unlink = webkit_content_editor_selection_unlink;
+       iface->find = webkit_content_editor_find;
        iface->selection_replace = webkit_content_editor_selection_replace;
+       iface->replace_all = webkit_content_editor_replace_all;
        iface->selection_save = webkit_content_editor_selection_save;
        iface->selection_restore = webkit_content_editor_selection_restore;
        iface->selection_wrap = webkit_content_editor_selection_wrap;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]