Skip to content

Commit

Permalink
Allow 'decimal' and 'none' in <counter-style-name>
Browse files Browse the repository at this point in the history
… other than in `@counter-style`.
  • Loading branch information
SimonSapin committed Apr 26, 2017
1 parent 1146921 commit 0ff64bd
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 5 deletions.
15 changes: 14 additions & 1 deletion components/atoms/build.rs
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions components/atoms/static_atoms.txt
Expand Up @@ -8,6 +8,8 @@ left
center
right

none

hidden
submit
button
Expand Down
3 changes: 2 additions & 1 deletion components/style/counter_style/mod.rs
Expand Up @@ -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, &[])
}
}
}
Expand Down Expand Up @@ -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")))
}

Expand Down
1 change: 1 addition & 0 deletions components/style/counter_style/predefined.rs
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

predefined! {
"decimal",
"decimal-leading-zero",
"arabic-indic",
"armenian",
Expand Down
3 changes: 0 additions & 3 deletions components/style/counter_style/update_predefined.py
Expand Up @@ -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')

Expand Down
20 changes: 20 additions & 0 deletions components/style/gecko_string_cache/mod.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions components/style/stylesheets.rs
Expand Up @@ -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" => {
Expand Down

0 comments on commit 0ff64bd

Please sign in to comment.