Bug 590777 - part 2: Calculate viewport scale based on display DPI [r=mfinkle]

This commit is contained in:
Matt Brubeck 2010-11-16 14:50:34 -08:00
Родитель 8686f92368
Коммит 242a0fc124
4 изменённых файлов: 55 добавлений и 31 удалений

Просмотреть файл

@ -58,7 +58,9 @@ pref("toolkit.screen.lock", false);
pref("zoom.minPercent", 20);
pref("zoom.maxPercent", 400);
pref("toolkit.zoomManager.zoomValues", ".2,.3,.5,.67,.8,.9,1,1.1,1.2,1.33,1.5,1.7,2,2.4,3,4");
pref("zoom.dpiScale", 150);
// Device pixel to CSS px ratio, in percent. Set to -1 to calculate based on display density.
pref("browser.viewport.scaleRatio", -1);
/* use custom widget for html:select */
pref("ui.use_native_popup_windows", true);

Просмотреть файл

@ -495,7 +495,7 @@ var Browser = {
this.contentScrollboxScroller.scrollTo(x.value, 0);
this.pageScrollboxScroller.scrollTo(0, 0);
},
// cmd_scrollBottom does not work in Fennec (Bug 590535).
scrollContentToBottom: function scrollContentToBottom(aOptions) {
let x = {}, y = {};
@ -564,10 +564,10 @@ var Browser = {
keyword = aURL.substr(0, offset);
param = aURL.substr(offset + 1);
}
if (!aPostDataRef)
aPostDataRef = {};
let engine = Services.search.getEngineByAlias(keyword);
if (engine) {
let submission = engine.getSubmission(param);
@ -830,7 +830,7 @@ var Browser = {
// Add a new SSL exception for this URL
let uri = Services.io.newURI(json.url, null, null);
let sslExceptions = new SSLExceptions();
if (json.action == "permanent")
sslExceptions.addPermanentException(uri);
else
@ -838,7 +838,7 @@ var Browser = {
} catch (e) {
dump("EXCEPTION handle content command: " + e + "\n" );
}
// Automatically reload after the exception was added
aMessage.target.reload();
}
@ -1478,7 +1478,7 @@ const ContentTouchHandler = {
switch (aMessage.name) {
case "Browser:ContextMenu":
// Long tap
// Long tap
this._contextMenu = { name: aMessage.name, json: aMessage.json, target: aMessage.target };
break;
@ -2217,7 +2217,7 @@ var AlertsHelper = {
document.getElementById("alerts-image").setAttribute("src", aImageURL);
document.getElementById("alerts-title").value = aTitle;
document.getElementById("alerts-text").textContent = aText;
let container = this.container;
container.hidden = false;
container.height = container.getBoundingClientRect().height;
@ -2229,15 +2229,15 @@ var AlertsHelper = {
clearTimeout(this._timeoutID);
this._timeoutID = setTimeout(function() { self._timeoutAlert(); }, timeout);
},
_timeoutAlert: function ah__timeoutAlert() {
this._timeoutID = -1;
this.container.classList.remove("showing");
if (this._listener)
this._listener.observe(null, "alertfinished", this._cookie);
},
alertTransitionOver: function ah_alertTransitionOver() {
let container = this.container;
if (!container.classList.contains("showing")) {
@ -2518,15 +2518,25 @@ Tab.prototype = {
return null;
return this._notification.inputHandler;
},
get overlay() {
if (!this._notification)
return null;
return this._notification.overlay;
return this._notification.overlay;
},
/** Update browser styles when the viewport metadata changes. */
updateViewportMetadata: function updateViewportMetadata(aMetadata) {
if (aMetadata && aMetadata.autoScale) {
let scaleRatio = aMetadata.scaleRatio = this.getScaleRatio();
if ("defaultZoom" in aMetadata && aMetadata.defaultZoom > 0)
aMetadata.defaultZoom *= scaleRatio;
if ("minZoom" in aMetadata && aMetadata.minZoom > 0)
aMetadata.minZoom *= scaleRatio;
if ("maxZoom" in aMetadata && aMetadata.maxZoom > 0)
aMetadata.maxZoom *= scaleRatio;
}
this._metadata = aMetadata;
this.updateViewportSize();
},
@ -2544,17 +2554,14 @@ Tab.prototype = {
let viewportW, viewportH;
let metadata = this.metadata;
let scaleRatio = this.getScaleRatio();
if (metadata.autoScale) {
metadata.defaultZoom *= scaleRatio;
metadata.minZoom *= scaleRatio;
metadata.maxZoom *= scaleRatio;
}
if (metadata.autoSize) {
viewportW = screenW / metadata.defaultZoom;
viewportH = screenH / metadata.defaultZoom;
if ("scaleRatio" in metadata) {
viewportW = screenW / metadata.scaleRatio;
viewportH = screenH / metadata.scaleRatio;
} else {
viewportW = screenW;
viewportH = screenH;
}
} else {
viewportW = metadata.width;
viewportH = metadata.height;
@ -2583,7 +2590,18 @@ Tab.prototype = {
// The device-pixel-to-CSS-px ratio used to adjust meta viewport values.
// This is higher on higher-dpi displays, so pages stay about the same physical size.
getScaleRatio: function getScaleRatio() {
return Services.prefs.getIntPref("zoom.dpiScale") / 100;
let prefValue = Services.prefs.getIntPref("browser.viewport.scaleRatio");
if (prefValue > 0)
return prefValue / 100;
let dpi = Browser.windowUtils.displayDPI;
if (dpi < 200) // Includes desktop displays, and LDPI and MDPI Android devices
return 1;
else if (dpi < 300) // Includes Nokia N900, and HDPI Android devices
return 1.5;
// For very high-density displays like the iPhone 4, calculate an integer ratio.
return Math.floor(dpi / 150);
},
restoreViewportPosition: function restoreViewportPosition(aOldWidth, aNewWidth) {
@ -2651,7 +2669,7 @@ Tab.prototype = {
_createBrowser: function _createBrowser(aURI, aInsertBefore) {
if (this._browser)
throw "Browser already exists";
// Create a notification box around the browser
let notification = this._notification = document.createElement("notificationbox");
notification.classList.add("inputHandler");

Просмотреть файл

@ -527,8 +527,6 @@ Content.prototype = {
let contentObject = new Content();
let ViewportHandler = {
metadata: null,
init: function init() {
addEventListener("DOMWindowCreated", this, false);
addEventListener("DOMMetaAdded", this, false);
@ -560,13 +558,11 @@ let ViewportHandler = {
},
resetMetadata: function resetMetadata() {
this.metadata = null;
sendAsyncMessage("Browser:ViewportMetadata", null);
},
updateMetadata: function updateMetadata() {
this.metadata = this.getViewportMetadata();
sendAsyncMessage("Browser:ViewportMetadata", this.metadata);
sendAsyncMessage("Browser:ViewportMetadata", this.getViewportMetadata());
},
/**

Просмотреть файл

@ -44,6 +44,11 @@ let testURL_blank = baseURI + "browser_blank_01.html";
function testURL(n) {
return baseURI + "browser_viewport.sjs?" + encodeURIComponent(gTestData[n].metadata);
}
function scaleRatio(n) {
if ("scaleRatio" in gTestData[n])
return gTestData[n].scaleRatio;
return 150; // Default value matches our main target hardware (N900, Nexus One, etc.)
}
let working_tab;
@ -63,6 +68,8 @@ let loadUrl = function loadUrl(tab, url, callback) {
let gTestData = [
{ metadata: "", width: 980, scale: 1 },
{ metadata: "width=device-width, initial-scale=1", width: 533.33, scale: 1.5 },
{ metadata: "width=device-width", width: 533.33, scale: 1.5 },
{ metadata: "width=device-width, initial-scale=1", scaleRatio: 100, width: 800, scale: 1 },
{ metadata: "width=320, initial-scale=1", width: 533.33, scale: 1.5 },
{ metadata: "initial-scale=1.0, user-scalable=no", width: 533.33, scale: 1.5, disableZoom: true },
{ metadata: "initial-scale=1.0, user-scalable=0", width: 533.33, scale: 1.5, disableZoom: true },
@ -101,6 +108,7 @@ function test() {
function startTest(n) {
BrowserUI.goToURI(testURL_blank);
loadUrl(working_tab, testURL_blank, verifyBlank(n));
Services.prefs.setIntPref("browser.viewport.scaleRatio", scaleRatio(n));
}
function verifyBlank(n) {
@ -124,7 +132,6 @@ function is_approx(actual, expected, fuzz, description) {
function verifyTest(n) {
return function() {
is(window.innerWidth, 800, "Test assumes window width is 800px");
is(Services.prefs.getIntPref("zoom.dpiScale") / 100, 1.5, "Test assumes zoom.dpiScale is 1.5");
// Do sanity tests
var uri = working_tab.browser.currentURI.spec;
@ -173,6 +180,7 @@ function verifyTest(n) {
}
function finishTest(n) {
Services.prefs.clearUserPref("browser.viewport.scaleRatio");
if (n+1 < gTestData.length) {
startTest(n+1);
} else {