OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 background_color_animation_->Hide(); | 51 background_color_animation_->Hide(); |
52 } | 52 } |
53 } else { | 53 } else { |
54 background_error_percent_ = delegate->IsError() ? 1 : 0; | 54 background_error_percent_ = delegate->IsError() ? 1 : 0; |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 TranslateInfoBarBase::~TranslateInfoBarBase() { | 58 TranslateInfoBarBase::~TranslateInfoBarBase() { |
59 } | 59 } |
60 | 60 |
61 void TranslateInfoBarBase::Init() { | |
62 if (!ShowOptionsMenuButton()) | |
63 return; | |
64 | |
65 // The options button sits outside the translate_box so that it can be end | |
66 // packed in hbox_. | |
67 GtkWidget* options_menu_button = CreateMenuButton( | |
68 l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_OPTIONS)); | |
69 Signals()->Connect(options_menu_button, "clicked", | |
70 G_CALLBACK(&OnOptionsClickedThunk), this); | |
71 gtk_widget_show_all(options_menu_button); | |
72 gtk_util::CenterWidgetInHBox(hbox_, options_menu_button, true, 0); | |
73 } | |
74 | |
75 void TranslateInfoBarBase::GetTopColor(InfoBarDelegate::Type type, | 61 void TranslateInfoBarBase::GetTopColor(InfoBarDelegate::Type type, |
76 double* r, double* g, double* b) { | 62 double* r, double* g, double* b) { |
77 if (background_error_percent_ <= 0) { | 63 if (background_error_percent_ <= 0) { |
78 InfoBarGtk::GetTopColor(InfoBarDelegate::PAGE_ACTION_TYPE, r, g, b); | 64 InfoBarGtk::GetTopColor(InfoBarDelegate::PAGE_ACTION_TYPE, r, g, b); |
79 } else if (background_error_percent_ >= 1) { | 65 } else if (background_error_percent_ >= 1) { |
80 InfoBarGtk::GetTopColor(InfoBarDelegate::WARNING_TYPE, r, g, b); | 66 InfoBarGtk::GetTopColor(InfoBarDelegate::WARNING_TYPE, r, g, b); |
81 } else { | 67 } else { |
82 double normal_r, normal_g, normal_b; | 68 double normal_r, normal_g, normal_b; |
83 InfoBarGtk::GetTopColor(InfoBarDelegate::PAGE_ACTION_TYPE, | 69 InfoBarGtk::GetTopColor(InfoBarDelegate::PAGE_ACTION_TYPE, |
84 &normal_r, &normal_g, &normal_b); | 70 &normal_r, &normal_g, &normal_b); |
(...skipping 30 matching lines...) Expand all Loading... |
115 double offset_r = error_r - normal_r; | 101 double offset_r = error_r - normal_r; |
116 double offset_g = error_g - normal_g; | 102 double offset_g = error_g - normal_g; |
117 double offset_b = error_b - normal_b; | 103 double offset_b = error_b - normal_b; |
118 | 104 |
119 *r = normal_r + (background_error_percent_ * offset_r); | 105 *r = normal_r + (background_error_percent_ * offset_r); |
120 *g = normal_g + (background_error_percent_ * offset_g); | 106 *g = normal_g + (background_error_percent_ * offset_g); |
121 *b = normal_b + (background_error_percent_ * offset_b); | 107 *b = normal_b + (background_error_percent_ * offset_b); |
122 } | 108 } |
123 } | 109 } |
124 | 110 |
| 111 void TranslateInfoBarBase::InitWidgets() { |
| 112 InfoBarGtk::InitWidgets(); |
| 113 |
| 114 if (!ShowOptionsMenuButton()) |
| 115 return; |
| 116 |
| 117 // The options button sits outside the translate_box so that it can be end |
| 118 // packed in hbox_. |
| 119 GtkWidget* options_menu_button = CreateMenuButton( |
| 120 l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_OPTIONS)); |
| 121 Signals()->Connect(options_menu_button, "clicked", |
| 122 G_CALLBACK(&OnOptionsClickedThunk), this); |
| 123 gtk_widget_show_all(options_menu_button); |
| 124 gtk_util::CenterWidgetInHBox(hbox_, options_menu_button, true, 0); |
| 125 } |
| 126 |
125 void TranslateInfoBarBase::AnimationProgressed(const ui::Animation* animation) { | 127 void TranslateInfoBarBase::AnimationProgressed(const ui::Animation* animation) { |
| 128 DCHECK(widget()); |
126 if (animation == background_color_animation_.get()) { | 129 if (animation == background_color_animation_.get()) { |
127 background_error_percent_ = animation->GetCurrentValue(); | 130 background_error_percent_ = animation->GetCurrentValue(); |
128 // Queue the info bar widget for redisplay so it repaints its background. | 131 // Queue the info bar widget for redisplay so it repaints its background. |
129 gtk_widget_queue_draw(widget()); | 132 gtk_widget_queue_draw(widget()); |
130 } else { | 133 } else { |
131 InfoBar::AnimationProgressed(animation); | 134 InfoBar::AnimationProgressed(animation); |
132 } | 135 } |
133 } | 136 } |
134 | 137 |
135 bool TranslateInfoBarBase::ShowOptionsMenuButton() const { | 138 bool TranslateInfoBarBase::ShowOptionsMenuButton() const { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 case AFTER_TRANSLATE: | 210 case AFTER_TRANSLATE: |
208 infobar = new AfterTranslateInfoBar(owner, this); | 211 infobar = new AfterTranslateInfoBar(owner, this); |
209 break; | 212 break; |
210 case TRANSLATING: | 213 case TRANSLATING: |
211 case TRANSLATION_ERROR: | 214 case TRANSLATION_ERROR: |
212 infobar = new TranslateMessageInfoBar(owner, this); | 215 infobar = new TranslateMessageInfoBar(owner, this); |
213 break; | 216 break; |
214 default: | 217 default: |
215 NOTREACHED(); | 218 NOTREACHED(); |
216 } | 219 } |
217 infobar->Init(); | |
218 return infobar; | 220 return infobar; |
219 } | 221 } |
OLD | NEW |