aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/layout/display_list_builder.rs6
-rw-r--r--components/layout/model.rs14
-rw-r--r--components/style/animation.rs17
-rw-r--r--components/style/properties.mako.rs36
-rw-r--r--components/style/values.rs146
5 files changed, 36 insertions, 183 deletions
diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs
index 2c09a1be973..c63e7e1f5ae 100644
--- a/components/layout/display_list_builder.rs
+++ b/components/layout/display_list_builder.rs
@@ -18,7 +18,7 @@ use fragment::{CoordinateSystem, Fragment, IframeFragmentInfo, ImageFragmentInfo
use fragment::{ScannedTextFragmentInfo, SpecificFragmentInfo};
use inline::InlineFlow;
use list_item::ListItemFlow;
-use model::{self, MaybeAuto, ToGfxMatrix, ToAu};
+use model::{self, MaybeAuto, ToGfxMatrix};
use table_cell::CollapsedBordersForCell;
use canvas_traits::{CanvasMsg, FromLayoutMsg};
@@ -1176,8 +1176,8 @@ impl FragmentDisplayListBuilding for Fragment {
Matrix4::create_scale(sx, sy, sz)
}
&transform::ComputedOperation::Translate(tx, ty, tz) => {
- let tx = tx.to_au(border_box.size.width).to_f32_px();
- let ty = ty.to_au(border_box.size.height).to_f32_px();
+ let tx = model::specified(tx, border_box.size.width).to_f32_px();
+ let ty = model::specified(ty, border_box.size.height).to_f32_px();
let tz = tz.to_f32_px();
Matrix4::create_translation(tx, ty, tz)
}
diff --git a/components/layout/model.rs b/components/layout/model.rs
index d6587a13a4c..3c5cda25314 100644
--- a/components/layout/model.rs
+++ b/components/layout/model.rs
@@ -13,7 +13,7 @@ use std::cmp::{max, min};
use std::fmt;
use style::computed_values::transform::ComputedMatrix;
use style::properties::ComputedValues;
-use style::values::computed::{LengthAndPercentage, LengthOrPercentageOrAuto};
+use style::values::computed::LengthOrPercentageOrAuto;
use style::values::computed::{LengthOrPercentageOrNone, LengthOrPercentage};
use util::geometry::Au;
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())
- }
-}
-
diff --git a/components/style/animation.rs b/components/style/animation.rs
index cecf676c5e5..f094229b931 100644
--- a/components/style/animation.rs
+++ b/components/style/animation.rs
@@ -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::T as TransformList;
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
-use values::computed::{LengthAndPercentage, LengthOrPercentage, Length, Time};
+use values::computed::{LengthOrPercentage, Length, Time};
use values::CSSFloat;
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 {
#[inline]
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));
}
&TransformOperation::Translate(..) => {
- result.push(TransformOperation::Translate(LengthAndPercentage::zero(),
- LengthAndPercentage::zero(),
+ result.push(TransformOperation::Translate(LengthOrPercentage::zero(),
+ LengthOrPercentage::zero(),
Au(0)));
}
&TransformOperation::Scale(..) => {
diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs
index b37f2313497..354d956bf58 100644
--- a/components/style/properties.mako.rs
+++ b/components/style/properties.mako.rs
@@ -3245,8 +3245,8 @@ pub mod longhands {
pub enum ComputedOperation {
Matrix(ComputedMatrix),
Skew(CSSFloat, CSSFloat),
- Translate(computed::LengthAndPercentage,
- computed::LengthAndPercentage,
+ Translate(computed::LengthOrPercentage,
+ computed::LengthOrPercentage,
computed::Length),
Scale(CSSFloat, CSSFloat, CSSFloat),
Rotate(CSSFloat, CSSFloat, CSSFloat, computed::Angle),
@@ -3259,13 +3259,13 @@ pub mod longhands {
pub use self::computed_value::ComputedMatrix as SpecifiedMatrix;
fn parse_two_lengths_or_percentages(input: &mut Parser)
- -> Result<(specified::LengthAndPercentage,
- specified::LengthAndPercentage),()> {
- let first = try!(specified::LengthAndPercentage::parse(input));
+ -> Result<(specified::LengthOrPercentage,
+ specified::LengthOrPercentage),()> {
+ let first = try!(specified::LengthOrPercentage::parse(input));
let second = input.try(|input| {
try!(input.expect_comma());
- specified::LengthAndPercentage::parse(input)
- }).unwrap_or(specified::LengthAndPercentage::zero());
+ specified::LengthOrPercentage::parse(input)
+ }).unwrap_or(specified::LengthOrPercentage::zero());
Ok((first, second))
}
@@ -3282,8 +3282,8 @@ pub mod longhands {
enum SpecifiedOperation {
Matrix(SpecifiedMatrix),
Skew(CSSFloat, CSSFloat),
- Translate(specified::LengthAndPercentage,
- specified::LengthAndPercentage,
+ Translate(specified::LengthOrPercentage,
+ specified::LengthOrPercentage,
specified::Length),
Scale(CSSFloat, CSSFloat, CSSFloat),
Rotate(CSSFloat, CSSFloat, CSSFloat, specified::Angle),
@@ -3381,9 +3381,8 @@ pub mod longhands {
try!(input.parse_nested_block(|input| {
let tx = try!(specified::LengthOrPercentage::parse(input));
result.push(SpecifiedOperation::Translate(
- specified::LengthAndPercentage::from_length_or_percentage(
- &tx),
- specified::LengthAndPercentage::zero(),
+ tx,
+ specified::LengthOrPercentage::zero(),
specified::Length::Absolute(Au(0))));
Ok(())
}))
@@ -3392,9 +3391,8 @@ pub mod longhands {
try!(input.parse_nested_block(|input| {
let ty = try!(specified::LengthOrPercentage::parse(input));
result.push(SpecifiedOperation::Translate(
- specified::LengthAndPercentage::zero(),
- specified::LengthAndPercentage::from_length_or_percentage(
- &ty),
+ specified::LengthOrPercentage::zero(),
+ ty,
specified::Length::Absolute(Au(0))));
Ok(())
}))
@@ -3403,8 +3401,8 @@ pub mod longhands {
try!(input.parse_nested_block(|input| {
let tz = try!(specified::Length::parse(input));
result.push(SpecifiedOperation::Translate(
- specified::LengthAndPercentage::zero(),
- specified::LengthAndPercentage::zero(),
+ specified::LengthOrPercentage::zero(),
+ specified::LengthOrPercentage::zero(),
tz));
Ok(())
}))
@@ -3417,8 +3415,8 @@ pub mod longhands {
try!(input.expect_comma());
let tz = try!(specified::Length::parse(input));
result.push(SpecifiedOperation::Translate(
- specified::LengthAndPercentage::from_length_or_percentage(&tx),
- specified::LengthAndPercentage::from_length_or_percentage(&ty),
+ tx,
+ ty,
tz));
Ok(())
}))
diff --git a/components/style/values.rs b/components/style/values.rs
index 3411db28fe5..93d6ccc7e6c 100644
--- a/components/style/values.rs
+++ b/components/style/values.rs
@@ -79,7 +79,7 @@ pub mod specified {
use std::f32::consts::PI;
use std::fmt;
use std::fmt::Write;
- use std::ops::{Add, Mul};
+ use std::ops::Mul;
use url::Url;
use cssparser::{self, Token, Parser, ToCss, CssStringWriter};
use euclid::size::Size2D;
@@ -370,6 +370,10 @@ pub mod specified {
}
}
impl LengthOrPercentage {
+ pub fn zero() -> LengthOrPercentage {
+ LengthOrPercentage::Length(Length::Absolute(Au(0)))
+ }
+
fn parse_internal(input: &mut Parser, context: &AllowedNumericType)
-> 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
#[derive(Clone, PartialEq, Copy)]
pub enum PositionComponent {
@@ -936,7 +865,6 @@ pub mod computed {
use euclid::size::Size2D;
use properties::longhands;
use std::fmt;
- use std::ops::{Add, Mul};
use url::Url;
use util::geometry::Au;
@@ -1016,6 +944,13 @@ pub mod computed {
Length(Au),
Percentage(CSSFloat),
}
+
+ impl LengthOrPercentage {
+ pub fn zero() -> LengthOrPercentage {
+ LengthOrPercentage::Length(Au(0))
+ }
+ }
+
impl fmt::Debug for LengthOrPercentage {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
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 {
type ComputedValue = Image;