| 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/edit_search_engine_dialog.h" | 5 #include "chrome/browser/ui/gtk/edit_search_engine_dialog.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
| 26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // Forces text to lowercase when connected to an editable's "insert-text" | 30 // Forces text to lowercase when connected to an editable's "insert-text" |
| 31 // signal. (Like views Textfield::STYLE_LOWERCASE.) | 31 // signal. (Like views Textfield::STYLE_LOWERCASE.) |
| 32 void LowercaseInsertTextHandler(GtkEditable *editable, const gchar *text, | 32 void LowercaseInsertTextHandler(GtkEditable *editable, const gchar *text, |
| 33 gint length, gint *position, gpointer data) { | 33 gint length, gint *position, gpointer data) { |
| 34 base::string16 original_text = UTF8ToUTF16(text); | 34 base::string16 original_text = base::UTF8ToUTF16(text); |
| 35 base::string16 lower_text = base::i18n::ToLower(original_text); | 35 base::string16 lower_text = base::i18n::ToLower(original_text); |
| 36 if (lower_text != original_text) { | 36 if (lower_text != original_text) { |
| 37 std::string result = UTF16ToUTF8(lower_text); | 37 std::string result = base::UTF16ToUTF8(lower_text); |
| 38 // Prevent ourselves getting called recursively about our own edit. | 38 // Prevent ourselves getting called recursively about our own edit. |
| 39 g_signal_handlers_block_by_func(G_OBJECT(editable), | 39 g_signal_handlers_block_by_func(G_OBJECT(editable), |
| 40 reinterpret_cast<gpointer>(LowercaseInsertTextHandler), data); | 40 reinterpret_cast<gpointer>(LowercaseInsertTextHandler), data); |
| 41 gtk_editable_insert_text(editable, result.c_str(), result.size(), position); | 41 gtk_editable_insert_text(editable, result.c_str(), result.size(), position); |
| 42 g_signal_handlers_unblock_by_func(G_OBJECT(editable), | 42 g_signal_handlers_unblock_by_func(G_OBJECT(editable), |
| 43 reinterpret_cast<gpointer>(LowercaseInsertTextHandler), data); | 43 reinterpret_cast<gpointer>(LowercaseInsertTextHandler), data); |
| 44 // We've inserted our modified version, stop the defalut handler from | 44 // We've inserted our modified version, stop the defalut handler from |
| 45 // inserting the original. | 45 // inserting the original. |
| 46 g_signal_stop_emission_by_name(G_OBJECT(editable), "insert_text"); | 46 g_signal_stop_emission_by_name(G_OBJECT(editable), "insert_text"); |
| 47 } | 47 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 g_signal_connect(url_entry_, "changed", | 136 g_signal_connect(url_entry_, "changed", |
| 137 G_CALLBACK(OnEntryChangedThunk), this); | 137 G_CALLBACK(OnEntryChangedThunk), this); |
| 138 | 138 |
| 139 title_image_ = gtk_image_new_from_pixbuf(NULL); | 139 title_image_ = gtk_image_new_from_pixbuf(NULL); |
| 140 keyword_image_ = gtk_image_new_from_pixbuf(NULL); | 140 keyword_image_ = gtk_image_new_from_pixbuf(NULL); |
| 141 url_image_ = gtk_image_new_from_pixbuf(NULL); | 141 url_image_ = gtk_image_new_from_pixbuf(NULL); |
| 142 | 142 |
| 143 if (controller_->template_url()) { | 143 if (controller_->template_url()) { |
| 144 gtk_entry_set_text( | 144 gtk_entry_set_text( |
| 145 GTK_ENTRY(title_entry_), | 145 GTK_ENTRY(title_entry_), |
| 146 UTF16ToUTF8(controller_->template_url()->short_name()).c_str()); | 146 base::UTF16ToUTF8(controller_->template_url()->short_name()).c_str()); |
| 147 gtk_entry_set_text( | 147 gtk_entry_set_text( |
| 148 GTK_ENTRY(keyword_entry_), | 148 GTK_ENTRY(keyword_entry_), |
| 149 UTF16ToUTF8(controller_->template_url()->keyword()).c_str()); | 149 base::UTF16ToUTF8(controller_->template_url()->keyword()).c_str()); |
| 150 gtk_entry_set_text( | 150 gtk_entry_set_text( |
| 151 GTK_ENTRY(url_entry_), | 151 GTK_ENTRY(url_entry_), |
| 152 UTF16ToUTF8(controller_->template_url()->url_ref().DisplayURL()). | 152 base::UTF16ToUTF8(controller_->template_url()->url_ref().DisplayURL()). |
| 153 c_str()); | 153 c_str()); |
| 154 // We don't allow users to edit prepopulated URLs. | 154 // We don't allow users to edit prepopulated URLs. |
| 155 gtk_editable_set_editable( | 155 gtk_editable_set_editable( |
| 156 GTK_EDITABLE(url_entry_), | 156 GTK_EDITABLE(url_entry_), |
| 157 controller_->template_url()->prepopulate_id() == 0); | 157 controller_->template_url()->prepopulate_id() == 0); |
| 158 | 158 |
| 159 if (controller_->template_url()->prepopulate_id() != 0) { | 159 if (controller_->template_url()->prepopulate_id() != 0) { |
| 160 GtkWidget* fake_label = gtk_label_new("Fake label"); | 160 GtkWidget* fake_label = gtk_label_new("Fake label"); |
| 161 gtk_widget_set_sensitive(fake_label, | 161 gtk_widget_set_sensitive(fake_label, |
| 162 controller_->template_url()->prepopulate_id() == 0); | 162 controller_->template_url()->prepopulate_id() == 0); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 209 |
| 210 EnableControls(); | 210 EnableControls(); |
| 211 | 211 |
| 212 gtk_util::ShowDialog(dialog_); | 212 gtk_util::ShowDialog(dialog_); |
| 213 | 213 |
| 214 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); | 214 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); |
| 215 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroyThunk), this); | 215 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroyThunk), this); |
| 216 } | 216 } |
| 217 | 217 |
| 218 base::string16 EditSearchEngineDialog::GetTitleInput() const { | 218 base::string16 EditSearchEngineDialog::GetTitleInput() const { |
| 219 return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(title_entry_))); | 219 return base::UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(title_entry_))); |
| 220 } | 220 } |
| 221 | 221 |
| 222 base::string16 EditSearchEngineDialog::GetKeywordInput() const { | 222 base::string16 EditSearchEngineDialog::GetKeywordInput() const { |
| 223 return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(keyword_entry_))); | 223 return base::UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(keyword_entry_))); |
| 224 } | 224 } |
| 225 | 225 |
| 226 std::string EditSearchEngineDialog::GetURLInput() const { | 226 std::string EditSearchEngineDialog::GetURLInput() const { |
| 227 return gtk_entry_get_text(GTK_ENTRY(url_entry_)); | 227 return gtk_entry_get_text(GTK_ENTRY(url_entry_)); |
| 228 } | 228 } |
| 229 | 229 |
| 230 void EditSearchEngineDialog::EnableControls() { | 230 void EditSearchEngineDialog::EnableControls() { |
| 231 gtk_widget_set_sensitive(ok_button_, | 231 gtk_widget_set_sensitive(ok_button_, |
| 232 controller_->IsKeywordValid(GetKeywordInput()) && | 232 controller_->IsKeywordValid(GetKeywordInput()) && |
| 233 controller_->IsTitleValid(GetTitleInput()) && | 233 controller_->IsTitleValid(GetTitleInput()) && |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 GetURLInput()); | 267 GetURLInput()); |
| 268 } else { | 268 } else { |
| 269 controller_->CleanUpCancelledAdd(); | 269 controller_->CleanUpCancelledAdd(); |
| 270 } | 270 } |
| 271 gtk_widget_destroy(dialog_); | 271 gtk_widget_destroy(dialog_); |
| 272 } | 272 } |
| 273 | 273 |
| 274 void EditSearchEngineDialog::OnWindowDestroy(GtkWidget* widget) { | 274 void EditSearchEngineDialog::OnWindowDestroy(GtkWidget* widget) { |
| 275 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 275 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 276 } | 276 } |
| OLD | NEW |