| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/views/cocoa/native_widget_mac_accelerator_handler.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "ui/views/cocoa/native_widget_mac_nswindow.h" |
| 9 |
| 10 @implementation NativeWidgetMacAcceleratorHandler { |
| 11 @private |
| 12 NSWindow* parent_; |
| 13 } |
| 14 |
| 15 - (instancetype)initWithParentWindow:(NSWindow*)parent { |
| 16 if ((self = [super init])) { |
| 17 DCHECK(parent); |
| 18 parent_ = parent; |
| 19 [[NSNotificationCenter defaultCenter] |
| 20 addObserver:self |
| 21 selector:@selector(parentWindowWillClose:) |
| 22 name:NSWindowWillCloseNotification |
| 23 object:parent_]; |
| 24 } |
| 25 return self; |
| 26 } |
| 27 |
| 28 - (void)dealloc { |
| 29 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 30 [super dealloc]; |
| 31 } |
| 32 |
| 33 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item |
| 34 window:(NSWindow*)window { |
| 35 if (!parent_) |
| 36 return NO; |
| 37 id parent = parent_; |
| 38 if ([parent respondsToSelector:@selector(validateUserInterfaceItem:)]) |
| 39 return [parent validateUserInterfaceItem:item]; |
| 40 return NO; |
| 41 } |
| 42 |
| 43 - (void)commandDispatch:(id)sender window:(NSWindow*)window { |
| 44 id parent = parent_; |
| 45 if ([parent respondsToSelector:@selector(commandDispatch:)]) |
| 46 [parent commandDispatch:sender]; |
| 47 } |
| 48 |
| 49 - (void)commandDispatchUsingKeyModifiers:(id)sender window:(NSWindow*)window { |
| 50 id parent = parent_; |
| 51 if ([parent respondsToSelector:@selector(commandDispatchUsingKeyModifiers:)]) |
| 52 [parent commandDispatchUsingKeyModifiers:sender]; |
| 53 } |
| 54 |
| 55 - (void)parentWindowWillClose:(NSNotification*)notification { |
| 56 parent_ = nil; |
| 57 } |
| 58 |
| 59 @end |
| OLD | NEW |