Skip to content

Commit

Permalink
Make selector list pseudos work with class invalidation sets.
Browse files Browse the repository at this point in the history
Selectors like :not and :-webkit-any have selector lists. Classes, ids and
tag names in those lists were not taken into account when building class
invalidation sets.

Re-introduce a white-list for supported pseudos and disallow :not and
:-webkit-any for now.

R=esprehn@chromium.org,chrishtr@chromium.org
BUG=344893

Review URL: https://codereview.chromium.org/174013010

git-svn-id: svn://svn.chromium.org/blink/trunk@167560 bbb929c8-8fbe-4397-9dbb-9b2b20218538
  • Loading branch information
rune@opera.com committed Feb 21, 2014
1 parent f54b22e commit 8b4d2ba
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Change classes affecting :-webkit-any and :not.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS getComputedStyle(t1, null).backgroundColor is transparent
PASS getComputedStyle(t1, null).backgroundColor is green
PASS getComputedStyle(t2, null).backgroundColor is transparent
PASS getComputedStyle(t2, null).backgroundColor is green
PASS getComputedStyle(t3, null).backgroundColor is transparent
PASS getComputedStyle(t3, null).backgroundColor is green
PASS getComputedStyle(t4, null).backgroundColor is transparent
PASS getComputedStyle(t4, null).backgroundColor is green
PASS getComputedStyle(t5, null).backgroundColor is transparent
PASS getComputedStyle(t5, null).backgroundColor is green
PASS successfullyParsed is true

TEST COMPLETE
Background should be green
Background should be green
Background should be green
Background should be green
Background should be green
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<script src="../../../resources/js-test.js"></script>
<style>
.a1 .a2:-webkit-any(.a3, .a4) { background-color: green }
.b1 .b2:not(.b3) { background-color: green }
.c1 .c2:-webkit-any(:not(.c3)) { background-color: green }
.d1:not(.d2) .d3 { background-color: green; }
.e1 :not(.e2) { background-color: green; }
</style>
<div class="a1">
<div class="a2" id="t1">Background should be green</div>
</div>
<div class="b1">
<div class="b2 b3" id="t2">Background should be green</div>
</div>
<div class="c1">
<div class="c2 c3" id="t3">Background should be green</div>
</div>
<div id="outer-d" class="d1 d2">
<div id="t4" class="d3">Background should be green</div>
</div>
<div id="outer-e">
<div id="t5">Background should be green</div>
</div>
<script>
description("Change classes affecting :-webkit-any and :not.")

document.body.offsetTop; // force style recalc.

var transparent = 'rgba(0, 0, 0, 0)';
var green = 'rgb(0, 128, 0)';

var t1 = document.getElementById("t1");
shouldBe("getComputedStyle(t1, null).backgroundColor", "transparent");
t1.className = "a2 a3";
shouldBe("getComputedStyle(t1, null).backgroundColor", "green");

var t2 = document.getElementById("t2");
shouldBe("getComputedStyle(t2, null).backgroundColor", "transparent");
t2.className = "b2";
shouldBe("getComputedStyle(t2, null).backgroundColor", "green");

var t3 = document.getElementById("t3");
shouldBe("getComputedStyle(t3, null).backgroundColor", "transparent");
t3.className = "c2";
shouldBe("getComputedStyle(t3, null).backgroundColor", "green");

var t4 = document.getElementById("t4");
shouldBe("getComputedStyle(t4, null).backgroundColor", "transparent");
document.getElementById("outer-d").className = "d1";
shouldBe("getComputedStyle(t4, null).backgroundColor", "green");

var t5 = document.getElementById("t5");
shouldBe("getComputedStyle(t5, null).backgroundColor", "transparent");
document.getElementById("outer-e").className = "e1";
shouldBe("getComputedStyle(t5, null).backgroundColor", "green");
</script>
52 changes: 49 additions & 3 deletions third_party/WebKit/Source/core/css/RuleFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,58 @@ namespace WebCore {

static bool isSkippableComponentForInvalidation(const CSSSelector& selector)
{
if (selector.matchesPseudoElement() || selector.pseudoType() == CSSSelector::PseudoHost)
if (selector.m_match == CSSSelector::Tag
|| selector.m_match == CSSSelector::Id
|| selector.isAttributeSelector())
return true;
if (selector.m_match != CSSSelector::PseudoClass)
return false;
return true;
switch (selector.pseudoType()) {
case CSSSelector::PseudoEmpty:
case CSSSelector::PseudoFirstChild:
case CSSSelector::PseudoFirstOfType:
case CSSSelector::PseudoLastChild:
case CSSSelector::PseudoLastOfType:
case CSSSelector::PseudoOnlyChild:
case CSSSelector::PseudoOnlyOfType:
case CSSSelector::PseudoNthChild:
case CSSSelector::PseudoNthOfType:
case CSSSelector::PseudoNthLastChild:
case CSSSelector::PseudoNthLastOfType:
case CSSSelector::PseudoLink:
case CSSSelector::PseudoVisited:
case CSSSelector::PseudoAnyLink:
case CSSSelector::PseudoHover:
case CSSSelector::PseudoDrag:
case CSSSelector::PseudoFocus:
case CSSSelector::PseudoActive:
case CSSSelector::PseudoChecked:
case CSSSelector::PseudoEnabled:
case CSSSelector::PseudoDefault:
case CSSSelector::PseudoDisabled:
case CSSSelector::PseudoOptional:
case CSSSelector::PseudoRequired:
case CSSSelector::PseudoReadOnly:
case CSSSelector::PseudoReadWrite:
case CSSSelector::PseudoValid:
case CSSSelector::PseudoInvalid:
case CSSSelector::PseudoIndeterminate:
case CSSSelector::PseudoTarget:
case CSSSelector::PseudoLang:
case CSSSelector::PseudoRoot:
case CSSSelector::PseudoScope:
case CSSSelector::PseudoInRange:
case CSSSelector::PseudoOutOfRange:
case CSSSelector::PseudoUnresolved:
return true;
default:
return false;
}
ASSERT_NOT_REACHED();
return false;
}

// This method is somewhat conservative in what it acceptss.
// This method is somewhat conservative in what it accepts.
static bool supportsClassDescendantInvalidation(const CSSSelector& selector)
{
bool foundDescendantRelation = false;
Expand Down

0 comments on commit 8b4d2ba

Please sign in to comment.