| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 TranslateBubbleView::~TranslateBubbleView() { | 70 TranslateBubbleView::~TranslateBubbleView() { |
| 71 // A child view could refer to a model which is owned by this class when | 71 // A child view could refer to a model which is owned by this class when |
| 72 // the child view is destructed. For example, |source_language_combobx_model_| | 72 // the child view is destructed. For example, |source_language_combobx_model_| |
| 73 // is referred by Combobox's destructor. Before destroying the models, | 73 // is referred by Combobox's destructor. Before destroying the models, |
| 74 // removing the child views is needed. | 74 // removing the child views is needed. |
| 75 RemoveAllChildViews(true); | 75 RemoveAllChildViews(true); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // static | 78 // static |
| 79 void TranslateBubbleView::ShowBubble( | 79 views::Widget* TranslateBubbleView::ShowBubble( |
| 80 views::View* anchor_view, | 80 views::View* anchor_view, |
| 81 content::WebContents* web_contents, | 81 content::WebContents* web_contents, |
| 82 translate::TranslateStep step, | 82 translate::TranslateStep step, |
| 83 translate::TranslateErrors::Type error_type, | 83 translate::TranslateErrors::Type error_type, |
| 84 DisplayReason reason) { | 84 DisplayReason reason) { |
| 85 if (translate_bubble_view_) { | 85 if (translate_bubble_view_) { |
| 86 // When the user reads the advanced setting panel, the bubble should not be | 86 // When the user reads the advanced setting panel, the bubble should not be |
| 87 // changed because they are focusing on the bubble. | 87 // changed because they are focusing on the bubble. |
| 88 if (translate_bubble_view_->web_contents() == web_contents && | 88 if (translate_bubble_view_->web_contents() == web_contents && |
| 89 translate_bubble_view_->model()->GetViewState() == | 89 translate_bubble_view_->model()->GetViewState() == |
| 90 TranslateBubbleModel::VIEW_STATE_ADVANCED) { | 90 TranslateBubbleModel::VIEW_STATE_ADVANCED) { |
| 91 return; | 91 return nullptr; |
| 92 } | 92 } |
| 93 if (step != translate::TRANSLATE_STEP_TRANSLATE_ERROR) { | 93 if (step != translate::TRANSLATE_STEP_TRANSLATE_ERROR) { |
| 94 TranslateBubbleModel::ViewState state = | 94 TranslateBubbleModel::ViewState state = |
| 95 TranslateBubbleModelImpl::TranslateStepToViewState(step); | 95 TranslateBubbleModelImpl::TranslateStepToViewState(step); |
| 96 translate_bubble_view_->SwitchView(state); | 96 translate_bubble_view_->SwitchView(state); |
| 97 } else { | 97 } else { |
| 98 translate_bubble_view_->SwitchToErrorView(error_type); | 98 translate_bubble_view_->SwitchToErrorView(error_type); |
| 99 } | 99 } |
| 100 return; | 100 return nullptr; |
| 101 } else { | 101 } else { |
| 102 if (step == translate::TRANSLATE_STEP_AFTER_TRANSLATE && | 102 if (step == translate::TRANSLATE_STEP_AFTER_TRANSLATE && |
| 103 reason == AUTOMATIC) { | 103 reason == AUTOMATIC) { |
| 104 return; | 104 return nullptr; |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 std::string source_language; | 108 std::string source_language; |
| 109 std::string target_language; | 109 std::string target_language; |
| 110 ChromeTranslateClient::GetTranslateLanguages( | 110 ChromeTranslateClient::GetTranslateLanguages( |
| 111 web_contents, &source_language, &target_language); | 111 web_contents, &source_language, &target_language); |
| 112 | 112 |
| 113 scoped_ptr<translate::TranslateUIDelegate> ui_delegate( | 113 scoped_ptr<translate::TranslateUIDelegate> ui_delegate( |
| 114 new translate::TranslateUIDelegate( | 114 new translate::TranslateUIDelegate( |
| 115 ChromeTranslateClient::GetManagerFromWebContents(web_contents) | 115 ChromeTranslateClient::GetManagerFromWebContents(web_contents) |
| 116 ->GetWeakPtr(), | 116 ->GetWeakPtr(), |
| 117 source_language, | 117 source_language, |
| 118 target_language)); | 118 target_language)); |
| 119 scoped_ptr<TranslateBubbleModel> model( | 119 scoped_ptr<TranslateBubbleModel> model( |
| 120 new TranslateBubbleModelImpl(step, std::move(ui_delegate))); | 120 new TranslateBubbleModelImpl(step, std::move(ui_delegate))); |
| 121 TranslateBubbleView* view = new TranslateBubbleView( | 121 TranslateBubbleView* view = new TranslateBubbleView( |
| 122 anchor_view, std::move(model), error_type, web_contents); | 122 anchor_view, std::move(model), error_type, web_contents); |
| 123 views::BubbleDelegateView::CreateBubble(view); | 123 views::Widget* bubble_widget = views::BubbleDelegateView::CreateBubble(view); |
| 124 view->ShowForReason(reason); | 124 view->ShowForReason(reason); |
| 125 return bubble_widget; |
| 125 } | 126 } |
| 126 | 127 |
| 127 // static | 128 // static |
| 128 void TranslateBubbleView::CloseBubble() { | 129 void TranslateBubbleView::CloseBubble() { |
| 129 if (!translate_bubble_view_) | 130 if (!translate_bubble_view_) |
| 130 return; | 131 return; |
| 131 | 132 |
| 132 translate_bubble_view_->GetWidget()->Close(); | 133 translate_bubble_view_->GetWidget()->Close(); |
| 133 } | 134 } |
| 134 | 135 |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 base::string16 label; | 756 base::string16 label; |
| 756 if (model_->IsPageTranslatedInCurrentLanguages()) | 757 if (model_->IsPageTranslatedInCurrentLanguages()) |
| 757 label = l10n_util::GetStringUTF16(IDS_DONE); | 758 label = l10n_util::GetStringUTF16(IDS_DONE); |
| 758 else | 759 else |
| 759 label = l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_ACCEPT); | 760 label = l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_ACCEPT); |
| 760 advanced_done_button_->SetText(label); | 761 advanced_done_button_->SetText(label); |
| 761 advanced_done_button_->SizeToPreferredSize(); | 762 advanced_done_button_->SizeToPreferredSize(); |
| 762 if (advanced_view_) | 763 if (advanced_view_) |
| 763 advanced_view_->Layout(); | 764 advanced_view_->Layout(); |
| 764 } | 765 } |
| OLD | NEW |