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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 1129693002: Make Mac pinch thresholding apply only to zoom (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
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/renderer_host/render_widget_host_view_mac.h" 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
6 6
7 #import <objc/runtime.h> 7 #import <objc/runtime.h>
8 #include <OpenGL/gl.h> 8 #include <OpenGL/gl.h>
9 #include <QuartzCore/QuartzCore.h> 9 #include <QuartzCore/QuartzCore.h>
10 10
(...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 self = [super initWithFrame:NSZeroRect]; 1749 self = [super initWithFrame:NSZeroRect];
1750 if (self) { 1750 if (self) {
1751 self.acceptsTouchEvents = YES; 1751 self.acceptsTouchEvents = YES;
1752 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); 1752 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper);
1753 editCommand_helper_->AddEditingSelectorsToClass([self class]); 1753 editCommand_helper_->AddEditingSelectorsToClass([self class]);
1754 1754
1755 renderWidgetHostView_.reset(r); 1755 renderWidgetHostView_.reset(r);
1756 canBeKeyView_ = YES; 1756 canBeKeyView_ = YES;
1757 opaque_ = YES; 1757 opaque_ = YES;
1758 focusedPluginIdentifier_ = -1; 1758 focusedPluginIdentifier_ = -1;
1759 lastUsedPinchEventTimestamp_ = 0; 1759 pinchLastGestureTimestamp_ = 0;
1760 pinchHasReachedZoomThreshold_ = false;
1760 1761
1761 // OpenGL support: 1762 // OpenGL support:
1762 if ([self respondsToSelector: 1763 if ([self respondsToSelector:
1763 @selector(setWantsBestResolutionOpenGLSurface:)]) { 1764 @selector(setWantsBestResolutionOpenGLSurface:)]) {
1764 [self setWantsBestResolutionOpenGLSurface:YES]; 1765 [self setWantsBestResolutionOpenGLSurface:YES];
1765 } 1766 }
1766 [[NSNotificationCenter defaultCenter] 1767 [[NSNotificationCenter defaultCenter]
1767 addObserver:self 1768 addObserver:self
1768 selector:@selector(didChangeScreenParameters:) 1769 selector:@selector(didChangeScreenParameters:)
1769 name:NSApplicationDidChangeScreenParametersNotification 1770 name:NSApplicationDidChangeScreenParametersNotification
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
2281 if (endWheelMonitor_) { 2282 if (endWheelMonitor_) {
2282 [NSEvent removeMonitor:endWheelMonitor_]; 2283 [NSEvent removeMonitor:endWheelMonitor_];
2283 endWheelMonitor_ = nil; 2284 endWheelMonitor_ = nil;
2284 } 2285 }
2285 } 2286 }
2286 2287
2287 - (void)beginGestureWithEvent:(NSEvent*)event { 2288 - (void)beginGestureWithEvent:(NSEvent*)event {
2288 [responderDelegate_ beginGestureWithEvent:event]; 2289 [responderDelegate_ beginGestureWithEvent:event];
2289 gestureBeginEvent_.reset( 2290 gestureBeginEvent_.reset(
2290 new WebGestureEvent(WebInputEventFactory::gestureEvent(event, self))); 2291 new WebGestureEvent(WebInputEventFactory::gestureEvent(event, self)));
2291 unusedPinchAmount_ = 0; 2292
2293 // If more than 1 second has passed since the last pinch gesture ended, reset
aelias_OOO_until_Jul13 2015/05/06 23:20:24 I don't like timeouts as a rule. Why not reset th
ccameron 2015/05/07 17:09:05 If someone is doing several pinches in a row, to z
aelias_OOO_until_Jul13 2015/05/07 18:16:16 I see. How about checking if page_scale_factor ==
2294 // the zoom threshold levels.
2295 const NSTimeInterval kSecondsUntilZoomThresholdReEnabled = 1;
2296 if ([event timestamp] - pinchLastGestureTimestamp_ >
2297 kSecondsUntilZoomThresholdReEnabled) {
2298 pinchHasReachedZoomThreshold_ = false;
2299 pinchUnusedAmount_ = 0;
2300 }
2292 } 2301 }
2293 2302
2294 - (void)endGestureWithEvent:(NSEvent*)event { 2303 - (void)endGestureWithEvent:(NSEvent*)event {
2295 [responderDelegate_ endGestureWithEvent:event]; 2304 [responderDelegate_ endGestureWithEvent:event];
2296 gestureBeginEvent_.reset(); 2305 gestureBeginEvent_.reset();
2297 2306
2298 if (!renderWidgetHostView_->render_widget_host_) 2307 if (!renderWidgetHostView_->render_widget_host_)
2299 return; 2308 return;
2300 2309
2301 if (gestureBeginPinchSent_) { 2310 if (gestureBeginPinchSent_) {
2302 WebGestureEvent endEvent(WebInputEventFactory::gestureEvent(event, self)); 2311 WebGestureEvent endEvent(WebInputEventFactory::gestureEvent(event, self));
2303 endEvent.type = WebInputEvent::GesturePinchEnd; 2312 endEvent.type = WebInputEvent::GesturePinchEnd;
2304 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(endEvent); 2313 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(endEvent);
2305 gestureBeginPinchSent_ = NO; 2314 gestureBeginPinchSent_ = NO;
2306 lastUsedPinchEventTimestamp_ = [event timestamp]; 2315 if (pinchHasReachedZoomThreshold_)
2316 pinchLastGestureTimestamp_ = [event timestamp];
2307 } 2317 }
2308 } 2318 }
2309 2319
2310 - (void)touchesMovedWithEvent:(NSEvent*)event { 2320 - (void)touchesMovedWithEvent:(NSEvent*)event {
2311 [responderDelegate_ touchesMovedWithEvent:event]; 2321 [responderDelegate_ touchesMovedWithEvent:event];
2312 } 2322 }
2313 2323
2314 - (void)touchesBeganWithEvent:(NSEvent*)event { 2324 - (void)touchesBeganWithEvent:(NSEvent*)event {
2315 [responderDelegate_ touchesBeganWithEvent:event]; 2325 [responderDelegate_ touchesBeganWithEvent:event];
2316 } 2326 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2409 - (void)magnifyWithEvent:(NSEvent*)event { 2419 - (void)magnifyWithEvent:(NSEvent*)event {
2410 if (!renderWidgetHostView_->render_widget_host_) 2420 if (!renderWidgetHostView_->render_widget_host_)
2411 return; 2421 return;
2412 2422
2413 // If, due to nesting of multiple gestures (e.g, from multiple touch 2423 // If, due to nesting of multiple gestures (e.g, from multiple touch
2414 // devices), the beginning of the gesture has been lost, skip the remainder 2424 // devices), the beginning of the gesture has been lost, skip the remainder
2415 // of the gesture. 2425 // of the gesture.
2416 if (!gestureBeginEvent_) 2426 if (!gestureBeginEvent_)
2417 return; 2427 return;
2418 2428
2429 if (!pinchHasReachedZoomThreshold_) {
2430 pinchUnusedAmount_ += [event magnification];
aelias_OOO_until_Jul13 2015/05/06 23:20:24 Please make this multiplicative. Otherwise this w
ccameron 2015/05/07 17:09:06 Done. I had made it additive to match the earlier
2431 if (pinchUnusedAmount_ < -0.4 || pinchUnusedAmount_ > 0.4)
2432 pinchHasReachedZoomThreshold_ = true;
2433 }
2434
2419 // Send a GesturePinchBegin event if none has been sent yet. 2435 // Send a GesturePinchBegin event if none has been sent yet.
2420 if (!gestureBeginPinchSent_) { 2436 if (!gestureBeginPinchSent_) {
2421 // If less than 1 second has passed since an intentional pinch zoom
2422 // was done, don't threshold zooms, because subsequent zooms are likely
2423 // intentional.
2424 const NSTimeInterval kSecondsUntilZoomThresholdReEnabled = 1;
2425 if ([event timestamp] - lastUsedPinchEventTimestamp_ >
2426 kSecondsUntilZoomThresholdReEnabled) {
2427 // Require that a 40% zoom be hit before actually zooming the page,
2428 // to avoid accidental zooms.
2429 // http://crbug.com/478981
2430 unusedPinchAmount_ += [event magnification];
2431 if (unusedPinchAmount_ > -0.4 && unusedPinchAmount_ < 0.4)
2432 return;
2433 }
2434
2435 WebGestureEvent beginEvent(*gestureBeginEvent_); 2437 WebGestureEvent beginEvent(*gestureBeginEvent_);
2436 beginEvent.type = WebInputEvent::GesturePinchBegin; 2438 beginEvent.type = WebInputEvent::GesturePinchBegin;
2437 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(beginEvent); 2439 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(beginEvent);
2438 gestureBeginPinchSent_ = YES; 2440 gestureBeginPinchSent_ = YES;
2439 } 2441 }
2440 2442
2441 // Send a GesturePinchUpdate event. 2443 // Send a GesturePinchUpdate event.
2442 const WebGestureEvent& updateEvent = 2444 WebGestureEvent updateEvent =
2443 WebInputEventFactory::gestureEvent(event, self); 2445 WebInputEventFactory::gestureEvent(event, self);
2446 updateEvent.data.pinchUpdate.zoomDisabled = !pinchHasReachedZoomThreshold_;
2444 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(updateEvent); 2447 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(updateEvent);
2445 } 2448 }
2446 2449
2447 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { 2450 - (void)viewWillMoveToWindow:(NSWindow*)newWindow {
2448 NSWindow* oldWindow = [self window]; 2451 NSWindow* oldWindow = [self window];
2449 2452
2450 NSNotificationCenter* notificationCenter = 2453 NSNotificationCenter* notificationCenter =
2451 [NSNotificationCenter defaultCenter]; 2454 [NSNotificationCenter defaultCenter];
2452 2455
2453 // Backing property notifications crash on 10.6 when building with the 10.7 2456 // Backing property notifications crash on 10.6 when building with the 10.7
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after
3490 3493
3491 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3494 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3492 // regions that are not draggable. (See ControlRegionView in 3495 // regions that are not draggable. (See ControlRegionView in
3493 // native_app_window_cocoa.mm). This requires the render host view to be 3496 // native_app_window_cocoa.mm). This requires the render host view to be
3494 // draggable by default. 3497 // draggable by default.
3495 - (BOOL)mouseDownCanMoveWindow { 3498 - (BOOL)mouseDownCanMoveWindow {
3496 return YES; 3499 return YES;
3497 } 3500 }
3498 3501
3499 @end 3502 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698