-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_mac.mm
113 lines (85 loc) · 3.89 KB
/
view_mac.mm
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
#include "view.h"
#import <Cocoa/Cocoa.h>
#include <Awesomium/WebCore.h>
#include <Awesomium/STLHelpers.h>
#include <vector>
@interface WinDelegate : NSObject<NSWindowDelegate> {
Awesomium::WebView* webView;
}
@property (assign) Awesomium::WebView* webView;
- (void)windowDidResize:(NSNotification *)notification;
@end
using namespace Awesomium;
class ViewMac : public View,
public WebViewListener::View {
public:
ViewMac(int width, int height) {
web_view_ = WebCore::instance()->CreateWebView(width,
height,
0,
Awesomium::kWebViewType_Window);
web_view_->set_view_listener(this);
window_ = [[[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, width, height)
styleMask:NSTitledWindowMask | NSResizableWindowMask | NSClosableWindowMask
backing:NSBackingStoreBuffered defer:NO]
autorelease];
[window_ cascadeTopLeftFromPoint:NSMakePoint(20,20)];
[window_ setTitle:@"Application"];
NSView* contentsContainer = [window_ contentView];
NSView* contentsNativeView = web_view_->window();
NSRect contentsNativeViewFrame = [contentsContainer frame];
contentsNativeViewFrame.origin = NSZeroPoint;
[contentsNativeView setFrame:contentsNativeViewFrame];
[contentsContainer addSubview:contentsNativeView];
win_delegate_ = [[WinDelegate alloc] init];
[window_ setDelegate:win_delegate_];
win_delegate_.webView = web_view_;
[window_ makeKeyAndOrderFront:nil];
}
virtual ~ViewMac() {
[window_ setDelegate:nil];
[win_delegate_ release];
[window_ release];
web_view_->Destroy();
}
// Following methods are inherited from WebViewListener::View
virtual void OnChangeTitle(Awesomium::WebView* caller,
const Awesomium::WebString& title) {
std::string title_utf8(ToString(title));
[window_ setTitle:[[NSString alloc] initWithUTF8String:title_utf8.c_str()]];
}
virtual void OnChangeAddressBar(Awesomium::WebView* caller,
const Awesomium::WebURL& url) { }
virtual void OnChangeTooltip(Awesomium::WebView* caller,
const Awesomium::WebString& tooltip) { }
virtual void OnChangeTargetURL(Awesomium::WebView* caller,
const Awesomium::WebURL& url) { }
virtual void OnChangeCursor(Awesomium::WebView* caller,
Awesomium::Cursor cursor) { }
virtual void OnChangeFocus(Awesomium::WebView* caller,
Awesomium::FocusedElementType focused_type) { }
virtual void OnAddConsoleMessage(Awesomium::WebView* caller,
const Awesomium::WebString& message,
int line_number,
const Awesomium::WebString& source) { }
virtual void OnShowCreatedWebView(Awesomium::WebView* caller,
Awesomium::WebView* new_view,
const Awesomium::WebURL& opener_url,
const Awesomium::WebURL& target_url,
const Awesomium::Rect& initial_pos,
bool is_popup) { }
protected:
NSWindow* window_;
WinDelegate* win_delegate_;
};
View* View::Create(int width, int height) {
return new ViewMac(width, height);
}
@implementation WinDelegate
@synthesize webView;
- (void)windowDidResize:(NSNotification *)notification {
NSWindow* window = [notification object];
NSSize windowSize = [[window contentView] frame].size;
webView->Resize((int)windowSize.width, (int)windowSize.height);
}
@end