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 #import "base/mac/bind_objc_block.h" |
| 12 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
| 13 #include "base/mac/scoped_nsobject.h" | 13 #include "base/mac/scoped_nsobject.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" | 16 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" |
| 17 #import "ui/base/cocoa/window_size_constants.h" | 17 #import "ui/base/cocoa/window_size_constants.h" |
| 18 #include "ui/gfx/font_list.h" | 18 #include "ui/gfx/font_list.h" |
| 19 #import "ui/gfx/mac/coordinate_conversion.h" | 19 #import "ui/gfx/mac/coordinate_conversion.h" |
| 20 #import "ui/gfx/mac/nswindow_frame_controls.h" | 20 #import "ui/gfx/mac/nswindow_frame_controls.h" |
| 21 #include "ui/native_theme/native_theme.h" | 21 #include "ui/native_theme/native_theme.h" |
| 22 #include "ui/native_theme/native_theme_mac.h" | 22 #include "ui/native_theme/native_theme_mac.h" |
| 23 #import "ui/views/cocoa/bridged_content_view.h" | 23 #import "ui/views/cocoa/bridged_content_view.h" |
| 24 #import "ui/views/cocoa/bridged_native_widget.h" | 24 #import "ui/views/cocoa/bridged_native_widget.h" |
| 25 #include "ui/views/cocoa/cocoa_mouse_capture.h" | 25 #include "ui/views/cocoa/cocoa_mouse_capture.h" |
| 26 #import "ui/views/cocoa/drag_drop_client_mac.h" | 26 #import "ui/views/cocoa/drag_drop_client_mac.h" |
| 27 #import "ui/views/cocoa/native_widget_mac_accelerator_handler.h" | |
| 27 #import "ui/views/cocoa/native_widget_mac_nswindow.h" | 28 #import "ui/views/cocoa/native_widget_mac_nswindow.h" |
| 28 #import "ui/views/cocoa/views_nswindow_delegate.h" | 29 #import "ui/views/cocoa/views_nswindow_delegate.h" |
| 29 #include "ui/views/widget/drop_helper.h" | 30 #include "ui/views/widget/drop_helper.h" |
| 30 #include "ui/views/widget/widget_delegate.h" | 31 #include "ui/views/widget/widget_delegate.h" |
| 31 #include "ui/views/window/native_frame_view.h" | 32 #include "ui/views/window/native_frame_view.h" |
| 32 | 33 |
| 33 // Self-owning animation delegate that starts a hide animation, then calls | 34 // Self-owning animation delegate that starts a hide animation, then calls |
| 34 // -[NSWindow close] when the animation ends, releasing itself. | 35 // -[NSWindow close] when the animation ends, releasing itself. |
| 35 @interface ViewsNSWindowCloseAnimator : NSObject<NSAnimationDelegate> { | 36 @interface ViewsNSWindowCloseAnimator : NSObject<NSAnimationDelegate> { |
| 36 @private | 37 @private |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 return | 115 return |
| 115 [view convertPoint:NSMakePoint(0, NSHeight([view frame])) toView:nil].y; | 116 [view convertPoint:NSMakePoint(0, NSHeight([view frame])) toView:nil].y; |
| 116 } | 117 } |
| 117 | 118 |
| 118 //////////////////////////////////////////////////////////////////////////////// | 119 //////////////////////////////////////////////////////////////////////////////// |
| 119 // NativeWidgetMac, internal::NativeWidgetPrivate implementation: | 120 // NativeWidgetMac, internal::NativeWidgetPrivate implementation: |
| 120 | 121 |
| 121 void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { | 122 void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { |
| 122 ownership_ = params.ownership; | 123 ownership_ = params.ownership; |
| 123 name_ = params.name; | 124 name_ = params.name; |
| 124 base::scoped_nsobject<NSWindow> window([CreateNSWindow(params) retain]); | 125 NativeWidgetMacNSWindow* ns_window = CreateNSWindow(params); |
| 126 base::scoped_nsobject<NSWindow> window([ns_window retain]); | |
|
tapted
2017/01/02 23:11:49
if you are just after the concrete type, you can m
| |
| 125 [window setReleasedWhenClosed:NO]; // Owned by scoped_nsobject. | 127 [window setReleasedWhenClosed:NO]; // Owned by scoped_nsobject. |
| 128 | |
| 129 if (params.parent && params.pass_accelerator_to_parent) { | |
|
tapted
2017/01/02 23:11:49
I don't think we need params.pass_accelerator_to_p
| |
| 130 if (auto* bridge = | |
| 131 NativeWidgetMac::GetBridgeForNativeWindow([params.parent window])) { | |
| 132 DCHECK(bridge->ns_window()); | |
| 133 [ns_window setCommandHandler:[[[NativeWidgetMacAcceleratorHandler alloc] | |
| 134 initWithParentWindow:bridge->ns_window()] | |
| 135 autorelease]]; | |
| 136 } | |
| 137 } | |
| 138 | |
| 126 bridge_->Init(window, params); | 139 bridge_->Init(window, params); |
| 127 | 140 |
| 128 // Only set always-on-top here if it is true since setting it may affect how | 141 // Only set always-on-top here if it is true since setting it may affect how |
| 129 // the window is treated by Expose. | 142 // the window is treated by Expose. |
| 130 if (params.keep_on_top) | 143 if (params.keep_on_top) |
| 131 SetAlwaysOnTop(true); | 144 SetAlwaysOnTop(true); |
| 132 | 145 |
| 133 delegate_->OnNativeWidgetCreated(true); | 146 delegate_->OnNativeWidgetCreated(true); |
| 134 | 147 |
| 135 bridge_->SetFocusManager(GetWidget()->GetFocusManager()); | 148 bridge_->SetFocusManager(GetWidget()->GetFocusManager()); |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 778 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; | 791 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; |
| 779 } | 792 } |
| 780 | 793 |
| 781 - (void)animationDidEnd:(NSAnimation*)animation { | 794 - (void)animationDidEnd:(NSAnimation*)animation { |
| 782 [window_ close]; | 795 [window_ close]; |
| 783 [animation_ setDelegate:nil]; | 796 [animation_ setDelegate:nil]; |
| 784 [self release]; | 797 [self release]; |
| 785 } | 798 } |
| 786 | 799 |
| 787 @end | 800 @end |
| OLD | NEW |