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/before_translate_infobar_gtk.h" | 5 #include "chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/translate/translate_infobar_delegate.h" | 8 #include "chrome/browser/translate/translate_infobar_delegate.h" |
9 #include "chrome/browser/ui/gtk/gtk_util.h" | 9 #include "chrome/browser/ui/gtk/gtk_util.h" |
10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 GetDelegate()->target_language_index()); | 38 GetDelegate()->target_language_index()); |
39 g_signal_connect(combobox, "changed", | 39 g_signal_connect(combobox, "changed", |
40 G_CALLBACK(&OnLanguageModifiedThunk), this); | 40 G_CALLBACK(&OnLanguageModifiedThunk), this); |
41 gtk_box_pack_start(GTK_BOX(hbox), combobox, FALSE, FALSE, 0); | 41 gtk_box_pack_start(GTK_BOX(hbox), combobox, FALSE, FALSE, 0); |
42 gtk_box_pack_start(GTK_BOX(hbox), | 42 gtk_box_pack_start(GTK_BOX(hbox), |
43 CreateLabel(UTF16ToUTF8(text.substr(offset))), | 43 CreateLabel(UTF16ToUTF8(text.substr(offset))), |
44 FALSE, FALSE, 0); | 44 FALSE, FALSE, 0); |
45 | 45 |
46 GtkWidget* button = gtk_button_new_with_label( | 46 GtkWidget* button = gtk_button_new_with_label( |
47 l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_ACCEPT).c_str()); | 47 l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_ACCEPT).c_str()); |
48 g_signal_connect(button, "clicked",G_CALLBACK(&OnAcceptPressedThunk), this); | 48 g_signal_connect(button, "clicked", G_CALLBACK(&OnAcceptPressedThunk), this); |
49 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | 49 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); |
50 | 50 |
51 button = gtk_button_new_with_label( | 51 button = gtk_button_new_with_label( |
52 l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_DENY).c_str()); | 52 l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_DENY).c_str()); |
53 g_signal_connect(button, "clicked",G_CALLBACK(&OnDenyPressedThunk), this); | 53 g_signal_connect(button, "clicked", G_CALLBACK(&OnDenyPressedThunk), this); |
54 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | 54 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); |
55 | 55 |
56 TranslateInfoBarDelegate* delegate = GetDelegate(); | 56 TranslateInfoBarDelegate* delegate = GetDelegate(); |
57 if (delegate->ShouldShowNeverTranslateButton()) { | 57 if (delegate->ShouldShowNeverTranslateButton()) { |
58 std::string label = | 58 std::string label = |
59 l10n_util::GetStringFUTF8(IDS_TRANSLATE_INFOBAR_NEVER_TRANSLATE, | 59 l10n_util::GetStringFUTF8(IDS_TRANSLATE_INFOBAR_NEVER_TRANSLATE, |
60 delegate->GetLanguageDisplayableNameAt( | 60 delegate->GetLanguageDisplayableNameAt( |
61 delegate->original_language_index())); | 61 delegate->original_language_index())); |
62 button = gtk_button_new_with_label(label.c_str()); | 62 button = gtk_button_new_with_label(label.c_str()); |
63 g_signal_connect(button, "clicked", | 63 g_signal_connect(button, "clicked", |
(...skipping 11 matching lines...) Expand all Loading... |
75 G_CALLBACK(&OnAlwaysTranslatePressedThunk), this); | 75 G_CALLBACK(&OnAlwaysTranslatePressedThunk), this); |
76 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | 76 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 bool BeforeTranslateInfoBar::ShowOptionsMenuButton() const { | 80 bool BeforeTranslateInfoBar::ShowOptionsMenuButton() const { |
81 return true; | 81 return true; |
82 } | 82 } |
83 | 83 |
84 void BeforeTranslateInfoBar::OnLanguageModified(GtkWidget* sender) { | 84 void BeforeTranslateInfoBar::OnLanguageModified(GtkWidget* sender) { |
| 85 if (!owned()) |
| 86 return; // We're closing; don't call anything, it might access the owner. |
85 size_t index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender)); | 87 size_t index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender)); |
86 if (index == GetDelegate()->original_language_index()) | 88 if (index == GetDelegate()->original_language_index()) |
87 return; | 89 return; |
88 | 90 |
89 GetDelegate()->SetOriginalLanguage(index); | 91 GetDelegate()->SetOriginalLanguage(index); |
90 } | 92 } |
91 | 93 |
92 void BeforeTranslateInfoBar::OnAcceptPressed(GtkWidget* sender) { | 94 void BeforeTranslateInfoBar::OnAcceptPressed(GtkWidget* sender) { |
| 95 if (!owned()) |
| 96 return; // We're closing; don't call anything, it might access the owner. |
93 GetDelegate()->Translate(); | 97 GetDelegate()->Translate(); |
94 } | 98 } |
95 | 99 |
96 void BeforeTranslateInfoBar::OnDenyPressed(GtkWidget* sender) { | 100 void BeforeTranslateInfoBar::OnDenyPressed(GtkWidget* sender) { |
| 101 if (!owned()) |
| 102 return; // We're closing; don't call anything, it might access the owner. |
97 GetDelegate()->TranslationDeclined(); | 103 GetDelegate()->TranslationDeclined(); |
98 RemoveSelf(); | 104 RemoveSelf(); |
99 } | 105 } |
100 | 106 |
101 void BeforeTranslateInfoBar::OnNeverTranslatePressed(GtkWidget* sender) { | 107 void BeforeTranslateInfoBar::OnNeverTranslatePressed(GtkWidget* sender) { |
| 108 if (!owned()) |
| 109 return; // We're closing; don't call anything, it might access the owner. |
102 GetDelegate()->NeverTranslatePageLanguage(); | 110 GetDelegate()->NeverTranslatePageLanguage(); |
103 } | 111 } |
104 | 112 |
105 void BeforeTranslateInfoBar::OnAlwaysTranslatePressed(GtkWidget* sender) { | 113 void BeforeTranslateInfoBar::OnAlwaysTranslatePressed(GtkWidget* sender) { |
| 114 if (!owned()) |
| 115 return; // We're closing; don't call anything, it might access the owner. |
106 GetDelegate()->AlwaysTranslatePageLanguage(); | 116 GetDelegate()->AlwaysTranslatePageLanguage(); |
107 } | 117 } |
OLD | NEW |