From ada1da1073889e8a0955221817645c28ff384f82 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 29 Oct 2012 16:31:24 -0700 Subject: [PATCH] Move css::color, and css::value to rust-css --- src/rust-css | 2 +- src/servo/content/content_task.rs | 2 +- src/servo/css/color.rs | 292 ----------------- src/servo/css/lexer.rs | 14 +- src/servo/css/parser.rs | 6 +- src/servo/css/parser_util.rs | 4 +- src/servo/css/resolve/apply.rs | 2 +- src/servo/css/resolve/matching.rs | 2 +- src/servo/css/styles.rs | 8 +- src/servo/css/values.rs | 380 ----------------------- src/servo/dom/document.rs | 2 +- src/servo/dom/node.rs | 2 +- src/servo/html/hubbub_html_parser.rs | 2 +- src/servo/layout/block.rs | 2 +- src/servo/layout/box.rs | 8 +- src/servo/layout/box_builder.rs | 4 +- src/servo/layout/display_list_builder.rs | 2 +- src/servo/layout/inline.rs | 2 +- src/servo/layout/layout_task.rs | 2 +- src/servo/layout/root.rs | 2 +- src/servo/servo.rc | 3 - src/servo/text/text_run.rs | 2 +- 22 files changed, 35 insertions(+), 710 deletions(-) delete mode 100644 src/servo/css/color.rs delete mode 100644 src/servo/css/values.rs diff --git a/src/rust-css b/src/rust-css index 8b668287b7c..2a61c1cb0d1 160000 --- a/src/rust-css +++ b/src/rust-css @@ -1 +1 @@ -Subproject commit 8b668287b7c208abbd6e29f1413387e5cefe4491 +Subproject commit 2a61c1cb0d1878f238cd2e33377a254d29ff7f2e diff --git a/src/servo/content/content_task.rs b/src/servo/content/content_task.rs index 5b0432f2fcb..b32e1e6c5b4 100644 --- a/src/servo/content/content_task.rs +++ b/src/servo/content/content_task.rs @@ -23,7 +23,7 @@ use layout::layout_task; use layout_task::{LayoutTask, BuildMsg, BuildData}; use resource::image_cache_task::ImageCacheTask; -use css::values::Stylesheet; +use newcss::values::Stylesheet; use jsrt = js::rust::rt; use js::rust::{cx, methods}; diff --git a/src/servo/css/color.rs b/src/servo/css/color.rs deleted file mode 100644 index 37086b062ad..00000000000 --- a/src/servo/css/color.rs +++ /dev/null @@ -1,292 +0,0 @@ -use float::round; -use libc::types::os::arch::c95::c_double; -use css_colors::*; -use cmp::Eq; - -pub enum Color = {red : u8, green : u8, blue : u8, alpha : float}; - -impl Color : Eq { - pure fn eq(other: &Color) -> bool { - return self.red == other.red && self.green == other.green && self.blue == other.blue && - self.alpha == other.alpha; - } - pure fn ne(other: &Color) -> bool { - !self.eq(other) - } -} - -pub fn rgba(r : u8, g : u8, b : u8, a : float) -> Color { - Color({red : r, green : g, blue : b, alpha : a}) -} - -pub fn rgb(r : u8, g : u8, b : u8) -> Color { - return rgba(r, g, b, 1.0); -} - -pub fn hsla(h : float, s : float, l : float, a : float) -> Color { - // Algorithm for converting hsl to rbg taken from - // http://www.w3.org/TR/2003/CR-css3-color-20030514/#hsl-color - let m2 = if l <= 0.5 { l*(s + 1.0) } else { l + s - l*s }; - let m1 = l*2.0 - m2; - let h = h / 360.0; - - fn hue_to_rgb(m1 : float, m2 : float, h : float) -> float { - let h = if h < 0.0 { h + 1.0 } else if h > 1.0 { h - 1.0 } else { h }; - - match h { - 0.0 .. 1.0/6.0 => m1 + (m2 - m1)*h*6.0, - 1.0/6.0 .. 1.0/2.0 => m2, - 1.0/2.0 .. 2.0/3.0 => m1 + (m2 - m1)*(4.0 - 6.0*h), - 2.0/3.0 .. 1.0 => return m1, - _ => fail ~"unexpected hue value" - } - } - - let r = round(255.0*hue_to_rgb(m1, m2, h + 1.0/3.0) as c_double);; - let g = round(255.0*hue_to_rgb(m1, m2, h) as c_double); - let b = round(255.0*hue_to_rgb(m1, m2, h - 1.0/3.0) as c_double); - - return rgba(r as u8, g as u8, b as u8, a); -} - -pub fn hsl(h : float, s : float, l : float) -> Color { - return hsla(h, s, l, 1.0); -} - -impl Color { - fn print() -> ~str { - fmt!("rgba(%u,%u,%u,%f)", self.red as uint, self.green as uint, - self.blue as uint, self.alpha) - } -} - -mod parsing { - export parse_color; - - fn fail_unrecognized(col : &str) -> Option { - warn!("Unrecognized color %s", col); - return None; - } - - /** Match an exact color keyword. */ - fn parse_by_name(color : &str) -> Option { - let col = match color.to_lower() { - ~"black" => black(), - ~"silver" => silver(), - ~"gray" => gray(), - ~"grey" => gray(), - ~"white" => white(), - ~"maroon" => maroon(), - ~"red" => red(), - ~"purple" => purple(), - ~"fuchsia" => fuchsia(), - ~"green" => green(), - ~"lime" => lime(), - ~"olive" => olive(), - ~"yellow" => yellow(), - ~"navy" => navy(), - ~"blue" => blue(), - ~"teal" => teal(), - ~"aqua" => aqua(), - _ => return fail_unrecognized(color) - }; - - return Some(col); - } - - /** Parses a color specification in the form rgb(foo,bar,baz) */ - fn parse_rgb(color : &str) -> Option { - // Shave off the rgb( and the ) - let only_colors = color.substr(4u, color.len() - 5u); - - // split up r, g, and b - let cols = only_colors.split_char(','); - if cols.len() != 3u { return fail_unrecognized(color); } - - match (u8::from_str(cols[0]), u8::from_str(cols[1]), - u8::from_str(cols[2])) { - (Some(r), Some(g), Some(b)) => { Some(rgb(r, g, b)) } - _ => { fail_unrecognized(color) } - } - } - - /** Parses a color specification in the form rgba(foo,bar,baz,qux) */ - fn parse_rgba(color : &str) -> Option { - // Shave off the rgba( and the ) - let only_vals = color.substr(5u, color.len() - 6u); - - // split up r, g, and b - let cols = only_vals.split_char(','); - if cols.len() != 4u { return fail_unrecognized(color); } - - match (u8::from_str(cols[0]), u8::from_str(cols[1]), - u8::from_str(cols[2]), float::from_str(cols[3])) { - (Some(r), Some(g), Some(b), Some(a)) => { Some(rgba(r, g, b, a)) } - _ => { fail_unrecognized(color) } - } - } - - /** Parses a color specification in the form hsl(foo,bar,baz) */ - fn parse_hsl(color : &str) -> Option { - // Shave off the hsl( and the ) - let only_vals = color.substr(4u, color.len() - 5u); - - // split up h, s, and l - let vals = only_vals.split_char(','); - if vals.len() != 3u { return fail_unrecognized(color); } - - match (float::from_str(vals[0]), float::from_str(vals[1]), - float::from_str(vals[2])) { - (Some(h), Some(s), Some(l)) => { Some(hsl(h, s, l)) } - _ => { fail_unrecognized(color) } - } - } - - /** Parses a color specification in the form hsla(foo,bar,baz,qux) */ - fn parse_hsla(color : &str) -> Option { - // Shave off the hsla( and the ) - let only_vals = color.substr(5u, color.len() - 6u); - - let vals = only_vals.split_char(','); - if vals.len() != 4u { return fail_unrecognized(color); } - - match (float::from_str(vals[0]), float::from_str(vals[1]), - float::from_str(vals[2]), float::from_str(vals[3])) { - (Some(h), Some(s), Some(l), Some(a)) => { Some(hsla(h, s, l, a)) } - _ => { fail_unrecognized(color) } - } - } - - // Currently colors are supported in rgb(a,b,c) form and also by - // keywords for several common colors. - // TODO: extend this - fn parse_color(color : &str) -> Option { - match color { - c if c.starts_with("rgb(") => parse_rgb(c), - c if c.starts_with("rgba(") => parse_rgba(c), - c if c.starts_with("hsl(") => parse_hsl(c), - c if c.starts_with("hsla(") => parse_hsla(c), - c => parse_by_name(c) - } - } -} - -#[cfg(test)] -mod test { - use css_colors::*; - use option::unwrap; - use parsing::parse_color; - - #[test] - fn test_parse_by_name() { - assert red().eq(&unwrap(parse_color(~"red"))); - assert lime().eq(&unwrap(parse_color(~"Lime"))); - assert blue().eq(&unwrap(parse_color(~"BLUE"))); - assert green().eq(&unwrap(parse_color(~"GreEN"))); - assert white().eq(&unwrap(parse_color(~"white"))); - assert black().eq(&unwrap(parse_color(~"Black"))); - assert gray().eq(&unwrap(parse_color(~"Gray"))); - assert silver().eq(&unwrap(parse_color(~"SiLvEr"))); - assert maroon().eq(&unwrap(parse_color(~"maroon"))); - assert purple().eq(&unwrap(parse_color(~"PURPLE"))); - assert fuchsia().eq(&unwrap(parse_color(~"FUCHSIA"))); - assert olive().eq(&unwrap(parse_color(~"oLiVe"))); - assert yellow().eq(&unwrap(parse_color(~"yellow"))); - assert navy().eq(&unwrap(parse_color(~"NAVY"))); - assert teal().eq(&unwrap(parse_color(~"Teal"))); - assert aqua().eq(&unwrap(parse_color(~"Aqua"))); - assert None == parse_color(~"foobarbaz"); - } - - #[test] - fn test_parsing_rgb() { - assert red().eq(&unwrap(parse_color(~"rgb(255,0,0)"))); - assert red().eq(&unwrap(parse_color(~"rgba(255,0,0,1.0)"))); - assert red().eq(&unwrap(parse_color(~"rgba(255,0,0,1)"))); - assert lime().eq(&unwrap(parse_color(~"rgba(0,255,0,1.00)"))); - assert rgb(1u8,2u8,3u8).eq(&unwrap(parse_color(~"rgb(1,2,03)"))); - assert rgba(15u8,250u8,3u8,0.5).eq(&unwrap(parse_color(~"rgba(15,250,3,.5)"))); - assert rgba(15u8,250u8,3u8,0.5).eq(&unwrap(parse_color(~"rgba(15,250,3,0.5)"))); - assert None == parse_color(~"rbga(1,2,3)"); - } - - #[test] - fn test_parsing_hsl() { - assert red().eq(&unwrap(parse_color(~"hsl(0,1,.5)"))); - assert lime().eq(&unwrap(parse_color(~"hsl(120.0,1.0,.5)"))); - assert blue().eq(&unwrap(parse_color(~"hsl(240.0,1.0,.5)"))); - assert green().eq(&unwrap(parse_color(~"hsl(120.0,1.0,.25)"))); - assert white().eq(&unwrap(parse_color(~"hsl(1.0,1.,1.0)"))); - assert white().eq(&unwrap(parse_color(~"hsl(129.0,0.3,1.0)"))); - assert black().eq(&unwrap(parse_color(~"hsl(231.2,0.75,0.0)"))); - assert black().eq(&unwrap(parse_color(~"hsl(11.2,0.0,0.0)"))); - assert gray().eq(&unwrap(parse_color(~"hsl(0.0,0.0,0.5)"))); - assert maroon().eq(&unwrap(parse_color(~"hsl(0.0,1.0,0.25)"))); - assert purple().eq(&unwrap(parse_color(~"hsl(300.0,1.0,0.25)"))); - assert fuchsia().eq(&unwrap(parse_color(~"hsl(300,1.0,0.5)"))); - assert olive().eq(&unwrap(parse_color(~"hsl(60.,1.0,0.25)"))); - assert yellow().eq(&unwrap(parse_color(~"hsl(60.,1.0,0.5)"))); - assert navy().eq(&unwrap(parse_color(~"hsl(240.0,1.0,.25)"))); - assert teal().eq(&unwrap(parse_color(~"hsl(180.0,1.0,.25)"))); - assert aqua().eq(&unwrap(parse_color(~"hsl(180.0,1.0,.5)"))); - assert None == parse_color(~"hsl(1,2,3,.4)"); - } -} - - -/** Define the colors specified by css */ -mod css_colors { - // The 16 basic css colors - fn black() -> Color { - Color({red : 0u8, green : 0u8, blue : 0u8, alpha : 1.0}) - } - fn silver() -> Color { - Color({red : 192u8, green : 192u8, blue : 192u8, alpha : 1.0}) - } - fn gray() -> Color { - Color({red : 128u8, green : 128u8, blue : 128u8, alpha : 1.0}) - } - fn white() -> Color { - Color({red : 255u8, green : 255u8, blue : 255u8, alpha : 1.0}) - } - fn maroon() -> Color { - Color({red : 128u8, green : 0u8, blue : 0u8, alpha : 1.0}) - } - fn red() -> Color { - Color({red : 255u8, green : 0u8, blue : 0u8, alpha : 1.0}) - } - fn purple() -> Color { - Color({red : 128u8, green : 0u8, blue : 128u8, alpha : 1.0}) - } - fn fuchsia() -> Color { - Color({red : 255u8, green : 0u8, blue : 255u8, alpha : 1.0}) - } - fn green() -> Color { - Color({red : 0u8, green : 128u8, blue : 0u8, alpha : 1.0}) - } - fn lime() -> Color { - Color({red : 0u8, green : 255u8, blue : 0u8, alpha : 1.0}) - } - fn olive() -> Color { - Color({red : 128u8, green : 128u8, blue : 0u8, alpha : 1.0}) - } - fn yellow() -> Color { - Color({red : 255u8, green : 255u8, blue : 0u8, alpha : 1.0}) - } - fn navy() -> Color { - Color({red : 0u8, green : 0u8, blue : 128u8, alpha : 1.0}) - } - fn blue() -> Color { - Color({red : 0u8, green : 0u8, blue : 255u8, alpha : 1.0}) - } - fn teal() -> Color { - Color({red : 0u8, green : 128u8, blue : 128u8, alpha : 1.0}) - } - fn aqua() -> Color { - Color({red : 0u8, green : 255u8, blue : 255u8, alpha : 1.0}) - } - - - // The other 130 css colors - // TODO -} diff --git a/src/servo/css/lexer.rs b/src/servo/css/lexer.rs index 76c007d1de9..ecbc2bfa8ea 100644 --- a/src/servo/css/lexer.rs +++ b/src/servo/css/lexer.rs @@ -31,7 +31,7 @@ pub enum Token { Sibling, Comma, Element(~str), - Attr(css::values::Attr), + Attr(newcss::values::Attr), Description(~str, ~str), Eof } @@ -119,8 +119,8 @@ impl CssLexer : CssLexerMethods { } match ch { - '.' as u8 => return Attr(css::values::Includes(~"class", self.input_state.parse_ident())), - '#' as u8 => return Attr(css::values::Includes(~"id", self.input_state.parse_ident())), + '.' as u8 => return Attr(newcss::values::Includes(~"class", self.input_state.parse_ident())), + '#' as u8 => return Attr(newcss::values::Includes(~"id", self.input_state.parse_ident())), '[' as u8 => { let attr_name = self.input_state.parse_ident(); @@ -130,21 +130,21 @@ impl CssLexer : CssLexerMethods { } if ch == ']' as u8 { - return Attr(css::values::Exists(move attr_name)); + return Attr(newcss::values::Exists(move attr_name)); } else if ch == '=' as u8 { let attr_val = self.input_state.parse_ident(); self.input_state.expect(']' as u8); - return Attr(css::values::Exact(move attr_name, move attr_val)); + return Attr(newcss::values::Exact(move attr_name, move attr_val)); } else if ch == '~' as u8 { self.input_state.expect('=' as u8); let attr_val = self.input_state.parse_ident(); self.input_state.expect(']' as u8); - return Attr(css::values::Includes(move attr_name, move attr_val)); + return Attr(newcss::values::Includes(move attr_name, move attr_val)); } else if ch == '|' as u8 { self.input_state.expect('=' as u8); let attr_val = self.input_state.parse_ident(); self.input_state.expect(']' as u8); - return Attr(css::values::StartsWith(move attr_name, move attr_val)); + return Attr(newcss::values::StartsWith(move attr_name, move attr_val)); } fail #fmt("Unexpected symbol %c in attribute", ch as char); diff --git a/src/servo/css/parser.rs b/src/servo/css/parser.rs index 52e2be08775..ab84d52b1ed 100644 --- a/src/servo/css/parser.rs +++ b/src/servo/css/parser.rs @@ -5,16 +5,16 @@ Constructs a list of css style rules from a token stream // TODO: fail according to the css spec instead of failing when things // are not as expected -use css::values::*; +use newcss::values::*; // Disambiguate parsed Selector, Rule values from tokens -use css = css::values; +use css = newcss::values; use tok = lexer; use lexer::Token; use comm::recv; use option::{map, is_none}; use vec::push; use parser_util::*; -use color::parsing::parse_color; +use newcss::color::parsing::parse_color; use vec::push; type TokenReader = {stream : pipes::Port, mut lookahead : Option}; diff --git a/src/servo/css/parser_util.rs b/src/servo/css/parser_util.rs index 663fb7fdd2e..f012f401eb6 100644 --- a/src/servo/css/parser_util.rs +++ b/src/servo/css/parser_util.rs @@ -1,6 +1,6 @@ //! Helper functions to parse values of specific attributes -use css::values::*; +use newcss::values::*; use str::{pop_char, from_chars}; use float::from_str; use option::map; @@ -93,7 +93,7 @@ fn parse_display_type(str : &str) -> ParseResult { mod test { use css::lexer::spawn_css_lexer_from_string; use css::parser::build_stylesheet; - use css::values::{Stylesheet, Element, FontSize, Width, Height}; + use newcss::values::{Stylesheet, Element, FontSize, Width, Height}; // TODO: use helper methods to create test values diff --git a/src/servo/css/resolve/apply.rs b/src/servo/css/resolve/apply.rs index ad284b9f73e..0e4d3641e78 100644 --- a/src/servo/css/resolve/apply.rs +++ b/src/servo/css/resolve/apply.rs @@ -11,7 +11,7 @@ use image::ImageHolder; use resource::image_cache_task::ImageCacheTask; use std::net::url::Url; -use css::values::*; +use newcss::values::*; trait ResolveMethods { pure fn initial() -> T; diff --git a/src/servo/css/resolve/matching.rs b/src/servo/css/resolve/matching.rs index ead820fb886..c16f4f8a140 100644 --- a/src/servo/css/resolve/matching.rs +++ b/src/servo/css/resolve/matching.rs @@ -5,7 +5,7 @@ use dom::node::{LayoutData, Node, Text}; use dom::element::ElementData; -use values::*; +use newcss::values::*; use styles::{SpecifiedStyle}; /** diff --git a/src/servo/css/styles.rs b/src/servo/css/styles.rs index 839683b6492..c2f3b319606 100644 --- a/src/servo/css/styles.rs +++ b/src/servo/css/styles.rs @@ -4,13 +4,13 @@ use std::arc::{ARC, get, clone}; use core::dvec::DVec; -use css::values::*; -use css::values::Stylesheet; +use newcss::values::*; +use newcss::values::Stylesheet; use dom::element::{HTMLDivElement, HTMLHeadElement, HTMLImageElement, UnknownElement, HTMLScriptElement}; use dom::node::{Comment, Doctype, Element, Text, Node, NodeKind, NodeTree, LayoutData}; -use color::{Color, rgb}; -use color::css_colors::{white, black}; +use newcss::color::{Color, rgb}; +use newcss::color::css_colors::{white, black}; use layout::context::LayoutContext; #[allow(non_implicitly_copyable_typarams)] diff --git a/src/servo/css/values.rs b/src/servo/css/values.rs deleted file mode 100644 index 025a8e6884d..00000000000 --- a/src/servo/css/values.rs +++ /dev/null @@ -1,380 +0,0 @@ -/*! -Defines how css rules, both selectors and style specifications, are -stored. CSS selector-matching rules, as presented by -http://www.w3.org/TR/CSS2/selector.html are represented by nested types. -*/ - -use SharedColor = color::Color; -use cmp::Eq; -use std::net::url::Url; - -// CSS Units - -enum ParseResult { - Value(T), - CSSInitial, - CSSInherit, - Fail -} - -enum CSSValue { - Specified(T), - Initial, - Inherit -} - -impl ParseResult { - pure fn extract(f: fn(v: CSSValue) -> U) -> Option { extract(&self, f) } -} - -pure fn extract(res: &ParseResult, f: fn(v: CSSValue) -> U) -> Option { - match *res { - Fail => None, - CSSInitial => Some(f(Initial)), - CSSInherit => Some(f(Inherit)), - Value(x) => Some(f(Specified(x))) - } -} - -impl CSSValue : Eq { - pure fn eq(other: &CSSValue) -> bool { - match (self, *other) { - (Initial, Initial) => true, - (Inherit, Inherit) => true, - (Specified(a), Specified(b)) => a == b, - _ => false - } - } - pure fn ne(other: &CSSValue) -> bool { - return !self.eq(other); - } -} - -enum Auto = (); - -pub enum Length { - Em(float), // normalized to 'em' - Px(float) // normalized to 'px' -} - -impl Length { - pure fn rel() -> float { - match self { - Em(x) => x, - _ => fail ~"attempted to access relative unit of an absolute length" - } - } - pure fn abs() -> float { - match self { - Em(x) => x, - _ => fail ~"attempted to access relative unit of an absolute length" - } - } -} - -pub enum BoxSizing { // used by width, height, top, left, etc - BoxLength(Length), - BoxPercent(float), - BoxAuto -} - -enum AbsoluteSize { - XXSmall, - XSmall, - Small, - Medium, - Large, - XLarge, - XXLarge -} - -enum RelativeSize { - Larger, - Smaller -} - -// CSS property values - -enum CSSBackgroundAttachment { - BgAttachScroll, - BgAttachFixed -} - -enum CSSBackgroundColor { - BgColor(SharedColor), - BgColorTransparent -} - -enum CSSBackgroundRepeat { - BgRepeat, - BgRepeatX, - BgRepeatY, - BgNoRepeat -} - -enum CSSBackgroundImage { - BgImage(Url), - BgImageNone, -} - -enum CSSBorderColor { - BdrColor(SharedColor), - BdrColorTransparent -} - -enum CSSBorderStyle { - BdrStyleNone, - BdrStyleHidden, - BdrStyleDotted, - BdrStyleDashed, - BdrStyleSolid, - BdrStyleDouble, - BdrStyleGroove, - BdrStyleRidge, - BdrStyleInset, - BdrStyleOutset, -} - -enum CSSColor { - TextColor(SharedColor) -} - -enum CSSDirection { - DirectionLtr, - DirectionRtl -} - -enum CSSDisplay { - DisplayInline, - DisplayBlock, - DisplayListItem, - DisplayInlineBlock, - DisplayTable, - DisplayInlineTable, - DisplayTableRowGroup, - DisplayTableHeaderGroup, - DisplayTableFooterGroup, - DisplayTableRow, - DisplayTableColumnGroup, - DisplayTableColumn, - DisplayTableCell, - DisplayTableCaption, - DisplayNone -} - -enum CSSFloat { - FloatLeft, - FloatRight, - FloatNone -} - -enum CSSFontSize { - AbsoluteSize(AbsoluteSize), - RelativeSize(RelativeSize), - LengthSize(Length), - PercentSize(float) -} - -enum CSSPosition { - PosStatic, - PosRelative, - PosAbsolute, - PosFixed -} - -// Stylesheet parts - -enum StyleDeclaration { - BackgroundColor(CSSValue), - Display(CSSValue), - FontSize(CSSValue), - Height(CSSValue), - Color(CSSValue), - Width(CSSValue), - BorderColor(CSSValue), - BorderWidth(CSSValue), - Position(CSSValue), - Top(CSSValue), - Right(CSSValue), - Bottom(CSSValue), - Left(CSSValue), -} - -pub enum Attr { - Exists(~str), - Exact(~str, ~str), - Includes(~str, ~str), - StartsWith(~str, ~str) -} - -pub enum Selector { - Element(~str, ~[Attr]), - Child(~Selector, ~Selector), - Descendant(~Selector, ~Selector), - Sibling(~Selector, ~Selector) -} - -pub type Rule = (~[~Selector], ~[StyleDeclaration]); - -type Stylesheet = ~[~Rule]; - - -impl Length: cmp::Eq { - pure fn eq(other: &Length) -> bool { - match (self, *other) { - (Em(a), Em(b)) => a == b, - (Px(a), Px(b)) => a == b, - (_, _) => false - } - } - pure fn ne(other: &Length) -> bool { - return !self.eq(other); - } -} - -impl BoxSizing: cmp::Eq { - pure fn eq(other: &BoxSizing) -> bool { - match (self, *other) { - (BoxLength(a), BoxLength(b)) => a == b, - (BoxPercent(a), BoxPercent(b)) => a == b, - (BoxAuto, BoxAuto) => true, - (_, _) => false - } - } - pure fn ne(other: &BoxSizing) -> bool { - return !self.eq(other); - } -} - -impl AbsoluteSize: cmp::Eq { - pure fn eq(other: &AbsoluteSize) -> bool { - self as uint == (*other) as uint - } - pure fn ne(other: &AbsoluteSize) -> bool { - return !self.eq(other); - } -} - -impl RelativeSize: cmp::Eq { - pure fn eq(other: &RelativeSize) -> bool { - self as uint == (*other) as uint - } - pure fn ne(other: &RelativeSize) -> bool { - return !self.eq(other); - } -} - - - -impl CSSBackgroundColor: cmp::Eq { - pure fn eq(other: &CSSBackgroundColor) -> bool { - match (self, *other) { - (BgColor(a), BgColor(b)) => a == b, - (BgColorTransparent, BgColorTransparent) => true, - (_, _) => false - } - } - pure fn ne(other: &CSSBackgroundColor) -> bool { - return !self.eq(other); - } -} - - -impl CSSColor: cmp::Eq { - pure fn eq(other: &CSSColor) -> bool { - match (self, *other) { - (TextColor(a), TextColor(b)) => a == b - } - } - pure fn ne(other: &CSSColor) -> bool { - return !self.eq(other); - } -} - -impl CSSDisplay: cmp::Eq { - pure fn eq(other: &CSSDisplay) -> bool { - self as uint == (*other) as uint - } - pure fn ne(other: &CSSDisplay) -> bool { - return !self.eq(other); - } -} - - -impl CSSFontSize: cmp::Eq { - pure fn eq(other: &CSSFontSize) -> bool { - match (self, *other) { - (AbsoluteSize(a), AbsoluteSize(b)) => a == b, - (RelativeSize(a), RelativeSize(b)) => a == b, - (LengthSize(a), LengthSize(b)) => a == b, - (PercentSize(a), PercentSize(b)) => a == b, - (_, _) => false - } - } - pure fn ne(other: &CSSFontSize) -> bool { - return !self.eq(other); - } -} -/* -impl StyleDeclaration: cmp::Eq { - pure fn eq(&&other: StyleDeclaration) -> bool { - match (self, other) { - (BackgroundColor(a), BackgroundColor(b)) => a == b, - (Display(a), Display(b)) => a == b, - (FontSize(a), FontSize(b)) => a == b, - (Height(a), Height(b)) => a == b, - (Color(a), Color(b)) => a == b, - (Width(a), Width(b)) => a == b, - - (BackgroundColor(*), _) - | (Display(*), _) - | (FontSize(*), _) - | (Height(*), _) - | (Color(*), _) - | (Width(*), _) => false - } - } -}*/ - -impl Attr: cmp::Eq { - pure fn eq(other: &Attr) -> bool { - match (copy self, copy *other) { - (Exists(a), Exists(b)) => a == b, - - (Exact(a, aa), Exact(b, bb)) - | (Includes(a, aa), Includes(b, bb)) - | (StartsWith(a, aa), StartsWith(b, bb)) => a == b && aa == bb, - - (Exists(*), _) - | (Exact(*), _) - | (Includes(*), _) - | (StartsWith(*), _) => false - } - } - pure fn ne(other: &Attr) -> bool { - return !self.eq(other); - } -} - -impl Selector: cmp::Eq { - pure fn eq(other: &Selector) -> bool { - // FIXME: Lots of copying here - match (copy self, copy *other) { - (Element(s_a, attrs_a), Element(s_b, attrs_b)) => s_a == s_b && attrs_a == attrs_b, - - (Child(s1a, s2a), Child(s1b, s2b)) - | (Descendant(s1a, s2a), Descendant(s1b, s2b)) - | (Sibling(s1a, s2a), Sibling(s1b, s2b)) => { - s1a == s1b && s2a == s2b - } - - (Element(*), _) => false, - (Child(*), _) => false, - (Descendant(*), _) => false, - (Sibling(*), _) => false - } - } - pure fn ne(other: &Selector) -> bool { - return !self.eq(other); - } -} diff --git a/src/servo/dom/document.rs b/src/servo/dom/document.rs index b5336288a66..e464a2ed041 100644 --- a/src/servo/dom/document.rs +++ b/src/servo/dom/document.rs @@ -1,4 +1,4 @@ -use css::values::Stylesheet; +use newcss::values::Stylesheet; use dom::node::{NodeScope, Node}; use std::arc::ARC; diff --git a/src/servo/dom/node.rs b/src/servo/dom/node.rs index acb6ad25ad3..e72ad515792 100644 --- a/src/servo/dom/node.rs +++ b/src/servo/dom/node.rs @@ -1,6 +1,6 @@ /* The core DOM types. Defines the basic DOM hierarchy as well as all the HTML elements. */ use css::styles::SpecifiedStyle; -use css::values::Stylesheet; +use newcss::values::Stylesheet; use dom::bindings; use dom::document::Document; use dom::element::{Attr, ElementData}; diff --git a/src/servo/html/hubbub_html_parser.rs b/src/servo/html/hubbub_html_parser.rs index 4c515c24431..d73d8b01223 100644 --- a/src/servo/html/hubbub_html_parser.rs +++ b/src/servo/html/hubbub_html_parser.rs @@ -1,6 +1,6 @@ use au = gfx::geometry; use content::content_task::ContentTask; -use css::values::Stylesheet; +use newcss::values::Stylesheet; use dom::cow; use dom::element::*; use dom::event::{Event, ReflowEvent}; diff --git a/src/servo/layout/block.rs b/src/servo/layout/block.rs index 9be387e6cd4..6f06fe1f103 100644 --- a/src/servo/layout/block.rs +++ b/src/servo/layout/block.rs @@ -1,5 +1,5 @@ use au = gfx::geometry; -use css::values::*; +use newcss::values::*; use geom::point::Point2D; use geom::rect::Rect; use geom::size::Size2D; diff --git a/src/servo/layout/box.rs b/src/servo/layout/box.rs index 56612510f2c..cc9f87ffb35 100644 --- a/src/servo/layout/box.rs +++ b/src/servo/layout/box.rs @@ -1,6 +1,6 @@ /* Fundamental layout structures and algorithms. */ -use css::color::rgb; +use newcss::color::rgb; use arc = std::arc; use arc::ARC; use au = gfx::geometry; @@ -9,9 +9,9 @@ use core::dvec::DVec; use core::to_str::ToStr; use core::rand; use css::styles::SpecifiedStyle; -use css::values::{BoxSizing, Length, Px, CSSDisplay, Specified, BgColor, BgColorTransparent}; -use css::values::{BdrColor, PosAbsolute}; -use css::color::{Color, rgba}; +use newcss::values::{BoxSizing, Length, Px, CSSDisplay, Specified, BgColor, BgColorTransparent}; +use newcss::values::{BdrColor, PosAbsolute}; +use newcss::color::{Color, rgba}; use dom::element::{ElementKind, HTMLDivElement, HTMLImageElement}; use dom::node::{Element, Node, NodeData, NodeKind, NodeTree}; use geom::rect::Rect; diff --git a/src/servo/layout/box_builder.rs b/src/servo/layout/box_builder.rs index 69e8a66b744..783a5c8f057 100644 --- a/src/servo/layout/box_builder.rs +++ b/src/servo/layout/box_builder.rs @@ -2,8 +2,8 @@ use au = gfx::geometry; use core::dvec::DVec; use css::styles::{SpecifiedStyle, empty_style_for_node_kind}; -use css::values::{CSSDisplay, DisplayBlock, DisplayInline, DisplayInlineBlock, DisplayNone}; -use css::values::{Inherit, Initial, Specified}; +use newcss::values::{CSSDisplay, DisplayBlock, DisplayInline, DisplayInlineBlock, DisplayNone}; +use newcss::values::{Inherit, Initial, Specified}; use dom::element::*; use dom::node::{Comment, Doctype, Element, Text, Node, LayoutData}; use image::holder::ImageHolder; diff --git a/src/servo/layout/display_list_builder.rs b/src/servo/layout/display_list_builder.rs index 2cbdd219946..df1cd59cd58 100644 --- a/src/servo/layout/display_list_builder.rs +++ b/src/servo/layout/display_list_builder.rs @@ -2,7 +2,7 @@ export DisplayListBuilder; use au = gfx::geometry; use au::Au; -use css::values::{BgColor, BgColorTransparent, Specified}; +use newcss::values::{BgColor, BgColorTransparent, Specified}; use dom::node::{Text, NodeScope}; use dom::cow::Scope; use dvec::DVec; diff --git a/src/servo/layout/inline.rs b/src/servo/layout/inline.rs index 27c9ef7ced1..3a78eb756f4 100644 --- a/src/servo/layout/inline.rs +++ b/src/servo/layout/inline.rs @@ -1,7 +1,7 @@ use au = gfx::geometry; use core::dlist::DList; use core::dvec::DVec; -use css::values::{BoxAuto, BoxLength, Px}; +use newcss::values::{BoxAuto, BoxLength, Px}; use dom::node::Node; use geom::point::Point2D; use geom::rect::Rect; diff --git a/src/servo/layout/layout_task.rs b/src/servo/layout/layout_task.rs index 310fe56f5b1..2cd32dab07a 100644 --- a/src/servo/layout/layout_task.rs +++ b/src/servo/layout/layout_task.rs @@ -8,7 +8,7 @@ use au::Au; use content::content_task; use core::dvec::DVec; use css::resolve::apply::apply_style; -use css::values::Stylesheet; +use newcss::values::Stylesheet; use dl = gfx::display_list; use dom::event::{Event, ReflowEvent}; use dom::node::{Node, LayoutData}; diff --git a/src/servo/layout/root.rs b/src/servo/layout/root.rs index 6da9dae0230..c0640ca1599 100644 --- a/src/servo/layout/root.rs +++ b/src/servo/layout/root.rs @@ -1,5 +1,5 @@ use au = gfx::geometry; -use css::values::*; +use newcss::values::*; use geom::point::Point2D; use geom::rect::Rect; use gfx::display_list::{DisplayList, DisplayListBuilder}; diff --git a/src/servo/servo.rc b/src/servo/servo.rc index 4cd71ccfd14..2877ed41675 100755 --- a/src/servo/servo.rc +++ b/src/servo/servo.rc @@ -49,14 +49,11 @@ pub mod css { pub mod parser; pub mod parser_util; - pub mod values; pub mod styles; pub mod resolve { pub mod apply; pub mod matching; } - - pub mod color; } pub mod layout { diff --git a/src/servo/text/text_run.rs b/src/servo/text/text_run.rs index 1d85a657272..c5657391f2a 100644 --- a/src/servo/text/text_run.rs +++ b/src/servo/text/text_run.rs @@ -9,7 +9,7 @@ use gfx::geometry::Au; use glyph::GlyphStore; use layout::context::LayoutContext; use libc::{c_void}; -use css::color; +use newcss::color; use std::arc; use servo_util::range::{Range, MutableRange};