Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / translate / translate_bubble_model_impl.cc
blob20417d00be73cf6c6e82b6de1f498cc1ccbb9733
1 // Copyright 2013 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.
5 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h"
7 #include "chrome/browser/translate/chrome_translate_client.h"
8 #include "components/translate/core/browser/language_state.h"
9 #include "components/translate/core/browser/translate_ui_delegate.h"
11 TranslateBubbleModelImpl::TranslateBubbleModelImpl(
12 translate::TranslateStep step,
13 scoped_ptr<translate::TranslateUIDelegate> ui_delegate)
14 : ui_delegate_(ui_delegate.Pass()),
15 view_state_transition_(TranslateStepToViewState(step)) {
18 TranslateBubbleModelImpl::~TranslateBubbleModelImpl() {
21 // static
22 TranslateBubbleModel::ViewState
23 TranslateBubbleModelImpl::TranslateStepToViewState(
24 translate::TranslateStep step) {
25 switch (step) {
26 case translate::TRANSLATE_STEP_BEFORE_TRANSLATE:
27 return TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE;
28 case translate::TRANSLATE_STEP_TRANSLATING:
29 return TranslateBubbleModel::VIEW_STATE_TRANSLATING;
30 case translate::TRANSLATE_STEP_AFTER_TRANSLATE:
31 return TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE;
32 case translate::TRANSLATE_STEP_TRANSLATE_ERROR:
33 return TranslateBubbleModel::VIEW_STATE_ERROR;
36 NOTREACHED();
37 return TranslateBubbleModel::VIEW_STATE_ERROR;
40 TranslateBubbleModel::ViewState TranslateBubbleModelImpl::GetViewState() const {
41 return view_state_transition_.view_state();
44 void TranslateBubbleModelImpl::SetViewState(
45 TranslateBubbleModel::ViewState view_state) {
46 view_state_transition_.SetViewState(view_state);
49 void TranslateBubbleModelImpl::ShowError(
50 translate::TranslateErrors::Type error_type) {
51 ui_delegate_->OnErrorShown(error_type);
54 void TranslateBubbleModelImpl::GoBackFromAdvanced() {
55 view_state_transition_.GoBackFromAdvanced();
58 int TranslateBubbleModelImpl::GetNumberOfLanguages() const {
59 return ui_delegate_->GetNumberOfLanguages();
62 base::string16 TranslateBubbleModelImpl::GetLanguageNameAt(int index) const {
63 return ui_delegate_->GetLanguageNameAt(index);
66 int TranslateBubbleModelImpl::GetOriginalLanguageIndex() const {
67 return ui_delegate_->GetOriginalLanguageIndex();
70 void TranslateBubbleModelImpl::UpdateOriginalLanguageIndex(int index) {
71 ui_delegate_->UpdateOriginalLanguageIndex(index);
74 int TranslateBubbleModelImpl::GetTargetLanguageIndex() const {
75 return ui_delegate_->GetTargetLanguageIndex();
78 void TranslateBubbleModelImpl::UpdateTargetLanguageIndex(int index) {
79 ui_delegate_->UpdateTargetLanguageIndex(index);
82 void TranslateBubbleModelImpl::SetNeverTranslateLanguage(bool value) {
83 ui_delegate_->SetLanguageBlocked(value);
86 void TranslateBubbleModelImpl::SetNeverTranslateSite(bool value) {
87 ui_delegate_->SetSiteBlacklist(value);
90 bool TranslateBubbleModelImpl::ShouldAlwaysTranslate() const {
91 return ui_delegate_->ShouldAlwaysTranslate();
94 void TranslateBubbleModelImpl::SetAlwaysTranslate(bool value) {
95 ui_delegate_->SetAlwaysTranslate(value);
98 void TranslateBubbleModelImpl::Translate() {
99 ui_delegate_->Translate();
102 void TranslateBubbleModelImpl::RevertTranslation() {
103 ui_delegate_->RevertTranslation();
106 void TranslateBubbleModelImpl::TranslationDeclined(bool explicitly_closed) {
107 ui_delegate_->TranslationDeclined(explicitly_closed);
110 bool TranslateBubbleModelImpl::IsPageTranslatedInCurrentLanguages() const {
111 const translate::LanguageState& language_state =
112 ui_delegate_->GetLanguageState();
113 return ui_delegate_->GetOriginalLanguageCode() ==
114 language_state.original_language() &&
115 ui_delegate_->GetTargetLanguageCode() ==
116 language_state.current_language();