[evolution] Bug #707392 - Only very first Collapse/Expand button in message header pane works



commit 969d80155347d1eaa120b5a09cd95885a18687df
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Sep 13 11:23:14 2013 +0200

    Bug #707392 - Only very first Collapse/Expand button in message header pane works
    
    When we were collecting the elements for adding the onclick event
    listeners, we were using the webkit_dom_document_get_element_by_id
    method, but when email had multiple TO, CC or BCC headers it was
    returning just the first elements with given id. To fix this we moved
    to webkit_dom_*_query_selector methods that give us more powerfull
    element extraction from document.
    
    When toggling the visibility of header row, we are now operating just
    in the row that contains the clicked element.
    
    This patch also remove the suffixes from all  __evo-moreaddr ids.

 em-format/e-mail-formatter-utils.c |   43 ++++++++-----------------
 mail/e-mail-display.c              |   61 +++++++++++------------------------
 2 files changed, 33 insertions(+), 71 deletions(-)
---
diff --git a/em-format/e-mail-formatter-utils.c b/em-format/e-mail-formatter-utils.c
index 1967a61..0e9eda4 100644
--- a/em-format/e-mail-formatter-utils.c
+++ b/em-format/e-mail-formatter-utils.c
@@ -200,48 +200,33 @@ e_mail_formatter_format_address (EMailFormatter *formatter,
 
                /* Let us add a '...' if we have more addresses */
                if (limit > 0 && i == limit && a != NULL) {
-                       const gchar *id = NULL;
-
-                       if (strcmp (field, _("To")) == 0) {
-                               id = "to";
-                       } else if (strcmp (field, _("Cc")) == 0) {
-                               id = "cc";
-                       } else if (strcmp (field, _("Bcc")) == 0) {
-                               id = "bcc";
-                       }
+                       if (strcmp (field, _("To")) == 0 ||
+                           strcmp (field, _("Cc")) == 0 ||
+                           strcmp (field, _("Bcc")) == 0) {
 
-                       if (id != NULL) {
-                               g_string_append_printf (
+                               g_string_append (
                                        out,
-                                       "<span id=\"__evo-moreaddr-%s\" "
-                                       "style=\"display: none;\">", id);
+                                       "<span id=\"__evo-moreaddr\" "
+                                       "style=\"display: none;\">");
                                str = g_strdup_printf (
                                        "<img src=\"evo-file://%s/plus.png\" "
-                                       "id=\"__evo-moreaddr-img-%s\" class=\"navigable\">",
-                                       EVOLUTION_IMAGESDIR, id);
+                                       "id=\"__evo-moreaddr-img\" class=\"navigable\">",
+                                       EVOLUTION_IMAGESDIR);
                        }
                }
        }
 
        if (elipsize && str) {
-               const gchar *id = NULL;
-
-               if (strcmp (field, _("To")) == 0) {
-                       id = "to";
-               } else if (strcmp (field, _("Cc")) == 0) {
-                       id = "cc";
-               } else if (strcmp (field, _("Bcc")) == 0) {
-                       id = "bcc";
-               }
+               if (strcmp (field, _("To")) == 0 ||
+                   strcmp (field, _("Cc")) == 0 ||
+                   strcmp (field, _("Bcc")) == 0) {
 
-               if (id != NULL) {
-                       g_string_append_printf (
+                       g_string_append (
                                out,
                                "</span>"
                                "<span class=\"navigable\" "
-                                       "id=\"__evo-moreaddr-ellipsis-%s\" "
-                                       "style=\"display: inline;\">...</span>",
-                               id);
+                                       "id=\"__evo-moreaddr-ellipsis\" "
+                                       "style=\"display: inline;\">...</span>");
                }
        }
 
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 919ba68..d4a0277 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -769,37 +769,31 @@ toggle_headers_visibility (WebKitDOMElement *button,
        d (printf ("Headers %s!\n", expanded ? "collapsed" : "expanded"));
 }
 
-static const gchar *addresses[] = { "to", "cc", "bcc" };
-
 static void
 toggle_address_visibility (WebKitDOMElement *button,
-                           WebKitDOMEvent *event,
-                           const gchar *address)
+                           WebKitDOMEvent *event)
 {
        WebKitDOMElement *full_addr, *ellipsis;
+       WebKitDOMElement *parent;
        WebKitDOMCSSStyleDeclaration *css_full, *css_ellipsis;
-       WebKitDOMDocument *document;
-       gchar *id;
        const gchar *path;
        gboolean expanded;
 
-       document = webkit_dom_node_get_owner_document (
-               WEBKIT_DOM_NODE (button));
+       /* <b> element */
+       parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (button));
+       /* <td> element */
+       parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (parent));
 
