Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/apps/app_window_native_widget_mac.h" | 5 #include "chrome/browser/ui/views/apps/app_window_native_widget_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/mac/mac_util.h" | |
| 10 #include "base/mac/sdk_forward_declarations.h" | |
| 11 #import "chrome/browser/ui/cocoa/apps/nswindow_util.h" | |
| 9 #import "chrome/browser/ui/views/apps/native_widget_mac_frameless_nswindow.h" | 12 #import "chrome/browser/ui/views/apps/native_widget_mac_frameless_nswindow.h" |
| 10 #import "ui/base/cocoa/window_size_constants.h" | 13 #import "ui/base/cocoa/window_size_constants.h" |
| 14 #include "ui/views/widget/widget_delegate.h" | |
| 11 | 15 |
| 12 AppWindowNativeWidgetMac::AppWindowNativeWidgetMac(views::Widget* widget) | 16 AppWindowNativeWidgetMac::AppWindowNativeWidgetMac(views::Widget* widget) |
| 13 : NativeWidgetMac(widget) { | 17 : NativeWidgetMac(widget) { |
| 14 } | 18 } |
| 15 | 19 |
| 16 AppWindowNativeWidgetMac::~AppWindowNativeWidgetMac() { | 20 AppWindowNativeWidgetMac::~AppWindowNativeWidgetMac() { |
| 17 } | 21 } |
| 18 | 22 |
| 23 void AppWindowNativeWidgetMac::OnSizeConstraintsChanged() { | |
| 24 NativeWidgetMac::OnSizeConstraintsChanged(); | |
| 25 | |
| 26 gfx::Size minimum_size = delegate()->GetMinimumSize(); | |
|
tapted
2015/03/20 12:12:53
I think to be consistent with aura widgets, this c
jackhou1
2015/03/25 23:32:23
Done.
| |
| 27 gfx::Size maximum_size = delegate()->GetMaximumSize(); | |
| 28 bool is_resizable = delegate()->AsWidget()->widget_delegate()->CanResize(); | |
| 29 bool shows_resize_controls = | |
| 30 is_resizable && (minimum_size.IsEmpty() || minimum_size != maximum_size); | |
| 31 bool shows_fullscreen_controls = | |
| 32 is_resizable && delegate()->AsWidget()->widget_delegate()->CanMaximize(); | |
| 33 | |
| 34 NSWindow* window = GetNativeWindow(); | |
| 35 SetResizableStyleMask(window, shows_resize_controls); | |
| 36 if (base::mac::IsOSSnowLeopard()) | |
| 37 [window setShowsResizeIndicator:shows_resize_controls]; | |
| 38 | |
| 39 // Set the window to participate in Lion Fullscreen mode. Setting this flag | |
| 40 // has no effect on Snow Leopard or earlier. UI controls for fullscreen are | |
| 41 // only shown for apps that have unbounded size. | |
| 42 if (base::mac::IsOSLionOrLater()) | |
| 43 SetFullScreenCollectionBehavior(window, shows_fullscreen_controls); | |
| 44 | |
| 45 [[window standardWindowButton:NSWindowZoomButton] | |
| 46 setEnabled:shows_fullscreen_controls]; | |
|
tapted
2015/03/20 12:12:53
I wonder if this is all complicated enough to try
jackhou1
2015/03/25 23:32:23
Done.
| |
| 47 } | |
| 48 | |
| 19 NSWindow* AppWindowNativeWidgetMac::CreateNSWindow( | 49 NSWindow* AppWindowNativeWidgetMac::CreateNSWindow( |
| 20 const views::Widget::InitParams& params) { | 50 const views::Widget::InitParams& params) { |
| 21 // If the window has a standard frame, use the same NSWindow as | 51 // If the window has a standard frame, use the same NSWindow as |
| 22 // NativeWidgetMac. | 52 // NativeWidgetMac. |
| 23 if (!params.remove_standard_frame) | 53 if (!params.remove_standard_frame) |
| 24 return NativeWidgetMac::CreateNSWindow(params); | 54 return NativeWidgetMac::CreateNSWindow(params); |
| 25 | 55 |
| 26 // NSTexturedBackgroundWindowMask is needed to implement draggable window | 56 // NSTexturedBackgroundWindowMask is needed to implement draggable window |
| 27 // regions. | 57 // regions. |
| 28 NSUInteger style_mask = NSTexturedBackgroundWindowMask | NSTitledWindowMask | | 58 NSUInteger style_mask = NSTexturedBackgroundWindowMask | NSTitledWindowMask | |
| 29 NSClosableWindowMask | NSMiniaturizableWindowMask | | 59 NSClosableWindowMask | NSMiniaturizableWindowMask | |
| 30 NSResizableWindowMask; | 60 NSResizableWindowMask; |
| 31 return [[[NativeWidgetMacFramelessNSWindow alloc] | 61 return [[[NativeWidgetMacFramelessNSWindow alloc] |
| 32 initWithContentRect:ui::kWindowSizeDeterminedLater | 62 initWithContentRect:ui::kWindowSizeDeterminedLater |
| 33 styleMask:style_mask | 63 styleMask:style_mask |
| 34 backing:NSBackingStoreBuffered | 64 backing:NSBackingStoreBuffered |
| 35 defer:YES] autorelease]; | 65 defer:YES] autorelease]; |
| 36 } | 66 } |
| OLD | NEW |