Bug 1282902 - Part 1 - Add a helper method for getting the content viewer size in device pixels. r=kats
The intention is for the session store to record the current window size and then pass it to the MobileViewportManager for restoring, so the latter can correctly scale the stored resolution if the display width has since changed. However currently all window dimensions available from the JS side are measured in CSS pixels rounded to integers. Transforming those values back into display pixels by multiplying them with "window.devicePixelRatio" (or accessing window.gScreenWidth/Height, which does the same thing internally) unfortunately introduces some rounding errors.
Therefore this patch introduces a new helper method in DOMWindowUtils which allows to access the content window width as measured in device pixels from the JS side, too.
MozReview-Commit-ID: FGNQlXhkgrU
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -332,16 +332,32 @@ nsDOMWindowUtils::UpdateLayerTree()
presShell->Paint(view, view->GetBounds(),
nsIPresShell::PAINT_LAYERS | nsIPresShell::PAINT_SYNC_DECODE_IMAGES);
}
}
return NS_OK;
}
NS_IMETHODIMP
+nsDOMWindowUtils::GetContentViewerSize(uint32_t *aDisplayWidth, uint32_t *aDisplayHeight)
+{
+ nsIPresShell* presShell = GetPresShell();
+ LayoutDeviceIntSize displaySize;
+
+ if (!presShell || !nsLayoutUtils::GetContentViewerSize(presShell->GetPresContext(), displaySize)) {
+ return NS_ERROR_FAILURE;
+ }
+
+ *aDisplayWidth = displaySize.width;
+ *aDisplayHeight = displaySize.height;
+
+ 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)
{
nsIDocument* doc = GetDocument();
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -117,16 +117,21 @@ interface nsIDOMWindowUtils : nsISupport
*/
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);
/**
+ * Information about the window size in device pixels.
+ */
+ void getContentViewerSize(out uint32_t aDisplayWidth, out uint32_t aDisplayHeight);
+
+ /**
* For any scrollable element, this allows you to override the
* visible region and draw more than what is visible, which is
* useful for asynchronous drawing. The "displayport" will be
* <xPx, yPx, widthPx, heightPx> in units of CSS pixels,
* regardless of the size of the enclosing container. This
* will *not* trigger reflow.
*
* For the root scroll area, pass in the root document element.