| 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/views/translate/translate_bubble_view.h" | 5 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 is_in_incognito_window, | 153 is_in_incognito_window, |
| 154 browser); | 154 browser); |
| 155 views::BubbleDelegateView::CreateBubble(view)->Show(); | 155 views::BubbleDelegateView::CreateBubble(view)->Show(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 // static | 158 // static |
| 159 bool TranslateBubbleView::IsShowing() { | 159 bool TranslateBubbleView::IsShowing() { |
| 160 return translate_bubble_view_ != NULL; | 160 return translate_bubble_view_ != NULL; |
| 161 } | 161 } |
| 162 | 162 |
| 163 // static |
| 164 TranslateBubbleView* TranslateBubbleView::GetCurrentBubble() { |
| 165 return translate_bubble_view_; |
| 166 } |
| 167 |
| 163 void TranslateBubbleView::Init() { | 168 void TranslateBubbleView::Init() { |
| 164 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, | 169 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, |
| 165 0, 0, 0)); | 170 0, 0, 0)); |
| 166 | 171 |
| 167 before_translate_view_ = CreateViewBeforeTranslate(); | 172 before_translate_view_ = CreateViewBeforeTranslate(); |
| 168 translating_view_ = CreateViewTranslating(); | 173 translating_view_ = CreateViewTranslating(); |
| 169 after_translate_view_ = CreateViewAfterTranslate(); | 174 after_translate_view_ = CreateViewAfterTranslate(); |
| 170 error_view_ = CreateViewError(); | 175 error_view_ = CreateViewError(); |
| 171 advanced_view_ = CreateViewAdvanced(); | 176 advanced_view_ = CreateViewAdvanced(); |
| 172 | 177 |
| 173 AddChildView(before_translate_view_); | 178 AddChildView(before_translate_view_); |
| 174 AddChildView(translating_view_); | 179 AddChildView(translating_view_); |
| 175 AddChildView(after_translate_view_); | 180 AddChildView(after_translate_view_); |
| 176 AddChildView(error_view_); | 181 AddChildView(error_view_); |
| 177 AddChildView(advanced_view_); | 182 AddChildView(advanced_view_); |
| 178 | 183 |
| 179 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | 184 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
| 180 | 185 |
| 181 UpdateChildVisibilities(); | 186 UpdateChildVisibilities(); |
| 182 } | 187 } |
| 183 | 188 |
| 184 void TranslateBubbleView::ButtonPressed(views::Button* sender, | 189 void TranslateBubbleView::ButtonPressed(views::Button* sender, |
| 185 const ui::Event& event) { | 190 const ui::Event& event) { |
| 186 HandleButtonPressed(static_cast<ButtonID>(sender->id())); | 191 HandleButtonPressed(static_cast<ButtonID>(sender->id())); |
| 187 } | 192 } |
| 188 | 193 |
| 189 void TranslateBubbleView::WindowClosing() { | 194 void TranslateBubbleView::WindowClosing() { |
| 190 if (!translate_executed_) | 195 if (!translate_executed_ && |
| 196 (browser_ == NULL || !browser_->IsAttemptingToCloseBrowser())) { |
| 191 model_->TranslationDeclined(); | 197 model_->TranslationDeclined(); |
| 198 } |
| 192 | 199 |
| 193 // We have to reset |translate_bubble_view_| here, not in our destructor, | 200 // We have to reset |translate_bubble_view_| here, not in our destructor, |
| 194 // because we'll be destroyed asynchronously and the shown state will be | 201 // because we'll be destroyed asynchronously and the shown state will be |
| 195 // checked before then. | 202 // checked before then. |
| 196 DCHECK_EQ(translate_bubble_view_, this); | 203 DCHECK_EQ(translate_bubble_view_, this); |
| 197 translate_bubble_view_ = NULL; | 204 translate_bubble_view_ = NULL; |
| 198 } | 205 } |
| 199 | 206 |
| 200 bool TranslateBubbleView::AcceleratorPressed( | 207 bool TranslateBubbleView::AcceleratorPressed( |
| 201 const ui::Accelerator& accelerator) { | 208 const ui::Accelerator& accelerator) { |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 l10n_util::GetStringFUTF16(IDS_TRANSLATE_BUBBLE_ALWAYS, | 751 l10n_util::GetStringFUTF16(IDS_TRANSLATE_BUBBLE_ALWAYS, |
| 745 source_language_name, | 752 source_language_name, |
| 746 target_language_name); | 753 target_language_name); |
| 747 // "Always translate" checkbox doesn't exist in an incognito window. | 754 // "Always translate" checkbox doesn't exist in an incognito window. |
| 748 if (always_translate_checkbox_) { | 755 if (always_translate_checkbox_) { |
| 749 always_translate_checkbox_->SetText(message); | 756 always_translate_checkbox_->SetText(message); |
| 750 always_translate_checkbox_->SetChecked( | 757 always_translate_checkbox_->SetChecked( |
| 751 model_->ShouldAlwaysTranslate()); | 758 model_->ShouldAlwaysTranslate()); |
| 752 } | 759 } |
| 753 } | 760 } |
| OLD | NEW |