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_model_adapter.h" | 5 #include "ui/views/controls/menu/menu_model_adapter.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/base/l10n/l10n_util.h" | 8 #include "ui/base/l10n/l10n_util.h" |
9 #include "ui/base/models/menu_model.h" | 9 #include "ui/base/models/menu_model.h" |
10 #include "ui/views/controls/menu/submenu_view.h" | 10 #include "ui/views/controls/menu/submenu_view.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 BuildMenuImpl(menu, menu_model_); | 43 BuildMenuImpl(menu, menu_model_); |
44 menu->ChildrenChanged(); | 44 menu->ChildrenChanged(); |
45 } | 45 } |
46 | 46 |
47 MenuItemView* MenuModelAdapter::CreateMenu() { | 47 MenuItemView* MenuModelAdapter::CreateMenu() { |
48 MenuItemView* item = new MenuItemView(this); | 48 MenuItemView* item = new MenuItemView(this); |
49 BuildMenu(item); | 49 BuildMenu(item); |
50 return item; | 50 return item; |
51 } | 51 } |
52 | 52 |
53 MenuItemView* MenuModelAdapter::CreateCustomItem(MenuItemView* parent, int id) { | |
54 return NULL; | |
55 } | |
56 | |
53 // MenuModelAdapter, MenuDelegate implementation: | 57 // MenuModelAdapter, MenuDelegate implementation: |
54 | 58 |
55 void MenuModelAdapter::ExecuteCommand(int id) { | 59 void MenuModelAdapter::ExecuteCommand(int id) { |
56 ui::MenuModel* model = menu_model_; | 60 ui::MenuModel* model = menu_model_; |
57 int index = 0; | 61 int index = 0; |
58 if (ui::MenuModel::GetModelAndIndexForCommandId(id, &model, &index)) { | 62 if (ui::MenuModel::GetModelAndIndexForCommandId(id, &model, &index)) { |
59 model->ActivatedAt(index); | 63 model->ActivatedAt(index); |
60 return; | 64 return; |
61 } | 65 } |
62 | 66 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 } | 180 } |
177 | 181 |
178 // MenuModelAdapter, private: | 182 // MenuModelAdapter, private: |
179 | 183 |
180 void MenuModelAdapter::BuildMenuImpl(MenuItemView* menu, ui::MenuModel* model) { | 184 void MenuModelAdapter::BuildMenuImpl(MenuItemView* menu, ui::MenuModel* model) { |
181 DCHECK(menu); | 185 DCHECK(menu); |
182 DCHECK(model); | 186 DCHECK(model); |
183 bool has_icons = model->HasIcons(); | 187 bool has_icons = model->HasIcons(); |
184 const int item_count = model->GetItemCount(); | 188 const int item_count = model->GetItemCount(); |
185 for (int i = 0; i < item_count; ++i) { | 189 for (int i = 0; i < item_count; ++i) { |
186 MenuItemView* item = menu->AppendMenuItemFromModel( | 190 MenuItemView* item = CreateCustomItem(menu, model->GetCommandIdAt(i)); |
sky
2013/03/20 14:35:09
Can we rename this CreateMenuItem and have it do t
benwells
2013/03/20 23:08:30
Good idea, renamed to AppendMenuItem, which simpli
| |
187 model, i, model->GetCommandIdAt(i)); | 191 if (item) { |
192 menu->CreateSubmenu(); | |
193 menu->GetSubmenu()->AddChildViewAt(item, i); | |
194 } else { | |
195 item = menu->AppendMenuItemFromModel(model, i, model->GetCommandIdAt(i)); | |
196 } | |
188 | 197 |
189 if (item) | 198 if (item) |
190 item->SetVisible(model->IsVisibleAt(i)); | 199 item->SetVisible(model->IsVisibleAt(i)); |
191 | 200 |
192 if (model->GetTypeAt(i) == ui::MenuModel::TYPE_SUBMENU) { | 201 if (model->GetTypeAt(i) == ui::MenuModel::TYPE_SUBMENU) { |
193 DCHECK(item); | 202 DCHECK(item); |
194 DCHECK_EQ(MenuItemView::SUBMENU, item->GetType()); | 203 DCHECK_EQ(MenuItemView::SUBMENU, item->GetType()); |
195 ui::MenuModel* submodel = model->GetSubmenuModelAt(i); | 204 ui::MenuModel* submodel = model->GetSubmenuModelAt(i); |
196 DCHECK(submodel); | 205 DCHECK(submodel); |
197 BuildMenuImpl(item, submodel); | 206 BuildMenuImpl(item, submodel); |
198 has_icons = has_icons || item->has_icons(); | 207 has_icons = has_icons || item->has_icons(); |
199 | 208 |
200 menu_map_[item] = submodel; | 209 menu_map_[item] = submodel; |
201 } | 210 } |
202 } | 211 } |
203 | 212 |
204 menu->set_has_icons(has_icons); | 213 menu->set_has_icons(has_icons); |
205 } | 214 } |
206 | 215 |
207 } // namespace views | 216 } // namespace views |
OLD | NEW |