[evolution/wip/webkit-composer: 697/966] Move caret position setting from em-composer-utils to e-composer-private
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit-composer: 697/966] Move caret position setting from em-composer-utils to e-composer-private
- Date: Wed, 23 Apr 2014 10:52:01 +0000 (UTC)
commit 21556d16e999849b2cd1056334957156b8800082
Author: Tomas Popela <tpopela redhat com>
Date: Tue Apr 23 11:06:09 2013 +0200
Move caret position setting from em-composer-utils to e-composer-private
Moving caret position setting from mail/em-composer-utils.c to
composer/e-composer-private.c because the caret position set in em-composer-utils.c
was modified by setting a signature to email. Also e_editor_selection_{save|restore}
calls were removed because they are not working properly in this case.
composer/e-composer-private.c | 178 ++++++++--------------------------------
mail/em-composer-utils.c | 92 ---------------------
2 files changed, 36 insertions(+), 234 deletions(-)
---
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index 4fc5202..7d315d3 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -781,58 +781,26 @@ composer_size_allocate_cb (GtkWidget *widget,
}
static void
-insert_paragraph_with_input (WebKitDOMElement *paragraph,
- WebKitDOMElement *body)
-{
- WebKitDOMNode *node = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body));
-
- if (node) {
- webkit_dom_node_insert_before (
- WEBKIT_DOM_NODE (body),
- WEBKIT_DOM_NODE (paragraph),
- node,
- NULL);
- } else {
- webkit_dom_node_append_child (
- WEBKIT_DOM_NODE (body),
- WEBKIT_DOM_NODE (paragraph),
- NULL);
- }
-}
-
-static void
composer_move_caret (EMsgComposer *composer)
{
+ WebKitDOMHTMLElement *body;
+ WebKitDOMRange *new_range;
EEditor *editor;
EEditorWidget *editor_widget;
- EEditorSelection *editor_selection;
- GSettings *settings;
- gboolean start_bottom, html_mode, top_signature;
- gboolean has_paragraphs_in_body = TRUE;
WebKitDOMDocument *document;
WebKitDOMDOMWindow *window;
+ WebKitDOMElement *br_bottom;
WebKitDOMDOMSelection *dom_selection;
- WebKitDOMElement *input_start, *element, *signature;
- WebKitDOMHTMLElement *body;
- WebKitDOMNodeList *list, *blockquotes;
- WebKitDOMRange *new_range;
+ GSettings *settings;
+ gboolean start_bottom;
/* When there is an option composer-reply-start-bottom set we have
* to move the caret between reply and signature. */
settings = g_settings_new ("org.gnome.evolution.mail");
start_bottom = g_settings_get_boolean (settings, "composer-reply-start-bottom");
- g_object_unref (settings);
-
- top_signature =
- use_top_signature (composer) &&
- !composer->priv->is_from_message &&
- !composer->priv->is_from_new_message;
editor = e_msg_composer_get_editor (composer);
editor_widget = e_editor_get_editor_widget (editor);
- editor_selection = e_editor_widget_get_selection (editor_widget);
- html_mode = e_editor_widget_get_html_mode (editor_widget);
-
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (editor_widget));
window = webkit_dom_document_get_default_view (document);
dom_selection = webkit_dom_dom_window_get_selection (window);
@@ -840,91 +808,33 @@ composer_move_caret (EMsgComposer *composer)
body = webkit_dom_document_get_body (document);
new_range = webkit_dom_document_create_range (document);
- element = webkit_dom_document_get_element_by_id (document, "-x-evo-caret-position");
- /* Caret position found => composer mode changed */
- if (element) {
- e_editor_selection_restore_caret_position (editor_selection);
- /* We want to force spellcheck just in case that we switched to plain
- * text mode (when switching to html mode, the underlined words are
- * preserved */
- if (!html_mode)
- e_editor_widget_force_spellcheck (editor_widget);
- return;
- }
-
- /* If editing message as new don't handle with caret */
- if (composer->priv->is_from_message) {
- e_editor_selection_restore_caret_position (editor_selection);
- if (!html_mode)
- e_editor_widget_quote_plain_text (editor_widget);
- e_editor_widget_force_spellcheck (editor_widget);
-
- return;
- }
-
- list = webkit_dom_document_get_elements_by_class_name (document, "-x-evo-paragraph");
- signature = webkit_dom_document_query_selector (document, ".-x-evolution-signature", NULL);
- /* Situation when wrapped paragraph is just in signature and not in message body */
- if (webkit_dom_node_list_get_length (list) == 1) {
- if (signature && webkit_dom_element_query_selector (signature, ".-x-evo-paragraph", NULL))
- has_paragraphs_in_body = FALSE;
- }
+ if (start_bottom) {
+ WebKitDOMNodeList *blockquotes;
- if (webkit_dom_node_list_get_length (list) == 0)
- has_paragraphs_in_body = FALSE;
+ blockquotes = webkit_dom_document_get_elements_by_tag_name (document, "blockquote");
+ if (webkit_dom_node_list_get_length (blockquotes) != 0) {
+ /* Move caret between reply and signature. */
+ new_range = webkit_dom_document_create_range (document);
+ webkit_dom_range_select_node_contents (new_range,
+ WEBKIT_DOM_NODE (
+ webkit_dom_node_get_next_sibling (webkit_dom_node_list_item
(blockquotes, 0))
+ ), NULL);
+ webkit_dom_range_collapse (new_range, TRUE, NULL);
- blockquotes = webkit_dom_document_get_elements_by_tag_name (document, "blockquote");
+ } else {
+ br_bottom = webkit_dom_document_get_element_by_id (document, "-x-evolution-br-reply");
- if (!has_paragraphs_in_body) {
- element = e_editor_selection_get_paragraph_element (
- editor_selection, document, -1);
- webkit_dom_element_set_id (
- WEBKIT_DOM_ELEMENT (element), "-x-evo-input-start");
- webkit_dom_html_element_set_inner_html (
- WEBKIT_DOM_HTML_ELEMENT (element), UNICODE_ZERO_WIDTH_SPACE, NULL);
- }
+ if (!br_bottom) {
+ WebKitDOMElement *br;
- if (start_bottom) {
- if (webkit_dom_node_list_get_length (blockquotes) != 0) {
- if (!has_paragraphs_in_body) {
- if (!top_signature) {
- webkit_dom_node_insert_before (
- WEBKIT_DOM_NODE (body),
- WEBKIT_DOM_NODE (element),
- signature ?
- webkit_dom_node_get_parent_node (
- WEBKIT_DOM_NODE (signature)) :
- webkit_dom_node_get_next_sibling (
- webkit_dom_node_list_item (blockquotes, 0)),
- NULL);
- } else {
- webkit_dom_node_append_child (
- WEBKIT_DOM_NODE (body),
- WEBKIT_DOM_NODE (element),
- NULL);
- }
+ br = webkit_dom_document_create_element (document, "BR", NULL);
+ webkit_dom_html_element_set_id (WEBKIT_DOM_HTML_ELEMENT (br),
"-x-evolution-br-reply");
+ webkit_dom_node_append_child (WEBKIT_DOM_NODE (body), WEBKIT_DOM_NODE (br),
NULL);
+ br_bottom = webkit_dom_document_get_element_by_id (document,
"-x-evolution-br-reply");
}
- e_editor_selection_restore_caret_position (editor_selection);
- if (!html_mode)
- e_editor_widget_quote_plain_text (editor_widget);
- e_editor_widget_force_spellcheck (editor_widget);
-
- input_start = webkit_dom_document_get_element_by_id (document, "-x-evo-input-start");
- if (input_start)
- webkit_dom_range_select_node_contents (new_range, WEBKIT_DOM_NODE
(input_start), NULL);
-
+ webkit_dom_range_select_node_contents (new_range, WEBKIT_DOM_NODE (br_bottom), NULL);
webkit_dom_range_collapse (new_range, FALSE, NULL);
- } else {
- if (!has_paragraphs_in_body)
- insert_paragraph_with_input (
- element, WEBKIT_DOM_ELEMENT (body));
-
- webkit_dom_range_select_node_contents (new_range,
- WEBKIT_DOM_NODE (
- webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body))),
- NULL);
- webkit_dom_range_collapse (new_range, TRUE, NULL);
}
g_signal_connect (
@@ -932,38 +842,25 @@ composer_move_caret (EMsgComposer *composer)
G_CALLBACK (composer_size_allocate_cb), NULL);
} else {
/* Move caret on the beginning of message */
- if (!has_paragraphs_in_body) {
- insert_paragraph_with_input (
- element, WEBKIT_DOM_ELEMENT (body));
-
- if (webkit_dom_node_list_get_length (blockquotes) != 0) {
- if (!html_mode) {
- WebKitDOMNode *blockquote;
-
- blockquote = webkit_dom_node_list_item (blockquotes, 0);
-
- /* FIXME determine when we can skip this */
- e_editor_selection_wrap_paragraph (
- editor_selection,
- WEBKIT_DOM_ELEMENT (blockquote));
-
- e_editor_selection_restore_caret_position (editor_selection);
- e_editor_widget_quote_plain_text (editor_widget);
- body = webkit_dom_document_get_body (document);
- }
- e_editor_widget_force_spellcheck (editor_widget);
- }
+ if (!webkit_dom_document_get_element_by_id (document, "-x-evolution-br-reply")) {
+ WebKitDOMElement *br;
+
+ br = webkit_dom_document_create_element (document, "BR", NULL);
+ webkit_dom_html_element_set_id (WEBKIT_DOM_HTML_ELEMENT (br),
"-x-evolution-br-reply");
+ webkit_dom_node_insert_before (WEBKIT_DOM_NODE (body), WEBKIT_DOM_NODE (br),
webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body)), NULL);
}
webkit_dom_range_select_node_contents (new_range,
WEBKIT_DOM_NODE (
- webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body))),
- NULL);
+ webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body))
+ ), NULL);
webkit_dom_range_collapse (new_range, TRUE, NULL);
}
webkit_dom_dom_selection_remove_all_ranges (dom_selection);
webkit_dom_dom_selection_add_range (dom_selection, new_range);
+
+ g_object_unref (settings);
}
static void
@@ -1081,8 +978,6 @@ insert:
editor_widget = e_editor_get_editor_widget (editor);
selection = e_editor_widget_get_selection (editor_widget);
- e_editor_selection_save (selection);
-
/* This prevents our command before/after callbacks from
* screwing around with the signature as we insert it. */
composer->priv->in_signature_insert = TRUE;
@@ -1143,8 +1038,7 @@ insert:
g_string_free (html_buffer, TRUE);
}
- e_editor_selection_restore (selection);
-
+ composer_move_caret (composer);
composer->priv->in_signature_insert = FALSE;
exit:
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index f2677c7..39496b2 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -2813,88 +2813,6 @@ attribution_format (CamelMimeMessage *message)
}
static void
-composer_size_allocate_cb (GtkWidget *widget,
- gpointer user_data)
-{
- GtkWidget *scrolled_window;
- GtkAdjustment *adj;
-
- scrolled_window = gtk_widget_get_parent (GTK_WIDGET (widget));
- adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window));
-
- /* Scroll only when there is some size allocated */
- if (gtk_adjustment_get_upper (adj) != 0.0) {
- /* Scroll web view down to caret */
- gtk_adjustment_set_value (adj, gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size
(adj));
- gtk_scrolled_window_set_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window), adj);
- /* Disconnect because we don't want to scroll down the view on every window size change */
- g_signal_handlers_disconnect_by_func (
- widget, G_CALLBACK (composer_size_allocate_cb), NULL);
- }
-}
-
-static void
-web_view_load_status_changed_cb (WebKitWebView *webkit_web_view,
- GParamSpec *pspec,
- gpointer user_data)
-{
- WebKitDOMDocument *document;
- WebKitDOMRange *new_range;
- WebKitDOMElement *br;
- WebKitDOMHTMLElement *body;
- WebKitDOMNode *br_node;
- WebKitDOMDOMWindow *window;
- WebKitDOMDOMSelection *window_selection;
- WebKitLoadStatus status;
-
- status = webkit_web_view_get_load_status (webkit_web_view);
- if (status != WEBKIT_LOAD_FINISHED)
- return;
-
- /* Move caret on the end of body element */
- document = webkit_web_view_get_dom_document (webkit_web_view);
- window = webkit_dom_document_get_default_view (document);
- window_selection = webkit_dom_dom_window_get_selection (window);
- body = webkit_dom_document_get_body (document);
-
- br = webkit_dom_document_create_element (document, "BR", NULL);
- br_node = webkit_dom_node_append_child (WEBKIT_DOM_NODE (body), WEBKIT_DOM_NODE(br), NULL);
-
- new_range = webkit_dom_document_create_range (document);
- webkit_dom_range_select_node_contents (new_range, WEBKIT_DOM_NODE (br_node), NULL);
- webkit_dom_range_collapse (new_range, FALSE, NULL);
-
- webkit_dom_dom_selection_remove_all_ranges (window_selection);
- webkit_dom_dom_selection_add_range (window_selection, new_range);
-
- /* Disconnect because we don't want to move caret down on every web view status change */
- g_signal_handlers_disconnect_by_func (
- webkit_web_view, G_CALLBACK (web_view_load_status_changed_cb), NULL);
-}
-
-static void
-composer_set_caret_on_body_end (EMsgComposer *composer)
-{
- EEditor *editor;
- EEditorWidget *widget;
-
- editor = e_msg_composer_get_editor (composer);
- widget = e_editor_get_editor_widget (editor);
-
- /* Scroll web view down to caret - we have to wait until
- * GtkScrolledWindow is resized */
- g_signal_connect (
- widget, "size-allocate",
- G_CALLBACK (composer_size_allocate_cb), NULL);
-
- /* Set caret on the end of body - we have to wait until
- * the page is loaded */
- g_signal_connect (
- WEBKIT_WEB_VIEW(widget), "notify::load-status",
- G_CALLBACK (web_view_load_status_changed_cb), NULL);
-}
-
-static void
composer_set_body (EMsgComposer *composer,
CamelMimeMessage *message,
EMailReplyStyle style,
@@ -2903,8 +2821,6 @@ composer_set_body (EMsgComposer *composer,
gchar *text, *credits, *original;
CamelMimePart *part;
CamelSession *session;
- GSettings *settings;
- gboolean start_bottom;
guint32 validity_found = 0;
session = e_msg_composer_ref_session (composer);
@@ -2929,9 +2845,6 @@ composer_set_body (EMsgComposer *composer,
g_free (text);
g_free (original);
emu_update_composers_security (composer, validity_found);
-
- if (start_bottom)
- composer_set_caret_on_body_end (composer);
break;
case E_MAIL_REPLY_STYLE_QUOTED:
@@ -2946,14 +2859,9 @@ composer_set_body (EMsgComposer *composer,
e_msg_composer_set_body_text (composer, text, TRUE);
g_free (text);
emu_update_composers_security (composer, validity_found);
-
- if (start_bottom)
- composer_set_caret_on_body_end (composer);
break;
}
- g_object_unref (settings);
-
g_object_unref (session);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]