Bug 1721601. Move "zoom in if can't zoom out" from being a flag to part of ZoomTarget for AsyncPanZoomController::ZoomToRect. r=botond

Instead of passing this flag all of the time for double taps we want to decide to do this or not in CalculateRectToZoomTo. Moving it into ZoomTarget seems like a good way to do this (which is done in the next patch).

Differential Revision: https://phabricator.services.mozilla.com/D128435
This commit is contained in:
Timothy Nikkel
2021-10-16 05:07:55 +00:00
parent ceff4805e0
commit d6a5d9edd2
9 changed files with 38 additions and 21 deletions

View File

@@ -1432,7 +1432,8 @@ void BrowserChild::HandleDoubleTap(const CSSPoint& aPoint,
mApzcTreeManager) {
ScrollableLayerGuid guid(mLayersId, presShellId, viewId);
mApzcTreeManager->ZoomToRect(guid, zoomTarget, ZOOM_IN_IF_CANT_ZOOM_OUT);
mApzcTreeManager->ZoomToRect(guid, zoomTarget,
ZoomToRectBehavior::DEFAULT_BEHAVIOR);
}
}
@@ -1535,7 +1536,7 @@ void BrowserChild::ZoomToRect(const uint32_t& aPresShellId,
ScrollableLayerGuid guid(mLayersId, aPresShellId, aViewId);
if (mApzcTreeManager) {
mApzcTreeManager->ZoomToRect(guid, ZoomTarget{aRect, Nothing()}, aFlags);
mApzcTreeManager->ZoomToRect(guid, ZoomTarget{aRect}, aFlags);
}
}

View File

@@ -37,9 +37,6 @@ enum ZoomToRectBehavior : uint32_t {
DISABLE_ZOOM_OUT = 1 << 0,
PAN_INTO_VIEW_ONLY = 1 << 1,
ONLY_ZOOM_TO_DEFAULT_SCALE = 1 << 2,
// If we are asked to zoom out but cannot (due to zoom constraints, etc), then
// zoom in some small amount to provide feedback to the user.
ZOOM_IN_IF_CANT_ZOOM_OUT = 1 << 3
};
class AsyncDragMetrics;

View File

