| Index: content/browser/web_contents/web_contents_impl.cc
|
| diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
| index 195edc388d7e714b3c4772930b2b099f260654fa..330f935985a3c02af7247d37fbbc601b03c5e734 100644
|
| --- a/content/browser/web_contents/web_contents_impl.cc
|
| +++ b/content/browser/web_contents/web_contents_impl.cc
|
| @@ -332,6 +332,8 @@ WebContentsImpl::WebContentsImpl(
|
| minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
|
| maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
|
| temporary_zoom_settings_(false),
|
| + totalPinchGestureAmount_(0),
|
| + currentPinchZoomStepDelta_(0),
|
| color_chooser_identifier_(0),
|
| render_view_message_source_(NULL),
|
| fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
|
| @@ -1215,6 +1217,44 @@ bool WebContentsImpl::PreHandleGestureEvent(
|
| return delegate_ && delegate_->PreHandleGestureEvent(this, event);
|
| }
|
|
|
| +bool WebContentsImpl::HandleGestureEvent(
|
| + const blink::WebGestureEvent& event) {
|
| + // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
|
| + // Use them to implement browser zoom, as for HandleWheelEvent above.
|
| + if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
|
| + event.sourceDevice == blink::WebGestureEvent::Touchpad) {
|
| + // The scale difference necessary to trigger a zoom action. Derived from
|
| + // experimentation to find a value that feels reasonable.
|
| + const float kZoomStepValue = 0.6;
|
| +
|
| + // Find the (absolute) thresholds on either side of the current zoom factor,
|
| + // then convert those to actual numbers to trigger a zoom in or out.
|
| + // This logic deliberately makes the range around the starting zoom value
|
| + // for the gesture twice as large as the other ranges (i.e., the notches are
|
| + // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
|
| + // so that it's easier to get back to your starting point than it is to
|
| + // overshoot.
|
| + float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
|
| + float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
|
| + float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
|
| + : -backStep;
|
| + float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
|
| + : backStep;
|
| +
|
| + totalPinchGestureAmount_ += event.data.pinchUpdate.scale;
|
| + if (totalPinchGestureAmount_ > zoomInThreshold) {
|
| + currentPinchZoomStepDelta_++;
|
| + delegate_->ContentsZoomChange(true);
|
| + } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
|
| + currentPinchZoomStepDelta_--;
|
| + delegate_->ContentsZoomChange(false);
|
| + }
|
| + return true;
|
| + }
|
| +
|
| + return false;
|
| +}
|
| +
|
| #if defined(OS_WIN)
|
| gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
|
| return accessible_parent_;
|
|
|