[evolution/wip/webkit2] Fix the HT dialog and create a test for it



commit bd686b630cc52563bba7a370a8d94e1ab15a902f
Author: Tomas Popela <tpopela redhat com>
Date:   Tue Jul 19 17:40:14 2016 +0200

    Fix the HT dialog and create a test for it

 e-util/e-html-editor-hrule-dialog.c                |    6 +-
 e-util/test-html-editor-units.c                    |   15 +++++
 modules/webkit-editor/e-webkit-editor.c            |   29 ++++------
 .../web-extension/e-dialogs-dom-functions.c        |    6 +-
 .../web-extension/e-dialogs-dom-functions.h        |    4 +-
 .../web-extension/e-editor-web-extension.c         |   57 ++------------------
 6 files changed, 39 insertions(+), 78 deletions(-)
---
diff --git a/e-util/e-html-editor-hrule-dialog.c b/e-util/e-html-editor-hrule-dialog.c
index ead01f3..5dc6860 100644
--- a/e-util/e-html-editor-hrule-dialog.c
+++ b/e-util/e-html-editor-hrule-dialog.c
@@ -200,15 +200,15 @@ html_editor_hrule_dialog_show (GtkWidget *widget)
        EHTMLEditorHRuleDialog *dialog;
        EHTMLEditor *editor;
        EContentEditor *cnt_editor;
-       gboolean h_rule_found = FALSE;
+       gboolean created_new_h_rule = FALSE;
 
        dialog = E_HTML_EDITOR_HRULE_DIALOG (widget);
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        cnt_editor = e_html_editor_get_content_editor (editor);
 
-       h_rule_found = e_content_editor_on_h_rule_dialog_open (cnt_editor);
+       created_new_h_rule = e_content_editor_on_h_rule_dialog_open (cnt_editor);
 
-       if (h_rule_found) {
+       if (!created_new_h_rule) {
                html_editor_hrule_dialog_get_alignment (dialog);
                html_editor_hrule_dialog_get_size (dialog);
                html_editor_hrule_dialog_get_width (dialog);
diff --git a/e-util/test-html-editor-units.c b/e-util/test-html-editor-units.c
index 313fd1b..a2386d5 100644
--- a/e-util/test-html-editor-units.c
+++ b/e-util/test-html-editor-units.c
@@ -622,6 +622,20 @@ test_insert_link_typed_remove (TestFixture *fixture)
                g_test_fail ();
 }
 
+static void
+test_insert_hrule (TestFixture *fixture)
+{
+       if (!test_utils_run_simple_test (fixture,
+               "mode:html\n"
+               "type:text\n"
+               "action:insert-rule\n"
+               "seq:ttttt\n" /* Move to the Close button */
+               "type:\\n\n",
+               HTML_PREFIX "<p>text</p><hr align=\"left\" size=\"2\" noshade=\"\">" HTML_SUFFIX,
+               "text"))
+               g_test_fail ();
+}
+
 gint
 main (gint argc,
       gchar *argv[])
@@ -705,6 +719,7 @@ main (gint argc,
        add_test ("/insert/link/typed", test_insert_link_typed);
        add_test ("/insert/link/typed/change-description", test_insert_link_typed_change_description);
        add_test ("/insert/link/typed/remove", test_insert_link_typed_remove);
+       add_test ("/insert/h-rule", test_insert_hrule);
 
        #undef add_test
 
diff --git a/modules/webkit-editor/e-webkit-editor.c b/modules/webkit-editor/e-webkit-editor.c
index 1b8b4d7..b64404d 100644
--- a/modules/webkit-editor/e-webkit-editor.c
+++ b/modules/webkit-editor/e-webkit-editor.c
@@ -2517,7 +2517,7 @@ webkit_editor_on_h_rule_dialog_close (EContentEditor *editor)
        wk_editor = E_WEBKIT_EDITOR (editor);
 
        webkit_editor_call_simple_extension_function (
-               wk_editor, "EEditorHRuleDialogSaveHistoryOnExit");
+               wk_editor, "EEditorHRuleDialogOnClose");
 }
 
 static void
