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

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

Issue 138363004: Views Textfield fixes and cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove the unused controller accessor. Created 6 years, 11 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/views/edit_search_engine_dialog.h" 5 #include "chrome/browser/ui/views/edit_search_engine_dialog.h"
6 6
7 #include "base/i18n/case_conversion.h"
7 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
8 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/search_engines/template_url.h" 11 #include "chrome/browser/search_engines/template_url.h"
11 #include "chrome/browser/ui/search_engines/edit_search_engine_controller.h" 12 #include "chrome/browser/ui/search_engines/edit_search_engine_controller.h"
12 #include "chrome/browser/ui/views/constrained_window_views.h" 13 #include "chrome/browser/ui/views/constrained_window_views.h"
13 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
15 #include "grit/ui_resources.h" 16 #include "grit/ui_resources.h"
16 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 96
96 bool EditSearchEngineDialog::Accept() { 97 bool EditSearchEngineDialog::Accept() {
97 controller_->AcceptAddOrEdit(title_tf_->text(), keyword_tf_->text(), 98 controller_->AcceptAddOrEdit(title_tf_->text(), keyword_tf_->text(),
98 base::UTF16ToUTF8(url_tf_->text())); 99 base::UTF16ToUTF8(url_tf_->text()));
99 return true; 100 return true;
100 } 101 }
101 102
102 void EditSearchEngineDialog::ContentsChanged( 103 void EditSearchEngineDialog::ContentsChanged(
103 Textfield* sender, 104 Textfield* sender,
104 const base::string16& new_contents) { 105 const base::string16& new_contents) {
106 // Force the keyword text to be lowercase, keep the caret or selection.
107 if (sender == keyword_tf_) {
108 const gfx::SelectionModel selection_model = sender->GetSelectionModel();
109 sender->SetText(base::i18n::ToLower(new_contents));
110 sender->SelectSelectionModel(selection_model);
sky 2014/01/14 23:17:13 This seems really heavyweight and easy to lose sta
msw 2014/01/15 01:22:03 The ToT implementation is worse, it actually clamp
111 }
112
105 GetDialogClientView()->UpdateDialogButtons(); 113 GetDialogClientView()->UpdateDialogButtons();
106 UpdateImageViews(); 114 UpdateImageViews();
107 } 115 }
108 116
109 bool EditSearchEngineDialog::HandleKeyEvent( 117 bool EditSearchEngineDialog::HandleKeyEvent(
110 Textfield* sender, 118 Textfield* sender,
111 const ui::KeyEvent& key_event) { 119 const ui::KeyEvent& key_event) {
112 return false; 120 return false;
113 } 121 }
114 122
115 void EditSearchEngineDialog::Init() { 123 void EditSearchEngineDialog::Init() {
116 // Create the views we'll need. 124 // Create the views we'll need.
117 if (controller_->template_url()) { 125 if (controller_->template_url()) {
118 title_tf_ = CreateTextfield(controller_->template_url()->short_name(), 126 title_tf_ = CreateTextfield(controller_->template_url()->short_name());
119 false); 127 keyword_tf_ = CreateTextfield(controller_->template_url()->keyword());
120 keyword_tf_ = CreateTextfield(controller_->template_url()->keyword(), true);
121 url_tf_ = CreateTextfield( 128 url_tf_ = CreateTextfield(
122 controller_->template_url()->url_ref().DisplayURL(), false); 129 controller_->template_url()->url_ref().DisplayURL());
123 // We don't allow users to edit prepopulate URLs. This is done as 130 // We don't allow users to edit prepopulate URLs. This is done as
124 // occasionally we need to update the URL of prepopulated TemplateURLs. 131 // occasionally we need to update the URL of prepopulated TemplateURLs.
125 url_tf_->SetReadOnly(controller_->template_url()->prepopulate_id() != 0); 132 url_tf_->SetReadOnly(controller_->template_url()->prepopulate_id() != 0);
126 } else { 133 } else {
127 title_tf_ = CreateTextfield(base::string16(), false); 134 title_tf_ = CreateTextfield(base::string16());
128 keyword_tf_ = CreateTextfield(base::string16(), true); 135 keyword_tf_ = CreateTextfield(base::string16());
129 url_tf_ = CreateTextfield(base::string16(), false); 136 url_tf_ = CreateTextfield(base::string16());
130 } 137 }
131 title_iv_ = new views::ImageView(); 138 title_iv_ = new views::ImageView();
132 keyword_iv_ = new views::ImageView(); 139 keyword_iv_ = new views::ImageView();
133 url_iv_ = new views::ImageView(); 140 url_iv_ = new views::ImageView();
134 141
135 UpdateImageViews(); 142 UpdateImageViews();
136 143
137 const int related_x = views::kRelatedControlHorizontalSpacing; 144 const int related_x = views::kRelatedControlHorizontalSpacing;
138 const int related_y = views::kRelatedControlVerticalSpacing; 145 const int related_y = views::kRelatedControlVerticalSpacing;
139 const int unrelated_y = views::kUnrelatedControlVerticalSpacing; 146 const int unrelated_y = views::kUnrelatedControlVerticalSpacing;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 layout->AddPaddingRow(0, related_y); 223 layout->AddPaddingRow(0, related_y);
217 } 224 }
218 225
219 views::Label* EditSearchEngineDialog::CreateLabel(int message_id) { 226 views::Label* EditSearchEngineDialog::CreateLabel(int message_id) {
220 views::Label* label = 227 views::Label* label =
221 new views::Label(l10n_util::GetStringUTF16(message_id)); 228 new views::Label(l10n_util::GetStringUTF16(message_id));
222 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 229 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
223 return label; 230 return label;
224 } 231 }
225 232
226 Textfield* EditSearchEngineDialog::CreateTextfield(const base::string16& text, 233 Textfield* EditSearchEngineDialog::CreateTextfield(const base::string16& text) {
227 bool lowercase) { 234 Textfield* text_field = new Textfield();
228 Textfield* text_field = new Textfield(
229 lowercase ? Textfield::STYLE_LOWERCASE : Textfield::STYLE_DEFAULT);
230 text_field->SetText(text); 235 text_field->SetText(text);
231 text_field->SetController(this); 236 text_field->set_controller(this);
232 return text_field; 237 return text_field;
233 } 238 }
234 239
235 void EditSearchEngineDialog::UpdateImageViews() { 240 void EditSearchEngineDialog::UpdateImageViews() {
236 UpdateImageView(keyword_iv_, controller_->IsKeywordValid(keyword_tf_->text()), 241 UpdateImageView(keyword_iv_, controller_->IsKeywordValid(keyword_tf_->text()),
237 IDS_SEARCH_ENGINES_INVALID_KEYWORD_TT); 242 IDS_SEARCH_ENGINES_INVALID_KEYWORD_TT);
238 UpdateImageView(url_iv_, 243 UpdateImageView(url_iv_,
239 controller_->IsURLValid(base::UTF16ToUTF8(url_tf_->text())), 244 controller_->IsURLValid(base::UTF16ToUTF8(url_tf_->text())),
240 IDS_SEARCH_ENGINES_INVALID_URL_TT); 245 IDS_SEARCH_ENGINES_INVALID_URL_TT);
241 UpdateImageView(title_iv_, controller_->IsTitleValid(title_tf_->text()), 246 UpdateImageView(title_iv_, controller_->IsTitleValid(title_tf_->text()),
242 IDS_SEARCH_ENGINES_INVALID_TITLE_TT); 247 IDS_SEARCH_ENGINES_INVALID_TITLE_TT);
243 } 248 }
244 249
245 void EditSearchEngineDialog::UpdateImageView(views::ImageView* image_view, 250 void EditSearchEngineDialog::UpdateImageView(views::ImageView* image_view,
246 bool is_valid, 251 bool is_valid,
247 int invalid_message_id) { 252 int invalid_message_id) {
248 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 253 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
249 if (is_valid) { 254 if (is_valid) {
250 image_view->SetTooltipText(base::string16()); 255 image_view->SetTooltipText(base::string16());
251 image_view->SetImage(rb.GetImageSkiaNamed(IDR_INPUT_GOOD)); 256 image_view->SetImage(rb.GetImageSkiaNamed(IDR_INPUT_GOOD));
252 } else { 257 } else {
253 image_view->SetTooltipText(l10n_util::GetStringUTF16(invalid_message_id)); 258 image_view->SetTooltipText(l10n_util::GetStringUTF16(invalid_message_id));
254 image_view->SetImage(rb.GetImageSkiaNamed(IDR_INPUT_ALERT)); 259 image_view->SetImage(rb.GetImageSkiaNamed(IDR_INPUT_ALERT));
255 } 260 }
256 } 261 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/edit_search_engine_dialog.h ('k') | chrome/browser/ui/views/find_bar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698