Title: [226613] trunk
Revision
226613
Author
[email protected]
Date
2018-01-08 22:19:20 -0800 (Mon, 08 Jan 2018)

Log Message

Special list-item counter starts from an incorrect number for ::before and ::after
https://bugs.webkit.org/show_bug.cgi?id=181084

Reviewed by Zalan Bujtas.

Source/WebCore:

Test: fast/css/counters/counter-list-item.html

* Sources.txt: Removed CounterDirectives.cpp.
* WebCore.xcodeproj/project.pbxproj: Ditto.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::counterToCSSValue): Updated for changes to the CounterDirectives struct.
* css/StyleBuilderCustom.h:
(WebCore::StyleBuilderCustom::applyInheritCounter): Ditto.
(WebCore::StyleBuilderCustom::applyValueCounter): Ditto.

* html/HTMLLIElement.cpp:
(WebCore::HTMLLIElement::parseValue): Call setExplicitValue(std::nullopt) instead
of clearExplicitValue since we are using std::optional now.

* rendering/RenderCounter.cpp:
(WebCore::listItemCounterDirectives): Added. Computes the counter directives that
express the effects on the list-item counter from list item and list elements.
Used something as close to what the CSS 3 draft says as possible. This uses a
negative increment when creating a list to counteract the positive increment done
by a list element, except in the case of an unordered list. This is where the bug
fix actually lies. Also fixed handling of reversed ordered lists at the same time.
(WebCore::planCounter): Refactored to use the function above. Also changed the
code to pay attention to both the counter directives and the implicit ones from
list item and list elements, getting as close as possible to what the specification
seems to call for.

* rendering/RenderListItem.cpp:
(WebCore::RenderListItem::RenderListItem): Since we are using std::optional and no
longer using bit fields, simplified the constructor for each list item.
(WebCore::RenderListItem::calcValue const): Deleted.
(WebCore::RenderListItem::updateValueNow const): Merged in all the code from the
old calcValue function, but it is also simpler now since m_value is std::optional.
(WebCore::RenderListItem::updateValue): Updated to use std::optional.
(WebCore::RenderListItem::setExplicitValue): Ditto.
(WebCore::RenderListItem::clearExplicitValue): Deleted.
(WebCore::RenderListItem::updateListMarkerNumbers): Updated to use std::optional.
(WebCore::RenderListItem::isInReversedOrderedList const): Added. This is used by
the counter code so it can decrement instead of incrementing.

* rendering/RenderListItem.h: Updated to use std::optional. Also marked functions
final instead of override and initialized m_notInList after making it not be a
bitfield any more.

* rendering/style/CounterDirectives.cpp: Removed.
* rendering/style/CounterDirectives.h: Removed most of the CounterDirectives
class and replaced it with a struct with two std::optional. Added an addClamped
function so the counter code can share it with the addIncrementValue function.
If we want to make a faster version that doesn't use double, we can come back
and do that. Also moved the == function to the header since the implementation
is so trivial.

* rendering/style/StyleAllInOne.cpp: Removed CounterDirectives.cpp.

* rendering/style/StyleRareNonInheritedData.cpp:
(WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData): Updated to
use std::make_unique directly instead of using a clone function.

LayoutTests:

* fast/css/counters/counter-list-item-expected.html: Added.
* fast/css/counters/counter-list-item.html: Added.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (226612 => 226613)


--- trunk/LayoutTests/ChangeLog	2018-01-09 04:08:21 UTC (rev 226612)
+++ trunk/LayoutTests/ChangeLog	2018-01-09 06:19:20 UTC (rev 226613)
@@ -1,3 +1,13 @@
+2018-01-08  Darin Adler  <[email protected]>
+
+        Special list-item counter starts from an incorrect number for ::before and ::after
+        https://bugs.webkit.org/show_bug.cgi?id=181084
+
+        Reviewed by Zalan Bujtas.
+
+        * fast/css/counters/counter-list-item-expected.html: Added.
+        * fast/css/counters/counter-list-item.html: Added.
+
 2018-01-08  Said Abou-Hallawa  <[email protected]>
 
         A canvas should not be tainted if it draws a data URL SVGImage with a <foreignObject>

Added: trunk/LayoutTests/fast/css/counters/counter-list-item-expected.html (0 => 226613)


