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

Side by Side Diff: chrome/browser/views/edit_keyword_controller.cc

Issue 115825: Move text_field.cc and rename the class to Textfield in preparation for porti... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 7 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
« no previous file with comments | « chrome/browser/views/edit_keyword_controller.h ('k') | chrome/browser/views/find_bar_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/views/edit_keyword_controller.h" 5 #include "chrome/browser/views/edit_keyword_controller.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "chrome/browser/metrics/user_metrics.h" 10 #include "chrome/browser/metrics/user_metrics.h"
11 #include "chrome/browser/net/url_fixer_upper.h" 11 #include "chrome/browser/net/url_fixer_upper.h"
12 #include "chrome/browser/profile.h" 12 #include "chrome/browser/profile.h"
13 #include "chrome/browser/search_engines/template_url.h" 13 #include "chrome/browser/search_engines/template_url.h"
14 #include "chrome/browser/search_engines/template_url_model.h" 14 #include "chrome/browser/search_engines/template_url_model.h"
15 #include "chrome/browser/views/keyword_editor_view.h" 15 #include "chrome/browser/views/keyword_editor_view.h"
16 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
17 #include "grit/app_resources.h" 17 #include "grit/app_resources.h"
18 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
19 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
20 #include "views/controls/label.h" 20 #include "views/controls/label.h"
21 #include "views/controls/image_view.h" 21 #include "views/controls/image_view.h"
22 #include "views/controls/table/table_view.h" 22 #include "views/controls/table/table_view.h"
23 #include "views/grid_layout.h" 23 #include "views/grid_layout.h"
24 #include "views/standard_layout.h" 24 #include "views/standard_layout.h"
25 #include "views/window/window.h" 25 #include "views/window/window.h"
26 26
27 using views::GridLayout; 27 using views::GridLayout;
28 using views::ImageView; 28 using views::ImageView;
29 using views::TextField; 29 using views::Textfield;
30 30
31 31
32 namespace { 32 namespace {
33 // Converts a URL as understood by TemplateURL to one appropriate for display 33 // Converts a URL as understood by TemplateURL to one appropriate for display
34 // to the user. 34 // to the user.
35 std::wstring GetDisplayURL(const TemplateURL& turl) { 35 std::wstring GetDisplayURL(const TemplateURL& turl) {
36 return turl.url() ? turl.url()->DisplayURL() : std::wstring(); 36 return turl.url() ? turl.url()->DisplayURL() : std::wstring();
37 } 37 }
38 } // namespace 38 } // namespace
39 39
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 url_string); 146 url_string);
147 } 147 }
148 } 148 }
149 return true; 149 return true;
150 } 150 }
151 151
152 views::View* EditKeywordController::GetContentsView() { 152 views::View* EditKeywordController::GetContentsView() {
153 return view_; 153 return view_;
154 } 154 }
155 155
156 void EditKeywordController::ContentsChanged(TextField* sender, 156 void EditKeywordController::ContentsChanged(Textfield* sender,
157 const std::wstring& new_contents) { 157 const std::wstring& new_contents) {
158 GetDialogClientView()->UpdateDialogButtons(); 158 GetDialogClientView()->UpdateDialogButtons();
159 UpdateImageViews(); 159 UpdateImageViews();
160 } 160 }
161 161
162 bool EditKeywordController::HandleKeystroke( 162 bool EditKeywordController::HandleKeystroke(
163 TextField* sender, 163 Textfield* sender,
164 const views::TextField::Keystroke& key) { 164 const views::Textfield::Keystroke& key) {
165 return false; 165 return false;
166 } 166 }
167 167
168 void EditKeywordController::Init() { 168 void EditKeywordController::Init() {
169 // Create the views we'll need. 169 // Create the views we'll need.
170 view_ = new views::View(); 170 view_ = new views::View();
171 if (template_url_) { 171 if (template_url_) {
172 title_tf_ = CreateTextField(template_url_->short_name(), false); 172 title_tf_ = CreateTextfield(template_url_->short_name(), false);
173 keyword_tf_ = CreateTextField(template_url_->keyword(), true); 173 keyword_tf_ = CreateTextfield(template_url_->keyword(), true);
174 url_tf_ = CreateTextField(GetDisplayURL(*template_url_), false); 174 url_tf_ = CreateTextfield(GetDisplayURL(*template_url_), false);
175 // We don't allow users to edit prepopulate URLs. This is done as 175 // We don't allow users to edit prepopulate URLs. This is done as
176 // occasionally we need to update the URL of prepopulated TemplateURLs. 176 // occasionally we need to update the URL of prepopulated TemplateURLs.
177 url_tf_->SetReadOnly(template_url_->prepopulate_id() != 0); 177 url_tf_->SetReadOnly(template_url_->prepopulate_id() != 0);
178 } else { 178 } else {
179 title_tf_ = CreateTextField(std::wstring(), false); 179 title_tf_ = CreateTextfield(std::wstring(), false);
180 keyword_tf_ = CreateTextField(std::wstring(), true); 180 keyword_tf_ = CreateTextfield(std::wstring(), true);
181 url_tf_ = CreateTextField(std::wstring(), false); 181 url_tf_ = CreateTextfield(std::wstring(), false);
182 } 182 }
183 title_iv_ = new ImageView(); 183 title_iv_ = new ImageView();
184 keyword_iv_ = new ImageView(); 184 keyword_iv_ = new ImageView();
185 url_iv_ = new ImageView(); 185 url_iv_ = new ImageView();
186 186
187 UpdateImageViews(); 187 UpdateImageViews();
188 188
189 const int related_x = kRelatedControlHorizontalSpacing; 189 const int related_x = kRelatedControlHorizontalSpacing;
190 const int related_y = kRelatedControlVerticalSpacing; 190 const int related_y = kRelatedControlVerticalSpacing;
191 const int unrelated_y = kUnrelatedControlVerticalSpacing; 191 const int unrelated_y = kUnrelatedControlVerticalSpacing;
192 192
193 // View and GridLayout take care of deleting GridLayout for us. 193 // View and GridLayout take care of deleting GridLayout for us.
194 GridLayout* layout = CreatePanelGridLayout(view_); 194 GridLayout* layout = CreatePanelGridLayout(view_);
195 view_->SetLayoutManager(layout); 195 view_->SetLayoutManager(layout);
196 196
197 // Define the structure of the layout. 197 // Define the structure of the layout.
198 198
199 // For the buttons. 199 // For the buttons.
200 views::ColumnSet* column_set = layout->AddColumnSet(0); 200 views::ColumnSet* column_set = layout->AddColumnSet(0);
201 column_set->AddPaddingColumn(1, 0); 201 column_set->AddPaddingColumn(1, 0);
202 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, 202 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
203 GridLayout::USE_PREF, 0, 0); 203 GridLayout::USE_PREF, 0, 0);
204 column_set->AddPaddingColumn(0, related_x); 204 column_set->AddPaddingColumn(0, related_x);
205 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, 205 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
206 GridLayout::USE_PREF, 0, 0); 206 GridLayout::USE_PREF, 0, 0);
207 column_set->LinkColumnSizes(1, 3, -1); 207 column_set->LinkColumnSizes(1, 3, -1);
208 208
209 // For the textfields. 209 // For the Textfields.
210 column_set = layout->AddColumnSet(1); 210 column_set = layout->AddColumnSet(1);
211 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 211 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
212 GridLayout::USE_PREF, 0, 0); 212 GridLayout::USE_PREF, 0, 0);
213 column_set->AddPaddingColumn(0, related_x); 213 column_set->AddPaddingColumn(0, related_x);
214 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, 214 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
215 GridLayout::USE_PREF, 0, 0); 215 GridLayout::USE_PREF, 0, 0);
216 column_set->AddPaddingColumn(0, related_x); 216 column_set->AddPaddingColumn(0, related_x);
217 column_set->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 217 column_set->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
218 GridLayout::USE_PREF, 0, 0); 218 GridLayout::USE_PREF, 0, 0);
219 219
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 266
267 layout->AddPaddingRow(0, related_y); 267 layout->AddPaddingRow(0, related_y);
268 } 268 }
269 269
270 views::Label* EditKeywordController::CreateLabel(int message_id) { 270 views::Label* EditKeywordController::CreateLabel(int message_id) {
271 views::Label* label = new views::Label(l10n_util::GetString(message_id)); 271 views::Label* label = new views::Label(l10n_util::GetString(message_id));
272 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 272 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
273 return label; 273 return label;
274 } 274 }
275 275
276 TextField* EditKeywordController::CreateTextField(const std::wstring& text, 276 Textfield* EditKeywordController::CreateTextfield(const std::wstring& text,
277 bool lowercase) { 277 bool lowercase) {
278 TextField* text_field = new TextField( 278 Textfield* text_field = new Textfield(
279 lowercase ? TextField::STYLE_LOWERCASE : TextField::STYLE_DEFAULT); 279 lowercase ? Textfield::STYLE_LOWERCASE : Textfield::STYLE_DEFAULT);
280 text_field->SetText(text); 280 text_field->SetText(text);
281 text_field->SetController(this); 281 text_field->SetController(this);
282 return text_field; 282 return text_field;
283 } 283 }
284 284
285 bool EditKeywordController::IsURLValid() const { 285 bool EditKeywordController::IsURLValid() const {
286 std::wstring url = GetURL(); 286 std::wstring url = GetURL();
287 if (url.empty()) 287 if (url.empty())
288 return false; 288 return false;
289 289
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 356 }
357 357
358 void EditKeywordController::CleanUpCancelledAdd() { 358 void EditKeywordController::CleanUpCancelledAdd() {
359 if (!keyword_editor_view_ && template_url_) { 359 if (!keyword_editor_view_ && template_url_) {
360 // When we have no KeywordEditorView, we know that the template_url_ 360 // When we have no KeywordEditorView, we know that the template_url_
361 // hasn't yet been added to the model, so we need to clean it up. 361 // hasn't yet been added to the model, so we need to clean it up.
362 delete template_url_; 362 delete template_url_;
363 template_url_ = NULL; 363 template_url_ = NULL;
364 } 364 }
365 } 365 }
OLDNEW
« no previous file with comments | « chrome/browser/views/edit_keyword_controller.h ('k') | chrome/browser/views/find_bar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698