mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
Back out ae2e45d25a1a, 4f144a06d0cc, 2e80be1d7d18 (bug 716575) for Android Talos red
This commit is contained in:
parent
6fb16e9cb4
commit
0e175dfa7d
@ -1537,22 +1537,10 @@ public:
|
||||
* which places the viewport information in the document header instead
|
||||
* of returning it directly.
|
||||
*
|
||||
* @param aDisplayWidth width of the on-screen display area for this
|
||||
* document, in device pixels.
|
||||
* @param aDisplayHeight height of the on-screen display area for this
|
||||
* document, in device pixels.
|
||||
*
|
||||
* NOTE: If the site is optimized for mobile (via the doctype), this
|
||||
* will return viewport information that specifies default information.
|
||||
*/
|
||||
static ViewportInfo GetViewportInfo(nsIDocument* aDocument,
|
||||
uint32_t aDisplayWidth,
|
||||
uint32_t aDisplayHeight);
|
||||
|
||||
/**
|
||||
* The device-pixel-to-CSS-px ratio used to adjust meta viewport values.
|
||||
*/
|
||||
static double GetDevicePixelsPerMetaViewportPixel(nsIWidget* aWidget);
|
||||
static ViewportInfo GetViewportInfo(nsIDocument* aDocument);
|
||||
|
||||
// Call EnterMicroTask when you're entering JS execution.
|
||||
// Usually the best way to do this is to use nsAutoMicroTask.
|
||||
|
@ -12,8 +12,6 @@
|
||||
#include "jsdbgapi.h"
|
||||
#include "jsfriendapi.h"
|
||||
|
||||
#include "math.h"
|
||||
|
||||
#include "Layers.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "nsCOMPtr.h"
|
||||
@ -5085,7 +5083,7 @@ static void ProcessViewportToken(nsIDocument *aDocument,
|
||||
|
||||
/* static */
|
||||
ViewportInfo
|
||||
nsContentUtils::GetViewportInfo(nsIDocument *aDocument, uint32_t aDisplayWidth, uint32_t aDisplayHeight)
|
||||
nsContentUtils::GetViewportInfo(nsIDocument *aDocument)
|
||||
{
|
||||
ViewportInfo ret;
|
||||
ret.defaultZoom = 1.0;
|
||||
@ -5174,38 +5172,37 @@ nsContentUtils::GetViewportInfo(nsIDocument *aDocument, uint32_t aDisplayWidth,
|
||||
autoSize = true;
|
||||
}
|
||||
|
||||
// Now convert the scale into device pixels per CSS pixel.
|
||||
nsIWidget *widget = WidgetForDocument(aDocument);
|
||||
double pixelRatio = widget ? GetDevicePixelsPerMetaViewportPixel(widget) : 1.0;
|
||||
scaleFloat *= pixelRatio;
|
||||
scaleMinFloat *= pixelRatio;
|
||||
scaleMaxFloat *= pixelRatio;
|
||||
// XXXjwir3:
|
||||
// See bug 706918, comment 23 for more information on this particular section
|
||||
// of the code. We're using "screen size" in place of the size of the content
|
||||
// area, because on mobile, these are close or equal. This will work for our
|
||||
// purposes (bug 706198), but it will need to be changed in the future to be
|
||||
// more correct when we bring the rest of the viewport code into platform.
|
||||
// We actually want the size of the content area, in the event that we don't
|
||||
// have any metadata about the width and/or height. On mobile, the screen size
|
||||
// and the size of the content area are very close, or the same value.
|
||||
// In XUL fennec, the content area is the size of the <browser> widget, but
|
||||
// in native fennec, the content area is the size of the Gecko LayerView
|
||||
// object.
|
||||
|
||||
uint32_t width, height;
|
||||
if (autoSize) {
|
||||
// aDisplayWidth and aDisplayHeight are in device pixels; convert them to
|
||||
// CSS pixels for the viewport size.
|
||||
width = aDisplayWidth / pixelRatio;
|
||||
height = aDisplayHeight / pixelRatio;
|
||||
} else {
|
||||
nsresult widthErrorCode, heightErrorCode;
|
||||
width = widthStr.ToInteger(&widthErrorCode);
|
||||
height = heightStr.ToInteger(&heightErrorCode);
|
||||
// TODO:
|
||||
// Once bug 716575 has been resolved, this code should be changed so that it
|
||||
// does the right thing on all platforms.
|
||||
nsresult result;
|
||||
int32_t screenLeft, screenTop, screenWidth, screenHeight;
|
||||
nsCOMPtr<nsIScreenManager> screenMgr =
|
||||
do_GetService("@mozilla.org/gfx/screenmanager;1", &result);
|
||||
|
||||
// If width or height has not been set to a valid number by this point,
|
||||
// fall back to a default value.
|
||||
bool validWidth = (!widthStr.IsEmpty() && NS_SUCCEEDED(widthErrorCode) && width > 0);
|
||||
bool validHeight = (!heightStr.IsEmpty() && NS_SUCCEEDED(heightErrorCode) && height > 0);
|
||||
if (!validWidth) {
|
||||
if (validHeight) {
|
||||
width = (uint32_t) ((height * aDisplayWidth) / aDisplayHeight);
|
||||
} else {
|
||||
width = Preferences::GetInt("browser.viewport.desktopWidth",
|
||||
kViewportDefaultScreenWidth);
|
||||
}
|
||||
}
|
||||
if (!validHeight) {
|
||||
height = (uint32_t) ((width * aDisplayHeight) / aDisplayWidth);
|
||||
nsCOMPtr<nsIScreen> screen;
|
||||
screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
|
||||
screen->GetRect(&screenLeft, &screenTop, &screenWidth, &screenHeight);
|
||||
|
||||
uint32_t width = widthStr.ToInteger(&errorCode);
|
||||
if (NS_FAILED(errorCode)) {
|
||||
if (autoSize) {
|
||||
width = screenWidth;
|
||||
} else {
|
||||
width = Preferences::GetInt("browser.viewport.desktopWidth", 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5215,7 +5212,19 @@ nsContentUtils::GetViewportInfo(nsIDocument *aDocument, uint32_t aDisplayWidth,
|
||||
// Also recalculate the default zoom, if it wasn't specified in the metadata,
|
||||
// and the width is specified.
|
||||
if (scaleStr.IsEmpty() && !widthStr.IsEmpty()) {
|
||||
scaleFloat = NS_MAX(scaleFloat, ((float)aDisplayWidth) / (float)width);
|
||||
scaleFloat = NS_MAX(scaleFloat, (float)(screenWidth/width));
|
||||
}
|
||||
|
||||
uint32_t height = heightStr.ToInteger(&errorCode);
|
||||
|
||||
if (NS_FAILED(errorCode)) {
|
||||
height = width * ((float)screenHeight / screenWidth);
|
||||
}
|
||||
|
||||
// If height was provided by the user, but width wasn't, then we should
|
||||
// calculate the width.
|
||||
if (widthStr.IsEmpty() && !heightStr.IsEmpty()) {
|
||||
width = (uint32_t) ((height * screenWidth) / screenHeight);
|
||||
}
|
||||
|
||||
height = NS_MIN(height, kViewportMaxHeight);
|
||||
@ -5224,11 +5233,11 @@ nsContentUtils::GetViewportInfo(nsIDocument *aDocument, uint32_t aDisplayWidth,
|
||||
// We need to perform a conversion, but only if the initial or maximum
|
||||
// scale were set explicitly by the user.
|
||||
if (!scaleStr.IsEmpty() && NS_SUCCEEDED(scaleErrorCode)) {
|
||||
width = NS_MAX(width, (uint32_t)(aDisplayWidth / scaleFloat));
|
||||
height = NS_MAX(height, (uint32_t)(aDisplayHeight / scaleFloat));
|
||||
width = NS_MAX(width, (uint32_t)(screenWidth / scaleFloat));
|
||||
height = NS_MAX(height, (uint32_t)(screenHeight / scaleFloat));
|
||||
} else if (!maxScaleStr.IsEmpty() && NS_SUCCEEDED(scaleMaxErrorCode)) {
|
||||
width = NS_MAX(width, (uint32_t)(aDisplayWidth / scaleMaxFloat));
|
||||
height = NS_MAX(height, (uint32_t)(aDisplayHeight / scaleMaxFloat));
|
||||
width = NS_MAX(width, (uint32_t)(screenWidth / scaleMaxFloat));
|
||||
height = NS_MAX(height, (uint32_t)(screenHeight / scaleMaxFloat));
|
||||
}
|
||||
|
||||
bool allowZoom = true;
|
||||
@ -5251,24 +5260,6 @@ nsContentUtils::GetViewportInfo(nsIDocument *aDocument, uint32_t aDisplayWidth,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* static */
|
||||
double
|
||||
nsContentUtils::GetDevicePixelsPerMetaViewportPixel(nsIWidget* aWidget)
|
||||
{
|
||||
int prefValue = Preferences::GetInt("browser.viewport.scaleRatio", 0);
|
||||
if (prefValue > 0)
|
||||
return double(prefValue) / 100.0;
|
||||
|
||||
float dpi = aWidget->GetDPI();
|
||||
if (dpi < 200.0) // Includes desktop displays, and LDPI and MDPI Android devices
|
||||
return 1.0;
|
||||
else if (dpi < 300.0) // Includes Nokia N900, and HDPI Android devices
|
||||
return 1.5;
|
||||
|
||||
// For very high-density displays like the iPhone 4, calculate an integer ratio.
|
||||
return floor(dpi / 150.0);
|
||||
}
|
||||
|
||||
/* static */
|
||||
nsresult
|
||||
nsContentUtils::ProcessViewportInfo(nsIDocument *aDocument,
|
||||
|
@ -250,13 +250,6 @@ MOCHITEST_FILES_A = \
|
||||
file_XHRDocURI.text \
|
||||
file_XHRDocURI.text^headers^ \
|
||||
test_DOMException.html \
|
||||
test_meta_viewport0.html \
|
||||
test_meta_viewport1.html \
|
||||
test_meta_viewport2.html \
|
||||
test_meta_viewport3.html \
|
||||
test_meta_viewport4.html \
|
||||
test_meta_viewport5.html \
|
||||
test_meta_viewport6.html \
|
||||
test_mutationobservers.html \
|
||||
mutationobserver_dialog.html \
|
||||
test_bug744830.html \
|
||||
|
@ -1,76 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>meta viewport test</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<p>No <meta name="viewport"> tag</p>
|
||||
<script type="application/javascript;version=1.7">
|
||||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
let tests = [];
|
||||
|
||||
tests.push(function test1() {
|
||||
SpecialPowers.pushPrefEnv({"set": [["browser.viewport.scaleRatio", 100]]},
|
||||
function() {
|
||||
let info = getViewportInfo(800, 480);
|
||||
is(info.defaultZoom, 0, "initial scale is unspecified");
|
||||
is(info.minZoom, 0, "minumum scale defaults to the absolute minumum");
|
||||
is(info.maxZoom, 10, "maximum scale defaults to the absolute maximum");
|
||||
is(info.width, 980, "width is the default width");
|
||||
is(info.height, 588, "height is proportional to displayHeight");
|
||||
is(info.autoSize, false, "autoSize is disabled by default");
|
||||
is(info.allowZoom, true, "zooming is enabled by default");
|
||||
|
||||
info = getViewportInfo(490, 600);
|
||||
is(info.width, 980, "width is still the default width");
|
||||
is(info.height, 1200, "height is proportional to the new displayHeight");
|
||||
|
||||
nextTest();
|
||||
});
|
||||
});
|
||||
|
||||
tests.push(function test2() {
|
||||
SpecialPowers.pushPrefEnv({"set": [["browser.viewport.scaleRatio", 150]]},
|
||||
function() {
|
||||
let info = getViewportInfo(800, 480);
|
||||
is(info.width, 980, "width is still the default width");
|
||||
is(info.height, 588, "height is still proportional to displayHeight");
|
||||
|
||||
nextTest();
|
||||
});
|
||||
});
|
||||
|
||||
function getViewportInfo(aDisplayWidth, aDisplayHeight) {
|
||||
let defaultZoom = {}, allowZoom = {}, minZoom = {}, maxZoom = {},
|
||||
width = {}, height = {}, autoSize = {};
|
||||
|
||||
let cwu = SpecialPowers.getDOMWindowUtils(window);
|
||||
cwu.getViewportInfo(aDisplayWidth, aDisplayHeight, defaultZoom, allowZoom,
|
||||
minZoom, maxZoom, width, height, autoSize);
|
||||
return {
|
||||
defaultZoom: defaultZoom.value,
|
||||
minZoom: minZoom.value,
|
||||
maxZoom: maxZoom.value,
|
||||
width: width.value,
|
||||
height: height.value,
|
||||
autoSize: autoSize.value,
|
||||
allowZoom: allowZoom.value
|
||||
};
|
||||
}
|
||||
|
||||
function nextTest() {
|
||||
if (tests.length)
|
||||
(tests.shift())();
|
||||
else
|
||||
SimpleTest.finish();
|
||||
}
|
||||
addEventListener("load", nextTest);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,76 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>meta viewport test</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<p>width=device-width, initial-scale=1</p>
|
||||
<script type="application/javascript;version=1.7">
|
||||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
let tests = [];
|
||||
|
||||
tests.push(function test1() {
|
||||
SpecialPowers.pushPrefEnv({"set": [["browser.viewport.scaleRatio", 100]]},
|
||||
function() {
|
||||
let info = getViewportInfo(800, 480);
|
||||
is(info.defaultZoom, 1, "initial zoom is 100%");
|
||||
is(info.width, 800, "width is the same as the displayWidth");
|
||||
is(info.height, 480, "height is the same as the displayHeight");
|
||||
is(info.autoSize, true, "width=device-width enables autoSize");
|
||||
is(info.allowZoom, true, "zooming is enabled by default");
|
||||
|
||||
info = getViewportInfo(900, 600);
|
||||
is(info.width, 900, "changing the displayWidth changes the width");
|
||||
is(info.height, 600, "changing the displayHeight changes the height");
|
||||
|
||||
nextTest();
|
||||
});
|
||||
});
|
||||
|
||||
tests.push(function test2() {
|
||||
SpecialPowers.pushPrefEnv({"set": [["browser.viewport.scaleRatio", 150]]},
|
||||
function() {
|
||||
let info = getViewportInfo(900, 600);
|
||||
is(info.defaultZoom, 1.5, "initial zoom is 150%");
|
||||
is(info.width, 600, "width equals displayWidth/1.5");
|
||||
is(info.height, 400, "height equals displayHeight/1.5");
|
||||
|
||||
nextTest();
|
||||
});
|
||||
});
|
||||
|
||||
function getViewportInfo(aDisplayWidth, aDisplayHeight) {
|
||||
let defaultZoom = {}, allowZoom = {}, minZoom = {}, maxZoom = {},
|
||||
width = {}, height = {}, autoSize = {};
|
||||
|
||||
let cwu = SpecialPowers.getDOMWindowUtils(window);
|
||||
cwu.getViewportInfo(aDisplayWidth, aDisplayHeight, defaultZoom, allowZoom,
|
||||
minZoom, maxZoom, width, height, autoSize);
|
||||
return {
|
||||
defaultZoom: defaultZoom.value,
|
||||
minZoom: minZoom.value,
|
||||
maxZoom: maxZoom.value,
|
||||
width: width.value,
|
||||
height: height.value,
|
||||
autoSize: autoSize.value,
|
||||
allowZoom: allowZoom.value
|
||||
};
|
||||
}
|
||||
|
||||
function nextTest() {
|
||||
if (tests.length)
|
||||
(tests.shift())();
|
||||
else
|
||||
SimpleTest.finish();
|
||||
}
|
||||
addEventListener("load", nextTest);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,76 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>meta viewport test</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<meta name="viewport" content="width=device-width">
|
||||
</head>
|
||||
<body>
|
||||
<p>width=device-width</p>
|
||||
<script type="application/javascript;version=1.7">
|
||||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
let tests = [];
|
||||
|
||||
tests.push(function test1() {
|
||||
SpecialPowers.pushPrefEnv({"set": [["browser.viewport.scaleRatio", 100]]},
|
||||
function() {
|
||||
let info = getViewportInfo(800, 480);
|
||||
is(info.defaultZoom, 1, "initial zoom is 100%");
|
||||
is(info.width, 800, "width is the same as the displayWidth");
|
||||
is(info.height, 480, "height is the same as the displayHeight");
|
||||
is(info.autoSize, true, "width=device-width enables autoSize");
|
||||
is(info.allowZoom, true, "zooming is enabled by default");
|
||||
|
||||
info = getViewportInfo(900, 600);
|
||||
is(info.width, 900, "changing the displayWidth changes the width");
|
||||
is(info.height, 600, "changing the displayHeight changes the height");
|
||||
|
||||
nextTest();
|
||||
});
|
||||
});
|
||||
|
||||
tests.push(function test2() {
|
||||
SpecialPowers.pushPrefEnv({"set": [["browser.viewport.scaleRatio", 150]]},
|
||||
function() {
|
||||
let info = getViewportInfo(900, 600);
|
||||
is(info.defaultZoom, 1.5, "initial zoom is 150%");
|
||||
is(info.width, 600, "width equals displayWidth/1.5");
|
||||
is(info.height, 400, "height equals displayHeight/1.5");
|
||||
|
||||
nextTest();
|
||||
});
|
||||
});
|
||||
|
||||
function getViewportInfo(aDisplayWidth, aDisplayHeight) {
|
||||
let defaultZoom = {}, allowZoom = {}, minZoom = {}, maxZoom = {},
|
||||
width = {}, height = {}, autoSize = {};
|
||||
|
||||
let cwu = SpecialPowers.getDOMWindowUtils(window);
|
||||
cwu.getViewportInfo(aDisplayWidth, aDisplayHeight, defaultZoom, allowZoom,
|
||||
minZoom, maxZoom, width, height, autoSize);
|
||||
return {
|
||||
defaultZoom: defaultZoom.value,
|
||||
minZoom: minZoom.value,
|
||||
maxZoom: maxZoom.value,
|
||||
width: width.value,
|
||||
height: height.value,
|
||||
autoSize: autoSize.value,
|
||||
allowZoom: allowZoom.value
|
||||
};
|
||||
}
|
||||
|
||||
function nextTest() {
|
||||
if (tests.length)
|
||||
(tests.shift())();
|
||||
else
|
||||
SimpleTest.finish();
|
||||
}
|
||||
addEventListener("load", nextTest);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,78 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>meta viewport test</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<meta name="viewport" content="width=320">
|
||||
</head>
|
||||
<body>
|
||||
<p>width=320</p>
|
||||
<script type="application/javascript;version=1.7">
|
||||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
let tests = [];
|
||||
|
||||
tests.push(function test1() {
|
||||
SpecialPowers.pushPrefEnv({"set": [["browser.viewport.scaleRatio", 100]]},
|
||||
function() {
|
||||
let info = getViewportInfo(800, 480);
|
||||
is(info.defaultZoom, 2.5, "initial zoom fits the displayWidth");
|
||||
is(info.width, 320, "width is set explicitly");
|
||||
is(info.height, 223, "height is at the absolute minimum");
|
||||
is(info.autoSize, false, "width=device-width enables autoSize");
|
||||
is(info.allowZoom, true, "zooming is enabled by default");
|
||||
|
||||
info = getViewportInfo(480, 800);
|
||||
is(info.defaultZoom, 1.5, "initial zoom fits the new displayWidth");
|
||||
is(info.width, 320, "explicit width is unchanged");
|
||||
is(info.height, 533, "height changes proportional to displayHeight");
|
||||
|
||||
nextTest();
|
||||
});
|
||||
});
|
||||
|
||||
tests.push(function test2() {
|
||||
SpecialPowers.pushPrefEnv({"set": [["browser.viewport.scaleRatio", 150]]},
|
||||
function() {
|
||||
// With an explicit width in CSS px, the scaleRatio has no effect.
|
||||
let info = getViewportInfo(800, 480);
|
||||
is(info.defaultZoom, 2.5, "initial zoom still fits the displayWidth");
|
||||
is(info.width, 320, "width is still set explicitly");
|
||||
is(info.height, 223, "height is still minimum height");
|
||||
|
||||
nextTest();
|
||||
});
|
||||
});
|
||||
|
||||
function getViewportInfo(aDisplayWidth, aDisplayHeight) {
|
||||
let defaultZoom = {}, allowZoom = {}, minZoom = {}, maxZoom = {},
|
||||
width = {}, height = {}, autoSize = {};
|
||||
|
||||
let cwu = SpecialPowers.getDOMWindowUtils(window);
|
||||
cwu.getViewportInfo(aDisplayWidth, aDisplayHeight, defaultZoom, allowZoom,
|
||||
minZoom, maxZoom, width, height, autoSize);
|
||||
return {
|
||||
defaultZoom: defaultZoom.value,
|
||||
minZoom: minZoom.value,
|
||||
maxZoom: maxZoom.value,
|
||||
width: width.value,
|
||||
height: height.value,
|
||||
autoSize: autoSize.value,
|
||||
allowZoom: allowZoom.value
|
||||
};
|
||||
}
|
||||
|
||||
function nextTest() {
|
||||
if (tests.length)
|
||||
(tests.shift())();
|
||||
else
|
||||
SimpleTest.finish();
|
||||
}
|
||||
addEventListener("load", nextTest);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,77 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>meta viewport test</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
|
||||
</head>
|
||||
<body>
|
||||
<p>initial-scale=1.0, user-scalable=no</p>
|
||||
<script type="application/javascript;version=1.7">
|
||||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
let tests = [];
|
||||
|
||||
tests.push(function test1() {
|
||||
SpecialPowers.pushPrefEnv({"set": [["browser.viewport.scaleRatio", 100]]},
|
||||
function() {
|
||||
let info = getViewportInfo(800, 480);
|
||||
is(info.defaultZoom, 1, "initial zoom is set explicitly");
|
||||
is(info.width, 800, "width fits the initial zoom level");
|
||||
is(info.height, 480, "height fits the initial zoom level");
|
||||
is(info.autoSize, true, "initial-scale=1 enables autoSize");
|
||||
is(info.allowZoom, false, "zooming is explicitly disabled");
|
||||
|
||||
info = getViewportInfo(480, 800);
|
||||
is(info.defaultZoom, 1, "initial zoom is still set explicitly");
|
||||
is(info.width, 480, "width changes to match the displayWidth");
|
||||
is(info.height, 800, "height changes to match the displayHeight");
|
||||
|
||||
nextTest();
|
||||
});
|
||||
});
|
||||
|
||||
tests.push(function test2() {
|
||||
SpecialPowers.pushPrefEnv({"set": [["browser.viewport.scaleRatio", 150]]},
|
||||
function() {
|
||||
let info = getViewportInfo(800, 480);
|
||||
is(info.defaultZoom, 1.5, "initial zoom is adjusted for device pixel ratio");
|
||||
is(info.width, 533, "width fits the initial zoom");
|
||||
is(info.height, 320, "height fits the initial zoom");
|
||||
|
||||
nextTest();
|
||||
});
|
||||
});
|
||||
|
||||
function getViewportInfo(aDisplayWidth, aDisplayHeight) {
|
||||
let defaultZoom = {}, allowZoom = {}, minZoom = {}, maxZoom = {},
|
||||
width = {}, height = {}, autoSize = {};
|
||||
|
||||
let cwu = SpecialPowers.getDOMWindowUtils(window);
|
||||
cwu.getViewportInfo(aDisplayWidth, aDisplayHeight, defaultZoom, allowZoom,
|
||||
minZoom, maxZoom, width, height, autoSize);
|
||||
return {
|
||||
defaultZoom: defaultZoom.value,
|
||||
minZoom: minZoom.value,
|
||||
maxZoom: maxZoom.value,
|
||||
width: width.value,
|
||||
height: height.value,
|
||||
autoSize: autoSize.value,
|
||||
allowZoom: allowZoom.value
|
||||
};
|
||||
}
|
||||
|
||||
function nextTest() {
|
||||
if (tests.length)
|
||||
(tests.shift())();
|
||||
else
|
||||
SimpleTest.finish();
|
||||
}
|
||||
addEventListener("load", nextTest);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,53 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>meta viewport test</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<meta name="viewport" content="user-scalable=NO">
|
||||
</head>
|
||||
<body>
|
||||
<p>user-scalable=NO</p>
|
||||
<script type="application/javascript;version=1.7">
|
||||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
let tests = [];
|
||||
|
||||
tests.push(function test1() {
|
||||
let info = getViewportInfo(800, 480);
|
||||
is(info.allowZoom, true, "user-scalable values are case-sensitive; 'NO' is not valid");
|
||||
|
||||
nextTest();
|
||||
});
|
||||
|
||||
function getViewportInfo(aDisplayWidth, aDisplayHeight) {
|
||||
let defaultZoom = {}, allowZoom = {}, minZoom = {}, maxZoom = {},
|
||||
width = {}, height = {}, autoSize = {};
|
||||
|
||||
let cwu = SpecialPowers.getDOMWindowUtils(window);
|
||||
cwu.getViewportInfo(aDisplayWidth, aDisplayHeight, defaultZoom, allowZoom,
|
||||
minZoom, maxZoom, width, height, autoSize);
|
||||
return {
|
||||
defaultZoom: defaultZoom.value,
|
||||
minZoom: minZoom.value,
|
||||
maxZoom: maxZoom.value,
|
||||
width: width.value,
|
||||
height: height.value,
|
||||
autoSize: autoSize.value,
|
||||
allowZoom: allowZoom.value
|
||||
};
|
||||
}
|
||||
|
||||
function nextTest() {
|
||||
if (tests.length)
|
||||
(tests.shift())();
|
||||
else
|
||||
SimpleTest.finish();
|
||||
}
|
||||
addEventListener("load", nextTest);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,82 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>meta viewport test</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<meta name="viewport" content="width=2000, minimum-scale=0.75">
|
||||
</head>
|
||||
<body>
|
||||
<p>width=2000, minimum-scale=0.75</p>
|
||||
<script type="application/javascript;version=1.7">
|
||||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
let tests = [];
|
||||
|
||||
tests.push(function test1() {
|
||||
SpecialPowers.pushPrefEnv({"set": [["browser.viewport.scaleRatio", 100]]},
|
||||
function() {
|
||||
let info = getViewportInfo(800, 480);
|
||||
is(info.minZoom, 0.75, "minumum scale is set explicitly");
|
||||
is(info.defaultZoom, 0.75, "initial scale is bounded by the minimum scale");
|
||||
is(info.maxZoom, 10, "maximum scale defaults to the absolute maximum");
|
||||
is(info.width, 2000, "width is set explicitly");
|
||||
is(info.height, 1200, "height is proportional to displayHeight");
|
||||
is(info.autoSize, false, "autoSize is disabled by default");
|
||||
is(info.allowZoom, true, "zooming is enabled by default");
|
||||
|
||||
info = getViewportInfo(2000, 1000);
|
||||
is(info.minZoom, 0.75, "minumum scale is still set explicitly");
|
||||
is(info.defaultZoom, 1, "initial scale fits the width");
|
||||
is(info.width, 2000, "width is set explicitly");
|
||||
is(info.height, 1000, "height is proportional to the new displayHeight");
|
||||
|
||||
nextTest();
|
||||
});
|
||||
});
|
||||
|
||||
tests.push(function test2() {
|
||||
SpecialPowers.pushPrefEnv({"set": [["browser.viewport.scaleRatio", 150]]},
|
||||
function() {
|
||||
let info = getViewportInfo(800, 480);
|
||||
is(info.minZoom, 1.125, "minumum scale is converted to device pixel scale");
|
||||
is(info.defaultZoom, 1.125, "initial scale is bounded by the minimum scale");
|
||||
is(info.maxZoom, 15, "maximum scale defaults to the absolute maximum");
|
||||
is(info.width, 2000, "width is still set explicitly");
|
||||
is(info.height, 1200, "height is still proportional to displayHeight");
|
||||
|
||||
nextTest();
|
||||
});
|
||||
});
|
||||
|
||||
function getViewportInfo(aDisplayWidth, aDisplayHeight) {
|
||||
let defaultZoom = {}, allowZoom = {}, minZoom = {}, maxZoom = {},
|
||||
width = {}, height = {}, autoSize = {};
|
||||
|
||||
let cwu = SpecialPowers.getDOMWindowUtils(window);
|
||||
cwu.getViewportInfo(aDisplayWidth, aDisplayHeight, defaultZoom, allowZoom,
|
||||
minZoom, maxZoom, width, height, autoSize);
|
||||
return {
|
||||
defaultZoom: defaultZoom.value,
|
||||
minZoom: minZoom.value,
|
||||
maxZoom: maxZoom.value,
|
||||
width: width.value,
|
||||
height: height.value,
|
||||
autoSize: autoSize.value,
|
||||
allowZoom: allowZoom.value
|
||||
};
|
||||
}
|
||||
|
||||
function nextTest() {
|
||||
if (tests.length)
|
||||
(tests.shift())();
|
||||
else
|
||||
SimpleTest.finish();
|
||||
}
|
||||
addEventListener("load", nextTest);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -263,30 +263,6 @@ nsDOMWindowUtils::SetCSSViewport(float aWidthPx, float aHeightPx)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::GetViewportInfo(uint32_t aDisplayWidth, uint32_t aDisplayHeight,
|
||||
double *aDefaultZoom, bool *aAllowZoom,
|
||||
double *aMinZoom, double *aMaxZoom,
|
||||
uint32_t *aWidth, uint32_t *aHeight,
|
||||
bool *aAutoSize)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
|
||||
NS_ENSURE_STATE(window);
|
||||
|
||||
nsCOMPtr<nsIDocument> doc(do_QueryInterface(window->GetExtantDocument()));
|
||||
NS_ENSURE_STATE(doc);
|
||||
|
||||
ViewportInfo info = nsContentUtils::GetViewportInfo(doc, aDisplayWidth, aDisplayHeight);
|
||||
*aDefaultZoom = info.defaultZoom;
|
||||
*aAllowZoom = info.allowZoom;
|
||||
*aMinZoom = info.minZoom;
|
||||
*aMaxZoom = info.maxZoom;
|
||||
*aWidth = info.width;
|
||||
*aHeight = info.height;
|
||||
*aAutoSize = info.autoSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static void DestroyNsRect(void* aObject, nsIAtom* aPropertyName,
|
||||
void* aPropertyValue, void* aData)
|
||||
{
|
||||
|
@ -103,16 +103,6 @@ interface nsIDOMWindowUtils : nsISupports {
|
||||
*/
|
||||
void setCSSViewport(in float aWidthPx, in float aHeightPx);
|
||||
|
||||
/**
|
||||
* Information retrieved from the <meta name="viewport"> tag.
|
||||
* See nsContentUtils::GetViewportInfo for more information.
|
||||
*/
|
||||
void getViewportInfo(in uint32_t aDisplayWidth, in uint32_t aDisplayHeight,
|
||||
out double aDefaultZoom, out boolean aAllowZoom,
|
||||
out double aMinZoom, out double aMaxZoom,
|
||||
out uint32_t aWidth, out uint32_t aHeight,
|
||||
out boolean aAutoSize);
|
||||
|
||||
/**
|
||||
* For any scrollable element, this allows you to override the
|
||||
* visible region and draw more than what is visible, which is
|
||||
|
@ -5066,34 +5066,8 @@ nsLayoutUtils::FontSizeInflationEnabled(nsPresContext *aPresContext)
|
||||
return false;
|
||||
}
|
||||
|
||||
// XXXjwir3:
|
||||
// See bug 706918, comment 23 for more information on this particular section
|
||||
// of the code. We're using "screen size" in place of the size of the content
|
||||
// area, because on mobile, these are close or equal. This will work for our
|
||||
// purposes (bug 706198), but it will need to be changed in the future to be
|
||||
// more correct when we bring the rest of the viewport code into platform.
|
||||
// We actually want the size of the content area, in the event that we don't
|
||||
// have any metadata about the width and/or height. On mobile, the screen size
|
||||
// and the size of the content area are very close, or the same value.
|
||||
// In XUL fennec, the content area is the size of the <browser> widget, but
|
||||
// in native fennec, the content area is the size of the Gecko LayerView
|
||||
// object.
|
||||
|
||||
// TODO:
|
||||
// Once bug 716575 has been resolved, this code should be changed so that it
|
||||
// does the right thing on all platforms.
|
||||
nsresult result;
|
||||
int32_t screenLeft, screenTop, screenWidth, screenHeight;
|
||||
nsCOMPtr<nsIScreenManager> screenMgr =
|
||||
do_GetService("@mozilla.org/gfx/screenmanager;1", &result);
|
||||
|
||||
nsCOMPtr<nsIScreen> screen;
|
||||
screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
|
||||
screen->GetRect(&screenLeft, &screenTop, &screenWidth, &screenHeight);
|
||||
|
||||
ViewportInfo vInf =
|
||||
nsContentUtils::GetViewportInfo(aPresContext->PresShell()->GetDocument(),
|
||||
screenWidth, screenHeight);
|
||||
nsContentUtils::GetViewportInfo(aPresContext->PresShell()->GetDocument());
|
||||
|
||||
if (vInf.defaultZoom >= 1.0 || vInf.autoSize) {
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user