--- trunk/LayoutTests/fast/css/counters/counter-list-item-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/counters/counter-list-item-expected.html	2018-01-09 06:19:20 UTC (rev 226613)
@@ -0,0 +1,98 @@
+<!DOCTYPE HTML>
+
+<h2>Test counter(list-item), using generated content</h2>
+
+<div style="float: left; width: 200px">
+
+Ordered lists
+
+<ol>
+    <li>1 a 1</li>
+    <li>2 b 2</li>
+    <li>3 c 3</li>
+</ol>
+
+<ol>
+    <li value="30">30 a 30</li>
+    <li value="31">31 b 31</li>
+    <li value="32">32 c 32</li>
+</ol>
+
+<ol>
+    <li>1 a 1</li>
+    <li>2 b 2</li>
+    <li value="30">30 c 30</li>
+    <li value="31">31 d 31</li>
+    <li value="35">35 e 35</li>
+    <li value="36">36 f 36</li>
+</ol>
+
+</div>
+
+<div style="float: left; width: 200px">
+
+Reversed ordered lists
+
+<ol>
+    <li value="3">3 a 3</li>
+    <li value="2">2 b 2</li>
+    <li value="1">1 c 1</li>
+</ol>
+
+<ol>
+    <li value="30">30 a 30</li>
+    <li value="29">29 b 29</li>
+    <li value="28">28 c 28</li>
+</ol>
+
+<ol>
+    <li value="6">6 a 6</li>
+    <li value="5">5 b 5</li>
+    <li value="30">30 c 30</li>
+    <li value="29">29 d 29</li>
+    <li value="35">35 e 35</li>
+    <li value="34">34 f 34</li>
+</ol>
+
+</div>
+
+<div style="float: left; width: 200px">
+
+Unordered lists
+
+<ul>
+    <li>1 a 1</li>
+    <li>2 b 2</li>
+    <li>3 c 3</li>
+</ul>
+
+<ul>
+    <li>1 a 1</li>
+    <li>2 b 2</li>
+    <li>30 c 30</li>
+    <li>31 d 31</li>
+    <li>35 e 35</li>
+    <li>36 f 36</li>
+</ul>
+
+</div>
+
+<div style="float: left; width: 200px">
+
+Some simple combinations with directives
+
+<ol>
+    <li>100 a 100</li>
+    <li>300 b 300</li>
+    <li>401 c 401</li>
+    <li>1100 d 1100</li>
+</ol>
+
+<ol>
+    <li value="30">30 a 30</li>
+    <li value="31">230 b 230</li>
+    <li value="32">401 c 401</li>
+    <li value="33">1100 d 1100</li>
+</ol>
+
+</div>

Added: trunk/LayoutTests/fast/css/counters/counter-list-item.html (0 => 226613)


--- trunk/LayoutTests/fast/css/counters/counter-list-item.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/counters/counter-list-item.html	2018-01-09 06:19:20 UTC (rev 226613)
@@ -0,0 +1,108 @@
+<!DOCTYPE HTML>
+
+<style>
+li:before {
+    content: counter(list-item) " ";
+}
+li:after {
+    content: " " counter(list-item);
+}
+</style>
+
+<h2>Test counter(list-item), using generated content</h2>
+
+<div style="float: left; width: 200px">
+
+Ordered lists
+
+<ol>
+    <li>a</li>
+    <li>b</li>
+    <li>c</li>
+</ol>
+
+<ol start="30">
+    <li>a</li>
+    <li>b</li>
+    <li>c</li>
+</ol>
+
+<ol>
+    <li>a</li>
+    <li>b</li>
+    <li value="30">c</li>
+    <li>d</li>
+    <li value="35">e</li>
+    <li>f</li>
+</ol>
+
+</div>
+
+<div style="float: left; width: 200px">
+
+Reversed ordered lists
+
+<ol reversed>
+    <li>a</li>
+    <li>b</li>
+    <li>c</li>
+</ol>
+
+<ol start="30" reversed>
+    <li>a</li>
+    <li>b</li>
+    <li>c</li>
+</ol>
+
+<ol reversed>
+    <li>a</li>
+    <li>b</li>
+    <li value="30">c</li>
+    <li>d</li>
+    <li value="35">e</li>
+    <li>f</li>
+</ol>
+
+</div>
+
+<div style="float: left; width: 200px">
+
+Unordered lists
+
+<ul>
+    <li>a</li>
+    <li>b</li>
+    <li>c</li>
+</ul>
+
+<ul>
+    <li>a</li>
+    <li>b</li>
+    <li value="30">c</li>
+    <li>d</li>
+    <li value="35">e</li>
+    <li>f</li>
+</ul>
+
+</div>
+
+<div style="float: left; width: 200px">
+
+Some simple combinations with directives
+
+<ol style="counter-reset: list-item 100">
+    <li>a</li>
+    <li style="counter-increment: list-item 200">b</li>
+    <li style="counter-reset: list-item 400">c</li>
+    <li style="counter-reset: list-item 500; counter-increment: list-item 600">d</li>
+</ol>
+
+<ol start="30">
+    <li>a</li>
+    <li style="counter-increment: list-item 200">b</li>
+    <li style="counter-reset: list-item 400">c</li>
+    <li style="counter-reset: list-item 500; counter-increment: list-item 600">d</li>
+</ol>
+
+</div>
+

