Skip to content

Commit

Permalink
Set document font explicitly with CSS in conversation viewer: Bug 713746
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rschroll committed Jun 4, 2014
1 parent ef98b7d commit 4cfd18b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
26 changes: 26 additions & 0 deletions src/client/conversation-viewer/conversation-web-view.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions theming/message-viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion theming/message-viewer.html
Original file line number Diff line number Diff line change
@@ -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>
Expand Down

0 comments on commit 4cfd18b

Please sign in to comment.