Title: [132633] trunk
Revision
132633
Author
[email protected]
Date
2012-10-26 05:27:15 -0700 (Fri, 26 Oct 2012)

Log Message

Printing should use use high resolution images when available
https://bugs.webkit.org/show_bug.cgi?id=100488

Reviewed by Antti Koivisto.

The images loaded using -webkit-device-pixel-ratio depends on
the display type (deviceScaleFactor) and thus affects which
images are being used for printing. Printing should always
use the higher resolution images (aka 'retina' images).

Source/WebCore:

Test: fast/media/mq-pixel-ratio-print.html

* css/MediaQueryEvaluator.cpp:
(WebCore::device_pixel_ratioMediaFeatureEval):

LayoutTests:

Added a test testing -webkit-device-pixel-ratio media query
in conjuntion with 'print' media type.

* fast/media/mq-pixel-ratio-print-expected.txt: Added.
* fast/media/mq-pixel-ratio-print.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (132632 => 132633)


--- trunk/LayoutTests/ChangeLog	2012-10-26 12:25:27 UTC (rev 132632)
+++ trunk/LayoutTests/ChangeLog	2012-10-26 12:27:15 UTC (rev 132633)
@@ -1,3 +1,21 @@
+2012-10-26  Kenneth Rohde Christiansen  <[email protected]>
+
+        Printing should use use high resolution images when available
+        https://bugs.webkit.org/show_bug.cgi?id=100488
+
+        Reviewed by Antti Koivisto.
+
+        The images loaded using -webkit-device-pixel-ratio depends on
+        the display type (deviceScaleFactor) and thus affects which
+        images are being used for printing. Printing should always
+        use the higher resolution images (aka 'retina' images).
+
+        Added a test testing -webkit-device-pixel-ratio media query
+        in conjuntion with 'print' media type.
+
+        * fast/media/mq-pixel-ratio-print-expected.txt: Added.
+        * fast/media/mq-pixel-ratio-print.html: Added.
+
 2012-10-26  Raphael Kubo da Costa  <[email protected]>
 
         [EFL] ... And another pixel rebaseline after r131941 and r131991.

Added: trunk/LayoutTests/fast/media/mq-pixel-ratio-print-expected.txt (0 => 132633)


--- trunk/LayoutTests/fast/media/mq-pixel-ratio-print-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/media/mq-pixel-ratio-print-expected.txt	2012-10-26 12:27:15 UTC (rev 132633)
@@ -0,0 +1,14 @@
+CSS3 media query test: -webkit-device-pixel-ratio combined with print.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS matchMedia('(-webkit-min-device-pixel-ratio: 1)').matches is true
+PASS resolutionFromStyle() is 1
+PASS matchMedia('(-webkit-min-device-pixel-ratio: 3)').matches is true
+PASS resolutionFromStyle() is 3
+PASS resolutionFromStyle() is 3.125
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/media/mq-pixel-ratio-print.html (0 => 132633)


