mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Account for left-to-right rather than right-to-left precedence of classes in selector maps.
MozReview-Commit-ID: 8qIl4k3RxaC
This commit is contained in:
parent
7f4c846321
commit
1c7f2a9f09
2 changed files with 11 additions and 12 deletions
|
@ -369,15 +369,12 @@ impl<T: SelectorMapEntry> SelectorMap<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Searches the selector from right to left, beginning to the left of the
|
/// Searches a compound selector from left to right. If the compound selector
|
||||||
/// ::pseudo-element (if any), and ending at the first combinator.
|
/// is a pseudo-element, it's ignored.
|
||||||
///
|
///
|
||||||
/// The first non-None value returned from |f| is returned.
|
/// The first non-None value returned from |f| is returned.
|
||||||
///
|
|
||||||
/// Effectively, pseudo-elements are ignored, given only state pseudo-classes
|
|
||||||
/// may appear before them.
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn find_from_right<F, R>(mut iter: SelectorIter<SelectorImpl>,
|
fn find_from_left<F, R>(mut iter: SelectorIter<SelectorImpl>,
|
||||||
mut f: F)
|
mut f: F)
|
||||||
-> Option<R>
|
-> Option<R>
|
||||||
where F: FnMut(&Component<SelectorImpl>) -> Option<R>,
|
where F: FnMut(&Component<SelectorImpl>) -> Option<R>,
|
||||||
|
@ -388,6 +385,8 @@ fn find_from_right<F, R>(mut iter: SelectorIter<SelectorImpl>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Effectively, pseudo-elements are ignored, given only state pseudo-classes
|
||||||
|
// may appear before them.
|
||||||
if iter.next_sequence() == Some(Combinator::PseudoElement) {
|
if iter.next_sequence() == Some(Combinator::PseudoElement) {
|
||||||
for ss in &mut iter {
|
for ss in &mut iter {
|
||||||
if let Some(r) = f(ss) {
|
if let Some(r) = f(ss) {
|
||||||
|
@ -403,7 +402,7 @@ fn find_from_right<F, R>(mut iter: SelectorIter<SelectorImpl>,
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn get_id_name(iter: SelectorIter<SelectorImpl>)
|
pub fn get_id_name(iter: SelectorIter<SelectorImpl>)
|
||||||
-> Option<Atom> {
|
-> Option<Atom> {
|
||||||
find_from_right(iter, |ss| {
|
find_from_left(iter, |ss| {
|
||||||
// TODO(pradeep): Implement case-sensitivity based on the
|
// TODO(pradeep): Implement case-sensitivity based on the
|
||||||
// document type and quirks mode.
|
// document type and quirks mode.
|
||||||
if let Component::ID(ref id) = *ss {
|
if let Component::ID(ref id) = *ss {
|
||||||
|
@ -417,7 +416,7 @@ pub fn get_id_name(iter: SelectorIter<SelectorImpl>)
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn get_class_name(iter: SelectorIter<SelectorImpl>)
|
pub fn get_class_name(iter: SelectorIter<SelectorImpl>)
|
||||||
-> Option<Atom> {
|
-> Option<Atom> {
|
||||||
find_from_right(iter, |ss| {
|
find_from_left(iter, |ss| {
|
||||||
// TODO(pradeep): Implement case-sensitivity based on the
|
// TODO(pradeep): Implement case-sensitivity based on the
|
||||||
// document type and quirks mode.
|
// document type and quirks mode.
|
||||||
if let Component::Class(ref class) = *ss {
|
if let Component::Class(ref class) = *ss {
|
||||||
|
@ -431,7 +430,7 @@ pub fn get_class_name(iter: SelectorIter<SelectorImpl>)
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn get_local_name(iter: SelectorIter<SelectorImpl>)
|
pub fn get_local_name(iter: SelectorIter<SelectorImpl>)
|
||||||
-> Option<LocalNameSelector<SelectorImpl>> {
|
-> Option<LocalNameSelector<SelectorImpl>> {
|
||||||
find_from_right(iter, |ss| {
|
find_from_left(iter, |ss| {
|
||||||
if let Component::LocalName(ref n) = *ss {
|
if let Component::LocalName(ref n) = *ss {
|
||||||
return Some(LocalNameSelector {
|
return Some(LocalNameSelector {
|
||||||
name: n.name.clone(),
|
name: n.name.clone(),
|
||||||
|
|
|
@ -194,7 +194,7 @@ fn test_get_id_name() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_class_name() {
|
fn test_get_class_name() {
|
||||||
let (rules_list, _) = get_mock_rules(&[".intro.foo", "#top"]);
|
let (rules_list, _) = get_mock_rules(&[".intro.foo", "#top"]);
|
||||||
assert_eq!(selector_map::get_class_name(rules_list[0][0].selector.iter()), Some(Atom::from("foo")));
|
assert_eq!(selector_map::get_class_name(rules_list[0][0].selector.iter()), Some(Atom::from("intro")));
|
||||||
assert_eq!(selector_map::get_class_name(rules_list[1][0].selector.iter()), None);
|
assert_eq!(selector_map::get_class_name(rules_list[1][0].selector.iter()), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,8 +220,8 @@ fn test_insert() {
|
||||||
selector_map.insert(rules_list[1][0].clone(), QuirksMode::NoQuirks);
|
selector_map.insert(rules_list[1][0].clone(), QuirksMode::NoQuirks);
|
||||||
assert_eq!(1, selector_map.id_hash.get(&Atom::from("top"), QuirksMode::NoQuirks).unwrap()[0].source_order);
|
assert_eq!(1, selector_map.id_hash.get(&Atom::from("top"), QuirksMode::NoQuirks).unwrap()[0].source_order);
|
||||||
selector_map.insert(rules_list[0][0].clone(), QuirksMode::NoQuirks);
|
selector_map.insert(rules_list[0][0].clone(), QuirksMode::NoQuirks);
|
||||||
assert_eq!(0, selector_map.class_hash.get(&Atom::from("foo"), QuirksMode::NoQuirks).unwrap()[0].source_order);
|
assert_eq!(0, selector_map.class_hash.get(&Atom::from("intro"), QuirksMode::NoQuirks).unwrap()[0].source_order);
|
||||||
assert!(selector_map.class_hash.get(&Atom::from("intro"), QuirksMode::NoQuirks).is_none());
|
assert!(selector_map.class_hash.get(&Atom::from("foo"), QuirksMode::NoQuirks).is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue