Chromium Code Reviews| Index: ui/views/widget/native_widget_mac.mm |
| diff --git a/ui/views/widget/native_widget_mac.mm b/ui/views/widget/native_widget_mac.mm |
| index bf45dfcba0043c3486eaf8944b77261a139af8c9..0ea3755251d4bae2a1c2611e75d9744be2468a3e 100644 |
| --- a/ui/views/widget/native_widget_mac.mm |
| +++ b/ui/views/widget/native_widget_mac.mm |
| @@ -9,12 +9,38 @@ |
| #include "base/mac/foundation_util.h" |
| #include "base/mac/scoped_nsobject.h" |
| #include "ui/gfx/font_list.h" |
| +#include "ui/gfx/mac/point_utils.h" |
| #include "ui/native_theme/native_theme.h" |
| #import "ui/views/cocoa/bridged_content_view.h" |
| #import "ui/views/cocoa/bridged_native_widget.h" |
| #import "ui/views/cocoa/views_nswindow_delegate.h" |
| namespace views { |
| +namespace { |
| + |
| +NSInteger StyleMaskForParams(const Widget::InitParams& params) { |
| + // TODO(tapted): Determine better masks when there are use cases for it. |
| + if (params.type == Widget::InitParams::TYPE_WINDOW) { |
| + return NSTitledWindowMask | NSClosableWindowMask | |
| + NSMiniaturizableWindowMask | NSResizableWindowMask; |
| + } |
| + return NSBorderlessWindowMask; |
| +} |
| + |
| +NSRect ValidateContentRect(NSRect content_rect) { |
| + // A contentRect with zero width or height is a banned practice in Chrome, due |
| + // to unpredictable OSX treatment. For now, silently give a minimum dimension. |
| + // TODO(tapted): Add a DCHECK, or add emulation logic (e.g. to auto-hide). |
| + if (NSWidth(content_rect) == 0) |
| + content_rect.size.width = 1; |
| + |
| + if (NSHeight(content_rect) == 0) |
| + content_rect.size.height = 1; |
| + |
| + return content_rect; |
| +} |
| + |
| +} // namespace |
| //////////////////////////////////////////////////////////////////////////////// |
| // NativeWidgetMac, public: |
| @@ -48,12 +74,11 @@ void NativeWidgetMac::OnWindowWillClose() { |
| void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { |
| ownership_ = params.ownership; |
| - // TODO(tapted): Convert position into Cocoa's flipped coordinate space. |
| - NSRect content_rect = |
| - NSMakeRect(0, 0, params.bounds.width(), params.bounds.height()); |
| - // TODO(tapted): Determine a good initial style mask from |params|. |
| - NSInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | |
| - NSMiniaturizableWindowMask | NSResizableWindowMask; |
| + NSInteger style_mask = StyleMaskForParams(params); |
| + NSRect content_rect = ValidateContentRect( |
| + [NSWindow contentRectForFrameRect:gfx::ScreenRectToNSRect(params.bounds) |
| + styleMask:style_mask]); |
| + |
| base::scoped_nsobject<NSWindow> window( |
| [[NSWindow alloc] initWithContentRect:content_rect |
| styleMask:style_mask |
| @@ -191,13 +216,13 @@ void NativeWidgetMac::InitModalType(ui::ModalType modal_type) { |
| } |
| gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const { |
| - NOTIMPLEMENTED(); |
| - return gfx::Rect(); |
| + return gfx::ScreenRectFromNSRect([GetNativeWindow() frame]); |
| } |
| gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const { |
| - NOTIMPLEMENTED(); |
| - return gfx::Rect(); |
| + NSWindow* window = GetNativeWindow(); |
| + return gfx::ScreenRectFromNSRect( |
| + [window contentRectForFrameRect:[window frame]]); |
| } |
| gfx::Rect NativeWidgetMac::GetRestoredBounds() const { |
| @@ -206,11 +231,16 @@ gfx::Rect NativeWidgetMac::GetRestoredBounds() const { |
| } |
| void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) { |
| - NOTIMPLEMENTED(); |
| + [GetNativeWindow() setFrame:gfx::ScreenRectToNSRect(bounds) |
| + display:YES |
| + animate:NO]; |
| } |
| void NativeWidgetMac::SetSize(const gfx::Size& size) { |
| - [GetNativeWindow() setContentSize:NSMakeSize(size.width(), size.height())]; |
| + NSWindow* window = GetNativeWindow(); |
| + NSRect frame_rect = NSMakeRect(0, 0, size.width(), size.height()); |
| + NSRect content_rect = [window contentRectForFrameRect:frame_rect]; |
|
Andre
2014/06/25 17:59:51
Isn't this supposed to set the window's frame inst
tapted
2014/06/26 08:44:32
This part of it was OK -- there's no -[NSWindow se
|
| + [window setContentSize:content_rect.size]; |
| } |
|
tapted
2014/06/25 10:55:56
Not sure if calling -[NSWindow setContenSize:] is
|
| void NativeWidgetMac::StackAbove(gfx::NativeView native_view) { |
| @@ -230,10 +260,13 @@ void NativeWidgetMac::SetShape(gfx::NativeRegion shape) { |
| } |
| void NativeWidgetMac::Close() { |
| - // Calling performClose: will momentarily highlight the close button. |
| - [GetNativeWindow() performSelector:@selector(performClose:) |
| - withObject:nil |
| - afterDelay:0]; |
| + NSWindow* window = GetNativeWindow(); |
| + // Calling performClose: will momentarily highlight the close button, but |
| + // AppKit will reject it if there is no close button. |
| + SEL close_selector = ([window styleMask] & NSClosableWindowMask) |
| + ? @selector(performClose:) |
| + : @selector(close); |
| + [window performSelector:close_selector withObject:nil afterDelay:0]; |
| } |
| void NativeWidgetMac::CloseNow() { |