Chromium Code Reviews| Index: Source/web/WebViewImpl.cpp |
| diff --git a/Source/web/WebViewImpl.cpp b/Source/web/WebViewImpl.cpp |
| index 3d9f83084ba3f24961e679bb124edea2fa77f6b1..838de04bcc7bfefb9aa63c6bbddf5f38c0b1249f 100644 |
| --- a/Source/web/WebViewImpl.cpp |
| +++ b/Source/web/WebViewImpl.cpp |
| @@ -2144,8 +2144,29 @@ bool WebViewImpl::handleInputEvent(const WebInputEvent& inputEvent) |
| // Unhandled touchpad gesture pinch events synthesize mouse wheel events. |
| if (inputEvent.type == WebInputEvent::GesturePinchUpdate) { |
| - if (handleSyntheticWheelFromTouchpadPinchEvent(static_cast<const WebGestureEvent&>(inputEvent))) |
| + const WebGestureEvent& pinchEvent = static_cast<const WebGestureEvent&>(inputEvent); |
| + // First, synthesize a Windows-like wheel event to send to any handlers that may exist. |
| + if (handleSyntheticWheelFromTouchpadPinchEvent(pinchEvent)) |
| return true; |
| + |
| + // If the event remains unhandled, use it pinch the viewport. |
| + const float magnifyDelta = pinchEvent.data.pinchUpdate.scale; |
| + const float oldPageScale = pageScaleFactor(); |
| + setPageScaleFactor(oldPageScale * magnifyDelta); |
|
aelias_OOO_until_Jul13
2015/01/30 21:21:40
Please avoid this call to setPageScaleFactor, sinc
ccameron
2015/02/02 23:59:07
Done.
|
| + const float newPageScale = pageScaleFactor(); |
| + |
| + // Keep the center-of-pinch anchor specified by (x, y) in a stable |
| + // position over the course of the magnify. |
| + const FloatPoint anchor(pinchEvent.x, pinchEvent.y); |
| + FloatPoint anchorAtOldScale = anchor.scaledBy(1.f / oldPageScale); |
| + FloatPoint anchorAtNewScale = anchor.scaledBy(1.f / newPageScale); |
| + FloatSize anchorDelta = anchorAtOldScale - anchorAtNewScale; |
| + page()->frameHost().pinchViewport().move(FloatPoint(anchorDelta.width(), anchorDelta.height())); |
| + |
| + // TODO(ccameron): Always return that the event was handled. Once the pinch-zoom content scale |
| + // handlers have been remove from content, this function may return false if the page scale does |
| + // not change. |
| + return true; |
| } |
| return false; |