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::AppendMenuItem(MenuItemView* menu, |
| 54 ui::MenuModel* model, |
| 55 int index) { |
| 56 return menu->AppendMenuItemFromModel(model, index, |
| 57 model->GetCommandIdAt(index)); |
| 58 } |
| 59 |
53 // MenuModelAdapter, MenuDelegate implementation: | 60 // MenuModelAdapter, MenuDelegate implementation: |
54 | 61 |
55 void MenuModelAdapter::ExecuteCommand(int id) { | 62 void MenuModelAdapter::ExecuteCommand(int id) { |
56 ui::MenuModel* model = menu_model_; | 63 ui::MenuModel* model = menu_model_; |
57 int index = 0; | 64 int index = 0; |
58 if (ui::MenuModel::GetModelAndIndexForCommandId(id, &model, &index)) { | 65 if (ui::MenuModel::GetModelAndIndexForCommandId(id, &model, &index)) { |
59 model->ActivatedAt(index); | 66 model->ActivatedAt(index); |
60 return; | 67 return; |
61 } | 68 } |
62 | 69 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } | 183 } |
177 | 184 |
178 // MenuModelAdapter, private: | 185 // MenuModelAdapter, private: |
179 | 186 |
180 void MenuModelAdapter::BuildMenuImpl(MenuItemView* menu, ui::MenuModel* model) { | 187 void MenuModelAdapter::BuildMenuImpl(MenuItemView* menu, ui::MenuModel* model) { |
181 DCHECK(menu); | 188 DCHECK(menu); |
182 DCHECK(model); | 189 DCHECK(model); |
183 bool has_icons = model->HasIcons(); | 190 bool has_icons = model->HasIcons(); |
184 const int item_count = model->GetItemCount(); | 191 const int item_count = model->GetItemCount(); |
185 for (int i = 0; i < item_count; ++i) { | 192 for (int i = 0; i < item_count; ++i) { |
186 MenuItemView* item = menu->AppendMenuItemFromModel( | 193 MenuItemView* item = AppendMenuItem(menu, model, i); |
187 model, i, model->GetCommandIdAt(i)); | |
188 | 194 |
189 if (item) | 195 if (item) |
190 item->SetVisible(model->IsVisibleAt(i)); | 196 item->SetVisible(model->IsVisibleAt(i)); |
191 | 197 |
192 if (model->GetTypeAt(i) == ui::MenuModel::TYPE_SUBMENU) { | 198 if (model->GetTypeAt(i) == ui::MenuModel::TYPE_SUBMENU) { |
193 DCHECK(item); | 199 DCHECK(item); |
194 DCHECK_EQ(MenuItemView::SUBMENU, item->GetType()); | 200 DCHECK_EQ(MenuItemView::SUBMENU, item->GetType()); |
195 ui::MenuModel* submodel = model->GetSubmenuModelAt(i); | 201 ui::MenuModel* submodel = model->GetSubmenuModelAt(i); |
196 DCHECK(submodel); | 202 DCHECK(submodel); |
197 BuildMenuImpl(item, submodel); | 203 BuildMenuImpl(item, submodel); |
198 has_icons = has_icons || item->has_icons(); | 204 has_icons = has_icons || item->has_icons(); |
199 | 205 |
200 menu_map_[item] = submodel; | 206 menu_map_[item] = submodel; |
201 } | 207 } |
202 } | 208 } |
203 | 209 |
204 menu->set_has_icons(has_icons); | 210 menu->set_has_icons(has_icons); |
205 } | 211 } |
206 | 212 |
207 } // namespace views | 213 } // namespace views |
OLD | NEW |