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

Unified Diff: ios/chrome/browser/ui/stack_view/card_stack_pinch_gesture_recognizer.mm

Issue 2587023002: Upstream Chrome on iOS source code [8/11]. (Closed)
Patch Set: Created 4 years 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: 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
« no previous file with comments | « ios/chrome/browser/ui/stack_view/card_stack_pinch_gesture_recognizer.h ('k') | ios/chrome/browser/ui/stack_view/card_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698