[evolution/wip/mcrha/webkit-jsc-api] Use more functions in EWebKitEditor from JSC
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/mcrha/webkit-jsc-api] Use more functions in EWebKitEditor from JSC
- Date: Mon, 4 Nov 2019 18:07:05 +0000 (UTC)
commit 86bef2b92a1d759fdef13d66ad1eb93a83f111c0
Author: Milan Crha <mcrha redhat com>
Date: Mon Nov 4 19:07:04 2019 +0100
Use more functions in EWebKitEditor from JSC
data/webkit/e-editor.js | 92 ++-
data/webkit/e-undo-redo.js | 12 +
src/e-util/e-html-editor-actions.c | 34 +-
src/e-util/e-html-editor-actions.h | 6 +
src/e-util/e-html-editor-manager.ui | 5 +
src/e-util/e-html-editor-paragraph-dialog.c | 10 +
src/e-util/e-html-editor-private.h | 3 +-
src/e-util/e-html-editor.c | 25 +-
src/modules/webkit-editor/e-webkit-editor.c | 686 ++++++++++-----------
.../web-extension/e-editor-web-extension.c | 2 +-
10 files changed, 490 insertions(+), 385 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 2923f605cf..926d79ce49 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -64,7 +64,11 @@ var EvoEditor = {
bgColor : null,
fontSize : null,
fontFamily : null,
- indented : false
+ indented : false,
+ bodyFgColor : null,
+ bodyBgColor : null,
+ bodyLinkColor : null,
+ bodyVlinkColor : null
}
};
@@ -129,6 +133,8 @@ EvoEditor.maybeUpdateFormattingState = function(force)
}
value = computedStyle ? computedStyle.color : "";
+ if (value == "-webkit-standard")
+ value = "";
if (value != EvoEditor.formattingState.fgColor) {
EvoEditor.formattingState.fgColor = value;
changes["fgColor"] = value;
@@ -162,6 +168,34 @@ EvoEditor.maybeUpdateFormattingState = function(force)
nchanges++;
}
+ value = document.body.text;
+ if (value != EvoEditor.formattingState.bodyFgColor) {
+ EvoEditor.formattingState.bodyFgColor = value;
+ changes["bodyFgColor"] = value;
+ nchanges++;
+ }
+
+ value = document.body.bgColor;
+ if (value != EvoEditor.formattingState.bodyBgColor) {
+ EvoEditor.formattingState.bodyBgColor = value;
+ changes["bodyBgColor"] = value;
+ nchanges++;
+ }
+
+ value = document.body.link;
+ if (value != EvoEditor.formattingState.bodyLinkColor) {
+ EvoEditor.formattingState.bodyLinkColor = value;
+ changes["bodyLinkColor"] = value;
+ nchanges++;
+ }
+
+ value = document.body.vLink;
+ if (value != EvoEditor.formattingState.bodyVlinkColor) {
+ EvoEditor.formattingState.bodyVlinkColor = value;
+ changes["bodyVlinkColor"] = value;
+ nchanges++;
+ }
+
var parent, obj = {
script : 0,
blockFormat : null,
@@ -249,7 +283,7 @@ EvoEditor.maybeUpdateFormattingState = function(force)
nchanges++;
}
- value = obj.blockFormat;
+ value = obj.blockFormat == null ? EvoEditor.E_CONTENT_EDITOR_BLOCK_FORMAT_PARAGRAPH : obj.blockFormat;
if (value != EvoEditor.formattingState.blockFormat) {
EvoEditor.formattingState.blockFormat = value;
changes["blockFormat"] = value;
@@ -512,6 +546,12 @@ EvoEditor.ForeachChildInAffectedContent = function(affected, traversar)
return EvoEditor.ForeachChild(parent, firstChildIndex, lastChildIndex, traversar);
}
+EvoEditor.EmitContentChanged = function()
+{
+ if (window.webkit.messageHandlers.contentChanged)
+ window.webkit.messageHandlers.contentChanged.postMessage(null);
+}
+
EvoEditor.StoreSelection = function()
{
EvoEditor.storedSelection = EvoSelection.Store(document);
@@ -553,6 +593,7 @@ EvoEditor.SetAlignment = function(alignment)
var traversar = {
record : null,
toSet : null,
+ anyChanged : false,
flat : false,
onlyBlockElements : true,
@@ -571,6 +612,7 @@ EvoEditor.SetAlignment = function(alignment)
traversar.record.changes[traversar.record.changes.length] = change;
}
+ traversar.anyChanged = true;
element.style.textAlign = traversar.toSet;
}
@@ -612,6 +654,9 @@ EvoEditor.SetAlignment = function(alignment)
} finally {
EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "setAlignment");
EvoEditor.maybeUpdateFormattingState(true);
+
+ if (traversar.anyChanged)
+ EvoEditor.EmitContentChanged();
}
}
@@ -894,6 +939,7 @@ EvoEditor.SetBlockFormat = function(format)
} finally {
EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "setBlockFormat");
EvoEditor.maybeUpdateFormattingState(true);
+ EvoEditor.EmitContentChanged();
}
}
@@ -1011,6 +1057,7 @@ EvoEditor.Indent = function(increment)
} finally {
EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, increment ? "Indent" : "Outdent");
EvoEditor.maybeUpdateFormattingState(true);
+ EvoEditor.EmitContentChanged();
}
}
@@ -1022,6 +1069,47 @@ EvoEditor.InsertHTML = function(opType, html)
} finally {
EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_GROUP, opType);
EvoEditor.maybeUpdateFormattingState(true);
+ EvoEditor.EmitContentChanged();
+ }
+}
+
+EvoEditor.applySetBodyAttribute = function(record, isUndo)
+{
+ if (isUndo) {
+ if (record.beforeValue)
+ document.body.setAttribute(record.attrName, record.beforeValue);
+ else
+ document.body.removeAttribute(record.attrName);
+ } else {
+ if (record.attrValue)
+ document.body.setAttribute(record.attrName, record.attrValue);
+ else
+ document.body.removeAttribute(record.attrName);
+ }
+}
+
+EvoEditor.SetBodyAttribute = function(name, value)
+{
+ var record;
+
+ record = EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "setBodyAttribute::" + name,
document.body, document.body, EvoEditor.CLAIM_CONTENT_FLAG_NONE);
+
+ try {
+ if (record) {
+ record.attrName = name;
+ record.attrValue = value;
+ record.beforeValue = document.body.getAttribute(name);
+ record.apply = EvoEditor.applySetBodyAttribute;
+ }
+
+ if (value)
+ document.body.setAttribute(name, value);
+ else
+ document.body.removeAttribute(name);
+ } finally {
+ EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "setBodyAttribute::" + name);
+ EvoEditor.maybeUpdateFormattingState(true);
+ EvoEditor.EmitContentChanged();
}
}
diff --git a/data/webkit/e-undo-redo.js b/data/webkit/e-undo-redo.js
index b1ce8a0814..701df0cb06 100644
--- a/data/webkit/e-undo-redo.js
+++ b/data/webkit/e-undo-redo.js
@@ -385,6 +385,7 @@ EvoUndoRedo.before_input_cb = function(inputEvent)
EvoUndoRedo.input_cb = function(inputEvent)
{
if (EvoUndoRedo.disabled) {
+ EvoEditor.EmitContentChanged();
return;
}
@@ -399,6 +400,9 @@ EvoUndoRedo.input_cb = function(inputEvent)
!EvoUndoRedo.stack.topInsertTextAtSamePlace()) {
EvoUndoRedo.stack.maybeMergeInsertText(true);
}
+
+ EvoEditor.maybeUpdateFormattingState(opType.startsWith("format"));
+ EvoEditor.EmitContentChanged();
}
EvoUndoRedo.applyRecord = function(record, isUndo, withSelection)
@@ -620,16 +624,24 @@ EvoUndoRedo.Undo = function()
{
var record = EvoUndoRedo.stack.undo();
+ if (!record)
+ return;
+
EvoUndoRedo.applyRecord(record, true, true);
EvoEditor.maybeUpdateFormattingState(true);
+ EvoEditor.EmitContentChanged();
}
EvoUndoRedo.Redo = function()
{
var record = EvoUndoRedo.stack.redo();
+ if (!record)
+ return;
+
EvoUndoRedo.applyRecord(record, false, true);
EvoEditor.maybeUpdateFormattingState(true);
+ EvoEditor.EmitContentChanged();
}
EvoUndoRedo.Clear = function()
diff --git a/src/e-util/e-html-editor-actions.c b/src/e-util/e-html-editor-actions.c
index 0c151a72a4..5a7648ff8e 100644
--- a/src/e-util/e-html-editor-actions.c
+++ b/src/e-util/e-html-editor-actions.c
@@ -606,7 +606,8 @@ action_mode_cb (GtkRadioAction *action,
action_group = editor->priv->html_context_actions;
gtk_action_group_set_visible (action_group, is_html);
- gtk_widget_set_sensitive (editor->priv->color_combo_box, is_html);
+ gtk_widget_set_sensitive (editor->priv->fg_color_combo_box, is_html);
+ gtk_widget_set_sensitive (editor->priv->bg_color_combo_box, is_html);
if (is_html) {
gtk_widget_show (editor->priv->html_toolbar);
@@ -1133,6 +1134,13 @@ static GtkRadioActionEntry core_justify_entries[] = {
N_("Center Alignment"),
E_CONTENT_EDITOR_ALIGNMENT_CENTER },
+ { "justify-fill",
+ "format-justify-fill",
+ N_("_Justified"),
+ "<Control>j",
+ N_("Align Justified"),
+ E_CONTENT_EDITOR_ALIGNMENT_JUSTIFY },
+
{ "justify-left",
"format-justify-left",
N_("_Left"),
@@ -1400,6 +1408,22 @@ static GtkToggleActionEntry html_toggle_entries[] = {
NULL,
FALSE },
+ { "subscript",
+ NULL,
+ N_("Subs_cript"),
+ "<Control><Shift>b",
+ N_("Subscript"),
+ NULL,
+ FALSE },
+
+ { "superscript",
+ NULL,
+ N_("Su_perscript"),
+ "<Control><Shift>p",
+ N_("Superscript"),
+ NULL,
+ FALSE },
+
{ "underline",
"format-text-underline",
N_("_Underline"),
@@ -2162,6 +2186,14 @@ editor_actions_bind (EHTMLEditor *editor)
cnt_editor, "strikethrough",
ACTION (STRIKETHROUGH), "active",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+ e_binding_bind_property (
+ cnt_editor, "subscript",
+ ACTION (SUBSCRIPT), "active",
+ G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+ e_binding_bind_property (
+ cnt_editor, "superscript",
+ ACTION (SUPERSCRIPT), "active",
+ G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
e_binding_bind_property (
cnt_editor, "underline",
ACTION (UNDERLINE), "active",
diff --git a/src/e-util/e-html-editor-actions.h b/src/e-util/e-html-editor-actions.h
index 74b2773eee..7ea6286d55 100644
--- a/src/e-util/e-html-editor-actions.h
+++ b/src/e-util/e-html-editor-actions.h
@@ -101,6 +101,8 @@
E_HTML_EDITOR_ACTION ((editor), "italic")
#define E_HTML_EDITOR_ACTION_JUSTIFY_CENTER(editor) \
E_HTML_EDITOR_ACTION ((editor), "justify-center")
+#define E_HTML_EDITOR_ACTION_JUSTIFY_FILL(editor) \
+ E_HTML_EDITOR_ACTION ((editor), "justify-fill")
#define E_HTML_EDITOR_ACTION_JUSTIFY_LEFT(editor) \
E_HTML_EDITOR_ACTION ((editor), "justify-left")
#define E_HTML_EDITOR_ACTION_JUSTIFY_RIGHT(editor) \
@@ -151,6 +153,10 @@
E_HTML_EDITOR_ACTION ((editor), "style-h6")
#define E_HTML_EDITOR_ACTION_STYLE_NORMAL(editor) \
E_HTML_EDITOR_ACTION ((editor), "style-normal")
+#define E_HTML_EDITOR_ACTION_SUBSCRIPT(editor) \
+ E_HTML_EDITOR_ACTION ((editor), "subscript")
+#define E_HTML_EDITOR_ACTION_SUPERSCRIPT(editor) \
+ E_HTML_EDITOR_ACTION ((editor), "superscript")
#define E_HTML_EDITOR_ACTION_TEST_URL(editor) \
E_HTML_EDITOR_ACTION ((editor), "test-url")
#define E_HTML_EDITOR_ACTION_UNDERLINE(editor) \
diff --git a/src/e-util/e-html-editor-manager.ui b/src/e-util/e-html-editor-manager.ui
index e6af175d34..fa89576d3b 100644
--- a/src/e-util/e-html-editor-manager.ui
+++ b/src/e-util/e-html-editor-manager.ui
@@ -59,6 +59,9 @@
<menuitem action='italic'/>
<menuitem action='underline'/>
<menuitem action='strikethrough'/>
+ <separator/>
+ <menuitem action='subscript'/>
+ <menuitem action='superscript'/>
</menu>
<menu action='font-size-menu'>
<menuitem action='size-minus-two'/>
@@ -91,6 +94,7 @@
<menuitem action='justify-left'/>
<menuitem action='justify-center'/>
<menuitem action='justify-right'/>
+ <menuitem action='justify-fill'/>
</menu>
<separator/>
<menuitem action='indent'/>
@@ -117,6 +121,7 @@
<toolitem action='justify-left'/>
<toolitem action='justify-center'/>
<toolitem action='justify-right'/>
+ <toolitem action='justify-fill'/>
<separator/>
<toolitem action='unindent'/>
<toolitem action='indent'/>
diff --git a/src/e-util/e-html-editor-paragraph-dialog.c b/src/e-util/e-html-editor-paragraph-dialog.c
index 014de3b98b..15ccebc00b 100644
--- a/src/e-util/e-html-editor-paragraph-dialog.c
+++ b/src/e-util/e-html-editor-paragraph-dialog.c
@@ -41,6 +41,7 @@ struct _EHTMLEditorParagraphDialogPrivate {
GtkWidget *left_button;
GtkWidget *center_button;
GtkWidget *right_button;
+ GtkWidget *justified_button;
};
static void
@@ -122,6 +123,15 @@ html_editor_paragraph_dialog_constructed (GObject *object)
e_html_editor_get_action (editor, "justify-right"));
dialog->priv->right_button = widget;
+ /* Justified */
+ widget = gtk_toggle_button_new_with_label (_("_Justified"));
+ gtk_button_set_use_stock (GTK_BUTTON (widget), TRUE);
+ gtk_grid_attach (grid, widget, 2, 0, 1, 1);
+ gtk_activatable_set_related_action (
+ GTK_ACTIVATABLE (widget),
+ e_html_editor_get_action (editor, "justify-fill"));
+ dialog->priv->justified_button = widget;
+
gtk_widget_show_all (GTK_WIDGET (main_layout));
}
diff --git a/src/e-util/e-html-editor-private.h b/src/e-util/e-html-editor-private.h
index 5d66c203b2..03e6a65390 100644
--- a/src/e-util/e-html-editor-private.h
+++ b/src/e-util/e-html-editor-private.h
@@ -77,7 +77,8 @@ struct _EHTMLEditorPrivate {
GtkWidget *cell_dialog;
GtkWidget *spell_check_dialog;
- GtkWidget *color_combo_box;
+ GtkWidget *fg_color_combo_box;
+ GtkWidget *bg_color_combo_box;
GtkWidget *mode_combo_box;
GtkWidget *size_combo_box;
GtkWidget *style_combo_box;
diff --git a/src/e-util/e-html-editor.c b/src/e-util/e-html-editor.c
index e4a7538ac9..06c92530d9 100644
--- a/src/e-util/e-html-editor.c
+++ b/src/e-util/e-html-editor.c
@@ -768,7 +768,15 @@ html_editor_constructed (GObject *object)
gtk_container_add (GTK_CONTAINER (tool_item), widget);
gtk_widget_set_tooltip_text (widget, _("Font Color"));
gtk_toolbar_insert (toolbar, tool_item, 0);
- priv->color_combo_box = g_object_ref (widget);
+ priv->fg_color_combo_box = g_object_ref (widget);
+ gtk_widget_show_all (GTK_WIDGET (tool_item));
+
+ tool_item = gtk_tool_item_new ();
+ widget = e_color_combo_new ();
+ gtk_container_add (GTK_CONTAINER (tool_item), widget);
+ gtk_widget_set_tooltip_text (widget, _("Background Color"));
+ gtk_toolbar_insert (toolbar, tool_item, 1);
+ priv->bg_color_combo_box = g_object_ref (widget);
gtk_widget_show_all (GTK_WIDGET (tool_item));
tool_item = gtk_tool_item_new ();
@@ -809,7 +817,8 @@ html_editor_dispose (GObject *object)
g_clear_object (&priv->alert_bar);
g_clear_object (&priv->edit_area);
- g_clear_object (&priv->color_combo_box);
+ g_clear_object (&priv->fg_color_combo_box);
+ g_clear_object (&priv->bg_color_combo_box);
g_clear_object (&priv->mode_combo_box);
g_clear_object (&priv->size_combo_box);
g_clear_object (&priv->style_combo_box);
@@ -942,12 +951,20 @@ e_html_editor_content_editor_initialized (EContentEditor *content_editor,
g_return_if_fail (content_editor == e_html_editor_get_content_editor (html_editor));
e_binding_bind_property (
- html_editor->priv->color_combo_box, "current-color",
+ html_editor->priv->fg_color_combo_box, "current-color",
content_editor, "font-color",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
e_binding_bind_property (
content_editor, "editable",
- html_editor->priv->color_combo_box, "sensitive",
+ html_editor->priv->fg_color_combo_box, "sensitive",
+ G_BINDING_SYNC_CREATE);
+ e_binding_bind_property (
+ html_editor->priv->bg_color_combo_box, "current-color",
+ content_editor, "background-color",
+ G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+ e_binding_bind_property (
+ content_editor, "editable",
+ html_editor->priv->bg_color_combo_box, "sensitive",
G_BINDING_SYNC_CREATE);
editor_actions_bind (html_editor);
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index f810810333..578acd85cc 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -78,8 +78,6 @@ struct _EWebKitEditorPrivate {
EWebExtensionContainer *container;
GDBusProxy *web_extension_proxy;
gint stamp; /* Changed only in the main thread, doesn't need locking */
- guint web_extension_selection_changed_cb_id;
- guint web_extension_content_changed_cb_id;
guint web_extension_user_changed_default_colors_cb_id;
gboolean html_mode;
@@ -104,6 +102,10 @@ struct _EWebKitEditorPrivate {
GdkRGBA *background_color;
GdkRGBA *font_color;
+ GdkRGBA *body_fg_color;
+ GdkRGBA *body_bg_color;
+ GdkRGBA *body_link_color;
+ GdkRGBA *body_vlink_color;
gchar *font_name;
@@ -350,62 +352,74 @@ webkit_editor_set_can_redo (EWebKitEditor *wk_editor,
}
static void
-web_extension_content_changed_cb (GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- EWebKitEditor *wk_editor)
+content_changed_cb (WebKitUserContentManager *manager,
+ WebKitJavascriptResult *js_result,
+ gpointer user_data)
{
- if (g_strcmp0 (signal_name, "ContentChanged") != 0)
- return;
+ EWebKitEditor *wk_editor = user_data;
+
+ g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
- if (parameters) {
- guint64 page_id = 0;
+ webkit_editor_set_changed (wk_editor, TRUE);
+}
+
+static gboolean
+webkit_editor_update_color_value (JSCValue *jsc_params,
+ const gchar *param_name,
+ GdkRGBA **out_rgba)
+{
+ JSCValue *jsc_value;
+ GdkRGBA color;
+ gboolean res = FALSE;
+
+ g_return_val_if_fail (jsc_params != NULL, FALSE);
+ g_return_val_if_fail (out_rgba != NULL, FALSE);
+
+ jsc_value = jsc_value_object_get_property (jsc_params, param_name);
+ if (jsc_value && jsc_value_is_string (jsc_value)) {
+ gchar *value;
+
+ value = jsc_value_to_string (jsc_value);
+
+ if (value && *value && gdk_rgba_parse (&color, value)) {
+ if (!(*out_rgba) || !gdk_rgba_equal (&color, *out_rgba)) {
+ if (*out_rgba)
+ gdk_rgba_free (*out_rgba);
+ *out_rgba = gdk_rgba_copy (&color);
+
+ res = TRUE;
+ }
+ } else {
+ if (*out_rgba) {
+ gdk_rgba_free (*out_rgba);
+ res = TRUE;
+ }
- g_variant_get (parameters, "(t)", &page_id);
+ *out_rgba = NULL;
+ }
- if (page_id == webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (wk_editor)))
- webkit_editor_set_changed (wk_editor, TRUE);
+ g_free (value);
}
+
+ g_clear_object (&jsc_value);
+
+ return res;
}
static void
-web_extension_selection_changed_cb (GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- EWebKitEditor *wk_editor)
+formatting_changed_cb (WebKitUserContentManager *manager,
+ WebKitJavascriptResult *js_result,
+ gpointer user_data)
{
- guint64 page_id = 0;
- gchar *font_color = NULL;
- guint32 alignment, block_format, style_flags, font_size;
- gboolean is_indented;
-
- if (g_strcmp0 (signal_name, "SelectionChanged") != 0)
- return;
+ EWebKitEditor *wk_editor = user_data;
+ JSCValue *jsc_params, *jsc_value;
+ GObject *object;
+ guint32 style_flags;
- if (!parameters)
- return;
+ g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
- g_variant_get (
- parameters,
- "(tiibiis)",
- &page_id,
- &alignment,
- &block_format,
- &is_indented,
- &style_flags,
- &font_size,
- &font_color);
-
- if (page_id != webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (wk_editor))) {
- g_free (font_color);
- return;
- }
+ jsc_params = webkit_javascript_result_get_js_value (js_result);
+ g_return_if_fail (jsc_value_is_object (jsc_params));
webkit_web_view_can_execute_editing_command (
WEBKIT_WEB_VIEW (wk_editor),
@@ -428,49 +442,140 @@ web_extension_selection_changed_cb (GDBusConnection *connection,
(GAsyncReadyCallback) webkit_editor_can_paste_cb,
wk_editor);
- g_object_freeze_notify (G_OBJECT (wk_editor));
+ object = G_OBJECT (wk_editor);
- wk_editor->priv->alignment = alignment;
- wk_editor->priv->block_format = block_format;
- wk_editor->priv->is_indented = is_indented;
- wk_editor->priv->style_flags = style_flags;
- wk_editor->priv->font_size = font_size;
+ g_object_freeze_notify (object);
- if (wk_editor->priv->html_mode) {
- GdkRGBA color;
+ 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 (font_color && *font_color && gdk_rgba_parse (&color, font_color)) {
- if (wk_editor->priv->font_color)
- gdk_rgba_free (wk_editor->priv->font_color);
- wk_editor->priv->font_color = gdk_rgba_copy (&color);
+ if (value != wk_editor->priv->alignment) {
+ wk_editor->priv->alignment = value;
+ g_object_notify (object, "alignment");
}
}
- g_free (font_color);
+ g_clear_object (&jsc_value);
- g_object_notify (G_OBJECT (wk_editor), "can-undo");
- g_object_notify (G_OBJECT (wk_editor), "can-redo");
+ 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);
- g_object_notify (G_OBJECT (wk_editor), "alignment");
- g_object_notify (G_OBJECT (wk_editor), "block-format");
- g_object_notify (G_OBJECT (wk_editor), "indented");
+ if (value != wk_editor->priv->block_format) {
+ wk_editor->priv->block_format = value;
+ g_object_notify (object, "block-format");
+ }
+ }
+ g_clear_object (&jsc_value);
+
+ 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");
+ }
+ }
+ g_clear_object (&jsc_value);
+
+ style_flags = E_CONTENT_EDITOR_STYLE_NONE;
+
+ 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);
- if (wk_editor->priv->html_mode) {
- /* g_object_notify (G_OBJECT (wk_editor), "background-color"); */
g_object_notify (G_OBJECT (wk_editor), "bold");
- /* g_object_notify (G_OBJECT (wk_editor), "font-name"); */
- g_object_notify (G_OBJECT (wk_editor), "font-size");
- g_object_notify (G_OBJECT (wk_editor), "font-color");
+ }
+ g_clear_object (&jsc_value);
+
+ 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");
- g_object_notify (G_OBJECT (wk_editor), "monospaced");
- g_object_notify (G_OBJECT (wk_editor), "strikethrough");
- g_object_notify (G_OBJECT (wk_editor), "subscript");
- g_object_notify (G_OBJECT (wk_editor), "superscript");
+ }
+ g_clear_object (&jsc_value);
+
+ 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");
}
+ g_clear_object (&jsc_value);
- g_object_thaw_notify (G_OBJECT (wk_editor));
-}
+ 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");
+ }
+ g_clear_object (&jsc_value);
+
+ 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));
+
+ if ((wk_editor->priv->style_flags & E_CONTENT_EDITOR_STYLE_IS_SUBSCRIPT) != (style_flags &
E_CONTENT_EDITOR_STYLE_IS_SUBSCRIPT))
+ 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))
+ 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;
+ 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");
+ }
+ }
+ g_clear_object (&jsc_value);
+
+ 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);
+
+ 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");
+ } else {
+ g_free (value);
+ }
+ }
+ g_clear_object (&jsc_value);
+
+ if (webkit_editor_update_color_value (jsc_params, "fgColor", &wk_editor->priv->font_color))
+ g_object_notify (object, "font-color");
+
+ if (webkit_editor_update_color_value (jsc_params, "bgColor", &wk_editor->priv->background_color))
+ g_object_notify (object, "background-color");
+
+ webkit_editor_update_color_value (jsc_params, "bodyFgColor", &wk_editor->priv->body_fg_color);
+ webkit_editor_update_color_value (jsc_params, "bodyBgColor", &wk_editor->priv->body_bg_color);
+ webkit_editor_update_color_value (jsc_params, "bodyLinkColor", &wk_editor->priv->body_link_color);
+ webkit_editor_update_color_value (jsc_params, "bodyVlinkColor", &wk_editor->priv->body_vlink_color);
+
+ g_object_thaw_notify (object);
+}
static void
undu_redo_state_changed_cb (WebKitUserContentManager *manager,
@@ -601,18 +706,6 @@ e_webkit_editor_set_web_extension_proxy (EWebKitEditor *wk_editor,
if (connection && g_dbus_connection_is_closed (connection))
connection = NULL;
- if (wk_editor->priv->web_extension_content_changed_cb_id) {
- if (connection)
- g_dbus_connection_signal_unsubscribe (connection,
wk_editor->priv->web_extension_content_changed_cb_id);
- wk_editor->priv->web_extension_content_changed_cb_id = 0;
- }
-
- if (wk_editor->priv->web_extension_selection_changed_cb_id) {
- if (connection)
- g_dbus_connection_signal_unsubscribe (connection,
wk_editor->priv->web_extension_selection_changed_cb_id);
- wk_editor->priv->web_extension_selection_changed_cb_id = 0;
- }
-
if (wk_editor->priv->web_extension_user_changed_default_colors_cb_id) {
if (connection)
g_dbus_connection_signal_unsubscribe (connection,
wk_editor->priv->web_extension_user_changed_default_colors_cb_id);
@@ -625,32 +718,6 @@ e_webkit_editor_set_web_extension_proxy (EWebKitEditor *wk_editor,
if (proxy) {
wk_editor->priv->web_extension_proxy = g_object_ref (proxy);
- wk_editor->priv->web_extension_selection_changed_cb_id =
- g_dbus_connection_signal_subscribe (
- g_dbus_proxy_get_connection (wk_editor->priv->web_extension_proxy),
- g_dbus_proxy_get_name (wk_editor->priv->web_extension_proxy),
- E_WEBKIT_EDITOR_WEB_EXTENSION_INTERFACE,
- "SelectionChanged",
- E_WEBKIT_EDITOR_WEB_EXTENSION_OBJECT_PATH,
- NULL,
- G_DBUS_SIGNAL_FLAGS_NONE,
- (GDBusSignalCallback) web_extension_selection_changed_cb,
- wk_editor,
- NULL);
-
- wk_editor->priv->web_extension_content_changed_cb_id =
- g_dbus_connection_signal_subscribe (
- g_dbus_proxy_get_connection (wk_editor->priv->web_extension_proxy),
- g_dbus_proxy_get_name (wk_editor->priv->web_extension_proxy),
- E_WEBKIT_EDITOR_WEB_EXTENSION_INTERFACE,
- "ContentChanged",
- E_WEBKIT_EDITOR_WEB_EXTENSION_OBJECT_PATH,
- NULL,
- G_DBUS_SIGNAL_FLAGS_NONE,
- (GDBusSignalCallback) web_extension_content_changed_cb,
- wk_editor,
- NULL);
-
wk_editor->priv->web_extension_user_changed_default_colors_cb_id =
g_dbus_connection_signal_subscribe (
g_dbus_proxy_get_connection (wk_editor->priv->web_extension_proxy),
@@ -753,53 +820,6 @@ webkit_editor_remove_element_attribute (EWebKitEditor *wk_editor,
"ElementRemoveAttributeBySelector", g_variant_new ("(tss)", page_id, selector, attribute));
}
-static void
-webkit_editor_set_format_boolean (EWebKitEditor *wk_editor,
- const gchar *format_dom_function,
- gboolean format_value)
-{
- guint64 page_id;
-
- page_id = current_page_id (wk_editor);
-
- e_web_extension_container_call_simple (wk_editor->priv->container, page_id, wk_editor->priv->stamp,
- format_dom_function, g_variant_new ("(tb)", page_id, format_value));
-}
-
-static void
-webkit_editor_set_format_int (EWebKitEditor *wk_editor,
- const gchar *format_dom_function,
- gint32 format_value)
-{
- guint64 page_id;
-
- page_id = current_page_id (wk_editor);
-
- e_web_extension_container_call_simple (wk_editor->priv->container, page_id, wk_editor->priv->stamp,
- format_dom_function, g_variant_new ("(ti)", page_id, format_value));
-}
-
-static void
-webkit_editor_set_format_string (EWebKitEditor *wk_editor,
- const gchar *format_name,
- const gchar *format_dom_function,
- const gchar *format_value)
-{
- guint64 page_id;
-
- if (!wk_editor->priv->html_mode)
- return;
-
- webkit_editor_set_changed (wk_editor, TRUE);
-
- page_id = current_page_id (wk_editor);
-
- e_web_extension_container_call_simple (wk_editor->priv->container, page_id, wk_editor->priv->stamp,
- format_dom_function, g_variant_new ("(ts)", page_id, format_value));
-
- g_object_notify (G_OBJECT (wk_editor), format_name);
-}
-
static void
webkit_editor_queue_post_reload_operation (EWebKitEditor *wk_editor,
PostReloadOperationFunc func,
@@ -1361,200 +1381,116 @@ webkit_editor_update_styles (EContentEditor *editor)
}
static void
-webkit_editor_page_set_text_color (EContentEditor *editor,
- const GdkRGBA *value)
+webkit_editor_set_body_color_attribute (EContentEditor *editor,
+ const gchar *attr_name,
+ const GdkRGBA *value)
{
- EWebKitEditor *wk_editor;
- gchar *color;
+ EWebKitEditor *wk_editor = E_WEBKIT_EDITOR (editor);
- wk_editor = E_WEBKIT_EDITOR (editor);
+ if (value && value->alpha > 1e-9) {
+ gchar color[64];
- color = g_strdup_printf ("#%06x", e_rgba_to_value (value));
+ g_snprintf (color, 63, "#%06x", e_rgba_to_value (value));
- webkit_editor_set_element_attribute (wk_editor, "body", "text", color);
+ e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
+ "EvoEditor.SetBodyAttribute(%s, %s);",
+ attr_name,
+ color);
+ } else {
+ e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
+ "EvoEditor.SetBodyAttribute(%s, null);",
+ attr_name);
+ }
+}
- g_free (color);
+static void
+webkit_editor_page_set_text_color (EContentEditor *editor,
+ const GdkRGBA *value)
+{
+ webkit_editor_set_body_color_attribute (editor, "text", value);
}
static void
webkit_editor_page_get_text_color (EContentEditor *editor,
GdkRGBA *color)
{
- EWebKitEditor *wk_editor;
- GVariant *result;
-
- wk_editor = E_WEBKIT_EDITOR (editor);
-
- if (!wk_editor->priv->html_mode)
- goto theme;
-
- result = webkit_editor_get_element_attribute (wk_editor, "body", "text");
- if (result) {
- const gchar *value;
+ EWebKitEditor *wk_editor = E_WEBKIT_EDITOR (editor);
- g_variant_get (result, "(&s)", &value);
- if (!value || !*value || !gdk_rgba_parse (color, value)) {
- g_variant_unref (result);
- goto theme;
- }
- g_variant_unref (result);
- return;
+ if (wk_editor->priv->html_mode &&
+ wk_editor->priv->body_fg_color) {
+ *color = *wk_editor->priv->body_fg_color;
+ } else {
+ e_utils_get_theme_color (GTK_WIDGET (wk_editor), "theme_text_color",
E_UTILS_DEFAULT_THEME_TEXT_COLOR, color);
}
-
- theme:
- e_utils_get_theme_color (
- GTK_WIDGET (wk_editor),
- "theme_text_color",
- E_UTILS_DEFAULT_THEME_TEXT_COLOR,
- color);
}
static void
webkit_editor_page_set_background_color (EContentEditor *editor,
const GdkRGBA *value)
{
- EWebKitEditor *wk_editor;
- gchar *color;
-
- wk_editor = E_WEBKIT_EDITOR (editor);
-
- if (value->alpha != 0.0)
- color = g_strdup_printf ("#%06x", e_rgba_to_value (value));
- else
- color = g_strdup ("");
-
- webkit_editor_set_element_attribute (wk_editor, "body", "bgcolor", color);
-
- g_free (color);
+ webkit_editor_set_body_color_attribute (editor, "bgcolor", value);
}
static void
webkit_editor_page_get_background_color (EContentEditor *editor,
GdkRGBA *color)
{
- EWebKitEditor *wk_editor;
- GVariant *result;
+ EWebKitEditor *wk_editor = E_WEBKIT_EDITOR (editor);
- wk_editor = E_WEBKIT_EDITOR (editor);
-
- if (!wk_editor->priv->html_mode)
- goto theme;
-
- result = webkit_editor_get_element_attribute (wk_editor, "body", "bgcolor");
- if (result) {
- const gchar *value;
-
- g_variant_get (result, "(&s)", &value);
- if (!value || !*value || !gdk_rgba_parse (color, value)) {
- g_variant_unref (result);
- goto theme;
- }
- g_variant_unref (result);
- return;
+ if (wk_editor->priv->html_mode &&
+ wk_editor->priv->body_bg_color) {
+ *color = *wk_editor->priv->body_bg_color;
+ } else {
+ e_utils_get_theme_color (GTK_WIDGET (wk_editor), "theme_base_color",
E_UTILS_DEFAULT_THEME_BASE_COLOR, color);
}
-
- theme:
- e_utils_get_theme_color (
- GTK_WIDGET (wk_editor),
- "theme_base_color",
- E_UTILS_DEFAULT_THEME_BASE_COLOR,
- color);
}
static void
webkit_editor_page_set_link_color (EContentEditor *editor,
const GdkRGBA *value)
{
- EWebKitEditor *wk_editor;
- gchar *color;
-
- wk_editor = E_WEBKIT_EDITOR (editor);
-
- color = g_strdup_printf ("#%06x", e_rgba_to_value (value));
-
- webkit_editor_set_element_attribute (wk_editor, "body", "link", color);
-
- g_free (color);
+ webkit_editor_set_body_color_attribute (editor, "link", value);
}
static void
webkit_editor_page_get_link_color (EContentEditor *editor,
GdkRGBA *color)
{
- EWebKitEditor *wk_editor;
- GVariant *result;
-
- wk_editor = E_WEBKIT_EDITOR (editor);
-
- if (!wk_editor->priv->html_mode)
- goto theme;
-
- result = webkit_editor_get_element_attribute (wk_editor, "body", "link");
- if (result) {
- const gchar *value;
+ EWebKitEditor *wk_editor = E_WEBKIT_EDITOR (editor);
- g_variant_get (result, "(&s)", &value);
- if (!value || !*value || !gdk_rgba_parse (color, value)) {
- g_variant_unref (result);
- goto theme;
- }
- g_variant_unref (result);
- return;
+ if (wk_editor->priv->html_mode &&
+ wk_editor->priv->body_link_color) {
+ *color = *wk_editor->priv->body_link_color;
+ } else {
+ color->alpha = 1;
+ color->red = 0;
+ color->green = 0;
+ color->blue = 1;
}
-
- theme:
- color->alpha = 1;
- color->red = 0;
- color->green = 0;
- color->blue = 1;
}
static void
webkit_editor_page_set_visited_link_color (EContentEditor *editor,
const GdkRGBA *value)
{
- EWebKitEditor *wk_editor;
- gchar *color;
-
- wk_editor = E_WEBKIT_EDITOR (editor);
-
- color = g_strdup_printf ("#%06x", e_rgba_to_value (value));
-
- webkit_editor_set_element_attribute (wk_editor, "body", "vlink", color);
-
- g_free (color);
+ webkit_editor_set_body_color_attribute (editor, "vlink", value);
}
static void
webkit_editor_page_get_visited_link_color (EContentEditor *editor,
GdkRGBA *color)
{
- EWebKitEditor *wk_editor;
- GVariant *result;
+ EWebKitEditor *wk_editor = E_WEBKIT_EDITOR (editor);
- wk_editor = E_WEBKIT_EDITOR (editor);
-
- if (!wk_editor->priv->html_mode)
- goto theme;
-
- result = webkit_editor_get_element_attribute (wk_editor, "body", "vlink");
- if (result) {
- const gchar *value;
-
- g_variant_get (result, "(&s)", &value);
- if (!value || !*value || !gdk_rgba_parse (color, value)) {
- g_variant_unref (result);
- goto theme;
- }
- g_variant_unref (result);
- return;
+ if (wk_editor->priv->html_mode &&
+ wk_editor->priv->body_vlink_color) {
+ *color = *wk_editor->priv->body_vlink_color;
+ } else {
+ color->alpha = 1;
+ color->red = 1;
+ color->green = 0;
+ color->blue = 0;
}
-
- theme:
- color->alpha = 1;
- color->red = 1;
- color->green = 0;
- color->blue = 0;
}
static void
@@ -2222,8 +2158,8 @@ webkit_editor_selection_indent (EContentEditor *editor)
wk_editor = E_WEBKIT_EDITOR (editor);
- webkit_editor_call_simple_extension_function (
- wk_editor, "DOMSelectionIndent");
+ e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
+ "EvoEditor.Indent(+1);");
}
static void
@@ -2233,8 +2169,8 @@ webkit_editor_selection_unindent (EContentEditor *editor)
wk_editor = E_WEBKIT_EDITOR (editor);
- webkit_editor_call_simple_extension_function (
- wk_editor, "DOMSelectionUnindent");
+ e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
+ "EvoEditor.Indent(-1);");
}
static void
@@ -3820,21 +3756,16 @@ webkit_editor_set_background_color (EWebKitEditor *wk_editor,
g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
- if (gdk_rgba_equal (value, wk_editor->priv->background_color))
+ if ((!value && !wk_editor->priv->background_color) ||
+ (value && wk_editor->priv->background_color && gdk_rgba_equal (value,
wk_editor->priv->background_color)))
return;
- color = g_strdup_printf ("#%06x", e_rgba_to_value (value));
-
- if (wk_editor->priv->background_color)
- gdk_rgba_free (wk_editor->priv->background_color);
-
- wk_editor->priv->background_color = gdk_rgba_copy (value);
+ if (value)
+ color = g_strdup_printf ("#%06x", e_rgba_to_value (value));
+ else
+ color = NULL;
- webkit_editor_set_format_string (
- wk_editor,
- "background-color",
- "DOMSelectionSetBackgroundColor",
- color);
+ webkit_web_view_execute_editing_command_with_argument (WEBKIT_WEB_VIEW (wk_editor), "BackColor",
color ? color : "");
g_free (color);
}
@@ -3844,12 +3775,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->web_extension_proxy) {
- g_warning ("EHTMLEditorWebExtension not ready at %s!", G_STRFUNC);
- return NULL;
- }
-
- if (!wk_editor->priv->html_mode || !wk_editor->priv->background_color)
+ if (!wk_editor->priv->background_color)
return &white;
return wk_editor->priv->background_color;
@@ -3861,10 +3787,7 @@ webkit_editor_set_font_name (EWebKitEditor *wk_editor,
{
g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
- wk_editor->priv->font_name = g_strdup (value);
-
- webkit_editor_set_format_string (
- wk_editor, "font-name", "DOMSelectionSetFontName", value);
+ webkit_web_view_execute_editing_command_with_argument (WEBKIT_WEB_VIEW (wk_editor), "FontName",
value);
}
static const gchar *
@@ -3883,21 +3806,16 @@ webkit_editor_set_font_color (EWebKitEditor *wk_editor,
g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
- if (gdk_rgba_equal (value, wk_editor->priv->font_color))
+ if ((!value && !wk_editor->priv->font_color) ||
+ (value && wk_editor->priv->font_color && gdk_rgba_equal (value, wk_editor->priv->font_color)))
return;
- color = g_strdup_printf ("#%06x", e_rgba_to_value (value));
-
- if (wk_editor->priv->font_color)
- gdk_rgba_free (wk_editor->priv->font_color);
-
- wk_editor->priv->font_color = gdk_rgba_copy (value);
+ if (value)
+ color = g_strdup_printf ("#%06x", e_rgba_to_value (value));
+ else
+ color = NULL;
- webkit_editor_set_format_string (
- wk_editor,
- "font-color",
- "DOMSelectionSetFontColor",
- color);
+ webkit_web_view_execute_editing_command_with_argument (WEBKIT_WEB_VIEW (wk_editor), "ForeColor",
color ? color : "");
g_free (color);
}
@@ -3907,11 +3825,6 @@ webkit_editor_get_font_color (EWebKitEditor *wk_editor)
{
g_return_val_if_fail (E_IS_WEBKIT_EDITOR (wk_editor), NULL);
- if (!wk_editor->priv->web_extension_proxy) {
- g_warning ("EHTMLEditorWebExtension not ready at %s!", G_STRFUNC);
- return NULL;
- }
-
if (!wk_editor->priv->html_mode || !wk_editor->priv->font_color)
return &black;
@@ -3922,15 +3835,21 @@ static void
webkit_editor_set_font_size (EWebKitEditor *wk_editor,
gint value)
{
+ gchar sz[2] = { 0, 0 };
+
g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
if (wk_editor->priv->font_size == value)
return;
- wk_editor->priv->font_size = value;
+ if (value >= 1 && value <= 7) {
+ sz[0] = '0' + value;
+ } else {
+ g_warn_if_reached ();
+ return;
+ }
- webkit_editor_set_format_int (
- wk_editor, "DOMSelectionSetFontSize", value);
+ webkit_web_view_execute_editing_command_with_argument (WEBKIT_WEB_VIEW (wk_editor), "FontSize", sz);
}
static gint
@@ -3944,17 +3863,38 @@ webkit_editor_get_font_size (EWebKitEditor *wk_editor)
static void
webkit_editor_set_style_flag (EWebKitEditor *wk_editor,
EContentEditorStyleFlags flag,
- gboolean do_set,
- const gchar *dom_function_name)
+ gboolean do_set)
{
g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
if (((wk_editor->priv->style_flags & flag) != 0 ? 1 : 0) == (do_set ? 1 : 0))
return;
- wk_editor->priv->style_flags = (wk_editor->priv->style_flags & ~flag) | (do_set ? flag : 0);
-
- webkit_editor_set_format_boolean (wk_editor, dom_function_name, do_set);
+ switch (flag) {
+ case E_CONTENT_EDITOR_STYLE_NONE:
+ break;
+ case E_CONTENT_EDITOR_STYLE_IS_BOLD:
+ webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (wk_editor), "Bold");
+ break;
+ case E_CONTENT_EDITOR_STYLE_IS_ITALIC:
+ webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (wk_editor), "Italic");
+ break;
+ case E_CONTENT_EDITOR_STYLE_IS_UNDERLINE:
+ webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (wk_editor), "Underline");
+ break;
+ case E_CONTENT_EDITOR_STYLE_IS_STRIKETHROUGH:
+ webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (wk_editor), "Strikethrough");
+ break;
+ case E_CONTENT_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:
+ webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (wk_editor), "Subscript");
+ break;
+ case E_CONTENT_EDITOR_STYLE_IS_SUPERSCRIPT:
+ webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (wk_editor), "Superscript");
+ break;
+ }
}
static gboolean
@@ -5234,9 +5174,15 @@ webkit_editor_constructed (GObject *object)
manager = webkit_web_view_get_user_content_manager (WEBKIT_WEB_VIEW (wk_editor));
+ g_signal_connect_object (manager, "script-message-received::contentChanged",
+ G_CALLBACK (content_changed_cb), wk_editor, 0);
+ g_signal_connect_object (manager, "script-message-received::formattingChanged",
+ G_CALLBACK (formatting_changed_cb), wk_editor, 0);
g_signal_connect_object (manager, "script-message-received::undoRedoStateChanged",
G_CALLBACK (undu_redo_state_changed_cb), wk_editor, 0);
+ webkit_user_content_manager_register_script_message_handler (manager, "contentChanged");
+ webkit_user_content_manager_register_script_message_handler (manager, "formattingChanged");
webkit_user_content_manager_register_script_message_handler (manager, "undoRedoStateChanged");
/* Give spell check languages to WebKit */
@@ -5400,15 +5346,12 @@ webkit_editor_finalize (GObject *object)
priv->post_reload_operations = NULL;
}
- if (priv->background_color != NULL) {
- gdk_rgba_free (priv->background_color);
- priv->background_color = NULL;
- }
-
- if (priv->font_color != NULL) {
- gdk_rgba_free (priv->font_color);
- priv->font_color = NULL;
- }
+ g_clear_pointer (&priv->background_color, gdk_rgba_free);
+ g_clear_pointer (&priv->font_color, gdk_rgba_free);
+ g_clear_pointer (&priv->body_fg_color, gdk_rgba_free);
+ g_clear_pointer (&priv->body_bg_color, gdk_rgba_free);
+ g_clear_pointer (&priv->body_link_color, gdk_rgba_free);
+ g_clear_pointer (&priv->body_vlink_color, gdk_rgba_free);
g_free (priv->last_hover_uri);
priv->last_hover_uri = NULL;
@@ -5464,8 +5407,7 @@ webkit_editor_set_property (GObject *object,
webkit_editor_set_style_flag (
E_WEBKIT_EDITOR (object),
E_CONTENT_EDITOR_STYLE_IS_BOLD,
- g_value_get_boolean (value),
- "DOMSelectionSetBold");
+ g_value_get_boolean (value));
return;
case PROP_FONT_COLOR:
@@ -5496,48 +5438,42 @@ webkit_editor_set_property (GObject *object,
webkit_editor_set_style_flag (
E_WEBKIT_EDITOR (object),
E_CONTENT_EDITOR_STYLE_IS_ITALIC,
- g_value_get_boolean (value),
- "DOMSelectionSetItalic");
+ g_value_get_boolean (value));
return;
case PROP_MONOSPACED:
webkit_editor_set_style_flag (
E_WEBKIT_EDITOR (object),
E_CONTENT_EDITOR_STYLE_IS_MONOSPACE,
- g_value_get_boolean (value),
- "DOMSelectionSetMonospaced");
+ g_value_get_boolean (value));
return;
case PROP_STRIKETHROUGH:
webkit_editor_set_style_flag (
E_WEBKIT_EDITOR (object),
E_CONTENT_EDITOR_STYLE_IS_STRIKETHROUGH,
- g_value_get_boolean (value),
- "DOMSelectionSetStrikethrough");
+ g_value_get_boolean (value));
return;
case PROP_SUBSCRIPT:
webkit_editor_set_style_flag (
E_WEBKIT_EDITOR (object),
E_CONTENT_EDITOR_STYLE_IS_SUBSCRIPT,
- g_value_get_boolean (value),
- "DOMSelectionSetSubscript");
+ g_value_get_boolean (value));
return;
case PROP_SUPERSCRIPT:
webkit_editor_set_style_flag (
E_WEBKIT_EDITOR (object),
E_CONTENT_EDITOR_STYLE_IS_SUPERSCRIPT,
- g_value_get_boolean (value),
- "DOMSelectionSetSuperscript");
+ g_value_get_boolean (value));
return;
case PROP_UNDERLINE:
webkit_editor_set_style_flag (
E_WEBKIT_EDITOR (object),
E_CONTENT_EDITOR_STYLE_IS_UNDERLINE,
- g_value_get_boolean (value),
- "DOMSelectionSetUnderline");
+ g_value_get_boolean (value));
return;
case PROP_START_BOTTOM:
@@ -6640,8 +6576,6 @@ e_webkit_editor_init (EWebKitEditor *wk_editor)
wk_editor->priv->start_bottom = E_THREE_STATE_INCONSISTENT;
wk_editor->priv->top_signature = E_THREE_STATE_INCONSISTENT;
- wk_editor->priv->web_extension_selection_changed_cb_id = 0;
- wk_editor->priv->web_extension_content_changed_cb_id = 0;
wk_editor->priv->web_extension_user_changed_default_colors_cb_id = 0;
}
diff --git a/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
b/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
index 7b02093190..d357c122b1 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
@@ -2520,7 +2520,7 @@ window_object_cleared_cb (WebKitScriptWorld *world,
jsc_context = webkit_frame_get_js_context (frame);
- /* Read in order as each other uses the previous */
+ /* Read in order approximately as each other uses the previous */
load_javascript_file (jsc_context, "e-convert.js");
load_javascript_file (jsc_context, "e-selection.js");
load_javascript_file (jsc_context, "e-undo-redo.js");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]