mirror of
https://github.com/servo/servo.git
synced 2025-07-31 19:20:22 +01:00
Auto merge of #6796 - glennw:transform-translate-fix, r=pcwalton
Change transforms to use LengthOrPercentage. This simplifies an upcoming PR to support serializing transform values for css style declarations. Related to issue #6643. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6796) <!-- Reviewable:end -->
This commit is contained in:
commit
a409699a0b
5 changed files with 36 additions and 183 deletions
|
@ -18,7 +18,7 @@ use fragment::{CoordinateSystem, Fragment, IframeFragmentInfo, ImageFragmentInfo
|
||||||
use fragment::{ScannedTextFragmentInfo, SpecificFragmentInfo};
|
use fragment::{ScannedTextFragmentInfo, SpecificFragmentInfo};
|
||||||
use inline::InlineFlow;
|
use inline::InlineFlow;
|
||||||
use list_item::ListItemFlow;
|
use list_item::ListItemFlow;
|
||||||
use model::{self, MaybeAuto, ToGfxMatrix, ToAu};
|
use model::{self, MaybeAuto, ToGfxMatrix};
|
||||||
use table_cell::CollapsedBordersForCell;
|
use table_cell::CollapsedBordersForCell;
|
||||||
|
|
||||||
use canvas_traits::{CanvasMsg, FromLayoutMsg};
|
use canvas_traits::{CanvasMsg, FromLayoutMsg};
|
||||||
|
@ -1176,8 +1176,8 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
Matrix4::create_scale(sx, sy, sz)
|
Matrix4::create_scale(sx, sy, sz)
|
||||||
}
|
}
|
||||||
&transform::ComputedOperation::Translate(tx, ty, tz) => {
|
&transform::ComputedOperation::Translate(tx, ty, tz) => {
|
||||||
let tx = tx.to_au(border_box.size.width).to_f32_px();
|
let tx = model::specified(tx, border_box.size.width).to_f32_px();
|
||||||
let ty = ty.to_au(border_box.size.height).to_f32_px();
|
let ty = model::specified(ty, border_box.size.height).to_f32_px();
|
||||||
let tz = tz.to_f32_px();
|
let tz = tz.to_f32_px();
|
||||||
Matrix4::create_translation(tx, ty, tz)
|
Matrix4::create_translation(tx, ty, tz)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ use std::cmp::{max, min};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style::computed_values::transform::ComputedMatrix;
|
use style::computed_values::transform::ComputedMatrix;
|
||||||
use style::properties::ComputedValues;
|
use style::properties::ComputedValues;
|
||||||
use style::values::computed::{LengthAndPercentage, LengthOrPercentageOrAuto};
|
use style::values::computed::LengthOrPercentageOrAuto;
|
||||||
use style::values::computed::{LengthOrPercentageOrNone, LengthOrPercentage};
|
use style::values::computed::{LengthOrPercentageOrNone, LengthOrPercentage};
|
||||||
use util::geometry::Au;
|
use util::geometry::Au;
|
||||||
use util::logical_geometry::LogicalMargin;
|
use util::logical_geometry::LogicalMargin;
|
||||||
|
@ -439,15 +439,3 @@ impl ToGfxMatrix for ComputedMatrix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ToAu {
|
|
||||||
fn to_au(&self, containing_size: Au) -> Au;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToAu for LengthAndPercentage {
|
|
||||||
#[inline]
|
|
||||||
fn to_au(&self, containing_size: Au) -> Au {
|
|
||||||
self.length + Au::from_f32_px(self.percentage * containing_size.to_f32_px())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ use properties::longhands::transform::computed_value::ComputedMatrix;
|
||||||
use properties::longhands::transform::computed_value::ComputedOperation as TransformOperation;
|
use properties::longhands::transform::computed_value::ComputedOperation as TransformOperation;
|
||||||
use properties::longhands::transform::computed_value::T as TransformList;
|
use properties::longhands::transform::computed_value::T as TransformList;
|
||||||
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
|
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
|
||||||
use values::computed::{LengthAndPercentage, LengthOrPercentage, Length, Time};
|
use values::computed::{LengthOrPercentage, Length, Time};
|
||||||
use values::CSSFloat;
|
use values::CSSFloat;
|
||||||
use cssparser::{RGBA, Color};
|
use cssparser::{RGBA, Color};
|
||||||
|
|
||||||
|
@ -506,17 +506,6 @@ impl Interpolate for LengthOrPercentage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Interpolate for LengthAndPercentage {
|
|
||||||
#[inline]
|
|
||||||
fn interpolate(&self, other: &LengthAndPercentage, time: f32)
|
|
||||||
-> Option<LengthAndPercentage> {
|
|
||||||
Some(LengthAndPercentage {
|
|
||||||
length: self.length.interpolate(&other.length, time).unwrap(),
|
|
||||||
percentage: self.percentage.interpolate(&other.percentage, time).unwrap(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Interpolate for LengthOrPercentageOrAuto {
|
impl Interpolate for LengthOrPercentageOrAuto {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn interpolate(&self, other: &LengthOrPercentageOrAuto, time: f32)
|
fn interpolate(&self, other: &LengthOrPercentageOrAuto, time: f32)
|
||||||
|
@ -795,8 +784,8 @@ fn build_identity_transform_list(list: &Vec<TransformOperation>) -> Vec<Transfor
|
||||||
result.push(TransformOperation::Skew(0.0, 0.0));
|
result.push(TransformOperation::Skew(0.0, 0.0));
|
||||||
}
|
}
|
||||||
&TransformOperation::Translate(..) => {
|
&TransformOperation::Translate(..) => {
|
||||||
result.push(TransformOperation::Translate(LengthAndPercentage::zero(),
|
result.push(TransformOperation::Translate(LengthOrPercentage::zero(),
|
||||||
LengthAndPercentage::zero(),
|
LengthOrPercentage::zero(),
|
||||||
Au(0)));
|
Au(0)));
|
||||||
}
|
}
|
||||||
&TransformOperation::Scale(..) => {
|
&TransformOperation::Scale(..) => {
|
||||||
|
|
|
@ -3245,8 +3245,8 @@ pub mod longhands {
|
||||||
pub enum ComputedOperation {
|
pub enum ComputedOperation {
|
||||||
Matrix(ComputedMatrix),
|
Matrix(ComputedMatrix),
|
||||||
Skew(CSSFloat, CSSFloat),
|
Skew(CSSFloat, CSSFloat),
|
||||||
Translate(computed::LengthAndPercentage,
|
Translate(computed::LengthOrPercentage,
|
||||||
computed::LengthAndPercentage,
|
computed::LengthOrPercentage,
|
||||||
computed::Length),
|
computed::Length),
|
||||||
Scale(CSSFloat, CSSFloat, CSSFloat),
|
Scale(CSSFloat, CSSFloat, CSSFloat),
|
||||||
Rotate(CSSFloat, CSSFloat, CSSFloat, computed::Angle),
|
Rotate(CSSFloat, CSSFloat, CSSFloat, computed::Angle),
|
||||||
|
@ -3259,13 +3259,13 @@ pub mod longhands {
|
||||||
pub use self::computed_value::ComputedMatrix as SpecifiedMatrix;
|
pub use self::computed_value::ComputedMatrix as SpecifiedMatrix;
|
||||||
|
|
||||||
fn parse_two_lengths_or_percentages(input: &mut Parser)
|
fn parse_two_lengths_or_percentages(input: &mut Parser)
|
||||||
-> Result<(specified::LengthAndPercentage,
|
-> Result<(specified::LengthOrPercentage,
|
||||||
specified::LengthAndPercentage),()> {
|
specified::LengthOrPercentage),()> {
|
||||||
let first = try!(specified::LengthAndPercentage::parse(input));
|
let first = try!(specified::LengthOrPercentage::parse(input));
|
||||||
let second = input.try(|input| {
|
let second = input.try(|input| {
|
||||||
try!(input.expect_comma());
|
try!(input.expect_comma());
|
||||||
specified::LengthAndPercentage::parse(input)
|
specified::LengthOrPercentage::parse(input)
|
||||||
}).unwrap_or(specified::LengthAndPercentage::zero());
|
}).unwrap_or(specified::LengthOrPercentage::zero());
|
||||||
Ok((first, second))
|
Ok((first, second))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3282,8 +3282,8 @@ pub mod longhands {
|
||||||
enum SpecifiedOperation {
|
enum SpecifiedOperation {
|
||||||
Matrix(SpecifiedMatrix),
|
Matrix(SpecifiedMatrix),
|
||||||
Skew(CSSFloat, CSSFloat),
|
Skew(CSSFloat, CSSFloat),
|
||||||
Translate(specified::LengthAndPercentage,
|
Translate(specified::LengthOrPercentage,
|
||||||
specified::LengthAndPercentage,
|
specified::LengthOrPercentage,
|
||||||
specified::Length),
|
specified::Length),
|
||||||
Scale(CSSFloat, CSSFloat, CSSFloat),
|
Scale(CSSFloat, CSSFloat, CSSFloat),
|
||||||
Rotate(CSSFloat, CSSFloat, CSSFloat, specified::Angle),
|
Rotate(CSSFloat, CSSFloat, CSSFloat, specified::Angle),
|
||||||
|
@ -3381,9 +3381,8 @@ pub mod longhands {
|
||||||
try!(input.parse_nested_block(|input| {
|
try!(input.parse_nested_block(|input| {
|
||||||
let tx = try!(specified::LengthOrPercentage::parse(input));
|
let tx = try!(specified::LengthOrPercentage::parse(input));
|
||||||
result.push(SpecifiedOperation::Translate(
|
result.push(SpecifiedOperation::Translate(
|
||||||
specified::LengthAndPercentage::from_length_or_percentage(
|
tx,
|
||||||
&tx),
|
specified::LengthOrPercentage::zero(),
|
||||||
specified::LengthAndPercentage::zero(),
|
|
||||||
specified::Length::Absolute(Au(0))));
|
specified::Length::Absolute(Au(0))));
|
||||||
Ok(())
|
Ok(())
|
||||||
}))
|
}))
|
||||||
|
@ -3392,9 +3391,8 @@ pub mod longhands {
|
||||||
try!(input.parse_nested_block(|input| {
|
try!(input.parse_nested_block(|input| {
|
||||||
let ty = try!(specified::LengthOrPercentage::parse(input));
|
let ty = try!(specified::LengthOrPercentage::parse(input));
|
||||||
result.push(SpecifiedOperation::Translate(
|
result.push(SpecifiedOperation::Translate(
|
||||||
specified::LengthAndPercentage::zero(),
|
specified::LengthOrPercentage::zero(),
|
||||||
specified::LengthAndPercentage::from_length_or_percentage(
|
ty,
|
||||||
&ty),
|
|
||||||
specified::Length::Absolute(Au(0))));
|
specified::Length::Absolute(Au(0))));
|
||||||
Ok(())
|
Ok(())
|
||||||
}))
|
}))
|
||||||
|
@ -3403,8 +3401,8 @@ pub mod longhands {
|
||||||
try!(input.parse_nested_block(|input| {
|
try!(input.parse_nested_block(|input| {
|
||||||
let tz = try!(specified::Length::parse(input));
|
let tz = try!(specified::Length::parse(input));
|
||||||
result.push(SpecifiedOperation::Translate(
|
result.push(SpecifiedOperation::Translate(
|
||||||
specified::LengthAndPercentage::zero(),
|
specified::LengthOrPercentage::zero(),
|
||||||
specified::LengthAndPercentage::zero(),
|
specified::LengthOrPercentage::zero(),
|
||||||
tz));
|
tz));
|
||||||
Ok(())
|
Ok(())
|
||||||
}))
|
}))
|
||||||
|
@ -3417,8 +3415,8 @@ pub mod longhands {
|
||||||
try!(input.expect_comma());
|
try!(input.expect_comma());
|
||||||
let tz = try!(specified::Length::parse(input));
|
let tz = try!(specified::Length::parse(input));
|
||||||
result.push(SpecifiedOperation::Translate(
|
result.push(SpecifiedOperation::Translate(
|
||||||
specified::LengthAndPercentage::from_length_or_percentage(&tx),
|
tx,
|
||||||
specified::LengthAndPercentage::from_length_or_percentage(&ty),
|
ty,
|
||||||
tz));
|
tz));
|
||||||
Ok(())
|
Ok(())
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -79,7 +79,7 @@ pub mod specified {
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::ops::{Add, Mul};
|
use std::ops::Mul;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use cssparser::{self, Token, Parser, ToCss, CssStringWriter};
|
use cssparser::{self, Token, Parser, ToCss, CssStringWriter};
|
||||||
use euclid::size::Size2D;
|
use euclid::size::Size2D;
|
||||||
|
@ -370,6 +370,10 @@ pub mod specified {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl LengthOrPercentage {
|
impl LengthOrPercentage {
|
||||||
|
pub fn zero() -> LengthOrPercentage {
|
||||||
|
LengthOrPercentage::Length(Length::Absolute(Au(0)))
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_internal(input: &mut Parser, context: &AllowedNumericType)
|
fn parse_internal(input: &mut Parser, context: &AllowedNumericType)
|
||||||
-> Result<LengthOrPercentage, ()>
|
-> Result<LengthOrPercentage, ()>
|
||||||
{
|
{
|
||||||
|
@ -521,81 +525,6 @@ pub mod specified {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The sum of a series of lengths and a percentage. This is used in `calc()` and other things
|
|
||||||
/// that effectively work like it (e.g. transforms).
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
|
||||||
pub struct LengthAndPercentage {
|
|
||||||
/// The length components.
|
|
||||||
pub lengths: Vec<Length>,
|
|
||||||
/// The percentage component.
|
|
||||||
pub percentage: CSSFloat,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LengthAndPercentage {
|
|
||||||
pub fn zero() -> LengthAndPercentage {
|
|
||||||
LengthAndPercentage {
|
|
||||||
lengths: Vec::new(),
|
|
||||||
percentage: 0.0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_length_or_percentage(length_or_percentage: &LengthOrPercentage)
|
|
||||||
-> LengthAndPercentage {
|
|
||||||
match *length_or_percentage {
|
|
||||||
LengthOrPercentage::Length(ref length) => {
|
|
||||||
LengthAndPercentage::from_length(*length)
|
|
||||||
}
|
|
||||||
LengthOrPercentage::Percentage(percentage) => {
|
|
||||||
LengthAndPercentage::from_percentage(percentage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse(input: &mut Parser) -> Result<LengthAndPercentage, ()> {
|
|
||||||
LengthOrPercentage::parse(input).map(|value| {
|
|
||||||
LengthAndPercentage::from_length_or_percentage(&value)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_length(length: Length) -> LengthAndPercentage {
|
|
||||||
LengthAndPercentage {
|
|
||||||
lengths: vec![length],
|
|
||||||
percentage: 0.0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_percentage(percentage: CSSFloat) -> LengthAndPercentage {
|
|
||||||
LengthAndPercentage {
|
|
||||||
lengths: Vec::new(),
|
|
||||||
percentage: percentage,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Add<LengthAndPercentage> for LengthAndPercentage {
|
|
||||||
type Output = LengthAndPercentage;
|
|
||||||
|
|
||||||
fn add(self, other: LengthAndPercentage) -> LengthAndPercentage {
|
|
||||||
let mut new_lengths = self.lengths.clone();
|
|
||||||
new_lengths.push_all(&other.lengths);
|
|
||||||
LengthAndPercentage {
|
|
||||||
lengths: new_lengths,
|
|
||||||
percentage: self.percentage + other.percentage,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Mul<CSSFloat> for LengthAndPercentage {
|
|
||||||
type Output = LengthAndPercentage;
|
|
||||||
|
|
||||||
fn mul(self, scalar: CSSFloat) -> LengthAndPercentage {
|
|
||||||
LengthAndPercentage {
|
|
||||||
lengths: self.lengths.iter().map(|length| *length * scalar).collect(),
|
|
||||||
percentage: self.percentage * scalar,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://dev.w3.org/csswg/css2/colors.html#propdef-background-position
|
// http://dev.w3.org/csswg/css2/colors.html#propdef-background-position
|
||||||
#[derive(Clone, PartialEq, Copy)]
|
#[derive(Clone, PartialEq, Copy)]
|
||||||
pub enum PositionComponent {
|
pub enum PositionComponent {
|
||||||
|
@ -936,7 +865,6 @@ pub mod computed {
|
||||||
use euclid::size::Size2D;
|
use euclid::size::Size2D;
|
||||||
use properties::longhands;
|
use properties::longhands;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ops::{Add, Mul};
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use util::geometry::Au;
|
use util::geometry::Au;
|
||||||
|
|
||||||
|
@ -1016,6 +944,13 @@ pub mod computed {
|
||||||
Length(Au),
|
Length(Au),
|
||||||
Percentage(CSSFloat),
|
Percentage(CSSFloat),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl LengthOrPercentage {
|
||||||
|
pub fn zero() -> LengthOrPercentage {
|
||||||
|
LengthOrPercentage::Length(Au(0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Debug for LengthOrPercentage {
|
impl fmt::Debug for LengthOrPercentage {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
@ -1140,63 +1075,6 @@ pub mod computed {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The sum of a series of lengths and a percentage. This is used in `calc()` and other things
|
|
||||||
/// that effectively work like it (e.g. transforms).
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
||||||
pub struct LengthAndPercentage {
|
|
||||||
/// The length component.
|
|
||||||
pub length: Au,
|
|
||||||
/// The percentage component.
|
|
||||||
pub percentage: CSSFloat,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LengthAndPercentage {
|
|
||||||
#[inline]
|
|
||||||
pub fn zero() -> LengthAndPercentage {
|
|
||||||
LengthAndPercentage {
|
|
||||||
length: Au(0),
|
|
||||||
percentage: 0.0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToComputedValue for specified::LengthAndPercentage {
|
|
||||||
type ComputedValue = LengthAndPercentage;
|
|
||||||
|
|
||||||
fn to_computed_value(&self, context: &Context) -> LengthAndPercentage {
|
|
||||||
let mut total_length = Au(0);
|
|
||||||
for length in self.lengths.iter() {
|
|
||||||
total_length = total_length + length.to_computed_value(context)
|
|
||||||
}
|
|
||||||
LengthAndPercentage {
|
|
||||||
length: total_length,
|
|
||||||
percentage: self.percentage,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Add<LengthAndPercentage> for LengthAndPercentage {
|
|
||||||
type Output = LengthAndPercentage;
|
|
||||||
|
|
||||||
fn add(self, other: LengthAndPercentage) -> LengthAndPercentage {
|
|
||||||
LengthAndPercentage {
|
|
||||||
length: self.length + other.length,
|
|
||||||
percentage: self.percentage + other.percentage,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Mul<CSSFloat> for LengthAndPercentage {
|
|
||||||
type Output = LengthAndPercentage;
|
|
||||||
|
|
||||||
fn mul(self, scalar: CSSFloat) -> LengthAndPercentage {
|
|
||||||
LengthAndPercentage {
|
|
||||||
length: Au::from_f32_px(self.length.to_f32_px() * scalar),
|
|
||||||
percentage: self.percentage * scalar,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToComputedValue for specified::Image {
|
impl ToComputedValue for specified::Image {
|
||||||
type ComputedValue = Image;
|
type ComputedValue = Image;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue