Skip to content

Commit

Permalink
style: Unship the legacy syntax for -moz-transform.
Browse files Browse the repository at this point in the history
Intent to unship link:

  https://groups.google.com/d/msg/mozilla.dev.platform/T3PGm97MPNU/59XUavMlCgAJ

Reviewed-by: xidorn
Bug: 1438297
MozReview-Commit-ID: 6ybGBasPAWU
  • Loading branch information
emilio committed Feb 19, 2018
1 parent a98da8c commit 7473796
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 242 deletions.
24 changes: 7 additions & 17 deletions components/style/properties/declaration_block.rs
Expand Up @@ -866,23 +866,13 @@ impl PropertyDeclarationBlock {
};

// Substeps 7 and 8
// We need to check the shorthand whether it's an alias property or not.
// If it's an alias property, it should be serialized like its longhand.
if shorthand.flags().contains(PropertyFlags::SHORTHAND_ALIAS_PROPERTY) {
append_serialization::<Cloned<slice::Iter< _>>, _>(
dest,
&property,
value,
importance,
&mut is_first_serialization)?;
} else {
append_serialization::<Cloned<slice::Iter< _>>, _>(
dest,
&shorthand,
value,
importance,
&mut is_first_serialization)?;
}
append_serialization::<Cloned<slice::Iter< _>>, _>(
dest,
&shorthand,
value,
importance,
&mut is_first_serialization,
)?;

