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

Side by Side Diff: chrome/browser/ui/cocoa/chrome_event_processing_window.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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/cocoa/chrome_event_processing_window.h" 5 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "chrome/browser/ui/cocoa/chrome_command_dispatcher_delegate.h" 8 #import "chrome/browser/ui/cocoa/chrome_command_dispatcher_delegate.h"
9 #import "ui/base/cocoa/user_interface_item_command_handler.h"
9 10
10 @implementation ChromeEventProcessingWindow { 11 @implementation ChromeEventProcessingWindow {
11 @private 12 @private
12 base::scoped_nsobject<CommandDispatcher> commandDispatcher_; 13 base::scoped_nsobject<CommandDispatcher> commandDispatcher_;
13 base::scoped_nsobject<ChromeCommandDispatcherDelegate> 14 base::scoped_nsobject<ChromeCommandDispatcherDelegate>
14 commandDispatcherDelegate_; 15 commandDispatcherDelegate_;
16 base::scoped_nsprotocol<id<UserInterfaceItemCommandHandler>> commandHandler_;
15 } 17 }
16 18
17 - (instancetype)initWithContentRect:(NSRect)contentRect 19 - (instancetype)initWithContentRect:(NSRect)contentRect
18 styleMask:(NSUInteger)windowStyle 20 styleMask:(NSUInteger)windowStyle
19 backing:(NSBackingStoreType)bufferingType 21 backing:(NSBackingStoreType)bufferingType
20 defer:(BOOL)deferCreation { 22 defer:(BOOL)deferCreation {
21 if ((self = [super initWithContentRect:contentRect 23 if ((self = [super initWithContentRect:contentRect
22 styleMask:windowStyle 24 styleMask:windowStyle
23 backing:bufferingType 25 backing:bufferingType
24 defer:deferCreation])) { 26 defer:deferCreation])) {
25 commandDispatcher_.reset([[CommandDispatcher alloc] initWithOwner:self]); 27 commandDispatcher_.reset([[CommandDispatcher alloc] initWithOwner:self]);
26 commandDispatcherDelegate_.reset( 28 commandDispatcherDelegate_.reset(
27 [[ChromeCommandDispatcherDelegate alloc] init]); 29 [[ChromeCommandDispatcherDelegate alloc] init]);
28 [commandDispatcher_ setDelegate:commandDispatcherDelegate_]; 30 [commandDispatcher_ setDelegate:commandDispatcherDelegate_];
29 } 31 }
30 return self; 32 return self;
31 } 33 }
32 34
33 - (BOOL)handleExtraKeyboardShortcut:(NSEvent*)event { 35 - (BOOL)handleExtraKeyboardShortcut:(NSEvent*)event {
34 return [commandDispatcherDelegate_ handleExtraKeyboardShortcut:event 36 return [commandDispatcherDelegate_ handleExtraKeyboardShortcut:event
35 window:self]; 37 window:self];
36 } 38 }
37 39
38 // CommandDispatchingWindow implementation. 40 // CommandDispatchingWindow implementation.
39 41
42 - (void)setCommandHandler:(id<UserInterfaceItemCommandHandler>)commandHandler {
43 commandHandler_.reset([commandHandler retain]);
44 }
45
40 - (BOOL)redispatchKeyEvent:(NSEvent*)event { 46 - (BOOL)redispatchKeyEvent:(NSEvent*)event {
41 return [commandDispatcher_ redispatchKeyEvent:event]; 47 return [commandDispatcher_ redispatchKeyEvent:event];
42 } 48 }
43 49
44 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event { 50 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event {
45 return [super performKeyEquivalent:event]; 51 return [super performKeyEquivalent:event];
46 } 52 }
47 53
54 - (void)commandDispatch:(id)sender {
55 [commandHandler_ commandDispatch:sender window:self];
56 }
57
58 - (void)commandDispatchUsingKeyModifiers:(id)sender {
59 [commandHandler_ commandDispatchUsingKeyModifiers:sender window:self];
60 }
61
48 // NSWindow overrides. 62 // NSWindow overrides.
49 63
50 - (BOOL)performKeyEquivalent:(NSEvent*)event { 64 - (BOOL)performKeyEquivalent:(NSEvent*)event {
51 return [commandDispatcher_ performKeyEquivalent:event]; 65 return [commandDispatcher_ performKeyEquivalent:event];
52 } 66 }
53 67
54 - (void)sendEvent:(NSEvent*)event { 68 - (void)sendEvent:(NSEvent*)event {
55 if (![commandDispatcher_ preSendEvent:event]) 69 if (![commandDispatcher_ preSendEvent:event])
56 [super sendEvent:event]; 70 [super sendEvent:event];
57 } 71 }
58 72
73 // NSWindow overrides (NSUserInterfaceValidations implementation).
74
75 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
76 // Since this class implements these selectors, |super| will always say they
77 // are enabled. Only use [super] to validate other selectors. If there is no
78 // command handler, defer to AppController.
79 if ([item action] == @selector(commandDispatch:) ||
80 [item action] == @selector(commandDispatchUsingKeyModifiers:)) {
81 return commandHandler_
82 ? [commandHandler_ validateUserInterfaceItem:item window:self]
83 : [[NSApp delegate] validateUserInterfaceItem:item];
84 }
85
86 return [super validateUserInterfaceItem:item];
87 }
88
59 @end // ChromeEventProcessingWindow 89 @end // ChromeEventProcessingWindow
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller.mm ('k') | chrome/browser/ui/views/frame/browser_frame_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698