diff options
author | Tomas Popela <tpopela@redhat.com> | 2014-09-05 19:40:28 +0800 |
---|---|---|
committer | Tomas Popela <tpopela@redhat.com> | 2014-09-05 19:51:43 +0800 |
commit | f7953bea98be2ca5fe80bd4f49c622c7e05241fc (patch) | |
tree | dc47ca028f04685f12bdbb5e96a024c806b75129 /e-util | |
parent | fa55238d1ebf5e454d66858e7a523e8acc91ee65 (diff) | |
download | gsoc2013-evolution-f7953bea98be2ca5fe80bd4f49c622c7e05241fc.tar gsoc2013-evolution-f7953bea98be2ca5fe80bd4f49c622c7e05241fc.tar.gz gsoc2013-evolution-f7953bea98be2ca5fe80bd4f49c622c7e05241fc.tar.bz2 gsoc2013-evolution-f7953bea98be2ca5fe80bd4f49c622c7e05241fc.tar.lz gsoc2013-evolution-f7953bea98be2ca5fe80bd4f49c622c7e05241fc.tar.xz gsoc2013-evolution-f7953bea98be2ca5fe80bd4f49c622c7e05241fc.tar.zst gsoc2013-evolution-f7953bea98be2ca5fe80bd4f49c622c7e05241fc.zip |
EHTMLEditor - Use get_parent_block_node_from_child where possible
This will ensure that the right node (the block node) will be returned
when the selection is saved inside the bold/italic/underlined text or
inside the anchor.
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/e-html-editor-selection.c | 38 | ||||
-rw-r--r-- | e-util/e-html-editor-view.c | 47 |
2 files changed, 42 insertions, 43 deletions
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c index 017eb324f0..08bcd62040 100644 --- a/e-util/e-html-editor-selection.c +++ b/e-util/e-html-editor-selection.c @@ -1338,6 +1338,21 @@ set_block_alignment (WebKitDOMElement *element, } } +static WebKitDOMNode * +get_parent_block_node_from_child (WebKitDOMNode *node) +{ + WebKitDOMNode *parent = webkit_dom_node_get_parent_node (node); + + if (element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-temp-text-wrapper") || + WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (parent) || + element_has_tag (WEBKIT_DOM_ELEMENT (parent), "b") || + element_has_tag (WEBKIT_DOM_ELEMENT (parent), "i") || + element_has_tag (WEBKIT_DOM_ELEMENT (parent), "u")) + parent = webkit_dom_node_get_parent_node (parent); + + return parent; +} + /** * e_html_editor_selection_set_alignment: * @selection: an #EHTMLEditorSelection @@ -1395,7 +1410,7 @@ e_html_editor_selection_set_alignment (EHTMLEditorSelection *selection, return; } - block = webkit_dom_node_get_parent_node ( + block = get_parent_block_node_from_child ( WEBKIT_DOM_NODE (selection_start_marker)); while (block && !after_selection_end) { @@ -1549,11 +1564,7 @@ get_block_node (WebKitDOMRange *range) WebKitDOMNode *node; node = webkit_dom_range_get_common_ancestor_container (range, NULL); - if (!WEBKIT_DOM_IS_ELEMENT (node)) - node = WEBKIT_DOM_NODE (webkit_dom_node_get_parent_element (node)); - - if (element_has_class (WEBKIT_DOM_ELEMENT (node), "-x-evo-temp-text-wrapper")) - node = WEBKIT_DOM_NODE (webkit_dom_node_get_parent_element (node)); + node = get_parent_block_node_from_child (node); return node; } @@ -1806,21 +1817,6 @@ get_citation_level (WebKitDOMNode *node) return level; } -static WebKitDOMNode * -get_parent_block_node_from_child (WebKitDOMNode *node) -{ - WebKitDOMNode *parent = webkit_dom_node_get_parent_node (node); - - if (element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-temp-text-wrapper") || - WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (parent) || - element_has_tag (WEBKIT_DOM_ELEMENT (parent), "b") || - element_has_tag (WEBKIT_DOM_ELEMENT (parent), "i") || - element_has_tag (WEBKIT_DOM_ELEMENT (parent), "u")) - parent = webkit_dom_node_get_parent_node (parent); - - return parent; -} - static void format_change_block_to_block (EHTMLEditorSelection *selection, EHTMLEditorSelectionBlockFormat format, diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c index acd52806bc..72e4eca180 100644 --- a/e-util/e-html-editor-view.c +++ b/e-util/e-html-editor-view.c @@ -577,6 +577,21 @@ return_pressed_in_empty_line (EHTMLEditorSelection *selection, return FALSE; } +static WebKitDOMNode * +get_parent_block_node_from_child (WebKitDOMNode *node) +{ + WebKitDOMNode *parent = webkit_dom_node_get_parent_node (node); + + if (element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-temp-text-wrapper") || + WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (parent) || + element_has_tag (WEBKIT_DOM_ELEMENT (parent), "b") || + element_has_tag (WEBKIT_DOM_ELEMENT (parent), "i") || + element_has_tag (WEBKIT_DOM_ELEMENT (parent), "u")) + parent = webkit_dom_node_get_parent_node (parent); + + return parent; +} + static WebKitDOMElement * insert_new_line_into_citation (EHTMLEditorView *view, const gchar *html_to_insert) @@ -604,7 +619,7 @@ insert_new_line_into_citation (EHTMLEditorView *view, selection_start_marker = webkit_dom_document_get_element_by_id ( document, "-x-evo-selection-start-marker"); - current_block = webkit_dom_node_get_parent_node ( + current_block = get_parent_block_node_from_child ( WEBKIT_DOM_NODE (selection_start_marker)); block_clone = webkit_dom_node_clone_node (current_block, TRUE); @@ -910,8 +925,7 @@ body_input_event_cb (WebKitDOMElement *element, WebKitDOMElement *block; gboolean remove_quoting = FALSE; - block = webkit_dom_node_get_parent_element ( - WEBKIT_DOM_NODE (element)); + block = WEBKIT_DOM_ELEMENT (parent); if (webkit_dom_element_query_selector ( WEBKIT_DOM_ELEMENT (block), ".-x-evo-quoted", NULL)) { WebKitDOMNode *prev_sibling; @@ -927,10 +941,6 @@ body_input_event_cb (WebKitDOMElement *element, WEBKIT_DOM_ELEMENT (prev_sibling), "-x-evo-quoted"); } - if (element_has_class (block, "-x-evo-temp-text-wrapper")) - block = webkit_dom_node_get_parent_element ( - WEBKIT_DOM_NODE (block)); - content = webkit_dom_node_get_text_content (WEBKIT_DOM_NODE (block)); text_length = g_utf8_strlen (content, -1); g_free (content); @@ -1625,7 +1635,7 @@ emoticon_read_async_cb (GFile *file, } /* Sometimes selection end marker is in body. Move it into next sibling */ - selection_end_marker_parent = webkit_dom_node_get_parent_node ( + selection_end_marker_parent = get_parent_block_node_from_child ( WEBKIT_DOM_NODE (selection_end_marker)); if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (selection_end_marker_parent)) { webkit_dom_node_insert_before ( @@ -2302,17 +2312,13 @@ change_quoted_block_to_normal (EHTMLEditorView *view) if (!selection_start_marker || !selection_end_marker) return FALSE; - block = webkit_dom_node_get_parent_element ( - WEBKIT_DOM_NODE (selection_start_marker)); + block = WEBKIT_DOM_ELEMENT (get_parent_block_node_from_child ( + WEBKIT_DOM_NODE (selection_start_marker))); citation_level = get_citation_level ( WEBKIT_DOM_NODE (selection_start_marker), FALSE); if (selection_start_marker && citation_level > 0) { - if (element_has_class (block, "-x-evo-temp-text-wrapper")) - block = webkit_dom_node_get_parent_element ( - WEBKIT_DOM_NODE (block)); - if (webkit_dom_element_query_selector ( WEBKIT_DOM_ELEMENT (block), ".-x-evo-quoted", NULL)) { @@ -4444,7 +4450,7 @@ html_editor_view_insert_converted_html_into_selection (EHTMLEditorView *view, if (webkit_dom_node_is_same_node (first_paragraph, last_paragraph)) { WebKitDOMNode *child, *parent; - parent = webkit_dom_node_get_parent_node ( + parent = get_parent_block_node_from_child ( WEBKIT_DOM_NODE (selection_start_marker)); remove_quoting_from_element (WEBKIT_DOM_ELEMENT (parent)); @@ -4468,7 +4474,7 @@ html_editor_view_insert_converted_html_into_selection (EHTMLEditorView *view, } /* Pasting content parsed into the multiple paragraphs */ - parent = webkit_dom_node_get_parent_node ( + parent = get_parent_block_node_from_child ( WEBKIT_DOM_NODE (selection_start_marker)); remove_quoting_from_element (WEBKIT_DOM_ELEMENT (parent)); @@ -4489,7 +4495,7 @@ html_editor_view_insert_converted_html_into_selection (EHTMLEditorView *view, if (WEBKIT_DOM_IS_HTMLBR_ELEMENT (child)) remove_node (child); - parent = webkit_dom_node_get_parent_node ( + parent = get_parent_block_node_from_child ( WEBKIT_DOM_NODE (selection_end_marker)), child = webkit_dom_node_get_next_sibling ( @@ -4510,9 +4516,6 @@ html_editor_view_insert_converted_html_into_selection (EHTMLEditorView *view, e_html_editor_selection_get_caret_position_node (document), NULL); - if (element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-temp-text-wrapper")) - parent = webkit_dom_node_get_parent_node (parent); - /* Insert the paragraph with the end of the pasted text after * the paragraph that contains the selection end */ webkit_dom_node_insert_before ( @@ -4545,7 +4548,7 @@ html_editor_view_insert_converted_html_into_selection (EHTMLEditorView *view, remove_quoting_from_element (WEBKIT_DOM_ELEMENT (parent)); remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (parent)); - parent = webkit_dom_node_get_parent_node ( + parent = get_parent_block_node_from_child ( WEBKIT_DOM_NODE (selection_start_marker)); parent = WEBKIT_DOM_NODE (e_html_editor_selection_wrap_paragraph_length ( selection, WEBKIT_DOM_ELEMENT (parent), length)); @@ -4700,7 +4703,7 @@ html_editor_view_insert_converted_html_into_selection (EHTMLEditorView *view, selection_end_marker = webkit_dom_document_get_element_by_id ( document, "-x-evo-selection-end-marker"); - paragraph = webkit_dom_node_get_parent_node ( + paragraph = get_parent_block_node_from_child ( WEBKIT_DOM_NODE (selection_start_marker)); parent = webkit_dom_node_get_parent_node (paragraph); if (element_has_class (WEBKIT_DOM_ELEMENT (paragraph), "-x-evo-paragraph") && |