Skip to content

Commit

Permalink
Bug 1803611 - Part 1: Use shared code for AppWindow::SetPosition/And/…
Browse files Browse the repository at this point in the history
…Size. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D166877
  • Loading branch information
matc-pub committed Jan 27, 2023
1 parent 00d5305 commit b185310
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 64 deletions.
131 changes: 67 additions & 64 deletions xpfe/appshell/AppWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,30 +673,15 @@ double AppWindow::GetWidgetCSSToDeviceScale() {
}

NS_IMETHODIMP AppWindow::SetPositionDesktopPix(int32_t aX, int32_t aY) {
mWindow->Move(aX, aY);
if (mSizingShellFromXUL) {
// If we're invoked for sizing from XUL, we want to neither ignore anything
// nor persist anything, since it's already the value in XUL.
return NS_OK;
}
if (!mChromeLoaded) {
// If we're called before the chrome is loaded someone obviously wants this
// window at this position. We don't persist this one-time position.
mIgnoreXULPosition = true;
return NS_OK;
}
PersistentAttributesDirty(PersistentAttribute::Position, Sync);
return NS_OK;
return MoveResize(Some(DesktopIntPoint(aX, aY)), Nothing(), false);
}

// The parameters here are device pixels; do the best we can to convert to
// desktop px, using the window's current scale factor (if available).
NS_IMETHODIMP AppWindow::SetPosition(int32_t aX, int32_t aY) {
// Don't reset the window's size mode here - platforms that don't want to move
// maximized windows should reset it in their respective Move implementation.
DesktopToLayoutDeviceScale currScale = mWindow->GetDesktopToDeviceScale();
DesktopPoint pos = LayoutDeviceIntPoint(aX, aY) / currScale;
return SetPositionDesktopPix(pos.x, pos.y);
return MoveResize(Some(LayoutDeviceIntPoint(aX, aY)), Nothing(), false);
}

