Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 848d89d

Browse files
committed
Bug 1583534 - Further simplify PresShell::ResizeReflow. r=botond
In particular, not let ResizeReflow take the old and new size. Most of the callers pass dummy values anyway. Instead, use the old size of the layout viewport. This ensures we fire resize events only if the layout viewport actually changes. This is important because the first resize of the mobile viewport manager after a navigation has an "old size" of 0x0, even though the layout viewport is initialized on presshell initialization to the right size. Thus, we fire resize events unnecessarily in that case, which is the root cause for bug 1528052. To do this, we need to shuffle a bit of code in nsDocumentViewer that deals with delayed resizes, to set the visible area _and_ invalidate layout, rather than setting the visible area and _then_ relying on doing a resize reflow. Further cleanup is possible, though not required for my android resizing fix, so will do separately. Differential Revision: https://phabricator.services.mozilla.com/D46944 --HG-- extra : moz-landing-system : lando
1 parent b12c436 commit 848d89d

12 files changed

Lines changed: 50 additions & 49 deletions

dom/base/nsGlobalWindowOuter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3852,6 +3852,11 @@ void nsGlobalWindowOuter::SetCSSViewportWidthAndHeight(nscoord aInnerWidth,
38523852
shellArea.SetHeight(aInnerHeight);
38533853
shellArea.SetWidth(aInnerWidth);
38543854

3855+
// FIXME(emilio): This doesn't seem to be ok, this doesn't reflow or
3856+
// anything... Should go through PresShell::ResizeReflow.
3857+
//
3858+
// But I don't think this can be reached by content, as we don't allow to set
3859+
// inner{Width,Height}.
38553860
presContext->SetVisibleArea(shellArea);
38563861
}
38573862

gfx/layers/apz/test/gtest/mvm/TestMobileViewportManager.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ class MockMVMContext : public MVMContext {
8282
mResolution = aResolution;
8383
mMVM->ResolutionUpdated(aOrigin);
8484
}
85-
void Reflow(const CSSSize& aNewSize, const CSSSize& aOldSize,
86-
ResizeEventFlag aResizeEventFlag) {
85+
void Reflow(const CSSSize& aNewSize, ResizeEventFlag) {
8786
mICBSize = aNewSize;
8887
mContentSize = mLayoutFunction(mICBSize);
8988
}

layout/base/GeckoMVMContext.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void GeckoMVMContext::UpdateDisplayPortMargins() {
176176
}
177177
}
178178

179-
void GeckoMVMContext::Reflow(const CSSSize& aNewSize, const CSSSize& aOldSize,
179+
void GeckoMVMContext::Reflow(const CSSSize& aNewSize,
180180
ResizeEventFlag aResizeEventFlag) {
181181
MOZ_ASSERT(mPresShell);
182182

@@ -189,8 +189,7 @@ void GeckoMVMContext::Reflow(const CSSSize& aNewSize, const CSSSize& aOldSize,
189189
presShell->ResizeReflowIgnoreOverride(
190190
nsPresContext::CSSPixelsToAppUnits(aNewSize.width),
191191
nsPresContext::CSSPixelsToAppUnits(aNewSize.height),
192-
nsPresContext::CSSPixelsToAppUnits(aOldSize.width),
193-
nsPresContext::CSSPixelsToAppUnits(aOldSize.height), reflowOptions);
192+
reflowOptions);
194193
}
195194

196195
} // namespace mozilla

layout/base/GeckoMVMContext.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ class GeckoMVMContext : public MVMContext {
5555
void SetVisualViewportSize(const CSSSize& aSize) override;
5656
void UpdateDisplayPortMargins() override;
5757
MOZ_CAN_RUN_SCRIPT_BOUNDARY
58-
void Reflow(const CSSSize& aNewSize, const CSSSize& aOldSize,
59-
ResizeEventFlag aResizeEventFlag) override;
58+
void Reflow(const CSSSize& aNewSize, ResizeEventFlag) override;
6059

6160
private:
6261
RefPtr<dom::Document> mDocument;

layout/base/MVMContext.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ class MVMContext {
6363
IfNecessary, // resize events will be fired if necessary.
6464
Suppress, // resize events will never be fired.
6565
};
66-
virtual void Reflow(const CSSSize& aNewSize, const CSSSize& aOldSize,
67-
ResizeEventFlag aResizeEventFlag) = 0;
66+
virtual void Reflow(const CSSSize& aNewSize, ResizeEventFlag) = 0;
6867
};
6968

