Title: [111888] trunk
Revision
111888
Author
[email protected]
Date
2012-03-23 12:37:39 -0700 (Fri, 23 Mar 2012)

Log Message

CSSParser doesn't set border-*-width/style/color to initial by border shorthand property
https://bugs.webkit.org/show_bug.cgi?id=82040

Reviewed by Antti Koivisto.

Source/WebCore: 

The border shorthand property sets values for border-width, border-style, and border-color shorthand properties.
While CSSParser::parseValue can process these shorthand properties properly and set the longhand properties
such as border-top-width, border-right-width, ... border-left-color, CSSParser::addProperty can't and the
initialization in parseShorthand fails for the border property.

Fixed the bug by explicitly initializing longhand properties.

Changing the behavior here is unlikely to break the Web since our behavior already differs from that of Firefox
and Internet Explorer. Both of those browsers return the actual initial values such as "medium" and "currentColor".
This discrepancy is tracked by https://bugs.webkit.org/show_bug.cgi?id=82078.

Test: fast/css/border-shorthand-initialize-longhands.html

* css/CSSParser.cpp:
(WebCore::CSSParser::parseValue): Uses borderAbridgedLonghand.
(WebCore::CSSParser::parseShorthand): Uses longhand properties for initialization if one is available.
This allows us to initialize multiple properties (e.g. border-*-color) for a single property missing in the set.
* css/CSSPropertyLonghand.cpp:
(WebCore::borderAbridgedLonghand): Added. The longhand here (border-width, border-style, border-color) is
"abridged" in the sense that they're still shorthands.
* css/CSSPropertyLonghand.h:
(WebCore::CSSPropertyLonghand::CSSPropertyLonghand):
(CSSPropertyLonghand): Added the version that takes longhand instances for initialization purposes.
(WebCore::CSSPropertyLonghand::longhandsForInitialization):

LayoutTests: 

Added a comprehensive regression test.

* fast/css/border-shorthand-initialize-longhands-expected.txt: Added.
* fast/css/border-shorthand-initialize-longhands.html: Added.
* inspector/styles/styles-new-API-expected.txt: Correctly lists border's longhand properties.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (111887 => 111888)


--- trunk/LayoutTests/ChangeLog	2012-03-23 19:30:21 UTC (rev 111887)
+++ trunk/LayoutTests/ChangeLog	2012-03-23 19:37:39 UTC (rev 111888)
@@ -1,3 +1,16 @@
+2012-03-23  Ryosuke Niwa  <[email protected]>
+
+        CSSParser doesn't set border-*-width/style/color to initial by border shorthand property
+        https://bugs.webkit.org/show_bug.cgi?id=82040
+
+        Reviewed by Antti Koivisto.
+
+        Added a comprehensive regression test.
+
+        * fast/css/border-shorthand-initialize-longhands-expected.txt: Added.
+        * fast/css/border-shorthand-initialize-longhands.html: Added.
+        * inspector/styles/styles-new-API-expected.txt: Correctly lists border's longhand properties.
+
 2012-03-22  Ojan Vafai  <[email protected]>
 
         Initial triage pass of css3/selectors3/xhtml for the Chromium ports.

Added: trunk/LayoutTests/fast/css/border-shorthand-initialize-longhands-expected.txt (0 => 111888)


--- trunk/LayoutTests/fast/css/border-shorthand-initialize-longhands-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/border-shorthand-initialize-longhands-expected.txt	2012-03-23 19:37:39 UTC (rev 111888)
@@ -0,0 +1,22 @@
+This test ensures border shorthand property initializes longhand properties such as border-top-style and border-right-color.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS div.setAttribute('style', 'border: 1px');div.style.borderTopStyle is 'initial'
+PASS div.style.borderTopStyle is 'initial'
+PASS div.style.borderRightStyle is 'initial'
+PASS div.style.borderBottomStyle is 'initial'
+PASS div.style.borderLeftStyle is 'initial'
+PASS div.style.borderTopColor is 'initial'
+PASS div.style.borderRightColor is 'initial'
+PASS div.style.borderBottomColor is 'initial'
+PASS div.style.borderLeftColor is 'initial'
+PASS div.setAttribute('style', 'border: solid');div.style.borderTopWidth is 'initial'
+PASS div.style.borderRightWidth is 'initial'
+PASS div.style.borderBottomWidth is 'initial'
+PASS div.style.borderLeftWidth is 'initial'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/css/border-shorthand-initialize-longhands.html (0 => 111888)


