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

Side by Side Diff: ui/base/models/menu_model.cc

Issue 7067032: Add MenuModelAdapter to wrap ui::MenuModel with views::MenuDelegate interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restore NOTREACHED() in IsCommandEnabled(). Created 9 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base/models/menu_model.h" 5 #include "ui/base/models/menu_model.h"
6 6
7 namespace ui { 7 namespace ui {
8 8
9 int MenuModel::GetFirstItemIndex(gfx::NativeMenu native_menu) const { 9 int MenuModel::GetFirstItemIndex(gfx::NativeMenu native_menu) const {
10 return 0; 10 return 0;
11 } 11 }
12 12
13 bool MenuModel::IsVisibleAt(int index) const { 13 bool MenuModel::IsVisibleAt(int index) const {
14 return true; 14 return true;
15 } 15 }
16 16
17 bool MenuModel::GetModelAndIndexForCommandId(int command_id, 17 bool MenuModel::GetModelAndIndexForCommandId(int command_id,
18 MenuModel** model, int* index) { 18 MenuModel** model, int* index) {
19 int item_count = (*model)->GetItemCount(); 19 const int item_count = (*model)->GetItemCount();
20 for (int i = 0; i < item_count; ++i) { 20 for (int i = 0; i < item_count; ++i) {
21 if ((*model)->GetTypeAt(i) == TYPE_SUBMENU) { 21 const int candidate_index = i + (*model)->GetFirstItemIndex(NULL);
sky 2011/05/25 15:41:12 Move this call outside the loop.
rhashimoto 2011/05/25 16:24:37 Done.
22 MenuModel* submenu_model = (*model)->GetSubmenuModelAt(i); 22 if ((*model)->GetTypeAt(candidate_index) == TYPE_SUBMENU) {
23 MenuModel* submenu_model = (*model)->GetSubmenuModelAt(candidate_index);
23 if (GetModelAndIndexForCommandId(command_id, &submenu_model, index)) { 24 if (GetModelAndIndexForCommandId(command_id, &submenu_model, index)) {
24 *model = submenu_model; 25 *model = submenu_model;
25 return true; 26 return true;
26 } 27 }
27 } 28 }
28 if ((*model)->GetCommandIdAt(i) == command_id) { 29 if ((*model)->GetCommandIdAt(candidate_index) == command_id) {
29 *index = i; 30 *index = candidate_index;
30 return true; 31 return true;
31 } 32 }
32 } 33 }
33 return false; 34 return false;
34 } 35 }
35 36
36 const gfx::Font* MenuModel::GetLabelFontAt(int index) const { 37 const gfx::Font* MenuModel::GetLabelFontAt(int index) const {
37 return NULL; 38 return NULL;
38 } 39 }
39 40
40 // Default implementation ignores the disposition. 41 // Default implementation ignores the disposition.
41 void MenuModel::ActivatedAtWithDisposition(int index, int disposition) { 42 void MenuModel::ActivatedAtWithDisposition(int index, int disposition) {
42 ActivatedAt(index); 43 ActivatedAt(index);
43 } 44 }
44 45
45 } // namespace ui 46 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698