--- trunk/LayoutTests/fast/media/mq-pixel-ratio-print.html	                        (rev 0)
+++ trunk/LayoutTests/fast/media/mq-pixel-ratio-print.html	2012-10-26 12:27:15 UTC (rev 132633)
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+
+<div id="detector"></div>
+
+<style>
+    #detector { width: 100px; }
+    @media (-webkit-min-device-pixel-ratio: 1) { #detector { width: 10px; } }
+    @media print and (-webkit-min-device-pixel-ratio: 3) { #detector { width: 30px; } }
+</style>
+
+<script>
+    description("CSS3 media query test: -webkit-device-pixel-ratio combined with print.")
+
+    if (window.testRunner && window.internals) {
+        window.testRunner.dumpAsText();
+
+        function resolutionFromStyle() {
+            var width = getComputedStyle(document.getElementById("detector")).width;
+            switch (width) {
+                case "10px":
+                    return 1;
+                case "30px":
+                    return 3;
+                case "31px":
+                    return 3.125;
+                default:
+                    return undefined;
+            }
+        }
+
+        function appendMediaRule(rule) {
+            var lastStyleSheet = document.styleSheets[document.styleSheets.length - 1];
+            lastStyleSheet.insertRule(rule, lastStyleSheet.cssRules.length);
+        }
+
+        shouldBe("matchMedia('(-webkit-min-device-pixel-ratio: 1)').matches", "true");
+        shouldBe("resolutionFromStyle()", "1");
+
+        // Test printing.
+
+        window.internals.settings.setMediaTypeOverride("print");
+        shouldBe("matchMedia('(-webkit-min-device-pixel-ratio: 3)').matches", "true");
+
+        // Should match the one requiring 'print' media type.
+        shouldBe("resolutionFromStyle()", "3");
+
+        // As well as those matching 'all'.
+        appendMediaRule("@media (-webkit-min-device-pixel-ratio: 3.125) { #detector { width: 31px; } }");
+        shouldBe("resolutionFromStyle()", "3.125");
+    }
+</script>
+
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (132632 => 132633)


--- trunk/Source/WebCore/ChangeLog	2012-10-26 12:25:27 UTC (rev 132632)
+++ trunk/Source/WebCore/ChangeLog	2012-10-26 12:27:15 UTC (rev 132633)
@@ -1,3 +1,20 @@
+2012-10-26  Kenneth Rohde Christiansen  <[email protected]>
+
+        Printing should use use high resolution images when available
+        https://bugs.webkit.org/show_bug.cgi?id=100488
+
+        Reviewed by Antti Koivisto.
+
+        The images loaded using -webkit-device-pixel-ratio depends on
+        the display type (deviceScaleFactor) and thus affects which
+        images are being used for printing. Printing should always
+        use the higher resolution images (aka 'retina' images).
+
+        Test: fast/media/mq-pixel-ratio-print.html
+
+        * css/MediaQueryEvaluator.cpp:
+        (WebCore::device_pixel_ratioMediaFeatureEval):
+
 2012-10-26  Ilya Tikhonovsky  <[email protected]>
 
         Web Inspector: NMI instrument InspectorResourceAgent. it caches resources for the front-end.

Modified: trunk/Source/WebCore/css/MediaQueryEvaluator.cpp (132632 => 132633)


--- trunk/Source/WebCore/css/MediaQueryEvaluator.cpp	2012-10-26 12:25:27 UTC (rev 132632)
+++ trunk/Source/WebCore/css/MediaQueryEvaluator.cpp	2012-10-26 12:27:15 UTC (rev 132633)
@@ -289,10 +289,27 @@
 
 static bool device_pixel_ratioMediaFeatureEval(CSSValue *value, RenderStyle*, Frame* frame, MediaFeaturePrefix op)
 {
-    if (value)
-        return value->isPrimitiveValue() && compareValue(frame->page()->deviceScaleFactor(), static_cast<CSSPrimitiveValue*>(value)->getFloatValue(), op);
+    // FIXME: Possible handle other media types than 'screen' and 'print'.
+    float deviceScaleFactor = 0;
 
-    return frame->page()->deviceScaleFactor() != 0;
+    // This checks the actual media type applied to the document, and we know
+    // this method only got called if this media type matches the one defined
+    // in the query. Thus, if if the document's media type is "print", the
+    // media type of the query will either be "print" or "all".
+    String mediaType = frame->view()->mediaType();
+    if (equalIgnoringCase(mediaType, "screen"))
+        deviceScaleFactor = frame->page()->deviceScaleFactor();
+    else if (equalIgnoringCase(mediaType, "print")) {
+        // The resolution of images while printing should not depend on the dpi
+        // of the screen. Until we support proper ways of querying this info
+        // we use 300px which is considered minimum for current printers.
+        deviceScaleFactor = 3.125; // 300dpi / 96dpi;
+    }
+
+    if (!value)
+        return !!deviceScaleFactor;
+
+    return value->isPrimitiveValue() && compareValue(deviceScaleFactor, static_cast<CSSPrimitiveValue*>(value)->getFloatValue(), op);
 }
 
 static bool resolutionMediaFeatureEval(CSSValue* value, RenderStyle*, Frame* frame, MediaFeaturePrefix op)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to