Bug 890938 - Convert AsyncPanZoomController::ZoomToRect to take a CSSRect instead of a gfxRect. r=kats

This commit is contained in:
Botond Ballo 2013-07-11 10:43:35 -04:00
parent c2eedbfda2
commit e1a8133ba6
8 changed files with 27 additions and 29 deletions

View File

@ -27,8 +27,8 @@ include "mozilla/layers/CompositorTypes.h";
using IPC::Principal;
using gfxMatrix;
using gfxRect;
using gfxSize;
using CSSRect;
using mozilla::layers::FrameMetrics;
using mozilla::layout::ScrollingBehavior;
using mozilla::void_t;
@ -264,7 +264,7 @@ parent:
* Instructs the TabParent to forward a request to zoom to a rect given in
* CSS pixels. This rect is relative to the document.
*/
ZoomToRect(gfxRect aRect);
ZoomToRect(CSSRect aRect);
/**
* We know for sure that content has either preventDefaulted or not

View File

@ -325,9 +325,9 @@ TabChild::Observe(nsISupports *aSubject,
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aSubject));
nsCOMPtr<nsITabChild> tabChild(GetTabChildFrom(docShell));
if (tabChild == this) {
gfxRect rect;
CSSRect rect;
sscanf(NS_ConvertUTF16toUTF8(aData).get(),
"{\"x\":%lf,\"y\":%lf,\"w\":%lf,\"h\":%lf}",
"{\"x\":%f,\"y\":%f,\"w\":%f,\"h\":%f}",
&rect.x, &rect.y, &rect.width, &rect.height);
SendZoomToRect(rect);
}

View File

@ -1465,7 +1465,7 @@ TabParent::RecvPRenderFrameConstructor(PRenderFrameParent* actor,
}
bool
TabParent::RecvZoomToRect(const gfxRect& aRect)
TabParent::RecvZoomToRect(const CSSRect& aRect)
{
if (RenderFrameParent* rfp = GetRenderFrame()) {
rfp->ZoomToRect(aRect);

View File

@ -152,7 +152,7 @@ public:
virtual bool RecvGetDPI(float* aValue);
virtual bool RecvGetDefaultScale(double* aValue);
virtual bool RecvGetWidgetNativeData(WindowsHandle* aValue);
virtual bool RecvZoomToRect(const gfxRect& aRect);
virtual bool RecvZoomToRect(const CSSRect& aRect);
virtual bool RecvUpdateZoomConstraints(const bool& aAllowZoom,
const float& aMinZoom,
const float& aMaxZoom);

View File

@ -1252,9 +1252,7 @@ void AsyncPanZoomController::DetectScrollableSubframe() {
mDelayPanning = true;
}
void AsyncPanZoomController::ZoomToRect(const gfxRect& aRect) {
CSSRect zoomToRect(aRect.x, aRect.y, aRect.width, aRect.height);
void AsyncPanZoomController::ZoomToRect(CSSRect aRect) {
SetState(ANIMATING_ZOOM);
{
@ -1278,19 +1276,19 @@ void AsyncPanZoomController::ZoomToRect(const gfxRect& aRect) {
/ intrinsicScale;
float localMaxZoom = mMaxZoom / intrinsicScale;
if (!zoomToRect.IsEmpty()) {
if (!aRect.IsEmpty()) {
// Intersect the zoom-to-rect to the CSS rect to make sure it fits.
zoomToRect = zoomToRect.Intersect(cssPageRect);
aRect = aRect.Intersect(cssPageRect);
float targetResolution =
std::min(compositionBounds.width / zoomToRect.width,
compositionBounds.height / zoomToRect.height);
std::min(compositionBounds.width / aRect.width,
compositionBounds.height / aRect.height);
targetZoom = targetResolution / intrinsicScale;
}
// 1. If the rect is empty, request received from browserElementScrolling.js
// 2. currentZoom is equal to mMaxZoom and user still double-tapping it
// 3. currentZoom is equal to localMinZoom and user still double-tapping it
// Treat these three cases as a request to zoom out as much as possible.
if (zoomToRect.IsEmpty() ||
if (aRect.IsEmpty() ||
(currentZoom == localMaxZoom && targetZoom >= localMaxZoom) ||
(currentZoom == localMinZoom && targetZoom <= localMinZoom)) {
CSSRect compositedRect = mFrameMetrics.CalculateCompositedRectInCssPixels();
@ -1299,14 +1297,14 @@ void AsyncPanZoomController::ZoomToRect(const gfxRect& aRect) {
cssPageRect.width * (compositedRect.height / compositedRect.width);
float dh = compositedRect.height - newHeight;
zoomToRect = CSSRect(0.0f,
aRect = CSSRect(0.0f,
y + dh/2,
cssPageRect.width,
newHeight);
zoomToRect = zoomToRect.Intersect(cssPageRect);
aRect = aRect.Intersect(cssPageRect);
float targetResolution =
std::min(compositionBounds.width / zoomToRect.width,
compositionBounds.height / zoomToRect.height);
std::min(compositionBounds.width / aRect.width,
compositionBounds.height / aRect.height);
targetZoom = targetResolution / intrinsicScale;
}
@ -1320,17 +1318,17 @@ void AsyncPanZoomController::ZoomToRect(const gfxRect& aRect) {
// If either of these conditions are met, the page will be
// overscrolled after zoomed
if (zoomToRect.y + rectAfterZoom.height > cssPageRect.height) {
zoomToRect.y = cssPageRect.height - rectAfterZoom.height;
zoomToRect.y = zoomToRect.y > 0 ? zoomToRect.y : 0;
if (aRect.y + rectAfterZoom.height > cssPageRect.height) {
aRect.y = cssPageRect.height - rectAfterZoom.height;
aRect.y = aRect.y > 0 ? aRect.y : 0;
}
if (zoomToRect.x + rectAfterZoom.width > cssPageRect.width) {
zoomToRect.x = cssPageRect.width - rectAfterZoom.width;
zoomToRect.x = zoomToRect.x > 0 ? zoomToRect.x : 0;
if (aRect.x + rectAfterZoom.width > cssPageRect.width) {
aRect.x = cssPageRect.width - rectAfterZoom.width;
aRect.x = aRect.x > 0 ? aRect.x : 0;
}
mStartZoomToMetrics = mFrameMetrics;
mEndZoomToMetrics.mScrollOffset = zoomToRect.TopLeft();
mEndZoomToMetrics.mScrollOffset = aRect.TopLeft();
mAnimationStartTime = GetFrameTime();

View File

@ -131,9 +131,9 @@ public:
/**
* Kicks an animation to zoom to a rect. This may be either a zoom out or zoom
* in. The actual animation is done on the compositor thread after being set
* up. |aRect| must be given in CSS pixels, relative to the document.
* up.
*/
void ZoomToRect(const gfxRect& aRect);
void ZoomToRect(CSSRect aRect);
/**
* If we have touch listeners, this should always be called when we know

View File

@ -964,7 +964,7 @@ RenderFrameParent::BuildDisplayList(nsDisplayListBuilder* aBuilder,
}
void
RenderFrameParent::ZoomToRect(const gfxRect& aRect)
RenderFrameParent::ZoomToRect(const CSSRect& aRect)
{
if (mPanZoomController) {
mPanZoomController->ZoomToRect(aRect);

View File

@ -98,7 +98,7 @@ public:
void NotifyDimensionsChanged(ScreenIntSize size);
void ZoomToRect(const gfxRect& aRect);
void ZoomToRect(const CSSRect& aRect);
void ContentReceivedTouch(bool aPreventDefault);