Auto merge of #13110 - emilio:element-flags, r=SimonSapin

Fix incremental restyling under some circumstances due to our bogus use of ElementFlags.

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [x] There are tests for these changes OR

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Depends on https://github.com/servo/rust-selectors/pull/98

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13110)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-09-01 02:44:36 -05:00 committed by GitHub
commit 57b372ba3b
18 changed files with 153 additions and 64 deletions

View file

@ -33,7 +33,7 @@ range = {path = "../range"}
rustc-serialize = "0.3" rustc-serialize = "0.3"
script_layout_interface = {path = "../script_layout_interface"} script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"} script_traits = {path = "../script_traits"}
selectors = {version = "0.12", features = ["heap_size"]} selectors = {version = "0.13", features = ["heap_size"]}
serde_macros = "0.8" serde_macros = "0.8"
smallvec = "0.1" smallvec = "0.1"
string_cache = {version = "0.2.26", features = ["heap_size"]} string_cache = {version = "0.2.26", features = ["heap_size"]}

View file

@ -61,7 +61,7 @@ regex = "0.1.43"
rustc-serialize = "0.3" rustc-serialize = "0.3"
script_layout_interface = {path = "../script_layout_interface"} script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"} script_traits = {path = "../script_traits"}
selectors = {version = "0.12", features = ["heap_size"]} selectors = {version = "0.13", features = ["heap_size"]}
serde = "0.8" serde = "0.8"
smallvec = "0.1" smallvec = "0.1"
string_cache = {version = "0.2.26", features = ["heap_size", "unstable"]} string_cache = {version = "0.2.26", features = ["heap_size", "unstable"]}

View file

