[evolution/wip/webkit-composer: 854/966] EEditorWidget: Don't remove block align when chaging composer mode



commit 4260eab05d62ca6196d4e05a857eb7704320805a
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Feb 28 12:38:23 2014 +0100

    EEditorWidget: Don't remove block align when chaging composer mode

 e-util/e-editor-selection.c |   10 +++++---
 e-util/e-editor-selection.h |    3 +-
 e-util/e-editor-widget.c    |   49 +++++++++++++++++++++++++++++++++++--------
 3 files changed, 48 insertions(+), 14 deletions(-)
---
diff --git a/e-util/e-editor-selection.c b/e-util/e-editor-selection.c
index 49b6de2..afebbfd 100644
--- a/e-util/e-editor-selection.c
+++ b/e-util/e-editor-selection.c
@@ -2266,7 +2266,7 @@ e_editor_selection_unindent (EEditorSelection *selection)
 
                if (level == 1 && element_has_class (WEBKIT_DOM_ELEMENT (node_clone), "-x-evo-paragraph"))
                        e_editor_selection_set_paragraph_style (
-                               selection, WEBKIT_DOM_ELEMENT (node_clone), word_wrap_length, 0);
+                               selection, WEBKIT_DOM_ELEMENT (node_clone), word_wrap_length, 0, "");
 
                /* Insert the unindented element */
                webkit_dom_node_insert_before (
@@ -4172,14 +4172,16 @@ void
 e_editor_selection_set_paragraph_style (EEditorSelection *selection,
                                         WebKitDOMElement *element,
                                         gint width,
-                                        gint offset)
+                                        gint offset,
+                                        const gchar *style_to_add)
 {
        gint word_wrap_length = (width == -1) ? selection->priv->word_wrap_length : width;
 
        webkit_dom_element_set_class_name (element, "-x-evo-paragraph");
        if (!is_in_html_mode (selection)) {
                gchar *style = g_strdup_printf (
-                       "width: %dch; word-wrap: normal;", (word_wrap_length + offset));
+                       "width: %dch; word-wrap: normal; %s",
+                       (word_wrap_length + offset), style_to_add);
                webkit_dom_element_set_attribute (element, "style", style, NULL);
                g_free (style);
        }
@@ -4194,7 +4196,7 @@ e_editor_selection_get_paragraph_element (EEditorSelection *selection,
        WebKitDOMElement *element;
 
        element = webkit_dom_document_create_element (document, "DIV", NULL);
-       e_editor_selection_set_paragraph_style (selection, element, width, offset);
+       e_editor_selection_set_paragraph_style (selection, element, width, offset, "");
 
        return element;
 }
diff --git a/e-util/e-editor-selection.h b/e-util/e-editor-selection.h
index f05ebc6..f537053 100644
--- a/e-util/e-editor-selection.h
+++ b/e-util/e-editor-selection.h
@@ -183,7 +183,8 @@ void                e_editor_selection_set_paragraph_style
                                                (EEditorSelection *selection,
                                                 WebKitDOMElement *element,
                                                 gint width,
-                                                gint offset);
+                                                gint offset,
+                                                const gchar *style_to_add);
 WebKitDOMElement *
                e_editor_selection_get_paragraph_element
                                                (EEditorSelection *selection,
diff --git a/e-util/e-editor-widget.c b/e-util/e-editor-widget.c
index c5fc8a5..9715279 100644
--- a/e-util/e-editor-widget.c
+++ b/e-util/e-editor-widget.c
@@ -333,7 +333,7 @@ body_input_event_cb (WebKitDOMElement *element,
                                e_editor_selection_set_paragraph_style (
                                        e_editor_widget_get_selection (editor_widget),
                                        WEBKIT_DOM_ELEMENT (parent),
-                                       -1, 0);
+                                       -1, 0, "");
                        }
                }
        }
@@ -3758,22 +3758,53 @@ toggle_paragraphs_style (EEditorWidget *widget)
        length = webkit_dom_node_list_get_length (paragraphs);
 
        for (ii = 0; ii < length; ii++) {
+               gchar *style;
+               const gchar *css_align;
                WebKitDOMNode *node = webkit_dom_node_list_item (paragraphs, ii);
 
-               if (html_mode)
-                       /* In HTML mode the paragraphs don't have width limit */
-                       webkit_dom_element_remove_attribute (
+               if (html_mode) {
+                       style = webkit_dom_element_get_attribute (
                                WEBKIT_DOM_ELEMENT (node), "style");
-               else {
+
+                       if ((css_align = strstr (style, "text-align: "))) {
+                               webkit_dom_element_set_attribute (
+                                       WEBKIT_DOM_ELEMENT (node),
+                                       "style",
+                                       g_str_has_prefix (css_align + 12, "center") ?
+                                               "text-align: center" :
+                                               "text-align: right",
+                                       NULL);
+                       } else {
+                               /* In HTML mode the paragraphs don't have width limit */
+                               webkit_dom_element_remove_attribute (
+                                       WEBKIT_DOM_ELEMENT (node), "style");
+                       }
+                       g_free (style);
+               } else {
                        WebKitDOMNode *parent;
 
                        parent = webkit_dom_node_get_parent_node (node);
                        /* If the paragraph is inside indented paragraph don't set
                         * the style as it will be inherited */
-                       if (!element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-indented"))
-                               /* In HTML mode the paragraphs have width limit */
-                               e_editor_selection_set_paragraph_style (
-                                       selection, WEBKIT_DOM_ELEMENT (node), -1, 0);
+                       if (!element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-indented")) {
+                               style = webkit_dom_element_get_attribute (
+                                       WEBKIT_DOM_ELEMENT (node), "style");
+
+                               if ((css_align = strstr (style, "text-align: "))) {
+                                       const gchar *style_to_add;
+
+                                       style_to_add = g_str_has_prefix (
+                                               css_align + 12, "center") ?
+                                                       "text-align: center;" :
+                                                       "text-align: right;";
+
+                                       /* In HTML mode the paragraphs have width limit */
+                                       e_editor_selection_set_paragraph_style (
+                                               selection, WEBKIT_DOM_ELEMENT (node),
+                                               -1, 0, style_to_add);
+                               }
+                               g_free (style);
+                       }
                }
        }
 }


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