summaryrefslogtreecommitdiff
path: root/UICaboodle
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2011-02-17 01:45:59 -0800
committerJay Freeman (saurik) <saurik@saurik.com>2011-02-17 02:21:53 -0800
commitf196b921bfe9e90d63869d060ae3e102dc82408a (patch)
treee8c3544eeb6598058fcb959f27f54e216b23b9a0 /UICaboodle
parent0893a034f90f80629c5b634b564bdd4977c48369 (diff)
Use document.dispatchEvent() for UIViewController events.
Diffstat (limited to 'UICaboodle')
-rw-r--r--UICaboodle/BrowserView.h2
-rw-r--r--UICaboodle/BrowserView.mm43
2 files changed, 45 insertions, 0 deletions
diff --git a/UICaboodle/BrowserView.h b/UICaboodle/BrowserView.h
index f6d689a..692704a 100644
--- a/UICaboodle/BrowserView.h
+++ b/UICaboodle/BrowserView.h
@@ -126,4 +126,6 @@
- (void) close;
+- (void) dispatchEvent:(NSString *)event;
+
@end
diff --git a/UICaboodle/BrowserView.mm b/UICaboodle/BrowserView.mm
index 956e359..bdb5753 100644
--- a/UICaboodle/BrowserView.mm
+++ b/UICaboodle/BrowserView.mm
@@ -1174,4 +1174,47 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
return 980;
}
+- (void) dispatchEvent:(NSString *)event {
+ WebThreadLocked lock;
+
+ NSString *script([NSString stringWithFormat:@
+ "(function() {"
+ "var event = this.document.createEvent('Events');"
+ "event.initEvent('%@', false, false);"
+ "this.document.dispatchEvent(event);"
+ "})();"
+ , event]);
+
+ NSMutableArray *frames([NSMutableArray arrayWithObjects:
+ [[[webview_ _documentView] webView] mainFrame]
+ , nil]);
+
+ while (WebFrame *frame = [frames lastObject]) {
+ WebScriptObject *object([frame windowObject]);
+ [object evaluateWebScript:script];
+ [frames removeLastObject];
+ [frames addObjectsFromArray:[frame childFrames]];
+ }
+}
+
+- (void) viewWillAppear:(BOOL)animated {
+ [self dispatchEvent:@"CydiaViewWillAppear"];
+ [super viewWillAppear:animated];
+}
+
+- (void) viewDidAppear:(BOOL)animated {
+ [self dispatchEvent:@"CydiaViewDidAppear"];
+ [super viewDidAppear:animated];
+}
+
+- (void) viewWillDisappear:(BOOL)animated {
+ [self dispatchEvent:@"CydiaViewWillDisappear"];
+ [super viewWillDisappear:animated];
+}
+
+- (void) viewDidDisappear:(BOOL)animated {
+ [self dispatchEvent:@"CydiaViewDidDisappear"];
+ [super viewDidDisappear:animated];
+}
+
@end