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

Unified Diff: ui/views/controls/menu/menu_model_adapter.cc

Issue 23530070: backup for dynamic recent tabs submenu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new RecentTabsMenuModelDelegate w/ new intf Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/menu/menu_model_adapter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/menu/menu_model_adapter.cc
diff --git a/ui/views/controls/menu/menu_model_adapter.cc b/ui/views/controls/menu/menu_model_adapter.cc
index 15c6cf66139c3d56f626d543c50c515472f8288d..07f1f403fd82fe9f22beb04c5dd40ea96f1fd562 100644
--- a/ui/views/controls/menu/menu_model_adapter.cc
+++ b/ui/views/controls/menu/menu_model_adapter.cc
@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/menu_model.h"
+#include "ui/gfx/image/image.h"
#include "ui/views/controls/menu/submenu_view.h"
#include "ui/views/views_delegate.h"
@@ -50,11 +51,82 @@ MenuItemView* MenuModelAdapter::CreateMenu() {
return item;
}
+// Static.
+MenuItemView* MenuModelAdapter::AddMenuItemFromModelAt(ui::MenuModel* model,
+ int model_index,
+ MenuItemView* menu,
+ int menu_index,
+ int item_id) {
+ gfx::Image icon;
+ model->GetIconAt(model_index, &icon);
+ string16 label, sublabel, minor_text;
+ ui::MenuSeparatorType separator_style = ui::NORMAL_SEPARATOR;
+ MenuItemView::Type type;
+ ui::MenuModel::ItemType menu_type = model->GetTypeAt(model_index);
+
+ switch (menu_type) {
+ case ui::MenuModel::TYPE_COMMAND:
+ type = MenuItemView::NORMAL;
+ label = model->GetLabelAt(model_index);
+ sublabel = model->GetSublabelAt(model_index);
+ minor_text = model->GetMinorTextAt(model_index);
+ break;
+ case ui::MenuModel::TYPE_CHECK:
+ type = MenuItemView::CHECKBOX;
+ label = model->GetLabelAt(model_index);
+ sublabel = model->GetSublabelAt(model_index);
+ minor_text = model->GetMinorTextAt(model_index);
+ break;
+ case ui::MenuModel::TYPE_RADIO:
+ type = MenuItemView::RADIO;
+ label = model->GetLabelAt(model_index);
+ sublabel = model->GetSublabelAt(model_index);
+ minor_text = model->GetMinorTextAt(model_index);
+ break;
+ case ui::MenuModel::TYPE_SEPARATOR:
+ icon = gfx::Image();
+ type = MenuItemView::SEPARATOR;
+ separator_style = model->GetSeparatorTypeAt(model_index);
+ break;
+ case ui::MenuModel::TYPE_SUBMENU:
+ type = MenuItemView::SUBMENU;
+ label = model->GetLabelAt(model_index);
+ sublabel = model->GetSublabelAt(model_index);
+ minor_text = model->GetMinorTextAt(model_index);
+ break;
+ default:
+ NOTREACHED();
+ type = MenuItemView::NORMAL;
+ break;
+ }
+
+ return menu->AddMenuItemAt(
+ menu_index,
+ item_id,
+ label,
+ sublabel,
+ minor_text,
+ icon.IsEmpty() ? gfx::ImageSkia() : *icon.ToImageSkia(),
+ type,
+ separator_style);
+}
+
+// Static.
+MenuItemView* MenuModelAdapter::AppendMenuItemFromModel(ui::MenuModel* model,
+ int model_index,
+ MenuItemView* menu,
+ int item_id) {
+ const int menu_index = menu->HasSubmenu() ?
+ menu->GetSubmenu()->child_count() : 0;
+ return AddMenuItemFromModelAt(model, model_index, menu, menu_index, item_id);
+}
+
+
MenuItemView* MenuModelAdapter::AppendMenuItem(MenuItemView* menu,
ui::MenuModel* model,
int index) {
- return menu->AppendMenuItemFromModel(model, index,
- model->GetCommandIdAt(index));
+ return AppendMenuItemFromModel(model, index, menu,
+ model->GetCommandIdAt(index));
}
// MenuModelAdapter, MenuDelegate implementation:
« no previous file with comments | « ui/views/controls/menu/menu_model_adapter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698