mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 23:23:33 +00:00
Bug 803207 - Kill GetDevicePixelsPerMetaViewportPixel and use widget scaling correctly on Fennec. r=mbrubeck
This commit is contained in:
parent
eb2df38350
commit
7c400dc164
@ -1519,15 +1519,6 @@ public:
|
||||
uint32_t aDisplayWidth,
|
||||
uint32_t aDisplayHeight);
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
/**
|
||||
* The device-pixel-to-CSS-px ratio used to adjust meta viewport values.
|
||||
* XXX Not to be used --- use nsIWidget::GetDefaultScale instead. Will be
|
||||
* removed when bug 803207 is fixed.
|
||||
*/
|
||||
static double GetDevicePixelsPerMetaViewportPixel(nsIWidget* aWidget);
|
||||
#endif
|
||||
|
||||
// Call EnterMicroTask when you're entering JS execution.
|
||||
// Usually the best way to do this is to use nsAutoMicroTask.
|
||||
static void EnterMicroTask() { ++sMicroTaskLevel; }
|
||||
|
@ -4837,30 +4837,6 @@ nsContentUtils::GetViewportInfo(nsIDocument *aDocument,
|
||||
return aDocument->GetViewportInfo(aDisplayWidth, aDisplayHeight);
|
||||
}
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
/* static */
|
||||
double
|
||||
nsContentUtils::GetDevicePixelsPerMetaViewportPixel(nsIWidget* aWidget)
|
||||
{
|
||||
int32_t 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, LDPI and MDPI Android devices
|
||||
return 1.0;
|
||||
}
|
||||
if (dpi < 300.0) {
|
||||
// Includes Nokia N900, and HDPI Android devices
|
||||
return 1.5;
|
||||
}
|
||||
// For very high-density displays like the iPhone 4, use an integer ratio.
|
||||
return floor(dpi / 150.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* static */
|
||||
nsresult
|
||||
nsContentUtils::ProcessViewportInfo(nsIDocument *aDocument,
|
||||
|
@ -6906,12 +6906,7 @@ nsDocument::GetViewportInfo(uint32_t aDisplayWidth,
|
||||
}
|
||||
// Now convert the scale into device pixels per CSS pixel.
|
||||
nsIWidget *widget = nsContentUtils::WidgetForDocument(this);
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
// Temporarily use special Android code until bug 803207 is fixed
|
||||
double pixelRatio = widget ? nsContentUtils::GetDevicePixelsPerMetaViewportPixel(widget) : 1.0;
|
||||
#else
|
||||
double pixelRatio = widget ? widget->GetDefaultScale() : 1.0;
|
||||
#endif
|
||||
float scaleFloat = mScaleFloat * pixelRatio;
|
||||
float scaleMinFloat= mScaleMinFloat * pixelRatio;
|
||||
float scaleMaxFloat = mScaleMaxFloat * pixelRatio;
|
||||
|
@ -1,6 +1,3 @@
|
||||
function scaleRatio(scale) {
|
||||
if (navigator.appVersion.indexOf("Android") >= 0) {
|
||||
return {"set": [["browser.viewport.scaleRatio", 100*scale]]};
|
||||
}
|
||||
return {"set": [["layout.css.devPixelsPerPx", "" + scale]]};
|
||||
}
|
||||
|
@ -41,8 +41,6 @@ pref("toolkit.zoomManager.zoomValues", ".2,.3,.5,.67,.8,.9,1,1.1,1.2,1.33,1.5,1.
|
||||
// Mobile will use faster, less durable mode.
|
||||
pref("toolkit.storage.synchronous", 0);
|
||||
|
||||
// Device pixel to CSS px ratio, in percent. Set to -1 to calculate based on display density.
|
||||
pref("browser.viewport.scaleRatio", -1);
|
||||
pref("browser.viewport.desktopWidth", 980);
|
||||
// The default fallback zoom level to render pages at. Set to -1 to fit page; otherwise
|
||||
// the value is divided by 1000 and clamped to hard-coded min/max scale values.
|
||||
|
@ -426,6 +426,13 @@ public class GeckoEvent {
|
||||
mPointRadii[index] = new Point((int)size,(int)size);
|
||||
mOrientations[index] = 0;
|
||||
}
|
||||
if (!keepInViewCoordinates) {
|
||||
// If we are converting to gecko CSS pixels, then we should adjust the
|
||||
// radii as well
|
||||
float zoom = GeckoAppShell.getLayerView().getViewportMetrics().zoomFactor;
|
||||
mPointRadii[index].x /= zoom;
|
||||
mPointRadii[index].y /= zoom;
|
||||
}
|
||||
mPressures[index] = event.getPressure(eventIndex);
|
||||
} catch (Exception ex) {
|
||||
Log.e(LOGTAG, "Error creating motion point " + index, ex);
|
||||
|
@ -2800,7 +2800,7 @@ Tab.prototype = {
|
||||
if (BrowserApp.selectedTab == this) {
|
||||
if (resolution != this._drawZoom) {
|
||||
this._drawZoom = resolution;
|
||||
cwu.setResolution(resolution, resolution);
|
||||
cwu.setResolution(resolution / window.devicePixelRatio, resolution / window.devicePixelRatio);
|
||||
}
|
||||
} else if (!fuzzyEquals(resolution, zoom)) {
|
||||
dump("Warning: setDisplayPort resolution did not match zoom for background tab! (" + resolution + " != " + zoom + ")");
|
||||
@ -3080,7 +3080,7 @@ Tab.prototype = {
|
||||
if (BrowserApp.selectedTab == this) {
|
||||
let cwu = window.top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
||||
this._drawZoom = aZoom;
|
||||
cwu.setResolution(aZoom, aZoom);
|
||||
cwu.setResolution(aZoom / window.devicePixelRatio, aZoom / window.devicePixelRatio);
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -3675,7 +3675,7 @@ Tab.prototype = {
|
||||
aMetadata.minZoom = aMetadata.maxZoom = NaN;
|
||||
}
|
||||
|
||||
let scaleRatio = aMetadata.scaleRatio;
|
||||
let scaleRatio = window.devicePixelRatio;
|
||||
|
||||
if (aMetadata.defaultZoom > 0)
|
||||
aMetadata.defaultZoom *= scaleRatio;
|
||||
@ -3716,8 +3716,8 @@ Tab.prototype = {
|
||||
|
||||
let metadata = this.metadata;
|
||||
if (metadata.autoSize) {
|
||||
viewportW = screenW / metadata.scaleRatio;
|
||||
viewportH = screenH / metadata.scaleRatio;
|
||||
viewportW = screenW / window.devicePixelRatio;
|
||||
viewportH = screenH / window.devicePixelRatio;
|
||||
} else {
|
||||
viewportW = metadata.width;
|
||||
viewportH = metadata.height;
|
||||
@ -3811,7 +3811,7 @@ Tab.prototype = {
|
||||
sendMessageToJava({
|
||||
type: "Tab:ViewportMetadata",
|
||||
allowZoom: metadata.allowZoom,
|
||||
defaultZoom: metadata.defaultZoom || metadata.scaleRatio,
|
||||
defaultZoom: metadata.defaultZoom || window.devicePixelRatio,
|
||||
minZoom: metadata.minZoom || 0,
|
||||
maxZoom: metadata.maxZoom || 0,
|
||||
isRTL: metadata.isRTL,
|
||||
@ -5450,8 +5450,8 @@ var ViewportHandler = {
|
||||
break;
|
||||
|
||||
let oldScreenWidth = gScreenWidth;
|
||||
gScreenWidth = window.outerWidth;
|
||||
gScreenHeight = window.outerHeight;
|
||||
gScreenWidth = window.outerWidth * window.devicePixelRatio;
|
||||
gScreenHeight = window.outerHeight * window.devicePixelRatio;
|
||||
let tabs = BrowserApp.tabs;
|
||||
for (let i = 0; i < tabs.length; i++)
|
||||
tabs[i].updateViewportSize(oldScreenWidth);
|
||||
@ -5551,23 +5551,6 @@ var ViewportHandler = {
|
||||
return Math.max(min, Math.min(max, num));
|
||||
},
|
||||
|
||||
// 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() {
|
||||
let prefValue = Services.prefs.getIntPref("browser.viewport.scaleRatio");
|
||||
if (prefValue > 0)
|
||||
return prefValue / 100;
|
||||
|
||||
let dpi = this.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);
|
||||
},
|
||||
|
||||
get displayDPI() {
|
||||
let utils = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
||||
delete this.displayDPI;
|
||||
@ -5603,7 +5586,6 @@ var ViewportHandler = {
|
||||
* autoSize (boolean): Resize the CSS viewport when the window resizes.
|
||||
* allowZoom (boolean): Let the user zoom in or out.
|
||||
* isSpecified (boolean): Whether the page viewport is specified or not.
|
||||
* scaleRatio (float): The device-pixel-to-CSS-px ratio.
|
||||
*/
|
||||
function ViewportMetadata(aMetadata = {}) {
|
||||
this.width = ("width" in aMetadata) ? aMetadata.width : 0;
|
||||
@ -5614,7 +5596,6 @@ function ViewportMetadata(aMetadata = {}) {
|
||||
this.autoSize = ("autoSize" in aMetadata) ? aMetadata.autoSize : false;
|
||||
this.allowZoom = ("allowZoom" in aMetadata) ? aMetadata.allowZoom : true;
|
||||
this.isSpecified = ("isSpecified" in aMetadata) ? aMetadata.isSpecified : false;
|
||||
this.scaleRatio = ViewportHandler.getScaleRatio();
|
||||
this.isRTL = ("isRTL" in aMetadata) ? aMetadata.isRTL : false;
|
||||
Object.seal(this);
|
||||
}
|
||||
@ -5628,7 +5609,6 @@ ViewportMetadata.prototype = {
|
||||
autoSize: null,
|
||||
allowZoom: null,
|
||||
isSpecified: null,
|
||||
scaleRatio: null,
|
||||
isRTL: null,
|
||||
};
|
||||
|
||||
|
@ -781,9 +781,19 @@ AndroidGeckoEvent::MakeTouchEvent(nsIWidget* widget)
|
||||
const nsIntPoint& offset = widget->WidgetToScreenOffset();
|
||||
event.touches.SetCapacity(endIndex - startIndex);
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
// In this code branch, we are dispatching this event directly
|
||||
// into Gecko (as opposed to going through the AsyncPanZoomController),
|
||||
// and the Points() array has points in CSS pixels, which we need
|
||||
// to convert.
|
||||
nsIntPoint pt(
|
||||
(Points()[i].x * widget->GetDefaultScale()) - offset.x,
|
||||
(Points()[i].y * widget->GetDefaultScale()) - offset.y);
|
||||
nsIntPoint radii(
|
||||
PointRadii()[i].x * widget->GetDefaultScale(),
|
||||
PointRadii()[i].y * widget->GetDefaultScale());
|
||||
nsRefPtr<Touch> t = new Touch(PointIndicies()[i],
|
||||
Points()[i] - offset,
|
||||
PointRadii()[i],
|
||||
pt,
|
||||
radii,
|
||||
Orientations()[i],
|
||||
Pressures()[i]);
|
||||
event.touches.AppendElement(t);
|
||||
|
@ -338,6 +338,20 @@ nsWindow::GetDPI()
|
||||
return 160.0f;
|
||||
}
|
||||
|
||||
double
|
||||
nsWindow::GetDefaultScaleInternal()
|
||||
{
|
||||
float dpi = GetDPI();
|
||||
if (dpi < 200) { // includes desktop displays, LDPI, and MDPI Android devices
|
||||
return 1.0;
|
||||
}
|
||||
if (dpi < 300) { // includes Nokia N900, HDPI Android devices
|
||||
return 1.5;
|
||||
}
|
||||
// for very high-density displays calculate an integer ratio.
|
||||
return floor(dpi / 150);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWindow::Show(bool aState)
|
||||
{
|
||||
|
@ -70,6 +70,7 @@ public:
|
||||
NS_IMETHOD SetParent(nsIWidget* aNewParent);
|
||||
virtual nsIWidget *GetParent(void);
|
||||
virtual float GetDPI();
|
||||
virtual double GetDefaultScaleInternal();
|
||||
NS_IMETHOD Show(bool aState);
|
||||
NS_IMETHOD SetModal(bool aModal);
|
||||
virtual bool IsVisible() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user