From c51fdbf971097be5ccd6564b2dd61ffd37155d86 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Sat, 7 Jul 2012 21:41:27 -0700 Subject: [PATCH] Change our interpretation of resolution units in CSS to match updates to the spec: i.e., device pixels per CSS inch (instead of device pixels per physical inch). (Bug 771390) r=bzbarsky Given that this makes GetResolution work like GetDevicePixelRatio, I believe this should also fix bug 662061 (on resolution's behavior when zooming)? --- layout/style/nsMediaFeatures.cpp | 7 ++++--- layout/style/test/test_media_queries.html | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/layout/style/nsMediaFeatures.cpp b/layout/style/nsMediaFeatures.cpp index a814f30a42a9..1fc94d689ad9 100644 --- a/layout/style/nsMediaFeatures.cpp +++ b/layout/style/nsMediaFeatures.cpp @@ -248,9 +248,10 @@ static nsresult GetResolution(nsPresContext* aPresContext, const nsMediaFeature*, nsCSSValue& aResult) { - // Resolution values are in device pixels, not CSS pixels. - nsDeviceContext *dx = GetDeviceContextFor(aPresContext); - float dpi = float(dx->AppUnitsPerPhysicalInch()) / float(dx->AppUnitsPerDevPixel()); + // Resolution measures device pixels per CSS (inch/cm/pixel). We + // return it in device pixels per CSS inches. + float dpi = float(nsPresContext::AppUnitsPerCSSInch()) / + float(aPresContext->AppUnitsPerDevPixel()); aResult.SetFloatValue(dpi, eCSSUnit_Inch); return NS_OK; } diff --git a/layout/style/test/test_media_queries.html b/layout/style/test/test_media_queries.html index 074e323d7d74..dbbbf10eb15a 100644 --- a/layout/style/test/test_media_queries.html +++ b/layout/style/test/test_media_queries.html @@ -483,6 +483,7 @@ function run() { var dpi_low = resolution - 1; if (query_applies("(min-resolution: " + resolution + "dpi)")) { // It's exact! + is(resolution % 96, 0, "resolution should be a multiple of 96dpi"); should_apply("(resolution: " + resolution + "dpi)"); should_not_apply("(resolution: " + (resolution + 1) + "dpi)"); should_not_apply("(resolution: " + (resolution - 1) + "dpi)"); @@ -490,6 +491,7 @@ function run() { } else { // We have no way to test resolution applying since it need not be // an integer. + ok(false, "resolution should be a multiple of 96dpi"); should_not_apply("(resolution: " + resolution + "dpi)"); should_not_apply("(resolution: " + (resolution - 1) + "dpi)"); dpi_high = resolution;