--- trunk/LayoutTests/fast/css/border-shorthand-initialize-longhands.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/border-shorthand-initialize-longhands.html	2012-03-23 19:37:39 UTC (rev 111888)
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+
+description("This test ensures border shorthand property initializes longhand properties such as border-top-style and border-right-color.");
+
+var div = document.createElement('div');
+shouldBe("div.setAttribute('style', 'border: 1px');div.style.borderTopStyle", "'initial'");
+shouldBe("div.style.borderTopStyle", "'initial'");
+shouldBe("div.style.borderRightStyle", "'initial'");
+shouldBe("div.style.borderBottomStyle", "'initial'");
+shouldBe("div.style.borderLeftStyle", "'initial'");
+
+shouldBe("div.style.borderTopColor", "'initial'");
+shouldBe("div.style.borderRightColor", "'initial'");
+shouldBe("div.style.borderBottomColor", "'initial'");
+shouldBe("div.style.borderLeftColor", "'initial'");
+
+shouldBe("div.setAttribute('style', 'border: solid');div.style.borderTopWidth", "'initial'");
+shouldBe("div.style.borderRightWidth", "'initial'");
+shouldBe("div.style.borderBottomWidth", "'initial'");
+shouldBe("div.style.borderLeftWidth", "'initial'");
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/inspector/styles/styles-new-API-expected.txt (111887 => 111888)


--- trunk/LayoutTests/inspector/styles/styles-new-API-expected.txt	2012-03-23 19:30:21 UTC (rev 111887)
+++ trunk/LayoutTests/inspector/styles/styles-new-API-expected.txt	2012-03-23 19:37:39 UTC (rev 111888)
@@ -183,7 +183,10 @@
 ['border-right-style':'solid'] @[undefined-undefined] style
 ['border-bottom-style':'solid'] @[undefined-undefined] style
 ['border-left-style':'solid'] @[undefined-undefined] style
-['border-color':'initial'] @[undefined-undefined] style
+['border-top-color':'initial'] @[undefined-undefined] style
+['border-right-color':'initial'] @[undefined-undefined] style
+['border-bottom-color':'initial'] @[undefined-undefined] style
+['border-left-color':'initial'] @[undefined-undefined] style
 ['border-image':'initial'] @[undefined-undefined] style
 ['border-top-width':'0px'] @[undefined-undefined] style
 ['border-right-width':'0px'] @[undefined-undefined] style
@@ -420,7 +423,10 @@
 ['border-right-style':'solid'] @[undefined-undefined] style
 ['border-bottom-style':'solid'] @[undefined-undefined] style
 ['border-left-style':'solid'] @[undefined-undefined] style
-['border-color':'initial'] @[undefined-undefined] style
+['border-top-color':'initial'] @[undefined-undefined] style
+['border-right-color':'initial'] @[undefined-undefined] style
+['border-bottom-color':'initial'] @[undefined-undefined] style
+['border-left-color':'initial'] @[undefined-undefined] style
 ['border-image':'initial'] @[undefined-undefined] style
 ['border-top-width':'1px'] @[undefined-undefined] style
 ['border-right-width':'1px'] @[undefined-undefined] style
@@ -444,7 +450,10 @@
 ['border-right-style':'solid'] @[undefined-undefined] style
 ['border-bottom-style':'solid'] @[undefined-undefined] style
 ['border-left-style':'solid'] @[undefined-undefined] style
-['border-color':'initial'] @[undefined-undefined] style
+['border-top-color':'initial'] @[undefined-undefined] style
+['border-right-color':'initial'] @[undefined-undefined] style
+['border-bottom-color':'initial'] @[undefined-undefined] style
+['border-left-color':'initial'] @[undefined-undefined] style
 ['border-image':'initial'] @[undefined-undefined] style
 ['border-top-width':'1px'] @[undefined-undefined] style
 ['border-right-width':'1px'] @[undefined-undefined] style

