mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 21:00:50 +00:00
Bug 1270019 - Add a SetRestoreResolution API for fennec's SessionRestore to use. r=rbarker
MozReview-Commit-ID: 7WqmgAkFItQ
This commit is contained in:
parent
fb874a938d
commit
b9e4a263e3
@ -496,6 +496,19 @@ nsDOMWindowUtils::SetResolutionAndScaleTo(float aResolution)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::SetRestoreResolution(float aResolution)
|
||||
{
|
||||
nsIPresShell* presShell = GetPresShell();
|
||||
if (!presShell) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
presShell->SetRestoreResolution(aResolution);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::GetResolution(float* aResolution)
|
||||
{
|
||||
|
@ -222,6 +222,13 @@ interface nsIDOMWindowUtils : nsISupports {
|
||||
*/
|
||||
void setResolutionAndScaleTo(in float aResolution);
|
||||
|
||||
/**
|
||||
* Set a resolution on the presShell which is the "restored" from history.
|
||||
* This resolution should be used when painting for the first time. Calling
|
||||
* this too late may have no effect.
|
||||
*/
|
||||
void setRestoreResolution(in float aResolution);
|
||||
|
||||
/**
|
||||
* Whether the resolution has been set by the user.
|
||||
* This gives a way to check whether the provided resolution is the default
|
||||
|
@ -84,6 +84,12 @@ MobileViewportManager::Destroy()
|
||||
mPresShell = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
MobileViewportManager::SetRestoreResolution(float aResolution)
|
||||
{
|
||||
mRestoreResolution = Some(aResolution);
|
||||
}
|
||||
|
||||
void
|
||||
MobileViewportManager::RequestReflow()
|
||||
{
|
||||
@ -145,6 +151,22 @@ MobileViewportManager::SetInitialViewport()
|
||||
RefreshViewportSize(false);
|
||||
}
|
||||
|
||||
CSSToScreenScale
|
||||
MobileViewportManager::ClampZoom(const CSSToScreenScale& aZoom,
|
||||
const nsViewportInfo& aViewportInfo)
|
||||
{
|
||||
CSSToScreenScale zoom = aZoom;
|
||||
if (zoom < aViewportInfo.GetMinZoom()) {
|
||||
zoom = aViewportInfo.GetMinZoom();
|
||||
MVM_LOG("%p: Clamped to %f\n", this, zoom.scale);
|
||||
}
|
||||
if (zoom > aViewportInfo.GetMaxZoom()) {
|
||||
zoom = aViewportInfo.GetMaxZoom();
|
||||
MVM_LOG("%p: Clamped to %f\n", this, zoom.scale);
|
||||
}
|
||||
return zoom;
|
||||
}
|
||||
|
||||
CSSToScreenScale
|
||||
MobileViewportManager::UpdateResolution(const nsViewportInfo& aViewportInfo,
|
||||
const ScreenIntSize& aDisplaySize,
|
||||
@ -156,18 +178,18 @@ MobileViewportManager::UpdateResolution(const nsViewportInfo& aViewportInfo,
|
||||
LayoutDeviceToLayerScale res(mPresShell->GetResolution());
|
||||
|
||||
if (mIsFirstPaint) {
|
||||
CSSToScreenScale defaultZoom = aViewportInfo.GetDefaultZoom();
|
||||
MVM_LOG("%p: default zoom from viewport is %f\n", this, defaultZoom.scale);
|
||||
if (!aViewportInfo.IsDefaultZoomValid()) {
|
||||
defaultZoom = MaxScaleRatio(ScreenSize(aDisplaySize), aViewport);
|
||||
MVM_LOG("%p: Intrinsic computed zoom is %f\n", this, defaultZoom.scale);
|
||||
if (defaultZoom < aViewportInfo.GetMinZoom()) {
|
||||
defaultZoom = aViewportInfo.GetMinZoom();
|
||||
MVM_LOG("%p: Clamped to %f\n", this, defaultZoom.scale);
|
||||
}
|
||||
if (defaultZoom > aViewportInfo.GetMaxZoom()) {
|
||||
defaultZoom = aViewportInfo.GetMaxZoom();
|
||||
MVM_LOG("%p: Clamped to %f\n", this, defaultZoom.scale);
|
||||
CSSToScreenScale defaultZoom;
|
||||
if (mRestoreResolution) {
|
||||
defaultZoom = CSSToScreenScale(mRestoreResolution.value() * cssToDev.scale);
|
||||
MVM_LOG("%p: restored zoom is %f\n", this, defaultZoom.scale);
|
||||
defaultZoom = ClampZoom(defaultZoom, aViewportInfo);
|
||||
} else {
|
||||
defaultZoom = aViewportInfo.GetDefaultZoom();
|
||||
MVM_LOG("%p: default zoom from viewport is %f\n", this, defaultZoom.scale);
|
||||
if (!aViewportInfo.IsDefaultZoomValid()) {
|
||||
defaultZoom = MaxScaleRatio(ScreenSize(aDisplaySize), aViewport);
|
||||
MVM_LOG("%p: Intrinsic computed zoom is %f\n", this, defaultZoom.scale);
|
||||
defaultZoom = ClampZoom(defaultZoom, aViewportInfo);
|
||||
}
|
||||
}
|
||||
MOZ_ASSERT(aViewportInfo.GetMinZoom() <= defaultZoom &&
|
||||
|
@ -27,6 +27,11 @@ public:
|
||||
nsIDocument* aDocument);
|
||||
void Destroy();
|
||||
|
||||
/* Provide a resolution to use during the first paint instead of the default
|
||||
* resolution computed from the viewport info metadata. This is in the same
|
||||
* "units" as the argument to nsDOMWindowUtils::SetResolutionAndScaleTo. */
|
||||
void SetRestoreResolution(float aResolution);
|
||||
|
||||
/* Notify the MobileViewportManager that a reflow was requested in the
|
||||
* presShell.*/
|
||||
void RequestReflow();
|
||||
@ -49,6 +54,10 @@ private:
|
||||
/* Secondary main helper method to update just the SPCSPS. */
|
||||
void RefreshSPCSPS();
|
||||
|
||||
/* Helper to clamp the given zoom by the min/max in the viewport info. */
|
||||
mozilla::CSSToScreenScale ClampZoom(const mozilla::CSSToScreenScale& aZoom,
|
||||
const nsViewportInfo& aViewportInfo);
|
||||
|
||||
/* Updates the presShell resolution and returns the new zoom. */
|
||||
mozilla::CSSToScreenScale UpdateResolution(const nsViewportInfo& aViewportInfo,
|
||||
const mozilla::ScreenIntSize& aDisplaySize,
|
||||
@ -67,6 +76,7 @@ private:
|
||||
bool mPainted;
|
||||
mozilla::LayoutDeviceIntSize mDisplaySize;
|
||||
mozilla::CSSSize mMobileViewportSize;
|
||||
mozilla::Maybe<float> mRestoreResolution;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1435,6 +1435,12 @@ public:
|
||||
*/
|
||||
virtual bool ScaleToResolution() const = 0;
|
||||
|
||||
/**
|
||||
* Used by session restore code to restore a resolution before the first
|
||||
* paint.
|
||||
*/
|
||||
virtual void SetRestoreResolution(float aResolution) = 0;
|
||||
|
||||
/**
|
||||
* Returns whether we are in a DrawWindow() call that used the
|
||||
* DRAWWINDOW_DO_NOT_FLUSH flag.
|
||||
|
@ -5565,6 +5565,13 @@ float PresShell::GetCumulativeNonRootScaleResolution()
|
||||
return resolution;
|
||||
}
|
||||
|
||||
void PresShell::SetRestoreResolution(float aResolution)
|
||||
{
|
||||
if (mMobileViewportManager) {
|
||||
mMobileViewportManager->SetRestoreResolution(aResolution);
|
||||
}
|
||||
}
|
||||
|
||||
void PresShell::SetRenderingState(const RenderingState& aState)
|
||||
{
|
||||
if (mRenderFlags != aState.mRenderFlags) {
|
||||
|
@ -232,6 +232,7 @@ public:
|
||||
virtual bool ScaleToResolution() const override;
|
||||
virtual float GetCumulativeResolution() override;
|
||||
virtual float GetCumulativeNonRootScaleResolution() override;
|
||||
virtual void SetRestoreResolution(float aResolution) override;
|
||||
|
||||
//nsIViewObserver interface
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user