Bug 779527 - Use the physical device resolution for media queries on mobile [r=dbaron]

This commit is contained in:
Matt Brubeck 2012-08-31 13:29:47 -07:00
parent 2e1a8c6da4
commit 93de3c87cf
2 changed files with 9 additions and 3 deletions

View File

@ -250,7 +250,15 @@ GetResolution(nsPresContext* aPresContext, const nsMediaFeature*,
{
// Resolution measures device pixels per CSS (inch/cm/pixel). We
// return it in device pixels per CSS inches.
float dpi = float(nsPresContext::AppUnitsPerCSSInch()) /
//
// However, on platforms where the CSS viewport is not fixed to the
// screen viewport, use the device resolution instead (bug 779527).
nsIPresShell *shell = aPresContext->PresShell();
float appUnitsPerInch = shell->GetIsViewportOverridden() ?
GetDeviceContextFor(aPresContext)->AppUnitsPerPhysicalInch() :
nsPresContext::AppUnitsPerCSSInch();
float dpi = appUnitsPerInch /
float(aPresContext->AppUnitsPerDevPixel());
aResult.SetFloatValue(dpi, eCSSUnit_Inch);
return NS_OK;

View File

@ -487,7 +487,6 @@ 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_apply("(resolution: " + Math.floor(resolution/96) + "dppx)");
should_not_apply("(resolution: " + (resolution + 1) + "dpi)");
@ -496,7 +495,6 @@ 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;