mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Make use of predefined_type for some aliased types
This commit is contained in:
parent
61a17993eb
commit
63965f55f5
8 changed files with 81 additions and 174 deletions
|
@ -8,14 +8,18 @@
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<%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, initial_specified_value=None, **kwargs)">
|
needs_context=True, vector=False, computed_type=None, 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;
|
||||||
use cssparser::{Color as CSSParserColor, RGBA};
|
use cssparser::{Color as CSSParserColor, RGBA};
|
||||||
pub use values::specified::${type} as SpecifiedValue;
|
pub use values::specified::${type} as SpecifiedValue;
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
|
% if computed_type:
|
||||||
|
pub use ${computed_type} as T;
|
||||||
|
% else:
|
||||||
pub use values::computed::${type} as T;
|
pub use values::computed::${type} as T;
|
||||||
|
% endif
|
||||||
}
|
}
|
||||||
#[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:
|
% if initial_specified_value:
|
||||||
|
@ -36,10 +40,16 @@
|
||||||
% if vector:
|
% if vector:
|
||||||
<%call expr="vector_longhand(name, predefined_type=type, **kwargs)">
|
<%call expr="vector_longhand(name, predefined_type=type, **kwargs)">
|
||||||
${predefined_type_inner(name, type, initial_value, parse_method)}
|
${predefined_type_inner(name, type, initial_value, parse_method)}
|
||||||
|
% if caller:
|
||||||
|
${caller.body()}
|
||||||
|
% endif
|
||||||
</%call>
|
</%call>
|
||||||
% else:
|
% else:
|
||||||
<%call expr="longhand(name, predefined_type=type, **kwargs)">
|
<%call expr="longhand(name, predefined_type=type, **kwargs)">
|
||||||
${predefined_type_inner(name, type, initial_value, parse_method)}
|
${predefined_type_inner(name, type, initial_value, parse_method)}
|
||||||
|
% if caller:
|
||||||
|
${caller.body()}
|
||||||
|
% endif
|
||||||
</%call>
|
</%call>
|
||||||
% endif
|
% endif
|
||||||
</%def>
|
</%def>
|
||||||
|
|
|
@ -89,42 +89,13 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
}
|
}
|
||||||
</%helpers:vector_longhand>
|
</%helpers:vector_longhand>
|
||||||
|
|
||||||
<%helpers:vector_longhand name="background-position-x" animation_value_type="ComputedValue"
|
<%helpers:predefined_type name="background-position-x" type="position::HorizontalPosition"
|
||||||
|
initial_value="computed::position::HorizontalPosition::zero()"
|
||||||
|
initial_specified_value="specified::position::HorizontalPosition::left()"
|
||||||
spec="https://drafts.csswg.org/css-backgrounds-4/#propdef-background-position-x"
|
spec="https://drafts.csswg.org/css-backgrounds-4/#propdef-background-position-x"
|
||||||
delegate_animate="True">
|
animation_value_type="ComputedValue" vector="True" delegate_animate="True">
|
||||||
use std::fmt;
|
|
||||||
use style_traits::ToCss;
|
|
||||||
use values::HasViewportPercentage;
|
|
||||||
use values::specified::position::HorizontalPosition;
|
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub mod computed_value {
|
|
||||||
use values::computed::position::HorizontalPosition;
|
|
||||||
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
|
|
||||||
|
|
||||||
pub type T = HorizontalPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub type SpecifiedValue = HorizontalPosition;
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(missing_docs)]
|
/// Get the initial value for horizontal position.
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
|
||||||
use values::generics::position::HorizontalPosition;
|
|
||||||
HorizontalPosition(computed::LengthOrPercentage::Percentage(0.0))
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
|
||||||
use values::generics::position::{HorizontalPosition, Keyword, PositionValue};
|
|
||||||
HorizontalPosition(PositionValue {
|
|
||||||
keyword: Some(Keyword::Left),
|
|
||||||
position: None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub fn get_initial_position_value() -> SpecifiedValue {
|
pub fn get_initial_position_value() -> SpecifiedValue {
|
||||||
use values::generics::position::{HorizontalPosition, PositionValue};
|
use values::generics::position::{HorizontalPosition, PositionValue};
|
||||||
use values::specified::{LengthOrPercentage, Percentage};
|
use values::specified::{LengthOrPercentage, Percentage};
|
||||||
|
@ -133,66 +104,23 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
position: Some(LengthOrPercentage::Percentage(Percentage(0.0))),
|
position: Some(LengthOrPercentage::Percentage(Percentage(0.0))),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
</%helpers:predefined_type>
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
<%helpers:predefined_type name="background-position-y" type="position::VerticalPosition"
|
||||||
pub fn parse(context: &ParserContext, input: &mut Parser)
|
initial_value="computed::position::VerticalPosition::zero()"
|
||||||
-> Result<SpecifiedValue, ()> {
|
initial_specified_value="specified::position::VerticalPosition::top()"
|
||||||
HorizontalPosition::parse(context, input)
|
|
||||||
}
|
|
||||||
</%helpers:vector_longhand>
|
|
||||||
|
|
||||||
<%helpers:vector_longhand name="background-position-y" animation_value_type="ComputedValue"
|
|
||||||
spec="https://drafts.csswg.org/css-backgrounds-4/#propdef-background-position-y"
|
spec="https://drafts.csswg.org/css-backgrounds-4/#propdef-background-position-y"
|
||||||
delegate_animate="True">
|
animation_value_type="ComputedValue" vector="True" delegate_animate="True">
|
||||||
use std::fmt;
|
/// Get the initial value for vertical position.
|
||||||
use style_traits::ToCss;
|
|
||||||
use values::HasViewportPercentage;
|
|
||||||
use values::specified::position::VerticalPosition;
|
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub mod computed_value {
|
|
||||||
use values::computed::position::VerticalPosition;
|
|
||||||
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
|
|
||||||
|
|
||||||
pub type T = VerticalPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub type SpecifiedValue = VerticalPosition;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
|
||||||
use values::generics::position::VerticalPosition;
|
|
||||||
VerticalPosition(computed::LengthOrPercentage::Percentage(0.0))
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
|
||||||
use values::generics::position::{Keyword, PositionValue, VerticalPosition};
|
|
||||||
VerticalPosition(PositionValue {
|
|
||||||
keyword: Some(Keyword::Top),
|
|
||||||
position: None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub fn get_initial_position_value() -> SpecifiedValue {
|
pub fn get_initial_position_value() -> SpecifiedValue {
|
||||||
use values::generics::position::{PositionValue, VerticalPosition};
|
use values::generics::position::{VerticalPosition, PositionValue};
|
||||||
use values::specified::{LengthOrPercentage, Percentage};
|
use values::specified::{LengthOrPercentage, Percentage};
|
||||||
VerticalPosition(PositionValue {
|
VerticalPosition(PositionValue {
|
||||||
keyword: None,
|
keyword: None,
|
||||||
position: Some(LengthOrPercentage::Percentage(Percentage(0.0))),
|
position: Some(LengthOrPercentage::Percentage(Percentage(0.0))),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
</%helpers:predefined_type>
|
||||||
#[inline]
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub fn parse(context: &ParserContext, input: &mut Parser)
|
|
||||||
-> Result<SpecifiedValue, ()> {
|
|
||||||
VerticalPosition::parse(context, input)
|
|
||||||
}
|
|
||||||
</%helpers:vector_longhand>
|
|
||||||
|
|
||||||
<%helpers:vector_longhand name="background-repeat" animation_value_type="none"
|
<%helpers:vector_longhand name="background-repeat" animation_value_type="none"
|
||||||
spec="https://drafts.csswg.org/css-backgrounds/#the-background-repeat">
|
spec="https://drafts.csswg.org/css-backgrounds/#the-background-repeat">
|
||||||
|
|
|
@ -21,47 +21,24 @@
|
||||||
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-color"),
|
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-color"),
|
||||||
spec=maybe_logical_spec(side, "color"),
|
spec=maybe_logical_spec(side, "color"),
|
||||||
animation_value_type="IntermediateColor", logical = side[1])}
|
animation_value_type="IntermediateColor", logical = side[1])}
|
||||||
% endfor
|
|
||||||
|
|
||||||
% for side in ALL_SIDES:
|
|
||||||
${helpers.predefined_type("border-%s-style" % side[0], "BorderStyle",
|
${helpers.predefined_type("border-%s-style" % side[0], "BorderStyle",
|
||||||
"specified::BorderStyle::none",
|
"specified::BorderStyle::none",
|
||||||
need_clone=True,
|
need_clone=True,
|
||||||
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-style"),
|
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-style"),
|
||||||
spec=maybe_logical_spec(side, "style"),
|
spec=maybe_logical_spec(side, "style"),
|
||||||
animation_value_type="none", logical = side[1])}
|
animation_value_type="none", logical=side[1])}
|
||||||
|
|
||||||
|
${helpers.predefined_type("border-%s-width" % side[0], "BorderWidth", "Au::from_px(3)",
|
||||||
|
computed_type="::app_units::Au",
|
||||||
|
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-width"),
|
||||||
|
spec=maybe_logical_spec(side, "width"),
|
||||||
|
animation_value_type="ComputedValue", logical=side[1])}
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
${helpers.gecko_keyword_conversion(Keyword('border-style',
|
${helpers.gecko_keyword_conversion(Keyword('border-style',
|
||||||
"none solid double dotted dashed hidden groove ridge inset outset"),
|
"none solid double dotted dashed hidden groove ridge inset outset"),
|
||||||
type="::values::specified::BorderStyle")}
|
type="::values::specified::BorderStyle")}
|
||||||
% for side in ALL_SIDES:
|
|
||||||
<%helpers:longhand name="border-${side[0]}-width" animation_value_type="ComputedValue" logical="${side[1]}"
|
|
||||||
alias="${maybe_moz_logical_alias(product, side, '-moz-border-%s-width')}"
|
|
||||||
spec="${maybe_logical_spec(side, 'width')}">
|
|
||||||
use app_units::Au;
|
|
||||||
use std::fmt;
|
|
||||||
use style_traits::ToCss;
|
|
||||||
use values::HasViewportPercentage;
|
|
||||||
use values::specified::BorderWidth;
|
|
||||||
|
|
||||||
pub type SpecifiedValue = BorderWidth;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn parse(context: &ParserContext, input: &mut Parser)
|
|
||||||
-> Result<SpecifiedValue, ()> {
|
|
||||||
BorderWidth::parse(context, input)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod computed_value {
|
|
||||||
use app_units::Au;
|
|
||||||
pub type T = Au;
|
|
||||||
}
|
|
||||||
#[inline] pub fn get_initial_value() -> computed_value::T {
|
|
||||||
Au::from_px(3) // medium
|
|
||||||
}
|
|
||||||
</%helpers:longhand>
|
|
||||||
% endfor
|
|
||||||
|
|
||||||
// FIXME(#4126): when gfx supports painting it, make this Size2D<LengthOrPercentage>
|
// FIXME(#4126): when gfx supports painting it, make this Size2D<LengthOrPercentage>
|
||||||
% for corner in ["top-left", "top-right", "bottom-right", "bottom-left"]:
|
% for corner in ["top-left", "top-right", "bottom-right", "bottom-left"]:
|
||||||
|
|
|
@ -40,36 +40,11 @@ ${helpers.single_keyword("column-fill", "balance auto", extra_prefixes="moz",
|
||||||
products="gecko", animation_value_type="none",
|
products="gecko", animation_value_type="none",
|
||||||
spec="https://drafts.csswg.org/css-multicol/#propdef-column-fill")}
|
spec="https://drafts.csswg.org/css-multicol/#propdef-column-fill")}
|
||||||
|
|
||||||
// https://drafts.csswg.org/css-multicol-1/#propdef-column-rule-width
|
${helpers.predefined_type("column-rule-width", "BorderWidth", "Au::from_px(3)",
|
||||||
<%helpers:longhand name="column-rule-width" products="gecko" animation_value_type="ComputedValue" extra_prefixes="moz"
|
initial_specified_value="specified::BorderWidth::Medium",
|
||||||
spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule-width">
|
products="gecko", computed_type="::app_units::Au",
|
||||||
use app_units::Au;
|
spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule-width",
|
||||||
use std::fmt;
|
animation_value_type="ComputedValue", extra_prefixes="moz")}
|
||||||
use style_traits::ToCss;
|
|
||||||
use values::HasViewportPercentage;
|
|
||||||
use values::specified::BorderWidth;
|
|
||||||
|
|
||||||
pub mod computed_value {
|
|
||||||
use app_units::Au;
|
|
||||||
pub type T = Au;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type SpecifiedValue = BorderWidth;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
|
||||||
Au::from_px(3) // medium
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
|
||||||
BorderWidth::Medium
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
|
||||||
BorderWidth::parse(context, input)
|
|
||||||
}
|
|
||||||
</%helpers:longhand>
|
|
||||||
|
|
||||||
// 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",
|
||||||
|
|
|
@ -1236,33 +1236,11 @@ ${helpers.predefined_type(
|
||||||
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")}
|
||||||
|
|
||||||
<%helpers:longhand products="gecko" name="-webkit-text-stroke-width" animation_value_type="none"
|
${helpers.predefined_type("-webkit-text-stroke-width", "BorderWidth", "Au::from_px(0)",
|
||||||
spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-width">
|
initial_specified_value="specified::BorderWidth::from_length(specified::Length::zero())",
|
||||||
use app_units::Au;
|
computed_type="::app_units::Au", products="gecko",
|
||||||
use std::fmt;
|
spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-width",
|
||||||
use style_traits::ToCss;
|
animation_value_type="none")}
|
||||||
use values::HasViewportPercentage;
|
|
||||||
use values::specified::{BorderWidth, Length};
|
|
||||||
|
|
||||||
pub type SpecifiedValue = BorderWidth;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
|
||||||
BorderWidth::parse(context, input)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod computed_value {
|
|
||||||
use app_units::Au;
|
|
||||||
pub type T = Au;
|
|
||||||
}
|
|
||||||
#[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>
|
|
||||||
|
|
||||||
|
|
||||||
// CSS Ruby Layout Module Level 1
|
// CSS Ruby Layout Module Level 1
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
//! Computed values.
|
//! Computed values.
|
||||||
|
|
||||||
use app_units::Au;
|
|
||||||
use euclid::size::Size2D;
|
use euclid::size::Size2D;
|
||||||
use font_metrics::FontMetricsProvider;
|
use font_metrics::FontMetricsProvider;
|
||||||
use media_queries::Device;
|
use media_queries::Device;
|
||||||
|
@ -16,6 +15,7 @@ use super::generics::BorderRadiusSize as GenericBorderRadiusSize;
|
||||||
use super::specified;
|
use super::specified;
|
||||||
use super::specified::grid::{TrackBreadth as GenericTrackBreadth, TrackSize as GenericTrackSize};
|
use super::specified::grid::{TrackBreadth as GenericTrackBreadth, TrackSize as GenericTrackSize};
|
||||||
|
|
||||||
|
pub use app_units::Au;
|
||||||
pub use cssparser::Color as CSSColor;
|
pub use cssparser::Color as CSSColor;
|
||||||
pub use self::image::{AngleOrCorner, EndingShape as GradientShape, Gradient, GradientKind, Image, ImageRect};
|
pub use self::image::{AngleOrCorner, EndingShape as GradientShape, Gradient, GradientKind, Image, ImageRect};
|
||||||
pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword};
|
pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword};
|
||||||
|
|
|
@ -59,7 +59,23 @@ pub type HorizontalPosition = GenericHorizontalPosition<LengthOrPercentage>;
|
||||||
|
|
||||||
impl Copy for HorizontalPosition {}
|
impl Copy for HorizontalPosition {}
|
||||||
|
|
||||||
|
impl HorizontalPosition {
|
||||||
|
#[inline]
|
||||||
|
/// Create a zero position value.
|
||||||
|
pub fn zero() -> HorizontalPosition {
|
||||||
|
GenericHorizontalPosition(LengthOrPercentage::Percentage(0.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The computed value of a vertical `<position>`
|
/// The computed value of a vertical `<position>`
|
||||||
pub type VerticalPosition = GenericVerticalPosition<LengthOrPercentage>;
|
pub type VerticalPosition = GenericVerticalPosition<LengthOrPercentage>;
|
||||||
|
|
||||||
impl Copy for VerticalPosition {}
|
impl Copy for VerticalPosition {}
|
||||||
|
|
||||||
|
impl VerticalPosition {
|
||||||
|
#[inline]
|
||||||
|
/// Create a zero position value.
|
||||||
|
pub fn zero() -> VerticalPosition {
|
||||||
|
GenericVerticalPosition(LengthOrPercentage::Percentage(0.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -219,6 +219,18 @@ impl ToComputedValue for HorizontalPosition {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HorizontalPosition {
|
||||||
|
#[inline]
|
||||||
|
/// Initial specified value for vertical position (`top` keyword).
|
||||||
|
pub fn left() -> HorizontalPosition {
|
||||||
|
GenericHorizontalPosition(PositionValue {
|
||||||
|
keyword: Some(Keyword::Left),
|
||||||
|
position: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// The specified value of vertical `<position>`
|
/// The specified value of vertical `<position>`
|
||||||
pub type VerticalPosition = GenericVerticalPosition<PositionValue<LengthOrPercentage>>;
|
pub type VerticalPosition = GenericVerticalPosition<PositionValue<LengthOrPercentage>>;
|
||||||
|
|
||||||
|
@ -238,3 +250,14 @@ impl ToComputedValue for VerticalPosition {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl VerticalPosition {
|
||||||
|
#[inline]
|
||||||
|
/// Initial specified value for vertical position (`top` keyword).
|
||||||
|
pub fn top() -> VerticalPosition {
|
||||||
|
GenericVerticalPosition(PositionValue {
|
||||||
|
keyword: Some(Keyword::Top),
|
||||||
|
position: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue