Split Au type into separate crate, with minimal dependencies.

This commit is contained in:
Glenn Watson 2015-09-28 16:53:00 +10:00
parent fb6d0946cb
commit 339a3f869b
72 changed files with 376 additions and 235 deletions

View file

@ -30,6 +30,9 @@ features = [ "serde-serialization" ]
version = "0.2"
features = [ "serde_serialization" ]
[dependencies.app_units]
path = "../app_units"
[dependencies]
log = "0.3"
encoding = "0.2"

View file

@ -2,6 +2,7 @@
* 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/. */
use app_units::Au;
use cssparser::{Color, RGBA};
use euclid::point::Point2D;
use properties::ComputedValues;
@ -25,7 +26,6 @@ use properties::longhands::z_index::computed_value::T as ZIndex;
use std::cmp::Ordering;
use std::iter::repeat;
use util::bezier::Bezier;
use util::geometry::Au;
use values::CSSFloat;
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
use values::computed::{Calc, Length, LengthOrPercentage, Time};

View file

@ -16,6 +16,7 @@
#![plugin(serde_macros)]
#![plugin(plugins)]
extern crate app_units;
#[macro_use]
extern crate bitflags;
#[macro_use]

View file

@ -2,11 +2,12 @@
* 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/. */
use app_units::Au;
use cssparser::{Delimiter, Parser, Token};
use euclid::size::{Size2D, TypedSize2D};
use properties::longhands;
use std::ascii::AsciiExt;
use util::geometry::{Au, ViewportPx};
use util::geometry::ViewportPx;
use values::specified;

View file

@ -14,10 +14,10 @@ use std::intrinsics;
use std::mem;
use std::sync::Arc;
use app_units::Au;
use cssparser::{Parser, Color, RGBA, AtRuleParser, DeclarationParser,
DeclarationListParser, parse_important, ToCss, TokenSerializationType};
use url::Url;
use util::geometry::Au;
use util::logical_geometry::{LogicalMargin, PhysicalSide, WritingMode};
use euclid::SideOffsets2D;
use euclid::size::Size2D;
@ -28,6 +28,7 @@ use computed_values;
use parser::{ParserContext, log_css_error};
use selectors::matching::DeclarationBlock;
use stylesheets::Origin;
use values::AuExtensionMethods;
use values::computed::{self, ToComputedValue};
use values::specified::{Length, BorderStyle};
@ -274,7 +275,7 @@ pub mod longhands {
<%def name="predefined_type(name, type, initial_value, parse_method='parse')">
<%self:longhand name="${name}">
#[allow(unused_imports)]
use util::geometry::Au;
use app_units::Au;
pub type SpecifiedValue = specified::${type};
pub mod computed_value {
pub use values::computed::${type} as T;
@ -317,9 +318,9 @@ pub mod longhands {
% for side in ["top", "right", "bottom", "left"]:
<%self:longhand name="border-${side}-width">
use app_units::Au;
use cssparser::ToCss;
use std::fmt;
use util::geometry::Au;
use values::computed::Context;
impl ToCss for SpecifiedValue {
@ -336,7 +337,7 @@ pub mod longhands {
#[derive(Clone, PartialEq)]
pub struct SpecifiedValue(pub specified::Length);
pub mod computed_value {
use util::geometry::Au;
use app_units::Au;
pub type T = Au;
}
#[inline] pub fn get_initial_value() -> computed_value::T {
@ -385,9 +386,10 @@ pub mod longhands {
</%self:longhand>
<%self:longhand name="outline-width">
use app_units::Au;
use cssparser::ToCss;
use std::fmt;
use util::geometry::Au;
use values::AuExtensionMethods;
use values::computed::Context;
impl ToCss for SpecifiedValue {
@ -402,7 +404,7 @@ pub mod longhands {
#[derive(Clone, PartialEq)]
pub struct SpecifiedValue(pub specified::Length);
pub mod computed_value {
use util::geometry::Au;
use app_units::Au;
pub type T = Au;
}
pub use super::border_top_width::get_initial_value;
@ -649,6 +651,7 @@ pub mod longhands {
<%self:longhand name="line-height">
use cssparser::ToCss;
use std::fmt;
use values::AuExtensionMethods;
use values::CSSFloat;
use values::computed::Context;
@ -692,8 +695,8 @@ pub mod longhands {
}
}
pub mod computed_value {
use app_units::Au;
use std::fmt;
use util::geometry::Au;
use values::CSSFloat;
#[derive(PartialEq, Copy, Clone, HeapSizeOf)]
pub enum T {
@ -791,8 +794,9 @@ pub mod longhands {
})
}
pub mod computed_value {
use app_units::Au;
use std::fmt;
use util::geometry::Au;
use values::AuExtensionMethods;
use values::{CSSFloat, computed};
#[allow(non_camel_case_types)]
#[derive(PartialEq, Copy, Clone, HeapSizeOf)]
@ -1397,6 +1401,7 @@ pub mod longhands {
<%self:longhand name="background-position">
use cssparser::ToCss;
use std::fmt;
use values::AuExtensionMethods;
use values::computed::Context;
pub mod computed_value {
@ -1911,9 +1916,9 @@ pub mod longhands {
</%self:longhand>
<%self:longhand name="font-size">
use app_units::Au;
use cssparser::ToCss;
use std::fmt;
use util::geometry::Au;
use values::computed::Context;
impl ToCss for SpecifiedValue {
@ -1925,7 +1930,7 @@ pub mod longhands {
#[derive(Clone, PartialEq)]
pub struct SpecifiedValue(pub specified::Length); // Percentages are the same as em.
pub mod computed_value {
use util::geometry::Au;
use app_units::Au;
pub type T = Au;
}
const MEDIUM_PX: i32 = 16;
@ -2034,6 +2039,7 @@ pub mod longhands {
<%self:longhand name="letter-spacing">
use cssparser::ToCss;
use std::fmt;
use values::AuExtensionMethods;
use values::computed::Context;
#[derive(Clone, Copy, PartialEq)]
@ -2052,7 +2058,7 @@ pub mod longhands {
}
pub mod computed_value {
use util::geometry::Au;
use app_units::Au;
#[derive(Clone, PartialEq, HeapSizeOf)]
pub struct T(pub Option<Au>);
}
@ -2096,6 +2102,7 @@ pub mod longhands {
<%self:longhand name="word-spacing">
use cssparser::ToCss;
use std::fmt;
use values::AuExtensionMethods;
use values::computed::Context;
#[derive(Clone, Copy, PartialEq)]
@ -2114,7 +2121,7 @@ pub mod longhands {
}
pub mod computed_value {
use util::geometry::Au;
use app_units::Au;
#[derive(Clone, PartialEq, HeapSizeOf)]
pub struct T(pub Option<Au>);
}
@ -2372,14 +2379,15 @@ pub mod longhands {
${single_keyword("caption-side", "top bottom")}
<%self:longhand name="border-spacing">
use app_units::Au;
use values::AuExtensionMethods;
use values::computed::Context;
use cssparser::ToCss;
use std::fmt;
use util::geometry::Au;
pub mod computed_value {
use util::geometry::Au;
use app_units::Au;
#[derive(Clone, Copy, Debug, PartialEq, RustcEncodable, HeapSizeOf)]
pub struct T {
@ -2536,6 +2544,7 @@ pub mod longhands {
<%self:longhand name="column-width" experimental="True">
use cssparser::ToCss;
use std::fmt;
use values::AuExtensionMethods;
use values::computed::Context;
#[derive(Clone, Copy, PartialEq)]
@ -2554,7 +2563,7 @@ pub mod longhands {
}
pub mod computed_value {
use util::geometry::Au;
use app_units::Au;
#[derive(Clone, PartialEq, HeapSizeOf)]
pub struct T(pub Option<Au>);
}
@ -2664,6 +2673,7 @@ pub mod longhands {
<%self:longhand name="column-gap" experimental="True">
use cssparser::ToCss;
use std::fmt;
use values::AuExtensionMethods;
use values::computed::Context;
#[derive(Clone, Copy, PartialEq)]
@ -2682,7 +2692,7 @@ pub mod longhands {
}
pub mod computed_value {
use util::geometry::Au;
use app_units::Au;
#[derive(Clone, PartialEq, HeapSizeOf)]
pub struct T(pub Option<Au>);
}
@ -2771,6 +2781,7 @@ pub mod longhands {
<%self:longhand name="box-shadow">
use cssparser::{self, ToCss};
use std::fmt;
use values::AuExtensionMethods;
use values::computed::Context;
#[derive(Clone, PartialEq)]
@ -2825,8 +2836,8 @@ pub mod longhands {
}
pub mod computed_value {
use app_units::Au;
use std::fmt;
use util::geometry::Au;
use values::computed;
#[derive(Clone, PartialEq, HeapSizeOf)]
@ -2927,7 +2938,7 @@ pub mod longhands {
}
pub fn parse_one_box_shadow(input: &mut Parser) -> Result<SpecifiedBoxShadow, ()> {
use util::geometry::Au;
use app_units::Au;
let mut lengths = [specified::Length::Absolute(Au(0)); 4];
let mut lengths_parsed = false;
let mut color = None;
@ -2990,13 +3001,14 @@ pub mod longhands {
<%self:longhand name="clip">
use cssparser::ToCss;
use std::fmt;
use values::AuExtensionMethods;
// NB: `top` and `left` are 0 if `auto` per CSS 2.1 11.1.2.
use values::computed::Context;
pub mod computed_value {
use util::geometry::Au;
use app_units::Au;
#[derive(Clone, PartialEq, Eq, Copy, Debug, HeapSizeOf)]
pub struct ClipRect {
@ -3109,8 +3121,8 @@ pub mod longhands {
}
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
use app_units::Au;
use std::ascii::AsciiExt;
use util::geometry::Au;
use values::specified::Length;
if input.try(|input| input.expect_ident_matching("auto")).is_ok() {
@ -3144,7 +3156,7 @@ pub mod longhands {
<%self:longhand name="text-shadow">
use cssparser::{self, ToCss};
use std::fmt;
use values::AuExtensionMethods;
use values::computed::Context;
#[derive(Clone, PartialEq)]
@ -3173,8 +3185,8 @@ pub mod longhands {
}
pub mod computed_value {
use app_units::Au;
use cssparser::Color;
use util::geometry::Au;
#[derive(Clone, PartialEq, Debug, HeapSizeOf)]
pub struct T(pub Vec<TextShadow>);
@ -3265,7 +3277,7 @@ pub mod longhands {
}
fn parse_one_text_shadow(input: &mut Parser) -> Result<SpecifiedTextShadow,()> {
use util::geometry::Au;
use app_units::Au;
let mut lengths = [specified::Length::Absolute(Au(0)); 3];
let mut lengths_parsed = false;
let mut color = None;
@ -3338,6 +3350,7 @@ pub mod longhands {
//pub use self::computed_value::T as SpecifiedValue;
use cssparser::ToCss;
use std::fmt;
use values::AuExtensionMethods;
use values::CSSFloat;
use values::specified::{Angle, Length};
@ -3359,7 +3372,7 @@ pub mod longhands {
}
pub mod computed_value {
use util::geometry::Au;
use app_units::Au;
use values::CSSFloat;
use values::specified::{Angle};
@ -3566,12 +3579,12 @@ pub mod longhands {
</%self:longhand>
<%self:longhand name="transform">
use app_units::Au;
use values::CSSFloat;
use values::computed::Context;
use cssparser::ToCss;
use std::fmt;
use util::geometry::Au;
pub mod computed_value {
use values::CSSFloat;
@ -4109,12 +4122,13 @@ pub mod longhands {
${single_keyword("transform-style", "auto flat preserve-3d")}
<%self:longhand name="transform-origin">
use app_units::Au;
use values::AuExtensionMethods;
use values::computed::Context;
use values::specified::{Length, LengthOrPercentage, Percentage};
use cssparser::ToCss;
use std::fmt;
use util::geometry::Au;
pub mod computed_value {
use values::computed::{Length, LengthOrPercentage};
@ -5171,7 +5185,7 @@ pub mod shorthands {
'border-%s-radius' % (corner)
for corner in ['top-left', 'top-right', 'bottom-right', 'bottom-left']
)}">
use util::geometry::Au;
use app_units::Au;
use values::specified::{Length, LengthOrPercentage};
use values::specified::BorderRadiusSize;

View file

@ -4,6 +4,34 @@
pub use cssparser::RGBA;
use app_units::Au;
use std::fmt;
// This is a re-implementation of the ToCss trait in cssparser.
// It's done here because the app_units crate shouldn't depend
// on cssparser, and it's not possible to implement a trait when
// both the trait and the type are defined in different crates.
pub trait AuExtensionMethods {
/// Serialize `self` in CSS syntax, writing to `dest`.
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write;
/// Serialize `self` in CSS syntax and return a string.
///
/// (This is a convenience wrapper for `to_css` and probably should not be overridden.)
#[inline]
fn to_css_string(&self) -> String {
let mut s = String::new();
self.to_css(&mut s).unwrap();
s
}
}
impl AuExtensionMethods for Au {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
write!(dest, "{}px", self.to_f64_px())
}
}
macro_rules! define_numbered_css_keyword_enum {
($name: ident: $( $css: expr => $variant: ident = $value: expr ),+,) => {
define_numbered_css_keyword_enum!($name: $( $css => $variant = $value ),+);
@ -40,6 +68,7 @@ pub type CSSFloat = f32;
pub mod specified {
use app_units::Au;
use cssparser::{self, CssStringWriter, Parser, ToCss, Token};
use euclid::size::Size2D;
use parser::ParserContext;
@ -49,10 +78,9 @@ pub mod specified {
use std::fmt::{self, Write};
use std::ops::Mul;
use style_traits::values::specified::AllowedNumericType;
use super::AuExtensionMethods;
use super::CSSFloat;
use url::Url;
use util::geometry::Au;
#[derive(Clone, PartialEq, Debug, HeapSizeOf)]
pub struct CSSColor {
@ -1209,13 +1237,14 @@ pub mod specified {
}
pub mod computed {
use app_units::Au;
use euclid::size::Size2D;
use properties::longhands;
use std::fmt;
use super::AuExtensionMethods;
use super::specified::AngleOrCorner;
use super::{CSSFloat, specified};
use url::Url;
use util::geometry::Au;
pub use cssparser::Color as CSSColor;
pub use super::specified::{Angle, BorderStyle, Time};

View file

@ -2,6 +2,7 @@
* 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/. */
use app_units::Au;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, parse_important};
use euclid::scale_factor::ScaleFactor;
use euclid::size::{Size2D, TypedSize2D};
@ -12,7 +13,7 @@ use std::collections::hash_map::{Entry, HashMap};
use std::intrinsics;
use style_traits::viewport::{Orientation, UserZoom, ViewportConstraints, Zoom};
use stylesheets::Origin;
use util::geometry::{Au, ViewportPx};
use util::geometry::ViewportPx;
use values::computed::{Context, ToComputedValue};
use values::specified::LengthOrPercentageOrAuto;