Modified: trunk/Source/WebCore/ChangeLog (226612 => 226613)


--- trunk/Source/WebCore/ChangeLog	2018-01-09 04:08:21 UTC (rev 226612)
+++ trunk/Source/WebCore/ChangeLog	2018-01-09 06:19:20 UTC (rev 226613)
@@ -1,3 +1,68 @@
+2018-01-08  Darin Adler  <[email protected]>
+
+        Special list-item counter starts from an incorrect number for ::before and ::after
+        https://bugs.webkit.org/show_bug.cgi?id=181084
+
+        Reviewed by Zalan Bujtas.
+
+        Test: fast/css/counters/counter-list-item.html
+
+        * Sources.txt: Removed CounterDirectives.cpp.
+        * WebCore.xcodeproj/project.pbxproj: Ditto.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::counterToCSSValue): Updated for changes to the CounterDirectives struct.
+        * css/StyleBuilderCustom.h:
+        (WebCore::StyleBuilderCustom::applyInheritCounter): Ditto.
+        (WebCore::StyleBuilderCustom::applyValueCounter): Ditto.
+
+        * html/HTMLLIElement.cpp:
+        (WebCore::HTMLLIElement::parseValue): Call setExplicitValue(std::nullopt) instead
+        of clearExplicitValue since we are using std::optional now.
+
+        * rendering/RenderCounter.cpp:
+        (WebCore::listItemCounterDirectives): Added. Computes the counter directives that
+        express the effects on the list-item counter from list item and list elements.
+        Used something as close to what the CSS 3 draft says as possible. This uses a
+        negative increment when creating a list to counteract the positive increment done
+        by a list element, except in the case of an unordered list. This is where the bug
+        fix actually lies. Also fixed handling of reversed ordered lists at the same time.
+        (WebCore::planCounter): Refactored to use the function above. Also changed the
+        code to pay attention to both the counter directives and the implicit ones from
+        list item and list elements, getting as close as possible to what the specification
+        seems to call for.
+
+        * rendering/RenderListItem.cpp:
+        (WebCore::RenderListItem::RenderListItem): Since we are using std::optional and no
+        longer using bit fields, simplified the constructor for each list item.
+        (WebCore::RenderListItem::calcValue const): Deleted.
+        (WebCore::RenderListItem::updateValueNow const): Merged in all the code from the
+        old calcValue function, but it is also simpler now since m_value is std::optional.
+        (WebCore::RenderListItem::updateValue): Updated to use std::optional.
+        (WebCore::RenderListItem::setExplicitValue): Ditto.
+        (WebCore::RenderListItem::clearExplicitValue): Deleted.
+        (WebCore::RenderListItem::updateListMarkerNumbers): Updated to use std::optional.
+        (WebCore::RenderListItem::isInReversedOrderedList const): Added. This is used by
+        the counter code so it can decrement instead of incrementing.
+
+        * rendering/RenderListItem.h: Updated to use std::optional. Also marked functions
+        final instead of override and initialized m_notInList after making it not be a
+        bitfield any more.
+
+        * rendering/style/CounterDirectives.cpp: Removed.
+        * rendering/style/CounterDirectives.h: Removed most of the CounterDirectives
+        class and replaced it with a struct with two std::optional. Added an addClamped
+        function so the counter code can share it with the addIncrementValue function.
+        If we want to make a faster version that doesn't use double, we can come back
+        and do that. Also moved the == function to the header since the implementation
+        is so trivial.
+
+        * rendering/style/StyleAllInOne.cpp: Removed CounterDirectives.cpp.
+
+        * rendering/style/StyleRareNonInheritedData.cpp:
+        (WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData): Updated to
+        use std::make_unique directly instead of using a clone function.
+
 2018-01-08  Wenson Hsieh  <[email protected]>
 
         [Attachment Support] Expose HTMLAttachmentElement.uniqueIdentifier to bindings

Modified: trunk/Source/WebCore/Sources.txt (226612 => 226613)


--- trunk/Source/WebCore/Sources.txt	2018-01-09 04:08:21 UTC (rev 226612)
+++ trunk/Source/WebCore/Sources.txt	2018-01-09 06:19:20 UTC (rev 226613)
@@ -1898,7 +1898,6 @@
 
 rendering/style/BasicShapes.cpp
 rendering/style/ContentData.cpp
-rendering/style/CounterDirectives.cpp
 rendering/style/FillLayer.cpp
 rendering/style/GridPosition.cpp
 rendering/style/GridPositionsResolver.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (226612 => 226613)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-01-09 04:08:21 UTC (rev 226612)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-01-09 06:19:20 UTC (rev 226613)
@@ -12355,7 +12355,6 @@
 		BC5EB8B70E8201BD00B25965 /* StyleDeprecatedFlexibleBoxData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleDeprecatedFlexibleBoxData.h; sourceTree = "<group>"; };
 		BC5EB8C10E82031B00B25965 /* ShadowData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShadowData.cpp; sourceTree = "<group>"; };
 		BC5EB8C20E82031B00B25965 /* ShadowData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShadowData.h; sourceTree = "<group>"; };
-		BC5EB94E0E82056B00B25965 /* CounterDirectives.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CounterDirectives.cpp; sourceTree = "<group>"; };
 		BC5EB94F0E82056B00B25965 /* CounterDirectives.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CounterDirectives.h; sourceTree = "<group>"; };
 		BC5EB9780E82069200B25965 /* CounterContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CounterContent.h; sourceTree = "<group>"; };
 		BC5EB97E0E82072500B25965 /* ContentData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContentData.cpp; sourceTree = "<group>"; };
@@ -23297,7 +23296,6 @@
 				BC5EB97E0E82072500B25965 /* ContentData.cpp */,
 				BC5EB97F0E82072500B25965 /* ContentData.h */,
 				BC5EB9780E82069200B25965 /* CounterContent.h */,
-				BC5EB94E0E82056B00B25965 /* CounterDirectives.cpp */,
 				BC5EB94F0E82056B00B25965 /* CounterDirectives.h */,
 				BC2272A10E82E87C00E7F975 /* CursorData.h */,
 				BC2272AC0E82E8F300E7F975 /* CursorList.h */,

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (226612 => 226613)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2018-01-09 04:08:21 UTC (rev 226612)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2018-01-09 06:19:20 UTC (rev 226613)
@@ -1937,10 +1937,10 @@
 
     auto& cssValuePool = CSSValuePool::singleton();
     auto list = CSSValueList::createSpaceSeparated();
-    for (CounterDirectiveMap::const_iterator it = map->begin(); it != map->end(); ++it) {
-        list->append(cssValuePool.createValue(it->key, CSSPrimitiveValue::CSS_STRING));
-        short number = propertyID == CSSPropertyCounterIncrement ? it->value.incrementValue() : it->value.resetValue();
-        list->append(cssValuePool.createValue((double)number, CSSPrimitiveValue::CSS_NUMBER));
+    for (auto& keyValue : *map) {
+        list->append(cssValuePool.createValue(keyValue.key, CSSPrimitiveValue::CSS_STRING));
+        double number = (propertyID == CSSPropertyCounterIncrement ? keyValue.value.incrementValue : keyValue.value.resetValue).value_or(0);
+        list->append(cssValuePool.createValue(number, CSSPrimitiveValue::CSS_NUMBER));
     }
     return WTFMove(list);
 }

Modified: trunk/Source/WebCore/css/StyleBuilderCustom.h (226612 => 226613)


--- trunk/Source/WebCore/css/StyleBuilderCustom.h	2018-01-09 04:08:21 UTC (rev 226612)
+++ trunk/Source/WebCore/css/StyleBuilderCustom.h	2018-01-09 06:19:20 UTC (rev 226613)
@@ -1140,9 +1140,9 @@
     for (auto& keyValue : const_cast<RenderStyle*>(styleResolver.parentStyle())->accessCounterDirectives()) {
         CounterDirectives& directives = map.add(keyValue.key, CounterDirectives()).iterator->value;
         if (counterBehavior == Reset)
-            directives.inheritReset(keyValue.value);
+            directives.resetValue = keyValue.value.resetValue;
         else
-            directives.inheritIncrement(keyValue.value);
+            directives.incrementValue = keyValue.value.incrementValue;
     }
 }
 
@@ -1157,9 +1157,9 @@
     CounterDirectiveMap& map = styleResolver.style()->accessCounterDirectives();
     for (auto& keyValue : map) {
         if (counterBehavior == Reset)
-            keyValue.value.clearReset();
+            keyValue.value.resetValue = std::nullopt;
         else
-            keyValue.value.clearIncrement();
+            keyValue.value.incrementValue = std::nullopt;
     }
 
     if (setCounterIncrementToNone)
@@ -1174,7 +1174,7 @@
         int value = pair->second()->intValue();
         CounterDirectives& directives = map.add(identifier, CounterDirectives()).iterator->value;
         if (counterBehavior == Reset)
