diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2017-04-25 10:44:10 +0200 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2017-04-26 13:04:27 +0900 |
commit | 0ff64bdc59e75c4fa16927db5cc8797bf60f9a36 (patch) | |
tree | d4312e064b4a99df6b8b08ec6081f642f2a8ea0f | |
parent | 11469218661fe3076b255eba35c2b0736dcce500 (diff) | |
download | servo-0ff64bdc59e75c4fa16927db5cc8797bf60f9a36.tar.gz servo-0ff64bdc59e75c4fa16927db5cc8797bf60f9a36.zip |
Allow 'decimal' and 'none' in `<counter-style-name>`
… other than in `@counter-style`.
-rw-r--r-- | components/atoms/build.rs | 15 | ||||
-rw-r--r-- | components/atoms/static_atoms.txt | 2 | ||||
-rw-r--r-- | components/style/counter_style/mod.rs | 3 | ||||
-rw-r--r-- | components/style/counter_style/predefined.rs | 1 | ||||
-rwxr-xr-x | components/style/counter_style/update_predefined.py | 3 | ||||
-rw-r--r-- | components/style/gecko_string_cache/mod.rs | 20 | ||||
-rw-r--r-- | components/style/stylesheets.rs | 6 |
7 files changed, 45 insertions, 5 deletions
diff --git a/components/atoms/build.rs b/components/atoms/build.rs index 4de629d288c..c8edc9bcd5a 100644 --- a/components/atoms/build.rs +++ b/components/atoms/build.rs @@ -12,7 +12,20 @@ use std::path::Path; fn main() { let static_atoms = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("static_atoms.txt"); let static_atoms = BufReader::new(File::open(&static_atoms).unwrap()); - string_cache_codegen::AtomType::new("Atom", "atom!") + let mut atom_type = string_cache_codegen::AtomType::new("Atom", "atom!"); + + macro_rules! predefined { + ($($name: expr,)+) => { + { + $( + atom_type.atom($name); + )+ + } + } + } + include!("../style/counter_style/predefined.rs"); + + atom_type .atoms(static_atoms.lines().map(Result::unwrap)) .write_to_file(&Path::new(&env::var("OUT_DIR").unwrap()).join("atom.rs")) .unwrap(); diff --git a/components/atoms/static_atoms.txt b/components/atoms/static_atoms.txt index df9cd426984..a41aae29289 100644 --- a/components/atoms/static_atoms.txt +++ b/components/atoms/static_atoms.txt @@ -8,6 +8,8 @@ left center right +none + hidden submit button diff --git a/components/style/counter_style/mod.rs b/components/style/counter_style/mod.rs index f27aecc8549..8397ebff755 100644 --- a/components/style/counter_style/mod.rs +++ b/components/style/counter_style/mod.rs @@ -38,7 +38,7 @@ pub fn parse_counter_style_name(input: &mut Parser) -> Result<CustomIdent, ()> { if let Some(&lower_cased) = predefined(&ident) { Ok(CustomIdent(Atom::from(lower_cased))) } else { - CustomIdent::from_ident(ident, &["decimal", "none"]) + CustomIdent::from_ident(ident, &[]) } } } @@ -248,6 +248,7 @@ counter_style_descriptors! { /// https://drafts.csswg.org/css-counter-styles/#counter-style-fallback "fallback" fallback / eCSSCounterDesc_Fallback: Fallback = { + // FIXME https://bugzilla.mozilla.org/show_bug.cgi?id=1359323 use atom!() Fallback(CustomIdent(Atom::from("decimal"))) } diff --git a/components/style/counter_style/predefined.rs b/components/style/counter_style/predefined.rs index dee17e90377..7b27514cd33 100644 --- a/components/style/counter_style/predefined.rs +++ b/components/style/counter_style/predefined.rs @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ predefined! { + "decimal", "decimal-leading-zero", "arabic-indic", "armenian", diff --git a/components/style/counter_style/update_predefined.py b/components/style/counter_style/update_predefined.py index 9e64545b593..3e5be33e448 100755 --- a/components/style/counter_style/update_predefined.py +++ b/components/style/counter_style/update_predefined.py @@ -25,9 +25,6 @@ def main(filename): predefined! { """) for name in names: - # FIXME https://github.com/w3c/csswg-drafts/issues/1285 - if name == 'decimal': - continue f.write(' "%s",\n' % name) f.write('}\n') diff --git a/components/style/gecko_string_cache/mod.rs b/components/style/gecko_string_cache/mod.rs index b612c027c45..63ba6d7977c 100644 --- a/components/style/gecko_string_cache/mod.rs +++ b/components/style/gecko_string_cache/mod.rs @@ -13,6 +13,7 @@ use gecko_bindings::bindings::Gecko_ReleaseAtom; use gecko_bindings::structs::nsIAtom; use nsstring::nsAString; use precomputed_hash::PrecomputedHash; +use std::ascii::AsciiExt; use std::borrow::{Cow, Borrow}; use std::char::{self, DecodeUtf16}; use std::fmt::{self, Write}; @@ -224,6 +225,25 @@ impl Atom { Atom(WeakAtom::new(ptr)) } } + + /// Return whether two atoms are ASCII-case-insensitive matches + pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool { + let a = self.as_slice(); + let b = other.as_slice(); + a.len() == b.len() && a.iter().zip(b).all(|(&a16, &b16)| { + if a16 <= 0x7F && b16 <= 0x7F { + (a16 as u8).eq_ignore_ascii_case(&(b16 as u8)) + } else { + a16 == b16 + } + }) + } + + /// Return whether this atom is an ASCII-case-insensitive match for the given string + pub fn eq_str_ignore_ascii_case(&self, other: &str) -> bool { + self.chars().map(|r| r.map(|c: char| c.to_ascii_lowercase())) + .eq(other.chars().map(|c: char| Ok(c.to_ascii_lowercase()))) + } } impl Hash for Atom { diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index 5460dba620b..4012761a6ef 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -1117,6 +1117,12 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> { return Err(()) } let name = parse_counter_style_name(input)?; + // FIXME: use static atoms and eq_ignore_ascii_case + // https://bugzilla.mozilla.org/show_bug.cgi?id=1359323 + // "decimal" is already lower-cased by `parse_counter_style_name`. + if name.0 == "decimal" || name.0.eq_str_ignore_ascii_case("none") { + return Err(()) + } Ok(AtRuleType::WithBlock(AtRulePrelude::CounterStyle(name))) }, "viewport" => { |