]> git.saurik.com Git - cydia.git/blame - CyteKit/dispatchEvent.mm
Remove obsolete commented-out source check stuff.
[cydia.git] / CyteKit / dispatchEvent.mm
CommitLineData
31f9c8f7 1/* Cydia - iPhone UIKit Front-End for Debian APT
323746d3 2 * Copyright (C) 2008-2013 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
22#include "CyteKit/dispatchEvent.h"
23#include "CyteKit/WebThreadLocked.hpp"
24
ea5bf5cc
JF
25#include <WebCore/WebEvent.h>
26
31f9c8f7
JF
27#include <WebKit/WebFrame.h>
28#include <WebKit/WebScriptObject.h>
29#include <WebKit/WebView.h>
30
31#include <objc/runtime.h>
32
33#include <CydiaSubstrate/CydiaSubstrate.h>
34
35@implementation UIWebDocumentView (CyteDispatchEvent)
36
37- (void) dispatchEvent:(NSString *)event {
38 WebThreadLocked lock;
39
40 NSString *script([NSString stringWithFormat:@
41 "(function() {"
42 "var event = this.document.createEvent('Events');"
43 "event.initEvent('%@', false, false);"
44 "this.document.dispatchEvent(event);"
45 "})();"
46 , event]);
47
48 NSMutableArray *frames([NSMutableArray arrayWithObjects:
49 [[self webView] mainFrame]
50 , nil]);
51
52 while (WebFrame *frame = [frames lastObject]) {
53 WebScriptObject *object([frame windowObject]);
54 [object evaluateWebScript:script];
55 [frames removeLastObject];
56 [frames addObjectsFromArray:[frame childFrames]];
57 }
58}
59
60@end
4f651400
JF
61
62MSHook(void, UIWebBrowserView$_webTouchEventsRecognized$, UIWebBrowserView *self, SEL _cmd, UIWebTouchEventsGestureRecognizer *recognizer) {
63 _UIWebBrowserView$_webTouchEventsRecognized$(self, _cmd, recognizer);
64
ea5bf5cc
JF
65 switch ([recognizer type]) {
66 case WebEventTouchEnd:
67 [self dispatchEvent:@"CydiaTouchEnd"];
68 break;
69
70 case WebEventTouchCancel:
71 [self dispatchEvent:@"CydiaTouchCancel"];
72 break;
73 }
4f651400
JF
74}
75
76__attribute__((__constructor__)) static void $() {
77 if (Class $UIWebBrowserView = objc_getClass("UIWebBrowserView")) {
78 if (Method method = class_getInstanceMethod($UIWebBrowserView, @selector(_webTouchEventsRecognized:))) {
4cc9e99a 79 _UIWebBrowserView$_webTouchEventsRecognized$ = reinterpret_cast<void (*)(UIWebBrowserView *, SEL, UIWebTouchEventsGestureRecognizer *)>(method_getImplementation(method));
4f651400
JF
80 method_setImplementation(method, reinterpret_cast<IMP>(&$UIWebBrowserView$_webTouchEventsRecognized$));
81 }
82 }
83}