[evolution/wip/webkit-composer: 572/966] Implement 'Monospaced' button



commit 33af69d1fe4ae3c4b9c1f33454bb6d55509473a0
Author: Dan Vrátil <dvratil redhat com>
Date:   Thu Aug 23 16:42:58 2012 +0200

    Implement 'Monospaced' button

 e-util/e-editor-selection.c |   33 +++++++++++++++++++++++----------
 1 files changed, 23 insertions(+), 10 deletions(-)
---
diff --git a/e-util/e-editor-selection.c b/e-util/e-editor-selection.c
index 8dee08c..0358a87 100644
--- a/e-util/e-editor-selection.c
+++ b/e-util/e-editor-selection.c
@@ -1208,12 +1208,14 @@ void
 e_editor_selection_set_monospaced (EEditorSelection *selection,
                                   gboolean monospaced)
 {
+       WebKitDOMDocument *document;
        WebKitDOMRange *range;
+       gboolean is_monospaced;
 
        g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
 
-       if ((e_editor_selection_get_monospaced (selection) ? TRUE : FALSE)
-                               == (monospaced ? TRUE : FALSE)) {
+       is_monospaced = e_editor_selection_get_monospaced (selection) ? TRUE : FALSE;
+       if ((is_monospaced ? TRUE : FALSE) == (monospaced ? TRUE : FALSE)) {
                return;
        }
 
@@ -1222,16 +1224,27 @@ e_editor_selection_set_monospaced (EEditorSelection *selection,
                return;
        }
 
-       /* FIXME WEBKIT Although we can implement applying and
-        * removing style on our own by advanced DOM manipulation,
-        * this change will not be recorded in UNDO and REDO history
-        * TODO: Think of something..... */
+       document = webkit_web_view_get_dom_document (selection->priv->webview);
        if (monospaced) {
-
-               /* apply_format (selection, "TT"); */
-
+               WebKitDOMElement *wrapper;
+               gchar *html;
+
+               wrapper = webkit_dom_document_create_element (document, "TT", NULL);
+               webkit_dom_node_append_child (
+                       WEBKIT_DOM_NODE (wrapper),
+                       WEBKIT_DOM_NODE (webkit_dom_range_clone_contents (range, NULL)),
+                       NULL);
+
+               html = webkit_dom_html_element_get_outer_html (
+                               WEBKIT_DOM_HTML_ELEMENT (wrapper));
+               e_editor_selection_insert_html (selection, html);
        } else {
-               /* remove_format (selection, "TT"); */
+               /* XXX This removes _all_ formatting that the selection has.
+                *     In theory it's possible to write a code that would remove
+                *     the <TT> from selection using advanced DOM manipulation,
+                *     but right now I don't really feel like writing it all... */
+               webkit_dom_document_exec_command (
+                       document, "removeFormat", FALSE, "");
        }
 
        g_object_notify (G_OBJECT (selection), "monospaced");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]