Allow 'decimal' and 'none' in <counter-style-name>

… other than in `@counter-style`.
This commit is contained in:
Simon Sapin 2017-04-25 10:44:10 +02:00
parent 1146921866
commit 0ff64bdc59
7 changed files with 45 additions and 5 deletions

View file

@ -12,7 +12,20 @@ use std::path::Path;
fn main() { fn main() {
let static_atoms = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("static_atoms.txt"); 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()); 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)) .atoms(static_atoms.lines().map(Result::unwrap))
.write_to_file(&Path::new(&env::var("OUT_DIR").unwrap()).join("atom.rs")) .write_to_file(&Path::new(&env::var("OUT_DIR").unwrap()).join("atom.rs"))
.unwrap(); .unwrap();

View file

@ -8,6 +8,8 @@ left
center center
right right
none
hidden hidden
submit submit
button button

View file

@ -38,7 +38,7 @@ pub fn parse_counter_style_name(input: &mut Parser) -> Result<CustomIdent, ()> {
if let Some(&lower_cased) = predefined(&ident) { if let Some(&lower_cased) = predefined(&ident) {
Ok(CustomIdent(Atom::from(lower_cased))) Ok(CustomIdent(Atom::from(lower_cased)))
} else { } 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 /// https://drafts.csswg.org/css-counter-styles/#counter-style-fallback
"fallback" fallback / eCSSCounterDesc_Fallback: Fallback = { "fallback" fallback / eCSSCounterDesc_Fallback: Fallback = {
// FIXME https://bugzilla.mozilla.org/show_bug.cgi?id=1359323 use atom!()
Fallback(CustomIdent(Atom::from("decimal"))) Fallback(CustomIdent(Atom::from("decimal")))
} }

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
predefined! { predefined! {
"decimal",
"decimal-leading-zero", "decimal-leading-zero",
"arabic-indic", "arabic-indic",
"armenian", "armenian",

View file

@ -25,9 +25,6 @@ def main(filename):
predefined! { predefined! {
""") """)
for name in names: for name in names:
# FIXME https://github.com/w3c/csswg-drafts/issues/1285
if name == 'decimal':
continue
f.write(' "%s",\n' % name) f.write(' "%s",\n' % name)
f.write('}\n') f.write('}\n')

View file

@ -13,6 +13,7 @@ use gecko_bindings::bindings::Gecko_ReleaseAtom;
use gecko_bindings::structs::nsIAtom; use gecko_bindings::structs::nsIAtom;
use nsstring::nsAString; use nsstring::nsAString;
use precomputed_hash::PrecomputedHash; use precomputed_hash::PrecomputedHash;
use std::ascii::AsciiExt;
use std::borrow::{Cow, Borrow}; use std::borrow::{Cow, Borrow};
use std::char::{self, DecodeUtf16}; use std::char::{self, DecodeUtf16};
use std::fmt::{self, Write}; use std::fmt::{self, Write};
@ -224,6 +225,25 @@ impl Atom {
Atom(WeakAtom::new(ptr)) 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 { impl Hash for Atom {

View file

@ -1117,6 +1117,12 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
return Err(()) return Err(())
} }
let name = parse_counter_style_name(input)?; 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))) Ok(AtRuleType::WithBlock(AtRulePrelude::CounterStyle(name)))
}, },
"viewport" => { "viewport" => {