7069
} // namespace mozilla

layout/base/MobileViewportManager.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,15 +589,13 @@ void MobileViewportManager::RefreshViewportSize(bool aForceAdjustResolution) {
589589
UpdateDisplayPortMargins();
590590
}
591591

592-
CSSSize oldSize = mMobileViewportSize;
593-
594592
// Update internal state.
595593
mMobileViewportSize = viewport;
596594

597595
RefPtr<MobileViewportManager> strongThis(this);
598596

599597
// Kick off a reflow.
600-
mContext->Reflow(viewport, oldSize,
598+
mContext->Reflow(viewport,
601599
mIsFirstPaint ? MVMContext::ResizeEventFlag::Suppress
602600
: MVMContext::ResizeEventFlag::IfNecessary);
603601

layout/base/PresShell.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,6 @@ void PresShell::sPaintSuppressionCallback(nsITimer* aTimer, void* aPresShell) {
18381838
}
18391839

18401840
nsresult PresShell::ResizeReflow(nscoord aWidth, nscoord aHeight,
1841-
nscoord aOldWidth, nscoord aOldHeight,
18421841
ResizeReflowOptions aOptions) {
18431842
if (mZoomConstraintsClient) {
18441843
// If we have a ZoomConstraintsClient and the available screen area
@@ -1856,22 +1855,22 @@ nsresult PresShell::ResizeReflow(nscoord aWidth, nscoord aHeight,
18561855
return NS_OK;
18571856
}
18581857

1859-
return ResizeReflowIgnoreOverride(aWidth, aHeight, aOldWidth, aOldHeight,
1860-
aOptions);
1858+
return ResizeReflowIgnoreOverride(aWidth, aHeight, aOptions);
18611859
}
18621860

18631861
void PresShell::SimpleResizeReflow(nscoord aWidth, nscoord aHeight,
1864-
nscoord aOldWidth, nscoord aOldHeight) {
1862+
ResizeReflowOptions aOptions) {
18651863
MOZ_ASSERT(aWidth != NS_UNCONSTRAINEDSIZE);
18661864
MOZ_ASSERT(aHeight != NS_UNCONSTRAINEDSIZE);
1865+
nsSize oldSize = mPresContext->GetVisibleArea().Size();
18671866
mPresContext->SetVisibleArea(nsRect(0, 0, aWidth, aHeight));
18681867
nsIFrame* rootFrame = GetRootFrame();
18691868
if (!rootFrame) {
18701869
return;
18711870
}
18721871
WritingMode wm = rootFrame->GetWritingMode();
18731872
bool isBSizeChanging =
1874-
wm.IsVertical() ? aOldWidth != aWidth : aOldHeight != aHeight;
1873+
wm.IsVertical() ? oldSize.width != aWidth : oldSize.height != aHeight;
18751874
if (isBSizeChanging) {
18761875
nsLayoutUtils::MarkIntrinsicISizesDirtyIfDependentOnBSize(rootFrame);
18771876
}
@@ -1880,18 +1879,18 @@ void PresShell::SimpleResizeReflow(nscoord aWidth, nscoord aHeight,
18801879

18811880
// For compat with the old code path which always reflowed as long as there
18821881
// was a root frame.
1883-
if (!mPresContext->SuppressingResizeReflow()) {
1882+
bool suppressReflow = (aOptions & ResizeReflowOptions::SuppressReflow) ||
1883+
mPresContext->SuppressingResizeReflow();
1884+
if (!suppressReflow) {
18841885
mDocument->FlushPendingNotifications(FlushType::InterruptibleLayout);
18851886
}
18861887
}
18871888

18881889
nsresult PresShell::ResizeReflowIgnoreOverride(nscoord aWidth, nscoord aHeight,
1889-
nscoord aOldWidth,
1890-
nscoord aOldHeight,
18911890
ResizeReflowOptions aOptions) {
18921891
MOZ_ASSERT(!mIsReflowing, "Shouldn't be in reflow here!");
1893-
1894-
if (aWidth == aOldWidth && aHeight == aOldHeight) {
1892+
nsSize oldSize = mPresContext->GetVisibleArea().Size();
1893+
if (oldSize == nsSize(aWidth, aHeight)) {
18951894
return NS_OK;
18961895
}
18971896

@@ -1911,12 +1910,13 @@ nsresult PresShell::ResizeReflowIgnoreOverride(nscoord aWidth, nscoord aHeight,
19111910
};
19121911

19131912
if (!(aOptions & ResizeReflowOptions::BSizeLimit)) {
1914-
SimpleResizeReflow(aWidth, aHeight, aOldWidth, aOldHeight);
1913+
SimpleResizeReflow(aWidth, aHeight, aOptions);
19151914
postResizeEventIfNeeded();
19161915
return NS_OK;
19171916
}
19181917

1919-
MOZ_ASSERT(!mPresContext->SuppressingResizeReflow(),
1918+
MOZ_ASSERT(!mPresContext->SuppressingResizeReflow() &&
1919+
!(aOptions & ResizeReflowOptions::SuppressReflow),
19201920
"Can't suppress resize reflow and shrink-wrap at the same time");
19211921

19221922
// Make sure that style is flushed before setting the pres context

layout/base/PresShell.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,20 +344,17 @@ class PresShell final : public nsStubDocumentObserver,
344344
* coordinates for aWidth and aHeight must be in standard nscoord's.
345345
*/
346346
MOZ_CAN_RUN_SCRIPT nsresult
347-
ResizeReflow(nscoord aWidth, nscoord aHeight, nscoord aOldWidth = 0,
348-
nscoord aOldHeight = 0,
349-
ResizeReflowOptions aOptions = ResizeReflowOptions::NoOption);
347+
ResizeReflow(nscoord aWidth, nscoord aHeight,
348+
ResizeReflowOptions = ResizeReflowOptions::NoOption);
350349
MOZ_CAN_RUN_SCRIPT nsresult ResizeReflowIgnoreOverride(
351-
nscoord aWidth, nscoord aHeight, nscoord aOldWidth, nscoord aOldHeight,
352-
ResizeReflowOptions aOptions = ResizeReflowOptions::NoOption);
350+
nscoord aWidth, nscoord aHeight, ResizeReflowOptions);
353351

354352
private:
355353
/**
356354
* This is what ResizeReflowIgnoreOverride does when not shrink-wrapping (that
357355
* is, when ResizeReflowOptions::BSizeLimit is not specified).
358356
*/
359-
void SimpleResizeReflow(nscoord aWidth, nscoord aHeight, nscoord aOldWidth,
360-
nscoord aOldHeight);
357+
void SimpleResizeReflow(nscoord aWidth, nscoord aHeight, ResizeReflowOptions);
361358

362359
public:
363360
/**

layout/base/PresShellForwards.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ enum class ResizeReflowOptions : uint32_t {
4141
// additional reflow to zoom the content by the initial-scale or auto scaling
4242
// and we don't want any resize events during the initial paint.
4343
SuppressResizeEvent = 1 << 1,
44+
// Invalidate layout, but don't reflow.
45+
//
46+
// TODO(emilio): Ideally this should just become the default, or we should
47+
// unconditionally not reflow and rely on the caller to do so, having a
48+
// separate API for shrink-to-fit.
49+
SuppressReflow = 1 << 2,
4450
};
4551

4652
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(ResizeReflowOptions)

layout/base/nsDocumentViewer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3176,7 +3176,7 @@ nsresult nsDocumentViewer::GetContentSizeInternal(int32_t* aWidth,
31763176
prefWidth = aMaxWidth;
31773177
}
31783178

3179-
nsresult rv = presShell->ResizeReflow(prefWidth, aMaxHeight, 0, 0,
3179+
nsresult rv = presShell->ResizeReflow(prefWidth, aMaxHeight,
31803180
ResizeReflowOptions::BSizeLimit);
31813181
NS_ENSURE_SUCCESS(rv, rv);
31823182

0 commit comments

Comments
 (0)