OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/views/widget/native_widget_mac.h" | 5 #include "ui/views/widget/native_widget_mac.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "ui/gfx/font_list.h" | 12 #include "ui/gfx/font_list.h" |
13 #import "ui/gfx/mac/coordinate_conversion.h" | 13 #import "ui/gfx/mac/coordinate_conversion.h" |
14 #include "ui/native_theme/native_theme.h" | 14 #include "ui/native_theme/native_theme.h" |
15 #import "ui/views/cocoa/bridged_content_view.h" | 15 #import "ui/views/cocoa/bridged_content_view.h" |
16 #import "ui/views/cocoa/bridged_native_widget.h" | 16 #import "ui/views/cocoa/bridged_native_widget.h" |
17 #import "ui/views/cocoa/views_nswindow_delegate.h" | 17 #import "ui/views/cocoa/views_nswindow_delegate.h" |
18 #include "ui/views/window/native_frame_view.h" | 18 #include "ui/views/window/native_frame_view.h" |
19 | 19 |
20 @interface NativeWidgetMacNSWindow : NSWindow | 20 @interface NativeWidgetMacNSWindow : NSWindow |
| 21 - (ViewsNSWindowDelegate*)viewsNSWindowDelegate; |
21 @end | 22 @end |
22 | 23 |
23 @implementation NativeWidgetMacNSWindow | 24 @implementation NativeWidgetMacNSWindow |
24 | 25 |
| 26 - (ViewsNSWindowDelegate*)viewsNSWindowDelegate { |
| 27 return base::mac::ObjCCastStrict<ViewsNSWindowDelegate>([self delegate]); |
| 28 } |
| 29 |
25 // Override canBecome{Key,Main}Window to always return YES, otherwise Windows | 30 // Override canBecome{Key,Main}Window to always return YES, otherwise Windows |
26 // with a styleMask of NSBorderlessWindowMask default to NO. | 31 // with a styleMask of NSBorderlessWindowMask default to NO. |
27 - (BOOL)canBecomeKeyWindow { | 32 - (BOOL)canBecomeKeyWindow { |
28 return YES; | 33 return YES; |
29 } | 34 } |
30 | 35 |
31 - (BOOL)canBecomeMainWindow { | 36 - (BOOL)canBecomeMainWindow { |
32 return YES; | 37 return YES; |
33 } | 38 } |
34 | 39 |
| 40 // Override orderWindow to intercept visibility changes, since there is no way |
| 41 // to observe these changes via NSWindowDelegate. |
| 42 - (void)orderWindow:(NSWindowOrderingMode)orderingMode |
| 43 relativeTo:(NSInteger)otherWindowNumber { |
| 44 [[self viewsNSWindowDelegate] onWindowOrderWillChange:orderingMode]; |
| 45 [super orderWindow:orderingMode relativeTo:otherWindowNumber]; |
| 46 [[self viewsNSWindowDelegate] onWindowOrderChanged]; |
| 47 } |
| 48 |
35 @end | 49 @end |
36 | 50 |
37 namespace views { | 51 namespace views { |
38 namespace { | 52 namespace { |
39 | 53 |
40 NSInteger StyleMaskForParams(const Widget::InitParams& params) { | 54 NSInteger StyleMaskForParams(const Widget::InitParams& params) { |
41 // TODO(tapted): Determine better masks when there are use cases for it. | 55 // TODO(tapted): Determine better masks when there are use cases for it. |
42 if (params.remove_standard_frame) | 56 if (params.remove_standard_frame) |
43 return NSBorderlessWindowMask; | 57 return NSBorderlessWindowMask; |
44 | 58 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 308 |
295 void NativeWidgetMac::StackBelow(gfx::NativeView native_view) { | 309 void NativeWidgetMac::StackBelow(gfx::NativeView native_view) { |
296 NOTIMPLEMENTED(); | 310 NOTIMPLEMENTED(); |
297 } | 311 } |
298 | 312 |
299 void NativeWidgetMac::SetShape(gfx::NativeRegion shape) { | 313 void NativeWidgetMac::SetShape(gfx::NativeRegion shape) { |
300 NOTIMPLEMENTED(); | 314 NOTIMPLEMENTED(); |
301 } | 315 } |
302 | 316 |
303 void NativeWidgetMac::Close() { | 317 void NativeWidgetMac::Close() { |
| 318 if (!bridge_) |
| 319 return; |
| 320 |
| 321 // Clear the view early to suppress repaints. |
| 322 bridge_->SetRootView(NULL); |
| 323 |
304 NSWindow* window = GetNativeWindow(); | 324 NSWindow* window = GetNativeWindow(); |
305 // Calling performClose: will momentarily highlight the close button, but | 325 // Calling performClose: will momentarily highlight the close button, but |
306 // AppKit will reject it if there is no close button. | 326 // AppKit will reject it if there is no close button. |
307 SEL close_selector = ([window styleMask] & NSClosableWindowMask) | 327 SEL close_selector = ([window styleMask] & NSClosableWindowMask) |
308 ? @selector(performClose:) | 328 ? @selector(performClose:) |
309 : @selector(close); | 329 : @selector(close); |
310 [window performSelector:close_selector withObject:nil afterDelay:0]; | 330 [window performSelector:close_selector withObject:nil afterDelay:0]; |
311 } | 331 } |
312 | 332 |
313 void NativeWidgetMac::CloseNow() { | 333 void NativeWidgetMac::CloseNow() { |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 } | 625 } |
606 | 626 |
607 // static | 627 // static |
608 gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() { | 628 gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() { |
609 NOTIMPLEMENTED(); | 629 NOTIMPLEMENTED(); |
610 return gfx::FontList(); | 630 return gfx::FontList(); |
611 } | 631 } |
612 | 632 |
613 } // namespace internal | 633 } // namespace internal |
614 } // namespace views | 634 } // namespace views |
OLD | NEW |