NS_IMETHODIMP AppWindow::GetPosition(int32_t* aX, int32_t* aY) {
Expand All @@ -707,29 +692,7 @@ NS_IMETHODIMP AppWindow::SetSize(int32_t aCX, int32_t aCY, bool aRepaint) {
/* any attempt to set the window's size or position overrides the window's
zoom state. this is important when these two states are competing while
the window is being opened. but it should probably just always be so. */
mWindow->SetSizeMode(nsSizeMode_Normal);

mIntrinsicallySized = false;

DesktopToLayoutDeviceScale scale = mWindow->GetDesktopToDeviceScale();
DesktopSize size = LayoutDeviceIntSize(aCX, aCY) / scale;
mWindow->Resize(size.width, size.height, aRepaint);
if (mSizingShellFromXUL) {
// If we're invoked for sizing from XUL, we want to neither ignore anything
// nor persist anything, since it's already the value in XUL.
return NS_OK;
}
if (!mChromeLoaded) {
// If we're called before the chrome is loaded someone obviously wants this
// window at this size & in the normal size mode (since it is the only mode
// in which setting dimensions makes sense). We don't persist this one-time
// size.
mIgnoreXULSize = true;
mIgnoreXULSizeMode = true;
return NS_OK;
}
PersistentAttributesDirty(PersistentAttribute::Size, Sync);
return NS_OK;
return MoveResize(Nothing(), Some(LayoutDeviceIntSize(aCX, aCY)), aRepaint);
}

NS_IMETHODIMP AppWindow::GetSize(int32_t* aCX, int32_t* aCY) {
Expand All @@ -741,30 +704,9 @@ NS_IMETHODIMP AppWindow::SetPositionAndSize(int32_t aX, int32_t aY, int32_t aCX,
/* any attempt to set the window's size or position overrides the window's
zoom state. this is important when these two states are competing while
the window is being opened. but it should probably just always be so. */
mWindow->SetSizeMode(nsSizeMode_Normal);

mIntrinsicallySized = false;

DesktopToLayoutDeviceScale scale = mWindow->GetDesktopToDeviceScale();
DesktopRect rect = LayoutDeviceIntRect(aX, aY, aCX, aCY) / scale;
mWindow->Resize(rect.X(), rect.Y(), rect.Width(), rect.Height(),
!!(aFlags & nsIBaseWindow::eRepaint));
if (mSizingShellFromXUL) {
// If we're invoked for sizing from XUL, we want to neither ignore anything
// nor persist anything, since it's already the value in XUL.
return NS_OK;
}
if (!mChromeLoaded) {
// If we're called before the chrome is loaded someone obviously wants this
// window at this size and position. We don't persist this one-time setting.
mIgnoreXULPosition = true;
mIgnoreXULSize = true;
mIgnoreXULSizeMode = true;
return NS_OK;
}
PersistentAttributesDirty(
{PersistentAttribute::Size, PersistentAttribute::Position}, Sync);
return NS_OK;
return MoveResize(Some(LayoutDeviceIntPoint(aX, aY)),
Some(LayoutDeviceIntSize(aCX, aCY)),
!!(aFlags & nsIBaseWindow::eRepaint));
}

NS_IMETHODIMP AppWindow::GetPositionAndSize(int32_t* x, int32_t* y, int32_t* cx,
Expand Down Expand Up @@ -798,6 +740,67 @@ AppWindow::GetDimensions(DimensionKind aDimensionKind, int32_t* aX, int32_t* aY,
return NS_ERROR_NOT_IMPLEMENTED;
}

nsresult AppWindow::MoveResize(const Maybe<LayoutDeviceIntPoint>& aPosition,
const Maybe<LayoutDeviceIntSize>& aSize,
bool aRepaint) {
DesktopToLayoutDeviceScale scale = mWindow->GetDesktopToDeviceScale();

return MoveResize(aPosition ? Some(*aPosition / scale) : Nothing(),
aSize ? Some(*aSize / scale) : Nothing(), aRepaint);
}

nsresult AppWindow::MoveResize(const Maybe<DesktopPoint>& aPosition,
const Maybe<DesktopSize>& aSize, bool aRepaint) {
NS_ENSURE_STATE(mWindow);
PersistentAttributes dirtyAttributes;

if (!aPosition && !aSize) {
MOZ_ASSERT_UNREACHABLE("Doing nothing?");
return NS_ERROR_UNEXPECTED;
}

if (aSize) {
mWindow->SetSizeMode(nsSizeMode_Normal);
mIntrinsicallySized = false;
}

if (aPosition && aSize) {
mWindow->Resize(aPosition->x, aPosition->y, aSize->width, aSize->height,
aRepaint);
dirtyAttributes = {PersistentAttribute::Size,
PersistentAttribute::Position};
} else if (aSize) {
mWindow->Resize(aSize->width, aSize->height, aRepaint);
dirtyAttributes = {PersistentAttribute::Size};
} else if (aPosition) {
mWindow->Move(aPosition->x, aPosition->y);
dirtyAttributes = {PersistentAttribute::Position};
}

if (mSizingShellFromXUL) {
// If we're invoked for sizing from XUL, we want to neither ignore anything
// nor persist anything, since it's already the value in XUL.
return NS_OK;
}
if (!mChromeLoaded) {
// If we're called before the chrome is loaded someone obviously wants this
// window at this size & in the normal size mode (since it is the only mode
// in which setting dimensions makes sense). We don't persist this one-time
// position/size.
if (aPosition) {
mIgnoreXULPosition = true;
}
if (aSize) {
mIgnoreXULSize = true;
mIgnoreXULSizeMode = true;
}
return NS_OK;
}

PersistentAttributesDirty(dirtyAttributes, Sync);
return NS_OK;
}

NS_IMETHODIMP AppWindow::Center(nsIAppWindow* aRelative, bool aScreen,
bool aAlert) {
DesktopIntRect rect;
Expand Down
5 changes: 5 additions & 0 deletions xpfe/appshell/AppWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "nsDocShell.h"
#include "nsRect.h"
#include "Units.h"
#include "mozilla/Maybe.h"
#include "mozilla/Mutex.h"

// Interfaces needed
Expand Down Expand Up @@ -383,6 +384,10 @@ class AppWindow final : public nsIBaseWindow,
nsresult SetPrimaryRemoteTabSize(int32_t aWidth, int32_t aHeight);
void SizeShellToWithLimit(int32_t aDesiredWidth, int32_t aDesiredHeight,
int32_t shellItemWidth, int32_t shellItemHeight);
nsresult MoveResize(const Maybe<LayoutDeviceIntPoint>& aPosition,
const Maybe<LayoutDeviceIntSize>& aSize, bool aRepaint);
nsresult MoveResize(const Maybe<DesktopPoint>& aPosition,
const Maybe<DesktopSize>& aSize, bool aRepaint);
nsCOMPtr<nsIXULStore> mLocalStore;
};

Expand Down

0 comments on commit b185310

Please sign in to comment.