mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Update cssparser to 0.9
This commit is contained in:
parent
9702d6920a
commit
c3cad2d6c7
17 changed files with 72 additions and 82 deletions
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue