blob: 20417d00be73cf6c6e82b6de1f498cc1ccbb9733 (
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
// Copyright 2013 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/ui/translate/translate_bubble_model_impl.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "components/translate/core/browser/language_state.h"
#include "components/translate/core/browser/translate_ui_delegate.h"
TranslateBubbleModelImpl::TranslateBubbleModelImpl(
translate::TranslateStep step,
scoped_ptr<translate::TranslateUIDelegate> ui_delegate)
: ui_delegate_(ui_delegate.Pass()),
view_state_transition_(TranslateStepToViewState(step)) {
}
TranslateBubbleModelImpl::~TranslateBubbleModelImpl() {
}
// static
TranslateBubbleModel::ViewState
TranslateBubbleModelImpl::TranslateStepToViewState(
translate::TranslateStep step) {
switch (step) {
case translate::TRANSLATE_STEP_BEFORE_TRANSLATE:
return TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE;
case translate::TRANSLATE_STEP_TRANSLATING:
return TranslateBubbleModel::VIEW_STATE_TRANSLATING;
case translate::TRANSLATE_STEP_AFTER_TRANSLATE:
return TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE;
case translate::TRANSLATE_STEP_TRANSLATE_ERROR:
return TranslateBubbleModel::VIEW_STATE_ERROR;
}
NOTREACHED();
return TranslateBubbleModel::VIEW_STATE_ERROR;
}
TranslateBubbleModel::ViewState TranslateBubbleModelImpl::GetViewState() const {
return view_state_transition_.view_state();
}
void TranslateBubbleModelImpl::SetViewState(
TranslateBubbleModel::ViewState view_state) {
view_state_transition_.SetViewState(view_state);
}
void TranslateBubbleModelImpl::ShowError(
translate::TranslateErrors::Type error_type) {
ui_delegate_->OnErrorShown(error_type);
}
void TranslateBubbleModelImpl::GoBackFromAdvanced() {
view_state_transition_.GoBackFromAdvanced();
}
int TranslateBubbleModelImpl::GetNumberOfLanguages() const {
return ui_delegate_->GetNumberOfLanguages();
}
base::string16 TranslateBubbleModelImpl::GetLanguageNameAt(int index) const {
return ui_delegate_->GetLanguageNameAt(index);
}
int TranslateBubbleModelImpl::GetOriginalLanguageIndex() const {
return ui_delegate_->GetOriginalLanguageIndex();
}
void TranslateBubbleModelImpl::UpdateOriginalLanguageIndex(int index) {
ui_delegate_->UpdateOriginalLanguageIndex(index);
}
int TranslateBubbleModelImpl::GetTargetLanguageIndex() const {
return ui_delegate_->GetTargetLanguageIndex();
}
void TranslateBubbleModelImpl::UpdateTargetLanguageIndex(int index) {
ui_delegate_->UpdateTargetLanguageIndex(index);
}
void TranslateBubbleModelImpl::SetNeverTranslateLanguage(bool value) {
ui_delegate_->SetLanguageBlocked(value);
}
void TranslateBubbleModelImpl::SetNeverTranslateSite(bool value) {
ui_delegate_->SetSiteBlacklist(value);
}
bool TranslateBubbleModelImpl::ShouldAlwaysTranslate() const {
return ui_delegate_->ShouldAlwaysTranslate();
}
void TranslateBubbleModelImpl::SetAlwaysTranslate(bool value) {
ui_delegate_->SetAlwaysTranslate(value);
}
void TranslateBubbleModelImpl::Translate() {
ui_delegate_->Translate();
}
void TranslateBubbleModelImpl::RevertTranslation() {
ui_delegate_->RevertTranslation();
}
void TranslateBubbleModelImpl::TranslationDeclined(bool explicitly_closed) {
ui_delegate_->TranslationDeclined(explicitly_closed);
}
bool TranslateBubbleModelImpl::IsPageTranslatedInCurrentLanguages() const {
const translate::LanguageState& language_state =
ui_delegate_->GetLanguageState();
return ui_delegate_->GetOriginalLanguageCode() ==
language_state.original_language() &&
ui_delegate_->GetTargetLanguageCode() ==
language_state.current_language();
}
|