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

Unified Diff: content/browser/web_contents/web_contents_impl.cc

Issue 181723006: Handle mac trackpad zoom via GesturePinch events (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: jdduke CR feedback and fix win build errors Created 6 years, 9 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: 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..56eb360294b746a0914a6721f8bae409547dfdbd 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.6f;
+
+ // 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_;

Powered by Google App Engine
This is Rietveld 408576698