[evolution/wip/webkit2] Change the Normal block DOM structure
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit2] Change the Normal block DOM structure
- Date: Fri, 18 Mar 2016 11:56:43 +0000 (UTC)
commit 67a824fb6c3a799fbf7e8c7635bf7f5001cf12cf
Author: Tomas Popela <tpopela redhat com>
Date: Fri Mar 18 12:52:24 2016 +0100
Change the Normal block DOM structure
From div.-x-evo-paragraph to p[data-evo-paragraph]. This will allow us to quickly
identify the blocks as there will be no need to parse the CSS classes as we can
later easily use the WEBKIT_DOM_IS_HTML_PARAHRAPH_ELEMENT macro.
.../composer/e-composer-private-dom-functions.c | 10 ++--
.../e-html-editor-selection-dom-functions.c | 34 +++++-----
.../composer/e-html-editor-undo-redo-manager.c | 3 +-
.../composer/e-html-editor-view-dom-functions.c | 70 ++++++++++++++++----
web-extensions/e-dom-utils.c | 1 +
5 files changed, 79 insertions(+), 39 deletions(-)
---
diff --git a/web-extensions/composer/e-composer-private-dom-functions.c
b/web-extensions/composer/e-composer-private-dom-functions.c
index f39e10e..c83f7f2 100644
--- a/web-extensions/composer/e-composer-private-dom-functions.c
+++ b/web-extensions/composer/e-composer-private-dom-functions.c
@@ -116,7 +116,7 @@ composer_move_caret (WebKitDOMDocument *document,
gboolean has_paragraphs_in_body = TRUE;
WebKitDOMElement *element, *signature;
WebKitDOMHTMLElement *body;
- WebKitDOMHTMLCollection *paragraphs;
+ WebKitDOMNodeList *paragraphs;
is_message_from_draft = e_html_editor_web_extension_is_message_from_draft (extension);
is_message_from_edit_as_new =
@@ -152,11 +152,11 @@ composer_move_caret (WebKitDOMDocument *document,
webkit_dom_element_set_attribute (
WEBKIT_DOM_ELEMENT (body), "data-new-message", "", NULL);
- paragraphs = webkit_dom_document_get_elements_by_class_name_as_html_collection (document,
"-x-evo-paragraph");
+ paragraphs = webkit_dom_document_query_selector_all (document, "[data-evo-paragraph]", NULL);
signature = webkit_dom_document_query_selector (document, ".-x-evo-signature-wrapper", NULL);
/* Situation when wrapped paragraph is just in signature and not in message body */
- if (webkit_dom_html_collection_get_length (paragraphs) == 1)
- if (signature && webkit_dom_element_query_selector (signature, ".-x-evo-paragraph", NULL))
+ if (webkit_dom_node_list_get_length (paragraphs) == 1)
+ if (signature && webkit_dom_element_query_selector (signature, "[data-evo-paragraph]", NULL))
has_paragraphs_in_body = FALSE;
/*
@@ -183,7 +183,7 @@ composer_move_caret (WebKitDOMDocument *document,
NULL);
}
- if (webkit_dom_html_collection_get_length (paragraphs) == 0)
+ if (webkit_dom_node_list_get_length (paragraphs) == 0)
has_paragraphs_in_body = FALSE;
element = webkit_dom_document_get_element_by_id (document, "-x-evo-input-start");
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 08d3b5b..5fd4e70 100644
--- a/web-extensions/composer/e-html-editor-selection-dom-functions.c
+++ b/web-extensions/composer/e-html-editor-selection-dom-functions.c
@@ -505,7 +505,7 @@ dom_set_paragraph_style (WebKitDOMDocument *document,
gint word_wrap_length = set_word_wrap_length (extension, width);
WebKitDOMNode *parent;
- element_add_class (element, "-x-evo-paragraph");
+ webkit_dom_element_set_attribute (element, "data-evo-paragraph", "", NULL);
/* Don't set the alignment for nodes as they are handled separately. */
if (!node_is_list (WEBKIT_DOM_NODE (element))) {
@@ -680,7 +680,7 @@ indent_block (WebKitDOMDocument *document,
}
/* Remove style and let the paragraph inherit it from parent */
- if (element_has_class (WEBKIT_DOM_ELEMENT (block), "-x-evo-paragraph"))
+ if (webkit_dom_element_has_attribute (WEBKIT_DOM_ELEMENT (block), "data-evo-paragraph"))
webkit_dom_element_remove_attribute (
WEBKIT_DOM_ELEMENT (block), "style");
@@ -876,7 +876,7 @@ do_format_change_list_to_block (WebKitDOMDocument *document,
node = WEBKIT_DOM_NODE (element);
- if (element_has_class (element, "-x-evo-paragraph"))
+ if (webkit_dom_element_has_attribute (element, "data-evo-paragraph"))
final_width = e_html_editor_web_extension_get_word_wrap_length
(extension) -
SPACES_PER_INDENTATION * level;
@@ -1064,7 +1064,7 @@ dom_selection_indent (WebKitDOMDocument *document,
goto next;
}
- if (element_has_class (WEBKIT_DOM_ELEMENT (block), "-x-evo-paragraph")) {
+ if (webkit_dom_element_has_attribute (WEBKIT_DOM_ELEMENT (block),
"data-evo-paragraph")) {
level = get_indentation_level (WEBKIT_DOM_ELEMENT (block));
final_width = word_wrap_length - SPACES_PER_INDENTATION * (level + 1);
@@ -1097,7 +1097,7 @@ dom_selection_indent (WebKitDOMDocument *document,
}
}
- if (element_has_class (WEBKIT_DOM_ELEMENT (block), "-x-evo-paragraph")) {
+ if (webkit_dom_element_has_attribute (WEBKIT_DOM_ELEMENT (block),
"data-evo-paragraph")) {
level = get_indentation_level (
WEBKIT_DOM_ELEMENT (block_to_process));
@@ -1277,7 +1277,7 @@ unindent_block (WebKitDOMDocument *document,
}
}
- if (level == 1 && element_has_class (WEBKIT_DOM_ELEMENT (node_clone), "-x-evo-paragraph")) {
+ if (level == 1 && webkit_dom_element_has_attribute (WEBKIT_DOM_ELEMENT (node_clone),
"data-evo-paragraph")) {
dom_set_paragraph_style (
document, extension, WEBKIT_DOM_ELEMENT (node_clone), word_wrap_length, 0,
"");
element_add_class (
@@ -2811,8 +2811,9 @@ wrap_lines (WebKitDOMDocument *document,
WebKitDOMElement *element;
/* Create a wrapper DIV and put the processed content into it */
- element = webkit_dom_document_create_element (document, "DIV", NULL);
- element_add_class (element, "-x-evo-paragraph");
+ element = webkit_dom_document_create_element (document, "p", NULL);
+ webkit_dom_element_set_attribute (
+ element, "data-evo-paragraph", "", NULL);
webkit_dom_node_append_child (
WEBKIT_DOM_NODE (element),
WEBKIT_DOM_NODE (start_node),
@@ -2950,7 +2951,7 @@ dom_get_paragraph_element (WebKitDOMDocument *document,
{
WebKitDOMElement *element;
- element = webkit_dom_document_create_element (document, "DIV", NULL);
+ element = webkit_dom_document_create_element (document, "p", NULL);
dom_set_paragraph_style (document, extension, element, width, offset, "");
return element;
@@ -3080,7 +3081,7 @@ dom_selection_wrap (WebKitDOMDocument *document,
/* Don't try to wrap the 'Normal' blocks as they are already wrapped and*/
/* also skip blocks that we already wrapped with this function. */
- if ((!html_mode && element_has_class (WEBKIT_DOM_ELEMENT (block), "-x-evo-paragraph")) ||
+ if ((!html_mode && webkit_dom_element_has_attribute (WEBKIT_DOM_ELEMENT (block),
"data-evo-paragraph")) ||
webkit_dom_element_has_attribute (WEBKIT_DOM_ELEMENT (block), "data-user-wrapped")) {
block = next_block;
continue;
@@ -3136,7 +3137,7 @@ dom_wrap_paragraphs_in_document (WebKitDOMDocument *document,
gint ii, length;
list = webkit_dom_document_query_selector_all (
- document, "div.-x-evo-paragraph:not(#-x-evo-input-start)", NULL);
+ document, "[data-evo-paragraph]:not(#-x-evo-input-start)", NULL);
length = webkit_dom_node_list_get_length (list);
@@ -4960,16 +4961,13 @@ dom_selection_get_block_format (WebKitDOMDocument *document,
else {
WebKitDOMNode *block = get_block_node (range);
- if (WEBKIT_DOM_IS_HTML_DIV_ELEMENT (block) ||
- element_has_class (WEBKIT_DOM_ELEMENT (block), "-x-evo-paragraph"))
+ if (WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT (block) ||
+ webkit_dom_element_has_attribute (WEBKIT_DOM_ELEMENT (block),
"data-evo-paragraph"))
result = E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_PARAGRAPH;
else {
/* Paragraphs inside quote */
- if ((element = dom_node_find_parent_element (node, "DIV")) != NULL)
- if (element_has_class (element, "-x-evo-paragraph"))
- result = E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_PARAGRAPH;
- else
- result = E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_BLOCKQUOTE;
+ if ((element = dom_node_find_parent_element (node, "P")) != NULL)
+ result = E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_PARAGRAPH;
else
result = E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_BLOCKQUOTE;
}
diff --git a/web-extensions/composer/e-html-editor-undo-redo-manager.c
b/web-extensions/composer/e-html-editor-undo-redo-manager.c
index 7498a64..e56301c 100644
--- a/web-extensions/composer/e-html-editor-undo-redo-manager.c
+++ b/web-extensions/composer/e-html-editor-undo-redo-manager.c
@@ -543,8 +543,7 @@ undo_delete (WebKitDOMDocument *document,
if (WEBKIT_DOM_IS_ELEMENT (first_child) &&
!(WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (first_child) ||
WEBKIT_DOM_IS_HTML_PRE_ELEMENT (first_child) ||
- (WEBKIT_DOM_IS_HTML_DIV_ELEMENT (first_child) &&
- element_has_class (WEBKIT_DOM_ELEMENT (first_child), "-x-evo-paragraph"))))
+ WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT (first_child)))
single_block = TRUE;
}
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 03542e4..dadc008 100644
--- a/web-extensions/composer/e-html-editor-view-dom-functions.c
+++ b/web-extensions/composer/e-html-editor-view-dom-functions.c
@@ -602,7 +602,8 @@ wrap_and_quote_element (WebKitDOMDocument *document,
dom_remove_quoting_from_element (element);
dom_remove_wrapping_from_element (element);
- if (element_has_class (element, "-x-evo-paragraph")) {
+ if (WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT (element) &&
+ webkit_dom_element_has_attribute (element, "data-evo-paragraph")) {
gint word_wrap_length, length;
word_wrap_length = e_html_editor_web_extension_get_word_wrap_length (extension);
@@ -1917,9 +1918,9 @@ fix_paragraph_structure_after_pressing_enter (WebKitDOMDocument *document,
WebKitDOMNodeList *list;
/* When pressing Enter on empty line in the list (or after heading elements)
- * WebKit will end thatlist and inserts <div><br></div> so mark it for wrapping. */
+ * WebKit will end that list and inserts <div><br></div> so mark it for wrapping. */
list = webkit_dom_document_query_selector_all (
- document, "body > div:not(.-x-evo-paragraph) > br", NULL);
+ document, "body > div > br", NULL);
length = webkit_dom_node_list_get_length (list);
for (ii = 0; ii < length; ii++) {
@@ -2777,11 +2778,14 @@ body_input_event_process (WebKitDOMDocument *document,
g_free (text);
parent = webkit_dom_node_get_parent_node (node);
- if ((WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT (parent) ||
- WEBKIT_DOM_IS_HTML_DIV_ELEMENT (parent)) &&
- !element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-paragraph")) {
+ if (WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT (parent) &&
+ !webkit_dom_element_has_attribute (WEBKIT_DOM_ELEMENT (parent), "data-evo-paragraph")) {
if (html_mode)
- element_add_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-paragraph");
+ webkit_dom_element_set_attribute (
+ WEBKIT_DOM_ELEMENT (parent),
+ "data-evo-paragraph",
+ "",
+ NULL);
else
dom_set_paragraph_style (
document, extension, WEBKIT_DOM_ELEMENT (parent), -1, 0, "");
@@ -3223,7 +3227,7 @@ body_key_up_event_process_backspace_or_delete (WebKitDOMDocument *document,
WEBKIT_DOM_NODE (selection_start_marker)));
dom_remove_quoting_from_element (block);
- if (element_has_class (block, "-x-evo-paragraph")) {
+ if (webkit_dom_element_has_attribute (block, "data-evo-paragraph")) {
gint length, word_wrap_length;
word_wrap_length = e_html_editor_web_extension_get_word_wrap_length (extension);
@@ -5164,7 +5168,7 @@ quote_plain_text_elements_after_wrapping_in_document (WebKitDOMDocument *documen
/* Also quote the PRE elements as well. */
list = webkit_dom_document_query_selector_all (
- document, "blockquote[type=cite] > div.-x-evo-paragraph, blockquote[type=cite] > pre", NULL);
+ document, "blockquote[type=cite] > p[data-evo-paragraph], blockquote[type=cite] > pre", NULL);
length = webkit_dom_node_list_get_length (list);
for (ii = 0; ii < length; ii++) {
@@ -5380,7 +5384,7 @@ dom_convert_content (WebKitDOMDocument *document,
/* Remove all previously inserted paragraphs. */
list = webkit_dom_document_query_selector_all (
- document, ".-x-evo-paragraph:not([data-headers])", NULL);
+ document, "p[data-evo-paragraph]:not([data-headers])", NULL);
length = webkit_dom_node_list_get_length (list);
for (ii = 0; ii < length; ii++) {
WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
@@ -6866,7 +6870,7 @@ process_elements (EHTMLEditorWebExtension *extension,
}
/* Leave paragraphs as they are */
- if (element_has_class (WEBKIT_DOM_ELEMENT (child), "-x-evo-paragraph")) {
+ if (webkit_dom_element_has_attribute (WEBKIT_DOM_ELEMENT (child), "data-evo-paragraph")) {
if (changing_mode && to_plain_text) {
content = webkit_dom_element_get_outer_html (
WEBKIT_DOM_ELEMENT (child));
@@ -7194,7 +7198,7 @@ toggle_paragraphs_style_in_element (WebKitDOMDocument *document,
WebKitDOMNodeList *paragraphs;
paragraphs = webkit_dom_element_query_selector_all (
- element, ":not(td) > .-x-evo-paragraph", NULL);
+ element, ":not(td) > [data-evo-paragraph]", NULL);
length = webkit_dom_node_list_get_length (paragraphs);
@@ -7426,7 +7430,7 @@ dom_process_content_for_plain_text (WebKitDOMDocument *document,
}
paragraphs = webkit_dom_element_query_selector_all (
- WEBKIT_DOM_ELEMENT (source), ".-x-evo-paragraph", NULL);
+ WEBKIT_DOM_ELEMENT (source), "[data-evo-paragraph]", NULL);
length = webkit_dom_node_list_get_length (paragraphs);
for (ii = 0; ii < length; ii++) {
@@ -7689,7 +7693,7 @@ wrap_paragraphs_in_quoted_content (WebKitDOMDocument *document,
WebKitDOMNodeList *paragraphs;
paragraphs = webkit_dom_document_query_selector_all (
- document, "blockquote[type=cite] > .-x-evo-paragraph", NULL);
+ document, "blockquote[type=cite] > [data-evo-paragraph]", NULL);
length = webkit_dom_node_list_get_length (paragraphs);
for (ii = 0; ii < length; ii++) {
@@ -7806,6 +7810,40 @@ change_cid_images_src_to_base64 (WebKitDOMDocument *document,
g_hash_table_remove_all (inline_images);
}
+static void
+adapt_to_editor_dom_changes (WebKitDOMDocument *document)
+{
+ WebKitDOMHTMLCollection *collection;
+ gint ii, length;
+
+ /* Normal block code div.-x-evo-paragraph replaced by p[data-evo-paragraph] */
+ collection = webkit_dom_document_get_elements_by_class_name_as_html_collection (document,
"-x-evo-paragraph");
+ length = webkit_dom_html_collection_get_length (collection);
+ for (ii = 0; ii < length; ii++) {
+ WebKitDOMNode *node, *child;
+ WebKitDOMElement *element;
+ gchar *style;
+
+ node = webkit_dom_html_collection_item (collection, ii);
+ element = webkit_dom_document_create_element (document, "p", NULL);
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (node),
+ WEBKIT_DOM_NODE (element),
+ node,
+ NULL);
+
+ while ((child = webkit_dom_node_get_first_child (node)))
+ webkit_dom_node_append_child (WEBKIT_DOM_NODE (element), child, NULL);
+
+ style = webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (node), "style");
+ webkit_dom_element_set_attribute (element, "style", style, NULL);
+
+ remove_node (node);
+ g_object_unref (node);
+ }
+ g_object_unref (collection);
+}
+
void
dom_process_content_after_load (WebKitDOMDocument *document,
EHTMLEditorWebExtension *extension)
@@ -7819,6 +7857,8 @@ dom_process_content_after_load (WebKitDOMDocument *document,
* versions of Evolution or other MUAs */
dom_exec_command (
document, extension, E_HTML_EDITOR_VIEW_COMMAND_STYLE_WITH_CSS, "false");
+ dom_exec_command (
+ document, extension, E_HTML_EDITOR_VIEW_COMMAND_DEFAULT_PARAGRAPH_SEPARATOR, "p");
body = webkit_dom_document_get_body (document);
@@ -7864,6 +7904,8 @@ dom_process_content_after_load (WebKitDOMDocument *document,
return;
}
+ adapt_to_editor_dom_changes (document);
+
/* Make the quote marks non-selectable. */
dom_disable_quote_marks_select (document);
dom_set_links_active (document, FALSE);
diff --git a/web-extensions/e-dom-utils.c b/web-extensions/e-dom-utils.c
index 9c99686..8a873fd 100644
--- a/web-extensions/e-dom-utils.c
+++ b/web-extensions/e-dom-utils.c
@@ -1890,6 +1890,7 @@ get_parent_block_element (WebKitDOMNode *node)
return WEBKIT_DOM_ELEMENT (node);
while (parent &&
+ !WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT (parent) &&
!WEBKIT_DOM_IS_HTML_DIV_ELEMENT (parent) &&
!WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (parent) &&
!WEBKIT_DOM_IS_HTML_U_LIST_ELEMENT (parent) &&
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]