[evolution/wip/mcrha/webkit-jsc-api] Converted more functions to JSC API, enabled file:// URI load in composer
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/mcrha/webkit-jsc-api] Converted more functions to JSC API, enabled file:// URI load in composer
- Date: Thu, 16 Jan 2020 17:43:09 +0000 (UTC)
commit bc8ef05199dba922f3481376bafb28801f92e68c
Author: Milan Crha <mcrha redhat com>
Date: Thu Jan 16 18:44:29 2020 +0100
Converted more functions to JSC API, enabled file:// URI load in composer
data/webkit/e-editor.js | 27 +++++++
src/modules/webkit-editor/e-webkit-editor.c | 83 +++++++++++++---------
.../web-extension/e-editor-web-extension.c | 11 ++-
3 files changed, 86 insertions(+), 35 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 761a0cb557..cc05bb5fb8 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -3416,6 +3416,33 @@ EvoEditor.SpellCheckContinue = function(fromCaret, directionNext)
return null;
}
+EvoEditor.MoveSelectionToPoint = function(xx, yy, cancel_if_not_collapsed)
+{
+ if (!cancel_if_not_collapsed || document.getSelection().isCollapsed) {
+ var range = document.caretRangeFromPoint(xx, yy);
+
+ document.getSelection().removeAllRanges();
+ document.getSelection().addRange(range);
+ }
+}
+
+EvoEditor.InsertEmoticon = function(text, imageUri)
+{
+ if (imageUri) {
+ EvoEditor.InsertHTML("InsertEmoticon",
+ "<span class=\"-x-evo-smiley-wrapper\">" +
+ "<img class=\"-x-evo-smiley-img\" src=\"" + imageUri + "\" alt=\"" +
+ text.replace(/\&/g, "&").replace(/\"/g, """).replace(/\'/g,
"'") +
+ "\">" +
+ "<span class=\"-x-evo-smiley-text\">" +
+ text.replace(/\&/g, "&").replace(/</g, "<").replace(/>/g, ">") +
+ "</span>" +
+ "</span>​");
+ } else {
+ EvoEditor.InsertHTML("InsertEmoticon", text);
+ }
+}
+
EvoEditor.onContextMenu = function(event)
{
var node = event.target;
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index 9efdb6b8ce..8ba2d00960 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -1376,13 +1376,21 @@ webkit_editor_update_styles (EContentEditor *editor)
" font-family: Monospace; \n"
"}\n");
- g_string_append (
- stylesheet,
- "body[data-evo-plain-text] img.-x-evo-smiley-img, "
- "body:not([data-evo-plain-text]) span.-x-evo-smiley-text "
- "{\n"
- " display: none \n"
- "}\n");
+ if (wk_editor->priv->html_mode) {
+ g_string_append (
+ stylesheet,
+ "span.-x-evo-smiley-text"
+ "{\n"
+ " display: none \n"
+ "}\n");
+ } else {
+ g_string_append (
+ stylesheet,
+ "img.-x-evo-smiley-img"
+ "{\n"
+ " display: none \n"
+ "}\n");
+ }
g_string_append (
stylesheet,
@@ -2382,28 +2390,19 @@ webkit_editor_redo (EContentEditor *editor)
static void
webkit_editor_move_caret_on_coordinates (EContentEditor *editor,
- gint x,
- gint y,
- gboolean cancel_if_not_collapsed)
+ gint xx,
+ gint yy,
+ gboolean cancel_if_not_collapsed)
{
EWebKitEditor *wk_editor;
- GVariant *result;
- wk_editor = E_WEBKIT_EDITOR (editor);
- if (!wk_editor->priv->web_extension_proxy) {
- printf ("EHTMLEditorWebExtension not ready at %s!\n", G_STRFUNC);
- return;
- }
+ g_return_if_fail (E_IS_WEBKIT_EDITOR (editor));
- result = e_util_invoke_g_dbus_proxy_call_sync_wrapper_with_error_check (
- wk_editor->priv->web_extension_proxy,
- "DOMMoveSelectionOnPoint",
- g_variant_new (
- "(tiib)", current_page_id (wk_editor), x, y, cancel_if_not_collapsed),
- NULL);
+ wk_editor = E_WEBKIT_EDITOR (editor);
- if (result)
- g_variant_unref (result);
+ e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
+ "EvoEditor.MoveSelectionToPoint(%d, %d, %x);",
+ xx, yy, cancel_if_not_collapsed);
}
static void
@@ -2411,19 +2410,30 @@ webkit_editor_insert_emoticon (EContentEditor *editor,
EEmoticon *emoticon)
{
EWebKitEditor *wk_editor;
+ GSettings *settings;
+ const gchar *text;
+ gchar *image_uri = NULL;
- wk_editor = E_WEBKIT_EDITOR (editor);
- if (!wk_editor->priv->web_extension_proxy) {
- printf ("EHTMLEditorWebExtension not ready at %s!\n", G_STRFUNC);
- return;
+ g_return_if_fail (E_IS_WEBKIT_EDITOR (editor));
+ g_return_if_fail (emoticon != NULL);
+
+ settings = e_util_ref_settings ("org.gnome.evolution.mail");
+
+ if (g_settings_get_boolean (settings, "composer-unicode-smileys")) {
+ text = emoticon->unicode_character;
+ } else {
+ text = emoticon->text_face;
+ image_uri = e_emoticon_get_uri (emoticon);
}
- e_util_invoke_g_dbus_proxy_call_with_error_check (
- wk_editor->priv->web_extension_proxy,
- "DOMInsertSmiley",
- g_variant_new (
- "(ts)", current_page_id (wk_editor), e_emoticon_get_name (emoticon)),
- wk_editor->priv->cancellable);
+ wk_editor = E_WEBKIT_EDITOR (editor);
+
+ e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
+ "EvoEditor.InsertEmoticon(%s, %s);",
+ text, image_uri);
+
+ g_clear_object (&settings);
+ g_free (image_uri);
}
static void
@@ -4241,6 +4251,11 @@ webkit_editor_constructed (GObject *object)
g_object_ref (content_request), g_object_unref);
g_object_unref (content_request);
+ content_request = e_file_request_new ();
+ webkit_web_context_register_uri_scheme (web_context, "evo-file", webkit_editor_process_uri_request_cb,
+ g_object_ref (content_request), g_object_unref);
+ g_object_unref (content_request);
+
webkit_web_view_set_editable (web_view, TRUE);
web_settings = webkit_web_view_get_settings (web_view);
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 765f8ffb63..560a00d24c 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
@@ -59,7 +59,7 @@ static void
e_editor_web_extension_init (EEditorWebExtension *extension)
{
extension->priv = e_editor_web_extension_get_instance_private (extension);
- extension->priv->spell_checker = e_spell_checker_new ();
+ extension->priv->spell_checker = NULL;
}
static gpointer
@@ -234,6 +234,9 @@ evo_editor_jsc_set_spell_check_languages (const gchar *langs,
else
strv = NULL;
+ if (!extension->priv->spell_checker)
+ extension->priv->spell_checker = e_spell_checker_new ();
+
e_spell_checker_set_active_languages (extension->priv->spell_checker, (const gchar * const *) strv);
g_object_unref (extension);
@@ -256,6 +259,12 @@ evo_editor_jsc_spell_check_word (const gchar *word,
if (!extension)
return TRUE;
+ /* It should be created as part of EvoEditor.SetSpellCheckLanguages(). */
+ g_warn_if_fail (extension->priv->spell_checker != NULL);
+
+ if (!extension->priv->spell_checker)
+ extension->priv->spell_checker = e_spell_checker_new ();
+
is_correct = e_spell_checker_check_word (extension->priv->spell_checker, word, -1);
g_object_unref (extension);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]