Modified: trunk/Source/WebCore/ChangeLog (111887 => 111888)


--- trunk/Source/WebCore/ChangeLog	2012-03-23 19:30:21 UTC (rev 111887)
+++ trunk/Source/WebCore/ChangeLog	2012-03-23 19:37:39 UTC (rev 111888)
@@ -1,3 +1,35 @@
+2012-03-23  Ryosuke Niwa  <[email protected]>
+
+        CSSParser doesn't set border-*-width/style/color to initial by border shorthand property
+        https://bugs.webkit.org/show_bug.cgi?id=82040
+
+        Reviewed by Antti Koivisto.
+
+        The border shorthand property sets values for border-width, border-style, and border-color shorthand properties.
+        While CSSParser::parseValue can process these shorthand properties properly and set the longhand properties
+        such as border-top-width, border-right-width, ... border-left-color, CSSParser::addProperty can't and the
+        initialization in parseShorthand fails for the border property.
+
+        Fixed the bug by explicitly initializing longhand properties.
+
+        Changing the behavior here is unlikely to break the Web since our behavior already differs from that of Firefox
+        and Internet Explorer. Both of those browsers return the actual initial values such as "medium" and "currentColor".
+        This discrepancy is tracked by https://bugs.webkit.org/show_bug.cgi?id=82078.
+
+        Test: fast/css/border-shorthand-initialize-longhands.html
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseValue): Uses borderAbridgedLonghand.
+        (WebCore::CSSParser::parseShorthand): Uses longhand properties for initialization if one is available.
+        This allows us to initialize multiple properties (e.g. border-*-color) for a single property missing in the set.
+        * css/CSSPropertyLonghand.cpp:
+        (WebCore::borderAbridgedLonghand): Added. The longhand here (border-width, border-style, border-color) is
+        "abridged" in the sense that they're still shorthands.
+        * css/CSSPropertyLonghand.h:
+        (WebCore::CSSPropertyLonghand::CSSPropertyLonghand):
+        (CSSPropertyLonghand): Added the version that takes longhand instances for initialization purposes.
+        (WebCore::CSSPropertyLonghand::longhandsForInitialization):
+
 2012-03-23  Tony Chang  <[email protected]>
 
         [chromium] rename newwtf target back to wtf

Modified: trunk/Source/WebCore/css/CSSParser.cpp (111887 => 111888)


