Bug 1105109 - Add a ScrollByAndClamp() utility function to AsyncPanZoomController. r=kats
MozReview-Commit-ID: GPnuL0kmWsN
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -2911,16 +2911,20 @@ void AsyncPanZoomController::AdjustScrol
RequestContentRepaint();
UpdateSharedCompositorFrameMetrics();
}
void AsyncPanZoomController::ScrollBy(const CSSPoint& aOffset) {
mFrameMetrics.ScrollBy(aOffset);
}
+void AsyncPanZoomController::ScrollByAndClamp(const CSSPoint& aOffset) {
+ mFrameMetrics.ClampAndSetScrollOffset(mFrameMetrics.GetScrollOffset() + aOffset);
+}
+
void AsyncPanZoomController::ScaleWithFocus(float aScale,
const CSSPoint& aFocus) {
mFrameMetrics.ZoomBy(aScale);
// We want to adjust the scroll offset such that the CSS point represented by aFocus remains
// at the same position on the screen before and after the change in zoom. The below code
// accomplishes this; see https://bugzilla.mozilla.org/show_bug.cgi?id=923431#c6 for an
// in-depth explanation of how.
mFrameMetrics.SetScrollOffset((mFrameMetrics.GetScrollOffset() + aFocus) - (aFocus / aScale));
--- a/gfx/layers/apz/src/AsyncPanZoomController.h
+++ b/gfx/layers/apz/src/AsyncPanZoomController.h
@@ -527,21 +527,29 @@ protected:
* Helper method to cancel any gesture currently going to Gecko. Used
* primarily when a user taps the screen over some clickable content but then
* pans down instead of letting go (i.e. to cancel a previous touch so that a
* new one can properly take effect.
*/
nsEventStatus OnCancelTap(const TapGestureInput& aEvent);
/**
- * Scrolls the viewport by an X,Y offset.
+ * Scroll the scroll frame by an X,Y offset.
+ * The resulting scroll offset is not clamped to the scrollable rect;
+ * the caller must ensure it stays within range.
*/
void ScrollBy(const CSSPoint& aOffset);
/**
+ * Scroll the scroll frame by an X,Y offset, clamping the resulting
+ * scroll offset to the scrollable rect.
+ */
+ void ScrollByAndClamp(const CSSPoint& aOffset);
+
+ /**
* Scales the viewport by an amount (note that it multiplies this scale in to
* the current scale, it doesn't set it to |aScale|). Also considers a focus
* point so that the page zooms inward/outward from that point.
*/
void ScaleWithFocus(float aScale,
const CSSPoint& aFocus);
/**