Move css::color, and css::value to rust-css

This commit is contained in:
Brian Anderson 2012-10-29 16:31:24 -07:00
parent ef63245502
commit ada1da1073
22 changed files with 35 additions and 710 deletions

@ -1 +1 @@
Subproject commit 8b668287b7c208abbd6e29f1413387e5cefe4491
Subproject commit 2a61c1cb0d1878f238cd2e33377a254d29ff7f2e

View file

@ -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};

View file

@ -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<Color> {
warn!("Unrecognized color %s", col);
return None;
}
/** Match an exact color keyword. */
fn parse_by_name(color : &str) -> Option<Color> {
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<Color> {
// 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<Color> {
// 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<Color> {
// 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<Color> {
// 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<Color> {
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
}

View file

@ -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);

View file

@ -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<Token>, mut lookahead : Option<Token>};

View file

@ -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<CSSDisplay> {
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

View file

@ -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<T> {
pure fn initial() -> T;

View file

@ -5,7 +5,7 @@
use dom::node::{LayoutData, Node, Text};
use dom::element::ElementData;
use values::*;
use newcss::values::*;
use styles::{SpecifiedStyle};
/**

View file

@ -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)]

View file

@ -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<T> {
Value(T),
CSSInitial,
CSSInherit,
Fail
}
enum CSSValue<T : Copy> {
Specified(T),
Initial,
Inherit
}
impl<T : Copy> ParseResult<T> {
pure fn extract<U>(f: fn(v: CSSValue<T>) -> U) -> Option<U> { extract(&self, f) }
}
pure fn extract<T : Copy, U>(res: &ParseResult<T>, f: fn(v: CSSValue<T>) -> U) -> Option<U> {
match *res {
Fail => None,
CSSInitial => Some(f(Initial)),
CSSInherit => Some(f(Inherit)),
Value(x) => Some(f(Specified(x)))
}
}
impl<T: Eq Copy> CSSValue<T> : Eq {
pure fn eq(other: &CSSValue<T>) -> bool {
match (self, *other) {
(Initial, Initial) => true,
(Inherit, Inherit) => true,
(Specified(a), Specified(b)) => a == b,
_ => false
}
}
pure fn ne(other: &CSSValue<T>) -> 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<CSSBackgroundColor>),
Display(CSSValue<CSSDisplay>),
FontSize(CSSValue<CSSFontSize>),
Height(CSSValue<BoxSizing>),
Color(CSSValue<CSSColor>),
Width(CSSValue<BoxSizing>),
BorderColor(CSSValue<CSSBorderColor>),
BorderWidth(CSSValue<Length>),
Position(CSSValue<CSSPosition>),
Top(CSSValue<Length>),
Right(CSSValue<Length>),
Bottom(CSSValue<Length>),
Left(CSSValue<Length>),
}
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);
}
}

View file

@ -1,4 +1,4 @@
use css::values::Stylesheet;
use newcss::values::Stylesheet;
use dom::node::{NodeScope, Node};
use std::arc::ARC;

View file

@ -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};

View file

@ -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};

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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};

View file

@ -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};

View file

@ -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 {

View file

@ -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};