Title: [132490] trunk
Revision
132490
Author
[email protected]
Date
2012-10-25 08:58:21 -0700 (Thu, 25 Oct 2012)

Log Message

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

Reviewed by Antti Koivisto.

Special case print to not use the dpi of the screen, but one of 300.

Updated the resolution media query test to cover this.

Source/WebCore:

* css/MediaQueryEvaluator.cpp:
(WebCore::resolutionMediaFeatureEval): Update compared decimal points
to three, due to 300 / 96 being equal to 3.125.

LayoutTests:

* fast/media/mq-resolution-expected.txt:
* fast/media/mq-resolution.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (132489 => 132490)


--- trunk/LayoutTests/ChangeLog	2012-10-25 15:55:22 UTC (rev 132489)
+++ trunk/LayoutTests/ChangeLog	2012-10-25 15:58:21 UTC (rev 132490)
@@ -1,3 +1,17 @@
+2012-10-25  Kenneth Rohde Christiansen  <[email protected]>
+
+        'resolution' MQ: Printing should use use high resolution images when available
+        https://bugs.webkit.org/show_bug.cgi?id=100382
+
+        Reviewed by Antti Koivisto.
+
+        Special case print to not use the dpi of the screen, but one of 300.
+
+        Updated the resolution media query test to cover this.
+
+        * fast/media/mq-resolution-expected.txt:
+        * fast/media/mq-resolution.html:
+
 2012-10-25  Kevin Ellis  <[email protected]>
 
         Can't easily position the cursor on an empty line in a textarea with touch if touch adjustment is enabled

Modified: trunk/LayoutTests/fast/media/mq-resolution-expected.txt (132489 => 132490)


--- trunk/LayoutTests/fast/media/mq-resolution-expected.txt	2012-10-25 15:55:22 UTC (rev 132489)
+++ trunk/LayoutTests/fast/media/mq-resolution-expected.txt	2012-10-25 15:58:21 UTC (rev 132490)
@@ -34,6 +34,10 @@
 PASS matchMedia('(min-resolution: 100dpcm)').matches is false
 PASS matchMedia('(max-resolution: 85dpcm)').matches is false
 PASS matchMedia('(max-resolution: 100dpcm)').matches is true
+PASS matchMedia('(min-resolution: 300dpi)').matches is true
+PASS matchMedia('(min-resolution: 118dpcm)').matches is true
+PASS resolutionFromStyle() is 3
+PASS resolutionFromStyle() is 3.125
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/media/mq-resolution.html (132489 => 132490)


--- trunk/LayoutTests/fast/media/mq-resolution.html	2012-10-25 15:55:22 UTC (rev 132489)
+++ trunk/LayoutTests/fast/media/mq-resolution.html	2012-10-25 15:58:21 UTC (rev 132490)
@@ -6,11 +6,12 @@
 <div id="detector"></div>
 
 <style>
