Implement the matching for :nth-last-child(An+B of selector-list)
authorbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Nov 2014 21:00:33 +0000 (21:00 +0000)
committerbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Nov 2014 21:00:33 +0000 (21:00 +0000)
commit9078e4627d91a4a2b4c899be2143af7e0476dd38
tree40fbc20b299c176ca26b7d733bb4d539c99ccd7f
parent8449a1156132607aa78b85d44b482f82900d62bb
Implement the matching for :nth-last-child(An+B of selector-list)
https://bugs.webkit.org/show_bug.cgi?id=138650

Patch by Benjamin Poulain <bpoulain@apple.com> on 2014-11-13
Reviewed by Andreas Kling.

Source/WebCore:

Matching is trivial based on the existing CSS4 infrastructure.

The tricky part is style invalidation. In the cases of the old :nth-last-child()
and :nth-last-of-type(), we were using the flag ChildrenAffectedByBackwardPositionalRules.

The problem with ChildrenAffectedByBackwardPositionalRules is that it only invalidate
subtrees when nodes are being added or removed. It is a valuable optimization by itself
since tree updates are less common than property updates.

For the case of property updates, I have added the new flag "ChildrenAffectedByPropertyBasedBackwardPositionalRules".
It pretty much work the same way but invalidates subtree on style recalc.

Tests: fast/css/nth-child-and-nth-last-child.html
       fast/css/nth-last-child-of-classname.html
       fast/css/nth-last-child-of-complex-selector.html
       fast/css/nth-last-child-of-compound-selector.html
       fast/css/nth-last-child-of-style-sharing-1.html
       fast/css/nth-last-child-of-style-sharing-2.html
       fast/css/nth-last-child-of-style-update-optimization.html
       fast/css/nth-last-child-of-tagname.html
       fast/selectors/nth-last-child-of-class-style-update.html

* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne):
* dom/Element.cpp:
(WebCore::Element::setChildrenAffectedByPropertyBasedBackwardPositionalRules):
(WebCore::Element::hasFlagsSetDuringStylingOfChildren):
(WebCore::Element::rareDataChildrenAffectedByPropertyBasedBackwardPositionalRules):
* dom/Element.h:
(WebCore::Element::childrenAffectedByPropertyBasedBackwardPositionalRules):
* dom/ElementRareData.h:
(WebCore::ElementRareData::childrenAffectedByPropertyBasedBackwardPositionalRules):
(WebCore::ElementRareData::setChildrenAffectedByPropertyBasedBackwardPositionalRules):
(WebCore::ElementRareData::ElementRareData):
(WebCore::ElementRareData::resetDynamicRestyleObservations):
* dom/Node.cpp:
(WebCore::Node::updateAncestorsForStyleRecalc):
(WebCore::Node::setNeedsStyleRecalc):
(WebCore::markAncestorsWithChildNeedsStyleRecalc): Deleted.
* dom/Node.h:
Unlike the other marking steps, ChildrenAffectedByPropertyBasedBackwardPositionalRules can only really
affect one level (because we don't have a parent-selectors). It is quite easy to mark large
trees with ChildrenAffectedByPropertyBasedBackwardPositionalRules by using a selector list that is a bit
too generic. When that happen, we must be careful not invalidating everything, just the affected subtree.

LayoutTests:

* fast/selectors/nth-last-child-of-class-style-update-expected.txt: Added.
* fast/selectors/nth-last-child-of-class-style-update.html: Added.
Verify simple cases of style update.

* fast/css/nth-last-child-of-style-update-optimization-expected.txt: Added.
* fast/css/nth-last-child-of-style-update-optimization.html: Added.
Verify that style invalidation stays reasonable.

* fast/css/nth-last-child-of-style-sharing-1-expected.html: Added.
* fast/css/nth-last-child-of-style-sharing-1.html: Added.
* fast/css/nth-last-child-of-style-sharing-2-expected.html: Added.
* fast/css/nth-last-child-of-style-sharing-2.html: Added.
Check that style sharing is disabled for elements matching :nth-last-child().

* fast/css/nth-child-and-nth-last-child-expected.html: Added.
* fast/css/nth-child-and-nth-last-child.html: Added.
Test uniqueness testing by combining :nth-child() and :nth-last-child().

* fast/css/nth-last-child-of-classname-expected.html: Added.
* fast/css/nth-last-child-of-classname.html: Added.
* fast/css/nth-last-child-of-complex-selector-expected.html: Added.
* fast/css/nth-last-child-of-complex-selector.html: Added.
* fast/css/nth-last-child-of-compound-selector-expected.html: Added.
* fast/css/nth-last-child-of-compound-selector.html: Added.
* fast/css/nth-last-child-of-tagname-expected.html: Added.
* fast/css/nth-last-child-of-tagname.html: Added.
Test matching, those are the "last-child" counterpart of the existing
"nth-child-of" tests.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176084 268f45cc-cd09-0410-ab3c-d52691b4dbfc
26 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/css/nth-child-and-nth-last-child-expected.html [new file with mode: 0644]
LayoutTests/fast/css/nth-child-and-nth-last-child.html [new file with mode: 0644]
LayoutTests/fast/css/nth-last-child-of-classname-expected.html [new file with mode: 0644]
LayoutTests/fast/css/nth-last-child-of-classname.html [new file with mode: 0644]
LayoutTests/fast/css/nth-last-child-of-complex-selector-expected.html [new file with mode: 0644]
LayoutTests/fast/css/nth-last-child-of-complex-selector.html [new file with mode: 0644]
LayoutTests/fast/css/nth-last-child-of-compound-selector-expected.html [new file with mode: 0644]
LayoutTests/fast/css/nth-last-child-of-compound-selector.html [new file with mode: 0644]
LayoutTests/fast/css/nth-last-child-of-style-sharing-1-expected.html [new file with mode: 0644]
LayoutTests/fast/css/nth-last-child-of-style-sharing-1.html [new file with mode: 0644]
LayoutTests/fast/css/nth-last-child-of-style-sharing-2-expected.html [new file with mode: 0644]
LayoutTests/fast/css/nth-last-child-of-style-sharing-2.html [new file with mode: 0644]
LayoutTests/fast/css/nth-last-child-of-style-update-optimization-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/nth-last-child-of-style-update-optimization.html [new file with mode: 0644]
LayoutTests/fast/css/nth-last-child-of-tagname-expected.html [new file with mode: 0644]
LayoutTests/fast/css/nth-last-child-of-tagname.html [new file with mode: 0644]
LayoutTests/fast/selectors/nth-last-child-of-class-style-update-expected.txt [new file with mode: 0644]
LayoutTests/fast/selectors/nth-last-child-of-class-style-update.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/SelectorChecker.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/ElementRareData.h
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Node.h