Auto merge of #15552 - servo:cssparserup, r=nox

Update cssparser to 0.9

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15552)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-02-15 03:58:38 -08:00 committed by GitHub
commit 216a89f776
17 changed files with 72 additions and 82 deletions

View file

@ -12,7 +12,7 @@ path = "lib.rs"
[dependencies]
azure = {git = "https://github.com/servo/rust-azure", features = ["plugins"]}
canvas_traits = {path = "../canvas_traits"}
cssparser = {version = "0.8", features = ["heap_size", "serde-serialization"]}
cssparser = {version = "0.9", features = ["heap_size", "serde-serialization"]}
euclid = "0.10.1"
gleam = "0.2.8"
ipc-channel = "0.5"

View file

@ -10,7 +10,7 @@ name = "canvas_traits"
path = "lib.rs"
[dependencies]
cssparser = {version = "0.8", features = ["heap_size", "serde-serialization"]}
cssparser = {version = "0.9", features = ["heap_size", "serde-serialization"]}
euclid = "0.10.1"
heapsize = "0.3.0"
heapsize_derive = "0.1"

View file

@ -14,7 +14,7 @@ app_units = "0.3"
atomic_refcell = "0.1"
bitflags = "0.7"
canvas_traits = {path = "../canvas_traits"}
cssparser = {version = "0.8", features = ["heap_size", "serde-serialization"]}
cssparser = {version = "0.9", features = ["heap_size", "serde-serialization"]}
euclid = "0.10.1"
fnv = "1.0"
gfx = {path = "../gfx"}

View file

@ -11,7 +11,7 @@ path = "lib.rs"
[dependencies]
bitflags = "0.7"
cssparser = {version = "0.8", features = ["heap_size", "serde-serialization"]}
cssparser = {version = "0.9", features = ["heap_size", "serde-serialization"]}
heapsize = "0.3.0"
heapsize_derive = "0.1"
plugins = {path = "../plugins"}

View file

@ -34,7 +34,7 @@ byteorder = "1.0"
canvas_traits = {path = "../canvas_traits"}
caseless = "0.1.0"
cookie = {version = "0.2.5", features = ["serialize-rustc"]}
cssparser = {version = "0.8", features = ["heap_size", "serde-serialization"]}
cssparser = {version = "0.9", features = ["heap_size", "serde-serialization"]}
deny_public_fields = {path = "../deny_public_fields"}
devtools_traits = {path = "../devtools_traits"}
domobject_derive = {path = "../domobject_derive"}

View file

@ -13,7 +13,7 @@ path = "lib.rs"
app_units = "0.3"
atomic_refcell = "0.1"
canvas_traits = {path = "../canvas_traits"}
cssparser = {version = "0.8", features = ["heap_size", "serde-serialization"]}
cssparser = {version = "0.9", features = ["heap_size", "serde-serialization"]}
euclid = "0.10.1"
gfx_traits = {path = "../gfx_traits"}
heapsize = "0.3.0"

View file

@ -18,5 +18,5 @@ path = "lib.rs"
[dependencies]
bitflags = "0.7"
matches = "0.1"
cssparser = ">=0.6, <0.9"
cssparser = "0.9"
fnv = "1.0"

View file

@ -26,7 +26,7 @@ app_units = "0.3"
atomic_refcell = "0.1"
bitflags = "0.7"
cfg-if = "0.1.0"
cssparser = "0.8"
cssparser = "0.9"
encoding = "0.2"
euclid = "0.10.1"
fnv = "1.0"

View file

@ -12,6 +12,7 @@
use computed_values::{font_style, font_weight, font_stretch};
use computed_values::font_family::FamilyName;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
#[cfg(feature = "gecko")] use cssparser::UnicodeRange;
use parser::{ParserContext, log_css_error, Parse};
use std::fmt;
use std::iter;
@ -238,7 +239,7 @@ macro_rules! font_face_descriptors {
dest.write_str("@font-face {\n")?;
$(
dest.write_str(concat!(" ", $m_name, ": "))?;
self.$m_ident.to_css(dest)?;
ToCss::to_css(&self.$m_ident, dest)?;
dest.write_str(";\n")?;
)*
$(
@ -247,7 +248,7 @@ macro_rules! font_face_descriptors {
// But it can be false for other descriptors.
if self.$o_ident != $o_initial {
dest.write_str(concat!(" ", $o_name, ": "))?;
self.$o_ident.to_css(dest)?;
ToCss::to_css(&self.$o_ident, dest)?;
dest.write_str(";\n")?;
}
)*
@ -298,8 +299,8 @@ font_face_descriptors! {
"font-stretch" stretch: font_stretch::T = font_stretch::T::normal,
/// The ranges of code points outside of which this font face should not be used.
"unicode-range" unicode_range: Vec<unicode_range::Range> = vec![
unicode_range::Range { start: 0, end: unicode_range::MAX }
"unicode-range" unicode_range: Vec<UnicodeRange> = vec![
UnicodeRange { start: 0, end: 0x10FFFF }
],
]
}
@ -316,51 +317,3 @@ font_face_descriptors! {
optional descriptors = [
]
}
/// https://drafts.csswg.org/css-fonts/#unicode-range-desc
#[cfg(feature = "gecko")]
pub mod unicode_range {
use cssparser::{Parser, Token};
use parser::{ParserContext, Parse};
use std::fmt;
use style_traits::{ToCss, OneOrMoreCommaSeparated};
/// Maximum value of the end of a range
pub const MAX: u32 = ::std::char::MAX as u32;
/// A single range: https://drafts.csswg.org/css-fonts/#urange-value
#[derive(Debug, PartialEq, Eq)]
pub struct Range {
/// Start of the range, inclusive
pub start: u32,
/// End of the range, inclusive
pub end: u32,
}
impl OneOrMoreCommaSeparated for Range {}
impl Parse for Range {
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
// FIXME: The unicode-range token has been removed from the CSS Syntax spec,
// cssparser should be updated accordingly
// and implement https://drafts.csswg.org/css-syntax/#urange instead
match input.next() {
Ok(Token::UnicodeRange(start, end)) => {
if end <= MAX && start <= end {
Ok(Range { start: start, end: end })
} else {
Err(())
}
}
_ => Err(())
}
}
}
impl ToCss for Range {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
Token::UnicodeRange(self.start, self.end).to_css(dest)
}
}
}