for current_longhand in &current_longhands {
// Substep 9
Expand Down
46 changes: 1 addition & 45 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -968,10 +968,7 @@ def set_gecko_property(ffi_name, expr):
<%
transform_functions = [
("Matrix3D", "matrix3d", ["number"] * 16),
("PrefixedMatrix3D", "matrix3d", ["number"] * 12 + ["lopon"] * 2
+ ["lon"] + ["number"]),
("Matrix", "matrix", ["number"] * 6),
("PrefixedMatrix", "matrix", ["number"] * 4 + ["lopon"] * 2),
("Translate", "translate", ["lop", "optional_lop"]),
("Translate3D", "translate3d", ["lop", "lop", "length"]),
("TranslateX", "translatex", ["lop"]),
Expand Down Expand Up @@ -1027,8 +1024,6 @@ transform_functions = [
# need to cast it to f32.
"integer_to_percentage" : "bindings::Gecko_CSSValue_SetPercentage(%s, %s as f32)",
"lop" : "%s.set_lop(%s)",
"lopon" : "set_lopon(%s, %s)",
"lon" : "set_lon(%s, %s)",
"angle" : "%s.set_angle(%s)",
"number" : "bindings::Gecko_CSSValue_SetNumber(%s, %s)",
# Note: We use nsCSSValueSharedList here, instead of nsCSSValueList_heap
Expand Down Expand Up @@ -1106,16 +1101,7 @@ transform_functions = [
field_names = ["from_list", "to_list", "count"]

%>
<%

guard = ""
if name == "Matrix3D" or name == "Matrix":
guard = "if !needs_prefix "
elif name == "PrefixedMatrix3D" or name == "PrefixedMatrix":
guard = "if needs_prefix "

%>
structs::nsCSSKeyword::eCSSKeyword_${keyword} ${guard}=> {
structs::nsCSSKeyword::eCSSKeyword_${keyword} => {
::values::generics::transform::TransformOperation::${name}${pre_symbols}
% for index, item in enumerate(items):
% if keyword == "matrix3d":
Expand Down Expand Up @@ -1149,7 +1135,6 @@ fn set_single_transform_function(
servo_value: &values::computed::TransformOperation,
gecko_value: &mut structs::nsCSSValue /* output */
) {
use values::computed::{Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrNumber};
use values::computed::TransformOperation;
use values::generics::transform::{Matrix, Matrix3D};

Expand All @@ -1159,22 +1144,6 @@ fn set_single_transform_function(
value
};

unsafe fn set_lopon(css: &mut structs::nsCSSValue, lopon: LengthOrPercentageOrNumber) {
let lop = match lopon {
Either::First(number) => LengthOrPercentage::Length(Length::new(number)),
Either::Second(lop) => lop,
};
css.set_lop(lop);
}

unsafe fn set_lon(css: &mut structs::nsCSSValue, lopon: LengthOrNumber) {
let length = match lopon {
Either::Second(number) => Length::new(number),
Either::First(l) => l,
};
bindings::Gecko_CSSValue_SetPixelLength(css, length.px())
}

unsafe {
match *servo_value {
% for servo, gecko, format in transform_functions:
Expand Down Expand Up @@ -1228,19 +1197,6 @@ fn clone_single_transform_function(
bindings::Gecko_CSSValue_GetKeyword(bindings::Gecko_CSSValue_GetArrayItemConst(gecko_value, 0))
};

let needs_prefix = if transform_function == structs::nsCSSKeyword::eCSSKeyword_matrix3d {
unsafe {
bindings::Gecko_CSSValue_GetArrayItemConst(gecko_value, 13).mUnit
!= structs::nsCSSUnit::eCSSUnit_Number ||
bindings::Gecko_CSSValue_GetArrayItemConst(gecko_value, 14).mUnit
!= structs::nsCSSUnit::eCSSUnit_Number ||
bindings::Gecko_CSSValue_GetArrayItemConst(gecko_value, 15).mUnit
!= structs::nsCSSUnit::eCSSUnit_Number
}
} else {
false
};

unsafe {
match transform_function {
% for servo, gecko, format in transform_functions:
Expand Down
2 changes: 1 addition & 1 deletion components/style/properties/longhand/box.mako.rs
Expand Up @@ -395,7 +395,7 @@ ${helpers.predefined_type(

${helpers.predefined_type("transform", "Transform",
"generics::transform::Transform::none()",
extra_prefixes="webkit",
extra_prefixes="webkit moz",
animation_value_type="ComputedValue",
gecko_ffi_name="mSpecifiedTransform",
flags="CREATES_STACKING_CONTEXT FIXPOS_CB",
Expand Down
34 changes: 8 additions & 26 deletions components/style/properties/properties.mako.rs
Expand Up @@ -793,14 +793,12 @@ bitflags! {
/// This property has values that can establish a containing block for
/// absolutely positioned elements.
const ABSPOS_CB = 1 << 2;
/// This shorthand property is an alias of another property.
const SHORTHAND_ALIAS_PROPERTY = 1 << 3;
/// This longhand property applies to ::first-letter.
const APPLIES_TO_FIRST_LETTER = 1 << 4;
const APPLIES_TO_FIRST_LETTER = 1 << 3;
/// This longhand property applies to ::first-line.
const APPLIES_TO_FIRST_LINE = 1 << 5;
const APPLIES_TO_FIRST_LINE = 1 << 4;
/// This longhand property applies to ::placeholder.
const APPLIES_TO_PLACEHOLDER = 1 << 6;
const APPLIES_TO_PLACEHOLDER = 1 << 5;
}
}

Expand Down Expand Up @@ -1687,17 +1685,10 @@ impl ToCss for VariableDeclaration {
{
// https://drafts.csswg.org/css-variables/#variables-in-shorthands
match self.value.from_shorthand {
// Normally, we shouldn't be printing variables here if they came from
// shorthands. But we should allow properties that came from shorthand
// aliases. That also matches with the Gecko behavior.
// FIXME(emilio): This is just a hack for `-moz-transform`.
Some(shorthand) if shorthand.flags().contains(PropertyFlags::SHORTHAND_ALIAS_PROPERTY) => {
dest.write_str(&*self.value.css)?
}
None => {
dest.write_str(&*self.value.css)?
}
_ => {},
Some(..) => {},
}
Ok(())
}
Expand Down Expand Up @@ -1768,20 +1759,11 @@ impl PropertyDeclaration {
fn with_variables_from_shorthand(&self, shorthand: ShorthandId) -> Option< &str> {
match *self {
PropertyDeclaration::WithVariables(ref declaration) => {
if let Some(s) = declaration.value.from_shorthand {
if s == shorthand {
Some(&*declaration.value.css)
} else { None }
} else {
// Normally, longhand property that doesn't come from a shorthand
// should return None here. But we return Some to longhands if they
// came from a shorthand alias. Because for example, we should be able to
// get -moz-transform's value from transform.
if shorthand.flags().contains(PropertyFlags::SHORTHAND_ALIAS_PROPERTY) {
return Some(&*declaration.value.css);
}
None
let s = declaration.value.from_shorthand?;
if s != shorthand {
return None;
}
Some(&*declaration.value.css)
},
_ => None,
}
Expand Down
17 changes: 1 addition & 16 deletions components/style/properties/shorthand/box.mako.rs
Expand Up @@ -392,7 +392,7 @@ macro_rules! try_parse_one {
spec="https://wicg.github.io/overscroll-behavior/#overscroll-behavior-properties">
pub fn parse_value<'i, 't>(
_: &ParserContext,
input: &mut Parser<'i, 't>
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
use values::specified::OverscrollBehavior;
let behavior_x = OverscrollBehavior::parse(input)?;
Expand All @@ -416,18 +416,3 @@ macro_rules! try_parse_one {
}
}
</%helpers:shorthand>

<%helpers:shorthand name="-moz-transform" products="gecko"
sub_properties="transform"
gecko_pref="layout.css.prefixes.transforms"
flags="SHORTHAND_ALIAS_PROPERTY"
derive_serialize="True"
spec="Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/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)?,
})
}
</%helpers:shorthand>
48 changes: 1 addition & 47 deletions components/style/values/computed/transform.rs
Expand Up @@ -6,10 +6,9 @@

use euclid::{Transform3D, Vector3D};
use num_traits::Zero;
use super::{CSSFloat, Either};
use super::CSSFloat;
use values::animated::ToAnimatedZero;
use values::computed::{Angle, Integer, Length, LengthOrPercentage, Number, Percentage};
use values::computed::{LengthOrNumber, LengthOrPercentageOrNumber};
use values::generics::transform::{self, Matrix as GenericMatrix, Matrix3D as GenericMatrix3D};
use values::generics::transform::{Transform as GenericTransform, TransformOperation as GenericTransformOperation};
use values::generics::transform::Rotate as GenericRotate;
Expand All @@ -26,9 +25,7 @@ pub type TransformOperation = GenericTransformOperation<
Number,
Length,
Integer,
LengthOrNumber,
LengthOrPercentage,
LengthOrPercentageOrNumber,
>;
/// A computed CSS `transform`
pub type Transform = GenericTransform<TransformOperation>;
Expand Down Expand Up @@ -56,12 +53,8 @@ impl TransformOrigin {

/// computed value of matrix3d()
pub type Matrix3D = GenericMatrix3D<Number>;
/// computed value of matrix3d() in -moz-transform
pub type PrefixedMatrix3D = GenericMatrix3D<Number, LengthOrPercentageOrNumber, LengthOrNumber>;
/// computed value of matrix()
pub type Matrix = GenericMatrix<Number>;
/// computed value of matrix() in -moz-transform
pub type PrefixedMatrix = GenericMatrix<Number, LengthOrPercentageOrNumber>;

// we rustfmt_skip here because we want the matrices to look like
// matrices instead of being split across lines
Expand Down Expand Up @@ -95,21 +88,6 @@ impl Matrix3D {
}
}

#[cfg_attr(rustfmt, rustfmt_skip)]
impl PrefixedMatrix3D {
#[inline]
/// Get an identity matrix
pub fn identity() -> Self {
Self {
m11: 1.0, m12: 0.0, m13: 0.0, m14: 0.0,
m21: 0.0, m22: 1.0, m23: 0.0, m24: 0.0,
m31: 0.0, m32: 0.0, m33: 1.0, m34: 0.0,
m41: Either::First(0.), m42: Either::First(0.),
m43: Either::First(Length::new(0.)), m44: 1.0
}
}
}

#[cfg_attr(rustfmt, rustfmt_skip)]
impl Matrix {
#[inline]
Expand All @@ -136,20 +114,6 @@ impl From<Matrix> for Matrix3D {
}
}

#[cfg_attr(rustfmt, rustfmt_skip)]
impl PrefixedMatrix {
#[inline]
/// Get an identity matrix
pub fn identity() -> Self {
Self {
a: 1., c: 0., /* 0 0 */
b: 0., d: 1., /* 0 0 */
/* 0 0 1 0 */
e: Either::First(0.), f: Either::First(0.), /* 0 1 */
}
}
}

#[cfg_attr(rustfmt, rustfmt_skip)]
impl From<Transform3D<CSSFloat>> for Matrix3D {
#[inline]
Expand Down Expand Up @@ -213,17 +177,7 @@ impl ToAnimatedZero for TransformOperation {
fn to_animated_zero(&self) -> Result<Self, ()> {
match *self {
GenericTransformOperation::Matrix3D(..) => Ok(GenericTransformOperation::Matrix3D(Matrix3D::identity())),
GenericTransformOperation::PrefixedMatrix3D(..) => {
Ok(GenericTransformOperation::PrefixedMatrix3D(
PrefixedMatrix3D::identity(),
))
},
GenericTransformOperation::Matrix(..) => Ok(GenericTransformOperation::Matrix(Matrix::identity())),
GenericTransformOperation::PrefixedMatrix(..) => {
Ok(GenericTransformOperation::PrefixedMatrix(
PrefixedMatrix::identity(),
))
},
GenericTransformOperation::Skew(sx, sy) => {
Ok(GenericTransformOperation::Skew(
sx.to_animated_zero()?,
Expand Down

0 comments on commit 7473796

Please sign in to comment.