@@ -2656,24 +2656,20 @@ webkit_editor_h_rule_set_no_shade (EContentEditor *editor,
                return;
        }
 
-       g_dbus_proxy_call (
-               wk_editor->priv->web_extension,
-               "HRElementSetNoShade",
-               g_variant_new (
-                       "(tsb)", current_page_id (wk_editor), "-x-evo-current-hr", value),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       if (value)
+               webkit_editor_set_element_attribute (
+                       wk_editor, "#-x-evo-current-hr", "noshade", "");
+       else
+               webkit_editor_remove_element_attribute (
+                       wk_editor, "#-x-evo-current-hr", "noshade");
 }
 
 static gboolean
 webkit_editor_h_rule_get_no_shade (EContentEditor *editor)
 {
        EWebKitEditor *wk_editor;
-       gboolean value = FALSE;
        GVariant *result;
+       gboolean no_shade = FALSE;
 
        wk_editor = E_WEBKIT_EDITOR (editor);
        if (!wk_editor->priv->web_extension) {
@@ -2683,20 +2679,19 @@ webkit_editor_h_rule_get_no_shade (EContentEditor *editor)
 
        result = g_dbus_proxy_call_sync (
                wk_editor->priv->web_extension,
-               "HRElementGetNoShade",
-               g_variant_new (
-                       "(ts)", current_page_id (wk_editor), "-x-evo-current-hr"),
+               "ElementHasAttribute",
+               g_variant_new ("(tss)", current_page_id (wk_editor), "-x-evo-current-hr", "noshade"),
                G_DBUS_CALL_FLAGS_NONE,
                -1,
                NULL,
                NULL);
 
        if (result) {
-               g_variant_get (result, "(b)", &value);
+               g_variant_get (result, "(b)", &no_shade);
                g_variant_unref (result);
        }
 
-       return value;
+       return no_shade;
 }
 
 static void
diff --git a/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c 
b/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c
index 0731363..f678edd 100644
--- a/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c
+++ b/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c
@@ -457,7 +457,7 @@ get_current_hrule_element (WebKitDOMDocument *document)
 }
 
 gboolean
-e_dialogs_dom_hrule_find_hrule (EEditorPage *editor_page)
+e_dialogs_dom_h_rule_find_hrule (EEditorPage *editor_page)
 {
        EEditorUndoRedoManager *manager;
        gboolean created = FALSE;
@@ -521,7 +521,7 @@ e_dialogs_dom_hrule_find_hrule (EEditorPage *editor_page)
 }
 
 void
