Changeset 132490 in webkit


Ignore:
Timestamp:
Oct 25, 2012 8:58:21 AM (11 years ago)
Author:
kenneth@webkit.org
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:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r132488 r132490  
     12012-10-25  Kenneth Rohde Christiansen  <kenneth@webkit.org>
     2
     3        'resolution' MQ: Printing should use use high resolution images when available
     4        https://bugs.webkit.org/show_bug.cgi?id=100382
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Special case print to not use the dpi of the screen, but one of 300.
     9
     10        Updated the resolution media query test to cover this.
     11
     12        * fast/media/mq-resolution-expected.txt:
     13        * fast/media/mq-resolution.html:
     14
    1152012-10-25  Kevin Ellis  <kevers@chromium.org>
    216
  • trunk/LayoutTests/fast/media/mq-resolution-expected.txt

    r132227 r132490  
    3535PASS matchMedia('(max-resolution: 85dpcm)').matches is false
    3636PASS matchMedia('(max-resolution: 100dpcm)').matches is true
     37PASS matchMedia('(min-resolution: 300dpi)').matches is true
     38PASS matchMedia('(min-resolution: 118dpcm)').matches is true
     39PASS resolutionFromStyle() is 3
     40PASS resolutionFromStyle() is 3.125
    3741PASS successfullyParsed is true
    3842
  • trunk/LayoutTests/fast/media/mq-resolution.html

    r132227 r132490  
    77
    88<style>
    9     #detector { width: 10px; }
     9    #detector { width: 100px; }
    1010    @media (resolution: 1.00dppx) { #detector { width: 10px; } }
    1111    @media (resolution: 1.50dppx) { #detector { width: 15px; } }
    1212    @media (resolution: 2.00dppx) { #detector { width: 20px; } }
    1313    @media (resolution: 2.25dppx) { #detector { width: 23px; } }
     14    @media print and (min-resolution: 3dppx) { #detector { width: 30px; } }
    1415</style>
    1516
     
    3132                case "23px":
    3233                    return 2.25;
     34                case "30px":
     35                    return 3;
     36                case "31px":
     37                    return 3.125;
    3338                default:
    3439                    return undefined;
    3540            }
     41        }
     42
     43        function appendMediaRule(rule) {
     44            var lastStyleSheet = document.styleSheets[document.styleSheets.length - 1];
     45            lastStyleSheet.insertRule(rule, lastStyleSheet.cssRules.length);
    3646        }
    3747
     
    8393        shouldBe("matchMedia('(max-resolution: 85dpcm)').matches", "false");
    8494        shouldBe("matchMedia('(max-resolution: 100dpcm)').matches", "true");
     95
     96        // Test printing.
     97
     98        window.internals.settings.setMediaTypeOverride("print");
     99        shouldBe("matchMedia('(min-resolution: 300dpi)').matches", "true");
     100        shouldBe("matchMedia('(min-resolution: 118dpcm)').matches", "true");
     101
     102        // Should match the one requiring 'print' media type.
     103        shouldBe("resolutionFromStyle()", "3");
     104
     105        // As well as those matching 'all'.
     106        appendMediaRule("@media (resolution: 3.125dppx) { #detector { width: 31px; } }");
     107        shouldBe("resolutionFromStyle()", "3.125");
    85108    }
    86109</script>
  • trunk/Source/WebCore/ChangeLog

    r132489 r132490  
     12012-10-25  Kenneth Rohde Christiansen  <kenneth@webkit.org>
     2
     3        'resolution' MQ: Printing should use use high resolution images when available
     4        https://bugs.webkit.org/show_bug.cgi?id=100382
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Special case print to not use the dpi of the screen, but one of 300.
     9
     10        Updated the resolution media query test to cover this.
     11
     12        * css/MediaQueryEvaluator.cpp:
     13        (WebCore::resolutionMediaFeatureEval): Update compared decimal points
     14        to three, due to 300 / 96 being equal to 3.125.
     15
    1162012-10-25  Kinuko Yasuda  <kinuko@chromium.org>
    217
  • trunk/Source/WebCore/css/MediaQueryEvaluator.cpp

    r132227 r132490  
    316316    //     round((220 * 1.0 / 96) * 4) / 4 = 2.0
    317317
    318     float horiDPI = frame->document()->domWindow()->screen()->horizontalDPI();
    319     float vertDPI = frame->document()->domWindow()->screen()->verticalDPI();
     318    float horiDPI;
     319    float vertDPI;
     320
     321    // This checks the actual media type applied to the document, and we know
     322    // this method only got called if this media type matches the one defined
     323    // in the query. Thus, if if the document's media type is "print", the
     324    // media type of the query will either be "print" or "all".
     325    String mediaType = frame->view()->mediaType();
     326    if (equalIgnoringCase(mediaType, "screen")) {
     327        Screen* screen = frame->document()->domWindow()->screen();
     328        horiDPI = screen->horizontalDPI();
     329        vertDPI = screen->verticalDPI();
     330    } else if (equalIgnoringCase(mediaType, "print")) {
     331        // The resolution of images while printing should not depend on the dpi
     332        // of the screen. Until we support proper ways of querying this info
     333        // we use 300px which is considered minimum for current printers.
     334        horiDPI = vertDPI = 300;
     335    } else {
     336        // FIXME: Possible handle other media types than 'screen' and 'print'.
     337        // For now, do not match.
     338        return false;
     339    }
    320340
    321341    float leastDenseDPI = std::min(horiDPI, vertDPI);
     
    345365        // http://dev.w3.org/csswg/css3-values/#absolute-lengths recommends
    346366        // "that the pixel unit refer to the whole number of device pixels that
    347         // best approximates the reference pixel". We compare with 2 decimal
     367        // best approximates the reference pixel". We compare with 3 decimal
    348368        // points, which aligns with current device-pixel-ratio's in use.
    349         float leastDenseDensity = floorf(leastDenseDPI * 100 / 96) / 100;
    350         float mostDenseDensity = floorf(leastDenseDPI * 100 / 96) / 100;
     369        float leastDenseDensity = floorf(leastDenseDPI * 1000 / 96) / 1000;
     370        float mostDenseDensity = floorf(leastDenseDPI * 1000 / 96) / 1000;
    351371        float testedDensity = rawValue->getFloatValue(CSSPrimitiveValue::CSS_DPPX);
    352372        return compareResolution(leastDenseDensity, mostDenseDensity, testedDensity, op);
Note: See TracChangeset for help on using the changeset viewer.