[evolution/wip/webkit2] Pressing the Return key in the image wrapper will duplicate the image wrapper structure



commit 197f1c19d1a33f982423be32c8c1de1884b0e4fd
Author: Tomas Popela <tpopela redhat com>
Date:   Thu Mar 3 17:04:14 2016 +0100

    Pressing the Return key in the image wrapper will duplicate the image wrapper structure

 .../e-html-editor-selection-dom-functions.c        |    7 --
 .../composer/e-html-editor-view-dom-functions.c    |   85 ++++++++++++++++++++
 2 files changed, 85 insertions(+), 7 deletions(-)
---
diff --git a/web-extensions/composer/e-html-editor-selection-dom-functions.c 
b/web-extensions/composer/e-html-editor-selection-dom-functions.c
index 331d516..bdf7612 100644
--- a/web-extensions/composer/e-html-editor-selection-dom-functions.c
+++ b/web-extensions/composer/e-html-editor-selection-dom-functions.c
@@ -1605,13 +1605,6 @@ dom_selection_save (WebKitDOMDocument *document)
                        webkit_dom_node_get_first_child (container),
                        NULL);
                goto insert_end_marker;
-       } else if (element_has_class (WEBKIT_DOM_ELEMENT (container), "-x-evo-resizable-wrapper")) {
-               marker_node = webkit_dom_node_insert_before (
-                       parent_node,
-                       WEBKIT_DOM_NODE (start_marker),
-                       webkit_dom_node_get_next_sibling (container),
-                       NULL);
-               goto insert_end_marker;
        } else if (WEBKIT_DOM_IS_HTML_TABLE_CELL_ELEMENT (container)) {
                marker_node = webkit_dom_node_insert_before (
                        container,
diff --git a/web-extensions/composer/e-html-editor-view-dom-functions.c 
b/web-extensions/composer/e-html-editor-view-dom-functions.c
index b44c71e..8626e4c 100644
--- a/web-extensions/composer/e-html-editor-view-dom-functions.c
+++ b/web-extensions/composer/e-html-editor-view-dom-functions.c
@@ -564,6 +564,7 @@ get_parent_block_node_from_child (WebKitDOMNode *node)
            element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-quoted") ||
            element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-quote-character") ||
            element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-signature") ||
+           element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-resizable-wrapper") ||
            WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (parent) ||
            element_has_tag (WEBKIT_DOM_ELEMENT (parent), "b") ||
            element_has_tag (WEBKIT_DOM_ELEMENT (parent), "i") ||
@@ -9037,6 +9038,87 @@ selection_is_in_empty_list_item (WebKitDOMNode *selection_start_marker)
        return TRUE;
 }
 
+static gboolean
+return_pressed_in_image_wrapper (WebKitDOMDocument *document,
+                                EHTMLEditorWebExtension *extension)
+{
+       EHTMLEditorHistoryEvent *ev = NULL;
+       EHTMLEditorUndoRedoManager *manager;
+       WebKitDOMDocumentFragment *fragment;
+       WebKitDOMElement *selection_start_marker;
+       WebKitDOMNode *parent, *block, *clone;
+
+       if (!dom_selection_is_collapsed (document))
+               return FALSE;
+
+       dom_selection_save (document);
+
+       selection_start_marker = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-start-marker");
+
+       parent = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (selection_start_marker));
+       if (!element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-resizable-wrapper")) {
+               dom_selection_restore (document);
+               return FALSE;
+       }
+
+       manager = e_html_editor_web_extension_get_undo_redo_manager (extension);
+
+       if (!e_html_editor_undo_redo_manager_is_operation_in_progress (manager)) {
+               ev = g_new0 (EHTMLEditorHistoryEvent, 1);
+               ev->type = HISTORY_INPUT;
+
+               dom_selection_get_coordinates (
+                       document,
+                       &ev->before.start.x,
+                       &ev->before.start.y,
+                       &ev->before.end.x,
+                       &ev->before.end.y);
+
+               fragment = webkit_dom_document_create_document_fragment (document);
+
+               g_object_set_data (
+                       G_OBJECT (fragment), "history-return-key", GINT_TO_POINTER (1));
+       }
+
+       block = get_parent_block_node_from_child (
+               WEBKIT_DOM_NODE (selection_start_marker));
+
+       clone = webkit_dom_node_clone_node (block, FALSE);
+       webkit_dom_node_append_child (
+               clone, WEBKIT_DOM_NODE (webkit_dom_document_create_element (document, "br", NULL)), NULL);
+
+       webkit_dom_node_insert_before (
+               webkit_dom_node_get_parent_node (block),
+               clone,
+               block,
+               NULL);
+
+       if (ev) {
+               webkit_dom_node_append_child (
+                       WEBKIT_DOM_NODE (fragment),
+                       webkit_dom_node_clone_node (clone, TRUE),
+                       NULL);
+
+               dom_selection_get_coordinates (
+                       document,
+                       &ev->after.start.x,
+                       &ev->after.start.y,
+                       &ev->after.end.x,
+                       &ev->after.end.y);
+
+               ev->data.fragment = fragment;
+
+               e_html_editor_undo_redo_manager_insert_history_event (manager, ev);
+       }
+
+       e_html_editor_web_extension_set_content_changed (extension);
+
+       dom_selection_restore (document);
+
+       return TRUE;
+}
+
 gboolean
 return_pressed_in_empty_list_item (WebKitDOMDocument *document,
                                   EHTMLEditorWebExtension *extension)
@@ -9258,6 +9340,9 @@ key_press_event_process_return_key (WebKitDOMDocument *document,
        if (return_pressed_in_empty_list_item (document, extension))
                return TRUE;
 
+       if (return_pressed_in_image_wrapper (document, extension))
+               return TRUE;
+
        return FALSE;
 }
 


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