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

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: Implemented reviewer recommendations. 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
« no previous file with comments | « ui/base/models/menu_model.h ('k') | views/controls/menu/menu_item_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 const int index_offset = (*model)->GetFirstItemIndex(NULL);
20 for (int i = 0; i < item_count; ++i) { 21 for (int i = 0; i < item_count; ++i) {
21 if ((*model)->GetTypeAt(i) == TYPE_SUBMENU) { 22 const int candidate_index = i + index_offset;
22 MenuModel* submenu_model = (*model)->GetSubmenuModelAt(i); 23 if ((*model)->GetTypeAt(candidate_index) == TYPE_SUBMENU) {
24 MenuModel* submenu_model = (*model)->GetSubmenuModelAt(candidate_index);
23 if (GetModelAndIndexForCommandId(command_id, &submenu_model, index)) { 25 if (GetModelAndIndexForCommandId(command_id, &submenu_model, index)) {
24 *model = submenu_model; 26 *model = submenu_model;
25 return true; 27 return true;
26 } 28 }
27 } 29 }
28 if ((*model)->GetCommandIdAt(i) == command_id) { 30 if ((*model)->GetCommandIdAt(candidate_index) == command_id) {
29 *index = i; 31 *index = candidate_index;
30 return true; 32 return true;
31 } 33 }
32 } 34 }
33 return false; 35 return false;
34 } 36 }
35 37
36 const gfx::Font* MenuModel::GetLabelFontAt(int index) const { 38 const gfx::Font* MenuModel::GetLabelFontAt(int index) const {
37 return NULL; 39 return NULL;
38 } 40 }
39 41
40 // Default implementation ignores the disposition. 42 // Default implementation ignores the disposition.
41 void MenuModel::ActivatedAtWithDisposition(int index, int disposition) { 43 void MenuModel::ActivatedAtWithDisposition(int index, int disposition) {
42 ActivatedAt(index); 44 ActivatedAt(index);
43 } 45 }
44 46
45 } // namespace ui 47 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/models/menu_model.h ('k') | views/controls/menu/menu_item_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698