Reviewed by Maciej.
authorbdakin <bdakin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Apr 2006 22:35:33 +0000 (22:35 +0000)
committerbdakin <bdakin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Apr 2006 22:35:33 +0000 (22:35 +0000)
        Fix for <rdar://problem/4518632> getComputedStyle returns 'auto'
        for dimensions like 'margin-left'

        * css/CSSComputedStyleDeclaration.cpp:
        (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue): For
        margin and padding, to match Firefox we now go to the renderer to
        get the property value instead of calling valueForLength() on the
        style attribute. valueForLength() will return the string 'auto' if
        that was what was specified in the CSS, or a percentage if it was
        specified as a percent. But to match Firefox, we always want to
        return a pixel value for margin and padding.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@14067 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/css/marginComputedStyle-expected.checksum [new file with mode: 0644]
LayoutTests/fast/css/marginComputedStyle-expected.png [new file with mode: 0644]
LayoutTests/fast/css/marginComputedStyle-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/marginComputedStyle.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/css/CSSComputedStyleDeclaration.cpp

index 447758bc5e52831cbd405c61c3fab7cde26f0904..903e855ff053a2206db21f4af7653bcbf89bb5b1 100644 (file)
@@ -1,3 +1,15 @@
+2006-04-25  Beth Dakin  <bdakin@apple.com>
+
+        Reviewed by Maciej.
+
+        Layout test for <rdar://problem/4518632> getComputedStyle returns 
+        'auto' for dimensions like 'margin-left'
+
+        * fast/css/marginComputedStyle-expected.checksum: Added.
+        * fast/css/marginComputedStyle-expected.png: Added.
+        * fast/css/marginComputedStyle-expected.txt: Added.
+        * fast/css/marginComputedStyle.html: Added.
+
 2006-04-26  Mitz Pettel  <opendarwin.org@mitzpettel.com>
 
         Reviewed by darin.  Landed by eseidel.