@@ -5483,19 +5483,19 @@ void AsyncPanZoomController::ZoomToRect(const ZoomTarget& aZoomTarget,
// 2. currentZoom is equal to mZoomConstraints.mMaxZoom and user still
// double-tapping it
// Treat these cases as a request to zoom out as much as possible
// unless we were passed the ZOOM_IN_IF_CANT_ZOOM_OUT flag and currentZoom
// unless cantZoomOutBehavior == ZoomIn and currentZoom
// is equal to localMinZoom and user still double-tapping it, then try to
// zoom in a small amount to provide feedback to the user.
bool zoomOut = false;
// True if we are already zoomed out and we are asked to either stay there
// or zoom out more and the ZOOM_IN_IF_CANT_ZOOM_OUT flag was passed.
// or zoom out more and cantZoomOutBehavior == ZoomIn.
bool zoomInDefaultAmount = false;
if (aFlags & DISABLE_ZOOM_OUT) {
zoomOut = false;
} else {
if (rect.IsEmpty()) {
if (currentZoom == localMinZoom &&
(aFlags & ZOOM_IN_IF_CANT_ZOOM_OUT) &&
aZoomTarget.cantZoomOutBehavior == CantZoomOutBehavior::ZoomIn &&
(defaultZoomInAmount != 1.f)) {
zoomInDefaultAmount = true;
} else {
@@ -5508,7 +5508,8 @@ void AsyncPanZoomController::ZoomToRect(const ZoomTarget& aZoomTarget,
// already at min zoom and asked to zoom out further
if (!zoomOut && currentZoom == localMinZoom && targetZoom <= localMinZoom &&
(aFlags & ZOOM_IN_IF_CANT_ZOOM_OUT) && (defaultZoomInAmount != 1.f)) {
aZoomTarget.cantZoomOutBehavior == CantZoomOutBehavior::ZoomIn &&
(defaultZoomInAmount != 1.f)) {
zoomInDefaultAmount = true;
}
MOZ_ASSERT(!(zoomInDefaultAmount && zoomOut));

View File

@@ -380,7 +380,7 @@ TEST_F(APZCBasicTester, ZoomAndScrollableRectChangeAfterZoomChange) {
MakeApzcZoomable();
// Zoom to right side.
ZoomTarget zoomTarget{CSSRect(75, 25, 25, 25), Nothing()};
ZoomTarget zoomTarget{CSSRect(75, 25, 25, 25)};
apzc->ZoomToRect(zoomTarget, 0);
// Run the animation to completion, should take 250ms/16.67ms = 15 frames, but
@@ -392,7 +392,7 @@ TEST_F(APZCBasicTester, ZoomAndScrollableRectChangeAfterZoomChange) {
EXPECT_FALSE(apzc->IsAsyncZooming());
// Zoom out.
ZoomTarget zoomTarget2{CSSRect(0, 0, 100, 100), Nothing()};
ZoomTarget zoomTarget2{CSSRect(0, 0, 100, 100)};
apzc->ZoomToRect(zoomTarget2, 0);
// Run the animation a few times to get it going.
@@ -449,7 +449,7 @@ TEST_F(APZCBasicTester, ZoomToRectAndCompositionBoundsChange) {
MakeApzcZoomable();
// Start a zoom to a rect.
ZoomTarget zoomTarget{CSSRect(25, 25, 25, 25), Nothing()};
ZoomTarget zoomTarget{CSSRect(25, 25, 25, 25)};
apzc->ZoomToRect(zoomTarget, 0);
// Run the animation a few times to get it going.

View File

@@ -149,7 +149,7 @@ void ChromeProcessController::HandleDoubleTap(
"IAPZCTreeManager::ZoomToRect", mAPZCTreeManager,
&IAPZCTreeManager::ZoomToRect,
ScrollableLayerGuid(aGuid.mLayersId, presShellId, viewId),
zoomTarget, ZoomToRectBehavior::ZOOM_IN_IF_CANT_ZOOM_OUT));
zoomTarget, ZoomToRectBehavior::DEFAULT_BEHAVIOR));
}
}

View File

@@ -206,13 +206,13 @@ ZoomTarget CalculateRectToZoomTo(
RefPtr<PresShell> presShell = aRootContentDocument->GetPresShell();
if (!presShell) {
return ZoomTarget{zoomOut};
return ZoomTarget{zoomOut, CantZoomOutBehavior::ZoomIn};
}
nsIScrollableFrame* rootScrollFrame =
presShell->GetRootScrollFrameAsScrollable();
if (!rootScrollFrame) {
return ZoomTarget{zoomOut};
return ZoomTarget{zoomOut, CantZoomOutBehavior::ZoomIn};
}
CSSPoint documentRelativePoint =
@@ -222,7 +222,8 @@ ZoomTarget CalculateRectToZoomTo(
nsCOMPtr<dom::Element> element = ElementFromPoint(presShell, aPoint);
if (!element) {
return ZoomTarget{zoomOut, Nothing(), Some(documentRelativePoint)};
return ZoomTarget{zoomOut, CantZoomOutBehavior::ZoomIn, Nothing(),
Some(documentRelativePoint)};
}
FrameMetrics metrics =
@@ -234,7 +235,8 @@ ZoomTarget CalculateRectToZoomTo(
}
if (!element) {
return ZoomTarget{zoomOut, Nothing(), Some(documentRelativePoint)};
return ZoomTarget{zoomOut, CantZoomOutBehavior::ZoomIn, Nothing(),
Some(documentRelativePoint)};
}
CSSPoint visualScrollOffset = metrics.GetVisualScrollOffset();
@@ -336,7 +338,8 @@ ZoomTarget CalculateRectToZoomTo(
// If the rect is already taking up most of the visible area and is
// stretching the width of the page, then we want to zoom out instead.
if (RectHasAlmostSameZoomLevel(rect, compositedArea)) {
return ZoomTarget{zoomOut, Nothing(), Some(documentRelativePoint)};
return ZoomTarget{zoomOut, CantZoomOutBehavior::ZoomIn, Nothing(),
Some(documentRelativePoint)};
}
elementBoundingRect = AddHMargin(elementBoundingRect, margin, metrics);
@@ -348,8 +351,8 @@ ZoomTarget CalculateRectToZoomTo(
rect.Round();
elementBoundingRect.Round();
return ZoomTarget{rect, Some(elementBoundingRect),
Some(documentRelativePoint)};
return ZoomTarget{rect, CantZoomOutBehavior::ZoomIn,
Some(elementBoundingRect), Some(documentRelativePoint)};
}
} // namespace layers

View File

@@ -19,11 +19,17 @@ class Document;
namespace layers {
enum class CantZoomOutBehavior : int8_t { Nothing = 0, ZoomIn };
struct ZoomTarget {
// The preferred target rect that we'd like to zoom in on, if possible. An
// empty rect means the browser should zoom out.
CSSRect targetRect;
// If we are asked to zoom out but cannot (due to zoom constraints, etc), then
// zoom in some small amount to provide feedback to the user.
CantZoomOutBehavior cantZoomOutBehavior = CantZoomOutBehavior::Nothing;
// If zooming all the way in on |targetRect| is not possible (for example, due
// to a max zoom constraint), |elementBoundingRect| may be used to inform a
// more optimal target scroll position (for example, we may try to maximize

View File

@@ -987,12 +987,20 @@ struct ParamTraits<mozilla::RayReferenceData> {
}
};
template <>
struct ParamTraits<mozilla::layers::CantZoomOutBehavior>
: public ContiguousEnumSerializerInclusive<
mozilla::layers::CantZoomOutBehavior,
mozilla::layers::CantZoomOutBehavior::Nothing,
mozilla::layers::CantZoomOutBehavior::ZoomIn> {};
template <>
struct ParamTraits<mozilla::layers::ZoomTarget> {
typedef mozilla::layers::ZoomTarget paramType;
static void Write(Message* aMsg, const paramType& aParam) {
WriteParam(aMsg, aParam.targetRect);
WriteParam(aMsg, aParam.cantZoomOutBehavior);
WriteParam(aMsg, aParam.elementBoundingRect);
WriteParam(aMsg, aParam.documentRelativePointerPosition);
}
@@ -1000,6 +1008,7 @@ struct ParamTraits<mozilla::layers::ZoomTarget> {
static bool Read(const Message* aMsg, PickleIterator* aIter,
paramType* aResult) {
return (ReadParam(aMsg, aIter, &aResult->targetRect) &&
ReadParam(aMsg, aIter, &aResult->cantZoomOutBehavior) &&
ReadParam(aMsg, aIter, &aResult->elementBoundingRect) &&
ReadParam(aMsg, aIter, &aResult->documentRelativePointerPosition));
}

View File

@@ -1869,7 +1869,7 @@ void nsBaseWidget::ZoomToRect(const uint32_t& aPresShellId,
"layers::IAPZCTreeManager::ZoomToRect", mAPZC,
&IAPZCTreeManager::ZoomToRect,
ScrollableLayerGuid(layerId, aPresShellId, aViewId),
ZoomTarget{aRect, Nothing()}, aFlags));
ZoomTarget{aRect}, aFlags));
}
#ifdef ACCESSIBILITY