mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
Update to rust-cssparser 0.4.0
This commit is contained in:
parent
021f441d24
commit
69d398f29a
14 changed files with 141 additions and 136 deletions
|
@ -18,20 +18,13 @@ path = "../util"
|
|||
[dependencies.style_traits]
|
||||
path = "../style_traits"
|
||||
|
||||
[dependencies.selectors]
|
||||
git = "https://github.com/servo/rust-selectors"
|
||||
features = ["unstable"]
|
||||
|
||||
[dependencies.cssparser]
|
||||
version = "0.3.9"
|
||||
features = [ "serde-serialization" ]
|
||||
|
||||
[dependencies.url]
|
||||
version = "0.2"
|
||||
features = [ "serde_serialization" ]
|
||||
|
||||
[dependencies]
|
||||
app_units = {version = "0.1", features = ["plugins"]}
|
||||
cssparser = { version = "0.4", features = [ "serde-serialization" ] }
|
||||
log = "0.3"
|
||||
encoding = "0.2"
|
||||
fnv = "1.0"
|
||||
|
@ -40,6 +33,7 @@ matches = "0.1"
|
|||
bitflags = "0.3"
|
||||
num = "0.1.24"
|
||||
lazy_static = "0.1.10"
|
||||
selectors = { version = "0.2", features = ["unstable"] }
|
||||
smallvec = "0.1"
|
||||
string_cache = "0.1"
|
||||
string_cache_plugin = "0.1"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use computed_values::font_family::FontFamily;
|
||||
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, Token};
|
||||
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
|
||||
use parser::{ParserContext, log_css_error};
|
||||
use properties::longhands::font_family::parse_one_family;
|
||||
use std::ascii::AsciiExt;
|
||||
|
@ -106,23 +106,12 @@ fn parse_one_non_generic_family_name(input: &mut Parser) -> Result<Atom, ()> {
|
|||
|
||||
|
||||
fn parse_one_src(context: &ParserContext, input: &mut Parser) -> Result<Source, ()> {
|
||||
let url = match input.next() {
|
||||
// Parsing url()
|
||||
Ok(Token::Url(url)) => {
|
||||
UrlParser::new().base_url(context.base_url).parse(&url).unwrap_or_else(
|
||||
|_error| Url::parse("about:invalid").unwrap())
|
||||
},
|
||||
// Parsing local() with early return
|
||||
Ok(Token::Function(name)) => {
|
||||
if name.eq_ignore_ascii_case("local") {
|
||||
return Ok(Source::Local(try!(input.parse_nested_block(|input| {
|
||||
parse_one_non_generic_family_name(input)
|
||||
}))))
|
||||
}
|
||||
return Err(())
|
||||
},
|
||||
_ => return Err(())
|
||||
};
|
||||
if input.try(|input| input.expect_function_matching("local")).is_ok() {
|
||||
return Ok(Source::Local(try!(input.parse_nested_block(parse_one_non_generic_family_name))))
|
||||
}
|
||||
let url = try!(input.expect_url());
|
||||
let url = UrlParser::new().base_url(context.base_url).parse(&url).unwrap_or_else(
|
||||
|_error| Url::parse("about:invalid").unwrap());
|
||||
|
||||
// Parsing optional format()
|
||||
let format_hints = if input.try(|input| input.expect_function_matching("format")).is_ok() {
|
||||
|
|
|
@ -1138,6 +1138,7 @@ pub mod longhands {
|
|||
use std::fmt;
|
||||
use url::Url;
|
||||
use values::computed::Context;
|
||||
use values::LocalToCss;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub enum SpecifiedValue {
|
||||
|
@ -1149,9 +1150,7 @@ pub mod longhands {
|
|||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
SpecifiedValue::None => dest.write_str("none"),
|
||||
SpecifiedValue::Url(ref url) => {
|
||||
Token::Url(url.to_string().into()).to_css(dest)
|
||||
}
|
||||
SpecifiedValue::Url(ref url) => url.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1160,6 +1159,7 @@ pub mod longhands {
|
|||
use cssparser::{ToCss, Token};
|
||||
use std::fmt;
|
||||
use url::Url;
|
||||
use values::LocalToCss;
|
||||
|
||||
#[derive(Clone, PartialEq, HeapSizeOf)]
|
||||
pub struct T(pub Option<Url>);
|
||||
|
@ -1168,7 +1168,7 @@ pub mod longhands {
|
|||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self.0 {
|
||||
None => dest.write_str("none"),
|
||||
Some(ref url) => Token::Url(url.to_string().into()).to_css(dest)
|
||||
Some(ref url) => url.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1359,6 +1359,7 @@ pub mod longhands {
|
|||
use std::fmt;
|
||||
use values::computed::Context;
|
||||
use values::specified::Image;
|
||||
use values::LocalToCss;
|
||||
|
||||
pub mod computed_value {
|
||||
use values::computed;
|
||||
|
@ -1370,8 +1371,7 @@ pub mod longhands {
|
|||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self.0 {
|
||||
None => dest.write_str("none"),
|
||||
Some(computed::Image::Url(ref url)) =>
|
||||
::cssparser::Token::Url(url.to_string().into()).to_css(dest),
|
||||
Some(computed::Image::Url(ref url)) => url.to_css(dest),
|
||||
Some(computed::Image::LinearGradient(ref gradient)) =>
|
||||
gradient.to_css(dest)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
pub use cssparser::RGBA;
|
||||
|
||||
use app_units::Au;
|
||||
use std::fmt;
|
||||
use cssparser::CssStringWriter;
|
||||
use std::fmt::{self, Write};
|
||||
use url::Url;
|
||||
|
||||
|
||||
// This is a re-implementation of the ToCss trait in cssparser.
|
||||
// It's done here because the app_units crate shouldn't depend
|
||||
|
@ -64,6 +67,22 @@ macro_rules! define_numbered_css_keyword_enum {
|
|||
}
|
||||
}
|
||||
|
||||
/// The real ToCss trait can’t be implemented for Url
|
||||
/// since neither rust-url or rust-cssparser depend on the other.
|
||||
pub trait LocalToCss {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write;
|
||||
}
|
||||
|
||||
impl LocalToCss for Url {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(dest.write_str("url(\""));
|
||||
try!(write!(CssStringWriter::new(dest), "{}", self));
|
||||
try!(dest.write_str("\")"));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub type CSSFloat = f32;
|
||||
|
||||
pub const FONT_MEDIUM_PX: i32 = 16;
|
||||
|
@ -1177,20 +1196,16 @@ pub mod specified {
|
|||
|
||||
impl Image {
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<Image, ()> {
|
||||
match try!(input.next()) {
|
||||
Token::Url(url) => {
|
||||
Ok(Image::Url(context.parse_url(&url)))
|
||||
}
|
||||
Token::Function(name) => {
|
||||
match_ignore_ascii_case! { name,
|
||||
"linear-gradient" => {
|
||||
Ok(Image::LinearGradient(try!(
|
||||
input.parse_nested_block(LinearGradient::parse_function))))
|
||||
}
|
||||
_ => Err(())
|
||||
if let Ok(url) = input.try(|input| input.expect_url()) {
|
||||
Ok(Image::Url(context.parse_url(&url)))
|
||||
} else {
|
||||
match_ignore_ascii_case! { try!(input.expect_function()),
|
||||
"linear-gradient" => {
|
||||
Ok(Image::LinearGradient(try!(
|
||||
input.parse_nested_block(LinearGradient::parse_function))))
|
||||
}
|
||||
_ => Err(())
|
||||
}
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue