Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions Browser/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ @interface ViewController ()
NSString *temporaryURL;
}

@property UIWebView *webview;
@property id webview;
@property (strong) CADisplayLink *link;
@property (strong, nonatomic) GCController *controller;
@property BOOL cursorMode;
Expand All @@ -39,17 +39,20 @@ - (void)viewDidLoad {
cursorView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Cursor"]];
cursorView.hidden = YES;

self.webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"]]];

Class UIWebViewClass = NSClassFromString(@"UIWebView");

_webview = [[UIWebViewClass alloc] initWithFrame:[UIScreen mainScreen].bounds];
[_webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"]]];

[self.view addSubview:self.webview];
[self.view addSubview:_webview];
[self.view addSubview:cursorView];

self.link = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateCursor)];
[self.link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];

self.webview.scrollView.bounces = YES;
self.webview.scrollView.panGestureRecognizer.allowedTouchTypes = @[ @(UITouchTypeIndirect) ];
[_webview scrollView].bounces = YES;
[_webview scrollView].panGestureRecognizer.allowedTouchTypes = @[ @(UITouchTypeIndirect) ];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setupController) name:GCControllerDidConnectNotification object:nil];
}
Expand All @@ -60,14 +63,14 @@ -(void)toggleMode

if (self.cursorMode)
{
self.webview.scrollView.scrollEnabled = NO;
self.webview.userInteractionEnabled = NO;
[_webview scrollView].scrollEnabled = NO;
[_webview setUserInteractionEnabled:NO];
cursorView.hidden = NO;
}
else
{
self.webview.scrollView.scrollEnabled = YES;
self.webview.userInteractionEnabled = YES;
[_webview scrollView].scrollEnabled = YES;
[_webview setUserInteractionEnabled:YES];
cursorView.hidden = YES;
}
}
Expand All @@ -92,13 +95,13 @@ -(void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)even
[self dismissViewControllerAnimated:YES completion:nil];
}
else
[self.webview goBack];
[_webview goBack];
}
else if (presses.anyObject.type == UIPressTypeSelect)
{
/* Gross. */
CGPoint point = [self.webview convertPoint:cursorView.frame.origin toView:nil];
[self.webview stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.elementFromPoint(%i, %i).click()", (int)point.x, (int)point.y]];
[_webview stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.elementFromPoint(%i, %i).click()", (int)point.x, (int)point.y]];
}

else if (presses.anyObject.type == UIPressTypePlayPause)
Expand All @@ -123,7 +126,7 @@ -(void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)even
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@", temporaryURL]]]];
[_webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@", temporaryURL]]]];
temporaryURL = nil;
}];

Expand Down