Chromium Code Reviews| 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 |
| 11 #import "base/mac/bind_objc_block.h" | |
| 11 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
| 12 #include "base/mac/scoped_nsobject.h" | 13 #include "base/mac/scoped_nsobject.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | |
| 14 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" | 16 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" |
| 15 #import "ui/base/cocoa/window_size_constants.h" | 17 #import "ui/base/cocoa/window_size_constants.h" |
| 16 #include "ui/gfx/font_list.h" | 18 #include "ui/gfx/font_list.h" |
| 17 #import "ui/gfx/mac/coordinate_conversion.h" | 19 #import "ui/gfx/mac/coordinate_conversion.h" |
| 18 #import "ui/gfx/mac/nswindow_frame_controls.h" | 20 #import "ui/gfx/mac/nswindow_frame_controls.h" |
| 19 #include "ui/native_theme/native_theme.h" | 21 #include "ui/native_theme/native_theme.h" |
| 20 #include "ui/native_theme/native_theme_mac.h" | 22 #include "ui/native_theme/native_theme_mac.h" |
| 21 #import "ui/views/cocoa/bridged_content_view.h" | 23 #import "ui/views/cocoa/bridged_content_view.h" |
| 22 #import "ui/views/cocoa/bridged_native_widget.h" | 24 #import "ui/views/cocoa/bridged_native_widget.h" |
| 23 #include "ui/views/cocoa/cocoa_mouse_capture.h" | 25 #include "ui/views/cocoa/cocoa_mouse_capture.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 | 362 |
| 361 // Clear the view early to suppress repaints. | 363 // Clear the view early to suppress repaints. |
| 362 bridge_->SetRootView(NULL); | 364 bridge_->SetRootView(NULL); |
| 363 | 365 |
| 364 // Widget::Close() ensures [Non]ClientView::CanClose() returns true, so there | 366 // Widget::Close() ensures [Non]ClientView::CanClose() returns true, so there |
| 365 // is no need to call the NSWindow or its delegate's -windowShouldClose: | 367 // is no need to call the NSWindow or its delegate's -windowShouldClose: |
| 366 // implementation in the manner of -[NSWindow performClose:]. But, | 368 // implementation in the manner of -[NSWindow performClose:]. But, |
| 367 // like -performClose:, first remove the window from AppKit's display | 369 // like -performClose:, first remove the window from AppKit's display |
| 368 // list to avoid crashes like http://crbug.com/156101. | 370 // list to avoid crashes like http://crbug.com/156101. |
| 369 [window orderOut:nil]; | 371 [window orderOut:nil]; |
| 370 [window performSelector:@selector(close) withObject:nil afterDelay:0]; | 372 |
| 373 // Many tests assume that base::RunLoop().RunUntilIdle() is always sufficient | |
| 374 // to execute a close. However, in rare cases, -performSelector:..afterDelay:0 | |
| 375 // does not do this. So post a regular task. | |
| 376 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, base::BindBlock(^() { | |
|
Robert Sesek
2016/07/01 02:31:38
nit: just ^{ will work
tapted
2016/07/01 03:31:53
Done.
| |
| 377 [window close]; | |
| 378 })); | |
| 371 } | 379 } |
| 372 | 380 |
| 373 void NativeWidgetMac::CloseNow() { | 381 void NativeWidgetMac::CloseNow() { |
| 374 if (!bridge_) | 382 if (!bridge_) |
| 375 return; | 383 return; |
| 376 | 384 |
| 377 // Notify observers while |bridged_| is still valid. | 385 // Notify observers while |bridged_| is still valid. |
| 378 delegate_->OnNativeWidgetDestroying(); | 386 delegate_->OnNativeWidgetDestroying(); |
| 379 // Reset |bridge_| to NULL before destroying it. | 387 // Reset |bridge_| to NULL before destroying it. |
| 380 std::unique_ptr<BridgedNativeWidget> bridge(std::move(bridge_)); | 388 std::unique_ptr<BridgedNativeWidget> bridge(std::move(bridge_)); |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 750 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; | 758 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; |
| 751 } | 759 } |
| 752 | 760 |
| 753 - (void)animationDidEnd:(NSAnimation*)animation { | 761 - (void)animationDidEnd:(NSAnimation*)animation { |
| 754 [window_ close]; | 762 [window_ close]; |
| 755 [animation_ setDelegate:nil]; | 763 [animation_ setDelegate:nil]; |
| 756 [self release]; | 764 [self release]; |
| 757 } | 765 } |
| 758 | 766 |
| 759 @end | 767 @end |
| OLD | NEW |