Bug 1375930: Fix rem computation on the root element. r?heycam
I'll be really pissed off if this doesn't make any new test pass and I have to
write one...
I don't actually know how could we get this so wrong for so long...
MozReview-Commit-ID: DK98SS1w5nO
--- a/servo/components/style/values/specified/length.rs
+++ b/servo/components/style/values/specified/length.rs
@@ -107,17 +107,16 @@ impl FontRelativeLength {
reference_font_size,
context.style().writing_mode,
context.in_media_query,
context.device)
}
let reference_font_size = base_size.resolve(context);
- let root_font_size = context.device.root_font_size();
match *self {
FontRelativeLength::Em(length) => reference_font_size.scale_by(length),
FontRelativeLength::Ex(length) => {
match query_font_metrics(context, reference_font_size) {
FontMetricsQueryResult::Available(metrics) => metrics.x_height.scale_by(length),
// https://drafts.csswg.org/css-values/#ex
//
// In the cases where it is impossible or impractical to
@@ -144,17 +143,29 @@ impl FontRelativeLength {
if context.style().writing_mode.is_vertical() {
reference_font_size.scale_by(length)
} else {
reference_font_size.scale_by(0.5 * length)
}
}
}
}
- FontRelativeLength::Rem(length) => root_font_size.scale_by(length)
+ FontRelativeLength::Rem(length) => {
+ // https://drafts.csswg.org/css-values/#rem:
+ //
+ // When specified on the font-size property of the root
+ // element, the rem units refer to the property’s initial
+ // value.
+ //
+ if context.is_root_element {
+ reference_font_size.scale_by(length)
+ } else {
+ context.device.root_font_size().scale_by(length)
+ }
+ }
}
}
}
#[derive(Clone, PartialEq, Copy, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
/// A viewport-relative length.
///