mac: Revert to simplest undocked-only devtools.
This makes porting Chrome's devtools easier.
This commit is contained in:
parent
6c825042b5
commit
7d130c9697
5 changed files with 59 additions and 226 deletions
|
@ -60,7 +60,6 @@
|
|||
'browser/mac/bry_application.mm',
|
||||
'browser/mac/bry_inspectable_web_contents_view.h',
|
||||
'browser/mac/bry_inspectable_web_contents_view.mm',
|
||||
'browser/mac/bry_inspectable_web_contents_view_private.h',
|
||||
'browser/media/media_capture_devices_dispatcher.cc',
|
||||
'browser/media/media_capture_devices_dispatcher.h',
|
||||
'browser/media/media_stream_devices_controller.cc',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#import "browser/inspectable_web_contents_view_mac.h"
|
||||
|
||||
#import "browser/inspectable_web_contents.h"
|
||||
#import "browser/mac/bry_inspectable_web_contents_view_private.h"
|
||||
#import "browser/mac/bry_inspectable_web_contents_view.h"
|
||||
|
||||
#import "content/public/browser/web_contents_view.h"
|
||||
#import <AppKit/AppKit.h>
|
||||
|
@ -18,7 +18,6 @@ InspectableWebContentsViewMac::InspectableWebContentsViewMac(InspectableWebConte
|
|||
}
|
||||
|
||||
InspectableWebContentsViewMac::~InspectableWebContentsViewMac() {
|
||||
[view_ removeFromNotificationCenter];
|
||||
}
|
||||
|
||||
gfx::NativeView InspectableWebContentsViewMac::GetNativeView() const {
|
||||
|
|
|
@ -1,14 +1,24 @@
|
|||
#import <AppKit/AppKit.h>
|
||||
|
||||
@class BRYInspectableWebContentsViewPrivate;
|
||||
#include <string>
|
||||
|
||||
@interface BRYInspectableWebContentsView
|
||||
: NSView<NSWindowDelegate, NSSplitViewDelegate> {
|
||||
@private
|
||||
BRYInspectableWebContentsViewPrivate *_private;
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
|
||||
namespace brightray {
|
||||
class InspectableWebContentsViewMac;
|
||||
}
|
||||
|
||||
- (void)removeFromNotificationCenter;
|
||||
@interface BRYInspectableWebContentsView : NSView<NSWindowDelegate> {
|
||||
@private
|
||||
brightray::InspectableWebContentsViewMac* inspectableWebContentsView_;
|
||||
base::scoped_nsobject<NSWindow> devtools_window_;
|
||||
BOOL devtools_visible_;
|
||||
}
|
||||
|
||||
- (instancetype)initWithInspectableWebContentsViewMac:(brightray::InspectableWebContentsViewMac*)inspectableWebContentsView;
|
||||
- (IBAction)showDevTools:(id)sender;
|
||||
- (void)setDevToolsVisible:(BOOL)visible;
|
||||
- (BOOL)isDevToolsVisible;
|
||||
- (BOOL)setDockSide:(const std::string&)side ;
|
||||
|
||||
@end
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#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/render_widget_host_view.h"
|
||||
#import "content/public/browser/web_contents_view.h"
|
||||
|
@ -10,243 +9,83 @@
|
|||
|
||||
using namespace brightray;
|
||||
|
||||
@interface GraySplitView : NSSplitView
|
||||
- (NSColor*)dividerColor;
|
||||
@end
|
||||
|
||||
@implementation GraySplitView
|
||||
- (NSColor*)dividerColor {
|
||||
return [NSColor darkGrayColor];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@interface BRYInspectableWebContentsViewPrivate : NSObject {
|
||||
@public
|
||||
InspectableWebContentsViewMac *inspectableWebContentsView;
|
||||
GraySplitView *splitView;
|
||||
NSWindow *window;
|
||||
BOOL visible;
|
||||
}
|
||||
@end
|
||||
|
||||
namespace {
|
||||
|
||||
NSRect devtoolsWindowFrame(NSView *referenceView) {
|
||||
auto screenFrame = [referenceView.window convertRectToScreen:[referenceView convertRect:referenceView.bounds toView:nil]];
|
||||
return NSInsetRect(screenFrame, NSWidth(screenFrame) / 6, NSHeight(screenFrame) / 6);
|
||||
}
|
||||
|
||||
void SetActive(content::WebContents* web_contents, bool active) {
|
||||
auto render_widget_host_view = web_contents->GetRenderWidgetHostView();
|
||||
if (!render_widget_host_view)
|
||||
return;
|
||||
|
||||
render_widget_host_view->SetActive(active);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@implementation BRYInspectableWebContentsView
|
||||
|
||||
- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac *)inspectableWebContentsView {
|
||||
- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)inspectableWebContentsView {
|
||||
self = [super init];
|
||||
if (!self)
|
||||
return nil;
|
||||
|
||||
_private = [[BRYInspectableWebContentsViewPrivate alloc] init];
|
||||
_private->inspectableWebContentsView = inspectableWebContentsView;
|
||||
_private->splitView = [[GraySplitView alloc] init];
|
||||
_private->splitView.delegate = self;
|
||||
inspectableWebContentsView_ = inspectableWebContentsView;
|
||||
devtools_visible_ = NO;
|
||||
|
||||
[self addSubview:_private->splitView];
|
||||
_private->splitView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
||||
_private->splitView.dividerStyle = NSSplitViewDividerStyleThin;
|
||||
[_private->splitView addSubview:inspectableWebContentsView->inspectable_web_contents()->GetWebContents()->GetView()->GetNativeView()];
|
||||
auto webView = inspectableWebContentsView->inspectable_web_contents()->GetWebContents()->GetView()->GetNativeView();
|
||||
webView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
||||
[self addSubview:webView];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_private->window release];
|
||||
[_private->splitView release];
|
||||
[_private release];
|
||||
_private = nil;
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)removeFromNotificationCenter {
|
||||
[NSNotificationCenter.defaultCenter removeObserver:self];
|
||||
}
|
||||
|
||||
- (IBAction)showDevTools:(id)sender {
|
||||
_private->inspectableWebContentsView->inspectable_web_contents()->ShowDevTools();
|
||||
inspectableWebContentsView_->inspectable_web_contents()->ShowDevTools();
|
||||
}
|
||||
|
||||
- (void)setDevToolsVisible:(BOOL)visible {
|
||||
if (_private->visible == visible)
|
||||
if (devtools_visible_ == visible)
|
||||
return;
|
||||
_private->visible = visible;
|
||||
devtools_visible_ = visible;
|
||||
|
||||
if ([self isDocked]) {
|
||||
if (visible) {
|
||||
[_private->window makeKeyAndOrderFront:nil];
|
||||
} else {
|
||||
[_private->window orderOut:nil];
|
||||
}
|
||||
return;
|
||||
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];
|
||||
}
|
||||
|
||||
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;
|
||||
CGFloat amount;
|
||||
CGRectEdge edge;
|
||||
if ([_private->splitView isVertical]) {
|
||||
amount = CGRectGetWidth(frame) * 2 / 3;
|
||||
edge = CGRectMaxXEdge;
|
||||
} else {
|
||||
amount = CGRectGetHeight(frame) * 2 / 3;
|
||||
edge = CGRectMaxYEdge;
|
||||
}
|
||||
CGRectDivide(frame, &inspectedViewFrame, &devToolsFrame, amount, edge);
|
||||
|
||||
inspectedView.frame = NSRectFromCGRect(inspectedViewFrame);
|
||||
devToolsView.frame = NSRectFromCGRect(devToolsFrame);
|
||||
|
||||
[_private->splitView addSubview:devToolsView];
|
||||
[devtools_window_ makeKeyAndOrderFront:nil];
|
||||
} else {
|
||||
[devToolsView removeFromSuperview];
|
||||
[devtools_window_ performClose:nil];
|
||||
}
|
||||
|
||||
[_private->splitView adjustSubviews];
|
||||
}
|
||||
|
||||
- (BOOL)isDevToolsVisible {
|
||||
return _private->visible;
|
||||
return devtools_visible_;
|
||||
}
|
||||
|
||||
- (BOOL)setDockSide:(const std::string&)side {
|
||||
if (side == "right") {
|
||||
_private->splitView.vertical = YES;
|
||||
[self moveToSplitView];
|
||||
} else if (side == "bottom") {
|
||||
_private->splitView.vertical = NO;
|
||||
[self moveToSplitView];
|
||||
} else if (side == "undocked") {
|
||||
[self moveToWindow];
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)moveToWindow {
|
||||
if (!_private->window) {
|
||||
auto styleMask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask | NSTexturedBackgroundWindowMask | NSUnifiedTitleAndToolbarWindowMask;
|
||||
auto contentRect = [UnderlayOpenGLHostingWindow contentRectForFrameRect:devtoolsWindowFrame(_private->splitView) styleMask:styleMask];
|
||||
_private->window = [[UnderlayOpenGLHostingWindow alloc] initWithContentRect:contentRect styleMask:styleMask backing:NSBackingStoreBuffered defer:YES];
|
||||
_private->window.delegate = self;
|
||||
_private->window.releasedWhenClosed = NO;
|
||||
_private->window.title = @"Developer Tools";
|
||||
_private->window.frameAutosaveName = @"brightray.developer.tools";
|
||||
[_private->window setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge];
|
||||
[_private->window setContentBorderThickness:24 forEdge:NSMaxYEdge];
|
||||
}
|
||||
|
||||
auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents();
|
||||
auto devToolsView = devToolsWebContents->GetView()->GetNativeView();
|
||||
|
||||
NSView *contentView = _private->window.contentView;
|
||||
devToolsView.frame = contentView.bounds;
|
||||
devToolsView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
||||
|
||||
[contentView addSubview:devToolsView];
|
||||
[_private->window makeKeyAndOrderFront:nil];
|
||||
[_private->splitView adjustSubviews];
|
||||
}
|
||||
|
||||
- (void)moveToSplitView {
|
||||
[_private->window orderOut:nil];
|
||||
|
||||
auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents();
|
||||
auto devToolsView = devToolsWebContents->GetView()->GetNativeView();
|
||||
|
||||
[_private->splitView addSubview:devToolsView];
|
||||
[_private->splitView adjustSubviews];
|
||||
}
|
||||
|
||||
- (BOOL)isDocked {
|
||||
auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents();
|
||||
if (!devToolsWebContents)
|
||||
return NO;
|
||||
auto devToolsView = devToolsWebContents->GetView()->GetNativeView();
|
||||
|
||||
return _private->window && devToolsView.window == _private->window;
|
||||
}
|
||||
|
||||
- (void)window:(NSWindow *)window didBecomeActive:(BOOL)active {
|
||||
auto inspectable_contents = _private->inspectableWebContentsView->inspectable_web_contents();
|
||||
|
||||
// Changes to the active state of the window we create only affects the dev tools contents.
|
||||
if (window == _private->window) {
|
||||
SetActive(inspectable_contents->devtools_web_contents(), active);
|
||||
return;
|
||||
}
|
||||
|
||||
// Changes the window that hosts us always affect our main web contents. If the dev tools are also
|
||||
// hosted in this window, they are affected too.
|
||||
SetActive(inspectable_contents->GetWebContents(), active);
|
||||
if (![self isDocked])
|
||||
return;
|
||||
SetActive(inspectable_contents->devtools_web_contents(), active);
|
||||
}
|
||||
|
||||
#pragma mark - NSView
|
||||
|
||||
- (void)viewWillMoveToWindow:(NSWindow *)newWindow {
|
||||
if (self.window) {
|
||||
[NSNotificationCenter.defaultCenter removeObserver:self name:NSWindowDidBecomeKeyNotification object:self.window];
|
||||
[NSNotificationCenter.defaultCenter removeObserver:self name:NSWindowDidResignKeyNotification object:self.window];
|
||||
}
|
||||
|
||||
if (!newWindow)
|
||||
return;
|
||||
|
||||
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:newWindow];
|
||||
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:newWindow];
|
||||
}
|
||||
|
||||
#pragma mark - NSSplitViewDelegate
|
||||
|
||||
-(void)splitViewWillResizeSubviews:(NSNotification *)notification {
|
||||
[[_private->splitView window] disableScreenUpdatesUntilFlush];
|
||||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark - NSWindowDelegate
|
||||
|
||||
- (BOOL)windowShouldClose:(id)sender {
|
||||
_private->visible = NO;
|
||||
[_private->window orderOut:nil];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)windowDidBecomeKey:(NSNotification *)notification {
|
||||
[self window:notification.object didBecomeActive:YES];
|
||||
}
|
||||
|
||||
- (void)windowDidResignKey:(NSNotification *)notification {
|
||||
[self window:notification.object didBecomeActive:NO];
|
||||
- (void)windowWillClose:(NSNotification*)notification {
|
||||
devtools_visible_ = NO;
|
||||
devtools_window_.reset();
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BRYInspectableWebContentsViewPrivate
|
||||
@end
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
#import "browser/mac/bry_inspectable_web_contents_view.h"
|
||||
|
||||
namespace brightray {
|
||||
class InspectableWebContentsViewMac;
|
||||
}
|
||||
|
||||
@interface BRYInspectableWebContentsView (Private)
|
||||
|
||||
- (instancetype)initWithInspectableWebContentsViewMac:(brightray::InspectableWebContentsViewMac *)inspectableWebContentsView;
|
||||
- (void)setDevToolsVisible:(BOOL)visible;
|
||||
- (BOOL)isDevToolsVisible;
|
||||
- (BOOL)setDockSide:(const std::string&)side;
|
||||
|
||||
@end
|
Loading…
Reference in a new issue