refactor: setup contentView on initialization
This commit is contained in:
parent
a08b4f780c
commit
ada884a129
1 changed files with 29 additions and 35 deletions
|
@ -252,8 +252,7 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
||||||
|
|
||||||
NSRect main_screen_rect = [[[NSScreen screens] firstObject] frame];
|
NSRect main_screen_rect = [[[NSScreen screens] firstObject] frame];
|
||||||
gfx::Rect bounds(round((NSWidth(main_screen_rect) - width) / 2),
|
gfx::Rect bounds(round((NSWidth(main_screen_rect) - width) / 2),
|
||||||
round((NSHeight(main_screen_rect) - height) / 2),
|
round((NSHeight(main_screen_rect) - height) / 2), width,
|
||||||
width,
|
|
||||||
height);
|
height);
|
||||||
|
|
||||||
options.Get(options::kResizable, &resizable_);
|
options.Get(options::kResizable, &resizable_);
|
||||||
|
@ -432,19 +431,6 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
||||||
// Set maximizable state last to ensure zoom button does not get reset
|
// Set maximizable state last to ensure zoom button does not get reset
|
||||||
// by calls to other APIs.
|
// by calls to other APIs.
|
||||||
SetMaximizable(maximizable);
|
SetMaximizable(maximizable);
|
||||||
}
|
|
||||||
|
|
||||||
NativeWindowMac::~NativeWindowMac() {
|
|
||||||
[NSEvent removeMonitor:wheel_event_monitor_];
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindowMac::SetContentView(
|
|
||||||
brightray::InspectableWebContents* web_contents) {
|
|
||||||
if (content_view_)
|
|
||||||
[content_view_ removeFromSuperview];
|
|
||||||
|
|
||||||
content_view_ = web_contents->GetView()->GetNativeView();
|
|
||||||
[content_view_ setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
|
||||||
|
|
||||||
// Make sure the bottom corner is rounded for non-modal windows:
|
// Make sure the bottom corner is rounded for non-modal windows:
|
||||||
// http://crbug.com/396264. But do not enable it on OS X 10.9 for transparent
|
// http://crbug.com/396264. But do not enable it on OS X 10.9 for transparent
|
||||||
|
@ -457,10 +443,7 @@ void NativeWindowMac::SetContentView(
|
||||||
[[window_ contentView] setWantsLayer:YES];
|
[[window_ contentView] setWantsLayer:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_frame()) {
|
if (!has_frame()) {
|
||||||
[content_view_ setFrame:[[window_ contentView] bounds]];
|
|
||||||
[[window_ contentView] addSubview:content_view_];
|
|
||||||
} else {
|
|
||||||
// In OSX 10.10, adding subviews to the root view for the NSView hierarchy
|
// In OSX 10.10, adding subviews to the root view for the NSView hierarchy
|
||||||
// produces warnings. To eliminate the warnings, we resize the contentView
|
// produces warnings. To eliminate the warnings, we resize the contentView
|
||||||
// to fill the window, and add subviews to that.
|
// to fill the window, and add subviews to that.
|
||||||
|
@ -469,27 +452,15 @@ void NativeWindowMac::SetContentView(
|
||||||
[container_view_
|
[container_view_
|
||||||
setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||||
[container_view_ setFrame:[[[window_ contentView] superview] bounds]];
|
[container_view_ setFrame:[[[window_ contentView] superview] bounds]];
|
||||||
|
|
||||||
// Move the vibrantView from the old content view.
|
|
||||||
if ([window_ vibrantView]) {
|
|
||||||
[[window_ vibrantView] removeFromSuperview];
|
|
||||||
[container_view_ addSubview:[window_ vibrantView]
|
|
||||||
positioned:NSWindowBelow
|
|
||||||
relativeTo:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
[window_ setContentView:container_view_];
|
[window_ setContentView:container_view_];
|
||||||
|
|
||||||
[content_view_ setFrame:[container_view_ bounds]];
|
|
||||||
[container_view_ addSubview:content_view_];
|
|
||||||
|
|
||||||
// The fullscreen button should always be hidden for frameless window.
|
// The fullscreen button should always be hidden for frameless window.
|
||||||
[[window_ standardWindowButton:NSWindowFullScreenButton] setHidden:YES];
|
[[window_ standardWindowButton:NSWindowFullScreenButton] setHidden:YES];
|
||||||
|
|
||||||
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) {
|
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) {
|
||||||
NSView* window_button_view = [[[CustomWindowButtonView alloc]
|
NSView* buttonsView = [[[CustomWindowButtonView alloc]
|
||||||
initWithFrame:NSZeroRect] autorelease];
|
initWithFrame:NSZeroRect] autorelease];
|
||||||
[container_view_ addSubview:window_button_view];
|
[[window_ contentView] addSubview:buttonsView];
|
||||||
} else {
|
} else {
|
||||||
if (title_bar_style_ != NORMAL) {
|
if (title_bar_style_ != NORMAL) {
|
||||||
if (base::mac::IsOS10_9()) {
|
if (base::mac::IsOS10_9()) {
|
||||||
|
@ -513,6 +484,29 @@ void NativeWindowMac::SetContentView(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NativeWindowMac::~NativeWindowMac() {
|
||||||
|
[NSEvent removeMonitor:wheel_event_monitor_];
|
||||||
|
}
|
||||||
|
|
||||||
|
void NativeWindowMac::SetContentView(
|
||||||
|
brightray::InspectableWebContents* web_contents) {
|
||||||
|
if (content_view_)
|
||||||
|
[content_view_ removeFromSuperview];
|
||||||
|
|
||||||
|
content_view_ = web_contents->GetView()->GetNativeView();
|
||||||
|
[content_view_ setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||||
|
[content_view_ setFrame:[[window_ contentView] bounds]];
|
||||||
|
|
||||||
|
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) {
|
||||||
|
NSView* buttonsView = [[[window_ contentView] subviews] lastObject];
|
||||||
|
[[window_ contentView] addSubview:content_view_
|
||||||
|
positioned:NSWindowBelow
|
||||||
|
relativeTo:buttonsView];
|
||||||
|
} else {
|
||||||
|
[[window_ contentView] addSubview:content_view_];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::Close() {
|
void NativeWindowMac::Close() {
|
||||||
// When this is a sheet showing, performClose won't work.
|
// When this is a sheet showing, performClose won't work.
|
||||||
if (is_modal() && parent() && IsVisible()) {
|
if (is_modal() && parent() && IsVisible()) {
|
||||||
|
@ -984,8 +978,8 @@ void NativeWindowMac::SetBackgroundColor(SkColor color) {
|
||||||
// views::Widget adds a layer for the content view.
|
// views::Widget adds a layer for the content view.
|
||||||
auto* bridge = views::NativeWidgetMac::GetBridgeForNativeWindow(window_);
|
auto* bridge = views::NativeWidgetMac::GetBridgeForNativeWindow(window_);
|
||||||
NSView* compositor_superview =
|
NSView* compositor_superview =
|
||||||
static_cast<ui::AcceleratedWidgetMacNSView*>(bridge)->
|
static_cast<ui::AcceleratedWidgetMacNSView*>(bridge)
|
||||||
AcceleratedWidgetGetNSView();
|
->AcceleratedWidgetGetNSView();
|
||||||
[[compositor_superview layer] setBackgroundColor:cgcolor];
|
[[compositor_superview layer] setBackgroundColor:cgcolor];
|
||||||
// When using WebContents as content view, the contentView also has layer.
|
// When using WebContents as content view, the contentView also has layer.
|
||||||
if ([[window_ contentView] wantsLayer])
|
if ([[window_ contentView] wantsLayer])
|
||||||
|
|
Loading…
Add table
Reference in a new issue