OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/shelf_item_dialog.h" | 5 #include "chrome/browser/views/shelf_item_dialog.h" |
6 | 6 |
7 #include "app/gfx/text_elider.h" | 7 #include "app/gfx/text_elider.h" |
8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
10 #include "base/gfx/png_decoder.h" | 10 #include "base/gfx/png_decoder.h" |
11 #include "base/stl_util-inl.h" | 11 #include "base/stl_util-inl.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "chrome/browser/net/url_fixer_upper.h" | 13 #include "chrome/browser/net/url_fixer_upper.h" |
14 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
15 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "chrome/common/pref_service.h" | 17 #include "chrome/common/pref_service.h" |
18 #include "grit/app_resources.h" | 18 #include "grit/app_resources.h" |
19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
20 #include "grit/locale_settings.h" | 20 #include "grit/locale_settings.h" |
21 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
22 #include "views/background.h" | 22 #include "views/background.h" |
23 #include "views/controls/label.h" | 23 #include "views/controls/label.h" |
24 #include "views/controls/text_field.h" | 24 #include "views/controls/textfield/textfield.h" |
25 #include "views/focus/focus_manager.h" | 25 #include "views/focus/focus_manager.h" |
26 #include "views/grid_layout.h" | 26 #include "views/grid_layout.h" |
27 #include "views/standard_layout.h" | 27 #include "views/standard_layout.h" |
28 #include "views/widget/widget.h" | 28 #include "views/widget/widget.h" |
29 | 29 |
30 using base::Time; | 30 using base::Time; |
31 using base::TimeDelta; | 31 using base::TimeDelta; |
32 using views::ColumnSet; | 32 using views::ColumnSet; |
33 using views::GridLayout; | 33 using views::GridLayout; |
34 | 34 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 297 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
298 GridLayout::FIXED, kTableWidth, 0); | 298 GridLayout::FIXED, kTableWidth, 0); |
299 | 299 |
300 if (show_title) { | 300 if (show_title) { |
301 layout->StartRow(0, labels_column_set_id); | 301 layout->StartRow(0, labels_column_set_id); |
302 views::Label* title_label = new views::Label(); | 302 views::Label* title_label = new views::Label(); |
303 title_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 303 title_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
304 title_label->SetText(l10n_util::GetString(IDS_ASI_TITLE_LABEL)); | 304 title_label->SetText(l10n_util::GetString(IDS_ASI_TITLE_LABEL)); |
305 layout->AddView(title_label); | 305 layout->AddView(title_label); |
306 | 306 |
307 title_field_ = new views::TextField(); | 307 title_field_ = new views::Textfield(); |
308 title_field_->SetController(this); | 308 title_field_->SetController(this); |
309 layout->AddView(title_field_); | 309 layout->AddView(title_field_); |
310 | 310 |
311 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 311 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
312 } else { | 312 } else { |
313 title_field_ = NULL; | 313 title_field_ = NULL; |
314 } | 314 } |
315 | 315 |
316 layout->StartRow(0, labels_column_set_id); | 316 layout->StartRow(0, labels_column_set_id); |
317 views::Label* url_label = new views::Label(); | 317 views::Label* url_label = new views::Label(); |
318 url_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 318 url_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
319 url_label->SetText(l10n_util::GetString(IDS_ASI_URL)); | 319 url_label->SetText(l10n_util::GetString(IDS_ASI_URL)); |
320 layout->AddView(url_label); | 320 layout->AddView(url_label); |
321 | 321 |
322 url_field_ = new views::TextField(); | 322 url_field_ = new views::Textfield(); |
323 url_field_->SetController(this); | 323 url_field_->SetController(this); |
324 layout->AddView(url_field_); | 324 layout->AddView(url_field_); |
325 | 325 |
326 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); | 326 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); |
327 | 327 |
328 layout->StartRow(0, single_column_view_set_id); | 328 layout->StartRow(0, single_column_view_set_id); |
329 views::Label* description_label = new views::Label(); | 329 views::Label* description_label = new views::Label(); |
330 description_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 330 description_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
331 description_label->SetText(l10n_util::GetString(IDS_ASI_DESCRIPTION)); | 331 description_label->SetText(l10n_util::GetString(IDS_ASI_DESCRIPTION)); |
332 description_label->SetFont( | 332 description_label->SetFont( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 if (handle != expected_title_handle_) | 390 if (handle != expected_title_handle_) |
391 return; | 391 return; |
392 | 392 |
393 std::wstring s; | 393 std::wstring s; |
394 if (success) | 394 if (success) |
395 s = info->title(); | 395 s = info->title(); |
396 if (s.empty()) | 396 if (s.empty()) |
397 s = l10n_util::GetString(IDS_ASI_DEFAULT_TITLE); | 397 s = l10n_util::GetString(IDS_ASI_DEFAULT_TITLE); |
398 | 398 |
399 if (title_field_) { | 399 if (title_field_) { |
400 // expected_title_handle_ is reset if the title textfield is edited so we | 400 // expected_title_handle_ is reset if the title Textfield is edited so we |
401 // can safely set the value. | 401 // can safely set the value. |
402 title_field_->SetText(s); | 402 title_field_->SetText(s); |
403 title_field_->SelectAll(); | 403 title_field_->SelectAll(); |
404 } | 404 } |
405 expected_title_handle_ = 0; | 405 expected_title_handle_ = 0; |
406 } | 406 } |
407 | 407 |
408 void ShelfItemDialog::InitiateTitleAutoFill(const GURL& url) { | 408 void ShelfItemDialog::InitiateTitleAutoFill(const GURL& url) { |
409 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 409 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
410 if (!hs) | 410 if (!hs) |
411 return; | 411 return; |
412 | 412 |
413 if (expected_title_handle_) | 413 if (expected_title_handle_) |
414 hs->CancelRequest(expected_title_handle_); | 414 hs->CancelRequest(expected_title_handle_); |
415 | 415 |
416 expected_title_handle_ = hs->QueryURL(url, false, &history_consumer_, | 416 expected_title_handle_ = hs->QueryURL(url, false, &history_consumer_, |
417 NewCallback(this, &ShelfItemDialog::OnURLInfoAvailable)); | 417 NewCallback(this, &ShelfItemDialog::OnURLInfoAvailable)); |
418 } | 418 } |
419 | 419 |
420 void ShelfItemDialog::ContentsChanged(views::TextField* sender, | 420 void ShelfItemDialog::ContentsChanged(views::Textfield* sender, |
421 const std::wstring& new_contents) { | 421 const std::wstring& new_contents) { |
422 // If the user has edited the title field we no longer want to autofill it | 422 // If the user has edited the title field we no longer want to autofill it |
423 // so we reset the expected handle to an impossible value. | 423 // so we reset the expected handle to an impossible value. |
424 if (sender == title_field_) | 424 if (sender == title_field_) |
425 expected_title_handle_ = 0; | 425 expected_title_handle_ = 0; |
426 GetDialogClientView()->UpdateDialogButtons(); | 426 GetDialogClientView()->UpdateDialogButtons(); |
427 } | 427 } |
428 | 428 |
429 bool ShelfItemDialog::Accept() { | 429 bool ShelfItemDialog::Accept() { |
430 if (!IsDialogButtonEnabled(MessageBoxFlags::DIALOGBUTTON_OK)) { | 430 if (!IsDialogButtonEnabled(MessageBoxFlags::DIALOGBUTTON_OK)) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 OnSelectionChanged(); | 514 OnSelectionChanged(); |
515 PerformModelChange(); | 515 PerformModelChange(); |
516 if (window()) | 516 if (window()) |
517 window()->Close(); | 517 window()->Close(); |
518 } | 518 } |
519 } | 519 } |
520 | 520 |
521 GURL ShelfItemDialog::GetInputURL() const { | 521 GURL ShelfItemDialog::GetInputURL() const { |
522 return GURL(URLFixerUpper::FixupURL(url_field_->GetText(), L"")); | 522 return GURL(URLFixerUpper::FixupURL(url_field_->GetText(), L"")); |
523 } | 523 } |
OLD | NEW |