Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: chrome/browser/ui/gtk/edit_search_engine_dialog.cc

Issue 9968016: Move the URL string from TemplateURLRef onto the owning TemplateURL. This will make it easier to m… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/net/url_fixer_upper.h" 13 #include "chrome/browser/net/url_fixer_upper.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/search_engines/template_url.h" 15 #include "chrome/browser/search_engines/template_url.h"
16 #include "chrome/browser/search_engines/template_url_service.h" 16 #include "chrome/browser/search_engines/template_url_service.h"
17 #include "chrome/browser/ui/gtk/gtk_util.h" 17 #include "chrome/browser/ui/gtk/gtk_util.h"
18 #include "chrome/browser/ui/search_engines/edit_search_engine_controller.h" 18 #include "chrome/browser/ui/search_engines/edit_search_engine_controller.h"
19 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
20 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
21 #include "grit/theme_resources.h" 21 #include "grit/theme_resources.h"
22 #include "grit/ui_resources.h" 22 #include "grit/ui_resources.h"
23 #include "ui/base/gtk/gtk_hig_constants.h" 23 #include "ui/base/gtk/gtk_hig_constants.h"
24 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
27 27
28 namespace { 28 namespace {
29 29
30 std::string GetDisplayURL(const TemplateURL& turl) {
31 return turl.url() ? UTF16ToUTF8(turl.url()->DisplayURL()) : std::string();
32 }
33
34 // 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"
35 // signal. (Like views Textfield::STYLE_LOWERCASE.) 31 // signal. (Like views Textfield::STYLE_LOWERCASE.)
36 void LowercaseInsertTextHandler(GtkEditable *editable, const gchar *text, 32 void LowercaseInsertTextHandler(GtkEditable *editable, const gchar *text,
37 gint length, gint *position, gpointer data) { 33 gint length, gint *position, gpointer data) {
38 string16 original_text = UTF8ToUTF16(text); 34 string16 original_text = UTF8ToUTF16(text);
39 string16 lower_text = base::i18n::ToLower(original_text); 35 string16 lower_text = base::i18n::ToLower(original_text);
40 if (lower_text != original_text) { 36 if (lower_text != original_text) {
41 std::string result = UTF16ToUTF8(lower_text); 37 std::string result = UTF16ToUTF8(lower_text);
42 // Prevent ourselves getting called recursively about our own edit. 38 // Prevent ourselves getting called recursively about our own edit.
43 g_signal_handlers_block_by_func(G_OBJECT(editable), 39 g_signal_handlers_block_by_func(G_OBJECT(editable),
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 142
147 if (controller_->template_url()) { 143 if (controller_->template_url()) {
148 gtk_entry_set_text( 144 gtk_entry_set_text(
149 GTK_ENTRY(title_entry_), 145 GTK_ENTRY(title_entry_),
150 UTF16ToUTF8(controller_->template_url()->short_name()).c_str()); 146 UTF16ToUTF8(controller_->template_url()->short_name()).c_str());
151 gtk_entry_set_text( 147 gtk_entry_set_text(
152 GTK_ENTRY(keyword_entry_), 148 GTK_ENTRY(keyword_entry_),
153 UTF16ToUTF8(controller_->template_url()->keyword()).c_str()); 149 UTF16ToUTF8(controller_->template_url()->keyword()).c_str());
154 gtk_entry_set_text( 150 gtk_entry_set_text(
155 GTK_ENTRY(url_entry_), 151 GTK_ENTRY(url_entry_),
156 GetDisplayURL(*controller_->template_url()).c_str()); 152 UTF16ToUTF8(controller_->template_url()->url_ref().DisplayURL()).
153 c_str());
157 // We don't allow users to edit prepopulated URLs. 154 // We don't allow users to edit prepopulated URLs.
158 gtk_editable_set_editable( 155 gtk_editable_set_editable(
159 GTK_EDITABLE(url_entry_), 156 GTK_EDITABLE(url_entry_),
160 controller_->template_url()->prepopulate_id() == 0); 157 controller_->template_url()->prepopulate_id() == 0);
161 158
162 if (controller_->template_url()->prepopulate_id() != 0) { 159 if (controller_->template_url()->prepopulate_id() != 0) {
163 GtkWidget* fake_label = gtk_label_new("Fake label"); 160 GtkWidget* fake_label = gtk_label_new("Fake label");
164 gtk_widget_set_sensitive(fake_label, 161 gtk_widget_set_sensitive(fake_label,
165 controller_->template_url()->prepopulate_id() == 0); 162 controller_->template_url()->prepopulate_id() == 0);
166 GtkStyle* label_style = gtk_widget_get_style(fake_label); 163 GtkStyle* label_style = gtk_widget_get_style(fake_label);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 GetURLInput()); 267 GetURLInput());
271 } else { 268 } else {
272 controller_->CleanUpCancelledAdd(); 269 controller_->CleanUpCancelledAdd();
273 } 270 }
274 gtk_widget_destroy(dialog_); 271 gtk_widget_destroy(dialog_);
275 } 272 }
276 273
277 void EditSearchEngineDialog::OnWindowDestroy(GtkWidget* widget) { 274 void EditSearchEngineDialog::OnWindowDestroy(GtkWidget* widget) {
278 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 275 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
279 } 276 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698