Bug 968991 - Only initialize the root metrics after getting both before-first-paint and the mInnerSize dimensions. r=botond

This commit is contained in:
Kartikaya Gupta 2014-02-21 18:12:43 -05:00
Родитель dda1d29077
Коммит 1ac3aca311
2 изменённых файлов: 50 добавлений и 20 удалений

Просмотреть файл

@ -316,6 +316,32 @@ TabChild::HandleEvent(nsIDOMEvent* aEvent)
return NS_OK;
}
void
TabChild::InitializeRootMetrics()
{
// Calculate a really simple resolution that we probably won't
// be keeping, as well as putting the scroll offset back to
// the top-left of the page.
mLastRootMetrics.mViewport = CSSRect(CSSPoint(), kDefaultViewportSize);
mLastRootMetrics.mCompositionBounds = ScreenIntRect(ScreenIntPoint(), mInnerSize);
mLastRootMetrics.mZoom = mLastRootMetrics.CalculateIntrinsicScale();
mLastRootMetrics.mDevPixelsPerCSSPixel = mWidget->GetDefaultScale();
// We use ScreenToLayerScale(1) below in order to turn the
// async zoom amount into the gecko zoom amount.
mLastRootMetrics.mCumulativeResolution =
mLastRootMetrics.mZoom / mLastRootMetrics.mDevPixelsPerCSSPixel * ScreenToLayerScale(1);
// This is the root layer, so the cumulative resolution is the same
// as the resolution.
mLastRootMetrics.mResolution = mLastRootMetrics.mCumulativeResolution / LayoutDeviceToParentLayerScale(1);
mLastRootMetrics.mScrollOffset = CSSPoint(0, 0);
}
bool
TabChild::HasValidInnerSize()
{
return (mInnerSize.width != 0) && (mInnerSize.height != 0);
}
NS_IMETHODIMP
TabChild::Observe(nsISupports *aSubject,
const char *aTopic,
@ -352,26 +378,16 @@ TabChild::Observe(nsISupports *aSubject,
// page.
SetCSSViewport(kDefaultViewportSize);
// Calculate a really simple resolution that we probably won't
// be keeping, as well as putting the scroll offset back to
// the top-left of the page.
mLastRootMetrics.mViewport = CSSRect(CSSPoint(), kDefaultViewportSize);
mLastRootMetrics.mCompositionBounds = ScreenIntRect(ScreenIntPoint(), mInnerSize);
mLastRootMetrics.mZoom = mLastRootMetrics.CalculateIntrinsicScale();
mLastRootMetrics.mDevPixelsPerCSSPixel = mWidget->GetDefaultScale();
// We use ScreenToLayerScale(1) below in order to turn the
// async zoom amount into the gecko zoom amount.
mLastRootMetrics.mCumulativeResolution =
mLastRootMetrics.mZoom / mLastRootMetrics.mDevPixelsPerCSSPixel * ScreenToLayerScale(1);
// This is the root layer, so the cumulative resolution is the same
// as the resolution.
mLastRootMetrics.mResolution = mLastRootMetrics.mCumulativeResolution / LayoutDeviceToParentLayerScale(1);
mLastRootMetrics.mScrollOffset = CSSPoint(0, 0);
utils->SetResolution(mLastRootMetrics.mResolution.scale,
mLastRootMetrics.mResolution.scale);
HandlePossibleViewportChange();
// In some cases before-first-paint gets called before
// RecvUpdateDimensions is called and therefore before we have an
// mInnerSize value set. In such cases defer initializing the viewport
// until we we get an inner size.
if (HasValidInnerSize()) {
InitializeRootMetrics();
utils->SetResolution(mLastRootMetrics.mResolution.scale,
mLastRootMetrics.mResolution.scale);
HandlePossibleViewportChange();
}
}
}
}
@ -1458,6 +1474,9 @@ TabChild::RecvUpdateDimensions(const nsRect& rect, const nsIntSize& size, const
mOuterRect.width = rect.width;
mOuterRect.height = rect.height;
bool initialSizing = !HasValidInnerSize()
&& (size.width != 0 && size.height != 0);
mOrientation = orientation;
mInnerSize = ScreenIntSize::FromUnknownSize(
gfx::IntSize(size.width, size.height));
@ -1468,6 +1487,14 @@ TabChild::RecvUpdateDimensions(const nsRect& rect, const nsIntSize& size, const
baseWin->SetPositionAndSize(0, 0, size.width, size.height,
true);
if (initialSizing && mContentDocumentIsDisplayed) {
// If this is the first time we're getting a valid mInnerSize, and the
// before-first-paint event has already been handled, then we need to set
// up our default viewport here. See the corresponding call to
// InitializeRootMetrics in the before-first-paint handler.
InitializeRootMetrics();
}
HandlePossibleViewportChange();
return true;

Просмотреть файл

@ -411,6 +411,9 @@ private:
nsresult Init();
void InitializeRootMetrics();
bool HasValidInnerSize();
// Notify others that our TabContext has been updated. (At the moment, this
// sets the appropriate app-id and is-browser flags on our docshell.)
//