electron/brightray/browser/mac/bry_inspectable_web_contents_view.mm
Adam Roben b2a79856ef Add InspectableWebContents
This class can be used to create a content::WebContents that can be inspected
by the Chrome Dev Tools. This requires embedding applications to copy
content_shell.pak into their resource bundle.

Right now the dev tools are always docked to the bottom of the view; we don't
yet support undocking or changing the docked side.

Fixes #1.
2013-03-14 09:05:42 -04:00

77 lines
No EOL
2.4 KiB
Text

#import "browser/mac/bry_inspectable_web_contents_view.h"
#import "browser/inspectable_web_contents_impl.h"
#import "browser/inspectable_web_contents_view_mac.h"
#import "browser/mac/bry_inspectable_web_contents_view_private.h"
#import "content/public/browser/web_contents_view.h"
using namespace brightray;
@interface BRYInspectableWebContentsViewPrivate : NSObject {
@public
InspectableWebContentsViewMac *inspectableWebContentsView;
NSSplitView *splitView;
}
@end
@implementation BRYInspectableWebContentsView
- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac *)inspectableWebContentsView {
self = [super init];
if (!self)
return nil;
_private = [[BRYInspectableWebContentsViewPrivate alloc] init];
_private->inspectableWebContentsView = inspectableWebContentsView;
_private->splitView = [[NSSplitView alloc] init];
[self addSubview:_private->splitView];
_private->splitView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
_private->splitView.dividerStyle = NSSplitViewDividerStyleThin;
[_private->splitView addSubview:inspectableWebContentsView->inspectable_web_contents()->GetWebContents()->GetView()->GetNativeView()];
return self;
}
- (void)dealloc {
[_private release];
_private = nil;
[super dealloc];
}
- (IBAction)showDevTools:(id)sender {
_private->inspectableWebContentsView->inspectable_web_contents()->ShowDevTools();
}
- (void)setDevToolsVisible:(BOOL)visible {
BOOL wasVisible = _private->splitView.subviews.count == 2;
if (wasVisible == visible)
return;
auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents();
auto devToolsView = devToolsWebContents->GetView()->GetNativeView();
if (visible) {
auto inspectedView = _private->inspectableWebContentsView->inspectable_web_contents()->GetWebContents()->GetView()->GetNativeView();
CGRect frame = NSRectToCGRect(inspectedView.frame);
CGRect inspectedViewFrame;
CGRect devToolsFrame;
CGRectDivide(frame, &inspectedViewFrame, &devToolsFrame, CGRectGetHeight(frame) * 2 / 3, CGRectMaxYEdge);
inspectedView.frame = NSRectFromCGRect(inspectedViewFrame);
devToolsView.frame = NSRectFromCGRect(devToolsFrame);
[_private->splitView addSubview:devToolsView];
} else {
[devToolsView removeFromSuperview];
}
[_private->splitView adjustSubviews];
}
@end
@implementation BRYInspectableWebContentsViewPrivate
@end