| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "views/controls/menu/menu_item_view.h" | 5 #include "views/controls/menu/menu_item_view.h" | 
| 6 | 6 | 
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" | 
|  | 8 #include "app/menus/menu_model.h" | 
| 8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" | 
| 9 #include "gfx/canvas.h" | 10 #include "gfx/canvas.h" | 
| 10 #include "grit/app_strings.h" | 11 #include "grit/app_strings.h" | 
| 11 #include "views/controls/button/text_button.h" | 12 #include "views/controls/button/text_button.h" | 
| 12 #include "views/controls/button/menu_button.h" | 13 #include "views/controls/button/menu_button.h" | 
| 13 #include "views/controls/menu/menu_config.h" | 14 #include "views/controls/menu/menu_config.h" | 
| 14 #include "views/controls/menu/menu_controller.h" | 15 #include "views/controls/menu/menu_controller.h" | 
| 15 #include "views/controls/menu/menu_separator.h" | 16 #include "views/controls/menu/menu_separator.h" | 
| 16 #include "views/controls/menu/submenu_view.h" | 17 #include "views/controls/menu/submenu_view.h" | 
| 17 | 18 | 
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 230   controller_->Run(parent, NULL, this, bounds, anchor, NULL); | 231   controller_->Run(parent, NULL, this, bounds, anchor, NULL); | 
| 231 } | 232 } | 
| 232 | 233 | 
| 233 void MenuItemView::Cancel() { | 234 void MenuItemView::Cancel() { | 
| 234   if (controller_ && !canceled_) { | 235   if (controller_ && !canceled_) { | 
| 235     canceled_ = true; | 236     canceled_ = true; | 
| 236     controller_->Cancel(MenuController::EXIT_ALL); | 237     controller_->Cancel(MenuController::EXIT_ALL); | 
| 237   } | 238   } | 
| 238 } | 239 } | 
| 239 | 240 | 
|  | 241 MenuItemView* MenuItemView::AppendMenuItemFromModel(menus::MenuModel* model, | 
|  | 242                                                     int index, | 
|  | 243                                                     int id) { | 
|  | 244   SkBitmap icon; | 
|  | 245   std::wstring label; | 
|  | 246   MenuItemView::Type type; | 
|  | 247   menus::MenuModel::ItemType menu_type = model->GetTypeAt(index); | 
|  | 248   switch (menu_type) { | 
|  | 249     case menus::MenuModel::TYPE_COMMAND: | 
|  | 250       model->GetIconAt(index, &icon); | 
|  | 251       type = MenuItemView::NORMAL; | 
|  | 252       label = UTF16ToWide(model->GetLabelAt(index)); | 
|  | 253       break; | 
|  | 254     case menus::MenuModel::TYPE_CHECK: | 
|  | 255       type = MenuItemView::CHECKBOX; | 
|  | 256       label = UTF16ToWide(model->GetLabelAt(index)); | 
|  | 257       break; | 
|  | 258     case menus::MenuModel::TYPE_RADIO: | 
|  | 259       type = MenuItemView::RADIO; | 
|  | 260       label = UTF16ToWide(model->GetLabelAt(index)); | 
|  | 261       break; | 
|  | 262     case menus::MenuModel::TYPE_SEPARATOR: | 
|  | 263       type = MenuItemView::SEPARATOR; | 
|  | 264       break; | 
|  | 265     case menus::MenuModel::TYPE_SUBMENU: | 
|  | 266       type = MenuItemView::SUBMENU; | 
|  | 267       label = UTF16ToWide(model->GetLabelAt(index)); | 
|  | 268       break; | 
|  | 269     default: | 
|  | 270       NOTREACHED(); | 
|  | 271       type = MenuItemView::NORMAL; | 
|  | 272       break; | 
|  | 273   } | 
|  | 274 | 
|  | 275   return AppendMenuItemImpl(id, label, icon, type); | 
|  | 276 } | 
|  | 277 | 
| 240 MenuItemView* MenuItemView::AppendMenuItemImpl(int item_id, | 278 MenuItemView* MenuItemView::AppendMenuItemImpl(int item_id, | 
| 241                                                const std::wstring& label, | 279                                                const std::wstring& label, | 
| 242                                                const SkBitmap& icon, | 280                                                const SkBitmap& icon, | 
| 243                                                Type type) { | 281                                                Type type) { | 
| 244   if (!submenu_) | 282   if (!submenu_) | 
| 245     CreateSubmenu(); | 283     CreateSubmenu(); | 
| 246   if (type == SEPARATOR) { | 284   if (type == SEPARATOR) { | 
| 247     submenu_->AddChildView(new MenuSeparator()); | 285     submenu_->AddChildView(new MenuSeparator()); | 
| 248     return NULL; | 286     return NULL; | 
| 249   } | 287   } | 
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 618 } | 656 } | 
| 619 | 657 | 
| 620 std::wstring MenuItemView::GetAcceleratorText() { | 658 std::wstring MenuItemView::GetAcceleratorText() { | 
| 621   Accelerator accelerator; | 659   Accelerator accelerator; | 
| 622   return (GetDelegate() && | 660   return (GetDelegate() && | 
| 623           GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? | 661           GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? | 
| 624       accelerator.GetShortcutText() : std::wstring(); | 662       accelerator.GetShortcutText() : std::wstring(); | 
| 625 } | 663 } | 
| 626 | 664 | 
| 627 }  // namespace views | 665 }  // namespace views | 
| OLD | NEW | 
|---|