[evolution/webkit-composer: 23/185] Make font-size change work



commit 9356086e64459c03bdc31b46a37ecb4e2057b60e
Author: Dan Vrátil <dvratil redhat com>
Date:   Fri Aug 3 12:52:13 2012 +0200

    Make font-size change work
    
    The 'current-value' property of font-size action group
    is binded to 'font-size' property of EEditorSelection,
    so toggling the action and change of current value when
    selection changes is all automatic.

 e-util/e-editor-actions.c   | 19 +++++-------------
 e-util/e-editor-actions.h   |  2 ++
 e-util/e-editor-selection.c | 47 ++++++++++++++++++++++++++++++++++-----------
 e-util/e-editor-selection.h | 14 +++++++-------
 4 files changed, 50 insertions(+), 32 deletions(-)
---
diff --git a/e-util/e-editor-actions.c b/e-util/e-editor-actions.c
index 0043dda..f7737d4 100644
--- a/e-util/e-editor-actions.c
+++ b/e-util/e-editor-actions.c
@@ -1069,19 +1069,6 @@ action_show_replace_cb (GtkAction *action,
 }
 
 static void
-action_size_cb (GtkRadioAction *action,
-                GtkRadioAction *current,
-                EEditor *editor)
-{
-       EEditorSelection *selection;
-
-       selection = e_editor_widget_get_selection (
-                       e_editor_get_editor_widget (editor));
-       e_editor_selection_set_font_size (
-               selection, gtk_radio_action_get_current_value (current));
-}
-
-static void
 action_spell_check_cb (GtkAction *action,
                        EEditor *editor)
 {
@@ -2078,7 +2065,7 @@ editor_actions_init (EEditor *editor)
                action_group, html_size_entries,
                G_N_ELEMENTS (html_size_entries),
                E_EDITOR_SELECTION_FONT_SIZE_NORMAL,
-               G_CALLBACK (action_size_cb), editor);
+               NULL, NULL);
        gtk_ui_manager_insert_action_group (manager, action_group, 0);
 
        /* Context Menu Actions */
