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 #import "ui/views/cocoa/native_widget_mac_nswindow.h" | 5 #import "ui/views/cocoa/native_widget_mac_nswindow.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #import "ui/views/cocoa/views_nswindow_delegate.h" | 8 #import "ui/views/cocoa/views_nswindow_delegate.h" |
| 9 #include "ui/views/controls/menu/menu_controller.h" | 9 #include "ui/views/controls/menu/menu_controller.h" |
| 10 #include "ui/views/widget/native_widget_mac.h" | 10 #include "ui/views/widget/native_widget_mac.h" |
| 11 #include "ui/views/widget/widget_delegate.h" | 11 #include "ui/views/widget/widget_delegate.h" |
| 12 | 12 |
| 13 @interface NativeWidgetMacNSWindow () | 13 @interface NativeWidgetMacNSWindow () |
| 14 - (ViewsNSWindowDelegate*)viewsNSWindowDelegate; | 14 - (ViewsNSWindowDelegate*)viewsNSWindowDelegate; |
| 15 - (views::Widget*)viewsWidget; | 15 - (views::Widget*)viewsWidget; |
| 16 - (BOOL)hasViewsMenuActive; | 16 - (BOOL)hasViewsMenuActive; |
| 17 | 17 |
| 18 // Private API on NSWindow, determines whether the title is drawn on the title | 18 // Private API on NSWindow, determines whether the title is drawn on the title |
| 19 // bar. The title is still visible in menus, Expose, etc. | 19 // bar. The title is still visible in menus, Expose, etc. |
| 20 - (BOOL)_isTitleHidden; | 20 - (BOOL)_isTitleHidden; |
| 21 @end | 21 @end |
| 22 | 22 |
| 23 @implementation NativeWidgetMacNSWindow { | 23 @implementation NativeWidgetMacNSWindow { |
| 24 @private | 24 @private |
| 25 base::scoped_nsobject<CommandDispatcher> commandDispatcher_; | 25 base::scoped_nsobject<CommandDispatcher> commandDispatcher_; |
| 26 } | 26 } |
| 27 | 27 |
| 28 @synthesize commandHandler; | |
|
tapted
2015/09/04 02:56:24
With this approach (i.e. assign not retain), I thi
jackhou1
2015/09/04 06:13:59
Changed to retain.
| |
| 29 | |
| 28 - (instancetype)initWithContentRect:(NSRect)contentRect | 30 - (instancetype)initWithContentRect:(NSRect)contentRect |
| 29 styleMask:(NSUInteger)windowStyle | 31 styleMask:(NSUInteger)windowStyle |
| 30 backing:(NSBackingStoreType)bufferingType | 32 backing:(NSBackingStoreType)bufferingType |
| 31 defer:(BOOL)deferCreation { | 33 defer:(BOOL)deferCreation { |
| 32 if ((self = [super initWithContentRect:contentRect | 34 if ((self = [super initWithContentRect:contentRect |
| 33 styleMask:windowStyle | 35 styleMask:windowStyle |
| 34 backing:bufferingType | 36 backing:bufferingType |
| 35 defer:deferCreation])) { | 37 defer:deferCreation])) { |
| 36 commandDispatcher_.reset([[CommandDispatcher alloc] initWithOwner:self]); | 38 commandDispatcher_.reset([[CommandDispatcher alloc] initWithOwner:self]); |
| 37 } | 39 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 // CommandDispatchingWindow implementation. | 163 // CommandDispatchingWindow implementation. |
| 162 | 164 |
| 163 - (BOOL)redispatchKeyEvent:(NSEvent*)event { | 165 - (BOOL)redispatchKeyEvent:(NSEvent*)event { |
| 164 return [commandDispatcher_ redispatchKeyEvent:event]; | 166 return [commandDispatcher_ redispatchKeyEvent:event]; |
| 165 } | 167 } |
| 166 | 168 |
| 167 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event { | 169 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event { |
| 168 return [super performKeyEquivalent:event]; | 170 return [super performKeyEquivalent:event]; |
| 169 } | 171 } |
| 170 | 172 |
| 173 - (void)commandDispatch:(id)sender { | |
| 174 [[self commandHandler] commandDispatch:sender window:self]; | |
| 175 } | |
| 176 | |
| 177 - (void)commandDispatchUsingKeyModifiers:(id)sender { | |
| 178 [[self commandHandler] commandDispatchUsingKeyModifiers:sender window:self]; | |
| 179 } | |
| 180 | |
| 181 // NSWindow overrides (NSUserInterfaceItemValidations implementation) | |
| 182 | |
| 183 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { | |
| 184 // Since this class implements these selectors, |super| will always say they | |
|
tapted
2015/09/04 02:56:24
Then perhaps this logic can move into commandDispa
jackhou1
2015/09/04 06:13:59
Ah, I agree sharing this logic would be good. But
| |
| 185 // are enabled. Only use [super] to validate other selectors. If there is no | |
| 186 // command handler, defer to AppController. | |
| 187 if ([item action] == @selector(commandDispatch:) || | |
| 188 [item action] == @selector(commandDispatchUsingKeyModifiers:)) { | |
| 189 return | |
| 190 [self commandHandler] | |
| 191 ? [[self commandHandler] validateUserInterfaceItem:item window:self] | |
| 192 : [[NSApp delegate] validateUserInterfaceItem:item]; | |
| 193 } | |
| 194 | |
| 195 return [super validateUserInterfaceItem:item]; | |
| 196 } | |
| 197 | |
| 171 @end | 198 @end |
| OLD | NEW |