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 <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 id<NSWindowDelegate> window_delegate = [window delegate]; | 89 id<NSWindowDelegate> window_delegate = [window delegate]; |
90 if ([window_delegate respondsToSelector:@selector(nativeWidgetMac)]) { | 90 if ([window_delegate respondsToSelector:@selector(nativeWidgetMac)]) { |
91 ViewsNSWindowDelegate* delegate = | 91 ViewsNSWindowDelegate* delegate = |
92 base::mac::ObjCCastStrict<ViewsNSWindowDelegate>(window_delegate); | 92 base::mac::ObjCCastStrict<ViewsNSWindowDelegate>(window_delegate); |
93 return [delegate nativeWidgetMac]->bridge_.get(); | 93 return [delegate nativeWidgetMac]->bridge_.get(); |
94 } | 94 } |
95 return nullptr; // Not created by NativeWidgetMac. | 95 return nullptr; // Not created by NativeWidgetMac. |
96 } | 96 } |
97 | 97 |
98 bool NativeWidgetMac::IsWindowModalSheet() const { | 98 bool NativeWidgetMac::IsWindowModalSheet() const { |
99 return GetWidget()->widget_delegate()->GetModalType() == | 99 return bridge_ && bridge_->parent() && |
100 ui::MODAL_TYPE_WINDOW; | 100 GetWidget()->widget_delegate()->GetModalType() == |
| 101 ui::MODAL_TYPE_WINDOW; |
101 } | 102 } |
102 | 103 |
103 void NativeWidgetMac::OnWindowWillClose() { | 104 void NativeWidgetMac::OnWindowWillClose() { |
104 // Note: If closed via CloseNow(), |bridge_| will already be reset. If closed | 105 // Note: If closed via CloseNow(), |bridge_| will already be reset. If closed |
105 // by the user, or via Close() and a RunLoop, notify observers while |bridge_| | 106 // by the user, or via Close() and a RunLoop, notify observers while |bridge_| |
106 // is still a valid pointer, then reset it. | 107 // is still a valid pointer, then reset it. |
107 if (bridge_) { | 108 if (bridge_) { |
108 delegate_->OnNativeWidgetDestroying(); | 109 delegate_->OnNativeWidgetDestroying(); |
109 [GetNativeWindow() setDelegate:nil]; | 110 [GetNativeWindow() setDelegate:nil]; |
110 bridge_.reset(); | 111 bridge_.reset(); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 const gfx::ImageSkia& app_icon) { | 286 const gfx::ImageSkia& app_icon) { |
286 NOTIMPLEMENTED(); | 287 NOTIMPLEMENTED(); |
287 } | 288 } |
288 | 289 |
289 void NativeWidgetMac::InitModalType(ui::ModalType modal_type) { | 290 void NativeWidgetMac::InitModalType(ui::ModalType modal_type) { |
290 if (modal_type == ui::MODAL_TYPE_NONE) | 291 if (modal_type == ui::MODAL_TYPE_NONE) |
291 return; | 292 return; |
292 | 293 |
293 // System modal windows not implemented (or used) on Mac. | 294 // System modal windows not implemented (or used) on Mac. |
294 DCHECK_NE(ui::MODAL_TYPE_SYSTEM, modal_type); | 295 DCHECK_NE(ui::MODAL_TYPE_SYSTEM, modal_type); |
295 DCHECK(bridge_->parent()); | 296 |
296 // Everyhing happens upon show. | 297 // A peculiarity of the constrained window framework is that it permits a |
| 298 // dialog of MODAL_TYPE_WINDOW to have a null parent window; falling back to |
| 299 // a non-modal window in this case. |
| 300 DCHECK(bridge_->parent() || modal_type == ui::MODAL_TYPE_WINDOW); |
| 301 |
| 302 // Everything happens upon show. |
297 } | 303 } |
298 | 304 |
299 gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const { | 305 gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const { |
300 return gfx::ScreenRectFromNSRect([GetNativeWindow() frame]); | 306 return gfx::ScreenRectFromNSRect([GetNativeWindow() frame]); |
301 } | 307 } |
302 | 308 |
303 gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const { | 309 gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const { |
304 NSWindow* window = GetNativeWindow(); | 310 NSWindow* window = GetNativeWindow(); |
305 return gfx::ScreenRectFromNSRect( | 311 return gfx::ScreenRectFromNSRect( |
306 [window contentRectForFrameRect:[window frame]]); | 312 [window contentRectForFrameRect:[window frame]]); |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; | 765 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; |
760 } | 766 } |
761 | 767 |
762 - (void)animationDidEnd:(NSAnimation*)animation { | 768 - (void)animationDidEnd:(NSAnimation*)animation { |
763 [window_ close]; | 769 [window_ close]; |
764 [animation_ setDelegate:nil]; | 770 [animation_ setDelegate:nil]; |
765 [self release]; | 771 [self release]; |
766 } | 772 } |
767 | 773 |
768 @end | 774 @end |
OLD | NEW |