Bug 1927967 - Use typed units for nsDocumentViewer bounds. r=hiro,dholbert

SVG is fine because it always uses an effective DPI of 1. The rest
already use and assume layout pixels.

Differential Revision: https://phabricator.services.mozilla.com/D228120
This commit is contained in:
Emilio Cobos Álvarez
2024-11-06 12:37:39 +00:00
parent fa9120c5f7
commit e923afbf46
10 changed files with 42 additions and 44 deletions

View File

@@ -6884,9 +6884,9 @@ nsresult nsDocShell::CaptureState() {
// Capture the current content viewer bounds. // Capture the current content viewer bounds.
if (mDocumentViewer) { if (mDocumentViewer) {
nsIntRect bounds; LayoutDeviceIntRect bounds;
mDocumentViewer->GetBounds(bounds); mDocumentViewer->GetBounds(bounds);
mOSHE->SetViewerBounds(bounds); mOSHE->SetViewerBounds(bounds.ToUnknownRect());
} }
// Capture the docshell hierarchy. // Capture the docshell hierarchy.
@@ -7234,7 +7234,7 @@ nsresult nsDocShell::RestoreFromHistory() {
nsView* rootViewSibling = nullptr; nsView* rootViewSibling = nullptr;
nsView* rootViewParent = nullptr; nsView* rootViewParent = nullptr;
nsIntRect newBounds(0, 0, 0, 0); LayoutDeviceIntRect newBounds(0, 0, 0, 0);
PresShell* oldPresShell = GetPresShell(); PresShell* oldPresShell = GetPresShell();
if (oldPresShell) { if (oldPresShell) {
@@ -7541,7 +7541,8 @@ nsresult nsDocShell::RestoreFromHistory() {
// cached viewer size (skipping the resize if they are equal). // cached viewer size (skipping the resize if they are equal).
if (newRootView) { if (newRootView) {
if (!newBounds.IsEmpty() && !newBounds.IsEqualEdges(oldBounds)) { if (!newBounds.IsEmpty() &&
!newBounds.ToUnknownRect().IsEqualEdges(oldBounds)) {
MOZ_LOG(gPageCacheLog, LogLevel::Debug, MOZ_LOG(gPageCacheLog, LogLevel::Debug,
("resize widget(%d, %d, %d, %d)", newBounds.x, newBounds.y, ("resize widget(%d, %d, %d, %d)", newBounds.x, newBounds.y,
newBounds.width, newBounds.height)); newBounds.width, newBounds.height));
@@ -7938,7 +7939,7 @@ nsresult nsDocShell::SetupNewViewer(nsIDocumentViewer* aNewViewer,
nsCOMPtr<nsIWidget> widget; nsCOMPtr<nsIWidget> widget;
NS_ENSURE_SUCCESS(GetMainWidget(getter_AddRefs(widget)), NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(GetMainWidget(getter_AddRefs(widget)), NS_ERROR_FAILURE);
nsIntRect bounds(x, y, cx, cy); LayoutDeviceIntRect bounds(x, y, cx, cy);
mDocumentViewer->SetNavigationTiming(mTiming); mDocumentViewer->SetNavigationTiming(mTiming);

View File

@@ -1163,7 +1163,7 @@ class nsDocShell final : public nsDocLoader,
nsWeakPtr mBrowserChild; nsWeakPtr mBrowserChild;
// Dimensions of the docshell // Dimensions of the docshell
nsIntRect mBounds; mozilla::LayoutDeviceIntRect mBounds;
/** /**
* Content-Type Hint of the most-recently initiated load. Used for * Content-Type Hint of the most-recently initiated load. Used for

View File

@@ -33,7 +33,7 @@ class RemotePrintJobChild;
%} %}
[ptr] native nsIWidgetPtr(nsIWidget); [ptr] native nsIWidgetPtr(nsIWidget);
[ref] native nsIntRectRef(nsIntRect); [ref] native LayoutDeviceIntRectRef(mozilla::LayoutDeviceIntRect);
[ptr] native nsPresContextPtr(nsPresContext); [ptr] native nsPresContextPtr(nsPresContext);
[ptr] native nsViewPtr(nsView); [ptr] native nsViewPtr(nsView);
[ptr] native nsDOMNavigationTimingPtr(nsDOMNavigationTiming); [ptr] native nsDOMNavigationTimingPtr(nsDOMNavigationTiming);
@@ -46,7 +46,7 @@ class RemotePrintJobChild;
interface nsIDocumentViewer : nsISupports interface nsIDocumentViewer : nsISupports
{ {
[noscript] void init(in nsIWidgetPtr aParentWidget, [noscript] void init(in nsIWidgetPtr aParentWidget,
[const] in nsIntRectRef aBounds, [const] in LayoutDeviceIntRectRef aBounds,
in WindowGlobalChildPtr aWindowActor); in WindowGlobalChildPtr aWindowActor);
attribute nsIDocShell container; attribute nsIDocShell container;
@@ -163,13 +163,13 @@ interface nsIDocumentViewer : nsISupports
*/ */
[noscript,nostdcall] void setDocument(in Document aDocument); [noscript,nostdcall] void setDocument(in Document aDocument);
[noscript] void getBounds(in nsIntRectRef aBounds); [noscript] void getBounds(in LayoutDeviceIntRectRef aBounds);
[noscript] void setBounds([const] in nsIntRectRef aBounds); [noscript] void setBounds([const] in LayoutDeviceIntRectRef aBounds);
/** /**
* The 'aFlags' argument to setBoundsWithFlags is a set of these bits. * The 'aFlags' argument to setBoundsWithFlags is a set of these bits.
*/ */
const unsigned long eDelayResize = 1; const unsigned long eDelayResize = 1;
[noscript] void setBoundsWithFlags([const] in nsIntRectRef aBounds, [noscript] void setBoundsWithFlags([const] in LayoutDeviceIntRectRef aBounds,
in unsigned long aFlags); in unsigned long aFlags);
/** /**

View File

@@ -993,7 +993,7 @@ nsresult ExternalResourceMap::AddExternalResource(nsIURI* aURI,
// Make sure that hiding our viewer will tear down its presentation. // Make sure that hiding our viewer will tear down its presentation.
aViewer->SetSticky(false); aViewer->SetSticky(false);
rv = aViewer->Init(nullptr, nsIntRect(0, 0, 0, 0), nullptr); rv = aViewer->Init(nullptr, LayoutDeviceIntRect(), nullptr);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
rv = aViewer->Open(nullptr, nullptr); rv = aViewer->Open(nullptr, nullptr);
} }

View File

@@ -3654,17 +3654,14 @@ static void PrepareForFullscreenChange(nsIDocShell* aDocShell,
nsCOMPtr<nsIDocumentViewer> viewer; nsCOMPtr<nsIDocumentViewer> viewer;
aDocShell->GetDocViewer(getter_AddRefs(viewer)); aDocShell->GetDocViewer(getter_AddRefs(viewer));
if (viewer) { if (viewer) {
nsIntRect viewerBounds; LayoutDeviceIntRect viewerBounds;
viewer->GetBounds(viewerBounds); viewer->GetBounds(viewerBounds);
nscoord auPerDev = presShell->GetPresContext()->AppUnitsPerDevPixel(); nscoord auPerDev = presShell->GetPresContext()->AppUnitsPerDevPixel();
if (aOldSize) { if (aOldSize) {
*aOldSize = LayoutDeviceIntSize::ToAppUnits( *aOldSize =
LayoutDeviceIntSize::FromUnknownSize(viewerBounds.Size()), LayoutDeviceIntSize::ToAppUnits(viewerBounds.Size(), auPerDev);
auPerDev);
} }
LayoutDeviceIntSize newSize = auto newSize = LayoutDeviceIntSize::FromAppUnitsRounded(aSize, auPerDev);
LayoutDeviceIntSize::FromAppUnitsRounded(aSize, auPerDev);
viewerBounds.SizeTo(newSize.width, newSize.height); viewerBounds.SizeTo(newSize.width, newSize.height);
viewer->SetBounds(viewerBounds); viewer->SetBounds(viewerBounds);
} }

View File

@@ -138,7 +138,7 @@ nsresult gfxSVGGlyphsDocument::SetupPresentation() {
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
auto upem = mOwner->FontEntry()->UnitsPerEm(); auto upem = mOwner->FontEntry()->UnitsPerEm();
rv = viewer->Init(nullptr, gfx::IntRect(0, 0, upem, upem), nullptr); rv = viewer->Init(nullptr, LayoutDeviceIntRect(0, 0, upem, upem), nullptr);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
rv = viewer->Open(nullptr, nullptr); rv = viewer->Open(nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);

View File

@@ -72,12 +72,14 @@ void SVGDocumentWrapper::UpdateViewportBounds(const nsIntSize& aViewportSize) {
MOZ_ASSERT(!mIgnoreInvalidation, "shouldn't be reentrant"); MOZ_ASSERT(!mIgnoreInvalidation, "shouldn't be reentrant");
mIgnoreInvalidation = true; mIgnoreInvalidation = true;
nsIntRect currentBounds; LayoutDeviceIntRect currentBounds;
mViewer->GetBounds(currentBounds); mViewer->GetBounds(currentBounds);
// If the bounds have changed, we need to do a layout flush. // If the bounds have changed, we need to do a layout flush.
if (currentBounds.Size() != aViewportSize) { if (currentBounds.Size().ToUnknownSize() != aViewportSize) {
mViewer->SetBounds(IntRect(IntPoint(0, 0), aViewportSize)); mViewer->SetBounds(LayoutDeviceIntRect(
LayoutDeviceIntPoint(),
LayoutDeviceIntSize::FromUnknownSize(aViewportSize)));
FlushLayout(); FlushLayout();
} }
@@ -207,7 +209,7 @@ SVGDocumentWrapper::OnStartRequest(nsIRequest* aRequest) {
mViewer->GetDocument()->SetIsBeingUsedAsImage(); mViewer->GetDocument()->SetIsBeingUsedAsImage();
StopAnimation(); // otherwise animations start automatically in helper doc StopAnimation(); // otherwise animations start automatically in helper doc
rv = mViewer->Init(nullptr, nsIntRect(0, 0, 0, 0), nullptr); rv = mViewer->Init(nullptr, LayoutDeviceIntRect(), nullptr);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
rv = mViewer->Open(nullptr, nullptr); rv = mViewer->Open(nullptr, nullptr);
} }

View File

@@ -364,7 +364,7 @@ class nsDocumentViewer final : public nsIDocumentViewer,
*/ */
nsresult InitInternal(nsIWidget* aParentWidget, nsISupports* aState, nsresult InitInternal(nsIWidget* aParentWidget, nsISupports* aState,
mozilla::dom::WindowGlobalChild* aActor, mozilla::dom::WindowGlobalChild* aActor,
const nsIntRect& aBounds, bool aDoCreation, const LayoutDeviceIntRect& aBounds, bool aDoCreation,
bool aNeedMakeCX = true, bool aNeedMakeCX = true,
bool aForceSetNewDocument = true); bool aForceSetNewDocument = true);
/** /**
@@ -434,7 +434,7 @@ class nsDocumentViewer final : public nsIDocumentViewer,
nsIWidget* mParentWidget; // purposely won't be ref counted. May be null nsIWidget* mParentWidget; // purposely won't be ref counted. May be null
bool mAttachedToParent; // view is attached to the parent widget bool mAttachedToParent; // view is attached to the parent widget
nsIntRect mBounds; LayoutDeviceIntRect mBounds;
int16_t mNumURLStarts; int16_t mNumURLStarts;
int16_t mDestroyBlockedCount; int16_t mDestroyBlockedCount;
@@ -673,7 +673,8 @@ nsDocumentViewer::GetContainer(nsIDocShell** aResult) {
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDocumentViewer::Init(nsIWidget* aParentWidget, const nsIntRect& aBounds, nsDocumentViewer::Init(nsIWidget* aParentWidget,
const LayoutDeviceIntRect& aBounds,
WindowGlobalChild* aActor) { WindowGlobalChild* aActor) {
return InitInternal(aParentWidget, nullptr, aActor, aBounds, true); return InitInternal(aParentWidget, nullptr, aActor, aBounds, true);
} }
@@ -729,11 +730,10 @@ nsresult nsDocumentViewer::InitPresentationStuff(bool aDoInitialReflow) {
p2a == p2a ==
mPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom()); mPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
nscoord width = p2a * mBounds.width; const nsSize size = LayoutDevicePixel::ToAppUnits(mBounds.Size(), p2a);
nscoord height = p2a * mBounds.height;
mViewManager->SetWindowDimensions(width, height); mViewManager->SetWindowDimensions(size.width, size.height);
mPresContext->SetInitialVisibleArea(nsRect(0, 0, width, height)); mPresContext->SetInitialVisibleArea(nsRect(nsPoint(), size));
// We rely on the default zoom not being initialized until here. // We rely on the default zoom not being initialized until here.
mPresContext->RecomputeBrowsingContextDependentData(); mPresContext->RecomputeBrowsingContextDependentData();
} }
@@ -796,8 +796,8 @@ static already_AddRefed<nsPresContext> CreatePresContext(
// all the new objects or just initialize the existing ones // all the new objects or just initialize the existing ones
nsresult nsDocumentViewer::InitInternal( nsresult nsDocumentViewer::InitInternal(
nsIWidget* aParentWidget, nsISupports* aState, WindowGlobalChild* aActor, nsIWidget* aParentWidget, nsISupports* aState, WindowGlobalChild* aActor,
const nsIntRect& aBounds, bool aDoCreation, bool aNeedMakeCX /*= true*/, const LayoutDeviceIntRect& aBounds, bool aDoCreation,
bool aForceSetNewDocument /* = true*/) { bool aNeedMakeCX /*= true*/, bool aForceSetNewDocument /* = true*/) {
// We don't want any scripts to run here. That can cause flushing, // We don't want any scripts to run here. That can cause flushing,
// which can cause reentry into initialization of this document viewer, // which can cause reentry into initialization of this document viewer,
// which would be disastrous. // which would be disastrous.
@@ -1883,7 +1883,7 @@ nsPresContext* nsDocumentViewer::GetPresContext() { return mPresContext; }
nsViewManager* nsDocumentViewer::GetViewManager() { return mViewManager; } nsViewManager* nsDocumentViewer::GetViewManager() { return mViewManager; }
NS_IMETHODIMP NS_IMETHODIMP
nsDocumentViewer::GetBounds(nsIntRect& aResult) { nsDocumentViewer::GetBounds(LayoutDeviceIntRect& aResult) {
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE); NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
aResult = mBounds; aResult = mBounds;
return NS_OK; return NS_OK;
@@ -1926,7 +1926,7 @@ void nsDocumentViewer::SetPreviousViewer(nsIDocumentViewer* aViewer) {
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDocumentViewer::SetBoundsWithFlags(const nsIntRect& aBounds, nsDocumentViewer::SetBoundsWithFlags(const LayoutDeviceIntRect& aBounds,
uint32_t aFlags) { uint32_t aFlags) {
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE); NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
@@ -1963,13 +1963,12 @@ nsDocumentViewer::SetBoundsWithFlags(const nsIntRect& aBounds,
// need to invalidate because what we want to draw to the screen has // need to invalidate because what we want to draw to the screen has
// changed. // changed.
if (viewDims.width == width && viewDims.height == height) { if (viewDims.width == width && viewDims.height == height) {
nsIFrame* f = rootView->GetFrame(); if (nsIFrame* f = rootView->GetFrame()) {
if (f) {
f->InvalidateFrame(); f->InvalidateFrame();
// Forcibly refresh the viewport sizes even if the view size is not // Forcibly refresh the viewport sizes even if the view size is not
// changed since it is possible that the |mBounds| change means that // changed since it is possible that the |mBounds| change means that
// the software keyboard appeared/disappered, in such cases we might // the software keyboard appeared/disappeared. In such cases we might
// need to fire visual viewport events. // need to fire visual viewport events.
mPresShell->RefreshViewportSize(); mPresShell->RefreshViewportSize();
} }
@@ -1996,7 +1995,7 @@ nsDocumentViewer::SetBoundsWithFlags(const nsIntRect& aBounds,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDocumentViewer::SetBounds(const nsIntRect& aBounds) { nsDocumentViewer::SetBounds(const LayoutDeviceIntRect& aBounds) {
return SetBoundsWithFlags(aBounds, 0); return SetBoundsWithFlags(aBounds, 0);
} }
@@ -2639,8 +2638,7 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP nsDocumentViewer::GetContentSize(
// Leave our viewport in a consistent state. // Leave our viewport in a consistent state.
{ {
auto newBounds = LayoutDeviceIntRect::FromAppUnitsToOutside( auto newBounds = LayoutDeviceIntRect::FromAppUnitsToOutside(
shellArea, presContext->AppUnitsPerDevPixel()) shellArea, presContext->AppUnitsPerDevPixel());
.ToUnknownRect();
newBounds.MoveTo(mBounds.TopLeft()); newBounds.MoveTo(mBounds.TopLeft());
SetBounds(newBounds); SetBounds(newBounds);
} }

View File

@@ -8022,7 +8022,7 @@ bool nsLayoutUtils::GetDocumentViewerSize(
return false; return false;
} }
nsIntRect bounds; LayoutDeviceIntRect bounds;
viewer->GetBounds(bounds); viewer->GetBounds(bounds);
if (aPresContext->IsRootContentDocumentCrossProcess() && if (aPresContext->IsRootContentDocumentCrossProcess() &&
@@ -8038,7 +8038,7 @@ bool nsLayoutUtils::GetDocumentViewerSize(
} }
} }
aOutSize = LayoutDeviceIntRect::FromUnknownRect(bounds).Size(); aOutSize = bounds.Size();
return true; return true;
} }

View File

@@ -1322,7 +1322,7 @@ nsresult nsPrintJob::ReflowPrintObject(const UniquePtr<nsPrintObject>& aPO) {
do_QueryInterface(mDocViewerPrint)) { do_QueryInterface(mDocViewerPrint)) {
// If we're print-previewing and the top level document, use the bounds // If we're print-previewing and the top level document, use the bounds
// from our doc viewer. Page bounds is not what we want. // from our doc viewer. Page bounds is not what we want.
nsIntRect bounds; LayoutDeviceIntRect bounds;
viewer->GetBounds(bounds); viewer->GetBounds(bounds);
adjSize = nsSize(bounds.width * p2a, bounds.height * p2a); adjSize = nsSize(bounds.width * p2a, bounds.height * p2a);
} }