Bug 948377 - Remove unwanted rounding in CalculateCompositedRectInCssPixels; add a CalculateCompositedSizeInCssPixels also. r=botond

This commit is contained in:
Kartikaya Gupta 2014-03-28 10:36:47 -04:00
parent 002131ebed
commit 31afc0a194
8 changed files with 51 additions and 35 deletions

View File

@ -288,7 +288,7 @@ TabChildBase::HandlePossibleViewportChange()
metrics.mResolution = metrics.mCumulativeResolution / LayoutDeviceToParentLayerScale(1);
utils->SetResolution(metrics.mResolution.scale, metrics.mResolution.scale);
CSSSize scrollPort = CSSSize(metrics.CalculateCompositedRectInCssPixels().Size());
CSSSize scrollPort = metrics.CalculateCompositedSizeInCssPixels();
utils->SetScrollPositionClampingScrollPortSize(scrollPort.width, scrollPort.height);
// The call to GetPageSize forces a resize event to content, so we need to
@ -424,7 +424,7 @@ TabChildBase::ProcessUpdateFrame(const FrameMetrics& aFrameMetrics)
FrameMetrics newMetrics = aFrameMetrics;
APZCCallbackHelper::UpdateRootFrame(utils, newMetrics);
CSSRect cssCompositedRect = CSSRect(newMetrics.CalculateCompositedRectInCssPixels());
CSSSize cssCompositedSize = newMetrics.CalculateCompositedSizeInCssPixels();
// The BrowserElementScrolling helper must know about these updated metrics
// for other functions it performs, such as double tap handling.
// Note, %f must not be used because it is locale specific!
@ -453,9 +453,9 @@ TabChildBase::ProcessUpdateFrame(const FrameMetrics& aFrameMetrics)
data.AppendPrintf(" }");
data.AppendLiteral(", \"cssCompositedRect\" : ");
data.AppendLiteral("{ \"width\" : ");
data.AppendFloat(cssCompositedRect.width);
data.AppendFloat(cssCompositedSize.width);
data.AppendLiteral(", \"height\" : ");
data.AppendFloat(cssCompositedRect.height);
data.AppendFloat(cssCompositedSize.height);
data.AppendLiteral(" }");
data.AppendLiteral(" }");

View File

@ -162,17 +162,17 @@ public:
CSSRect GetExpandedScrollableRect() const
{
CSSRect scrollableRect = mScrollableRect;
CSSRect compBounds = CSSRect(CalculateCompositedRectInCssPixels());
if (scrollableRect.width < compBounds.width) {
CSSSize compSize = CalculateCompositedSizeInCssPixels();
if (scrollableRect.width < compSize.width) {
scrollableRect.x = std::max(0.f,
scrollableRect.x - (compBounds.width - scrollableRect.width));
scrollableRect.width = compBounds.width;
scrollableRect.x - (compSize.width - scrollableRect.width));
scrollableRect.width = compSize.width;
}
if (scrollableRect.height < compBounds.height) {
if (scrollableRect.height < compSize.height) {
scrollableRect.y = std::max(0.f,
scrollableRect.y - (compBounds.height - scrollableRect.height));
scrollableRect.height = compBounds.height;
scrollableRect.y - (compSize.height - scrollableRect.height));
scrollableRect.height = compSize.height;
}
return scrollableRect;
@ -195,9 +195,14 @@ public:
return mZoom * mTransformScale;
}
CSSIntRect CalculateCompositedRectInCssPixels() const
CSSSize CalculateCompositedSizeInCssPixels() const
{
return gfx::RoundedIn(mCompositionBounds / GetZoomToParent());
return mCompositionBounds.Size() / GetZoomToParent();
}
CSSRect CalculateCompositedRectInCssPixels() const
{
return mCompositionBounds / GetZoomToParent();
}
void ScrollBy(const CSSPoint& aPoint)

View File

