[evolution/wip/mcrha/webkit-jsc-api: 229/292] Change formatting style notification



commit 88894d97e78ade6c06b3c38acae44f6e4f28c662
Author: Milan Crha <mcrha redhat com>
Date:   Thu Nov 7 18:25:30 2019 +0100

    Change formatting style notification

 data/webkit/e-editor.js                     |  60 ++++++----
 data/webkit/e-undo-redo.js                  |   8 +-
 src/e-util/e-html-editor.c                  |   4 +
 src/e-util/e-util-enums.h                   |  24 ----
 src/modules/webkit-editor/e-webkit-editor.c | 177 ++++++++++++++++++----------
 5 files changed, 163 insertions(+), 110 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 413a6e4a18..4ec5a08dc7 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -49,8 +49,13 @@ var EvoEditor = {
 
        TEXT_INDENT_SIZE : 3, /* in characters */
 
+       FORCE_NO : 0,
+       FORCE_YES : 1,
+       FORCE_MAYBE : 2,
+
        htmlFormat : false,
        storedSelection : null,
+       forceFormatStateUpdate : false,
        formattingState : {
                baseElement : null, // to avoid often notifications when just moving within the same node
                bold : false,
@@ -83,10 +88,12 @@ EvoEditor.maybeUpdateFormattingState = function(force)
        if (baseElem && baseElem.nodeType == baseElem.TEXT_NODE)
                baseElem = baseElem.parentElement;
 
-       if (!force && EvoEditor.formattingState.baseElement === baseElem) {
+       if (force == EvoEditor.FORCE_NO && EvoEditor.formattingState.baseElement === baseElem) {
                return;
        }
 
+       force = force == EvoEditor.FORCE_YES;
+
        EvoEditor.formattingState.baseElement = baseElem;
 
        var changes = {}, nchanges = 0, value, tmp, computedStyle;
@@ -103,7 +110,7 @@ EvoEditor.maybeUpdateFormattingState = function(force)
        tmp = computedStyle ? computedStyle.fontStyle : "";
 
        value = tmp == "italic" || tmp == "oblique";
-       if (value != EvoEditor.formattingState.italic) {
+       if (force || value != EvoEditor.formattingState.italic) {
                EvoEditor.formattingState.italic = value;
                changes["italic"] = value;
                nchanges++;
@@ -112,21 +119,21 @@ EvoEditor.maybeUpdateFormattingState = function(force)
        tmp = computedStyle ? computedStyle.webkitTextDecorationsInEffect : "";
 
        value = tmp.search("underline") >= 0;
-       if (value != EvoEditor.formattingState.underline) {
+       if (force || value != EvoEditor.formattingState.underline) {
                EvoEditor.formattingState.underline = value;
                changes["underline"] = value;
                nchanges++;
        }
 
        value = tmp.search("line-through") >= 0;
-       if (value != EvoEditor.formattingState.strikethrough) {
+       if (force || value != EvoEditor.formattingState.strikethrough) {
                EvoEditor.formattingState.strikethrough = value;
                changes["strikethrough"] = value;
                nchanges++;
        }
 
        value = computedStyle ? computedStyle.fontFamily : "";
-       if (value != EvoEditor.formattingState.fontFamily) {
+       if (force || value != EvoEditor.formattingState.fontFamily) {
                EvoEditor.formattingState.fontFamily = value;
                changes["fontFamily"] = value;
                nchanges++;
@@ -135,7 +142,7 @@ EvoEditor.maybeUpdateFormattingState = function(force)
        value = computedStyle ? computedStyle.color : "";
        if (value == "-webkit-standard")
                value = "";
-       if (value != EvoEditor.formattingState.fgColor) {
+       if (force || value != EvoEditor.formattingState.fgColor) {
                EvoEditor.formattingState.fgColor = value;
                changes["fgColor"] = value;
                nchanges++;
@@ -155,35 +162,35 @@ EvoEditor.maybeUpdateFormattingState = function(force)
        else
                value = EvoEditor.E_CONTENT_EDITOR_ALIGNMENT_NONE;
 
-       if (value != EvoEditor.formattingState.alignment) {
+       if (force || value != EvoEditor.formattingState.alignment) {
                EvoEditor.formattingState.alignment = value;
                changes["alignment"] = value;
                nchanges++;
        }
 
        value = document.body.text;
-       if (value != EvoEditor.formattingState.bodyFgColor) {
+       if (force || value != EvoEditor.formattingState.bodyFgColor) {
                EvoEditor.formattingState.bodyFgColor = value;
                changes["bodyFgColor"] = value;
                nchanges++;
        }
 
        value = document.body.bgColor;
-       if (value != EvoEditor.formattingState.bodyBgColor) {
+       if (force || value != EvoEditor.formattingState.bodyBgColor) {
                EvoEditor.formattingState.bodyBgColor = value;
                changes["bodyBgColor"] = value;
                nchanges++;
        }
 
        value = document.body.link;
-       if (value != EvoEditor.formattingState.bodyLinkColor) {
+       if (force || value != EvoEditor.formattingState.bodyLinkColor) {
                EvoEditor.formattingState.bodyLinkColor = value;
                changes["bodyLinkColor"] = value;
                nchanges++;
        }
 
        value = document.body.vLink;
-       if (value != EvoEditor.formattingState.bodyVlinkColor) {
+       if (force || value != EvoEditor.formattingState.bodyVlinkColor) {
                EvoEditor.formattingState.bodyVlinkColor = value;
                changes["bodyVlinkColor"] = value;
                nchanges++;
@@ -276,40 +283,45 @@ EvoEditor.maybeUpdateFormattingState = function(force)
        }
 
        value = obj.script;
-       if (value != EvoEditor.formattingState.script) {
+       if (force || value != EvoEditor.formattingState.script) {
                EvoEditor.formattingState.script = value;
                changes["script"] = value;
                nchanges++;
        }
 
        value = obj.blockFormat == null ? EvoEditor.E_CONTENT_EDITOR_BLOCK_FORMAT_PARAGRAPH : obj.blockFormat;
-       if (value != EvoEditor.formattingState.blockFormat) {
+       if (force || value != EvoEditor.formattingState.blockFormat) {
                EvoEditor.formattingState.blockFormat = value;
                changes["blockFormat"] = value;
                nchanges++;
        }
 
        value = obj.fontSize;
-       if (value != EvoEditor.formattingState.fontSize) {
+       if (force || value != EvoEditor.formattingState.fontSize) {
                EvoEditor.formattingState.fontSize = value;
                changes["fontSize"] = value;
                nchanges++;
        }
 
        value = obj.indented == null ? false : obj.indented;
-       if (value != EvoEditor.formattingState.indented) {
+       if (force || value != EvoEditor.formattingState.indented) {
                EvoEditor.formattingState.indented = value;
                changes["indented"] = value;
                nchanges++;
        }
 
        value = obj.bgColor ? obj.bgColor : computedStyle.backgroundColor;
-       if (value != EvoEditor.formattingState.bgColor) {
+       if (force || value != EvoEditor.formattingState.bgColor) {
                EvoEditor.formattingState.bgColor = value;
                changes["bgColor"] = value;
                nchanges++;
        }
 
+       if (force) {
+               changes["forced"] = true;
+               nchanges++;
+       }
+
        if (nchanges > 0)
                window.webkit.messageHandlers.formattingChanged.postMessage(changes);
 }
@@ -665,7 +677,7 @@ EvoEditor.SetAlignment = function(alignment)
                }
        } finally {
                EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "setAlignment");
-               EvoEditor.maybeUpdateFormattingState(true);
+               EvoEditor.maybeUpdateFormattingState(EvoEditor.FORCE_MAYBE);
 
                if (traversar.anyChanged)
                        EvoEditor.EmitContentChanged();
@@ -950,7 +962,7 @@ EvoEditor.SetBlockFormat = function(format)
                }
        } finally {
                EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "setBlockFormat");
-               EvoEditor.maybeUpdateFormattingState(true);
+               EvoEditor.maybeUpdateFormattingState(EvoEditor.FORCE_MAYBE);
                EvoEditor.EmitContentChanged();
        }
 }
@@ -1064,7 +1076,7 @@ EvoEditor.Indent = function(increment)
                }
        } finally {
                EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, increment ? "Indent" : "Outdent");
-               EvoEditor.maybeUpdateFormattingState(true);
+               EvoEditor.maybeUpdateFormattingState(EvoEditor.FORCE_MAYBE);
                EvoEditor.EmitContentChanged();
        }
 }
@@ -1076,7 +1088,7 @@ EvoEditor.InsertHTML = function(opType, html)
                document.execCommand("insertHTML", false, html);
        } finally {
                EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_GROUP, opType);
-               EvoEditor.maybeUpdateFormattingState(true);
+               EvoEditor.maybeUpdateFormattingState(EvoEditor.FORCE_MAYBE);
                EvoEditor.EmitContentChanged();
        }
 }
@@ -1116,7 +1128,7 @@ EvoEditor.SetBodyAttribute = function(name, value)
                        document.body.removeAttribute(name);
        } finally {
                EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "setBodyAttribute::" + name);
-               EvoEditor.maybeUpdateFormattingState(true);
+               EvoEditor.maybeUpdateFormattingState(EvoEditor.FORCE_MAYBE);
                EvoEditor.EmitContentChanged();
        }
 }
@@ -1141,6 +1153,10 @@ EvoEditor.initializeContent = function()
 }
 
 document.onload = EvoEditor.initializeContent;
-document.onselectionchange = function() { EvoEditor.maybeUpdateFormattingState(false); };
+
+document.onselectionchange = function() {
+       EvoEditor.maybeUpdateFormattingState(EvoEditor.forceFormatStateUpdate ? EvoEditor.FORCE_YES : 
EvoEditor.FORCE_MAYBE);
+       EvoEditor.forceFormatStateUpdate = false;
+};
 
 EvoEditor.initializeContent();
diff --git a/data/webkit/e-undo-redo.js b/data/webkit/e-undo-redo.js
index bebbd1670a..3d2f7edc3d 100644
--- a/data/webkit/e-undo-redo.js
+++ b/data/webkit/e-undo-redo.js
@@ -450,6 +450,8 @@ EvoUndoRedo.input_cb = function(inputEvent)
 
        if (EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_EVENT, opType)) {
                EvoEditor.EmitContentChanged();
+
+               EvoEditor.maybeUpdateFormattingState(EvoEditor.FORCE_MAYBE);
        }
 
        if (!EvoUndoRedo.ongoingRecordings.length && opType == "insertText" &&
@@ -457,7 +459,7 @@ EvoUndoRedo.input_cb = function(inputEvent)
                EvoUndoRedo.stack.maybeMergeInsertText(true);
        }
 
-       EvoEditor.maybeUpdateFormattingState(opType.startsWith("format"));
+       EvoEditor.forceFormatStateUpdate = EvoEditor.forceFormatStateUpdate || opType == "" || 
opType.startsWith("format");
 }
 
 EvoUndoRedo.applyRecord = function(record, isUndo, withSelection)
@@ -715,7 +717,7 @@ EvoUndoRedo.Undo = function()
                return;
 
        EvoUndoRedo.applyRecord(record, true, true);
-       EvoEditor.maybeUpdateFormattingState(true);
+       EvoEditor.maybeUpdateFormattingState(EvoEditor.FORCE_YES);
        EvoEditor.EmitContentChanged();
 }
 
