From 529616ef3a6d15c3d4a7d9654e7a1ee77aa7db4a Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Sun, 30 Dec 2018 02:16:42 +0000 Subject: [PATCH] Bug 1516368 - Change SetResolutionAndScaleTo to take an enum instead of an nsAtoms*. r=botond There is no reason to use nsAtoms*, it's error prone, i.e. the function can take arbitrary nsAtoms*. Depends on D15339 Differential Revision: https://phabricator.services.mozilla.com/D15340 --HG-- extra : moz-landing-system : lando --- dom/base/nsDOMWindowUtils.cpp | 3 ++- dom/base/nsDocument.cpp | 5 +++-- gfx/layers/apz/util/APZCCallbackHelper.cpp | 3 ++- layout/base/MobileViewportManager.cpp | 3 ++- layout/base/PresShell.cpp | 4 ++-- layout/base/PresShell.h | 3 ++- layout/base/nsIPresShell.h | 13 +++++++++---- layout/generic/nsGfxScrollFrame.cpp | 2 +- 8 files changed, 23 insertions(+), 13 deletions(-) diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index bb936c4bf41c..ca0ea768e701 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -548,7 +548,8 @@ nsDOMWindowUtils::SetResolutionAndScaleTo(float aResolution) { return NS_ERROR_FAILURE; } - presShell->SetResolutionAndScaleTo(aResolution, nsGkAtoms::other); + presShell->SetResolutionAndScaleTo(aResolution, + nsIPresShell::ChangeOrigin::eOther); return NS_OK; } diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 9b0da7c0e9f4..180bf662b41f 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -10148,7 +10148,8 @@ void nsIDocument::CleanupFullscreenState() { // Restore the zoom level that was in place prior to entering fullscreen. if (nsIPresShell* shell = GetShell()) { if (shell->GetMobileViewportManager()) { - shell->SetResolutionAndScaleTo(mSavedResolution, nsGkAtoms::restore); + shell->SetResolutionAndScaleTo(mSavedResolution, + nsIPresShell::ChangeOrigin::eRestore); } } @@ -10546,7 +10547,7 @@ bool nsIDocument::ApplyFullscreen(UniquePtr aRequest) { // Save the previous resolution so it can be restored. child->mSavedResolution = shell->GetResolution(); shell->SetResolutionAndScaleTo(manager->ComputeIntrinsicResolution(), - nsGkAtoms::other); + nsIPresShell::ChangeOrigin::eOther); } } diff --git a/gfx/layers/apz/util/APZCCallbackHelper.cpp b/gfx/layers/apz/util/APZCCallbackHelper.cpp index 2a6e43040cc7..8262b160b063 100644 --- a/gfx/layers/apz/util/APZCCallbackHelper.cpp +++ b/gfx/layers/apz/util/APZCCallbackHelper.cpp @@ -318,7 +318,8 @@ void APZCCallbackHelper::UpdateRootFrame(const RepaintRequest& aRequest) { // last paint. presShellResolution = aRequest.GetPresShellResolution() * aRequest.GetAsyncZoom().scale; - shell->SetResolutionAndScaleTo(presShellResolution, nsGkAtoms::apz); + shell->SetResolutionAndScaleTo(presShellResolution, + nsIPresShell::ChangeOrigin::eApz); } // Do this as late as possible since scrolling can flush layout. It also diff --git a/layout/base/MobileViewportManager.cpp b/layout/base/MobileViewportManager.cpp index 8ee734bd89a6..b856c4046566 100644 --- a/layout/base/MobileViewportManager.cpp +++ b/layout/base/MobileViewportManager.cpp @@ -329,7 +329,8 @@ void MobileViewportManager::UpdateResolution( if (newZoom) { LayoutDeviceToLayerScale resolution = ZoomToResolution(*newZoom, cssToDev); MVM_LOG("%p: setting resolution %f\n", this, resolution.scale); - mPresShell->SetResolutionAndScaleTo(resolution.scale, nsGkAtoms::other); + mPresShell->SetResolutionAndScaleTo(resolution.scale, + nsIPresShell::ChangeOrigin::eOther); MVM_LOG("%p: New zoom is %f\n", this, newZoom->scale); } diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index 721cc8a5f06f..8d45fe0cb220 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -5157,7 +5157,7 @@ void PresShell::SetIgnoreViewportScrolling(bool aIgnore) { } nsresult PresShell::SetResolutionAndScaleTo(float aResolution, - nsAtom* aOrigin) { + ChangeOrigin aOrigin) { if (!(aResolution > 0.0)) { return NS_ERROR_ILLEGAL_VALUE; } @@ -5171,7 +5171,7 @@ nsresult PresShell::SetResolutionAndScaleTo(float aResolution, if (mMobileViewportManager) { mMobileViewportManager->ResolutionUpdated(); } - if (aOrigin != nsGkAtoms::apz) { + if (aOrigin != ChangeOrigin::eApz) { mResolutionUpdated = true; } if (auto* window = nsGlobalWindowInner::Cast(mDocument->GetInnerWindow())) { diff --git a/layout/base/PresShell.h b/layout/base/PresShell.h index b17efe5756c1..246312c0bb5e 100644 --- a/layout/base/PresShell.h +++ b/layout/base/PresShell.h @@ -195,7 +195,8 @@ class PresShell final : public nsIPresShell, void SetIgnoreViewportScrolling(bool aIgnore) override; - nsresult SetResolutionAndScaleTo(float aResolution, nsAtom* aOrigin) override; + nsresult SetResolutionAndScaleTo(float aResolution, + ChangeOrigin aOrigin) override; bool IsResolutionUpdated() const override { return mResolutionUpdated; } void SetResolutionUpdated(bool aUpdated) override { mResolutionUpdated = aUpdated; diff --git a/layout/base/nsIPresShell.h b/layout/base/nsIPresShell.h index e4d1af0006d1..96e31479b202 100644 --- a/layout/base/nsIPresShell.h +++ b/layout/base/nsIPresShell.h @@ -1371,12 +1371,17 @@ class nsIPresShell : public nsStubDocumentObserver { * The resolution defaults to 1.0. * * |aOrigin| specifies who originated the resolution change. For changes - * sent by APZ, pass nsGkAtoms::apz. For changes sent by the main thread, - * use pass nsGkAtoms::other or nsGkAtoms::restore (similar to the |aOrigin| - * parameter of nsIScrollableFrame::ScrollToCSSPixels()). + * sent by APZ, pass ChangeOrigin::eApz. For changes sent by the main thread, + * use pass ChangeOrigin::Other or ChangeOrigin::Restore (similar to the + * |aOrigin| parameter of nsIScrollableFrame::ScrollToCSSPixels()). */ + enum class ChangeOrigin : uint8_t { + eApz, + eRestore, + eOther, + }; virtual nsresult SetResolutionAndScaleTo(float aResolution, - nsAtom* aOrigin) = 0; + ChangeOrigin aOrigin) = 0; float GetResolution() const { return mResolution.valueOr(1.0); } virtual float GetCumulativeResolution() = 0; diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index ac14a999a1dd..0f5c889379d6 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -6162,7 +6162,7 @@ void ScrollFrameHelper::RestoreState(PresState* aState) { if (mIsRoot) { nsIPresShell* presShell = mOuter->PresShell(); presShell->SetResolutionAndScaleTo(aState->resolution(), - nsGkAtoms::restore); + nsIPresShell::ChangeOrigin::eRestore); } }