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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 GetWidget()->widget_delegate()->GetModalType() == |
100 ui::MODAL_TYPE_WINDOW; | 100 ui::MODAL_TYPE_WINDOW; |
101 } | 101 } |
102 | 102 |
103 void NativeWidgetMac::OnWindowWillClose() { | 103 void NativeWidgetMac::OnWindowDestroyed() { |
karandeepb
2016/10/18 10:00:29
DCHECK(bridge_)?
tapted
2016/10/19 06:20:25
Done.
| |
104 // Note: If closed via CloseNow(), |bridge_| will already be reset. If closed | 104 bridge_.reset(); |
105 // by the user, or via Close() and a RunLoop, notify observers while |bridge_| | |
106 // is still a valid pointer, then reset it. | |
107 if (bridge_) { | |
108 delegate_->OnNativeWidgetDestroying(); | |
109 [GetNativeWindow() setDelegate:nil]; | |
110 bridge_.reset(); | |
111 } | |
112 delegate_->OnNativeWidgetDestroyed(); | 105 delegate_->OnNativeWidgetDestroyed(); |
113 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 106 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
114 delete this; | 107 delete this; |
115 } | 108 } |
116 | 109 |
117 int NativeWidgetMac::SheetPositionY() { | 110 int NativeWidgetMac::SheetPositionY() { |
118 NSView* view = GetNativeView(); | 111 NSView* view = GetNativeView(); |
119 return | 112 return |
120 [view convertPoint:NSMakePoint(0, NSHeight([view frame])) toView:nil].y; | 113 [view convertPoint:NSMakePoint(0, NSHeight([view frame])) toView:nil].y; |
121 } | 114 } |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 // is no need to call the NSWindow or its delegate's -windowShouldClose: | 357 // is no need to call the NSWindow or its delegate's -windowShouldClose: |
365 // implementation in the manner of -[NSWindow performClose:]. But, | 358 // implementation in the manner of -[NSWindow performClose:]. But, |
366 // like -performClose:, first remove the window from AppKit's display | 359 // like -performClose:, first remove the window from AppKit's display |
367 // list to avoid crashes like http://crbug.com/156101. | 360 // list to avoid crashes like http://crbug.com/156101. |
368 [window orderOut:nil]; | 361 [window orderOut:nil]; |
369 | 362 |
370 // Many tests assume that base::RunLoop().RunUntilIdle() is always sufficient | 363 // Many tests assume that base::RunLoop().RunUntilIdle() is always sufficient |
371 // to execute a close. However, in rare cases, -performSelector:..afterDelay:0 | 364 // to execute a close. However, in rare cases, -performSelector:..afterDelay:0 |
372 // does not do this. So post a regular task. | 365 // does not do this. So post a regular task. |
373 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, base::BindBlock(^{ | 366 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, base::BindBlock(^{ |
374 [window close]; | 367 [window close]; |
karandeepb
2016/10/18 10:00:29
While closing a window asynchronously, we don't te
tapted
2016/10/19 06:20:25
Actually, the ObjectiveC block automatically incre
karandeepb
2016/10/20 00:50:23
Lots of subtle stuff. Acknowledged.
| |
375 })); | 368 })); |
376 } | 369 } |
377 | 370 |
378 void NativeWidgetMac::CloseNow() { | 371 void NativeWidgetMac::CloseNow() { |
379 if (!bridge_) | 372 if (!bridge_) |
380 return; | 373 return; |
381 | 374 |
382 // Notify observers while |bridged_| is still valid. | 375 // Cocoa ignores -close calls on open sheets, so they should be closed |
383 delegate_->OnNativeWidgetDestroying(); | 376 // asynchronously, using Widget::Close(). |
384 // Reset |bridge_| to NULL before destroying it. | 377 DCHECK(!IsWindowModalSheet()); |
tapted
2016/10/18 05:09:09
This can probably be fixed now... but should get s
| |
385 std::unique_ptr<BridgedNativeWidget> bridge(std::move(bridge_)); | 378 |
379 // NSWindows must be retained until -[NSWindow close] returns. | |
380 base::scoped_nsobject<NSWindow> window(GetNativeWindow(), | |
381 base::scoped_policy::RETAIN); | |
382 | |
383 // If there's a bridge at this point, it means there must be a window as well. | |
384 DCHECK(window); | |
385 [window close]; | |
karandeepb
2016/10/18 10:00:29
Should we orderOut: here to avoid crashes like htt
tapted
2016/10/19 06:20:25
I'm actually thinking of removing the orderOut alt
karandeepb
2016/10/20 00:50:23
Acknowledged. Although, the Widget::Close document
tapted
2016/10/20 04:42:44
ooh - nice find. Yeah I guess we should be consist
| |
386 // Note: |this| is deleted here when ownership_ == NATIVE_WIDGET_OWNS_WIDGET. | |
386 } | 387 } |
387 | 388 |
388 void NativeWidgetMac::Show() { | 389 void NativeWidgetMac::Show() { |
389 ShowWithWindowState(ui::SHOW_STATE_NORMAL); | 390 ShowWithWindowState(ui::SHOW_STATE_NORMAL); |
390 } | 391 } |
391 | 392 |
392 void NativeWidgetMac::Hide() { | 393 void NativeWidgetMac::Hide() { |
393 if (!bridge_) | 394 if (!bridge_) |
394 return; | 395 return; |
395 | 396 |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
759 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; | 760 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; |
760 } | 761 } |
761 | 762 |
762 - (void)animationDidEnd:(NSAnimation*)animation { | 763 - (void)animationDidEnd:(NSAnimation*)animation { |
763 [window_ close]; | 764 [window_ close]; |
764 [animation_ setDelegate:nil]; | 765 [animation_ setDelegate:nil]; |
765 [self release]; | 766 [self release]; |
766 } | 767 } |
767 | 768 |
768 @end | 769 @end |
OLD | NEW |