@@ -727,7 +729,7 @@ EvoUndoRedo.Redo = function()
                return;
 
        EvoUndoRedo.applyRecord(record, false, true);
-       EvoEditor.maybeUpdateFormattingState(true);
+       EvoEditor.maybeUpdateFormattingState(EvoEditor.FORCE_YES);
        EvoEditor.EmitContentChanged();
 }
 
diff --git a/src/e-util/e-html-editor.c b/src/e-util/e-html-editor.c
index 526971b013..a4bff9dc9d 100644
--- a/src/e-util/e-html-editor.c
+++ b/src/e-util/e-html-editor.c
@@ -657,6 +657,7 @@ html_editor_constructed (GObject *object)
 {
        EHTMLEditor *editor = E_HTML_EDITOR (object);
        EHTMLEditorPrivate *priv = editor->priv;
+       GdkRGBA transparent = { 0, 0, 0, 0 };
        GtkWidget *widget;
        GtkToolbar *toolbar;
        GtkToolItem *tool_item;
@@ -773,6 +774,9 @@ html_editor_constructed (GObject *object)
 
        tool_item = gtk_tool_item_new ();
        widget = e_color_combo_new ();
+       e_color_combo_set_default_color (E_COLOR_COMBO (widget), &transparent);
+       e_color_combo_set_current_color (E_COLOR_COMBO (widget), &transparent);
+       e_color_combo_set_default_transparent (E_COLOR_COMBO (widget), TRUE);
        gtk_container_add (GTK_CONTAINER (tool_item), widget);
        gtk_widget_set_tooltip_text (widget, _("Background Color"));
        gtk_toolbar_insert (toolbar, tool_item, 1);
diff --git a/src/e-util/e-util-enums.h b/src/e-util/e-util-enums.h
index 4ea7165872..b4090d55a6 100644
--- a/src/e-util/e-util-enums.h
+++ b/src/e-util/e-util-enums.h
@@ -206,30 +206,6 @@ typedef enum {
        E_CONTENT_EDITOR_NODE_IS_TEXT_COLLAPSED = 1 << 6
 } EContentEditorNodeFlags;
 
-/**
- * EContentEditorStyleFlags:
- * @E_CONTENT_EDITOR_STYLE_NONE: None from the below.
- * @E_CONTENT_EDITOR_STYLE_IS_BOLD:
- * @E_CONTENT_EDITOR_STYLE_IS_ITALIC:
- * @E_CONTENT_EDITOR_STYLE_IS_UNDERLINE:
- * @E_CONTENT_EDITOR_STYLE_IS_STRIKETHROUGH:
- * @E_CONTENT_EDITOR_STYLE_IS_MONOSPACE:
- * @E_CONTENT_EDITOR_STYLE_IS_SUBSCRIPT:
- * @E_CONTENT_EDITOR_STYLE_IS_SUPERSCRIPT:
- *
- * Since: 3.22
- **/
-typedef enum {
-       E_CONTENT_EDITOR_STYLE_NONE             = 0,
-       E_CONTENT_EDITOR_STYLE_IS_BOLD          = 1 << 0,
-       E_CONTENT_EDITOR_STYLE_IS_ITALIC        = 1 << 1,
-       E_CONTENT_EDITOR_STYLE_IS_UNDERLINE     = 1 << 2,
-       E_CONTENT_EDITOR_STYLE_IS_STRIKETHROUGH = 1 << 3,
-       E_CONTENT_EDITOR_STYLE_IS_MONOSPACE     = 1 << 4,
-       E_CONTENT_EDITOR_STYLE_IS_SUBSCRIPT     = 1 << 5,
-       E_CONTENT_EDITOR_STYLE_IS_SUPERSCRIPT   = 1 << 6
-} EContentEditorStyleFlags;
-
 /**
  * EContentEditorBlockFormat:
  * @E_CONTENT_EDITOR_BLOCK_FORMAT_NONE:
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index 93948d3856..b78ba15cdc 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -151,9 +151,19 @@ struct _EWebKitEditorPrivate {
 };
 
 static const GdkRGBA black = { 0, 0, 0, 1 };
-static const GdkRGBA white = { 1, 1, 1, 1 };
 static const GdkRGBA transparent = { 0, 0, 0, 0 };
 
+typedef enum {
+       E_WEBKIT_EDITOR_STYLE_NONE              = 0,
+       E_WEBKIT_EDITOR_STYLE_IS_BOLD           = 1 << 0,
+       E_WEBKIT_EDITOR_STYLE_IS_ITALIC = 1 << 1,
+       E_WEBKIT_EDITOR_STYLE_IS_UNDERLINE      = 1 << 2,
+       E_WEBKIT_EDITOR_STYLE_IS_STRIKETHROUGH  = 1 << 3,
+       E_WEBKIT_EDITOR_STYLE_IS_MONOSPACE      = 1 << 4,
+       E_WEBKIT_EDITOR_STYLE_IS_SUBSCRIPT      = 1 << 5,
+       E_WEBKIT_EDITOR_STYLE_IS_SUPERSCRIPT    = 1 << 6
+} EWebKitEditorStyleFlags;
+
 typedef void (*PostReloadOperationFunc) (EWebKitEditor *wk_editor, gpointer data, 
EContentEditorInsertContentFlags flags);
 
 typedef struct {
@@ -409,7 +419,7 @@ formatting_changed_cb (WebKitUserContentManager *manager,
        EWebKitEditor *wk_editor = user_data;
        JSCValue *jsc_params, *jsc_value;
        GObject *object;
-       guint32 style_flags;
+       gboolean changed, forced = FALSE;
 
        g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
 
@@ -441,109 +451,148 @@ formatting_changed_cb (WebKitUserContentManager *manager,
 
        g_object_freeze_notify (object);
 
+       jsc_value = jsc_value_object_get_property (jsc_params, "forced");
+       if (jsc_value && jsc_value_is_boolean (jsc_value)) {
+               forced = jsc_value_to_boolean (jsc_value);
+       }
+       g_clear_object (&jsc_value);
+
+       changed = FALSE;
        jsc_value = jsc_value_object_get_property (jsc_params, "alignment");
        if (jsc_value && jsc_value_is_number (jsc_value)) {
                gint value = jsc_value_to_int32 (jsc_value);
 
                if (value != wk_editor->priv->alignment) {
                        wk_editor->priv->alignment = value;
-                       g_object_notify (object, "alignment");
+                       changed = TRUE;
                }
        }
        g_clear_object (&jsc_value);
 
+       if (changed || forced)
+               g_object_notify (object, "alignment");
+
+       changed = FALSE;
        jsc_value = jsc_value_object_get_property (jsc_params, "blockFormat");
        if (jsc_value && jsc_value_is_number (jsc_value)) {
                gint value = jsc_value_to_int32 (jsc_value);
 
                if (value != wk_editor->priv->block_format) {
                        wk_editor->priv->block_format = value;
-                       g_object_notify (object, "block-format");
+                       changed = TRUE;
                }
        }
        g_clear_object (&jsc_value);
 
+       if (changed || forced)
+               g_object_notify (object, "block-format");
+
+       changed = FALSE;
        jsc_value = jsc_value_object_get_property (jsc_params, "indented");
        if (jsc_value && jsc_value_is_boolean (jsc_value)) {
                gboolean value = jsc_value_to_boolean (jsc_value);
 
                if ((value ? 1: 0) != (wk_editor->priv->is_indented ? 1 : 0)) {
                        wk_editor->priv->is_indented = value;
-                       g_object_notify (object, "indented");
+                       changed = TRUE;
                }
        }
        g_clear_object (&jsc_value);
 
-       style_flags = E_CONTENT_EDITOR_STYLE_NONE;
+       if (changed || forced)
+               g_object_notify (object, "indented");
+
+       #define update_style_flag(_flag, _set) \
+               changed = (wk_editor->priv->style_flags & (_flag)) != ((_set) ? (_flag) : 0); \
+               wk_editor->priv->style_flags = (wk_editor->priv->style_flags & ~(_flag)) | ((_set) ? (_flag) 
: 0);
 
+       changed = FALSE;
        jsc_value = jsc_value_object_get_property (jsc_params, "bold");
        if (jsc_value && jsc_value_is_boolean (jsc_value)) {
                gboolean value = jsc_value_to_boolean (jsc_value);
 
-               style_flags |= (value ? E_CONTENT_EDITOR_STYLE_IS_BOLD : 0);
-
-               g_object_notify (G_OBJECT (wk_editor), "bold");
+               update_style_flag (E_WEBKIT_EDITOR_STYLE_IS_BOLD, value);
        }
        g_clear_object (&jsc_value);
 
+       if (changed || forced)
+               g_object_notify (G_OBJECT (wk_editor), "bold");
+
+       changed = FALSE;
        jsc_value = jsc_value_object_get_property (jsc_params, "italic");
        if (jsc_value && jsc_value_is_boolean (jsc_value)) {
                gboolean value = jsc_value_to_boolean (jsc_value);
 
-               style_flags |= (value ? E_CONTENT_EDITOR_STYLE_IS_ITALIC : 0);
-
-               g_object_notify (G_OBJECT (wk_editor), "italic");
+               update_style_flag (E_WEBKIT_EDITOR_STYLE_IS_ITALIC, value);
        }
        g_clear_object (&jsc_value);
 
+       if (changed || forced)
+               g_object_notify (G_OBJECT (wk_editor), "italic");
+
+       changed = FALSE;
        jsc_value = jsc_value_object_get_property (jsc_params, "underline");
        if (jsc_value && jsc_value_is_boolean (jsc_value)) {
                gboolean value = jsc_value_to_boolean (jsc_value);
 
-               style_flags |= (value ? E_CONTENT_EDITOR_STYLE_IS_UNDERLINE : 0);
-
-               g_object_notify (G_OBJECT (wk_editor), "underline");
+               update_style_flag (E_WEBKIT_EDITOR_STYLE_IS_UNDERLINE, value);
        }
        g_clear_object (&jsc_value);
 
+       if (changed || forced)
+               g_object_notify (G_OBJECT (wk_editor), "underline");
+
+       changed = FALSE;
        jsc_value = jsc_value_object_get_property (jsc_params, "strikethrough");
        if (jsc_value && jsc_value_is_boolean (jsc_value)) {
                gboolean value = jsc_value_to_boolean (jsc_value);
 
-               style_flags |= (value ? E_CONTENT_EDITOR_STYLE_IS_STRIKETHROUGH : 0);
-
-               g_object_notify (G_OBJECT (wk_editor), "strikethrough");
+               update_style_flag (E_WEBKIT_EDITOR_STYLE_IS_STRIKETHROUGH, value);
        }
        g_clear_object (&jsc_value);
 
+       if (changed || forced)
+               g_object_notify (G_OBJECT (wk_editor), "strikethrough");
+
        jsc_value = jsc_value_object_get_property (jsc_params, "script");
        if (jsc_value && jsc_value_is_number (jsc_value)) {
                gint value = jsc_value_to_int32 (jsc_value);
 
-               style_flags |= (value < 0 ? E_CONTENT_EDITOR_STYLE_IS_SUBSCRIPT : (value > 0 ? 
E_CONTENT_EDITOR_STYLE_IS_SUPERSCRIPT : 0));
+               changed = FALSE;
+               update_style_flag (E_WEBKIT_EDITOR_STYLE_IS_SUBSCRIPT, value < 0);
 
-               if ((wk_editor->priv->style_flags & E_CONTENT_EDITOR_STYLE_IS_SUBSCRIPT) != (style_flags & 
E_CONTENT_EDITOR_STYLE_IS_SUBSCRIPT))
+               if (changed || forced)
                        g_object_notify (object, "subscript");
 
-               if ((wk_editor->priv->style_flags & E_CONTENT_EDITOR_STYLE_IS_SUPERSCRIPT) != (style_flags & 
E_CONTENT_EDITOR_STYLE_IS_SUPERSCRIPT))
+               changed = FALSE;
+               update_style_flag (E_WEBKIT_EDITOR_STYLE_IS_SUPERSCRIPT, value > 0);
+
+               if (changed || forced)
                        g_object_notify (object, "superscript");
+       } else if (forced) {
+               g_object_notify (object, "subscript");
+               g_object_notify (object, "superscript");
        }
        g_clear_object (&jsc_value);
 
-       if (wk_editor->priv->style_flags != style_flags)
-               wk_editor->priv->style_flags = style_flags;
+       #undef update_style_flag
 
+       changed = FALSE;
        jsc_value = jsc_value_object_get_property (jsc_params, "fontSize");
        if (jsc_value && jsc_value_is_number (jsc_value)) {
                gint value = jsc_value_to_int32 (jsc_value);
 
                if (value != wk_editor->priv->font_size) {
                        wk_editor->priv->font_size = value;
-                       g_object_notify (object, "font-size");
+                       changed = TRUE;
                }
        }
        g_clear_object (&jsc_value);
 
+       if (changed || forced)
+               g_object_notify (object, "font-size");
+
+       changed = FALSE;
        jsc_value = jsc_value_object_get_property (jsc_params, "fontFamily");
        if (jsc_value && jsc_value_is_string (jsc_value)) {
                gchar *value = jsc_value_to_string (jsc_value);
@@ -551,17 +600,20 @@ formatting_changed_cb (WebKitUserContentManager *manager,
                if (g_strcmp0 (value, wk_editor->priv->font_name) != 0) {
                        g_free (wk_editor->priv->font_name);
                        wk_editor->priv->font_name = value;
-                       g_object_notify (object, "font-name");
+                       changed = TRUE;
                } else {
                        g_free (value);
                }
        }
        g_clear_object (&jsc_value);
 
-       if (webkit_editor_update_color_value (jsc_params, "fgColor", &wk_editor->priv->font_color))
+       if (changed || forced)
+               g_object_notify (object, "font-name");
+
+       if (webkit_editor_update_color_value (jsc_params, "fgColor", &wk_editor->priv->font_color) || forced)
                g_object_notify (object, "font-color");
 
-       if (webkit_editor_update_color_value (jsc_params, "bgColor", &wk_editor->priv->background_color))
+       if (webkit_editor_update_color_value (jsc_params, "bgColor", &wk_editor->priv->background_color) || 
forced)
                g_object_notify (object, "background-color");
 
        webkit_editor_update_color_value (jsc_params, "bodyFgColor", &wk_editor->priv->body_fg_color);
@@ -593,7 +645,6 @@ undu_redo_state_changed_cb (WebKitUserContentManager *manager,
        state = jsc_value_to_int32 (jsc_value);
        g_clear_object (&jsc_value);
 
-       printf ("%s: state:%x\n", __FUNCTION__, state);
        webkit_editor_set_can_undo (wk_editor, (state & E_UNDO_REDO_STATE_CAN_UNDO) != 0);
        webkit_editor_set_can_redo (wk_editor, (state & E_UNDO_REDO_STATE_CAN_REDO) != 0);
 }
@@ -1893,7 +1944,6 @@ webkit_editor_undo (EContentEditor *editor)
 
        wk_editor = E_WEBKIT_EDITOR (editor);
 
-       printf ("%s:\n", __FUNCTION__);
        e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
                "EvoUndoRedo.Undo();");
 }
@@ -1914,7 +1964,7 @@ webkit_editor_redo (EContentEditor *editor)
        g_return_if_fail (E_IS_WEBKIT_EDITOR (editor));
 
        wk_editor = E_WEBKIT_EDITOR (editor);
-       printf ("%s:\n", __FUNCTION__);
+
        e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
                "EvoUndoRedo.Redo();");
 }
@@ -3663,12 +3713,17 @@ webkit_editor_set_background_color (EWebKitEditor *wk_editor,
            (value && wk_editor->priv->background_color && gdk_rgba_equal (value, 
wk_editor->priv->background_color)))
                return;
 
-       if (value)
+       if (value && value->alpha > 1e-9) {
                color = g_strdup_printf ("#%06x", e_rgba_to_value (value));
-       else
+               g_clear_pointer (&wk_editor->priv->background_color, gdk_rgba_free);
+               wk_editor->priv->background_color = gdk_rgba_copy (value);
+       } else {
                color = NULL;
+               g_clear_pointer (&wk_editor->priv->background_color, gdk_rgba_free);
+               wk_editor->priv->background_color = NULL;
+       }
 
-       webkit_web_view_execute_editing_command_with_argument (WEBKIT_WEB_VIEW (wk_editor), "BackColor", 
color ? color : "");
+       webkit_web_view_execute_editing_command_with_argument (WEBKIT_WEB_VIEW (wk_editor), "BackColor", 
color ? color : "inherit");
 
        g_free (color);
 }
@@ -3679,7 +3734,7 @@ webkit_editor_get_background_color (EWebKitEditor *wk_editor)
        g_return_val_if_fail (E_IS_WEBKIT_EDITOR (wk_editor), NULL);
 
        if (!wk_editor->priv->background_color)
-               return &white;
+               return &transparent;
 
        return wk_editor->priv->background_color;
 }
@@ -3765,7 +3820,7 @@ webkit_editor_get_font_size (EWebKitEditor *wk_editor)
 
 static void
 webkit_editor_set_style_flag (EWebKitEditor *wk_editor,
-                             EContentEditorStyleFlags flag,
+                             EWebKitEditorStyleFlags flag,
                              gboolean do_set)
 {
        g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
@@ -3774,27 +3829,27 @@ webkit_editor_set_style_flag (EWebKitEditor *wk_editor,
                return;
 
        switch (flag) {
-       case E_CONTENT_EDITOR_STYLE_NONE:
+       case E_WEBKIT_EDITOR_STYLE_NONE:
                break;
-       case E_CONTENT_EDITOR_STYLE_IS_BOLD:
+       case E_WEBKIT_EDITOR_STYLE_IS_BOLD:
                webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (wk_editor), "Bold");
                break;
-       case E_CONTENT_EDITOR_STYLE_IS_ITALIC:
+       case E_WEBKIT_EDITOR_STYLE_IS_ITALIC:
                webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (wk_editor), "Italic");
                break;
-       case E_CONTENT_EDITOR_STYLE_IS_UNDERLINE:
+       case E_WEBKIT_EDITOR_STYLE_IS_UNDERLINE:
                webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (wk_editor), "Underline");
                break;
-       case E_CONTENT_EDITOR_STYLE_IS_STRIKETHROUGH:
+       case E_WEBKIT_EDITOR_STYLE_IS_STRIKETHROUGH:
                webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (wk_editor), "Strikethrough");
                break;
-       case E_CONTENT_EDITOR_STYLE_IS_MONOSPACE:
+       case E_WEBKIT_EDITOR_STYLE_IS_MONOSPACE:
                webkit_web_view_execute_editing_command_with_argument (WEBKIT_WEB_VIEW (wk_editor), 
"FontName", "monospace");
                break;
-       case E_CONTENT_EDITOR_STYLE_IS_SUBSCRIPT:
+       case E_WEBKIT_EDITOR_STYLE_IS_SUBSCRIPT:
                webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (wk_editor), "Subscript");
                break;
-       case E_CONTENT_EDITOR_STYLE_IS_SUPERSCRIPT:
+       case E_WEBKIT_EDITOR_STYLE_IS_SUPERSCRIPT:
                webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (wk_editor), "Superscript");
                break;
        }
@@ -3802,7 +3857,7 @@ webkit_editor_set_style_flag (EWebKitEditor *wk_editor,
 
 static gboolean
 webkit_editor_get_style_flag (EWebKitEditor *wk_editor,
-                             EContentEditorStyleFlags flag)
+                             EWebKitEditorStyleFlags flag)
 {
        g_return_val_if_fail (E_IS_WEBKIT_EDITOR (wk_editor), FALSE);
 
@@ -4360,7 +4415,7 @@ webkit_editor_cell_set_background_color (EContentEditor *editor,
                return;
        }
 
-       if (value->alpha != 0.0)
+       if (value && value->alpha > 1e-9)
                color = g_strdup_printf ("#%06x", e_rgba_to_value (value));
        else
                color = g_strdup ("");
@@ -5297,7 +5352,7 @@ webkit_editor_set_property (GObject *object,
                case PROP_BOLD:
                        webkit_editor_set_style_flag (
                                E_WEBKIT_EDITOR (object),
-                               E_CONTENT_EDITOR_STYLE_IS_BOLD,
+                               E_WEBKIT_EDITOR_STYLE_IS_BOLD,
                                g_value_get_boolean (value));
                        return;
 
@@ -5328,42 +5383,42 @@ webkit_editor_set_property (GObject *object,
                case PROP_ITALIC:
                        webkit_editor_set_style_flag (
                                E_WEBKIT_EDITOR (object),
-                               E_CONTENT_EDITOR_STYLE_IS_ITALIC,
+                               E_WEBKIT_EDITOR_STYLE_IS_ITALIC,
                                g_value_get_boolean (value));
                        return;
 
                case PROP_MONOSPACED:
                        webkit_editor_set_style_flag (
                                E_WEBKIT_EDITOR (object),
-                               E_CONTENT_EDITOR_STYLE_IS_MONOSPACE,
+                               E_WEBKIT_EDITOR_STYLE_IS_MONOSPACE,
                                g_value_get_boolean (value));
                        return;
 
                case PROP_STRIKETHROUGH:
                        webkit_editor_set_style_flag (
                                E_WEBKIT_EDITOR (object),
-                               E_CONTENT_EDITOR_STYLE_IS_STRIKETHROUGH,
+                               E_WEBKIT_EDITOR_STYLE_IS_STRIKETHROUGH,
                                g_value_get_boolean (value));
                        return;
 
                case PROP_SUBSCRIPT:
                        webkit_editor_set_style_flag (
                                E_WEBKIT_EDITOR (object),
-                               E_CONTENT_EDITOR_STYLE_IS_SUBSCRIPT,
+                               E_WEBKIT_EDITOR_STYLE_IS_SUBSCRIPT,
                                g_value_get_boolean (value));
                        return;
 
                case PROP_SUPERSCRIPT:
                        webkit_editor_set_style_flag (
                                E_WEBKIT_EDITOR (object),
-                               E_CONTENT_EDITOR_STYLE_IS_SUPERSCRIPT,
+                               E_WEBKIT_EDITOR_STYLE_IS_SUPERSCRIPT,
                                g_value_get_boolean (value));
                        return;
 
                case PROP_UNDERLINE:
                        webkit_editor_set_style_flag (
                                E_WEBKIT_EDITOR (object),
-                               E_CONTENT_EDITOR_STYLE_IS_UNDERLINE,
+                               E_WEBKIT_EDITOR_STYLE_IS_UNDERLINE,
                                g_value_get_boolean (value));
                        return;
 
@@ -5494,7 +5549,7 @@ webkit_editor_get_property (GObject *object,
                                value,
                                webkit_editor_get_style_flag (
                                        E_WEBKIT_EDITOR (object),
-                                       E_CONTENT_EDITOR_STYLE_IS_BOLD));
+                                       E_WEBKIT_EDITOR_STYLE_IS_BOLD));
                        return;
 
                case PROP_FONT_COLOR:
@@ -5530,7 +5585,7 @@ webkit_editor_get_property (GObject *object,
                                value,
                                webkit_editor_get_style_flag (
                                        E_WEBKIT_EDITOR (object),
-                                       E_CONTENT_EDITOR_STYLE_IS_ITALIC));
+                                       E_WEBKIT_EDITOR_STYLE_IS_ITALIC));
                        return;
 
                case PROP_MONOSPACED:
@@ -5538,7 +5593,7 @@ webkit_editor_get_property (GObject *object,
                                value,
                                webkit_editor_get_style_flag (
                                        E_WEBKIT_EDITOR (object),
-                                       E_CONTENT_EDITOR_STYLE_IS_MONOSPACE));
+                                       E_WEBKIT_EDITOR_STYLE_IS_MONOSPACE));
                        return;
 
                case PROP_STRIKETHROUGH:
@@ -5546,7 +5601,7 @@ webkit_editor_get_property (GObject *object,
                                value,
                                webkit_editor_get_style_flag (
                                        E_WEBKIT_EDITOR (object),
-                                       E_CONTENT_EDITOR_STYLE_IS_STRIKETHROUGH));
+                                       E_WEBKIT_EDITOR_STYLE_IS_STRIKETHROUGH));
                        return;
 
                case PROP_SUBSCRIPT:
@@ -5554,7 +5609,7 @@ webkit_editor_get_property (GObject *object,
                                value,
                                webkit_editor_get_style_flag (
                                        E_WEBKIT_EDITOR (object),
-                                       E_CONTENT_EDITOR_STYLE_IS_SUBSCRIPT));
+                                       E_WEBKIT_EDITOR_STYLE_IS_SUBSCRIPT));
                        return;
 
                case PROP_SUPERSCRIPT:
@@ -5562,7 +5617,7 @@ webkit_editor_get_property (GObject *object,
                                value,
                                webkit_editor_get_style_flag (
                                        E_WEBKIT_EDITOR (object),
-                                       E_CONTENT_EDITOR_STYLE_IS_SUPERSCRIPT));
+                                       E_WEBKIT_EDITOR_STYLE_IS_SUPERSCRIPT));
                        return;
 
                case PROP_UNDERLINE:
@@ -5570,7 +5625,7 @@ webkit_editor_get_property (GObject *object,
                                value,
                                webkit_editor_get_style_flag (
                                        E_WEBKIT_EDITOR (object),
-                                       E_CONTENT_EDITOR_STYLE_IS_UNDERLINE));
+                                       E_WEBKIT_EDITOR_STYLE_IS_UNDERLINE));
                        return;
 
                case PROP_START_BOTTOM:
@@ -6476,8 +6531,8 @@ e_webkit_editor_init (EWebKitEditor *wk_editor)
        wk_editor->priv->current_user_stylesheet = NULL;
        wk_editor->priv->suppress_color_changes = FALSE;
 
-       wk_editor->priv->font_color = gdk_rgba_copy (&black);
-       wk_editor->priv->background_color = gdk_rgba_copy (&white);
+       wk_editor->priv->font_color = NULL;
+       wk_editor->priv->background_color = NULL;
        wk_editor->priv->font_name = NULL;
        wk_editor->priv->font_size = E_CONTENT_EDITOR_FONT_SIZE_NORMAL;
        wk_editor->priv->block_format = E_CONTENT_EDITOR_BLOCK_FORMAT_PARAGRAPH;


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