Auto merge of #7683 - frewsxcv:html-font-element-size-attr, r=nox

Implement `size` attribute for <font> element



<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7683)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-10-05 02:33:02 -06:00
commit 7debfd1f4c
12 changed files with 220 additions and 181 deletions

View file

@ -1919,6 +1919,7 @@ pub mod longhands {
use app_units::Au;
use cssparser::ToCss;
use std::fmt;
use values::FONT_MEDIUM_PX;
use values::computed::Context;
impl ToCss for SpecifiedValue {
@ -1933,9 +1934,8 @@ pub mod longhands {
use app_units::Au;
pub type T = Au;
}
const MEDIUM_PX: i32 = 16;
#[inline] pub fn get_initial_value() -> computed_value::T {
Au::from_px(MEDIUM_PX)
Au::from_px(FONT_MEDIUM_PX)
}
impl ToComputedValue for SpecifiedValue {
@ -1958,21 +1958,8 @@ pub mod longhands {
specified::LengthOrPercentage::Calc(_) => Err(())
})
.or_else(|()| {
match_ignore_ascii_case! { try!(input.expect_ident()),
"xx-small" => Ok(specified::Length::Absolute(Au::from_px(MEDIUM_PX) * 3 / 5)),
"x-small" => Ok(specified::Length::Absolute(Au::from_px(MEDIUM_PX) * 3 / 4)),
"small" => Ok(specified::Length::Absolute(Au::from_px(MEDIUM_PX) * 8 / 9)),
"medium" => Ok(specified::Length::Absolute(Au::from_px(MEDIUM_PX))),
"large" => Ok(specified::Length::Absolute(Au::from_px(MEDIUM_PX) * 6 / 5)),
"x-large" => Ok(specified::Length::Absolute(Au::from_px(MEDIUM_PX) * 3 / 2)),
"xx-large" => Ok(specified::Length::Absolute(Au::from_px(MEDIUM_PX) * 2)),
// https://github.com/servo/servo/issues/3423#issuecomment-56321664
"smaller" => Ok(specified::Length::FontRelative(specified::FontRelativeLength::Em(0.85))),
"larger" => Ok(specified::Length::FontRelative(specified::FontRelativeLength::Em(1.2)))
_ => Err(())
}
let ident = try!(input.expect_ident());
specified::Length::from_str(&ident as &str).ok_or(())
})
.map(SpecifiedValue)
}

View file

@ -66,6 +66,8 @@ macro_rules! define_numbered_css_keyword_enum {
pub type CSSFloat = f32;
pub const FONT_MEDIUM_PX: i32 = 16;
pub mod specified {
use app_units::Au;
@ -79,7 +81,7 @@ pub mod specified {
use std::ops::Mul;
use style_traits::values::specified::AllowedNumericType;
use super::AuExtensionMethods;
use super::CSSFloat;
use super::{CSSFloat, FONT_MEDIUM_PX};
use url::Url;
#[derive(Clone, PartialEq, Debug, HeapSizeOf)]
@ -293,6 +295,24 @@ pub mod specified {
const AU_PER_PT: CSSFloat = AU_PER_IN / 72.;
const AU_PER_PC: CSSFloat = AU_PER_PT * 12.;
impl Length {
// https://drafts.csswg.org/css-fonts-3/#font-size-prop
pub fn from_str(s: &str) -> Option<Length> {
Some(match_ignore_ascii_case! { s,
"xx-small" => Length::Absolute(Au::from_px(FONT_MEDIUM_PX) * 3 / 5),
"x-small" => Length::Absolute(Au::from_px(FONT_MEDIUM_PX) * 3 / 4),
"small" => Length::Absolute(Au::from_px(FONT_MEDIUM_PX) * 8 / 9),
"medium" => Length::Absolute(Au::from_px(FONT_MEDIUM_PX)),
"large" => Length::Absolute(Au::from_px(FONT_MEDIUM_PX) * 6 / 5),
"x-large" => Length::Absolute(Au::from_px(FONT_MEDIUM_PX) * 3 / 2),
"xx-large" => Length::Absolute(Au::from_px(FONT_MEDIUM_PX) * 2),
// https://github.com/servo/servo/issues/3423#issuecomment-56321664
"smaller" => Length::FontRelative(FontRelativeLength::Em(0.85)),
"larger" => Length::FontRelative(FontRelativeLength::Em(1.2))
_ => return None
})
}
#[inline]
fn parse_internal(input: &mut Parser, context: &AllowedNumericType) -> Result<Length, ()> {
match try!(input.next()) {