Chromium Code Reviews| Index: chrome/browser/extensions/extension_menu_manager.cc |
| =================================================================== |
| --- chrome/browser/extensions/extension_menu_manager.cc (revision 114114) |
| +++ chrome/browser/extensions/extension_menu_manager.cc (working copy) |
| @@ -461,6 +461,58 @@ |
| } |
| } |
| +void ExtensionMenuManager::SanitizeRadioButtons() { |
|
Aaron Boodman
2011/12/15 00:53:55
You could pass in the extension ID to cut down on
|
| + MenuItemMap::iterator i; |
| + for (i = context_items_.begin(); i != context_items_.end(); ++i) { |
| + RecursiveSanitizeRadioButtons(i->second); |
| + } |
| +} |
| + |
| +void ExtensionMenuManager::RecursiveSanitizeRadioButtons( |
| + const ExtensionMenuItem::List& item_list) { |
| + ExtensionMenuItem::List::const_iterator i; |
| + |
| + i = item_list.begin(); |
| + while (i != item_list.end()) { |
| + if ((*i)->child_count() > 0) { |
| + RecursiveSanitizeRadioButtons((*i)->children()); |
| + } |
| + |
| + if ((*i)->type() == ExtensionMenuItem::RADIO) { |
| + ExtensionMenuItem::List::const_iterator radio_run_ittr; |
|
Aaron Boodman
2011/12/15 00:53:55
s/ittr/iter/g ?
Aaron Boodman
2011/12/15 00:53:55
Better to declare this right about the loop where
|
| + |
| + // If there are multiple items selected, the last one will override the |
| + // others. This is the default behavior when adding radio items via |
| + // chrome.contextMenus.create(). |
| + ExtensionMenuItem::List::const_iterator last_checked = item_list.end(); |
| + for (radio_run_ittr = i; radio_run_ittr != item_list.end(); |
| + ++radio_run_ittr) { |
| + if ((*radio_run_ittr)->type() != ExtensionMenuItem::RADIO) { |
| + break; |
| + } |
| + |
| + if ((*radio_run_ittr)->checked()) { |
| + last_checked = radio_run_ittr; |
| + } |
| + |
| + (*radio_run_ittr)->SetChecked(false); |
| + } |
| + |
| + // If check radio items were found in this run, |
| + // check the first radio item in the list (i). |
| + if (last_checked != item_list.end()) { |
| + (*last_checked)->SetChecked(true); |
| + } else { |
| + (*i)->SetChecked(true); |
| + } |
| + |
| + i = radio_run_ittr; |
| + } else { |
| + ++i; |
| + } |
| + } |
| +} |
| + |
| const SkBitmap& ExtensionMenuManager::GetIconForExtension( |
| const std::string& extension_id) { |
| return icon_manager_.GetIcon(extension_id); |