Title: [153067] trunk
Revision
153067
Author
[email protected]
Date
2013-07-23 16:42:16 -0700 (Tue, 23 Jul 2013)

Log Message

The computed values of fix length padding should be subpixel precision like margin
https://bugs.webkit.org/show_bug.cgi?id=118936

Reviewed by Simon Fraser.

Source/WebCore: 

The bug was caused by ComputedStyleExtractor::propertyValue always returning the used value
for padding. Fixed the bug by returning the computed value when they're of fixed length.

This aligns the behaviors of getComputedStyle(~).padding~ with getComputedStyle(~).margin~,
which had been fixed in r102149. While the current CSSOM specification says getComputedStyle
should return the used values for margins when display property is set to anything but none,
new behavior matches that of Chrome, Firefox, and Internet Explorer.

Also extracted zoomAdjustedPaddingOrMarginPixelValue to reduce the code duplication.

Test: fast/css/getComputedStyle/getComputedStyle-padding-margin-subpixel-length.html

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::zoomAdjustedPaddingOrMarginPixelValue): Extracted.
(WebCore::ComputedStyleExtractor::propertyValue):

LayoutTests: 

Add a regression test for obtaining the computed values of floating point padding and margin.
They shouldn't be rounded to whole pixels.

* fast/css/getComputedStyle/getComputedStyle-padding-margin-subpixel-length-expected.txt: Added.
* fast/css/getComputedStyle/getComputedStyle-padding-margin-subpixel-length.html: Added.
* fast/shapes/shape-inside/shape-inside-shape-logical-top-expected.html: Use a different technique to detect
the subpixel layout since paddings

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (153066 => 153067)


--- trunk/LayoutTests/ChangeLog	2013-07-23 22:51:42 UTC (rev 153066)
+++ trunk/LayoutTests/ChangeLog	2013-07-23 23:42:16 UTC (rev 153067)
@@ -1,3 +1,18 @@
+2013-07-22  Ryosuke Niwa  <[email protected]>
+
+        The computed values of fix length padding should be subpixel precision like margin
+        https://bugs.webkit.org/show_bug.cgi?id=118936
+
+        Reviewed by Simon Fraser.
+
+        Add a regression test for obtaining the computed values of floating point padding and margin.
+        They shouldn't be rounded to whole pixels.
+
+        * fast/css/getComputedStyle/getComputedStyle-padding-margin-subpixel-length-expected.txt: Added.
+        * fast/css/getComputedStyle/getComputedStyle-padding-margin-subpixel-length.html: Added.
+        * fast/shapes/shape-inside/shape-inside-shape-logical-top-expected.html: Use a different technique to detect
+        the subpixel layout since paddings
+
 2013-07-23  Bem Jones-Bey  <[email protected]>
 
         [CSS Shapes] New positioning model: support for rounded rectangle shape-outside

Added: trunk/LayoutTests/fast/css/getComputedStyle/getComputedStyle-padding-margin-subpixel-length-expected.txt (0 => 153067)


--- trunk/LayoutTests/fast/css/getComputedStyle/getComputedStyle-padding-margin-subpixel-length-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/getComputedStyle/getComputedStyle-padding-margin-subpixel-length-expected.txt	2013-07-23 23:42:16 UTC (rev 153067)
@@ -0,0 +1,19 @@
+Test calling getPropertyValue on computed margin styles.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS getComputedStyle(testElement).marginTop is "1.5px"
+PASS getComputedStyle(testElement).marginRight is "2.5px"
+PASS getComputedStyle(testElement).marginBottom is "3.5px"
+PASS getComputedStyle(testElement).marginLeft is "4.5px"
+PASS getComputedStyle(testElement).margin is "1.5px 2.5px 3.5px 4.5px"
+PASS getComputedStyle(testElement).paddingTop is "5.5px"
+PASS getComputedStyle(testElement).paddingRight is "6.5px"
+PASS getComputedStyle(testElement).paddingBottom is "7.5px"
+PASS getComputedStyle(testElement).paddingLeft is "8.5px"
+PASS getComputedStyle(testElement).padding is "5.5px 6.5px 7.5px 8.5px"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/css/getComputedStyle/getComputedStyle-padding-margin-subpixel-length.html (0 => 153067)


