Update rustc to 00b112c45a604fa6f4b59af2a40c9deeadfdb7c6/rustc-1.0.0-dev.

This commit is contained in:
Josh Matthews 2015-01-15 13:26:44 -05:00 committed by Glenn Watson
parent ff8cbff810
commit 95fc29fa0d
255 changed files with 3550 additions and 3362 deletions

View file

@ -18,9 +18,6 @@ path = "../util"
[dependencies.geom]
git = "https://github.com/servo/rust-geom"
[dependencies.url]
git = "https://github.com/servo/rust-url"
[dependencies.cssparser]
git = "https://github.com/servo/rust-cssparser"
@ -37,3 +34,4 @@ git = "https://github.com/servo/string-cache"
text_writer = "0.1.1"
encoding = "0.2"
matches = "0.1"
url = "*"

View file

@ -12,15 +12,15 @@ use url::{Url, UrlParser};
use parser::ParserContext;
pub fn iter_font_face_rules_inner(rules: &[CSSRule], device: &Device,
callback: |family: &str, source: &Source|) {
pub fn iter_font_face_rules_inner<F>(rules: &[CSSRule], device: &Device,
callback: &F) where F: Fn(&str, &Source) {
for rule in rules.iter() {
match *rule {
CSSRule::Style(..) |
CSSRule::Charset(..) |
CSSRule::Namespace(..) => {},
CSSRule::Media(ref rule) => if rule.media_queries.evaluate(device) {
iter_font_face_rules_inner(rule.rules.as_slice(), device, |f, s| callback(f, s))
iter_font_face_rules_inner(rule.rules.as_slice(), device, callback)
},
CSSRule::FontFace(ref rule) => {
for source in rule.sources.iter() {
@ -31,19 +31,19 @@ pub fn iter_font_face_rules_inner(rules: &[CSSRule], device: &Device,
}
}
#[deriving(Clone, Show, PartialEq, Eq)]
#[derive(Clone, Show, PartialEq, Eq)]
pub enum Source {
Url(UrlSource),
Local(String),
}
#[deriving(Clone, Show, PartialEq, Eq)]
#[derive(Clone, Show, PartialEq, Eq)]
pub struct UrlSource {
pub url: Url,
pub format_hints: Vec<String>,
}
#[deriving(Show, PartialEq, Eq)]
#[derive(Show, PartialEq, Eq)]
pub struct FontFaceRule {
pub family: String,
pub sources: Vec<Source>,
@ -82,7 +82,7 @@ impl<'a, 'b> AtRuleParser<(), ()> for FontFaceRuleParser<'a, 'b> {}
impl<'a, 'b> DeclarationParser<()> for FontFaceRuleParser<'a, 'b> {
fn parse_value(&mut self, name: &str, input: &mut Parser) -> Result<(), ()> {
match_ignore_ascii_case! { name:
match_ignore_ascii_case! { name,
"font-family" => {
self.family = Some(try!(parse_one_non_generic_family_name(input)));
Ok(())

View file

@ -18,14 +18,14 @@ use servo_util::smallvec::VecLike;
use servo_util::str::LengthOrPercentageOrAuto;
/// Legacy presentational attributes that take a length as defined in HTML5 § 2.4.4.4.
#[deriving(Copy, PartialEq, Eq)]
#[derive(Copy, PartialEq, Eq)]
pub enum LengthAttribute {
/// `<td width>`
Width,
}
/// Legacy presentational attributes that take an integer as defined in HTML5 § 2.4.4.2.
#[deriving(Copy, PartialEq, Eq)]
#[derive(Copy, PartialEq, Eq)]
pub enum IntegerAttribute {
/// `<input size>`
Size,
@ -34,7 +34,7 @@ pub enum IntegerAttribute {
}
/// Legacy presentational attributes that take a nonnegative integer as defined in HTML5 § 2.4.4.2.
#[deriving(Copy, PartialEq, Eq)]
#[derive(Copy, PartialEq, Eq)]
pub enum UnsignedIntegerAttribute {
/// `<td border>`
Border,
@ -43,7 +43,7 @@ pub enum UnsignedIntegerAttribute {
}
/// Legacy presentational attributes that take a simple color as defined in HTML5 § 2.4.6.
#[deriving(Copy, PartialEq, Eq)]
#[derive(Copy, PartialEq, Eq)]
pub enum SimpleColorAttribute {
/// `<body bgcolor>`
BgColor,

View file

@ -2,15 +2,17 @@
* 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(globs, macro_rules)]
#![feature(plugin)]
#![feature(int_uint)]
#![feature(box_syntax)]
#![deny(unused_imports)]
#![deny(unused_variables)]
#![allow(missing_copy_implementations)]
#![allow(unstable)]
#![feature(phase)]
#[phase(plugin, link)] extern crate log;
#[phase(plugin)] extern crate string_cache_macros;
#[macro_use] extern crate log;
#[no_link] #[macro_use] #[plugin] extern crate string_cache_macros;
extern crate collections;
extern crate geom;
@ -18,22 +20,16 @@ extern crate serialize;
extern crate text_writer;
extern crate url;
#[phase(plugin, link)]
#[macro_use]
extern crate cssparser;
#[phase(plugin)]
#[macro_use]
extern crate matches;
extern crate encoding;
extern crate string_cache;
#[phase(plugin)]
extern crate string_cache_macros;
#[phase(plugin)]
extern crate plugins;
#[phase(plugin)]
#[macro_use]
extern crate lazy_static;
extern crate "util" as servo_util;
@ -70,7 +66,7 @@ pub mod stylesheets;
pub mod parser;
pub mod selectors;
pub mod selector_matching;
pub mod values;
#[macro_use] pub mod values;
pub mod properties;
pub mod namespaces;
pub mod node;

View file

@ -11,12 +11,12 @@ use servo_util::geometry::{Au, ViewportPx};
use values::{computed, specified};
#[deriving(Show, PartialEq)]
#[derive(Show, PartialEq)]
pub struct MediaQueryList {
media_queries: Vec<MediaQuery>
}
#[deriving(PartialEq, Eq, Copy, Show)]
#[derive(PartialEq, Eq, Copy, Show)]
pub enum Range<T> {
Min(T),
Max(T),
@ -33,18 +33,18 @@ impl<T: Ord> Range<T> {
}
}
#[deriving(PartialEq, Eq, Copy, Show)]
#[derive(PartialEq, Eq, Copy, Show)]
pub enum Expression {
Width(Range<Au>),
}
#[deriving(PartialEq, Eq, Copy, Show)]
#[derive(PartialEq, Eq, Copy, Show)]
pub enum Qualifier {
Only,
Not,
}
#[deriving(Show, PartialEq)]
#[derive(Show, PartialEq)]
pub struct MediaQuery {
qualifier: Option<Qualifier>,
media_type: MediaQueryType,
@ -62,13 +62,13 @@ impl MediaQuery {
}
}
#[deriving(PartialEq, Eq, Copy, Show)]
#[derive(PartialEq, Eq, Copy, Show)]
pub enum MediaQueryType {
All, // Always true
MediaType(MediaType),
}
#[deriving(PartialEq, Eq, Copy, Show)]
#[derive(PartialEq, Eq, Copy, Show)]
pub enum MediaType {
Screen,
Print,
@ -76,7 +76,7 @@ pub enum MediaType {
}
#[allow(missing_copy_implementations)]
#[deriving(Show)]
#[derive(Show)]
pub struct Device {
pub media_type: MediaType,
pub viewport_size: TypedSize2D<ViewportPx, f32>,
@ -109,7 +109,7 @@ impl Expression {
let name = try!(input.expect_ident());
try!(input.expect_colon());
// TODO: Handle other media features
match_ignore_ascii_case! { name:
match_ignore_ascii_case! { name,
"min-width" => {
Ok(Expression::Width(Range::Min(try!(parse_non_negative_length(input)))))
},
@ -136,7 +136,7 @@ impl MediaQuery {
let media_type;
if let Ok(ident) = input.try(|input| input.expect_ident()) {
media_type = match_ignore_ascii_case! { ident:
media_type = match_ignore_ascii_case! { ident,
"screen" => MediaQueryType::MediaType(MediaType::Screen),
"print" => MediaQueryType::MediaType(MediaType::Print),
"all" => MediaQueryType::All
@ -222,7 +222,7 @@ mod tests {
use url::Url;
use std::borrow::ToOwned;
fn test_media_rule(css: &str, callback: |&MediaQueryList, &str|) {
fn test_media_rule<F>(css: &str, callback: F) where F: Fn(&MediaQueryList, &str) {
let url = Url::parse("http://localhost").unwrap();
let stylesheet = Stylesheet::from_str(css, url, Origin::Author);
let mut rule_count: int = 0;

View file

@ -8,7 +8,7 @@ use string_cache::{Atom, Namespace};
use parser::ParserContext;
#[deriving(Clone)]
#[derive(Clone)]
pub struct NamespaceMap {
pub default: Option<Namespace>,
pub prefix_map: HashMap<String, Namespace>,

View file

@ -20,7 +20,7 @@ pub trait TNode<'a, E: TElement<'a>> : Clone + Copy {
fn is_document(self) -> bool;
fn is_element(self) -> bool;
fn as_element(self) -> E;
fn match_attr(self, attr: &AttrSelector, test: |&str| -> bool) -> bool;
fn match_attr<F>(self, attr: &AttrSelector, test: F) -> bool where F: Fn(&str) -> bool;
fn is_html_element_in_html_document(self) -> bool;
fn has_changed(self) -> bool;
@ -55,7 +55,7 @@ pub trait TElement<'a> : Copy {
// really messy, since there is a `JSRef` and a `RefCell` involved. Maybe
// in the future when we have associated types and/or a more convenient
// JS GC story... --pcwalton
fn each_class(self, callback: |&Atom|);
fn each_class<F>(self, callback: F) where F: FnMut(&Atom);
}
pub trait TElementAttributes : Copy {

View file

@ -361,7 +361,7 @@ pub mod longhands {
pub mod computed_value {
use std::fmt;
#[deriving(PartialEq, Clone, Eq, Copy)]
#[derive(PartialEq, Clone, Eq, Copy)]
pub enum T {
Auto,
Number(i32),
@ -451,7 +451,7 @@ pub mod longhands {
<%self:longhand name="line-height">
use std::fmt;
use values::CSSFloat;
#[deriving(Clone, PartialEq, Copy)]
#[derive(Clone, PartialEq, Copy)]
pub enum SpecifiedValue {
Normal,
Length(specified::Length),
@ -462,7 +462,7 @@ pub mod longhands {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&SpecifiedValue::Normal => write!(f, "normal"),
&SpecifiedValue::Length(length) => write!(f, "{}", length),
&SpecifiedValue::Length(length) => write!(f, "{:?}", length),
&SpecifiedValue::Number(number) => write!(f, "{}", number),
&SpecifiedValue::Percentage(number) => write!(f, "{}%", number * 100.),
}
@ -493,7 +493,7 @@ pub mod longhands {
use values::CSSFloat;
use servo_util::geometry::Au;
use std::fmt;
#[deriving(PartialEq, Copy, Clone)]
#[derive(PartialEq, Copy, Clone)]
pub enum T {
Normal,
Length(Au),
@ -503,7 +503,7 @@ pub mod longhands {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&T::Normal => write!(f, "normal"),
&T::Length(length) => write!(f, "{}%", length),
&T::Length(length) => write!(f, "{:?}%", length),
&T::Number(number) => write!(f, "{}", number),
}
}
@ -535,7 +535,7 @@ pub mod longhands {
<% vertical_align_keywords = (
"baseline sub super top text-top middle bottom text-bottom".split()) %>
#[allow(non_camel_case_types)]
#[deriving(Clone, PartialEq, Copy)]
#[derive(Clone, PartialEq, Copy)]
pub enum SpecifiedValue {
% for keyword in vertical_align_keywords:
${to_rust_ident(keyword)},
@ -548,7 +548,7 @@ pub mod longhands {
% for keyword in vertical_align_keywords:
&SpecifiedValue::${to_rust_ident(keyword)} => write!(f, "${keyword}"),
% endfor
&SpecifiedValue::LengthOrPercentage(lop) => write!(f, "{}", lop),
&SpecifiedValue::LengthOrPercentage(lop) => write!(f, "{:?}", lop),
}
}
}
@ -558,7 +558,7 @@ pub mod longhands {
input.try(specified::LengthOrPercentage::parse_non_negative)
.map(SpecifiedValue::LengthOrPercentage)
.or_else(|()| {
match_ignore_ascii_case! { try!(input.expect_ident()):
match_ignore_ascii_case! { try!(input.expect_ident()),
% for keyword in vertical_align_keywords[:-1]:
"${keyword}" => Ok(SpecifiedValue::${to_rust_ident(keyword)}),
% endfor
@ -576,7 +576,7 @@ pub mod longhands {
use servo_util::geometry::Au;
use std::fmt;
#[allow(non_camel_case_types)]
#[deriving(PartialEq, Copy, Clone)]
#[derive(PartialEq, Copy, Clone)]
pub enum T {
% for keyword in vertical_align_keywords:
${to_rust_ident(keyword)},
@ -590,7 +590,7 @@ pub mod longhands {
% for keyword in vertical_align_keywords:
&T::${to_rust_ident(keyword)} => write!(f, "${keyword}"),
% endfor
&T::Length(length) => write!(f, "{}", length),
&T::Length(length) => write!(f, "{:?}", length),
&T::Percentage(number) => write!(f, "{}%", number),
}
}
@ -642,7 +642,7 @@ pub mod longhands {
use cssparser::Token;
pub mod computed_value {
use std::fmt;
#[deriving(PartialEq, Eq, Clone)]
#[derive(PartialEq, Eq, Clone)]
pub enum ContentItem {
StringContent(String),
}
@ -654,7 +654,7 @@ pub mod longhands {
}
}
#[allow(non_camel_case_types)]
#[deriving(PartialEq, Eq, Clone)]
#[derive(PartialEq, Eq, Clone)]
pub enum T {
normal,
none,
@ -667,7 +667,7 @@ pub mod longhands {
&T::none => write!(f, "none"),
&T::Content(ref content) => {
for c in content.iter() {
let _ = write!(f, "{}", c);
let _ = write!(f, "{:?}", c);
}
Ok(())
}
@ -781,26 +781,26 @@ pub mod longhands {
use values::computed::LengthOrPercentage;
use std::fmt;
#[deriving(PartialEq, Copy, Clone)]
#[derive(PartialEq, Copy, Clone)]
pub struct T {
pub horizontal: LengthOrPercentage,
pub vertical: LengthOrPercentage,
}
impl fmt::Show for T {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} {}", self.horizontal, self.vertical)
write!(f, "{:?} {:?}", self.horizontal, self.vertical)
}
}
}
#[deriving(Clone, PartialEq, Copy)]
#[derive(Clone, PartialEq, Copy)]
pub struct SpecifiedValue {
pub horizontal: specified::LengthOrPercentage,
pub vertical: specified::LengthOrPercentage,
}
impl fmt::Show for SpecifiedValue {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} {}", self.horizontal, self.vertical)
write!(f, "{:?} {:?}", self.horizontal, self.vertical)
}
}
@ -923,7 +923,7 @@ pub mod longhands {
use self::computed_value::FontFamily;
pub mod computed_value {
use std::fmt;
#[deriving(PartialEq, Eq, Clone)]
#[derive(PartialEq, Eq, Clone)]
pub enum FontFamily {
FamilyName(String),
// Generic
@ -974,7 +974,7 @@ pub mod longhands {
return Ok(FontFamily::FamilyName(value.into_owned()))
}
let first_ident = try!(input.expect_ident());
// match_ignore_ascii_case! { first_ident:
// match_ignore_ascii_case! { first_ident,
// "serif" => return Ok(Serif),
// "sans-serif" => return Ok(SansSerif),
// "cursive" => return Ok(Cursive),
@ -997,7 +997,7 @@ pub mod longhands {
<%self:longhand name="font-weight">
use std::fmt;
#[deriving(Clone, PartialEq, Eq, Copy)]
#[derive(Clone, PartialEq, Eq, Copy)]
pub enum SpecifiedValue {
Bolder,
Lighter,
@ -1019,7 +1019,7 @@ pub mod longhands {
/// normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
input.try(|input| {
match_ignore_ascii_case! { try!(input.expect_ident()):
match_ignore_ascii_case! { try!(input.expect_ident()),
"bold" => Ok(SpecifiedValue::Weight700),
"normal" => Ok(SpecifiedValue::Weight400),
"bolder" => Ok(SpecifiedValue::Bolder),
@ -1043,7 +1043,7 @@ pub mod longhands {
}
pub mod computed_value {
use std::fmt;
#[deriving(PartialEq, Eq, Copy, Clone)]
#[derive(PartialEq, Eq, Copy, Clone)]
pub enum T {
% for weight in range(100, 901, 100):
Weight${weight},
@ -1130,7 +1130,7 @@ pub mod longhands {
specified::LengthOrPercentage::Percentage(value) => specified::Length::Em(value)
})
.or_else(|()| {
match_ignore_ascii_case! { try!(input.expect_ident()):
match_ignore_ascii_case! { try!(input.expect_ident()),
"xx-small" => Ok(specified::Length::Au(Au::from_px(MEDIUM_PX) * 3 / 5)),
"x-small" => Ok(specified::Length::Au(Au::from_px(MEDIUM_PX) * 3 / 4)),
"small" => Ok(specified::Length::Au(Au::from_px(MEDIUM_PX) * 8 / 9)),
@ -1218,7 +1218,7 @@ pub mod longhands {
<%self:longhand name="text-decoration">
pub use super::computed_as_specified as to_computed_value;
use std::fmt;
#[deriving(PartialEq, Eq, Copy, Clone)]
#[derive(PartialEq, Eq, Copy, Clone)]
pub struct SpecifiedValue {
pub underline: bool,
pub overline: bool,
@ -1270,7 +1270,7 @@ pub mod longhands {
let mut blink = false;
let mut empty = true;
loop {
match_ignore_ascii_case! { try!(input.expect_ident()):
match_ignore_ascii_case! { try!(input.expect_ident()),
"underline" => if result.underline { return Err(()) }
else { empty = false; result.underline = true },
"overline" => if result.overline { return Err(()) }
@ -1279,7 +1279,7 @@ pub mod longhands {
else { empty = false; result.line_through = true },
"blink" => if blink { return Err(()) }
else { empty = false; blink = true }
_ => break,
_ => break
}
}
if !empty { Ok(result) } else { Err(()) }
@ -1293,7 +1293,7 @@ pub mod longhands {
use cssparser::RGBA;
pub use super::computed_as_specified as to_computed_value;
#[deriving(Clone, PartialEq, Copy)]
#[derive(Clone, PartialEq, Copy)]
pub struct SpecifiedValue {
pub underline: Option<RGBA>,
pub overline: Option<RGBA>,
@ -1411,7 +1411,7 @@ pub mod longhands {
pub mod computed_value {
use servo_util::cursor::Cursor;
#[deriving(Clone, PartialEq, Eq, Copy, Show)]
#[derive(Clone, PartialEq, Eq, Copy, Show)]
pub enum T {
AutoCursor,
SpecifiedCursor(Cursor),
@ -1474,7 +1474,7 @@ pub mod longhands {
pub type SpecifiedValue = Vec<SpecifiedBoxShadow>;
#[deriving(Clone, PartialEq)]
#[derive(Clone, PartialEq)]
pub struct SpecifiedBoxShadow {
pub offset_x: specified::Length,
pub offset_y: specified::Length,
@ -1489,10 +1489,10 @@ pub mod longhands {
if self.inset {
let _ = write!(f, "inset ");
}
let _ = write!(f, "{} {} {} {}", self.offset_x, self.offset_y,
let _ = write!(f, "{:?} {:?} {:?} {:?}", self.offset_x, self.offset_y,
self.blur_radius, self.spread_radius);
if let Some(ref color) = self.color {
let _ = write!(f, "{}", color);
let _ = write!(f, "{:?}", color);
}
Ok(())
}
@ -1505,7 +1505,7 @@ pub mod longhands {
pub type T = Vec<BoxShadow>;
#[deriving(Clone, PartialEq, Copy)]
#[derive(Clone, PartialEq, Copy)]
pub struct BoxShadow {
pub offset_x: Au,
pub offset_y: Au,
@ -1520,7 +1520,7 @@ pub mod longhands {
if self.inset {
let _ = write!(f, "inset ");
}
let _ = write!(f, "{} {} {} {} {}", self.offset_x, self.offset_y,
let _ = write!(f, "{:?} {:?} {:?} {:?} {:?}", self.offset_x, self.offset_y,
self.blur_radius, self.spread_radius, self.color);
Ok(())
}
@ -1561,7 +1561,7 @@ pub mod longhands {
pub fn parse_one_box_shadow(input: &mut Parser) -> Result<SpecifiedBoxShadow, ()> {
use servo_util::geometry::Au;
let mut lengths = [specified::Length::Au(Au(0)), ..4];
let mut lengths = [specified::Length::Au(Au(0)); 4];
let mut lengths_parsed = false;
let mut color = None;
let mut inset = false;
@ -1626,7 +1626,7 @@ pub mod longhands {
pub mod computed_value {
use servo_util::geometry::Au;
#[deriving(Clone, PartialEq, Eq, Copy, Show)]
#[derive(Clone, PartialEq, Eq, Copy, Show)]
pub struct ClipRect {
pub top: Au,
pub right: Option<Au>,
@ -1637,7 +1637,7 @@ pub mod longhands {
pub type T = Option<ClipRect>;
}
#[deriving(Clone, Show, PartialEq, Copy)]
#[derive(Clone, Show, PartialEq, Copy)]
pub struct SpecifiedClipRect {
pub top: specified::Length,
pub right: Option<specified::Length>,
@ -1706,7 +1706,7 @@ pub mod longhands {
use values::CSSFloat;
// TODO(pcwalton): `blur`, `drop-shadow`
#[deriving(Clone, PartialEq, Show)]
#[derive(Clone, PartialEq, Show)]
pub enum Filter {
Brightness(CSSFloat),
Contrast(CSSFloat),
@ -1718,7 +1718,7 @@ pub mod longhands {
Sepia(CSSFloat),
}
#[deriving(Clone, PartialEq, Show)]
#[derive(Clone, PartialEq, Show)]
pub struct T {
pub filters: Vec<Filter>,
}
@ -1768,7 +1768,7 @@ pub mod longhands {
loop {
if let Ok(function_name) = input.try(|input| input.expect_function()) {
filters.push(try!(input.parse_nested_block(|input| {
match_ignore_ascii_case! { function_name:
match_ignore_ascii_case! { function_name,
"brightness" => parse_factor(input).map(Filter::Brightness),
"contrast" => parse_factor(input).map(Filter::Contrast),
"grayscale" => parse_factor(input).map(Filter::Grayscale),
@ -2031,9 +2031,9 @@ pub mod shorthands {
let _ignored = context;
fn parse_one_set_of_border_radii(mut input: &mut Parser)
-> Result<[LengthOrPercentage, ..4], ()> {
-> Result<[LengthOrPercentage; 4], ()> {
let mut count = 0;
let mut values = [LengthOrPercentage::Length(Length::Au(Au(0))), ..4];
let mut values = [LengthOrPercentage::Length(Length::Au(Au(0))); 4];
while count < 4 {
if let Ok(value) = input.try(LengthOrPercentage::parse) {
values[count] = value;
@ -2272,7 +2272,7 @@ mod property_bit_field {
use std::mem;
pub struct PropertyBitField {
storage: [uint, ..(${len(LONGHANDS)} - 1 + uint::BITS) / uint::BITS]
storage: [uint; (${len(LONGHANDS)} - 1 + uint::BITS) / uint::BITS]
}
impl PropertyBitField {
@ -2309,7 +2309,7 @@ mod property_bit_field {
/// Declarations are stored in reverse order.
/// Overridden declarations are skipped.
#[deriving(Show, PartialEq)]
#[derive(Show, PartialEq)]
pub struct PropertyDeclarationBlock {
pub important: Arc<Vec<PropertyDeclaration>>,
pub normal: Arc<Vec<PropertyDeclaration>>,
@ -2399,7 +2399,7 @@ fn deduplicate_property_declarations(declarations: Vec<PropertyDeclaration>)
}
#[deriving(Copy, PartialEq, Eq, Show)]
#[derive(Copy, PartialEq, Eq, Show)]
pub enum CSSWideKeyword {
InitialKeyword,
InheritKeyword,
@ -2408,7 +2408,7 @@ pub enum CSSWideKeyword {
impl CSSWideKeyword {
pub fn parse(input: &mut Parser) -> Result<CSSWideKeyword, ()> {
match_ignore_ascii_case! { try!(input.expect_ident()):
match_ignore_ascii_case! { try!(input.expect_ident()),
"initial" => Ok(CSSWideKeyword::InitialKeyword),
"inherit" => Ok(CSSWideKeyword::InheritKeyword),
"unset" => Ok(CSSWideKeyword::UnsetKeyword)
@ -2418,7 +2418,7 @@ impl CSSWideKeyword {
}
#[deriving(Clone, PartialEq, Eq, Copy, Show)]
#[derive(Clone, PartialEq, Eq, Copy, Show)]
pub enum DeclaredValue<T> {
SpecifiedValue(T),
Initial,
@ -2431,14 +2431,14 @@ pub enum DeclaredValue<T> {
impl<T: Show> DeclaredValue<T> {
pub fn specified_value(&self) -> Option<String> {
match self {
&DeclaredValue::SpecifiedValue(ref inner) => Some(format!("{}", inner)),
&DeclaredValue::SpecifiedValue(ref inner) => Some(format!("{:?}", inner)),
&DeclaredValue::Initial => None,
&DeclaredValue::Inherit => Some("inherit".to_owned()),
}
}
}
#[deriving(Clone, PartialEq)]
#[derive(Clone, PartialEq)]
pub enum PropertyDeclaration {
% for property in LONGHANDS:
${property.camel_case}(DeclaredValue<longhands::${property.ident}::SpecifiedValue>),
@ -2446,7 +2446,7 @@ pub enum PropertyDeclaration {
}
#[deriving(Eq, PartialEq, Copy)]
#[derive(Eq, PartialEq, Copy)]
pub enum PropertyDeclarationParseResult {
UnknownProperty,
ExperimentalProperty,
@ -2472,15 +2472,15 @@ impl PropertyDeclaration {
% if property.derived_from is None:
&PropertyDeclaration::${property.camel_case}(ref value) =>
value.specified_value()
.unwrap_or_else(|| format!("{}", longhands::${property.ident}::get_initial_value())),
.unwrap_or_else(|| format!("{:?}", longhands::${property.ident}::get_initial_value())),
% endif
% endfor
decl => panic!("unsupported property declaration: {}", decl.name()),
decl => panic!("unsupported property declaration: {:?}", decl.name()),
}
}
pub fn matches(&self, name: &str) -> bool {
let name_lower = name.as_slice().to_ascii_lower();
let name_lower = name.as_slice().to_ascii_lowercase();
match (self, name_lower.as_slice()) {
% for property in LONGHANDS:
% if property.derived_from is None:
@ -2493,7 +2493,7 @@ impl PropertyDeclaration {
pub fn parse(name: &str, context: &ParserContext, input: &mut Parser,
result_list: &mut Vec<PropertyDeclaration>) -> PropertyDeclarationParseResult {
match_ignore_ascii_case! { name:
match_ignore_ascii_case! { name,
% for property in LONGHANDS:
% if property.derived_from is None:
"${property.name}" => {
@ -2579,7 +2579,7 @@ pub mod style_structs {
% for style_struct in STYLE_STRUCTS:
#[allow(missing_copy_implementations)]
#[deriving(PartialEq, Clone)]
#[derive(PartialEq, Clone)]
pub struct ${style_struct.name} {
% for longhand in style_struct.longhands:
pub ${longhand.ident}: longhands::${longhand.ident}::computed_value::T,
@ -2588,7 +2588,7 @@ pub mod style_structs {
% endfor
}
#[deriving(Clone)]
#[derive(Clone)]
pub struct ComputedValues {
% for style_struct in STYLE_STRUCTS:
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
@ -2918,7 +2918,7 @@ pub fn cascade(applicable_declarations: &[DeclarationBlock],
DeclaredValue::Inherit => inherited_style.$style_struct_getter().$property.clone(),
}
};
)
);
// Initialize `context`
// Declarations blocks are already stored in increasing precedence order.
@ -3136,9 +3136,9 @@ pub fn is_supported_property(property: &str) -> bool {
}
#[macro_export]
macro_rules! css_properties_accessors(
($macro: ident) => (
$macro!(
macro_rules! css_properties_accessors {
($macro_name: ident) => {
$macro_name! {
% for property in SHORTHANDS + LONGHANDS:
## Servo internal CSS properties are not accessible.
## FIXME: Add BinaryName WebIDL annotation (#4435).
@ -3150,9 +3150,9 @@ macro_rules! css_properties_accessors(
% endif
% endif
% endfor
)
)
)
}
}
}
pub fn longhands_from_shorthand(shorthand: &str) -> Option<Vec<String>> {
match shorthand {

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::ascii::AsciiExt;
use std::cmp::Ordering;
use std::collections::HashMap;
use std::hash::Hash;
use std::sync::Arc;
@ -183,14 +184,14 @@ impl SelectorMap {
match SelectorMap::get_id_name(&rule) {
Some(id_name) => {
self.id_hash.find_push(id_name, rule);
find_push(&mut self.id_hash, id_name, rule);
return;
}
None => {}
}
match SelectorMap::get_class_name(&rule) {
Some(class_name) => {
self.class_hash.find_push(class_name, rule);
find_push(&mut self.class_hash, class_name, rule);
return;
}
None => {}
@ -198,8 +199,8 @@ impl SelectorMap {
match SelectorMap::get_local_name(&rule) {
Some(LocalName { name, lower_name }) => {
self.local_name_hash.find_push(name, rule.clone());
self.lower_local_name_hash.find_push(lower_name, rule);
find_push(&mut self.local_name_hash, name, rule.clone());
find_push(&mut self.lower_local_name_hash, lower_name, rule);
return;
}
None => {}
@ -294,7 +295,7 @@ impl Stylist {
for &filename in ["user-agent.css", "servo.css", "presentational-hints.css"].iter() {
let ua_stylesheet = Stylesheet::from_bytes(
read_resource_file(&[filename]).unwrap().as_slice(),
Url::parse(format!("chrome:///{}", filename).as_slice()).unwrap(),
Url::parse(format!("chrome:///{:?}", filename).as_slice()).unwrap(),
None,
None,
Origin::UserAgent);
@ -512,7 +513,7 @@ impl PerPseudoElementSelectorMap {
}
}
#[deriving(Clone)]
#[derive(Clone)]
struct Rule {
// This is an Arc because Rule will essentially be cloned for every node
// that it matches. Selector contains an owned vector (through
@ -523,7 +524,7 @@ struct Rule {
/// A property declaration together with its precedence among rules of equal specificity so that
/// we can sort them.
#[deriving(Clone, Show)]
#[derive(Clone, Show)]
pub struct DeclarationBlock {
pub declarations: Arc<Vec<PropertyDeclaration>>,
source_order: uint,
@ -618,7 +619,7 @@ fn matches_compound_selector<'a,E,N>(selector: &CompoundSelector,
/// However since the selector "c1" raises
/// NotMatchedAndRestartFromClosestDescendant. So the selector
/// "b1 + c1 > b2 ~ " doesn't match and restart matching from "d1".
#[deriving(PartialEq, Eq, Copy)]
#[derive(PartialEq, Eq, Copy)]
enum SelectorMatchingResult {
Matched,
NotMatchedAndRestartFromClosestLaterSibling,
@ -758,7 +759,6 @@ fn matches_compound_selector_internal<'a,E,N>(selector: &CompoundSelector,
}
bitflags! {
#[deriving(Copy)]
flags CommonStyleAffectingAttributes: u8 {
const HIDDEN_ATTRIBUTE = 0x01,
const NO_WRAP_ATTRIBUTE = 0x02,
@ -773,7 +773,7 @@ pub struct CommonStyleAffectingAttributeInfo {
pub mode: CommonStyleAffectingAttributeMode,
}
#[deriving(Copy)]
#[derive(Copy)]
pub enum CommonStyleAffectingAttributeMode {
IsPresent(CommonStyleAffectingAttributes),
IsEqual(&'static str, CommonStyleAffectingAttributes),
@ -781,7 +781,7 @@ pub enum CommonStyleAffectingAttributeMode {
// NB: This must match the order in `layout::css::matching::CommonStyleAffectingAttributes`.
#[inline]
pub fn common_style_affecting_attributes() -> [CommonStyleAffectingAttributeInfo, ..5] {
pub fn common_style_affecting_attributes() -> [CommonStyleAffectingAttributeInfo; 5] {
[
CommonStyleAffectingAttributeInfo {
atom: atom!("hidden"),
@ -809,7 +809,7 @@ pub fn common_style_affecting_attributes() -> [CommonStyleAffectingAttributeInfo
/// Attributes that, if present, disable style sharing. All legacy HTML attributes must be in
/// either this list or `common_style_affecting_attributes`. See the comment in
/// `synthesize_presentational_hints_for_legacy_attributes`.
pub fn rare_style_affecting_attributes() -> [Atom, ..3] {
pub fn rare_style_affecting_attributes() -> [Atom; 3] {
[ atom!("bgcolor"), atom!("border"), atom!("colspan") ]
}
@ -1141,22 +1141,15 @@ fn matches_last_child<'a,E,N>(element: &N) -> bool where E: TElement<'a>, N: TNo
}
}
trait FindPush<K, V> {
fn find_push(&mut self, key: K, value: V);
}
impl<K: Eq + Hash, V> FindPush<K, V> for HashMap<K, Vec<V>> {
fn find_push(&mut self, key: K, value: V) {
match self.get_mut(&key) {
Some(vec) => {
vec.push(value);
return
}
None => {}
fn find_push(map: &mut HashMap<Atom, Vec<Rule>>, key: Atom, value: Rule) {
match map.get_mut(&key) {
Some(vec) => {
vec.push(value);
return
}
self.insert(key, vec![value]);
None => {}
}
map.insert(key, vec![value]);
}
#[cfg(test)]
@ -1223,7 +1216,7 @@ mod tests {
#[test]
fn test_get_local_name(){
let rules_list = get_mock_rules(&["img.foo", "#top", "IMG", "ImG"]);
let check = |i, names: Option<(&str, &str)>| {
let check = |&:i: uint, names: Option<(&str, &str)>| {
assert!(SelectorMap::get_local_name(&rules_list[i][0])
== names.map(|(name, lower_name)| LocalName {
name: Atom::from_slice(name),

View file

@ -5,7 +5,7 @@
use std::cmp;
use std::ascii::{AsciiExt, OwnedAsciiExt};
use std::sync::Arc;
use std::str::CowString;
use std::string::CowString;
use cssparser::{Token, Parser, parse_nth};
use string_cache::{Atom, Namespace};
@ -16,14 +16,14 @@ use namespaces::NamespaceMap;
use stylesheets::Origin;
#[deriving(PartialEq, Clone, Show)]
#[derive(PartialEq, Clone, Show)]
pub struct Selector {
pub compound_selectors: Arc<CompoundSelector>,
pub pseudo_element: Option<PseudoElement>,
pub specificity: u32,
}
#[deriving(Eq, PartialEq, Clone, Hash, Copy, Show)]
#[derive(Eq, PartialEq, Clone, Hash, Copy, Show)]
pub enum PseudoElement {
Before,
After,
@ -31,13 +31,13 @@ pub enum PseudoElement {
}
#[deriving(PartialEq, Clone, Show)]
#[derive(PartialEq, Clone, Show)]
pub struct CompoundSelector {
pub simple_selectors: Vec<SimpleSelector>,
pub next: Option<(Box<CompoundSelector>, Combinator)>, // c.next is left of c
}
#[deriving(PartialEq, Clone, Copy, Show)]
#[derive(PartialEq, Clone, Copy, Show)]
pub enum Combinator {
Child, // >
Descendant, // space
@ -45,7 +45,7 @@ pub enum Combinator {
LaterSibling, // ~
}
#[deriving(Eq, PartialEq, Clone, Hash, Show)]
#[derive(Eq, PartialEq, Clone, Hash, Show)]
pub enum SimpleSelector {
ID(Atom),
Class(Atom),
@ -85,27 +85,27 @@ pub enum SimpleSelector {
}
#[deriving(Eq, PartialEq, Clone, Hash, Copy, Show)]
#[derive(Eq, PartialEq, Clone, Hash, Copy, Show)]
pub enum CaseSensitivity {
CaseSensitive, // Selectors spec says language-defined, but HTML says sensitive.
CaseInsensitive,
}
#[deriving(Eq, PartialEq, Clone, Hash, Show)]
#[derive(Eq, PartialEq, Clone, Hash, Show)]
pub struct LocalName {
pub name: Atom,
pub lower_name: Atom,
}
#[deriving(Eq, PartialEq, Clone, Hash, Show)]
#[derive(Eq, PartialEq, Clone, Hash, Show)]
pub struct AttrSelector {
pub name: Atom,
pub lower_name: Atom,
pub namespace: NamespaceConstraint,
}
#[deriving(Eq, PartialEq, Clone, Hash, Show)]
#[derive(Eq, PartialEq, Clone, Hash, Show)]
pub enum NamespaceConstraint {
Any,
Specific(Namespace),
@ -288,7 +288,7 @@ fn parse_type_selector(context: &ParserContext, input: &mut Parser)
Some(name) => {
simple_selectors.push(SimpleSelector::LocalName(LocalName {
name: Atom::from_slice(name.as_slice()),
lower_name: Atom::from_slice(name.into_owned().into_ascii_lower().as_slice())
lower_name: Atom::from_slice(name.into_owned().into_ascii_lowercase().as_slice())
}))
}
None => (),
@ -299,7 +299,7 @@ fn parse_type_selector(context: &ParserContext, input: &mut Parser)
}
#[deriving(Show)]
#[derive(Show)]
enum SimpleSelectorParseResult {
SimpleSelector(SimpleSelector),
PseudoElement(PseudoElement),
@ -313,7 +313,7 @@ fn parse_qualified_name<'i, 't>
(context: &ParserContext, input: &mut Parser<'i, 't>,
in_attr_selector: bool)
-> Result<Option<(NamespaceConstraint, Option<CowString<'i>>)>, ()> {
let default_namespace = |local_name| {
let default_namespace = |:local_name| {
let namespace = match context.namespaces.default {
Some(ref ns) => NamespaceConstraint::Specific(ns.clone()),
None => NamespaceConstraint::Any,
@ -321,7 +321,7 @@ fn parse_qualified_name<'i, 't>
Ok(Some((namespace, local_name)))
};
let explicit_namespace = |input: &mut Parser<'i, 't>, namespace| {
let explicit_namespace = |&: input: &mut Parser<'i, 't>, namespace| {
match input.next_including_whitespace() {
Ok(Token::Delim('*')) if !in_attr_selector => {
Ok(Some((namespace, None)))
@ -383,7 +383,7 @@ fn parse_attribute_selector(context: &ParserContext, input: &mut Parser)
Some((_, None)) => unreachable!(),
Some((namespace, Some(local_name))) => AttrSelector {
namespace: namespace,
lower_name: Atom::from_slice(local_name.as_slice().to_ascii_lower().as_slice()),
lower_name: Atom::from_slice(local_name.as_slice().to_ascii_lowercase().as_slice()),
name: Atom::from_slice(local_name.as_slice()),
},
};
@ -408,7 +408,7 @@ fn parse_attribute_selector(context: &ParserContext, input: &mut Parser)
// [foo|=bar]
Ok(Token::DashMatch) => {
let value = try!(parse_value(input));
let dashing_value = format!("{}-", value);
let dashing_value = format!("{:?}-", value);
Ok(SimpleSelector::AttrDashMatch(attr, value, dashing_value))
}
// [foo^=bar]
@ -507,7 +507,7 @@ fn parse_functional_pseudo_class(context: &ParserContext,
name: &str,
inside_negation: bool)
-> Result<SimpleSelector,()> {
match_ignore_ascii_case! { name:
match_ignore_ascii_case! { name,
"nth-child" => parse_nth_pseudo_class(input, SimpleSelector::NthChild),
"nth-of-type" => parse_nth_pseudo_class(input, SimpleSelector::NthOfType),
"nth-last-child" => parse_nth_pseudo_class(input, SimpleSelector::NthLastChild),
@ -524,8 +524,8 @@ fn parse_functional_pseudo_class(context: &ParserContext,
}
fn parse_nth_pseudo_class(input: &mut Parser, selector: |i32, i32| -> SimpleSelector)
-> Result<SimpleSelector, ()> {
fn parse_nth_pseudo_class<F>(input: &mut Parser, selector: F) -> Result<SimpleSelector, ()>
where F: FnOnce(i32, i32) -> SimpleSelector {
let (a, b) = try!(parse_nth(input));
Ok(selector(a, b))
}
@ -566,7 +566,7 @@ fn parse_one_simple_selector(context: &ParserContext,
Ok(Token::Ident(name)) => {
match parse_simple_pseudo_class(context, name.as_slice()) {
Err(()) => {
let pseudo_element = match_ignore_ascii_case! { name:
let pseudo_element = match_ignore_ascii_case! { name,
// Supported CSS 2.1 pseudo-elements only.
// ** Do not add to this list! **
"before" => PseudoElement::Before,
@ -607,7 +607,7 @@ fn parse_one_simple_selector(context: &ParserContext,
}
fn parse_simple_pseudo_class(context: &ParserContext, name: &str) -> Result<SimpleSelector,()> {
match_ignore_ascii_case! { name:
match_ignore_ascii_case! { name,
"any-link" => Ok(SimpleSelector::AnyLink),
"link" => Ok(SimpleSelector::Link),
"visited" => Ok(SimpleSelector::Visited),
@ -635,7 +635,7 @@ fn parse_simple_pseudo_class(context: &ParserContext, name: &str) -> Result<Simp
}
fn parse_pseudo_element(name: &str) -> Result<PseudoElement, ()> {
match_ignore_ascii_case! { name:
match_ignore_ascii_case! { name,
"before" => Ok(PseudoElement::Before),
"after" => Ok(PseudoElement::After)
_ => Err(())
@ -673,7 +673,7 @@ mod tests {
#[test]
fn test_parsing() {
assert_eq!(parse(""), Err(()))
assert_eq!(parse(""), Err(())) ;
assert_eq!(parse("EeÉ"), Ok(vec!(Selector {
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: vec!(SimpleSelector::LocalName(LocalName {
@ -683,7 +683,7 @@ mod tests {
}),
pseudo_element: None,
specificity: specificity(0, 0, 1),
})))
})));
assert_eq!(parse(".foo"), Ok(vec!(Selector {
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: vec!(SimpleSelector::Class(Atom::from_slice("foo"))),
@ -691,7 +691,7 @@ mod tests {
}),
pseudo_element: None,
specificity: specificity(0, 1, 0),
})))
})));
assert_eq!(parse("#bar"), Ok(vec!(Selector {
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: vec!(SimpleSelector::ID(Atom::from_slice("bar"))),
@ -699,7 +699,7 @@ mod tests {
}),
pseudo_element: None,
specificity: specificity(1, 0, 0),
})))
})));
assert_eq!(parse("e.foo#bar"), Ok(vec!(Selector {
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: vec!(SimpleSelector::LocalName(LocalName {
@ -711,7 +711,7 @@ mod tests {
}),
pseudo_element: None,
specificity: specificity(1, 1, 1),
})))
})));
assert_eq!(parse("e.foo #bar"), Ok(vec!(Selector {
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: vec!(SimpleSelector::ID(Atom::from_slice("bar"))),
@ -725,7 +725,7 @@ mod tests {
}),
pseudo_element: None,
specificity: specificity(1, 1, 1),
})))
})));
// Default namespace does not apply to attribute selectors
// https://github.com/mozilla/servo/pull/1652
let mut namespaces = NamespaceMap::new();
@ -740,7 +740,7 @@ mod tests {
}),
pseudo_element: None,
specificity: specificity(0, 1, 0),
})))
})));
// Default namespace does not apply to attribute selectors
// https://github.com/mozilla/servo/pull/1652
namespaces.default = Some(ns!(MathML));
@ -755,7 +755,7 @@ mod tests {
}),
pseudo_element: None,
specificity: specificity(0, 1, 0),
})))
})));
// Default namespace does apply to type selectors
assert_eq!(parse_ns("e", namespaces), Ok(vec!(Selector {
compound_selectors: Arc::new(CompoundSelector {
@ -769,7 +769,7 @@ mod tests {
}),
pseudo_element: None,
specificity: specificity(0, 0, 1),
})))
})));
// https://github.com/mozilla/servo/issues/1723
assert_eq!(parse("::before"), Ok(vec!(Selector {
compound_selectors: Arc::new(CompoundSelector {
@ -778,7 +778,7 @@ mod tests {
}),
pseudo_element: Some(PseudoElement::Before),
specificity: specificity(0, 0, 1),
})))
})));
assert_eq!(parse("div :after"), Ok(vec!(Selector {
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: vec!(),
@ -791,7 +791,7 @@ mod tests {
}),
pseudo_element: Some(PseudoElement::After),
specificity: specificity(0, 0, 2),
})))
})));
assert_eq!(parse("#d1 > .ok"), Ok(vec![Selector {
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: vec![

View file

@ -15,11 +15,11 @@ use selectors::{Selector, parse_selector_list};
use parser::ParserContext;
use properties::{PropertyDeclarationBlock, parse_property_declaration_list};
use namespaces::{NamespaceMap, parse_namespace_rule};
use media_queries::{mod, Device, MediaQueryList, parse_media_query_list};
use media_queries::{self, Device, MediaQueryList, parse_media_query_list};
use font_face::{FontFaceRule, Source, parse_font_face_block, iter_font_face_rules_inner};
#[deriving(Clone, PartialEq, Eq, Copy, Show)]
#[derive(Clone, PartialEq, Eq, Copy, Show)]
pub enum Origin {
UserAgent,
Author,
@ -27,7 +27,7 @@ pub enum Origin {
}
#[deriving(Show, PartialEq)]
#[derive(Show, PartialEq)]
pub struct Stylesheet {
/// List of rules in the order they were found (important for
/// cascading order)
@ -36,7 +36,7 @@ pub struct Stylesheet {
}
#[deriving(Show, PartialEq)]
#[derive(Show, PartialEq)]
pub enum CSSRule {
Charset(String),
Namespace(Option<String>, Namespace),
@ -45,14 +45,14 @@ pub enum CSSRule {
FontFace(FontFaceRule),
}
#[deriving(Show, PartialEq)]
#[derive(Show, PartialEq)]
pub struct MediaRule {
pub media_queries: MediaQueryList,
pub rules: Vec<CSSRule>,
}
#[deriving(Show, PartialEq)]
#[derive(Show, PartialEq)]
pub struct StyleRule {
pub selectors: Vec<Selector>,
pub declarations: PropertyDeclarationBlock,
@ -60,7 +60,7 @@ pub struct StyleRule {
impl Stylesheet {
pub fn from_bytes_iter<I: Iterator<Vec<u8>>>(
pub fn from_bytes_iter<I: Iterator<Item=Vec<u8>>>(
mut input: I, base_url: Url, protocol_encoding_label: Option<&str>,
environment_encoding: Option<EncodingRef>, origin: Origin) -> Stylesheet {
let mut bytes = vec!();
@ -122,7 +122,7 @@ struct MainRuleParser<'a, 'b: 'a> {
}
#[deriving(Eq, PartialEq, Ord, PartialOrd)]
#[derive(Eq, PartialEq, Ord, PartialOrd)]
enum State {
Start = 1,
Imports = 2,
@ -140,7 +140,7 @@ enum AtRulePrelude {
impl<'a, 'b> AtRuleParser<AtRulePrelude, CSSRule> for MainRuleParser<'a, 'b> {
fn parse_prelude(&mut self, name: &str, input: &mut Parser)
-> Result<AtRuleType<AtRulePrelude, CSSRule>, ()> {
match_ignore_ascii_case! { name:
match_ignore_ascii_case! { name,
"charset" => {
if self.state <= State::Start {
// Valid @charset rules are just ignored
@ -174,7 +174,7 @@ impl<'a, 'b> AtRuleParser<AtRulePrelude, CSSRule> for MainRuleParser<'a, 'b> {
self.state = State::Body;
match_ignore_ascii_case! { name:
match_ignore_ascii_case! { name,
"media" => {
let media_queries = parse_media_query_list(input);
Ok(AtRuleType::WithBlock(AtRulePrelude::Media(media_queries)))
@ -217,13 +217,13 @@ impl<'a, 'b> QualifiedRuleParser<Vec<Selector>, CSSRule> for MainRuleParser<'a,
}
pub fn iter_style_rules<'a>(rules: &[CSSRule], device: &media_queries::Device,
callback: |&StyleRule|) {
pub fn iter_style_rules<'a, F>(rules: &[CSSRule], device: &media_queries::Device,
callback: &mut F) where F: FnMut(&StyleRule) {
for rule in rules.iter() {
match *rule {
CSSRule::Style(ref rule) => callback(rule),
CSSRule::Media(ref rule) => if rule.media_queries.evaluate(device) {
iter_style_rules(rule.rules.as_slice(), device, |s| callback(s))
iter_style_rules(rule.rules.as_slice(), device, callback)
},
CSSRule::FontFace(..) |
CSSRule::Charset(..) |
@ -232,7 +232,7 @@ pub fn iter_style_rules<'a>(rules: &[CSSRule], device: &media_queries::Device,
}
}
pub fn iter_stylesheet_media_rules(stylesheet: &Stylesheet, callback: |&MediaRule|) {
pub fn iter_stylesheet_media_rules<F>(stylesheet: &Stylesheet, mut callback: F) where F: FnMut(&MediaRule) {
for rule in stylesheet.rules.iter() {
match *rule {
CSSRule::Media(ref rule) => callback(rule),
@ -245,15 +245,15 @@ pub fn iter_stylesheet_media_rules(stylesheet: &Stylesheet, callback: |&MediaRul
}
#[inline]
pub fn iter_stylesheet_style_rules(stylesheet: &Stylesheet, device: &media_queries::Device,
callback: |&StyleRule|) {
iter_style_rules(stylesheet.rules.as_slice(), device, callback)
pub fn iter_stylesheet_style_rules<F>(stylesheet: &Stylesheet, device: &media_queries::Device,
mut callback: F) where F: FnMut(&StyleRule) {
iter_style_rules(stylesheet.rules.as_slice(), device, &mut callback)
}
#[inline]
pub fn iter_font_face_rules(stylesheet: &Stylesheet, device: &Device,
callback: |family: &str, source: &Source|) {
pub fn iter_font_face_rules<F>(stylesheet: &Stylesheet, device: &Device,
callback: &F) where F: Fn(&str, &Source) {
iter_font_face_rules_inner(stylesheet.rules.as_slice(), device, callback)
}
@ -265,6 +265,7 @@ fn test_parse_stylesheet() {
use selectors::*;
use string_cache::Atom;
use properties::{PropertyDeclaration, DeclaredValue, longhands};
use std::borrow::ToOwned;
let css = r"
@namespace url(http://www.w3.org/1999/xhtml);
@ -293,7 +294,7 @@ fn test_parse_stylesheet() {
name: atom!(type),
lower_name: atom!(type),
namespace: NamespaceConstraint::Specific(ns!("")),
}, "hidden".into_string(), CaseSensitivity::CaseInsensitive)
}, "hidden".to_owned(), CaseSensitivity::CaseInsensitive)
],
next: None,
}),
@ -374,7 +375,7 @@ fn test_parse_stylesheet() {
PropertyDeclaration::BackgroundPosition(DeclaredValue::Initial),
PropertyDeclaration::BackgroundColor(DeclaredValue::SpecifiedValue(
longhands::background_color::SpecifiedValue {
authored: Some("blue".into_string()),
authored: Some("blue".to_owned()),
parsed: cssparser::Color::RGBA(cssparser::RGBA {
red: 0., green: 0., blue: 1., alpha: 1.
}),

View file

@ -3,23 +3,22 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![allow(non_camel_case_types)]
#![macro_escape]
macro_rules! define_css_keyword_enum {
($name: ident: $( $css: expr => $variant: ident ),+,) => {
define_css_keyword_enum!($name: $( $css => $variant ),+)
define_css_keyword_enum!($name: $( $css => $variant ),+);
};
($name: ident: $( $css: expr => $variant: ident ),+) => {
#[allow(non_camel_case_types)]
#[deriving(Clone, Eq, PartialEq, FromPrimitive, Copy)]
#[derive(Clone, Eq, PartialEq, FromPrimitive, Copy)]
pub enum $name {
$( $variant ),+
}
impl $name {
pub fn parse(input: &mut ::cssparser::Parser) -> Result<$name, ()> {
match_ignore_ascii_case! { try!(input.expect_ident()):
match_ignore_ascii_case! { try!(input.expect_ident()),
$( $css => Ok($name::$variant) ),+
_ => Err(())
}
@ -61,7 +60,7 @@ pub mod specified {
use super::CSSFloat;
use super::computed;
#[deriving(Clone, PartialEq)]
#[derive(Clone, PartialEq)]
pub struct CSSColor {
pub parsed: cssparser::Color,
pub authored: Option<String>,
@ -94,7 +93,7 @@ pub mod specified {
}
}
#[deriving(Clone, PartialEq)]
#[derive(Clone, PartialEq)]
pub struct CSSRGBA {
pub parsed: cssparser::RGBA,
pub authored: Option<String>,
@ -112,7 +111,7 @@ pub mod specified {
}
}
#[deriving(Clone, PartialEq)]
#[derive(Clone, PartialEq)]
pub struct CSSImage(pub Option<Image>);
impl fmt::Show for CSSImage {
@ -128,7 +127,7 @@ pub mod specified {
}
}
#[deriving(Clone, PartialEq, Copy)]
#[derive(Clone, PartialEq, Copy)]
pub enum Length {
Au(Au), // application units
Em(CSSFloat),
@ -184,7 +183,7 @@ pub mod specified {
Length::parse_internal(input, /* negative_ok = */ false)
}
pub fn parse_dimension(value: CSSFloat, unit: &str) -> Result<Length, ()> {
match_ignore_ascii_case! { unit:
match_ignore_ascii_case! { unit,
"px" => Ok(Length::from_px(value)),
"in" => Ok(Length::Au(Au((value * AU_PER_IN) as i32))),
"cm" => Ok(Length::Au(Au((value * AU_PER_CM) as i32))),
@ -204,7 +203,7 @@ pub mod specified {
}
#[deriving(Clone, PartialEq, Copy)]
#[derive(Clone, PartialEq, Copy)]
pub enum LengthOrPercentage {
Length(Length),
Percentage(CSSFloat), // [0 .. 100%] maps to [0.0 .. 1.0]
@ -251,7 +250,7 @@ pub mod specified {
}
}
#[deriving(Clone, PartialEq, Copy)]
#[derive(Clone, PartialEq, Copy)]
pub enum LengthOrPercentageOrAuto {
Length(Length),
Percentage(CSSFloat), // [0 .. 100%] maps to [0.0 .. 1.0]
@ -302,7 +301,7 @@ pub mod specified {
}
}
#[deriving(Clone, PartialEq, Copy)]
#[derive(Clone, PartialEq, Copy)]
pub enum LengthOrPercentageOrNone {
Length(Length),
Percentage(CSSFloat), // [0 .. 100%] maps to [0.0 .. 1.0]
@ -355,7 +354,7 @@ pub mod specified {
}
// http://dev.w3.org/csswg/css2/colors.html#propdef-background-position
#[deriving(Clone, PartialEq, Copy)]
#[derive(Clone, PartialEq, Copy)]
pub enum PositionComponent {
Length(Length),
Percentage(CSSFloat), // [0 .. 100%] maps to [0.0 .. 1.0]
@ -379,7 +378,7 @@ pub mod specified {
Ok(PositionComponent::Length(Length::Au(Au(0))))
}
Token::Ident(value) => {
match_ignore_ascii_case! { value:
match_ignore_ascii_case! { value,
"center" => Ok(PositionComponent::Center),
"left" => Ok(PositionComponent::Left),
"right" => Ok(PositionComponent::Right),
@ -405,7 +404,7 @@ pub mod specified {
}
}
#[deriving(Clone, PartialEq, PartialOrd, Copy)]
#[derive(Clone, PartialEq, PartialOrd, Copy)]
pub struct Angle(pub CSSFloat);
impl fmt::Show for Angle {
@ -435,7 +434,7 @@ pub mod specified {
pub fn parse(input: &mut Parser) -> Result<Angle, ()> {
match try!(input.next()) {
Token::Dimension(value, unit) => {
match_ignore_ascii_case! { unit:
match_ignore_ascii_case! { unit,
"deg" => Ok(Angle(value.value * RAD_PER_DEG)),
"grad" => Ok(Angle(value.value * RAD_PER_GRAD)),
"turn" => Ok(Angle(value.value * RAD_PER_TURN)),
@ -450,7 +449,7 @@ pub mod specified {
}
/// Specified values for an image according to CSS-IMAGES.
#[deriving(Clone, PartialEq)]
#[derive(Clone, PartialEq)]
pub enum Image {
Url(Url),
LinearGradient(LinearGradient),
@ -481,7 +480,7 @@ pub mod specified {
Ok(Image::Url(context.parse_url(url.as_slice())))
}
Token::Function(name) => {
match_ignore_ascii_case! { name:
match_ignore_ascii_case! { name,
"linear-gradient" => {
Ok(Image::LinearGradient(try!(
input.parse_nested_block(LinearGradient::parse_function))))
@ -505,7 +504,7 @@ pub mod specified {
}
/// Specified values for a CSS linear gradient.
#[deriving(Clone, PartialEq)]
#[derive(Clone, PartialEq)]
pub struct LinearGradient {
/// The angle or corner of the gradient.
pub angle_or_corner: AngleOrCorner,
@ -532,7 +531,7 @@ pub mod specified {
}
/// Specified values for an angle or a corner in a linear gradient.
#[deriving(Clone, PartialEq, Copy)]
#[derive(Clone, PartialEq, Copy)]
pub enum AngleOrCorner {
Angle(Angle),
Corner(HorizontalDirection, VerticalDirection),
@ -558,7 +557,7 @@ pub mod specified {
}
/// Specified values for one color stop in a linear gradient.
#[deriving(Clone, PartialEq)]
#[derive(Clone, PartialEq)]
pub struct ColorStop {
/// The color of this stop.
pub color: CSSColor,
@ -583,8 +582,8 @@ pub mod specified {
}
}
define_css_keyword_enum!(HorizontalDirection: "left" => Left, "right" => Right)
define_css_keyword_enum!(VerticalDirection: "top" => Top, "bottom" => Bottom)
define_css_keyword_enum!(HorizontalDirection: "left" => Left, "right" => Right);
define_css_keyword_enum!(VerticalDirection: "top" => Top, "bottom" => Bottom);
fn parse_one_color_stop(input: &mut Parser) -> Result<ColorStop, ()> {
Ok(ColorStop {
@ -644,7 +643,7 @@ pub mod specified {
pub fn parse_border_width(input: &mut Parser) -> Result<Length, ()> {
input.try(Length::parse_non_negative).or_else(|()| {
match_ignore_ascii_case! { try!(input.expect_ident()):
match_ignore_ascii_case! { try!(input.expect_ident()),
"thin" => Ok(Length::from_px(1.)),
"medium" => Ok(Length::from_px(3.)),
"thick" => Ok(Length::from_px(5.))
@ -742,7 +741,7 @@ pub mod computed {
}
}
#[deriving(PartialEq, Clone, Copy)]
#[derive(PartialEq, Clone, Copy)]
pub enum LengthOrPercentage {
Length(Au),
Percentage(CSSFloat),
@ -750,7 +749,7 @@ pub mod computed {
impl fmt::Show for LengthOrPercentage {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&LengthOrPercentage::Length(length) => write!(f, "{}", length),
&LengthOrPercentage::Length(length) => write!(f, "{:?}", length),
&LengthOrPercentage::Percentage(percentage) => write!(f, "{}%", percentage * 100.),
}
}
@ -767,7 +766,7 @@ pub mod computed {
}
}
#[deriving(PartialEq, Clone, Copy)]
#[derive(PartialEq, Clone, Copy)]
pub enum LengthOrPercentageOrAuto {
Length(Au),
Percentage(CSSFloat),
@ -776,7 +775,7 @@ pub mod computed {
impl fmt::Show for LengthOrPercentageOrAuto {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&LengthOrPercentageOrAuto::Length(length) => write!(f, "{}", length),
&LengthOrPercentageOrAuto::Length(length) => write!(f, "{:?}", length),
&LengthOrPercentageOrAuto::Percentage(percentage) => write!(f, "{}%", percentage * 100.),
&LengthOrPercentageOrAuto::Auto => write!(f, "auto"),
}
@ -795,7 +794,7 @@ pub mod computed {
}
}
#[deriving(PartialEq, Clone, Copy)]
#[derive(PartialEq, Clone, Copy)]
pub enum LengthOrPercentageOrNone {
Length(Au),
Percentage(CSSFloat),
@ -804,7 +803,7 @@ pub mod computed {
impl fmt::Show for LengthOrPercentageOrNone {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&LengthOrPercentageOrNone::Length(length) => write!(f, "{}", length),
&LengthOrPercentageOrNone::Length(length) => write!(f, "{:?}", length),
&LengthOrPercentageOrNone::Percentage(percentage) => write!(f, "{}%", percentage * 100.),
&LengthOrPercentageOrNone::None => write!(f, "none"),
}
@ -824,7 +823,7 @@ pub mod computed {
}
/// Computed values for an image according to CSS-IMAGES.
#[deriving(Clone, PartialEq)]
#[derive(Clone, PartialEq)]
pub enum Image {
Url(Url),
LinearGradient(LinearGradient),
@ -834,13 +833,13 @@ pub mod computed {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&Image::Url(ref url) => write!(f, "url(\"{}\")", url),
&Image::LinearGradient(ref grad) => write!(f, "linear-gradient({})", grad),
&Image::LinearGradient(ref grad) => write!(f, "linear-gradient({:?})", grad),
}
}
}
/// Computed values for a CSS linear gradient.
#[deriving(Clone, PartialEq)]
#[derive(Clone, PartialEq)]
pub struct LinearGradient {
/// The angle or corner of the gradient.
pub angle_or_corner: AngleOrCorner,
@ -851,16 +850,16 @@ pub mod computed {
impl fmt::Show for LinearGradient {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let _ = write!(f, "{}", self.angle_or_corner);
let _ = write!(f, "{:?}", self.angle_or_corner);
for stop in self.stops.iter() {
let _ = write!(f, ", {}", stop);
let _ = write!(f, ", {:?}", stop);
}
Ok(())
}
}
/// Computed values for one color stop in a linear gradient.
#[deriving(Clone, PartialEq, Copy)]
#[derive(Clone, PartialEq, Copy)]
pub struct ColorStop {
/// The color of this stop.
pub color: CSSColor,
@ -872,9 +871,9 @@ pub mod computed {
impl fmt::Show for ColorStop {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let _ = write!(f, "{}", self.color);
let _ = write!(f, "{:?}", self.color);
self.position.map(|pos| {
let _ = write!(f, " {}", pos);
let _ = write!(f, " {:?}", pos);
});
Ok(())
}