OLD | NEW |
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/options/cookies_view.h" | 5 #include "chrome/browser/views/options/cookies_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/gfx/canvas.h" | 9 #include "app/gfx/canvas.h" |
10 #include "app/gfx/color_utils.h" | 10 #include "app/gfx/color_utils.h" |
11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
12 #include "app/resource_bundle.h" | 12 #include "app/resource_bundle.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/time_format.h" | 15 #include "base/time_format.h" |
16 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
18 #include "grit/locale_settings.h" | 18 #include "grit/locale_settings.h" |
19 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
20 #include "net/base/cookie_monster.h" | 20 #include "net/base/cookie_monster.h" |
21 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
22 #include "views/border.h" | 22 #include "views/border.h" |
23 #include "views/grid_layout.h" | 23 #include "views/grid_layout.h" |
24 #include "views/controls/label.h" | 24 #include "views/controls/label.h" |
25 #include "views/controls/button/native_button.h" | 25 #include "views/controls/button/native_button.h" |
26 #include "views/controls/text_field.h" | |
27 #include "views/controls/table/table_view.h" | 26 #include "views/controls/table/table_view.h" |
| 27 #include "views/controls/textfield/textfield.h" |
28 #include "views/standard_layout.h" | 28 #include "views/standard_layout.h" |
29 | 29 |
30 // static | 30 // static |
31 views::Window* CookiesView::instance_ = NULL; | 31 views::Window* CookiesView::instance_ = NULL; |
32 static const int kCookieInfoViewBorderSize = 1; | 32 static const int kCookieInfoViewBorderSize = 1; |
33 static const int kCookieInfoViewInsetSize = 3; | 33 static const int kCookieInfoViewInsetSize = 3; |
34 static const int kSearchFilterDelayMs = 500; | 34 static const int kSearchFilterDelayMs = 500; |
35 | 35 |
36 /////////////////////////////////////////////////////////////////////////////// | 36 /////////////////////////////////////////////////////////////////////////////// |
37 // CookiesTableModel | 37 // CookiesTableModel |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 virtual void ViewHierarchyChanged(bool is_add, | 332 virtual void ViewHierarchyChanged(bool is_add, |
333 views::View* parent, | 333 views::View* parent, |
334 views::View* child); | 334 views::View* child); |
335 | 335 |
336 private: | 336 private: |
337 // Set up the view layout | 337 // Set up the view layout |
338 void Init(); | 338 void Init(); |
339 | 339 |
340 // Individual property labels | 340 // Individual property labels |
341 views::Label* name_label_; | 341 views::Label* name_label_; |
342 views::TextField* name_value_field_; | 342 views::Textfield* name_value_field_; |
343 views::Label* content_label_; | 343 views::Label* content_label_; |
344 views::TextField* content_value_field_; | 344 views::Textfield* content_value_field_; |
345 views::Label* domain_label_; | 345 views::Label* domain_label_; |
346 views::TextField* domain_value_field_; | 346 views::Textfield* domain_value_field_; |
347 views::Label* path_label_; | 347 views::Label* path_label_; |
348 views::TextField* path_value_field_; | 348 views::Textfield* path_value_field_; |
349 views::Label* send_for_label_; | 349 views::Label* send_for_label_; |
350 views::TextField* send_for_value_field_; | 350 views::Textfield* send_for_value_field_; |
351 views::Label* created_label_; | 351 views::Label* created_label_; |
352 views::TextField* created_value_field_; | 352 views::Textfield* created_value_field_; |
353 views::Label* expires_label_; | 353 views::Label* expires_label_; |
354 views::TextField* expires_value_field_; | 354 views::Textfield* expires_value_field_; |
355 | 355 |
356 DISALLOW_COPY_AND_ASSIGN(CookieInfoView); | 356 DISALLOW_COPY_AND_ASSIGN(CookieInfoView); |
357 }; | 357 }; |
358 | 358 |
359 /////////////////////////////////////////////////////////////////////////////// | 359 /////////////////////////////////////////////////////////////////////////////// |
360 // CookieInfoView, public: | 360 // CookieInfoView, public: |
361 | 361 |
362 CookieInfoView::CookieInfoView() | 362 CookieInfoView::CookieInfoView() |
363 : name_label_(NULL), | 363 : name_label_(NULL), |
364 name_value_field_(NULL), | 364 name_value_field_(NULL), |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 // CookieInfoView, private: | 446 // CookieInfoView, private: |
447 | 447 |
448 void CookieInfoView::Init() { | 448 void CookieInfoView::Init() { |
449 SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); | 449 SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); |
450 views::Border* border = views::Border::CreateSolidBorder( | 450 views::Border* border = views::Border::CreateSolidBorder( |
451 kCookieInfoViewBorderSize, border_color); | 451 kCookieInfoViewBorderSize, border_color); |
452 set_border(border); | 452 set_border(border); |
453 | 453 |
454 name_label_ = new views::Label( | 454 name_label_ = new views::Label( |
455 l10n_util::GetString(IDS_COOKIES_COOKIE_NAME_LABEL)); | 455 l10n_util::GetString(IDS_COOKIES_COOKIE_NAME_LABEL)); |
456 name_value_field_ = new views::TextField; | 456 name_value_field_ = new views::Textfield; |
457 content_label_ = new views::Label( | 457 content_label_ = new views::Label( |
458 l10n_util::GetString(IDS_COOKIES_COOKIE_CONTENT_LABEL)); | 458 l10n_util::GetString(IDS_COOKIES_COOKIE_CONTENT_LABEL)); |
459 content_value_field_ = new views::TextField; | 459 content_value_field_ = new views::Textfield; |
460 domain_label_ = new views::Label( | 460 domain_label_ = new views::Label( |
461 l10n_util::GetString(IDS_COOKIES_COOKIE_DOMAIN_LABEL)); | 461 l10n_util::GetString(IDS_COOKIES_COOKIE_DOMAIN_LABEL)); |
462 domain_value_field_ = new views::TextField; | 462 domain_value_field_ = new views::Textfield; |
463 path_label_ = new views::Label( | 463 path_label_ = new views::Label( |
464 l10n_util::GetString(IDS_COOKIES_COOKIE_PATH_LABEL)); | 464 l10n_util::GetString(IDS_COOKIES_COOKIE_PATH_LABEL)); |
465 path_value_field_ = new views::TextField; | 465 path_value_field_ = new views::Textfield; |
466 send_for_label_ = new views::Label( | 466 send_for_label_ = new views::Label( |
467 l10n_util::GetString(IDS_COOKIES_COOKIE_SENDFOR_LABEL)); | 467 l10n_util::GetString(IDS_COOKIES_COOKIE_SENDFOR_LABEL)); |
468 send_for_value_field_ = new views::TextField; | 468 send_for_value_field_ = new views::Textfield; |
469 created_label_ = new views::Label( | 469 created_label_ = new views::Label( |
470 l10n_util::GetString(IDS_COOKIES_COOKIE_CREATED_LABEL)); | 470 l10n_util::GetString(IDS_COOKIES_COOKIE_CREATED_LABEL)); |
471 created_value_field_ = new views::TextField; | 471 created_value_field_ = new views::Textfield; |
472 expires_label_ = new views::Label( | 472 expires_label_ = new views::Label( |
473 l10n_util::GetString(IDS_COOKIES_COOKIE_EXPIRES_LABEL)); | 473 l10n_util::GetString(IDS_COOKIES_COOKIE_EXPIRES_LABEL)); |
474 expires_value_field_ = new views::TextField; | 474 expires_value_field_ = new views::Textfield; |
475 | 475 |
476 using views::GridLayout; | 476 using views::GridLayout; |
477 using views::ColumnSet; | 477 using views::ColumnSet; |
478 | 478 |
479 GridLayout* layout = new GridLayout(this); | 479 GridLayout* layout = new GridLayout(this); |
480 layout->SetInsets(kCookieInfoViewInsetSize, | 480 layout->SetInsets(kCookieInfoViewInsetSize, |
481 kCookieInfoViewInsetSize, | 481 kCookieInfoViewInsetSize, |
482 kCookieInfoViewInsetSize, | 482 kCookieInfoViewInsetSize, |
483 kCookieInfoViewInsetSize); | 483 kCookieInfoViewInsetSize); |
484 SetLayoutManager(layout); | 484 SetLayoutManager(layout); |
(...skipping 29 matching lines...) Expand all Loading... |
514 layout->StartRow(0, three_column_layout_id); | 514 layout->StartRow(0, three_column_layout_id); |
515 layout->AddView(created_label_); | 515 layout->AddView(created_label_); |
516 layout->AddView(created_value_field_); | 516 layout->AddView(created_value_field_); |
517 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); | 517 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); |
518 layout->StartRow(0, three_column_layout_id); | 518 layout->StartRow(0, three_column_layout_id); |
519 layout->AddView(expires_label_); | 519 layout->AddView(expires_label_); |
520 layout->AddView(expires_value_field_); | 520 layout->AddView(expires_value_field_); |
521 | 521 |
522 // Color these borderless text areas the same as the containing dialog. | 522 // Color these borderless text areas the same as the containing dialog. |
523 SkColor text_area_background = color_utils::GetSysSkColor(COLOR_3DFACE); | 523 SkColor text_area_background = color_utils::GetSysSkColor(COLOR_3DFACE); |
524 // Now that the TextFields are in the view hierarchy, we can initialize them. | 524 // Now that the Textfields are in the view hierarchy, we can initialize them. |
525 name_value_field_->SetReadOnly(true); | 525 name_value_field_->SetReadOnly(true); |
526 name_value_field_->RemoveBorder(); | 526 name_value_field_->RemoveBorder(); |
527 name_value_field_->SetBackgroundColor(text_area_background); | 527 name_value_field_->SetBackgroundColor(text_area_background); |
528 content_value_field_->SetReadOnly(true); | 528 content_value_field_->SetReadOnly(true); |
529 content_value_field_->RemoveBorder(); | 529 content_value_field_->RemoveBorder(); |
530 content_value_field_->SetBackgroundColor(text_area_background); | 530 content_value_field_->SetBackgroundColor(text_area_background); |
531 domain_value_field_->SetReadOnly(true); | 531 domain_value_field_->SetReadOnly(true); |
532 domain_value_field_->RemoveBorder(); | 532 domain_value_field_->RemoveBorder(); |
533 domain_value_field_->SetBackgroundColor(text_area_background); | 533 domain_value_field_->SetBackgroundColor(text_area_background); |
534 path_value_field_->SetReadOnly(true); | 534 path_value_field_->SetReadOnly(true); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 remove_button_->SetEnabled(selected_row_count != 0); | 603 remove_button_->SetEnabled(selected_row_count != 0); |
604 if (cookies_table_->RowCount() == 0) | 604 if (cookies_table_->RowCount() == 0) |
605 UpdateForEmptyState(); | 605 UpdateForEmptyState(); |
606 } | 606 } |
607 | 607 |
608 void CookiesView::OnTableViewDelete(views::TableView* table_view) { | 608 void CookiesView::OnTableViewDelete(views::TableView* table_view) { |
609 cookies_table_->RemoveSelectedCookies(); | 609 cookies_table_->RemoveSelectedCookies(); |
610 } | 610 } |
611 | 611 |
612 /////////////////////////////////////////////////////////////////////////////// | 612 /////////////////////////////////////////////////////////////////////////////// |
613 // CookiesView, views::TextField::Controller implementation: | 613 // CookiesView, views::Textfield::Controller implementation: |
614 | 614 |
615 void CookiesView::ContentsChanged(views::TextField* sender, | 615 void CookiesView::ContentsChanged(views::Textfield* sender, |
616 const std::wstring& new_contents) { | 616 const std::wstring& new_contents) { |
617 search_update_factory_.RevokeAll(); | 617 search_update_factory_.RevokeAll(); |
618 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 618 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
619 search_update_factory_.NewRunnableMethod( | 619 search_update_factory_.NewRunnableMethod( |
620 &CookiesView::UpdateSearchResults), kSearchFilterDelayMs); | 620 &CookiesView::UpdateSearchResults), kSearchFilterDelayMs); |
621 } | 621 } |
622 | 622 |
623 bool CookiesView::HandleKeystroke(views::TextField* sender, | 623 bool CookiesView::HandleKeystroke(views::Textfield* sender, |
624 const views::TextField::Keystroke& key) { | 624 const views::Textfield::Keystroke& key) { |
625 if (views::TextField::IsKeystrokeEscape(key)) { | 625 if (views::Textfield::IsKeystrokeEscape(key)) { |
626 ResetSearchQuery(); | 626 ResetSearchQuery(); |
627 } else if (views::TextField::IsKeystrokeEnter(key)) { | 627 } else if (views::Textfield::IsKeystrokeEnter(key)) { |
628 search_update_factory_.RevokeAll(); | 628 search_update_factory_.RevokeAll(); |
629 UpdateSearchResults(); | 629 UpdateSearchResults(); |
630 } | 630 } |
631 return false; | 631 return false; |
632 } | 632 } |
633 | 633 |
634 /////////////////////////////////////////////////////////////////////////////// | 634 /////////////////////////////////////////////////////////////////////////////// |
635 // CookiesView, views::DialogDelegate implementation: | 635 // CookiesView, views::DialogDelegate implementation: |
636 | 636 |
637 std::wstring CookiesView::GetWindowTitle() const { | 637 std::wstring CookiesView::GetWindowTitle() const { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 info_view_(NULL), | 693 info_view_(NULL), |
694 remove_button_(NULL), | 694 remove_button_(NULL), |
695 remove_all_button_(NULL), | 695 remove_all_button_(NULL), |
696 profile_(profile), | 696 profile_(profile), |
697 ALLOW_THIS_IN_INITIALIZER_LIST(search_update_factory_(this)) { | 697 ALLOW_THIS_IN_INITIALIZER_LIST(search_update_factory_(this)) { |
698 } | 698 } |
699 | 699 |
700 void CookiesView::Init() { | 700 void CookiesView::Init() { |
701 search_label_ = new views::Label( | 701 search_label_ = new views::Label( |
702 l10n_util::GetString(IDS_COOKIES_SEARCH_LABEL)); | 702 l10n_util::GetString(IDS_COOKIES_SEARCH_LABEL)); |
703 search_field_ = new views::TextField; | 703 search_field_ = new views::Textfield; |
704 search_field_->SetController(this); | 704 search_field_->SetController(this); |
705 clear_search_button_ = new views::NativeButton( | 705 clear_search_button_ = new views::NativeButton( |
706 this, l10n_util::GetString(IDS_COOKIES_CLEAR_SEARCH_LABEL)); | 706 this, l10n_util::GetString(IDS_COOKIES_CLEAR_SEARCH_LABEL)); |
707 description_label_ = new views::Label( | 707 description_label_ = new views::Label( |
708 l10n_util::GetString(IDS_COOKIES_INFO_LABEL)); | 708 l10n_util::GetString(IDS_COOKIES_INFO_LABEL)); |
709 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 709 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
710 | 710 |
711 cookies_table_model_.reset(new CookiesTableModel(profile_)); | 711 cookies_table_model_.reset(new CookiesTableModel(profile_)); |
712 info_view_ = new CookieInfoView; | 712 info_view_ = new CookieInfoView; |
713 std::vector<views::TableColumn> columns; | 713 std::vector<views::TableColumn> columns; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 void CookiesView::ResetSearchQuery() { | 781 void CookiesView::ResetSearchQuery() { |
782 search_field_->SetText(EmptyWString()); | 782 search_field_->SetText(EmptyWString()); |
783 UpdateSearchResults(); | 783 UpdateSearchResults(); |
784 } | 784 } |
785 | 785 |
786 void CookiesView::UpdateForEmptyState() { | 786 void CookiesView::UpdateForEmptyState() { |
787 info_view_->ClearCookieDisplay(); | 787 info_view_->ClearCookieDisplay(); |
788 remove_button_->SetEnabled(false); | 788 remove_button_->SetEnabled(false); |
789 remove_all_button_->SetEnabled(false); | 789 remove_all_button_->SetEnabled(false); |
790 } | 790 } |
OLD | NEW |