--- trunk/LayoutTests/fast/css/getComputedStyle/getComputedStyle-padding-margin-subpixel-length.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/getComputedStyle/getComputedStyle-padding-margin-subpixel-length.html	2013-07-23 23:42:16 UTC (rev 153067)
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+#testElement { 
+margin-top: 1.5px;
+margin-right: 2.5px;
+margin-bottom: 3.5px;
+margin-left: 4.5px;
+
+padding-top: 5.5px;
+padding-right: 6.5px;
+padding-bottom: 7.5px;
+padding-left: 8.5px;
+}
+</style>
+<script src=""
+</head>
+<body>
+<div id="testElement"></div>
+<script>
+
+description('Test calling getPropertyValue on computed margin styles.');
+
+var testElement = document.getElementById('testElement');
+shouldBe('getComputedStyle(testElement).marginTop', '"1.5px"');
+shouldBe('getComputedStyle(testElement).marginRight', '"2.5px"');
+shouldBe('getComputedStyle(testElement).marginBottom', '"3.5px"');
+shouldBe('getComputedStyle(testElement).marginLeft', '"4.5px"');
+shouldBe('getComputedStyle(testElement).margin', '"1.5px 2.5px 3.5px 4.5px"');
+
+shouldBe('getComputedStyle(testElement).paddingTop', '"5.5px"');
+shouldBe('getComputedStyle(testElement).paddingRight', '"6.5px"');
+shouldBe('getComputedStyle(testElement).paddingBottom', '"7.5px"');
+shouldBe('getComputedStyle(testElement).paddingLeft', '"8.5px"');
+shouldBe('getComputedStyle(testElement).padding', '"5.5px 6.5px 7.5px 8.5px"');
+
+var successfullyParsed = true;
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/fast/shapes/shape-inside/shape-inside-shape-logical-top-expected.html (153066 => 153067)


--- trunk/LayoutTests/fast/shapes/shape-inside/shape-inside-shape-logical-top-expected.html	2013-07-23 22:51:42 UTC (rev 153066)
+++ trunk/LayoutTests/fast/shapes/shape-inside/shape-inside-shape-logical-top-expected.html	2013-07-23 23:42:16 UTC (rev 153067)
@@ -16,18 +16,25 @@
         height: 186px;
         border: 2px solid blue;
     }
+    #elementWith105pxHeight {
+        position: absolute;
+        left: 0;
+        top: 0;
+        height: 10.5px;
+    }
 </style>
 <script>
 function init() {
     // If subpixel layout is not enabled, fix shape-inside's padding-top value.
     var shapeInsideElt = document.getElementById("shape-inside");
-    if (window.getComputedStyle(shapeInsideElt).paddingTop == "20px")
+    if (getComputedStyle(document.getElementById('elementWith105pxHeight')).height == "10px")
         shapeInsideElt.style.paddingTop = "21px"
 }
 </script>
 </head>
 <body _onload_="init()">
     <div id="shape-inside">
+        <span id="elementWith105pxHeight"></span>
         <div id="border"></div>
         This text should be contained by the blue square.
     </div>

Modified: trunk/Source/WebCore/ChangeLog (153066 => 153067)


--- trunk/Source/WebCore/ChangeLog	2013-07-23 22:51:42 UTC (rev 153066)
+++ trunk/Source/WebCore/ChangeLog	2013-07-23 23:42:16 UTC (rev 153067)
@@ -1,3 +1,26 @@
+2013-07-19  Ryosuke Niwa  <[email protected]>
+
+        The computed values of fix length padding should be subpixel precision like margin
+        https://bugs.webkit.org/show_bug.cgi?id=118936
+
+        Reviewed by Simon Fraser.
+
+        The bug was caused by ComputedStyleExtractor::propertyValue always returning the used value
+        for padding. Fixed the bug by returning the computed value when they're of fixed length.
+
+        This aligns the behaviors of getComputedStyle(~).padding~ with getComputedStyle(~).margin~,
+        which had been fixed in r102149. While the current CSSOM specification says getComputedStyle
+        should return the used values for margins when display property is set to anything but none,
+        new behavior matches that of Chrome, Firefox, and Internet Explorer.
+
+        Also extracted zoomAdjustedPaddingOrMarginPixelValue to reduce the code duplication.
+
+        Test: fast/css/getComputedStyle/getComputedStyle-padding-margin-subpixel-length.html
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::zoomAdjustedPaddingOrMarginPixelValue): Extracted.
+        (WebCore::ComputedStyleExtractor::propertyValue):
+
 2013-07-23  Alex Christensen  <[email protected]>
 
         Updated ANGLE to latest git commit (047373aa3eb408be62be52ade840fa5f11e72337).

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (153066 => 153067)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2013-07-23 22:51:42 UTC (rev 153066)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2013-07-23 23:42:16 UTC (rev 153067)
@@ -1596,6 +1596,18 @@
     return styledNode->computedStyle(styledNode->isPseudoElement() ? NOPSEUDO : pseudoElementSpecifier);
 }
 
