Add get_initial_specified_value to many longhands

This commit is contained in:
Xidorn Quan 2017-02-28 15:20:34 +11:00
parent ce46e6d034
commit 2e07ce7e84
10 changed files with 90 additions and 4 deletions

View file

@ -5,7 +5,7 @@
<%! from data import Keyword, to_rust_ident, to_camel_case, LOGICAL_SIDES, PHYSICAL_SIDES, LOGICAL_SIZES %>
<%def name="predefined_type(name, type, initial_value, parse_method='parse',
needs_context=True, vector=False, **kwargs)">
needs_context=True, vector=False, initial_specified_value=None, **kwargs)">
<%def name="predefined_type_inner(name, type, initial_value, parse_method)">
#[allow(unused_imports)]
use app_units::Au;
@ -15,6 +15,9 @@
pub use values::computed::${type} as T;
}
#[inline] pub fn get_initial_value() -> computed_value::T { ${initial_value} }
% if initial_specified_value:
#[inline] pub fn get_initial_specified_value() -> SpecifiedValue { ${initial_specified_value} }
% endif
#[allow(unused_variables)]
#[inline] pub fn parse(context: &ParserContext, input: &mut Parser)
-> Result<SpecifiedValue, ()> {

View file

@ -8,6 +8,7 @@
${helpers.predefined_type("background-color", "CSSColor",
"::cssparser::Color::RGBA(::cssparser::RGBA::transparent())",
initial_specified_value="SpecifiedValue::transparent()",
spec="https://drafts.csswg.org/css-backgrounds/#background-color",
animatable=True, complex_color=True)}

View file

@ -10,6 +10,7 @@
${helpers.predefined_type("column-width",
"length::LengthOrAuto",
"Either::Second(Auto)",
initial_specified_value="Either::Second(Auto)",
parse_method="parse_non_negative_length",
extra_prefixes="moz",
animatable=False,
@ -62,6 +63,11 @@ ${helpers.predefined_type("column-width",
computed_value::T(None)
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue::Auto
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
@ -146,6 +152,7 @@ ${helpers.single_keyword("column-fill", "auto balance", extra_prefixes="moz",
// https://drafts.csswg.org/css-multicol-1/#crc
${helpers.predefined_type("column-rule-color", "CSSColor",
"::cssparser::Color::CurrentColor",
initial_specified_value="specified::CSSColor::currentcolor()",
products="gecko", animatable=True, extra_prefixes="moz",
complex_color=True, need_clone=True,
spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule-color")}

View file

@ -326,6 +326,11 @@ ${helpers.single_keyword("font-variant-caps",
computed_value::T::Weight400 // normal
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue::Normal
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
@ -407,6 +412,11 @@ ${helpers.single_keyword("font-variant-caps",
Au::from_px(FONT_MEDIUM_PX)
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue(specified::LengthOrPercentage::Length(NoCalcLength::medium()))
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
@ -502,6 +512,11 @@ ${helpers.single_keyword("font-variant-caps",
computed_value::T::None
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue::None
}
/// none | <number>
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
use values::specified::Number;
@ -750,6 +765,11 @@ ${helpers.single_keyword("font-variant-position",
computed_value::T::Normal
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue::Normal
}
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
Ok(SpecifiedValue::Normal)

View file

@ -101,6 +101,11 @@
#[inline]
pub fn get_initial_value() -> computed_value::T { computed_value::T::Normal }
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue::Normal
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
@ -1031,6 +1036,7 @@ ${helpers.single_keyword("text-align-last",
${helpers.predefined_type("text-emphasis-color", "CSSColor",
"::cssparser::Color::CurrentColor",
initial_specified_value="specified::CSSColor::currentcolor()",
products="gecko", animatable=True,
complex_color=True, need_clone=True,
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-color")}
@ -1056,6 +1062,7 @@ ${helpers.predefined_type(
${helpers.predefined_type(
"-webkit-text-stroke-color", "CSSColor",
"CSSParserColor::CurrentColor",
initial_specified_value="specified::CSSColor::currentcolor()",
products="gecko", animatable=True,
complex_color=True, need_clone=True,
spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-color")}
@ -1066,7 +1073,7 @@ ${helpers.predefined_type(
use std::fmt;
use style_traits::ToCss;
use values::HasViewportPercentage;
use values::specified::BorderWidth;
use values::specified::{BorderWidth, Length};
pub type SpecifiedValue = BorderWidth;
@ -1082,6 +1089,10 @@ ${helpers.predefined_type(
#[inline] pub fn get_initial_value() -> computed_value::T {
Au::from_px(0)
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
BorderWidth::from_length(Length::zero())
}
</%helpers:longhand>

View file

@ -38,7 +38,7 @@ ${helpers.single_keyword("list-style-type", """
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-type")}
${helpers.predefined_type("list-style-image", "UrlOrNone", "Either::Second(None_)",
animatable=False,
initial_specified_value="Either::Second(None_)", animatable=False,
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-image")}
<%helpers:longhand name="quotes" animatable="False"

View file

@ -11,6 +11,7 @@
// TODO(pcwalton): `invert`
${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::CurrentColor",
initial_specified_value="specified::CSSColor::currentcolor()",
animatable=True, complex_color=True, need_clone=True,
spec="https://drafts.csswg.org/css-ui/#propdef-outline-color")}
@ -39,6 +40,11 @@ ${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::Curr
Either::Second(BorderStyle::none)
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
Either::Second(BorderStyle::none)
}
pub mod computed_value {
pub type T = super::SpecifiedValue;
}
@ -88,7 +94,13 @@ ${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::Curr
use app_units::Au;
pub type T = Au;
}
pub use super::border_top_width::get_initial_value;
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue(specified::Length::NoCalc(specified::NoCalcLength::medium()))
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;

View file

@ -169,6 +169,10 @@ ${helpers.single_keyword("unicode-bidi",
#[inline] pub fn get_initial_value() -> computed_value::T {
computed_value::none
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue::empty()
}
/// none | [ underline || overline || line-through || blink ]
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
let mut result = SpecifiedValue::empty();
@ -219,7 +223,8 @@ ${helpers.single_keyword("text-decoration-style",
${helpers.predefined_type(
"text-decoration-color", "CSSColor",
"CSSParserColor::RGBA(RGBA::new(0, 0, 0, 255))",
"::cssparser::Color::CurrentColor",
initial_specified_value="specified::CSSColor::currentcolor()",
complex_color=True,
products="gecko",
animatable=True,

View file

@ -344,6 +344,12 @@ impl NoCalcLength {
*self == NoCalcLength::Absolute(Au(0))
}
#[inline]
/// Returns a `medium` length.
pub fn medium() -> NoCalcLength {
NoCalcLength::Absolute(Au::from_px(FONT_MEDIUM_PX))
}
/// Get an absolute length from a px value.
#[inline]
pub fn from_px(px_value: CSSFloat) -> NoCalcLength {

View file

@ -78,6 +78,27 @@ impl ToCss for CSSColor {
}
}
impl CSSColor {
#[inline]
/// Returns currentcolor value.
pub fn currentcolor() -> CSSColor {
CSSColor {
parsed: cssparser::Color::CurrentColor,
authored: None,
}
}
#[inline]
/// Returns transparent value.
pub fn transparent() -> CSSColor {
CSSColor {
parsed: cssparser::Color::RGBA(cssparser::RGBA::transparent()),
// This should probably be "transparent", but maybe it doesn't matter.
authored: None,
}
}
}
#[derive(Clone, PartialEq, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[allow(missing_docs)]