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

Side by Side Diff: ios/chrome/browser/ui/side_swipe_gesture_recognizer.mm

Issue 2295283002: Work around PanGestureRecognizer iOS10 issue. (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #import "ios/chrome/browser/ui/side_swipe_gesture_recognizer.h" 5 #import "ios/chrome/browser/ui/side_swipe_gesture_recognizer.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
(...skipping 29 matching lines...) Expand all
40 // immediately if the touches aren't at the edge of the touched view. 40 // immediately if the touches aren't at the edge of the touched view.
41 - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { 41 - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
42 [super touchesBegan:touches withEvent:event]; 42 [super touchesBegan:touches withEvent:event];
43 43
44 // Don't interrupt gestures in progress. 44 // Don't interrupt gestures in progress.
45 if (self.state != UIGestureRecognizerStatePossible) 45 if (self.state != UIGestureRecognizerStatePossible)
46 return; 46 return;
47 47
48 UITouch* touch = [[event allTouches] anyObject]; 48 UITouch* touch = [[event allTouches] anyObject];
49 CGPoint location = [touch locationInView:self.view]; 49 CGPoint location = [touch locationInView:self.view];
50 _startPoint = CGPointZero;
50 if (_swipeEdge > 0) { 51 if (_swipeEdge > 0) {
51 if (location.x > _swipeEdge && 52 if (location.x > _swipeEdge &&
52 location.x < CGRectGetMaxX([self.view bounds]) - _swipeEdge) { 53 location.x < CGRectGetMaxX([self.view bounds]) - _swipeEdge) {
53 self.state = UIGestureRecognizerStateFailed; 54 self.state = UIGestureRecognizerStateFailed;
54 } else { 55 } else {
55 if (location.x < _swipeEdge) { 56 if (location.x < _swipeEdge) {
56 _direction = UISwipeGestureRecognizerDirectionRight; 57 _direction = UISwipeGestureRecognizerDirectionRight;
57 } else { 58 } else {
58 _direction = UISwipeGestureRecognizerDirectionLeft; 59 _direction = UISwipeGestureRecognizerDirectionLeft;
59 } 60 }
(...skipping 11 matching lines...) Expand all
71 [super touchesMoved:touches withEvent:event]; 72 [super touchesMoved:touches withEvent:event];
72 return; 73 return;
73 } 74 }
74 75
75 // Only one touch. 76 // Only one touch.
76 if ([[event allTouches] count] > 1) { 77 if ([[event allTouches] count] > 1) {
77 self.state = UIGestureRecognizerStateFailed; 78 self.state = UIGestureRecognizerStateFailed;
78 return; 79 return;
79 } 80 }
80 81
82 // In iOS10, sometimes a PanGestureRecognizer will fire a touchesMoved even
83 // after touchesBegan sets its state to |UIGestureRecognizerStateFailed|.
84 // Somehow the state is re-set to UIGestureRecognizerStatePossible, and ends
85 // up in moved. Checking if |_startPoint| has been set is a secondary way to
86 // catch for failed gestures.
87 if (CGPointEqualToPoint(_startPoint, CGPointZero)) {
88 self.state = UIGestureRecognizerStateFailed;
89 return;
90 }
91
81 // Don't swipe at an angle greater than |kMaxSwipeYAngle|. 92 // Don't swipe at an angle greater than |kMaxSwipeYAngle|.
82 UITouch* touch = [[event allTouches] anyObject]; 93 UITouch* touch = [[event allTouches] anyObject];
83 CGPoint currentPoint = [touch locationInView:self.view]; 94 CGPoint currentPoint = [touch locationInView:self.view];
84 CGFloat dy = currentPoint.y - _startPoint.y; 95 CGFloat dy = currentPoint.y - _startPoint.y;
85 CGFloat dx = std::abs(currentPoint.x - _startPoint.x); 96 CGFloat dx = std::abs(currentPoint.x - _startPoint.x);
86 CGFloat degrees = std::fabs(std::atan2(dy, dx) * 180 / CGFloat(M_PI)); 97 CGFloat degrees = std::fabs(std::atan2(dy, dx) * 180 / CGFloat(M_PI));
87 if (degrees > kMaxSwipeYAngle) { 98 if (degrees > kMaxSwipeYAngle) {
88 self.state = UIGestureRecognizerStateFailed; 99 self.state = UIGestureRecognizerStateFailed;
89 return; 100 return;
90 } 101 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 _startPoint = CGPointZero; 141 _startPoint = CGPointZero;
131 [super touchesEnded:touches withEvent:event]; 142 [super touchesEnded:touches withEvent:event];
132 } 143 }
133 144
134 - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event { 145 - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
135 _startPoint = CGPointZero; 146 _startPoint = CGPointZero;
136 [super touchesCancelled:touches withEvent:event]; 147 [super touchesCancelled:touches withEvent:event];
137 } 148 }
138 149
139 @end 150 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698