Bug 944047 - Store the last FrameMetrics for sub-frames in TabChild. r=botond

As well as the root frame, make sure to store the last received FrameMetrics
for sub-frames in TabChild. This prevents us sending scroll events triggered
by the APZC back to the APZC.
This commit is contained in:
Chris Lord 2013-12-05 20:47:21 +00:00
Родитель 6d5ec9a183
Коммит 4cb7e3c097
2 изменённых файлов: 28 добавлений и 22 удалений

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

@ -322,21 +322,25 @@ TabChild::HandleEvent(nsIDOMEvent* aEvent)
CSSIntPoint scrollOffset = scrollFrame->GetScrollPositionCSSPixels();
if (viewId == mLastMetrics.mScrollId) {
// For the root frame, we store the last metrics, including the last
// scroll offset, sent by APZC. (This is updated in ProcessUpdateFrame()).
if (viewId == mLastRootMetrics.mScrollId) {
// We store the last metrics that was sent via the TabParent (This is
// updated in ProcessUpdateFrame and RecvUpdateFrame).
// We use this here to avoid sending APZC back a scroll event that
// originally came from APZC (besides being unnecessary, the event might
// be slightly out of date by the time it reaches APZC).
// We should probably do this for subframes, too.
if (RoundedToInt(mLastMetrics.mScrollOffset) == scrollOffset) {
if (RoundedToInt(mLastRootMetrics.mScrollOffset) == scrollOffset) {
return NS_OK;
}
// Update the last scroll offset now, otherwise RecvUpdateDimensions()
// might trigger a scroll to the old offset before RecvUpdateFrame()
// gets a chance to update it.
mLastMetrics.mScrollOffset = scrollOffset;
mLastRootMetrics.mScrollOffset = scrollOffset;
} else if (viewId == mLastSubFrameMetrics.mScrollId) {
if (RoundedToInt(mLastSubFrameMetrics.mScrollOffset) == scrollOffset) {
return NS_OK;
}
mLastSubFrameMetrics.mScrollOffset = scrollOffset;
}
SendUpdateScrollOffset(presShellId, viewId, scrollOffset);
@ -384,21 +388,21 @@ TabChild::Observe(nsISupports *aSubject,
// 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.
mLastMetrics.mViewport = CSSRect(CSSPoint(), kDefaultViewportSize);
mLastMetrics.mCompositionBounds = ScreenIntRect(ScreenIntPoint(), mInnerSize);
mLastMetrics.mZoom = mLastMetrics.CalculateIntrinsicScale();
mLastMetrics.mDevPixelsPerCSSPixel = mWidget->GetDefaultScale();
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.
mLastMetrics.mCumulativeResolution =
mLastMetrics.mZoom / mLastMetrics.mDevPixelsPerCSSPixel * ScreenToLayerScale(1);
mLastRootMetrics.mCumulativeResolution =
mLastRootMetrics.mZoom / mLastRootMetrics.mDevPixelsPerCSSPixel * ScreenToLayerScale(1);
// This is the root layer, so the cumulative resolution is the same
// as the resolution.
mLastMetrics.mResolution = mLastMetrics.mCumulativeResolution / LayoutDeviceToParentLayerScale(1);
mLastMetrics.mScrollOffset = CSSPoint(0, 0);
mLastRootMetrics.mResolution = mLastRootMetrics.mCumulativeResolution / LayoutDeviceToParentLayerScale(1);
mLastRootMetrics.mScrollOffset = CSSPoint(0, 0);
utils->SetResolution(mLastMetrics.mResolution.scale,
mLastMetrics.mResolution.scale);
utils->SetResolution(mLastRootMetrics.mResolution.scale,
mLastRootMetrics.mResolution.scale);
HandlePossibleViewportChange();
}
@ -554,7 +558,7 @@ TabChild::HandlePossibleViewportChange()
}
float oldBrowserWidth = mOldViewportWidth;
mLastMetrics.mViewport.SizeTo(viewport);
mLastRootMetrics.mViewport.SizeTo(viewport);
if (!oldBrowserWidth) {
oldBrowserWidth = kDefaultViewportSize.width;
}
@ -600,12 +604,12 @@ TabChild::HandlePossibleViewportChange()
return;
}
float oldScreenWidth = mLastMetrics.mCompositionBounds.width;
float oldScreenWidth = mLastRootMetrics.mCompositionBounds.width;
if (!oldScreenWidth) {
oldScreenWidth = mInnerSize.width;
}
FrameMetrics metrics(mLastMetrics);
FrameMetrics metrics(mLastRootMetrics);
metrics.mViewport = CSSRect(CSSPoint(), viewport);
metrics.mScrollableRect = CSSRect(CSSPoint(), pageSize);
metrics.mCompositionBounds = ScreenIntRect(ScreenIntPoint(), mInnerSize);
@ -1532,6 +1536,7 @@ TabChild::RecvUpdateFrame(const FrameMetrics& aFrameMetrics)
if (content) {
FrameMetrics newSubFrameMetrics(aFrameMetrics);
APZCCallbackHelper::UpdateSubFrame(content, newSubFrameMetrics);
mLastSubFrameMetrics = newSubFrameMetrics;
return true;
}
}
@ -1539,7 +1544,7 @@ TabChild::RecvUpdateFrame(const FrameMetrics& aFrameMetrics)
// We've recieved a message that is out of date and we want to ignore.
// However we can't reply without painting so we reply by painting the
// exact same thing as we did before.
return ProcessUpdateFrame(mLastMetrics);
return ProcessUpdateFrame(mLastRootMetrics);
}
bool
@ -1603,7 +1608,7 @@ TabChild::ProcessUpdateFrame(const FrameMetrics& aFrameMetrics)
DispatchMessageManagerMessage(NS_LITERAL_STRING("Viewport:Change"), data);
mLastMetrics = newMetrics;
mLastRootMetrics = newMetrics;
return true;
}

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

@ -463,7 +463,8 @@ private:
nsCOMPtr<nsIWebNavigation> mWebNav;
nsCOMPtr<nsIWidget> mWidget;
nsCOMPtr<nsIURI> mLastURI;
FrameMetrics mLastMetrics;
FrameMetrics mLastRootMetrics;
FrameMetrics mLastSubFrameMetrics;
RenderFrameChild* mRemoteFrame;
nsRefPtr<ContentChild> mManager;
nsRefPtr<TabChildGlobal> mTabChildGlobal;