diff options
author | rhashimoto@chromium.org <rhashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-25 19:41:35 +0000 |
---|---|---|
committer | rhashimoto@chromium.org <rhashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-25 19:41:35 +0000 |
commit | 882e27ed5c8f54c2ac783594a07a78dbb9dc6c30 (patch) | |
tree | 098e4b94335b2ce6d7604d9421f3b33a8912a9f0 /ui | |
parent | 4e5ec62100ffdcda4790e660e853807fd8c2576d (diff) | |
download | chromium_src-882e27ed5c8f54c2ac783594a07a78dbb9dc6c30.zip chromium_src-882e27ed5c8f54c2ac783594a07a78dbb9dc6c30.tar.gz chromium_src-882e27ed5c8f54c2ac783594a07a78dbb9dc6c30.tar.bz2 |
Add MenuModelAdapter to wrap ui::MenuModel with views::MenuDelegate interface.
- added ViewsDelegate::GetDispositionForEvent() pure virtual
- added MenuModelAdapter
- added unit test for MenuModelAdapter
- added comment for MenuModel::GetFirstItemIndex() that callers may pass NULL for NativeMenu argument
- fixed index offset bug in MenuModel::GetModelAndIndexForCommandId()
- fixed spurious call to MenuDelegate::IsCommandEnabled()
BUG=none
TEST=included
Review URL: http://codereview.chromium.org/7067032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86677 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/base/models/menu_model.cc | 12 | ||||
-rw-r--r-- | ui/base/models/menu_model.h | 3 |
2 files changed, 9 insertions, 6 deletions
diff --git a/ui/base/models/menu_model.cc b/ui/base/models/menu_model.cc index c7defd9..1d90c36 100644 --- a/ui/base/models/menu_model.cc +++ b/ui/base/models/menu_model.cc @@ -16,17 +16,19 @@ bool MenuModel::IsVisibleAt(int index) const { bool MenuModel::GetModelAndIndexForCommandId(int command_id, MenuModel** model, int* index) { - int item_count = (*model)->GetItemCount(); + const int item_count = (*model)->GetItemCount(); + const int index_offset = (*model)->GetFirstItemIndex(NULL); for (int i = 0; i < item_count; ++i) { - if ((*model)->GetTypeAt(i) == TYPE_SUBMENU) { - MenuModel* submenu_model = (*model)->GetSubmenuModelAt(i); + const int candidate_index = i + index_offset; + if ((*model)->GetTypeAt(candidate_index) == TYPE_SUBMENU) { + MenuModel* submenu_model = (*model)->GetSubmenuModelAt(candidate_index); if (GetModelAndIndexForCommandId(command_id, &submenu_model, index)) { *model = submenu_model; return true; } } - if ((*model)->GetCommandIdAt(i) == command_id) { - *index = i; + if ((*model)->GetCommandIdAt(candidate_index) == command_id) { + *index = candidate_index; return true; } } diff --git a/ui/base/models/menu_model.h b/ui/base/models/menu_model.h index daca3da..a0c3627 100644 --- a/ui/base/models/menu_model.h +++ b/ui/base/models/menu_model.h @@ -44,7 +44,8 @@ class MenuModel { // Returns the index of the first item. This is 0 for most menus except the // system menu on Windows. |native_menu| is the menu to locate the start index - // within. It is guaranteed to be reset to a clean default state. + // within. It is guaranteed to be reset to a clean default state. Some + // callers of this method may pass NULL for native_menu. // IMPORTANT: If the model implementation returns something _other_ than 0 // here, it must offset the values for |index| it passes to the // methods below by this number - this is NOT done automatically! |