-    #detector { width: 10px; }
+    #detector { width: 100px; }
     @media (resolution: 1.00dppx) { #detector { width: 10px; } }
     @media (resolution: 1.50dppx) { #detector { width: 15px; } }
     @media (resolution: 2.00dppx) { #detector { width: 20px; } }
     @media (resolution: 2.25dppx) { #detector { width: 23px; } }
+    @media print and (min-resolution: 3dppx) { #detector { width: 30px; } }
 </style>
 
 <script>
@@ -30,11 +31,20 @@
                     return 2;
                 case "23px":
                     return 2.25;
+                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('(resolution: 0dpi)').matches", "false");
         shouldBe("matchMedia('(min-resolution: 0dpi)').matches", "false");
         shouldBe("matchMedia('(max-resolution: 0dpi)').matches", "false");
@@ -82,6 +92,19 @@
         shouldBe("matchMedia('(min-resolution: 100dpcm)').matches", "false");
         shouldBe("matchMedia('(max-resolution: 85dpcm)').matches", "false");
         shouldBe("matchMedia('(max-resolution: 100dpcm)').matches", "true");
+
+        // Test printing.
+
+        window.internals.settings.setMediaTypeOverride("print");
+        shouldBe("matchMedia('(min-resolution: 300dpi)').matches", "true");
+        shouldBe("matchMedia('(min-resolution: 118dpcm)').matches", "true");
+
+        // Should match the one requiring 'print' media type.
+        shouldBe("resolutionFromStyle()", "3");
+
+        // As well as those matching 'all'.
+        appendMediaRule("@media (resolution: 3.125dppx) { #detector { width: 31px; } }");
+        shouldBe("resolutionFromStyle()", "3.125");
     }
 </script>
 

Modified: trunk/Source/WebCore/ChangeLog (132489 => 132490)


--- trunk/Source/WebCore/ChangeLog	2012-10-25 15:55:22 UTC (rev 132489)
+++ trunk/Source/WebCore/ChangeLog	2012-10-25 15:58:21 UTC (rev 132490)
@@ -1,3 +1,18 @@
+2012-10-25  Kenneth Rohde Christiansen  <[email protected]>
+
+        'resolution' MQ: Printing should use use high resolution images when available
+        https://bugs.webkit.org/show_bug.cgi?id=100382
+
+        Reviewed by Antti Koivisto.
+
+        Special case print to not use the dpi of the screen, but one of 300.
+
+        Updated the resolution media query test to cover this.
+
+        * css/MediaQueryEvaluator.cpp:
+        (WebCore::resolutionMediaFeatureEval): Update compared decimal points
+        to three, due to 300 / 96 being equal to 3.125.
+
 2012-10-25  Kinuko Yasuda  <[email protected]>
 
         [chromium] External FileSystem should use the root path returned by requestFileSystem

Modified: trunk/Source/WebCore/css/MediaQueryEvaluator.cpp (132489 => 132490)


--- trunk/Source/WebCore/css/MediaQueryEvaluator.cpp	2012-10-25 15:55:22 UTC (rev 132489)
+++ trunk/Source/WebCore/css/MediaQueryEvaluator.cpp	2012-10-25 15:58:21 UTC (rev 132490)
@@ -315,9 +315,29 @@
     // Example (high-range resolution laptop):
     //     round((220 * 1.0 / 96) * 4) / 4 = 2.0
 
-    float horiDPI = frame->document()->domWindow()->screen()->horizontalDPI();
-    float vertDPI = frame->document()->domWindow()->screen()->verticalDPI();
+    float horiDPI;
+    float vertDPI;
 
+    // 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")) {
+        Screen* screen = frame->document()->domWindow()->screen();
+        horiDPI = screen->horizontalDPI();
+        vertDPI = screen->verticalDPI();
+    } 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.
+        horiDPI = vertDPI = 300;
+    } else {
+        // FIXME: Possible handle other media types than 'screen' and 'print'.
+        // For now, do not match.
+        return false;
+    }
+
     float leastDenseDPI = std::min(horiDPI, vertDPI);
     float mostDenseDPI = std::max(horiDPI, vertDPI);
 
@@ -344,10 +364,10 @@
     if (rawValue->isDotsPerPixel()) {
         // http://dev.w3.org/csswg/css3-values/#absolute-lengths recommends
         // "that the pixel unit refer to the whole number of device pixels that
-        // best approximates the reference pixel". We compare with 2 decimal
+        // best approximates the reference pixel". We compare with 3 decimal
         // points, which aligns with current device-pixel-ratio's in use.
-        float leastDenseDensity = floorf(leastDenseDPI * 100 / 96) / 100;
-        float mostDenseDensity = floorf(leastDenseDPI * 100 / 96) / 100;
+        float leastDenseDensity = floorf(leastDenseDPI * 1000 / 96) / 1000;
+        float mostDenseDensity = floorf(leastDenseDPI * 1000 / 96) / 1000;
         float testedDensity = rawValue->getFloatValue(CSSPrimitiveValue::CSS_DPPX);
         return compareResolution(leastDenseDensity, mostDenseDensity, testedDensity, op);
     }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to