зеркало из https://github.com/mozilla/gecko-dev.git
bug 674373 pt 5 - provide a fullZoom API in nsIDOMWindowUtils, and use this rather than inferring zoom from CSS to device pixel ratio. r=roc
This commit is contained in:
Родитель
ed41d7aef7
Коммит
7c72bd5ca4
|
@ -733,7 +733,7 @@ const gFormSubmitObserver = {
|
|||
offset = parseInt(style.paddingLeft) + parseInt(style.borderLeftWidth);
|
||||
}
|
||||
|
||||
offset = Math.round(offset * utils.screenPixelsPerCSSPixel);
|
||||
offset = Math.round(offset * utils.fullZoom);
|
||||
|
||||
position = "after_start";
|
||||
}
|
||||
|
@ -7551,9 +7551,9 @@ var MousePosTracker = {
|
|||
},
|
||||
|
||||
handleEvent: function (event) {
|
||||
var screenPixelsPerCSSPixel = this._windowUtils.screenPixelsPerCSSPixel;
|
||||
this._x = event.screenX / screenPixelsPerCSSPixel - window.mozInnerScreenX;
|
||||
this._y = event.screenY / screenPixelsPerCSSPixel - window.mozInnerScreenY;
|
||||
var fullZoom = this._windowUtils.fullZoom;
|
||||
this._x = event.screenX / fullZoom - window.mozInnerScreenX;
|
||||
this._y = event.screenY / fullZoom - window.mozInnerScreenY;
|
||||
|
||||
this._listeners.forEach(function (listener) {
|
||||
try {
|
||||
|
|
|
@ -694,7 +694,7 @@ Highlighter.prototype = {
|
|||
this.zoom =
|
||||
this.win.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindowUtils)
|
||||
.screenPixelsPerCSSPixel;
|
||||
.fullZoom;
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -175,7 +175,7 @@ LayoutHelpers = {
|
|||
let zoom =
|
||||
aWin.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIDOMWindowUtils)
|
||||
.screenPixelsPerCSSPixel;
|
||||
.fullZoom;
|
||||
|
||||
// adjust rect for zoom scaling
|
||||
let aRectScaled = {};
|
||||
|
|
|
@ -62,7 +62,7 @@ function runTest() {
|
|||
|
||||
let [ctrlKey, isMomentum] = outstandingTests.shift();
|
||||
let scrollTopBefore = scrollbox.scrollTop;
|
||||
let zoomFactorBefore = winUtils.screenPixelsPerCSSPixel;
|
||||
let zoomFactorBefore = winUtils.fullZoom;
|
||||
sendTouchpadScrollMotion(scrollbox, 1, ctrlKey, isMomentum);
|
||||
|
||||
setTimeout(function () {
|
||||
|
@ -70,14 +70,14 @@ function runTest() {
|
|||
if (!ctrlKey) {
|
||||
let postfix = isMomentum ? ", even after releasing the touchpad" : "";
|
||||
// Normal scroll: scroll
|
||||
is(winUtils.screenPixelsPerCSSPixel, zoomFactorBefore, "Normal scrolling shouldn't change zoom" + postfix);
|
||||
is(winUtils.fullZoom, zoomFactorBefore, "Normal scrolling shouldn't change zoom" + postfix);
|
||||
isnot(scrollbox.scrollTop, scrollTopBefore, "Normal scrolling should scroll" + postfix);
|
||||
} else {
|
||||
if (!isMomentum) {
|
||||
isnot(winUtils.screenPixelsPerCSSPixel, zoomFactorBefore, "Ctrl-scrolling should zoom while the user is touching the touchpad");
|
||||
isnot(winUtils.fullZoom, zoomFactorBefore, "Ctrl-scrolling should zoom while the user is touching the touchpad");
|
||||
is(scrollbox.scrollTop, scrollTopBefore, "Ctrl-scrolling shouldn't scroll while the user is touching the touchpad");
|
||||
} else {
|
||||
is(winUtils.screenPixelsPerCSSPixel, zoomFactorBefore, "Momentum scrolling shouldn't zoom, even when pressing Ctrl");
|
||||
is(winUtils.fullZoom, zoomFactorBefore, "Momentum scrolling shouldn't zoom, even when pressing Ctrl");
|
||||
isnot(scrollbox.scrollTop, scrollTopBefore, "Momentum scrolling should scroll, even when pressing Ctrl");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1510,6 +1510,25 @@ nsDOMWindowUtils::GetScreenPixelsPerCSSPixel(float* aScreenPixels)
|
|||
return window->GetDevicePixelRatio(aScreenPixels);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::GetFullZoom(float* aFullZoom)
|
||||
{
|
||||
*aFullZoom = 1.0f;
|
||||
|
||||
if (!nsContentUtils::IsCallerTrustedForRead()) {
|
||||
return NS_ERROR_DOM_SECURITY_ERR;
|
||||
}
|
||||
|
||||
nsPresContext* presContext = GetPresContext();
|
||||
if (!presContext) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*aFullZoom = presContext->DeviceContext()->GetPixelScale();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::DispatchDOMEventViaPresShell(nsIDOMNode* aTarget,
|
||||
nsIDOMEvent* aEvent,
|
||||
|
|
|
@ -40,7 +40,7 @@ interface nsIDOMTouch;
|
|||
interface nsIDOMClientRect;
|
||||
interface nsIURI;
|
||||
|
||||
[scriptable, uuid(90d8e97b-2c61-4c05-9f1c-e568d22f5bdc)]
|
||||
[scriptable, uuid(47405734-D827-44AE-AC01-EF10E80F5D04)]
|
||||
interface nsIDOMWindowUtils : nsISupports {
|
||||
|
||||
/**
|
||||
|
@ -697,6 +697,14 @@ interface nsIDOMWindowUtils : nsISupports {
|
|||
*/
|
||||
readonly attribute float screenPixelsPerCSSPixel;
|
||||
|
||||
/**
|
||||
* Get the current zoom factor.
|
||||
* This is _approximately_ the same as nsIMarkupDocumentViewer.fullZoom,
|
||||
* but takes into account Gecko's quantization of the zoom factor, which is
|
||||
* implemented by adjusting the (integer) number of appUnits per devPixel.
|
||||
*/
|
||||
readonly attribute float fullZoom;
|
||||
|
||||
/**
|
||||
* Dispatches aEvent via the nsIPresShell object of the window's document.
|
||||
* The event is dispatched to aTarget, which should be an object
|
||||
|
|
|
@ -734,4 +734,6 @@ nsDeviceContext::UpdateScaledAppUnits()
|
|||
{
|
||||
mAppUnitsPerDevPixel =
|
||||
NS_MAX(1, NSToIntRound(float(mAppUnitsPerDevNotScaledPixel) / mPixelScale));
|
||||
// adjust mPixelScale to reflect appunit rounding
|
||||
mPixelScale = float(mAppUnitsPerDevNotScaledPixel) / mAppUnitsPerDevPixel;
|
||||
}
|
||||
|
|
|
@ -222,6 +222,11 @@ public:
|
|||
*/
|
||||
bool SetPixelScale(float aScale);
|
||||
|
||||
/**
|
||||
* Returns the pixel scaling factor (page zoom factor) applied.
|
||||
*/
|
||||
float GetPixelScale() const { return mPixelScale; }
|
||||
|
||||
/**
|
||||
* True if this device context was created for printing.
|
||||
*/
|
||||
|
|
|
@ -38,11 +38,11 @@ function run() {
|
|||
return window.getComputedStyle(document.getElementById(divName), null).visibility == "visible";
|
||||
}
|
||||
|
||||
function getZoomRatio() {
|
||||
function getScreenPixelsPerCSSPixel() {
|
||||
return SpecialPowers.DOMWindowUtils.screenPixelsPerCSSPixel;
|
||||
}
|
||||
|
||||
var screenPixelsPerCSSPixel = getZoomRatio();
|
||||
var screenPixelsPerCSSPixel = getScreenPixelsPerCSSPixel();
|
||||
var baseRatio = 1.0 * screenPixelsPerCSSPixel;
|
||||
var doubleRatio = 2.0 * screenPixelsPerCSSPixel;
|
||||
var halfRatio = 0.5 * screenPixelsPerCSSPixel;
|
||||
|
@ -61,10 +61,10 @@ function run() {
|
|||
|
||||
ok(isVisible("zoom1"), "Base ratio rule should apply at base zoom level");
|
||||
ok(!isVisible("zoom2") && !isVisible("zoom3"), "no other rules should apply");
|
||||
var origZoom = zoom(2 * screenPixelsPerCSSPixel);
|
||||
var origZoom = zoom(2);
|
||||
ok(isVisible("zoom2"), "Double ratio rule should apply at double zoom level");
|
||||
ok(!isVisible("zoom1") && !isVisible("zoom3"), "no other rules should apply");
|
||||
zoom(0.5 * screenPixelsPerCSSPixel);
|
||||
zoom(0.5);
|
||||
ok(isVisible("zoom3"), "Half ratio rule should apply at half zoom level");
|
||||
ok(!isVisible("zoom1") && !isVisible("zoom2"), "no other rules should apply");
|
||||
zoom(origZoom);
|
||||
|
|
Загрузка…
Ссылка в новой задаче