gboolean e_html_editor_node_is_selection_position_node (WebKitDOMNode *node) { WebKitDOMElement *element; if (!node || !WEBKIT_DOM_IS_ELEMENT (node)) return FALSE; element = WEBKIT_DOM_ELEMENT (node); return element_has_id (element, "-x-evo-selection-start-marker") || element_has_id (element, "-x-evo-selection-end-marker"); }
static void move_caret_after_signature_inserted (EEditorPage *editor_page) { WebKitDOMDocument *document; WebKitDOMElement *element, *signature; WebKitDOMHTMLElement *body; WebKitDOMNodeList *paragraphs = NULL; gboolean top_signature; gboolean start_bottom; gboolean has_paragraphs_in_body = TRUE; g_return_if_fail (E_IS_EDITOR_PAGE (editor_page)); document = e_editor_page_get_document (editor_page); top_signature = use_top_signature (); start_bottom = start_typing_at_bottom (); body = webkit_dom_document_get_body (document); e_editor_page_block_selection_changed (editor_page); paragraphs = webkit_dom_document_query_selector_all (document, "[data-evo-paragraph]", NULL); signature = webkit_dom_document_query_selector (document, ".-x-evo-signature-wrapper", NULL); /* Situation when wrapped paragraph is just in signature and not in message body */ if (webkit_dom_node_list_get_length (paragraphs) == 1) { WebKitDOMNode *node; node = webkit_dom_node_list_item (paragraphs, 0); if (signature && webkit_dom_element_query_selector (signature, "[data-evo-paragraph]", NULL)) has_paragraphs_in_body = FALSE; /* Don't take the credentials into account. */ if (!webkit_dom_node_get_previous_sibling (node) && !element_has_id (WEBKIT_DOM_ELEMENT (node), "-x-evo-input-start")) has_paragraphs_in_body = FALSE; } /* * * Keeping Signatures in the beginning of composer * ------------------------------------------------ * * Purists are gonna blast me for this. * But there are so many people (read Outlook users) who want this. * And Evo is an exchange-client, Outlook-replacement etc. * So Here it goes :( * * -- Sankar * */ if (signature && top_signature) { WebKitDOMElement *spacer; spacer = prepare_top_signature_spacer (editor_page); webkit_dom_node_insert_before ( WEBKIT_DOM_NODE (body), WEBKIT_DOM_NODE (spacer), webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (signature)), NULL); } if (webkit_dom_node_list_get_length (paragraphs) == 0) has_paragraphs_in_body = FALSE; element = webkit_dom_document_get_element_by_id (document, "-x-evo-input-start"); if (!signature) { if (start_bottom) { if (!element) { element = e_editor_dom_prepare_paragraph (editor_page, FALSE); webkit_dom_element_set_id (element, "-x-evo-input-start"); webkit_dom_node_append_child ( WEBKIT_DOM_NODE (body), WEBKIT_DOM_NODE (element), NULL); } } else element = WEBKIT_DOM_ELEMENT (body); goto move_caret; } /* When there is an option composer-reply-start-bottom set we have * to move the caret between reply and signature. */ if (!has_paragraphs_in_body) { element = e_editor_dom_prepare_paragraph (editor_page, FALSE); webkit_dom_element_set_id (element, "-x-evo-input-start"); if (top_signature) { if (start_bottom) { webkit_dom_node_append_child ( WEBKIT_DOM_NODE (body), WEBKIT_DOM_NODE (element), NULL); } else { webkit_dom_node_insert_before ( WEBKIT_DOM_NODE (body), WEBKIT_DOM_NODE (element), WEBKIT_DOM_NODE (signature), NULL); } } else { if (start_bottom) webkit_dom_node_insert_before ( WEBKIT_DOM_NODE (body), WEBKIT_DOM_NODE (element), WEBKIT_DOM_NODE (signature), NULL); else element = WEBKIT_DOM_ELEMENT (body); } } else { if (!element && top_signature) { element = e_editor_dom_prepare_paragraph (editor_page, FALSE); webkit_dom_element_set_id (element, "-x-evo-input-start"); if (start_bottom) { webkit_dom_node_append_child ( WEBKIT_DOM_NODE (body), WEBKIT_DOM_NODE (element), NULL); } else { webkit_dom_node_insert_before ( WEBKIT_DOM_NODE (body), WEBKIT_DOM_NODE (element), WEBKIT_DOM_NODE (signature), NULL); } } else if (element && top_signature && !start_bottom) { webkit_dom_node_insert_before ( WEBKIT_DOM_NODE (body), WEBKIT_DOM_NODE (element), WEBKIT_DOM_NODE (signature), NULL); } else if (element && start_bottom) { /* Leave it how it is */ } else element = WEBKIT_DOM_ELEMENT (body); } move_caret: if (element) { WebKitDOMDOMSelection *dom_selection = NULL; WebKitDOMDOMWindow *dom_window = NULL; WebKitDOMRange *range = NULL; dom_window = webkit_dom_document_get_default_view (document); dom_selection = webkit_dom_dom_window_get_selection (dom_window); range = webkit_dom_document_create_range (document); webkit_dom_range_select_node_contents ( range, WEBKIT_DOM_NODE (element), NULL); webkit_dom_range_collapse (range, TRUE, NULL); webkit_dom_dom_selection_remove_all_ranges (dom_selection); webkit_dom_dom_selection_add_range (dom_selection, range); g_clear_object (&dom_selection); g_clear_object (&dom_window); g_clear_object (&range); } if (start_bottom) e_editor_dom_scroll_to_caret (editor_page); g_clear_object (¶graphs); e_editor_dom_force_spell_check_in_viewport (editor_page); e_editor_page_unblock_selection_changed (editor_page); }