Skip to content

Commit

Permalink
style: Hide LocalMatchingContext.
Browse files Browse the repository at this point in the history
This type is a lot of complexity related to a very specific thing such as the
hover and active quirk.

Instead of that, move `nesting_level` to `MatchingContext`, and simplify all
this computing whether the quirk applies upfront, for each complex selector we
test.

This is less error-prone, and also allows simplifying more stuff in a bit.
  • Loading branch information
emilio committed Oct 14, 2017
1 parent 48c8515 commit 11485ed
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 183 deletions.
6 changes: 3 additions & 3 deletions components/layout_thread/dom_wrapper.rs
Expand Up @@ -51,7 +51,7 @@ use script_layout_interface::{OpaqueStyleAndLayoutData, StyleData};
use script_layout_interface::wrapper_traits::{DangerousThreadSafeLayoutNode, GetLayoutData, LayoutNode};
use script_layout_interface::wrapper_traits::{PseudoElementType, ThreadSafeLayoutElement, ThreadSafeLayoutNode};
use selectors::attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity};
use selectors::matching::{ElementSelectorFlags, LocalMatchingContext, MatchingContext, RelevantLinkStatus};
use selectors::matching::{ElementSelectorFlags, MatchingContext, RelevantLinkStatus};
use selectors::matching::VisitedHandlingMode;
use selectors::sink::Push;
use servo_arc::{Arc, ArcBorrow};
Expand Down Expand Up @@ -720,7 +720,7 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {

fn match_non_ts_pseudo_class<F>(&self,
pseudo_class: &NonTSPseudoClass,
_: &mut LocalMatchingContext<Self::Impl>,
_: &mut MatchingContext,
_: &RelevantLinkStatus,
_: &mut F)
-> bool
Expand Down Expand Up @@ -1240,7 +1240,7 @@ impl<'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> {

fn match_non_ts_pseudo_class<F>(&self,
_: &NonTSPseudoClass,
_: &mut LocalMatchingContext<Self::Impl>,
_: &mut MatchingContext,
_: &RelevantLinkStatus,
_: &mut F)
-> bool
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/element.rs
Expand Up @@ -89,7 +89,7 @@ use script_layout_interface::message::ReflowGoal;
use script_thread::ScriptThread;
use selectors::Element as SelectorsElement;
use selectors::attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity};
use selectors::matching::{ElementSelectorFlags, LocalMatchingContext, MatchingContext, RelevantLinkStatus};
use selectors::matching::{ElementSelectorFlags, MatchingContext, MatchingMode, RelevantLinkStatus};
use selectors::matching::{HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS};
use selectors::sink::Push;
use servo_arc::Arc;
Expand Down Expand Up @@ -2583,7 +2583,7 @@ impl<'a> SelectorsElement for DomRoot<Element> {

fn match_non_ts_pseudo_class<F>(&self,
pseudo_class: &NonTSPseudoClass,
_: &mut LocalMatchingContext<Self::Impl>,
_: &mut MatchingContext,
_: &RelevantLinkStatus,
_: &mut F)
-> bool
Expand Down
4 changes: 4 additions & 0 deletions components/selectors/context.rs
Expand Up @@ -102,6 +102,9 @@ pub struct MatchingContext<'a> {
/// See https://drafts.csswg.org/selectors-4/#scope-pseudo
pub scope_element: Option<OpaqueElement>,

/// The current nesting level of selectors that we're matching.
pub nesting_level: usize,

quirks_mode: QuirksMode,
classes_and_ids_case_sensitivity: CaseSensitivity,
}
Expand Down Expand Up @@ -140,6 +143,7 @@ impl<'a> MatchingContext<'a> {
relevant_link_found: false,
classes_and_ids_case_sensitivity: quirks_mode.classes_and_ids_case_sensitivity(),
scope_element: None,
nesting_level: 0,
}
}

Expand Down

0 comments on commit 11485ed

Please sign in to comment.