OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/gtk/translate/after_translate_infobar_gtk.h" | 5 #include "chrome/browser/gtk/translate/after_translate_infobar_gtk.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/gtk/gtk_util.h" | 10 #include "chrome/browser/gtk/gtk_util.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 gtk_box_pack_start(GTK_BOX(hbox), CreateLabel(UTF16ToUTF8(strings[2])), | 58 gtk_box_pack_start(GTK_BOX(hbox), CreateLabel(UTF16ToUTF8(strings[2])), |
59 FALSE, FALSE, 0); | 59 FALSE, FALSE, 0); |
60 | 60 |
61 GtkWidget* button = gtk_button_new_with_label( | 61 GtkWidget* button = gtk_button_new_with_label( |
62 l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_REVERT).c_str()); | 62 l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_REVERT).c_str()); |
63 g_signal_connect(button, "clicked",G_CALLBACK(&OnRevertPressedThunk), this); | 63 g_signal_connect(button, "clicked",G_CALLBACK(&OnRevertPressedThunk), this); |
64 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | 64 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); |
65 } | 65 } |
66 | 66 |
67 void AfterTranslateInfoBar::OnOriginalLanguageModified(GtkWidget* sender) { | 67 void AfterTranslateInfoBar::OnOriginalLanguageModified(GtkWidget* sender) { |
| 68 if (!delegate()) |
| 69 return; |
| 70 |
68 int index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender)); | 71 int index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender)); |
69 if (index == GetDelegate()->original_language_index()) | 72 if (index == GetDelegate()->original_language_index()) |
70 return; | 73 return; |
71 | 74 |
72 // Setting the language will lead to a new translation that is going to close | 75 // Setting the language will lead to a new translation that is going to close |
73 // the infobar. This is not OK to do this from the signal handler, so we'll | 76 // the infobar. This is not OK to do this from the signal handler, so we'll |
74 // defer it. | 77 // defer it. |
75 MessageLoop::current()->PostTask(FROM_HERE, method_factory_.NewRunnableMethod( | 78 MessageLoop::current()->PostTask(FROM_HERE, method_factory_.NewRunnableMethod( |
76 &AfterTranslateInfoBar::SetOriginalLanguage, index)); | 79 &AfterTranslateInfoBar::SetOriginalLanguage, index)); |
77 } | 80 } |
78 | 81 |
79 void AfterTranslateInfoBar::OnTargetLanguageModified(GtkWidget* sender) { | 82 void AfterTranslateInfoBar::OnTargetLanguageModified(GtkWidget* sender) { |
| 83 if (!delegate()) |
| 84 return; |
| 85 |
80 int index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender)); | 86 int index = GetLanguageComboboxActiveId(GTK_COMBO_BOX(sender)); |
81 if (index == GetDelegate()->target_language_index()) | 87 if (index == GetDelegate()->target_language_index()) |
82 return; | 88 return; |
83 | 89 |
84 // See comment in OnOriginalLanguageModified on why we use a task. | 90 // See comment in OnOriginalLanguageModified on why we use a task. |
85 MessageLoop::current()->PostTask(FROM_HERE, method_factory_.NewRunnableMethod( | 91 MessageLoop::current()->PostTask(FROM_HERE, method_factory_.NewRunnableMethod( |
86 &AfterTranslateInfoBar::SetTargetLanguage, index)); | 92 &AfterTranslateInfoBar::SetTargetLanguage, index)); |
87 } | 93 } |
88 | 94 |
89 void AfterTranslateInfoBar::OnRevertPressed(GtkWidget* sender) { | 95 void AfterTranslateInfoBar::OnRevertPressed(GtkWidget* sender) { |
90 GetDelegate()->RevertTranslation(); | 96 if (delegate()) |
| 97 GetDelegate()->RevertTranslation(); |
91 } | 98 } |
92 | 99 |
93 void AfterTranslateInfoBar::SetOriginalLanguage(int language_index) { | 100 void AfterTranslateInfoBar::SetOriginalLanguage(int language_index) { |
94 GetDelegate()->SetOriginalLanguage(language_index); | 101 if (delegate()) |
| 102 GetDelegate()->SetOriginalLanguage(language_index); |
95 } | 103 } |
96 | 104 |
97 void AfterTranslateInfoBar::SetTargetLanguage(int language_index) { | 105 void AfterTranslateInfoBar::SetTargetLanguage(int language_index) { |
98 GetDelegate()->SetTargetLanguage(language_index); | 106 if (delegate()) |
| 107 GetDelegate()->SetTargetLanguage(language_index); |
99 } | 108 } |
OLD | NEW |