mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #6827 - glennw:serialize-translate, r=pcwalton
Add ToCss serialization support for translation transforms. Ref #6643. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6827) <!-- Reviewable:end -->
This commit is contained in:
commit
d62f0fb7c4
1 changed files with 73 additions and 6 deletions
|
@ -3278,11 +3278,21 @@ pub mod longhands {
|
|||
Ok((first, second))
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
enum TranslateKind {
|
||||
Translate,
|
||||
TranslateX,
|
||||
TranslateY,
|
||||
TranslateZ,
|
||||
Translate3D,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
enum SpecifiedOperation {
|
||||
Matrix(SpecifiedMatrix),
|
||||
Skew(CSSFloat, CSSFloat),
|
||||
Translate(specified::LengthOrPercentage,
|
||||
Translate(TranslateKind,
|
||||
specified::LengthOrPercentage,
|
||||
specified::LengthOrPercentage,
|
||||
specified::Length),
|
||||
Scale(CSSFloat, CSSFloat, CSSFloat),
|
||||
|
@ -3291,9 +3301,61 @@ pub mod longhands {
|
|||
}
|
||||
|
||||
impl ToCss for SpecifiedOperation {
|
||||
fn to_css<W>(&self, _: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
// TODO(pcwalton)
|
||||
Ok(())
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
// todo(gw): implement serialization for transform
|
||||
// types other than translate.
|
||||
SpecifiedOperation::Matrix(_m) => {
|
||||
Ok(())
|
||||
}
|
||||
SpecifiedOperation::Skew(_sx, _sy) => {
|
||||
Ok(())
|
||||
}
|
||||
SpecifiedOperation::Translate(kind, tx, ty, tz) => {
|
||||
match kind {
|
||||
TranslateKind::Translate => {
|
||||
try!(dest.write_str("translate("));
|
||||
try!(tx.to_css(dest));
|
||||
try!(dest.write_str(", "));
|
||||
try!(ty.to_css(dest));
|
||||
dest.write_str(")")
|
||||
}
|
||||
TranslateKind::TranslateX => {
|
||||
try!(dest.write_str("translateX("));
|
||||
try!(tx.to_css(dest));
|
||||
dest.write_str(")")
|
||||
}
|
||||
TranslateKind::TranslateY => {
|
||||
try!(dest.write_str("translateY("));
|
||||
try!(ty.to_css(dest));
|
||||
dest.write_str(")")
|
||||
}
|
||||
TranslateKind::TranslateZ => {
|
||||
try!(dest.write_str("translateZ("));
|
||||
try!(tz.to_css(dest));
|
||||
dest.write_str(")")
|
||||
}
|
||||
TranslateKind::Translate3D => {
|
||||
try!(dest.write_str("translate3d("));
|
||||
try!(tx.to_css(dest));
|
||||
try!(dest.write_str(", "));
|
||||
try!(ty.to_css(dest));
|
||||
try!(dest.write_str(", "));
|
||||
try!(tz.to_css(dest));
|
||||
dest.write_str(")")
|
||||
}
|
||||
}
|
||||
}
|
||||
SpecifiedOperation::Scale(_sx, _sy, _sz) => {
|
||||
Ok(())
|
||||
}
|
||||
SpecifiedOperation::Rotate(_ax, _ay, _az, _angle) => {
|
||||
Ok(())
|
||||
}
|
||||
SpecifiedOperation::Perspective(_p) => {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3371,7 +3433,8 @@ pub mod longhands {
|
|||
"translate" => {
|
||||
try!(input.parse_nested_block(|input| {
|
||||
let (tx, ty) = try!(parse_two_lengths_or_percentages(input));
|
||||
result.push(SpecifiedOperation::Translate(tx,
|
||||
result.push(SpecifiedOperation::Translate(TranslateKind::Translate,
|
||||
tx,
|
||||
ty,
|
||||
specified::Length::Absolute(Au(0))));
|
||||
Ok(())
|
||||
|
@ -3381,6 +3444,7 @@ pub mod longhands {
|
|||
try!(input.parse_nested_block(|input| {
|
||||
let tx = try!(specified::LengthOrPercentage::parse(input));
|
||||
result.push(SpecifiedOperation::Translate(
|
||||
TranslateKind::TranslateX,
|
||||
tx,
|
||||
specified::LengthOrPercentage::zero(),
|
||||
specified::Length::Absolute(Au(0))));
|
||||
|
@ -3391,6 +3455,7 @@ pub mod longhands {
|
|||
try!(input.parse_nested_block(|input| {
|
||||
let ty = try!(specified::LengthOrPercentage::parse(input));
|
||||
result.push(SpecifiedOperation::Translate(
|
||||
TranslateKind::TranslateY,
|
||||
specified::LengthOrPercentage::zero(),
|
||||
ty,
|
||||
specified::Length::Absolute(Au(0))));
|
||||
|
@ -3401,6 +3466,7 @@ pub mod longhands {
|
|||
try!(input.parse_nested_block(|input| {
|
||||
let tz = try!(specified::Length::parse(input));
|
||||
result.push(SpecifiedOperation::Translate(
|
||||
TranslateKind::TranslateZ,
|
||||
specified::LengthOrPercentage::zero(),
|
||||
specified::LengthOrPercentage::zero(),
|
||||
tz));
|
||||
|
@ -3415,6 +3481,7 @@ pub mod longhands {
|
|||
try!(input.expect_comma());
|
||||
let tz = try!(specified::Length::parse(input));
|
||||
result.push(SpecifiedOperation::Translate(
|
||||
TranslateKind::Translate3D,
|
||||
tx,
|
||||
ty,
|
||||
tz));
|
||||
|
@ -3557,7 +3624,7 @@ pub mod longhands {
|
|||
SpecifiedOperation::Matrix(ref matrix) => {
|
||||
result.push(computed_value::ComputedOperation::Matrix(*matrix));
|
||||
}
|
||||
SpecifiedOperation::Translate(ref tx, ref ty, ref tz) => {
|
||||
SpecifiedOperation::Translate(_, ref tx, ref ty, ref tz) => {
|
||||
result.push(computed_value::ComputedOperation::Translate(tx.to_computed_value(context),
|
||||
ty.to_computed_value(context),
|
||||
tz.to_computed_value(context)));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue