Title: [95664] trunk
Revision
95664
Author
ad...@chromium.org
Date
2011-09-21 12:47:48 -0700 (Wed, 21 Sep 2011)

Log Message

Clean up CSS Counter code
https://bugs.webkit.org/show_bug.cgi?id=68492

Reviewed by Tony Chang.

Source/WebCore:

Several cleanups/fixes:
- Make Counter::listStyle() return the actual list style string,
  rather than empty string.
- Handle a specified list style of "none" correctly when generating
  cssText and in Counter::listStyle().
- Use StringBuilder when generating cssText.

Test: fast/css/counters/getCounterValue.html

* css/CSSParser.cpp:
(WebCore::CSSParser::parseCounterContent):
Simplify processing (moving conversion to CSSStyleSelector),
pass a CSS_IDENT as the listStyle to Counter::create.
* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::cssText):
Use StringBuilder.
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::applyProperty):
Convert from a CSS_IDENT to an EListStyleType.
* css/Counter.h:
(WebCore::Counter::listStyleIdent):
Renamed from listStyleNumber to match its new functionality.

LayoutTests:

Added tests for setting the list style to "none"
as well as tests for getCounterValue.

* fast/css/counters/counter-cssText-expected.txt:
* fast/css/counters/counter-cssText.html:
* fast/css/counters/getCounterValue-expected.txt: Added.
* fast/css/counters/getCounterValue.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (95663 => 95664)


--- trunk/LayoutTests/ChangeLog	2011-09-21 19:34:39 UTC (rev 95663)
+++ trunk/LayoutTests/ChangeLog	2011-09-21 19:47:48 UTC (rev 95664)
@@ -1,3 +1,18 @@
+2011-09-21  Adam Klein  <ad...@chromium.org>
+
+        Clean up CSS Counter code
+        https://bugs.webkit.org/show_bug.cgi?id=68492
+
+        Reviewed by Tony Chang.
+
+        Added tests for setting the list style to "none"
+        as well as tests for getCounterValue.
+
+        * fast/css/counters/counter-cssText-expected.txt:
+        * fast/css/counters/counter-cssText.html:
+        * fast/css/counters/getCounterValue-expected.txt: Added.
+        * fast/css/counters/getCounterValue.html: Added.
+
 2011-09-21  Chang Shu  <c...@webkit.org>
 
         [WK2] [Mac] Implement a more-complete MouseDown/MouseUp/MouseMoveTo functions for WebKit2 EventSender

Modified: trunk/LayoutTests/fast/css/counters/counter-cssText-expected.txt (95663 => 95664)


--- trunk/LayoutTests/fast/css/counters/counter-cssText-expected.txt	2011-09-21 19:34:39 UTC (rev 95663)
+++ trunk/LayoutTests/fast/css/counters/counter-cssText-expected.txt	2011-09-21 19:47:48 UTC (rev 95664)
@@ -7,6 +7,7 @@
 PASS rules[3].style.cssText is "content: counters(section, ':', decimal); "
 PASS rules[4].style.cssText is "content: counter(section, lower-roman); "
 PASS rules[5].style.cssText is "content: counters(section, ',', upper-roman); "
+PASS rules[6].style.cssText is "content: counter(section, none); "
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/css/counters/counter-cssText.html (95663 => 95664)


--- trunk/LayoutTests/fast/css/counters/counter-cssText.html	2011-09-21 19:34:39 UTC (rev 95663)
+++ trunk/LayoutTests/fast/css/counters/counter-cssText.html	2011-09-21 19:47:48 UTC (rev 95664)
@@ -21,6 +21,9 @@
 h3:after {
     content: counters(section, ",", upper-roman);
 }
+h4:before {
+    content: counter(section, none);
+}
 </style>
 </head>
 <p id=description></p>
@@ -32,6 +35,7 @@
 shouldBeEqualToString("rules[3].style.cssText", "content: counters(section, ':', decimal); ");
 shouldBeEqualToString("rules[4].style.cssText", "content: counter(section, lower-roman); ");
 shouldBeEqualToString("rules[5].style.cssText", "content: counters(section, ',', upper-roman); ");
+shouldBeEqualToString("rules[6].style.cssText", "content: counter(section, none); ");
 window.successfullyParsed = true;
 </script>
 <script src=""

Added: trunk/LayoutTests/fast/css/counters/getCounterValue-expected.txt (0 => 95664)


--- trunk/LayoutTests/fast/css/counters/getCounterValue-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/counters/getCounterValue-expected.txt	2011-09-21 19:47:48 UTC (rev 95664)
@@ -0,0 +1,24 @@
+Test the Counter object returned by the getCounterValue method of CSSPrimitiveValues
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS counters[0].identifier is "section"
+PASS counters[0].listStyle is "decimal"
+PASS counters[0].separator is ""
+PASS counters[1].identifier is "section"
+PASS counters[1].listStyle is "decimal"
+PASS counters[1].separator is ":"
+PASS counters[2].identifier is "section"
+PASS counters[2].listStyle is "lower-roman"
+PASS counters[2].separator is ""
+PASS counters[3].identifier is "section"
+PASS counters[3].listStyle is "upper-roman"
+PASS counters[3].separator is ","
+PASS counters[4].identifier is "section"
+PASS counters[4].listStyle is "none"
+PASS counters[4].separator is ""
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/css/counters/getCounterValue.html (0 => 95664)


--- trunk/LayoutTests/fast/css/counters/getCounterValue.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/counters/getCounterValue.html	2011-09-21 19:47:48 UTC (rev 95664)
@@ -0,0 +1,67 @@
+<html>
+<head>
+<link rel=stylesheet href=""
+<script src=""
+<style>
+body {
+    counter-reset: section;
+}
+h1 {
+    counter-increment: section;
+}
+h2:before {
+    content: counter(section);
+}
+h2:after {
+    content: counters(section, ":", decimal);
+}
+h3:before {
+    content: counter(section, lower-roman);
+}
+h3:after {
+    content: counters(section, ",", upper-roman);
+}
+h3:before {
+    content: counter(section, none);
+}
+</style>
+</head>
+<p id=description></p>
+<div id=console></div>
+<script>
+description("Test the Counter object returned by the getCounterValue method of CSSPrimitiveValues");
+
+function getCounter(cssRule) {
+    return cssRule.style.getPropertyCSSValue('content')[0].getCounterValue();
+}
+
+var rules = document.styleSheets[1].cssRules;
+var counters = [];
+for (var i = 2; i < rules.length; i++) {
+    counters.push(getCounter(rules[i]));
+}
+shouldBeEqualToString("counters[0].identifier", "section");
+shouldBeEqualToString("counters[0].listStyle", "decimal");
+shouldBeEqualToString("counters[0].separator", "");
+
+shouldBeEqualToString("counters[1].identifier", "section");
+shouldBeEqualToString("counters[1].listStyle", "decimal");
+shouldBeEqualToString("counters[1].separator", ":");
+
+shouldBeEqualToString("counters[2].identifier", "section");
+shouldBeEqualToString("counters[2].listStyle", "lower-roman");
+shouldBeEqualToString("counters[2].separator", "");
+
+shouldBeEqualToString("counters[3].identifier", "section");
+shouldBeEqualToString("counters[3].listStyle", "upper-roman");
+shouldBeEqualToString("counters[3].separator", ",");
+
+shouldBeEqualToString("counters[4].identifier", "section");
+shouldBeEqualToString("counters[4].listStyle", "none");
+shouldBeEqualToString("counters[4].separator", "");
+
+window.successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (95663 => 95664)


--- trunk/Source/WebCore/ChangeLog	2011-09-21 19:34:39 UTC (rev 95663)
+++ trunk/Source/WebCore/ChangeLog	2011-09-21 19:47:48 UTC (rev 95664)
@@ -1,3 +1,33 @@
+2011-09-21  Adam Klein  <ad...@chromium.org>
+
+        Clean up CSS Counter code
+        https://bugs.webkit.org/show_bug.cgi?id=68492
+
+        Reviewed by Tony Chang.
+
+        Several cleanups/fixes:
+        - Make Counter::listStyle() return the actual list style string,
+          rather than empty string.
+        - Handle a specified list style of "none" correctly when generating
+          cssText and in Counter::listStyle().
+        - Use StringBuilder when generating cssText.
+
+        Test: fast/css/counters/getCounterValue.html
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseCounterContent):
+        Simplify processing (moving conversion to CSSStyleSelector),
+        pass a CSS_IDENT as the listStyle to Counter::create.
+        * css/CSSPrimitiveValue.cpp:
+        (WebCore::CSSPrimitiveValue::cssText):
+        Use StringBuilder.
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::applyProperty):
+        Convert from a CSS_IDENT to an EListStyleType.
+        * css/Counter.h:
+        (WebCore::Counter::listStyleIdent):
+        Renamed from listStyleNumber to match its new functionality.
+
 2011-09-21  Chris Marrin  <cmar...@apple.com>
 
         Check in WebCore.vcproj file unchanged but written like MSDev likes it

Modified: trunk/Source/WebCore/css/CSSParser.cpp (95663 => 95664)


--- trunk/Source/WebCore/css/CSSParser.cpp	2011-09-21 19:34:39 UTC (rev 95663)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2011-09-21 19:47:48 UTC (rev 95664)
@@ -3663,7 +3663,7 @@
     RefPtr<CSSPrimitiveValue> listStyle;
     i = args->next();
     if (!i) // Make the list style default decimal
