Use helpers.predefined_type for transform property.

This commit is contained in:
Xidorn Quan 2017-11-07 15:40:41 -08:00
parent fad4d7ae49
commit 8b9bbfea75
7 changed files with 45 additions and 51 deletions

View file

@ -2999,13 +2999,13 @@ fn static_assert() {
% endfor
}
</%def>
fn set_single_transform_function(servo_value: &longhands::transform::computed_value::ComputedOperation,
fn set_single_transform_function(servo_value: &values::computed::TransformOperation,
gecko_value: &mut structs::nsCSSValue /* output */) {
use properties::longhands::transform::computed_value::ComputedOperation;
use values::computed::{Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrNumber};
use values::computed::TransformOperation;
use values::generics::transform::{Matrix, Matrix3D};
let convert_to_ns_css_value = |item: &ComputedOperation| -> structs::nsCSSValue {
let convert_to_ns_css_value = |item: &TransformOperation| -> structs::nsCSSValue {
let mut value = structs::nsCSSValue::null();
Self::set_single_transform_function(item, &mut value);
value
@ -3035,7 +3035,7 @@ fn static_assert() {
}
}
}
pub fn convert_transform(input: &[longhands::transform::computed_value::ComputedOperation],
pub fn convert_transform(input: &[values::computed::TransformOperation],
output: &mut structs::root::RefPtr<structs::root::nsCSSValueSharedList>) {
use gecko_bindings::sugar::refptr::RefPtr;
@ -3088,7 +3088,7 @@ fn static_assert() {
pre_symbols = "("
post_symbols = ")"
if keyword == "interpolatematrix" or keyword == "accumulatematrix":
# We generate this like: "ComputedOperation::InterpolateMatrix {", so the space is
# We generate this like: "TransformOperation::InterpolateMatrix {", so the space is
# between "InterpolateMatrix"/"AccumulateMatrix" and '{'
pre_symbols = " {"
post_symbols = "}"
@ -3144,14 +3144,13 @@ fn static_assert() {
},
</%def>
fn clone_single_transform_function(gecko_value: &structs::nsCSSValue)
-> longhands::transform::computed_value::ComputedOperation {
use properties::longhands::transform::computed_value::ComputedOperation;
use values::computed::{Length, Percentage};
-> values::computed::TransformOperation {
use values::computed::{Length, Percentage, TransformOperation};
use values::generics::transform::{Matrix, Matrix3D};
use values::generics::transform::Transform;
let convert_shared_list_to_operations = |value: &structs::nsCSSValue|
-> Vec<ComputedOperation> {
-> Vec<TransformOperation> {
debug_assert!(value.mUnit == structs::nsCSSUnit::eCSSUnit_SharedList);
let value_list = unsafe {
value.mValue.mSharedList.as_ref()

View file

@ -567,42 +567,12 @@ ${helpers.predefined_type(
allow_empty="NotInitial"
)}
<%helpers:longhand name="transform" extra_prefixes="webkit"
animation_value_type="ComputedValue"
flags="CREATES_STACKING_CONTEXT FIXPOS_CB"
spec="https://drafts.csswg.org/css-transforms/#propdef-transform">
use values::generics::transform::Transform;
pub mod computed_value {
pub use values::computed::transform::Transform as T;
pub use values::computed::transform::TransformOperation as ComputedOperation;
}
pub use values::specified::transform::Transform as SpecifiedValue;
pub use values::specified::transform::TransformOperation as SpecifiedOperation;
#[inline]
pub fn get_initial_value() -> computed_value::T {
Transform(vec![])
}
/// Parses `transform` property.
#[inline]
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue,ParseError<'i>> {
SpecifiedValue::parse_internal(context, input, false)
}
/// Parses `-moz-transform` property. This prefixed property also accepts LengthOrPercentage
/// in the nondiagonal homogeneous components of matrix and matrix3d.
#[inline]
pub fn parse_prefixed<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue,ParseError<'i>> {
SpecifiedValue::parse_internal(context, input, true)
}
</%helpers:longhand>
${helpers.predefined_type("transform", "Transform",
"generics::transform::Transform::none()",
extra_prefixes="webkit",
animation_value_type="ComputedValue",
flags="CREATES_STACKING_CONTEXT FIXPOS_CB",
spec="https://drafts.csswg.org/css-transforms/#propdef-transform")}
// CSSOM View Module
// https://www.w3.org/TR/cssom-view-1/

View file

@ -363,12 +363,11 @@ macro_rules! try_parse_one {
flags="SHORTHAND_ALIAS_PROPERTY"
derive_serialize="True"
spec="Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/transform">
use properties::longhands::transform;
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Longhands, ParseError<'i>> {
use values::specified::transform::Transform;
Ok(expanded! {
transform: transform::parse_prefixed(context, input)?,
transform: Transform::parse_prefixed(context, input)?,
})
}
</%helpers:shorthand>

View file

@ -57,7 +57,7 @@ pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDash
pub use self::table::XSpan;
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, TextOverflow, WordSpacing};
pub use self::time::Time;
pub use self::transform::{TimingFunction, TransformOrigin};
pub use self::transform::{TimingFunction, Transform, TransformOperation, TransformOrigin};
#[cfg(feature = "gecko")]
pub mod align;

View file

@ -450,3 +450,10 @@ impl<T: ToCss> ToCss for Transform<T> {
Ok(())
}
}
impl<T> Transform<T> {
/// `none`
pub fn none() -> Self {
Transform(vec![])
}
}

View file

@ -53,7 +53,7 @@ pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDash
pub use self::table::XSpan;
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, TextOverflow, WordSpacing};
pub use self::time::Time;
pub use self::transform::{TimingFunction, TransformOrigin};
pub use self::transform::{TimingFunction, Transform, TransformOrigin};
pub use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent;
#[cfg(feature = "gecko")]

View file

@ -39,7 +39,7 @@ pub type TransformOrigin = GenericTransformOrigin<OriginComponent<X>, OriginComp
impl Transform {
/// Internal parse function for deciding if we wish to accept prefixed values or not
// Allow unitless zero angle for rotate() and skew() to align with gecko
pub fn parse_internal<'i, 't>(
fn parse_internal<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
prefixed: bool,
@ -252,6 +252,25 @@ impl Transform {
})
})?))
}
/// Parses `-moz-transform` property. This prefixed property also accepts LengthOrPercentage
/// in the nondiagonal homogeneous components of matrix and matrix3d.
#[inline]
pub fn parse_prefixed<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
Transform::parse_internal(context, input, true)
}
}
impl Parse for Transform {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>
) -> Result<Self, ParseError<'i>> {
Transform::parse_internal(context, input, false)
}
}
/// The specified value of a component of a CSS `<transform-origin>`.