[evolution/wip/webkit2] Partially port e-utils to WK2 (still some code is commented out)
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit2] Partially port e-utils to WK2 (still some code is commented out)
- Date: Fri, 5 Dec 2014 13:42:17 +0000 (UTC)
commit 527a49ce678f4fbc7c026c19ad4742cc39b06fcc
Author: Tomas Popela <tpopela redhat com>
Date: Fri Dec 5 14:40:47 2014 +0100
Partially port e-utils to WK2 (still some code is commented out)
e-util/Makefile.am | 61 +-
e-util/e-dom-utils.c | 2 +-
e-util/e-html-editor-actions.c | 53 +-
e-util/e-html-editor-cell-dialog-dom-functions.h | 8 +-
e-util/e-html-editor-dom-functions.c | 2 +-
...nsion-names.h => e-html-editor-dom-functions.h} | 21 +-
e-util/e-html-editor-link-dialog.c | 5 +-
e-util/e-html-editor-selection-dom-functions.c | 357 ++--
e-util/e-html-editor-selection-dom-functions.h | 98 +-
e-util/e-html-editor-selection.c | 53 +-
e-util/e-html-editor-selection.h | 72 -
...-html-editor-spell-check-dialog-dom-functions.c | 190 ++
...html-editor-spell-check-dialog-dom-functions.h} | 22 +-
e-util/e-html-editor-spell-check-dialog.c | 257 +--
e-util/e-html-editor-table-dialog-dom-functions.c | 31 +-
e-util/e-html-editor-table-dialog-dom-functions.h | 4 +-
e-util/e-html-editor-view-dom-functions.c | 1957 +++++++++++++++-----
e-util/e-html-editor-view-dom-functions.h | 41 +-
e-util/e-html-editor-view.c | 1664 +++--------------
e-util/e-html-editor-view.h | 8 +-
.../e-html-editor-web-extension-main.c | 0
.../e-html-editor-web-extension-names.h | 0
.../e-html-editor-web-extension.c | 338 +++-
.../e-html-editor-web-extension.h | 27 +
e-util/e-html-editor.c | 30 +-
e-util/e-mail-signature-editor.c | 34 +-
e-util/e-misc-utils.c | 37 +
e-util/e-misc-utils.h | 2 +
e-util/e-web-view.c | 135 +-
e-util/e-web-view.h | 2 +-
e-util/web-extensions/Makefile.am | 24 -
web-extensions/Makefile.am | 11 +-
web-extensions/e-web-extension-main.c | 1 +
.../e-web-extension-names.h | 14 +-
web-extensions/e-web-extension.c | 5 +-
35 files changed, 2936 insertions(+), 2630 deletions(-)
---
diff --git a/e-util/Makefile.am b/e-util/Makefile.am
index ca267ec..0431949 100644
--- a/e-util/Makefile.am
+++ b/e-util/Makefile.am
@@ -1,5 +1,7 @@
NULL =
+webextensions_LTLIBRARIES = libehtmleditorwebextension.la
+
privsolib_LTLIBRARIES = libevolution-util.la
evolution_util_includedir = $(privincludedir)/e-util
@@ -61,7 +63,6 @@ noinst_PROGRAMS = \
test-category-completion \
test-contact-store \
test-dateedit \
- test-html-editor \
test-mail-signatures \
test-name-selector \
test-preferences-window \
@@ -200,22 +201,16 @@ evolution_util_include_HEADERS = \
e-filter-rule.h \
e-focus-tracker.h \
e-html-editor-actions.h \
- e-html-editor-actions-dom-functions.h \
e-html-editor-cell-dialog.h \
- e-html-editor-cell-dialog-dom-functions.h \
e-html-editor-dialog.h \
e-html-editor-find-dialog.h \
e-html-editor-hrule-dialog.h \
- e-html-editor-hrule-dialog-dom-functions.h \
e-html-editor-image-dialog.h \
- e-html-editor-image-dialog-dom-functions.h \
e-html-editor-link-dialog.h \
- e-html-editor-link-dialog-dom-functions.h \
e-html-editor-page-dialog.h \
e-html-editor-paragraph-dialog.h \
e-html-editor-replace-dialog.h \
e-html-editor-selection.h \
- e-html-editor-selection-dom-functions.h \
e-html-editor-spell-check-dialog.h \
e-html-editor-table-dialog.h \
e-html-editor-text-dialog.h \
@@ -287,9 +282,6 @@ evolution_util_include_HEADERS = \
e-source-selector-dialog.h \
e-source-selector.h \
e-source-util.h \
- e-spell-checker.h \
- e-spell-dictionary.h \
- e-spell-entry.h \
e-spell-text-view.h \
e-spinner.h \
e-stock-request.h \
@@ -478,23 +470,17 @@ libevolution_util_la_SOURCES = \
e-filter-rule.c \
e-focus-tracker.c \
e-html-editor-actions.c \
- e-html-editor-actions-dom-functions.c \
e-html-editor-cell-dialog.c \
- e-html-editor-cell-dialog-dom-functions.c \
e-html-editor-dialog.c \
e-html-editor-find-dialog.c \
e-html-editor-hrule-dialog.c \
- e-html-editor-hrule-dialog-dom-functions.c \
e-html-editor-image-dialog.c \
- e-html-editor-image-dialog-dom-functions.c \
e-html-editor-link-dialog.c \
- e-html-editor-link-dialog-dom-functions.c \
e-html-editor-page-dialog.c \
e-html-editor-paragraph-dialog.c \
e-html-editor-private.h \
e-html-editor-replace-dialog.c \
e-html-editor-selection.c \
- e-html-editor-selection-dom-functions.c \
e-html-editor-spell-check-dialog.c \
e-html-editor-table-dialog.c \
e-html-editor-text-dialog.c \
@@ -566,9 +552,6 @@ libevolution_util_la_SOURCES = \
e-source-selector-dialog.c \
e-source-selector.c \
e-source-util.c \
- e-spell-checker.c \
- e-spell-dictionary.c \
- e-spell-entry.c \
e-spell-text-view.c \
e-spinner.c \
e-stock-request.c \
@@ -697,9 +680,9 @@ test_dateedit_CPPFLAGS = $(TEST_CPPFLAGS)
test_dateedit_SOURCES = test-dateedit.c
test_dateedit_LDADD = $(TEST_LDADD)
-test_html_editor_CPPFLAGS = $(TEST_CPPFLAGS)
-test_html_editor_SOURCES = test-html-editor.c
-test_html_editor_LDADD = $(TEST_LDADD)
+#test_html_editor_CPPFLAGS = $(TEST_CPPFLAGS)
+#test_html_editor_SOURCES = test-html-editor.c
+#test_html_editor_LDADD = $(TEST_LDADD)
test_mail_signatures_CPPFLAGS = $(TEST_CPPFLAGS)
test_mail_signatures_SOURCES = test-mail-signatures.c
@@ -733,6 +716,40 @@ test_tree_view_frame_CPPFLAGS = $(TEST_CPPFLAGS)
test_tree_view_frame_SOURCES = test-tree-view-frame.c
test_tree_view_frame_LDADD = $(TEST_LDADD)
+libehtmleditorwebextension_la_SOURCES = \
+ e-html-editor-actions-dom-functions.h \
+ e-html-editor-cell-dialog-dom-functions.h \
+ e-html-editor-hrule-dialog-dom-functions.h \
+ e-html-editor-image-dialog-dom-functions.h \
+ e-html-editor-link-dialog-dom-functions.h \
+ e-html-editor-selection-dom-functions.h \
+ e-html-editor-spell-check-dialog-dom-functions.h \
+ e-html-editor-view-dom-functions.h \
+ e-html-editor-actions-dom-functions.c \
+ e-html-editor-cell-dialog-dom-functions.c \
+ e-html-editor-hrule-dialog-dom-functions.c \
+ e-html-editor-image-dialog-dom-functions.c \
+ e-html-editor-link-dialog-dom-functions.c \
+ e-html-editor-selection-dom-functions.c \
+ e-html-editor-spell-check-dialog-dom-functions.c \
+ e-html-editor-table-dialog-dom-functions.h \
+ e-html-editor-table-dialog-dom-functions.c \
+ e-html-editor-view-dom-functions.c \
+ e-html-editor-web-extension.c \
+ e-html-editor-web-extension.h \
+ e-html-editor-web-extension-names.h \
+ e-html-editor-web-extension-main.c
+
+libehtmleditorwebextension_la_CPPFLAGS = \
+ $(libevolution_util_la_CPPFLAGS) \
+ $(WEB_EXTENSIONS_CFLAGS)
+
+libehtmleditorwebextension_la_LIBADD = \
+ libevolution-util.la \
+ $(WEB_EXTENSIONS_LIBS)
+
+libehtmleditorwebextension_la_LDFLAGS = \
+ -module -avoid-version -no-undefined
EXTRA_DIST = \
e-system.error.xml \
filter.error.xml \
diff --git a/e-util/e-dom-utils.c b/e-util/e-dom-utils.c
index 871aab5..cc2d165 100644
--- a/e-util/e-dom-utils.c
+++ b/e-util/e-dom-utils.c
@@ -25,7 +25,7 @@
#include "../web-extensions/e-web-extension.h"
-#include "e-misc-utils.h"
+#include <e-util/e-misc-utils.h>
#include <config.h>
diff --git a/e-util/e-html-editor-actions.c b/e-util/e-html-editor-actions.c
index 800902c..452f3d0 100644
--- a/e-util/e-html-editor-actions.c
+++ b/e-util/e-html-editor-actions.c
@@ -40,7 +40,6 @@ insert_html_file_ready_cb (GFile *file,
GAsyncResult *result,
EHTMLEditor *editor)
{
- EHTMLEditorSelection *selection;
gchar *contents = NULL;
gsize length;
GError *error = NULL;
@@ -64,9 +63,7 @@ insert_html_file_ready_cb (GFile *file,
return;
}
- selection = e_html_editor_view_get_selection (
- e_html_editor_get_view (editor));
- e_html_editor_selection_insert_html (selection, contents);
+ e_html_editor_view_insert_html (e_html_editor_get_view (editor), contents);
g_free (contents);
g_object_unref (editor);
@@ -77,7 +74,6 @@ insert_text_file_ready_cb (GFile *file,
GAsyncResult *result,
EHTMLEditor *editor)
{
- EHTMLEditorSelection *selection;
gchar *contents;
gsize length;
GError *error = NULL;
@@ -101,9 +97,7 @@ insert_text_file_ready_cb (GFile *file,
return;
}
- selection = e_html_editor_view_get_selection (
- e_html_editor_get_view (editor));
- e_html_editor_selection_insert_text (selection, contents);
+ e_html_editor_view_insert_text (e_html_editor_get_view (editor), contents);
g_free (contents);
g_object_unref (editor);
@@ -114,12 +108,12 @@ editor_update_static_spell_actions (EHTMLEditor *editor)
{
ESpellChecker *checker;
EHTMLEditorView *view;
- guint count;
+ guint count = 0;
view = e_html_editor_get_view (editor);
checker = e_html_editor_view_get_spell_checker (view);
-
- count = e_spell_checker_count_active_languages (checker);
+/* FIXME WK2
+ count = e_spell_checker_count_active_languages (checker);*/
gtk_action_set_visible (ACTION (CONTEXT_SPELL_ADD), count == 1);
gtk_action_set_visible (ACTION (CONTEXT_SPELL_ADD_MENU), count > 1);
@@ -228,9 +222,10 @@ action_context_spell_add_cb (GtkAction *action,
selection = e_html_editor_view_get_selection (editor->priv->html_editor_view);
word = e_html_editor_selection_get_caret_word (selection);
+ /* FIXME WK2
if (word && *word) {
e_spell_checker_learn_word (spell_checker, word);
- }
+ } */
}
static void
@@ -246,9 +241,10 @@ action_context_spell_ignore_cb (GtkAction *action,
selection = e_html_editor_view_get_selection (editor->priv->html_editor_view);
word = e_html_editor_selection_get_caret_word (selection);
+ /* FIXME WK2
if (word && *word) {
e_spell_checker_ignore_word (spell_checker, word);
- }
+ }*/
}
static void
@@ -295,7 +291,8 @@ action_insert_emoticon_cb (GtkAction *action,
g_return_if_fail (emoticon != NULL);
view = e_html_editor_get_view (editor);
- e_html_editor_view_insert_smiley (view, emoticon);
+/* FIXME WK2
+ e_html_editor_view_insert_smiley (view, emoticon); */
}
static void
@@ -442,7 +439,8 @@ action_language_cb (GtkToggleAction *toggle_action,
language_code = gtk_action_get_name (GTK_ACTION (toggle_action));
active = gtk_toggle_action_get_active (toggle_action);
- e_spell_checker_set_language_active (checker, language_code, active);
+ /* FIXME WK2
+ e_spell_checker_set_language_active (checker, language_code, active);*/
/* Update "Add Word To" context menu item visibility. */
action_name = g_strdup_printf ("context-spell-add-%s", language_code);
@@ -535,13 +533,10 @@ action_paste_cb (GtkAction *action,
{
EHTMLEditorView *view = e_html_editor_get_view (editor);
- /* If WebView doesn't have focus, focus it */
- if (gtk_widget_has_focus (GTK_WIDGET (view))) {
+ /* Only paste if WebView is focused. */
+ if (gtk_widget_has_focus (GTK_WIDGET (view)))
webkit_web_view_execute_editing_command (
WEBKIT_WEB_VIEW (view), WEBKIT_EDITING_COMMAND_PASTE);
-
- e_html_editor_view_force_spell_check (view);
- }
}
static void
@@ -550,10 +545,8 @@ action_paste_as_text_cb (GtkAction *action,
{
EHTMLEditorView *view = e_html_editor_get_view (editor);
- if (gtk_widget_has_focus (GTK_WIDGET (view))) {
+ if (gtk_widget_has_focus (GTK_WIDGET (view)))
e_html_editor_view_paste_as_text (view);
- e_html_editor_view_force_spell_check (view);
- }
}
static void
@@ -562,10 +555,8 @@ action_paste_quote_cb (GtkAction *action,
{
EHTMLEditorView *view = e_html_editor_get_view (editor);
- if (gtk_widget_has_focus (GTK_WIDGET (view))) {
+ if (gtk_widget_has_focus (GTK_WIDGET (view)))
e_html_editor_view_paste_clipboard_quoted (view);
- e_html_editor_view_force_spell_check (view);
- }
}
static void
@@ -1552,11 +1543,12 @@ static GtkActionEntry spell_context_entries[] = {
static void
editor_actions_setup_languages_menu (EHTMLEditor *editor)
{
+#if 0
ESpellChecker *checker;
EHTMLEditorView *view;
GtkUIManager *manager;
GtkActionGroup *action_group;
- GList *list, *link;
+ GList *list = NULL, *link;
guint merge_id;
manager = editor->priv->manager;
@@ -1570,7 +1562,7 @@ editor_actions_setup_languages_menu (EHTMLEditor *editor)
for (link = list; link != NULL; link = g_list_next (link)) {
ESpellDictionary *dictionary = link->data;
GtkToggleAction *action;
- gboolean active;
+ gboolean active = FALSE;
action = gtk_toggle_action_new (
e_spell_dictionary_get_code (dictionary),
@@ -1602,15 +1594,17 @@ editor_actions_setup_languages_menu (EHTMLEditor *editor)
}
g_list_free (list);
+#endif
}
static void
editor_actions_setup_spell_check_menu (EHTMLEditor *editor)
{
+#if 0
ESpellChecker *checker;
GtkUIManager *manager;
GtkActionGroup *action_group;
- GList *available_dicts, *iter;
+ GList *available_dicts = NULL, *iter;
guint merge_id;
manager = editor->priv->manager;
@@ -1679,6 +1673,7 @@ editor_actions_setup_spell_check_menu (EHTMLEditor *editor)
}
g_list_free (available_dicts);
+#endif
}
void
diff --git a/e-util/e-html-editor-cell-dialog-dom-functions.h
b/e-util/e-html-editor-cell-dialog-dom-functions.h
index c27e506..83959b2 100644
--- a/e-util/e-html-editor-cell-dialog-dom-functions.h
+++ b/e-util/e-html-editor-cell-dialog-dom-functions.h
@@ -1,5 +1,5 @@
/*
- * e-html-editor-actions-dom-functions.h
+ * e-html-editor-cell-dialog-dom-functions.h
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -16,8 +16,8 @@
*
*/
-#ifndef E_HTML_EDITOR_ACTIONS_DOM_FUNCTIONS_H
-#define E_HTML_EDITOR_ACTIONS_DOM_FUNCTIONS_H
+#ifndef E_HTML_EDITOR_CELL_DIALOG_DOM_FUNCTIONS_H
+#define E_HTML_EDITOR_CELL_DIALOG_DOM_FUNCTIONS_H
#include <webkitdom/webkitdom.h>
@@ -69,4 +69,4 @@ void e_html_editor_cell_dialog_set_element_bg_color
G_END_DECLS
-#endif /* E_HTML_EDITOR_ACTIONS_DOM_FUNCTIONS_H */
+#endif /* E_HTML_EDITOR_CELL_DIALOG_DOM_FUNCTIONS_H */
diff --git a/e-util/e-html-editor-dom-functions.c b/e-util/e-html-editor-dom-functions.c
index 386113b..12e9c23 100644
--- a/e-util/e-html-editor-dom-functions.c
+++ b/e-util/e-html-editor-dom-functions.c
@@ -22,7 +22,7 @@
#include "e-dom-utils.h"
guint
-get_e_html_editor_flags_for_element_on_coordinates (WebKitDOMDocument *document,
+e_html_editor_get_flags_for_element_on_coordinates (WebKitDOMDocument *document,
gint32 x,
gint32 y)
{
diff --git a/e-util/web-extensions/e-html-editor-web-extension-names.h b/e-util/e-html-editor-dom-functions.h
similarity index 59%
copy from e-util/web-extensions/e-html-editor-web-extension-names.h
copy to e-util/e-html-editor-dom-functions.h
index 0c42931..d4fdf49 100644
--- a/e-util/web-extensions/e-html-editor-web-extension-names.h
+++ b/e-util/e-html-editor-dom-functions.h
@@ -1,5 +1,5 @@
/*
- * e-html-editor-web-extension-names.h
+ * e-html-editor-dom-functions.h
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -16,11 +16,18 @@
*
*/
-#ifndef E_HTML_EDITOR_WEB_EXTENSION_NAMES_H
-#define E_HTML_EDITOR_WEB_EXTENSION_NAMES_H
+#ifndef E_HTML_EDITOR_DOM_FUNCTIONS_H
+#define E_HTML_EDITOR_DOM_FUNCTIONS_H
-#define E_HTML_EDITOR_WEB_EXTENSION_SERVICE_NAME "org.gnome.Evolution.EHTMLEditor.WebExtension"
-#define E_HTML_EDITOR_WEB_EXTENSION_OBJECT_PATH "/org/gnome/Evolution/EHTMLEditor/WebExtension"
-#define E_HTML_EDITOR_WEB_EXTENSION_INTERFACE "org.gnome.Evolution.EHTMLEditor.WebExtension"
+#include <webkitdom/webkitdom.h>
-#endif /* E_HTML_EDITOR_WEB_EXTENSION_NAMES_H */
+G_BEGIN_DECLS
+
+guint e_html_editor_get_flags_for_element_on_coordinates
+ (WebKitDOMDocument *document,
+ gint32 x,
+ gint32 y);
+
+G_END_DECLS
+
+#endif /* E_HTML_EDITOR__DOM_FUNCTIONS_H */
diff --git a/e-util/e-html-editor-link-dialog.c b/e-util/e-html-editor-link-dialog.c
index 0bde260..bd5d4e1 100644
--- a/e-util/e-html-editor-link-dialog.c
+++ b/e-util/e-html-editor-link-dialog.c
@@ -88,12 +88,11 @@ html_editor_link_dialog_remove_link (EHTMLEditorLinkDialog *dialog)
{
EHTMLEditor *editor;
EHTMLEditorView *view;
- EHTMLEditorSelection *selection;
editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
view = e_html_editor_get_view (editor);
- selection = e_html_editor_view_get_selection (view);
- e_html_editor_selection_unlink (selection);
+ e_html_editor_view_call_simple_extension_function (
+ view, "EHTMLEditorSelectionDOMUnlink");
gtk_widget_hide (GTK_WIDGET (dialog));
}
diff --git a/e-util/e-html-editor-selection-dom-functions.c b/e-util/e-html-editor-selection-dom-functions.c
index d08f4c8..d273852 100644
--- a/e-util/e-html-editor-selection-dom-functions.c
+++ b/e-util/e-html-editor-selection-dom-functions.c
@@ -21,6 +21,7 @@
#include "e-util-enums.h"
#include "e-dom-utils.h"
#include "e-html-editor-view-dom-functions.h"
+#include "e-html-editor-web-extension.h"
#include <string.h>
#include <stdlib.h>
@@ -31,13 +32,6 @@
#include <webkitdom/WebKitDOMDOMSelection.h>
#include <webkitdom/WebKitDOMDOMWindowUnstable.h>
-#define UNICODE_ZERO_WIDTH_SPACE "\xe2\x80\x8b"
-#define UNICODE_NBSP "\xc2\xa0"
-
-#define SPACES_PER_INDENTATION 4
-#define SPACES_PER_LIST_LEVEL 8
-#define MINIMAL_PARAGRAPH_WIDTH 5
-
static const GdkRGBA black = { 0, 0, 0, 1 };
void
@@ -97,7 +91,7 @@ dom_create_caret_position_node (WebKitDOMDocument *document)
return WEBKIT_DOM_NODE (element);
}
-static WebKitDOMRange *
+WebKitDOMRange *
dom_get_current_range (WebKitDOMDocument *document)
{
WebKitDOMDOMWindow *window;
@@ -133,7 +127,6 @@ gchar *
dom_selection_get_string (WebKitDOMDocument *document,
EHTMLEditorWebExtension *extension)
{
- gchar *text;
WebKitDOMRange *range;
range = dom_get_current_range (document);
@@ -226,7 +219,7 @@ fix_quoting_nodes_after_caret_restoration (WebKitDOMDOMSelection *window_selecti
window_selection, "move", "backward", "character");
}
-static void
+void
dom_move_caret_into_element (WebKitDOMDocument *document,
WebKitDOMElement *element)
{
@@ -460,8 +453,8 @@ dom_create_link (WebKitDOMDocument *document,
*
* Returns: #EHTMLEditorSelectionBlockFormat
*/
-static EHTMLEditorSelectionBlockFormat
-get_list_format_from_node (WebKitDOMNode *node)
+EHTMLEditorSelectionBlockFormat
+dom_get_list_format_from_node (WebKitDOMNode *node)
{
EHTMLEditorSelectionBlockFormat format =
E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_UNORDERED_LIST;
@@ -611,9 +604,9 @@ set_word_wrap_length (EHTMLEditorWebExtension *extension,
e_html_editor_web_extension_get_word_wrap_length (extension) : user_word_wrap_length;
}
-static void
-dom_set_paragraph_style (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+void
+dom_set_paragraph_style (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
WebKitDOMElement *element,
gint width,
gint offset,
@@ -642,8 +635,8 @@ dom_set_paragraph_style (EHTMLEditorWebExtension *extension,
}
static WebKitDOMElement *
-create_list_element (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+create_list_element (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
EHTMLEditorSelectionBlockFormat format,
gint level,
gboolean html_mode)
@@ -662,7 +655,7 @@ create_list_element (EHTMLEditorWebExtension *extension,
offset = (level + 1) * -SPACES_PER_LIST_LEVEL;
if (!html_mode)
- dom_set_paragraph_style (extension, document, list, -1, offset, "");
+ dom_set_paragraph_style (document, extension, list, -1, offset, "");
return list;
}
@@ -720,9 +713,9 @@ merge_lists_if_possible (WebKitDOMNode *list)
prev_sibling = webkit_dom_node_get_previous_sibling (WEBKIT_DOM_NODE (list));
next_sibling = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (list));
- format = get_list_format_from_node (list),
- prev = get_list_format_from_node (prev_sibling);
- next = get_list_format_from_node (next_sibling);
+ format = dom_get_list_format_from_node (list),
+ prev = dom_get_list_format_from_node (prev_sibling);
+ next = dom_get_list_format_from_node (next_sibling);
if (format == prev && format != -1 && prev != -1)
merge_list_into_list (prev_sibling, list, TRUE);
@@ -732,8 +725,8 @@ merge_lists_if_possible (WebKitDOMNode *list)
}
static void
-indent_list (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document)
+indent_list (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
WebKitDOMElement *selection_start_marker, *selection_end_marker;
WebKitDOMNode *item, *next_item;
@@ -754,10 +747,10 @@ indent_list (EHTMLEditorWebExtension *extension,
WebKitDOMNode *source_list = webkit_dom_node_get_parent_node (item);
EHTMLEditorSelectionBlockFormat format;
- format = get_list_format_from_node (source_list);
+ format = dom_get_list_format_from_node (source_list);
list = create_list_element (
- extension, document, format, get_list_level (item), html_mode);
+ document, extension, format, get_list_level (item), html_mode);
element_add_class (list, "-x-evo-indented");
@@ -781,8 +774,8 @@ indent_list (EHTMLEditorWebExtension *extension,
}
static void
-dom_set_indented_style (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+dom_set_indented_style (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
WebKitDOMElement *element,
gint width)
{
@@ -803,27 +796,27 @@ dom_set_indented_style (EHTMLEditorWebExtension *extension,
}
static WebKitDOMElement *
-dom_get_indented_element (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+dom_get_indented_element (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
gint width)
{
WebKitDOMElement *element;
element = webkit_dom_document_create_element (document, "DIV", NULL);
- dom_set_indented_style (extension, document, element, width);
+ dom_set_indented_style (document, extension, element, width);
return element;
}
static void
-indent_block (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+indent_block (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
WebKitDOMNode *block,
gint width)
{
WebKitDOMElement *element;
- element = dom_get_indented_element (extension, document, width);
+ element = dom_get_indented_element (document, extension, width);
webkit_dom_node_insert_before (
webkit_dom_node_get_parent_node (block),
@@ -975,9 +968,9 @@ add_selection_markers_into_element_start (WebKitDOMDocument *document,
*
* Indents current paragraph by one level.
*/
-static void
-dom_indent (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document)
+void
+dom_selection_indent (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
gboolean after_selection_start = FALSE, after_selection_end = FALSE;
WebKitDOMElement *selection_start_marker, *selection_end_marker;
@@ -1031,7 +1024,7 @@ dom_indent (EHTMLEditorWebExtension *extension,
length = webkit_dom_node_list_get_length (list);
if (length == 0 && node_is_list_or_item (block)) {
- indent_list (extension, document);
+ indent_list (document, extension);
goto next;
}
@@ -1050,7 +1043,7 @@ dom_indent (EHTMLEditorWebExtension *extension,
!e_html_editor_web_extension_get_html_mode (extension))
goto next;
- indent_block (extension, document, block, final_width);
+ indent_block (document, extension, block, final_width);
if (after_selection_end)
goto next;
@@ -1080,7 +1073,7 @@ dom_indent (EHTMLEditorWebExtension *extension,
!e_html_editor_web_extension_get_html_mode (extension))
continue;
- indent_block (extension, document, block_to_process, final_width);
+ indent_block (document, extension, block_to_process, final_width);
if (after_selection_end)
break;
@@ -1094,7 +1087,7 @@ dom_indent (EHTMLEditorWebExtension *extension,
}
dom_selection_restore (document);
- dom_force_spell_check_for_current_paragraph (document);
+ dom_force_spell_check_for_current_paragraph (document, extension);
/* FIXME WK2
g_object_notify (G_OBJECT (selection), "indented"); */
@@ -1170,8 +1163,8 @@ unindent_list (WebKitDOMDocument *document)
}
static void
-unindent_block (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+unindent_block (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
WebKitDOMNode *block)
{
gboolean before_node = TRUE;
@@ -1200,12 +1193,12 @@ unindent_block (EHTMLEditorWebExtension *extension,
/* Look if we have previous siblings, if so, we have to
* create new blockquote that will include them */
if (webkit_dom_node_get_previous_sibling (block_to_process))
- prev_blockquote = dom_get_indented_element (extension, document, width);
+ prev_blockquote = dom_get_indented_element (document, extension, width);
/* Look if we have next siblings, if so, we have to
* create new blockquote that will include them */
if (webkit_dom_node_get_next_sibling (block_to_process))
- next_blockquote = dom_get_indented_element (extension, document, width);
+ next_blockquote = dom_get_indented_element (document, extension, width);
/* Copy nodes that are before / after the element that we want to unindent */
while ((child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element)))) {
@@ -1239,7 +1232,7 @@ unindent_block (EHTMLEditorWebExtension *extension,
if (level == 1 && element_has_class (WEBKIT_DOM_ELEMENT (node_clone), "-x-evo-paragraph")) {
dom_set_paragraph_style (
- extension, document, WEBKIT_DOM_ELEMENT (node_clone), word_wrap_length, 0, "");
+ document, extension, WEBKIT_DOM_ELEMENT (node_clone), word_wrap_length, 0, "");
element_add_class (
WEBKIT_DOM_ELEMENT (node_clone),
get_css_alignment_value_class (alignment));
@@ -1273,9 +1266,9 @@ unindent_block (EHTMLEditorWebExtension *extension,
*
* Unindents current paragraph by one level.
*/
-static void
-dom_unindent (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document)
+void
+dom_selection_unindent (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
gboolean after_selection_start = FALSE, after_selection_end = FALSE;
WebKitDOMElement *selection_start_marker, *selection_end_marker;
@@ -1352,7 +1345,7 @@ dom_unindent (EHTMLEditorWebExtension *extension,
goto next;
}
- unindent_block (extension, document, block);
+ unindent_block (document, extension, block);
if (after_selection_end)
goto next;
@@ -1375,7 +1368,7 @@ dom_unindent (EHTMLEditorWebExtension *extension,
continue;
}
- unindent_block (extension, document, block_to_process);
+ unindent_block (document, extension, block_to_process);
if (after_selection_end)
break;
@@ -1387,7 +1380,7 @@ dom_unindent (EHTMLEditorWebExtension *extension,
dom_selection_restore (document);
- dom_force_spell_check_for_current_paragraph (document);
+ dom_force_spell_check_for_current_paragraph (document, extension);
/* FIXME XXX - Check if the block is still indented */
set_dbus_property_boolean (extension, "Indented", TRUE);
@@ -1842,7 +1835,7 @@ find_where_to_break_line (WebKitDOMNode *node,
*
* Returns: Whether the selection is collapsed (just caret) or not (someting is selected).
*/
-static gboolean
+gboolean
dom_selection_is_collapsed (WebKitDOMDocument *document)
{
WebKitDOMRange *range;
@@ -1854,7 +1847,7 @@ dom_selection_is_collapsed (WebKitDOMDocument *document)
return webkit_dom_range_get_collapsed (range, NULL);
}
-static void
+void
dom_scroll_to_caret (WebKitDOMDocument *document)
{
glong element_top, element_left;
@@ -1888,36 +1881,9 @@ dom_scroll_to_caret (WebKitDOMDocument *document)
dom_selection_restore (document);
}
-/**
- * e_html_editor_selection_insert_html:
- * @selection: an #EHTMLEditorSelection
- * @html_text: an HTML code to insert
- *
- * Insert @html_text into document at current cursor position. When a text range
- * is selected, it will be replaced by @html_text.
- */
-static void
-dom_insert_html (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
- const gchar *html_text)
-{
- g_return_if_fail (html_text != NULL);
-
- if (e_html_editor_web_extension_get_html_mode (extension)) {
- dom_exec_command (
- document, E_HTML_EDITOR_VIEW_COMMAND_INSERT_HTML, html_text);
-/* FIXME WK2
- e_html_editor_view_check_magic_links (view, FALSE);
-*/
- dom_force_spell_check (document);
- dom_scroll_to_caret (document);
- } else
- dom_convert_and_insert_html_into_selection (document, extension, html_text, TRUE);
-}
-
static WebKitDOMElement *
-wrap_lines (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+wrap_lines (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
WebKitDOMNode *paragraph,
gboolean remove_all_br,
gint word_wrap_length)
@@ -2307,23 +2273,81 @@ wrap_lines (EHTMLEditorWebExtension *extension,
}
}
-static WebKitDOMElement *
-dom_get_paragraph_element (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+void
+dom_remove_wrapping_from_element (WebKitDOMElement *element)
+{
+ WebKitDOMNodeList *list;
+ gint ii, length;
+
+ list = webkit_dom_element_query_selector_all (
+ element, "br.-x-evo-wrap-br", NULL);
+ length = webkit_dom_node_list_get_length (list);
+ for (ii = 0; ii < length; ii++)
+ remove_node (webkit_dom_node_list_item (list, ii));
+
+ webkit_dom_node_normalize (WEBKIT_DOM_NODE (element));
+
+ g_object_unref (list);
+}
+
+void
+dom_remove_quoting_from_element (WebKitDOMElement *element)
+{
+ gint ii, length;
+ WebKitDOMNodeList *list;
+
+ list = webkit_dom_element_query_selector_all (
+ element, "span.-x-evo-quoted", NULL);
+ length = webkit_dom_node_list_get_length (list);
+ for (ii = 0; ii < length; ii++)
+ remove_node (webkit_dom_node_list_item (list, ii));
+ g_object_unref (list);
+
+ list = webkit_dom_element_query_selector_all (
+ element, "span.-x-evo-temp-text-wrapper", NULL);
+ length = webkit_dom_node_list_get_length (list);
+ for (ii = 0; ii < length; ii++) {
+ WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+ WebKitDOMNode *parent = webkit_dom_node_get_parent_node (node);
+
+ while (webkit_dom_node_get_first_child (node))
+ webkit_dom_node_insert_before (
+ parent,
+ webkit_dom_node_get_first_child (node),
+ node,
+ NULL);
+
+ remove_node (node);
+ }
+ g_object_unref (list);
+
+ list = webkit_dom_element_query_selector_all (
+ element, "br.-x-evo-temp-br", NULL);
+ length = webkit_dom_node_list_get_length (list);
+ for (ii = 0; ii < length; ii++)
+ remove_node (webkit_dom_node_list_item (list, ii));
+ g_object_unref (list);
+
+ webkit_dom_node_normalize (WEBKIT_DOM_NODE (element));
+}
+
+WebKitDOMElement *
+dom_get_paragraph_element (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
gint width,
gint offset)
{
WebKitDOMElement *element;
element = webkit_dom_document_create_element (document, "DIV", NULL);
- dom_set_paragraph_style (extension, document, element, width, offset, "");
+ dom_set_paragraph_style (document, extension, element, width, offset, "");
return element;
}
-static WebKitDOMElement *
-dom_put_node_into_paragraph (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+WebKitDOMElement *
+dom_put_node_into_paragraph (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
WebKitDOMNode *node,
WebKitDOMNode *caret_position)
{
@@ -2331,7 +2355,7 @@ dom_put_node_into_paragraph (EHTMLEditorWebExtension *extension,
WebKitDOMElement *container;
range = webkit_dom_document_create_range (document);
- container = dom_get_paragraph_element (extension, document, -1, 0);
+ container = dom_get_paragraph_element (document, extension, -1, 0);
webkit_dom_range_select_node (range, node, NULL);
webkit_dom_range_surround_contents (range, WEBKIT_DOM_NODE (container), NULL);
/* We have to move caret position inside this container */
@@ -2348,8 +2372,8 @@ dom_put_node_into_paragraph (EHTMLEditorWebExtension *extension,
*/
static void
-dom_wrap_lines (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document)
+dom_wrap_lines (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
gint word_wrap_length;
WebKitDOMRange *range;
@@ -2399,8 +2423,8 @@ dom_wrap_lines (EHTMLEditorWebExtension *extension,
if (WEBKIT_DOM_IS_TEXT (paragraph))
paragraph = WEBKIT_DOM_NODE (
dom_put_node_into_paragraph (
- extension,
document,
+ extension,
paragraph,
WEBKIT_DOM_NODE (caret)));
} else {
@@ -2448,13 +2472,13 @@ dom_wrap_lines (EHTMLEditorWebExtension *extension,
g_free (text_content);
wrap_lines (
- extension, document, paragraph, FALSE, word_wrap_length);
+ document, extension, paragraph, FALSE, word_wrap_length);
} else {
dom_save_caret_position (document);
/* If we have selection -> wrap it */
wrap_lines (
- extension, document, NULL, FALSE, word_wrap_length); }
+ document, extension, NULL, FALSE, word_wrap_length); }
active_paragraph = webkit_dom_document_get_element_by_id (
document, "-x-evo-active-paragraph");
@@ -2467,16 +2491,16 @@ dom_wrap_lines (EHTMLEditorWebExtension *extension,
WEBKIT_DOM_ELEMENT (active_paragraph), "id");
}
-static WebKitDOMElement *
-dom_wrap_paragraph_length (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+WebKitDOMElement *
+dom_wrap_paragraph_length (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
WebKitDOMElement *paragraph,
gint length)
{
g_return_val_if_fail (WEBKIT_DOM_IS_ELEMENT (paragraph), NULL);
g_return_val_if_fail (length >= MINIMAL_PARAGRAPH_WIDTH, NULL);
- return wrap_lines (extension, document, WEBKIT_DOM_NODE (paragraph), FALSE, length);
+ return wrap_lines (document, extension, WEBKIT_DOM_NODE (paragraph), FALSE, length);
}
static gint
@@ -2496,9 +2520,9 @@ get_citation_level (WebKitDOMNode *node)
return level;
}
-static void
-dom_wrap_paragraphs_in_document (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document)
+void
+dom_wrap_paragraphs_in_document (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
WebKitDOMNodeList *list;
gint ii, length;
@@ -2521,20 +2545,20 @@ dom_wrap_paragraphs_in_document (EHTMLEditorWebExtension *extension,
while (item && WEBKIT_DOM_IS_HTML_LI_ELEMENT (item)) {
dom_wrap_paragraph_length (
- extension, document, WEBKIT_DOM_ELEMENT (item), word_wrap_length -
quote);
+ document, extension, WEBKIT_DOM_ELEMENT (item), word_wrap_length -
quote);
item = webkit_dom_node_get_next_sibling (item);
}
} else {
dom_wrap_paragraph_length (
- extension, document, WEBKIT_DOM_ELEMENT (node), word_wrap_length - quote);
+ document, extension, WEBKIT_DOM_ELEMENT (node), word_wrap_length - quote);
}
}
g_object_unref (list);
}
-static WebKitDOMElement *
-dom_wrap_paragraph (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+WebKitDOMElement *
+dom_wrap_paragraph (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
WebKitDOMElement *paragraph)
{
gint indentation_level, citation_level, quote;
@@ -2562,7 +2586,7 @@ dom_wrap_paragraph (EHTMLEditorWebExtension *extension,
final_width -= SPACES_PER_INDENTATION * indentation_level;
return dom_wrap_paragraph_length (
- extension, document, WEBKIT_DOM_ELEMENT (paragraph), final_width);
+ document, extension, WEBKIT_DOM_ELEMENT (paragraph), final_width);
}
static void
@@ -3216,7 +3240,7 @@ dom_selection_set_monospaced (WebKitDOMDocument *document,
g_free (outer_html);
g_free (tmp);
- dom_force_spell_check_for_current_paragraph (document);
+ dom_force_spell_check_for_current_paragraph (document, extension);
}
/* Re-set formatting */
@@ -3689,7 +3713,7 @@ dom_selection_get_block_format (WebKitDOMDocument *document,
if (dom_node_find_parent_element (node, "UL")) {
result = E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_UNORDERED_LIST;
} else if ((element = dom_node_find_parent_element (node, "OL")) != NULL) {
- result = get_list_format_from_node (WEBKIT_DOM_NODE (element));
+ result = dom_get_list_format_from_node (WEBKIT_DOM_NODE (element));
} else if (dom_node_find_parent_element (node, "PRE")) {
result = E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_PRE;
} else if (dom_node_find_parent_element (node, "ADDRESS")) {
@@ -3734,64 +3758,6 @@ dom_selection_get_block_format (WebKitDOMDocument *document,
return result;
}
-static void
-remove_wrapping_from_element (WebKitDOMElement *element)
-{
- WebKitDOMNodeList *list;
- gint ii, length;
-
- list = webkit_dom_element_query_selector_all (
- element, "br.-x-evo-wrap-br", NULL);
- length = webkit_dom_node_list_get_length (list);
- for (ii = 0; ii < length; ii++)
- remove_node (webkit_dom_node_list_item (list, ii));
-
- webkit_dom_node_normalize (WEBKIT_DOM_NODE (element));
-
- g_object_unref (list);
-}
-
-static void
-remove_quoting_from_element (WebKitDOMElement *element)
-{
- gint ii, length;
- WebKitDOMNodeList *list;
-
- list = webkit_dom_element_query_selector_all (
- element, "span.-x-evo-quoted", NULL);
- length = webkit_dom_node_list_get_length (list);
- for (ii = 0; ii < length; ii++)
- remove_node (webkit_dom_node_list_item (list, ii));
- g_object_unref (list);
-
- list = webkit_dom_element_query_selector_all (
- element, "span.-x-evo-temp-text-wrapper", NULL);
- length = webkit_dom_node_list_get_length (list);
- for (ii = 0; ii < length; ii++) {
- WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
- WebKitDOMNode *parent = webkit_dom_node_get_parent_node (node);
-
- while (webkit_dom_node_get_first_child (node))
- webkit_dom_node_insert_before (
- parent,
- webkit_dom_node_get_first_child (node),
- node,
- NULL);
-
- remove_node (node);
- }
- g_object_unref (list);
-
- list = webkit_dom_element_query_selector_all (
- element, "br.-x-evo-temp-br", NULL);
- length = webkit_dom_node_list_get_length (list);
- for (ii = 0; ii < length; ii++)
- remove_node (webkit_dom_node_list_item (list, ii));
- g_object_unref (list);
-
- webkit_dom_node_normalize (WEBKIT_DOM_NODE (element));
-}
-
static gboolean
is_citation_node (WebKitDOMNode *node)
{
@@ -3855,18 +3821,18 @@ process_block_to_block (WebKitDOMDocument *document,
if (webkit_dom_element_query_selector (
WEBKIT_DOM_ELEMENT (block), "span.-x-evo-quoted", NULL)) {
quoted = TRUE;
- remove_quoting_from_element (WEBKIT_DOM_ELEMENT (block));
+ dom_remove_quoting_from_element (WEBKIT_DOM_ELEMENT (block));
}
if (!html_mode)
- remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (block));
+ dom_remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (block));
after_selection_end = webkit_dom_node_is_same_node (block, end_block);
next_block = webkit_dom_node_get_next_sibling (block);
if (format == E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_PARAGRAPH)
- element = dom_get_paragraph_element (extension, document, -1, 0);
+ element = dom_get_paragraph_element (document, extension, -1, 0);
else
element = webkit_dom_document_create_element (
document, value, NULL);
@@ -3927,7 +3893,7 @@ process_block_to_block (WebKitDOMDocument *document,
quote = citation_level ? citation_level * 2 : 0;
element = dom_wrap_paragraph_length (
- extension, document, element, word_wrap_length - quote);
+ document, extension, element, word_wrap_length - quote);
}
}
@@ -4022,7 +3988,7 @@ format_change_block_to_list (WebKitDOMDocument *document,
block = get_parent_block_node_from_child (
WEBKIT_DOM_NODE (selection_start_marker));
- list = create_list_element (extension, document, format, 0, html_mode);
+ list = create_list_element (document, extension, format, 0, html_mode);
if (webkit_dom_element_query_selector (
WEBKIT_DOM_ELEMENT (block), "span.-x-evo-quoted", NULL)) {
@@ -4071,8 +4037,8 @@ format_change_block_to_list (WebKitDOMDocument *document,
next_block = webkit_dom_node_get_next_sibling (
WEBKIT_DOM_NODE (block));
- remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (block));
- remove_quoting_from_element (WEBKIT_DOM_ELEMENT (block));
+ dom_remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (block));
+ dom_remove_quoting_from_element (WEBKIT_DOM_ELEMENT (block));
item = webkit_dom_document_create_element (document, "LI", NULL);
content = webkit_dom_node_get_text_content (block);
@@ -4165,7 +4131,7 @@ format_change_list_from_list (WebKitDOMDocument *document,
if (!selection_start_marker || !selection_end_marker)
return;
- new_list = create_list_element (extension, document, to, 0, html_mode);
+ new_list = create_list_element (document, extension, to, 0, html_mode);
/* Copy elements from previous block to list */
item = get_list_item_node_from_child (
@@ -4277,8 +4243,8 @@ format_change_list_to_list (WebKitDOMDocument *document,
}
}
- prev = get_list_format_from_node (prev_list);
- next = get_list_format_from_node (next_list);
+ prev = dom_get_list_format_from_node (prev_list);
+ next = dom_get_list_format_from_node (next_list);
if (format == prev && format != -1 && prev != -1) {
if (selection_starts_in_first_child && selection_ends_in_last_child) {
@@ -4340,7 +4306,7 @@ format_change_list_to_block (WebKitDOMDocument *document,
if (!after_end) {
if (format == E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_PARAGRAPH)
- element = dom_get_paragraph_element (extension, document, -1, 0);
+ element = dom_get_paragraph_element (document, extension, -1, 0);
else
element = webkit_dom_document_create_element (
document, value, NULL);
@@ -4472,7 +4438,7 @@ dom_selection_set_block_format (WebKitDOMDocument *document,
if (!from_list && to_list)
format_change_block_to_list (document, extension, format);
- dom_force_spell_check_for_current_paragraph (document);
+ dom_force_spell_check_for_current_paragraph (document, extension);
/* When changing the format we need to re-set the alignment */
dom_selection_set_alignment (
@@ -4712,7 +4678,7 @@ dom_selection_set_alignment (WebKitDOMDocument *document,
dom_selection_restore (document);
- dom_force_spell_check_for_current_paragraph (document);
+ dom_force_spell_check_for_current_paragraph (document, extension);
/* FIXME WK2
g_object_notify (G_OBJECT (selection), "alignment");*/
@@ -4726,8 +4692,8 @@ dom_selection_set_alignment (WebKitDOMDocument *document,
* Replaces currently selected text with @replacement.
*/
void
-dom_selection_replace (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+dom_selection_replace (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
const gchar *replacement)
{
e_html_editor_web_extension_set_content_changed (extension);
@@ -4742,8 +4708,8 @@ dom_selection_replace (EHTMLEditorWebExtension *extension,
* Replaces current word under cursor with @replacement.
*/
void
-dom_replace_caret_word (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+dom_replace_caret_word (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
const gchar *replacement)
{
WebKitDOMDOMWindow *window;
@@ -4831,3 +4797,24 @@ dom_selection_has_text (WebKitDOMDocument *document)
return FALSE;
}
+/**
+ * e_html_editor_selection_get_list_alignment_from_node:
+ * @node: #an WebKitDOMNode
+ *
+ * Returns alignment of given list.
+ *
+ * Returns: #EHTMLEditorSelectionAlignment
+ */
+EHTMLEditorSelectionAlignment
+dom_get_list_alignment_from_node (WebKitDOMNode *node)
+{
+ if (element_has_class (WEBKIT_DOM_ELEMENT (node), "-x-evo-list-item-align-left"))
+ return E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
+ if (element_has_class (WEBKIT_DOM_ELEMENT (node), "-x-evo-list-item-align-center"))
+ return E_HTML_EDITOR_SELECTION_ALIGNMENT_CENTER;
+ if (element_has_class (WEBKIT_DOM_ELEMENT (node), "-x-evo-list-item-align-right"))
+ return E_HTML_EDITOR_SELECTION_ALIGNMENT_RIGHT;
+
+ return E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
+}
+
diff --git a/e-util/e-html-editor-selection-dom-functions.h b/e-util/e-html-editor-selection-dom-functions.h
index b513f92..ddd23f0 100644
--- a/e-util/e-html-editor-selection-dom-functions.h
+++ b/e-util/e-html-editor-selection-dom-functions.h
@@ -21,10 +21,35 @@
#include <webkitdom/webkitdom.h>
-#include "web-extensions/e-html-editor-web-extension.h"
+#include "e-html-editor-web-extension.h"
#include "e-util-enums.h"
+#define UNICODE_ZERO_WIDTH_SPACE "\xe2\x80\x8b"
+#define UNICODE_NBSP "\xc2\xa0"
+
+#define URL_PATTERN \
+ "((([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[\\-;:&=\\+\\$,\\w]+@)?" \
+ "[A-Za-z0-9\\.\\-]+|(?:www\\.|[\\-;:&=\\+\\$,\\w]+@)" \
+ "[A-Za-z0-9\\.\\-]+)((?:\\/[\\+~%\\/\\.\\w\\-]*)?\\?" \
+ "?(?:[\\-\\+=&;% \\ \\w]*)#?(?:[\\.\\!\\/\\\\w]*))?)"
+
+#define URL_PATTERN_SPACE URL_PATTERN "\\s"
+
+/* http://www.w3.org/TR/html5/forms.html#valid-e-mail-address */
+#define E_MAIL_PATTERN \
+ "[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+ [a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}"\
+ "[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*"
+
+#define E_MAIL_PATTERN_SPACE E_MAIL_PATTERN "\\s"
+
+#define QUOTE_SYMBOL ">"
+
+#define SPACES_PER_INDENTATION 4
+#define SPACES_PER_LIST_LEVEL 8
+#define TAB_LENGTH 8
+#define MINIMAL_PARAGRAPH_WIDTH 5
+
G_BEGIN_DECLS
void dom_replace_base64_image_src (WebKitDOMDocument *document,
@@ -37,19 +62,19 @@ void dom_clear_caret_position_marker (WebKitDOMDocument *document);
WebKitDOMNode *
dom_create_caret_position_node (WebKitDOMDocument *document);
-/*
+
WebKitDOMRange *
dom_get_current_range (WebKitDOMDocument *document);
-*/
+
gchar * dom_selection_get_string (WebKitDOMDocument *document,
EHTMLEditorWebExtension *extension);
WebKitDOMElement *
dom_save_caret_position (WebKitDOMDocument *document);
-/*
+
void dom_move_caret_into_element (WebKitDOMDocument *document,
WebKitDOMElement *element);
-*/
+
void dom_restore_caret_position (WebKitDOMDocument *document);
void dom_unlink (WebKitDOMDocument *document);
@@ -57,10 +82,61 @@ void dom_unlink (WebKitDOMDocument *document);
void dom_create_link (WebKitDOMDocument *document,
const gchar *uri);
+EHTMLEditorSelectionBlockFormat
+ dom_get_list_format_from_node (WebKitDOMNode *node);
+
+void dom_selection_indent (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension);
+
+void dom_selection_unindent (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension);
+
void dom_selection_save (WebKitDOMDocument *document);
void dom_selection_restore (WebKitDOMDocument *document);
+gboolean dom_selection_is_collapsed (WebKitDOMDocument *document);
+
+void dom_scroll_to_caret (WebKitDOMDocument *document);
+
+void dom_remove_wrapping_from_element
+ (WebKitDOMElement *element);
+
+void dom_remove_quoting_from_element (WebKitDOMElement *element);
+
+void dom_set_paragraph_style (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
+ WebKitDOMElement *element,
+ gint width,
+ gint offset,
+ const gchar *style_to_add);
+
+WebKitDOMElement *
+ dom_get_paragraph_element (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
+ gint width,
+ gint offset);
+
+WebKitDOMElement *
+ dom_put_node_into_paragraph (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
+ WebKitDOMNode *node,
+ WebKitDOMNode *caret_position);
+
+WebKitDOMElement *
+ dom_wrap_paragraph_length (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
+ WebKitDOMElement *paragraph,
+ gint length);
+
+WebKitDOMElement *
+ dom_wrap_paragraph (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
+ WebKitDOMElement *paragraph);
+
+void dom_wrap_paragraphs_in_document (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension);
+
gboolean dom_selection_is_underline (WebKitDOMDocument *document,
EHTMLEditorWebExtension *extension);
@@ -160,18 +236,22 @@ void dom_selection_set_alignment (WebKitDOMDocument *document,
EHTMLEditorWebExtension *extension,
EHTMLEditorSelectionAlignment alignment);
-void dom_selection_replace (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+void dom_selection_replace (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
const gchar *replacement);
-void dom_replace_caret_word (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+void dom_replace_caret_word (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
const gchar *replacement);
gchar * dom_get_caret_word (WebKitDOMDocument *document);
gboolean dom_selection_has_text (WebKitDOMDocument *document);
+EHTMLEditorSelectionAlignment
+ dom_get_list_alignment_from_node
+ (WebKitDOMNode *node);
+
G_END_DECLS
#endif /* E_HTML_EDITOR_SELECTION_DOM_FUNCTIONS_H */
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index d9bb798..4c081f0 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -1488,6 +1488,34 @@ e_html_editor_selection_is_indented (EHTMLEditorSelection *selection)
return html_editor_selection_get_format_boolean (selection, "indented");
}
+void
+e_html_editor_selection_indent (EHTMLEditorSelection *selection)
+{
+ EHTMLEditorView *view;
+
+ g_return_if_fail (E_IS_HTML_EDITOR_SELECTION (selection));
+
+ view = e_html_editor_selection_ref_html_editor_view (selection);
+ g_return_if_fail (view != NULL);
+
+ e_html_editor_view_call_simple_extension_function (view, "DOMSelectionIndent");
+ g_object_unref (view);
+}
+
+void
+e_html_editor_selection_unindent (EHTMLEditorSelection *selection)
+{
+ EHTMLEditorView *view;
+
+ g_return_if_fail (E_IS_HTML_EDITOR_SELECTION (selection));
+
+ view = e_html_editor_selection_ref_html_editor_view (selection);
+ g_return_if_fail (view != NULL);
+
+ e_html_editor_view_call_simple_extension_function (view, "DOMSelectionUnindent");
+ g_object_unref (view);
+}
+
/**
* e_html_editor_selection_is_bold:
* @selection: an #EHTMLEditorSelection
@@ -1744,31 +1772,6 @@ e_html_editor_selection_set_underline (EHTMLEditorSelection *selection,
&selection->priv->is_underline);
}
-/**
- * e_html_editor_selection_insert_text:
- * @selection: an #EHTMLEditorSelection
- * @plain_text: text to insert
- *
- * Inserts @plain_text at current cursor position. When a text range is selected,
- * it will be replaced by @plain_text.
- */
-void
-e_html_editor_selection_insert_text (EHTMLEditorSelection *selection,
- const gchar *plain_text)
-{
- EHTMLEditorView *view;
-
- g_return_if_fail (E_IS_HTML_EDITOR_SELECTION (selection));
- g_return_if_fail (plain_text != NULL);
-
- view = e_html_editor_selection_ref_html_editor_view (selection);
- g_return_if_fail (view != NULL);
-
- e_html_editor_view_convert_and_insert_plain_text (view, plain_text);
-
- g_object_unref (view);
-}
-
/************************* image_load_and_insert_async() *************************/
typedef struct _LoadContext LoadContext;
diff --git a/e-util/e-html-editor-selection.h b/e-util/e-html-editor-selection.h
index e434e2f..8251cbe 100644
--- a/e-util/e-html-editor-selection.h
+++ b/e-util/e-html-editor-selection.h
@@ -167,12 +167,6 @@ const gchar * e_html_editor_selection_get_string
(EHTMLEditorSelection *selection);
void e_html_editor_selection_replace (EHTMLEditorSelection *selection,
const gchar *new_string);
-void e_html_editor_selection_insert_text
- (EHTMLEditorSelection *selection,
- const gchar *plain_text);
-void e_html_editor_selection_insert_html
- (EHTMLEditorSelection *selection,
- const gchar *html_text);
void e_html_editor_selection_insert_as_text
(EHTMLEditorSelection *selection,
const gchar *html_text);
@@ -183,62 +177,6 @@ void e_html_editor_selection_replace_image_src
void e_html_editor_selection_insert_image
(EHTMLEditorSelection *selection,
const gchar *image_uri);
-/*
-void e_html_editor_selection_move_caret_into_element
- (WebKitDOMDocument *document,
- WebKitDOMElement *element);
-void e_html_editor_selection_clear_caret_position_marker
- (EHTMLEditorSelection *selection);
-WebKitDOMNode *
- e_html_editor_selection_get_caret_position_node
- (WebKitDOMDocument *document);
-WebKitDOMElement *
- e_html_editor_selection_save_caret_position
- (EHTMLEditorSelection *selection);
-void e_html_editor_selection_restore_caret_position
- (EHTMLEditorSelection *selection);
-void e_html_editor_selection_set_indented_style
- (EHTMLEditorSelection *selection,
- WebKitDOMElement *element,
- gint width);
-WebKitDOMElement *
- e_html_editor_selection_get_indented_element
- (EHTMLEditorSelection *selection,
- WebKitDOMDocument *document,
- gint width);
-void e_html_editor_selection_set_paragraph_style
- (EHTMLEditorSelection *selection,
- WebKitDOMElement *element,
- gint width,
- gint offset,
- const gchar *style_to_add);
-WebKitDOMElement *
- e_html_editor_selection_get_paragraph_element
- (EHTMLEditorSelection *selection,
- WebKitDOMDocument *document,
- gint width,
- gint offset);
-WebKitDOMElement *
- e_html_editor_selection_put_node_into_paragraph
- (EHTMLEditorSelection *selection,
- WebKitDOMDocument *document,
- WebKitDOMNode *node,
- WebKitDOMNode *caret_position);
-void e_html_editor_selection_wrap_lines
- (EHTMLEditorSelection *selection);
-WebKitDOMElement *
- e_html_editor_selection_wrap_paragraph_length
- (EHTMLEditorSelection *selection,
- WebKitDOMElement *paragraph,
- gint length);
-void e_html_editor_selection_wrap_paragraphs_in_document
- (EHTMLEditorSelection *selection,
- WebKitDOMDocument *document);
-WebKitDOMElement *
- e_html_editor_selection_wrap_paragraph
- (EHTMLEditorSelection *selection,
- WebKitDOMElement *paragraph);
-*/
void e_html_editor_selection_save (EHTMLEditorSelection *selection);
void e_html_editor_selection_restore (EHTMLEditorSelection *selection);
void e_html_editor_selection_move (EHTMLEditorSelection *selection,
@@ -249,16 +187,6 @@ void e_html_editor_selection_extend (EHTMLEditorSelection *selection,
EHTMLEditorSelectionGranularity granularity);
void e_html_editor_selection_scroll_to_caret
(EHTMLEditorSelection *selection);
-/*
-EHTMLEditorSelectionBlockFormat
- e_html_editor_selection_get_list_format_from_node
- (WebKitDOMNode *node);
-EHTMLEditorSelectionAlignment
- e_html_editor_selection_get_list_alignment_from_node
- (WebKitDOMNode *node);
-void remove_wrapping_from_element (WebKitDOMElement *element);
-void remove_quoting_from_element (WebKitDOMElement *element);
-*/
G_END_DECLS
#endif /* E_HTML_EDITOR_SELECTION_H */
diff --git a/e-util/e-html-editor-spell-check-dialog-dom-functions.c
b/e-util/e-html-editor-spell-check-dialog-dom-functions.c
new file mode 100644
index 0000000..1d023a4
--- /dev/null
+++ b/e-util/e-html-editor-spell-check-dialog-dom-functions.c
@@ -0,0 +1,190 @@
+/*
+ * e-html-editor-spell-check-dialog-dom-functions.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "e-html-editor-spell-check-dialog-dom-functions.h"
+
+#include "e-dom-utils.h"
+
+#define WEBKIT_DOM_USE_UNSTABLE_API
+#include <webkitdom/WebKitDOMDOMSelection.h>
+#include <webkitdom/WebKitDOMDOMWindowUnstable.h>
+
+static gboolean
+select_next_word (WebKitDOMDOMSelection *selection)
+{
+ gulong anchor_offset, focus_offset;
+ WebKitDOMNode *anchor, *focus;
+
+ anchor = webkit_dom_dom_selection_get_anchor_node (selection);
+ anchor_offset = webkit_dom_dom_selection_get_anchor_offset (selection);
+
+ focus = webkit_dom_dom_selection_get_focus_node (selection);
+ focus_offset = webkit_dom_dom_selection_get_focus_offset (selection);
+
+ /* Jump _behind_ next word */
+ webkit_dom_dom_selection_modify (selection, "move", "forward", "word");
+ /* Jump before the word */
+ webkit_dom_dom_selection_modify (selection, "move", "backward", "word");
+ /* Select it */
+ webkit_dom_dom_selection_modify (selection, "extend", "forward", "word");
+
+ /* If the selection didn't change, then we have most probably
+ * reached the end of document - return FALSE */
+ return !((anchor == webkit_dom_dom_selection_get_anchor_node (selection)) &&
+ (anchor_offset == webkit_dom_dom_selection_get_anchor_offset (selection)) &&
+ (focus == webkit_dom_dom_selection_get_focus_node (selection)) &&
+ (focus_offset == webkit_dom_dom_selection_get_focus_offset (selection)));
+}
+
+gchar *
+e_html_editor_spell_check_dialog_next (WebKitDOMDocument *document,
+ const gchar *word)
+{
+ gulong start_offset, end_offset;
+ WebKitDOMDOMSelection *selection;
+ WebKitDOMDOMWindow *window;
+ WebKitDOMNode *start = NULL, *end = NULL;
+
+ window = webkit_dom_document_get_default_view (document);
+ selection = webkit_dom_dom_window_get_selection (window);
+
+ if (!word) {
+ webkit_dom_dom_selection_modify (
+ selection, "move", "left", "documentboundary");
+ } else {
+ /* Remember last selected word */
+ start = webkit_dom_dom_selection_get_anchor_node (selection);
+ end = webkit_dom_dom_selection_get_focus_node (selection);
+ start_offset = webkit_dom_dom_selection_get_anchor_offset (selection);
+ end_offset = webkit_dom_dom_selection_get_focus_offset (selection);
+ }
+
+#if 0 /* FIXME WK2 */
+ while (select_next_word (selection)) {
+ WebKitDOMRange *range;
+ WebKitSpellChecker *checker;
+ gint loc, len;
+ gchar *word;
+
+ range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
+ word = webkit_dom_range_get_text (range);
+
+ checker = WEBKIT_SPELL_CHECKER (webkit_get_text_checker ());
+ webkit_spell_checker_check_spelling_of_string (
+ checker, word, &loc, &len);
+
+ /* Found misspelled word! */
+ if (loc != -1)
+ return word;
+
+ g_free (word);
+ }
+#endif
+ /* Restore the selection to contain the last misspelled word. This is
+ * reached only when we reach the end of the document */
+ if (start && end)
+ webkit_dom_dom_selection_set_base_and_extent (
+ selection, start, start_offset, end, end_offset, NULL);
+
+ return FALSE;
+}
+
+static gboolean
+select_previous_word (WebKitDOMDOMSelection *selection)
+{
+ WebKitDOMNode *old_anchor_node;
+ WebKitDOMNode *new_anchor_node;
+ gulong old_anchor_offset;
+ gulong new_anchor_offset;
+
+ old_anchor_node = webkit_dom_dom_selection_get_anchor_node (selection);
+ old_anchor_offset = webkit_dom_dom_selection_get_anchor_offset (selection);
+
+ /* Jump on the beginning of current word */
+ webkit_dom_dom_selection_modify (selection, "move", "backward", "word");
+ /* Jump before previous word */
+ webkit_dom_dom_selection_modify (selection, "move", "backward", "word");
+ /* Select it */
+ webkit_dom_dom_selection_modify (selection, "extend", "forward", "word");
+
+ /* If the selection start didn't change, then we have most probably
+ * reached the beginnig of document. Return FALSE */
+
+ new_anchor_node = webkit_dom_dom_selection_get_anchor_node (selection);
+ new_anchor_offset = webkit_dom_dom_selection_get_anchor_offset (selection);
+
+ return (new_anchor_node != old_anchor_node) ||
+ (new_anchor_offset != old_anchor_offset);
+}
+
+gchar *
+e_html_editor_spell_check_dialog_prev (WebKitDOMDocument *document,
+ const gchar *word)
+{
+ gulong start_offset, end_offset;
+ WebKitDOMDOMSelection *selection;
+ WebKitDOMDOMWindow *window;
+ WebKitDOMNode *start = NULL, *end = NULL;
+
+ window = webkit_dom_document_get_default_view (document);
+ selection = webkit_dom_dom_window_get_selection (window);
+
+ if (!word) {
+ webkit_dom_dom_selection_modify (
+ selection, "move", "right", "documentboundary");
+ webkit_dom_dom_selection_modify (
+ selection, "extend", "backward", "word");
+ } else {
+ /* Remember last selected word */
+ start = webkit_dom_dom_selection_get_anchor_node (selection);
+ end = webkit_dom_dom_selection_get_focus_node (selection);
+ start_offset = webkit_dom_dom_selection_get_anchor_offset (selection);
+ end_offset = webkit_dom_dom_selection_get_focus_offset (selection);
+ }
+#if 0 /* FIXME WK2 */
+ while (select_previous_word (selection)) {
+ WebKitDOMRange *range;
+ WebKitSpellChecker *checker;
+ gint loc, len;
+ gchar *word;
+
+ range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
+ word = webkit_dom_range_get_text (range);
+
+ checker = WEBKIT_SPELL_CHECKER (webkit_get_text_checker ());
+ webkit_spell_checker_check_spelling_of_string (
+ checker, word, &loc, &len);
+
+ /* Found misspelled word! */
+ if (loc != -1) {
+ html_editor_spell_check_dialog_set_word (dialog, word);
+ g_free (word);
+ return TRUE;
+ }
+
+ g_free (word);
+ }
+#endif
+ /* Restore the selection to contain the last misspelled word. This is
+ * reached only when we reach the beginning of the document */
+ if (start && end)
+ webkit_dom_dom_selection_set_base_and_extent (
+ selection, start, start_offset, end, end_offset, NULL);
+
+ return FALSE;
+}
diff --git a/e-util/web-extensions/e-html-editor-web-extension-names.h
b/e-util/e-html-editor-spell-check-dialog-dom-functions.h
similarity index 57%
copy from e-util/web-extensions/e-html-editor-web-extension-names.h
copy to e-util/e-html-editor-spell-check-dialog-dom-functions.h
index 0c42931..86334e7 100644
--- a/e-util/web-extensions/e-html-editor-web-extension-names.h
+++ b/e-util/e-html-editor-spell-check-dialog-dom-functions.h
@@ -1,5 +1,5 @@
/*
- * e-html-editor-web-extension-names.h
+ * e-html-editor-spell-check-dialog-dom-functions.h
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -16,11 +16,19 @@
*
*/
-#ifndef E_HTML_EDITOR_WEB_EXTENSION_NAMES_H
-#define E_HTML_EDITOR_WEB_EXTENSION_NAMES_H
+#ifndef E_HTML_SPELL_CHECK_DIALOG_DOM_FUNCTIONS_H
+#define E_HTML_SPELL_CHECK_DIALOG_DOM_FUNCTIONS_H
-#define E_HTML_EDITOR_WEB_EXTENSION_SERVICE_NAME "org.gnome.Evolution.EHTMLEditor.WebExtension"
-#define E_HTML_EDITOR_WEB_EXTENSION_OBJECT_PATH "/org/gnome/Evolution/EHTMLEditor/WebExtension"
-#define E_HTML_EDITOR_WEB_EXTENSION_INTERFACE "org.gnome.Evolution.EHTMLEditor.WebExtension"
+#include <webkitdom/webkitdom.h>
-#endif /* E_HTML_EDITOR_WEB_EXTENSION_NAMES_H */
+G_BEGIN_DECLS
+
+gchar * e_html_editor_spell_check_dialog_prev (WebKitDOMDocument *document,
+ const gchar *word);
+
+gchar * e_html_editor_spell_check_dialog_next (WebKitDOMDocument *document,
+ const gchar *word);
+
+G_END_DECLS
+
+#endif /* E_HTML_EDITOR_SPELL_CHECK_DIALOG_DOM_FUNCTIONS_H */
diff --git a/e-util/e-html-editor-spell-check-dialog.c b/e-util/e-html-editor-spell-check-dialog.c
index 5d632a1..e1799ca 100644
--- a/e-util/e-html-editor-spell-check-dialog.c
+++ b/e-util/e-html-editor-spell-check-dialog.c
@@ -48,8 +48,6 @@ struct _EHTMLEditorSpellCheckDialogPrivate {
GtkWidget *suggestion_label;
GtkWidget *tree_view;
- WebKitDOMDOMSelection *selection;
-
gchar *word;
ESpellDictionary *current_dict;
};
@@ -74,7 +72,7 @@ html_editor_spell_check_dialog_set_word (EHTMLEditorSpellCheckDialog *dialog,
GtkTreeView *tree_view;
GtkListStore *store;
gchar *markup;
- GList *list, *link;
+ GList *list = NULL, *link;
if (word == NULL)
return;
@@ -92,9 +90,9 @@ html_editor_spell_check_dialog_set_word (EHTMLEditorSpellCheckDialog *dialog,
tree_view = GTK_TREE_VIEW (dialog->priv->tree_view);
store = GTK_LIST_STORE (gtk_tree_view_get_model (tree_view));
gtk_list_store_clear (store);
-
+/* FIXME WK2
list = e_spell_dictionary_get_suggestions (
- dialog->priv->current_dict, word, -1);
+ dialog->priv->current_dict, word, -1);*/
for (link = list; link != NULL; link = g_list_next (link)) {
GtkTreeIter iter;
@@ -117,90 +115,42 @@ html_editor_spell_check_dialog_set_word (EHTMLEditorSpellCheckDialog *dialog,
}
static gboolean
-select_next_word (EHTMLEditorSpellCheckDialog *dialog)
-{
- WebKitDOMNode *anchor, *focus;
- gulong anchor_offset, focus_offset;
-
- anchor = webkit_dom_dom_selection_get_anchor_node (dialog->priv->selection);
- anchor_offset = webkit_dom_dom_selection_get_anchor_offset (dialog->priv->selection);
-
- focus = webkit_dom_dom_selection_get_focus_node (dialog->priv->selection);
- focus_offset = webkit_dom_dom_selection_get_focus_offset (dialog->priv->selection);
-
- /* Jump _behind_ next word */
- webkit_dom_dom_selection_modify (
- dialog->priv->selection, "move", "forward", "word");
- /* Jump before the word */
- webkit_dom_dom_selection_modify (
- dialog->priv->selection, "move", "backward", "word");
- /* Select it */
- webkit_dom_dom_selection_modify (
- dialog->priv->selection, "extend", "forward", "word");
-
- /* If the selection didn't change, then we have most probably
- * reached the end of document - return FALSE */
- return !((anchor == webkit_dom_dom_selection_get_anchor_node (
- dialog->priv->selection)) &&
- (anchor_offset == webkit_dom_dom_selection_get_anchor_offset (
- dialog->priv->selection)) &&
- (focus == webkit_dom_dom_selection_get_focus_node (
- dialog->priv->selection)) &&
- (focus_offset == webkit_dom_dom_selection_get_focus_offset (
- dialog->priv->selection)));
-}
-
-static gboolean
-html_editor_spell_check_dialog_next (EHTMLEditorSpellCheckDialog *dialog)
+move_to_another_word (EHTMLEditorSpellCheckDialog *dialog,
+ const gchar *dom_function)
{
- WebKitDOMNode *start = NULL, *end = NULL;
- gulong start_offset, end_offset;
-
- if (dialog->priv->word == NULL) {
- webkit_dom_dom_selection_modify (
- dialog->priv->selection, "move", "left", "documentboundary");
- } else {
- /* Remember last selected word */
- start = webkit_dom_dom_selection_get_anchor_node (
- dialog->priv->selection);
- end = webkit_dom_dom_selection_get_focus_node (
- dialog->priv->selection);
- start_offset = webkit_dom_dom_selection_get_anchor_offset (
- dialog->priv->selection);
- end_offset = webkit_dom_dom_selection_get_focus_offset (
- dialog->priv->selection);
- }
-
- while (select_next_word (dialog)) {
- WebKitDOMRange *range;
- WebKitSpellChecker *checker;
- gint loc, len;
- gchar *word;
+ EHTMLEditor *editor;
+ EHTMLEditorView *view;
+ GDBusProxy *web_extension;
+ GVariant *result;
- range = webkit_dom_dom_selection_get_range_at (
- dialog->priv->selection, 0, NULL);
- word = webkit_dom_range_get_text (range);
+ editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
+ view = e_html_editor_get_view (editor);
+ web_extension = e_html_editor_view_get_web_extension_proxy (view);
+ if (!web_extension)
+ return FALSE;
+
+ result = g_dbus_proxy_call_sync (
+ web_extension,
+ dom_function,
+ g_variant_new (
+ "(ts)",
+ webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
+ dialog->priv->word),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL);
- checker = WEBKIT_SPELL_CHECKER (webkit_get_text_checker ());
- webkit_spell_checker_check_spelling_of_string (
- checker, word, &loc, &len);
+ if (result) {
+ const gchar *next_word;
+ gsize length;
- /* Found misspelled word! */
- if (loc != -1) {
- html_editor_spell_check_dialog_set_word (dialog, word);
- g_free (word);
+ next_word = g_variant_get_string (result, &length);
+ if (length > 0)
+ html_editor_spell_check_dialog_set_word (dialog, next_word);
+ g_variant_unref (result);
+ if (length > 0)
return TRUE;
- }
-
- g_free (word);
- }
-
- /* Restore the selection to contain the last misspelled word. This is
- * reached only when we reach the end of the document */
- if (start && end) {
- webkit_dom_dom_selection_set_base_and_extent (
- dialog->priv->selection, start, start_offset,
- end, end_offset, NULL);
}
/* Close the dialog */
@@ -209,100 +159,15 @@ html_editor_spell_check_dialog_next (EHTMLEditorSpellCheckDialog *dialog)
}
static gboolean
-select_previous_word (EHTMLEditorSpellCheckDialog *dialog)
+html_editor_spell_check_dialog_next (EHTMLEditorSpellCheckDialog *dialog)
{
- WebKitDOMNode *old_anchor_node;
- WebKitDOMNode *new_anchor_node;
- gulong old_anchor_offset;
- gulong new_anchor_offset;
-
- old_anchor_node = webkit_dom_dom_selection_get_anchor_node (
- dialog->priv->selection);
- old_anchor_offset = webkit_dom_dom_selection_get_anchor_offset (
- dialog->priv->selection);
-
- /* Jump on the beginning of current word */
- webkit_dom_dom_selection_modify (
- dialog->priv->selection, "move", "backward", "word");
- /* Jump before previous word */
- webkit_dom_dom_selection_modify (
- dialog->priv->selection, "move", "backward", "word");
- /* Select it */
- webkit_dom_dom_selection_modify (
- dialog->priv->selection, "extend", "forward", "word");
-
- /* If the selection start didn't change, then we have most probably
- * reached the beginnig of document. Return FALSE */
-
- new_anchor_node = webkit_dom_dom_selection_get_anchor_node (
- dialog->priv->selection);
- new_anchor_offset = webkit_dom_dom_selection_get_anchor_offset (
- dialog->priv->selection);
-
- return (new_anchor_node != old_anchor_node) ||
- (new_anchor_offset != old_anchor_offset);
+ return move_to_another_word (dialog, "EHTMLEditorSpellCheckDialogNext");
}
static gboolean
html_editor_spell_check_dialog_prev (EHTMLEditorSpellCheckDialog *dialog)
{
- WebKitDOMNode *start = NULL, *end = NULL;
- gulong start_offset, end_offset;
-
- if (dialog->priv->word == NULL) {
- webkit_dom_dom_selection_modify (
- dialog->priv->selection,
- "move", "right", "documentboundary");
- webkit_dom_dom_selection_modify (
- dialog->priv->selection,
- "extend", "backward", "word");
- } else {
- /* Remember last selected word */
- start = webkit_dom_dom_selection_get_anchor_node (
- dialog->priv->selection);
- end = webkit_dom_dom_selection_get_focus_node (
- dialog->priv->selection);
- start_offset = webkit_dom_dom_selection_get_anchor_offset (
- dialog->priv->selection);
- end_offset = webkit_dom_dom_selection_get_focus_offset (
- dialog->priv->selection);
- }
-
- while (select_previous_word (dialog)) {
- WebKitDOMRange *range;
- WebKitSpellChecker *checker;
- gint loc, len;
- gchar *word;
-
- range = webkit_dom_dom_selection_get_range_at (
- dialog->priv->selection, 0, NULL);
- word = webkit_dom_range_get_text (range);
-
- checker = WEBKIT_SPELL_CHECKER (webkit_get_text_checker ());
- webkit_spell_checker_check_spelling_of_string (
- checker, word, &loc, &len);
-
- /* Found misspelled word! */
- if (loc != -1) {
- html_editor_spell_check_dialog_set_word (dialog, word);
- g_free (word);
- return TRUE;
- }
-
- g_free (word);
- }
-
- /* Restore the selection to contain the last misspelled word. This is
- * reached only when we reach the beginning of the document */
- if (start && end) {
- webkit_dom_dom_selection_set_base_and_extent (
- dialog->priv->selection, start, start_offset,
- end, end_offset, NULL);
- }
-
- /* Close the dialog */
- gtk_widget_hide (GTK_WIDGET (dialog));
- return FALSE;
+ return move_to_another_word (dialog, "EHTMLEditorSpellCheckDialogPrev");
}
static void
@@ -310,7 +175,6 @@ html_editor_spell_check_dialog_replace (EHTMLEditorSpellCheckDialog *dialog)
{
EHTMLEditor *editor;
EHTMLEditorView *view;
- EHTMLEditorSelection *editor_selection;
GtkTreeModel *model;
GtkTreeSelection *selection;
GtkTreeIter iter;
@@ -318,15 +182,13 @@ html_editor_spell_check_dialog_replace (EHTMLEditorSpellCheckDialog *dialog)
editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
view = e_html_editor_get_view (editor);
- editor_selection = e_html_editor_view_get_selection (view);
selection = gtk_tree_view_get_selection (
GTK_TREE_VIEW (dialog->priv->tree_view));
gtk_tree_selection_get_selected (selection, &model, &iter);
gtk_tree_model_get (model, &iter, 0, &replacement, -1);
- e_html_editor_selection_insert_html (
- editor_selection, replacement);
+ e_html_editor_view_insert_html (view, replacement);
g_free (replacement);
html_editor_spell_check_dialog_next (dialog);
@@ -337,7 +199,6 @@ html_editor_spell_check_dialog_replace_all (EHTMLEditorSpellCheckDialog *dialog)
{
EHTMLEditor *editor;
EHTMLEditorView *view;
- EHTMLEditorSelection *editor_selection;
GtkTreeModel *model;
GtkTreeSelection *selection;
GtkTreeIter iter;
@@ -345,7 +206,6 @@ html_editor_spell_check_dialog_replace_all (EHTMLEditorSpellCheckDialog *dialog)
editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
view = e_html_editor_get_view (editor);
- editor_selection = e_html_editor_view_get_selection (view);
selection = gtk_tree_view_get_selection (
GTK_TREE_VIEW (dialog->priv->tree_view));
@@ -355,14 +215,14 @@ html_editor_spell_check_dialog_replace_all (EHTMLEditorSpellCheckDialog *dialog)
/* Repeatedly search for 'word', then replace selection by
* 'replacement'. Repeat until there's at least one occurence of
* 'word' in the document */
+#if 0 /* FIXME WK2 */
while (webkit_web_view_search_text (
WEBKIT_WEB_VIEW (view), dialog->priv->word,
FALSE, TRUE, TRUE)) {
- e_html_editor_selection_insert_html (
- editor_selection, replacement);
+ e_html_editor_view_insert_html (view, replacement);
}
-
+#endif
g_free (replacement);
html_editor_spell_check_dialog_next (dialog);
}
@@ -372,10 +232,10 @@ html_editor_spell_check_dialog_ignore (EHTMLEditorSpellCheckDialog *dialog)
{
if (dialog->priv->word == NULL)
return;
-
+/* FIXME WK2
e_spell_dictionary_ignore_word (
dialog->priv->current_dict, dialog->priv->word, -1);
-
+*/
html_editor_spell_check_dialog_next (dialog);
}
@@ -384,9 +244,9 @@ html_editor_spell_check_dialog_learn (EHTMLEditorSpellCheckDialog *dialog)
{
if (dialog->priv->word == NULL)
return;
-
+/* FIXME WK2
e_spell_dictionary_learn_word (
- dialog->priv->current_dict, dialog->priv->word, -1);
+ dialog->priv->current_dict, dialog->priv->word, -1); */
html_editor_spell_check_dialog_next (dialog);
}
@@ -415,24 +275,13 @@ html_editor_spell_check_dialog_set_dictionary (EHTMLEditorSpellCheckDialog *dial
static void
html_editor_spell_check_dialog_show (GtkWidget *widget)
{
- EHTMLEditor *editor;
- EHTMLEditorView *view;
EHTMLEditorSpellCheckDialog *dialog;
- WebKitDOMDocument *document;
- WebKitDOMDOMWindow *window;
dialog = E_HTML_EDITOR_SPELL_CHECK_DIALOG (widget);
g_free (dialog->priv->word);
dialog->priv->word = NULL;
- editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
- view = e_html_editor_get_view (editor);
-
- document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
- window = webkit_dom_document_get_default_view (document);
- dialog->priv->selection = webkit_dom_dom_window_get_selection (window);
-
/* Select the first word or quit */
if (html_editor_spell_check_dialog_next (dialog)) {
GTK_WIDGET_CLASS (e_html_editor_spell_check_dialog_parent_class)->
@@ -626,9 +475,9 @@ e_html_editor_spell_check_dialog_update_dictionaries (EHTMLEditorSpellCheckDialo
EHTMLEditorView *view;
ESpellChecker *spell_checker;
GtkComboBox *combo_box;
- GtkListStore *store;
+ GtkListStore *store = NULL;
GQueue queue = G_QUEUE_INIT;
- gchar **languages;
+ gchar **languages = NULL;
guint n_languages = 0;
guint ii;
@@ -637,7 +486,7 @@ e_html_editor_spell_check_dialog_update_dictionaries (EHTMLEditorSpellCheckDialo
editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
view = e_html_editor_get_view (editor);
spell_checker = e_html_editor_view_get_spell_checker (view);
-
+/* FIXME WK2
languages = e_spell_checker_list_active_languages (
spell_checker, &n_languages);
for (ii = 0; ii < n_languages; ii++) {
@@ -653,20 +502,22 @@ e_html_editor_spell_check_dialog_update_dictionaries (EHTMLEditorSpellCheckDialo
G_STRFUNC, languages[ii]);
}
g_strfreev (languages);
-
+*/
/* Populate a list store for the combo box. */
+#if 0 /* FIXME WK2 */
store = gtk_list_store_new (
NUM_COLUMNS,
G_TYPE_STRING, /* COLUMN_NAME */
E_TYPE_SPELL_DICTIONARY); /* COLUMN_DICTIONARY */
-
+#endif
while (!g_queue_is_empty (&queue)) {
ESpellDictionary *dictionary;
GtkTreeIter iter;
- const gchar *name;
+ const gchar *name = NULL;
dictionary = g_queue_pop_head (&queue);
- name = e_spell_dictionary_get_name (dictionary);
+ /* FIXME WK2
+ name = e_spell_dictionary_get_name (dictionary);*/
gtk_list_store_append (store, &iter);
gtk_list_store_set (
diff --git a/e-util/e-html-editor-table-dialog-dom-functions.c
b/e-util/e-html-editor-table-dialog-dom-functions.c
index 4fd37a8..e5d1835 100644
--- a/e-util/e-html-editor-table-dialog-dom-functions.c
+++ b/e-util/e-html-editor-table-dialog-dom-functions.c
@@ -1,5 +1,5 @@
/*
- * e-html-editor-cell-dialog-dom-functions.c
+ * e-html-editor-table-dialog-dom-functions.c
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -16,25 +16,26 @@
*
*/
-#include "e-html-editor-cell-dialog-dom-functions.h"
+#include "e-html-editor-table-dialog-dom-functions.h"
#include "e-dom-utils.h"
+#include "e-html-editor-selection-dom-functions.h"
#define WEBKIT_DOM_USE_UNSTABLE_API
#include <webkitdom/WebKitDOMDOMSelection.h>
#include <webkitdom/WebKitDOMDOMWindowUnstable.h>
-static WebKitDOMElement *
+static WebKitDOMHTMLTableElement *
get_current_table_element (WebKitDOMDocument *document)
{
- return webkit_dom_document_get_element_by_id (document, "-x-evo-current-table");
+ return WEBKIT_DOM_HTML_TABLE_ELEMENT (webkit_dom_document_get_element_by_id (document,
"-x-evo-current-table"));
}
void
e_html_editor_table_dialog_set_row_count (WebKitDOMDocument *document,
gulong expected_count)
{
- WebKitDOMElement *table_element;
+ WebKitDOMHTMLTableElement *table_element;
WebKitDOMHTMLCollection *rows;
gulong ii, current_count;
@@ -61,14 +62,14 @@ e_html_editor_table_dialog_set_row_count (WebKitDOMDocument *document,
gulong
e_html_editor_table_dialog_get_row_count (WebKitDOMDocument *document)
{
- WebKitDOMElement *table_element;
+ WebKitDOMHTMLTableElement *table_element;
WebKitDOMHTMLCollection *rows;
table_element = get_current_table_element (document);
if (!table_element)
return 0;
- rows = webkit_dom_html_table_element_get_rows (able_element);
+ rows = webkit_dom_html_table_element_get_rows (table_element);
return webkit_dom_html_collection_get_length (rows);
}
@@ -77,7 +78,7 @@ void
e_html_editor_table_dialog_set_column_count (WebKitDOMDocument *document,
gulong expected_columns)
{
- WebKitDOMElement *table_element;
+ WebKitDOMHTMLTableElement *table_element;
WebKitDOMHTMLCollection *rows;
gulong ii, row_count;
@@ -85,7 +86,7 @@ e_html_editor_table_dialog_set_column_count (WebKitDOMDocument *document,
if (!table_element)
return;
- rows = webkit_dom_html_table_element_get_rows (dialog->priv->table_element);
+ rows = webkit_dom_html_table_element_get_rows (table_element);
row_count = webkit_dom_html_collection_get_length (rows);
for (ii = 0; ii < row_count; ii++) {
@@ -116,7 +117,7 @@ e_html_editor_table_dialog_set_column_count (WebKitDOMDocument *document,
gulong
e_html_editor_table_dialog_get_column_count (WebKitDOMDocument *document)
{
- WebKitDOMElement *table_element;
+ WebKitDOMHTMLTableElement *table_element;
WebKitDOMHTMLCollection *rows, *columns;
WebKitDOMNode *row;
@@ -124,7 +125,7 @@ e_html_editor_table_dialog_get_column_count (WebKitDOMDocument *document)
if (!table_element)
return 0;
- rows = webkit_dom_html_table_element_get_rows (dialog->priv->table_element);
+ rows = webkit_dom_html_table_element_get_rows (table_element);
row = webkit_dom_html_collection_item (rows, 0);
columns = webkit_dom_html_table_row_element_get_cells (
@@ -133,7 +134,7 @@ e_html_editor_table_dialog_get_column_count (WebKitDOMDocument *document)
return webkit_dom_html_collection_get_length (columns);
}
-static
+static void
create_table (WebKitDOMDocument *document)
{
WebKitDOMElement *table, *br, *caret, *parent, *element;
@@ -156,7 +157,7 @@ create_table (WebKitDOMDocument *document)
webkit_dom_element_set_id (table, "-x-evo-current-table");
- caret = e_html_editor_selection_dom_save_caret_position (document);
+ caret = dom_save_caret_position (document);
parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (caret));
element = caret;
@@ -181,12 +182,10 @@ create_table (WebKitDOMDocument *document)
webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (element)),
NULL);
- e_html_editor_selection_dom_clear_caret_position_marker (document);
+ dom_clear_caret_position_marker (document);
/* FIXME WK2
e_html_editor_view_set_changed (view, TRUE);*/
-
- return table;
}
gboolean
diff --git a/e-util/e-html-editor-table-dialog-dom-functions.h
b/e-util/e-html-editor-table-dialog-dom-functions.h
index d1c70d5..01a7f8f 100644
--- a/e-util/e-html-editor-table-dialog-dom-functions.h
+++ b/e-util/e-html-editor-table-dialog-dom-functions.h
@@ -16,8 +16,8 @@
*
*/
-#ifndef E_HTML_TABLE_DIALOG_DOM_FUNCTIONS_H
-#define E_HTML_TABLE_DIALOG_DOM_FUNCTIONS_H
+#ifndef E_HTML_EDITOR_TABLE_DIALOG_DOM_FUNCTIONS_H
+#define E_HTML_EDITOR_TABLE_DIALOG_DOM_FUNCTIONS_H
#include <webkitdom/webkitdom.h>
diff --git a/e-util/e-html-editor-view-dom-functions.c b/e-util/e-html-editor-view-dom-functions.c
index 9b91397..beede09 100644
--- a/e-util/e-html-editor-view-dom-functions.c
+++ b/e-util/e-html-editor-view-dom-functions.c
@@ -18,8 +18,24 @@
#include "e-html-editor-view-dom-functions.h"
-#include "e-dom-utils.h"
#include "e-html-editor-selection-dom-functions.h"
+#include "e-dom-utils.h"
+#include "e-misc-utils.h"
+#include "e-emoticon-chooser.h"
+
+#include <string.h>
+
+#define WEBKIT_DOM_USE_UNSTABLE_API
+#include <webkitdom/WebKitDOMDocumentFragmentUnstable.h>
+#include <webkitdom/WebKitDOMRangeUnstable.h>
+#include <webkitdom/WebKitDOMDOMSelection.h>
+#include <webkitdom/WebKitDOMDOMWindowUnstable.h>
+
+#define HTML_KEY_CODE_BACKSPACE 8
+#define HTML_KEY_CODE_RETURN 13
+#define HTML_KEY_CODE_CONTROL 17
+#define HTML_KEY_CODE_SPACE 32
+#define HTML_KEY_CODE_DELETE 46
/**
* e_html_editor_view_dom_exec_command:
@@ -126,7 +142,8 @@ get_parent_block_element (WebKitDOMNode *node)
}
void
-dom_force_spell_check_for_current_paragraph (WebKitDOMDocument *document)
+dom_force_spell_check_for_current_paragraph (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
WebKitDOMDOMSelection *dom_selection;
WebKitDOMDOMWindow *window;
@@ -135,6 +152,9 @@ dom_force_spell_check_for_current_paragraph (WebKitDOMDocument *document)
WebKitDOMRange *end_range, *actual;
WebKitDOMText *text;
+ if (!e_html_editor_web_extension_get_inline_spelling_enabled (extension))
+ return;
+
window = webkit_dom_document_get_default_view (document);
dom_selection = webkit_dom_dom_window_get_selection (window);
@@ -208,7 +228,7 @@ dom_force_spell_check_for_current_paragraph (WebKitDOMDocument *document)
view, html_editor_view_selection_changed_cb, NULL);
e_html_editor_selection_unblock_selection_changed (selection);
*/
- do_selection_restore (document);
+ dom_selection_restore (document);
}
static WebKitDOMElement *
@@ -374,10 +394,10 @@ dom_turn_spell_check_off (WebKitDOMDocument *document)
}
void
-dom_force_spell_check (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document)
+dom_force_spell_check (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
- if (extension->priv->inline_spelling)
+ if (e_html_editor_web_extension_get_inline_spelling_enabled (extension))
refresh_spell_check (document, TRUE);
}
@@ -528,11 +548,12 @@ get_parent_block_node_from_child (WebKitDOMNode *node)
static WebKitDOMElement *
prepare_paragraph (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
gboolean with_selection)
{
WebKitDOMElement *element, *paragraph;
- paragraph = dom_get_paragraph_element (document, -1, 0);
+ paragraph = dom_get_paragraph_element (document, extension, -1, 0);
if (with_selection)
add_selection_markers_into_element_start (
@@ -547,14 +568,14 @@ prepare_paragraph (WebKitDOMDocument *document,
}
static WebKitDOMElement *
-insert_new_line_into_citation (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
+insert_new_line_into_citation (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
const gchar *html_to_insert)
{
gboolean html_mode = FALSE, ret_val, avoid_editor_call;
WebKitDOMElement *element, *paragraph = NULL;
- html_mode = is_in_html_mode (extension);
+ html_mode = e_html_editor_web_extension_get_html_mode (extension);
avoid_editor_call = return_pressed_in_empty_line (document);
@@ -590,7 +611,7 @@ insert_new_line_into_citation (EHTMLEditorWebExtension *extension,
parent = webkit_dom_node_get_parent_node (parent_block);
}
- paragraph = dom_get_paragraph_element (document, -1, 0);
+ paragraph = dom_get_paragraph_element (document, extension, -1, 0);
webkit_dom_node_append_child (
WEBKIT_DOM_NODE (paragraph),
@@ -652,7 +673,7 @@ insert_new_line_into_citation (EHTMLEditorWebExtension *extension,
if (WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (next_sibling)) {
gint citation_level, length;
- gint word_wrap_length = extension->priv->word_wrap_length;
+ gint word_wrap_length;
WebKitDOMNode *node;
node = webkit_dom_node_get_first_child (next_sibling);
@@ -660,24 +681,26 @@ insert_new_line_into_citation (EHTMLEditorWebExtension *extension,
node = webkit_dom_node_get_first_child (node);
citation_level = get_citation_level (node, FALSE);
+ word_wrap_length =
+ e_html_editor_web_extension_get_word_wrap_length (extension);
length = word_wrap_length - 2 * citation_level;
/* Rewrap and requote first block after the newly inserted line */
if (node && WEBKIT_DOM_IS_ELEMENT (node)) {
- remove_quoting_from_element (WEBKIT_DOM_ELEMENT (node));
- remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (node));
+ dom_remove_quoting_from_element (WEBKIT_DOM_ELEMENT (node));
+ dom_remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (node));
node = WEBKIT_DOM_NODE (dom_wrap_paragraph_length (
- document, WEBKIT_DOM_ELEMENT (node), length));
+ document, extension, WEBKIT_DOM_ELEMENT (node), length));
quote_plain_text_element_after_wrapping (
document, WEBKIT_DOM_ELEMENT (node), citation_level);
}
- dom_force_spell_check (document);
+ dom_force_spell_check (document, extension);
}
}
if (html_to_insert && *html_to_insert) {
- paragraph = prepare_paragraph (document, FALSE);
+ paragraph = prepare_paragraph (document, extension, FALSE);
webkit_dom_html_element_set_inner_html (
WEBKIT_DOM_HTML_ELEMENT (paragraph),
html_to_insert,
@@ -685,7 +708,7 @@ insert_new_line_into_citation (EHTMLEditorWebExtension *extension,
add_selection_markers_into_element_end (
document, paragraph, NULL, NULL);
} else
- paragraph = prepare_paragraph (document, TRUE);
+ paragraph = prepare_paragraph (document, extension, TRUE);
webkit_dom_node_insert_before (
webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (element)),
@@ -794,33 +817,32 @@ repair_gmail_blockquotes (WebKitDOMDocument *document)
g_object_unref (list);
}
-/* FIXME WK2 */
static void
dom_check_magic_links (WebKitDOMDocument *document,
- WebKitDOMRange *range,
- gboolean include_space_by_user,
- gboolean return_pressed,
- gboolean space_pressed)
+ EHTMLEditorWebExtension *extension,
+ gboolean include_space_by_user)
{
gchar *node_text;
gchar **urls;
+ gboolean include_space = FALSE;
+ gboolean is_email_address = FALSE;
+ gboolean return_key_pressed =
+ e_html_editor_web_extension_get_return_key_pressed (extension);
GRegex *regex = NULL;
GMatchInfo *match_info;
gint start_pos_url, end_pos_url;
WebKitDOMNode *node;
- gboolean include_space = FALSE;
- gboolean return_pressed = FALSE;
+ WebKitDOMRange *range;
- if (event != NULL) {
- return_pressed = is_return_key (event);
- include_space = (event->keyval == GDK_KEY_space);
- } else {
- include_space = include_space_by_user;
- }
+ if (include_space_by_user == TRUE)
+ include_space = TRUE;
+ else
+ include_space = e_html_editor_web_extension_get_return_key_pressed (extension);
+ range = dom_get_current_range (document);
node = webkit_dom_range_get_end_container (range, NULL);
- if (return_pressed)
+ if (return_key_pressed)
node = webkit_dom_node_get_previous_sibling (node);
if (!node)
@@ -837,7 +859,11 @@ dom_check_magic_links (WebKitDOMDocument *document,
if (!node_text || !(*node_text) || !g_utf8_validate (node_text, -1, NULL))
return;
- regex = g_regex_new (include_space ? URL_PATTERN_SPACE : URL_PATTERN, 0, 0, NULL);
+ if (strstr (node_text, "@") && !strstr (node_text, "://")) {
+ is_email_address = TRUE;
+ regex = g_regex_new (include_space ? E_MAIL_PATTERN_SPACE : E_MAIL_PATTERN, 0, 0, NULL);
+ } else
+ regex = g_regex_new (include_space ? URL_PATTERN_SPACE : URL_PATTERN, 0, 0, NULL);
if (!regex) {
g_free (node_text);
@@ -855,7 +881,7 @@ dom_check_magic_links (WebKitDOMDocument *document,
WebKitDOMElement *anchor;
const gchar* url_text;
- if (!return_pressed)
+ if (!return_key_pressed)
dom_save_caret_position (document);
g_match_info_fetch_pos (match_info, 0, &start_pos_url, &end_pos_url);
@@ -880,8 +906,12 @@ dom_check_magic_links (WebKitDOMDocument *document,
url_text = webkit_dom_text_get_whole_text (
WEBKIT_DOM_TEXT (url_text_node_clone));
- final_url = g_strconcat (
- g_str_has_prefix (url_text, "www") ? "http://" : "", url_text, NULL);
+ if (g_str_has_prefix (url_text, "www."))
+ final_url = g_strconcat ("http://" , url_text, NULL);
+ else if (is_email_address)
+ final_url = g_strconcat ("mailto:" , url_text, NULL);
+ else
+ final_url = g_strdup (url_text);
/* Create and prepare new anchor element */
anchor = webkit_dom_document_create_element (document, "A", NULL);
@@ -902,7 +932,7 @@ dom_check_magic_links (WebKitDOMDocument *document,
WEBKIT_DOM_NODE (url_text_node),
NULL);
- if (!return_pressed)
+ if (!return_key_pressed)
dom_restore_caret_position (document);
g_free (url_end_raw);
@@ -1047,7 +1077,7 @@ dom_embed_style_sheet (WebKitDOMDocument *document,
{
WebKitDOMElement *sheet;
- e_web_view_create_and_add_css_style_sheet (document, "-x-evo-composer-sheet");
+ e_dom_utils_create_and_add_css_style_sheet (document, "-x-evo-composer-sheet");
sheet = webkit_dom_document_get_element_by_id (document, "-x-evo-composer-sheet");
webkit_dom_element_set_attribute (
@@ -1056,7 +1086,7 @@ dom_embed_style_sheet (WebKitDOMDocument *document,
"text/css",
NULL);
- webkit_dom_html_element_set_inner_html (WEBKIT_DOM_HTML_ELEMENT (sheet), stylesheet_content, NULL);
+ webkit_dom_html_element_set_inner_html (WEBKIT_DOM_HTML_ELEMENT (sheet), style_sheet_content, NULL);
}
void
@@ -1070,6 +1100,376 @@ dom_remove_embed_style_sheet (WebKitDOMDocument *document)
remove_node (WEBKIT_DOM_NODE (sheet));
}
+/* Based on original use_pictograms() from GtkHTML */
+static const gchar *emoticons_chars =
+ /* 0 */ "DO)(|/PQ*!"
+ /* 10 */ "S\0:-\0:\0:-\0"
+ /* 20 */ ":\0:;=-\"\0:;"
+ /* 30 */ "B\"|\0:-'\0:X"
+ /* 40 */ "\0:\0:-\0:\0:-"
+ /* 50 */ "\0:\0:-\0:\0:-"
+ /* 60 */ "\0:\0:\0:-\0:\0"
+ /* 70 */ ":-\0:\0:-\0:\0";
+static gint emoticons_states[] = {
+ /* 0 */ 12, 17, 22, 34, 43, 48, 53, 58, 65, 70,
+ /* 10 */ 75, 0, -15, 15, 0, -15, 0, -17, 20, 0,
+ /* 20 */ -17, 0, -14, -20, -14, 28, 63, 0, -14, -20,
+ /* 30 */ -3, 63, -18, 0, -12, 38, 41, 0, -12, -2,
+ /* 40 */ 0, -4, 0, -10, 46, 0, -10, 0, -19, 51,
+ /* 50 */ 0, -19, 0, -11, 56, 0, -11, 0, -13, 61,
+ /* 60 */ 0, -13, 0, -6, 0, 68, -7, 0, -7, 0,
+ /* 70 */ -16, 73, 0, -16, 0, -21, 78, 0, -21, 0 };
+static const gchar *emoticons_icon_names[] = {
+ "face-angel",
+ "face-angry",
+ "face-cool",
+ "face-crying",
+ "face-devilish",
+ "face-embarrassed",
+ "face-kiss",
+ "face-laugh", /* not used */
+ "face-monkey", /* not used */
+ "face-plain",
+ "face-raspberry",
+ "face-sad",
+ "face-sick",
+ "face-smile",
+ "face-smile-big",
+ "face-smirk",
+ "face-surprise",
+ "face-tired",
+ "face-uncertain",
+ "face-wink",
+ "face-worried"
+};
+
+typedef struct _LoadContext LoadContext;
+
+struct _LoadContext {
+ EEmoticon *emoticon;
+ EHTMLEditorWebExtension *extension;
+ gchar *content_type;
+ gchar *name;
+ WebKitDOMDocument *document;
+};
+
+static LoadContext *
+emoticon_load_context_new (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
+ EEmoticon *emoticon)
+{
+ LoadContext *load_context;
+
+ load_context = g_slice_new0 (LoadContext);
+ load_context->emoticon = emoticon;
+ load_context->extension = extension;
+ load_context->document = document;
+
+ return load_context;
+}
+
+static void
+emoticon_load_context_free (LoadContext *load_context)
+{
+ g_free (load_context->content_type);
+ g_free (load_context->name);
+ g_slice_free (LoadContext, load_context);
+}
+
+static void
+emoticon_read_async_cb (GFile *file,
+ GAsyncResult *result,
+ LoadContext *load_context)
+{
+ EHTMLEditorWebExtension *extension = load_context->extension;
+ EEmoticon *emoticon = load_context->emoticon;
+ GError *error = NULL;
+ gboolean misplaced_selection = FALSE, empty = FALSE;
+ gchar *html, *node_text = NULL, *mime_type, *content;
+ gchar *base64_encoded, *output, *data;
+ const gchar *emoticon_start;
+ GFileInputStream *input_stream;
+ GOutputStream *output_stream;
+ gssize size;
+ WebKitDOMDocument *document = load_context->document;
+ WebKitDOMElement *span, *selection_start_marker, *selection_end_marker;
+ WebKitDOMNode *node, *insert_before, *prev_sibling, *next_sibling;
+ WebKitDOMNode *selection_end_marker_parent;
+ WebKitDOMRange *range;
+
+ input_stream = g_file_read_finish (file, result, &error);
+ g_return_if_fail (!error && input_stream);
+
+ output_stream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
+
+ size = g_output_stream_splice (
+ output_stream, G_INPUT_STREAM (input_stream),
+ G_OUTPUT_STREAM_SPLICE_NONE, NULL, &error);
+
+ if (error || (size == -1))
+ goto out;
+
+ dom_selection_save (document);
+
+ selection_start_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-start-marker");
+ selection_end_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-end-marker");
+
+ /* If the selection was not saved, move it into the first child of body */
+ if (!selection_start_marker || !selection_end_marker) {
+ WebKitDOMHTMLElement *body;
+ WebKitDOMNode *child;
+
+ body = webkit_dom_document_get_body (document);
+ child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body));
+
+ add_selection_markers_into_element_start (
+ document,
+ WEBKIT_DOM_ELEMENT (child),
+ &selection_start_marker,
+ &selection_end_marker);
+ }
+
+ /* Sometimes selection end marker is in body. Move it into next sibling */
+ selection_end_marker_parent = get_parent_block_node_from_child (
+ WEBKIT_DOM_NODE (selection_end_marker));
+ if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (selection_end_marker_parent)) {
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (
+ WEBKIT_DOM_NODE (selection_start_marker)),
+ WEBKIT_DOM_NODE (selection_end_marker),
+ WEBKIT_DOM_NODE (selection_start_marker),
+ NULL);
+ }
+ selection_end_marker_parent = webkit_dom_node_get_parent_node (
+ WEBKIT_DOM_NODE (selection_end_marker));
+
+ /* Determine before what node we have to insert the smiley */
+ insert_before = WEBKIT_DOM_NODE (selection_start_marker);
+ prev_sibling = webkit_dom_node_get_previous_sibling (
+ WEBKIT_DOM_NODE (selection_start_marker));
+ if (prev_sibling) {
+ if (webkit_dom_node_is_same_node (
+ prev_sibling, WEBKIT_DOM_NODE (selection_end_marker))) {
+ insert_before = WEBKIT_DOM_NODE (selection_end_marker);
+ } else {
+ prev_sibling = webkit_dom_node_get_previous_sibling (prev_sibling);
+ if (prev_sibling &&
+ webkit_dom_node_is_same_node (
+ prev_sibling, WEBKIT_DOM_NODE (selection_end_marker))) {
+ insert_before = WEBKIT_DOM_NODE (selection_end_marker);
+ }
+ }
+ } else
+ insert_before = WEBKIT_DOM_NODE (selection_start_marker);
+
+ /* Look if selection is misplaced - that means that the selection was
+ * restored before the previously inserted smiley in situations when we
+ * are writing more smileys in a row */
+ next_sibling = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (selection_end_marker));
+ if (next_sibling && WEBKIT_DOM_IS_ELEMENT (next_sibling))
+ if (element_has_class (WEBKIT_DOM_ELEMENT (next_sibling), "-x-evo-smiley-wrapper"))
+ misplaced_selection = TRUE;
+
+ mime_type = g_content_type_get_mime_type (load_context->content_type);
+ range = dom_get_current_range (document);
+ node = webkit_dom_range_get_end_container (range, NULL);
+ if (WEBKIT_DOM_IS_TEXT (node))
+ node_text = webkit_dom_text_get_whole_text (WEBKIT_DOM_TEXT (node));
+
+ data = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (output_stream));
+ base64_encoded = g_base64_encode ((const guchar *) data, size);
+ output = g_strconcat ("data:", mime_type, ";base64,", base64_encoded, NULL);
+
+ content = webkit_dom_node_get_text_content (selection_end_marker_parent);
+ empty = !*content || (g_strcmp0 (content, UNICODE_ZERO_WIDTH_SPACE) == 0);
+ g_free (content);
+
+ /* Insert span with image representation and another one with text
+ * represetation and hide/show them dependant on active composer mode */
+ /* ​ == UNICODE_ZERO_WIDTH_SPACE */
+ html = g_strdup_printf (
+ "<span class=\"-x-evo-smiley-wrapper -x-evo-resizable-wrapper\">"
+ "<img src=\"%s\" alt=\"%s\" x-evo-smiley=\"%s\" "
+ "class=\"-x-evo-smiley-img\" data-inline data-name=\"%s\"/>"
+ "<span class=\"-x-evo-smiley-text\" style=\"display: none;\">%s"
+ "</span></span>%s",
+ output, emoticon ? emoticon->text_face : "", emoticon->icon_name,
+ load_context->name, emoticon ? emoticon->text_face : "",
+ empty ? "​" : "");
+
+ span = webkit_dom_document_create_element (document, "SPAN", NULL);
+
+ if (misplaced_selection) {
+ /* Insert smiley and selection markers after it */
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (insert_before),
+ WEBKIT_DOM_NODE (selection_start_marker),
+ webkit_dom_node_get_next_sibling (next_sibling),
+ NULL);
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (insert_before),
+ WEBKIT_DOM_NODE (selection_end_marker),
+ webkit_dom_node_get_next_sibling (next_sibling),
+ NULL);
+ span = WEBKIT_DOM_ELEMENT (
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (insert_before),
+ WEBKIT_DOM_NODE (span),
+ webkit_dom_node_get_next_sibling (next_sibling),
+ NULL));
+ } else {
+ span = WEBKIT_DOM_ELEMENT (
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (insert_before),
+ WEBKIT_DOM_NODE (span),
+ insert_before,
+ NULL));
+ }
+
+ webkit_dom_html_element_set_outer_html (
+ WEBKIT_DOM_HTML_ELEMENT (span), html, NULL);
+
+ if (node_text) {
+ emoticon_start = g_utf8_strrchr (
+ node_text, -1, g_utf8_get_char (emoticon->text_face));
+ if (emoticon_start) {
+ webkit_dom_character_data_delete_data (
+ WEBKIT_DOM_CHARACTER_DATA (node),
+ g_utf8_strlen (node_text, -1) - strlen (emoticon_start),
+ strlen (emoticon->text_face),
+ NULL);
+ }
+ }
+
+ dom_selection_restore (document);
+
+ e_html_editor_web_extension_set_content_changed (extension);
+
+ g_free (html);
+ g_free (node_text);
+ g_free (base64_encoded);
+ g_free (output);
+ g_free (mime_type);
+ g_object_unref (output_stream);
+ out:
+ emoticon_load_context_free (load_context);
+}
+
+static void
+emoticon_query_info_async_cb (GFile *file,
+ GAsyncResult *result,
+ LoadContext *load_context)
+{
+ GError *error = NULL;
+ GFileInfo *info;
+
+ info = g_file_query_info_finish (file, result, &error);
+ g_return_if_fail (!error && info);
+
+ load_context->content_type = g_strdup (g_file_info_get_content_type (info));
+ load_context->name = g_strdup (g_file_info_get_name (info));
+
+ g_file_read_async (
+ file, G_PRIORITY_DEFAULT, NULL,
+ (GAsyncReadyCallback) emoticon_read_async_cb, load_context);
+
+ g_object_unref (info);
+}
+
+void
+dom_insert_smiley (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
+ EEmoticon *emoticon)
+{
+ GFile *file;
+ gchar *filename_uri;
+ LoadContext *load_context;
+
+ filename_uri = e_emoticon_get_uri (emoticon);
+ g_return_if_fail (filename_uri != NULL);
+
+ load_context = emoticon_load_context_new (document, extension, emoticon);
+
+ file = g_file_new_for_uri (filename_uri);
+ g_file_query_info_async (
+ file, "standard::*", G_FILE_QUERY_INFO_NONE,
+ G_PRIORITY_DEFAULT, NULL,
+ (GAsyncReadyCallback) emoticon_query_info_async_cb, load_context);
+
+ g_free (filename_uri);
+ g_object_unref (file);
+}
+
+static void
+dom_check_magic_smileys (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
+{
+ gint pos, state, relative, start;
+ gchar *node_text;
+ gunichar uc;
+ WebKitDOMNode *node;
+ WebKitDOMRange *range;
+
+ range = dom_get_current_range (document);
+ node = webkit_dom_range_get_end_container (range, NULL);
+ if (!WEBKIT_DOM_IS_TEXT (node))
+ return;
+
+ node_text = webkit_dom_text_get_whole_text (WEBKIT_DOM_TEXT (node));
+ if (node_text == NULL)
+ return;
+
+ start = webkit_dom_range_get_end_offset (range, NULL) - 1;
+ pos = start;
+ state = 0;
+ while (pos >= 0) {
+ uc = g_utf8_get_char (g_utf8_offset_to_pointer (node_text, pos));
+ relative = 0;
+ while (emoticons_chars[state + relative]) {
+ if (emoticons_chars[state + relative] == uc)
+ break;
+ relative++;
+ }
+ state = emoticons_states[state + relative];
+ /* 0 .. not found, -n .. found n-th */
+ if (state <= 0)
+ break;
+ pos--;
+ }
+
+ /* Special case needed to recognize angel and devilish. */
+ if (pos > 0 && state == -14) {
+ uc = g_utf8_get_char (g_utf8_offset_to_pointer (node_text, pos - 1));
+ if (uc == 'O') {
+ state = -1;
+ pos--;
+ } else if (uc == '>') {
+ state = -5;
+ pos--;
+ }
+ }
+
+ if (state < 0) {
+ const EEmoticon *emoticon;
+
+ if (pos > 0) {
+ uc = g_utf8_get_char (g_utf8_offset_to_pointer (node_text, pos - 1));
+ if (!g_unichar_isspace (uc)) {
+ g_free (node_text);
+ return;
+ }
+ }
+
+ emoticon = (e_emoticon_chooser_lookup_emoticon (
+ emoticons_icon_names[-state - 1]));
+ dom_insert_smiley (document, extension, (EEmoticon *) emoticon);
+ }
+
+ g_free (node_text);
+}
+
void
dom_set_links_active (WebKitDOMDocument *document,
gboolean active)
@@ -1078,7 +1478,7 @@ dom_set_links_active (WebKitDOMDocument *document,
if (active) {
style = webkit_dom_document_get_element_by_id (
- document, "--evolution-editor-style-a");
+ document, "-x-evo-style-a");
if (style)
remove_node (WEBKIT_DOM_NODE (style));
} else {
@@ -1086,7 +1486,7 @@ dom_set_links_active (WebKitDOMDocument *document,
head = webkit_dom_document_get_head (document);
style = webkit_dom_document_create_element (document, "STYLE", NULL);
- webkit_dom_element_set_id (style, "--evolution-editor-style-a");
+ webkit_dom_element_set_id (style, "-x-evo-style-a");
webkit_dom_html_element_set_inner_text (
WEBKIT_DOM_HTML_ELEMENT (style), "a { cursor: text; }", NULL);
@@ -1116,7 +1516,8 @@ fix_paragraph_structure_after_pressing_enter_after_smiley (WebKitDOMDocument *do
}
static void
-mark_node_as_paragraph_after_ending_list (WebKitDOMDocument *document)
+mark_node_as_paragraph_after_ending_list (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
gint ii, length;
WebKitDOMNodeList *list;
@@ -1131,13 +1532,14 @@ mark_node_as_paragraph_after_ending_list (WebKitDOMDocument *document)
WebKitDOMNode *node = webkit_dom_node_get_parent_node (
webkit_dom_node_list_item (list, ii));
- dom_set_paragraph_style (WEBKIT_DOM_ELEMENT (node), -1, 0, "");
+ dom_set_paragraph_style (document, extension, WEBKIT_DOM_ELEMENT (node), -1, 0, "");
}
g_object_unref (list);
}
static gboolean
surround_text_with_paragraph_if_needed (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
WebKitDOMNode *node)
{
WebKitDOMNode *next_sibling = webkit_dom_node_get_next_sibling (node);
@@ -1150,7 +1552,7 @@ surround_text_with_paragraph_if_needed (WebKitDOMDocument *document,
if (WEBKIT_DOM_IS_TEXT (node) &&
WEBKIT_DOM_IS_HTML_BODY_ELEMENT (webkit_dom_node_get_parent_node (node))) {
element = dom_put_node_into_paragraph (
- document, node, dom_caret_position_node (document));
+ document, extension, node, dom_create_caret_position_node (document));
if (WEBKIT_DOM_IS_HTML_BR_ELEMENT (next_sibling))
remove_node (next_sibling);
@@ -1171,7 +1573,21 @@ surround_text_with_paragraph_if_needed (WebKitDOMDocument *document,
return FALSE;
}
- static void
+
+static void
+body_keydown_event_cb (WebKitDOMElement *element,
+ WebKitDOMUIEvent *event,
+ EHTMLEditorWebExtension *extension)
+{
+ glong key_code;
+
+ key_code = webkit_dom_ui_event_get_key_code (event);
+ if (key_code == HTML_KEY_CODE_CONTROL)
+ dom_set_links_active (
+ webkit_dom_node_get_owner_document (WEBKIT_DOM_NODE (element)), TRUE);
+}
+
+static void
body_keypress_event_cb (WebKitDOMElement *element,
WebKitDOMUIEvent *event,
EHTMLEditorWebExtension *extension)
@@ -1182,9 +1598,9 @@ body_keypress_event_cb (WebKitDOMElement *element,
e_html_editor_web_extension_set_space_key_pressed (extension, FALSE);
key_code = webkit_dom_ui_event_get_key_code (event);
- if (key_code == 13)
+ if (key_code == HTML_KEY_CODE_RETURN)
e_html_editor_web_extension_set_return_key_pressed (extension, TRUE);
- else if (key_code == 32)
+ else if (key_code == HTML_KEY_CODE_SPACE)
e_html_editor_web_extension_set_space_key_pressed (extension, TRUE);
}
@@ -1199,18 +1615,18 @@ body_input_event_cb (WebKitDOMElement *element,
WebKitDOMRange *range;
document = webkit_dom_node_get_owner_document (WEBKIT_DOM_NODE (element));
- range = dom_get_range (document);
+ range = dom_get_current_range (document);
- html_mode = is_in_html_mode (extension)
- set_content_changed (extension);
+ html_mode = e_html_editor_web_extension_get_html_mode (extension);
+ e_html_editor_web_extension_set_content_changed (extension);
- if (extension->priv->magic_smileys && html_mode)
- html_editor_view_check_magic_smileys (view, range);
+ if (e_html_editor_web_extension_get_magic_smileys_enabled (extension) && html_mode)
+ dom_check_magic_smileys (document, extension);
if (e_html_editor_web_extension_get_return_key_pressed (extension) ||
e_html_editor_web_extension_get_space_key_pressed (extension)) {
- html_editor_view_check_magic_links (view, range, FALSE);
- mark_node_as_paragraph_after_ending_list (document);
+ dom_check_magic_links (document, extension, FALSE);
+ mark_node_as_paragraph_after_ending_list (document, extension);
if (html_mode)
fix_paragraph_structure_after_pressing_enter_after_smiley (document);
} else {
@@ -1218,10 +1634,10 @@ body_input_event_cb (WebKitDOMElement *element,
node = webkit_dom_range_get_end_container (range, NULL);
- if (surround_text_with_paragraph_if_needed (document, node)) {
+ if (surround_text_with_paragraph_if_needed (document, extension, node)) {
dom_restore_caret_position (document);
node = webkit_dom_range_get_end_container (range, NULL);
- range = dom_get_range (document);
+ range = dom_get_current_range (document);
}
if (WEBKIT_DOM_IS_TEXT (node)) {
@@ -1235,7 +1651,7 @@ body_input_event_cb (WebKitDOMElement *element,
prev_sibling = webkit_dom_node_get_previous_sibling (node);
if (WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (prev_sibling))
- html_editor_view_check_magic_links (view, range, FALSE);
+ dom_check_magic_links (document, extension, FALSE);
}
g_free (text);
}
@@ -1294,7 +1710,7 @@ body_input_event_cb (WebKitDOMElement *element,
element_add_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-paragraph");
else
dom_set_paragraph_style (
- selection, WEBKIT_DOM_ELEMENT (parent), -1, 0, "");
+ document, extension, WEBKIT_DOM_ELEMENT (parent), -1, 0, "");
}
/* When new smiley is added we have to use UNICODE_HIDDEN_SPACE to set the
@@ -1306,7 +1722,7 @@ body_input_event_cb (WebKitDOMElement *element,
element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-smiley-wrapper")) {
webkit_dom_node_insert_before (
webkit_dom_node_get_parent_node (parent),
- dom_crate_caret_position_node (document),
+ dom_create_caret_position_node (document),
webkit_dom_node_get_next_sibling (parent),
NULL);
webkit_dom_node_insert_before (
@@ -1325,7 +1741,7 @@ body_input_event_cb (WebKitDOMElement *element,
WebKitDOMNode *node, *parent;
WebKitDOMRange *range;
- range = dom_get_range (document);
+ range = dom_get_current_range (document);
node = webkit_dom_range_get_end_container (range, NULL);
citation_level = get_citation_level (node, FALSE);
@@ -1372,7 +1788,8 @@ body_input_event_cb (WebKitDOMElement *element,
WebKitDOMElement *block;
gboolean remove_quoting = FALSE;
- word_wrap_length = extension->priv->word_wrap_length;
+ word_wrap_length =
+ e_html_editor_web_extension_get_word_wrap_length (extension);
length = word_wrap_length - 2 * citation_level;
block = WEBKIT_DOM_ELEMENT (parent);
@@ -1394,9 +1811,9 @@ body_input_event_cb (WebKitDOMElement *element,
/* Wrap and quote the line */
if (!remove_quoting && text_length >= word_wrap_length) {
- remove_quoting_from_element (block);
+ dom_remove_quoting_from_element (block);
- block = dom_wrap_paragraph_length (document, block, length);
+ block = dom_wrap_paragraph_length (document, extension, block, length);
webkit_dom_node_normalize (WEBKIT_DOM_NODE (block));
quote_plain_text_element_after_wrapping (
document, WEBKIT_DOM_ELEMENT (block), citation_level);
@@ -1410,7 +1827,7 @@ body_input_event_cb (WebKitDOMElement *element,
NULL);
dom_selection_restore (document);
- dom_force_spell_check_for_current_paragraph (document);
+ dom_force_spell_check_for_current_paragraph (document, extension);
return;
}
}
@@ -1419,10 +1836,10 @@ body_input_event_cb (WebKitDOMElement *element,
}
static void
-remove_input_event_listener_from_body (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document)
+remove_input_event_listener_from_body (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
- if (!extension->priv->body_input_event_removed) {
+ if (!e_html_editor_web_extension_get_body_input_event_removed (extension)) {
webkit_dom_event_target_remove_event_listener (
WEBKIT_DOM_EVENT_TARGET (
webkit_dom_document_get_body (document)),
@@ -1430,15 +1847,15 @@ remove_input_event_listener_from_body (EHTMLEditorWebExtension *extension,
G_CALLBACK (body_input_event_cb),
FALSE);
- extension->priv->body_input_event_removed = TRUE;
+ e_html_editor_web_extension_set_body_input_event_removed (extension, TRUE);
}
}
static void
-register_input_event_listener_on_body (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document)
+register_input_event_listener_on_body (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
- if (extension->priv->body_input_event_removed) {
+ if (e_html_editor_web_extension_get_body_input_event_removed (extension)) {
webkit_dom_event_target_add_event_listener (
WEBKIT_DOM_EVENT_TARGET (
webkit_dom_document_get_body (document)),
@@ -1447,385 +1864,146 @@ register_input_event_listener_on_body (EHTMLEditorWebExtension *extension,
FALSE,
extension);
- extension->priv->body_input_event_removed = FALSE;
+ e_html_editor_web_extension_set_body_input_event_removed (extension, FALSE);
}
}
static void
-fix_structure_after_pasting_multiline_content (WebKitDOMNode *node)
+body_keyup_event_cb (WebKitDOMElement *element,
+ WebKitDOMUIEvent *event,
+ EHTMLEditorWebExtension *extension)
{
- WebKitDOMNode *first_child, *parent;
+ glong key_code;
+ WebKitDOMDocument *document;
- /* When pasting content that does not contain just the
- * one line text WebKit inserts all the content after the
- * first line into one element. So we have to take it out
- * of this element and insert it after that element. */
- parent = webkit_dom_node_get_parent_node (node);
- if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (parent))
+ document = webkit_dom_node_get_owner_document (WEBKIT_DOM_NODE (element));
+ register_input_event_listener_on_body (document, extension);
+ if (!dom_selection_is_collapsed (document))
return;
- first_child = webkit_dom_node_get_first_child (parent);
- while (first_child) {
- WebKitDOMNode *next_child =
- webkit_dom_node_get_next_sibling (first_child);
- if (webkit_dom_node_has_child_nodes (first_child))
- webkit_dom_node_insert_before (
- webkit_dom_node_get_parent_node (parent),
- first_child,
- parent,
- NULL);
- first_child = next_child;
- }
- remove_node (parent);
-}
-
-static void
-dom_convert_and_insert_html_into_selection (WebKitDOMDocument *document,
- EHTMLEditorWebExtension *extension,
- const gchar *html,
- gboolean is_html)
-{
- gboolean has_selection;
- gchar *inner_html;
- gint citation_level;
- WebKitDOMElement *selection_start_marker, *selection_end_marker, *element;
- WebKitDOMNode *node, *current_block;
-
- remove_input_event_listener_from_body (document);
- e_html_editor_selection_save (selection);
- selection_start_marker = webkit_dom_document_get_element_by_id (
- document, "-x-evo-selection-start-marker");
- selection_end_marker = webkit_dom_document_get_element_by_id (
- document, "-x-evo-selection-end-marker");
- current_block = get_parent_block_node_from_child (
- WEBKIT_DOM_NODE (selection_start_marker));
-
- element = webkit_dom_document_create_element (document, "div", NULL);
- if (is_html) {
- gchar *inner_text;
-
- webkit_dom_html_element_set_inner_html (
- WEBKIT_DOM_HTML_ELEMENT (element), html, NULL);
- inner_text = webkit_dom_html_element_get_inner_text (
- WEBKIT_DOM_HTML_ELEMENT (element));
- webkit_dom_html_element_set_inner_text (
- WEBKIT_DOM_HTML_ELEMENT (element), inner_text, NULL);
-
- g_free (inner_text);
- } else
- webkit_dom_html_element_set_inner_text (
- WEBKIT_DOM_HTML_ELEMENT (element), html, NULL);
-
- inner_html = webkit_dom_html_element_get_inner_html (
- WEBKIT_DOM_HTML_ELEMENT (element));
- parse_html_into_paragraphs (document, element, current_block, inner_html);
-
- g_free (inner_html);
-
- has_selection = !dom_selection_is_collapsed (document);
-
- citation_level = get_citation_level (WEBKIT_DOM_NODE (selection_end_marker), FALSE);
- /* Pasting into the citation */
- if (citation_level > 0) {
- gint length;
- gint word_wrap_length = extension->priv->word_wrap_length;
- WebKitDOMElement *br;
- WebKitDOMNode *first_paragraph, *last_paragraph;
- WebKitDOMNode *child, *parent;
-
- first_paragraph = webkit_dom_node_get_first_child (
- WEBKIT_DOM_NODE (element));
- last_paragraph = webkit_dom_node_get_last_child (
- WEBKIT_DOM_NODE (element));
-
- length = word_wrap_length - 2 * citation_level;
-
- /* Pasting text that was parsed just into one paragraph */
- if (webkit_dom_node_is_same_node (first_paragraph, last_paragraph)) {
- WebKitDOMNode *child, *parent;
-
- parent = get_parent_block_node_from_child (
- WEBKIT_DOM_NODE (selection_start_marker));
-
- remove_quoting_from_element (WEBKIT_DOM_ELEMENT (parent));
- remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (parent));
-
- while ((child = webkit_dom_node_get_first_child (first_paragraph)))
- webkit_dom_node_insert_before (
- parent,
- child,
- WEBKIT_DOM_NODE (selection_start_marker),
- NULL);
+ key_code = webkit_dom_ui_event_get_key_code (event);
+ if (key_code == HTML_KEY_CODE_BACKSPACE || key_code == HTML_KEY_CODE_DELETE) {
+ /* This will fix the structure after the situations where some text
+ * inside the quoted content is selected and afterwards deleted with
+ * BackSpace or Delete. */
+ gint level;
+ WebKitDOMElement *selection_start_marker, *selection_end_marker;
+ WebKitDOMElement *br_element;
+ WebKitDOMNode *node, *parent;
- parent = WEBKIT_DOM_NODE (
- dom_wrap_paragraph_length (
- document, WEBKIT_DOM_ELEMENT (parent), length));
- webkit_dom_node_normalize (parent);
- quote_plain_text_element_after_wrapping (
- document, WEBKIT_DOM_ELEMENT (parent), citation_level);
+ dom_selection_save (document);
+ selection_start_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-start-marker");
+ selection_end_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-end-marker");
- goto delete;
- }
+ level = get_citation_level (
+ WEBKIT_DOM_NODE (selection_start_marker), FALSE);
+ if (level == 0)
+ goto restore;
- /* Pasting content parsed into the multiple paragraphs */
- parent = get_parent_block_node_from_child (
+ node = webkit_dom_node_get_previous_sibling (
WEBKIT_DOM_NODE (selection_start_marker));
- remove_quoting_from_element (WEBKIT_DOM_ELEMENT (parent));
- remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (parent));
-
- /* Move the elements from the first paragraph before the selection start element */
- while ((child = webkit_dom_node_get_first_child (first_paragraph)))
- webkit_dom_node_insert_before (
- parent,
- child,
- WEBKIT_DOM_NODE (selection_start_marker),
- NULL);
-
- remove_node (first_paragraph);
+ if (WEBKIT_DOM_IS_HTML_BR_ELEMENT (node))
+ node = webkit_dom_node_get_previous_sibling (node);
- /* If the BR element is on the last position, remove it as we don't need it */
- child = webkit_dom_node_get_last_child (parent);
- if (WEBKIT_DOM_IS_HTML_BR_ELEMENT (child))
- remove_node (child);
-
- parent = get_parent_block_node_from_child (
- WEBKIT_DOM_NODE (selection_end_marker)),
-
- child = webkit_dom_node_get_next_sibling (
- WEBKIT_DOM_NODE (selection_end_marker));
- /* Move the elements that are in the same paragraph as the selection end
- * on the end of pasted text, but avoid BR on the end of paragraph */
- while (child) {
- WebKitDOMNode *next_child =
- webkit_dom_node_get_next_sibling (child);
- if (!(!next_child && WEBKIT_DOM_IS_HTML_BR_ELEMENT (child)))
- webkit_dom_node_append_child (last_paragraph, child, NULL);
- child = next_child;
- }
-
- /* Caret will be restored on the end of pasted text */
- webkit_dom_node_append_child (
- last_paragraph,
- dom_create_caret_position_node (document),
- NULL);
-
- /* Insert the paragraph with the end of the pasted text after
- * the paragraph that contains the selection end */
- webkit_dom_node_insert_before (
- webkit_dom_node_get_parent_node (parent),
- last_paragraph,
- webkit_dom_node_get_next_sibling (parent),
- NULL);
-
- /* Wrap, quote and move all paragraphs from pasted text into the body */
- while ((child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element)))) {
- child = WEBKIT_DOM_NODE (dom_wrap_paragraph_length (
- document, WEBKIT_DOM_ELEMENT (child), length));
- quote_plain_text_element_after_wrapping (
- document, WEBKIT_DOM_ELEMENT (child), citation_level);
- webkit_dom_node_insert_before (
- webkit_dom_node_get_parent_node (last_paragraph),
- child,
- last_paragraph,
- NULL);
- }
-
- webkit_dom_node_normalize (last_paragraph);
-
- last_paragraph = WEBKIT_DOM_NODE (
- dom_wrap_paragraph_length (
- document, WEBKIT_DOM_ELEMENT (last_paragraph), length));
- quote_plain_text_element_after_wrapping (
- document, WEBKIT_DOM_ELEMENT (last_paragraph), citation_level);
-
- remove_quoting_from_element (WEBKIT_DOM_ELEMENT (parent));
- remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (parent));
+ if (node)
+ goto restore;
parent = get_parent_block_node_from_child (
WEBKIT_DOM_NODE (selection_start_marker));
- parent = WEBKIT_DOM_NODE (dom_wrap_paragraph_length (
- document, WEBKIT_DOM_ELEMENT (parent), length));
- quote_plain_text_element_after_wrapping (
- document, WEBKIT_DOM_ELEMENT (parent), citation_level);
-
- /* If the pasted text begun or ended with a new line we have to
- * quote these paragraphs as well */
- br = webkit_dom_element_query_selector (
- WEBKIT_DOM_ELEMENT (last_paragraph), "br.-x-evo-last-br", NULL);
- if (br) {
- WebKitDOMNode *parent;
- parent = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (br));
- quote_plain_text_recursive (document, parent, parent, citation_level);
- webkit_dom_element_remove_attribute (br, "class");
- }
-
- br = webkit_dom_document_query_selector (
- document, "* > br.-x-evo-first-br", NULL);
- if (br) {
- WebKitDOMNode *parent;
-
- parent = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (br));
- quote_plain_text_recursive (document, parent, parent, citation_level);
- webkit_dom_element_remove_attribute (br, "class");
- }
- delete:
- dom_selection_restore (document);
- /* Remove the text that was meant to be replaced by the pasted text */
- if (has_selection)
- dom_exec_command (
- document, E_HTML_EDITOR_VIEW_COMMAND_DELETE, NULL);
-
- dom_restore_caret_position (document);
- g_object_unref (element);
- goto out;
- }
-
- remove_node (WEBKIT_DOM_NODE (selection_start_marker));
- remove_node (WEBKIT_DOM_NODE (selection_end_marker));
-
- inner_html = webkit_dom_html_element_get_inner_html (
- WEBKIT_DOM_HTML_ELEMENT (element));
- dom_exec_command (
- document, E_HTML_EDITOR_VIEW_COMMAND_INSERT_HTML, inner_html);
- g_free (inner_html);
-
- g_object_unref (element);
- dom_selection_save (document);
-
- element = webkit_dom_document_query_selector (
- document, "* > br.-x-evo-first-br", NULL);
- if (element) {
- WebKitDOMNode *next_sibling;
- WebKitDOMNode *parent;
-
- parent = webkit_dom_node_get_parent_node (
- WEBKIT_DOM_NODE (element));
-
- next_sibling = webkit_dom_node_get_next_sibling (parent);
- if (next_sibling)
- remove_node (WEBKIT_DOM_NODE (parent));
- else
- webkit_dom_element_remove_attribute (element, "class");
- }
-
- element = webkit_dom_document_query_selector (
- document, "* > br.-x-evo-last-br", NULL);
- if (element) {
- WebKitDOMNode *parent;
- WebKitDOMNode *child;
-
- parent = webkit_dom_node_get_parent_node (
- WEBKIT_DOM_NODE (element));
-
- node = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (parent));
- if (node) {
- node = webkit_dom_node_get_first_child (node);
- if (node) {
- inner_html = webkit_dom_node_get_text_content (node);
- if (g_str_has_prefix (inner_html, UNICODE_NBSP))
- webkit_dom_character_data_replace_data (
- WEBKIT_DOM_CHARACTER_DATA (node), 0, 1, "", NULL);
- g_free (inner_html);
- }
+ node = webkit_dom_node_get_previous_sibling (parent);
+ if (!node) {
+ /* Situation where the start of the selection was in the
+ * multiple quoted content and that start on the beginning
+ * of the citation.
+ *
+ * >
+ * >> |
+ * >> xx|x
+ * */
+ node = webkit_dom_node_get_parent_node (parent);
+ if (!WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (node))
+ goto restore;
+ node = webkit_dom_node_get_previous_sibling (node);
+ if (!node)
+ goto restore;
+ if (!WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (webkit_dom_node_get_parent_node (node)))
+ goto restore;
}
- selection_end_marker = webkit_dom_document_get_element_by_id (
- document, "-x-evo-selection-end-marker");
-
- if (has_selection) {
- /* Everything after the selection end marker have to be in separate
- * paragraph */
- child = webkit_dom_node_get_next_sibling (
- WEBKIT_DOM_NODE (selection_end_marker));
- /* Move the elements that are in the same paragraph as the selection end
- * on the end of pasted text, but avoid BR on the end of paragraph */
- while (child) {
- WebKitDOMNode *next_child =
- webkit_dom_node_get_next_sibling (child);
- if (!(!next_child && WEBKIT_DOM_IS_HTML_BR_ELEMENT (child)))
- webkit_dom_node_append_child (parent, child, NULL);
- child = next_child;
+ br_element = webkit_dom_element_query_selector (
+ WEBKIT_DOM_ELEMENT (node), "span.-x-evo-quote-character > br", NULL);
+ if (br_element) {
+ WebKitDOMNode *tmp;
+
+ if (WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (node)) {
+ /* We have to select the right block when the selection
+ * started on the end of the citation that is
+ * inside another citation.
+ *
+ * >>|
+ * > xx|x
+ */
+ /* <span class="-x-evo-quote-character"> */
+ node = webkit_dom_node_get_parent_node (
+ WEBKIT_DOM_NODE (br_element));
+ /* <span class="-x-evo-quoted"> */
+ node = webkit_dom_node_get_parent_node (node);
+ /* right block */
+ node = webkit_dom_node_get_parent_node (node);
}
- remove_node (WEBKIT_DOM_NODE (element));
+ webkit_dom_node_append_child (
+ node, WEBKIT_DOM_NODE (selection_start_marker), NULL);
- webkit_dom_node_insert_before (
- webkit_dom_node_get_parent_node (
- webkit_dom_node_get_parent_node (
- WEBKIT_DOM_NODE (selection_end_marker))),
- parent,
- webkit_dom_node_get_next_sibling (
- webkit_dom_node_get_parent_node (
- WEBKIT_DOM_NODE (selection_end_marker))),
- NULL);
- node = parent;
- } else {
- node = webkit_dom_node_get_next_sibling (parent);
- if (!node)
- fix_structure_after_pasting_multiline_content (parent);
- }
+ while ((tmp = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE
(selection_end_marker))))
+ webkit_dom_node_append_child (node, tmp, NULL);
- if (node) {
- /* Restore caret on the end of pasted text */
webkit_dom_node_insert_before (
node,
WEBKIT_DOM_NODE (selection_end_marker),
- webkit_dom_node_get_first_child (node),
- NULL);
-
- selection_start_marker = webkit_dom_document_get_element_by_id (
- document, "-x-evo-selection-start-marker");
- webkit_dom_node_insert_before (
- node,
- WEBKIT_DOM_NODE (selection_start_marker),
- webkit_dom_node_get_first_child (node),
+ webkit_dom_node_get_next_sibling (
+ WEBKIT_DOM_NODE (selection_start_marker)),
NULL);
- }
-
- if (element)
- webkit_dom_element_remove_attribute (element, "class");
- if (webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (parent)) && !has_selection)
+ webkit_dom_node_append_child (
+ node, WEBKIT_DOM_NODE (br_element), NULL);
remove_node (parent);
- } else {
- /* When pasting the content that was copied from the composer, WebKit
- * restores the selection wrongly, thus is saved wrongly and we have
- * to fix it */
- WebKitDOMNode *paragraph, *parent, *clone1, *clone2;
-
- selection_start_marker = webkit_dom_document_get_element_by_id (
- document, "-x-evo-selection-start-marker");
- selection_end_marker = webkit_dom_document_get_element_by_id (
- document, "-x-evo-selection-end-marker");
-
- paragraph = get_parent_block_node_from_child (
- WEBKIT_DOM_NODE (selection_start_marker));
- parent = webkit_dom_node_get_parent_node (paragraph);
- webkit_dom_element_remove_attribute (WEBKIT_DOM_ELEMENT (parent), "id");
+ }
+ restore:
+ dom_selection_restore (document);
+ } else if (key_code == HTML_KEY_CODE_CONTROL)
+ dom_set_links_active (document, FALSE);
+}
- /* Check if WebKit created wrong structure */
- clone1 = webkit_dom_node_clone_node (WEBKIT_DOM_NODE (paragraph), FALSE);
- clone2 = webkit_dom_node_clone_node (WEBKIT_DOM_NODE (parent), FALSE);
- if (webkit_dom_node_is_equal_node (clone1, clone2))
- fix_structure_after_pasting_multiline_content (paragraph);
+static void
+fix_structure_after_pasting_multiline_content (WebKitDOMNode *node)
+{
+ WebKitDOMNode *first_child, *parent;
- webkit_dom_node_insert_before (
- webkit_dom_node_get_parent_node (
- WEBKIT_DOM_NODE (selection_start_marker)),
- WEBKIT_DOM_NODE (selection_end_marker),
- webkit_dom_node_get_next_sibling (
- WEBKIT_DOM_NODE (selection_start_marker)),
- NULL);
+ /* When pasting content that does not contain just the
+ * one line text WebKit inserts all the content after the
+ * first line into one element. So we have to take it out
+ * of this element and insert it after that element. */
+ parent = webkit_dom_node_get_parent_node (node);
+ if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (parent))
+ return;
+ first_child = webkit_dom_node_get_first_child (parent);
+ while (first_child) {
+ WebKitDOMNode *next_child =
+ webkit_dom_node_get_next_sibling (first_child);
+ if (webkit_dom_node_has_child_nodes (first_child))
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (parent),
+ first_child,
+ parent,
+ NULL);
+ first_child = next_child;
}
-
- dom_selection_restore (document);
- out:
- dom_force_spell_check (document);
- dom_scroll_to_caret (document);
-
- register_input_event_listener_on_body (document);
+ remove_node (parent);
}
void
@@ -1866,10 +2044,10 @@ dom_quote_and_insert_text_into_selection (EHTMLEditorWebExtension *extension,
webkit_dom_node_append_child (
WEBKIT_DOM_NODE (blockquote), WEBKIT_DOM_NODE (element), NULL);
- if (!is_in_html_mode (extension))
+ if (!e_html_editor_web_extension_get_html_mode (extension))
dom_quote_plain_text_element (document, element);
- range = dom_get_range (document);
+ range = dom_get_current_range (document);
node = webkit_dom_range_get_end_container (range, NULL);
webkit_dom_node_append_child (
@@ -1879,20 +2057,20 @@ dom_quote_and_insert_text_into_selection (EHTMLEditorWebExtension *extension,
dom_restore_caret_position (document);
- dom_force_spell_check_for_current_paragraph (document);
+ dom_force_spell_check_for_current_paragraph (document, extension);
g_free (escaped_text);
}
gboolean
-dom_change_quoted_block_to_normal (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document)
+dom_change_quoted_block_to_normal (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
gboolean html_mode;
gint citation_level, success = FALSE;
WebKitDOMElement *selection_start_marker, *selection_end_marker, *block;
- html_mode = is_in_html_mode (extension);
+ html_mode = e_html_editor_web_extension_get_html_mode (extension);
selection_start_marker = webkit_dom_document_query_selector (
document, "span#-x-evo-selection-start-marker", NULL);
@@ -1946,7 +2124,7 @@ dom_change_quoted_block_to_normal (EHTMLEditorWebExtension *extension,
webkit_dom_element_set_id (
WEBKIT_DOM_ELEMENT (block), "-x-evo-to-remove");
- paragraph = insert_new_line_into_citation (document, inner_html);
+ paragraph = insert_new_line_into_citation (document, extension, inner_html);
g_free (inner_html);
if (paragraph) {
@@ -1966,8 +2144,8 @@ dom_change_quoted_block_to_normal (EHTMLEditorWebExtension *extension,
}
- remove_quoting_from_element (paragraph);
- remove_wrapping_from_element (paragraph);
+ dom_remove_quoting_from_element (paragraph);
+ dom_remove_wrapping_from_element (paragraph);
}
if (block)
@@ -1987,7 +2165,7 @@ dom_change_quoted_block_to_normal (EHTMLEditorWebExtension *extension,
gint length, word_wrap_length;
WebKitDOMNode *parent;
- word_wrap_length = extension->priv->word_wrap_length;
+ word_wrap_length = e_html_editor_web_extension_get_word_wrap_length (extension);
length = word_wrap_length - 2 * (citation_level - 1);
if (html_mode) {
@@ -2006,10 +2184,10 @@ dom_change_quoted_block_to_normal (EHTMLEditorWebExtension *extension,
}
- remove_quoting_from_element (block);
- remove_wrapping_from_element (block);
+ dom_remove_quoting_from_element (block);
+ dom_remove_wrapping_from_element (block);
- block = dom_wrap_paragraph_length (document, block, length);
+ block = dom_wrap_paragraph_length (document, extension, block, length);
webkit_dom_node_normalize (WEBKIT_DOM_NODE (block));
quote_plain_text_element_after_wrapping (document, block, citation_level - 1);
@@ -2725,7 +2903,7 @@ dom_dequote_plain_text (WebKitDOMDocument *document)
if (is_citation_node (WEBKIT_DOM_NODE (element))) {
element_remove_class (element, "-x-evo-plaintext-quoted");
- remove_quoting_from_element (element);
+ dom_remove_quoting_from_element (element);
}
}
g_object_unref (paragraphs);
@@ -2847,6 +3025,7 @@ append_new_paragraph (WebKitDOMElement *parent,
static WebKitDOMElement *
create_and_append_new_paragraph (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
WebKitDOMElement *parent,
WebKitDOMNode *block,
const gchar *content)
@@ -2854,7 +3033,7 @@ create_and_append_new_paragraph (WebKitDOMDocument *document,
WebKitDOMElement *paragraph;
if (!block || WEBKIT_DOM_IS_HTML_DIV_ELEMENT (block))
- paragraph = dom_get_paragraph_element (document, -1, 0);
+ paragraph = dom_get_paragraph_element (document, extension, -1, 0);
else
paragraph = WEBKIT_DOM_ELEMENT (webkit_dom_node_clone_node (block, FALSE));
@@ -2939,6 +3118,7 @@ check_if_end_paragraph (const gchar *input,
* setting it to another one and finally getting innerHTML from it */
static void
parse_html_into_paragraphs (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
WebKitDOMElement *blockquote,
WebKitDOMNode *block,
const gchar *html)
@@ -2948,7 +3128,7 @@ parse_html_into_paragraphs (WebKitDOMDocument *document,
gboolean citation_was_first_element = FALSE;
const gchar *prev_br, *next_br;
gchar *inner_html;
- GRegex *regex_nbsp = NULL, *regex_links = NULL, *regex_email = NULL;
+ GRegex *regex_nbsp = NULL, *regex_link = NULL, *regex_email = NULL;
GString *start, *end;
WebKitDOMElement *paragraph = NULL;
@@ -3056,14 +3236,14 @@ parse_html_into_paragraphs (WebKitDOMDocument *document,
if (g_strcmp0 (rest_to_insert, UNICODE_ZERO_WIDTH_SPACE) == 0) {
paragraph = create_and_append_new_paragraph (
- document, blockquote, block, "<br>");
+ document, extension, blockquote, block, "<br>");
} else if (prevent_block) {
gchar *html;
gchar *new_content;
if (!paragraph) {
if (!block || WEBKIT_DOM_IS_HTML_DIV_ELEMENT (block))
- paragraph =dom_get_paragraph_element (document, -1, 0);
+ paragraph = dom_get_paragraph_element (document, extension,
-1, 0);
else
paragraph = WEBKIT_DOM_ELEMENT (webkit_dom_node_clone_node
(block, FALSE));
}
@@ -3086,7 +3266,7 @@ parse_html_into_paragraphs (WebKitDOMDocument *document,
g_free (new_content);
} else
paragraph = create_and_append_new_paragraph (
- document, blockquote, block, rest_to_insert);
+ document, extension, blockquote, block, rest_to_insert);
if (rest_to_insert && *rest_to_insert && prevent_block && paragraph) {
glong length = 0;
@@ -3115,12 +3295,13 @@ parse_html_into_paragraphs (WebKitDOMDocument *document,
append_new_paragraph (blockquote, ¶graph);
paragraph = create_and_append_new_paragraph (
- document, blockquote, block, "<br>");
+ document, extension, blockquote, block, "<br>");
citation_was_first_element = FALSE;
} else if (first_element && !citation_was_first_element) {
paragraph = create_and_append_new_paragraph (
document,
+ extension,
blockquote,
block,
"<br class=\"-x-evo-first-br\">");
@@ -3205,10 +3386,10 @@ parse_html_into_paragraphs (WebKitDOMDocument *document,
if (g_strcmp0 (rest_to_insert, UNICODE_ZERO_WIDTH_SPACE) == 0)
create_and_append_new_paragraph (
- document, blockquote, block, "<br>");
+ document, extension, blockquote, block, "<br>");
else
create_and_append_new_paragraph (
- document, blockquote, block, rest_to_insert);
+ document, extension, blockquote, block, rest_to_insert);
g_free (rest_to_insert);
}
@@ -3351,7 +3532,7 @@ clear_attributes (WebKitDOMDocument *document)
name = webkit_dom_node_get_local_name (node);
- if (!g_str_has_prefix (name, "data-"))
+ if (!g_str_has_prefix (name, "data-") && (g_strcmp0 (name, "spellcheck") != 0))
webkit_dom_element_remove_attribute_node (
WEBKIT_DOM_ELEMENT (body),
WEBKIT_DOM_ATTR (node),
@@ -3363,9 +3544,35 @@ clear_attributes (WebKitDOMDocument *document)
}
static void
-html_editor_convert_view_content (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document,
- const gchar *preferred_text)
+register_html_events_handlers (WebKitDOMHTMLElement *body,
+ EHTMLEditorWebExtension *extension)
+{
+ webkit_dom_event_target_add_event_listener (
+ WEBKIT_DOM_EVENT_TARGET (body),
+ "keydown",
+ G_CALLBACK (body_keydown_event_cb),
+ FALSE,
+ extension);
+
+ webkit_dom_event_target_add_event_listener (
+ WEBKIT_DOM_EVENT_TARGET (body),
+ "keypress",
+ G_CALLBACK (body_keypress_event_cb),
+ FALSE,
+ extension);
+
+ webkit_dom_event_target_add_event_listener (
+ WEBKIT_DOM_EVENT_TARGET (body),
+ "keyup",
+ G_CALLBACK (body_keyup_event_cb),
+ FALSE,
+ extension);
+}
+
+void
+dom_convert_document (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
+ const gchar *preferred_text)
{
gboolean start_bottom, empty = FALSE;
gchar *inner_html;
@@ -3411,7 +3618,7 @@ html_editor_convert_view_content (EHTMLEditorWebExtension *extension,
g_object_unref (list);
/* Insert the paragraph where the caret will be. */
- paragraph = prepare_paragraph (document, TRUE);
+ paragraph = prepare_paragraph (document, extension, TRUE);
webkit_dom_element_set_id (paragraph, "-x-evo-input-start");
webkit_dom_node_insert_before (
WEBKIT_DOM_NODE (wrapper),
@@ -3440,7 +3647,7 @@ html_editor_convert_view_content (EHTMLEditorWebExtension *extension,
webkit_dom_node_insert_before (
WEBKIT_DOM_NODE (wrapper),
WEBKIT_DOM_NODE (prepare_paragraph (
- selection, document, FALSE)),
+ document, extension, FALSE)),
webkit_dom_node_get_next_sibling (
WEBKIT_DOM_NODE (signature)),
NULL);
@@ -3548,7 +3755,7 @@ html_editor_convert_view_content (EHTMLEditorWebExtension *extension,
empty = FALSE;
if (!empty)
- parse_html_into_paragraphs (document, content_wrapper, NULL, inner_html);
+ parse_html_into_paragraphs (document, extension, content_wrapper, NULL, inner_html);
if (!cite_body) {
if (!empty) {
@@ -3584,16 +3791,16 @@ html_editor_convert_view_content (EHTMLEditorWebExtension *extension,
if (paragraph)
webkit_dom_element_remove_attribute (paragraph, "class");
- if (!is_in_html_mode (extension)) {
- dom_wrap_paragraphs_in_document (document);
+ if (!e_html_editor_web_extension_get_html_mode (extension)) {
+ dom_wrap_paragraphs_in_document (document, extension);
quote_plain_text_elements_after_wrapping_in_document (document);
}
clear_attributes (document);
- dom_selection_restore (selection);
- dom_force_spell_check (document);
+ dom_selection_restore (document);
+ dom_force_spell_check (document, extension);
/* Register on input event that is called when the content (body) is modified */
webkit_dom_event_target_add_event_listener (
@@ -3601,19 +3808,364 @@ html_editor_convert_view_content (EHTMLEditorWebExtension *extension,
"input",
G_CALLBACK (body_input_event_cb),
FALSE,
- document);
-
- webkit_dom_event_target_add_event_listener (
- WEBKIT_DOM_EVENT_TARGET (body),
- "keypress",
- G_CALLBACK (body_keypress_event_cb),
- FALSE,
extension);
+ register_html_events_handlers (body, extension);
g_free (inner_html);
}
+void
+dom_convert_and_insert_html_into_selection (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
+ const gchar *html,
+ gboolean is_html)
+{
+ gboolean has_selection;
+ gchar *inner_html;
+ gint citation_level;
+ WebKitDOMElement *selection_start_marker, *selection_end_marker, *element;
+ WebKitDOMNode *node, *current_block;
+
+ remove_input_event_listener_from_body (document, extension);
+
+ dom_selection_save (document);
+ selection_start_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-start-marker");
+ selection_end_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-end-marker");
+ current_block = get_parent_block_node_from_child (
+ WEBKIT_DOM_NODE (selection_start_marker));
+
+ element = webkit_dom_document_create_element (document, "div", NULL);
+ if (is_html) {
+ gchar *inner_text;
+
+ webkit_dom_html_element_set_inner_html (
+ WEBKIT_DOM_HTML_ELEMENT (element), html, NULL);
+ inner_text = webkit_dom_html_element_get_inner_text (
+ WEBKIT_DOM_HTML_ELEMENT (element));
+ webkit_dom_html_element_set_inner_text (
+ WEBKIT_DOM_HTML_ELEMENT (element), inner_text, NULL);
+
+ g_free (inner_text);
+ } else
+ webkit_dom_html_element_set_inner_text (
+ WEBKIT_DOM_HTML_ELEMENT (element), html, NULL);
+
+ inner_html = webkit_dom_html_element_get_inner_html (
+ WEBKIT_DOM_HTML_ELEMENT (element));
+ parse_html_into_paragraphs (document, extension, element, current_block, inner_html);
+
+ g_free (inner_html);
+
+ has_selection = !dom_selection_is_collapsed (document);
+
+ citation_level = get_citation_level (WEBKIT_DOM_NODE (selection_end_marker), FALSE);
+ /* Pasting into the citation */
+ if (citation_level > 0) {
+ gint length;
+ gint word_wrap_length;
+ WebKitDOMElement *br;
+ WebKitDOMNode *first_paragraph, *last_paragraph;
+ WebKitDOMNode *child, *parent;
+
+ first_paragraph = webkit_dom_node_get_first_child (
+ WEBKIT_DOM_NODE (element));
+ last_paragraph = webkit_dom_node_get_last_child (
+ WEBKIT_DOM_NODE (element));
+
+ word_wrap_length = e_html_editor_web_extension_get_word_wrap_length (extension);
+ length = word_wrap_length - 2 * citation_level;
+
+ /* Pasting text that was parsed just into one paragraph */
+ if (webkit_dom_node_is_same_node (first_paragraph, last_paragraph)) {
+ WebKitDOMNode *child, *parent;
+
+ parent = get_parent_block_node_from_child (
+ WEBKIT_DOM_NODE (selection_start_marker));
+
+ dom_remove_quoting_from_element (WEBKIT_DOM_ELEMENT (parent));
+ dom_remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (parent));
+
+ while ((child = webkit_dom_node_get_first_child (first_paragraph)))
+ webkit_dom_node_insert_before (
+ parent,
+ child,
+ WEBKIT_DOM_NODE (selection_start_marker),
+ NULL);
+
+ parent = WEBKIT_DOM_NODE (
+ dom_wrap_paragraph_length (
+ document, extension, WEBKIT_DOM_ELEMENT (parent), length));
+ webkit_dom_node_normalize (parent);
+ quote_plain_text_element_after_wrapping (
+ document, WEBKIT_DOM_ELEMENT (parent), citation_level);
+
+ goto delete;
+ }
+
+ /* Pasting content parsed into the multiple paragraphs */
+ parent = get_parent_block_node_from_child (
+ WEBKIT_DOM_NODE (selection_start_marker));
+
+ dom_remove_quoting_from_element (WEBKIT_DOM_ELEMENT (parent));
+ dom_remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (parent));
+
+ /* Move the elements from the first paragraph before the selection start element */
+ while ((child = webkit_dom_node_get_first_child (first_paragraph)))
+ webkit_dom_node_insert_before (
+ parent,
+ child,
+ WEBKIT_DOM_NODE (selection_start_marker),
+ NULL);
+
+ remove_node (first_paragraph);
+
+ /* If the BR element is on the last position, remove it as we don't need it */
+ child = webkit_dom_node_get_last_child (parent);
+ if (WEBKIT_DOM_IS_HTML_BR_ELEMENT (child))
+ remove_node (child);
+
+ parent = get_parent_block_node_from_child (
+ WEBKIT_DOM_NODE (selection_end_marker)),
+
+ child = webkit_dom_node_get_next_sibling (
+ WEBKIT_DOM_NODE (selection_end_marker));
+ /* Move the elements that are in the same paragraph as the selection end
+ * on the end of pasted text, but avoid BR on the end of paragraph */
+ while (child) {
+ WebKitDOMNode *next_child =
+ webkit_dom_node_get_next_sibling (child);
+ if (!(!next_child && WEBKIT_DOM_IS_HTML_BR_ELEMENT (child)))
+ webkit_dom_node_append_child (last_paragraph, child, NULL);
+ child = next_child;
+ }
+
+ /* Caret will be restored on the end of pasted text */
+ webkit_dom_node_append_child (
+ last_paragraph,
+ dom_create_caret_position_node (document),
+ NULL);
+
+ /* Insert the paragraph with the end of the pasted text after
+ * the paragraph that contains the selection end */
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (parent),
+ last_paragraph,
+ webkit_dom_node_get_next_sibling (parent),
+ NULL);
+
+ /* Wrap, quote and move all paragraphs from pasted text into the body */
+ while ((child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element)))) {
+ child = WEBKIT_DOM_NODE (dom_wrap_paragraph_length (
+ document, extension, WEBKIT_DOM_ELEMENT (child), length));
+ quote_plain_text_element_after_wrapping (
+ document, WEBKIT_DOM_ELEMENT (child), citation_level);
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (last_paragraph),
+ child,
+ last_paragraph,
+ NULL);
+ }
+
+ webkit_dom_node_normalize (last_paragraph);
+
+ last_paragraph = WEBKIT_DOM_NODE (
+ dom_wrap_paragraph_length (
+ document, extension, WEBKIT_DOM_ELEMENT (last_paragraph), length));
+ quote_plain_text_element_after_wrapping (
+ document, WEBKIT_DOM_ELEMENT (last_paragraph), citation_level);
+
+ dom_remove_quoting_from_element (WEBKIT_DOM_ELEMENT (parent));
+ dom_remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (parent));
+
+ parent = get_parent_block_node_from_child (
+ WEBKIT_DOM_NODE (selection_start_marker));
+ parent = WEBKIT_DOM_NODE (dom_wrap_paragraph_length (
+ document, extension, WEBKIT_DOM_ELEMENT (parent), length));
+ quote_plain_text_element_after_wrapping (
+ document, WEBKIT_DOM_ELEMENT (parent), citation_level);
+
+ /* If the pasted text begun or ended with a new line we have to
+ * quote these paragraphs as well */
+ br = webkit_dom_element_query_selector (
+ WEBKIT_DOM_ELEMENT (last_paragraph), "br.-x-evo-last-br", NULL);
+ if (br) {
+ WebKitDOMNode *parent;
+
+ parent = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (br));
+ quote_plain_text_recursive (document, parent, parent, citation_level);
+ webkit_dom_element_remove_attribute (br, "class");
+ }
+
+ br = webkit_dom_document_query_selector (
+ document, "* > br.-x-evo-first-br", NULL);
+ if (br) {
+ WebKitDOMNode *parent;
+
+ parent = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (br));
+ quote_plain_text_recursive (document, parent, parent, citation_level);
+ webkit_dom_element_remove_attribute (br, "class");
+ }
+ delete:
+ dom_selection_restore (document);
+ /* Remove the text that was meant to be replaced by the pasted text */
+ if (has_selection)
+ dom_exec_command (
+ document, E_HTML_EDITOR_VIEW_COMMAND_DELETE, NULL);
+
+ dom_restore_caret_position (document);
+ g_object_unref (element);
+ goto out;
+ }
+
+ remove_node (WEBKIT_DOM_NODE (selection_start_marker));
+ remove_node (WEBKIT_DOM_NODE (selection_end_marker));
+
+ inner_html = webkit_dom_html_element_get_inner_html (
+ WEBKIT_DOM_HTML_ELEMENT (element));
+ dom_exec_command (
+ document, E_HTML_EDITOR_VIEW_COMMAND_INSERT_HTML, inner_html);
+ g_free (inner_html);
+
+ g_object_unref (element);
+ dom_selection_save (document);
+
+ element = webkit_dom_document_query_selector (
+ document, "* > br.-x-evo-first-br", NULL);
+ if (element) {
+ WebKitDOMNode *next_sibling;
+ WebKitDOMNode *parent;
+
+ parent = webkit_dom_node_get_parent_node (
+ WEBKIT_DOM_NODE (element));
+
+ next_sibling = webkit_dom_node_get_next_sibling (parent);
+ if (next_sibling)
+ remove_node (WEBKIT_DOM_NODE (parent));
+ else
+ webkit_dom_element_remove_attribute (element, "class");
+ }
+
+ element = webkit_dom_document_query_selector (
+ document, "* > br.-x-evo-last-br", NULL);
+ if (element) {
+ WebKitDOMNode *parent;
+ WebKitDOMNode *child;
+
+ parent = webkit_dom_node_get_parent_node (
+ WEBKIT_DOM_NODE (element));
+
+ node = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (parent));
+ if (node) {
+ node = webkit_dom_node_get_first_child (node);
+ if (node) {
+ inner_html = webkit_dom_node_get_text_content (node);
+ if (g_str_has_prefix (inner_html, UNICODE_NBSP))
+ webkit_dom_character_data_replace_data (
+ WEBKIT_DOM_CHARACTER_DATA (node), 0, 1, "", NULL);
+ g_free (inner_html);
+ }
+ }
+
+ selection_end_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-end-marker");
+
+ if (has_selection) {
+ /* Everything after the selection end marker have to be in separate
+ * paragraph */
+ child = webkit_dom_node_get_next_sibling (
+ WEBKIT_DOM_NODE (selection_end_marker));
+ /* Move the elements that are in the same paragraph as the selection end
+ * on the end of pasted text, but avoid BR on the end of paragraph */
+ while (child) {
+ WebKitDOMNode *next_child =
+ webkit_dom_node_get_next_sibling (child);
+ if (!(!next_child && WEBKIT_DOM_IS_HTML_BR_ELEMENT (child)))
+ webkit_dom_node_append_child (parent, child, NULL);
+ child = next_child;
+ }
+
+ remove_node (WEBKIT_DOM_NODE (element));
+
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (
+ webkit_dom_node_get_parent_node (
+ WEBKIT_DOM_NODE (selection_end_marker))),
+ parent,
+ webkit_dom_node_get_next_sibling (
+ webkit_dom_node_get_parent_node (
+ WEBKIT_DOM_NODE (selection_end_marker))),
+ NULL);
+ node = parent;
+ } else {
+ node = webkit_dom_node_get_next_sibling (parent);
+ if (!node)
+ fix_structure_after_pasting_multiline_content (parent);
+ }
+
+ if (node) {
+ /* Restore caret on the end of pasted text */
+ webkit_dom_node_insert_before (
+ node,
+ WEBKIT_DOM_NODE (selection_end_marker),
+ webkit_dom_node_get_first_child (node),
+ NULL);
+
+ selection_start_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-start-marker");
+ webkit_dom_node_insert_before (
+ node,
+ WEBKIT_DOM_NODE (selection_start_marker),
+ webkit_dom_node_get_first_child (node),
+ NULL);
+ }
+
+ if (element)
+ webkit_dom_element_remove_attribute (element, "class");
+
+ if (webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (parent)) && !has_selection)
+ remove_node (parent);
+ } else {
+ /* When pasting the content that was copied from the composer, WebKit
+ * restores the selection wrongly, thus is saved wrongly and we have
+ * to fix it */
+ WebKitDOMNode *paragraph, *parent, *clone1, *clone2;
+
+ selection_start_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-start-marker");
+ selection_end_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-end-marker");
+
+ paragraph = get_parent_block_node_from_child (
+ WEBKIT_DOM_NODE (selection_start_marker));
+ parent = webkit_dom_node_get_parent_node (paragraph);
+ webkit_dom_element_remove_attribute (WEBKIT_DOM_ELEMENT (parent), "id");
+
+ /* Check if WebKit created wrong structure */
+ clone1 = webkit_dom_node_clone_node (WEBKIT_DOM_NODE (paragraph), FALSE);
+ clone2 = webkit_dom_node_clone_node (WEBKIT_DOM_NODE (parent), FALSE);
+ if (webkit_dom_node_is_equal_node (clone1, clone2))
+ fix_structure_after_pasting_multiline_content (paragraph);
+
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (
+ WEBKIT_DOM_NODE (selection_start_marker)),
+ WEBKIT_DOM_NODE (selection_end_marker),
+ webkit_dom_node_get_next_sibling (
+ WEBKIT_DOM_NODE (selection_start_marker)),
+ NULL);
+ }
+
+ dom_selection_restore (document);
+ out:
+ dom_force_spell_check (document, extension);
+ dom_scroll_to_caret (document);
+
+ register_input_event_listener_on_body (document, extension);
+}
+
static gint
get_indentation_level (WebKitDOMElement *element)
{
@@ -4191,7 +4743,8 @@ process_elements (EHTMLEditorWebExtension *extension,
gchar *align;
gchar *content_with_align;
gint length;
- gint word_wrap_length = extension->priv->word_wrap_length;
+ gint word_wrap_length =
+ e_html_editor_web_extension_get_word_wrap_length (extension);
if (!g_str_has_prefix (css_align + 13, "left")) {
if (g_str_has_prefix (css_align + 13, "center"))
@@ -4619,15 +5172,15 @@ remove_images (WebKitDOMDocument *document)
}
static void
-toggle_smileys (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document)
+toggle_smileys (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
gboolean html_mode;
gint length;
gint ii;
WebKitDOMNodeList *smileys;
- html_mode = is_in_html_mode (extension);
+ html_mode = e_html_editor_web_extension_get_html_mode (extension);
smileys = webkit_dom_document_query_selector_all (
document, "img.-x-evo-smiley-img", NULL);
@@ -4658,6 +5211,7 @@ toggle_smileys (EHTMLEditorWebExtension *extension,
static void
toggle_paragraphs_style_in_element (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
WebKitDOMElement *element,
gboolean html_mode)
{
@@ -4712,7 +5266,7 @@ toggle_paragraphs_style_in_element (WebKitDOMDocument *document,
/* In plain text mode the paragraphs have width limit */
dom_set_paragraph_style (
- document, WEBKIT_DOM_ELEMENT (node), -1, 0, style_to_add);
+ document, extension, WEBKIT_DOM_ELEMENT (node), -1, 0, style_to_add);
g_free (style);
}
@@ -4722,13 +5276,14 @@ toggle_paragraphs_style_in_element (WebKitDOMDocument *document,
}
static void
-toggle_paragraphs_style (EHTMLEditorWebExtension *extension,
- WebKitDOMDocument *document)
+toggle_paragraphs_style (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
toggle_paragraphs_style_in_element (
document,
+ extension,
WEBKIT_DOM_ELEMENT (webkit_dom_document_get_body (document)),
- is_in_html_mode (extension));
+ e_html_editor_web_extension_get_html_mode (extension));
}
static gchar *
@@ -4754,7 +5309,8 @@ process_content_for_saving_as_draft (WebKitDOMDocument *document)
}
static gchar *
-process_content_for_mode_change (WebKitDOMDocument *document)
+process_content_for_mode_change (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
WebKitDOMNode *body;
GString *plain_text;
@@ -4772,6 +5328,7 @@ process_content_for_mode_change (WebKitDOMDocument *document)
static void
convert_element_from_html_to_plain_text (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
WebKitDOMElement *element,
gboolean *wrap,
gboolean *quote)
@@ -4831,6 +5388,7 @@ convert_element_from_html_to_plain_text (WebKitDOMDocument *document,
parse_html_into_paragraphs (
document,
+ extension,
main_blockquote ? blockquote : WEBKIT_DOM_ELEMENT (element),
NULL,
inner_html);
@@ -4911,12 +5469,12 @@ process_content_for_plain_text (EHTMLEditorWebExtension *extension,
source = webkit_dom_node_clone_node (WEBKIT_DOM_NODE (body), TRUE);
/* If composer is in HTML mode we have to move the content to plain version */
- if (is_in_html_mode (extension)) {
+ if (e_html_editor_web_extension_get_html_mode (extension)) {
if (converted || is_from_new_message) {
toggle_paragraphs_style_in_element (
- document, WEBKIT_DOM_ELEMENT (source), FALSE);
+ document, extension, WEBKIT_DOM_ELEMENT (source), FALSE);
remove_images_in_element (
- document, WEBKIT_DOM_ELEMENT (source));
+ WEBKIT_DOM_ELEMENT (source));
remove_background_images_in_document (document);
} else {
gchar *inner_html;
@@ -4951,7 +5509,7 @@ process_content_for_plain_text (EHTMLEditorWebExtension *extension,
g_object_unref (paragraphs);
convert_element_from_html_to_plain_text (
- document, div, &wrap, "e);
+ document, extension, div, &wrap, "e);
g_object_unref (source);
@@ -4980,13 +5538,13 @@ process_content_for_plain_text (EHTMLEditorWebExtension *extension,
if (WEBKIT_DOM_IS_HTML_LI_ELEMENT (item)) {
dom_wrap_paragraph (
- document, WEBKIT_DOM_ELEMENT (item));
+ document, extension, WEBKIT_DOM_ELEMENT (item));
}
item = next_item;
}
} else {
dom_wrap_paragraph (
- document, WEBKIT_DOM_ELEMENT (paragraph));
+ document, extension, WEBKIT_DOM_ELEMENT (paragraph));
}
}
g_object_unref (paragraphs);
@@ -5006,7 +5564,7 @@ process_content_for_plain_text (EHTMLEditorWebExtension *extension,
}
g_object_unref (paragraphs);
- if (is_in_html_mode (extension) || quote)
+ if (e_html_editor_web_extension_get_html_mode (extension) || quote)
quote_plain_text_recursive (document, source, source, 0);
process_elements (extension, source, FALSE, FALSE, TRUE, plain_text);
@@ -5021,7 +5579,8 @@ process_content_for_plain_text (EHTMLEditorWebExtension *extension,
}
static gchar *
-process_content_for_html (WebKitDOMDocument *document)
+process_content_for_html (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
WebKitDOMNode *body, *document_clone;
gchar *html_content;
@@ -5040,8 +5599,9 @@ process_content_for_html (WebKitDOMDocument *document)
return html_content;
}
-void
-convert_when_changing_composer_mode (WebKitDOMDocument *document)
+static void
+convert_when_changing_composer_mode (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
gboolean quote = FALSE, wrap = FALSE;
WebKitDOMHTMLElement *body;
@@ -5049,10 +5609,10 @@ convert_when_changing_composer_mode (WebKitDOMDocument *document)
body = webkit_dom_document_get_body (document);
convert_element_from_html_to_plain_text (
- document, WEBKIT_DOM_ELEMENT (body), &wrap, "e);
+ document, extension, WEBKIT_DOM_ELEMENT (body), &wrap, "e);
if (wrap)
- dom_wrap_paragraphs_in_document (document);
+ dom_wrap_paragraphs_in_document (document, extension);
if (quote) {
dom_selection_save (document);
@@ -5064,8 +5624,8 @@ convert_when_changing_composer_mode (WebKitDOMDocument *document)
dom_selection_restore (document);
}
- toggle_paragraphs_style (document);
- toggle_smileys (document);
+ toggle_paragraphs_style (document, extension);
+ toggle_smileys (document, extension);
remove_images (document);
remove_background_images_in_document (document);
@@ -5073,10 +5633,14 @@ convert_when_changing_composer_mode (WebKitDOMDocument *document)
webkit_dom_element_set_attribute (
WEBKIT_DOM_ELEMENT (body), "data-converted", "", NULL);
+
+ dom_force_spell_check (document, extension);
+ dom_scroll_to_caret (document);
}
static void
-wrap_paragraphs_in_quoted_content (WebKitDOMDocument *document)
+wrap_paragraphs_in_quoted_content (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
{
gint ii, length;
WebKitDOMNodeList *paragraphs;
@@ -5090,8 +5654,437 @@ wrap_paragraphs_in_quoted_content (WebKitDOMDocument *document)
paragraph = webkit_dom_node_list_item (paragraphs, ii);
- dom_wrap_paragraph (document, WEBKIT_DOM_ELEMENT (paragraph));
+ dom_wrap_paragraph (document, extension, WEBKIT_DOM_ELEMENT (paragraph));
}
g_object_unref (paragraphs);
}
+static void
+set_base64_to_element_attribute (GHashTable *inline_images,
+ WebKitDOMElement *element,
+ const gchar *attribute)
+{
+ gchar *attribute_value;
+ const gchar *base64_src;
+
+ attribute_value = webkit_dom_element_get_attribute (element, attribute);
+
+ if ((base64_src = g_hash_table_lookup (inline_images, attribute_value)) != NULL) {
+ const gchar *base64_data = strstr (base64_src, ";") + 1;
+ gchar *name;
+ glong name_length;
+
+ name_length =
+ g_utf8_strlen (base64_src, -1) -
+ g_utf8_strlen (base64_data, -1) - 1;
+ name = g_strndup (base64_src, name_length);
+
+ webkit_dom_element_set_attribute (element, "data-inline", "", NULL);
+ webkit_dom_element_set_attribute (element, "data-name", name, NULL);
+ webkit_dom_element_set_attribute (element, attribute, base64_data, NULL);
+
+ g_free (name);
+ }
+}
+
+static void
+change_cid_images_src_to_base64 (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
+{
+ GHashTable *inline_images;
+ gint ii, length;
+ WebKitDOMElement *document_element;
+ WebKitDOMNamedNodeMap *attributes;
+ WebKitDOMNodeList *list;
+
+ inline_images = e_html_editor_web_extension_get_inline_images (extension);
+
+ document_element = webkit_dom_document_get_document_element (document);
+
+ list = webkit_dom_document_query_selector_all (document, "img[src^=\"cid:\"]", NULL);
+ length = webkit_dom_node_list_get_length (list);
+ for (ii = 0; ii < length; ii++) {
+ WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+
+ set_base64_to_element_attribute (inline_images, WEBKIT_DOM_ELEMENT (node), "src");
+ }
+ g_object_unref (list);
+
+ /* Namespaces */
+ attributes = webkit_dom_element_get_attributes (document_element);
+ length = webkit_dom_named_node_map_get_length (attributes);
+ for (ii = 0; ii < length; ii++) {
+ gchar *name;
+ WebKitDOMNode *node = webkit_dom_named_node_map_item (attributes, ii);
+
+ name = webkit_dom_node_get_local_name (node);
+
+ if (g_str_has_prefix (name, "xmlns:")) {
+ const gchar *ns = name + 6;
+ gchar *attribute_ns = g_strconcat (ns, ":src", NULL);
+ gchar *selector = g_strconcat ("img[", ns, "\\:src^=\"cid:\"]", NULL);
+ gint ns_length, jj;
+
+ list = webkit_dom_document_query_selector_all (
+ document, selector, NULL);
+ ns_length = webkit_dom_node_list_get_length (list);
+ for (jj = 0; jj < ns_length; jj++) {
+ WebKitDOMNode *node = webkit_dom_node_list_item (list, jj);
+
+ set_base64_to_element_attribute (
+ inline_images, WEBKIT_DOM_ELEMENT (node), attribute_ns);
+ }
+
+ g_object_unref (list);
+ g_free (attribute_ns);
+ g_free (selector);
+ }
+ g_free (name);
+ }
+ g_object_unref (attributes);
+
+ list = webkit_dom_document_query_selector_all (
+ document, "[background^=\"cid:\"]", NULL);
+ length = webkit_dom_node_list_get_length (list);
+ for (ii = 0; ii < length; ii++) {
+ WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+
+ set_base64_to_element_attribute (
+ inline_images, WEBKIT_DOM_ELEMENT (node), "background");
+ }
+ g_object_unref (list);
+ g_hash_table_remove_all (inline_images);
+}
+
+void
+dom_process_content_after_load (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
+{
+ WebKitDOMHTMLElement *body;
+
+ /* Don't use CSS when possible to preserve compatibility with older
+ * versions of Evolution or other MUAs */
+ dom_exec_command (
+ document, E_HTML_EDITOR_VIEW_COMMAND_STYLE_WITH_CSS, "false");
+
+ body = webkit_dom_document_get_body (document);
+
+ webkit_dom_element_remove_attribute (WEBKIT_DOM_ELEMENT (body), "style");
+ webkit_dom_element_set_attribute (
+ WEBKIT_DOM_ELEMENT (body), "data-message", "", NULL);
+
+ if (e_html_editor_web_extension_get_convert_in_situ (extension)) {
+ dom_convert_document (document, extension, NULL);
+ e_html_editor_web_extension_set_convert_in_situ (extension, FALSE);
+
+ return;
+ }
+
+ put_body_in_citation (document);
+ move_elements_to_body (document);
+ repair_gmail_blockquotes (document);
+
+ if (webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (body), "data-evo-draft")) {
+ /* Restore the selection how it was when the draft was saved */
+ dom_move_caret_into_element (document, WEBKIT_DOM_ELEMENT (body));
+ dom_selection_restore (document);
+ }
+
+ dom_set_links_active (document, FALSE);
+
+ /* Register on input event that is called when the content (body) is modified */
+ register_input_event_listener_on_body (document, extension);
+ register_html_events_handlers (body, extension);
+
+ if (e_html_editor_web_extension_get_html_mode (extension))
+ change_cid_images_src_to_base64 (document, extension);
+
+ if (e_html_editor_web_extension_get_inline_spelling_enabled (extension))
+ dom_force_spell_check (document, extension);
+ else
+ dom_turn_spell_check_off (document);
+}
+
+GVariant *
+dom_get_inline_images (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
+ const gchar *uid_domain)
+{
+ GVariant *result;
+ GVariantBuilder *builder;
+ GHashTable *added;
+ gint length, ii;
+ WebKitDOMNodeList *list;
+
+ list = webkit_dom_document_query_selector_all (document, "img[data-inline]", NULL);
+
+ length = webkit_dom_node_list_get_length (list);
+ if (length == 0)
+ return NULL;
+
+ builder = g_variant_builder_new (G_VARIANT_TYPE ("asss"));
+
+ added = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ for (ii = 0; ii < length; ii++) {
+ const gchar *id;
+ gchar *cid;
+ WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+ gchar *src = webkit_dom_element_get_attribute (
+ WEBKIT_DOM_ELEMENT (node), "src");
+
+ if ((id = g_hash_table_lookup (added, src)) != NULL) {
+ cid = g_strdup_printf ("cid:%s", id);
+ g_free (src);
+ } else {
+ gchar *data_name = webkit_dom_element_get_attribute (
+ WEBKIT_DOM_ELEMENT (node), "data-name");
+ gchar *new_id;
+
+ new_id = camel_header_msgid_generate (uid_domain);
+ g_variant_builder_add (
+ builder, "sss", src, data_name, new_id);
+ cid = g_strdup_printf ("cid:%s", new_id);
+
+ g_hash_table_insert (added, src, new_id);
+ g_free (new_id);
+ }
+ webkit_dom_element_set_attribute (
+ WEBKIT_DOM_ELEMENT (node), "src", cid, NULL);
+ g_free (cid);
+ }
+ g_object_unref (list);
+
+ list = webkit_dom_document_query_selector_all (
+ document, "[data-inline][background]", NULL);
+ length = webkit_dom_node_list_get_length (list);
+ for (ii = 0; ii < length; ii++) {
+ const gchar *id;
+ gchar *cid = NULL;
+ WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+ gchar *src = webkit_dom_element_get_attribute (
+ WEBKIT_DOM_ELEMENT (node), "background");
+
+ if ((id = g_hash_table_lookup (added, src)) != NULL) {
+ cid = g_strdup_printf ("cid:%s", id);
+ webkit_dom_element_set_attribute (
+ WEBKIT_DOM_ELEMENT (node), "background", cid, NULL);
+ g_free (src);
+ } else {
+ gchar *data_name = webkit_dom_element_get_attribute (
+ WEBKIT_DOM_ELEMENT (node), "data-name");
+ gchar *new_id;
+
+ new_id = camel_header_msgid_generate (uid_domain);
+ g_variant_builder_add (
+ builder, "sss", src, data_name, new_id);
+ cid = g_strdup_printf ("cid:%s", new_id);
+
+ g_hash_table_insert (added, src, new_id);
+ g_free (new_id);
+
+ webkit_dom_element_set_attribute (
+ WEBKIT_DOM_ELEMENT (node), "background", cid, NULL);
+ }
+ g_free (cid);
+ }
+
+ g_object_unref (list);
+ g_hash_table_destroy (added);
+
+ result = g_variant_new ("asss", builder);
+ g_variant_builder_unref (builder);
+
+ return result;
+}
+
+/**
+ * e_html_editor_selection_insert_html:
+ * @selection: an #EHTMLEditorSelection
+ * @html_text: an HTML code to insert
+ *
+ * Insert @html_text into document at current cursor position. When a text range
+ * is selected, it will be replaced by @html_text.
+ */
+void
+dom_insert_html (EHTMLEditorWebExtension *extension,
+ WebKitDOMDocument *document,
+ const gchar *html_text)
+{
+ g_return_if_fail (html_text != NULL);
+
+ if (e_html_editor_web_extension_get_html_mode (extension)) {
+ dom_exec_command (
+ document, E_HTML_EDITOR_VIEW_COMMAND_INSERT_HTML, html_text);
+
+ dom_check_magic_links (document, extension, FALSE);
+ dom_force_spell_check (document, extension);
+ dom_scroll_to_caret (document);
+ } else
+ dom_convert_and_insert_html_into_selection (document, extension, html_text, TRUE);
+}
+
+static gboolean
+is_return_key (guint key_val)
+{
+ return (
+ (key_val == GDK_KEY_Return) ||
+ (key_val == GDK_KEY_Linefeed) ||
+ (key_val == GDK_KEY_KP_Enter));
+}
+
+gboolean
+dom_process_on_key_press (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
+ guint key_val)
+{
+
+ if (key_val == GDK_KEY_Tab)
+ return dom_exec_command (
+ document, E_HTML_EDITOR_VIEW_COMMAND_INSERT_TEXT, "\t");
+
+ if (is_return_key (key_val)) {
+ EHTMLEditorSelectionBlockFormat format;
+
+ /* When user presses ENTER in a citation block, WebKit does
+ * not break the citation automatically, so we need to use
+ * the special command to do it. */
+ if (dom_selection_is_citation (document)) {
+ remove_input_event_listener_from_body (document, extension);
+ return (insert_new_line_into_citation (document, extension, "")) ? TRUE : FALSE;
+ }
+
+ /* When the return is pressed in a H1-6 element, WebKit doesn't
+ * continue with the same element, but creates normal paragraph,
+ * so we have to unset the bold font. */
+ format = dom_selection_get_block_format (document, extension);
+ if (format >= E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_H1 &&
+ format <= E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_H6)
+ dom_selection_set_bold (document, extension, FALSE);
+ }
+
+ if (key_val == GDK_KEY_BackSpace) {
+ /* BackSpace pressed in the beginning of quoted content changes
+ * format to normal and inserts text into body */
+ if (dom_selection_is_collapsed (document)) {
+ dom_selection_save (document);
+ if (dom_change_quoted_block_to_normal (document, extension)) {
+ dom_selection_restore (document);
+ dom_force_spell_check_for_current_paragraph (document, extension);
+ return TRUE;
+ }
+ dom_selection_restore (document);
+ } else
+ remove_input_event_listener_from_body (document, extension);
+
+ /* BackSpace in indented block decrease indent level by one */
+ if (dom_selection_is_indented (document)) {
+ WebKitDOMElement *caret;
+ WebKitDOMNode *prev_sibling;
+
+ caret = dom_save_caret_position (document);
+
+ /* Empty text node before caret */
+ prev_sibling = webkit_dom_node_get_previous_sibling (
+ WEBKIT_DOM_NODE (caret));
+ if (prev_sibling && WEBKIT_DOM_IS_TEXT (prev_sibling)) {
+ gchar *content;
+
+ content = webkit_dom_node_get_text_content (prev_sibling);
+ if (g_strcmp0 (content, "") == 0)
+ prev_sibling = webkit_dom_node_get_previous_sibling (prev_sibling);
+ g_free (content);
+ }
+
+ dom_clear_caret_position_marker (document);
+
+ if (!prev_sibling) {
+ dom_selection_unindent (document, extension);
+ return TRUE;
+ }
+ }
+
+ if (prevent_from_deleting_last_element_in_body (document))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+gboolean
+dom_check_if_conversion_needed (WebKitDOMDocument *document)
+{
+ gboolean is_from_new_message, converted, edit_as_new, message, convert;
+ gboolean reply, hide;
+ WebKitDOMHTMLElement *body;
+
+ body = webkit_dom_document_get_body (document);
+
+ is_from_new_message = webkit_dom_element_has_attribute (
+ WEBKIT_DOM_ELEMENT (body), "data-new-message");
+ converted = webkit_dom_element_has_attribute (
+ WEBKIT_DOM_ELEMENT (body), "data-converted");
+ edit_as_new = webkit_dom_element_has_attribute (
+ WEBKIT_DOM_ELEMENT (body), "data-edit-as-new");
+ message = webkit_dom_element_has_attribute (
+ WEBKIT_DOM_ELEMENT (body), "data-message");
+
+ reply = !is_from_new_message && !edit_as_new && message;
+ hide = !reply && !converted;
+
+ convert = message && ((!hide && reply && !converted) || (edit_as_new && !converted));
+
+ return convert;
+}
+
+void
+dom_process_content_after_mode_change (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension)
+{
+ gboolean html_mode;
+ WebKitDOMElement *blockquote;
+
+ html_mode = e_html_editor_web_extension_get_html_mode (extension);
+
+ blockquote = webkit_dom_document_query_selector (
+ document, "blockquote[type|=cite]", NULL);
+
+ if (html_mode) {
+ if (blockquote)
+ dom_dequote_plain_text (document);
+
+ toggle_paragraphs_style (document, extension);
+ toggle_smileys (document, extension);
+ remove_wrapping_from_document (document);
+ } else {
+ gchar *plain;
+
+ dom_selection_save (document);
+
+ if (blockquote) {
+ wrap_paragraphs_in_quoted_content (document, extension);
+ quote_plain_text_elements_after_wrapping_in_document (
+ document);
+ }
+
+ toggle_paragraphs_style (document, extension);
+ toggle_smileys (document, extension);
+ remove_images (document);
+ remove_background_images_in_document (document);
+
+ plain = process_content_for_mode_change (document, extension);
+
+ if (*plain) {
+ webkit_dom_html_element_set_outer_html (
+ WEBKIT_DOM_HTML_ELEMENT (
+ webkit_dom_document_get_document_element (document)),
+ plain,
+ NULL);
+ dom_selection_restore (document);
+ dom_force_spell_check (document, extension);
+ }
+
+ g_free (plain);
+ }
+
+}
+
diff --git a/e-util/e-html-editor-view-dom-functions.h b/e-util/e-html-editor-view-dom-functions.h
index 4bf6963..49a7c23 100644
--- a/e-util/e-html-editor-view-dom-functions.h
+++ b/e-util/e-html-editor-view-dom-functions.h
@@ -21,7 +21,7 @@
#include <webkitdom/webkitdom.h>
-#include "web-extensions/e-html-editor-web-extension.h"
+#include "e-html-editor-web-extension.h"
#include "e-util-enums.h"
@@ -32,9 +32,22 @@ gboolean dom_exec_command (WebKitDOMDocument *document,
const gchar *value);
void dom_force_spell_check_for_current_paragraph
- (WebKitDOMDocument *document);
+ (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension);
+
+void dom_force_spell_check (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension);
+
+void dom_turn_spell_check_off (WebKitDOMDocument *document);
+
+void dom_embed_style_sheet (WebKitDOMDocument *document,
+ const gchar *style_sheet_content);
-void dom_force_spell_check (WebKitDOMDocument *document);
+void dom_remove_embed_style_sheet (WebKitDOMDocument *document);
+
+void dom_convert_document (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
+ const gchar *preferred_text);
void dom_convert_and_insert_html_into_selection
(WebKitDOMDocument *document,
@@ -45,6 +58,28 @@ void dom_convert_and_insert_html_into_selection
WebKitDOMElement *
dom_quote_plain_text_element (WebKitDOMDocument *document,
WebKitDOMElement *element);
+
+void dom_process_content_after_load (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension);
+
+GVariant * dom_get_inline_images (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
+ const gchar *uid_domain);
+
+void dom_insert_html (EHTMLEditorWebExtension *extension,
+ WebKitDOMDocument *document,
+ const gchar *html_text);
+
+gboolean dom_process_on_key_press (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension,
+ guint key_val);
+
+gboolean dom_check_if_conversion_needed (WebKitDOMDocument *document);
+
+void dom_process_content_after_mode_change
+ (WebKitDOMDocument *document,
+ EHTMLEditorWebExtension *extension);
+
G_END_DECLS
#endif /* E_HTML_EDITOR_VIEW_DOM_FUNCTIONS_H */
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index f80480a..9bc2b50 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -27,7 +27,7 @@
#include "e-emoticon-chooser.h"
#include "e-misc-utils.h"
-#include "web-extensions/e-html-editor-web-extension-names.h"
+#include "e-html-editor-web-extension-names.h"
#include <e-util/e-util.h>
#include <e-util/e-marshal.h>
@@ -38,30 +38,6 @@
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_HTML_EDITOR_VIEW, EHTMLEditorViewPrivate))
-#define UNICODE_ZERO_WIDTH_SPACE "\xe2\x80\x8b"
-#define UNICODE_NBSP "\xc2\xa0"
-
-#define URL_PATTERN \
- "((([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[\\-;:&=\\+\\$,\\w]+@)?" \
- "[A-Za-z0-9\\.\\-]+|(?:www\\.|[\\-;:&=\\+\\$,\\w]+@)" \
- "[A-Za-z0-9\\.\\-]+)((?:\\/[\\+~%\\/\\.\\w\\-]*)?\\?" \
- "?(?:[\\-\\+=&;% \\ \\w]*)#?(?:[\\.\\!\\/\\\\w]*))?)"
-
-#define URL_PATTERN_SPACE URL_PATTERN "\\s"
-
-/* http://www.w3.org/TR/html5/forms.html#valid-e-mail-address */
-#define E_MAIL_PATTERN \
- "[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+ [a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}"\
- "[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*"
-
-#define E_MAIL_PATTERN_SPACE E_MAIL_PATTERN "\\s"
-
-#define QUOTE_SYMBOL ">"
-
-/* Keep synchronized with the same value in EHTMLEditorSelection */
-#define SPACES_PER_LIST_LEVEL 8
-#define TAB_LENGTH 8
-
/**
* EHTMLEditorView:
*
@@ -86,10 +62,6 @@ struct _EHTMLEditorViewPrivate {
EHTMLEditorSelection *selection;
- WebKitDOMElement *element_under_mouse;
-
- GHashTable *inline_images;
-
GSettings *mail_settings;
GSettings *font_settings;
GSettings *aliasing_settings;
@@ -149,9 +121,9 @@ G_DEFINE_TYPE_WITH_CODE (
static void
html_editor_view_queue_post_reload_operation (EHTMLEditorView *view,
- PostReloadOperationFunc func,
- gpointer data,
- GDestroyNotify data_free_func)
+ PostReloadOperationFunc func,
+ gpointer data,
+ GDestroyNotify data_free_func)
{
PostReloadOperation *op;
@@ -340,798 +312,6 @@ html_editor_view_selection_changed_cb (EHTMLEditorView *view)
view);
}
-static gboolean
-html_editor_view_should_show_delete_interface_for_element (EHTMLEditorView *view,
- WebKitDOMHTMLElement *element)
-{
- return FALSE;
-}
-
-void
-e_html_editor_view_force_spell_check_for_current_paragraph (EHTMLEditorView *view)
-{
-/* FIXME WK2
- if (!view->priv->inline_spelling)
- return;
-*/
- /* Block callbacks of selection-changed signal as we don't want to
- * recount all the block format things in EHTMLEditorSelection and here as well
- * when we are moving with caret */
-/* FIXME WK2
- g_signal_handlers_block_by_func (
- view, html_editor_view_selection_changed_cb, NULL);
- e_html_editor_selection_block_selection_changed (selection);
-*/
-
- /* Unblock the callbacks */
-/* FIXME WK2
- g_signal_handlers_unblock_by_func (
- view, html_editor_view_selection_changed_cb, NULL);
- e_html_editor_selection_unblock_selection_changed (selection);
-*/
-}
-
-static void
-refresh_spell_check (EHTMLEditorView *view,
- gboolean enable_spell_check)
-{
- /* Block callbacks of selection-changed signal as we don't want to
- * recount all the block format things in EHTMLEditorSelection and here as well
- * when we are moving with caret */
-/* FIXME WK2
- g_signal_handlers_block_by_func (
- view, html_editor_view_selection_changed_cb, NULL);
- e_html_editor_selection_block_selection_changed (selection);
-*/
- /* Unblock the callbacks */
-/*
- g_signal_handlers_unblock_by_func (
- view, html_editor_view_selection_changed_cb, NULL);
- e_html_editor_selection_unblock_selection_changed (selection);
-*/
-}
-
-void
-e_html_editor_view_turn_spell_check_off (EHTMLEditorView *view)
-{
- refresh_spell_check (view, FALSE);
-}
-
-void
-e_html_editor_view_force_spell_check (EHTMLEditorView *view)
-{
- if (view->priv->inline_spelling)
- refresh_spell_check (view, TRUE);
-}
-
-static void
-set_base64_to_element_attribute (EHTMLEditorView *view,
- WebKitDOMElement *element,
- const gchar *attribute)
-{
- gchar *attribute_value;
- const gchar *base64_src;
-
- attribute_value = webkit_dom_element_get_attribute (element, attribute);
-
- if ((base64_src = g_hash_table_lookup (view->priv->inline_images, attribute_value)) != NULL) {
- const gchar *base64_data = strstr (base64_src, ";") + 1;
- gchar *name;
- glong name_length;
-
- name_length =
- g_utf8_strlen (base64_src, -1) -
- g_utf8_strlen (base64_data, -1) - 1;
- name = g_strndup (base64_src, name_length);
-
- webkit_dom_element_set_attribute (element, "data-inline", "", NULL);
- webkit_dom_element_set_attribute (element, "data-name", name, NULL);
- webkit_dom_element_set_attribute (element, attribute, base64_data, NULL);
-
- g_free (name);
- }
-}
-
-static void
-change_cid_images_src_to_base64 (EHTMLEditorView *view)
-{
- gint ii, length;
- WebKitDOMDocument *document;
- WebKitDOMElement *document_element;
- WebKitDOMNamedNodeMap *attributes;
- WebKitDOMNodeList *list;
-
- document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
- document_element = webkit_dom_document_get_document_element (document);
-
- list = webkit_dom_document_query_selector_all (document, "img[src^=\"cid:\"]", NULL);
- length = webkit_dom_node_list_get_length (list);
- for (ii = 0; ii < length; ii++) {
- WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
-
- set_base64_to_element_attribute (view, WEBKIT_DOM_ELEMENT (node), "src");
- }
- g_object_unref (list);
-
- /* Namespaces */
- attributes = webkit_dom_element_get_attributes (document_element);
- length = webkit_dom_named_node_map_get_length (attributes);
- for (ii = 0; ii < length; ii++) {
- gchar *name;
- WebKitDOMNode *node = webkit_dom_named_node_map_item (attributes, ii);
-
- name = webkit_dom_node_get_local_name (node);
-
- if (g_str_has_prefix (name, "xmlns:")) {
- const gchar *ns = name + 6;
- gchar *attribute_ns = g_strconcat (ns, ":src", NULL);
- gchar *selector = g_strconcat ("img[", ns, "\\:src^=\"cid:\"]", NULL);
- gint ns_length, jj;
-
- list = webkit_dom_document_query_selector_all (
- document, selector, NULL);
- ns_length = webkit_dom_node_list_get_length (list);
- for (jj = 0; jj < ns_length; jj++) {
- WebKitDOMNode *node = webkit_dom_node_list_item (list, jj);
-
- set_base64_to_element_attribute (
- view, WEBKIT_DOM_ELEMENT (node), attribute_ns);
- }
-
- g_object_unref (list);
- g_free (attribute_ns);
- g_free (selector);
- }
- g_free (name);
- }
- g_object_unref (attributes);
-
- list = webkit_dom_document_query_selector_all (
- document, "[background^=\"cid:\"]", NULL);
- length = webkit_dom_node_list_get_length (list);
- for (ii = 0; ii < length; ii++) {
- WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
-
- set_base64_to_element_attribute (
- view, WEBKIT_DOM_ELEMENT (node), "background");
- }
- g_object_unref (list);
- g_hash_table_remove_all (view->priv->inline_images);
-}
-
-/* Based on original use_pictograms() from GtkHTML */
-static const gchar *emoticons_chars =
- /* 0 */ "DO)(|/PQ*!"
- /* 10 */ "S\0:-\0:\0:-\0"
- /* 20 */ ":\0:;=-\"\0:;"
- /* 30 */ "B\"|\0:-'\0:X"
- /* 40 */ "\0:\0:-\0:\0:-"
- /* 50 */ "\0:\0:-\0:\0:-"
- /* 60 */ "\0:\0:\0:-\0:\0"
- /* 70 */ ":-\0:\0:-\0:\0";
-static gint emoticons_states[] = {
- /* 0 */ 12, 17, 22, 34, 43, 48, 53, 58, 65, 70,
- /* 10 */ 75, 0, -15, 15, 0, -15, 0, -17, 20, 0,
- /* 20 */ -17, 0, -14, -20, -14, 28, 63, 0, -14, -20,
- /* 30 */ -3, 63, -18, 0, -12, 38, 41, 0, -12, -2,
- /* 40 */ 0, -4, 0, -10, 46, 0, -10, 0, -19, 51,
- /* 50 */ 0, -19, 0, -11, 56, 0, -11, 0, -13, 61,
- /* 60 */ 0, -13, 0, -6, 0, 68, -7, 0, -7, 0,
- /* 70 */ -16, 73, 0, -16, 0, -21, 78, 0, -21, 0 };
-static const gchar *emoticons_icon_names[] = {
- "face-angel",
- "face-angry",
- "face-cool",
- "face-crying",
- "face-devilish",
- "face-embarrassed",
- "face-kiss",
- "face-laugh", /* not used */
- "face-monkey", /* not used */
- "face-plain",
- "face-raspberry",
- "face-sad",
- "face-sick",
- "face-smile",
- "face-smile-big",
- "face-smirk",
- "face-surprise",
- "face-tired",
- "face-uncertain",
- "face-wink",
- "face-worried"
-};
-
-static gboolean
-is_return_key (GdkEventKey *event)
-{
- return (
- (event->keyval == GDK_KEY_Return) ||
- (event->keyval == GDK_KEY_Linefeed) ||
- (event->keyval == GDK_KEY_KP_Enter));
-}
-
-static void
-html_editor_view_check_magic_links (EHTMLEditorView *view,
- WebKitDOMRange *range,
- gboolean include_space_by_user)
-{
- gchar *node_text;
- gchar **urls;
- GRegex *regex = NULL;
- GMatchInfo *match_info;
- gint start_pos_url, end_pos_url;
- WebKitDOMNode *node;
- gboolean include_space = FALSE;
- gboolean is_email_address = FALSE;
-
- if (include_space_by_user == TRUE)
- include_space = TRUE;
- else
- include_space = view->priv->space_key_pressed;
-
- node = webkit_dom_range_get_end_container (range, NULL);
-
- if (view->priv->return_key_pressed)
- node = webkit_dom_node_get_previous_sibling (node);
-
- if (!node)
- return;
-
- if (!WEBKIT_DOM_IS_TEXT (node)) {
- if (webkit_dom_node_has_child_nodes (node))
- node = webkit_dom_node_get_first_child (node);
- if (!WEBKIT_DOM_IS_TEXT (node))
- return;
- }
-
- node_text = webkit_dom_text_get_whole_text (WEBKIT_DOM_TEXT (node));
- if (!node_text || !(*node_text) || !g_utf8_validate (node_text, -1, NULL))
- return;
-
- if (strstr (node_text, "@") && !strstr (node_text, "://")) {
- is_email_address = TRUE;
- regex = g_regex_new (include_space ? E_MAIL_PATTERN_SPACE : E_MAIL_PATTERN, 0, 0, NULL);
- } else
- regex = g_regex_new (include_space ? URL_PATTERN_SPACE : URL_PATTERN, 0, 0, NULL);
-
- if (!regex) {
- g_free (node_text);
- return;
- }
-
- g_regex_match_all (regex, node_text, G_REGEX_MATCH_NOTEMPTY, &match_info);
- urls = g_match_info_fetch_all (match_info);
-
- if (urls) {
- gchar *final_url, *url_end_raw;
- glong url_start, url_end, url_length;
- WebKitDOMDocument *document;
- WebKitDOMNode *url_text_node_clone;
- WebKitDOMText *url_text_node;
- WebKitDOMElement *anchor;
- const gchar* url_text;
-
- document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
-
- if (!view->priv->return_key_pressed)
- e_html_editor_selection_save_caret_position (
- e_html_editor_view_get_selection (view));
-
- g_match_info_fetch_pos (match_info, 0, &start_pos_url, &end_pos_url);
-
- /* Get start and end position of url in node's text because positions
- * that we get from g_match_info_fetch_pos are not UTF-8 aware */
- url_end_raw = g_strndup(node_text, end_pos_url);
- url_end = g_utf8_strlen (url_end_raw, -1);
-
- url_length = g_utf8_strlen (urls[0], -1);
- url_start = url_end - url_length;
-
- webkit_dom_text_split_text (
- WEBKIT_DOM_TEXT (node),
- include_space ? url_end - 1 : url_end,
- NULL);
-
- url_text_node = webkit_dom_text_split_text (
- WEBKIT_DOM_TEXT (node), url_start, NULL);
- url_text_node_clone = webkit_dom_node_clone_node (
- WEBKIT_DOM_NODE (url_text_node), TRUE);
- url_text = webkit_dom_text_get_whole_text (
- WEBKIT_DOM_TEXT (url_text_node_clone));
-
- if (g_str_has_prefix (url_text, "www."))
- final_url = g_strconcat ("http://" , url_text, NULL);
- else if (is_email_address)
- final_url = g_strconcat ("mailto:" , url_text, NULL);
- else
- final_url = g_strdup (url_text);
-
- /* Create and prepare new anchor element */
- anchor = webkit_dom_document_create_element (document, "A", NULL);
-
- webkit_dom_html_element_set_inner_html (
- WEBKIT_DOM_HTML_ELEMENT (anchor),
- url_text,
- NULL);
-
- webkit_dom_html_anchor_element_set_href (
- WEBKIT_DOM_HTML_ANCHOR_ELEMENT (anchor),
- final_url);
-
- /* Insert new anchor element into document */
- webkit_dom_node_replace_child (
- webkit_dom_node_get_parent_node (node),
- WEBKIT_DOM_NODE (anchor),
- WEBKIT_DOM_NODE (url_text_node),
- NULL);
-
- if (!view->priv->return_key_pressed)
- e_html_editor_selection_restore_caret_position (
- e_html_editor_view_get_selection (view));
-
- g_free (url_end_raw);
- g_free (final_url);
- } else {
- WebKitDOMElement *parent;
- WebKitDOMNode *prev_sibling;
- gchar *href, *text, *url;
- gint diff;
- const char* text_to_append;
- gboolean appending_to_link = FALSE;
-
- parent = webkit_dom_node_get_parent_element (node);
- prev_sibling = webkit_dom_node_get_previous_sibling (node);
-
- /* If previous sibling is ANCHOR and actual text node is not beginning with
- * space => we're appending to link */
- if (WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (prev_sibling)) {
- text_to_append = webkit_dom_node_get_text_content (node);
- if (g_strcmp0 (text_to_append, "") != 0 &&
- !g_unichar_isspace (g_utf8_get_char (text_to_append))) {
-
- appending_to_link = TRUE;
- parent = WEBKIT_DOM_ELEMENT (prev_sibling);
- }
- }
-
- /* If parent is ANCHOR => we're editing the link */
- if (!WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (parent) && !appending_to_link) {
- g_match_info_free (match_info);
- g_regex_unref (regex);
- g_free (node_text);
- return;
- }
-
- /* edit only if href and description are the same */
- href = webkit_dom_html_anchor_element_get_href (
- WEBKIT_DOM_HTML_ANCHOR_ELEMENT (parent));
-
- if (appending_to_link) {
- gchar *inner_text;
-
- inner_text =
- webkit_dom_html_element_get_inner_text (
- WEBKIT_DOM_HTML_ELEMENT (parent)),
-
- text = g_strconcat (inner_text, text_to_append, NULL);
- g_free (inner_text);
- } else
- text = webkit_dom_html_element_get_inner_text (
- WEBKIT_DOM_HTML_ELEMENT (parent));
-
- if (strstr (href, "://") && !strstr (text, "://")) {
- url = strstr (href, "://") + 3;
- diff = strlen (text) - strlen (url);
-
- if (text [strlen (text) - 1] != '/')
- diff++;
-
- if ((g_strcmp0 (url, text) != 0 && ABS (diff) == 1) || appending_to_link) {
- gchar *inner_html, *protocol, *new_href;
-
- protocol = g_strndup (href, strstr (href, "://") - href + 3);
- inner_html = webkit_dom_html_element_get_inner_html (
- WEBKIT_DOM_HTML_ELEMENT (parent));
- new_href = g_strconcat (
- protocol, inner_html, appending_to_link ? text_to_append : "", NULL);
-
- webkit_dom_html_anchor_element_set_href (
- WEBKIT_DOM_HTML_ANCHOR_ELEMENT (parent),
- new_href);
-
- if (appending_to_link) {
- gchar *tmp;
-
- tmp = g_strconcat (inner_html, text_to_append, NULL);
- webkit_dom_html_element_set_inner_html (
- WEBKIT_DOM_HTML_ELEMENT (parent),
- tmp,
- NULL);
-
- remove_node (node);
-
- g_free (tmp);
- }
-
- g_free (new_href);
- g_free (protocol);
- g_free (inner_html);
- }
- } else {
- diff = strlen (text) - strlen (href);
- if (text [strlen (text) - 1] != '/')
- diff++;
-
- if ((g_strcmp0 (href, text) != 0 && ABS (diff) == 1) || appending_to_link) {
- gchar *inner_html;
- gchar *new_href;
-
- inner_html = webkit_dom_html_element_get_inner_html (
- WEBKIT_DOM_HTML_ELEMENT (parent));
- new_href = g_strconcat (
- inner_html,
- appending_to_link ? text_to_append : "",
- NULL);
-
- webkit_dom_html_anchor_element_set_href (
- WEBKIT_DOM_HTML_ANCHOR_ELEMENT (parent),
- new_href);
-
- if (appending_to_link) {
- gchar *tmp;
-
- tmp = g_strconcat (inner_html, text_to_append, NULL);
- webkit_dom_html_element_set_inner_html (
- WEBKIT_DOM_HTML_ELEMENT (parent),
- tmp,
- NULL);
-
- remove_node (node);
-
- g_free (tmp);
- }
-
- g_free (new_href);
- g_free (inner_html);
- }
-
- }
- g_free (text);
- g_free (href);
- }
-
- g_match_info_free (match_info);
- g_regex_unref (regex);
- g_free (node_text);
-}
-
-typedef struct _LoadContext LoadContext;
-
-struct _LoadContext {
- EHTMLEditorView *view;
- gchar *content_type;
- gchar *name;
- EEmoticon *emoticon;
-};
-
-static LoadContext *
-emoticon_load_context_new (EHTMLEditorView *view,
- EEmoticon *emoticon)
-{
- LoadContext *load_context;
-
- load_context = g_slice_new0 (LoadContext);
- load_context->view = view;
- load_context->emoticon = emoticon;
-
- return load_context;
-}
-
-static void
-emoticon_load_context_free (LoadContext *load_context)
-{
- g_free (load_context->content_type);
- g_free (load_context->name);
- g_slice_free (LoadContext, load_context);
-}
-
-static void
-emoticon_read_async_cb (GFile *file,
- GAsyncResult *result,
- LoadContext *load_context)
-{
- EHTMLEditorView *view = load_context->view;
- EEmoticon *emoticon = load_context->emoticon;
- GError *error = NULL;
- gboolean misplaced_selection = FALSE, empty = FALSE;
- gchar *html, *node_text = NULL, *mime_type, *content;
- gchar *base64_encoded, *output, *data;
- const gchar *emoticon_start;
- GFileInputStream *input_stream;
- GOutputStream *output_stream;
- gssize size;
- WebKitDOMDocument *document;
- WebKitDOMElement *span, *selection_start_marker, *selection_end_marker;
- WebKitDOMNode *node, *insert_before, *prev_sibling, *next_sibling;
- WebKitDOMNode *selection_end_marker_parent;
- WebKitDOMRange *range;
-
- input_stream = g_file_read_finish (file, result, &error);
- g_return_if_fail (!error && input_stream);
-
- output_stream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
-
- size = g_output_stream_splice (
- output_stream, G_INPUT_STREAM (input_stream),
- G_OUTPUT_STREAM_SPLICE_NONE, NULL, &error);
-
- if (error || (size == -1))
- goto out;
-
- e_html_editor_selection_save (e_html_editor_view_get_selection (view));
-
- document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
- selection_start_marker = webkit_dom_document_get_element_by_id (
- document, "-x-evo-selection-start-marker");
- selection_end_marker = webkit_dom_document_get_element_by_id (
- document, "-x-evo-selection-end-marker");
-
- /* If the selection was not saved, move it into the first child of body */
- if (!selection_start_marker || !selection_end_marker) {
- WebKitDOMHTMLElement *body;
- WebKitDOMNode *child;
-
- body = webkit_dom_document_get_body (document);
- child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body));
-
- add_selection_markers_into_element_start (
- document,
- WEBKIT_DOM_ELEMENT (child),
- &selection_start_marker,
- &selection_end_marker);
- }
-
- /* Sometimes selection end marker is in body. Move it into next sibling */
- selection_end_marker_parent = get_parent_block_node_from_child (
- WEBKIT_DOM_NODE (selection_end_marker));
- if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (selection_end_marker_parent)) {
- webkit_dom_node_insert_before (
- webkit_dom_node_get_parent_node (
- WEBKIT_DOM_NODE (selection_start_marker)),
- WEBKIT_DOM_NODE (selection_end_marker),
- WEBKIT_DOM_NODE (selection_start_marker),
- NULL);
- }
- selection_end_marker_parent = webkit_dom_node_get_parent_node (
- WEBKIT_DOM_NODE (selection_end_marker));
-
- /* Determine before what node we have to insert the smiley */
- insert_before = WEBKIT_DOM_NODE (selection_start_marker);
- prev_sibling = webkit_dom_node_get_previous_sibling (
- WEBKIT_DOM_NODE (selection_start_marker));
- if (prev_sibling) {
- if (webkit_dom_node_is_same_node (
- prev_sibling, WEBKIT_DOM_NODE (selection_end_marker))) {
- insert_before = WEBKIT_DOM_NODE (selection_end_marker);
- } else {
- prev_sibling = webkit_dom_node_get_previous_sibling (prev_sibling);
- if (prev_sibling &&
- webkit_dom_node_is_same_node (
- prev_sibling, WEBKIT_DOM_NODE (selection_end_marker))) {
- insert_before = WEBKIT_DOM_NODE (selection_end_marker);
- }
- }
- } else
- insert_before = WEBKIT_DOM_NODE (selection_start_marker);
-
- /* Look if selection is misplaced - that means that the selection was
- * restored before the previously inserted smiley in situations when we
- * are writing more smileys in a row */
- next_sibling = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (selection_end_marker));
- if (next_sibling && WEBKIT_DOM_IS_ELEMENT (next_sibling))
- if (element_has_class (WEBKIT_DOM_ELEMENT (next_sibling), "-x-evo-smiley-wrapper"))
- misplaced_selection = TRUE;
-
- mime_type = g_content_type_get_mime_type (load_context->content_type);
- range = dom_get_range (view);
- node = webkit_dom_range_get_end_container (range, NULL);
- if (WEBKIT_DOM_IS_TEXT (node))
- node_text = webkit_dom_text_get_whole_text (WEBKIT_DOM_TEXT (node));
-
- data = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (output_stream));
- base64_encoded = g_base64_encode ((const guchar *) data, size);
- output = g_strconcat ("data:", mime_type, ";base64,", base64_encoded, NULL);
-
- content = webkit_dom_node_get_text_content (selection_end_marker_parent);
- empty = !*content || (g_strcmp0 (content, UNICODE_ZERO_WIDTH_SPACE) == 0);
- g_free (content);
-
- /* Insert span with image representation and another one with text
- * represetation and hide/show them dependant on active composer mode */
- /* ​ == UNICODE_ZERO_WIDTH_SPACE */
- html = g_strdup_printf (
- "<span class=\"-x-evo-smiley-wrapper -x-evo-resizable-wrapper\">"
- "<img src=\"%s\" alt=\"%s\" x-evo-smiley=\"%s\" "
- "class=\"-x-evo-smiley-img\" data-inline data-name=\"%s\"/>"
- "<span class=\"-x-evo-smiley-text\" style=\"display: none;\">%s"
- "</span></span>%s",
- output, emoticon ? emoticon->text_face : "", emoticon->icon_name,
- load_context->name, emoticon ? emoticon->text_face : "",
- empty ? "​" : "");
-
- span = webkit_dom_document_create_element (document, "SPAN", NULL);
-
- if (misplaced_selection) {
- /* Insert smiley and selection markers after it */
- webkit_dom_node_insert_before (
- webkit_dom_node_get_parent_node (insert_before),
- WEBKIT_DOM_NODE (selection_start_marker),
- webkit_dom_node_get_next_sibling (next_sibling),
- NULL);
- webkit_dom_node_insert_before (
- webkit_dom_node_get_parent_node (insert_before),
- WEBKIT_DOM_NODE (selection_end_marker),
- webkit_dom_node_get_next_sibling (next_sibling),
- NULL);
- span = WEBKIT_DOM_ELEMENT (
- webkit_dom_node_insert_before (
- webkit_dom_node_get_parent_node (insert_before),
- WEBKIT_DOM_NODE (span),
- webkit_dom_node_get_next_sibling (next_sibling),
- NULL));
- } else {
- span = WEBKIT_DOM_ELEMENT (
- webkit_dom_node_insert_before (
- webkit_dom_node_get_parent_node (insert_before),
- WEBKIT_DOM_NODE (span),
- insert_before,
- NULL));
- }
-
- webkit_dom_html_element_set_outer_html (
- WEBKIT_DOM_HTML_ELEMENT (span), html, NULL);
-
- if (node_text) {
- emoticon_start = g_utf8_strrchr (
- node_text, -1, g_utf8_get_char (emoticon->text_face));
- if (emoticon_start) {
- webkit_dom_character_data_delete_data (
- WEBKIT_DOM_CHARACTER_DATA (node),
- g_utf8_strlen (node_text, -1) - strlen (emoticon_start),
- strlen (emoticon->text_face),
- NULL);
- }
- }
-
- e_html_editor_selection_restore (
- e_html_editor_view_get_selection (view));
-
- e_html_editor_view_set_changed (view, TRUE);
-
- g_free (html);
- g_free (node_text);
- g_free (base64_encoded);
- g_free (output);
- g_free (mime_type);
- g_object_unref (output_stream);
- out:
- emoticon_load_context_free (load_context);
-}
-
-static void
-emoticon_query_info_async_cb (GFile *file,
- GAsyncResult *result,
- LoadContext *load_context)
-{
- GError *error = NULL;
- GFileInfo *info;
-
- info = g_file_query_info_finish (file, result, &error);
- g_return_if_fail (!error && info);
-
- load_context->content_type = g_strdup (g_file_info_get_content_type (info));
- load_context->name = g_strdup (g_file_info_get_name (info));
-
- g_file_read_async (
- file, G_PRIORITY_DEFAULT, NULL,
- (GAsyncReadyCallback) emoticon_read_async_cb, load_context);
-
- g_object_unref (info);
-}
-
-void
-e_html_editor_view_insert_smiley (EHTMLEditorView *view,
- EEmoticon *emoticon)
-{
- GFile *file;
- gchar *filename_uri;
- LoadContext *load_context;
-
- filename_uri = e_emoticon_get_uri (emoticon);
- g_return_if_fail (filename_uri != NULL);
-
- load_context = emoticon_load_context_new (view, emoticon);
-
- file = g_file_new_for_uri (filename_uri);
- g_file_query_info_async (
- file, "standard::*", G_FILE_QUERY_INFO_NONE,
- G_PRIORITY_DEFAULT, NULL,
- (GAsyncReadyCallback) emoticon_query_info_async_cb, load_context);
-
- g_free (filename_uri);
- g_object_unref (file);
-}
-
-static void
-html_editor_view_check_magic_smileys (EHTMLEditorView *view,
- WebKitDOMRange *range)
-{
- gint pos;
- gint state;
- gint relative;
- gint start;
- gchar *node_text;
- gunichar uc;
- WebKitDOMNode *node;
-
- node = webkit_dom_range_get_end_container (range, NULL);
- if (!WEBKIT_DOM_IS_TEXT (node))
- return;
-
- node_text = webkit_dom_text_get_whole_text (WEBKIT_DOM_TEXT (node));
- if (node_text == NULL)
- return;
-
- start = webkit_dom_range_get_end_offset (range, NULL) - 1;
- pos = start;
- state = 0;
- while (pos >= 0) {
- uc = g_utf8_get_char (g_utf8_offset_to_pointer (node_text, pos));
- relative = 0;
- while (emoticons_chars[state + relative]) {
- if (emoticons_chars[state + relative] == uc)
- break;
- relative++;
- }
- state = emoticons_states[state + relative];
- /* 0 .. not found, -n .. found n-th */
- if (state <= 0)
- break;
- pos--;
- }
-
- /* Special case needed to recognize angel and devilish. */
- if (pos > 0 && state == -14) {
- uc = g_utf8_get_char (g_utf8_offset_to_pointer (node_text, pos - 1));
- if (uc == 'O') {
- state = -1;
- pos--;
- } else if (uc == '>') {
- state = -5;
- pos--;
- }
- }
-
- if (state < 0) {
- const EEmoticon *emoticon;
-
- if (pos > 0) {
- uc = g_utf8_get_char (g_utf8_offset_to_pointer (node_text, pos - 1));
- if (!g_unichar_isspace (uc)) {
- g_free (node_text);
- return;
- }
- }
-
- emoticon = (e_emoticon_chooser_lookup_emoticon (
- emoticons_icon_names[-state - 1]));
- e_html_editor_view_insert_smiley (view, (EEmoticon *) emoticon);
- }
-
- g_free (node_text);
-}
-
static void
insert_and_convert_html_into_selection (EHTMLEditorView *view,
const gchar *text,
@@ -1150,7 +330,7 @@ insert_and_convert_html_into_selection (EHTMLEditorView *view,
g_dbus_proxy_call (
web_extension,
- "DOMInsertAndConvertHTMLIntoSelection",
+ "DOMConvertAndInsertHTMLIntoSelection",
g_variant_new (
"(tsb)",
webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
@@ -1354,8 +534,6 @@ html_editor_view_dispose (GObject *object)
g_clear_object (&priv->selection);
g_clear_object (&priv->web_extension);
- g_hash_table_remove_all (priv->inline_images);
-
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_html_editor_view_parent_class)->dispose (object);
}
@@ -1367,8 +545,6 @@ html_editor_view_finalize (GObject *object)
priv = E_HTML_EDITOR_VIEW_GET_PRIVATE (object);
- g_hash_table_destroy (priv->inline_images);
-
if (priv->old_settings) {
g_hash_table_destroy (priv->old_settings);
priv->old_settings = NULL;
@@ -1388,24 +564,29 @@ html_editor_view_finalize (GObject *object)
static void
html_editor_view_constructed (GObject *object)
{
+ WebKitSettings *web_settings;
e_extensible_load_extensions (E_EXTENSIBLE (object));
/* Chain up to parent's constructed() method. */
G_OBJECT_CLASS (e_html_editor_view_parent_class)->constructed (object);
-/* FIXME WK2
- WebKitSettings *web_settings;
web_settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (object));
+
+ g_object_set (
+ G_OBJECT (web_settings),
+ "enable-scripts", FALSE,
+ "enable-plugins", FALSE,
+ NULL);
+/* FIXME WK2
g_object_set (
G_OBJECT (web_settings),
"enable-dom-paste", TRUE,
"enable-file-access-from-file-uris", TRUE,
"enable-spell-checking", TRUE,
- NULL);
-*/
+ NULL);*/
}
-
+/* FIXME WK2
static void
html_editor_view_save_element_under_mouse_click (GtkWidget *widget)
{
@@ -1430,7 +611,7 @@ html_editor_view_save_element_under_mouse_click (GtkWidget *widget)
view = E_HTML_EDITOR_VIEW (widget);
view->priv->element_under_mouse = element;
}
-
+*/
static gboolean
html_editor_view_button_press_event (GtkWidget *widget,
GdkEventButton *event)
@@ -1442,7 +623,8 @@ html_editor_view_button_press_event (GtkWidget *widget,
g_signal_emit (widget, signals[PASTE_PRIMARY_CLIPBOARD], 0);
event_handled = TRUE;
} else if (event->button == 3) {
- html_editor_view_save_element_under_mouse_click (widget);
+/* FIXME WK2
+ html_editor_view_save_element_under_mouse_click (widget); */
g_signal_emit (
widget, signals[POPUP_EVENT],
0, event, &event_handled);
@@ -1458,50 +640,26 @@ html_editor_view_button_press_event (GtkWidget *widget,
button_press_event (widget, event);
}
-static gboolean
-html_editor_view_button_release_event (GtkWidget *widget,
- GdkEventButton *event)
+static void
+editor_view_mouse_target_changed_cb (EHTMLEditorView *view,
+ WebKitHitTestResult *hit_test_result,
+ guint modifiers,
+ gpointer user_data)
{
- WebKitWebView *webview;
- WebKitHitTestResult *hit_test;
- WebKitHitTestResultContext context;
- gchar *uri;
+ /* Ctrl + Left Click on link opens it. */
+ if (webkit_hit_test_result_context_is_link (hit_test_result) &&
+ (modifiers & GDK_CONTROL_MASK)) {
+ GdkScreen *screen;
+ const gchar *uri;
+ GtkWidget *toplevel;
- webview = WEBKIT_WEB_VIEW (widget);
- hit_test = webkit_web_view_get_hit_test_result (webview, event);
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
+ screen = gtk_window_get_screen (GTK_WINDOW (toplevel));
- g_object_get (
- hit_test,
- "context", &context,
- "link-uri", &uri,
- NULL);
-
- g_object_unref (hit_test);
-
- /* Left click on a link */
- if ((context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) &&
- (event->button == 1)) {
+ uri = webkit_hit_test_result_get_link_uri (hit_test_result);
- /* Ctrl + Left Click on link opens it, otherwise ignore the
- * click completely */
- if (event->state & GDK_CONTROL_MASK) {
- GtkWidget *toplevel;
- GdkScreen *screen;
-
- toplevel = gtk_widget_get_toplevel (widget);
- screen = gtk_window_get_screen (GTK_WINDOW (toplevel));
- gtk_show_uri (screen, uri, event->time, NULL);
- g_free (uri);
- }
-
- return TRUE;
+ gtk_show_uri (screen, uri, GDK_CURRENT_TIME, NULL);
}
-
- g_free (uri);
-
- /* Chain up to parent's button_release_event() method. */
- return GTK_WIDGET_CLASS (e_html_editor_view_parent_class)->
- button_release_event (widget, event);
}
static gboolean
@@ -1509,11 +667,13 @@ html_editor_view_key_press_event (GtkWidget *widget,
GdkEventKey *event)
{
EHTMLEditorView *view = E_HTML_EDITOR_VIEW (widget);
+ GDBusProxy *web_extension;
+ GVariant *result;
if (event->keyval == GDK_KEY_Menu) {
gboolean event_handled;
-
- html_editor_view_save_element_under_mouse_click (widget);
+/* FIXME WK2
+ html_editor_view_save_element_under_mouse_click (widget); */
g_signal_emit (
widget, signals[POPUP_EVENT],
0, event, &event_handled);
@@ -1521,214 +681,34 @@ html_editor_view_key_press_event (GtkWidget *widget,
return event_handled;
}
- if (event->keyval == GDK_KEY_Tab)
- return e_html_editor_view_exec_command (
- view, E_HTML_EDITOR_VIEW_COMMAND_INSERT_TEXT, "\t");
-
- if ((event->keyval == GDK_KEY_Control_L) ||
- (event->keyval == GDK_KEY_Control_R)) {
-
- html_editor_view_set_links_active (view, TRUE);
- }
-
- if (is_return_key (event)) {
- EHTMLEditorSelection *selection;
- EHTMLEditorSelectionBlockFormat format;
-
- selection = e_html_editor_view_get_selection (view);
- /* When user presses ENTER in a citation block, WebKit does
- * not break the citation automatically, so we need to use
- * the special command to do it. */
- if (e_html_editor_selection_is_citation (selection)) {
- remove_input_event_listener_from_body (view);
- return (insert_new_line_into_citation (view, "")) ? TRUE : FALSE;
- }
-
- /* When the return is pressed in a H1-6 element, WebKit doesn't
- * continue with the same element, but creates normal paragraph,
- * so we have to unset the bold font. */
- format = e_html_editor_selection_get_block_format (selection);
- if (format >= E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_H1 &&
- format <= E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_H6)
- e_html_editor_selection_set_bold (selection, FALSE);
- }
-
- if (event->keyval == GDK_KEY_BackSpace) {
- EHTMLEditorSelection *selection;
+ web_extension = e_html_editor_view_get_web_extension_proxy (view);
+ if (web_extension)
+ return FALSE;
- selection = e_html_editor_view_get_selection (view);
+ result = g_dbus_proxy_call_sync (
+ web_extension,
+ "DOMProcessOnKeyPress",
+ g_variant_new (
+ "(tu)",
+ webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
+ event->keyval),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL);
- /* BackSpace pressed in the beginning of quoted content changes
- * format to normal and inserts text into body */
- if (e_html_editor_selection_is_collapsed (selection)) {
- e_html_editor_selection_save (selection);
- if (change_quoted_block_to_normal (view)) {
- e_html_editor_selection_restore (selection);
- e_html_editor_view_force_spell_check_for_current_paragraph (view);
- return TRUE;
- }
- e_html_editor_selection_restore (selection);
- } else
- remove_input_event_listener_from_body (view);
-
- /* BackSpace in indented block decrease indent level by one */
- if (e_html_editor_selection_is_indented (selection)) {
- WebKitDOMElement *caret;
- WebKitDOMNode *prev_sibling;
-
- caret = e_html_editor_selection_save_caret_position (selection);
-
- /* Empty text node before caret */
- prev_sibling = webkit_dom_node_get_previous_sibling (
- WEBKIT_DOM_NODE (caret));
- if (prev_sibling && WEBKIT_DOM_IS_TEXT (prev_sibling)) {
- gchar *content;
-
- content = webkit_dom_node_get_text_content (prev_sibling);
- if (g_strcmp0 (content, "") == 0)
- prev_sibling = webkit_dom_node_get_previous_sibling (prev_sibling);
- g_free (content);
- }
+ if (result) {
+ gboolean ret_val = FALSE;
- if (!prev_sibling) {
- e_html_editor_selection_clear_caret_position_marker (selection);
- e_html_editor_selection_unindent (selection);
- return TRUE;
- } else
- e_html_editor_selection_clear_caret_position_marker (selection);
- }
+ ret_val = g_variant_get_boolean (result);
+ g_variant_unref (result);
- if (prevent_from_deleting_last_element_in_body (view))
- return TRUE;
+ if (ret_val)
+ return ret_val;
}
/* Chain up to parent's key_press_event() method. */
- return GTK_WIDGET_CLASS (e_html_editor_view_parent_class)->
- key_press_event (widget, event);
-}
-
-static gboolean
-html_editor_view_key_release_event (GtkWidget *widget,
- GdkEventKey *event)
-{
- EHTMLEditorView *view;
- EHTMLEditorSelection *selection;
-
- view = E_HTML_EDITOR_VIEW (widget);
- register_input_event_listener_on_body (view);
-
- selection = e_html_editor_view_get_selection (view);
- if (!e_html_editor_selection_is_collapsed (selection))
- goto out;
-
- /* This will fix the structure after the situations where some text
- * inside the quoted content is selected and afterwards deleted with
- * BackSpace or Delete. */
- if ((event->keyval == GDK_KEY_BackSpace) ||
- (event->keyval == GDK_KEY_Delete)) {
- gint level;
- WebKitDOMElement *selection_start_marker, *selection_end_marker;
- WebKitDOMElement *element;
- WebKitDOMDocument *document;
- WebKitDOMNode *node, *parent;
-
- document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (widget));
-
- e_html_editor_selection_save (selection);
- selection_start_marker = webkit_dom_document_get_element_by_id (
- document, "-x-evo-selection-start-marker");
- selection_end_marker = webkit_dom_document_get_element_by_id (
- document, "-x-evo-selection-end-marker");
-
- level = get_citation_level (
- WEBKIT_DOM_NODE (selection_start_marker), FALSE);
- if (level == 0)
- goto restore;
-
- node = webkit_dom_node_get_previous_sibling (
- WEBKIT_DOM_NODE (selection_start_marker));
-
- if (WEBKIT_DOM_IS_HTMLBR_ELEMENT (node))
- node = webkit_dom_node_get_previous_sibling (node);
-
- if (node)
- goto restore;
-
- parent = get_parent_block_node_from_child (
- WEBKIT_DOM_NODE (selection_start_marker));
-
- node = webkit_dom_node_get_previous_sibling (parent);
- if (!node) {
- /* Situation where the start of the selection was in the
- * multiple quoted content and that start on the beginning
- * of the citation.
- *
- * >
- * >> |
- * >> xx|x
- * */
- node = webkit_dom_node_get_parent_node (parent);
- if (!WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (node))
- goto restore;
- node = webkit_dom_node_get_previous_sibling (node);
- if (!node)
- goto restore;
- if (!WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (webkit_dom_node_get_parent_node (node)))
- goto restore;
- }
-
- element = webkit_dom_element_query_selector (
- WEBKIT_DOM_ELEMENT (node), "span.-x-evo-quote-character > br", NULL);
- if (element) {
- WebKitDOMNode *tmp;
-
- if (WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (node)) {
- /* We have to select the right block when the selection
- * started on the end of the citation that is
- * inside another citation.
- *
- * >>|
- * > xx|x
- */
- /* <span class="-x-evo-quote-character"> */
- node = webkit_dom_node_get_parent_node (
- WEBKIT_DOM_NODE (element));
- /* <span class="-x-evo-quoted"> */
- node = webkit_dom_node_get_parent_node (node);
- /* right block */
- node = webkit_dom_node_get_parent_node (node);
- }
-
- webkit_dom_node_append_child (
- node, WEBKIT_DOM_NODE (selection_start_marker), NULL);
-
- while ((tmp = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE
(selection_end_marker))))
- webkit_dom_node_append_child (node, tmp, NULL);
-
- webkit_dom_node_insert_before (
- node,
- WEBKIT_DOM_NODE (selection_end_marker),
- webkit_dom_node_get_next_sibling (
- WEBKIT_DOM_NODE (selection_start_marker)),
- NULL);
-
- webkit_dom_node_append_child (
- node, WEBKIT_DOM_NODE (element), NULL);
- remove_node (parent);
- }
- restore:
- e_html_editor_selection_restore (selection);
- }
-
- if ((event->keyval == GDK_KEY_Control_L) ||
- (event->keyval == GDK_KEY_Control_R)) {
-
- html_editor_view_set_links_active (view, FALSE);
- }
- out:
- /* Chain up to parent's key_release_event() method. */
- return GTK_WIDGET_CLASS (e_html_editor_view_parent_class)->
- key_release_event (widget, event);
+ return GTK_WIDGET_CLASS (e_html_editor_view_parent_class)->key_press_event (widget, event);
}
static void
@@ -1940,15 +920,15 @@ html_editor_view_constructor (GType type,
GParamSpec* param_spec;
GObjectConstructParam *param = NULL;
- object_class = G_OBJECT_CLASS(g_type_class_ref(type));
- g_return_val_if_fail(object_class != NULL, NULL);
+ object_class = G_OBJECT_CLASS (g_type_class_ref(type));
+ g_return_val_if_fail (object_class != NULL, NULL);
if (construct_properties && n_construct_properties != 0) {
param_spec = g_object_class_find_property(object_class, "settings");
- if ((param = find_property(n_construct_properties, construct_properties, param_spec)))
+ if ((param = find_property (n_construct_properties, construct_properties, param_spec)))
g_value_take_object (param->value, e_web_view_get_default_webkit_settings ());
param_spec = g_object_class_find_property(object_class, "user-content-manager");
- if ((param = find_property(n_construct_properties, construct_properties, param_spec)))
+ if ((param = find_property (n_construct_properties, construct_properties, param_spec)))
g_value_take_object (param->value, webkit_user_content_manager_new ());
}
@@ -1986,9 +966,7 @@ e_html_editor_view_class_init (EHTMLEditorViewClass *class)
widget_class = GTK_WIDGET_CLASS (class);
widget_class->button_press_event = html_editor_view_button_press_event;
- widget_class->button_release_event = html_editor_view_button_release_event;
widget_class->key_press_event = html_editor_view_key_press_event;
- widget_class->key_release_event = html_editor_view_key_release_event;
class->paste_clipboard_quoted = html_editor_view_paste_clipboard_quoted;
@@ -2163,7 +1141,7 @@ e_html_editor_view_class_init (EHTMLEditorViewClass *class)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
-
+#if 0 /* FIXME WK2 */
/**
* EHTMLEditorView:spell-checker:
*
@@ -2179,7 +1157,7 @@ e_html_editor_view_class_init (EHTMLEditorViewClass *class)
E_TYPE_SPELL_CHECKER,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
-
+#endif
/**
* EHTMLEditorView:popup-event
*
@@ -2371,9 +1349,6 @@ static void
html_editor_view_load_changed (EHTMLEditorView *view,
WebKitLoadEvent load_event)
{
- WebKitDOMDocument *document;
- WebKitDOMHTMLElement *body;
-
if (load_event != WEBKIT_LOAD_FINISHED)
return;
@@ -2399,42 +1374,43 @@ html_editor_view_load_changed (EHTMLEditorView *view,
view->priv->reload_in_progress = FALSE;
- document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
- body = webkit_dom_document_get_body (document);
-
- webkit_dom_element_remove_attribute (WEBKIT_DOM_ELEMENT (body), "style");
- webkit_dom_element_set_attribute (
- WEBKIT_DOM_ELEMENT (body), "data-message", "", NULL);
+}
- if (view->priv->convert_in_situ) {
- html_editor_convert_view_content (view, NULL);
- view->priv->convert_in_situ = FALSE;
+static void
+set_cached_boolean_property (EHTMLEditorView *view,
+ const gchar *property_name,
+ gboolean value)
+{
+ GDBusProxy *web_extension;
+ web_extension = e_html_editor_view_get_web_extension_proxy (view);
+ if (!web_extension)
return;
- }
- put_body_in_citation (document);
- move_elements_to_body (document);
- repair_gmail_blockquotes (document);
+ g_dbus_proxy_set_cached_property (
+ web_extension, property_name, g_variant_new_boolean (value));
+}
- if (webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (body), "data-evo-draft")) {
- /* Restore the selection how it was when the draft was saved */
- e_html_editor_selection_move_caret_into_element (
- document, WEBKIT_DOM_ELEMENT (body));
- e_html_editor_selection_restore (
- e_html_editor_view_get_selection (view));
- }
+static gboolean
+get_cached_boolean_property (EHTMLEditorView *view,
+ const gchar *property_name)
+{
+ gboolean value = FALSE;
+ GVariant *result;
+ GDBusProxy *web_extension;
- /* Register on input event that is called when the content (body) is modified */
- register_input_event_listener_on_body (view);
+ web_extension = e_html_editor_view_get_web_extension_proxy (view);
+ if (!web_extension)
+ return FALSE;
- if (view->priv->html_mode)
- change_cid_images_src_to_base64 (view);
+ result = g_dbus_proxy_get_cached_property (web_extension, property_name);
+ if (!result)
+ return FALSE;
- if (view->priv->inline_spelling)
- e_html_editor_view_force_spell_check (view);
- else
- e_html_editor_view_turn_spell_check_off (view);
+ value = g_variant_get_boolean (result);
+ g_variant_unref (result);
+
+ return value;
}
/**
@@ -2451,33 +1427,31 @@ void
e_html_editor_view_set_html_mode (EHTMLEditorView *view,
gboolean html_mode)
{
- EHTMLEditorSelection *selection;
- gboolean is_from_new_message, converted, edit_as_new, message, convert;
- gboolean reply, hide;
- WebKitDOMElement *blockquote;
- WebKitDOMHTMLElement *body;
- WebKitDOMDocument *document;
+ gboolean convert = FALSE;
+ GDBusProxy *web_extension;
+ GVariant *result;
g_return_if_fail (E_IS_HTML_EDITOR_VIEW (view));
- selection = e_html_editor_view_get_selection (view);
-
- document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
- body = webkit_dom_document_get_body (document);
-
- is_from_new_message = webkit_dom_element_has_attribute (
- WEBKIT_DOM_ELEMENT (body), "data-new-message");
- converted = webkit_dom_element_has_attribute (
- WEBKIT_DOM_ELEMENT (body), "data-converted");
- edit_as_new = webkit_dom_element_has_attribute (
- WEBKIT_DOM_ELEMENT (body), "data-edit-as-new");
- message = webkit_dom_element_has_attribute (
- WEBKIT_DOM_ELEMENT (body), "data-message");
+ web_extension = e_html_editor_view_get_web_extension_proxy (view);
+ if (!web_extension)
+ return;
- reply = !is_from_new_message && !edit_as_new && message;
- hide = !reply && !converted;
+ result = g_dbus_proxy_call_sync (
+ web_extension,
+ "DOMCheckIfConversionNeeded",
+ g_variant_new (
+ "(t)",
+ webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL);
- convert = message && ((!hide && reply && !converted) || (edit_as_new && !converted));
+ if (result) {
+ convert = g_variant_get_boolean (result);
+ g_variant_unref (result);
+ }
/* If toggling from HTML to plain text mode, ask user first */
if (convert && view->priv->html_mode && !html_mode) {
@@ -2485,23 +1459,14 @@ e_html_editor_view_set_html_mode (EHTMLEditorView *view,
return;
view->priv->html_mode = html_mode;
-
- GDBusProxy *web_extension;
-
- g_return_if_fail (view != NULL);
-
- web_extension = e_html_editor_view_get_web_extension_proxy (view);
- if (!web_extension)
- return;
+ set_cached_boolean_property (view, "HTMLMode", html_mode);
g_dbus_proxy_call (
web_extension,
"ConvertWhenChangingComposerMode",
g_variant_new (
- "(tsb)",
- webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
- text,
- TRUE),
+ "(t)",
+ webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
@@ -2511,10 +1476,6 @@ e_html_editor_view_set_html_mode (EHTMLEditorView *view,
/* Update fonts - in plain text we only want monospace */
e_html_editor_view_update_fonts (view);
- e_html_editor_view_force_spell_check (view);
-
- e_html_editor_selection_scroll_to_caret (selection);
-
goto out;
}
@@ -2523,50 +1484,20 @@ e_html_editor_view_set_html_mode (EHTMLEditorView *view,
view->priv->html_mode = html_mode;
+ g_dbus_proxy_call_sync (
+ web_extension,
+ "DOMProcessContentAfterModeChange",
+ g_variant_new (
+ "(t)",
+ webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL);
+
/* Update fonts - in plain text we only want monospace */
e_html_editor_view_update_fonts (view);
- blockquote = webkit_dom_document_query_selector (
- document, "blockquote[type|=cite]", NULL);
-
- if (view->priv->html_mode) {
- if (blockquote)
- e_html_editor_view_dequote_plain_text (view);
-
- toggle_paragraphs_style (view);
- toggle_smileys (view);
- remove_wrapping_from_document (view);
- } else {
- gchar *plain;
-
- e_html_editor_selection_save (selection);
-
- if (blockquote) {
- wrap_paragraphs_in_quoted_content (selection, document);
- quote_plain_text_elements_after_wrapping_in_document (
- document);
- }
-
- toggle_paragraphs_style (view);
- toggle_smileys (view);
- remove_images (view);
- remove_background_images_in_document (document);
-
- plain = process_content_for_mode_change (view);
-
- if (*plain) {
- webkit_dom_html_element_set_outer_html (
- WEBKIT_DOM_HTML_ELEMENT (
- webkit_dom_document_get_document_element (document)),
- plain,
- NULL);
- e_html_editor_selection_restore (selection);
- e_html_editor_view_force_spell_check (view);
- }
-
- g_free (plain);
- }
-
out:
g_object_notify (G_OBJECT (view), "html-mode");
}
@@ -2577,27 +1508,23 @@ e_html_editor_view_init (EHTMLEditorView *view)
WebKitSettings *settings;
GSettings *g_settings;
GSettingsSchema *settings_schema;
- ESpellChecker *checker;
+// ESpellChecker *checker;
gchar **languages;
gchar *comma_separated;
view->priv = E_HTML_EDITOR_VIEW_GET_PRIVATE (view);
-
- webkit_web_view_set_editable (WEBKIT_WEB_VIEW (view), TRUE);
+/* FIXME WK2
+ webkit_web_view_set_editable (WEBKIT_WEB_VIEW (view), TRUE); */
settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (view));
view->priv->old_settings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)
g_variant_unref);
/* Override the spell-checker, use our own */
+/* FIXME WK2
checker = e_spell_checker_new ();
webkit_set_text_checker (G_OBJECT (checker));
g_object_unref (checker);
- /* Don't use CSS when possible to preserve compatibility with older
- * versions of Evolution or other MUAs */
- e_html_editor_view_exec_command (
- view, E_HTML_EDITOR_VIEW_COMMAND_STYLE_WITH_CSS, "false");
-
g_signal_connect (
view, "user-changed-contents",
G_CALLBACK (html_editor_view_user_changed_contents_cb), NULL);
@@ -2606,12 +1533,15 @@ e_html_editor_view_init (EHTMLEditorView *view)
G_CALLBACK (html_editor_view_selection_changed_cb), NULL);
g_signal_connect (
view, "should-show-delete-interface-for-element",
- G_CALLBACK (html_editor_view_should_show_delete_interface_for_element), NULL);
+ G_CALLBACK (html_editor_view_should_show_delete_interface_for_element), NULL);*/
g_signal_connect (
view, "load-changed",
G_CALLBACK (html_editor_view_load_changed), NULL);
+ g_signal_connect (
+ view, "mouse-target-changed",
+ G_CALLBACK (editor_view_mouse_target_changed_cb), NULL);
- e_signal_connect (
+ g_signal_connect (
webkit_web_context_get_default (), "initialize-web-extensions",
G_CALLBACK (initialize_web_extensions_cb), NULL);
@@ -2646,14 +1576,10 @@ e_html_editor_view_init (EHTMLEditorView *view)
view->priv->aliasing_settings = g_settings;
}
- view->priv->inline_images = g_hash_table_new_full (
- g_str_hash, g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) g_free);
-
e_html_editor_view_update_fonts (view);
/* Give spell check languages to WebKit */
+/* FIXME WK2
languages = e_spell_checker_list_active_languages (checker, NULL);
comma_separated = g_strjoinv (",", languages);
g_strfreev (languages);
@@ -2664,7 +1590,7 @@ e_html_editor_view_init (EHTMLEditorView *view)
NULL);
g_free (comma_separated);
-
+*/
view->priv->body_input_event_removed = TRUE;
view->priv->is_message_from_draft = FALSE;
view->priv->is_message_from_selection = FALSE;
@@ -2672,18 +1598,9 @@ e_html_editor_view_init (EHTMLEditorView *view)
view->priv->remove_initial_input_line = FALSE;
view->priv->convert_in_situ = FALSE;
- g_object_set (
- G_OBJECT (settings),
- "enable-scripts", FALSE,
- "enable-plugins", FALSE,
- NULL);
-
/* Make WebKit think we are displaying a local file, so that it
* does not block loading resources from file:// protocol */
webkit_web_view_load_html (WEBKIT_WEB_VIEW (view), "", "file://");
-
- html_editor_view_set_links_active (view, FALSE);
-
}
/**
@@ -2722,11 +1639,12 @@ e_html_editor_view_set_inline_spelling (EHTMLEditorView *view,
view->priv->inline_spelling = inline_spelling;
+/* FIXME WK2
if (inline_spelling)
e_html_editor_view_force_spell_check (view);
else
e_html_editor_view_turn_spell_check_off (view);
-
+*/
g_object_notify (G_OBJECT (view), "inline-spelling");
}
@@ -2818,7 +1736,9 @@ e_html_editor_view_set_magic_smileys (EHTMLEditorView *view,
ESpellChecker *
e_html_editor_view_get_spell_checker (EHTMLEditorView *view)
{
- return E_SPELL_CHECKER (webkit_get_text_checker ());
+/* FIXME WK2
+ return E_SPELL_CHECKER (webkit_get_text_checker ());*/
+ return NULL;
}
static gchar *
@@ -2919,6 +1839,54 @@ e_html_editor_view_convert_and_insert_html_to_plain_text (EHTMLEditorView *view,
}
/**
+ * e_html_editor_selection_insert_text:
+ * @selection: an #EHTMLEditorSelection
+ * @plain_text: text to insert
+ *
+ * Inserts @plain_text at current cursor position. When a text range is selected,
+ * it will be replaced by @plain_text.
+ */
+void
+e_html_editor_view_insert_text (EHTMLEditorView *view,
+ const gchar *plain_text)
+{
+ g_return_if_fail (E_IS_HTML_EDITOR_VIEW (view));
+ g_return_if_fail (plain_text != NULL);
+
+ e_html_editor_view_convert_and_insert_plain_text (view, plain_text);
+}
+
+void
+e_html_editor_view_insert_html (EHTMLEditorView *view,
+ const gchar *html_text)
+{
+ GDBusProxy *web_extension;
+
+ g_return_if_fail (E_IS_HTML_EDITOR_VIEW (view));
+ g_return_if_fail (html_text != NULL);
+
+ if (!html_text || !*html_text)
+ return;
+
+ web_extension = e_html_editor_view_get_web_extension_proxy (view);
+ if (!web_extension)
+ return;
+
+ g_dbus_proxy_call (
+ web_extension,
+ "DOMInsertHTML",
+ g_variant_new (
+ "(ts)",
+ webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
+ html_text),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL,
+ NULL);
+}
+
+/**
* e_html_editor_view_set_text_html:
* @view: an #EHTMLEditorView
* @text: HTML code to load into the editor
@@ -2929,6 +1897,7 @@ void
e_html_editor_view_set_text_html (EHTMLEditorView *view,
const gchar *text)
{
+#if 0 /* FIXME WK2 */
WebKitLoadStatus status;
/* It can happen that the view is not ready yet (it is in the middle of
@@ -2944,6 +1913,15 @@ e_html_editor_view_set_text_html (EHTMLEditorView *view,
g_free);
return;
}
+#endif
+ if (view->priv->reload_in_progress) {
+ html_editor_view_queue_post_reload_operation (
+ view,
+ (PostReloadOperationFunc) e_html_editor_view_set_text_html,
+ g_strdup (text),
+ g_free);
+ return;
+ }
view->priv->reload_in_progress = TRUE;
@@ -2985,6 +1963,8 @@ void
e_html_editor_view_set_text_plain (EHTMLEditorView *view,
const gchar *text)
{
+ GDBusProxy *web_extension;
+#if 0 /* FIXME WK2 */
WebKitLoadStatus status;
/* It can happen that the view is not ready yet (it is in the middle of
@@ -3000,10 +1980,33 @@ e_html_editor_view_set_text_plain (EHTMLEditorView *view,
g_free);
return;
}
-
+#endif
+ if (view->priv->reload_in_progress) {
+ html_editor_view_queue_post_reload_operation (
+ view,
+ (PostReloadOperationFunc) e_html_editor_view_set_text_html,
+ g_strdup (text),
+ g_free);
+ return;
+ }
view->priv->reload_in_progress = TRUE;
- html_editor_convert_view_content (view, text);
+ web_extension = e_html_editor_view_get_web_extension_proxy (view);
+ if (!web_extension)
+ return;
+
+ g_dbus_proxy_call (
+ web_extension,
+ "DOMConvertContent",
+ g_variant_new (
+ "(ts)",
+ webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
+ text),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL,
+ NULL);
}
/**
@@ -3137,13 +2140,15 @@ e_html_editor_view_update_fonts (EHTMLEditorView *view)
gboolean mark_citations, use_custom_font;
GdkColor *link = NULL;
GdkColor *visited = NULL;
- gchar *base64, *font, *aa = NULL, *citation_color;
+ gchar *font, *aa = NULL, *citation_color;
const gchar *styles[] = { "normal", "oblique", "italic" };
const gchar *smoothing = NULL;
GString *stylesheet;
GtkStyleContext *context;
PangoFontDescription *ms, *vw;
WebKitSettings *settings;
+ WebKitUserContentManager *manager;
+ WebKitUserStyleSheet *style_sheet;
g_return_if_fail (E_IS_HTML_EDITOR_VIEW (view));
@@ -3504,70 +2509,43 @@ e_html_editor_view_update_fonts (EHTMLEditorView *view)
gdk_color_free (link);
gdk_color_free (visited);
- base64 = g_base64_encode ((guchar *) stylesheet->str, stylesheet->len);
- g_string_free (stylesheet, TRUE);
-
- stylesheet = g_string_new ("data:text/css;charset=utf-8;base64,");
- g_string_append (stylesheet, base64);
- g_free (base64);
-
settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (view));
g_object_set (
G_OBJECT (settings),
- "default-font-size", pango_font_description_get_size (vw) / PANGO_SCALE,
- "default-font-family", pango_font_description_get_family (vw),
- "monospace-font-family", pango_font_description_get_family (ms),
- "default-monospace-font-size", (pango_font_description_get_size (ms) / PANGO_SCALE),
- "user-stylesheet-uri", stylesheet->str,
+ "default-font-size",
+ e_util_normalize_font_size (
+ GTK_WIDGET (view), pango_font_description_get_size (vw) / PANGO_SCALE),
+ "default-font-family",
+ pango_font_description_get_family (vw),
+ "monospace-font-family",
+ pango_font_description_get_family (ms),
+ "default-monospace-font-size",
+ e_util_normalize_font_size (
+ GTK_WIDGET (view), pango_font_description_get_size (ms) / PANGO_SCALE),
NULL);
- g_string_free (stylesheet, TRUE);
+ manager = webkit_web_view_get_user_content_manager (WEBKIT_WEB_VIEW (view));
+ webkit_user_content_manager_remove_all_style_sheets (manager);
- pango_font_description_free (ms);
- pango_font_description_free (vw);
-}
+ style_sheet = webkit_user_style_sheet_new (
+ stylesheet->str,
+ WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
+ WEBKIT_USER_STYLE_LEVEL_USER,
+ NULL,
+ NULL);
-/**
- * e_html_editor_view_get_element_under_mouse_click:
- * @view: an #EHTMLEditorView
- *
- * Returns DOM element, that was clicked on.
- *
- * Returns: DOM element on that was clicked.
- */
-WebKitDOMElement *
-e_html_editor_view_get_element_under_mouse_click (EHTMLEditorView *view)
-{
- g_return_val_if_fail (E_IS_HTML_EDITOR_VIEW (view), NULL);
+ webkit_user_content_manager_add_style_sheet (manager, style_sheet);
- return view->priv->element_under_mouse;
-}
+ webkit_user_style_sheet_unref (style_sheet);
-/**
- * e_html_editor_view_check_magic_links
- * @view: an #EHTMLEditorView
- * @include_space: If TRUE the pattern for link expects space on end
- *
- * Check if actual selection in given editor is link. If so, it is surrounded
- * with ANCHOR element.
- */
-void
-e_html_editor_view_check_magic_links (EHTMLEditorView *view,
- gboolean include_space)
-{
- WebKitDOMRange *range;
-
- g_return_if_fail (E_IS_HTML_EDITOR_VIEW (view));
-
- range = dom_get_range (view);
- html_editor_view_check_magic_links (view, range, include_space);
+ pango_font_description_free (ms);
+ pango_font_description_free (vw);
}
static CamelMimePart *
-e_html_editor_view_add_inline_image_from_element (EHTMLEditorView *view,
- WebKitDOMElement *element,
- const gchar *attribute,
- const gchar *uid_domain)
+create_part_for_inline_image_from_element_data (const gchar *element_src,
+ const gchar *name,
+ const gchar *id)
{
CamelStream *stream;
CamelDataWrapper *wrapper;
@@ -3575,17 +2553,9 @@ e_html_editor_view_add_inline_image_from_element (EHTMLEditorView *view,
gsize decoded_size;
gssize size;
gchar *mime_type = NULL;
- gchar *element_src, *cid, *name;
const gchar *base64_encoded_data;
guchar *base64_decoded_data;
- if (!WEBKIT_DOM_IS_ELEMENT (element)) {
- return NULL;
- }
-
- element_src = webkit_dom_element_get_attribute (
- WEBKIT_DOM_ELEMENT (element), attribute);
-
base64_encoded_data = strstr (element_src, ";base64,");
if (!base64_encoded_data)
goto out;
@@ -3617,15 +2587,11 @@ e_html_editor_view_add_inline_image_from_element (EHTMLEditorView *view,
camel_medium_set_content (CAMEL_MEDIUM (part), wrapper);
g_object_unref (wrapper);
- cid = camel_header_msgid_generate (uid_domain);
- camel_mime_part_set_content_id (part, cid);
- name = webkit_dom_element_get_attribute (element, "data-name");
+ camel_mime_part_set_content_id (part, id);
camel_mime_part_set_filename (part, name);
- g_free (name);
camel_mime_part_set_encoding (part, CAMEL_TRANSFER_ENCODING_BASE64);
out:
g_free (mime_type);
- g_free (element_src);
g_free (base64_decoded_data);
return part;
@@ -3633,84 +2599,45 @@ out:
GList *
e_html_editor_view_get_parts_for_inline_images (EHTMLEditorView *view,
- const gchar *uid_domain)
+ const gchar *uid_domain)
{
- GHashTable *added;
+ GDBusProxy *web_extension;
GList *parts = NULL;
- gint length, ii;
- WebKitDOMDocument *document;
- WebKitDOMNodeList *list;
+ GVariant *result;
- document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
- list = webkit_dom_document_query_selector_all (document, "img[data-inline]", NULL);
+ g_return_val_if_fail (E_IS_HTML_EDITOR_VIEW (view), NULL);
- length = webkit_dom_node_list_get_length (list);
- if (length == 0)
- return parts;
+ web_extension = e_html_editor_view_get_web_extension_proxy (view);
+ if (!web_extension)
+ return NULL;
- added = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
- for (ii = 0; ii < length; ii++) {
- const gchar *id;
- gchar *cid;
- WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
- gchar *src = webkit_dom_element_get_attribute (
- WEBKIT_DOM_ELEMENT (node), "src");
+ result = g_dbus_proxy_call_sync (
+ web_extension,
+ "DOMGetInlineImagesData",
+ g_variant_new (
+ "(ts)",
+ uid_domain,
+ webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL);
- if ((id = g_hash_table_lookup (added, src)) != NULL) {
- cid = g_strdup_printf ("cid:%s", id);
- } else {
+ if (result) {
+ const gchar *element_src, *name, *id;
+ GVariantIter *iter;
+
+ g_variant_get (result, "asss", &iter);
+ while (g_variant_iter_loop (iter, "&s&s&s", &element_src, &name, &id)) {
CamelMimePart *part;
- part = e_html_editor_view_add_inline_image_from_element (
- view, WEBKIT_DOM_ELEMENT (node), "src", uid_domain);
+ part = create_part_for_inline_image_from_element_data (
+ element_src, name, id);
parts = g_list_append (parts, part);
-
- id = camel_mime_part_get_content_id (part);
- cid = g_strdup_printf ("cid:%s", id);
-
- g_hash_table_insert (added, src, (gpointer) id);
- }
- webkit_dom_element_set_attribute (
- WEBKIT_DOM_ELEMENT (node), "src", cid, NULL);
- g_free (src);
- g_free (cid);
- }
- g_object_unref (list);
-
- list = webkit_dom_document_query_selector_all (
- document, "[data-inline][background]", NULL);
- length = webkit_dom_node_list_get_length (list);
- for (ii = 0; ii < length; ii++) {
- CamelMimePart *part;
- const gchar *id;
- gchar *cid = NULL;
- WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
- gchar *src = webkit_dom_element_get_attribute (
- WEBKIT_DOM_ELEMENT (node), "background");
-
- if ((id = g_hash_table_lookup (added, src)) != NULL) {
- cid = g_strdup_printf ("cid:%s", id);
- webkit_dom_element_set_attribute (
- WEBKIT_DOM_ELEMENT (node), "background", cid, NULL);
- } else {
- part = e_html_editor_view_add_inline_image_from_element (
- view, WEBKIT_DOM_ELEMENT (node), "background", uid_domain);
- if (part) {
- parts = g_list_append (parts, part);
- id = camel_mime_part_get_content_id (part);
- g_hash_table_insert (added, src, (gpointer) id);
- cid = g_strdup_printf ("cid:%s", id);
- webkit_dom_element_set_attribute (
- WEBKIT_DOM_ELEMENT (node), "background", cid, NULL);
- }
}
- g_free (src);
- g_free (cid);
+ g_variant_iter_free (iter);
}
- g_object_unref (list);
- g_hash_table_destroy (added);
-
return parts;
}
@@ -3727,10 +2654,15 @@ e_html_editor_view_add_inline_image_from_mime_part (EHTMLEditorView *view,
{
CamelDataWrapper *dw;
CamelStream *stream;
+ GDBusProxy *web_extension;
GByteArray *byte_array;
gchar *src, *base64_encoded, *mime_type, *cid_src;
const gchar *cid, *name;
+ web_extension = e_html_editor_view_get_web_extension_proxy (view);
+ if (!web_extension)
+ return;
+
stream = camel_stream_mem_new ();
dw = camel_medium_get_content (CAMEL_MEDIUM (part));
g_return_if_fail (dw);
@@ -3757,7 +2689,19 @@ e_html_editor_view_add_inline_image_from_mime_part (EHTMLEditorView *view,
}
cid_src = g_strdup_printf ("cid:%s", cid);
- g_hash_table_insert (view->priv->inline_images, cid_src, src);
+ g_dbus_proxy_call (
+ web_extension,
+ "DOMAddNewInlineImageIntoList",
+ g_variant_new (
+ "(tss)",
+ webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
+ cid_src,
+ src),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL,
+ NULL);
g_free (base64_encoded);
g_free (mime_type);
@@ -3778,7 +2722,7 @@ e_html_editor_view_is_message_from_draft (EHTMLEditorView *view)
{
g_return_val_if_fail (E_IS_HTML_EDITOR_VIEW (view), FALSE);
- return view->priv->is_message_from_draft;
+ return get_cached_boolean_property (view, "IsMessageFromDraft");
}
void
@@ -3795,7 +2739,7 @@ e_html_editor_view_is_message_from_edit_as_new (EHTMLEditorView *view)
{
g_return_val_if_fail (E_IS_HTML_EDITOR_VIEW (view), FALSE);
- return view->priv->is_message_from_edit_as_new;
+ return get_cached_boolean_property (view, "IsMessageFromEditAsNew");
}
void
e_html_editor_view_set_is_message_from_edit_as_new (EHTMLEditorView *view,
diff --git a/e-util/e-html-editor-view.h b/e-util/e-html-editor-view.h
index 37883a0..d8dc408 100644
--- a/e-util/e-html-editor-view.h
+++ b/e-util/e-html-editor-view.h
@@ -140,6 +140,10 @@ void e_html_editor_view_convert_and_insert_plain_text
void e_html_editor_view_convert_and_insert_html_to_plain_text
(EHTMLEditorView *view,
const gchar *html);
+void e_html_editor_view_insert_text (EHTMLEditorView *view,
+ const gchar *text);
+void e_html_editor_view_insert_html (EHTMLEditorView *view,
+ const gchar *html_text);
void e_html_editor_view_set_text_html
(EHTMLEditorView *view,
const gchar *text);
@@ -158,11 +162,11 @@ void e_html_editor_view_update_fonts (EHTMLEditorView *view);
WebKitDOMElement *
e_html_editor_view_get_element_under_mouse_click
(EHTMLEditorView *view);
-*/
+
void e_html_editor_view_check_magic_links
(EHTMLEditorView *view,
gboolean while_typing);
-/*
+
WebKitDOMElement *
e_html_editor_view_quote_plain_text_element
(EHTMLEditorView *view,
diff --git a/e-util/web-extensions/e-html-editor-web-extension-main.c
b/e-util/e-html-editor-web-extension-main.c
similarity index 100%
rename from e-util/web-extensions/e-html-editor-web-extension-main.c
rename to e-util/e-html-editor-web-extension-main.c
diff --git a/e-util/web-extensions/e-html-editor-web-extension-names.h
b/e-util/e-html-editor-web-extension-names.h
similarity index 100%
copy from e-util/web-extensions/e-html-editor-web-extension-names.h
copy to e-util/e-html-editor-web-extension-names.h
diff --git a/e-util/web-extensions/e-html-editor-web-extension.c b/e-util/e-html-editor-web-extension.c
similarity index 84%
rename from e-util/web-extensions/e-html-editor-web-extension.c
rename to e-util/e-html-editor-web-extension.c
index 6455ba9..8ad9e5f 100644
--- a/e-util/web-extensions/e-html-editor-web-extension.c
+++ b/e-util/e-html-editor-web-extension.c
@@ -26,22 +26,27 @@
#include <gtk/gtk.h>
#include <webkit2/webkit-web-extension.h>
-#include <e-util/e-dom-utils.h>
-#include <e-util/e-html-editor-actions-dom-functions.h>
-#include <e-util/e-html-editor-cell-dialog-dom-functions.h>
-#include <e-util/e-html-editor-dom-functions.h>
-#include <e-util/e-html-editor-hrule-dialog-dom-functions.h>
-#include <e-util/e-html-editor-image-dialog-dom-functions.h>
-#include <e-util/e-html-editor-link-dialog-dom-functions.h>
-#include <e-util/e-html-editor-selection-dom-functions.h>
-#include <e-util/e-html-editor-table-dialog-dom-functions.h>
-#include <e-util/e-html-editor-view-dom-functions.h>
+#include <camel/camel.h>
+
+#include "e-misc-utils.h"
+
+#include "e-dom-utils.h"
+#include "e-html-editor-actions-dom-functions.h"
+#include "e-html-editor-cell-dialog-dom-functions.h"
+#include "e-html-editor-dom-functions.h"
+#include "e-html-editor-hrule-dialog-dom-functions.h"
+#include "e-html-editor-image-dialog-dom-functions.h"
+#include "e-html-editor-link-dialog-dom-functions.h"
+#include "e-html-editor-selection-dom-functions.h"
+#include "e-html-editor-spell-check-dialog-dom-functions.h"
+#include "e-html-editor-table-dialog-dom-functions.h"
+#include "e-html-editor-view-dom-functions.h"
#define E_HTML_EDITOR_WEB_EXTENSION_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_HTML_EDITOR_WEB_EXTENSION, EHTMLEditorWebExtensionPrivate))
-struct _EWebExtensionPrivate {
+struct _EHTMLEditorWebExtensionPrivate {
WebKitWebExtension *wk_extension;
GDBusConnection *dbus_connection;
@@ -73,6 +78,15 @@ struct _EWebExtensionPrivate {
gboolean return_key_pressed;
gboolean space_key_pressed;
gint word_wrap_length;
+
+ gboolean convert_in_situ;
+ gboolean body_input_event_removed;
+ gboolean is_message_from_draft;
+ gboolean is_message_from_edit_as_new;
+ gboolean is_message_from_selection;
+ gboolean remove_initial_input_line;
+
+ GHashTable *inline_images;
};
static CamelDataCache *emd_global_http_cache = NULL;
@@ -87,6 +101,10 @@ static const char introspection_xml[] =
" <property type='b' name='InlineSpelling' access='readwrite'/>"
" <property type='b' name='MagicLinks' access='readwrite'/>"
" <property type='b' name='HTMLMode' access='readwrite'/>"
+" <property type='b' name='IsMessageFromEditAsNew' access='readwrite'/>"
+" <property type='b' name='IsMessageFromDraft' access='readwrite'/>"
+" <property type='b' name='IsMessageFromSelection' access='readwrite'/>"
+" <property type='b' name='RemoveInitialInputLine' access='readwrite'/>"
"<!-- ********************************************************* -->"
"<!-- These properties show the actual state of EHTMLEditorView -->"
"<!-- ********************************************************* -->"
@@ -295,6 +313,19 @@ static const char introspection_xml[] =
" <arg type='s' name='inner_text' direction='in'/>"
" </method>"
"<!-- ********************************************************* -->"
+"<!-- Functions that are used in EHTMLEditorSpellCheckDialog -->"
+"<!-- ********************************************************* -->"
+" <method name='EHTMLEditorSpellCheckDialogNext'>"
+" <arg type='t' name='page_id' direction='in'/>"
+" <arg type='s' name='word' direction='in'/>"
+" <arg type='s' name='next_word' direction='out'/>"
+" </method>"
+" <method name='EHTMLEditorSpellCheckDialogPrev'>"
+" <arg type='t' name='page_id' direction='in'/>"
+" <arg type='s' name='word' direction='in'/>"
+" <arg type='s' name='prev_word' direction='out'/>"
+" </method>"
+"<!-- ********************************************************* -->"
"<!-- Functions that are used in EHTMLEditorTableDialog -->"
"<!-- ********************************************************* -->"
" <method name='EHTMLEditorTableDialogSetRowCount'>"
@@ -335,6 +366,8 @@ static const char introspection_xml[] =
" </interface>"
"</node>";
+G_DEFINE_TYPE (EHTMLEditorWebExtension, e_html_editor_web_extension, G_TYPE_OBJECT)
+
static WebKitWebPage *
get_webkit_web_page_or_return_dbus_error (GDBusMethodInvocation *invocation,
WebKitWebExtension *web_extension,
@@ -365,7 +398,7 @@ handle_method_call (GDBusConnection *connection,
WebKitWebExtension *web_extension = extension->priv->wk_extension;
WebKitWebPage *web_page;
- if (g_strcmp0 (interface_name, EVOLUTION_WEB_EXTENSION_INTERFACE) != 0)
+ if (g_strcmp0 (interface_name, E_HTML_EDITOR_WEB_EXTENSION_INTERFACE) != 0)
return;
if (g_strcmp0 (method_name, "ElementHasAttribute") == 0) {
@@ -716,7 +749,7 @@ handle_method_call (GDBusConnection *connection,
g_dbus_method_invocation_return_value (invocation, NULL);
} else if (g_strcmp0 (method_name, "HRElementGetNoShade") == 0) {
- gboolean *value = FALSE;
+ gboolean value = FALSE;
const gchar *element_id;
WebKitDOMElement *element;
@@ -738,7 +771,6 @@ handle_method_call (GDBusConnection *connection,
invocation, g_variant_new_boolean (value));
} else if (g_strcmp0 (method_name, "EHTMLEditorImageDialogSetElementUrl") == 0) {
const gchar *value;
- guint scope;
g_variant_get (parameters, "(t&s)", &page_id, &value);
@@ -753,7 +785,6 @@ handle_method_call (GDBusConnection *connection,
g_dbus_method_invocation_return_value (invocation, NULL);
} else if (g_strcmp0 (method_name, "EHTMLEditorImageDialogGetElementUrl") == 0) {
gchar *value;
- guint scope;
g_variant_get (parameters, "(t)", &page_id);
@@ -932,7 +963,7 @@ handle_method_call (GDBusConnection *connection,
WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
g_dbus_method_invocation_return_value (
- invocation, g_variant_new_int32 (value);
+ invocation, g_variant_new_int32 (value));
} else if (g_strcmp0 (method_name, "ImageElementSetVSpace") == 0) {
const gchar *element_id;
glong value;
@@ -973,7 +1004,7 @@ handle_method_call (GDBusConnection *connection,
WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
g_dbus_method_invocation_return_value (
- invocation, g_variant_new_int32 (value);
+ invocation, g_variant_new_int32 (value));
} else if (g_strcmp0 (method_name, "EHTMLEditorLinkDialogOk") == 0) {
const gchar *url, *inner_text;
@@ -988,6 +1019,40 @@ handle_method_call (GDBusConnection *connection,
e_html_editor_link_dialog_ok (document, url, inner_text);
g_dbus_method_invocation_return_value (invocation, NULL);
+ } else if (g_strcmp0 (method_name, "EHTMLEditorSpellCheckDialogNext") == 0) {
+ const gchar *word;
+ gchar *value = NULL;
+
+ g_variant_get (parameters, "(t&s)", &page_id, &word);
+
+ web_page = get_webkit_web_page_or_return_dbus_error (
+ invocation, web_extension, page_id);
+ if (!web_page)
+ return;
+
+ document = webkit_web_page_get_dom_document (web_page);
+ value = e_html_editor_spell_check_dialog_next (document, word);
+
+ g_dbus_method_invocation_return_value (
+ invocation,
+ value ? g_variant_new_take_string (value) : NULL);
+ } else if (g_strcmp0 (method_name, "EHTMLEditorSpellCheckDialogPrev") == 0) {
+ const gchar *word;
+ gchar *value = NULL;
+
+ g_variant_get (parameters, "(t&s)", &page_id, &word);
+
+ web_page = get_webkit_web_page_or_return_dbus_error (
+ invocation, web_extension, page_id);
+ if (!web_page)
+ return;
+
+ document = webkit_web_page_get_dom_document (web_page);
+ value = e_html_editor_spell_check_dialog_prev (document, word);
+
+ g_dbus_method_invocation_return_value (
+ invocation,
+ value ? g_variant_new_take_string (value) : NULL);
} else if (g_strcmp0 (method_name, "EHTMLEditorTableDialogSetRowCount") == 0) {
gulong value;
@@ -1144,6 +1209,14 @@ handle_get_property (GDBusConnection *connection,
variant = g_variant_new_boolean (extension->priv->magic_links);
else if (g_strcmp0 (property_name, "HTMLMode") == 0)
variant = g_variant_new_boolean (extension->priv->html_mode);
+ else if (g_strcmp0 (property_name, "IsMessageFromEditAsNew") == 0)
+ variant = g_variant_new_boolean (extension->priv->is_message_from_edit_as_new);
+ else if (g_strcmp0 (property_name, "IsMessageFromDraft") == 0)
+ variant = g_variant_new_boolean (extension->priv->is_message_from_draft);
+ else if (g_strcmp0 (property_name, "IsMessageFromSelection") == 0)
+ variant = g_variant_new_boolean (extension->priv->is_message_from_selection);
+ else if (g_strcmp0 (property_name, "RemoveInitialInputLine") == 0)
+ variant = g_variant_new_boolean (extension->priv->remove_initial_input_line);
else if (g_strcmp0 (property_name, "Alignment") == 0)
variant = g_variant_new_int32 (extension->priv->alignment);
else if (g_strcmp0 (property_name, "BackgroundColor") == 0)
@@ -1208,6 +1281,90 @@ handle_set_property (GDBusConnection *connection,
"{sv}",
"ForceImageLoad",
g_variant_new_boolean (extension->priv->force_image_load));
+ } else if (g_strcmp0 (property_name, "IsMessageFromDraft") == 0) {
+ gboolean value = g_variant_get_boolean (variant);
+
+ if (value == extension->priv->is_message_from_draft)
+ goto exit;
+
+ extension->priv->is_message_from_draft = value;
+
+ g_variant_builder_add (builder,
+ "{sv}",
+ "IsMessageFromDraft",
+ g_variant_new_boolean (extension->priv->is_message_from_draft));
+ } else if (g_strcmp0 (property_name, "RemoveInitialInputLine") == 0) {
+ gboolean value = g_variant_get_boolean (variant);
+
+ if (value == extension->priv->remove_initial_input_line)
+ goto exit;
+
+ extension->priv->remove_initial_input_line = value;
+
+ g_variant_builder_add (builder,
+ "{sv}",
+ "RemoveInitialInputLine",
+ g_variant_new_boolean (extension->priv->remove_initial_input_line));
+ } else if (g_strcmp0 (property_name, "IsMessageFromSelection") == 0) {
+ gboolean value = g_variant_get_boolean (variant);
+
+ if (value == extension->priv->is_message_from_selection)
+ goto exit;
+
+ extension->priv->is_message_from_selection = value;
+
+ g_variant_builder_add (builder,
+ "{sv}",
+ "IsMessageFromSelection",
+ g_variant_new_boolean (extension->priv->is_message_from_selection));
+ } else if (g_strcmp0 (property_name, "IsMessageFromEditAsNew") == 0) {
+ gboolean value = g_variant_get_boolean (variant);
+
+ if (value == extension->priv->is_message_from_edit_as_new)
+ goto exit;
+
+ extension->priv->is_message_from_edit_as_new = value;
+
+ g_variant_builder_add (builder,
+ "{sv}",
+ "IsMessageFromEditAsNew",
+ g_variant_new_boolean (extension->priv->is_message_from_edit_as_new));
+ } else if (g_strcmp0 (property_name, "HTMLMode") == 0) {
+ gboolean value = g_variant_get_boolean (variant);
+
+ if (value == extension->priv->html_mode)
+ goto exit;
+
+ extension->priv->html_mode = value;
+
+ g_variant_builder_add (builder,
+ "{sv}",
+ "HTMLMode",
+ g_variant_new_boolean (extension->priv->html_mode));
+ } else if (g_strcmp0 (property_name, "MagicLinks") == 0) {
+ gboolean value = g_variant_get_boolean (variant);
+
+ if (value == extension->priv->magic_links)
+ goto exit;
+
+ extension->priv->magic_links = value;
+
+ g_variant_builder_add (builder,
+ "{sv}",
+ "MagicLinks",
+ g_variant_new_boolean (extension->priv->magic_links));
+ } else if (g_strcmp0 (property_name, "InlineSpelling") == 0) {
+ gboolean value = g_variant_get_boolean (variant);
+
+ if (value == extension->priv->inline_spelling)
+ goto exit;
+
+ extension->priv->inline_spelling = value;
+
+ g_variant_builder_add (builder,
+ "{sv}",
+ "InlineSpelling",
+ g_variant_new_boolean (extension->priv->inline_spelling));
} else if (g_strcmp0 (property_name, "Alignment") == 0) {
gint32 value = g_variant_get_int32 (variant);
@@ -1221,7 +1378,7 @@ handle_set_property (GDBusConnection *connection,
"Alignment",
g_variant_new_int32 (extension->priv->alignment));
} else if (g_strcmp0 (property_name, "BackgroundColor") == 0) {
- const gchar *value = g_variant_get_string (variant);
+ const gchar *value = g_variant_get_string (variant, NULL);
if (g_strcmp0 (value, extension->priv->background_color) != 0)
goto exit;
@@ -1258,7 +1415,7 @@ handle_set_property (GDBusConnection *connection,
"Bold",
g_variant_new_boolean (extension->priv->bold));
} else if (g_strcmp0 (property_name, "FontColor") == 0) {
- const gchar *value = g_variant_get_string (variant);
+ const gchar *value = g_variant_get_string (variant, NULL);
if (g_strcmp0 (value, extension->priv->font_color) != 0)
goto exit;
@@ -1271,7 +1428,7 @@ handle_set_property (GDBusConnection *connection,
"FontColor",
g_variant_new_string (extension->priv->font_color));
} else if (g_strcmp0 (property_name, "FontName") == 0) {
- const gchar *value = g_variant_get_string (variant);
+ const gchar *value = g_variant_get_string (variant, NULL);
if (g_strcmp0 (value, extension->priv->font_name) != 0)
goto exit;
@@ -1380,7 +1537,7 @@ handle_set_property (GDBusConnection *connection,
"Undeline",
g_variant_new_boolean (extension->priv->underline));
} else if (g_strcmp0 (property_name, "Text") == 0) {
- const gchar *value = g_variant_get_string (variant);
+ const gchar *value = g_variant_get_string (variant, NULL);
if (g_strcmp0 (value, extension->priv->text) != 0)
goto exit;
@@ -1421,7 +1578,7 @@ static const GDBusInterfaceVTable interface_vtable = {
};
static void
-e_html_editor_html_editor_web_extension_dispose (GObject *object)
+e_html_editor_web_extension_dispose (GObject *object)
{
EHTMLEditorWebExtension *extension = E_HTML_EDITOR_WEB_EXTENSION (object);
@@ -1455,15 +1612,29 @@ e_html_editor_html_editor_web_extension_dispose (GObject *object)
g_clear_object (&extension->priv->wk_extension);
+ g_hash_table_remove_all (extension->priv->inline_images);
+
+ /* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_html_editor_web_extension_parent_class)->dispose (object);
}
+static void
+e_html_editor_web_extension_finalize (GObject *object)
+{
+ EHTMLEditorWebExtension *extension = E_HTML_EDITOR_WEB_EXTENSION (object);
+
+ g_hash_table_destroy (extension->priv->inline_images);
+
+ /* Chain up to parent's finalize() method. */
+ G_OBJECT_CLASS (e_html_editor_web_extension_parent_class)->finalize (object);
+}
static void
-e_html_editor_web_extension_class_init (EHTMLEditorWebExtensionClass *klass)
+e_html_editor_web_extension_class_init (EHTMLEditorWebExtensionClass *class)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->dispose = e_html_editor_web_extension_dispose;
+ object_class->finalize = e_html_editor_web_extension_finalize;
g_type_class_add_private (object_class, sizeof(EHTMLEditorWebExtensionPrivate));
}
@@ -1496,7 +1667,20 @@ e_html_editor_web_extension_init (EHTMLEditorWebExtension *extension)
extension->priv->html_mode = FALSE;
extension->priv->return_key_pressed = FALSE;
extension->priv->space_key_pressed = FALSE;
+ extension->priv->body_input_event_removed = FALSE;
extension->priv->word_wrap_length = 71;
+
+ extension->priv->convert_in_situ = FALSE;
+ extension->priv->body_input_event_removed = FALSE;
+ extension->priv->is_message_from_draft = FALSE;
+ extension->priv->is_message_from_edit_as_new = FALSE;
+ extension->priv->is_message_from_selection = FALSE;
+ extension->priv->remove_initial_input_line = FALSE;
+
+ extension->priv->inline_images = g_hash_table_new_full (
+ g_str_hash, g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_free);
}
static gpointer
@@ -1535,11 +1719,11 @@ image_exists_in_cache (const gchar *image_uri)
return exists;
}
-static EMailImageLoadingPolicy
+static EImageLoadingPolicy
get_image_loading_policy (void)
{
GSettings *settings;
- EMailImageLoadingPolicy image_policy;
+ EImageLoadingPolicy image_policy;
settings = e_util_ref_settings ("org.gnome.evolution.mail");
image_policy = g_settings_get_enum (settings, "image-loading-policy");
@@ -1549,7 +1733,7 @@ get_image_loading_policy (void)
}
static void
-redirect_http_uri (EWebExtension *extension,
+redirect_http_uri (EHTMLEditorWebExtension *extension,
WebKitWebPage *web_page,
WebKitURIRequest *request)
{
@@ -1557,7 +1741,7 @@ redirect_http_uri (EWebExtension *extension,
gchar *new_uri;
SoupURI *soup_uri;
gboolean image_exists;
- EMailImageLoadingPolicy image_policy;
+ EImageLoadingPolicy image_policy;
uri = webkit_uri_request_get_uri (request);
@@ -1569,7 +1753,7 @@ redirect_http_uri (EWebExtension *extension,
* a native placeholder for it. */
image_policy = get_image_loading_policy ();
if (!image_exists && !extension->priv->force_image_load &&
- (image_policy == E_MAIL_IMAGE_LOADING_POLICY_NEVER)) {
+ (image_policy == E_IMAGE_LOADING_POLICY_NEVER)) {
webkit_uri_request_set_uri (request, "about:blank");
return;
}
@@ -1589,7 +1773,7 @@ static gboolean
web_page_send_request_cb (WebKitWebPage *web_page,
WebKitURIRequest *request,
WebKitURIResponse *redirected_response,
- EWebExtension *extension)
+ EHTMLEditorWebExtension *extension)
{
const char *request_uri;
const char *page_uri;
@@ -1616,33 +1800,36 @@ web_page_send_request_cb (WebKitWebPage *web_page,
static void
web_page_document_loaded_cb (WebKitWebPage *web_page,
- gpointer user_data)
+ EHTMLEditorWebExtension *web_extension)
{
+ WebKitDOMDocument *document;
+ document = webkit_web_page_get_dom_document (web_page);
+
+ dom_process_content_after_load (document, web_extension);
}
static void
web_page_created_cb (WebKitWebExtension *wk_extension,
WebKitWebPage *web_page,
- EWebExtension *extension)
+ EHTMLEditorWebExtension *extension)
{
g_signal_connect_object (
web_page, "send-request",
- G_CALLBACK (web_page_send_request),
+ G_CALLBACK (web_page_send_request_cb),
extension, 0);
g_signal_connect_object (
web_page, "document-loaded",
- G_CALLBACK (web_page_document_loaded),
+ G_CALLBACK (web_page_document_loaded_cb),
extension, 0);
-
}
void
-e_html_editor_web_extension_initialize (EWebExtension *extension,
+e_html_editor_web_extension_initialize (EHTMLEditorWebExtension *extension,
WebKitWebExtension *wk_extension)
{
- g_return_if_fail (E_HTML_EDITOR_IS_WEB_EXTENSION (extension));
+ g_return_if_fail (E_IS_HTML_EDITOR_WEB_EXTENSION (extension));
extension->priv->wk_extension = g_object_ref (wk_extension);
@@ -1656,6 +1843,10 @@ e_html_editor_web_extension_initialize (EWebExtension *extension,
camel_data_cache_set_expire_access (
emd_global_http_cache, 2 * 60 * 60);
}
+
+ g_signal_connect (
+ wk_extension, "page-created",
+ G_CALLBACK (web_page_created_cb), extension);
}
void
@@ -1733,7 +1924,7 @@ e_html_editor_web_extension_get_html_mode (EHTMLEditorWebExtension *extension)
GDBusConnection *
e_html_editor_web_extension_get_connection (EHTMLEditorWebExtension *extension)
{
- return extension->priv->connection;
+ return extension->priv->dbus_connection;
}
gint
@@ -1767,7 +1958,7 @@ e_html_editor_web_extension_get_underline (EHTMLEditorWebExtension *extension)
}
gboolean
-e_html_editor_web_extension_get_striketrough (EHTMLEditorWebExtension *extension)
+e_html_editor_web_extension_get_strikethrough (EHTMLEditorWebExtension *extension)
{
return extension->priv->strikethrough;
}
@@ -1822,3 +2013,72 @@ e_html_editor_web_extension_set_space_key_pressed (EHTMLEditorWebExtension *exte
extension->priv->space_key_pressed = value;
}
+gboolean
+e_html_editor_web_extension_get_magic_smileys_enabled (EHTMLEditorWebExtension *extension)
+{
+ return extension->priv->magic_smileys;
+}
+
+void
+e_html_editor_web_extension_set_inline_spelling (EHTMLEditorWebExtension *extension,
+ gboolean value)
+{
+ g_return_if_fail (E_IS_HTML_EDITOR_WEB_EXTENSION (extension));
+
+ if (extension->priv->inline_spelling == value)
+ return;
+
+ extension->priv->inline_spelling = value;
+/* FIXME WK2
+ if (inline_spelling)
+ e_html_editor_view_force_spell_check (view);
+ else
+ e_html_editor_view_turn_spell_check_off (view);*/
+}
+
+gboolean
+e_html_editor_web_extension_get_inline_spelling_enabled (EHTMLEditorWebExtension *extension)
+{
+ return extension->priv->inline_spelling;
+}
+
+gboolean
+e_html_editor_web_extension_get_body_input_event_removed (EHTMLEditorWebExtension *extension)
+{
+ return extension->priv->body_input_event_removed;
+}
+
+void
+e_html_editor_web_extension_set_body_input_event_removed (EHTMLEditorWebExtension *extension,
+ gboolean value)
+{
+ extension->priv->body_input_event_removed = value;
+}
+
+gboolean
+e_html_editor_web_extension_get_convert_in_situ (EHTMLEditorWebExtension *extension)
+{
+ return extension->priv->convert_in_situ;
+}
+
+void
+e_html_editor_web_extension_set_convert_in_situ (EHTMLEditorWebExtension *extension,
+ gboolean value)
+{
+ extension->priv->convert_in_situ = value;
+}
+
+GHashTable *
+e_html_editor_web_extension_get_inline_images (EHTMLEditorWebExtension *extension)
+{
+ return extension->priv->inline_images;
+}
+
+static void
+add_new_inline_image_into_list (EHTMLEditorWebExtension *extension,
+ const gchar *cid_src,
+ const gchar *src)
+{
+ g_hash_table_insert (extension->priv->inline_images, g_strdup(cid_src), g_strdup(src));
+}
+
diff --git a/e-util/web-extensions/e-html-editor-web-extension.h b/e-util/e-html-editor-web-extension.h
similarity index 82%
rename from e-util/web-extensions/e-html-editor-web-extension.h
rename to e-util/e-html-editor-web-extension.h
index 50c10dd..c30ba39 100644
--- a/e-util/web-extensions/e-html-editor-web-extension.h
+++ b/e-util/e-html-editor-web-extension.h
@@ -135,4 +135,31 @@ void e_html_editor_web_extension_set_space_key_pressed
(EHTMLEditorWebExtension *extension,
gboolean value);
+gboolean e_html_editor_web_extension_get_magic_smileys_enabled
+ (EHTMLEditorWebExtension *extension);
+
+void e_html_editor_web_extension_set_inline_spelling
+ (EHTMLEditorWebExtension *extension,
+ gboolean value);
+
+gboolean e_html_editor_web_extension_get_inline_spelling_enabled
+ (EHTMLEditorWebExtension *extension);
+
+gboolean e_html_editor_web_extension_get_body_input_event_removed
+ (EHTMLEditorWebExtension *extension);
+
+void e_html_editor_web_extension_set_body_input_event_removed
+ (EHTMLEditorWebExtension *extension,
+ gboolean value);
+
+gboolean e_html_editor_web_extension_get_convert_in_situ
+ (EHTMLEditorWebExtension *extension);
+
+void e_html_editor_web_extension_set_convert_in_situ
+ (EHTMLEditorWebExtension *extension,
+ gboolean value);
+
+GHashTable * e_html_editor_web_extension_get_inline_images
+ (EHTMLEditorWebExtension *extension);
+
#endif /* E_HTML_EDITOR_WEB_EXTENSION_H */
diff --git a/e-util/e-html-editor.c b/e-util/e-html-editor.c
index d367249..8fe1c16 100644
--- a/e-util/e-html-editor.c
+++ b/e-util/e-html-editor.c
@@ -108,7 +108,7 @@ action_context_spell_suggest_cb (GtkAction *action,
e_html_editor_selection_replace_caret_word (selection, word);
}
-
+#if 0 /* FIXME WK2 */
static void
html_editor_inline_spelling_suggestions (EHTMLEditor *editor)
{
@@ -128,7 +128,8 @@ html_editor_inline_spelling_suggestions (EHTMLEditor *editor)
view = e_html_editor_get_view (editor);
selection = e_html_editor_view_get_selection (view);
- checker = WEBKIT_SPELL_CHECKER (webkit_get_text_checker ());
+
+ checker = WEBKIT_SPELL_CHECKER (webkit_get_text_checker ());*/
word = e_html_editor_selection_get_caret_word (selection);
if (word == NULL || *word == '\0')
@@ -206,7 +207,7 @@ html_editor_inline_spelling_suggestions (EHTMLEditor *editor)
g_free (word);
g_strfreev (suggestions);
}
-
+#endif
/* Helper for html_editor_update_actions() */
static void
html_editor_spell_checkers_foreach (EHTMLEditor *editor,
@@ -215,7 +216,7 @@ html_editor_spell_checkers_foreach (EHTMLEditor *editor,
EHTMLEditorView *view;
EHTMLEditorSelection *selection;
ESpellChecker *spell_checker;
- ESpellDictionary *dictionary;
+ ESpellDictionary *dictionary = NULL;
GtkActionGroup *action_group;
GtkUIManager *manager;
GList *list, *link;
@@ -231,13 +232,14 @@ html_editor_spell_checkers_foreach (EHTMLEditor *editor,
word = e_html_editor_selection_get_caret_word (selection);
if (word == NULL || *word == '\0')
return;
-
+/* FIXME WK2
dictionary = e_spell_checker_ref_dictionary (
- spell_checker, language_code);
+ spell_checker, language_code);*/
if (dictionary != NULL) {
+ /* FIXME WK2
list = e_spell_dictionary_get_suggestions (
dictionary, word, -1);
- g_object_unref (dictionary);
+ g_object_unref (dictionary);*/
} else {
list = NULL;
}
@@ -307,7 +309,7 @@ static void
html_editor_update_actions (EHTMLEditor *editor,
guint flags)
{
- WebKitSpellChecker *checker;
+// WebKitSpellChecker *checker;
WebKitHitTestResult *hit_test;
WebKitHitTestResultContext context;
EHTMLEditorSelection *selection;
@@ -316,7 +318,7 @@ html_editor_update_actions (EHTMLEditor *editor,
GtkUIManager *manager;
GtkActionGroup *action_group;
GList *list;
- gchar **languages;
+ gchar **languages = NULL;
guint ii, n_languages;
gboolean visible;
guint merge_id;
@@ -388,6 +390,7 @@ html_editor_update_actions (EHTMLEditor *editor,
list = g_list_delete_link (list, list);
}
+#if 0 /* FIXME WK2 */
languages = e_spell_checker_list_active_languages (
spell_checker, &n_languages);
@@ -429,10 +432,10 @@ html_editor_update_actions (EHTMLEditor *editor,
/* Add actions and context menu content for active languages. */
for (ii = 0; ii < n_languages; ii++)
html_editor_spell_checkers_foreach (editor, languages[ii]);
-
+#endif
g_strfreev (languages);
}
-
+#if 0 /* FIXME WK2 */
static void
html_editor_spell_languages_changed (EHTMLEditor *editor)
{
@@ -470,7 +473,7 @@ html_editor_spell_languages_changed (EHTMLEditor *editor)
g_free (comma_separated);
}
-
+#endif
static gboolean
html_editor_context_menu_cb (WebKitWebView *webkit_web_view,
WebKitContextMenu *context_menu,
@@ -804,7 +807,8 @@ e_html_editor_class_init (EHTMLEditorClass *class)
widget_class->parent_set = html_editor_parent_changed;
class->update_actions = html_editor_update_actions;
- class->spell_languages_changed = html_editor_spell_languages_changed;
+/* FIXME WK2
+ class->spell_languages_changed = html_editor_spell_languages_changed; */
g_object_class_install_property (
object_class,
diff --git a/e-util/e-mail-signature-editor.c b/e-util/e-mail-signature-editor.c
index 45c4999..1b5173d 100644
--- a/e-util/e-mail-signature-editor.c
+++ b/e-util/e-mail-signature-editor.c
@@ -172,22 +172,22 @@ mail_signature_editor_delete_event_cb (EMailSignatureEditor *editor,
}
static void
-action_close_cb (GtkAction *action,
- EMailSignatureEditor *window)
+can_undo_cb (WebKitWebView *webkit_web_view,
+ GAsyncResult *result,
+ EMailSignatureEditor *window)
{
- EHTMLEditor *editor;
- EHTMLEditorView *view;
gboolean something_changed = FALSE;
const gchar *original_name;
const gchar *signature_name;
+ gboolean can_undo;
original_name = window->priv->original_name;
signature_name = gtk_entry_get_text (GTK_ENTRY (window->priv->entry));
- editor = e_mail_signature_editor_get_editor (window);
- view = e_html_editor_get_view (editor);
+ can_undo = webkit_web_view_can_execute_editing_command_finish (
+ webkit_web_view, result, NULL);
- something_changed |= webkit_web_view_can_undo (WEBKIT_WEB_VIEW (view));
+ something_changed |= can_undo;
something_changed |= (strcmp (signature_name, original_name) != 0);
if (something_changed) {
@@ -198,6 +198,7 @@ action_close_cb (GtkAction *action,
"widgets:ask-signature-changed", NULL);
if (response == GTK_RESPONSE_YES) {
GtkActionGroup *action_group;
+ GtkAction *action;
action_group = window->priv->action_group;
action = gtk_action_group_get_action (
@@ -209,6 +210,25 @@ action_close_cb (GtkAction *action,
}
gtk_widget_destroy (GTK_WIDGET (window));
+
+}
+
+static void
+action_close_cb (GtkAction *action,
+ EMailSignatureEditor *window)
+{
+ EHTMLEditor *editor;
+ EHTMLEditorView *view;
+
+ editor = e_mail_signature_editor_get_editor (window);
+ view = e_html_editor_get_view (editor);
+
+ webkit_web_view_can_execute_editing_command (
+ WEBKIT_WEB_VIEW (view),
+ WEBKIT_EDITING_COMMAND_UNDO,
+ NULL, /* cancellable */
+ (GAsyncReadyCallback) can_undo_cb,
+ window);
}
static void
diff --git a/e-util/e-misc-utils.c b/e-util/e-misc-utils.c
index 0cf65d2..9f5d6d8 100644
--- a/e-util/e-misc-utils.c
+++ b/e-util/e-misc-utils.c
@@ -3081,3 +3081,40 @@ e_util_cleanup_settings (void)
g_mutex_unlock (&settings_hash_lock);
}
+
+static gdouble
+get_screen_dpi (GdkScreen *screen)
+{
+ gdouble dpi;
+ gdouble dp, di;
+
+ dpi = gdk_screen_get_resolution (screen);
+ if (dpi != -1)
+ return dpi;
+
+ dp = hypot (gdk_screen_get_width (screen), gdk_screen_get_height (screen));
+ di = hypot (gdk_screen_get_width_mm (screen), gdk_screen_get_height_mm (screen)) / 25.4;
+
+ return dp / di;
+}
+
+guint
+e_util_normalize_font_size (GtkWidget *widget,
+ gdouble font_size)
+{
+ /* WebKit2 uses font sizes in pixels. */
+ GdkScreen *screen;
+ gdouble dpi;
+
+ if (widget) {
+ screen = gtk_widget_has_screen (widget) ?
+ gtk_widget_get_screen (widget) : gdk_screen_get_default ();
+ } else {
+ screen = gdk_screen_get_default ();
+ }
+
+ dpi = screen ? get_screen_dpi (screen) : 96;
+
+ return font_size / 72.0 * dpi;
+}
+
diff --git a/e-util/e-misc-utils.h b/e-util/e-misc-utils.h
index 3bd5f48..86e3dfa 100644
--- a/e-util/e-misc-utils.h
+++ b/e-util/e-misc-utils.h
@@ -285,6 +285,8 @@ void e_signal_disconnect_notify_handler
GSettings * e_util_ref_settings (const gchar *schema_id);
void e_util_cleanup_settings (void);
+guint e_util_normalize_font_size (GtkWidget *widget,
+ gdouble font_size);
G_END_DECLS
#endif /* E_MISC_UTILS_H */
diff --git a/e-util/e-web-view.c b/e-util/e-web-view.c
index 086c61e..81616d9 100644
--- a/e-util/e-web-view.c
+++ b/e-util/e-web-view.c
@@ -40,7 +40,7 @@
#include "e-selectable.h"
#include "e-stock-request.h"
-#include "../web-extensions/evolution-web-extension.h"
+#include "../web-extensions/e-web-extension-names.h"
#define E_WEB_VIEW_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
@@ -554,9 +554,8 @@ web_view_decide_policy_cb (EWebView *web_view,
navigation_action = webkit_navigation_policy_decision_get_navigation_action (navigation_decision);
navigation_type = webkit_navigation_action_get_navigation_type (navigation_action);
- if (navigation_type != WEBKIT_NAVIGATION_TYPE_LINK_CLICKED) {
+ if (navigation_type != WEBKIT_NAVIGATION_TYPE_LINK_CLICKED)
return FALSE;
- }
request = webkit_navigation_action_get_request (navigation_action);
uri = webkit_uri_request_get_uri (request);
@@ -595,7 +594,7 @@ web_view_decide_policy_cb (EWebView *web_view,
if (soup_uri_get_fragment (uri_link)) {
soup_uri_free (uri_link);
soup_uri_free (uri_frame);
- webkit_web_policy_decision_use (policy_decision);
+ webkit_policy_decision_use (decision);
return TRUE;
}
}
@@ -702,9 +701,9 @@ web_view_load_changed_cb (WebKitWebView *webkit_web_view,
}
static GObjectConstructParam*
-find_property(guint n_properties,
- GObjectConstructParam* properties,
- GParamSpec* param_spec)
+find_property (guint n_properties,
+ GObjectConstructParam* properties,
+ GParamSpec* param_spec)
{
while (n_properties--) {
if (properties->pspec == param_spec)
@@ -724,15 +723,15 @@ web_view_constructor (GType type,
GParamSpec* param_spec;
GObjectConstructParam *param = NULL;
- object_class = G_OBJECT_CLASS(g_type_class_ref(type));
- g_return_val_if_fail(object_class != NULL, NULL);
+ object_class = G_OBJECT_CLASS (g_type_class_ref(type));
+ g_return_val_if_fail (object_class != NULL, NULL);
if (construct_properties && n_construct_properties != 0) {
- param_spec = g_object_class_find_property(object_class, "settings");
- if ((param = find_property(n_construct_properties, construct_properties, param_spec)))
+ param_spec = g_object_class_find_property (object_class, "settings");
+ if ((param = find_property (n_construct_properties, construct_properties, param_spec)))
g_value_take_object (param->value, e_web_view_get_default_webkit_settings ());
param_spec = g_object_class_find_property(object_class, "user-content-manager");
- if ((param = find_property(n_construct_properties, construct_properties, param_spec)))
+ if ((param = find_property (n_construct_properties, construct_properties, param_spec)))
g_value_take_object (param->value, webkit_user_content_manager_new ());
}
@@ -1274,8 +1273,8 @@ web_extension_appeared_cb (GDBusConnection *connection,
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
NULL,
name,
- EVOLUTION_WEB_EXTENSION_OBJECT_PATH,
- EVOLUTION_WEB_EXTENSION_INTERFACE,
+ E_WEB_EXTENSION_OBJECT_PATH,
+ E_WEB_EXTENSION_INTERFACE,
NULL,
(GAsyncReadyCallback) web_extension_proxy_created_cb,
web_view);
@@ -1295,7 +1294,7 @@ web_view_watch_web_extension (EWebView *web_view)
web_view->priv->web_extension_watch_name_id =
g_bus_watch_name (
G_BUS_TYPE_SESSION,
- EVOLUTION_WEB_EXTENSION_SERVICE_NAME,
+ E_WEB_EXTENSION_SERVICE_NAME,
G_BUS_NAME_WATCHER_FLAGS_NONE,
(GBusNameAppearedCallback) web_extension_appeared_cb,
(GBusNameVanishedCallback) web_extension_vanished_cb,
@@ -1393,7 +1392,7 @@ web_view_update_actions_cb (WebKitWebView *webkit_web_view,
}
static void
-eb_view_update_actions (EWebView *web_view)
+web_view_update_actions (EWebView *web_view)
{
webkit_web_view_can_execute_editing_command (
WEBKIT_WEB_VIEW (web_view),
@@ -1727,6 +1726,7 @@ web_view_gtk_stock_uri_scheme_appeared_cb (WebKitURISchemeRequest *request)
gtk_style_context_set_path (context, path);
gtk_widget_path_free (path);
+ icon_set = gtk_style_context_lookup_icon_set (context, uri->host);
if (icon_set != NULL) {
GdkPixbuf *pixbuf;
@@ -2007,30 +2007,11 @@ e_web_view_selectable_init (ESelectableInterface *iface)
}
static void
-web_view_update_fonts (EWebView *web_view)
-{
- e_web_view_update_fonts (web_view);
-}
-
-void
-e_web_view_update_fonts (EWebView *web_view)
+initialize_web_extensions_cb (WebKitWebContext *web_context)
{
- EWebViewClass *class;
- PangoFontDescription *ms = NULL, *vw = NULL;
-
- g_return_if_fail (E_IS_WEB_VIEW (web_view));
-
- class = E_WEB_VIEW_GET_CLASS (web_view);
- if (class->set_fonts != NULL)
- class->set_fonts (web_view, &ms, &vw);
-
- e_web_view_update_fonts_settings (
- web_view->priv->font_settings,
- web_view->priv->aliasing_settings,
- ms, vw, GTK_WIDGET (web_view));
-
- pango_font_description_free (ms);
- pango_font_description_free (vw);
+ /* Set the web extensions dir before the process is launched */
+ webkit_web_context_set_web_extensions_directory (
+ web_context, EVOLUTION_WEB_EXTENSIONS_DIR);
}
static void
@@ -2053,40 +2034,40 @@ e_web_view_init (EWebView *web_view)
/* XXX No WebKitWebView class method pointers to
* override so we have to use signal handlers. */
#if 0
- e_signal_connect (
+ g_signal_connect (
web_view, "create-plugin-widget",
G_CALLBACK (web_view_create_plugin_widget_cb), NULL);
#endif
- e_signal_connect (
+ g_signal_connect (
web_view, "context-menu",
G_CALLBACK (web_view_context_menu_cb), NULL);
- u_signal_connect (
+ g_signal_connect (
web_view, "mouse-target-changed",
G_CALLBACK (web_view_mouse_target_changed_cb), NULL);
- e_signal_connect (
+ g_signal_connect (
web_view, "decide-policy",
G_CALLBACK (web_view_decide_policy_cb),
NULL);
- e_signal_connect (
+ g_signal_connect (
webkit_web_context_get_default (), "initialize-web-extensions",
G_CALLBACK (initialize_web_extensions_cb), NULL);
- e_signal_connect (
+ g_signal_connect (
web_view, "load-changed",
G_CALLBACK (web_view_load_changed_cb), NULL);
- e_signal_connect (
+ g_signal_connect (
web_view, "document-load-finished",
G_CALLBACK (style_updated_cb), NULL);
- e_signal_connect (
+ g_signal_connect (
web_view, "style-updated",
G_CALLBACK (style_updated_cb), NULL);
- e_signal_connect (
+ g_signal_connect (
web_view, "state-flags-changed",
G_CALLBACK (style_updated_cb), NULL);
@@ -2555,8 +2536,8 @@ e_web_view_set_editable (EWebView *web_view,
{
g_return_if_fail (E_IS_WEB_VIEW (web_view));
- /* FIXME XXX WK2 */
- webkit_web_view_set_editable (WEBKIT_WEB_VIEW (web_view), editable);
+ /* FIXME XXX WK2
+ webkit_web_view_set_editable (WEBKIT_WEB_VIEW (web_view), editable);*/
}
const gchar *
@@ -2868,7 +2849,7 @@ e_web_view_zoom_in (EWebView *web_view)
zoom_level = webkit_web_view_get_zoom_level (WEBKIT_WEB_VIEW (web_view));
/* zoom-step in WK1 was 0.1 */
zoom_level += 0.1;
- if (zoom_level < 4.9999) {
+ if (zoom_level < 4.9999)
webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW (web_view), zoom_level);
}
@@ -3083,42 +3064,6 @@ e_web_view_get_selection_content_html_sync (EWebView *web_view,
return NULL;
}
-static gdouble
-get_screen_dpi (GdkScreen *screen)
-{
- gdouble dpi;
- gdouble dp, di;
-
- dpi = gdk_screen_get_resolution (screen);
- if (dpi != -1)
- return dpi;
-
- dp = hypot (gdk_screen_get_width (screen), gdk_screen_get_height (screen));
- di = hypot (gdk_screen_get_width_mm (screen), gdk_screen_get_height_mm (screen)) / 25.4;
-
- return dp / di;
-}
-
-static guint
-normalize_font_size (GtkWidget *widget,
- gdouble font_size)
-{
- /* WebKit2 uses font sizes in pixels. */
- GdkScreen *screen;
- gdouble dpi;
-
- if (widget) {
- screen = gtk_widget_has_screen (widget) ?
- gtk_widget_get_screen (widget) : gdk_screen_get_default ();
- } else {
- screen = gdk_screen_get_default ();
- }
-
- dpi = screen ? get_screen_dpi (screen) : 96;
-
- return font_size / 72.0 * dpi;
-}
-
void
e_web_view_update_fonts_settings (GSettings *font_settings,
GSettings *aliasing_settings,
@@ -3261,24 +3206,24 @@ e_web_view_update_fonts_settings (GSettings *font_settings,
g_object_set (
wk_settings,
"default-font-size",
- normalize_font_size (
+ e_util_normalize_font_size (
view_widget, pango_font_description_get_size (vw) / PANGO_SCALE),
"default-font-family",
pango_font_description_get_family (vw),
"monospace-font-family",
pango_font_description_get_family (ms),
"default-monospace-font-size",
- normalize_font_size (
+ e_util_normalize_font_size (
view_widget, pango_font_description_get_size (ms) / PANGO_SCALE),
"minimum-font-size",
- normalize_font_size (
+ e_util_normalize_font_size (
view_widget, pango_font_description_get_size (min_size) / PANGO_SCALE),
NULL);
manager = webkit_web_view_get_user_content_manager (WEBKIT_WEB_VIEW (view_widget));
webkit_user_content_manager_remove_all_style_sheets (manager);
- webkit_user_style_sheet_new (
+ style_sheet = webkit_user_style_sheet_new (
stylesheet->str,
WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
WEBKIT_USER_STYLE_LEVEL_USER,
@@ -3316,14 +3261,6 @@ e_web_view_get_default_webkit_settings (void)
NULL);
}
-static void
-initialize_web_extensions_cb (WebKitWebContext *web_context)
-{
- /* Set the web extensions dir before the process is launched */
- webkit_web_context_set_web_extensions_directory (
- web_context, EVOLUTION_WEB_EXTENSIONS_DIR);
-}
-
void
e_web_view_update_fonts (EWebView *web_view)
{
diff --git a/e-util/e-web-view.h b/e-util/e-web-view.h
index 015bd50..0b62998 100644
--- a/e-util/e-web-view.h
+++ b/e-util/e-web-view.h
@@ -239,7 +239,7 @@ void e_web_view_install_request_handler
(EWebView *web_view,
GType handler_type);
void e_web_view_create_and_add_css_style_sheet
- (WebKitDOMDocument* document,
+ (EWebView *web_view,
const gchar *style_sheet_id);
void e_web_view_add_css_rule_into_style_sheet
(EWebView *web_view,
diff --git a/web-extensions/Makefile.am b/web-extensions/Makefile.am
index 5516a46..adfa012 100644
--- a/web-extensions/Makefile.am
+++ b/web-extensions/Makefile.am
@@ -1,22 +1,23 @@
-webextensions_LTLIBRARIES = libevolutionwebextension.la
+webextensions_LTLIBRARIES = libewebextension.la
-libevolutionwebextension_la_SOURCES = \
+libewebextension_la_SOURCES = \
e-web-extension.c \
e-web-extension.h \
+ e-web-extension-names.h \
e-web-extension-main.c
-libevolutionwebextension_la_CPPFLAGS = \
+libewebextension_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
-I$(top_srcdir) \
$(EVOLUTION_DATA_SERVER_CFLAGS) \
$(GNOME_PLATFORM_CFLAGS) \
$(WEB_EXTENSIONS_CFLAGS)
-libevolutionwebextension_la_LIBADD = \
+libewebextension_la_LIBADD = \
$(top_builddir)/e-util/libevolution-util.la \
$(EVOLUTION_DATA_SERVER_LIBS) \
$(GNOME_PLATFORM_LIBS) \
$(WEB_EXTENSIONS_LIBS)
-libevolutionwebextension_la_LDFLAGS = \
+libewebextension_la_LDFLAGS = \
-module -avoid-version -no-undefined
diff --git a/web-extensions/e-web-extension-main.c b/web-extensions/e-web-extension-main.c
index 5df0126..b6fb88b 100644
--- a/web-extensions/e-web-extension-main.c
+++ b/web-extensions/e-web-extension-main.c
@@ -19,6 +19,7 @@
#include "config.h"
#include "e-web-extension.h"
+#include "e-web-extension-names.h"
static void
bus_acquired_cb (GDBusConnection *connection,
diff --git a/e-util/web-extensions/e-html-editor-web-extension-names.h
b/web-extensions/e-web-extension-names.h
similarity index 59%
rename from e-util/web-extensions/e-html-editor-web-extension-names.h
rename to web-extensions/e-web-extension-names.h
index 0c42931..eedf271 100644
--- a/e-util/web-extensions/e-html-editor-web-extension-names.h
+++ b/web-extensions/e-web-extension-names.h
@@ -1,5 +1,5 @@
/*
- * e-html-editor-web-extension-names.h
+ * e-web-extension-names.h
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -16,11 +16,11 @@
*
*/
-#ifndef E_HTML_EDITOR_WEB_EXTENSION_NAMES_H
-#define E_HTML_EDITOR_WEB_EXTENSION_NAMES_H
+#ifndef E_WEB_EXTENSION_NAMES_H
+#define E_WEB_EXTENSION_NAMES_H
-#define E_HTML_EDITOR_WEB_EXTENSION_SERVICE_NAME "org.gnome.Evolution.EHTMLEditor.WebExtension"
-#define E_HTML_EDITOR_WEB_EXTENSION_OBJECT_PATH "/org/gnome/Evolution/EHTMLEditor/WebExtension"
-#define E_HTML_EDITOR_WEB_EXTENSION_INTERFACE "org.gnome.Evolution.EHTMLEditor.WebExtension"
+#define E_WEB_EXTENSION_SERVICE_NAME "org.gnome.Evolution.WebExtension"
+#define E_WEB_EXTENSION_OBJECT_PATH "/org/gnome/Evolution/WebExtension"
+#define E_WEB_EXTENSION_INTERFACE "org.gnome.Evolution.WebExtension"
-#endif /* E_HTML_EDITOR_WEB_EXTENSION_NAMES_H */
+#endif /* E_WEB_EXTENSION_NAMES_H */
diff --git a/web-extensions/e-web-extension.c b/web-extensions/e-web-extension.c
index 663d232..c9fe009 100644
--- a/web-extensions/e-web-extension.c
+++ b/web-extensions/e-web-extension.c
@@ -19,6 +19,7 @@
#include "config.h"
#include "e-web-extension.h"
+#include "e-web-extension-names.h"
#include <gio/gio.h>
#include <gtk/gtk.h>
@@ -462,9 +463,9 @@ e_web_extension_dispose (GObject *object)
}
static void
-e_web_extension_class_init (EWebExtensionClass *klass)
+e_web_extension_class_init (EWebExtensionClass *class)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->dispose = e_web_extension_dispose;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]