@ -241,7 +241,7 @@ bool
SharedFrameMetricsHelper::AboutToCheckerboard(const FrameMetrics& aContentMetrics,
const FrameMetrics& aCompositorMetrics)
{
return !aContentMetrics.mDisplayPort.Contains(CSSRect(aCompositorMetrics.CalculateCompositedRectInCssPixels()) - aCompositorMetrics.GetScrollOffset());
return !aContentMetrics.mDisplayPort.Contains(aCompositorMetrics.CalculateCompositedRectInCssPixels() - aCompositorMetrics.GetScrollOffset());
}
ClientTiledLayerBuffer::ClientTiledLayerBuffer(ClientTiledThebesLayer* aThebesLayer,

View File

@ -619,12 +619,12 @@ AsyncCompositionManager::ApplyAsyncTransformToScrollbar(ContainerLayer* aLayer)
Matrix4x4 scrollbarTransform;
if (aLayer->GetScrollbarDirection() == Layer::VERTICAL) {
float scale = metrics.CalculateCompositedRectInCssPixels().height / metrics.mScrollableRect.height;
float scale = metrics.CalculateCompositedSizeInCssPixels().height / metrics.mScrollableRect.height;
scrollbarTransform = scrollbarTransform * Matrix4x4().Scale(1.f, 1.f / transientTransform.GetYScale(), 1.f);
scrollbarTransform = scrollbarTransform * Matrix4x4().Translate(0, -transientTransform._42 * scale, 0);
}
if (aLayer->GetScrollbarDirection() == Layer::HORIZONTAL) {
float scale = metrics.CalculateCompositedRectInCssPixels().width / metrics.mScrollableRect.width;
float scale = metrics.CalculateCompositedSizeInCssPixels().width / metrics.mScrollableRect.width;
scrollbarTransform = scrollbarTransform * Matrix4x4().Scale(1.f / transientTransform.GetXScale(), 1.f, 1.f);
scrollbarTransform = scrollbarTransform * Matrix4x4().Translate(-transientTransform._41 * scale, 0, 0);
}

View File

@ -1427,7 +1427,7 @@ const LayerMargin AsyncPanZoomController::CalculatePendingDisplayPort(
const ScreenPoint& aVelocity,
double aEstimatedPaintDuration)
{
CSSRect compositionBounds(aFrameMetrics.CalculateCompositedRectInCssPixels());
CSSSize compositionBounds = aFrameMetrics.CalculateCompositedSizeInCssPixels();
CSSSize compositionSize = aFrameMetrics.GetRootCompositionSize();
compositionSize =
CSSSize(std::min(compositionBounds.width, compositionSize.width),
@ -1679,10 +1679,10 @@ ViewTransform AsyncPanZoomController::GetCurrentAsyncTransform() {
// within rendered content.
if (!gAllowCheckerboarding &&
!mLastContentPaintMetrics.mDisplayPort.IsEmpty()) {
CSSRect compositedRect(mLastContentPaintMetrics.CalculateCompositedRectInCssPixels());
CSSSize compositedSize = mLastContentPaintMetrics.CalculateCompositedSizeInCssPixels();
CSSPoint maxScrollOffset = lastPaintScrollOffset +
CSSPoint(mLastContentPaintMetrics.mDisplayPort.XMost() - compositedRect.width,
mLastContentPaintMetrics.mDisplayPort.YMost() - compositedRect.height);
CSSPoint(mLastContentPaintMetrics.mDisplayPort.XMost() - compositedSize.width,
mLastContentPaintMetrics.mDisplayPort.YMost() - compositedSize.height);
CSSPoint minScrollOffset = lastPaintScrollOffset + mLastContentPaintMetrics.mDisplayPort.TopLeft();
if (minScrollOffset.x < maxScrollOffset.x) {
@ -1868,11 +1868,11 @@ void AsyncPanZoomController::ZoomToRect(CSSRect aRect) {
if (aRect.IsEmpty() ||
(currentZoom == localMaxZoom && targetZoom >= localMaxZoom) ||
(currentZoom == localMinZoom && targetZoom <= localMinZoom)) {
CSSRect compositedRect = CSSRect(mFrameMetrics.CalculateCompositedRectInCssPixels());
CSSSize compositedSize = mFrameMetrics.CalculateCompositedSizeInCssPixels();
float y = scrollOffset.y;
float newHeight =
cssPageRect.width * (compositedRect.height / compositedRect.width);
float dh = compositedRect.height - newHeight;
cssPageRect.width * (compositedSize.height / compositedSize.width);
float dh = compositedSize.height - newHeight;
aRect = CSSRect(0.0f,
y + dh/2,
@ -1888,16 +1888,16 @@ void AsyncPanZoomController::ZoomToRect(CSSRect aRect) {
endZoomToMetrics.SetZoom(targetZoom / mFrameMetrics.mTransformScale);
// Adjust the zoomToRect to a sensible position to prevent overscrolling.
CSSRect rectAfterZoom = CSSRect(endZoomToMetrics.CalculateCompositedRectInCssPixels());
CSSSize sizeAfterZoom = endZoomToMetrics.CalculateCompositedSizeInCssPixels();
// If either of these conditions are met, the page will be
// overscrolled after zoomed
if (aRect.y + rectAfterZoom.height > cssPageRect.height) {
aRect.y = cssPageRect.height - rectAfterZoom.height;
if (aRect.y + sizeAfterZoom.height > cssPageRect.height) {
aRect.y = cssPageRect.height - sizeAfterZoom.height;
aRect.y = aRect.y > 0 ? aRect.y : 0;
}
if (aRect.x + rectAfterZoom.width > cssPageRect.width) {
aRect.x = cssPageRect.width - rectAfterZoom.width;
if (aRect.x + sizeAfterZoom.width > cssPageRect.width) {
aRect.x = cssPageRect.width - sizeAfterZoom.width;
aRect.x = aRect.x > 0 ? aRect.x : 0;
}
@ -2099,7 +2099,7 @@ void AsyncPanZoomController::SendAsyncScrollEvent() {
isRoot = mFrameMetrics.mIsRoot;
scrollableSize = mFrameMetrics.mScrollableRect.Size();
contentRect = CSSRect(mFrameMetrics.CalculateCompositedRectInCssPixels());
contentRect = mFrameMetrics.CalculateCompositedRectInCssPixels();
contentRect.MoveTo(mCurrentAsyncScrollOffset);
}

View File

@ -274,8 +274,7 @@ float Axis::GetOrigin() {
float Axis::GetCompositionLength() {
const FrameMetrics& metrics = mAsyncPanZoomController->GetFrameMetrics();
CSSRect cssCompositedRect = CSSRect(metrics.CalculateCompositedRectInCssPixels());
return GetRectLength(cssCompositedRect);
return GetRectLength(metrics.CalculateCompositedRectInCssPixels());
}
float Axis::GetPageStart() {

View File

@ -261,6 +261,18 @@ gfx::SizeTyped<dst> operator/(const gfx::SizeTyped<src>& aSize, const gfx::Scale
aSize.height / aScale.scale);
}
template<class src, class dst>
gfx::SizeTyped<dst> operator*(const gfx::IntSizeTyped<src>& aSize, const gfx::ScaleFactor<src, dst>& aScale) {
return gfx::SizeTyped<dst>(float(aSize.width) * aScale.scale,
float(aSize.height) * aScale.scale);
}
template<class src, class dst>
gfx::SizeTyped<dst> operator/(const gfx::IntSizeTyped<src>& aSize, const gfx::ScaleFactor<dst, src>& aScale) {
return gfx::SizeTyped<dst>(float(aSize.width) / aScale.scale,
float(aSize.height) / aScale.scale);
}
template<class src, class dst>
gfx::MarginTyped<dst> operator*(const gfx::MarginTyped<src>& aMargin, const gfx::ScaleFactor<src, dst>& aScale) {
return gfx::MarginTyped<dst>(aMargin.top * aScale.scale,

View File

@ -104,9 +104,9 @@ static void
RecenterDisplayPort(mozilla::layers::FrameMetrics& aFrameMetrics)
{
if (!aFrameMetrics.GetUseDisplayPortMargins()) {
CSSRect compositionBounds(aFrameMetrics.CalculateCompositedRectInCssPixels());
aFrameMetrics.mDisplayPort.x = (compositionBounds.width - aFrameMetrics.mDisplayPort.width) / 2;
aFrameMetrics.mDisplayPort.y = (compositionBounds.height - aFrameMetrics.mDisplayPort.height) / 2;
CSSSize compositionSize = aFrameMetrics.CalculateCompositedSizeInCssPixels();
aFrameMetrics.mDisplayPort.x = (compositionSize.width - aFrameMetrics.mDisplayPort.width) / 2;
aFrameMetrics.mDisplayPort.y = (compositionSize.height - aFrameMetrics.mDisplayPort.height) / 2;
} else {
LayerMargin margins = aFrameMetrics.GetDisplayPortMargins();
margins.right = margins.left = margins.LeftRight() / 2;
@ -175,7 +175,7 @@ APZCCallbackHelper::UpdateRootFrame(nsIDOMWindowUtils* aUtils,
// be 1000 pixels long but the frame would still be 100 pixels, and so the maximum
// scroll range would be 900. Therefore this calculation depends on the zoom applied
// to the content relative to the container.
CSSSize scrollPort = CSSSize(aMetrics.CalculateCompositedRectInCssPixels().Size());
CSSSize scrollPort = aMetrics.CalculateCompositedSizeInCssPixels();
aUtils->SetScrollPositionClampingScrollPortSize(scrollPort.width, scrollPort.height);
// Scroll the window to the desired spot