Bug 1773813 - Incorporate OS zoom factor in window sizing calculations. r=tnikkel
In bug 1773342 I made OS text scale factor behave like a full zoom factor which applies to all pages (including the browser chrome). That's generally straight forward but it makes some callsites that use unzoomed CSS coordinates misbehave (or behave correctly accidentally actually in some other cases). The main fix here is making nsIBaseWindow::UnscaledDevicePixelsPerCSSPixel() and nsIScreen::GetDefaultCSSScaleFactor() account for OS zoom as necessary. However, I also went through the relevant code and cleaned it up to use typed units and operations when possible. The setup means: * nsIWidget::GetDefaultScale() doesn't account for OS full zoom. * nsIBaseWindow and nsIScreen does. These are the places where this should matter and stuff can get confused, but this works surprisingly well for all callers (except one nsDeviceContext one which we use only for PuppetWidget and we can remove by falling back to 1.0 like all other widgets until the update comes). Differential Revision: https://phabricator.services.mozilla.com/D149033
This commit is contained in:
@@ -4641,20 +4641,14 @@ nsDocShell::Destroy() {
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
double nsDocShell::GetWidgetCSSToDeviceScale() {
|
||||||
nsDocShell::GetUnscaledDevicePixelsPerCSSPixel(double* aScale) {
|
|
||||||
if (mParentWidget) {
|
if (mParentWidget) {
|
||||||
*aScale = mParentWidget->GetDefaultScale().scale;
|
return mParentWidget->GetDefaultScale().scale;
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
if (nsCOMPtr<nsIBaseWindow> ownerWindow = do_QueryInterface(mTreeOwner)) {
|
||||||
nsCOMPtr<nsIBaseWindow> ownerWindow(do_QueryInterface(mTreeOwner));
|
return ownerWindow->GetWidgetCSSToDeviceScale();
|
||||||
if (ownerWindow) {
|
|
||||||
return ownerWindow->GetUnscaledDevicePixelsPerCSSPixel(aScale);
|
|
||||||
}
|
}
|
||||||
|
return 1.0;
|
||||||
*aScale = 1.0;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|||||||
@@ -552,14 +552,8 @@ nsDocShellTreeOwner::Destroy() {
|
|||||||
return NS_ERROR_NULL_POINTER;
|
return NS_ERROR_NULL_POINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
double nsDocShellTreeOwner::GetWidgetCSSToDeviceScale() {
|
||||||
nsDocShellTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(double* aScale) {
|
return mWebBrowser ? mWebBrowser->GetWidgetCSSToDeviceScale() : 1.0;
|
||||||
if (mWebBrowser) {
|
|
||||||
return mWebBrowser->GetUnscaledDevicePixelsPerCSSPixel(aScale);
|
|
||||||
}
|
|
||||||
|
|
||||||
*aScale = 1.0;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|||||||
@@ -7518,53 +7518,37 @@ void nsGlobalWindowInner::SetReplaceableWindowCoord(
|
|||||||
if (innerWidthSpecified || innerHeightSpecified || outerWidthSpecified ||
|
if (innerWidthSpecified || innerHeightSpecified || outerWidthSpecified ||
|
||||||
outerHeightSpecified) {
|
outerHeightSpecified) {
|
||||||
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin = outer->GetTreeOwnerWindow();
|
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin = outer->GetTreeOwnerWindow();
|
||||||
nsCOMPtr<nsIScreen> screen;
|
|
||||||
nsCOMPtr<nsIScreenManager> screenMgr(
|
nsCOMPtr<nsIScreenManager> screenMgr(
|
||||||
do_GetService("@mozilla.org/gfx/screenmanager;1"));
|
do_GetService("@mozilla.org/gfx/screenmanager;1"));
|
||||||
int32_t winLeft = 0;
|
|
||||||
int32_t winTop = 0;
|
|
||||||
int32_t winWidth = 0;
|
|
||||||
int32_t winHeight = 0;
|
|
||||||
double scale = 1.0;
|
|
||||||
|
|
||||||
if (treeOwnerAsWin && screenMgr) {
|
if (treeOwnerAsWin && screenMgr) {
|
||||||
// Acquire current window size.
|
// Acquire current window size.
|
||||||
treeOwnerAsWin->GetUnscaledDevicePixelsPerCSSPixel(&scale);
|
//
|
||||||
treeOwnerAsWin->GetPositionAndSize(&winLeft, &winTop, &winWidth,
|
// FIXME: This needs to account for full zoom like the outer window code
|
||||||
&winHeight);
|
// does! Ideally move there?
|
||||||
winLeft = NSToIntRound(winHeight / scale);
|
auto cssScale = treeOwnerAsWin->UnscaledDevicePixelsPerCSSPixel();
|
||||||
winTop = NSToIntRound(winWidth / scale);
|
LayoutDeviceIntRect devWinRect = treeOwnerAsWin->GetPositionAndSize();
|
||||||
winWidth = NSToIntRound(winWidth / scale);
|
CSSIntRect cssWinRect = RoundedToInt(devWinRect / cssScale);
|
||||||
winHeight = NSToIntRound(winHeight / scale);
|
|
||||||
|
|
||||||
// Acquire content window size.
|
// Acquire content window size.
|
||||||
CSSSize contentSize;
|
CSSSize contentSize;
|
||||||
outer->GetInnerSize(contentSize);
|
outer->GetInnerSize(contentSize);
|
||||||
|
|
||||||
screenMgr->ScreenForRect(winLeft, winTop, winWidth, winHeight,
|
nsCOMPtr<nsIScreen> screen = screenMgr->ScreenForRect(RoundedToInt(
|
||||||
getter_AddRefs(screen));
|
devWinRect / treeOwnerAsWin->DevicePixelsPerDesktopPixel()));
|
||||||
|
|
||||||
if (screen) {
|
if (screen) {
|
||||||
int32_t roundedValue = std::round(value);
|
int32_t roundedValue = std::round(value);
|
||||||
int32_t* targetContentWidth = nullptr;
|
int32_t* targetContentWidth = nullptr;
|
||||||
int32_t* targetContentHeight = nullptr;
|
int32_t* targetContentHeight = nullptr;
|
||||||
int32_t screenWidth = 0;
|
|
||||||
int32_t screenHeight = 0;
|
|
||||||
int32_t chromeWidth = 0;
|
|
||||||
int32_t chromeHeight = 0;
|
|
||||||
int32_t inputWidth = 0;
|
int32_t inputWidth = 0;
|
||||||
int32_t inputHeight = 0;
|
int32_t inputHeight = 0;
|
||||||
int32_t unused = 0;
|
int32_t unused = 0;
|
||||||
|
|
||||||
// Get screen dimensions (in device pixels)
|
CSSIntSize availScreenSize =
|
||||||
screen->GetAvailRect(&unused, &unused, &screenWidth, &screenHeight);
|
RoundedToInt(screen->GetAvailRect().Size() / cssScale);
|
||||||
// Convert them to CSS pixels
|
|
||||||
screenWidth = NSToIntRound(screenWidth / scale);
|
|
||||||
screenHeight = NSToIntRound(screenHeight / scale);
|
|
||||||
|
|
||||||
// Calculate the chrome UI size.
|
// Calculate the chrome UI size.
|
||||||
chromeWidth = winWidth - contentSize.width;
|
CSSIntSize chromeSize = cssWinRect.Size() - RoundedToInt(contentSize);
|
||||||
chromeHeight = winHeight - contentSize.height;
|
|
||||||
|
|
||||||
if (innerWidthSpecified || outerWidthSpecified) {
|
if (innerWidthSpecified || outerWidthSpecified) {
|
||||||
inputWidth = value;
|
inputWidth = value;
|
||||||
@@ -7577,9 +7561,10 @@ void nsGlobalWindowInner::SetReplaceableWindowCoord(
|
|||||||
}
|
}
|
||||||
|
|
||||||
nsContentUtils::CalcRoundedWindowSizeForResistingFingerprinting(
|
nsContentUtils::CalcRoundedWindowSizeForResistingFingerprinting(
|
||||||
chromeWidth, chromeHeight, screenWidth, screenHeight, inputWidth,
|
chromeSize.width, chromeSize.height, availScreenSize.width,
|
||||||
inputHeight, outerWidthSpecified, outerHeightSpecified,
|
availScreenSize.height, inputWidth, inputHeight,
|
||||||
targetContentWidth, targetContentHeight);
|
outerWidthSpecified, outerHeightSpecified, targetContentWidth,
|
||||||
|
targetContentHeight);
|
||||||
value = T(roundedValue);
|
value = T(roundedValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3429,56 +3429,20 @@ void nsGlobalWindowOuter::SetNameOuter(const nsAString& aName,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper functions used by many methods below.
|
// NOTE: The idea of this function is that it should return the same as
|
||||||
int32_t nsGlobalWindowOuter::DevToCSSIntPixelsForBaseWindow(
|
// nsPresContext::CSSToDeviceScale() if it was in aWindow synchronously. For
|
||||||
int32_t aDevicePixels, nsIBaseWindow* aWindow) {
|
// that, we use the UnscaledDevicePixelsPerCSSPixel() (which contains the device
|
||||||
|
// scale and the OS zoom scale) and then account for the browsing context full
|
||||||
|
// zoom. See the declaration of this function for context about why this is
|
||||||
|
// needed.
|
||||||
|
CSSToLayoutDeviceScale nsGlobalWindowOuter::CSSToDevScaleForBaseWindow(
|
||||||
|
nsIBaseWindow* aWindow) {
|
||||||
MOZ_ASSERT(aWindow);
|
MOZ_ASSERT(aWindow);
|
||||||
double scale;
|
auto scale = aWindow->UnscaledDevicePixelsPerCSSPixel();
|
||||||
aWindow->GetUnscaledDevicePixelsPerCSSPixel(&scale);
|
if (mBrowsingContext) {
|
||||||
double zoom = 1.0;
|
scale.scale *= mBrowsingContext->FullZoom();
|
||||||
if (mDocShell && mDocShell->GetPresContext()) {
|
|
||||||
zoom = mDocShell->GetPresContext()->GetFullZoom();
|
|
||||||
}
|
}
|
||||||
return std::floor(aDevicePixels / scale / zoom + 0.5);
|
return scale;
|
||||||
}
|
|
||||||
|
|
||||||
nsIntSize nsGlobalWindowOuter::DevToCSSIntPixelsForBaseWindow(
|
|
||||||
nsIntSize aDeviceSize, nsIBaseWindow* aWindow) {
|
|
||||||
MOZ_ASSERT(aWindow);
|
|
||||||
double scale;
|
|
||||||
aWindow->GetUnscaledDevicePixelsPerCSSPixel(&scale);
|
|
||||||
double zoom = 1.0;
|
|
||||||
if (mDocShell && mDocShell->GetPresContext()) {
|
|
||||||
zoom = mDocShell->GetPresContext()->GetFullZoom();
|
|
||||||
}
|
|
||||||
return nsIntSize::Round(
|
|
||||||
static_cast<float>(aDeviceSize.width / scale / zoom),
|
|
||||||
static_cast<float>(aDeviceSize.height / scale / zoom));
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t nsGlobalWindowOuter::CSSToDevIntPixelsForBaseWindow(
|
|
||||||
int32_t aCSSPixels, nsIBaseWindow* aWindow) {
|
|
||||||
MOZ_ASSERT(aWindow);
|
|
||||||
double scale;
|
|
||||||
aWindow->GetUnscaledDevicePixelsPerCSSPixel(&scale);
|
|
||||||
double zoom = 1.0;
|
|
||||||
if (mDocShell && mDocShell->GetPresContext()) {
|
|
||||||
zoom = mDocShell->GetPresContext()->GetFullZoom();
|
|
||||||
}
|
|
||||||
return std::floor(aCSSPixels * scale * zoom + 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsIntSize nsGlobalWindowOuter::CSSToDevIntPixelsForBaseWindow(
|
|
||||||
nsIntSize aCSSSize, nsIBaseWindow* aWindow) {
|
|
||||||
MOZ_ASSERT(aWindow);
|
|
||||||
double scale;
|
|
||||||
aWindow->GetUnscaledDevicePixelsPerCSSPixel(&scale);
|
|
||||||
double zoom = 1.0;
|
|
||||||
if (mDocShell && mDocShell->GetPresContext()) {
|
|
||||||
zoom = mDocShell->GetPresContext()->GetFullZoom();
|
|
||||||
}
|
|
||||||
return nsIntSize::Round(static_cast<float>(aCSSSize.width * scale * zoom),
|
|
||||||
static_cast<float>(aCSSSize.height * scale * zoom));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsGlobalWindowOuter::GetInnerSize(CSSSize& aSize) {
|
nsresult nsGlobalWindowOuter::GetInnerSize(CSSSize& aSize) {
|
||||||
@@ -3556,14 +3520,12 @@ void nsGlobalWindowOuter::SetInnerWidthOuter(double aInnerWidth,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nothing has been overriden, so change the docshell itself.
|
// Nothing has been overridden, so change the docshell itself.
|
||||||
int32_t height = 0;
|
|
||||||
int32_t unused = 0;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIBaseWindow> docShellAsWin(do_QueryInterface(mDocShell));
|
nsCOMPtr<nsIBaseWindow> docShellAsWin(do_QueryInterface(mDocShell));
|
||||||
docShellAsWin->GetSize(&unused, &height);
|
LayoutDeviceIntSize size = docShellAsWin->GetSize();
|
||||||
aError = SetDocShellWidthAndHeight(
|
size.width =
|
||||||
CSSToDevIntPixelsForBaseWindow(value, docShellAsWin), height);
|
(CSSCoord(value) * CSSToDevScaleForBaseWindow(docShellAsWin)).Rounded();
|
||||||
|
aError = SetDocShellSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
double nsGlobalWindowOuter::GetInnerHeightOuter(ErrorResult& aError) {
|
double nsGlobalWindowOuter::GetInnerHeightOuter(ErrorResult& aError) {
|
||||||
@@ -3603,21 +3565,19 @@ void nsGlobalWindowOuter::SetInnerHeightOuter(double aInnerHeight,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Nothing has been overriden, so change the docshell itself.
|
// Nothing has been overriden, so change the docshell itself.
|
||||||
int32_t height = 0;
|
|
||||||
int32_t width = 0;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIBaseWindow> docShellAsWin(do_QueryInterface(mDocShell));
|
nsCOMPtr<nsIBaseWindow> docShellAsWin(do_QueryInterface(mDocShell));
|
||||||
docShellAsWin->GetSize(&width, &height);
|
LayoutDeviceIntSize size = docShellAsWin->GetSize();
|
||||||
aError = SetDocShellWidthAndHeight(
|
size.height =
|
||||||
width, CSSToDevIntPixelsForBaseWindow(value, docShellAsWin));
|
(CSSCoord(value) * CSSToDevScaleForBaseWindow(docShellAsWin)).Rounded();
|
||||||
|
aError = SetDocShellSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsIntSize nsGlobalWindowOuter::GetOuterSize(CallerType aCallerType,
|
CSSIntSize nsGlobalWindowOuter::GetOuterSize(CallerType aCallerType,
|
||||||
ErrorResult& aError) {
|
ErrorResult& aError) {
|
||||||
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
||||||
CSSSize size;
|
CSSSize size;
|
||||||
aError = GetInnerSize(size);
|
aError = GetInnerSize(size);
|
||||||
return nsIntSize::Round(size.width, size.height);
|
return RoundedToInt(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Windows showing documents in RDM panes and any subframes within them
|
// Windows showing documents in RDM panes and any subframes within them
|
||||||
@@ -3625,24 +3585,18 @@ nsIntSize nsGlobalWindowOuter::GetOuterSize(CallerType aCallerType,
|
|||||||
if (mDoc) {
|
if (mDoc) {
|
||||||
Maybe<CSSIntSize> deviceSize = GetRDMDeviceSize(*mDoc);
|
Maybe<CSSIntSize> deviceSize = GetRDMDeviceSize(*mDoc);
|
||||||
if (deviceSize.isSome()) {
|
if (deviceSize.isSome()) {
|
||||||
const CSSIntSize& size = deviceSize.value();
|
return *deviceSize;
|
||||||
return nsIntSize(size.width, size.height);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin = GetTreeOwnerWindow();
|
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin = GetTreeOwnerWindow();
|
||||||
if (!treeOwnerAsWin) {
|
if (!treeOwnerAsWin) {
|
||||||
aError.Throw(NS_ERROR_FAILURE);
|
aError.Throw(NS_ERROR_FAILURE);
|
||||||
return nsIntSize(0, 0);
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
nsIntSize sizeDevPixels;
|
return RoundedToInt(treeOwnerAsWin->GetSize() /
|
||||||
aError = treeOwnerAsWin->GetSize(&sizeDevPixels.width, &sizeDevPixels.height);
|
CSSToDevScaleForBaseWindow(treeOwnerAsWin));
|
||||||
if (aError.Failed()) {
|
|
||||||
return nsIntSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
return DevToCSSIntPixelsForBaseWindow(sizeDevPixels, treeOwnerAsWin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t nsGlobalWindowOuter::GetOuterWidthOuter(CallerType aCallerType,
|
int32_t nsGlobalWindowOuter::GetOuterWidthOuter(CallerType aCallerType,
|
||||||
@@ -3668,20 +3622,11 @@ void nsGlobalWindowOuter::SetOuterSize(int32_t aLengthCSSPixels, bool aIsWidth,
|
|||||||
aIsWidth ? nullptr : &aLengthCSSPixels,
|
aIsWidth ? nullptr : &aLengthCSSPixels,
|
||||||
aCallerType);
|
aCallerType);
|
||||||
|
|
||||||
int32_t width, height;
|
LayoutDeviceIntSize size = treeOwnerAsWin->GetSize();
|
||||||
aError = treeOwnerAsWin->GetSize(&width, &height);
|
auto scale = CSSToDevScaleForBaseWindow(treeOwnerAsWin);
|
||||||
if (aError.Failed()) {
|
(aIsWidth ? size.width : size.height) =
|
||||||
return;
|
(CSSCoord(aLengthCSSPixels) * scale).Rounded();
|
||||||
}
|
aError = treeOwnerAsWin->SetSize(size.width, size.height, true);
|
||||||
|
|
||||||
int32_t lengthDevPixels =
|
|
||||||
CSSToDevIntPixelsForBaseWindow(aLengthCSSPixels, treeOwnerAsWin);
|
|
||||||
if (aIsWidth) {
|
|
||||||
width = lengthDevPixels;
|
|
||||||
} else {
|
|
||||||
height = lengthDevPixels;
|
|
||||||
}
|
|
||||||
aError = treeOwnerAsWin->SetSize(width, height, true);
|
|
||||||
|
|
||||||
CheckForDPIChange();
|
CheckForDPIChange();
|
||||||
}
|
}
|
||||||
@@ -3821,16 +3766,14 @@ void nsGlobalWindowOuter::SetScreenXOuter(int32_t aScreenX,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t x, y;
|
LayoutDeviceIntPoint pos = treeOwnerAsWin->GetPosition();
|
||||||
aError = treeOwnerAsWin->GetPosition(&x, &y);
|
|
||||||
if (aError.Failed()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckSecurityLeftAndTop(&aScreenX, nullptr, aCallerType);
|
CheckSecurityLeftAndTop(&aScreenX, nullptr, aCallerType);
|
||||||
x = CSSToDevIntPixelsForBaseWindow(aScreenX, treeOwnerAsWin);
|
|
||||||
|
|
||||||
aError = treeOwnerAsWin->SetPosition(x, y);
|
pos.x = (CSSCoord(aScreenX) * CSSToDevScaleForBaseWindow(treeOwnerAsWin))
|
||||||
|
.Rounded();
|
||||||
|
|
||||||
|
aError = treeOwnerAsWin->SetPosition(pos.x, pos.y);
|
||||||
|
|
||||||
CheckForDPIChange();
|
CheckForDPIChange();
|
||||||
}
|
}
|
||||||
@@ -3849,16 +3792,11 @@ void nsGlobalWindowOuter::SetScreenYOuter(int32_t aScreenY,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t x, y;
|
LayoutDeviceIntPoint pos = treeOwnerAsWin->GetPosition();
|
||||||
aError = treeOwnerAsWin->GetPosition(&x, &y);
|
|
||||||
if (aError.Failed()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckSecurityLeftAndTop(nullptr, &aScreenY, aCallerType);
|
CheckSecurityLeftAndTop(nullptr, &aScreenY, aCallerType);
|
||||||
y = CSSToDevIntPixelsForBaseWindow(aScreenY, treeOwnerAsWin);
|
pos.y = (CSSCoord(aScreenY) * CSSToDevScaleForBaseWindow(treeOwnerAsWin))
|
||||||
|
.Rounded();
|
||||||
aError = treeOwnerAsWin->SetPosition(x, y);
|
aError = treeOwnerAsWin->SetPosition(pos.x, pos.y);
|
||||||
|
|
||||||
CheckForDPIChange();
|
CheckForDPIChange();
|
||||||
}
|
}
|
||||||
@@ -3890,8 +3828,8 @@ void nsGlobalWindowOuter::CheckSecurityWidthAndHeight(int32_t* aWidth,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: Arguments to this function should have values in device pixels
|
// NOTE: Arguments to this function should have values in device pixels
|
||||||
nsresult nsGlobalWindowOuter::SetDocShellWidthAndHeight(int32_t aInnerWidth,
|
nsresult nsGlobalWindowOuter::SetDocShellSize(
|
||||||
int32_t aInnerHeight) {
|
const LayoutDeviceIntSize& aSize) {
|
||||||
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
||||||
|
|
||||||
nsCOMPtr<nsIDocShell> docShell = mDocShell;
|
nsCOMPtr<nsIDocShell> docShell = mDocShell;
|
||||||
@@ -3899,7 +3837,7 @@ nsresult nsGlobalWindowOuter::SetDocShellWidthAndHeight(int32_t aInnerWidth,
|
|||||||
docShell->GetTreeOwner(getter_AddRefs(treeOwner));
|
docShell->GetTreeOwner(getter_AddRefs(treeOwner));
|
||||||
NS_ENSURE_TRUE(treeOwner, NS_ERROR_FAILURE);
|
NS_ENSURE_TRUE(treeOwner, NS_ERROR_FAILURE);
|
||||||
|
|
||||||
NS_ENSURE_SUCCESS(treeOwner->SizeShellTo(docShell, aInnerWidth, aInnerHeight),
|
NS_ENSURE_SUCCESS(treeOwner->SizeShellTo(docShell, aSize.width, aSize.height),
|
||||||
NS_ERROR_FAILURE);
|
NS_ERROR_FAILURE);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
@@ -3944,18 +3882,9 @@ void nsGlobalWindowOuter::CheckSecurityLeftAndTop(int32_t* aLeft, int32_t* aTop,
|
|||||||
RefPtr<nsScreen> screen = GetScreen();
|
RefPtr<nsScreen> screen = GetScreen();
|
||||||
|
|
||||||
if (treeOwnerAsWin && screen) {
|
if (treeOwnerAsWin && screen) {
|
||||||
int32_t winLeft, winTop, winWidth, winHeight;
|
CSSToLayoutDeviceScale scale = CSSToDevScaleForBaseWindow(treeOwnerAsWin);
|
||||||
|
CSSIntRect winRect =
|
||||||
// Get the window size
|
CSSIntRect::Round(treeOwnerAsWin->GetPositionAndSize() / scale);
|
||||||
treeOwnerAsWin->GetPositionAndSize(&winLeft, &winTop, &winWidth,
|
|
||||||
&winHeight);
|
|
||||||
|
|
||||||
// convert those values to CSS pixels
|
|
||||||
// XXX four separate retrievals of the prescontext
|
|
||||||
winLeft = DevToCSSIntPixelsForBaseWindow(winLeft, treeOwnerAsWin);
|
|
||||||
winTop = DevToCSSIntPixelsForBaseWindow(winTop, treeOwnerAsWin);
|
|
||||||
winWidth = DevToCSSIntPixelsForBaseWindow(winWidth, treeOwnerAsWin);
|
|
||||||
winHeight = DevToCSSIntPixelsForBaseWindow(winHeight, treeOwnerAsWin);
|
|
||||||
|
|
||||||
// Get the screen dimensions
|
// Get the screen dimensions
|
||||||
// XXX This should use nsIScreenManager once it's fully fleshed out.
|
// XXX This should use nsIScreenManager once it's fully fleshed out.
|
||||||
@@ -3976,13 +3905,13 @@ void nsGlobalWindowOuter::CheckSecurityLeftAndTop(int32_t* aLeft, int32_t* aTop,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (aLeft) {
|
if (aLeft) {
|
||||||
if (screenLeft + screenWidth < *aLeft + winWidth)
|
if (screenLeft + screenWidth < *aLeft + winRect.width)
|
||||||
*aLeft = screenLeft + screenWidth - winWidth;
|
*aLeft = screenLeft + screenWidth - winRect.width;
|
||||||
if (screenLeft > *aLeft) *aLeft = screenLeft;
|
if (screenLeft > *aLeft) *aLeft = screenLeft;
|
||||||
}
|
}
|
||||||
if (aTop) {
|
if (aTop) {
|
||||||
if (screenTop + screenHeight < *aTop + winHeight)
|
if (screenTop + screenHeight < *aTop + winRect.height)
|
||||||
*aTop = screenTop + screenHeight - winHeight;
|
*aTop = screenTop + screenHeight - winRect.height;
|
||||||
if (screenTop > *aTop) *aTop = screenTop;
|
if (screenTop > *aTop) *aTop = screenTop;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -5414,18 +5343,16 @@ void nsGlobalWindowOuter::MoveByOuter(int32_t aXDif, int32_t aYDif,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// mild abuse of a "size" object so we don't need more helper functions
|
auto cssScale = CSSToDevScaleForBaseWindow(treeOwnerAsWin);
|
||||||
nsIntSize cssPos(
|
CSSIntPoint cssPos = RoundedToInt(treeOwnerAsWin->GetPosition() / cssScale);
|
||||||
DevToCSSIntPixelsForBaseWindow(nsIntSize(x, y), treeOwnerAsWin));
|
|
||||||
|
|
||||||
cssPos.width += aXDif;
|
cssPos.x += aXDif;
|
||||||
cssPos.height += aYDif;
|
cssPos.y += aYDif;
|
||||||
|
|
||||||
CheckSecurityLeftAndTop(&cssPos.width, &cssPos.height, aCallerType);
|
CheckSecurityLeftAndTop(&cssPos.x, &cssPos.y, aCallerType);
|
||||||
|
|
||||||
nsIntSize newDevPos(CSSToDevIntPixelsForBaseWindow(cssPos, treeOwnerAsWin));
|
LayoutDeviceIntPoint newDevPos = RoundedToInt(cssPos * cssScale);
|
||||||
|
aError = treeOwnerAsWin->SetPosition(newDevPos.x, newDevPos.y);
|
||||||
aError = treeOwnerAsWin->SetPosition(newDevPos.width, newDevPos.height);
|
|
||||||
|
|
||||||
CheckForDPIChange();
|
CheckForDPIChange();
|
||||||
}
|
}
|
||||||
@@ -5455,12 +5382,12 @@ void nsGlobalWindowOuter::ResizeToOuter(int32_t aWidth, int32_t aHeight,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsIntSize cssSize(aWidth, aHeight);
|
CSSIntSize cssSize(aWidth, aHeight);
|
||||||
CheckSecurityWidthAndHeight(&cssSize.width, &cssSize.height, aCallerType);
|
CheckSecurityWidthAndHeight(&cssSize.width, &cssSize.height, aCallerType);
|
||||||
|
|
||||||
nsIntSize devSz(CSSToDevIntPixelsForBaseWindow(cssSize, treeOwnerAsWin));
|
LayoutDeviceIntSize devSize =
|
||||||
|
RoundedToInt(cssSize * CSSToDevScaleForBaseWindow(treeOwnerAsWin));
|
||||||
aError = treeOwnerAsWin->SetSize(devSz.width, devSz.height, true);
|
aError = treeOwnerAsWin->SetSize(devSize.width, devSize.height, true);
|
||||||
|
|
||||||
CheckForDPIChange();
|
CheckForDPIChange();
|
||||||
}
|
}
|
||||||
@@ -5483,25 +5410,21 @@ void nsGlobalWindowOuter::ResizeByOuter(int32_t aWidthDif, int32_t aHeightDif,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t width, height;
|
LayoutDeviceIntSize size = treeOwnerAsWin->GetSize();
|
||||||
aError = treeOwnerAsWin->GetSize(&width, &height);
|
|
||||||
if (aError.Failed()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// To do this correctly we have to convert what we got from GetSize
|
// To do this correctly we have to convert what we got from GetSize
|
||||||
// into CSS pixels, add the arguments, do the security check, and
|
// into CSS pixels, add the arguments, do the security check, and
|
||||||
// then convert back to device pixels for the call to SetSize.
|
// then convert back to device pixels for the call to SetSize.
|
||||||
|
|
||||||
nsIntSize cssSize(
|
auto scale = CSSToDevScaleForBaseWindow(treeOwnerAsWin);
|
||||||
DevToCSSIntPixelsForBaseWindow(nsIntSize(width, height), treeOwnerAsWin));
|
CSSIntSize cssSize = RoundedToInt(size / scale);
|
||||||
|
|
||||||
cssSize.width += aWidthDif;
|
cssSize.width += aWidthDif;
|
||||||
cssSize.height += aHeightDif;
|
cssSize.height += aHeightDif;
|
||||||
|
|
||||||
CheckSecurityWidthAndHeight(&cssSize.width, &cssSize.height, aCallerType);
|
CheckSecurityWidthAndHeight(&cssSize.width, &cssSize.height, aCallerType);
|
||||||
|
|
||||||
nsIntSize newDevSize(CSSToDevIntPixelsForBaseWindow(cssSize, treeOwnerAsWin));
|
LayoutDeviceIntSize newDevSize = RoundedToInt(cssSize * scale);
|
||||||
|
|
||||||
aError = treeOwnerAsWin->SetSize(newDevSize.width, newDevSize.height, true);
|
aError = treeOwnerAsWin->SetSize(newDevSize.width, newDevSize.height, true);
|
||||||
|
|
||||||
|
|||||||
@@ -826,7 +826,7 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
|
|||||||
void SetCSSViewportWidthAndHeight(nscoord width, nscoord height);
|
void SetCSSViewportWidthAndHeight(nscoord width, nscoord height);
|
||||||
// Arguments to this function should have values in device pixels
|
// Arguments to this function should have values in device pixels
|
||||||
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
||||||
nsresult SetDocShellWidthAndHeight(int32_t width, int32_t height);
|
nsresult SetDocShellSize(const mozilla::LayoutDeviceIntSize& aInnerSize);
|
||||||
|
|
||||||
static bool CanSetProperty(const char* aPrefName);
|
static bool CanSetProperty(const char* aPrefName);
|
||||||
|
|
||||||
@@ -850,7 +850,7 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
|
|||||||
|
|
||||||
// Outer windows only.
|
// Outer windows only.
|
||||||
nsresult GetInnerSize(mozilla::CSSSize& aSize);
|
nsresult GetInnerSize(mozilla::CSSSize& aSize);
|
||||||
nsIntSize GetOuterSize(mozilla::dom::CallerType aCallerType,
|
mozilla::CSSIntSize GetOuterSize(mozilla::dom::CallerType aCallerType,
|
||||||
mozilla::ErrorResult& aError);
|
mozilla::ErrorResult& aError);
|
||||||
void SetOuterSize(int32_t aLengthCSSPixels, bool aIsWidth,
|
void SetOuterSize(int32_t aLengthCSSPixels, bool aIsWidth,
|
||||||
mozilla::dom::CallerType aCallerType,
|
mozilla::dom::CallerType aCallerType,
|
||||||
@@ -871,25 +871,14 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
|
|||||||
|
|
||||||
bool IsInModalState();
|
bool IsInModalState();
|
||||||
|
|
||||||
// Convenience functions for the many methods that need to scale
|
|
||||||
// from device to CSS pixels. This computes it with cached scale in
|
|
||||||
// PresContext which may be not recent information of the widget.
|
|
||||||
// Note: if PresContext is not available, they will assume a 1:1 ratio.
|
|
||||||
int32_t DevToCSSIntPixels(int32_t px);
|
|
||||||
nsIntSize DevToCSSIntPixels(nsIntSize px);
|
|
||||||
|
|
||||||
// Convenience functions for the methods which call methods of nsIBaseWindow
|
// Convenience functions for the methods which call methods of nsIBaseWindow
|
||||||
// because it takes/returns device pixels. Unfortunately, mPresContext may
|
// because it takes/returns device pixels. Unfortunately, mPresContext may
|
||||||
// have older scale value for the corresponding widget. Therefore, these
|
// have older scale value for the corresponding widget. Therefore, these
|
||||||
// helper methods convert between CSS pixels and device pixels with aWindow.
|
// helper methods convert between CSS pixels and device pixels with aWindow.
|
||||||
int32_t DevToCSSIntPixelsForBaseWindow(int32_t aDevicePixels,
|
//
|
||||||
nsIBaseWindow* aWindow);
|
// FIXME(emilio): Seems like updating the pres context dpi sync shouldn't be
|
||||||
nsIntSize DevToCSSIntPixelsForBaseWindow(nsIntSize aDeviceSize,
|
// all that much work and should avoid some hackiness?
|
||||||
nsIBaseWindow* aWindow);
|
mozilla::CSSToLayoutDeviceScale CSSToDevScaleForBaseWindow(nsIBaseWindow*);
|
||||||
int32_t CSSToDevIntPixelsForBaseWindow(int32_t aCSSPixels,
|
|
||||||
nsIBaseWindow* aWindow);
|
|
||||||
nsIntSize CSSToDevIntPixelsForBaseWindow(nsIntSize aCSSSize,
|
|
||||||
nsIBaseWindow* aWindow);
|
|
||||||
|
|
||||||
void SetFocusedElement(mozilla::dom::Element* aElement,
|
void SetFocusedElement(mozilla::dom::Element* aElement,
|
||||||
uint32_t aFocusMethod = 0,
|
uint32_t aFocusMethod = 0,
|
||||||
|
|||||||
@@ -1004,12 +1004,14 @@ mozilla::ipc::IPCResult BrowserParent::RecvSetDimensions(
|
|||||||
// We only care about the parameters that actually changed, see more details
|
// We only care about the parameters that actually changed, see more details
|
||||||
// in `BrowserChild::SetDimensions()`.
|
// in `BrowserChild::SetDimensions()`.
|
||||||
// Note that `BrowserChild::SetDimensions()` may be called before receiving
|
// Note that `BrowserChild::SetDimensions()` may be called before receiving
|
||||||
// our `SendUIResolutionChanged()` call. Therefore, if given each cordinate
|
// our `SendUIResolutionChanged()` call. Therefore, if given each coordinate
|
||||||
// shouldn't be ignored, we need to recompute it if DPI has been changed.
|
// shouldn't be ignored, we need to recompute it if DPI has been changed.
|
||||||
// And also note that don't use `mDefaultScale.scale` here since it may be
|
// And also note that don't use `mDefaultScale.scale` here since it may be
|
||||||
// different from the result of `GetUnscaledDevicePixelsPerCSSPixel()`.
|
// different from the result of `GetWidgetCSSToDeviceScale()`.
|
||||||
double currentScale;
|
// NOTE(emilio): We use GetWidgetCSSToDeviceScale() because the old scale is a
|
||||||
treeOwnerAsWin->GetUnscaledDevicePixelsPerCSSPixel(¤tScale);
|
// widget scale, and we only use the current scale to scale up/down the
|
||||||
|
// relevant values.
|
||||||
|
double currentScale = treeOwnerAsWin->GetWidgetCSSToDeviceScale();
|
||||||
|
|
||||||
int32_t x = aX;
|
int32_t x = aX;
|
||||||
int32_t y = aY;
|
int32_t y = aY;
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ void nsDeviceContext::SetDPI(double* aScale) {
|
|||||||
mAppUnitsPerDevPixelAtUnitFullZoom =
|
mAppUnitsPerDevPixelAtUnitFullZoom =
|
||||||
NS_lround((AppUnitsPerCSSPixel() * 96) / dpi);
|
NS_lround((AppUnitsPerCSSPixel() * 96) / dpi);
|
||||||
} else {
|
} else {
|
||||||
RefPtr<widget::Screen> primaryScreen =
|
RefPtr<const widget::Screen> primaryScreen =
|
||||||
ScreenManager::GetSingleton().GetPrimaryScreen();
|
ScreenManager::GetSingleton().GetPrimaryScreen();
|
||||||
MOZ_ASSERT(primaryScreen);
|
MOZ_ASSERT(primaryScreen);
|
||||||
|
|
||||||
@@ -109,12 +109,8 @@ void nsDeviceContext::SetDPI(double* aScale) {
|
|||||||
// the caller to pass to child contexts if needed
|
// the caller to pass to child contexts if needed
|
||||||
CSSToLayoutDeviceScale scale =
|
CSSToLayoutDeviceScale scale =
|
||||||
mWidget ? mWidget->GetDefaultScale() : CSSToLayoutDeviceScale(1.0);
|
mWidget ? mWidget->GetDefaultScale() : CSSToLayoutDeviceScale(1.0);
|
||||||
|
MOZ_ASSERT(scale.scale > 0.0);
|
||||||
devPixelsPerCSSPixel = scale.scale;
|
devPixelsPerCSSPixel = scale.scale;
|
||||||
// In case that the widget returns -1, use the primary screen's
|
|
||||||
// value as default.
|
|
||||||
if (devPixelsPerCSSPixel < 0) {
|
|
||||||
primaryScreen->GetDefaultCSSScaleFactor(&devPixelsPerCSSPixel);
|
|
||||||
}
|
|
||||||
if (aScale) {
|
if (aScale) {
|
||||||
*aScale = devPixelsPerCSSPixel;
|
*aScale = devPixelsPerCSSPixel;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -860,10 +860,8 @@ nsWebBrowser::Destroy() {
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
double nsWebBrowser::GetWidgetCSSToDeviceScale() {
|
||||||
nsWebBrowser::GetUnscaledDevicePixelsPerCSSPixel(double* aScale) {
|
return mParentWidget ? mParentWidget->GetDefaultScale().scale : 1.0;
|
||||||
*aScale = mParentWidget ? mParentWidget->GetDefaultScale().scale : 1.0;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|||||||
@@ -539,7 +539,7 @@ nsWindowWatcher::OpenWindowWithRemoteTab(nsIRemoteTab* aRemoteTab,
|
|||||||
// get various interfaces for aDocShellItem, used throughout this method
|
// get various interfaces for aDocShellItem, used throughout this method
|
||||||
CSSToDesktopScale cssToDesktopScale(1.0f);
|
CSSToDesktopScale cssToDesktopScale(1.0f);
|
||||||
if (nsCOMPtr<nsIBaseWindow> win = do_QueryInterface(parentTreeOwner)) {
|
if (nsCOMPtr<nsIBaseWindow> win = do_QueryInterface(parentTreeOwner)) {
|
||||||
cssToDesktopScale = win->GetCSSToDesktopScale();
|
cssToDesktopScale = win->GetUnscaledCSSToDesktopScale();
|
||||||
}
|
}
|
||||||
SizeSpec sizeSpec = CalcSizeSpec(features, false, cssToDesktopScale);
|
SizeSpec sizeSpec = CalcSizeSpec(features, false, cssToDesktopScale);
|
||||||
sizeSpec.ScaleBy(aOpenerFullZoom);
|
sizeSpec.ScaleBy(aOpenerFullZoom);
|
||||||
@@ -723,7 +723,7 @@ nsresult nsWindowWatcher::OpenWindowInternal(
|
|||||||
|
|
||||||
CSSToDesktopScale cssToDesktopScale(1.0);
|
CSSToDesktopScale cssToDesktopScale(1.0);
|
||||||
if (nsCOMPtr<nsIBaseWindow> win = do_QueryInterface(parentDocShell)) {
|
if (nsCOMPtr<nsIBaseWindow> win = do_QueryInterface(parentDocShell)) {
|
||||||
cssToDesktopScale = win->GetCSSToDesktopScale();
|
cssToDesktopScale = win->GetUnscaledCSSToDesktopScale();
|
||||||
}
|
}
|
||||||
SizeSpec sizeSpec =
|
SizeSpec sizeSpec =
|
||||||
CalcSizeSpec(features, hasChromeParent, cssToDesktopScale);
|
CalcSizeSpec(features, hasChromeParent, cssToDesktopScale);
|
||||||
@@ -2209,9 +2209,7 @@ static void SizeOpenedWindow(nsIDocShellTreeOwner* aTreeOwner,
|
|||||||
DesktopToLayoutDeviceScale devToDesktopScale =
|
DesktopToLayoutDeviceScale devToDesktopScale =
|
||||||
treeOwnerAsWin->DevicePixelsPerDesktopPixel();
|
treeOwnerAsWin->DevicePixelsPerDesktopPixel();
|
||||||
|
|
||||||
LayoutDeviceIntRect devPxRect;
|
LayoutDeviceIntRect devPxRect = treeOwnerAsWin->GetPositionAndSize();
|
||||||
treeOwnerAsWin->GetPositionAndSize(&devPxRect.x, &devPxRect.y,
|
|
||||||
&devPxRect.width, &devPxRect.height);
|
|
||||||
width = (LayoutDeviceCoord(devPxRect.width) / cssToDevScale).Rounded();
|
width = (LayoutDeviceCoord(devPxRect.width) / cssToDevScale).Rounded();
|
||||||
height = (LayoutDeviceCoord(devPxRect.height) / cssToDevScale).Rounded();
|
height = (LayoutDeviceCoord(devPxRect.height) / cssToDevScale).Rounded();
|
||||||
left = (LayoutDeviceCoord(devPxRect.x) / devToDesktopScale).Rounded();
|
left = (LayoutDeviceCoord(devPxRect.x) / devToDesktopScale).Rounded();
|
||||||
@@ -2287,7 +2285,8 @@ static void SizeOpenedWindow(nsIDocShellTreeOwner* aTreeOwner,
|
|||||||
CSSIntCoord winWidth = width + extraWidth;
|
CSSIntCoord winWidth = width + extraWidth;
|
||||||
CSSIntCoord winHeight = height + extraHeight;
|
CSSIntCoord winHeight = height + extraHeight;
|
||||||
|
|
||||||
const auto screenCssToDesktopScale = screen->GetCSSToDesktopScale();
|
auto screenCssToDesktopScale = screen->GetCSSToDesktopScale();
|
||||||
|
|
||||||
const DesktopIntRect screenDesktopRect = screen->GetAvailRectDisplayPix();
|
const DesktopIntRect screenDesktopRect = screen->GetAvailRectDisplayPix();
|
||||||
// Get screen dimensions (in CSS pixels)
|
// Get screen dimensions (in CSS pixels)
|
||||||
const CSSSize screenCssSize =
|
const CSSSize screenCssSize =
|
||||||
|
|||||||
@@ -81,9 +81,6 @@ NS_IMPL_ISUPPORTS_INHERITED(PuppetWidget, nsBaseWidget,
|
|||||||
PuppetWidget::PuppetWidget(BrowserChild* aBrowserChild)
|
PuppetWidget::PuppetWidget(BrowserChild* aBrowserChild)
|
||||||
: mBrowserChild(aBrowserChild),
|
: mBrowserChild(aBrowserChild),
|
||||||
mMemoryPressureObserver(nullptr),
|
mMemoryPressureObserver(nullptr),
|
||||||
mDPI(-1),
|
|
||||||
mRounding(1),
|
|
||||||
mDefaultScale(-1),
|
|
||||||
mEnabled(false),
|
mEnabled(false),
|
||||||
mVisible(false),
|
mVisible(false),
|
||||||
mSizeMode(nsSizeMode_Normal),
|
mSizeMode(nsSizeMode_Normal),
|
||||||
@@ -1009,12 +1006,6 @@ bool PuppetWidget::NeedsPaint() {
|
|||||||
return mVisible;
|
return mVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
float PuppetWidget::GetDPI() { return mDPI; }
|
|
||||||
|
|
||||||
double PuppetWidget::GetDefaultScaleInternal() { return mDefaultScale; }
|
|
||||||
|
|
||||||
int32_t PuppetWidget::RoundsWidgetCoordinatesTo() { return mRounding; }
|
|
||||||
|
|
||||||
LayoutDeviceIntPoint PuppetWidget::GetChromeOffset() {
|
LayoutDeviceIntPoint PuppetWidget::GetChromeOffset() {
|
||||||
if (!GetOwningBrowserChild()) {
|
if (!GetOwningBrowserChild()) {
|
||||||
NS_WARNING("PuppetWidget without Tab does not have chrome information.");
|
NS_WARNING("PuppetWidget without Tab does not have chrome information.");
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ class PuppetWidget : public nsBaseWidget,
|
|||||||
return GetWindowPosition();
|
return GetWindowPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t RoundsWidgetCoordinatesTo() override;
|
int32_t RoundsWidgetCoordinatesTo() override { return mRounding; }
|
||||||
|
|
||||||
void InitEvent(WidgetGUIEvent& aEvent,
|
void InitEvent(WidgetGUIEvent& aEvent,
|
||||||
LayoutDeviceIntPoint* aPoint = nullptr);
|
LayoutDeviceIntPoint* aPoint = nullptr);
|
||||||
@@ -201,12 +201,8 @@ class PuppetWidget : public nsBaseWidget,
|
|||||||
|
|
||||||
virtual void SetCursor(const Cursor&) override;
|
virtual void SetCursor(const Cursor&) override;
|
||||||
|
|
||||||
// Gets the DPI of the screen corresponding to this widget.
|
float GetDPI() override { return mDPI; }
|
||||||
// Contacts the parent process which gets the DPI from the
|
double GetDefaultScaleInternal() override { return mDefaultScale; }
|
||||||
// proper widget there. TODO: Handle DPI changes that happen
|
|
||||||
// later on.
|
|
||||||
virtual float GetDPI() override;
|
|
||||||
virtual double GetDefaultScaleInternal() override;
|
|
||||||
|
|
||||||
virtual bool NeedsPaint() override;
|
virtual bool NeedsPaint() override;
|
||||||
|
|
||||||
@@ -385,10 +381,10 @@ class PuppetWidget : public nsBaseWidget,
|
|||||||
NativeIMEContext mNativeIMEContext;
|
NativeIMEContext mNativeIMEContext;
|
||||||
ContentCacheInChild mContentCache;
|
ContentCacheInChild mContentCache;
|
||||||
|
|
||||||
// The DPI of the screen corresponding to this widget
|
// The DPI of the parent widget containing this widget.
|
||||||
float mDPI;
|
float mDPI = 96;
|
||||||
int32_t mRounding;
|
int32_t mRounding = 1;
|
||||||
double mDefaultScale;
|
double mDefaultScale = 1.0f;
|
||||||
|
|
||||||
ScreenIntMargin mSafeAreaInsets;
|
ScreenIntMargin mSafeAreaInsets;
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "mozilla/dom/DOMTypes.h"
|
#include "mozilla/dom/DOMTypes.h"
|
||||||
#include "mozilla/Hal.h"
|
#include "mozilla/Hal.h"
|
||||||
|
#include "mozilla/LookAndFeel.h"
|
||||||
#include "mozilla/StaticPrefs_layout.h"
|
#include "mozilla/StaticPrefs_layout.h"
|
||||||
|
|
||||||
namespace mozilla::widget {
|
namespace mozilla::widget {
|
||||||
@@ -136,6 +137,7 @@ Screen::GetDefaultCSSScaleFactor(double* aOutScale) {
|
|||||||
} else {
|
} else {
|
||||||
*aOutScale = mDefaultCssScale.scale;
|
*aOutScale = mDefaultCssScale.scale;
|
||||||
}
|
}
|
||||||
|
*aOutScale *= LookAndFeel::SystemZoomSettings().mFullZoom;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,9 +50,6 @@ class Screen final : public nsIScreen {
|
|||||||
const DesktopToLayoutDeviceScale& GetContentsScaleFactor() const {
|
const DesktopToLayoutDeviceScale& GetContentsScaleFactor() const {
|
||||||
return mContentsScale;
|
return mContentsScale;
|
||||||
}
|
}
|
||||||
const CSSToLayoutDeviceScale& GetDefaultCSSScaleFactor() const {
|
|
||||||
return mDefaultCssScale;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual ~Screen() = default;
|
virtual ~Screen() = default;
|
||||||
|
|||||||
@@ -225,6 +225,7 @@ UNIFIED_SOURCES += [
|
|||||||
"nsDragServiceProxy.cpp",
|
"nsDragServiceProxy.cpp",
|
||||||
"nsFilePickerProxy.cpp",
|
"nsFilePickerProxy.cpp",
|
||||||
"nsHTMLFormatConverter.cpp",
|
"nsHTMLFormatConverter.cpp",
|
||||||
|
"nsIBaseWindow.cpp",
|
||||||
"nsIDeviceContextSpec.cpp",
|
"nsIDeviceContextSpec.cpp",
|
||||||
"nsIWidgetListener.cpp",
|
"nsIWidgetListener.cpp",
|
||||||
"nsPrimitiveHelpers.cpp",
|
"nsPrimitiveHelpers.cpp",
|
||||||
|
|||||||
14
widget/nsIBaseWindow.cpp
Normal file
14
widget/nsIBaseWindow.cpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "nsIBaseWindow.h"
|
||||||
|
#include "mozilla/LookAndFeel.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
|
CSSToLayoutDeviceScale nsIBaseWindow::UnscaledDevicePixelsPerCSSPixel() {
|
||||||
|
return CSSToLayoutDeviceScale(GetWidgetCSSToDeviceScale() *
|
||||||
|
LookAndFeel::SystemZoomSettings().mFullZoom);
|
||||||
|
}
|
||||||
@@ -93,6 +93,14 @@ interface nsIBaseWindow : nsISupports
|
|||||||
*/
|
*/
|
||||||
void getPosition(out long x, out long y);
|
void getPosition(out long x, out long y);
|
||||||
|
|
||||||
|
%{C++
|
||||||
|
mozilla::LayoutDeviceIntPoint GetPosition() {
|
||||||
|
int32_t x = 0, y = 0;
|
||||||
|
GetPosition(&x, &y);
|
||||||
|
return mozilla::LayoutDeviceIntPoint(x, y);
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Sets the width and height of the control.
|
Sets the width and height of the control.
|
||||||
*/
|
*/
|
||||||
@@ -103,6 +111,14 @@ interface nsIBaseWindow : nsISupports
|
|||||||
*/
|
*/
|
||||||
void getSize(out long cx, out long cy);
|
void getSize(out long cx, out long cy);
|
||||||
|
|
||||||
|
%{C++
|
||||||
|
mozilla::LayoutDeviceIntSize GetSize() {
|
||||||
|
int32_t w = 0, h = 0;
|
||||||
|
GetSize(&w, &h);
|
||||||
|
return mozilla::LayoutDeviceIntSize(w, h);
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 'flags' argument to setPositionAndSize is a set of these bits.
|
* The 'flags' argument to setPositionAndSize is a set of these bits.
|
||||||
*/
|
*/
|
||||||
@@ -122,6 +138,14 @@ interface nsIBaseWindow : nsISupports
|
|||||||
*/
|
*/
|
||||||
void getPositionAndSize(out long x, out long y, out long cx, out long cy);
|
void getPositionAndSize(out long x, out long y, out long cx, out long cy);
|
||||||
|
|
||||||
|
%{C++
|
||||||
|
mozilla::LayoutDeviceIntRect GetPositionAndSize() {
|
||||||
|
int32_t x = 0, y = 0, w = 0, h = 0;
|
||||||
|
GetPositionAndSize(&x, &y, &w, &h);
|
||||||
|
return mozilla::LayoutDeviceIntRect(x, y, w, h);
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell the window to repaint itself
|
* Tell the window to repaint itself
|
||||||
* @param aForce - if true, repaint immediately
|
* @param aForce - if true, repaint immediately
|
||||||
@@ -186,20 +210,23 @@ interface nsIBaseWindow : nsISupports
|
|||||||
[noscript] readonly attribute nsIWidget mainWidget;
|
[noscript] readonly attribute nsIWidget mainWidget;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The number of device pixels per CSS pixel used on this window's current
|
The number of device pixels per CSS pixel used by this window's widget at the
|
||||||
screen at the default zoom level.
|
default full zoom level.
|
||||||
This is the value returned by GetDefaultScale() of the underlying widget.
|
This is the value returned by GetDefaultScale() of the underlying widget.
|
||||||
Note that this may change if the window is moved between screens with
|
Note that this may change if the window is moved between screens with
|
||||||
differing resolutions.
|
differing resolutions.
|
||||||
|
NOTE: This is mostly an implementation detail of
|
||||||
|
UnscaledDevicePixelsPerCSSPixel, which is what you probably want to use.
|
||||||
*/
|
*/
|
||||||
readonly attribute double unscaledDevicePixelsPerCSSPixel;
|
[noscript, notxpcom, nostdcall] readonly attribute double widgetCSSToDeviceScale;
|
||||||
|
|
||||||
%{C++
|
%{C++
|
||||||
mozilla::CSSToLayoutDeviceScale UnscaledDevicePixelsPerCSSPixel() {
|
// The number of device pixels per CSS pixel used on this window's current
|
||||||
double s = 1.0;
|
// screen at the default full zoom level.
|
||||||
GetUnscaledDevicePixelsPerCSSPixel(&s);
|
//
|
||||||
return mozilla::CSSToLayoutDeviceScale(s);
|
// This is the widget scale _plus_ the OS zoom scale if appropriate.
|
||||||
}
|
// Implemented in AppWindow.cpp
|
||||||
|
mozilla::CSSToLayoutDeviceScale UnscaledDevicePixelsPerCSSPixel();
|
||||||
%}
|
%}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -223,7 +250,7 @@ interface nsIBaseWindow : nsISupports
|
|||||||
return mozilla::DesktopToLayoutDeviceScale(s);
|
return mozilla::DesktopToLayoutDeviceScale(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
mozilla::CSSToDesktopScale GetCSSToDesktopScale() {
|
mozilla::CSSToDesktopScale GetUnscaledCSSToDesktopScale() {
|
||||||
return UnscaledDevicePixelsPerCSSPixel() / DevicePixelsPerDesktopPixel();
|
return UnscaledDevicePixelsPerCSSPixel() / DevicePixelsPerDesktopPixel();
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|||||||
@@ -244,17 +244,10 @@ LRESULT StatusBarEntry::OnMessage(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
|
|||||||
return DefWindowProc(hWnd, msg, wp, lp);
|
return DefWindowProc(hWnd, msg, wp, lp);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDocShell> docShell = popupFrame->PresContext()->GetDocShell();
|
nsPresContext* pc = popupFrame->PresContext();
|
||||||
nsCOMPtr<nsIBaseWindow> baseWin = do_QueryInterface(docShell);
|
const CSSIntPoint point = gfx::RoundedToInt(
|
||||||
MOZ_DIAGNOSTIC_ASSERT(baseWin);
|
LayoutDeviceIntPoint(GET_X_LPARAM(wp), GET_Y_LPARAM(wp)) /
|
||||||
if (!baseWin) {
|
pc->CSSToDevPixelScale());
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
double scale = 1.0;
|
|
||||||
baseWin->GetUnscaledDevicePixelsPerCSSPixel(&scale);
|
|
||||||
int32_t x = NSToIntRound(GET_X_LPARAM(wp) / scale);
|
|
||||||
int32_t y = NSToIntRound(GET_Y_LPARAM(wp) / scale);
|
|
||||||
|
|
||||||
// The menu that is being opened is a Gecko <xul:menu>, and the popup code
|
// The menu that is being opened is a Gecko <xul:menu>, and the popup code
|
||||||
// that manages it expects that the window that the <xul:menu> belongs to
|
// that manages it expects that the window that the <xul:menu> belongs to
|
||||||
@@ -265,7 +258,8 @@ LRESULT StatusBarEntry::OnMessage(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
|
|||||||
// focuses any window in the parent process).
|
// focuses any window in the parent process).
|
||||||
::SetForegroundWindow(win);
|
::SetForegroundWindow(win);
|
||||||
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
||||||
pm->ShowPopupAtScreen(popupFrame->GetContent(), x, y, false, nullptr);
|
pm->ShowPopupAtScreen(popupFrame->GetContent(), point.x, point.y, false,
|
||||||
|
nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return DefWindowProc(hWnd, msg, wp, lp);
|
return DefWindowProc(hWnd, msg, wp, lp);
|
||||||
|
|||||||
@@ -180,31 +180,22 @@ nsresult AppWindow::Initialize(nsIAppWindow* aParent, nsIAppWindow* aOpener,
|
|||||||
|
|
||||||
mIsHiddenWindow = aIsHiddenWindow;
|
mIsHiddenWindow = aIsHiddenWindow;
|
||||||
|
|
||||||
int32_t initialX = 0, initialY = 0;
|
DesktopIntPoint initialPos;
|
||||||
nsCOMPtr<nsIBaseWindow> base(do_QueryInterface(aOpener));
|
nsCOMPtr<nsIBaseWindow> base(do_QueryInterface(aOpener));
|
||||||
if (base) {
|
if (base) {
|
||||||
int32_t x, y, width, height;
|
LayoutDeviceIntRect rect = base->GetPositionAndSize();
|
||||||
rv = base->GetPositionAndSize(&x, &y, &width, &height);
|
mOpenerScreenRect =
|
||||||
if (NS_FAILED(rv)) {
|
DesktopIntRect::Round(rect / base->DevicePixelsPerDesktopPixel());
|
||||||
mOpenerScreenRect.SetEmpty();
|
if (!mOpenerScreenRect.IsEmpty()) {
|
||||||
} else {
|
initialPos = mOpenerScreenRect.TopLeft();
|
||||||
double scale;
|
ConstrainToOpenerScreen(&initialPos.x, &initialPos.y);
|
||||||
if (NS_SUCCEEDED(base->GetUnscaledDevicePixelsPerCSSPixel(&scale))) {
|
|
||||||
mOpenerScreenRect.SetRect(
|
|
||||||
NSToIntRound(x / scale), NSToIntRound(y / scale),
|
|
||||||
NSToIntRound(width / scale), NSToIntRound(height / scale));
|
|
||||||
} else {
|
|
||||||
mOpenerScreenRect.SetRect(x, y, width, height);
|
|
||||||
}
|
|
||||||
initialX = mOpenerScreenRect.X();
|
|
||||||
initialY = mOpenerScreenRect.Y();
|
|
||||||
ConstrainToOpenerScreen(&initialX, &initialY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: need to get the default window size from prefs...
|
// XXX: need to get the default window size from prefs...
|
||||||
// Doesn't come from prefs... will come from CSS/XUL/RDF
|
// Doesn't come from prefs... will come from CSS/XUL/RDF
|
||||||
DesktopIntRect deskRect(initialX, initialY, aInitialWidth, aInitialHeight);
|
DesktopIntRect deskRect(initialPos,
|
||||||
|
DesktopIntSize(aInitialWidth, aInitialHeight));
|
||||||
|
|
||||||
// Create top level window
|
// Create top level window
|
||||||
if (gfxPlatform::IsHeadless()) {
|
if (gfxPlatform::IsHeadless()) {
|
||||||
@@ -688,9 +679,8 @@ NS_IMETHODIMP AppWindow::GetDevicePixelsPerDesktopPixel(double* aScale) {
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP AppWindow::GetUnscaledDevicePixelsPerCSSPixel(double* aScale) {
|
double AppWindow::GetWidgetCSSToDeviceScale() {
|
||||||
*aScale = mWindow ? mWindow->GetDefaultScale().scale : 1.0;
|
return mWindow ? mWindow->GetDefaultScale().scale : 1.0;
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP AppWindow::SetPositionDesktopPix(int32_t aX, int32_t aY) {
|
NS_IMETHODIMP AppWindow::SetPositionDesktopPix(int32_t aX, int32_t aY) {
|
||||||
@@ -853,11 +843,7 @@ NS_IMETHODIMP AppWindow::Center(nsIAppWindow* aRelative, bool aScreen,
|
|||||||
}
|
}
|
||||||
if (!aRelative) {
|
if (!aRelative) {
|
||||||
if (!mOpenerScreenRect.IsEmpty()) {
|
if (!mOpenerScreenRect.IsEmpty()) {
|
||||||
// FIXME - check if these are device or display pixels
|
screen = screenmgr->ScreenForRect(mOpenerScreenRect);
|
||||||
screenmgr->ScreenForRect(mOpenerScreenRect.X(), mOpenerScreenRect.Y(),
|
|
||||||
mOpenerScreenRect.Width(),
|
|
||||||
mOpenerScreenRect.Height(),
|
|
||||||
getter_AddRefs(screen));
|
|
||||||
} else {
|
} else {
|
||||||
screenmgr->GetPrimaryScreen(getter_AddRefs(screen));
|
screenmgr->GetPrimaryScreen(getter_AddRefs(screen));
|
||||||
}
|
}
|
||||||
@@ -1028,9 +1014,7 @@ NS_IMETHODIMP AppWindow::SetEnabled(bool aEnable) {
|
|||||||
|
|
||||||
NS_IMETHODIMP AppWindow::GetMainWidget(nsIWidget** aMainWidget) {
|
NS_IMETHODIMP AppWindow::GetMainWidget(nsIWidget** aMainWidget) {
|
||||||
NS_ENSURE_ARG_POINTER(aMainWidget);
|
NS_ENSURE_ARG_POINTER(aMainWidget);
|
||||||
|
NS_IF_ADDREF(*aMainWidget = mWindow);
|
||||||
*aMainWidget = mWindow;
|
|
||||||
NS_IF_ADDREF(*aMainWidget);
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1146,9 +1130,7 @@ NS_IMETHODIMP AppWindow::ForceRoundedDimensions() {
|
|||||||
int32_t contentHeightCSS = 0;
|
int32_t contentHeightCSS = 0;
|
||||||
int32_t windowWidthCSS = 0;
|
int32_t windowWidthCSS = 0;
|
||||||
int32_t windowHeightCSS = 0;
|
int32_t windowHeightCSS = 0;
|
||||||
double devicePerCSSPixels = 1.0;
|
double devicePerCSSPixels = UnscaledDevicePixelsPerCSSPixel().scale;
|
||||||
|
|
||||||
GetUnscaledDevicePixelsPerCSSPixel(&devicePerCSSPixels);
|
|
||||||
|
|
||||||
GetAvailScreenSize(&availWidthCSS, &availHeightCSS);
|
GetAvailScreenSize(&availWidthCSS, &availHeightCSS);
|
||||||
|
|
||||||
@@ -1384,7 +1366,10 @@ bool AppWindow::LoadSizeFromXUL(int32_t& aSpecWidth, int32_t& aSpecHeight) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AppWindow::SetSpecifiedSize(int32_t aSpecWidth, int32_t aSpecHeight) {
|
void AppWindow::SetSpecifiedSize(int32_t aSpecWidth, int32_t aSpecHeight) {
|
||||||
// constrain to screen size
|
// These are in CSS pixels of the main window.
|
||||||
|
// TODO(emilio): In my testing we usually have a pres context around, can we
|
||||||
|
// just use it? That'd simplify the coordinate calculations.
|
||||||
|
{
|
||||||
int32_t screenWidth;
|
int32_t screenWidth;
|
||||||
int32_t screenHeight;
|
int32_t screenHeight;
|
||||||
|
|
||||||
@@ -1396,20 +1381,17 @@ void AppWindow::SetSpecifiedSize(int32_t aSpecWidth, int32_t aSpecHeight) {
|
|||||||
aSpecHeight = screenHeight;
|
aSpecHeight = screenHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NS_ASSERTION(mWindow, "we expected to have a window already");
|
NS_ASSERTION(mWindow, "we expected to have a window already");
|
||||||
|
|
||||||
int32_t currWidth = 0;
|
|
||||||
int32_t currHeight = 0;
|
|
||||||
GetSize(&currWidth, &currHeight); // returns device pixels
|
|
||||||
|
|
||||||
// convert specified values to device pixels, and resize if needed
|
|
||||||
double cssToDevPx = mWindow ? mWindow->GetDefaultScale().scale : 1.0;
|
|
||||||
aSpecWidth = NSToIntRound(aSpecWidth * cssToDevPx);
|
|
||||||
aSpecHeight = NSToIntRound(aSpecHeight * cssToDevPx);
|
|
||||||
mIntrinsicallySized = false;
|
mIntrinsicallySized = false;
|
||||||
if (aSpecWidth != currWidth || aSpecHeight != currHeight) {
|
|
||||||
SetSize(aSpecWidth, aSpecHeight, false);
|
// Convert specified values to device pixels, and resize if needed
|
||||||
|
auto newSize = RoundedToInt(CSSIntSize(aSpecWidth, aSpecHeight) *
|
||||||
|
UnscaledDevicePixelsPerCSSPixel());
|
||||||
|
if (newSize != nsIBaseWindow::GetSize()) {
|
||||||
|
SetSize(newSize.width, newSize.height, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1516,10 +1498,7 @@ void AppWindow::StaggerPosition(int32_t& aRequestedX, int32_t& aRequestedY,
|
|||||||
nsAutoString windowType;
|
nsAutoString windowType;
|
||||||
windowElement->GetAttribute(WINDOWTYPE_ATTRIBUTE, windowType);
|
windowElement->GetAttribute(WINDOWTYPE_ATTRIBUTE, windowType);
|
||||||
|
|
||||||
int32_t screenTop = 0, // it's pointless to initialize these ...
|
DesktopIntRect screenRect;
|
||||||
screenRight = 0, // ... but to prevent oversalubrious and ...
|
|
||||||
screenBottom = 0, // ... underbright compilers from ...
|
|
||||||
screenLeft = 0; // ... issuing warnings.
|
|
||||||
bool gotScreen = false;
|
bool gotScreen = false;
|
||||||
|
|
||||||
{ // fetch screen coordinates
|
{ // fetch screen coordinates
|
||||||
@@ -1527,26 +1506,21 @@ void AppWindow::StaggerPosition(int32_t& aRequestedX, int32_t& aRequestedY,
|
|||||||
do_GetService("@mozilla.org/gfx/screenmanager;1"));
|
do_GetService("@mozilla.org/gfx/screenmanager;1"));
|
||||||
if (screenMgr) {
|
if (screenMgr) {
|
||||||
nsCOMPtr<nsIScreen> ourScreen;
|
nsCOMPtr<nsIScreen> ourScreen;
|
||||||
// the coordinates here are already display pixels
|
// The coordinates here are already display pixels
|
||||||
|
// XXX aSpecWidth and aSpecHeight are CSS pixels!
|
||||||
screenMgr->ScreenForRect(aRequestedX, aRequestedY, aSpecWidth,
|
screenMgr->ScreenForRect(aRequestedX, aRequestedY, aSpecWidth,
|
||||||
aSpecHeight, getter_AddRefs(ourScreen));
|
aSpecHeight, getter_AddRefs(ourScreen));
|
||||||
if (ourScreen) {
|
if (ourScreen) {
|
||||||
int32_t screenWidth, screenHeight;
|
screenRect = ourScreen->GetAvailRectDisplayPix();
|
||||||
ourScreen->GetAvailRectDisplayPix(&screenLeft, &screenTop, &screenWidth,
|
|
||||||
&screenHeight);
|
|
||||||
screenBottom = screenTop + screenHeight;
|
|
||||||
screenRight = screenLeft + screenWidth;
|
|
||||||
// Get the screen's scaling factors and convert staggering constants
|
// Get the screen's scaling factors and convert staggering constants
|
||||||
// from CSS px to desktop pixel units
|
// from CSS px to desktop pixel units
|
||||||
double desktopToDeviceScale = 1.0, cssToDeviceScale = 1.0;
|
auto scale = ourScreen->GetCSSToDesktopScale();
|
||||||
ourScreen->GetContentsScaleFactor(&desktopToDeviceScale);
|
kOffset = (CSSCoord(kOffset) * scale).Rounded();
|
||||||
ourScreen->GetDefaultCSSScaleFactor(&cssToDeviceScale);
|
kSlop = (CSSCoord(kSlop) * scale).Rounded();
|
||||||
double cssToDesktopFactor = cssToDeviceScale / desktopToDeviceScale;
|
|
||||||
kOffset = NSToIntRound(kOffset * cssToDesktopFactor);
|
|
||||||
kSlop = NSToIntRound(kSlop * cssToDesktopFactor);
|
|
||||||
// Convert dimensions from CSS to desktop pixels
|
// Convert dimensions from CSS to desktop pixels
|
||||||
aSpecWidth = NSToIntRound(aSpecWidth * cssToDesktopFactor);
|
aSpecWidth = (CSSCoord(aSpecWidth) * scale).Rounded();
|
||||||
aSpecHeight = NSToIntRound(aSpecHeight * cssToDesktopFactor);
|
aSpecHeight = (CSSCoord(aSpecHeight) * scale).Rounded();
|
||||||
gotScreen = true;
|
gotScreen = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1595,20 +1569,20 @@ void AppWindow::StaggerPosition(int32_t& aRequestedX, int32_t& aRequestedY,
|
|||||||
if (gotScreen) {
|
if (gotScreen) {
|
||||||
// if we're moving to the right and we need to bounce...
|
// if we're moving to the right and we need to bounce...
|
||||||
if (!(bouncedX & 0x1) &&
|
if (!(bouncedX & 0x1) &&
|
||||||
((aRequestedX + aSpecWidth) > screenRight)) {
|
((aRequestedX + aSpecWidth) > screenRect.XMost())) {
|
||||||
aRequestedX = screenRight - aSpecWidth;
|
aRequestedX = screenRect.XMost() - aSpecWidth;
|
||||||
++bouncedX;
|
++bouncedX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we're moving to the left and we need to bounce...
|
// if we're moving to the left and we need to bounce...
|
||||||
if ((bouncedX & 0x1) && aRequestedX < screenLeft) {
|
if ((bouncedX & 0x1) && aRequestedX < screenRect.X()) {
|
||||||
aRequestedX = screenLeft;
|
aRequestedX = screenRect.X();
|
||||||
++bouncedX;
|
++bouncedX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we hit the bottom then bounce to the top
|
// if we hit the bottom then bounce to the top
|
||||||
if (aRequestedY + aSpecHeight > screenBottom) {
|
if (aRequestedY + aSpecHeight > screenRect.YMost()) {
|
||||||
aRequestedY = screenTop;
|
aRequestedY = screenRect.Y();
|
||||||
++bouncedY;
|
++bouncedY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2176,7 +2150,8 @@ NS_IMETHODIMP
|
|||||||
AppWindow::GetPrimaryContentSize(int32_t* aWidth, int32_t* aHeight) {
|
AppWindow::GetPrimaryContentSize(int32_t* aWidth, int32_t* aHeight) {
|
||||||
if (mPrimaryBrowserParent) {
|
if (mPrimaryBrowserParent) {
|
||||||
return GetPrimaryRemoteTabSize(aWidth, aHeight);
|
return GetPrimaryRemoteTabSize(aWidth, aHeight);
|
||||||
} else if (mPrimaryContentShell) {
|
}
|
||||||
|
if (mPrimaryContentShell) {
|
||||||
return GetPrimaryContentShellSize(aWidth, aHeight);
|
return GetPrimaryContentShellSize(aWidth, aHeight);
|
||||||
}
|
}
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
@@ -2200,16 +2175,14 @@ nsresult AppWindow::GetPrimaryContentShellSize(int32_t* aWidth,
|
|||||||
nsCOMPtr<nsIBaseWindow> shellWindow(do_QueryInterface(mPrimaryContentShell));
|
nsCOMPtr<nsIBaseWindow> shellWindow(do_QueryInterface(mPrimaryContentShell));
|
||||||
NS_ENSURE_STATE(shellWindow);
|
NS_ENSURE_STATE(shellWindow);
|
||||||
|
|
||||||
int32_t devicePixelWidth, devicePixelHeight;
|
|
||||||
double shellScale = 1.0;
|
|
||||||
// We want to return CSS pixels. First, we get device pixels
|
// We want to return CSS pixels. First, we get device pixels
|
||||||
// from the content area...
|
// from the content area...
|
||||||
shellWindow->GetSize(&devicePixelWidth, &devicePixelHeight);
|
|
||||||
// And then get the device pixel scaling factor. Dividing device
|
// And then get the device pixel scaling factor. Dividing device
|
||||||
// pixels by this scaling factor gives us CSS pixels.
|
// pixels by this scaling factor gives us CSS pixels.
|
||||||
shellWindow->GetUnscaledDevicePixelsPerCSSPixel(&shellScale);
|
CSSIntSize size = RoundedToInt(
|
||||||
*aWidth = NSToIntRound(devicePixelWidth / shellScale);
|
shellWindow->GetSize() / shellWindow->UnscaledDevicePixelsPerCSSPixel());
|
||||||
*aHeight = NSToIntRound(devicePixelHeight / shellScale);
|
*aWidth = size.width;
|
||||||
|
*aHeight = size.width;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2227,9 +2200,9 @@ nsresult AppWindow::SetPrimaryRemoteTabSize(int32_t aWidth, int32_t aHeight) {
|
|||||||
int32_t shellWidth, shellHeight;
|
int32_t shellWidth, shellHeight;
|
||||||
GetPrimaryRemoteTabSize(&shellWidth, &shellHeight);
|
GetPrimaryRemoteTabSize(&shellWidth, &shellHeight);
|
||||||
|
|
||||||
double scale = 1.0;
|
// FIXME: This is wrong (pre-existing), the above call acounts for zoom and
|
||||||
GetUnscaledDevicePixelsPerCSSPixel(&scale);
|
// this one doesn't.
|
||||||
|
double scale = UnscaledDevicePixelsPerCSSPixel().scale;
|
||||||
SizeShellToWithLimit(aWidth, aHeight, shellWidth * scale,
|
SizeShellToWithLimit(aWidth, aHeight, shellWidth * scale,
|
||||||
shellHeight * scale);
|
shellHeight * scale);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
@@ -3306,10 +3279,7 @@ void AppWindow::ConstrainToOpenerScreen(int32_t* aX, int32_t* aY) {
|
|||||||
nsCOMPtr<nsIScreenManager> screenmgr =
|
nsCOMPtr<nsIScreenManager> screenmgr =
|
||||||
do_GetService("@mozilla.org/gfx/screenmanager;1");
|
do_GetService("@mozilla.org/gfx/screenmanager;1");
|
||||||
if (screenmgr) {
|
if (screenmgr) {
|
||||||
nsCOMPtr<nsIScreen> screen;
|
nsCOMPtr<nsIScreen> screen = screenmgr->ScreenForRect(mOpenerScreenRect);
|
||||||
screenmgr->ScreenForRect(
|
|
||||||
mOpenerScreenRect.X(), mOpenerScreenRect.Y(), mOpenerScreenRect.Width(),
|
|
||||||
mOpenerScreenRect.Height(), getter_AddRefs(screen));
|
|
||||||
if (screen) {
|
if (screen) {
|
||||||
screen->GetAvailRectDisplayPix(&left, &top, &width, &height);
|
screen->GetAvailRectDisplayPix(&left, &top, &width, &height);
|
||||||
if (*aX < left || *aX > left + width) {
|
if (*aX < left || *aX > left + width) {
|
||||||
|
|||||||
@@ -339,7 +339,9 @@ class AppWindow final : public nsIBaseWindow,
|
|||||||
uint32_t mChromeFlags;
|
uint32_t mChromeFlags;
|
||||||
nsCOMPtr<nsIOpenWindowInfo> mInitialOpenWindowInfo;
|
nsCOMPtr<nsIOpenWindowInfo> mInitialOpenWindowInfo;
|
||||||
nsString mTitle;
|
nsString mTitle;
|
||||||
nsIntRect mOpenerScreenRect; // the screen rect of the opener
|
|
||||||
|
// The screen rect of the opener.
|
||||||
|
mozilla::DesktopIntRect mOpenerScreenRect;
|
||||||
|
|
||||||
nsCOMPtr<nsIRemoteTab> mPrimaryBrowserParent;
|
nsCOMPtr<nsIRemoteTab> mPrimaryBrowserParent;
|
||||||
|
|
||||||
|
|||||||
@@ -262,10 +262,8 @@ NS_IMETHODIMP nsChromeTreeOwner::Destroy() {
|
|||||||
return mAppWindow->Destroy();
|
return mAppWindow->Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsChromeTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(
|
double nsChromeTreeOwner::GetWidgetCSSToDeviceScale() {
|
||||||
double* aScale) {
|
return mAppWindow ? mAppWindow->GetWidgetCSSToDeviceScale() : 1.0;
|
||||||
NS_ENSURE_STATE(mAppWindow);
|
|
||||||
return mAppWindow->GetUnscaledDevicePixelsPerCSSPixel(aScale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsChromeTreeOwner::GetDevicePixelsPerDesktopPixel(
|
NS_IMETHODIMP nsChromeTreeOwner::GetDevicePixelsPerDesktopPixel(
|
||||||
|
|||||||
@@ -397,10 +397,8 @@ NS_IMETHODIMP nsContentTreeOwner::Destroy() {
|
|||||||
return mAppWindow->Destroy();
|
return mAppWindow->Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsContentTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(
|
double nsContentTreeOwner::GetWidgetCSSToDeviceScale() {
|
||||||
double* aScale) {
|
return mAppWindow ? mAppWindow->GetWidgetCSSToDeviceScale() : 1.0;
|
||||||
NS_ENSURE_STATE(mAppWindow);
|
|
||||||
return mAppWindow->GetUnscaledDevicePixelsPerCSSPixel(aScale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsContentTreeOwner::GetDevicePixelsPerDesktopPixel(
|
NS_IMETHODIMP nsContentTreeOwner::GetDevicePixelsPerDesktopPixel(
|
||||||
|
|||||||
Reference in New Issue
Block a user