[css-lists] Fix 'content: counter(list-item)' in pseudo-elements #24365
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
::before, ::after and ::marker pseudo-elements can use the counter()
function in the 'content' property in order to retrieve the value of a
counter. This was already working well, except for the automatic
'list-item' counter.
The problem was that in <ol> elements, the counter was set to the start
value. For example, in '<ol start="3"><li></li></ol>', the counter was 3
in ol::before, but <li> increments it, so it became 4 in li::before.
This patch sets it to the start value minus 1, according to the spec
https://drafts.csswg.org/css-lists/#ua-stylesheet
There was also the problem that list items would increment the value,
even in reversed lists. E.g. in '<ol reversed><li></li><li></li></ol>',
the counter used to be 2 in ol::before, 3 in li:first-child::before,
and 4 in li:last-child::before. This patch checks whether the list item
is in a reversed list in order to decide if the value should be
incremented or decremented.
Bug: 796961
TEST=external/wpt/css/css-lists/counter-list-item.html
TEST=external/wpt/css/css-pseudo/marker-content-002.html
TEST=external/wpt/css/css-pseudo/marker-content-005.html
The former test is imported from WebKit.
Change-Id: I011499095379df547820eb6417f68ab61cf5a23d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2270305
Reviewed-by: Rune Lillesveen <futhark@chromium.org>
Commit-Queue: Oriol Brufau <obrufau@igalia.com>
Cr-Commit-Position: refs/heads/master@{#783493}