diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2015-04-23 00:14:02 +0200 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2015-05-05 10:07:34 -0400 |
commit | ef8edd4e87aeb3cc71dfd9da2f69437080f5410e (patch) | |
tree | 9146cdd7126ead59c57cacbaa04eda0f16761f65 /components/style | |
parent | 7b87085c1880c60aa3be5b3ec4572a0d93fd5537 (diff) | |
download | servo-ef8edd4e87aeb3cc71dfd9da2f69437080f5410e.tar.gz servo-ef8edd4e87aeb3cc71dfd9da2f69437080f5410e.zip |
Upgrade to rustc 551a74dddd84cf01440ee84148ebd18bc68bd7c8.
Diffstat (limited to 'components/style')
-rw-r--r-- | components/style/Cargo.toml | 5 | ||||
-rw-r--r-- | components/style/animation.rs | 89 | ||||
-rw-r--r-- | components/style/build.rs | 2 | ||||
-rw-r--r-- | components/style/legacy.rs | 26 | ||||
-rw-r--r-- | components/style/lib.rs | 3 | ||||
-rw-r--r-- | components/style/node.rs | 2 | ||||
-rw-r--r-- | components/style/properties.mako.rs | 292 | ||||
-rw-r--r-- | components/style/selector_matching.rs | 6 | ||||
-rw-r--r-- | components/style/stylesheets.rs | 4 | ||||
-rw-r--r-- | components/style/values.rs | 170 |
10 files changed, 293 insertions, 306 deletions
diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index dde46e98962..96438546fc5 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -18,9 +18,6 @@ path = "../util" [dependencies.geom] git = "https://github.com/servo/rust-geom" -[dependencies.cssparser] -git = "https://github.com/servo/rust-cssparser" - [dependencies.selectors] git = "https://github.com/servo/rust-selectors" @@ -34,10 +31,10 @@ git = "https://github.com/servo/string-cache" git = "https://github.com/servo/string-cache" [dependencies] -text_writer = "0.1.1" encoding = "0.2" rustc-serialize = "0.3" matches = "0.1" url = "0.2.16" mod_path = "0.1" bitflags = "*" +cssparser = "0.3.1" diff --git a/components/style/animation.rs b/components/style/animation.rs index 06e073bf745..d8652b3ea0e 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -21,10 +21,8 @@ use values::computed::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, Lengt use values::CSSFloat; use cssparser::{RGBA, Color}; -use std::num::Float; use std::cmp::Ordering; use std::iter::repeat; -use std::num::FromPrimitive; use util::bezier::Bezier; use util::geometry::Au; @@ -155,7 +153,7 @@ impl PropertyAnimation { } } - pub fn update(&self, style: &mut ComputedValues, time: f64) { + pub fn update(&self, style: &mut ComputedValues, time: f32) { let progress = match self.timing_function { TransitionTimingFunction::CubicBezier(p1, p2) => { // See `WebCore::AnimationBase::solveEpsilon(double)` in WebKit. @@ -163,10 +161,10 @@ impl PropertyAnimation { Bezier::new(p1, p2).solve(time, epsilon) } TransitionTimingFunction::Steps(steps, StartEnd::Start) => { - (time * (steps as f64)).ceil() / (steps as f64) + (time * (steps as f32)).ceil() / (steps as f32) } TransitionTimingFunction::Steps(steps, StartEnd::End) => { - (time * (steps as f64)).floor() / (steps as f64) + (time * (steps as f32)).floor() / (steps as f32) } }; @@ -336,19 +334,19 @@ impl AnimatedProperty { } trait Interpolate { - fn interpolate(&self, other: &Self, time: f64) -> Option<Self>; + fn interpolate(&self, other: &Self, time: f32) -> Option<Self>; } impl Interpolate for Au { #[inline] - fn interpolate(&self, other: &Au, time: f64) -> Option<Au> { - Some(Au((self.0 as f64 + (other.0 as f64 - self.0 as f64) * time).round() as i32)) + fn interpolate(&self, other: &Au, time: f32) -> Option<Au> { + Some(Au((self.0 as f32 + (other.0 as f32 - self.0 as f32) * time).round() as i32)) } } impl <T> Interpolate for Option<T> where T:Interpolate { #[inline] - fn interpolate(&self, other: &Option<T>, time: f64) -> Option<Option<T>> { + fn interpolate(&self, other: &Option<T>, time: f32) -> Option<Option<T>> { match (self, other) { (&Some(ref this), &Some(ref other)) => { this.interpolate(other, time).and_then(|value| { @@ -360,32 +358,32 @@ impl <T> Interpolate for Option<T> where T:Interpolate { } } -impl Interpolate for f64 { +impl Interpolate for f32 { #[inline] - fn interpolate(&self, other: &f64, time: f64) -> Option<f64> { + fn interpolate(&self, other: &f32, time: f32) -> Option<f32> { Some(*self + (*other - *self) * time) } } -impl Interpolate for f32 { +impl Interpolate for f64 { #[inline] - fn interpolate(&self, other: &f32, time: f64) -> Option<f32> { - Some(*self + (*other - *self) * (time as f32)) + fn interpolate(&self, other: &f64, time: f32) -> Option<f64> { + Some(*self + (*other - *self) * (time as f64)) } } impl Interpolate for i32 { #[inline] - fn interpolate(&self, other: &i32, time: f64) -> Option<i32> { - let a = *self as f64; - let b = *other as f64; + fn interpolate(&self, other: &i32, time: f32) -> Option<i32> { + let a = *self as f32; + let b = *other as f32; Some((a + (b - a) * time).round() as i32) } } impl Interpolate for Visibility { #[inline] - fn interpolate(&self, other: &Visibility, time: f64) + fn interpolate(&self, other: &Visibility, time: f32) -> Option<Visibility> { match (*self, *other) { (Visibility::visible, _) | (_, Visibility::visible) => { @@ -404,7 +402,7 @@ impl Interpolate for Visibility { impl Interpolate for ZIndex { #[inline] - fn interpolate(&self, other: &ZIndex, time: f64) + fn interpolate(&self, other: &ZIndex, time: f32) -> Option<ZIndex> { match (*self, *other) { (ZIndex::Number(ref this), @@ -420,7 +418,7 @@ impl Interpolate for ZIndex { impl Interpolate for VerticalAlign { #[inline] - fn interpolate(&self, other: &VerticalAlign, time: f64) + fn interpolate(&self, other: &VerticalAlign, time: f32) -> Option<VerticalAlign> { match (*self, *other) { (VerticalAlign::Length(ref this), @@ -436,7 +434,7 @@ impl Interpolate for VerticalAlign { impl Interpolate for BorderSpacing { #[inline] - fn interpolate(&self, other: &BorderSpacing, time: f64) + fn interpolate(&self, other: &BorderSpacing, time: f32) -> Option<BorderSpacing> { self.horizontal.interpolate(&other.horizontal, time).and_then(|horizontal| { self.vertical.interpolate(&other.vertical, time).and_then(|vertical| { @@ -448,7 +446,7 @@ impl Interpolate for BorderSpacing { impl Interpolate for RGBA { #[inline] - fn interpolate(&self, other: &RGBA, time: f64) -> Option<RGBA> { + fn interpolate(&self, other: &RGBA, time: f32) -> Option<RGBA> { match (self.red.interpolate(&other.red, time), self.green.interpolate(&other.green, time), self.blue.interpolate(&other.blue, time), @@ -463,7 +461,7 @@ impl Interpolate for RGBA { impl Interpolate for Color { #[inline] - fn interpolate(&self, other: &Color, time: f64) -> Option<Color> { + fn interpolate(&self, other: &Color, time: f32) -> Option<Color> { match (*self, *other) { (Color::RGBA(ref this), Color::RGBA(ref other)) => { this.interpolate(other, time).and_then(|value| { @@ -477,7 +475,7 @@ impl Interpolate for Color { impl Interpolate for LengthOrPercentage { #[inline] - fn interpolate(&self, other: &LengthOrPercentage, time: f64) + fn interpolate(&self, other: &LengthOrPercentage, time: f32) -> Option<LengthOrPercentage> { match (*self, *other) { (LengthOrPercentage::Length(ref this), @@ -499,7 +497,7 @@ impl Interpolate for LengthOrPercentage { impl Interpolate for LengthOrPercentageOrAuto { #[inline] - fn interpolate(&self, other: &LengthOrPercentageOrAuto, time: f64) + fn interpolate(&self, other: &LengthOrPercentageOrAuto, time: f32) -> Option<LengthOrPercentageOrAuto> { match (*self, *other) { (LengthOrPercentageOrAuto::Length(ref this), @@ -524,7 +522,7 @@ impl Interpolate for LengthOrPercentageOrAuto { impl Interpolate for LengthOrPercentageOrNone { #[inline] - fn interpolate(&self, other: &LengthOrPercentageOrNone, time: f64) + fn interpolate(&self, other: &LengthOrPercentageOrNone, time: f32) -> Option<LengthOrPercentageOrNone> { match (*self, *other) { (LengthOrPercentageOrNone::Length(ref this), @@ -549,7 +547,7 @@ impl Interpolate for LengthOrPercentageOrNone { impl Interpolate for LineHeight { #[inline] - fn interpolate(&self, other: &LineHeight, time: f64) + fn interpolate(&self, other: &LineHeight, time: f32) -> Option<LineHeight> { match (*self, *other) { (LineHeight::Length(ref this), @@ -572,20 +570,39 @@ impl Interpolate for LineHeight { } } +/// http://dev.w3.org/csswg/css-transitions/#animtype-font-weight impl Interpolate for FontWeight { #[inline] - fn interpolate(&self, other: &FontWeight, time: f64) + fn interpolate(&self, other: &FontWeight, time: f32) -> Option<FontWeight> { - let a = (*self as isize) as f64; - let b = (*other as isize) as f64; - let weight: Option<FontWeight> = FromPrimitive::from_isize((a + (b - a) * time).round() as isize); - weight + let a = (*self as u32) as f32; + let b = (*other as u32) as f32; + let weight = a + (b - a) * time; + Some(if weight < 150. { + FontWeight::Weight100 + } else if weight < 250. { + FontWeight::Weight200 + } else if weight < 350. { + FontWeight::Weight300 + } else if weight < 450. { + FontWeight::Weight400 + } else if weight < 550. { + FontWeight::Weight500 + } else if weight < 650. { + FontWeight::Weight600 + } else if weight < 750. { + FontWeight::Weight700 + } else if weight < 850. { + FontWeight::Weight800 + } else { + FontWeight::Weight900 + }) } } impl Interpolate for ClipRect { #[inline] - fn interpolate(&self, other: &ClipRect, time: f64) + fn interpolate(&self, other: &ClipRect, time: f32) -> Option<ClipRect> { match (self.top.interpolate(&other.top, time), self.right.interpolate(&other.right, time), @@ -601,7 +618,7 @@ impl Interpolate for ClipRect { impl Interpolate for BackgroundPosition { #[inline] - fn interpolate(&self, other: &BackgroundPosition, time: f64) + fn interpolate(&self, other: &BackgroundPosition, time: f32) -> Option<BackgroundPosition> { match (self.horizontal.interpolate(&other.horizontal, time), self.vertical.interpolate(&other.vertical, time)) { @@ -615,7 +632,7 @@ impl Interpolate for BackgroundPosition { impl Interpolate for TextShadow { #[inline] - fn interpolate(&self, other: &TextShadow, time: f64) + fn interpolate(&self, other: &TextShadow, time: f32) -> Option<TextShadow> { match (self.offset_x.interpolate(&other.offset_x, time), self.offset_y.interpolate(&other.offset_y, time), @@ -631,7 +648,7 @@ impl Interpolate for TextShadow { impl Interpolate for TextShadowList { #[inline] - fn interpolate(&self, other: &TextShadowList, time: f64) + fn interpolate(&self, other: &TextShadowList, time: f32) -> Option<TextShadowList> { let zero = TextShadow { offset_x: Au(0), diff --git a/components/style/build.rs b/components/style/build.rs index 8e2117614cf..80965f329f5 100644 --- a/components/style/build.rs +++ b/components/style/build.rs @@ -2,8 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#![feature(io, path)] - use std::env; use std::fs::File; use std::io::Write; diff --git a/components/style/legacy.rs b/components/style/legacy.rs index c65332246a4..f3a66f5138a 100644 --- a/components/style/legacy.rs +++ b/components/style/legacy.rs @@ -16,8 +16,8 @@ use properties::PropertyDeclaration; use properties::longhands::{self, border_spacing}; use selector_matching::Stylist; -use selectors::smallvec::VecLike; use util::geometry::Au; +use util::smallvec::VecLike; use util::str::LengthOrPercentageOrAuto; /// Legacy presentational attributes that take a length as defined in HTML5 § 2.4.4.4. @@ -88,9 +88,9 @@ impl PresentationalHintSynthesis for Stylist { V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> { let element = node.as_element(); - let length = matching_rules_list.vec_len(); + let length = matching_rules_list.len(); element.synthesize_presentational_hints_for_legacy_attributes(matching_rules_list); - if matching_rules_list.vec_len() != length { + if matching_rules_list.len() != length { // Never share style for elements with preshints *shareable = false; } @@ -101,13 +101,13 @@ impl PresentationalHintSynthesis for Stylist { LengthOrPercentageOrAuto::Auto => {} LengthOrPercentageOrAuto::Percentage(percentage) => { let width_value = specified::LengthOrPercentageOrAuto::Percentage(percentage); - matching_rules_list.vec_push(from_declaration( + matching_rules_list.push(from_declaration( PropertyDeclaration::Width(SpecifiedValue(width_value)))); *shareable = false } LengthOrPercentageOrAuto::Length(length) => { let width_value = specified::LengthOrPercentageOrAuto::Length(specified::Length::Absolute(length)); - matching_rules_list.vec_push(from_declaration( + matching_rules_list.push(from_declaration( PropertyDeclaration::Width(SpecifiedValue(width_value)))); *shareable = false } @@ -127,7 +127,7 @@ impl PresentationalHintSynthesis for Stylist { None => {} Some(length) => { let width_value = specified::Length::Absolute(Au::from_px(length as isize)); - matching_rules_list.vec_push(from_declaration( + matching_rules_list.push(from_declaration( PropertyDeclaration::BorderSpacing( SpecifiedValue( border_spacing::SpecifiedValue { @@ -146,7 +146,7 @@ impl PresentationalHintSynthesis for Stylist { Some(value) if value != 0 => { let value = specified::Length::ServoCharacterWidth( specified::CharacterWidth(value)); - matching_rules_list.vec_push(from_declaration( + matching_rules_list.push(from_declaration( PropertyDeclaration::Width(SpecifiedValue( specified::LengthOrPercentageOrAuto::Length(value))))); *shareable = false @@ -166,7 +166,7 @@ impl PresentationalHintSynthesis for Stylist { // // https://html.spec.whatwg.org/multipage/#textarea-effective-width let value = specified::Length::ServoCharacterWidth(specified::CharacterWidth(value)); - matching_rules_list.vec_push(from_declaration( + matching_rules_list.push(from_declaration( PropertyDeclaration::Width(SpecifiedValue( specified::LengthOrPercentageOrAuto::Length(value))))); *shareable = false @@ -179,7 +179,7 @@ impl PresentationalHintSynthesis for Stylist { // // https://html.spec.whatwg.org/multipage/#textarea-effective-height let value = specified::Length::FontRelative(specified::FontRelativeLength::Em(value as CSSFloat)); - matching_rules_list.vec_push(from_declaration( + matching_rules_list.push(from_declaration( PropertyDeclaration::Height(SpecifiedValue( longhands::height::SpecifiedValue( specified::LengthOrPercentageOrAuto::Length(value)))))); @@ -205,16 +205,16 @@ impl PresentationalHintSynthesis for Stylist { None => {} Some(length) => { let width_value = specified::Length::Absolute(Au::from_px(length as isize)); - matching_rules_list.vec_push(from_declaration( + matching_rules_list.push(from_declaration( PropertyDeclaration::BorderTopWidth(SpecifiedValue( longhands::border_top_width::SpecifiedValue(width_value))))); - matching_rules_list.vec_push(from_declaration( + matching_rules_list.push(from_declaration( PropertyDeclaration::BorderLeftWidth(SpecifiedValue( longhands::border_left_width::SpecifiedValue(width_value))))); - matching_rules_list.vec_push(from_declaration( + matching_rules_list.push(from_declaration( PropertyDeclaration::BorderBottomWidth(SpecifiedValue( longhands::border_bottom_width::SpecifiedValue(width_value))))); - matching_rules_list.vec_push(from_declaration( + matching_rules_list.push(from_declaration( PropertyDeclaration::BorderRightWidth(SpecifiedValue( longhands::border_right_width::SpecifiedValue(width_value))))); *shareable = false diff --git a/components/style/lib.rs b/components/style/lib.rs index b4de6f762c4..109216ecf55 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -18,7 +18,6 @@ extern crate collections; extern crate geom; -extern crate text_writer; extern crate url; #[macro_use] @@ -28,7 +27,7 @@ extern crate cssparser; extern crate matches; extern crate encoding; -extern crate "rustc-serialize" as rustc_serialize; +extern crate rustc_serialize; extern crate string_cache; extern crate selectors; diff --git a/components/style/node.rs b/components/style/node.rs index 6d2c84ac8cc..011066951c3 100644 --- a/components/style/node.rs +++ b/components/style/node.rs @@ -7,10 +7,10 @@ use legacy::{IntegerAttribute, LengthAttribute, UnsignedIntegerAttribute}; use properties::PropertyDeclaration; +use util::smallvec::VecLike; use util::str::LengthOrPercentageOrAuto; use selectors::matching::DeclarationBlock; -use selectors::smallvec::VecLike; pub use selectors::tree::{TNode, TElement}; pub trait TElementAttributes : Copy { diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index 9100f8221cd..ccf5095c0e8 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -232,10 +232,10 @@ pub mod longhands { use values::computed::{ToComputedValue, Context}; use util::geometry::Au; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self.0.to_css(dest) } } @@ -384,7 +384,7 @@ pub mod longhands { pub type SpecifiedValue = computed_value::T; pub mod computed_value { use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; #[derive(PartialEq, Clone, Eq, Copy, Debug)] pub enum T { @@ -393,7 +393,7 @@ pub mod longhands { } impl ToCss for T { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { &T::Auto => dest.write_str("auto"), &T::Number(number) => write!(dest, "{}", number), @@ -437,10 +437,10 @@ pub mod longhands { <%self:longhand name="height"> use values::computed::{ToComputedValue, Context}; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self.0.to_css(dest) } } @@ -493,7 +493,7 @@ pub mod longhands { <%self:longhand name="line-height"> use values::computed::{ToComputedValue, Context}; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; use values::CSSFloat; #[derive(Clone, PartialEq, Copy)] @@ -505,7 +505,7 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { &SpecifiedValue::Normal => dest.write_str("normal"), &SpecifiedValue::Length(length) => length.to_css(dest), @@ -583,7 +583,7 @@ pub mod longhands { <%self:longhand name="vertical-align"> use values::computed::{ToComputedValue, Context}; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; <% vertical_align_keywords = ( "baseline sub super top text-top middle bottom text-bottom".split()) %> @@ -597,7 +597,7 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { % for keyword in vertical_align_keywords: &SpecifiedValue::${to_rust_ident(keyword)} => dest.write_str("${keyword}"), @@ -716,12 +716,12 @@ pub mod longhands { use values::computed::{Context, ToComputedValue}; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; pub use self::computed_value::T as SpecifiedValue; impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self.0.to_css(dest) } } @@ -778,7 +778,7 @@ pub mod longhands { use super::super::list_style_type; use cssparser::{self, ToCss}; - use text_writer::{self, TextWriter}; + use std::fmt; #[derive(PartialEq, Eq, Clone)] pub enum ContentItem { @@ -799,7 +799,7 @@ pub mod longhands { } impl ToCss for ContentItem { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { &ContentItem::String(ref s) => { cssparser::serialize_string(&**s, dest) @@ -837,7 +837,7 @@ pub mod longhands { } impl ToCss for T { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { &T::normal => dest.write_str("normal"), &T::none => dest.write_str("none"), @@ -943,10 +943,9 @@ pub mod longhands { """)} <%self:longhand name="list-style-image"> - use std::borrow::IntoCow; use url::Url; use cssparser::{ToCss, Token}; - use text_writer::{self, TextWriter}; + use std::fmt; use values::computed::{ToComputedValue, Context}; #[derive(Clone, PartialEq, Eq)] @@ -956,11 +955,11 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { SpecifiedValue::None => dest.write_str("none"), SpecifiedValue::Url(ref url) => { - Token::Url(url.to_string().into_cow()).to_css(dest) + Token::Url(url.to_string().into()).to_css(dest) } } } @@ -997,11 +996,11 @@ pub mod longhands { </%self:longhand> <%self:longhand name="quotes"> - use text_writer::{self, TextWriter}; + use std::fmt; use values::computed::ComputedValueAsSpecified; + use std::borrow::Cow; use cssparser::{ToCss, Token}; - use std::borrow::IntoCow; pub use self::computed_value::T as SpecifiedValue; @@ -1013,16 +1012,16 @@ pub mod longhands { impl ComputedValueAsSpecified for SpecifiedValue {} impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { let mut first = true; for pair in self.0.iter() { if !first { try!(dest.write_str(" ")); } first = false; - try!(Token::QuotedString((*pair.0).into_cow()).to_css(dest)); + try!(Token::QuotedString(Cow::from(&*pair.0)).to_css(dest)); try!(dest.write_str(" ")); - try!(Token::QuotedString((*pair.1).into_cow()).to_css(dest)); + try!(Token::QuotedString(Cow::from(&*pair.1)).to_css(dest)); } Ok(()) } @@ -1066,11 +1065,11 @@ pub mod longhands { <%self:longhand name="counter-increment"> use super::content; - use text_writer::{self, TextWriter}; + use std::fmt; use values::computed::ComputedValueAsSpecified; use cssparser::{ToCss, Token}; - use std::borrow::{IntoCow, ToOwned}; + use std::borrow::{Cow, ToOwned}; pub use self::computed_value::T as SpecifiedValue; @@ -1087,15 +1086,15 @@ pub mod longhands { impl ComputedValueAsSpecified for SpecifiedValue {} impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { let mut first = true; for pair in self.0.iter() { if !first { try!(dest.write_str(" ")); } first = false; - try!(Token::QuotedString(pair.0.as_slice().into_cow()).to_css(dest)); - try!(dest.write_str(format!(" {}", pair.1).as_slice())); + try!(Token::QuotedString(Cow::from(&*pair.0)).to_css(dest)); + try!(write!(dest, " {}", pair.1)); } Ok(()) } @@ -1145,7 +1144,7 @@ pub mod longhands { use values::specified::Image; use values::computed::{ToComputedValue, Context}; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; pub mod computed_value { use values::computed; @@ -1156,7 +1155,7 @@ pub mod longhands { pub struct SpecifiedValue(pub Option<Image>); impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { SpecifiedValue(Some(ref image)) => image.to_css(dest), SpecifiedValue(None) => dest.write_str("none"), @@ -1190,7 +1189,7 @@ pub mod longhands { <%self:longhand name="background-position"> use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; use values::computed::{ToComputedValue, Context}; pub mod computed_value { @@ -1210,7 +1209,7 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.horizontal.to_css(dest)); try!(dest.write_str(" ")); try!(self.vertical.to_css(dest)); @@ -1300,7 +1299,7 @@ pub mod longhands { <%self:longhand name="background-size"> use cssparser::{ToCss, Token}; use std::ascii::AsciiExt; - use text_writer::{self, TextWriter}; + use std::fmt; use values::computed::{Context, ToComputedValue}; pub mod computed_value { @@ -1327,7 +1326,7 @@ pub mod longhands { } impl ToCss for SpecifiedExplicitSize { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.width.to_css(dest)); try!(dest.write_str(" ")); self.height.to_css(dest) @@ -1342,7 +1341,7 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { SpecifiedValue::Explicit(ref size) => size.to_css(dest), SpecifiedValue::Cover => dest.write_str("cover"), @@ -1461,12 +1460,13 @@ pub mod longhands { use self::computed_value::FontFamily; use string_cache::Atom; use values::computed::ComputedValueAsSpecified; + pub use self::computed_value::T as SpecifiedValue; impl ComputedValueAsSpecified for SpecifiedValue {} pub mod computed_value { use cssparser::ToCss; use string_cache::Atom; - use text_writer::{self, TextWriter}; + use std::fmt; #[derive(PartialEq, Eq, Clone, Hash)] pub enum FontFamily { @@ -1487,15 +1487,15 @@ pub mod longhands { } } impl ToCss for FontFamily { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { &FontFamily::FamilyName(ref name) => dest.write_str(name.as_slice()), } } } - impl ToCss for Vec<FontFamily> { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { - let mut iter = self.iter(); + impl ToCss for T { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + let mut iter = self.0.iter(); try!(iter.next().unwrap().to_css(dest)); for family in iter { try!(dest.write_str(", ")); @@ -1504,23 +1504,23 @@ pub mod longhands { Ok(()) } } - pub type T = Vec<FontFamily>; + #[derive(Clone, PartialEq, Eq, Hash)] + pub struct T(pub Vec<FontFamily>); } - pub type SpecifiedValue = computed_value::T; #[inline] pub fn get_initial_value() -> computed_value::T { - vec![FontFamily::FamilyName(Atom::from_slice("serif"))] + computed_value::T(vec![FontFamily::FamilyName(Atom::from_slice("serif"))]) } /// <family-name># /// <family-name> = <string> | [ <ident>+ ] /// TODO: <generic-family> pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> { - input.parse_comma_separated(parse_one_family) + input.parse_comma_separated(parse_one_family).map(SpecifiedValue) } pub fn parse_one_family(input: &mut Parser) -> Result<FontFamily, ()> { if let Ok(value) = input.try(|input| input.expect_string()) { - return Ok(FontFamily::FamilyName(Atom::from_slice(value.as_slice()))) + return Ok(FontFamily::FamilyName(Atom::from_slice(&value))) } let first_ident = try!(input.expect_ident()); // match_ignore_ascii_case! { first_ident, @@ -1536,7 +1536,7 @@ pub mod longhands { value.push_str(" "); value.push_str(&ident); } - Ok(FontFamily::FamilyName(Atom::from_slice(value.as_slice()))) + Ok(FontFamily::FamilyName(Atom::from_slice(&value))) } </%self:longhand> @@ -1546,7 +1546,7 @@ pub mod longhands { <%self:longhand name="font-weight"> use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; use values::computed::{ToComputedValue, Context}; #[derive(Clone, PartialEq, Eq, Copy)] @@ -1559,7 +1559,7 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { &SpecifiedValue::Bolder => dest.write_str("bolder"), &SpecifiedValue::Lighter => dest.write_str("lighter"), @@ -1596,7 +1596,7 @@ pub mod longhands { } pub mod computed_value { use std::fmt; - #[derive(PartialEq, Eq, Copy, Clone, Hash, FromPrimitive)] + #[derive(PartialEq, Eq, Copy, Clone, Hash)] pub enum T { % for weight in range(100, 901, 100): Weight${weight} = ${weight}, @@ -1667,10 +1667,10 @@ pub mod longhands { use util::geometry::Au; use values::computed::{ToComputedValue, Context}; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self.0.to_css(dest) } } @@ -1730,12 +1730,59 @@ pub mod longhands { ${new_style_struct("InheritedText", is_inherited=True)} - ${single_keyword("text-align", "start end left right center justify")} + <%self:longhand name="text-align"> + pub use self::computed_value::T as SpecifiedValue; + use values::computed::ComputedValueAsSpecified; + impl ComputedValueAsSpecified for SpecifiedValue {} + pub mod computed_value { + macro_rules! define_text_align { + ( $( $name: ident => $discriminant: expr, )+ ) => { + define_css_keyword_enum! { T: + $( + stringify!($name) => $name, + )+ + } + impl T { + pub fn to_u32(self) -> u32 { + match self { + $( + T::$name => $discriminant, + )+ + } + } + pub fn from_u32(discriminant: u32) -> Option<T> { + match discriminant { + $( + $discriminant => Some(T::$name), + )+ + _ => None + } + } + } + } + } + define_text_align! { + start => 0, + end => 1, + left => 2, + right => 3, + center => 4, + justify => 5, + } + } + #[inline] pub fn get_initial_value() -> computed_value::T { + computed_value::T::start + } + pub fn parse(_context: &ParserContext, input: &mut Parser) + -> Result<SpecifiedValue, ()> { + computed_value::T::parse(input) + } + </%self:longhand> <%self:longhand name="letter-spacing"> use values::computed::{ToComputedValue, Context}; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; #[derive(Clone, Copy, PartialEq)] pub enum SpecifiedValue { @@ -1744,7 +1791,7 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { SpecifiedValue::Normal => dest.write_str("normal"), SpecifiedValue::Specified(l) => l.to_css(dest), @@ -1786,7 +1833,7 @@ pub mod longhands { <%self:longhand name="word-spacing"> use values::computed::{ToComputedValue, Context}; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; #[derive(Clone, Copy, PartialEq)] pub enum SpecifiedValue { @@ -1795,7 +1842,7 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { SpecifiedValue::Normal => dest.write_str("normal"), SpecifiedValue::Specified(l) => l.to_css(dest), @@ -1852,7 +1899,7 @@ pub mod longhands { <%self:longhand name="text-decoration"> use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; use values::computed::ComputedValueAsSpecified; impl ComputedValueAsSpecified for SpecifiedValue {} @@ -1867,7 +1914,7 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { let mut space = false; if self.underline { try!(dest.write_str("underline")); @@ -2030,7 +2077,7 @@ pub mod longhands { use values::computed::{Context, ToComputedValue}; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; use util::geometry::Au; pub mod computed_value { @@ -2058,7 +2105,7 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.horizontal.to_css(dest)); try!(dest.write_str(" ")); self.vertical.to_css(dest) @@ -2137,7 +2184,7 @@ pub mod longhands { pub mod computed_value { use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; use util::cursor::Cursor; #[derive(Clone, PartialEq, Eq, Copy, Debug)] @@ -2147,7 +2194,7 @@ pub mod longhands { } impl ToCss for T { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { T::AutoCursor => dest.write_str("auto"), T::SpecifiedCursor(c) => c.to_css(dest), @@ -2183,7 +2230,7 @@ pub mod longhands { <%self:longhand name="column-width" experimental="True"> use values::computed::{ToComputedValue, Context}; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; #[derive(Clone, Copy, PartialEq)] pub enum SpecifiedValue { @@ -2192,7 +2239,7 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { SpecifiedValue::Auto => dest.write_str("auto"), SpecifiedValue::Specified(l) => l.to_css(dest), @@ -2234,7 +2281,7 @@ pub mod longhands { <%self:longhand name="column-count" experimental="True"> use values::computed::{ToComputedValue, Context}; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; #[derive(Clone, Copy, PartialEq)] pub enum SpecifiedValue { @@ -2243,7 +2290,7 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { SpecifiedValue::Auto => dest.write_str("auto"), SpecifiedValue::Specified(count) => write!(dest, "{}", count), @@ -2276,10 +2323,9 @@ pub mod longhands { if input.try(|input| input.expect_ident_matching("auto")).is_ok() { Ok(SpecifiedValue::Auto) } else { - use std::u32; let count = try!(input.expect_integer()); // Zero is invalid - if count <= 0 || count > (u32::MAX as i64) { + if count <= 0 { return Err(()) } Ok(SpecifiedValue::Specified(count as u32)) @@ -2290,7 +2336,7 @@ pub mod longhands { <%self:longhand name="column-gap" experimental="True"> use values::computed::{ToComputedValue, Context}; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; #[derive(Clone, Copy, PartialEq)] pub enum SpecifiedValue { @@ -2299,7 +2345,7 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { SpecifiedValue::Normal => dest.write_str("normal"), SpecifiedValue::Specified(l) => l.to_css(dest), @@ -2345,10 +2391,10 @@ pub mod longhands { use values::CSSFloat; use values::computed::{ToComputedValue, Context}; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self.0.to_css(dest) } } @@ -2385,10 +2431,11 @@ pub mod longhands { <%self:longhand name="box-shadow"> use cssparser::{self, ToCss}; - use text_writer::{self, TextWriter}; + use std::fmt; use values::computed::{ToComputedValue, Context}; - pub type SpecifiedValue = Vec<SpecifiedBoxShadow>; + #[derive(Clone, PartialEq)] + pub struct SpecifiedValue(Vec<SpecifiedBoxShadow>); #[derive(Clone, PartialEq)] pub struct SpecifiedBoxShadow { @@ -2400,9 +2447,9 @@ pub mod longhands { pub inset: bool, } - impl ToCss for Vec<SpecifiedBoxShadow> { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { - let mut iter = self.iter(); + impl ToCss for SpecifiedValue { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + let mut iter = self.0.iter(); if let Some(shadow) = iter.next() { try!(shadow.to_css(dest)); } else { @@ -2418,7 +2465,7 @@ pub mod longhands { } impl ToCss for SpecifiedBoxShadow { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { if self.inset { try!(dest.write_str("inset ")); } @@ -2474,9 +2521,9 @@ pub mod longhands { pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> { if input.try(|input| input.expect_ident_matching("none")).is_ok() { - Ok(Vec::new()) + Ok(SpecifiedValue(Vec::new())) } else { - input.parse_comma_separated(parse_one_box_shadow) + input.parse_comma_separated(parse_one_box_shadow).map(SpecifiedValue) } } @@ -2485,7 +2532,7 @@ pub mod longhands { #[inline] fn to_computed_value(&self, context: &Context) -> computed_value::T { - self.iter().map(|value| compute_one_box_shadow(value, context)).collect() + self.0.iter().map(|value| compute_one_box_shadow(value, context)).collect() } } @@ -2567,7 +2614,7 @@ pub mod longhands { <%self:longhand name="clip"> use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; // NB: `top` and `left` are 0 if `auto` per CSS 2.1 11.1.2. @@ -2595,10 +2642,11 @@ pub mod longhands { pub left: specified::Length, } - pub type SpecifiedValue = Option<SpecifiedClipRect>; + #[derive(Clone, Debug, PartialEq, Copy)] + pub struct SpecifiedValue(Option<SpecifiedClipRect>); impl ToCss for SpecifiedClipRect { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(dest.write_str("rect(")); try!(self.top.to_css(dest)); @@ -2625,9 +2673,9 @@ pub mod longhands { } } - impl ToCss for Option<SpecifiedClipRect> { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { - if let Some(ref rect) = *self { + impl ToCss for SpecifiedValue { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + if let Some(ref rect) = self.0 { rect.to_css(dest) } else { dest.write_str("auto") @@ -2645,7 +2693,7 @@ pub mod longhands { #[inline] fn to_computed_value(&self, context: &Context) -> computed_value::T { - self.map(|value| computed_value::ClipRect { + self.0.map(|value| computed_value::ClipRect { top: value.top.to_computed_value(context), right: value.right.map(|right| right.to_computed_value(context)), bottom: value.bottom.map(|bottom| bottom.to_computed_value(context)), @@ -2660,7 +2708,7 @@ pub mod longhands { use values::specified::Length; if input.try(|input| input.expect_ident_matching("auto")).is_ok() { - return Ok(None) + return Ok(SpecifiedValue(None)) } if !try!(input.expect_function()).eq_ignore_ascii_case("rect") { return Err(()) @@ -2675,12 +2723,12 @@ pub mod longhands { }) })); if sides.len() == 4 { - Ok(Some(SpecifiedClipRect { + Ok(SpecifiedValue(Some(SpecifiedClipRect { top: sides[0].unwrap_or(Length::Absolute(Au(0))), right: sides[1], bottom: sides[2], left: sides[3].unwrap_or(Length::Absolute(Au(0))), - })) + }))) } else { Err(()) } @@ -2690,7 +2738,6 @@ pub mod longhands { <%self:longhand name="text-shadow"> use cssparser::{self, ToCss}; use std::fmt; - use text_writer::{self, TextWriter}; use values::computed::{Context, ToComputedValue}; @@ -2736,7 +2783,7 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { let mut iter = self.0.iter(); if let Some(shadow) = iter.next() { try!(shadow.to_css(dest)); @@ -2753,7 +2800,7 @@ pub mod longhands { } impl ToCss for SpecifiedTextShadow { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.offset_x.to_css(dest)); try!(dest.write_str(" ")); try!(self.offset_y.to_css(dest)); @@ -2859,7 +2906,7 @@ pub mod longhands { use values::specified::{Angle, Length}; use values::CSSFloat; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; #[derive(Clone, PartialEq)] pub struct SpecifiedValue(Vec<SpecifiedFilter>); @@ -2937,7 +2984,7 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { let mut iter = self.0.iter(); if let Some(filter) = iter.next() { try!(filter.to_css(dest)); @@ -2954,7 +3001,7 @@ pub mod longhands { } impl ToCss for SpecifiedFilter { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { SpecifiedFilter::Blur(value) => { try!(dest.write_str("blur(")); @@ -3047,16 +3094,15 @@ pub mod longhands { use values::computed::{ToComputedValue, Context}; use cssparser::ToCss; - use std::f64; + use std::f32; use std::ops::Mul; - use text_writer::{self, TextWriter}; + use std::fmt; use util::geometry::Au; pub mod computed_value { use values::CSSFloat; use values::computed; - use std::num::Float; use std::ops::Mul; #[derive(Clone, Copy, Debug, PartialEq)] @@ -3148,8 +3194,8 @@ pub mod longhands { m31: specified::LengthAndPercentage, m32: specified::LengthAndPercentage, } - impl ToCss for Option<SpecifiedMatrix> { - fn to_css<W>(&self, _: &mut W) -> text_writer::Result where W: TextWriter { + impl ToCss for SpecifiedMatrix { + fn to_css<W>(&self, _: &mut W) -> fmt::Result where W: fmt::Write { // TODO(pcwalton) Ok(()) } @@ -3217,7 +3263,7 @@ pub mod longhands { } impl ToCss for SpecifiedOperation { - fn to_css<W>(&self, _: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, _: &mut W) -> fmt::Result where W: fmt::Write { // TODO(pcwalton) Ok(()) } @@ -3227,7 +3273,7 @@ pub mod longhands { pub struct SpecifiedValue(Vec<SpecifiedOperation>); impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { let mut first = true; for operation in self.0.iter() { if !first { @@ -3267,8 +3313,8 @@ pub mod longhands { return Err(()) } let (tx, ty) = - (specified::Length::Absolute(Au::from_frac_px(values[4])), - specified::Length::Absolute(Au::from_frac_px(values[5]))); + (specified::Length::Absolute(Au::from_frac32_px(values[4])), + specified::Length::Absolute(Au::from_frac32_px(values[5]))); let (tx, ty) = (specified::LengthAndPercentage::from_length(tx), specified::LengthAndPercentage::from_length(ty)); @@ -3394,7 +3440,7 @@ pub mod longhands { result.scale(sx, sy) } SpecifiedOperation::Rotate(ref theta) => { - result.rotate(f64::consts::PI_2 - theta.radians()); + result.rotate(f32::consts::PI_2 - theta.radians()); } SpecifiedOperation::Skew(sx, sy) => { result.skew(sx, sy) @@ -3411,7 +3457,7 @@ pub mod longhands { use values::specified::LengthOrPercentage; use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; pub mod computed_value { use values::computed::LengthOrPercentage; @@ -3430,7 +3476,7 @@ pub mod longhands { } impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.horizontal.to_css(dest)); try!(dest.write_str(" ")); self.vertical.to_css(dest) @@ -3534,7 +3580,7 @@ pub mod longhands { pub mod computed_value { use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; #[derive(Copy, Clone, Debug, PartialEq)] pub enum T { @@ -3544,7 +3590,7 @@ pub mod longhands { } impl ToCss for T { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { T::Auto => dest.write_str("auto"), T::CrispEdges => dest.write_str("crisp-edges"), @@ -3596,7 +3642,7 @@ pub mod longhands { pub mod computed_value { use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; use values::computed::{Context, ToComputedValue}; pub use values::computed::Time as SingleComputedValue; @@ -3614,7 +3660,7 @@ pub mod longhands { } impl ToCss for T { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { if self.0.is_empty() { return dest.write_str("none") } @@ -3704,18 +3750,18 @@ pub mod longhands { pub mod computed_value { use cssparser::ToCss; use geom::point::Point2D; - use text_writer::{self, TextWriter}; + use std::fmt; pub use self::TransitionTimingFunction as SingleComputedValue; #[derive(Copy, Clone, Debug, PartialEq)] pub enum TransitionTimingFunction { - CubicBezier(Point2D<f64>, Point2D<f64>), + CubicBezier(Point2D<f32>, Point2D<f32>), Steps(u32, StartEnd), } impl ToCss for TransitionTimingFunction { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { TransitionTimingFunction::CubicBezier(p1, p2) => { try!(dest.write_str("cubic-bezier(")); @@ -3746,7 +3792,7 @@ pub mod longhands { } impl ToCss for StartEnd { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { StartEnd::Start => dest.write_str("start"), StartEnd::End => dest.write_str("end"), @@ -3758,7 +3804,7 @@ pub mod longhands { pub struct T(pub Vec<TransitionTimingFunction>); impl ToCss for T { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { if self.0.is_empty() { return dest.write_str("none") } @@ -3857,7 +3903,7 @@ pub mod longhands { pub mod computed_value { use cssparser::ToCss; - use text_writer::{self, TextWriter}; + use std::fmt; pub use self::TransitionProperty as SingleComputedValue; @@ -3958,7 +4004,7 @@ pub mod longhands { ]; impl ToCss for TransitionProperty { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { TransitionProperty::All => dest.write_str("all"), TransitionProperty::BackgroundColor => dest.write_str("background-color"), @@ -4013,7 +4059,7 @@ pub mod longhands { pub struct T(pub Vec<SingleComputedValue>); impl ToCss for T { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { if self.0.is_empty() { return dest.write_str("none") } @@ -4500,7 +4546,7 @@ pub mod shorthands { font_weight: weight, font_size: size, line_height: line_height, - font_family: Some(family) + font_family: Some(font_family::SpecifiedValue(family)) }) </%self:shorthand> diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs index 6511f8c5772..211ae3dbe56 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -8,9 +8,9 @@ use selectors::bloom::BloomFilter; use selectors::matching::{SelectorMap, Rule}; use selectors::matching::DeclarationBlock as GenericDeclarationBlock; use selectors::parser::PseudoElement; -use selectors::smallvec::VecLike; use selectors::tree::TNode; use util::resource_files::read_resource_file; +use util::smallvec::VecLike; use legacy::PresentationalHintSynthesis; use media_queries::Device; @@ -213,7 +213,7 @@ impl Stylist { // Step 4: Normal style attributes. style_attribute.map(|sa| { shareable = false; - applicable_declarations.vec_push( + applicable_declarations.push( GenericDeclarationBlock::from_declarations(sa.normal.clone())) }); @@ -226,7 +226,7 @@ impl Stylist { // Step 6: `!important` style attributes. style_attribute.map(|sa| { shareable = false; - applicable_declarations.vec_push( + applicable_declarations.push( GenericDeclarationBlock::from_declarations(sa.important.clone())) }); diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index b910d3fe62a..90f4a7510df 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -18,7 +18,7 @@ use parser::{ParserContext, log_css_error}; use properties::{PropertyDeclarationBlock, parse_property_declaration_list}; use media_queries::{Device, MediaQueryList, parse_media_query_list}; use font_face::{FontFaceRule, parse_font_face_block}; -use util::smallvec::{SmallVec, SmallVec2}; +use util::smallvec::SmallVec2; /// Each style rule has an origin, which determines where it enters the cascade. @@ -178,7 +178,7 @@ impl<'a> Iterator for Rules<'a> { fn next(&mut self) -> Option<&'a CSSRule> { while !self.stack.is_empty() { let top = self.stack.len() - 1; - while let Some(rule) = self.stack.get_mut(top).next() { + while let Some(rule) = self.stack[top].next() { // handle conditional group rules match rule { &CSSRule::Media(ref rule) => { diff --git a/components/style/values.rs b/components/style/values.rs index 12614a0bddc..185bfd7280a 100644 --- a/components/style/values.rs +++ b/components/style/values.rs @@ -12,7 +12,7 @@ macro_rules! define_css_keyword_enum { }; ($name: ident: $( $css: expr => $variant: ident ),+) => { #[allow(non_camel_case_types)] - #[derive(Clone, Eq, PartialEq, FromPrimitive, Copy, Hash, RustcEncodable)] + #[derive(Clone, Eq, PartialEq, Copy, Hash, RustcEncodable, Debug)] pub enum $name { $( $variant ),+ } @@ -26,17 +26,9 @@ macro_rules! define_css_keyword_enum { } } - impl ::std::fmt::Debug for $name { - #[inline] - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - use cssparser::ToCss; - self.fmt_to_css(f) - } - } - impl ::cssparser::ToCss for $name { - fn to_css<W>(&self, dest: &mut W) -> ::text_writer::Result - where W: ::text_writer::TextWriter { + fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result + where W: ::std::fmt::Write { match self { $( &$name::$variant => dest.write_str($css) ),+ } @@ -51,7 +43,7 @@ macro_rules! define_numbered_css_keyword_enum { }; ($name: ident: $( $css: expr => $variant: ident = $value: expr ),+) => { #[allow(non_camel_case_types)] - #[derive(Clone, Eq, PartialEq, PartialOrd, Ord, FromPrimitive, Copy, RustcEncodable)] + #[derive(Clone, Eq, PartialEq, PartialOrd, Ord, Copy, RustcEncodable, Debug)] pub enum $name { $( $variant = $value ),+ } @@ -65,17 +57,9 @@ macro_rules! define_numbered_css_keyword_enum { } } - impl ::std::fmt::Debug for $name { - #[inline] - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - use cssparser::ToCss; - self.fmt_to_css(f) - } - } - impl ::cssparser::ToCss for $name { - fn to_css<W>(&self, dest: &mut W) -> ::text_writer::Result - where W: ::text_writer::TextWriter { + fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result + where W: ::std::fmt::Write { match self { $( &$name::$variant => dest.write_str($css) ),+ } @@ -85,26 +69,24 @@ macro_rules! define_numbered_css_keyword_enum { } -pub type CSSFloat = f64; +pub type CSSFloat = f32; pub mod specified { use std::ascii::AsciiExt; use std::cmp; - use std::f64::consts::PI; + use std::f32::consts::PI; use std::fmt; - use std::fmt::{Formatter, Debug}; - use std::num::{NumCast, ToPrimitive}; + use std::fmt::Write; use std::ops::{Add, Mul}; use url::Url; use cssparser::{self, Token, Parser, ToCss, CssStringWriter}; use geom::size::Size2D; use parser::ParserContext; - use text_writer::{self, TextWriter}; use util::geometry::Au; use super::CSSFloat; - #[derive(Clone, PartialEq)] + #[derive(Clone, PartialEq, Debug)] pub struct CSSColor { pub parsed: cssparser::Color, pub authored: Option<String>, @@ -124,12 +106,8 @@ pub mod specified { } } - impl fmt::Debug for CSSColor { - #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_to_css(f) } - } - impl ToCss for CSSColor { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self.authored { Some(ref s) => dest.write_str(s), None => self.parsed.to_css(dest), @@ -137,17 +115,14 @@ pub mod specified { } } - #[derive(Clone, PartialEq)] + #[derive(Clone, PartialEq, Debug)] pub struct CSSRGBA { pub parsed: cssparser::RGBA, pub authored: Option<String>, } - impl fmt::Debug for CSSRGBA { - #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_to_css(f) } - } impl ToCss for CSSRGBA { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self.authored { Some(ref s) => dest.write_str(s), None => self.parsed.to_css(dest), @@ -155,19 +130,15 @@ pub mod specified { } } - #[derive(Clone, PartialEq, Copy)] + #[derive(Clone, PartialEq, Copy, Debug)] pub enum FontRelativeLength { Em(CSSFloat), Ex(CSSFloat), Rem(CSSFloat) } - impl fmt::Debug for FontRelativeLength { - #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_to_css(f) } - } - impl ToCss for FontRelativeLength { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { &FontRelativeLength::Em(length) => write!(dest, "{}em", length), &FontRelativeLength::Ex(length) => write!(dest, "{}ex", length), @@ -193,7 +164,7 @@ pub mod specified { } } - #[derive(Clone, PartialEq, Copy)] + #[derive(Clone, PartialEq, Copy, Debug)] pub enum ViewportPercentageLength { Vw(CSSFloat), Vh(CSSFloat), @@ -201,12 +172,8 @@ pub mod specified { Vmax(CSSFloat) } - impl fmt::Debug for ViewportPercentageLength { - #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_to_css(f) } - } - impl ToCss for ViewportPercentageLength { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { &ViewportPercentageLength::Vw(length) => write!(dest, "{}vw", length), &ViewportPercentageLength::Vh(length) => write!(dest, "{}vh", length), @@ -220,7 +187,7 @@ pub mod specified { pub fn to_computed_value(&self, viewport_size: Size2D<Au>) -> Au { macro_rules! to_unit { ($viewport_dimension:expr) => { - $viewport_dimension.to_f64().unwrap() / 100.0 + $viewport_dimension.to_frac32_px() / 100.0 } } @@ -234,11 +201,11 @@ pub mod specified { &ViewportPercentageLength::Vmax(length) => length * to_unit!(cmp::max(viewport_size.width, viewport_size.height)), }; - NumCast::from(value).unwrap() + Au::from_frac32_px(value) } } - #[derive(Clone, PartialEq, Copy)] + #[derive(Clone, PartialEq, Copy, Debug)] pub struct CharacterWidth(pub i32); impl CharacterWidth { @@ -253,7 +220,7 @@ pub mod specified { } } - #[derive(Clone, PartialEq, Copy)] + #[derive(Clone, PartialEq, Copy, Debug)] pub enum Length { Absolute(Au), // application units FontRelative(FontRelativeLength), @@ -266,14 +233,10 @@ pub mod specified { ServoCharacterWidth(CharacterWidth), } - impl fmt::Debug for Length { - #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_to_css(f) } - } - impl ToCss for Length { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { - &Length::Absolute(length) => write!(dest, "{}px", length.to_subpx()), + &Length::Absolute(length) => write!(dest, "{}px", length.to_frac32_px()), &Length::FontRelative(length) => length.to_css(dest), &Length::ViewportPercentage(length) => length.to_css(dest), &Length::ServoCharacterWidth(_) @@ -288,7 +251,7 @@ pub mod specified { #[inline] fn mul(self, scalar: CSSFloat) -> Length { match self { - Length::Absolute(Au(v)) => Length::Absolute(Au(((v as f64) * scalar) as i32)), + Length::Absolute(Au(v)) => Length::Absolute(Au(((v as f32) * scalar) as i32)), Length::FontRelative(v) => Length::FontRelative(v * scalar), Length::ViewportPercentage(v) => Length::ViewportPercentage(v * scalar), Length::ServoCharacterWidth(_) => panic!("Can't multiply ServoCharacterWidth!"), @@ -374,18 +337,14 @@ pub mod specified { } - #[derive(Clone, PartialEq, Copy)] + #[derive(Clone, PartialEq, Copy, Debug)] pub enum LengthOrPercentage { Length(Length), Percentage(CSSFloat), // [0 .. 100%] maps to [0.0 .. 1.0] } - impl fmt::Debug for LengthOrPercentage { - #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_to_css(f) } - } - impl ToCss for LengthOrPercentage { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { &LengthOrPercentage::Length(length) => length.to_css(dest), &LengthOrPercentage::Percentage(percentage) @@ -421,19 +380,15 @@ pub mod specified { } } - #[derive(Clone, PartialEq, Copy)] + #[derive(Clone, PartialEq, Copy, Debug)] pub enum LengthOrPercentageOrAuto { Length(Length), Percentage(CSSFloat), // [0 .. 100%] maps to [0.0 .. 1.0] Auto, } - impl fmt::Debug for LengthOrPercentageOrAuto { - #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_to_css(f) } - } - impl ToCss for LengthOrPercentageOrAuto { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { &LengthOrPercentageOrAuto::Length(length) => length.to_css(dest), &LengthOrPercentageOrAuto::Percentage(percentage) @@ -472,19 +427,15 @@ pub mod specified { } } - #[derive(Clone, PartialEq, Copy)] + #[derive(Clone, PartialEq, Copy, Debug)] pub enum LengthOrPercentageOrNone { Length(Length), Percentage(CSSFloat), // [0 .. 100%] maps to [0.0 .. 1.0] None, } - impl fmt::Debug for LengthOrPercentageOrNone { - #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_to_css(f) } - } - impl ToCss for LengthOrPercentageOrNone { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { &LengthOrPercentageOrNone::Length(length) => length.to_css(dest), &LengthOrPercentageOrNone::Percentage(percentage) @@ -580,7 +531,7 @@ pub mod specified { fn add(self, other: LengthAndPercentage) -> LengthAndPercentage { let mut new_lengths = self.lengths.clone(); - new_lengths.push_all(other.lengths.as_slice()); + new_lengths.push_all(&other.lengths); LengthAndPercentage { lengths: new_lengths, percentage: self.percentage + other.percentage, @@ -650,22 +601,18 @@ pub mod specified { } } - #[derive(Clone, PartialEq, PartialOrd, Copy)] + #[derive(Clone, PartialEq, PartialOrd, Copy, Debug)] pub struct Angle(pub CSSFloat); - impl fmt::Debug for Angle { - #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_to_css(f) } - } - impl ToCss for Angle { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { let Angle(value) = *self; write!(dest, "{}rad", value) } } impl Angle { - pub fn radians(self) -> f64 { + pub fn radians(self) -> f32 { let Angle(radians) = self; radians } @@ -695,18 +642,14 @@ pub mod specified { } /// Specified values for an image according to CSS-IMAGES. - #[derive(Clone, PartialEq)] + #[derive(Clone, PartialEq, Debug)] pub enum Image { Url(Url), LinearGradient(LinearGradient), } - impl fmt::Debug for Image { - #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_to_css(f) } - } - impl ToCss for Image { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { &Image::Url(ref url) => { try!(dest.write_str("url(\"")); @@ -740,7 +683,7 @@ pub mod specified { } /// Specified values for a CSS linear gradient. - #[derive(Clone, PartialEq)] + #[derive(Clone, PartialEq, Debug)] pub struct LinearGradient { /// The angle or corner of the gradient. pub angle_or_corner: AngleOrCorner, @@ -749,42 +692,34 @@ pub mod specified { pub stops: Vec<ColorStop>, } - impl fmt::Debug for LinearGradient { - #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_to_css(f) } - } - impl ToCss for LinearGradient { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(dest.write_str("linear-gradient(")); try!(self.angle_or_corner.to_css(dest)); for stop in self.stops.iter() { try!(dest.write_str(", ")); try!(stop.to_css(dest)); } - try!(dest.write_char(')')); + try!(dest.write_str(")")); Ok(()) } } /// Specified values for an angle or a corner in a linear gradient. - #[derive(Clone, PartialEq, Copy)] + #[derive(Clone, PartialEq, Copy, Debug)] pub enum AngleOrCorner { Angle(Angle), Corner(HorizontalDirection, VerticalDirection), } - impl fmt::Debug for AngleOrCorner { - #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_to_css(f) } - } - impl ToCss for AngleOrCorner { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { &AngleOrCorner::Angle(angle) => angle.to_css(dest), &AngleOrCorner::Corner(horizontal, vertical) => { try!(dest.write_str("to ")); try!(horizontal.to_css(dest)); - try!(dest.write_char(' ')); + try!(dest.write_str(" ")); try!(vertical.to_css(dest)); Ok(()) } @@ -793,7 +728,7 @@ pub mod specified { } /// Specified values for one color stop in a linear gradient. - #[derive(Clone, PartialEq)] + #[derive(Clone, PartialEq, Debug)] pub struct ColorStop { /// The color of this stop. pub color: CSSColor, @@ -803,15 +738,11 @@ pub mod specified { pub position: Option<LengthOrPercentage>, } - impl fmt::Debug for ColorStop { - #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_to_css(f) } - } - impl ToCss for ColorStop { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.color.to_css(dest)); if let Some(position) = self.position { - try!(dest.write_char(' ')); + try!(dest.write_str(" ")); try!(position.to_css(dest)); } Ok(()) @@ -909,7 +840,7 @@ pub mod specified { impl Time { /// Returns the time in fractional seconds. - pub fn seconds(self) -> f64 { + pub fn seconds(self) -> f32 { let Time(seconds) = self; seconds } @@ -945,8 +876,8 @@ pub mod specified { } impl ToCss for Time { - fn to_css<W>(&self, dest: &mut W) -> text_writer::Result where W: TextWriter { - dest.write_str(format!("{}ms", self.0).as_slice()) + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + write!(dest, "{}ms", self.0) } } } @@ -959,7 +890,6 @@ pub mod computed { use geom::size::Size2D; use properties::longhands; use std::fmt; - use std::marker::MarkerTrait; use std::ops::{Add, Mul}; use url::Url; use util::geometry::Au; @@ -995,7 +925,7 @@ pub mod computed { fn to_computed_value(&self, _context: &Context) -> Self::ComputedValue; } - pub trait ComputedValueAsSpecified: MarkerTrait {} + pub trait ComputedValueAsSpecified {} impl<T> ToComputedValue for T where T: ComputedValueAsSpecified + Clone { type ComputedValue = T; @@ -1184,7 +1114,7 @@ pub mod computed { fn mul(self, scalar: CSSFloat) -> LengthAndPercentage { LengthAndPercentage { - length: Au::from_frac_px(self.length.to_subpx() * scalar), + length: Au::from_frac32_px(self.length.to_frac32_px() * scalar), percentage: self.percentage * scalar, } } |