| Index: ios/chrome/browser/ui/stack_view/card_stack_pinch_gesture_recognizer.mm
|
| diff --git a/ios/chrome/browser/ui/stack_view/card_stack_pinch_gesture_recognizer.mm b/ios/chrome/browser/ui/stack_view/card_stack_pinch_gesture_recognizer.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d5a8021114b9d518ba06eba10ebdacbef6c565c3
|
| --- /dev/null
|
| +++ b/ios/chrome/browser/ui/stack_view/card_stack_pinch_gesture_recognizer.mm
|
| @@ -0,0 +1,60 @@
|
| +// Copyright 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#import "ios/chrome/browser/ui/stack_view/card_stack_pinch_gesture_recognizer.h"
|
| +
|
| +#include "base/logging.h"
|
| +
|
| +@interface CardStackPinchGestureRecognizer ()
|
| +
|
| +// Returns the number of non-ended, non-cancelled touches in |event|.
|
| +- (NSUInteger)numberOfActiveTouchesInEvent:(UIEvent*)event;
|
| +
|
| +@end
|
| +
|
| +@implementation CardStackPinchGestureRecognizer
|
| +
|
| +@synthesize numberOfActiveTouches = numberOfActiveTouches_;
|
| +
|
| +- (NSUInteger)numberOfActiveTouches {
|
| + // Certain corner cases can cause |numberOfActiveTouches_| to temporarily
|
| + // grow to be larger than |[self numberOfTouches]| (this seems to occur only
|
| + // when the user brings two fingers very closely together). As a safeguard,
|
| + // ensure that the number returned is never greater than
|
| + // |[self numberOfTouches]|, as the latter number dictates the greatest index
|
| + // that a client can pass to |locationOfTouch:| without causing an exception.
|
| + return std::min(numberOfActiveTouches_, [self numberOfTouches]);
|
| +}
|
| +
|
| +- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
|
| + numberOfActiveTouches_ = [self numberOfActiveTouchesInEvent:event];
|
| + [super touchesBegan:touches withEvent:event];
|
| +}
|
| +
|
| +- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
|
| + numberOfActiveTouches_ = [self numberOfActiveTouchesInEvent:event];
|
| + [super touchesEnded:touches withEvent:event];
|
| +}
|
| +
|
| +- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
|
| + numberOfActiveTouches_ = [self numberOfActiveTouchesInEvent:event];
|
| + [super touchesCancelled:touches withEvent:event];
|
| +}
|
| +
|
| +- (void)reset {
|
| + numberOfActiveTouches_ = 0;
|
| + [super reset];
|
| +}
|
| +
|
| +- (NSUInteger)numberOfActiveTouchesInEvent:(UIEvent*)event {
|
| + NSUInteger count = 0;
|
| + for (UITouch* touch in [event touchesForGestureRecognizer:self]) {
|
| + if (touch.phase == UITouchPhaseBegan || touch.phase == UITouchPhaseMoved ||
|
| + touch.phase == UITouchPhaseStationary)
|
| + count++;
|
| + }
|
| + return count;
|
| +}
|
| +
|
| +@end
|
|
|