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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/translate/languages_menu_model.h" 6 7 #include "base/metrics/histogram.h" 8 #include "chrome/browser/translate/translate_infobar_delegate.h" 9 10 LanguagesMenuModel::LanguagesMenuModel( 11 TranslateInfoBarDelegate* translate_delegate, 12 LanguageType language_type) 13 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), 14 translate_infobar_delegate_(translate_delegate), 15 language_type_(language_type) { 16 for (size_t i = 0; i < translate_delegate->GetLanguageCount(); ++i) { 17 AddCheckItem(static_cast<int>(i), 18 translate_delegate->GetLanguageDisplayableNameAt(i)); 19 } 20 } 21 22 LanguagesMenuModel::~LanguagesMenuModel() { 23 } 24 25 bool LanguagesMenuModel::IsCommandIdChecked(int command_id) const { 26 return static_cast<size_t>(command_id) == ((language_type_ == ORIGINAL) ? 27 translate_infobar_delegate_->original_language_index() : 28 translate_infobar_delegate_->target_language_index()); 29 } 30 31 bool LanguagesMenuModel::IsCommandIdEnabled(int command_id) const { 32 // Prevent the same language from being selectable in original and target. 33 return static_cast<size_t>(command_id) != ((language_type_ == ORIGINAL) ? 34 translate_infobar_delegate_->target_language_index() : 35 translate_infobar_delegate_->original_language_index()); 36 } 37 38 bool LanguagesMenuModel::GetAcceleratorForCommandId( 39 int command_id, 40 ui::Accelerator* accelerator) { 41 return false; 42 } 43 44 void LanguagesMenuModel::ExecuteCommand(int command_id) { 45 size_t command_id_size_t = static_cast<size_t>(command_id); 46 if (language_type_ == ORIGINAL) { 47 UMA_HISTOGRAM_COUNTS("Translate.ModifyOriginalLang", 1); 48 translate_infobar_delegate_->SetOriginalLanguage(command_id_size_t); 49 return; 50 } 51 UMA_HISTOGRAM_COUNTS("Translate.ModifyTargetLang", 1); 52 translate_infobar_delegate_->SetTargetLanguage(command_id_size_t); 53 } 54