mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Add get_initial_specified_value to many longhands
This commit is contained in:
parent
ce46e6d034
commit
2e07ce7e84
10 changed files with 90 additions and 4 deletions
|
@ -5,7 +5,7 @@
|
||||||
<%! from data import Keyword, to_rust_ident, to_camel_case, LOGICAL_SIDES, PHYSICAL_SIDES, LOGICAL_SIZES %>
|
<%! 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',
|
<%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)">
|
<%def name="predefined_type_inner(name, type, initial_value, parse_method)">
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
|
@ -15,6 +15,9 @@
|
||||||
pub use values::computed::${type} as T;
|
pub use values::computed::${type} as T;
|
||||||
}
|
}
|
||||||
#[inline] pub fn get_initial_value() -> computed_value::T { ${initial_value} }
|
#[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)]
|
#[allow(unused_variables)]
|
||||||
#[inline] pub fn parse(context: &ParserContext, input: &mut Parser)
|
#[inline] pub fn parse(context: &ParserContext, input: &mut Parser)
|
||||||
-> Result<SpecifiedValue, ()> {
|
-> Result<SpecifiedValue, ()> {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
${helpers.predefined_type("background-color", "CSSColor",
|
${helpers.predefined_type("background-color", "CSSColor",
|
||||||
"::cssparser::Color::RGBA(::cssparser::RGBA::transparent())",
|
"::cssparser::Color::RGBA(::cssparser::RGBA::transparent())",
|
||||||
|
initial_specified_value="SpecifiedValue::transparent()",
|
||||||
spec="https://drafts.csswg.org/css-backgrounds/#background-color",
|
spec="https://drafts.csswg.org/css-backgrounds/#background-color",
|
||||||
animatable=True, complex_color=True)}
|
animatable=True, complex_color=True)}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
${helpers.predefined_type("column-width",
|
${helpers.predefined_type("column-width",
|
||||||
"length::LengthOrAuto",
|
"length::LengthOrAuto",
|
||||||
"Either::Second(Auto)",
|
"Either::Second(Auto)",
|
||||||
|
initial_specified_value="Either::Second(Auto)",
|
||||||
parse_method="parse_non_negative_length",
|
parse_method="parse_non_negative_length",
|
||||||
extra_prefixes="moz",
|
extra_prefixes="moz",
|
||||||
animatable=False,
|
animatable=False,
|
||||||
|
@ -62,6 +63,11 @@ ${helpers.predefined_type("column-width",
|
||||||
computed_value::T(None)
|
computed_value::T(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
|
SpecifiedValue::Auto
|
||||||
|
}
|
||||||
|
|
||||||
impl ToComputedValue for SpecifiedValue {
|
impl ToComputedValue for SpecifiedValue {
|
||||||
type ComputedValue = computed_value::T;
|
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
|
// https://drafts.csswg.org/css-multicol-1/#crc
|
||||||
${helpers.predefined_type("column-rule-color", "CSSColor",
|
${helpers.predefined_type("column-rule-color", "CSSColor",
|
||||||
"::cssparser::Color::CurrentColor",
|
"::cssparser::Color::CurrentColor",
|
||||||
|
initial_specified_value="specified::CSSColor::currentcolor()",
|
||||||
products="gecko", animatable=True, extra_prefixes="moz",
|
products="gecko", animatable=True, extra_prefixes="moz",
|
||||||
complex_color=True, need_clone=True,
|
complex_color=True, need_clone=True,
|
||||||
spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule-color")}
|
spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule-color")}
|
||||||
|
|
|
@ -326,6 +326,11 @@ ${helpers.single_keyword("font-variant-caps",
|
||||||
computed_value::T::Weight400 // normal
|
computed_value::T::Weight400 // normal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
|
SpecifiedValue::Normal
|
||||||
|
}
|
||||||
|
|
||||||
impl ToComputedValue for SpecifiedValue {
|
impl ToComputedValue for SpecifiedValue {
|
||||||
type ComputedValue = computed_value::T;
|
type ComputedValue = computed_value::T;
|
||||||
|
|
||||||
|
@ -407,6 +412,11 @@ ${helpers.single_keyword("font-variant-caps",
|
||||||
Au::from_px(FONT_MEDIUM_PX)
|
Au::from_px(FONT_MEDIUM_PX)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
|
SpecifiedValue(specified::LengthOrPercentage::Length(NoCalcLength::medium()))
|
||||||
|
}
|
||||||
|
|
||||||
impl ToComputedValue for SpecifiedValue {
|
impl ToComputedValue for SpecifiedValue {
|
||||||
type ComputedValue = computed_value::T;
|
type ComputedValue = computed_value::T;
|
||||||
|
|
||||||
|
@ -502,6 +512,11 @@ ${helpers.single_keyword("font-variant-caps",
|
||||||
computed_value::T::None
|
computed_value::T::None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
|
SpecifiedValue::None
|
||||||
|
}
|
||||||
|
|
||||||
/// none | <number>
|
/// none | <number>
|
||||||
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||||
use values::specified::Number;
|
use values::specified::Number;
|
||||||
|
@ -750,6 +765,11 @@ ${helpers.single_keyword("font-variant-position",
|
||||||
computed_value::T::Normal
|
computed_value::T::Normal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
|
SpecifiedValue::Normal
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||||
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
|
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
|
||||||
Ok(SpecifiedValue::Normal)
|
Ok(SpecifiedValue::Normal)
|
||||||
|
|
|
@ -101,6 +101,11 @@
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_initial_value() -> computed_value::T { computed_value::T::Normal }
|
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 {
|
impl ToComputedValue for SpecifiedValue {
|
||||||
type ComputedValue = computed_value::T;
|
type ComputedValue = computed_value::T;
|
||||||
|
|
||||||
|
@ -1031,6 +1036,7 @@ ${helpers.single_keyword("text-align-last",
|
||||||
|
|
||||||
${helpers.predefined_type("text-emphasis-color", "CSSColor",
|
${helpers.predefined_type("text-emphasis-color", "CSSColor",
|
||||||
"::cssparser::Color::CurrentColor",
|
"::cssparser::Color::CurrentColor",
|
||||||
|
initial_specified_value="specified::CSSColor::currentcolor()",
|
||||||
products="gecko", animatable=True,
|
products="gecko", animatable=True,
|
||||||
complex_color=True, need_clone=True,
|
complex_color=True, need_clone=True,
|
||||||
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-color")}
|
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-color")}
|
||||||
|
@ -1056,6 +1062,7 @@ ${helpers.predefined_type(
|
||||||
${helpers.predefined_type(
|
${helpers.predefined_type(
|
||||||
"-webkit-text-stroke-color", "CSSColor",
|
"-webkit-text-stroke-color", "CSSColor",
|
||||||
"CSSParserColor::CurrentColor",
|
"CSSParserColor::CurrentColor",
|
||||||
|
initial_specified_value="specified::CSSColor::currentcolor()",
|
||||||
products="gecko", animatable=True,
|
products="gecko", animatable=True,
|
||||||
complex_color=True, need_clone=True,
|
complex_color=True, need_clone=True,
|
||||||
spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-color")}
|
spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-color")}
|
||||||
|
@ -1066,7 +1073,7 @@ ${helpers.predefined_type(
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use values::HasViewportPercentage;
|
use values::HasViewportPercentage;
|
||||||
use values::specified::BorderWidth;
|
use values::specified::{BorderWidth, Length};
|
||||||
|
|
||||||
pub type SpecifiedValue = BorderWidth;
|
pub type SpecifiedValue = BorderWidth;
|
||||||
|
|
||||||
|
@ -1082,6 +1089,10 @@ ${helpers.predefined_type(
|
||||||
#[inline] pub fn get_initial_value() -> computed_value::T {
|
#[inline] pub fn get_initial_value() -> computed_value::T {
|
||||||
Au::from_px(0)
|
Au::from_px(0)
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
|
BorderWidth::from_length(Length::zero())
|
||||||
|
}
|
||||||
</%helpers:longhand>
|
</%helpers:longhand>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ ${helpers.single_keyword("list-style-type", """
|
||||||
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-type")}
|
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-type")}
|
||||||
|
|
||||||
${helpers.predefined_type("list-style-image", "UrlOrNone", "Either::Second(None_)",
|
${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")}
|
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-image")}
|
||||||
|
|
||||||
<%helpers:longhand name="quotes" animatable="False"
|
<%helpers:longhand name="quotes" animatable="False"
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
// TODO(pcwalton): `invert`
|
// TODO(pcwalton): `invert`
|
||||||
${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::CurrentColor",
|
${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::CurrentColor",
|
||||||
|
initial_specified_value="specified::CSSColor::currentcolor()",
|
||||||
animatable=True, complex_color=True, need_clone=True,
|
animatable=True, complex_color=True, need_clone=True,
|
||||||
spec="https://drafts.csswg.org/css-ui/#propdef-outline-color")}
|
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)
|
Either::Second(BorderStyle::none)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
|
Either::Second(BorderStyle::none)
|
||||||
|
}
|
||||||
|
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
pub type T = super::SpecifiedValue;
|
pub type T = super::SpecifiedValue;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +94,13 @@ ${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::Curr
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
pub type T = Au;
|
pub type T = Au;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use super::border_top_width::get_initial_value;
|
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 {
|
impl ToComputedValue for SpecifiedValue {
|
||||||
type ComputedValue = computed_value::T;
|
type ComputedValue = computed_value::T;
|
||||||
|
|
||||||
|
|
|
@ -169,6 +169,10 @@ ${helpers.single_keyword("unicode-bidi",
|
||||||
#[inline] pub fn get_initial_value() -> computed_value::T {
|
#[inline] pub fn get_initial_value() -> computed_value::T {
|
||||||
computed_value::none
|
computed_value::none
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
|
SpecifiedValue::empty()
|
||||||
|
}
|
||||||
/// none | [ underline || overline || line-through || blink ]
|
/// none | [ underline || overline || line-through || blink ]
|
||||||
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||||
let mut result = SpecifiedValue::empty();
|
let mut result = SpecifiedValue::empty();
|
||||||
|
@ -219,7 +223,8 @@ ${helpers.single_keyword("text-decoration-style",
|
||||||
|
|
||||||
${helpers.predefined_type(
|
${helpers.predefined_type(
|
||||||
"text-decoration-color", "CSSColor",
|
"text-decoration-color", "CSSColor",
|
||||||
"CSSParserColor::RGBA(RGBA::new(0, 0, 0, 255))",
|
"::cssparser::Color::CurrentColor",
|
||||||
|
initial_specified_value="specified::CSSColor::currentcolor()",
|
||||||
complex_color=True,
|
complex_color=True,
|
||||||
products="gecko",
|
products="gecko",
|
||||||
animatable=True,
|
animatable=True,
|
||||||
|
|
|
@ -344,6 +344,12 @@ impl NoCalcLength {
|
||||||
*self == NoCalcLength::Absolute(Au(0))
|
*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.
|
/// Get an absolute length from a px value.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_px(px_value: CSSFloat) -> NoCalcLength {
|
pub fn from_px(px_value: CSSFloat) -> NoCalcLength {
|
||||||
|
|
|
@ -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)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue