Commit caa05815 authored by rune@opera.com's avatar rune@opera.com

Support style invalidation for ::cue selectors.

Don't resort to subtree recalc in the presence of ::cue, ::cue(), :past
and :future selectors. Traverse the selector list in ::cue() to find
invalidation set features.

The test for the ::cue element yields a recalc for more than two elements
because ::cue is currently a PseudoWebKitCustomElement, and other such
elements are present as part of the shadow DOM for video elements.

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

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

git-svn-id: svn://svn.chromium.org/blink/trunk@185255 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d0442636
WEBVTT
1
00:00.000 --> 00:00.500
<00:00.000><i>Blah <b>Bleh </b></i><00:00.050><c>Ding </c><00:00.300><b.b>Booh</b>
Check that descendant style invalidation works with ::cue selectors.
EVENT(canplaythrough)
EVENT(seeked)
EXPECTED (getComputedStyle(cueNode).backgroundColor == 'rgb(255, 0, 0)') OK
EXPECTED (internals.updateStyleAndReturnAffectedElementCount() == '9') OK
EXPECTED (getComputedStyle(cueNode).backgroundColor == 'rgb(0, 128, 0)') OK
EXPECTED (getComputedStyle(cNode).backgroundColor == 'rgb(255, 0, 0)') OK
EXPECTED (internals.updateStyleAndReturnAffectedElementCount() == '2') OK
EXPECTED (getComputedStyle(cNode).backgroundColor == 'rgb(0, 128, 0)') OK
EXPECTED (getComputedStyle(iNode).backgroundColor == 'rgb(255, 0, 0)') OK
EXPECTED (internals.updateStyleAndReturnAffectedElementCount() == '2') OK
EXPECTED (getComputedStyle(iNode).backgroundColor == 'rgb(0, 128, 0)') OK
EXPECTED (getComputedStyle(bNode).backgroundColor == 'rgb(255, 0, 0)') OK
EXPECTED (internals.updateStyleAndReturnAffectedElementCount() == '2') OK
EXPECTED (getComputedStyle(bNode).backgroundColor == 'rgb(0, 128, 0)') OK
END OF TEST
<!DOCTYPE html>
<script src="../media-file.js"></script>
<script src="../video-test.js"></script>
<script src="../media-controls.js"></script>
<style>
video::cue,
video::cue(c),
video::cue(i:past),
video::cue(.b:future) { background-color: red }
.cue video::cue,
.cuefunc video::cue(c),
.past video::cue(i:past),
.future video::cue(.b:future) { background-color: green }
// This selector would have triggered sibling subtree recalc if we didn't
// support descendant invalidation for ::cue/::cue().
#ascendant + div { color: pink }
</style>
<script>
function seeked() {
var red = "rgb(255, 0, 0)";
var green = "rgb(0, 128, 0)";
cueNode = textTrackDisplayElement(video, "cue");
iNode = cueNode.firstElementChild;
cNode = iNode.nextSibling.nextSibling;
bNode = cNode.nextSibling.nextSibling;
testExpected("getComputedStyle(cueNode).backgroundColor", red);
ascendant.offsetTop;
ascendant.classList.add("cue");
if (window.internals)
testExpected("internals.updateStyleAndReturnAffectedElementCount()", 9);
testExpected("getComputedStyle(cueNode).backgroundColor", green);
testExpected("getComputedStyle(cNode).backgroundColor", red);
ascendant.offsetTop;
ascendant.classList.add("cuefunc");
if (window.internals)
testExpected("internals.updateStyleAndReturnAffectedElementCount()", 2);
testExpected("getComputedStyle(cNode).backgroundColor", green);
testExpected("getComputedStyle(iNode).backgroundColor", red);
ascendant.offsetTop;
ascendant.classList.add("past");
if (window.internals)
testExpected("internals.updateStyleAndReturnAffectedElementCount()", 2);
testExpected("getComputedStyle(iNode).backgroundColor", green);
testExpected("getComputedStyle(bNode).backgroundColor", red);
ascendant.offsetTop;
ascendant.classList.add("future");
if (window.internals)
testExpected("internals.updateStyleAndReturnAffectedElementCount()", 2);
testExpected("getComputedStyle(bNode).backgroundColor", green);
endTest();
}
window.onload = function() {
consoleWrite("Check that descendant style invalidation works with ::cue selectors.");
findMediaElement();
video.src = findMediaFile("video", "../content/test");
waitForEvent("seeked", seeked);
waitForEvent("canplaythrough", function() { video.currentTime = 0.1; });
};
</script>
<div id="ascendant">
<video>
<track src="captions-webvtt/invalidation.vtt" kind="captions" default>
</video>
<div></div>
<div></div>
</div>
<div>
<div></div>
</div>
......@@ -138,6 +138,9 @@ static bool supportsInvalidation(CSSSelector::PseudoType type)
case CSSSelector::PseudoInRange:
case CSSSelector::PseudoOutOfRange:
case CSSSelector::PseudoWebKitCustomElement:
case CSSSelector::PseudoCue:
case CSSSelector::PseudoFutureCue:
case CSSSelector::PseudoPastCue:
case CSSSelector::PseudoUnresolved:
case CSSSelector::PseudoContent:
case CSSSelector::PseudoHost:
......@@ -171,9 +174,6 @@ static bool requiresSubtreeInvalidation(const CSSSelector& selector)
switch (selector.pseudoType()) {
case CSSSelector::PseudoFirstLine:
case CSSSelector::PseudoFirstLetter:
case CSSSelector::PseudoCue:
case CSSSelector::PseudoFutureCue:
case CSSSelector::PseudoPastCue:
case CSSSelector::PseudoSpatialNavigationFocus:
// FIXME: Most pseudo classes/elements above can be supported and moved
// to assertSupportedPseudo(). Move on a case-by-case basis. If they
......@@ -200,6 +200,14 @@ void RuleFeature::trace(Visitor* visitor)
visitor->trace(rule);
}
static bool supportsInvalidationWithSelectorList(CSSSelector::PseudoType pseudo)
{
return pseudo == CSSSelector::PseudoAny
|| pseudo == CSSSelector::PseudoCue
|| pseudo == CSSSelector::PseudoHost
|| pseudo == CSSSelector::PseudoNot;
}
// This method is somewhat conservative in what it accepts.
RuleFeatureSet::InvalidationSetMode RuleFeatureSet::invalidationSetModeForSelector(const CSSSelector& selector)
{
......@@ -214,9 +222,7 @@ RuleFeatureSet::InvalidationSetMode RuleFeatureSet::invalidationSetModeForSelect
// We have found an invalidation set feature in the rightmost compound selector.
foundIdent = true;
}
} else if (component->pseudoType() == CSSSelector::PseudoNot
|| component->pseudoType() == CSSSelector::PseudoHost
|| component->pseudoType() == CSSSelector::PseudoAny) {
} else if (supportsInvalidationWithSelectorList(component->pseudoType())) {
if (const CSSSelectorList* selectorList = component->selectorList()) {
// Features inside :not() are not added to the feature set, so consider it a universal selector.
bool foundUniversal = component->pseudoType() == CSSSelector::PseudoNot;
......@@ -343,7 +349,7 @@ const CSSSelector* RuleFeatureSet::extractInvalidationSetFeatures(const CSSSelec
extractInvalidationSetFeature(*current, features);
// Initialize the entry in the invalidation set map, if supported.
invalidationSetForSelector(*current);
if (current->pseudoType() == CSSSelector::PseudoHost || current->pseudoType() == CSSSelector::PseudoAny || current->pseudoType() == CSSSelector::PseudoNot) {
if (supportsInvalidationWithSelectorList(current->pseudoType())) {
if (const CSSSelectorList* selectorList = current->selectorList()) {
for (const CSSSelector* selector = selectorList->first(); selector; selector = CSSSelectorList::next(*selector))
extractInvalidationSetFeatures(*selector, features, current->pseudoType() == CSSSelector::PseudoNot);
......@@ -405,7 +411,7 @@ void RuleFeatureSet::addFeaturesToInvalidationSets(const CSSSelector& selector,
if (current->isInsertionPointCrossing())
features.insertionPointCrossing = true;
if (const CSSSelectorList* selectorList = current->selectorList()) {
ASSERT(current->pseudoType() == CSSSelector::PseudoHost || current->pseudoType() == CSSSelector::PseudoAny || current->pseudoType() == CSSSelector::PseudoNot);
ASSERT(supportsInvalidationWithSelectorList(current->pseudoType()));
for (const CSSSelector* selector = selectorList->first(); selector; selector = CSSSelectorList::next(*selector))
addFeaturesToInvalidationSets(*selector, features);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment