[GTK][WPE] File and Directory Entries API is not enabled
[WebKit-https.git] / Source / WebKit / UIProcess / ios / WKSyntheticTapGestureRecognizer.mm
1 /*
2  * Copyright (C) 2014 - 2019 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #import "config.h"
27 #import "WKSyntheticTapGestureRecognizer.h"
28
29 #if PLATFORM(IOS_FAMILY)
30
31 #import <UIKit/UIGestureRecognizerSubclass.h>
32 #import <wtf/RetainPtr.h>
33 #import <wtf/WeakObjCPtr.h>
34
35 @implementation WKSyntheticTapGestureRecognizer {
36     id _gestureIdentifiedTarget;
37     SEL _gestureIdentifiedAction;
38     id _gestureFailedTarget;
39     SEL _gestureFailedAction;
40     id _resetTarget;
41     SEL _resetAction;
42     RetainPtr<NSNumber> _lastActiveTouchIdentifier;
43     WeakObjCPtr<UIScrollView> _lastTouchedScrollView;
44 }
45
46 - (void)setGestureIdentifiedTarget:(id)target action:(SEL)action
47 {
48     _gestureIdentifiedTarget = target;
49     _gestureIdentifiedAction = action;
50 }
51
52 - (void)setGestureFailedTarget:(id)target action:(SEL)action
53 {
54     _gestureFailedTarget = target;
55     _gestureFailedAction = action;
56 }
57
58 - (void)setResetTarget:(id)target action:(SEL)action
59 {
60     _resetTarget = target;
61     _resetAction = action;
62 }
63
64 - (void)setState:(UIGestureRecognizerState)state
65 {
66     if (state == UIGestureRecognizerStateEnded)
67         [_gestureIdentifiedTarget performSelector:_gestureIdentifiedAction withObject:self];
68     else if (state == UIGestureRecognizerStateFailed)
69         [_gestureFailedTarget performSelector:_gestureFailedAction withObject:self];
70     [super setState:state];
71 }
72
73 - (void)reset
74 {
75     [super reset];
76     [_resetTarget performSelector:_resetAction withObject:self];
77 #if ENABLE(POINTER_EVENTS) 
78     _lastActiveTouchIdentifier = nil;
79 #endif
80     _lastTouchedScrollView = nil;
81 }
82
83 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
84 {
85     [super touchesBegan:touches withEvent:event];
86
87     for (UITouch *touch in touches) {
88         if ([touch.view isKindOfClass:UIScrollView.class]) {
89             _lastTouchedScrollView = (UIScrollView *)touch.view;
90             break;
91         }
92     }
93 }
94
95 - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
96 {
97     [super touchesEnded:touches withEvent:event];
98 #if ENABLE(POINTER_EVENTS)
99     if (!_supportingWebTouchEventsGestureRecognizer)
100         return;
101
102     // FIXME: <rdar://problem/48035706>
103     NSMapTable<NSNumber *, UITouch *> *activeTouches = [_supportingWebTouchEventsGestureRecognizer activeTouchesByIdentifier];
104     for (NSNumber *touchIdentifier in activeTouches) {
105         UITouch *touch = [activeTouches objectForKey:touchIdentifier];
106         if ([touch.gestureRecognizers containsObject:self]) {
107             _lastActiveTouchIdentifier = touchIdentifier;
108             break;
109         }
110     }
111 #endif
112 }
113
114 - (UIScrollView *)lastTouchedScrollView
115 {
116     return _lastTouchedScrollView.get().get();
117 }
118
119 - (NSNumber*)lastActiveTouchIdentifier
120 {
121     return _lastActiveTouchIdentifier.get();
122 }
123
124 @end
125
126 #endif