Make font-size: larger/smaller work with the base size stuff

This commit is contained in:
Manish Goregaokar 2017-04-26 11:45:10 -07:00 committed by Manish Goregaokar
parent e23c8f1f3c
commit e4d39b5476
4 changed files with 14 additions and 6 deletions

View file

@ -741,6 +741,10 @@ ${helpers.single_keyword_system("font-variant-caps",
}
% endif
/// This is the ratio applied for font-size: larger
/// and smaller by both Firefox and Chrome
const LARGER_FONT_SIZE_RATIO: f32 = 1.2;
impl SpecifiedValue {
/// https://html.spec.whatwg.org/multipage/#rules-for-parsing-a-legacy-font-size
pub fn from_html_size(size: u8) -> Self {
@ -768,6 +772,10 @@ ${helpers.single_keyword_system("font-variant-caps",
return Some(em)
}
}
} else if let SpecifiedValue::Larger = *self {
return Some(LARGER_FONT_SIZE_RATIO)
} else if let SpecifiedValue::Smaller = *self {
return Some(1. / LARGER_FONT_SIZE_RATIO)
}
None
}
@ -799,11 +807,11 @@ ${helpers.single_keyword_system("font-variant-caps",
key.to_computed_value(context).scale_by(fraction)
}
SpecifiedValue::Smaller => {
FontRelativeLength::Em(0.85)
FontRelativeLength::Em(1. / LARGER_FONT_SIZE_RATIO)
.to_computed_value(context, base_size)
}
SpecifiedValue::Larger => {
FontRelativeLength::Em(1.2)
FontRelativeLength::Em(LARGER_FONT_SIZE_RATIO)
.to_computed_value(context, base_size)
}

View file

@ -21375,11 +21375,11 @@
"support"
],
"css/font_size.html": [
"1647905b6a68c9bb577afcbcca203208de524a88",
"7c944acb4f7d909083888a355e6d664c23081b99",
"reftest"
],
"css/font_size_ref.html": [
"b0b486eb2cbc8537edae3a7c76b08c8ecc9a0ef3",
"cc34cbb1aae8e0d3738476bb09264f0fade78ba6",
"support"
],
"css/font_style.html": [

View file

@ -8,7 +8,7 @@
<p style="font-size: 2em">2em is 40px.
<p style="font-size: 2rem">2rem is 14px.
<p style="font-size: 200%">200% is 40px.
<p style="font-size: smaller">smaller is 17px.
<p style="font-size: smaller">smaller is 16.66666…px.
<p style="font-size: larger">larger is 24px.
<p style="font-size: xx-small">xx-small is 9.6px.
<p style="font-size: x-small">x-small is 12px.

View file

@ -6,7 +6,7 @@
<p style="font-size: 40px">2em is 40px.
<p style="font-size: 14px">2rem is 14px.
<p style="font-size: 40px">200% is 40px.
<p style="font-size: 17px">smaller is 17px.
<p style="font-size: 16.6666666666666666666666666666px">smaller is 16.66666…px.
<p style="font-size: 24px">larger is 24px.
<p style="font-size: 9.6px">xx-small is 9.6px.
<p style="font-size: 12px">x-small is 12px.