Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Log element during selector matching
MozReview-Commit-ID: D8eFyRCy5BR
  • Loading branch information
jryans committed Jun 7, 2017
1 parent eaefcbe commit 6b1b8bb
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions components/script/dom/element.rs
Expand Up @@ -151,6 +151,12 @@ impl fmt::Debug for Element {
}
}

impl fmt::Debug for Root<Element> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
(**self).fmt(f)
}
}

#[derive(PartialEq, HeapSizeOf)]
pub enum ElementCreator {
ParserCreated(u64),
Expand Down
1 change: 1 addition & 0 deletions components/selectors/Cargo.toml
Expand Up @@ -25,6 +25,7 @@ gecko_like_types = []
bitflags = "0.7"
matches = "0.1"
cssparser = "0.13.7"
log = "0.3"
fnv = "1.0"
phf = "0.7.18"
precomputed-hash = "0.1"
Expand Down
1 change: 1 addition & 0 deletions components/selectors/lib.rs
Expand Up @@ -4,6 +4,7 @@

#[macro_use] extern crate bitflags;
#[macro_use] extern crate cssparser;
#[macro_use] extern crate log;
#[macro_use] extern crate matches;
extern crate fnv;
extern crate phf;
Expand Down
5 changes: 4 additions & 1 deletion components/selectors/matching.rs
Expand Up @@ -198,7 +198,7 @@ fn may_match<E>(hashes: &AncestorHashes,
/// and `is_unvisited` are based on relevant link state of only the current
/// complex selector being matched (not the global relevant link status for all
/// selectors in `MatchingContext`).
#[derive(PartialEq, Eq, Copy, Clone)]
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub enum RelevantLinkStatus {
/// Looking for a possible relevant link. This is the initial mode when
/// matching a selector.
Expand Down Expand Up @@ -429,6 +429,9 @@ fn matches_complex_selector_internal<E, F>(mut selector_iter: SelectorIter<E::Im
matches_simple_selector(simple, element, context, &relevant_link, flags_setter)
});

debug!("Matching for {:?}, simple selector {:?}, relevant link {:?}",
element, selector_iter, relevant_link);

let combinator = selector_iter.next_sequence();
let siblings = combinator.map_or(false, |c| c.is_sibling());
if siblings {
Expand Down
10 changes: 10 additions & 0 deletions components/selectors/parser.rs
Expand Up @@ -453,6 +453,16 @@ impl<'a, Impl: SelectorImpl> Iterator for SelectorIter<'a, Impl> {
}
}

impl<'a, Impl: SelectorImpl> fmt::Debug for SelectorIter<'a, Impl> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let iter = self.iter.clone().rev();
for component in iter {
component.to_css(f)?
}
Ok(())
}
}

/// An iterator over all simple selectors belonging to ancestors.
pub struct AncestorIter<'a, Impl: 'a + SelectorImpl>(SelectorIter<'a, Impl>);
impl<'a, Impl: 'a + SelectorImpl> AncestorIter<'a, Impl> {
Expand Down
3 changes: 2 additions & 1 deletion components/selectors/tree.rs
Expand Up @@ -8,8 +8,9 @@
use attr::{AttrSelectorOperation, NamespaceConstraint};
use matching::{ElementSelectorFlags, MatchingContext, RelevantLinkStatus};
use parser::SelectorImpl;
use std::fmt::Debug;

pub trait Element: Sized {
pub trait Element: Sized + Debug {
type Impl: SelectorImpl;

fn parent_element(&self) -> Option<Self>;
Expand Down
10 changes: 10 additions & 0 deletions components/style/restyle_hints.rs
Expand Up @@ -29,6 +29,7 @@ use smallvec::SmallVec;
use std::cell::Cell;
use std::clone::Clone;
use std::cmp;
use std::fmt;

/// When the ElementState of an element (like IN_HOVER_STATE) changes,
/// certain pseudo-classes (like :hover) may require us to restyle that
Expand Down Expand Up @@ -607,6 +608,15 @@ impl<'a, E> ElementWrapper<'a, E>
}
}

impl<'a, E> fmt::Debug for ElementWrapper<'a, E>
where E: TElement,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Ignore other fields for now, can change later if needed.
self.element.fmt(f)
}
}

#[cfg(feature = "gecko")]
fn dir_selector_to_state(s: &[u16]) -> ElementState {
// Jump through some hoops to deal with our Box<[u16]> thing.
Expand Down

0 comments on commit 6b1b8bb

Please sign in to comment.