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

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: Incorporate review feedback Created 5 years, 11 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
« no previous file with comments | « Source/core/frame/PinchViewport.h ('k') | Source/core/page/ChromeClient.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/frame/PinchViewport.cpp
diff --git a/Source/core/frame/PinchViewport.cpp b/Source/core/frame/PinchViewport.cpp
index 1155c901e87519d95012f3fee097682eae15b9e7..4e895c19432798bca08b5f06f96469d92d16c440 100644
--- a/Source/core/frame/PinchViewport.cpp
+++ b/Source/core/frame/PinchViewport.cpp
@@ -224,6 +224,34 @@ 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;
+
+ // 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();
aelias_OOO_until_Jul13 2015/02/03 19:10:11 I'm not confident FrameView is guaranteed to exist
+ 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):
« no previous file with comments | « Source/core/frame/PinchViewport.h ('k') | Source/core/page/ChromeClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698