summaryrefslogtreecommitdiffstats
path: root/chrome/browser/translate/languages_menu_model.cc
blob: 93bd100c0fbca5abf07fd745d2dc5ba4503597cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/translate/languages_menu_model.h"

#include "base/histogram.h"
#include "chrome/browser/translate/translate_infobar_delegate.h"

LanguagesMenuModel::LanguagesMenuModel(
    TranslateInfoBarDelegate* translate_delegate,
    LanguageType language_type)
    : ALLOW_THIS_IN_INITIALIZER_LIST(menus::SimpleMenuModel(this)),
      translate_infobar_delegate_(translate_delegate),
      language_type_(language_type) {
  for (int i = 0; i < translate_delegate->GetLanguageCount(); ++i)
    AddCheckItem(i, translate_delegate->GetLanguageDisplayableNameAt(i));
}

LanguagesMenuModel::~LanguagesMenuModel() {
}

bool LanguagesMenuModel::IsCommandIdChecked(int command_id) const {
  if (language_type_ == ORIGINAL)
    return command_id == translate_infobar_delegate_->original_language_index();
  return command_id == translate_infobar_delegate_->target_language_index();
}

bool LanguagesMenuModel::IsCommandIdEnabled(int command_id) const {
  // Prevent from having the same language selectable in original and target.
  if (language_type_ == ORIGINAL)
    return command_id != translate_infobar_delegate_->target_language_index();
  return command_id != translate_infobar_delegate_->original_language_index();
}

bool LanguagesMenuModel::GetAcceleratorForCommandId(
    int command_id, menus::Accelerator* accelerator) {
  return false;
}

void LanguagesMenuModel::ExecuteCommand(int command_id) {
  if (language_type_ == ORIGINAL) {
    UMA_HISTOGRAM_COUNTS("Translate.ModifyOriginalLang", 1);
    translate_infobar_delegate_->SetOriginalLanguage(command_id);
    return;
  }
  UMA_HISTOGRAM_COUNTS("Translate.ModifyTargetLang", 1);
  translate_infobar_delegate_->SetTargetLanguage(command_id);
}