View file

@ -6,7 +6,7 @@
#![deny(missing_docs)]
use cssparser::{Parser, SourcePosition};
use cssparser::{Parser, SourcePosition, UnicodeRange};
use error_reporting::ParseErrorReporter;
#[cfg(feature = "gecko")]
use gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI};
@ -109,3 +109,9 @@ impl<T> Parse for Vec<T> where T: Parse + OneOrMoreCommaSeparated {
input.parse_comma_separated(|input| T::parse(context, input))
}
}
impl Parse for UnicodeRange {
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
UnicodeRange::parse(input)
}
}

View file

@ -7,10 +7,10 @@
#![deny(missing_docs)]
use {Atom, Prefix, Namespace};
use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, decode_stylesheet_bytes};
use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, stylesheet_encoding, EncodingSupport};
use cssparser::{AtRuleType, RuleListParser, SourcePosition, Token, parse_one_rule};
use cssparser::ToCss as ParserToCss;
use encoding::EncodingRef;
use encoding::{self, EncodingRef, DecoderTrap};
use error_reporting::ParseErrorReporter;
use font_face::{FontFaceRule, parse_font_face_block};
use keyframes::{Keyframe, parse_keyframe_list};
@ -24,6 +24,7 @@ use servo_config::prefs::PREFS;
use servo_url::ServoUrl;
use std::cell::Cell;
use std::fmt;
use std::str;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use style_traits::ToCss;
@ -543,6 +544,33 @@ impl ToCss for StyleRule {
}
}
struct RustEncoding;
impl EncodingSupport for RustEncoding {
type Encoding = EncodingRef;
fn utf8() -> Self::Encoding {
encoding::all::UTF_8
}
fn is_utf16_be_or_le(encoding: &Self::Encoding) -> bool {
matches!(encoding.name(), "utf-16be" | "utf-16le")
}
fn from_label(ascii_label: &[u8]) -> Option<Self::Encoding> {
str::from_utf8(ascii_label).ok().and_then(encoding::label::encoding_from_whatwg_label)
}
}
fn decode_stylesheet_bytes(css: &[u8], protocol_encoding_label: Option<&str>,
environment_encoding: Option<EncodingRef>)
-> (String, EncodingRef) {
let fallback_encoding = stylesheet_encoding::<RustEncoding>(
css, protocol_encoding_label.map(str::as_bytes), environment_encoding);
let (result, used_encoding) = encoding::decode(css, DecoderTrap::Replace, fallback_encoding);
(result.unwrap(), used_encoding)
}
impl Stylesheet {
/// Parse a stylesheet from a set of bytes, potentially received over the
/// network.

View file

@ -15,7 +15,7 @@ servo = ["heapsize", "heapsize_derive", "serde", "serde_derive",
[dependencies]
app_units = "0.3"
cssparser = "0.8"
cssparser = "0.9"
euclid = "0.10.1"
heapsize = {version = "0.3.0", optional = true}
heapsize_derive = {version = "0.1", optional = true}

View file

@ -5,6 +5,7 @@
//! Helper types and traits for the handling of CSS values.
use app_units::Au;
use cssparser::UnicodeRange;
use std::fmt;
/// The real `ToCss` trait can't be implemented for types in crates that don't
@ -27,6 +28,8 @@ pub trait ToCss {
/// Marker trait to automatically implement ToCss for Vec<T>.
pub trait OneOrMoreCommaSeparated {}
impl OneOrMoreCommaSeparated for UnicodeRange {}
impl<T> ToCss for Vec<T> where T: ToCss + OneOrMoreCommaSeparated {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
let mut iter = self.iter();
@ -69,6 +72,7 @@ impl_to_css_for_predefined_type!(u32);
impl_to_css_for_predefined_type!(::cssparser::Token<'a>);
impl_to_css_for_predefined_type!(::cssparser::RGBA);
impl_to_css_for_predefined_type!(::cssparser::Color);
impl_to_css_for_predefined_type!(::cssparser::UnicodeRange);
#[macro_export]
macro_rules! define_css_keyword_enum {