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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/web_contents/web_contents_impl.h" 5 #include "content/browser/web_contents/web_contents_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 should_normally_be_visible_(true), 325 should_normally_be_visible_(true),
326 is_being_destroyed_(false), 326 is_being_destroyed_(false),
327 notify_disconnection_(false), 327 notify_disconnection_(false),
328 dialog_manager_(NULL), 328 dialog_manager_(NULL),
329 is_showing_before_unload_dialog_(false), 329 is_showing_before_unload_dialog_(false),
330 last_active_time_(base::TimeTicks::Now()), 330 last_active_time_(base::TimeTicks::Now()),
331 closed_by_user_gesture_(false), 331 closed_by_user_gesture_(false),
332 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), 332 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
333 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), 333 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
334 temporary_zoom_settings_(false), 334 temporary_zoom_settings_(false),
335 totalPinchGestureAmount_(0),
336 currentPinchZoomStepDelta_(0),
335 color_chooser_identifier_(0), 337 color_chooser_identifier_(0),
336 render_view_message_source_(NULL), 338 render_view_message_source_(NULL),
337 fullscreen_widget_routing_id_(MSG_ROUTING_NONE), 339 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
338 is_subframe_(false) { 340 is_subframe_(false) {
339 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) 341 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
340 g_created_callbacks.Get().at(i).Run(this); 342 g_created_callbacks.Get().at(i).Run(this);
341 frame_tree_.SetFrameRemoveListener( 343 frame_tree_.SetFrameRemoveListener(
342 base::Bind(&WebContentsImpl::OnFrameRemoved, 344 base::Bind(&WebContentsImpl::OnFrameRemoved,
343 base::Unretained(this))); 345 base::Unretained(this)));
344 } 346 }
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 } 1210 }
1209 #endif 1211 #endif
1210 return false; 1212 return false;
1211 } 1213 }
1212 1214
1213 bool WebContentsImpl::PreHandleGestureEvent( 1215 bool WebContentsImpl::PreHandleGestureEvent(
1214 const blink::WebGestureEvent& event) { 1216 const blink::WebGestureEvent& event) {
1215 return delegate_ && delegate_->PreHandleGestureEvent(this, event); 1217 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
1216 } 1218 }
1217 1219
1220 bool WebContentsImpl::HandleGestureEvent(
1221 const blink::WebGestureEvent& event) {
1222 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1223 // Use them to implement browser zoom, as for HandleWheelEvent above.
1224 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
1225 event.sourceDevice == blink::WebGestureEvent::Touchpad) {
1226 // The scale difference necessary to trigger a zoom action. Derived from
1227 // experimentation to find a value that feels reasonable.
1228 const float kZoomStepValue = 0.6f;
1229
1230 // Find the (absolute) thresholds on either side of the current zoom factor,
1231 // then convert those to actual numbers to trigger a zoom in or out.
1232 // This logic deliberately makes the range around the starting zoom value
1233 // for the gesture twice as large as the other ranges (i.e., the notches are
1234 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1235 // so that it's easier to get back to your starting point than it is to
1236 // overshoot.
1237 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1238 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1239 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1240 : -backStep;
1241 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1242 : backStep;
1243
1244 totalPinchGestureAmount_ += event.data.pinchUpdate.scale;
1245 if (totalPinchGestureAmount_ > zoomInThreshold) {
1246 currentPinchZoomStepDelta_++;
1247 delegate_->ContentsZoomChange(true);
1248 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1249 currentPinchZoomStepDelta_--;
1250 delegate_->ContentsZoomChange(false);
1251 }
1252 return true;
1253 }
1254
1255 return false;
1256 }
1257
1218 #if defined(OS_WIN) 1258 #if defined(OS_WIN)
1219 gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() { 1259 gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1220 return accessible_parent_; 1260 return accessible_parent_;
1221 } 1261 }
1222 #endif 1262 #endif
1223 1263
1224 void WebContentsImpl::HandleMouseDown() { 1264 void WebContentsImpl::HandleMouseDown() {
1225 if (delegate_) 1265 if (delegate_)
1226 delegate_->HandleMouseDown(); 1266 delegate_->HandleMouseDown();
1227 } 1267 }
(...skipping 2402 matching lines...) Expand 10 before | Expand all | Expand 10 after
3630 3670
3631 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { 3671 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3632 if (!delegate_) 3672 if (!delegate_)
3633 return; 3673 return;
3634 const gfx::Size new_size = GetPreferredSize(); 3674 const gfx::Size new_size = GetPreferredSize();
3635 if (new_size != old_size) 3675 if (new_size != old_size)
3636 delegate_->UpdatePreferredSize(this, new_size); 3676 delegate_->UpdatePreferredSize(this, new_size);
3637 } 3677 }
3638 3678
3639 } // namespace content 3679 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698