gecko-dev/widget/DimensionRequest.cpp
Matthias Camenzind c9300fab1e Bug 1786048 - Part 3: Merge nsIEmbeddingSiteWindow into nsIBaseWindow. r=emilio
Implementations of nsIEmbeddingSiteWindow and nsIBaseWindow largely
overlap, and where they don't, the nsIEmbeddingSiteWindow implementation
of the otherwise shared interface is primarily stubbed out with the
exception of Get/SetDimensions().

This patch moves a reimplementation of Get/SetDimensions() from
nsIEmbeddingSiteWindow to nsIBaseWindow. The other methods of
nsIEmbeddingSiteWindow remain covered by nsIBaseWindow.
Get/SetDimensions() can be implemented as part of nsIWebBrowserChrome
where nsIBaseWindow is not necessary. This removes the need for
nsIEmbeddingSiteWindow.

Blur() has also been moved to nsIWebBrowserChrome, as only
nsContentTreeOwner has an actual implementation which we in theory also
want to call from BrowserChild/Parent, but the spec suggests to
"selectively or uniformly ignore calls".

GetVisibility() had an implementation in BrowserChild that pretended to
always be visible. Instead of providing an interface for that,
nsDocShell now handles the not implemented case for tree owners.

nsIEmbeddingSiteWindow::GetSiteWindow() used to call through to
nsIBaseWindow::GetParentNativeWindow().

The Get/SetDimensions() implementation has been replaced with a strongly
typed setter, which is now also used directly from nsGlobalWindowOuter
to avoid problems that come with autodetecting unchanged dimensions,
when the current dimensions are outdated (e.g. immediately reverting a
change can be ignored).

Differential Revision: https://phabricator.services.mozilla.com/D160260
2022-12-15 23:13:00 +00:00

120 lines
3.3 KiB
C++

/* 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 "DimensionRequest.h"
#include "nsIBaseWindow.h"
#include "nsIDocShellTreeOwner.h"
namespace mozilla {
nsresult DimensionRequest::SupplementFrom(nsIBaseWindow* aSource) {
NS_ENSURE_ARG_POINTER(aSource);
int32_t x = 0, y = 0, width = 0, height = 0;
bool needsPosition = mX.isSome() != mY.isSome();
bool needsSize = mWidth.isSome() != mHeight.isSome();
if (!needsPosition && !needsSize) {
return NS_OK;
}
MOZ_TRY(aSource->GetDimensions(mDimensionKind, needsPosition ? &x : nullptr,
needsPosition ? &y : nullptr,
needsSize ? &width : nullptr,
needsSize ? &height : nullptr));
if (needsPosition) {
if (mX.isNothing()) {
mX.emplace(x);
}
if (mY.isNothing()) {
mY.emplace(y);
}
}
if (needsSize) {
if (mWidth.isNothing()) {
mWidth.emplace(width);
}
if (mHeight.isNothing()) {
mHeight.emplace(height);
}
}
MOZ_ASSERT(mX.isSome() == mY.isSome());
MOZ_ASSERT(mWidth.isSome() == mHeight.isSome());
return NS_OK;
}
nsresult DimensionRequest::ApplyOuterTo(nsIBaseWindow* aTarget) {
NS_ENSURE_ARG_POINTER(aTarget);
MOZ_ASSERT(mX.isSome() == mY.isSome(),
"Missing dimensions should have been completed.");
MOZ_ASSERT(mWidth.isSome() == mHeight.isSome(),
"Missing dimensions should have been completed.");
if (mDimensionKind != DimensionKind::Outer) {
MOZ_ASSERT_UNREACHABLE("Expected outer dimensions.");
return NS_ERROR_UNEXPECTED;
}
bool havePosition = mX.isSome() && mY.isSome();
bool haveSize = mWidth.isSome() && mHeight.isSome();
if (!havePosition && !haveSize) {
return NS_OK;
}
if (havePosition && haveSize) {
return aTarget->SetPositionAndSize(*mX, *mY, *mWidth, *mHeight, true);
}
if (havePosition) {
return aTarget->SetPosition(*mX, *mY);
}
if (haveSize) {
return aTarget->SetSize(*mWidth, *mHeight, true);
}
MOZ_ASSERT_UNREACHABLE();
return NS_ERROR_UNEXPECTED;
}
nsresult DimensionRequest::ApplyInnerTo(nsIDocShellTreeOwner* aTarget,
bool aAsRootShell) {
NS_ENSURE_ARG_POINTER(aTarget);
MOZ_ASSERT(mX.isSome() == mY.isSome(),
"Missing dimensions should have been completed.");
MOZ_ASSERT(mWidth.isSome() == mHeight.isSome(),
"Missing dimensions should have been completed.");
if (mDimensionKind != DimensionKind::Inner) {
MOZ_ASSERT_UNREACHABLE("Expected inner dimensions.");
return NS_ERROR_UNEXPECTED;
}
bool havePosition = mX.isSome() && mY.isSome();
bool haveSize = mWidth.isSome() && mHeight.isSome();
if (!havePosition && !haveSize) {
return NS_OK;
}
if (havePosition) {
MOZ_ASSERT_UNREACHABLE("Inner position is not implemented.");
return NS_ERROR_NOT_IMPLEMENTED;
}
if (haveSize) {
if (aAsRootShell) {
return aTarget->SetRootShellSize(*mWidth, *mHeight);
}
return aTarget->SetPrimaryContentSize(*mWidth, *mHeight);
}
MOZ_ASSERT_UNREACHABLE();
return NS_ERROR_UNEXPECTED;
}
} // namespace mozilla