-e_dialogs_dom_save_history_on_exit (EEditorPage *editor_page)
+e_dialogs_dom_h_rule_dialog_on_close (EEditorPage *editor_page)
 {
        EEditorUndoRedoManager *manager;
        EEditorHistoryEvent *ev = NULL;
@@ -541,7 +541,7 @@ e_dialogs_dom_save_history_on_exit (EEditorPage *editor_page)
        ev->data.dom.to = webkit_dom_node_clone_node_with_error (
                WEBKIT_DOM_NODE (element), TRUE, NULL);
 
-       if (!webkit_dom_node_is_equal_node (ev->data.dom.from, ev->data.dom.to)) {
+       if (ev->data.dom.from && !webkit_dom_node_is_equal_node (ev->data.dom.from, ev->data.dom.to)) {
                e_editor_dom_selection_get_coordinates (editor_page, &ev->after.start.x, &ev->after.start.y, 
&ev->after.end.x, &ev->after.end.y);
        } else {
                e_editor_undo_redo_manager_remove_current_history_event (manager);
diff --git a/modules/webkit-editor/web-extension/e-dialogs-dom-functions.h 
b/modules/webkit-editor/web-extension/e-dialogs-dom-functions.h
index 5e3ae4c..1e5188f 100644
--- a/modules/webkit-editor/web-extension/e-dialogs-dom-functions.h
+++ b/modules/webkit-editor/web-extension/e-dialogs-dom-functions.h
@@ -66,8 +66,8 @@ void          e_dialogs_dom_cell_set_element_bg_color
 
 /* ******************** HRule Dialog ***************** */
 
-gboolean       e_dialogs_dom_hrule_find_hrule  (EEditorPage *editor_page);
-void           e_dialogs_dom_save_history_on_exit
+gboolean       e_dialogs_dom_h_rule_find_hrule (EEditorPage *editor_page);
+void           e_dialogs_dom_h_rule_dialog_on_close
                                                (EEditorPage *editor_page);
 
 /* ******************** Image Dialog ***************** */
diff --git a/modules/webkit-editor/web-extension/e-editor-web-extension.c 
b/modules/webkit-editor/web-extension/e-editor-web-extension.c
index 6a0e0df..ab9591b 100644
--- a/modules/webkit-editor/web-extension/e-editor-web-extension.c
+++ b/modules/webkit-editor/web-extension/e-editor-web-extension.c
@@ -200,19 +200,9 @@ static const gchar *introspection_xml =
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='b' name='created_new_hr' direction='out'/>"
 "    </method>"
-"    <method name='EEditorHRuleDialogSaveHistoryOnExit'>"
+"    <method name='EEditorHRuleDialogOnClose'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "    </method>"
-"    <method name='HRElementSetNoShade'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='b' name='value' direction='in'/>"
-"    </method>"
-"    <method name='HRElementGetNoShade'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='b' name='value' direction='out'/>"
-"    </method>"
 "<!-- ********************************************************* -->"
 "<!--     Functions that are used in EEditorImageDialog     -->"
 "<!-- ********************************************************* -->"
@@ -991,59 +981,20 @@ handle_method_call (GDBusConnection *connection,
                if (!editor_page)
                        goto error;
 
-               created_new_hr = e_dialogs_dom_hrule_find_hrule (editor_page);
+               created_new_hr = e_dialogs_dom_h_rule_find_hrule (editor_page);
 
                g_dbus_method_invocation_return_value (
                        invocation, g_variant_new ("(b)", created_new_hr));
-       } else if (g_strcmp0 (method_name, "EEditorHRuleDialogSaveHistoryOnExit") == 0) {
+       } else if (g_strcmp0 (method_name, "EEditorHRuleDialogOnClose") == 0) {
                g_variant_get (parameters, "(t)", &page_id);
 
                editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
                if (!editor_page)
                        goto error;
 
-               e_dialogs_dom_save_history_on_exit (editor_page);
+               e_dialogs_dom_h_rule_dialog_on_close (editor_page);
 
                g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "HRElementSetNoShade") == 0) {
-               gboolean value = FALSE;
-               const gchar *element_id;
-               WebKitDOMElement *element;
-
-               g_variant_get (
-                       parameters, "(t&sb)", &page_id, &element_id, &value);
-
-               editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
-               if (!editor_page)
-                       goto error;
-
-               document = e_editor_page_get_document (editor_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       webkit_dom_html_hr_element_set_no_shade (
-                               WEBKIT_DOM_HTML_HR_ELEMENT (element), value);
-
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "HRElementGetNoShade") == 0) {
-               gboolean value = FALSE;
-               const gchar *element_id;
-               WebKitDOMElement *element;
-
-               g_variant_get (
-                       parameters, "(t&s)", &page_id, &element_id);
-
-               editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
-               if (!editor_page)
-                       goto error;
-
-               document = e_editor_page_get_document (editor_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       value = webkit_dom_html_hr_element_get_no_shade (
-                               WEBKIT_DOM_HTML_HR_ELEMENT (element));
-
-               g_dbus_method_invocation_return_value (
-                       invocation, g_variant_new ("(b)", value));
        } else if (g_strcmp0 (method_name, "EEditorImageDialogMarkImage") == 0) {
                g_variant_get (parameters, "(t)", &page_id);
 


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