-            directives.setResetValue(value);
+            directives.resetValue = value;
         else
             directives.addIncrementValue(value);
     }

Modified: trunk/Source/WebCore/html/HTMLLIElement.cpp (226612 => 226613)


--- trunk/Source/WebCore/html/HTMLLIElement.cpp	2018-01-09 04:08:21 UTC (rev 226612)
+++ trunk/Source/WebCore/html/HTMLLIElement.cpp	2018-01-09 06:19:20 UTC (rev 226613)
@@ -120,7 +120,7 @@
     if (valueOK)
         downcast<RenderListItem>(*renderer()).setExplicitValue(requestedValue);
     else
-        downcast<RenderListItem>(*renderer()).clearExplicitValue();
+        downcast<RenderListItem>(*renderer()).setExplicitValue(std::nullopt);
 }
 
 }

Modified: trunk/Source/WebCore/rendering/RenderCounter.cpp (226612 => 226613)


--- trunk/Source/WebCore/rendering/RenderCounter.cpp	2018-01-09 04:08:21 UTC (rev 226612)
+++ trunk/Source/WebCore/rendering/RenderCounter.cpp	2018-01-09 06:19:20 UTC (rev 226613)
@@ -1,6 +1,6 @@
-/**
+/*
  * Copyright (C) 2004 Allan Sandfeld Jensen ([email protected])
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2018 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -106,6 +106,26 @@
     return next ? next->renderer() : nullptr;
 }
 
+static CounterDirectives listItemCounterDirectives(RenderElement& renderer)
+{
+    CounterDirectives directives;
+    if (is<RenderListItem>(renderer)) {
+        auto& item = downcast<RenderListItem>(renderer);
+        if (auto explicitValue = item.explicitValue())
+            directives.resetValue = explicitValue.value();
+        else
+            directives.addIncrementValue(item.isInReversedOrderedList() ? -1 : 1);
+    } else if (auto element = renderer.element()) {
+        if (is<HTMLOListElement>(*element)) {
+            auto& list = downcast<HTMLOListElement>(*element);
+            directives.resetValue = list.start();
+            directives.addIncrementValue(list.isReversed() ? 1 : -1);
+        } else if (element->hasTagName(ulTag) || element->hasTagName(menuTag) || element->hasTagName(dirTag))
+            directives.resetValue = 0;
+    }
+    return directives;
+}
+
 static bool planCounter(RenderElement& renderer, const AtomicString& identifier, bool& isReset, int& value)
 {
     // We must have a generating node or else we cannot have a counter.
@@ -113,7 +133,7 @@
     if (!generatingElement)
         return false;
 
-    const RenderStyle& style = renderer.style();
+    auto& style = renderer.style();
 
     switch (style.styleType()) {
     case NOPSEUDO:
@@ -129,38 +149,26 @@
         return false; // Counters are forbidden from all other pseudo elements.
     }
 
-    const CounterDirectives directives = style.getCounterDirectives(identifier);
-    if (directives.isDefined()) {
-        value = directives.combinedValue();
-        isReset = directives.isReset();
-        return true;
-    }
+    auto directives = style.getCounterDirectives(identifier);
 
     if (identifier == "list-item") {
-        if (is<RenderListItem>(renderer)) {
-            if (downcast<RenderListItem>(renderer).hasExplicitValue()) {
-                value = downcast<RenderListItem>(renderer).explicitValue();
-                isReset = true;
-                return true;
-            }
-            value = 1;
-            isReset = false;
-            return true;
-        }
-        if (Element* element = renderer.element()) {
-            if (is<HTMLOListElement>(*element)) {
-                value = downcast<HTMLOListElement>(*element).start();
-                isReset = true;
-                return true;
-            }
-            if (element->hasTagName(ulTag) || element->hasTagName(menuTag) || element->hasTagName(dirTag)) {
-                value = 0;
-                isReset = true;
-                return true;
-            }
-        }
+        auto itemDirectives = listItemCounterDirectives(renderer);
+        if (!directives.resetValue)
+            directives.resetValue = itemDirectives.resetValue;
+        if (!directives.incrementValue)
+            directives.incrementValue = itemDirectives.incrementValue;
     }
 
+    if (directives.resetValue) {
+        value = CounterDirectives::addClamped(directives.resetValue.value(), directives.incrementValue.value_or(0));
+        isReset = true;
+        return true;
+    }
+    if (directives.incrementValue) {
+        value = directives.incrementValue.value();
+        isReset = false;
+        return true;
+    }
     return false;
 }
 

Modified: trunk/Source/WebCore/rendering/RenderListItem.cpp (226612 => 226613)


--- trunk/Source/WebCore/rendering/RenderListItem.cpp	2018-01-09 04:08:21 UTC (rev 226612)
+++ trunk/Source/WebCore/rendering/RenderListItem.cpp	2018-01-09 06:19:20 UTC (rev 226613)
@@ -1,7 +1,7 @@
-/**
+/*
  * Copyright (C) 1999 Lars Knoll ([email protected])
  *           (C) 1999 Antti Koivisto ([email protected])
- * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2003-2018 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Andrew Wellington ([email protected])
  *
  * This library is free software; you can redistribute it and/or
@@ -51,9 +51,6 @@
 
 RenderListItem::RenderListItem(Element& element, RenderStyle&& style)
     : RenderBlockFlow(element, WTFMove(style))
-    , m_hasExplicitValue(false)
-    , m_isValueUpToDate(false)
-    , m_notInList(false)
 {
     setInline(false);
 }
@@ -195,38 +192,30 @@
     return itemCount;
 }
 
-inline int RenderListItem::calcValue() const
+void RenderListItem::updateValueNow() const
 {
-    if (m_hasExplicitValue)
-        return m_explicitValue;
+    auto* list = enclosingList(*this);
+    auto* orderedList = is<HTMLOListElement>(list) ? downcast<HTMLOListElement>(list) : nullptr;
 
-    Element* list = enclosingList(*this);
-    HTMLOListElement* oListElement = is<HTMLOListElement>(list) ? downcast<HTMLOListElement>(list) : nullptr;
-    int valueStep = 1;
-    if (oListElement && oListElement->isReversed())
-        valueStep = -1;
-
     // FIXME: This recurses to a possible depth of the length of the list.
-    // That's not good -- we need to change this to an iterative algorithm.
-    if (RenderListItem* previousItem = previousListItem(list, *this))
-        return previousItem->value() + valueStep;
+    // That's not good, and we can and should change this to an iterative algorithm.
+    if (auto* previousItem = previousListItem(list, *this)) {
+        m_value = previousItem->value() + (orderedList && orderedList->isReversed() ? -1 : 1);
+        return;
+    }
 
-    if (oListElement)
-        return oListElement->start();
+    if (orderedList) {
+        m_value = orderedList->start();
+        return;
+    }
 
-    return 1;
+    m_value = 1;
 }
 
-void RenderListItem::updateValueNow() const
-{
-    m_value = calcValue();
-    m_isValueUpToDate = true;
-}
-
 void RenderListItem::updateValue()
 {
-    if (!m_hasExplicitValue) {
-        m_isValueUpToDate = false;
+    if (!m_explicitValue) {
+        m_value = std::nullopt;
         if (m_marker)
             m_marker->setNeedsLayoutAndPrefWidthsRecalc();
     }
@@ -391,25 +380,15 @@
         item->updateValue();
 }
 
-void RenderListItem::setExplicitValue(int value)
+void RenderListItem::setExplicitValue(std::optional<int> value)
 {
-    if (m_hasExplicitValue && m_explicitValue == value)
+    if (m_explicitValue == value)
         return;
     m_explicitValue = value;
     m_value = value;
-    m_hasExplicitValue = true;
     explicitValueChanged();
 }
 
-void RenderListItem::clearExplicitValue()
-{
-    if (!m_hasExplicitValue)
-        return;
-    m_hasExplicitValue = false;
-    m_isValueUpToDate = false;
-    explicitValueChanged();
-}
-
 static inline RenderListItem* previousOrNextItem(bool isListReversed, Element& list, RenderListItem& item)
 {
     return isListReversed ? previousListItem(&list, item) : nextListItem(list, item);
@@ -429,7 +408,7 @@
         isListReversed = oListElement.isReversed();
     }
     for (RenderListItem* item = previousOrNextItem(isListReversed, *listNode, *this); item; item = previousOrNextItem(isListReversed, *listNode, *item)) {
-        if (!item->m_isValueUpToDate) {
+        if (!item->m_value) {
             // If an item has been marked for update before, we can safely
             // assume that all the following ones have too.
             // This gives us the opportunity to stop here and avoid
@@ -440,4 +419,11 @@
     }
 }
 
+bool RenderListItem::isInReversedOrderedList() const
+{
+    auto* list = enclosingList(*this);
+    auto* orderedList = is<HTMLOListElement>(list) ? downcast<HTMLOListElement>(list) : nullptr;
+    return orderedList && orderedList->isReversed();
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/RenderListItem.h (226612 => 226613)


--- trunk/Source/WebCore/rendering/RenderListItem.h	2018-01-09 04:08:21 UTC (rev 226612)
+++ trunk/Source/WebCore/rendering/RenderListItem.h	2018-01-09 06:19:20 UTC (rev 226613)
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 1999 Lars Knoll ([email protected])
  *           (C) 1999 Antti Koivisto ([email protected])
- * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2003-2018 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -34,15 +34,14 @@
 public:
     RenderListItem(Element&, RenderStyle&&);
     virtual ~RenderListItem();
+
     Element& element() const { return downcast<Element>(nodeForNonAnonymous()); }
 
-    int value() const { if (!m_isValueUpToDate) updateValueNow(); return m_value; }
+    int value() const;
     void updateValue();
 
-    bool hasExplicitValue() const { return m_hasExplicitValue; }
-    int explicitValue() const { return m_explicitValue; }
-    void setExplicitValue(int value);
-    void clearExplicitValue();
+    std::optional<int> explicitValue() const { return m_explicitValue; }
+    void setExplicitValue(std::optional<int>);
 
     void setNotInList(bool notInList) { m_notInList = notInList; }
     bool notInList() const { return m_notInList; }
@@ -60,40 +59,45 @@
     RenderListMarker* markerRenderer() const { return m_marker.get(); }
     void setMarkerRenderer(RenderListMarker& marker) { m_marker = makeWeakPtr(marker); }
 
+    bool isInReversedOrderedList() const;
+
 private:
-    void willBeDestroyed() override;
+    void willBeDestroyed() final;
 
-    const char* renderName() const override { return "RenderListItem"; }
+    const char* renderName() const final { return "RenderListItem"; }
 
-    bool isListItem() const override { return true; }
+    bool isListItem() const final { return true; }
     
-    void insertedIntoTree() override;
-    void willBeRemovedFromTree() override;
+    void insertedIntoTree() final;
+    void willBeRemovedFromTree() final;
 
-    void paint(PaintInfo&, const LayoutPoint&) override;
+    void paint(PaintInfo&, const LayoutPoint&) final;
 
-    void layout() override;
+    void layout() final;
 
     void positionListMarker();
 
-    void addOverflowFromChildren() override;
-    void computePreferredLogicalWidths() override;
+    void addOverflowFromChildren() final;
+    void computePreferredLogicalWidths() final;
 
-    inline int calcValue() const;
     void updateValueNow() const;
     void explicitValueChanged();
 
-
-    int m_explicitValue;
+    std::optional<int> m_explicitValue;
     WeakPtr<RenderListMarker> m_marker;
-    mutable int m_value;
-    bool m_hasExplicitValue : 1;
-    mutable bool m_isValueUpToDate : 1;
-    bool m_notInList : 1;
+    mutable std::optional<int> m_value;
+    bool m_notInList { false };
 };
 
 bool isHTMLListElement(const Node&);
 
+inline int RenderListItem::value() const
+{
+    if (!m_value)
+        updateValueNow();
+    return m_value.value();
+}
+
 } // namespace WebCore
 
 SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderListItem, isListItem())

Deleted: trunk/Source/WebCore/rendering/style/CounterDirectives.cpp (226612 => 226613)


--- trunk/Source/WebCore/rendering/style/CounterDirectives.cpp	2018-01-09 04:08:21 UTC (rev 226612)
+++ trunk/Source/WebCore/rendering/style/CounterDirectives.cpp	2018-01-09 06:19:20 UTC (rev 226613)
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 1999 Antti Koivisto ([email protected])
- * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-#include "config.h"
-#include "CounterDirectives.h"
-
-namespace WebCore {
-
-bool operator==(const CounterDirectives& a, const CounterDirectives& b)
-{
-    return a.isIncrement() == b.isIncrement()
-      && a.incrementValue() == b.incrementValue()
-      && a.isReset() == b.isReset()
-      && a.resetValue() == b.resetValue();
-}
-
-std::unique_ptr<CounterDirectiveMap> clone(const CounterDirectiveMap& counterDirectives)
-{
-    auto result = std::make_unique<CounterDirectiveMap>();
-    *result = counterDirectives;
-    return result;
-}
-
-} // namespace WebCore

Modified: trunk/Source/WebCore/rendering/style/CounterDirectives.h (226612 => 226613)


--- trunk/Source/WebCore/rendering/style/CounterDirectives.h	2018-01-09 04:08:21 UTC (rev 226612)
+++ trunk/Source/WebCore/rendering/style/CounterDirectives.h	2018-01-09 06:19:20 UTC (rev 226613)
@@ -2,7 +2,7 @@
  * Copyright (C) 2000 Lars Knoll ([email protected])
  *           (C) 2000 Antti Koivisto ([email protected])
  *           (C) 2000 Dirk Mueller ([email protected])
- * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2003-2018 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Graham Dennis ([email protected])
  *
  * This library is free software; you can redistribute it and/or
@@ -32,77 +32,22 @@
 
 namespace WebCore {
 
-class CounterDirectives {
-public:
-    CounterDirectives()
-        : m_isResetSet(false)
-        , m_isIncrementSet(false)
-        , m_resetValue(0)
-        , m_incrementValue(0)
-    {
-    }
+struct CounterDirectives {
+    std::optional<int> resetValue;
+    std::optional<int> incrementValue;
 
-    // FIXME: The code duplication here could possibly be replaced by using two
-    // maps, or by using a container that held two generic Directive objects.
-
-    bool isReset() const { return m_isResetSet; }
-    int resetValue() const { return m_resetValue; }
-    void setResetValue(int value)
-    {
-        m_resetValue = value;
-        m_isResetSet = true;
-    }
-    void clearReset()
-    {
-        m_resetValue = 0;
-        m_isResetSet = false;
-    }
-    void inheritReset(CounterDirectives& parent)
-    {
-        m_resetValue = parent.m_resetValue;
-        m_isResetSet = parent.m_isResetSet;
-    }
-
-    bool isIncrement() const { return m_isIncrementSet; }
-    int incrementValue() const { return m_incrementValue; }
-    void addIncrementValue(int value)
-    {
-        m_incrementValue = clampToInteger((double)m_incrementValue + value);
-        m_isIncrementSet = true;
-    }
-    void clearIncrement()
-    {
-        m_incrementValue = 0;
-        m_isIncrementSet = false;
-    }
-    void inheritIncrement(CounterDirectives& parent)
-    {
-        m_incrementValue = parent.m_incrementValue;
-        m_isIncrementSet = parent.m_isIncrementSet;
-    }
-
-    bool isDefined() const { return isReset() || isIncrement(); }
-
-    int combinedValue() const
-    {
-        ASSERT(m_isResetSet || !m_resetValue);
-        ASSERT(m_isIncrementSet || !m_incrementValue);
-        // FIXME: Shouldn't allow overflow here.
-        return m_resetValue + m_incrementValue;
-    }
-
-private:
-    bool m_isResetSet;
-    bool m_isIncrementSet;
-    int m_resetValue;
-    int m_incrementValue;
+    void addIncrementValue(int additionalIncrement) { incrementValue = addClamped(incrementValue.value_or(0), additionalIncrement); }
+    static int addClamped(int a, int b) { return clampToInteger(static_cast<double>(a) + b);  }
 };
 
 bool operator==(const CounterDirectives&, const CounterDirectives&);
 inline bool operator!=(const CounterDirectives& a, const CounterDirectives& b) { return !(a == b); }
 
-typedef HashMap<AtomicString, CounterDirectives> CounterDirectiveMap;
+using CounterDirectiveMap = HashMap<AtomicString, CounterDirectives>;
 
-std::unique_ptr<CounterDirectiveMap> clone(const CounterDirectiveMap&);
+inline bool operator==(const CounterDirectives& a, const CounterDirectives& b)
+{
+    return a.incrementValue == b.incrementValue && a.resetValue == b.resetValue;
+}
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/style/StyleAllInOne.cpp (226612 => 226613)


--- trunk/Source/WebCore/rendering/style/StyleAllInOne.cpp	2018-01-09 04:08:21 UTC (rev 226612)
+++ trunk/Source/WebCore/rendering/style/StyleAllInOne.cpp	2018-01-09 06:19:20 UTC (rev 226613)
@@ -27,7 +27,6 @@
 
 #include "BasicShapes.cpp"
 #include "ContentData.cpp"
-#include "CounterDirectives.cpp"
 #include "FillLayer.cpp"
 #include "GridPositionsResolver.cpp"
 #include "KeyframeList.cpp"

Modified: trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp (226612 => 226613)


--- trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp	2018-01-09 04:08:21 UTC (rev 226612)
+++ trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp	2018-01-09 06:19:20 UTC (rev 226613)
@@ -135,7 +135,7 @@
     , scrollSnapArea(o.scrollSnapArea)
 #endif
     , content(o.content ? o.content->clone() : nullptr)
-    , counterDirectives(o.counterDirectives ? clone(*o.counterDirectives) : nullptr)
+    , counterDirectives(o.counterDirectives ? std::make_unique<CounterDirectiveMap>(*o.counterDirectives) : nullptr)
     , altText(o.altText)
     , boxShadow(o.boxShadow ? std::make_unique<ShadowData>(*o.boxShadow) : nullptr)
     , willChange(o.willChange)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to