--- trunk/Source/WebCore/css/CSSParser.cpp	2012-03-23 19:30:21 UTC (rev 111887)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2012-03-23 19:37:39 UTC (rev 111888)
@@ -2278,8 +2278,7 @@
     case CSSPropertyBorder:
         // [ 'border-width' || 'border-style' || <color> ] | inherit
     {
-        const int properties[3] = { CSSPropertyBorderWidth, CSSPropertyBorderStyle, CSSPropertyBorderColor };
-        if (parseShorthand(propId, CSSPropertyLonghand(properties, 3), important)) {
+        if (parseShorthand(propId, borderAbridgedLonghand(), important)) {
             // The CSS3 Borders and Backgrounds specification says that border also resets border-image. It's as
             // though a value of none was specified for the image.
             addProperty(CSSPropertyBorderImage, cssValuePool()->createImplicitInitialValue(), important);
@@ -2803,13 +2802,13 @@
 
     bool found = false;
     unsigned propertiesParsed = 0;
-    bool fnd[6]= { false, false, false, false, false, false }; // 6 is enough size.
+    bool propertyFound[6]= { false, false, false, false, false, false }; // 6 is enough size.
 
     while (m_valueList->current()) {
         found = false;
         for (unsigned propIndex = 0; !found && propIndex < longhand.length(); ++propIndex) {
-            if (!fnd[propIndex] && parseValue(longhand.properties()[propIndex], important)) {
-                    fnd[propIndex] = found = true;
+            if (!propertyFound[propIndex] && parseValue(longhand.properties()[propIndex], important)) {
+                    propertyFound[propIndex] = found = true;
                     propertiesParsed++;
             }
         }
@@ -2825,8 +2824,16 @@
 
     // Fill in any remaining properties with the initial value.
     ImplicitScope implicitScope(this, PropertyImplicit);
+    const CSSPropertyLonghand* const* const longhandsForInitialization = longhand.longhandsForInitialization();
     for (unsigned i = 0; i < longhand.length(); ++i) {
-        if (!fnd[i])
+        if (propertyFound[i])
+            continue;
+
+        if (longhandsForInitialization) {
+            const CSSPropertyLonghand& initLonghand = *(longhandsForInitialization[i]);
+            for (unsigned propIndex = 0; propIndex < initLonghand.length(); ++propIndex)
+                addProperty(initLonghand.properties()[propIndex], cssValuePool()->createImplicitInitialValue(), important);
+        } else
             addProperty(longhand.properties()[i], cssValuePool()->createImplicitInitialValue(), important);
     }
 

Modified: trunk/Source/WebCore/css/CSSPropertyLonghand.cpp (111887 => 111888)


--- trunk/Source/WebCore/css/CSSPropertyLonghand.cpp	2012-03-23 19:30:21 UTC (rev 111887)
+++ trunk/Source/WebCore/css/CSSPropertyLonghand.cpp	2012-03-23 19:37:39 UTC (rev 111888)
@@ -71,6 +71,19 @@
     return borderLonghand;
 }
 
+const CSSPropertyLonghand& borderAbridgedLonghand()
+{
+    static const int borderAbridgedProperties[] = { CSSPropertyBorderWidth, CSSPropertyBorderStyle, CSSPropertyBorderColor };
+    static const CSSPropertyLonghand* propertiesForInitialization[] = {
+        &borderWidthLonghand(),
+        &borderStyleLonghand(),
+        &borderColorLonghand(),
+    };
+    DEFINE_STATIC_LOCAL(CSSPropertyLonghand, borderAbridgedLonghand,
+        (borderAbridgedProperties, propertiesForInitialization, WTF_ARRAY_LENGTH(borderAbridgedProperties)));
+    return borderAbridgedLonghand;
+}
+
 const CSSPropertyLonghand& borderBottomLonghand()
 {
     static const int borderBottomProperties[] = { CSSPropertyBorderBottomWidth, CSSPropertyBorderBottomStyle, CSSPropertyBorderBottomColor };

Modified: trunk/Source/WebCore/css/CSSPropertyLonghand.h (111887 => 111888)


--- trunk/Source/WebCore/css/CSSPropertyLonghand.h	2012-03-23 19:30:21 UTC (rev 111887)
+++ trunk/Source/WebCore/css/CSSPropertyLonghand.h	2012-03-23 19:37:39 UTC (rev 111888)
@@ -27,21 +27,32 @@
 public:
     CSSPropertyLonghand()
         : m_properties(0)
+        , m_longhandsForInitialization(0)
         , m_length(0)
     {
     }
 
-    CSSPropertyLonghand(const int* firstProperty, unsigned numProperties)
-        : m_properties(firstProperty)
+    CSSPropertyLonghand(const int* properties, unsigned numProperties)
+        : m_properties(properties)
+        , m_longhandsForInitialization(0)
         , m_length(numProperties)
     {
     }
 
+    CSSPropertyLonghand(const int* properties, const CSSPropertyLonghand** longhandsForInitialization, unsigned numProperties)
+        : m_properties(properties)
+        , m_longhandsForInitialization(longhandsForInitialization)
+        , m_length(numProperties)
+    {
+    }
+
     const int* properties() const { return m_properties; }
+    const CSSPropertyLonghand** longhandsForInitialization() const { return m_longhandsForInitialization; }
     unsigned length() const { return m_length; }
 
 private:
     const int* m_properties;
+    const CSSPropertyLonghand** m_longhandsForInitialization;
     unsigned m_length;
 };
 
@@ -49,6 +60,7 @@
 const CSSPropertyLonghand& backgroundPositionLonghand();
 const CSSPropertyLonghand& backgroundRepeatLonghand();
 const CSSPropertyLonghand& borderLonghand();
+const CSSPropertyLonghand& borderAbridgedLonghand();
 const CSSPropertyLonghand& borderBottomLonghand();
 const CSSPropertyLonghand& borderColorLonghand();
 const CSSPropertyLonghand& borderImageLonghand();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to