Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(999)

Unified Diff: Source/core/frame/PinchViewport.cpp

Issue 889803004: Add touchpad pinch zoom support to Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update tests Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/frame/PinchViewport.cpp
diff --git a/Source/core/frame/PinchViewport.cpp b/Source/core/frame/PinchViewport.cpp
index 1155c901e87519d95012f3fee097682eae15b9e7..e9710efc6994dcfff1dd9f85b1eba682dbbc8532 100644
--- a/Source/core/frame/PinchViewport.cpp
+++ b/Source/core/frame/PinchViewport.cpp
@@ -224,6 +224,36 @@ void PinchViewport::setScaleAndLocation(float scale, const FloatPoint& location)
clampToBoundaries();
}
+bool PinchViewport::magnifyScaleAroundAnchor(float magnifyDelta, const FloatPoint& anchor)
+{
+ const float oldPageScale = scale();
+ const float newPageScale = frameHost().chrome().client().clampPageScaleFactorToLimits(
+ magnifyDelta * oldPageScale);
+ if (newPageScale == oldPageScale)
+ return false;
+ if (!mainFrame() || !mainFrame()->view())
+ return false;
+
+ // Keep the center-of-pinch anchor in a stable position over the course
+ // of the magnify.
+ FloatPoint anchorAtOldScale = anchor.scaledBy(1.f / oldPageScale);
+ FloatPoint anchorAtNewScale = anchor.scaledBy(1.f / newPageScale);
+ FloatSize anchorDelta = anchorAtOldScale - anchorAtNewScale;
+
+ // First try to use the anchor's delta to scroll the FrameView.
+ FloatSize anchorDeltaUnusedByScroll = anchorDelta;
+ FrameView* view = mainFrame()->view();
+ DoublePoint oldPosition = view->scrollPositionDouble();
+ view->scrollBy(DoubleSize(anchorDelta.width(), anchorDelta.height()));
+ DoublePoint newPosition = view->scrollPositionDouble();
+ anchorDeltaUnusedByScroll = anchorDelta - toFloatSize(newPosition - oldPosition);
+
+ // Manually bubble any remaining anchor delta up to the pinch viewport.
+ FloatPoint newLocation(location() + anchorDeltaUnusedByScroll);
+ setScaleAndLocation(newPageScale, newLocation);
+ return true;
+}
+
// Modifies the top of the graphics layer tree to add layers needed to support
// the inner/outer viewport fixed-position model for pinch zoom. When finished,
// the tree will look like this (with * denoting added layers):

Powered by Google App Engine
This is Rietveld 408576698