aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Wu <mwu@mozilla.com>2014-12-11 16:29:03 -0500
committerMichael Wu <mwu@mozilla.com>2014-12-11 16:29:03 -0500
commit94c019dce55fc4191b65cf300f305af57282b9c5 (patch)
tree5eebf42730d11cf3107825d157519e3c2afbad0b
parentd67bcfa7ce7b37e7ed45a53f1daddbc6b2f2ddf2 (diff)
downloadservo-94c019dce55fc4191b65cf300f305af57282b9c5.tar.gz
servo-94c019dce55fc4191b65cf300f305af57282b9c5.zip
Add support for the 'rem' css unit
-rw-r--r--components/style/media_queries.rs2
-rw-r--r--components/style/properties/common_types.rs11
-rw-r--r--components/style/properties/mod.rs.mako14
3 files changed, 20 insertions, 7 deletions
diff --git a/components/style/media_queries.rs b/components/style/media_queries.rs
index 6eea2cd3ee9..30879d64f4b 100644
--- a/components/style/media_queries.rs
+++ b/components/style/media_queries.rs
@@ -125,7 +125,7 @@ fn parse_value_as_length(value: &ComponentValue) -> Result<Au, ()> {
// http://dev.w3.org/csswg/mediaqueries3/ - Section 6
// em units are relative to the initial font-size.
let initial_font_size = longhands::font_size::get_initial_value();
- Ok(computed::compute_Au_with_font_size(length, initial_font_size))
+ Ok(computed::compute_Au_with_font_size(length, initial_font_size, initial_font_size))
}
fn parse_media_query_expression(iter: ParserIter) -> Result<Expression, ()> {
diff --git a/components/style/properties/common_types.rs b/components/style/properties/common_types.rs
index 3e8aad1d73c..46a6a784b43 100644
--- a/components/style/properties/common_types.rs
+++ b/components/style/properties/common_types.rs
@@ -25,6 +25,7 @@ pub mod specified {
Au_(Au), // application units
Em(CSSFloat),
Ex(CSSFloat),
+ Rem(CSSFloat),
/// HTML5 "character width", as defined in HTML5 § 14.5.4.
///
@@ -34,7 +35,6 @@ pub mod specified {
// XXX uncomment when supported:
// Ch(CSSFloat),
-// Rem(CSSFloat),
// Vw(CSSFloat),
// Vh(CSSFloat),
// Vmin(CSSFloat),
@@ -73,6 +73,7 @@ pub mod specified {
"pc" => Ok(Au_(Au((value * AU_PER_PC) as i32))),
"em" => Ok(Em(value)),
"ex" => Ok(Ex(value)),
+ "rem" => Ok(Rem(value)),
_ => Err(())
}
}
@@ -463,6 +464,7 @@ pub mod computed {
pub color: longhands::color::computed_value::T,
pub text_decoration: longhands::text_decoration::computed_value::T,
pub font_size: longhands::font_size::computed_value::T,
+ pub root_font_size: longhands::font_size::computed_value::T,
pub display: longhands::display::computed_value::T,
pub positioned: bool,
pub floated: bool,
@@ -471,19 +473,19 @@ pub mod computed {
pub border_bottom_present: bool,
pub border_left_present: bool,
pub is_root_element: bool,
- // TODO, as needed: root font size, viewport size, etc.
+ // TODO, as needed: viewport size, etc.
}
#[allow(non_snake_case)]
#[inline]
pub fn compute_Au(value: specified::Length, context: &Context) -> Au {
- compute_Au_with_font_size(value, context.font_size)
+ compute_Au_with_font_size(value, context.font_size, context.root_font_size)
}
/// A special version of `compute_Au` used for `font-size`.
#[allow(non_snake_case)]
#[inline]
- pub fn compute_Au_with_font_size(value: specified::Length, reference_font_size: Au) -> Au {
+ pub fn compute_Au_with_font_size(value: specified::Length, reference_font_size: Au, root_font_size: Au) -> Au {
match value {
specified::Au_(value) => value,
specified::Em(value) => reference_font_size.scale_by(value),
@@ -491,6 +493,7 @@ pub mod computed {
let x_height = 0.5; // TODO: find that from the font
reference_font_size.scale_by(value * x_height)
},
+ specified::Rem(value) => root_font_size.scale_by(value),
specified::ServoCharacterWidth(value) => {
// This applies the *converting a character width to pixels* algorithm as specified
// in HTML5 § 14.5.4.
diff --git a/components/style/properties/mod.rs.mako b/components/style/properties/mod.rs.mako
index 5dc02d89a9d..017cf4a6d08 100644
--- a/components/style/properties/mod.rs.mako
+++ b/components/style/properties/mod.rs.mako
@@ -1878,6 +1878,7 @@ pub struct ComputedValues {
% endfor
shareable: bool,
pub writing_mode: WritingMode,
+ pub root_font_size: Au,
}
impl ComputedValues {
@@ -2037,7 +2038,8 @@ lazy_static! {
}),
% endfor
shareable: true,
- writing_mode: WritingMode::empty()
+ writing_mode: WritingMode::empty(),
+ root_font_size: longhands::font_size::get_initial_value(),
};
}
@@ -2135,6 +2137,7 @@ fn cascade_with_cached_declarations(applicable_declarations: &[DeclarationBlock]
${style_struct.ident}: style_${style_struct.ident},
% endfor
shareable: shareable,
+ root_font_size: parent_style.root_font_size,
}
}
@@ -2176,6 +2179,7 @@ pub fn cascade(applicable_declarations: &[DeclarationBlock],
inherited_style.get_inheritedtext()._servo_text_decorations_in_effect,
// To be overridden by applicable declarations:
font_size: inherited_font_style.font_size,
+ root_font_size: inherited_style.root_font_size,
display: longhands::display::get_initial_value(),
color: inherited_style.get_color().color,
text_decoration: longhands::text_decoration::get_initial_value(),
@@ -2208,7 +2212,7 @@ pub fn cascade(applicable_declarations: &[DeclarationBlock],
FontSizeDeclaration(ref value) => {
context.font_size = match *value {
SpecifiedValue(specified_value) => computed::compute_Au_with_font_size(
- specified_value, context.inherited_font_size),
+ specified_value, context.inherited_font_size, context.root_font_size),
Initial => longhands::font_size::get_initial_value(),
Inherit => context.inherited_font_size,
}
@@ -2346,12 +2350,17 @@ pub fn cascade(applicable_declarations: &[DeclarationBlock],
box_.display = longhands::display::to_computed_value(box_.display, &context);
}
+ if is_root_element {
+ context.root_font_size = context.font_size;
+ }
+
(ComputedValues {
writing_mode: get_writing_mode(&*style_inheritedbox),
% for style_struct in STYLE_STRUCTS:
${style_struct.ident}: style_${style_struct.ident},
% endfor
shareable: shareable,
+ root_font_size: context.root_font_size,
}, cacheable)
}
@@ -2374,6 +2383,7 @@ pub fn cascade_anonymous(parent_style: &ComputedValues) -> ComputedValues {
% endfor
shareable: false,
writing_mode: parent_style.writing_mode,
+ root_font_size: parent_style.root_font_size,
};
{
let border = result.border.make_unique();