haikuwebkit/LayoutTests/fast/selectors/empty-adjacent-style-update...

74 lines
3.9 KiB
HTML
Raw Permalink Normal View History

CSS JIT: compile the :empty pseudo class https://bugs.webkit.org/show_bug.cgi?id=135958 Reviewed by Andreas Kling. Source/WebCore: Compile :empty, nothing fancy. Tests: fast/selectors/empty-basics.html fast/selectors/empty-long-adjacent-backtracking.html fast/selectors/empty-adjacent-style-update.html fast/selectors/empty-style-update.html * cssjit/SelectorCompiler.cpp: (WebCore::SelectorCompiler::addPseudoClassType): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementMatching): (WebCore::SelectorCompiler::jumpIfElementIsNotEmpty): (WebCore::SelectorCompiler::setElementStyleIsAffectedByEmpty): (WebCore::SelectorCompiler::setElementStyleFromContextIsAffectedByEmptyAndUpdateRenderStyleIfNecessary): (WebCore::SelectorCompiler::setElementStyleIsAffectedByEmptyAndUpdateRenderStyleIfNecessary): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsEmpty): * dom/CharacterData.h: (WebCore::CharacterData::dataMemoryOffset): * dom/ContainerNode.h: (WebCore::ContainerNode::firstChildMemoryOffset): * dom/Node.h: (WebCore::Node::flagIsText): Source/WTF: * wtf/text/StringImpl.h: (WTF::StringImpl::lengthMemoryOffset): LayoutTests: Add some test coverage, :empty had very little testing. The test empty-adjacent-style-update expose some problems with style update, I will look into them separately. * fast/selectors/empty-adjacent-style-update-expected.txt: Added. * fast/selectors/empty-adjacent-style-update.html: Added. * fast/selectors/empty-basics-expected.txt: Added. * fast/selectors/empty-basics.html: Added. * fast/selectors/empty-long-adjacent-backtracking-expected.txt: Added. * fast/selectors/empty-long-adjacent-backtracking.html: Added. * fast/selectors/empty-style-update-expected.txt: Added. * fast/selectors/empty-style-update.html: Added. Canonical link: https://commits.webkit.org/153820@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@172619 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-08-15 04:06:27 +00:00
<!doctype html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<style>
target {
background-color: white;
}
The style is not updated correctly when the pseudo class :empty is applied on anything but the rightmost element https://bugs.webkit.org/show_bug.cgi?id=135999 Reviewed by Antti Koivisto. Source/WebCore: In Element's checkForEmptyStyleChange(), the style invalidation was only considering the invalidation of the element for which the subtree has changed. When the pseudo class :empty is used with a sibling combinator (e.g. foo:empty+bar), we were never invalidating the style of the element on which the selector applies. This patch fixes the issue by invalidating the whole subtree rooted at the parent if the :empty rules applies to siblings. A new flag "styleOfSiblingsAffectedByEmpty" is introduced to cover this case. SelectorChecker just sets the flag all the time if any sibling rule exists. This is overkill but that code is just there for non-jit cases. SelectorCompiler does a better job and only sets the flag if matching anything else than the rightmost element. There is a case not optimized, :empty with descendant (e.g. foo:empty>bar). Those cases are useless in practice, it is not worth optimizing them. Tests: fast/css/pseudo-element-updates-on-empty.html fast/selectors/not-empty-adjacent-style-update.html fast/selectors/not-empty-style-update.html * css/SelectorChecker.cpp: (WebCore::SelectorChecker::checkOne): * cssjit/SelectorCompiler.cpp: (WebCore::SelectorCompiler::fragmentMatchesTheRightmostElement): shouldUseRenderStyleFromCheckingContext() is renamed fragmentMatchesTheRightmostElement() because it is now also used by generateElementIsEmpty() in a context where the Context's style is irrelevant. (WebCore::SelectorCompiler::SelectorCodeGenerator::generateSelectorChecker): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsActive): (WebCore::SelectorCompiler::setStyleOfSiblingsAffectedByEmpty): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsEmpty): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsFirstChild): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsHovered): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsLastChild): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsOnlyChild): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsNthChild): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementHasPseudoElement): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateRequestedPseudoElementEqualsToSelectorPseudoElement): (WebCore::SelectorCompiler::shouldUseRenderStyleFromCheckingContext): Deleted. (WebCore::SelectorCompiler::setElementStyleIsAffectedByEmptyAndUpdateRenderStyleIfNecessary): Deleted. * dom/Element.cpp: (WebCore::checkForEmptyStyleChange): (WebCore::Element::setStyleOfSiblingsAffectedByEmpty): (WebCore::Element::rareDataStyleOfSiblingsAffectedByEmpty): * dom/Element.h: (WebCore::Element::styleOfSiblingsAffectedByEmpty): * dom/ElementRareData.h: (WebCore::ElementRareData::styleOfSiblingsAffectedByEmpty): (WebCore::ElementRareData::setStyleOfSiblingsAffectedByEmpty): (WebCore::ElementRareData::ElementRareData): LayoutTests: * fast/css/pseudo-element-updates-on-empty-expected.html: Added. * fast/css/pseudo-element-updates-on-empty.html: Added. * fast/selectors/empty-adjacent-style-update-expected.txt: * fast/selectors/empty-adjacent-style-update.html: * fast/selectors/empty-style-update-expected.txt: * fast/selectors/empty-style-update.html: * fast/selectors/not-empty-adjacent-style-update-expected.txt: Copied from LayoutTests/fast/selectors/empty-adjacent-style-update-expected.txt. * fast/selectors/not-empty-adjacent-style-update.html: Copied from LayoutTests/fast/selectors/empty-adjacent-style-update.html. * fast/selectors/not-empty-style-update-expected.txt: Copied from LayoutTests/fast/selectors/empty-style-update-expected.txt. * fast/selectors/not-empty-style-update.html: Copied from LayoutTests/fast/selectors/empty-style-update.html. Canonical link: https://commits.webkit.org/153895@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@172721 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-08-18 20:52:04 +00:00
testcase:empty + target {
CSS JIT: compile the :empty pseudo class https://bugs.webkit.org/show_bug.cgi?id=135958 Reviewed by Andreas Kling. Source/WebCore: Compile :empty, nothing fancy. Tests: fast/selectors/empty-basics.html fast/selectors/empty-long-adjacent-backtracking.html fast/selectors/empty-adjacent-style-update.html fast/selectors/empty-style-update.html * cssjit/SelectorCompiler.cpp: (WebCore::SelectorCompiler::addPseudoClassType): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementMatching): (WebCore::SelectorCompiler::jumpIfElementIsNotEmpty): (WebCore::SelectorCompiler::setElementStyleIsAffectedByEmpty): (WebCore::SelectorCompiler::setElementStyleFromContextIsAffectedByEmptyAndUpdateRenderStyleIfNecessary): (WebCore::SelectorCompiler::setElementStyleIsAffectedByEmptyAndUpdateRenderStyleIfNecessary): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsEmpty): * dom/CharacterData.h: (WebCore::CharacterData::dataMemoryOffset): * dom/ContainerNode.h: (WebCore::ContainerNode::firstChildMemoryOffset): * dom/Node.h: (WebCore::Node::flagIsText): Source/WTF: * wtf/text/StringImpl.h: (WTF::StringImpl::lengthMemoryOffset): LayoutTests: Add some test coverage, :empty had very little testing. The test empty-adjacent-style-update expose some problems with style update, I will look into them separately. * fast/selectors/empty-adjacent-style-update-expected.txt: Added. * fast/selectors/empty-adjacent-style-update.html: Added. * fast/selectors/empty-basics-expected.txt: Added. * fast/selectors/empty-basics.html: Added. * fast/selectors/empty-long-adjacent-backtracking-expected.txt: Added. * fast/selectors/empty-long-adjacent-backtracking.html: Added. * fast/selectors/empty-style-update-expected.txt: Added. * fast/selectors/empty-style-update.html: Added. Canonical link: https://commits.webkit.org/153820@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@172619 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-08-15 04:06:27 +00:00
background-color: rgb(1, 2, 3);
}
</style>
</head>
<body>
<div>
<testcase id="with-renderer"></testcase>
<target id="target-with-renderer"></target>
</div>
<div style="display:none;">
<testcase id="without-renderer"></testcase>
<target id="target-without-renderer"></target>
</div>
</body>
<script>
description('Test the style with a :empty pseudo class used for a sibling of the styled element.');
var testCaseWithRender = document.getElementById("with-renderer");
var testCaseWithoutRenderer = document.getElementById("without-renderer");
The style is not updated correctly when the pseudo class :empty is applied on anything but the rightmost element https://bugs.webkit.org/show_bug.cgi?id=135999 Reviewed by Antti Koivisto. Source/WebCore: In Element's checkForEmptyStyleChange(), the style invalidation was only considering the invalidation of the element for which the subtree has changed. When the pseudo class :empty is used with a sibling combinator (e.g. foo:empty+bar), we were never invalidating the style of the element on which the selector applies. This patch fixes the issue by invalidating the whole subtree rooted at the parent if the :empty rules applies to siblings. A new flag "styleOfSiblingsAffectedByEmpty" is introduced to cover this case. SelectorChecker just sets the flag all the time if any sibling rule exists. This is overkill but that code is just there for non-jit cases. SelectorCompiler does a better job and only sets the flag if matching anything else than the rightmost element. There is a case not optimized, :empty with descendant (e.g. foo:empty>bar). Those cases are useless in practice, it is not worth optimizing them. Tests: fast/css/pseudo-element-updates-on-empty.html fast/selectors/not-empty-adjacent-style-update.html fast/selectors/not-empty-style-update.html * css/SelectorChecker.cpp: (WebCore::SelectorChecker::checkOne): * cssjit/SelectorCompiler.cpp: (WebCore::SelectorCompiler::fragmentMatchesTheRightmostElement): shouldUseRenderStyleFromCheckingContext() is renamed fragmentMatchesTheRightmostElement() because it is now also used by generateElementIsEmpty() in a context where the Context's style is irrelevant. (WebCore::SelectorCompiler::SelectorCodeGenerator::generateSelectorChecker): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsActive): (WebCore::SelectorCompiler::setStyleOfSiblingsAffectedByEmpty): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsEmpty): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsFirstChild): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsHovered): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsLastChild): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsOnlyChild): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsNthChild): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementHasPseudoElement): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateRequestedPseudoElementEqualsToSelectorPseudoElement): (WebCore::SelectorCompiler::shouldUseRenderStyleFromCheckingContext): Deleted. (WebCore::SelectorCompiler::setElementStyleIsAffectedByEmptyAndUpdateRenderStyleIfNecessary): Deleted. * dom/Element.cpp: (WebCore::checkForEmptyStyleChange): (WebCore::Element::setStyleOfSiblingsAffectedByEmpty): (WebCore::Element::rareDataStyleOfSiblingsAffectedByEmpty): * dom/Element.h: (WebCore::Element::styleOfSiblingsAffectedByEmpty): * dom/ElementRareData.h: (WebCore::ElementRareData::styleOfSiblingsAffectedByEmpty): (WebCore::ElementRareData::setStyleOfSiblingsAffectedByEmpty): (WebCore::ElementRareData::ElementRareData): LayoutTests: * fast/css/pseudo-element-updates-on-empty-expected.html: Added. * fast/css/pseudo-element-updates-on-empty.html: Added. * fast/selectors/empty-adjacent-style-update-expected.txt: * fast/selectors/empty-adjacent-style-update.html: * fast/selectors/empty-style-update-expected.txt: * fast/selectors/empty-style-update.html: * fast/selectors/not-empty-adjacent-style-update-expected.txt: Copied from LayoutTests/fast/selectors/empty-adjacent-style-update-expected.txt. * fast/selectors/not-empty-adjacent-style-update.html: Copied from LayoutTests/fast/selectors/empty-adjacent-style-update.html. * fast/selectors/not-empty-style-update-expected.txt: Copied from LayoutTests/fast/selectors/empty-style-update-expected.txt. * fast/selectors/not-empty-style-update.html: Copied from LayoutTests/fast/selectors/empty-style-update.html. Canonical link: https://commits.webkit.org/153895@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@172721 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-08-18 20:52:04 +00:00
debug("Initial state is empty.");
CSS JIT: compile the :empty pseudo class https://bugs.webkit.org/show_bug.cgi?id=135958 Reviewed by Andreas Kling. Source/WebCore: Compile :empty, nothing fancy. Tests: fast/selectors/empty-basics.html fast/selectors/empty-long-adjacent-backtracking.html fast/selectors/empty-adjacent-style-update.html fast/selectors/empty-style-update.html * cssjit/SelectorCompiler.cpp: (WebCore::SelectorCompiler::addPseudoClassType): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementMatching): (WebCore::SelectorCompiler::jumpIfElementIsNotEmpty): (WebCore::SelectorCompiler::setElementStyleIsAffectedByEmpty): (WebCore::SelectorCompiler::setElementStyleFromContextIsAffectedByEmptyAndUpdateRenderStyleIfNecessary): (WebCore::SelectorCompiler::setElementStyleIsAffectedByEmptyAndUpdateRenderStyleIfNecessary): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsEmpty): * dom/CharacterData.h: (WebCore::CharacterData::dataMemoryOffset): * dom/ContainerNode.h: (WebCore::ContainerNode::firstChildMemoryOffset): * dom/Node.h: (WebCore::Node::flagIsText): Source/WTF: * wtf/text/StringImpl.h: (WTF::StringImpl::lengthMemoryOffset): LayoutTests: Add some test coverage, :empty had very little testing. The test empty-adjacent-style-update expose some problems with style update, I will look into them separately. * fast/selectors/empty-adjacent-style-update-expected.txt: Added. * fast/selectors/empty-adjacent-style-update.html: Added. * fast/selectors/empty-basics-expected.txt: Added. * fast/selectors/empty-basics.html: Added. * fast/selectors/empty-long-adjacent-backtracking-expected.txt: Added. * fast/selectors/empty-long-adjacent-backtracking.html: Added. * fast/selectors/empty-style-update-expected.txt: Added. * fast/selectors/empty-style-update.html: Added. Canonical link: https://commits.webkit.org/153820@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@172619 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-08-15 04:06:27 +00:00
shouldBeEqualToString('getComputedStyle(document.getElementById("target-with-renderer")).backgroundColor', 'rgb(1, 2, 3)');
shouldBeEqualToString('getComputedStyle(document.getElementById("target-without-renderer")).backgroundColor', 'rgb(1, 2, 3)');
debug("Adding a comment does not change the :empty state.");
testCaseWithRender.appendChild(document.createComment("WebKit!"));
testCaseWithoutRenderer.appendChild(document.createComment("WebKit!"));
shouldBeEqualToString('getComputedStyle(document.getElementById("target-with-renderer")).backgroundColor', 'rgb(1, 2, 3)');
shouldBeEqualToString('getComputedStyle(document.getElementById("target-without-renderer")).backgroundColor', 'rgb(1, 2, 3)');
debug("Add an element as child make updates :empty.");
var elementForCaseWithRenderer = document.createElement('div');
var elementForCaseWithoutRenderer = document.createElement('div');
testCaseWithRender.appendChild(elementForCaseWithRenderer);
testCaseWithoutRenderer.appendChild(elementForCaseWithoutRenderer);
shouldBeEqualToString('getComputedStyle(document.getElementById("target-with-renderer")).backgroundColor', 'rgb(255, 255, 255)');
shouldBeEqualToString('getComputedStyle(document.getElementById("target-without-renderer")).backgroundColor', 'rgb(255, 255, 255)');
debug("Adding an empty text node, this is still not empty because of the element.");
testCaseWithRender.appendChild(document.createTextNode(''));
testCaseWithoutRenderer.appendChild(document.createTextNode(''));
shouldBeEqualToString('getComputedStyle(document.getElementById("target-with-renderer")).backgroundColor', 'rgb(255, 255, 255)');
shouldBeEqualToString('getComputedStyle(document.getElementById("target-without-renderer")).backgroundColor', 'rgb(255, 255, 255)');
debug("Removing the elements previously added should restore the :empty state.");
testCaseWithRender.removeChild(elementForCaseWithRenderer);
testCaseWithoutRenderer.removeChild(elementForCaseWithoutRenderer);
shouldBeEqualToString('getComputedStyle(document.getElementById("target-with-renderer")).backgroundColor', 'rgb(1, 2, 3)');
shouldBeEqualToString('getComputedStyle(document.getElementById("target-without-renderer")).backgroundColor', 'rgb(1, 2, 3)');
debug("Adding a non empty text node makes the state non empty.");
testCaseWithRender.appendChild(document.createTextNode('WebKit!'));
testCaseWithoutRenderer.appendChild(document.createTextNode('WebKit!'));
shouldBeEqualToString('getComputedStyle(document.getElementById("target-with-renderer")).backgroundColor', 'rgb(255, 255, 255)');
shouldBeEqualToString('getComputedStyle(document.getElementById("target-without-renderer")).backgroundColor', 'rgb(255, 255, 255)');
debug("Removing the last text child, back to being empty.");
testCaseWithRender.removeChild(testCaseWithRender.lastChild);
testCaseWithoutRenderer.removeChild(testCaseWithoutRenderer.lastChild);
shouldBeEqualToString('getComputedStyle(document.getElementById("target-with-renderer")).backgroundColor', 'rgb(1, 2, 3)');
shouldBeEqualToString('getComputedStyle(document.getElementById("target-without-renderer")).backgroundColor', 'rgb(1, 2, 3)');
</script>
<script src="../../resources/js-test-post.js"></script>
</html>