mirror of
https://github.com/servo/servo.git
synced 2025-07-25 08:10:21 +01:00
Add support for :scope pseudo-class
This commit is contained in:
parent
715fc9cea6
commit
ab46a0bbe0
4 changed files with 25 additions and 1 deletions
|
@ -284,7 +284,7 @@ fn complex_selector_specificity<Impl>(mut iter: slice::Iter<Component<Impl>>)
|
||||||
|
|
||||||
Component::FirstChild | Component::LastChild |
|
Component::FirstChild | Component::LastChild |
|
||||||
Component::OnlyChild | Component::Root |
|
Component::OnlyChild | Component::Root |
|
||||||
Component::Empty |
|
Component::Empty | Component::Scope |
|
||||||
Component::NthChild(..) |
|
Component::NthChild(..) |
|
||||||
Component::NthLastChild(..) |
|
Component::NthLastChild(..) |
|
||||||
Component::NthOfType(..) |
|
Component::NthOfType(..) |
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
use attr::CaseSensitivity;
|
use attr::CaseSensitivity;
|
||||||
use bloom::BloomFilter;
|
use bloom::BloomFilter;
|
||||||
use nth_index_cache::NthIndexCache;
|
use nth_index_cache::NthIndexCache;
|
||||||
|
use tree::OpaqueElement;
|
||||||
|
|
||||||
/// What kind of selector matching mode we should use.
|
/// What kind of selector matching mode we should use.
|
||||||
///
|
///
|
||||||
|
@ -88,6 +89,19 @@ pub struct MatchingContext<'a> {
|
||||||
/// only.)
|
/// only.)
|
||||||
pub relevant_link_found: bool,
|
pub relevant_link_found: bool,
|
||||||
|
|
||||||
|
/// The element which is going to match :scope pseudo-class. It can be
|
||||||
|
/// either one :scope element, or the scoping element.
|
||||||
|
///
|
||||||
|
/// Note that, although in theory there can be multiple :scope elements,
|
||||||
|
/// in current specs, at most one is specified, and when there is one,
|
||||||
|
/// scoping element is not relevant anymore, so we use a single field for
|
||||||
|
/// them.
|
||||||
|
///
|
||||||
|
/// When this is None, :scope will match the root element.
|
||||||
|
///
|
||||||
|
/// See https://drafts.csswg.org/selectors-4/#scope-pseudo
|
||||||
|
pub scope_element: Option<OpaqueElement>,
|
||||||
|
|
||||||
quirks_mode: QuirksMode,
|
quirks_mode: QuirksMode,
|
||||||
classes_and_ids_case_sensitivity: CaseSensitivity,
|
classes_and_ids_case_sensitivity: CaseSensitivity,
|
||||||
}
|
}
|
||||||
|
@ -125,6 +139,7 @@ impl<'a> MatchingContext<'a> {
|
||||||
quirks_mode,
|
quirks_mode,
|
||||||
relevant_link_found: false,
|
relevant_link_found: false,
|
||||||
classes_and_ids_case_sensitivity: quirks_mode.classes_and_ids_case_sensitivity(),
|
classes_and_ids_case_sensitivity: quirks_mode.classes_and_ids_case_sensitivity(),
|
||||||
|
scope_element: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -724,6 +724,12 @@ fn matches_simple_selector<E, F>(
|
||||||
flags_setter(element, HAS_EMPTY_SELECTOR);
|
flags_setter(element, HAS_EMPTY_SELECTOR);
|
||||||
element.is_empty()
|
element.is_empty()
|
||||||
}
|
}
|
||||||
|
Component::Scope => {
|
||||||
|
match context.shared.scope_element {
|
||||||
|
Some(ref scope_element) => element.opaque() == *scope_element,
|
||||||
|
None => element.is_root(),
|
||||||
|
}
|
||||||
|
}
|
||||||
Component::NthChild(a, b) => {
|
Component::NthChild(a, b) => {
|
||||||
matches_generic_nth_child(element, context, a, b, false, false, flags_setter)
|
matches_generic_nth_child(element, context, a, b, false, false, flags_setter)
|
||||||
}
|
}
|
||||||
|
|
|
@ -673,6 +673,7 @@ pub enum Component<Impl: SelectorImpl> {
|
||||||
FirstChild, LastChild, OnlyChild,
|
FirstChild, LastChild, OnlyChild,
|
||||||
Root,
|
Root,
|
||||||
Empty,
|
Empty,
|
||||||
|
Scope,
|
||||||
NthChild(i32, i32),
|
NthChild(i32, i32),
|
||||||
NthLastChild(i32, i32),
|
NthLastChild(i32, i32),
|
||||||
NthOfType(i32, i32),
|
NthOfType(i32, i32),
|
||||||
|
@ -969,6 +970,7 @@ impl<Impl: SelectorImpl> ToCss for Component<Impl> {
|
||||||
OnlyChild => dest.write_str(":only-child"),
|
OnlyChild => dest.write_str(":only-child"),
|
||||||
Root => dest.write_str(":root"),
|
Root => dest.write_str(":root"),
|
||||||
Empty => dest.write_str(":empty"),
|
Empty => dest.write_str(":empty"),
|
||||||
|
Scope => dest.write_str(":scope"),
|
||||||
FirstOfType => dest.write_str(":first-of-type"),
|
FirstOfType => dest.write_str(":first-of-type"),
|
||||||
LastOfType => dest.write_str(":last-of-type"),
|
LastOfType => dest.write_str(":last-of-type"),
|
||||||
OnlyOfType => dest.write_str(":only-of-type"),
|
OnlyOfType => dest.write_str(":only-of-type"),
|
||||||
|
@ -1699,6 +1701,7 @@ fn parse_simple_pseudo_class<'i, P, E, Impl>(parser: &P, name: CowRcStr<'i>)
|
||||||
"only-child" => Ok(Component::OnlyChild),
|
"only-child" => Ok(Component::OnlyChild),
|
||||||
"root" => Ok(Component::Root),
|
"root" => Ok(Component::Root),
|
||||||
"empty" => Ok(Component::Empty),
|
"empty" => Ok(Component::Empty),
|
||||||
|
"scope" => Ok(Component::Scope),
|
||||||
"first-of-type" => Ok(Component::FirstOfType),
|
"first-of-type" => Ok(Component::FirstOfType),
|
||||||
"last-of-type" => Ok(Component::LastOfType),
|
"last-of-type" => Ok(Component::LastOfType),
|
||||||
"only-of-type" => Ok(Component::OnlyOfType),
|
"only-of-type" => Ok(Component::OnlyOfType),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue