-
Notifications
You must be signed in to change notification settings - Fork 0
/
RPWebViewController.m
130 lines (99 loc) · 2.79 KB
/
RPWebViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// RPWebViewController.m
// Rampler
//
// Copyright 2010-2012 Fotonauts. All rights reserved.
//
#import "RPWebViewController.h"
#import "RPURLLoaderController.h"
@interface RPWebViewController()
@property (nonatomic) NSString *statusBarValue;
@end
@implementation RPWebViewController
@synthesize statusBarValue;
@synthesize webView;
- (void)open
{
if (!window) {
[NSBundle loadNibNamed:@"WebViewController" owner:self];
[webView setUIDelegate:self];
[webView setFrameLoadDelegate:self];
}
[window makeKeyAndOrderFront:nil];
}
- (IBAction)backButtonAction:(id)sender
{
[webView goBack:sender];
}
- (IBAction)forwardButtonAction:(id)sender
{
[webView goForward:sender];
}
- (IBAction)leftRightClicked:(id)sender
{
NSSegmentedControl* control = sender;
if ([control selectedSegment] == 0) {
[self backButtonAction:sender];
} else {
[self forwardButtonAction:sender];
}
}
- (IBAction)refresh:(id)sender
{
[[webView mainFrame] reload];
}
- (NSString*)currentURLString
{
WebFrame* frame = [webView mainFrame];
WebDataSource* currentDataSource;
(currentDataSource = [frame provisionalDataSource]) || (currentDataSource = [frame dataSource]);
NSURL* currentURL = [[currentDataSource request] URL];
return [currentURL absoluteString];
}
- (IBAction)sampleCurrentURL:(id)sender
{
RPURLLoaderController* urlLoader = [RPURLLoaderController sharedURLLoaderController];
if ([self currentURLString]) {
urlLoader.urlString = [self currentURLString];
}
[urlLoader openOpenURLDialog:sender];
}
- (IBAction)addressTextFieldAction:(id)sender
{
NSURL *url;
url = [NSURL URLWithString:[addressTextField stringValue]];
if (![url scheme] || [[url scheme] isEqualToString:@""]) {
url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", [addressTextField stringValue]]];
}
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
}
- (void)webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame
{
if (frame == [webView mainFrame])
[window setTitle:title];
}
@end
@implementation RPWebViewController(WebFrameLoadDelegate)
- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame
{
[addressTextField setStringValue:[self currentURLString]];
[statusBar setStringValue:@"Loading…"];
}
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
[statusBar setStringValue:self.statusBarValue];
}
@end
@implementation RPWebViewController(UIDelegate)
- (void)webView:(WebView *)sender setStatusText:(NSString *)text
{
if (![webView isLoading]) {
[statusBar setStringValue:text];
}
self.statusBarValue = text;
}
- (NSString *)webViewStatusText:(WebView *)sender
{
return self.statusBarValue;
}
@end