2013-03-14 13:03:50 +00:00
|
|
|
#import "browser/mac/bry_inspectable_web_contents_view.h"
|
|
|
|
|
|
|
|
#import "browser/inspectable_web_contents_impl.h"
|
|
|
|
#import "browser/inspectable_web_contents_view_mac.h"
|
|
|
|
|
2013-04-09 19:11:16 +00:00
|
|
|
#import "content/public/browser/render_widget_host_view.h"
|
2013-03-14 13:03:50 +00:00
|
|
|
#import "content/public/browser/web_contents_view.h"
|
2013-11-25 21:28:57 +00:00
|
|
|
#import "ui/base/cocoa/underlay_opengl_hosting_window.h"
|
2013-03-14 13:03:50 +00:00
|
|
|
|
|
|
|
using namespace brightray;
|
|
|
|
|
|
|
|
@implementation BRYInspectableWebContentsView
|
|
|
|
|
2014-07-01 12:57:49 +00:00
|
|
|
- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)inspectableWebContentsView {
|
2013-03-14 13:03:50 +00:00
|
|
|
self = [super init];
|
|
|
|
if (!self)
|
|
|
|
return nil;
|
|
|
|
|
2014-07-01 12:57:49 +00:00
|
|
|
inspectableWebContentsView_ = inspectableWebContentsView;
|
|
|
|
devtools_visible_ = NO;
|
2013-03-14 13:03:50 +00:00
|
|
|
|
2014-07-01 12:57:49 +00:00
|
|
|
auto webView = inspectableWebContentsView->inspectable_web_contents()->GetWebContents()->GetView()->GetNativeView();
|
|
|
|
webView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
|
|
[self addSubview:webView];
|
2013-03-14 13:03:50 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)showDevTools:(id)sender {
|
2014-07-01 12:57:49 +00:00
|
|
|
inspectableWebContentsView_->inspectable_web_contents()->ShowDevTools();
|
2013-03-14 13:03:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDevToolsVisible:(BOOL)visible {
|
2014-07-01 12:57:49 +00:00
|
|
|
if (devtools_visible_ == visible)
|
2013-03-27 16:15:46 +00:00
|
|
|
return;
|
2014-07-01 12:57:49 +00:00
|
|
|
devtools_visible_ = visible;
|
|
|
|
|
|
|
|
if (!devtools_window_) {
|
|
|
|
auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents();
|
|
|
|
auto devToolsView = devToolsWebContents->GetView()->GetNativeView();
|
|
|
|
|
|
|
|
auto styleMask = NSTitledWindowMask | NSClosableWindowMask |
|
|
|
|
NSMiniaturizableWindowMask | NSResizableWindowMask |
|
|
|
|
NSTexturedBackgroundWindowMask |
|
|
|
|
NSUnifiedTitleAndToolbarWindowMask;
|
|
|
|
devtools_window_.reset([[UnderlayOpenGLHostingWindow alloc]
|
|
|
|
initWithContentRect:NSMakeRect(0, 0, 800, 600)
|
|
|
|
styleMask:styleMask
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:YES]);
|
|
|
|
[devtools_window_ setDelegate:self];
|
|
|
|
[devtools_window_ setFrameAutosaveName:@"brightray.developer.tools"];
|
|
|
|
[devtools_window_ setTitle:@"Developer Tools"];
|
|
|
|
[devtools_window_ setReleasedWhenClosed:NO];
|
|
|
|
[devtools_window_ setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge];
|
|
|
|
[devtools_window_ setContentBorderThickness:24 forEdge:NSMaxYEdge];
|
|
|
|
|
|
|
|
NSView* contentView = [devtools_window_ contentView];
|
|
|
|
devToolsView.frame = contentView.bounds;
|
|
|
|
devToolsView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
|
|
|
|
|
|
[contentView addSubview:devToolsView];
|
2013-03-27 16:15:46 +00:00
|
|
|
}
|
|
|
|
|
2013-03-14 13:03:50 +00:00
|
|
|
if (visible) {
|
2014-07-01 12:57:49 +00:00
|
|
|
[devtools_window_ makeKeyAndOrderFront:nil];
|
2013-03-14 13:03:50 +00:00
|
|
|
} else {
|
2014-07-01 12:57:49 +00:00
|
|
|
[devtools_window_ performClose:nil];
|
2013-03-14 13:03:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-05 02:29:53 +00:00
|
|
|
- (BOOL)isDevToolsVisible {
|
2014-07-01 12:57:49 +00:00
|
|
|
return devtools_visible_;
|
2013-11-05 02:29:53 +00:00
|
|
|
}
|
|
|
|
|
2013-03-27 15:19:15 +00:00
|
|
|
- (BOOL)setDockSide:(const std::string&)side {
|
2013-03-27 16:15:46 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2014-07-01 12:57:49 +00:00
|
|
|
#pragma mark - NSWindowDelegate
|
2013-04-09 19:11:16 +00:00
|
|
|
|
2014-07-01 12:57:49 +00:00
|
|
|
- (void)windowWillClose:(NSNotification*)notification {
|
|
|
|
devtools_visible_ = NO;
|
|
|
|
devtools_window_.reset();
|
2013-04-09 19:11:16 +00:00
|
|
|
}
|
|
|
|
|
2013-03-14 13:03:50 +00:00
|
|
|
@end
|