| OLD | NEW |
| 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 #include "ui/views/controls/menu/menu_item_view.h" | 5 #include "ui/views/controls/menu/menu_item_view.h" |
| 6 | 6 |
| 7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "grit/ui_strings.h" | 10 #include "grit/ui_strings.h" |
| 11 #include "ui/base/accessibility/accessible_view_state.h" | 11 #include "ui/base/accessibility/accessible_view_state.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 13 #include "ui/base/models/menu_model.h" | 13 #include "ui/base/models/menu_model.h" |
| 14 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
| 15 #include "ui/gfx/image/image.h" |
| 15 #include "ui/views/controls/button/menu_button.h" | 16 #include "ui/views/controls/button/menu_button.h" |
| 16 #include "ui/views/controls/image_view.h" | 17 #include "ui/views/controls/image_view.h" |
| 17 #include "ui/views/controls/menu/menu_config.h" | 18 #include "ui/views/controls/menu/menu_config.h" |
| 18 #include "ui/views/controls/menu/menu_controller.h" | 19 #include "ui/views/controls/menu/menu_controller.h" |
| 19 #include "ui/views/controls/menu/menu_separator.h" | 20 #include "ui/views/controls/menu/menu_separator.h" |
| 20 #include "ui/views/controls/menu/submenu_view.h" | 21 #include "ui/views/controls/menu/submenu_view.h" |
| 21 | 22 |
| 22 namespace views { | 23 namespace views { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 280 |
| 280 MenuItemView* MenuItemView::AppendMenuItemWithIcon(int item_id, | 281 MenuItemView* MenuItemView::AppendMenuItemWithIcon(int item_id, |
| 281 const string16& label, | 282 const string16& label, |
| 282 const gfx::ImageSkia& icon) { | 283 const gfx::ImageSkia& icon) { |
| 283 return AppendMenuItemImpl(item_id, label, icon, NORMAL); | 284 return AppendMenuItemImpl(item_id, label, icon, NORMAL); |
| 284 } | 285 } |
| 285 | 286 |
| 286 MenuItemView* MenuItemView::AppendMenuItemFromModel(ui::MenuModel* model, | 287 MenuItemView* MenuItemView::AppendMenuItemFromModel(ui::MenuModel* model, |
| 287 int index, | 288 int index, |
| 288 int id) { | 289 int id) { |
| 289 gfx::ImageSkia icon; | 290 gfx::Image icon; |
| 290 string16 label; | 291 string16 label; |
| 291 MenuItemView::Type type; | 292 MenuItemView::Type type; |
| 292 ui::MenuModel::ItemType menu_type = model->GetTypeAt(index); | 293 ui::MenuModel::ItemType menu_type = model->GetTypeAt(index); |
| 293 switch (menu_type) { | 294 switch (menu_type) { |
| 294 case ui::MenuModel::TYPE_COMMAND: | 295 case ui::MenuModel::TYPE_COMMAND: |
| 295 model->GetIconAt(index, &icon); | 296 model->GetIconAt(index, &icon); |
| 296 type = MenuItemView::NORMAL; | 297 type = MenuItemView::NORMAL; |
| 297 label = model->GetLabelAt(index); | 298 label = model->GetLabelAt(index); |
| 298 break; | 299 break; |
| 299 case ui::MenuModel::TYPE_CHECK: | 300 case ui::MenuModel::TYPE_CHECK: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 311 model->GetIconAt(index, &icon); | 312 model->GetIconAt(index, &icon); |
| 312 type = MenuItemView::SUBMENU; | 313 type = MenuItemView::SUBMENU; |
| 313 label = model->GetLabelAt(index); | 314 label = model->GetLabelAt(index); |
| 314 break; | 315 break; |
| 315 default: | 316 default: |
| 316 NOTREACHED(); | 317 NOTREACHED(); |
| 317 type = MenuItemView::NORMAL; | 318 type = MenuItemView::NORMAL; |
| 318 break; | 319 break; |
| 319 } | 320 } |
| 320 | 321 |
| 321 return AppendMenuItemImpl(id, label, icon, type); | 322 return AppendMenuItemImpl(id, |
| 323 label, |
| 324 icon.IsEmpty() ? gfx::ImageSkia() : *icon.ToImageSkia(), |
| 325 type); |
| 322 } | 326 } |
| 323 | 327 |
| 324 MenuItemView* MenuItemView::AppendMenuItemImpl(int item_id, | 328 MenuItemView* MenuItemView::AppendMenuItemImpl(int item_id, |
| 325 const string16& label, | 329 const string16& label, |
| 326 const gfx::ImageSkia& icon, | 330 const gfx::ImageSkia& icon, |
| 327 Type type) { | 331 Type type) { |
| 328 const int index = submenu_ ? submenu_->child_count() : 0; | 332 const int index = submenu_ ? submenu_->child_count() : 0; |
| 329 return AddMenuItemAt(index, item_id, label, icon, type); | 333 return AddMenuItemAt(index, item_id, label, icon, type); |
| 330 } | 334 } |
| 331 | 335 |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 temp_width = menu_item->GetMaxIconViewWidth(); | 850 temp_width = menu_item->GetMaxIconViewWidth(); |
| 847 } else if (menu_item->icon_view()) { | 851 } else if (menu_item->icon_view()) { |
| 848 temp_width = menu_item->icon_view()->GetPreferredSize().width(); | 852 temp_width = menu_item->icon_view()->GetPreferredSize().width(); |
| 849 } | 853 } |
| 850 width = std::max(width, temp_width); | 854 width = std::max(width, temp_width); |
| 851 } | 855 } |
| 852 return width; | 856 return width; |
| 853 } | 857 } |
| 854 | 858 |
| 855 } // namespace views | 859 } // namespace views |
| OLD | NEW |