Title: [96471] trunk
Revision
96471
Author
[email protected]
Date
2011-10-02 01:25:34 -0700 (Sun, 02 Oct 2011)

Log Message

REGRESSION (r95502): Assertion failure in CSSPrimitiveValue::computeLengthDouble() when media query specifies unit-less length
https://bugs.webkit.org/show_bug.cgi?id=68760

Reviewed by Antti Koivisto.

Source/WebCore: 

Test: fast/media/invalid-lengths.html

Made length-comparison media queries accept only length values. In compatibility mode, numbers
are allowed as well, and they are interpreted as pixels.

* css/MediaQueryEvaluator.cpp:
(WebCore::computeLength): Added this helper function.
(WebCore::device_heightMediaFeatureEval): Changed to use computeLength().
(WebCore::device_widthMediaFeatureEval): Ditto.
(WebCore::heightMediaFeatureEval): Ditto.
(WebCore::widthMediaFeatureEval): Ditto.

LayoutTests: 

* fast/media/invalid-lengths-expected.txt: Added.
* fast/media/invalid-lengths.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (96470 => 96471)


--- trunk/LayoutTests/ChangeLog	2011-10-02 07:15:08 UTC (rev 96470)
+++ trunk/LayoutTests/ChangeLog	2011-10-02 08:25:34 UTC (rev 96471)
@@ -1,3 +1,13 @@
+2011-10-02  Dan Bernstein  <[email protected]>
+
+        REGRESSION (r95502): Assertion failure in CSSPrimitiveValue::computeLengthDouble() when media query specifies unit-less length
+        https://bugs.webkit.org/show_bug.cgi?id=68760
+
+        Reviewed by Antti Koivisto.
+
+        * fast/media/invalid-lengths-expected.txt: Added.
+        * fast/media/invalid-lengths.html: Added.
+
 2011-10-02  Dirk Schulze  <[email protected]>
 
         SVG Mask should take 'color-interpolation' into account to determine the color space of the mask image

Added: trunk/LayoutTests/fast/media/invalid-lengths-expected.txt (0 => 96471)


--- trunk/LayoutTests/fast/media/invalid-lengths-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/media/invalid-lengths-expected.txt	2011-10-02 08:25:34 UTC (rev 96471)
@@ -0,0 +1,7 @@
+PASS: "(min-device-width: 0)" evaluates to true.
+PASS: "(min-device-width: 1px)" evaluates to true.
+PASS: "(min-device-width: 1deg)" evaluates to false.
+PASS: "(min-device-width: 1)" evaluates to false.
+PASS: "(min-device-width: solid)" evaluates to false.
+PASS: "(min-device-width: "red")" evaluates to false.
+

Added: trunk/LayoutTests/fast/media/invalid-lengths.html (0 => 96471)


--- trunk/LayoutTests/fast/media/invalid-lengths.html	                        (rev 0)
+++ trunk/LayoutTests/fast/media/invalid-lengths.html	2011-10-02 08:25:34 UTC (rev 96471)
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<pre id="console">
+</pre>
+<script>
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+  
+    function log(message)
+    {
+        document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
+    }
+  
+    function testQuery(query, expected)
+    {
+        var actual = window.styleMedia.matchMedium(query);
+        var message = (actual === expected) ? 'PASS' : 'FAIL';
+        message += ": \"" + query + "\" evaluates to " + (actual ? "true" : "false") + ".";
+        log(message);
+    }
+  
+    testQuery('(min-device-width: 0)', true);
+    testQuery('(min-device-width: 1px)', true);
+    testQuery('(min-device-width: 1deg)', false);
+    testQuery('(min-device-width: 1)', false);
+    testQuery('(min-device-width: solid)', false);
+    testQuery('(min-device-width: "red")', false);
+</script>

Modified: trunk/Source/WebCore/ChangeLog (96470 => 96471)