-       id = g_strconcat ("__evo-moreaddr-", address, NULL);
-       full_addr = webkit_dom_document_get_element_by_id (document, id);
-       g_free (id);
+       full_addr = webkit_dom_element_query_selector (parent, "#__evo-moreaddr", NULL);
 
-       if (full_addr == NULL)
+       if (!full_addr)
                return;
 
        css_full = webkit_dom_element_get_style (full_addr);
 
-       id = g_strconcat ("__evo-moreaddr-ellipsis-", address, NULL);
-       ellipsis = webkit_dom_document_get_element_by_id (document, id);
-       g_free (id);
+       ellipsis = webkit_dom_element_query_selector (parent, "#__evo-moreaddr-ellipsis", NULL);
 
-       if (ellipsis == NULL)
+       if (!ellipsis)
                return;
 
        css_ellipsis = webkit_dom_element_get_style (ellipsis);
@@ -819,11 +813,9 @@ toggle_address_visibility (WebKitDOMElement *button,
                path = "evo-file://" EVOLUTION_IMAGESDIR "/minus.png";
 
        if (!WEBKIT_DOM_IS_HTML_IMAGE_ELEMENT (button)) {
-               id = g_strconcat ("__evo-moreaddr-img-", address, NULL);
-               button = webkit_dom_document_get_element_by_id (document, id);
-               g_free (id);
+               button = webkit_dom_element_query_selector (parent, "#__evo-moreaddr-img", NULL);
 
-               if (button == NULL)
+               if (!button)
                        return;
        }
 
@@ -895,7 +887,8 @@ setup_dom_bindings (GObject *object,
        WebKitLoadStatus load_status;
        WebKitDOMDocument *document;
        WebKitDOMElement *button;
-       gint ii = 0;
+       WebKitDOMNodeList *list;
+       gint length, ii = 0;
 
        frame = WEBKIT_WEB_FRAME (object);
        load_status = webkit_web_frame_get_load_status (frame);
@@ -913,33 +906,17 @@ setup_dom_bindings (GObject *object,
                        G_CALLBACK (toggle_headers_visibility),
                        FALSE, web_view);
 
-       for (ii = 0; ii < 3; ii++) {
-               gchar *id;
-
-               id = g_strconcat ("__evo-moreaddr-img-", addresses[ii], NULL);
-               button = webkit_dom_document_get_element_by_id (document, id);
-               g_free (id);
-
-               if (button == NULL)
-                       continue;
-
-               webkit_dom_event_target_add_event_listener (
-                       WEBKIT_DOM_EVENT_TARGET (button), "click",
-                       G_CALLBACK (toggle_address_visibility), FALSE,
-                       (gpointer) addresses[ii]);
+       list = webkit_dom_document_query_selector_all (document, "*[id^=__evo-moreaddr-]", NULL);
 
-               id = g_strconcat (
-                       "__evo-moreaddr-ellipsis-", addresses[ii], NULL);
-               button = webkit_dom_document_get_element_by_id (document, id);
-               g_free (id);
+       length = webkit_dom_node_list_get_length (list);
 
-               if (button == NULL)
-                       continue;
+       for (ii = 0; ii < length; ii++) {
+               button = WEBKIT_DOM_ELEMENT (webkit_dom_node_list_item (list, ii));
 
                webkit_dom_event_target_add_event_listener (
                        WEBKIT_DOM_EVENT_TARGET (button), "click",
                        G_CALLBACK (toggle_address_visibility), FALSE,
-                       (gpointer) addresses[ii]);
+                       NULL);
        }
 }
 


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