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

Unified Diff: ios/chrome/browser/ui/contextual_search/window_gesture_observer.mm

Issue 2588713002: Upstream Chrome on iOS source code [4/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/contextual_search/window_gesture_observer.mm
diff --git a/ios/chrome/browser/ui/contextual_search/window_gesture_observer.mm b/ios/chrome/browser/ui/contextual_search/window_gesture_observer.mm
new file mode 100644
index 0000000000000000000000000000000000000000..0ef504e8114087cc42992b25b0d97e3076c5df6c
--- /dev/null
+++ b/ios/chrome/browser/ui/contextual_search/window_gesture_observer.mm
@@ -0,0 +1,61 @@
+// Copyright 2014 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.
+
+#include "ios/chrome/browser/ui/contextual_search/window_gesture_observer.h"
+
+@implementation WindowGestureObserver {
+ NSObject* _target;
+ SEL _action;
+ BOOL _actionPassesSelf;
+}
+
+@synthesize viewToExclude = _viewToExclude;
+@synthesize touchedView = _touchedView;
+
+- (instancetype)initWithTarget:(id)target action:(SEL)action {
+ if ((self = [super initWithTarget:target action:action])) {
+ _target = static_cast<NSObject*>(target);
+ _action = action;
+ NSMethodSignature* signature = [_target methodSignatureForSelector:action];
+ _actionPassesSelf = [signature numberOfArguments] == 3;
+ [self removeTarget:target action:action];
+ self.cancelsTouchesInView = NO;
+ }
+ return self;
+}
+
+- (void)setViewToExclude:(UIView*)viewToExclude {
+ _viewToExclude = viewToExclude;
+ for (UIGestureRecognizer* recognizer in [viewToExclude gestureRecognizers]) {
+ [self requireGestureRecognizerToFail:recognizer];
+ }
+}
+
+- (void)addTarget:(id)target action:(SEL)action {
+ // No-op.
+}
+
+- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
+ _touchedView = nil;
+ for (UITouch* touch in touches) {
+ if (![[touch view] isDescendantOfView:_viewToExclude]) {
+ _touchedView = [touch view];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if (_actionPassesSelf) {
+ [_target performSelector:_action withObject:self];
+ } else {
+ [_target performSelector:_action];
+ }
+ });
+ // Only invoke from the first qualifying touch.
+ break;
+ }
+ }
+
+ // Cancels to forward touch to other handlers.
+ self.state = UIGestureRecognizerStateFailed;
+ [super touchesBegan:touches withEvent:event];
+}
+
+@end
« no previous file with comments | « ios/chrome/browser/ui/contextual_search/window_gesture_observer.h ('k') | ios/chrome/browser/ui/dialogs/dialog_presenter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698