diff --git a/LayoutTests/fast/css/marginComputedStyle-expected.checksum b/LayoutTests/fast/css/marginComputedStyle-expected.checksum
new file mode 100644 (file)
index 0000000..d9b0aa4
--- /dev/null
@@ -0,0 +1 @@
+4ace4202a3233d90771261e49c9f831d
\ No newline at end of file
diff --git a/LayoutTests/fast/css/marginComputedStyle-expected.png b/LayoutTests/fast/css/marginComputedStyle-expected.png
new file mode 100644 (file)
index 0000000..f3bef7c
Binary files /dev/null and b/LayoutTests/fast/css/marginComputedStyle-expected.png differ
diff --git a/LayoutTests/fast/css/marginComputedStyle-expected.txt b/LayoutTests/fast/css/marginComputedStyle-expected.txt
new file mode 100644 (file)
index 0000000..844cb7f
--- /dev/null
@@ -0,0 +1,33 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (186,0) size 412x48 [color=#FFFFFF] [bgcolor=#800080] [border: (10px double #000000)]
+        RenderText {#text} at (10,10) size 50x28
+          text run at (10,10) width 50: "Test"
+      RenderBlock (anonymous) at (0,48) size 784x144
+        RenderText {#text} at (0,0) size 84x18
+          text run at (0,0) width 84: "width: 392px"
+        RenderBR {BR} at (84,14) size 0x0
+        RenderText {#text} at (0,18) size 79x18
+          text run at (0,18) width 79: "height: 28px"
+        RenderBR {BR} at (79,32) size 0x0
+        RenderText {#text} at (0,36) size 117x18
+          text run at (0,36) width 117: "margin-left: 186px"
+        RenderBR {BR} at (117,50) size 0x0
+        RenderText {#text} at (0,54) size 126x18
+          text run at (0,54) width 126: "margin-right: 186px"
+        RenderBR {BR} at (126,68) size 0x0
+        RenderText {#text} at (0,72) size 101x18
+          text run at (0,72) width 101: "margin-top: 0px"
+        RenderBR {BR} at (101,86) size 0x0
+        RenderText {#text} at (0,90) size 125x18
+          text run at (0,90) width 125: "margin-bottom: 0px"
+        RenderBR {BR} at (125,104) size 0x0
+        RenderText {#text} at (0,108) size 108x18
+          text run at (0,108) width 108: "padding-left: 0px"
+        RenderBR {BR} at (108,122) size 0x0
+        RenderText {#text} at (0,126) size 55x18
+          text run at (0,126) width 55: "left: auto"
+        RenderBR {BR} at (55,140) size 0x0
diff --git a/LayoutTests/fast/css/marginComputedStyle.html b/LayoutTests/fast/css/marginComputedStyle.html
new file mode 100644 (file)
index 0000000..bc20d18
--- /dev/null
@@ -0,0 +1,46 @@
+<html>
+<head>
+<style>
+div { 
+    background: purple;
+    border: 10px double #000000; 
+    width:50%;
+    height:auto; 
+    margin-left:auto; 
+    margin-right:auto;
+    margin-top:auto;
+    margin-bottom:auto;
+    padding-left:auto;
+    left: auto;
+    color: white; 
+    font: 24px 'Lucida Grande';
+}
+</style>
+</head>
+
+<body>
+<div id="foo">Test</div>
+
+<script>
+    var foodiv = document.getElementById('foo');
+    document.write("width: " + window.getComputedStyle(foodiv, null).getPropertyValue("width"));
+    document.write( "<br>");
+    document.write("height: " + window.getComputedStyle(foodiv, null).getPropertyValue("height"));
+    document.write( "<br>");
+    document.write("margin-left: " + window.getComputedStyle(foodiv, null).getPropertyValue("margin-left"));
+    document.write( "<br>");
+    document.write("margin-right: " + window.getComputedStyle(foodiv, null).getPropertyValue("margin-right"));
+    document.write( "<br>");
+    document.write("margin-top: " + window.getComputedStyle(foodiv, null).getPropertyValue("margin-top"));
+    document.write( "<br>");
+    document.write("margin-bottom: " + window.getComputedStyle(foodiv, null).getPropertyValue("margin-bottom"));
+    document.write( "<br>");
+    document.write("padding-left: " + window.getComputedStyle(foodiv, null).getPropertyValue("padding-left"));
+    document.write( "<br>");
+    document.write("left: " + window.getComputedStyle(foodiv, null).getPropertyValue("left"));
+    document.write( "<br>");
+</script>
+
+</body>
+
+</html>
\ No newline at end of file
index 3fd1ec81d35a1d73d88fc20dffddf28305fe5288..632f575fbf2c64b349c680b9fc56fb0821a512e5 100644 (file)
@@ -1,3 +1,19 @@
+2006-04-25  Beth Dakin  <bdakin@apple.com>
+
+        Reviewed by Maciej.
+
+        Fix for <rdar://problem/4518632> getComputedStyle returns 'auto' 
+        for dimensions like 'margin-left'
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue): For 
+        margin and padding, to match Firefox we now go to the renderer to 
+        get the property value instead of calling valueForLength() on the 
+        style attribute. valueForLength() will return the string 'auto' if 
+        that was what was specified in the CSS, or a percentage if it was 
+        specified as a percent. But to match Firefox, we always want to 
+        return a pixel value for margin and padding.
+
 2006-04-26  Mitz Pettel  <opendarwin.org@mitzpettel.com>
 
         Reviewed by darin.  Landed by eseidel.
index d54c050e6b6161e06230ad5b44a2e4637d2a72a5..3400e2be4003e8dca3f111cb4c0d3d38d2febaa6 100644 (file)
@@ -786,13 +786,13 @@ PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(int proper
         ASSERT_NOT_REACHED();
         return 0;
     case CSS_PROP_MARGIN_TOP:
-        return valueForLength(style->marginTop());
+        return new CSSPrimitiveValue(renderer->marginTop(), CSSPrimitiveValue::CSS_PX);
     case CSS_PROP_MARGIN_RIGHT:
-        return valueForLength(style->marginRight());
+        return new CSSPrimitiveValue(renderer->marginRight(), CSSPrimitiveValue::CSS_PX);
     case CSS_PROP_MARGIN_BOTTOM:
-        return valueForLength(style->marginBottom());
+        return new CSSPrimitiveValue(renderer->marginBottom(), CSSPrimitiveValue::CSS_PX);
     case CSS_PROP_MARGIN_LEFT:
-        return valueForLength(style->marginLeft());
+        return new CSSPrimitiveValue(renderer->marginLeft(), CSSPrimitiveValue::CSS_PX);
     case CSS_PROP__WEBKIT_MARQUEE:
         // FIXME: unimplemented
         break;
@@ -893,13 +893,13 @@ PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(int proper
         ASSERT_NOT_REACHED();
         return 0;
     case CSS_PROP_PADDING_TOP:
-        return valueForLength(style->paddingTop());
+        return new CSSPrimitiveValue(renderer->paddingTop(), CSSPrimitiveValue::CSS_PX);
     case CSS_PROP_PADDING_RIGHT:
-        return valueForLength(style->paddingRight());
+        return new CSSPrimitiveValue(renderer->paddingRight(), CSSPrimitiveValue::CSS_PX);
     case CSS_PROP_PADDING_BOTTOM:
-        return valueForLength(style->paddingBottom());
+        return new CSSPrimitiveValue(renderer->paddingBottom(), CSSPrimitiveValue::CSS_PX);
     case CSS_PROP_PADDING_LEFT:
-        return valueForLength(style->paddingLeft());
+        return new CSSPrimitiveValue(renderer->paddingLeft(), CSSPrimitiveValue::CSS_PX);
     case CSS_PROP_PAGE:
         // FIXME: unimplemented
         break;