@ -70,7 +70,7 @@ use html5ever::serialize::SerializeOpts;
use html5ever::serialize::TraversalScope; use html5ever::serialize::TraversalScope;
use html5ever::serialize::TraversalScope::{ChildrenOnly, IncludeNode}; use html5ever::serialize::TraversalScope::{ChildrenOnly, IncludeNode};
use html5ever::tree_builder::{LimitedQuirks, NoQuirks, Quirks}; use html5ever::tree_builder::{LimitedQuirks, NoQuirks, Quirks};
use selectors::matching::{ElementFlags, matches}; use selectors::matching::{ElementFlags, MatchingReason, matches};
use selectors::matching::{HAS_SLOW_SELECTOR, HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS}; use selectors::matching::{HAS_SLOW_SELECTOR, HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS};
use selectors::parser::{AttrSelector, NamespaceConstraint, parse_author_origin_selector_list_from_str}; use selectors::parser::{AttrSelector, NamespaceConstraint, parse_author_origin_selector_list_from_str};
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
@ -2006,7 +2006,7 @@ impl ElementMethods for Element {
match parse_author_origin_selector_list_from_str(&selectors) { match parse_author_origin_selector_list_from_str(&selectors) {
Err(()) => Err(Error::Syntax), Err(()) => Err(Error::Syntax),
Ok(ref selectors) => { Ok(ref selectors) => {
Ok(matches(selectors, &Root::from_ref(self), None)) Ok(matches(selectors, &Root::from_ref(self), None, MatchingReason::Other))
} }
} }
} }
@ -2024,7 +2024,7 @@ impl ElementMethods for Element {
let root = self.upcast::<Node>(); let root = self.upcast::<Node>();
for element in root.inclusive_ancestors() { for element in root.inclusive_ancestors() {
if let Some(element) = Root::downcast::<Element>(element) { if let Some(element) = Root::downcast::<Element>(element) {
if matches(selectors, &element, None) { if matches(selectors, &element, None, MatchingReason::Other) {
return Ok(Some(element)); return Ok(Some(element));
} }
} }

View file

@ -63,7 +63,7 @@ use script_layout_interface::message::Msg;
use script_layout_interface::{HTMLCanvasData, OpaqueStyleAndLayoutData}; use script_layout_interface::{HTMLCanvasData, OpaqueStyleAndLayoutData};
use script_layout_interface::{LayoutNodeType, LayoutElementType, TrustedNodeAddress}; use script_layout_interface::{LayoutNodeType, LayoutElementType, TrustedNodeAddress};
use script_traits::UntrustedNodeAddress; use script_traits::UntrustedNodeAddress;
use selectors::matching::matches; use selectors::matching::{MatchingReason, matches};
use selectors::parser::Selector; use selectors::parser::Selector;
use selectors::parser::parse_author_origin_selector_list_from_str; use selectors::parser::parse_author_origin_selector_list_from_str;
use std::borrow::ToOwned; use std::borrow::ToOwned;
@ -319,7 +319,7 @@ impl<'a> Iterator for QuerySelectorIterator {
// (instead of passing `None`)? Probably. // (instead of passing `None`)? Probably.
self.iterator.by_ref().filter_map(|node| { self.iterator.by_ref().filter_map(|node| {
if let Some(element) = Root::downcast(node) { if let Some(element) = Root::downcast(node) {
if matches(selectors, &element, None) { if matches(selectors, &element, None, MatchingReason::Other) {
return Some(Root::upcast(element)); return Some(Root::upcast(element));
} }
} }
@ -711,7 +711,7 @@ impl Node {
// Step 3. // Step 3.
Ok(ref selectors) => { Ok(ref selectors) => {
Ok(self.traverse_preorder().filter_map(Root::downcast).find(|element| { Ok(self.traverse_preorder().filter_map(Root::downcast).find(|element| {
matches(selectors, element, None) matches(selectors, element, None, MatchingReason::Other)
})) }))
} }
} }

View file

@ -27,7 +27,7 @@ plugins = {path = "../plugins"}
profile_traits = {path = "../profile_traits"} profile_traits = {path = "../profile_traits"}
range = {path = "../range"} range = {path = "../range"}
script_traits = {path = "../script_traits"} script_traits = {path = "../script_traits"}
selectors = {version = "0.12", features = ["heap_size"]} selectors = {version = "0.13", features = ["heap_size"]}
string_cache = {version = "0.2.26", features = ["heap_size"]} string_cache = {version = "0.2.26", features = ["heap_size"]}
style = {path = "../style"} style = {path = "../style"}
url = {version = "1.2", features = ["heap_size"]} url = {version = "1.2", features = ["heap_size"]}

View file

@ -1164,7 +1164,7 @@ dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script_layout_interface 0.0.1", "script_layout_interface 0.0.1",
"script_traits 0.0.1", "script_traits 0.0.1",
"selectors 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1929,7 +1929,7 @@ dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script_layout_interface 0.0.1", "script_layout_interface 0.0.1",
"script_traits 0.0.1", "script_traits 0.0.1",
"selectors 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1965,7 +1965,7 @@ dependencies = [
"profile_traits 0.0.1", "profile_traits 0.0.1",
"range 0.0.1", "range 0.0.1",
"script_traits 0.0.1", "script_traits 0.0.1",
"selectors 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",
"url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2014,7 +2014,7 @@ dependencies = [
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.12.0" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2236,7 +2236,7 @@ dependencies = [
"quickersort 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "quickersort 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2256,7 +2256,7 @@ dependencies = [
"cssparser 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",
"style_traits 0.0.1", "style_traits 0.0.1",
@ -2867,7 +2867,7 @@ dependencies = [
"checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b" "checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b"
"checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084" "checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084"
"checksum scoped_threadpool 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3ef399c8893e8cb7aa9696e895427fab3a6bf265977bb96e126f24ddd2cda85a" "checksum scoped_threadpool 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3ef399c8893e8cb7aa9696e895427fab3a6bf265977bb96e126f24ddd2cda85a"
"checksum selectors 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd81c2af3eba55ccc7048696c517a0e594ae9a4045b8fb3cc6ad80cd6d65ca5" "checksum selectors 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9eee17ca1807581fc4cf0bfddda311dc421f295a71314b9276ecc787cc63ed6f"
"checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" "checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac"
"checksum serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bfdad8985ce7708e21ada7f3f188a0079de4f8e239155348a024e31f13cddf86" "checksum serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bfdad8985ce7708e21ada7f3f188a0079de4f8e239155348a024e31f13cddf86"
"checksum serde_codegen 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5ae9f0068a5f3266ac4d69eb0c1f9f048a2ac24a42af3db567bcd9a3ffe9d47e" "checksum serde_codegen 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5ae9f0068a5f3266ac4d69eb0c1f9f048a2ac24a42af3db567bcd9a3ffe9d47e"

View file

@ -40,7 +40,7 @@ ordered-float = "0.2.2"
quickersort = "2.0.0" quickersort = "2.0.0"
rand = "0.3" rand = "0.3"
rustc-serialize = "0.3" rustc-serialize = "0.3"
selectors = "0.12" selectors = "0.13"
serde = {version = "0.8", optional = true} serde = {version = "0.8", optional = true}
serde_macros = {version = "0.8", optional = true} serde_macros = {version = "0.8", optional = true}
smallvec = "0.1" smallvec = "0.1"

View file

@ -18,7 +18,7 @@ use properties::{ComputedValues, cascade, PropertyDeclarationBlock};
use selector_impl::{TheSelectorImpl, PseudoElement}; use selector_impl::{TheSelectorImpl, PseudoElement};
use selector_matching::{DeclarationBlock, Stylist}; use selector_matching::{DeclarationBlock, Stylist};
use selectors::bloom::BloomFilter; use selectors::bloom::BloomFilter;
use selectors::matching::{StyleRelations, AFFECTED_BY_PSEUDO_ELEMENTS}; use selectors::matching::{MatchingReason, StyleRelations, AFFECTED_BY_PSEUDO_ELEMENTS};
use selectors::{Element, MatchAttr}; use selectors::{Element, MatchAttr};
use sink::ForgetfulSink; use sink::ForgetfulSink;
use smallvec::SmallVec; use smallvec::SmallVec;
@ -658,7 +658,8 @@ pub trait ElementMatchMethods : TElement {
parent_bf, parent_bf,
style_attribute, style_attribute,
None, None,
&mut applicable_declarations.normal); &mut applicable_declarations.normal,
MatchingReason::ForStyling);
applicable_declarations.normal_shareable = relations_are_shareable(&relations); applicable_declarations.normal_shareable = relations_are_shareable(&relations);
@ -667,7 +668,8 @@ pub trait ElementMatchMethods : TElement {
parent_bf, parent_bf,
None, None,
Some(&pseudo.clone()), Some(&pseudo.clone()),
applicable_declarations.per_pseudo.entry(pseudo).or_insert(vec![])); applicable_declarations.per_pseudo.entry(pseudo).or_insert(vec![]),
MatchingReason::ForStyling);
}); });
let has_pseudos = let has_pseudos =

View file

@ -8,8 +8,8 @@ use element_state::*;
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
use heapsize::HeapSizeOf; use heapsize::HeapSizeOf;
use selector_impl::{ElementExt, TheSelectorImpl, NonTSPseudoClass, AttrValue}; use selector_impl::{ElementExt, TheSelectorImpl, NonTSPseudoClass, AttrValue};
use selectors::matching::StyleRelations;
use selectors::matching::matches_complex_selector; use selectors::matching::matches_complex_selector;
use selectors::matching::{MatchingReason, StyleRelations};
use selectors::parser::{AttrSelector, Combinator, ComplexSelector, SimpleSelector, SelectorImpl}; use selectors::parser::{AttrSelector, Combinator, ComplexSelector, SimpleSelector, SelectorImpl};
use selectors::{Element, MatchAttr}; use selectors::{Element, MatchAttr};
use std::clone::Clone; use std::clone::Clone;
@ -476,10 +476,12 @@ impl DependencySet {
if (attrs_changed || state_changes.intersects(dep.sensitivities.states)) && !hint.intersects(dep.hint) { if (attrs_changed || state_changes.intersects(dep.sensitivities.states)) && !hint.intersects(dep.hint) {
let matched_then = let matched_then =
matches_complex_selector(&dep.selector, snapshot, None, matches_complex_selector(&dep.selector, snapshot, None,
&mut StyleRelations::empty()); &mut StyleRelations::empty(),
MatchingReason::Other);
let matches_now = let matches_now =
matches_complex_selector(&dep.selector, element, None, matches_complex_selector(&dep.selector, element, None,
&mut StyleRelations::empty()); &mut StyleRelations::empty(),
MatchingReason::Other);
if matched_then != matches_now { if matched_then != matches_now {
hint.insert(dep.hint); hint.insert(dep.hint);
} }

View file

@ -16,7 +16,7 @@ use selector_impl::{ElementExt, TheSelectorImpl, PseudoElement};
use selectors::Element; use selectors::Element;
use selectors::bloom::BloomFilter; use selectors::bloom::BloomFilter;
use selectors::matching::{AFFECTED_BY_STYLE_ATTRIBUTE, AFFECTED_BY_PRESENTATIONAL_HINTS}; use selectors::matching::{AFFECTED_BY_STYLE_ATTRIBUTE, AFFECTED_BY_PRESENTATIONAL_HINTS};
use selectors::matching::{StyleRelations, matches_complex_selector}; use selectors::matching::{MatchingReason, StyleRelations, matches_complex_selector};
use selectors::parser::{Selector, SimpleSelector, LocalName, ComplexSelector}; use selectors::parser::{Selector, SimpleSelector, LocalName, ComplexSelector};
use sink::Push; use sink::Push;
use smallvec::VecLike; use smallvec::VecLike;
@ -293,7 +293,8 @@ impl Stylist {
None, None,
None, None,
Some(pseudo), Some(pseudo),
&mut declarations); &mut declarations,
MatchingReason::ForStyling);
let (computed, _) = let (computed, _) =
properties::cascade(self.device.au_viewport_size(), properties::cascade(self.device.au_viewport_size(),
@ -344,7 +345,8 @@ impl Stylist {
parent_bf: Option<&BloomFilter>, parent_bf: Option<&BloomFilter>,
style_attribute: Option<&Arc<PropertyDeclarationBlock>>, style_attribute: Option<&Arc<PropertyDeclarationBlock>>,
pseudo_element: Option<&PseudoElement>, pseudo_element: Option<&PseudoElement>,
applicable_declarations: &mut V) -> StyleRelations applicable_declarations: &mut V,
reason: MatchingReason) -> StyleRelations
where E: Element<Impl=TheSelectorImpl> + where E: Element<Impl=TheSelectorImpl> +
fmt::Debug + fmt::Debug +
PresentationalHintsSynthetizer, PresentationalHintsSynthetizer,
@ -370,6 +372,7 @@ impl Stylist {
parent_bf, parent_bf,
applicable_declarations, applicable_declarations,
&mut relations, &mut relations,
reason,
Importance::Normal); Importance::Normal);
debug!("UA normal: {:?}", relations); debug!("UA normal: {:?}", relations);
@ -387,12 +390,14 @@ impl Stylist {
parent_bf, parent_bf,
applicable_declarations, applicable_declarations,
&mut relations, &mut relations,
reason,
Importance::Normal); Importance::Normal);
debug!("user normal: {:?}", relations); debug!("user normal: {:?}", relations);
map.author.normal.get_all_matching_rules(element, map.author.normal.get_all_matching_rules(element,
parent_bf, parent_bf,
applicable_declarations, applicable_declarations,
&mut relations, &mut relations,
reason,
Importance::Normal); Importance::Normal);
debug!("author normal: {:?}", relations); debug!("author normal: {:?}", relations);
@ -413,6 +418,7 @@ impl Stylist {
parent_bf, parent_bf,
applicable_declarations, applicable_declarations,
&mut relations, &mut relations,
reason,
Importance::Important); Importance::Important);
debug!("author important: {:?}", relations); debug!("author important: {:?}", relations);
@ -434,6 +440,7 @@ impl Stylist {
parent_bf, parent_bf,
applicable_declarations, applicable_declarations,
&mut relations, &mut relations,
reason,
Importance::Important); Importance::Important);
debug!("user important: {:?}", relations); debug!("user important: {:?}", relations);
@ -442,6 +449,7 @@ impl Stylist {
parent_bf, parent_bf,
applicable_declarations, applicable_declarations,
&mut relations, &mut relations,
reason,
Importance::Important); Importance::Important);
debug!("UA important: {:?}", relations); debug!("UA important: {:?}", relations);
@ -468,19 +476,22 @@ impl Stylist {
{ {
use selectors::matching::StyleRelations; use selectors::matching::StyleRelations;
use selectors::matching::matches_complex_selector; use selectors::matching::matches_complex_selector;
// XXX we can probably do better, the candidate should already know what // TODO(emilio): we can probably do better, the candidate should already
// rules it matches. // know what rules it matches. Also, we should only match until we find
// a descendant combinator, the rest should be ok, since the parent is
// the same.
// //
// XXX Could the bloom filter help here? Should be available. // TODO(emilio): Use the bloom filter, since they contain the element's
// ancestor chain and it's correct for the candidate too.
for ref selector in self.non_common_style_affecting_attributes_selectors.iter() { for ref selector in self.non_common_style_affecting_attributes_selectors.iter() {
let element_matches = matches_complex_selector(&selector.complex_selector, let element_matches =
element, matches_complex_selector(&selector.complex_selector, element,
None, None, &mut StyleRelations::empty(),
&mut StyleRelations::empty()); MatchingReason::Other);
let candidate_matches = matches_complex_selector(&selector.complex_selector, let candidate_matches =
candidate, matches_complex_selector(&selector.complex_selector, candidate,
None, None, &mut StyleRelations::empty(),
&mut StyleRelations::empty()); MatchingReason::Other);
if element_matches != candidate_matches { if element_matches != candidate_matches {
return false; return false;
@ -497,20 +508,21 @@ impl Stylist {
{ {
use selectors::matching::StyleRelations; use selectors::matching::StyleRelations;
use selectors::matching::matches_complex_selector; use selectors::matching::matches_complex_selector;
// XXX we can probably do better, the candidate should already know what // TODO(emilio): we can probably do better, the candidate should already
// rules it matches. // know what rules it matches.
// //
// XXX The bloom filter would help here, and should be available. // TODO(emilio): Use the bloom filter, since they contain the element's
// ancestor chain and it's correct for the candidate too.
for ref selector in self.sibling_affecting_selectors.iter() { for ref selector in self.sibling_affecting_selectors.iter() {
let element_matches = matches_complex_selector(&selector.complex_selector, let element_matches =
element, matches_complex_selector(&selector.complex_selector, element,
None, None, &mut StyleRelations::empty(),
&mut StyleRelations::empty()); MatchingReason::Other);
let candidate_matches = matches_complex_selector(&selector.complex_selector, let candidate_matches =
candidate, matches_complex_selector(&selector.complex_selector, candidate,
None, None, &mut StyleRelations::empty(),
&mut StyleRelations::empty()); MatchingReason::Other);
if element_matches != candidate_matches { if element_matches != candidate_matches {
debug!("match_same_sibling_affecting_rules: Failure due to {:?}", debug!("match_same_sibling_affecting_rules: Failure due to {:?}",
@ -650,6 +662,7 @@ impl SelectorMap {
parent_bf: Option<&BloomFilter>, parent_bf: Option<&BloomFilter>,
matching_rules_list: &mut V, matching_rules_list: &mut V,
relations: &mut StyleRelations, relations: &mut StyleRelations,
reason: MatchingReason,
importance: Importance) importance: Importance)
where E: Element<Impl=TheSelectorImpl>, where E: Element<Impl=TheSelectorImpl>,
V: VecLike<DeclarationBlock> V: VecLike<DeclarationBlock>
@ -667,6 +680,7 @@ impl SelectorMap {
&id, &id,
matching_rules_list, matching_rules_list,
relations, relations,
reason,
importance) importance)
} }
@ -677,6 +691,7 @@ impl SelectorMap {
class, class,
matching_rules_list, matching_rules_list,
relations, relations,
reason,
importance); importance);
}); });
@ -691,6 +706,7 @@ impl SelectorMap {
element.get_local_name(), element.get_local_name(),
matching_rules_list, matching_rules_list,
relations, relations,
reason,
importance); importance);
SelectorMap::get_matching_rules(element, SelectorMap::get_matching_rules(element,
@ -698,6 +714,7 @@ impl SelectorMap {
&self.other_rules, &self.other_rules,
matching_rules_list, matching_rules_list,
relations, relations,
reason,
importance); importance);
// Sort only the rules we just added. // Sort only the rules we just added.
@ -735,6 +752,7 @@ impl SelectorMap {
key: &BorrowedStr, key: &BorrowedStr,
matching_rules: &mut Vector, matching_rules: &mut Vector,
relations: &mut StyleRelations, relations: &mut StyleRelations,
reason: MatchingReason,
importance: Importance) importance: Importance)
where E: Element<Impl=TheSelectorImpl>, where E: Element<Impl=TheSelectorImpl>,
Str: Borrow<BorrowedStr> + Eq + Hash, Str: Borrow<BorrowedStr> + Eq + Hash,
@ -747,6 +765,7 @@ impl SelectorMap {
rules, rules,
matching_rules, matching_rules,
relations, relations,
reason,
importance) importance)
} }
} }
@ -757,6 +776,7 @@ impl SelectorMap {
rules: &[Rule], rules: &[Rule],
matching_rules: &mut V, matching_rules: &mut V,
relations: &mut StyleRelations, relations: &mut StyleRelations,
reason: MatchingReason,
importance: Importance) importance: Importance)
where E: Element<Impl=TheSelectorImpl>, where E: Element<Impl=TheSelectorImpl>,
V: VecLike<DeclarationBlock> V: VecLike<DeclarationBlock>
@ -769,8 +789,8 @@ impl SelectorMap {
block.any_normal() block.any_normal()
}; };
if any_declaration_for_importance && if any_declaration_for_importance &&
matches_complex_selector(&*rule.selector, matches_complex_selector(&*rule.selector, element, parent_bf,
element, parent_bf, relations) { relations, reason) {
matching_rules.push(rule.declarations.clone()); matching_rules.push(rule.declarations.clone());
} }
} }

12
ports/cef/Cargo.lock generated
View file

@ -1072,7 +1072,7 @@ dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script_layout_interface 0.0.1", "script_layout_interface 0.0.1",
"script_traits 0.0.1", "script_traits 0.0.1",
"selectors 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1781,7 +1781,7 @@ dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script_layout_interface 0.0.1", "script_layout_interface 0.0.1",
"script_traits 0.0.1", "script_traits 0.0.1",
"selectors 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1817,7 +1817,7 @@ dependencies = [
"profile_traits 0.0.1", "profile_traits 0.0.1",
"range 0.0.1", "range 0.0.1",
"script_traits 0.0.1", "script_traits 0.0.1",
"selectors 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",
"url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1856,7 +1856,7 @@ dependencies = [
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.12.0" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2119,7 +2119,7 @@ dependencies = [
"quickersort 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "quickersort 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2721,7 +2721,7 @@ dependencies = [
"checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b" "checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b"
"checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084" "checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084"
"checksum scoped_threadpool 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3ef399c8893e8cb7aa9696e895427fab3a6bf265977bb96e126f24ddd2cda85a" "checksum scoped_threadpool 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3ef399c8893e8cb7aa9696e895427fab3a6bf265977bb96e126f24ddd2cda85a"
"checksum selectors 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd81c2af3eba55ccc7048696c517a0e594ae9a4045b8fb3cc6ad80cd6d65ca5" "checksum selectors 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9eee17ca1807581fc4cf0bfddda311dc421f295a71314b9276ecc787cc63ed6f"
"checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" "checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac"
"checksum serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bfdad8985ce7708e21ada7f3f188a0079de4f8e239155348a024e31f13cddf86" "checksum serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bfdad8985ce7708e21ada7f3f188a0079de4f8e239155348a024e31f13cddf86"
"checksum serde_codegen 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5ae9f0068a5f3266ac4d69eb0c1f9f048a2ac24a42af3db567bcd9a3ffe9d47e" "checksum serde_codegen 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5ae9f0068a5f3266ac4d69eb0c1f9f048a2ac24a42af3db567bcd9a3ffe9d47e"

View file

@ -11,7 +11,7 @@ dependencies = [
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",
"style_traits 0.0.1", "style_traits 0.0.1",
"url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -169,7 +169,7 @@ dependencies = [
"gecko_bindings 0.0.1", "gecko_bindings 0.0.1",
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -318,7 +318,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.12.0" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -374,7 +374,7 @@ dependencies = [
"quickersort 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "quickersort 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"style_traits 0.0.1", "style_traits 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
@ -538,7 +538,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum regex 0.1.73 (registry+https://github.com/rust-lang/crates.io-index)" = "56b7ee9f764ecf412c6e2fff779bca4b22980517ae335a21aeaf4e32625a5df2" "checksum regex 0.1.73 (registry+https://github.com/rust-lang/crates.io-index)" = "56b7ee9f764ecf412c6e2fff779bca4b22980517ae335a21aeaf4e32625a5df2"
"checksum regex-syntax 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "31040aad7470ad9d8c46302dcffba337bb4289ca5da2e3cd6e37b64109a85199" "checksum regex-syntax 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "31040aad7470ad9d8c46302dcffba337bb4289ca5da2e3cd6e37b64109a85199"
"checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b" "checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b"
"checksum selectors 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd81c2af3eba55ccc7048696c517a0e594ae9a4045b8fb3cc6ad80cd6d65ca5" "checksum selectors 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9eee17ca1807581fc4cf0bfddda311dc421f295a71314b9276ecc787cc63ed6f"
"checksum serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bfdad8985ce7708e21ada7f3f188a0079de4f8e239155348a024e31f13cddf86" "checksum serde 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bfdad8985ce7708e21ada7f3f188a0079de4f8e239155348a024e31f13cddf86"
"checksum smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "fcc8d19212aacecf95e4a7a2179b26f7aeb9732a915cf01f05b0d3e044865410" "checksum smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "fcc8d19212aacecf95e4a7a2179b26f7aeb9732a915cf01f05b0d3e044865410"
"checksum string_cache 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "32e79c75e2fc7bbe0cd0bafa9eeacef16a09e269e8518382a7283904c105c20e" "checksum string_cache 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "32e79c75e2fc7bbe0cd0bafa9eeacef16a09e269e8518382a7283904c105c20e"

View file

@ -19,7 +19,7 @@ lazy_static = "0.2"
libc = "0.2" libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]} log = {version = "0.3.5", features = ["release_max_level_info"]}
num_cpus = "0.2.2" num_cpus = "0.2.2"
selectors = "0.12" selectors = "0.13"
style = {path = "../../components/style", features = ["gecko"]} style = {path = "../../components/style", features = ["gecko"]}
style_traits = {path = "../../components/style_traits"} style_traits = {path = "../../components/style_traits"}
url = "1.2" url = "1.2"

View file

@ -14,5 +14,5 @@ cfg-if = "0.1.0"
gecko_bindings = {version = "0.0.1", path = "../gecko_bindings"} gecko_bindings = {version = "0.0.1", path = "../gecko_bindings"}
heapsize = "0.3.5" heapsize = "0.3.5"
libc = "0.2" libc = "0.2"
selectors = "0.12" selectors = "0.13"
serde = "0.8" serde = "0.8"

View file

@ -14,7 +14,7 @@ app_units = "0.3"
cssparser = {version = "0.6", features = ["heap_size"]} cssparser = {version = "0.6", features = ["heap_size"]}
euclid = "0.10.1" euclid = "0.10.1"
rustc-serialize = "0.3" rustc-serialize = "0.3"
selectors = {version = "0.12", features = ["heap_size"]} selectors = {version = "0.13", features = ["heap_size"]}
string_cache = {version = "0.2.26", features = ["heap_size"]} string_cache = {version = "0.2.26", features = ["heap_size"]}
style = {path = "../../../components/style"} style = {path = "../../../components/style"}
style_traits = {path = "../../../components/style_traits"} style_traits = {path = "../../../components/style_traits"}

View file

@ -4636,6 +4636,18 @@
"url": "/_mozilla/css/removeproperty.html" "url": "/_mozilla/css/removeproperty.html"
} }
], ],
"css/restyle-nth-child.html": [
{
"path": "css/restyle-nth-child.html",
"references": [
[
"/_mozilla/css/restyle-nth-child-ref.html",
"=="
]
],
"url": "/_mozilla/css/restyle-nth-child.html"
}
],
"css/restyle_hints_attr.html": [ "css/restyle_hints_attr.html": [
{ {
"path": "css/restyle_hints_attr.html", "path": "css/restyle_hints_attr.html",
@ -14006,6 +14018,18 @@
"url": "/_mozilla/css/removeproperty.html" "url": "/_mozilla/css/removeproperty.html"
} }
], ],
"css/restyle-nth-child.html": [
{
"path": "css/restyle-nth-child.html",
"references": [
[
"/_mozilla/css/restyle-nth-child-ref.html",
"=="
]
],
"url": "/_mozilla/css/restyle-nth-child.html"
}
],
"css/restyle_hints_attr.html": [ "css/restyle_hints_attr.html": [
{ {
"path": "css/restyle_hints_attr.html", "path": "css/restyle_hints_attr.html",

View file

@ -0,0 +1,17 @@
<!doctype html>
<meta charset="utf-8">
<title>CSS test reference.</title>
<style>
.container div {
width: 50px;
height: 50px;
background: blue;
}
.container div:nth-child(2) {
background: green;
}
</style>
<div class="container">
<div></div>
<div></div>
</div>

View file

@ -0,0 +1,24 @@
<!doctype html>
<meta charset="utf-8">
<title>Restyling of a child of a parent that didn't match nth-child but now
does should be correct.</title>
<link rel="match" href="restyle-nth-child-ref.html">
<style>
.container div {
width: 50px;
height: 50px;
background: blue;
}
.container div:nth-child(2) {
background: green;
}
</style>
<div class="container">
<div></div>
</div>
<script>
let container = document.querySelector('.container');
window.onload = function() {
container.insertBefore(document.createElement('div'), container.firstChild);
}
</script>