[evolution/webkit: 159/171] Use WebKit DOM bindings to collapse/expand headers
- From: Dan VrÃtil <dvratil src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/webkit: 159/171] Use WebKit DOM bindings to collapse/expand headers
- Date: Fri, 24 Feb 2012 12:47:50 +0000 (UTC)
commit 380fd648f562b6acd78083404c91da0a2ff9aef7
Author: Dan VrÃtil <dvratil redhat com>
Date: Tue Feb 21 14:51:34 2012 +0100
Use WebKit DOM bindings to collapse/expand headers
mail/e-mail-display.c | 113 ++++++++++++++++++++++++++++++++++++-------------
mail/em-format-html.c | 21 ++++-----
2 files changed, 93 insertions(+), 41 deletions(-)
---
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 0f83555..b1716c8 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -923,44 +923,96 @@ mail_display_plugin_widget_requested (WebKitWebView *web_view,
}
static void
-mail_display_frame_created (WebKitWebView *web_view,
- WebKitWebFrame *frame,
- gpointer user_data)
+toggle_headers_visibility (WebKitDOMElement *button,
+ WebKitDOMEvent *event,
+ WebKitWebView *web_view)
{
- /* Re-bind visibility of this newly created <iframe> with
- * related EAttachmentButton whenever content of this <iframe> is
- * (re)loaded */
+ WebKitDOMDocument *document;
+ WebKitDOMElement *short_headers, *full_headers;
+ WebKitDOMCSSStyleDeclaration *css_short, *css_full;
+ gboolean expanded;
+ const gchar *path;
- g_signal_connect (frame, "notify::load-status",
- G_CALLBACK (bind_attachment_iframe_visibility), NULL);
-}
+ document = webkit_web_view_get_dom_document (web_view);
+ short_headers = webkit_dom_document_get_element_by_id (
+ document, "__evo-short-headers");
+ if (!short_headers)
+ return;
-static void
-mail_display_headers_collapsed_state_changed (EWebView *web_view,
- size_t arg_count,
- const JSValueRef args[],
- gpointer user_data)
-{
- JSGlobalContextRef ctx = e_web_view_get_global_context (web_view);
+ css_short = webkit_dom_element_get_style (short_headers);
+
+ full_headers = webkit_dom_document_get_element_by_id (
+ document, "__evo-full-headers");
+ if (!full_headers)
+ return;
+
+ css_full = webkit_dom_element_get_style (full_headers);
+
+
+ expanded = (g_strcmp0(webkit_dom_css_style_declaration_get_property_value (
+ css_full, "display"), "block") == 0);
+
+ webkit_dom_css_style_declaration_set_property (css_full, "display",
+ expanded ? "none" : "block", "", NULL);
+ webkit_dom_css_style_declaration_set_property (css_short, "display",
+ expanded ? "block" : "none", "", NULL);
+
+ if (expanded)
+ path = "evo-file://" EVOLUTION_IMAGESDIR "/plus.png";
+ else
+ path = "evo-file://" EVOLUTION_IMAGESDIR "/minus.png";
+
+ webkit_dom_html_image_element_set_src (
+ WEBKIT_DOM_HTML_IMAGE_ELEMENT (button), path);
- e_mail_display_set_headers_collapsed (E_MAIL_DISPLAY (web_view),
- JSValueToBoolean (ctx, args[0]));
+ e_mail_display_set_headers_collapsed (E_MAIL_DISPLAY (web_view), !expanded);
+
+ d(printf("Headers %s!\n", expanded ? "collapsed" : "expanded"));
}
static void
-mail_display_install_js_callbacks (WebKitWebView *web_view,
- WebKitWebFrame *frame,
- gpointer context,
- gpointer window_object,
- gpointer user_data)
+bind_collapsable_headers (GObject *object,
+ GParamSpec *pspec,
+ gpointer user_data)
{
- if (frame != webkit_web_view_get_main_frame (web_view))
- return;
+ WebKitWebView *web_view;
+ WebKitWebFrame *frame;
+ WebKitLoadStatus load_status;
+ WebKitDOMDocument *document;
+ WebKitDOMElement *button;
- e_web_view_install_js_callback (E_WEB_VIEW (web_view), "headers_collapsed",
- (EWebViewJSFunctionCallback) mail_display_headers_collapsed_state_changed, user_data);
+ frame = WEBKIT_WEB_FRAME (object);
+ load_status = webkit_web_frame_get_load_status (frame);
+ if (load_status != WEBKIT_LOAD_FINISHED)
+ return;
+
+ web_view = webkit_web_frame_get_web_view (frame);
+ document = webkit_web_view_get_dom_document (web_view);
+ button = webkit_dom_document_get_element_by_id (
+ document, "__evo-collapse-headers-img");
+ if (!button)
+ return;
+
+ d(printf("Conntecting to __evo-collapsable-headers-img::click event\n"));
+
+ webkit_dom_event_target_add_event_listener (
+ WEBKIT_DOM_EVENT_TARGET (button), "click",
+ G_CALLBACK (toggle_headers_visibility), FALSE, web_view);
+}
+
+static void
+mail_display_frame_created (WebKitWebView *web_view,
+ WebKitWebFrame *frame,
+ gpointer user_data)
+{
+ d(printf("Frame %s created!\n", webkit_web_frame_get_name (frame)));
+ /* Re-bind visibility of this newly created <iframe> with
+ * related EAttachmentButton whenever content of this <iframe> is
+ * (re)loaded */
+ g_signal_connect (frame, "notify::load-status",
+ G_CALLBACK (bind_attachment_iframe_visibility), NULL);
}
static void
@@ -1033,6 +1085,7 @@ e_mail_display_init (EMailDisplay *display)
SoupSessionFeature *feature;
const gchar *user_cache_dir;
WebKitWebSettings *settings;
+ WebKitWebFrame *main_frame;
display->priv = E_MAIL_DISPLAY_GET_PRIVATE (display);
@@ -1052,8 +1105,6 @@ e_mail_display_init (EMailDisplay *display)
g_signal_connect (display, "navigation-policy-decision-requested",
G_CALLBACK (mail_display_link_clicked), NULL);
- g_signal_connect (display, "window-object-cleared",
- G_CALLBACK (mail_display_install_js_callbacks), NULL);
g_signal_connect (display, "resource-request-starting",
G_CALLBACK (mail_display_resource_requested), NULL);
g_signal_connect (display, "process-mailto",
@@ -1065,6 +1116,10 @@ e_mail_display_init (EMailDisplay *display)
g_signal_connect (display, "frame-created",
G_CALLBACK (mail_display_frame_created), NULL);
+ main_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (display));
+ g_signal_connect (main_frame, "notify::load-status",
+ G_CALLBACK (bind_collapsable_headers), NULL);
+
/* Because we are loading from a hard-coded string, there is
* no chance of I/O errors. Failure here implies a malformed
* UI definition. Full stop. */
diff --git a/mail/em-format-html.c b/mail/em-format-html.c
index cf124f7..294e2c8 100644
--- a/mail/em-format-html.c
+++ b/mail/em-format-html.c
@@ -854,7 +854,9 @@ efh_write_headers (EMFormat *emf,
if (info->headers_collapsable) {
g_string_append_printf (buffer,
- "<img src=\"evo-file://%s/%s\" onClick=\"collapse_headers();\" class=\"navigable\" id=\"collapse-headers-img\" /></td><td>",
+ "<img src=\"evo-file://%s/%s\" onClick=\"collapse_headers();\" "
+ "class=\"navigable\" id=\"__evo-collapse-headers-img\" />"
+ "</td><td>",
EVOLUTION_IMAGESDIR,
(info->headers_collapsed) ? "plus.png" : "minus.png");
@@ -1320,15 +1322,6 @@ efh_write_message (EMFormat *emf,
" if (e.display==\"inline\") { e.display=\"none\"; f.display=\"inline\"; g.src=g.src.substr(0,g.src.lastIndexOf(\"/\"))+\"/plus.png\"; }\n"
" else { e.display=\"inline\"; f.display=\"none\"; g.src=g.src.substr(0,g.src.lastIndexOf(\"/\"))+\"/minus.png\"; }\n"
"}\n"
- "function collapse_headers() {\n"
- " var f=window.document.getElementById(\"full-headers\").style;\n"
- " var s=window.document.getElementById(\"short-headers\").style;\n"
- " var i=window.document.getElementById(\"collapse-headers-img\");\n"
- " if (f.display==\"block\") { f.display=\"none\"; s.display=\"block\";\n"
- " i.src=i.src.substr(0,i.src.lastIndexOf(\"/\"))+\"/plus.png\"; window.headers_collapsed(true, window.em_format_html); }\n"
- " else { f.display=\"block\"; s.display=\"none\";\n"
- " i.src=i.src.substr(0,i.src.lastIndexOf(\"/\"))+\"/minus.png\"; window.headers_collapsed(false, window.em_format_html); }\n"
- "}\n"
"function set_header_visible(header,value,visible) { // Printing\n"
" var hdrs=window.document.getElementsByClassName('header-item');\n"
" for (var i = 0; i < hdrs.length; i++) { \n"
@@ -2295,7 +2288,9 @@ efh_format_short_headers (EMFormatHTML *efh,
evolution_imagesdir = g_filename_to_uri (EVOLUTION_IMAGESDIR, NULL, NULL);
from = g_string_new ("");
- g_string_append_printf (buffer, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" id=\"short-headers\" style=\"display: %s\">",
+ g_string_append_printf (buffer,
+ "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" "
+ "id=\"__evo-short-headers\" style=\"display: %s\">",
visible ? "block" : "none");
header = ((CamelMimePart *) part)->headers;
@@ -2383,7 +2378,9 @@ efh_format_full_headers (EMFormatHTML *efh,
evolution_imagesdir = g_filename_to_uri (EVOLUTION_IMAGESDIR, NULL, NULL);
- g_string_append_printf (buffer, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" id=\"full-headers\" style=\"display: %s\" width=\"100%%\">",
+ g_string_append_printf (buffer,
+ "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" "
+ "id=\"__evo-full-headers\" style=\"display: %s\" width=\"100%%\">",
visible ? "block" : "none");
header = ((CamelMimePart *) part)->headers;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]