| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" | 5 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "chrome/browser/translate/chrome_translate_client.h" | 9 #include "chrome/browser/translate/chrome_translate_client.h" |
| 10 #include "components/translate/core/browser/language_state.h" | 10 #include "components/translate/core/browser/language_state.h" |
| 11 #include "components/translate/core/browser/translate_ui_delegate.h" | 11 #include "components/translate/core/browser/translate_ui_delegate.h" |
| 12 | 12 |
| 13 TranslateBubbleModelImpl::TranslateBubbleModelImpl( | 13 TranslateBubbleModelImpl::TranslateBubbleModelImpl( |
| 14 translate::TranslateStep step, | 14 translate::TranslateStep step, |
| 15 std::unique_ptr<translate::TranslateUIDelegate> ui_delegate) | 15 std::unique_ptr<translate::TranslateUIDelegate> ui_delegate) |
| 16 : ui_delegate_(std::move(ui_delegate)), | 16 : ui_delegate_(std::move(ui_delegate)), |
| 17 view_state_transition_(TranslateStepToViewState(step)), | 17 view_state_transition_(TranslateStepToViewState(step)), |
| 18 translation_declined_(false), | 18 translation_declined_(false), |
| 19 translate_executed_(false) { | 19 translate_executed_(false) { |
| 20 if (GetViewState() != TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE) | 20 if (GetViewState() != TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE) |
| 21 translate_executed_ = true; | 21 translate_executed_ = true; |
| 22 } | 22 } |
| 23 | 23 |
| 24 TranslateBubbleModelImpl::~TranslateBubbleModelImpl() { | 24 TranslateBubbleModelImpl::~TranslateBubbleModelImpl() {} |
| 25 } | |
| 26 | 25 |
| 27 // static | 26 // static |
| 28 TranslateBubbleModel::ViewState | 27 TranslateBubbleModel::ViewState |
| 29 TranslateBubbleModelImpl::TranslateStepToViewState( | 28 TranslateBubbleModelImpl::TranslateStepToViewState( |
| 30 translate::TranslateStep step) { | 29 translate::TranslateStep step) { |
| 31 switch (step) { | 30 switch (step) { |
| 32 case translate::TRANSLATE_STEP_BEFORE_TRANSLATE: | 31 case translate::TRANSLATE_STEP_BEFORE_TRANSLATE: |
| 33 return TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE; | 32 return TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE; |
| 34 case translate::TRANSLATE_STEP_TRANSLATING: | 33 case translate::TRANSLATE_STEP_TRANSLATING: |
| 35 return TranslateBubbleModel::VIEW_STATE_TRANSLATING; | 34 return TranslateBubbleModel::VIEW_STATE_TRANSLATING; |
| 36 case translate::TRANSLATE_STEP_AFTER_TRANSLATE: | 35 case translate::TRANSLATE_STEP_AFTER_TRANSLATE: |
| 37 return TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE; | 36 return TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE; |
| 38 case translate::TRANSLATE_STEP_TRANSLATE_ERROR: | 37 case translate::TRANSLATE_STEP_TRANSLATE_ERROR: |
| 39 return TranslateBubbleModel::VIEW_STATE_ERROR; | 38 return TranslateBubbleModel::VIEW_STATE_ERROR; |
| 40 } | 39 } |
| 41 | 40 |
| 42 NOTREACHED(); | 41 NOTREACHED(); |
| 43 return TranslateBubbleModel::VIEW_STATE_ERROR; | 42 return TranslateBubbleModel::VIEW_STATE_ERROR; |
| 44 } | 43 } |
| 45 | 44 |
| 46 TranslateBubbleModel::ViewState TranslateBubbleModelImpl::GetViewState() const { | 45 TranslateBubbleModel::ViewState TranslateBubbleModelImpl::GetViewState() const { |
| 47 return view_state_transition_.view_state(); | 46 return view_state_transition_.view_state(); |
| 48 } | 47 } |
| 49 | 48 |
| 49 bool TranslateBubbleModelImpl::ShouldAlwaysTranslateBeCheckedByDefault() const { |
| 50 return ui_delegate_->ShouldAlwaysTranslateBeCheckedByDefault(); |
| 51 } |
| 52 |
| 50 void TranslateBubbleModelImpl::SetViewState( | 53 void TranslateBubbleModelImpl::SetViewState( |
| 51 TranslateBubbleModel::ViewState view_state) { | 54 TranslateBubbleModel::ViewState view_state) { |
| 52 view_state_transition_.SetViewState(view_state); | 55 view_state_transition_.SetViewState(view_state); |
| 53 } | 56 } |
| 54 | 57 |
| 55 void TranslateBubbleModelImpl::ShowError( | 58 void TranslateBubbleModelImpl::ShowError( |
| 56 translate::TranslateErrors::Type error_type) { | 59 translate::TranslateErrors::Type error_type) { |
| 57 ui_delegate_->OnErrorShown(error_type); | 60 ui_delegate_->OnErrorShown(error_type); |
| 58 } | 61 } |
| 59 | 62 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 119 |
| 117 void TranslateBubbleModelImpl::OnBubbleClosing() { | 120 void TranslateBubbleModelImpl::OnBubbleClosing() { |
| 118 if (!translate_executed_) | 121 if (!translate_executed_) |
| 119 ui_delegate_->TranslationDeclined(translation_declined_); | 122 ui_delegate_->TranslationDeclined(translation_declined_); |
| 120 } | 123 } |
| 121 | 124 |
| 122 bool TranslateBubbleModelImpl::IsPageTranslatedInCurrentLanguages() const { | 125 bool TranslateBubbleModelImpl::IsPageTranslatedInCurrentLanguages() const { |
| 123 const translate::LanguageState& language_state = | 126 const translate::LanguageState& language_state = |
| 124 ui_delegate_->GetLanguageState(); | 127 ui_delegate_->GetLanguageState(); |
| 125 return ui_delegate_->GetOriginalLanguageCode() == | 128 return ui_delegate_->GetOriginalLanguageCode() == |
| 126 language_state.original_language() && | 129 language_state.original_language() && |
| 127 ui_delegate_->GetTargetLanguageCode() == | 130 ui_delegate_->GetTargetLanguageCode() == |
| 128 language_state.current_language(); | 131 language_state.current_language(); |
| 129 } | 132 } |
| OLD | NEW |