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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ios/chrome/browser/ui/contextual_search/window_gesture_observer.h"
6
7 @implementation WindowGestureObserver {
8 NSObject* _target;
9 SEL _action;
10 BOOL _actionPassesSelf;
11 }
12
13 @synthesize viewToExclude = _viewToExclude;
14 @synthesize touchedView = _touchedView;
15
16 - (instancetype)initWithTarget:(id)target action:(SEL)action {
17 if ((self = [super initWithTarget:target action:action])) {
18 _target = static_cast<NSObject*>(target);
19 _action = action;
20 NSMethodSignature* signature = [_target methodSignatureForSelector:action];
21 _actionPassesSelf = [signature numberOfArguments] == 3;
22 [self removeTarget:target action:action];
23 self.cancelsTouchesInView = NO;
24 }
25 return self;
26 }
27
28 - (void)setViewToExclude:(UIView*)viewToExclude {
29 _viewToExclude = viewToExclude;
30 for (UIGestureRecognizer* recognizer in [viewToExclude gestureRecognizers]) {
31 [self requireGestureRecognizerToFail:recognizer];
32 }
33 }
34
35 - (void)addTarget:(id)target action:(SEL)action {
36 // No-op.
37 }
38
39 - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
40 _touchedView = nil;
41 for (UITouch* touch in touches) {
42 if (![[touch view] isDescendantOfView:_viewToExclude]) {
43 _touchedView = [touch view];
44 dispatch_async(dispatch_get_main_queue(), ^{
45 if (_actionPassesSelf) {
46 [_target performSelector:_action withObject:self];
47 } else {
48 [_target performSelector:_action];
49 }
50 });
51 // Only invoke from the first qualifying touch.
52 break;
53 }
54 }
55
56 // Cancels to forward touch to other handlers.
57 self.state = UIGestureRecognizerStateFailed;
58 [super touchesBegan:touches withEvent:event];
59 }
60
61 @end
OLDNEW
« 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