--- trunk/Source/WebCore/ChangeLog	2011-10-02 07:15:08 UTC (rev 96470)
+++ trunk/Source/WebCore/ChangeLog	2011-10-02 08:25:34 UTC (rev 96471)
@@ -1,3 +1,22 @@
+2011-10-02  Dan Bernstein  <[email protected]>
+
+        REGRESSION (r95502): Assertion failure in CSSPrimitiveValue::computeLengthDouble() when media query specifies unit-less length
+        https://bugs.webkit.org/show_bug.cgi?id=68760
+
+        Reviewed by Antti Koivisto.
+
+        Test: fast/media/invalid-lengths.html
+
+        Made length-comparison media queries accept only length values. In compatibility mode, numbers
+        are allowed as well, and they are interpreted as pixels.
+
+        * css/MediaQueryEvaluator.cpp:
+        (WebCore::computeLength): Added this helper function.
+        (WebCore::device_heightMediaFeatureEval): Changed to use computeLength().
+        (WebCore::device_widthMediaFeatureEval): Ditto.
+        (WebCore::heightMediaFeatureEval): Ditto.
+        (WebCore::widthMediaFeatureEval): Ditto.
+
 2011-10-02  Dirk Schulze  <[email protected]>
 
         SVG Mask should take 'color-interpolation' into account to determine the color space of the mask image

Modified: trunk/Source/WebCore/css/MediaQueryEvaluator.cpp (96470 => 96471)


--- trunk/Source/WebCore/css/MediaQueryEvaluator.cpp	2011-10-02 07:15:08 UTC (rev 96470)
+++ trunk/Source/WebCore/css/MediaQueryEvaluator.cpp	2011-10-02 08:25:34 UTC (rev 96471)
@@ -306,12 +306,33 @@
     return false;
 }
 
+static bool computeLength(CSSValue* value, bool strict, RenderStyle* style, RenderStyle* rootStyle, int& result)
+{
+    if (!value->isPrimitiveValue())
+        return false;
+
+    CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
+
+    if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_NUMBER) {
+        result = primitiveValue->getIntValue();
+        return !strict || !result;
+    }
+
+    if (primitiveValue->isLength()) {
+        result = primitiveValue->computeLength<int>(style, rootStyle);
+        return true;
+    }
+
+    return false;
+}
+
 static bool device_heightMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* frame, MediaFeaturePrefix op)
 {
     if (value) {
         FloatRect sg = screenRect(frame->page()->mainFrame()->view());
         RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
-        return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.height()), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
+        int length;
+        return computeLength(value, !frame->document()->inQuirksMode(), style, rootStyle, length) && compareValue(static_cast<int>(sg.height()), length, op);
     }
     // ({,min-,max-}device-height)
     // assume if we have a device, assume non-zero
@@ -323,7 +344,8 @@
     if (value) {
         FloatRect sg = screenRect(frame->page()->mainFrame()->view());
         RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
-        return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.width()), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
+        int length;
+        return computeLength(value, !frame->document()->inQuirksMode(), style, rootStyle, length) && compareValue(static_cast<int>(sg.width()), length, op);
     }
     // ({,min-,max-}device-width)
     // assume if we have a device, assume non-zero
@@ -333,10 +355,12 @@
 static bool heightMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* frame, MediaFeaturePrefix op)
 {
     FrameView* view = frame->view();
-    RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
 
-    if (value)
-        return value->isPrimitiveValue() && compareValue(view->layoutHeight(), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
+    if (value) {
+        RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
+        int length;
+        return computeLength(value, !frame->document()->inQuirksMode(), style, rootStyle, length) && compareValue(view->layoutHeight(), length, op);
+    }
 
     return view->layoutHeight() != 0;
 }
@@ -344,10 +368,12 @@
 static bool widthMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* frame, MediaFeaturePrefix op)
 {
     FrameView* view = frame->view();
-    RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
 
-    if (value)
-        return value->isPrimitiveValue() && compareValue(view->layoutWidth(), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
+    if (value) {
+        RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
+        int length;
+        return computeLength(value, !frame->document()->inQuirksMode(), style, rootStyle, length) && compareValue(view->layoutWidth(), length, op);
+    }
 
     return view->layoutWidth() != 0;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to