@@ -2172,6 +2159,10 @@ editor_actions_init (EEditor *editor)
                ACTION (BOLD), "active",
                G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
        g_object_bind_property (
+               editor->priv->selection, "font-size",
+               ACTION (FONT_SIZE_GROUP), "current-value",
+               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+       g_object_bind_property (
                editor->priv->selection, "indented",
                ACTION (UNINDENT), "sensitive",
                G_BINDING_SYNC_CREATE);
diff --git a/e-util/e-editor-actions.h b/e-util/e-editor-actions.h
index 1fdab3b..60c92f5 100644
--- a/e-util/e-editor-actions.h
+++ b/e-util/e-editor-actions.h
@@ -82,6 +82,8 @@
        E_EDITOR_ACTION ((editor), "edit-menu")
 #define E_EDITOR_ACTION_FIND_AGAIN(editor) \
        E_EDITOR_ACTION ((editor), "find-again")
+#define E_EDITOR_ACTION_FONT_SIZE_GROUP(editor) \
+       E_EDITOR_ACTION ((editor), "size-plus-zero")
 #define E_EDITOR_ACTION_FORMAT_MENU(editor) \
        E_EDITOR_ACTION ((editor), "format-menu")
 #define E_EDITOR_ACTION_FORMAT_TEXT(editor) \
diff --git a/e-util/e-editor-selection.c b/e-util/e-editor-selection.c
index 086f6a9..8eda4f5 100644
--- a/e-util/e-editor-selection.c
+++ b/e-util/e-editor-selection.c
@@ -69,6 +69,20 @@ enum {
        PROP_UNDERLINE,
 };
 
+static WebKitDOMElement *
+find_parent_element_by_type (WebKitDOMNode *node, GType type)
+{
+       while (node) {
+
+               if (G_TYPE_CHECK_INSTANCE_TYPE (node, type))
+                       return (WebKitDOMElement *) node;
+
+               node = (WebKitDOMNode *) webkit_dom_node_get_parent_element (node);
+       }
+
+       return NULL;
+}
+
 static WebKitDOMRange *
 editor_selection_get_current_range (EEditorSelection *selection)
 {
@@ -174,14 +188,12 @@ e_editor_selection_get_property (GObject *object,
        switch (property_id) {
                case PROP_ALIGNMENT:
                        g_value_set_int (value,
-                                       e_editor_selection_get_alignment (
-                                       selection));
+                               e_editor_selection_get_alignment (selection));
                        return;
 
                case PROP_BACKGROUND_COLOR:
                        g_value_set_string (value,
-                               e_editor_selection_get_background_color (
-                                       selection));
+                               e_editor_selection_get_background_color (selection));
                        return;
 
                case PROP_BOLD:
@@ -294,7 +306,7 @@ e_editor_selection_set_property (GObject *object,
 
                case PROP_FONT_SIZE:
                        e_editor_selection_set_font_size (
-                               selection, g_value_get_uint (value));
+                               selection, g_value_get_int (value));
                        return;
 
                case PROP_ITALIC:
@@ -895,23 +907,36 @@ guint
 e_editor_selection_get_font_size (EEditorSelection *selection)
 {
        WebKitDOMNode *node;
+       WebKitDOMElement *element;
        WebKitDOMRange *range;
-       WebKitDOMCSSStyleDeclaration *css;
        gchar *size;
        gint size_int;
 
-       g_return_val_if_fail (E_IS_EDITOR_SELECTION (selection), 0);
+       g_return_val_if_fail (
+               E_IS_EDITOR_SELECTION (selection),
+               E_EDITOR_SELECTION_FONT_SIZE_NORMAL);
 
        range = editor_selection_get_current_range (selection);
-       node = webkit_dom_range_get_common_ancestor_container (range, NULL);
+       if (!range) {
+               return E_EDITOR_SELECTION_FONT_SIZE_NORMAL;
+       }
 
-       g_free (selection->priv->font_family);
-       css = webkit_dom_element_get_style (WEBKIT_DOM_ELEMENT (node));
-       size = webkit_dom_css_style_declaration_get_property_value (css, "fontSize");
+       node = webkit_dom_range_get_common_ancestor_container (range, NULL);
+       element = find_parent_element_by_type (
+                       node, WEBKIT_TYPE_DOM_HTML_FONT_ELEMENT);
+       if (!element) {
+               return E_EDITOR_SELECTION_FONT_SIZE_NORMAL;
+       }
 
+       size = webkit_dom_html_font_element_get_size (
+                       WEBKIT_DOM_HTML_FONT_ELEMENT (element));
        size_int = atoi (size);
        g_free (size);
 
+       if (size_int == 0) {
+               return E_EDITOR_SELECTION_FONT_SIZE_NORMAL;
+       }
+
        return size_int;
 }
 
diff --git a/e-util/e-editor-selection.h b/e-util/e-editor-selection.h
index a7164e8..63b6737 100644
--- a/e-util/e-editor-selection.h
+++ b/e-util/e-editor-selection.h
@@ -70,13 +70,13 @@ typedef enum {
 } EEditorSelectionBlockFormat;
 
 typedef enum {
-       E_EDITOR_SELECTION_FONT_SIZE_TINY,
-       E_EDITOR_SELECTION_FONT_SIZE_SMALL,
-       E_EDITOR_SELECTION_FONT_SIZE_NORMAL,
-       E_EDITOR_SELECTION_FONT_SIZE_BIG,
-       E_EDITOR_SELECTION_FONT_SIZE_BIGGER,
-       E_EDITOR_SELECTION_FONT_SIZE_LARGE,
-       E_EDITOR_SELECTION_FONT_SIZE_VERY_LARGE,
+       E_EDITOR_SELECTION_FONT_SIZE_TINY       = 1, /* The values match actual */
+       E_EDITOR_SELECTION_FONT_SIZE_SMALL      = 2, /* size in <font size="X"> */
+       E_EDITOR_SELECTION_FONT_SIZE_NORMAL     = 3,
+       E_EDITOR_SELECTION_FONT_SIZE_BIG        = 4,
+       E_EDITOR_SELECTION_FONT_SIZE_BIGGER     = 5,
+       E_EDITOR_SELECTION_FONT_SIZE_LARGE      = 6,
+       E_EDITOR_SELECTION_FONT_SIZE_VERY_LARGE = 7
 } EEditorSelectionFontSize;
 
 typedef enum {


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