[geary] Set document font explicitly with CSS in conversation viewer: Bug 713746



commit 4cfd18b52e83425b80b6474e175120125deabb25
Author: Robert Schroll <rschroll gmail com>
Date:   Wed May 21 21:30:54 2014 -0700

    Set document font explicitly with CSS in conversation viewer: Bug 713746
    
    This avoids the previously-mentioned bug in "font-family: initial".
    
    Note that if you set the font size to 11pt in CSS, for example, you get
    15px.  But if you set it to 11pt with the WebSettings and then set that
    size with font-size: medium, you get 14 px.

 .../conversation-viewer/conversation-web-view.vala |   26 ++++++++++++++++++++
 theming/message-viewer.css                         |    2 -
 theming/message-viewer.html                        |    5 +++-
 3 files changed, 30 insertions(+), 3 deletions(-)
---
diff --git a/src/client/conversation-viewer/conversation-web-view.vala 
b/src/client/conversation-viewer/conversation-web-view.vala
index f2ccc2d..deab9b9 100644
--- a/src/client/conversation-viewer/conversation-web-view.vala
+++ b/src/client/conversation-viewer/conversation-web-view.vala
@@ -42,6 +42,7 @@ public class ConversationWebView : StylishWebView {
         navigation_policy_decision_requested.connect(on_navigation_policy_decision_requested);
         new_window_policy_decision_requested.connect(on_navigation_policy_decision_requested);
         web_inspector.inspect_web_view.connect(activate_inspector);
+        document_font_changed.connect(on_document_font_changed);
         
         // Load the HTML into WebKit.
         // Note: load_finished signal MUST be hooked up before this call.
@@ -125,6 +126,7 @@ public class ConversationWebView : StylishWebView {
             debug("Unable to load message-viewer document from files: %s", error.message);
         }
         
+        on_document_font_changed();
         load_user_style();
         
         // Grab the HTML container.
@@ -143,6 +145,30 @@ public class ConversationWebView : StylishWebView {
         set_icon_src("#link_warning_template .close_link_warning", "close-symbolic");
     }
     
+    private void on_document_font_changed() {
+        string document_css = "";
+        if (document_font != null) {
+            string font_family = Pango.FontDescription.from_string(document_font).get_family();
+            document_css = @".email .body { font-family: $font_family; font-size: medium; }\n";
+        }
+        
+        WebKit.DOM.Document document = get_dom_document();
+        WebKit.DOM.Element style_element = document.get_element_by_id("default_fonts");
+        if (style_element == null)  // Not yet loaded
+            return;
+        
+        ulong n = style_element.child_nodes.length;
+        try {
+            for (int i = 0; i < n; i++)
+                style_element.remove_child(style_element.first_child);
+            
+            WebKit.DOM.Text text_node = document.create_text_node(document_css);
+            style_element.append_child(text_node);
+        } catch (Error error) {
+            debug("Error updating default font style: %s", error.message);
+        }
+    }
+    
     private void load_user_style() {
         try {
             WebKit.DOM.Document document = get_dom_document();
diff --git a/theming/message-viewer.css b/theming/message-viewer.css
index 06b4989..fef37b0 100644
--- a/theming/message-viewer.css
+++ b/theming/message-viewer.css
@@ -217,8 +217,6 @@ body:not(.nohide) .email.hide .header_container .avatar {
     overflow-x: auto;
     overflow-y: hidden;
     position: relative;  /* in case anything inside is positioned */
-    font-family: initial;
-    font-size: medium;
 }
 
 .email .remote_images {
diff --git a/theming/message-viewer.html b/theming/message-viewer.html
index 7a22310..b928029 100644
--- a/theming/message-viewer.html
+++ b/theming/message-viewer.html
@@ -1,5 +1,8 @@
 <html>
-<head><title>Geary</title></head>
+<head>
+    <title>Geary</title>
+    <style id="default_fonts"></style>
+</head>
 <body>
 <div id="message_container"><span id="placeholder"></span></div>
 <div id="multiple_messages"><div id="selection_counter" class="email"></div></div>


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