Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: ui/views/cocoa/native_widget_mac_nswindow.mm

Issue 1250403002: [Mac] Move UI item validation to UserInterfaceItemCommandHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@commandexecute
Patch Set: Split out BrowserWindowCommandHandler and only use it in browser windows. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
OLDNEW
« ui/base/cocoa/command_dispatcher.h ('K') | « ui/base/cocoa/command_dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698