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

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: Properly release |commandHandler|. 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
« no previous file with comments | « ui/base/ui_base.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/base/cocoa/user_interface_item_command_handler.h"
8 #import "ui/views/cocoa/views_nswindow_delegate.h" 9 #import "ui/views/cocoa/views_nswindow_delegate.h"
9 #include "ui/views/controls/menu/menu_controller.h" 10 #include "ui/views/controls/menu/menu_controller.h"
10 #include "ui/views/widget/native_widget_mac.h" 11 #include "ui/views/widget/native_widget_mac.h"
11 #include "ui/views/widget/widget_delegate.h" 12 #include "ui/views/widget/widget_delegate.h"
12 13
13 @interface NativeWidgetMacNSWindow () 14 @interface NativeWidgetMacNSWindow ()
14 - (ViewsNSWindowDelegate*)viewsNSWindowDelegate; 15 - (ViewsNSWindowDelegate*)viewsNSWindowDelegate;
15 - (views::Widget*)viewsWidget; 16 - (views::Widget*)viewsWidget;
16 - (BOOL)hasViewsMenuActive; 17 - (BOOL)hasViewsMenuActive;
17 18
18 // Private API on NSWindow, determines whether the title is drawn on the title 19 // Private API on NSWindow, determines whether the title is drawn on the title
19 // bar. The title is still visible in menus, Expose, etc. 20 // bar. The title is still visible in menus, Expose, etc.
20 - (BOOL)_isTitleHidden; 21 - (BOOL)_isTitleHidden;
21 @end 22 @end
22 23
23 @implementation NativeWidgetMacNSWindow { 24 @implementation NativeWidgetMacNSWindow {
24 @private 25 @private
25 base::scoped_nsobject<CommandDispatcher> commandDispatcher_; 26 base::scoped_nsobject<CommandDispatcher> commandDispatcher_;
27 base::scoped_nsprotocol<id<UserInterfaceItemCommandHandler>> commandHandler_;
26 } 28 }
27 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])) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 155
154 NSCursor* cursor = [[self viewsNSWindowDelegate] cursor]; 156 NSCursor* cursor = [[self viewsNSWindowDelegate] cursor];
155 if (cursor) 157 if (cursor)
156 [cursor set]; 158 [cursor set];
157 else 159 else
158 [super cursorUpdate:theEvent]; 160 [super cursorUpdate:theEvent];
159 } 161 }
160 162
161 // CommandDispatchingWindow implementation. 163 // CommandDispatchingWindow implementation.
162 164
165 - (void)setCommandHandler:(id<UserInterfaceItemCommandHandler>)commandHandler {
166 commandHandler_.reset([commandHandler retain]);
167 }
168
163 - (BOOL)redispatchKeyEvent:(NSEvent*)event { 169 - (BOOL)redispatchKeyEvent:(NSEvent*)event {
164 return [commandDispatcher_ redispatchKeyEvent:event]; 170 return [commandDispatcher_ redispatchKeyEvent:event];
165 } 171 }
166 172
167 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event { 173 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event {
168 return [super performKeyEquivalent:event]; 174 return [super performKeyEquivalent:event];
169 } 175 }
170 176
177 - (void)commandDispatch:(id)sender {
178 [commandHandler_ commandDispatch:sender window:self];
179 }
180
181 - (void)commandDispatchUsingKeyModifiers:(id)sender {
182 [commandHandler_ commandDispatchUsingKeyModifiers:sender window:self];
183 }
184
185 // NSWindow overrides (NSUserInterfaceItemValidations implementation)
186
187 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
188 // Since this class implements these selectors, |super| will always say they
189 // are enabled. Only use [super] to validate other selectors. If there is no
190 // command handler, defer to AppController.
191 if ([item action] == @selector(commandDispatch:) ||
192 [item action] == @selector(commandDispatchUsingKeyModifiers:)) {
193 return commandHandler_
194 ? [commandHandler_ validateUserInterfaceItem:item window:self]
195 : [[NSApp delegate] validateUserInterfaceItem:item];
196 }
197
198 return [super validateUserInterfaceItem:item];
199 }
200
171 @end 201 @end
OLDNEW
« no previous file with comments | « ui/base/ui_base.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698