-        listStyle = primitiveValueCache()->createValue(CSSValueDecimal - CSSValueDisc, CSSPrimitiveValue::CSS_NUMBER);
+        listStyle = primitiveValueCache()->createIdentifierValue(CSSValueDecimal);
     else {
         if (i->unit != CSSParserValue::Operator || i->iValue != ',')
             return 0;
@@ -3672,15 +3672,13 @@
         if (i->unit != CSSPrimitiveValue::CSS_IDENT)
             return 0;
 
-        short ls = 0;
-        if (i->id == CSSValueNone)
-            ls = CSSValueKatakanaIroha - CSSValueDisc + 1;
-        else if (i->id >= CSSValueDisc && i->id <= CSSValueKatakanaIroha)
-            ls = i->id - CSSValueDisc;
+        int listStyleID = 0;
+        if (i->id == CSSValueNone || (i->id >= CSSValueDisc && i->id <= CSSValueKatakanaIroha))
+            listStyleID = i->id;
         else
             return 0;
 
-        listStyle = primitiveValueCache()->createValue(ls, (CSSPrimitiveValue::UnitTypes) i->unit);
+        listStyle = primitiveValueCache()->createIdentifierValue(listStyleID);
     }
 
     return primitiveValueCache()->createValue(Counter::create(identifier.release(), listStyle.release(), separator.release()));

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.cpp (95663 => 95664)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2011-09-21 19:34:39 UTC (rev 95663)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2011-09-21 19:47:48 UTC (rev 95664)
@@ -798,19 +798,27 @@
             text += ")";
             break;
         case CSS_COUNTER: {
+            DEFINE_STATIC_LOCAL(const String, counterParen, ("counter("));
+            DEFINE_STATIC_LOCAL(const String, countersParen, ("counters("));
+            DEFINE_STATIC_LOCAL(const String, commaSpace, (", "));
+
+            StringBuilder result;
             String separator = m_value.counter->separator();
-            text = separator.isEmpty() ? "counter(" : "counters(";
-            text += m_value.counter->identifier();
+            result.append(separator.isEmpty() ? counterParen : countersParen);
+
+            result.append(m_value.counter->identifier());
             if (!separator.isEmpty()) {
-                text += ", ";
-                text += quoteCSSStringIfNeeded(separator);
+                result.append(commaSpace);
+                result.append(quoteCSSStringIfNeeded(separator));
             }
-            const char* listStyleName = getValueName(m_value.counter->listStyleNumber() + CSSValueDisc);
-            if (listStyleName) {
-                text += ", ";
-                text += listStyleName;
+            String listStyle = m_value.counter->listStyle();
+            if (!listStyle.isEmpty()) {
+                result.append(commaSpace);
+                result.append(listStyle);
             }
-            text += ")";
+            result.append(')');
+
+            text = result.toString();
             break;
         }
         case CSS_RECT: {

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (95663 => 95664)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-09-21 19:34:39 UTC (rev 95663)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-09-21 19:47:48 UTC (rev 95664)
@@ -2697,8 +2697,11 @@
             }
             case CSSPrimitiveValue::CSS_COUNTER: {
                 Counter* counterValue = contentValue->getCounterValue();
-                OwnPtr<CounterContent> counter = adoptPtr(new CounterContent(counterValue->identifier(),
-                    (EListStyleType)counterValue->listStyleNumber(), counterValue->separator()));
+                EListStyleType listStyleType = NoneListStyle;
+                int listStyleIdent = counterValue->listStyleIdent();
+                if (listStyleIdent != CSSValueNone)
+                    listStyleType = static_cast<EListStyleType>(listStyleIdent - CSSValueDisc);
+                OwnPtr<CounterContent> counter = adoptPtr(new CounterContent(counterValue->identifier(), listStyleType, counterValue->separator()));
                 m_style->setContent(counter.release(), didSet);
                 didSet = true;
                 break;

Modified: trunk/Source/WebCore/css/Counter.h (95663 => 95664)


--- trunk/Source/WebCore/css/Counter.h	2011-09-21 19:34:39 UTC (rev 95663)
+++ trunk/Source/WebCore/css/Counter.h	2011-09-21 19:47:48 UTC (rev 95664)
@@ -37,7 +37,7 @@
     String listStyle() const { return m_listStyle ? m_listStyle->getStringValue() : String(); }
     String separator() const { return m_separator ? m_separator->getStringValue() : String(); }
 
-    int listStyleNumber() const { return m_listStyle ? m_listStyle->getIntValue() : 0; }
+    int listStyleIdent() const { return m_listStyle ? m_listStyle->getIdent() : 0; }
 
     void setIdentifier(PassRefPtr<CSSPrimitiveValue> identifier) { m_identifier = identifier; }
     void setListStyle(PassRefPtr<CSSPrimitiveValue> listStyle) { m_listStyle = listStyle; }
@@ -52,7 +52,7 @@
     }
 
     RefPtr<CSSPrimitiveValue> m_identifier; // string
-    RefPtr<CSSPrimitiveValue> m_listStyle; // int
+    RefPtr<CSSPrimitiveValue> m_listStyle; // ident
     RefPtr<CSSPrimitiveValue> m_separator; // string
 };
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to