Make use of predefined_type for some aliased types

This commit is contained in:
Ravi Shankar 2017-04-16 12:42:29 +05:30
parent 61a17993eb
commit 63965f55f5
8 changed files with 81 additions and 174 deletions

View file

@ -8,14 +8,18 @@
%>
<%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)">
#[allow(unused_imports)]
use app_units::Au;
use cssparser::{Color as CSSParserColor, RGBA};
pub use values::specified::${type} as SpecifiedValue;
pub mod computed_value {
% if computed_type:
pub use ${computed_type} as T;
% else:
pub use values::computed::${type} as T;
% endif
}
#[inline] pub fn get_initial_value() -> computed_value::T { ${initial_value} }
% if initial_specified_value:
@ -36,10 +40,16 @@
% if vector:
<%call expr="vector_longhand(name, predefined_type=type, **kwargs)">
${predefined_type_inner(name, type, initial_value, parse_method)}
% if caller:
${caller.body()}
% endif
</%call>
% else:
<%call expr="longhand(name, predefined_type=type, **kwargs)">
${predefined_type_inner(name, type, initial_value, parse_method)}
% if caller:
${caller.body()}
% endif
</%call>
% endif
</%def>

View file

@ -89,42 +89,13 @@ ${helpers.predefined_type("background-color", "CSSColor",
}
</%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"
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;
animation_value_type="ComputedValue" vector="True" delegate_animate="True">
#[inline]
#[allow(missing_docs)]
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)]
/// Get the initial value for horizontal position.
pub fn get_initial_position_value() -> SpecifiedValue {
use values::generics::position::{HorizontalPosition, PositionValue};
use values::specified::{LengthOrPercentage, Percentage};
@ -133,66 +104,23 @@ ${helpers.predefined_type("background-color", "CSSColor",
position: Some(LengthOrPercentage::Percentage(Percentage(0.0))),
})
}
</%helpers:predefined_type>
#[allow(missing_docs)]
pub fn parse(context: &ParserContext, input: &mut Parser)
-> Result<SpecifiedValue, ()> {
HorizontalPosition::parse(context, input)
}
</%helpers:vector_longhand>
<%helpers:vector_longhand name="background-position-y" animation_value_type="ComputedValue"
<%helpers:predefined_type name="background-position-y" type="position::VerticalPosition"
initial_value="computed::position::VerticalPosition::zero()"
initial_specified_value="specified::position::VerticalPosition::top()"
spec="https://drafts.csswg.org/css-backgrounds-4/#propdef-background-position-y"
delegate_animate="True">
use std::fmt;
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)]
animation_value_type="ComputedValue" vector="True" delegate_animate="True">
/// Get the initial value for vertical position.
pub fn get_initial_position_value() -> SpecifiedValue {
use values::generics::position::{PositionValue, VerticalPosition};
use values::generics::position::{VerticalPosition, PositionValue};
use values::specified::{LengthOrPercentage, Percentage};
VerticalPosition(PositionValue {
keyword: None,
position: Some(LengthOrPercentage::Percentage(Percentage(0.0))),
})
}
#[inline]
#[allow(missing_docs)]
pub fn parse(context: &ParserContext, input: &mut Parser)
-> Result<SpecifiedValue, ()> {
VerticalPosition::parse(context, input)
}
</%helpers:vector_longhand>
</%helpers:predefined_type>
<%helpers:vector_longhand name="background-repeat" animation_value_type="none"
spec="https://drafts.csswg.org/css-backgrounds/#the-background-repeat">

View file

@ -21,47 +21,24 @@
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-color"),
spec=maybe_logical_spec(side, "color"),
animation_value_type="IntermediateColor", logical = side[1])}
% endfor
% for side in ALL_SIDES:
${helpers.predefined_type("border-%s-style" % side[0], "BorderStyle",
"specified::BorderStyle::none",
need_clone=True,
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-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
${helpers.gecko_keyword_conversion(Keyword('border-style',
"none solid double dotted dashed hidden groove ridge inset outset"),
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>
% for corner in ["top-left", "top-right", "bottom-right", "bottom-left"]:

View file

@ -40,36 +40,11 @@ ${helpers.single_keyword("column-fill", "balance auto", extra_prefixes="moz",
products="gecko", animation_value_type="none",
spec="https://drafts.csswg.org/css-multicol/#propdef-column-fill")}
// https://drafts.csswg.org/css-multicol-1/#propdef-column-rule-width
<%helpers:longhand name="column-rule-width" products="gecko" animation_value_type="ComputedValue" extra_prefixes="moz"
spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule-width">
use app_units::Au;
use std::fmt;
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>
${helpers.predefined_type("column-rule-width", "BorderWidth", "Au::from_px(3)",
initial_specified_value="specified::BorderWidth::Medium",
products="gecko", computed_type="::app_units::Au",
spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule-width",
animation_value_type="ComputedValue", extra_prefixes="moz")}
// https://drafts.csswg.org/css-multicol-1/#crc
${helpers.predefined_type("column-rule-color", "CSSColor",

View file

@ -1236,33 +1236,11 @@ ${helpers.predefined_type(
complex_color=True, need_clone=True,
spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-color")}
<%helpers:longhand products="gecko" name="-webkit-text-stroke-width" animation_value_type="none"
spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-width">
use app_units::Au;
use std::fmt;
use style_traits::ToCss;
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>
${helpers.predefined_type("-webkit-text-stroke-width", "BorderWidth", "Au::from_px(0)",
initial_specified_value="specified::BorderWidth::from_length(specified::Length::zero())",
computed_type="::app_units::Au", products="gecko",
spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-width",
animation_value_type="none")}
// CSS Ruby Layout Module Level 1

View file

@ -4,7 +4,6 @@
//! Computed values.
use app_units::Au;
use euclid::size::Size2D;
use font_metrics::FontMetricsProvider;
use media_queries::Device;
@ -16,6 +15,7 @@ use super::generics::BorderRadiusSize as GenericBorderRadiusSize;
use super::specified;
use super::specified::grid::{TrackBreadth as GenericTrackBreadth, TrackSize as GenericTrackSize};
pub use app_units::Au;
pub use cssparser::Color as CSSColor;
pub use self::image::{AngleOrCorner, EndingShape as GradientShape, Gradient, GradientKind, Image, ImageRect};
pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword};

View file

@ -59,7 +59,23 @@ pub type HorizontalPosition = GenericHorizontalPosition<LengthOrPercentage>;
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>`
pub type VerticalPosition = GenericVerticalPosition<LengthOrPercentage>;
impl Copy for VerticalPosition {}
impl VerticalPosition {
#[inline]
/// Create a zero position value.
pub fn zero() -> VerticalPosition {
GenericVerticalPosition(LengthOrPercentage::Percentage(0.0))
}
}

View file

@ -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>`
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,
})
}
}