+typedef Length (RenderStyle::*RenderStyleLengthGetter)() const;
+typedef LayoutUnit (RenderBoxModelObject::*RenderBoxComputedCSSValueGetter)() const;
+
+template<RenderStyleLengthGetter lengthGetter, RenderBoxComputedCSSValueGetter computedCSSValueGetter>
+inline PassRefPtr<CSSValue> zoomAdjustedPaddingOrMarginPixelValue(RenderStyle* style, RenderObject* renderer)
+{
+    Length unzoomedLength = (style->*lengthGetter)();
+    if (unzoomedLength.isFixed() || !renderer || !renderer->isBox())
+        return zoomAdjustedPixelValueForLength(unzoomedLength, style);
+    return zoomAdjustedPixelValue((toRenderBox(renderer)->*computedCSSValueGetter)(), style);
+}
+
 PassRefPtr<CSSValue> ComputedStyleExtractor::propertyValue(CSSPropertyID propertyID, EUpdateLayout updateLayout) const
 {
     Node* styledNode = this->styledNode();
@@ -2072,12 +2084,8 @@
             if (style->locale().isNull())
                 return cssValuePool().createIdentifierValue(CSSValueAuto);
             return cssValuePool().createValue(style->locale(), CSSPrimitiveValue::CSS_STRING);
-        case CSSPropertyMarginTop: {
-            Length marginTop = style->marginTop();
-            if (marginTop.isFixed() || !renderer || !renderer->isBox())
-                return zoomAdjustedPixelValueForLength(marginTop, style.get());
-            return zoomAdjustedPixelValue(toRenderBox(renderer)->marginTop(), style.get());
-        }
+        case CSSPropertyMarginTop:
+            return zoomAdjustedPaddingOrMarginPixelValue<&RenderStyle::marginTop, &RenderBoxModelObject::marginTop>(style.get(), renderer);
         case CSSPropertyMarginRight: {
             Length marginRight = style->marginRight();
             if (marginRight.isFixed() || !renderer || !renderer->isBox())
@@ -2092,18 +2100,10 @@
                 value = toRenderBox(renderer)->marginRight();
             return zoomAdjustedPixelValue(value, style.get());
         }
-        case CSSPropertyMarginBottom: {
-            Length marginBottom = style->marginBottom();
-            if (marginBottom.isFixed() || !renderer || !renderer->isBox())
-                return zoomAdjustedPixelValueForLength(marginBottom, style.get());
-            return zoomAdjustedPixelValue(toRenderBox(renderer)->marginBottom(), style.get());
-        }
-        case CSSPropertyMarginLeft: {
-            Length marginLeft = style->marginLeft();
-            if (marginLeft.isFixed() || !renderer || !renderer->isBox())
-                return zoomAdjustedPixelValueForLength(marginLeft, style.get());
-            return zoomAdjustedPixelValue(toRenderBox(renderer)->marginLeft(), style.get());
-        }
+        case CSSPropertyMarginBottom:
+            return zoomAdjustedPaddingOrMarginPixelValue<&RenderStyle::marginBottom, &RenderBoxModelObject::marginBottom>(style.get(), renderer);
+        case CSSPropertyMarginLeft:
+            return zoomAdjustedPaddingOrMarginPixelValue<&RenderStyle::marginLeft, &RenderBoxModelObject::marginLeft>(style.get(), renderer);
         case CSSPropertyWebkitMarqueeDirection:
             return cssValuePool().createValue(style->marqueeDirection());
         case CSSPropertyWebkitMarqueeIncrement:
@@ -2163,21 +2163,13 @@
         case CSSPropertyOverflowY:
             return cssValuePool().createValue(style->overflowY());
         case CSSPropertyPaddingTop:
-            if (renderer && renderer->isBox())
-                return zoomAdjustedPixelValue(toRenderBox(renderer)->computedCSSPaddingTop(), style.get());
-            return zoomAdjustedPixelValueForLength(style->paddingTop(), style.get());
+            return zoomAdjustedPaddingOrMarginPixelValue<&RenderStyle::paddingTop, &RenderBoxModelObject::computedCSSPaddingTop>(style.get(), renderer);
         case CSSPropertyPaddingRight:
-            if (renderer && renderer->isBox())
-                return zoomAdjustedPixelValue(toRenderBox(renderer)->computedCSSPaddingRight(), style.get());
-            return zoomAdjustedPixelValueForLength(style->paddingRight(), style.get());
+            return zoomAdjustedPaddingOrMarginPixelValue<&RenderStyle::paddingRight, &RenderBoxModelObject::computedCSSPaddingRight>(style.get(), renderer);
         case CSSPropertyPaddingBottom:
-            if (renderer && renderer->isBox())
-                return zoomAdjustedPixelValue(toRenderBox(renderer)->computedCSSPaddingBottom(), style.get());
-            return zoomAdjustedPixelValueForLength(style->paddingBottom(), style.get());
+            return zoomAdjustedPaddingOrMarginPixelValue<&RenderStyle::paddingBottom, &RenderBoxModelObject::computedCSSPaddingBottom>(style.get(), renderer);
         case CSSPropertyPaddingLeft:
-            if (renderer && renderer->isBox())
-                return zoomAdjustedPixelValue(toRenderBox(renderer)->computedCSSPaddingLeft(), style.get());
-            return zoomAdjustedPixelValueForLength(style->paddingLeft(), style.get());
+            return zoomAdjustedPaddingOrMarginPixelValue<&RenderStyle::paddingLeft, &RenderBoxModelObject::computedCSSPaddingLeft>(style.get(), renderer);
         case CSSPropertyPageBreakAfter:
             return cssValuePool().createValue(style->pageBreakAfter());
         case CSSPropertyPageBreakBefore:
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to