Chromium Code Reviews| 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): |