diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2014-09-19 14:27:30 +0100 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2014-09-19 19:04:31 +0100 |
commit | 4e71b215b809471d8b0251fd8ab6872a27bece40 (patch) | |
tree | 0f09d69ac1daa683e495c7492c57144708ad896a | |
parent | 010d87b93ef9133a03426eac928b12477599055f (diff) | |
download | servo-4e71b215b809471d8b0251fd8ab6872a27bece40.tar.gz servo-4e71b215b809471d8b0251fd8ab6872a27bece40.zip |
Add font-size absolute size keywords. Fix #3417.
Relative size keywords are still missing:
https://github.com/servo/servo/issues/3423
-rw-r--r-- | components/style/properties/mod.rs.mako | 29 | ||||
-rw-r--r-- | tests/ref/basic.list | 3 | ||||
-rw-r--r-- | tests/ref/font_size.html | 13 | ||||
-rw-r--r-- | tests/ref/font_size_em.html | 13 | ||||
-rw-r--r-- | tests/ref/font_size_em_ref.html | 12 | ||||
-rw-r--r-- | tests/ref/font_size_percentage.html | 13 | ||||
-rw-r--r-- | tests/ref/font_size_ref.html | 13 |
7 files changed, 47 insertions, 49 deletions
diff --git a/components/style/properties/mod.rs.mako b/components/style/properties/mod.rs.mako index f65e9b35280..c6b4cec4028 100644 --- a/components/style/properties/mod.rs.mako +++ b/components/style/properties/mod.rs.mako @@ -904,8 +904,9 @@ pub mod longhands { use super::super::Au; pub type T = Au; } + static MEDIUM_PX: int = 16; #[inline] pub fn get_initial_value() -> computed_value::T { - Au::from_px(16) // medium + Au::from_px(MEDIUM_PX) } #[inline] pub fn to_computed_value(_value: SpecifiedValue, context: &computed::Context) @@ -913,16 +914,26 @@ pub mod longhands { // We already computed this element's font size; no need to compute it again. return context.font_size } - /// <length> | <percentage> - /// TODO: support <absolute-size> and <relative-size> + /// <length> | <percentage> | <absolute-size> + /// TODO: support <relative-size> pub fn from_component_value(input: &ComponentValue, _base_url: &Url) -> Result<SpecifiedValue, ()> { - specified::LengthOrPercentage::parse_non_negative(input).map(|value| { - match value { - specified::LP_Length(value) => value, - specified::LP_Percentage(value) => specified::Em(value), - } - }) + match specified::LengthOrPercentage::parse_non_negative(input) { + Ok(specified::LP_Length(value)) => return Ok(value), + Ok(specified::LP_Percentage(value)) => return Ok(specified::Em(value)), + Err(()) => (), + } + let au = match try!(get_ident_lower(input)).as_slice() { + "xx-small" => Au::from_px(MEDIUM_PX) * 3 / 5, + "x-small" => Au::from_px(MEDIUM_PX) * 3 / 4, + "small" => Au::from_px(MEDIUM_PX) * 8 / 9, + "medium" => Au::from_px(MEDIUM_PX), + "large" => Au::from_px(MEDIUM_PX) * 6 / 5, + "x-large" => Au::from_px(MEDIUM_PX) * 3 / 2, + "xx-large" => Au::from_px(MEDIUM_PX) * 2, + _ => return Err(()) + }; + Ok(specified::Au_(au)) } </%self:single_component_value> diff --git a/tests/ref/basic.list b/tests/ref/basic.list index 7f5a9ee7fa6..71120311643 100644 --- a/tests/ref/basic.list +++ b/tests/ref/basic.list @@ -23,8 +23,7 @@ == text_decoration_cached.html text_decoration_cached_ref.html # text_decoration_propagation_a.html text_decoration_propagation_b.html # inline_text_align_a.html inline_text_align_b.html -== font_size_em.html font_size_em_ref.html -== font_size_percentage.html font_size_em_ref.html +== font_size.html font_size_ref.html == img_size_a.html img_size_b.html == img_dynamic_remove.html img_dynamic_remove_ref.html == upper_id_attr.html upper_id_attr_ref.html diff --git a/tests/ref/font_size.html b/tests/ref/font_size.html new file mode 100644 index 00000000000..868a6f4b3d3 --- /dev/null +++ b/tests/ref/font_size.html @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<title>font-size (issues #1435, #3417)</title> +<body style="font-size: 20px"> +<p style="font-size: 24pt">24pt is 32px. +<p style="font-size: 2em">2em is 40px. +<p style="font-size: 200%">200% is 40px. +<p style="font-size: xx-small">xx-small is 9.6px. +<p style="font-size: x-small">x-small is 12px. +<p style="font-size: small">small is 14.2222…px. +<p style="font-size: medium">medium is 16px. +<p style="font-size: large">large is 19.2px. +<p style="font-size: x-large">x-large is 24px. +<p style="font-size: xx-large">xx-large is 32px. diff --git a/tests/ref/font_size_em.html b/tests/ref/font_size_em.html deleted file mode 100644 index 5f1983d12c0..00000000000 --- a/tests/ref/font_size_em.html +++ /dev/null @@ -1,13 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <title>font-size: 2em (Bug #1435)</title> - <style type="text/css"> - body { font-size: 20px; } - p { font-size: 2em; } - </style> - </head> - <body> - <p>This text should be 40px high.</p> - </body> -</html> diff --git a/tests/ref/font_size_em_ref.html b/tests/ref/font_size_em_ref.html deleted file mode 100644 index 3697fdb0e6d..00000000000 --- a/tests/ref/font_size_em_ref.html +++ /dev/null @@ -1,12 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <title>font-size: 2em (Bug #1435)</title> - <style type="text/css"> - p { font-size: 40px; } - </style> - </head> - <body> - <p>This text should be 40px high.</p> - </body> -</html> diff --git a/tests/ref/font_size_percentage.html b/tests/ref/font_size_percentage.html deleted file mode 100644 index d344ea782e9..00000000000 --- a/tests/ref/font_size_percentage.html +++ /dev/null @@ -1,13 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <title>font-size: 200% (Bug #1435)</title> - <style type="text/css"> - body { font-size: 20px } - p { font-size: 200%; } - </style> - </head> - <body> - <p>This text should be 40px high.</p> - </body> -</html> diff --git a/tests/ref/font_size_ref.html b/tests/ref/font_size_ref.html new file mode 100644 index 00000000000..d85c120b822 --- /dev/null +++ b/tests/ref/font_size_ref.html @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<title>font-size (issues #1435, #3417)</title> +<body> +<p style="font-size: 32px">24pt is 32px. +<p style="font-size: 40px">2em is 40px. +<p style="font-size: 40px">200% is 40px. +<p style="font-size: 9.6px">xx-small is 9.6px. +<p style="font-size: 12px">x-small is 12px. +<p style="font-size: 14.2222222222222222222222222222px">small is 14.2222…px. +<p style="font-size: 16px">medium is 16px. +<p style="font-size: 19.2px">large is 19.2px. +<p style="font-size: 24px">x-large is 24px. +<p style="font-size: 32px">xx-large is 32px. |