| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/base/cocoa/menu_controller.h" | 5 #import "ui/base/cocoa/menu_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "ui/base/accelerators/accelerator.h" | 9 #include "ui/base/accelerators/accelerator.h" |
| 10 #include "ui/base/accelerators/platform_accelerator_cocoa.h" | 10 #include "ui/base/accelerators/platform_accelerator_cocoa.h" |
| 11 #import "ui/base/cocoa/cocoa_event_utils.h" | |
| 12 #include "ui/base/l10n/l10n_util_mac.h" | 11 #include "ui/base/l10n/l10n_util_mac.h" |
| 13 #include "ui/base/models/simple_menu_model.h" | 12 #include "ui/base/models/simple_menu_model.h" |
| 13 #import "ui/events/event_utils.h" |
| 14 #include "ui/gfx/font_list.h" | 14 #include "ui/gfx/font_list.h" |
| 15 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
| 16 #include "ui/gfx/text_elider.h" | 16 #include "ui/gfx/text_elider.h" |
| 17 | 17 |
| 18 @interface MenuController (Private) | 18 @interface MenuController (Private) |
| 19 - (void)addSeparatorToMenu:(NSMenu*)menu | 19 - (void)addSeparatorToMenu:(NSMenu*)menu |
| 20 atIndex:(int)index; | 20 atIndex:(int)index; |
| 21 @end | 21 @end |
| 22 | 22 |
| 23 @implementation MenuController | 23 @implementation MenuController |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 197 |
| 198 // Called when the user chooses a particular menu item. |sender| is the menu | 198 // Called when the user chooses a particular menu item. |sender| is the menu |
| 199 // item chosen. | 199 // item chosen. |
| 200 - (void)itemSelected:(id)sender { | 200 - (void)itemSelected:(id)sender { |
| 201 NSInteger modelIndex = [sender tag]; | 201 NSInteger modelIndex = [sender tag]; |
| 202 ui::MenuModel* model = | 202 ui::MenuModel* model = |
| 203 static_cast<ui::MenuModel*>( | 203 static_cast<ui::MenuModel*>( |
| 204 [[sender representedObject] pointerValue]); | 204 [[sender representedObject] pointerValue]); |
| 205 DCHECK(model); | 205 DCHECK(model); |
| 206 if (model) { | 206 if (model) { |
| 207 int event_flags = ui::EventFlagsFromNSEvent([NSApp currentEvent]); | 207 int event_flags = ui::EventFlagsFromNative([NSApp currentEvent]); |
| 208 model->ActivatedAt(modelIndex, event_flags); | 208 model->ActivatedAt(modelIndex, event_flags); |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 | 211 |
| 212 - (NSMenu*)menu { | 212 - (NSMenu*)menu { |
| 213 if (!menu_ && model_) { | 213 if (!menu_ && model_) { |
| 214 menu_.reset([[self menuFromModel:model_] retain]); | 214 menu_.reset([[self menuFromModel:model_] retain]); |
| 215 [menu_ setDelegate:self]; | 215 [menu_ setDelegate:self]; |
| 216 // If this is to be used with a NSPopUpButtonCell, add an item at the 0th | 216 // If this is to be used with a NSPopUpButtonCell, add an item at the 0th |
| 217 // position that's empty. Doing it after the menu has been constructed won't | 217 // position that's empty. Doing it after the menu has been constructed won't |
| (...skipping 18 matching lines...) Expand all Loading... |
| 236 } | 236 } |
| 237 | 237 |
| 238 - (void)menuDidClose:(NSMenu*)menu { | 238 - (void)menuDidClose:(NSMenu*)menu { |
| 239 if (isMenuOpen_) { | 239 if (isMenuOpen_) { |
| 240 model_->MenuClosed(); | 240 model_->MenuClosed(); |
| 241 isMenuOpen_ = NO; | 241 isMenuOpen_ = NO; |
| 242 } | 242 } |
| 243 } | 243 } |
| 244 | 244 |
| 245 @end | 245 @end |
| OLD | NEW |