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/translate_tab_helper.h"
8 #include "chrome/browser/translate/translate_ui_delegate.h"
9 #include "components/translate/core/browser/language_state.h"
11 TranslateBubbleModelImpl::TranslateBubbleModelImpl(
12 TranslateTabHelper::TranslateStep step
,
13 scoped_ptr
<TranslateUIDelegate
> ui_delegate
)
14 : ui_delegate_(ui_delegate
.Pass()),
15 view_state_transition_(TranslateStepToViewState(step
)) {}
17 TranslateBubbleModelImpl::~TranslateBubbleModelImpl() {
21 TranslateBubbleModel::ViewState
22 TranslateBubbleModelImpl::TranslateStepToViewState(
23 TranslateTabHelper::TranslateStep step
) {
25 case TranslateTabHelper::BEFORE_TRANSLATE
:
26 return TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE
;
27 case TranslateTabHelper::TRANSLATING
:
28 return TranslateBubbleModel::VIEW_STATE_TRANSLATING
;
29 case TranslateTabHelper::AFTER_TRANSLATE
:
30 return TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE
;
31 case TranslateTabHelper::TRANSLATE_ERROR
:
32 return TranslateBubbleModel::VIEW_STATE_ERROR
;
36 return TranslateBubbleModel::VIEW_STATE_ERROR
;
39 TranslateBubbleModel::ViewState
TranslateBubbleModelImpl::GetViewState() const {
40 return view_state_transition_
.view_state();
43 void TranslateBubbleModelImpl::SetViewState(
44 TranslateBubbleModel::ViewState view_state
) {
45 view_state_transition_
.SetViewState(view_state
);
48 void TranslateBubbleModelImpl::ShowError(TranslateErrors::Type error_type
) {
49 ui_delegate_
->OnErrorShown(error_type
);
52 void TranslateBubbleModelImpl::GoBackFromAdvanced() {
53 view_state_transition_
.GoBackFromAdvanced();
56 int TranslateBubbleModelImpl::GetNumberOfLanguages() const {
57 return ui_delegate_
->GetNumberOfLanguages();
60 base::string16
TranslateBubbleModelImpl::GetLanguageNameAt(int index
) const {
61 return ui_delegate_
->GetLanguageNameAt(index
);
64 int TranslateBubbleModelImpl::GetOriginalLanguageIndex() const {
65 return ui_delegate_
->GetOriginalLanguageIndex();
68 void TranslateBubbleModelImpl::UpdateOriginalLanguageIndex(int index
) {
69 ui_delegate_
->UpdateOriginalLanguageIndex(index
);
72 int TranslateBubbleModelImpl::GetTargetLanguageIndex() const {
73 return ui_delegate_
->GetTargetLanguageIndex();
76 void TranslateBubbleModelImpl::UpdateTargetLanguageIndex(int index
) {
77 ui_delegate_
->UpdateTargetLanguageIndex(index
);
80 void TranslateBubbleModelImpl::SetNeverTranslateLanguage(bool value
) {
81 ui_delegate_
->SetLanguageBlocked(value
);
84 void TranslateBubbleModelImpl::SetNeverTranslateSite(bool value
) {
85 ui_delegate_
->SetSiteBlacklist(value
);
88 bool TranslateBubbleModelImpl::ShouldAlwaysTranslate() const {
89 return ui_delegate_
->ShouldAlwaysTranslate();
92 void TranslateBubbleModelImpl::SetAlwaysTranslate(bool value
) {
93 ui_delegate_
->SetAlwaysTranslate(value
);
96 void TranslateBubbleModelImpl::Translate() {
97 ui_delegate_
->Translate();
100 void TranslateBubbleModelImpl::RevertTranslation() {
101 ui_delegate_
->RevertTranslation();
104 void TranslateBubbleModelImpl::TranslationDeclined(bool explicitly_closed
) {
105 ui_delegate_
->TranslationDeclined(explicitly_closed
);
108 bool TranslateBubbleModelImpl::IsPageTranslatedInCurrentLanguages() const {
109 content::WebContents
* web_contents
= ui_delegate_
->web_contents();
110 TranslateTabHelper
* translate_tab_helper
=
111 TranslateTabHelper::FromWebContents(web_contents
);
112 LanguageState
& language_state
= translate_tab_helper
->GetLanguageState();
113 return ui_delegate_
->GetOriginalLanguageCode() ==
114 language_state
.original_language() &&
115 ui_delegate_
->GetTargetLanguageCode() ==
116 language_state
.current_language();