]> git.saurik.com Git - cydia.git/blame - CyteKit/dispatchEvent.mm
Ignore .dSYM folders I am suddenly ending up with.
[cydia.git] / CyteKit / dispatchEvent.mm
CommitLineData
31f9c8f7 1/* Cydia - iPhone UIKit Front-End for Debian APT
4c66fad9 2 * Copyright (C) 2008-2015 Jay Freeman (saurik)
31f9c8f7
JF
3*/
4
6d9696a5 5/* GNU General Public License, Version 3 {{{ */
31f9c8f7 6/*
6d9696a5
JF
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
31f9c8f7 11 *
6d9696a5
JF
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
31f9c8f7 16 *
6d9696a5
JF
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
19**/
31f9c8f7
JF
20/* }}} */
21
63755c48
JF
22#include "CyteKit/UCPlatform.h"
23
31f9c8f7
JF
24#include "CyteKit/dispatchEvent.h"
25#include "CyteKit/WebThreadLocked.hpp"
26
a09f7a48 27#include "Substrate.hpp"
31f9c8f7
JF
28
29@implementation UIWebDocumentView (CyteDispatchEvent)
30
31- (void) dispatchEvent:(NSString *)event {
32 WebThreadLocked lock;
33
34 NSString *script([NSString stringWithFormat:@
35 "(function() {"
36 "var event = this.document.createEvent('Events');"
37 "event.initEvent('%@', false, false);"
38 "this.document.dispatchEvent(event);"
39 "})();"
40 , event]);
41
42 NSMutableArray *frames([NSMutableArray arrayWithObjects:
43 [[self webView] mainFrame]
44 , nil]);
45
46 while (WebFrame *frame = [frames lastObject]) {
47 WebScriptObject *object([frame windowObject]);
48 [object evaluateWebScript:script];
49 [frames removeLastObject];
50 [frames addObjectsFromArray:[frame childFrames]];
51 }
52}
53
54@end
4f651400
JF
55
56MSHook(void, UIWebBrowserView$_webTouchEventsRecognized$, UIWebBrowserView *self, SEL _cmd, UIWebTouchEventsGestureRecognizer *recognizer) {
57 _UIWebBrowserView$_webTouchEventsRecognized$(self, _cmd, recognizer);
58
ea5bf5cc
JF
59 switch ([recognizer type]) {
60 case WebEventTouchEnd:
61 [self dispatchEvent:@"CydiaTouchEnd"];
62 break;
63
64 case WebEventTouchCancel:
65 [self dispatchEvent:@"CydiaTouchCancel"];
66 break;
67 }
4f651400
JF
68}
69
70__attribute__((__constructor__)) static void $() {
71 if (Class $UIWebBrowserView = objc_getClass("UIWebBrowserView")) {
72 if (Method method = class_getInstanceMethod($UIWebBrowserView, @selector(_webTouchEventsRecognized:))) {
4cc9e99a 73 _UIWebBrowserView$_webTouchEventsRecognized$ = reinterpret_cast<void (*)(UIWebBrowserView *, SEL, UIWebTouchEventsGestureRecognizer *)>(method_getImplementation(method));
4f651400
JF
74 method_setImplementation(method, reinterpret_cast<IMP>(&$UIWebBrowserView$_webTouchEventsRecognized$));
75 }
76 }
77}