mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Insert and lookup element selectors case-insensitively.
Both the insertion key for rules having a LocalNameSelector and the lookup-key sent in get_all_matching_rules should be ASCII lower case.
This commit is contained in:
parent
c4903298a4
commit
315352c3c5
1 changed files with 13 additions and 3 deletions
|
@ -42,6 +42,7 @@ pub enum StylesheetOrigin {
|
|||
/// element name, etc. will contain the Rules that actually match that
|
||||
/// node.
|
||||
pub struct SelectorMap {
|
||||
// TODO: Tune the initial capacity of the HashMap
|
||||
// FIXME: Use interned strings
|
||||
priv id_hash: HashMap<~str, ~[Rule]>,
|
||||
priv class_hash: HashMap<~str, ~[Rule]>,
|
||||
|
@ -88,7 +89,10 @@ impl SelectorMap {
|
|||
}
|
||||
|
||||
rules_list.push_all_move(SelectorMap::get_matching_rules_from_hash(
|
||||
node, pseudo_element, &self.element_hash, element.get_local_name()));
|
||||
node, pseudo_element, &self.element_hash,
|
||||
// HTML elements in HTML documents must be matched case-insensitively
|
||||
// TODO: case-sensitivity depends on the document type
|
||||
element.get_local_name().to_ascii_lower()));
|
||||
rules_list.push_all_move(SelectorMap::get_matching_rules(node, pseudo_element,
|
||||
self.universal_rules));
|
||||
}
|
||||
|
@ -166,6 +170,7 @@ impl SelectorMap {
|
|||
let simple_selector_sequence = &selector.compound_selectors.simple_selectors;
|
||||
for ss in simple_selector_sequence.iter() {
|
||||
match *ss {
|
||||
// TODO: Implement case-sensitivity based on the document type and quirks mode
|
||||
IDSelector(ref id) => return Some(id.clone()),
|
||||
_ => {}
|
||||
}
|
||||
|
@ -178,6 +183,7 @@ impl SelectorMap {
|
|||
let simple_selector_sequence = &rule.selector.compound_selectors.simple_selectors;
|
||||
for ss in simple_selector_sequence.iter() {
|
||||
match *ss {
|
||||
// TODO: Implement case-sensitivity based on the document type and quirks mode
|
||||
ClassSelector(ref class) => return Some(class.clone()),
|
||||
_ => {}
|
||||
}
|
||||
|
@ -190,7 +196,9 @@ impl SelectorMap {
|
|||
let simple_selector_sequence = &rule.selector.compound_selectors.simple_selectors;
|
||||
for ss in simple_selector_sequence.iter() {
|
||||
match *ss {
|
||||
LocalNameSelector(ref name) => return Some(name.clone()),
|
||||
// HTML elements in HTML documents must be matched case-insensitively
|
||||
// TODO: case-sensitivity depends on the document type
|
||||
LocalNameSelector(ref name) => return Some(name.to_ascii_lower()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -553,9 +561,11 @@ fn test_get_class_name(){
|
|||
|
||||
#[test]
|
||||
fn test_get_element_name(){
|
||||
let rules_list = get_mock_rules(["img.foo", "#top"]);
|
||||
let rules_list = get_mock_rules(["img.foo", "#top", "IMG", "ImG"]);
|
||||
assert_eq!(SelectorMap::get_element_name(rules_list[0][0].clone()), Some(~"img"));
|
||||
assert_eq!(SelectorMap::get_element_name(rules_list[1][0].clone()), None);
|
||||
assert_eq!(SelectorMap::get_element_name(rules_list[2][0].clone()), Some(~"img"));
|
||||
assert_eq!(SelectorMap::get_element_name(rules_list[3][0].clone()), Some(~"img"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue