OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gtk/infobars/translate_infobar_base_gtk.h" | 5 #include "chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/translate/options_menu_model.h" | 8 #include "chrome/browser/translate/options_menu_model.h" |
9 #include "chrome/browser/translate/translate_infobar_delegate.h" | 9 #include "chrome/browser/translate/translate_infobar_delegate.h" |
10 #include "chrome/browser/ui/gtk/gtk_util.h" | 10 #include "chrome/browser/ui/gtk/gtk_util.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 TranslateInfoBarBase::~TranslateInfoBarBase() { | 57 TranslateInfoBarBase::~TranslateInfoBarBase() { |
58 } | 58 } |
59 | 59 |
60 void TranslateInfoBarBase::Init() { | 60 void TranslateInfoBarBase::Init() { |
61 if (!ShowOptionsMenuButton()) | 61 if (!ShowOptionsMenuButton()) |
62 return; | 62 return; |
63 | 63 |
64 // The options button sits outside the translate_box so that it can be end | 64 // The options button sits outside the translate_box so that it can be end |
65 // packed in hbox_. | 65 // packed in hbox_. |
66 GtkWidget* options_menu_button = BuildOptionsMenuButton(); | 66 GtkWidget* options_menu_button = CreateMenuButton( |
| 67 l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_OPTIONS)); |
67 Signals()->Connect(options_menu_button, "clicked", | 68 Signals()->Connect(options_menu_button, "clicked", |
68 G_CALLBACK(&OnOptionsClickedThunk), this); | 69 G_CALLBACK(&OnOptionsClickedThunk), this); |
69 gtk_widget_show_all(options_menu_button); | 70 gtk_widget_show_all(options_menu_button); |
70 gtk_util::CenterWidgetInHBox(hbox_, options_menu_button, true, 0); | 71 gtk_util::CenterWidgetInHBox(hbox_, options_menu_button, true, 0); |
71 } | 72 } |
72 | 73 |
73 void TranslateInfoBarBase::GetTopColor(InfoBarDelegate::Type type, | 74 void TranslateInfoBarBase::GetTopColor(InfoBarDelegate::Type type, |
74 double* r, double* g, double* b) { | 75 double* r, double* g, double* b) { |
75 if (background_error_percent_ <= 0) { | 76 if (background_error_percent_ <= 0) { |
76 InfoBarGtk::GetTopColor(InfoBarDelegate::PAGE_ACTION_TYPE, r, g, b); | 77 InfoBarGtk::GetTopColor(InfoBarDelegate::PAGE_ACTION_TYPE, r, g, b); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 gtk_tree_model_get(gtk_combo_box_get_model(combo), &iter, | 182 gtk_tree_model_get(gtk_combo_box_get_model(combo), &iter, |
182 LANGUAGE_COMBO_COLUMN_ID, &id, | 183 LANGUAGE_COMBO_COLUMN_ID, &id, |
183 -1); | 184 -1); |
184 return static_cast<size_t>(id); | 185 return static_cast<size_t>(id); |
185 } | 186 } |
186 | 187 |
187 TranslateInfoBarDelegate* TranslateInfoBarBase::GetDelegate() { | 188 TranslateInfoBarDelegate* TranslateInfoBarBase::GetDelegate() { |
188 return static_cast<TranslateInfoBarDelegate*>(delegate()); | 189 return static_cast<TranslateInfoBarDelegate*>(delegate()); |
189 } | 190 } |
190 | 191 |
191 // static | |
192 GtkWidget* TranslateInfoBarBase::BuildOptionsMenuButton() { | |
193 GtkWidget* button = gtk_button_new(); | |
194 GtkWidget* former_child = gtk_bin_get_child(GTK_BIN(button)); | |
195 if (former_child) | |
196 gtk_container_remove(GTK_CONTAINER(button), former_child); | |
197 | |
198 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); | |
199 | |
200 GtkWidget* label = gtk_label_new( | |
201 l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_OPTIONS).c_str()); | |
202 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
203 | |
204 GtkWidget* arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE); | |
205 gtk_box_pack_start(GTK_BOX(hbox), arrow, FALSE, FALSE, 0); | |
206 | |
207 gtk_container_add(GTK_CONTAINER(button), hbox); | |
208 | |
209 return button; | |
210 } | |
211 | |
212 void TranslateInfoBarBase::OnOptionsClicked(GtkWidget* sender) { | 192 void TranslateInfoBarBase::OnOptionsClicked(GtkWidget* sender) { |
213 ShowMenuWithModel(sender, NULL, new OptionsMenuModel(GetDelegate())); | 193 ShowMenuWithModel(sender, NULL, new OptionsMenuModel(GetDelegate())); |
214 } | 194 } |
215 | 195 |
216 // TranslateInfoBarDelegate specific method: | 196 // TranslateInfoBarDelegate specific method: |
217 InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { | 197 InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { |
218 TranslateInfoBarBase* infobar = NULL; | 198 TranslateInfoBarBase* infobar = NULL; |
219 switch (type_) { | 199 switch (type_) { |
220 case BEFORE_TRANSLATE: | 200 case BEFORE_TRANSLATE: |
221 infobar = new BeforeTranslateInfoBar(owner, this); | 201 infobar = new BeforeTranslateInfoBar(owner, this); |
222 break; | 202 break; |
223 case AFTER_TRANSLATE: | 203 case AFTER_TRANSLATE: |
224 infobar = new AfterTranslateInfoBar(owner, this); | 204 infobar = new AfterTranslateInfoBar(owner, this); |
225 break; | 205 break; |
226 case TRANSLATING: | 206 case TRANSLATING: |
227 case TRANSLATION_ERROR: | 207 case TRANSLATION_ERROR: |
228 infobar = new TranslateMessageInfoBar(owner, this); | 208 infobar = new TranslateMessageInfoBar(owner, this); |
229 break; | 209 break; |
230 default: | 210 default: |
231 NOTREACHED(); | 211 NOTREACHED(); |
232 } | 212 } |
233 infobar->Init(); | 213 infobar->Init(); |
234 return infobar; | 214 return infobar; |
235 } | 215 } |
OLD | NEW |