| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/general_page_view.h" | 5 #include "chrome/browser/views/options/general_page_view.h" |
| 6 | 6 |
| 7 #include "app/combobox_model.h" | 7 #include "app/combobox_model.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "base/string_number_conversions.h" |
| 12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/browser.h" | 15 #include "chrome/browser/browser.h" |
| 15 #include "chrome/browser/browser_window.h" | 16 #include "chrome/browser/browser_window.h" |
| 16 #include "chrome/browser/custom_home_pages_table_model.h" | 17 #include "chrome/browser/custom_home_pages_table_model.h" |
| 17 #include "chrome/browser/dom_ui/new_tab_ui.h" | 18 #include "chrome/browser/dom_ui/new_tab_ui.h" |
| 18 #include "chrome/browser/instant/instant_confirm_dialog.h" | 19 #include "chrome/browser/instant/instant_confirm_dialog.h" |
| 20 #include "chrome/browser/instant/instant_controller.h" |
| 19 #include "chrome/browser/net/url_fixer_upper.h" | 21 #include "chrome/browser/net/url_fixer_upper.h" |
| 20 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
| 21 #include "chrome/browser/profile.h" | 23 #include "chrome/browser/profile.h" |
| 22 #include "chrome/browser/prefs/session_startup_pref.h" | 24 #include "chrome/browser/prefs/session_startup_pref.h" |
| 23 #include "chrome/browser/search_engines/template_url.h" | 25 #include "chrome/browser/search_engines/template_url.h" |
| 24 #include "chrome/browser/search_engines/template_url_model.h" | 26 #include "chrome/browser/search_engines/template_url_model.h" |
| 25 #include "chrome/browser/search_engines/template_url_model_observer.h" | 27 #include "chrome/browser/search_engines/template_url_model_observer.h" |
| 26 #include "chrome/browser/show_options_url.h" | 28 #include "chrome/browser/show_options_url.h" |
| 27 #include "chrome/browser/views/keyword_editor_view.h" | 29 #include "chrome/browser/views/keyword_editor_view.h" |
| 28 #include "chrome/browser/views/options/managed_prefs_banner_view.h" | 30 #include "chrome/browser/views/options/managed_prefs_banner_view.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 startup_use_current_page_button_(NULL), | 208 startup_use_current_page_button_(NULL), |
| 207 startup_custom_pages_table_(NULL), | 209 startup_custom_pages_table_(NULL), |
| 208 homepage_group_(NULL), | 210 homepage_group_(NULL), |
| 209 homepage_use_newtab_radio_(NULL), | 211 homepage_use_newtab_radio_(NULL), |
| 210 homepage_use_url_radio_(NULL), | 212 homepage_use_url_radio_(NULL), |
| 211 homepage_use_url_textfield_(NULL), | 213 homepage_use_url_textfield_(NULL), |
| 212 homepage_show_home_button_checkbox_(NULL), | 214 homepage_show_home_button_checkbox_(NULL), |
| 213 default_search_group_(NULL), | 215 default_search_group_(NULL), |
| 214 default_search_manage_engines_button_(NULL), | 216 default_search_manage_engines_button_(NULL), |
| 215 instant_checkbox_(NULL), | 217 instant_checkbox_(NULL), |
| 218 instant_type_label_(NULL), |
| 216 instant_link_(NULL), | 219 instant_link_(NULL), |
| 217 default_browser_group_(NULL), | 220 default_browser_group_(NULL), |
| 218 default_browser_status_label_(NULL), | 221 default_browser_status_label_(NULL), |
| 219 default_browser_use_as_default_button_(NULL), | 222 default_browser_use_as_default_button_(NULL), |
| 220 ALLOW_THIS_IN_INITIALIZER_LIST( | 223 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 221 default_browser_worker_( | 224 default_browser_worker_( |
| 222 new ShellIntegration::DefaultBrowserWorker(this))), | 225 new ShellIntegration::DefaultBrowserWorker(this))), |
| 223 OptionsPageView(profile) { | 226 OptionsPageView(profile) { |
| 224 } | 227 } |
| 225 | 228 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 NULL); | 291 NULL); |
| 289 KeywordEditorView::Show(profile()); | 292 KeywordEditorView::Show(profile()); |
| 290 } else if (sender == instant_checkbox_) { | 293 } else if (sender == instant_checkbox_) { |
| 291 if (instant_checkbox_->checked()) { | 294 if (instant_checkbox_->checked()) { |
| 292 // Don't toggle immediately, instead let | 295 // Don't toggle immediately, instead let |
| 293 // ShowInstantConfirmDialogIfNecessary do it. | 296 // ShowInstantConfirmDialogIfNecessary do it. |
| 294 instant_checkbox_->SetChecked(false); | 297 instant_checkbox_->SetChecked(false); |
| 295 browser::ShowInstantConfirmDialogIfNecessary( | 298 browser::ShowInstantConfirmDialogIfNecessary( |
| 296 GetWindow()->GetNativeWindow(), profile()); | 299 GetWindow()->GetNativeWindow(), profile()); |
| 297 } else { | 300 } else { |
| 298 profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, false); | 301 InstantController::Disable(profile()); |
| 299 } | 302 } |
| 300 } | 303 } |
| 301 } | 304 } |
| 302 | 305 |
| 303 /////////////////////////////////////////////////////////////////////////////// | 306 /////////////////////////////////////////////////////////////////////////////// |
| 304 // GeneralPageView, views::Combobox::Listener implementation: | 307 // GeneralPageView, views::Combobox::Listener implementation: |
| 305 | 308 |
| 306 void GeneralPageView::ItemChanged(views::Combobox* combobox, | 309 void GeneralPageView::ItemChanged(views::Combobox* combobox, |
| 307 int prev_index, int new_index) { | 310 int prev_index, int new_index) { |
| 308 if (combobox == default_search_engine_combobox_) { | 311 if (combobox == default_search_engine_combobox_) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 EnableHomepageURLField(!homepage_is_new_tab); | 437 EnableHomepageURLField(!homepage_is_new_tab); |
| 435 } | 438 } |
| 436 | 439 |
| 437 if (!pref_name || *pref_name == prefs::kShowHomeButton) { | 440 if (!pref_name || *pref_name == prefs::kShowHomeButton) { |
| 438 homepage_show_home_button_checkbox_->SetChecked( | 441 homepage_show_home_button_checkbox_->SetChecked( |
| 439 show_home_button_.GetValue()); | 442 show_home_button_.GetValue()); |
| 440 homepage_show_home_button_checkbox_->SetEnabled( | 443 homepage_show_home_button_checkbox_->SetEnabled( |
| 441 !show_home_button_.IsManaged()); | 444 !show_home_button_.IsManaged()); |
| 442 } | 445 } |
| 443 | 446 |
| 444 if (!pref_name || *pref_name == prefs::kInstantEnabled) | 447 if (!pref_name || *pref_name == prefs::kInstantEnabled) { |
| 445 instant_checkbox_->SetChecked(prefs->GetBoolean(prefs::kInstantEnabled)); | 448 bool is_instant_enabled = prefs->GetBoolean(prefs::kInstantEnabled); |
| 449 instant_checkbox_->SetChecked(is_instant_enabled); |
| 450 if (is_instant_enabled) { |
| 451 instant_type_label_->SetText( |
| 452 L"[" + |
| 453 UTF8ToWide( |
| 454 base::IntToString(prefs->GetInteger(prefs::kInstantType))) + |
| 455 L"]"); |
| 456 } |
| 457 instant_type_label_->SetVisible(is_instant_enabled); |
| 458 instant_type_label_->GetParent()->Layout(); |
| 459 } |
| 446 } | 460 } |
| 447 | 461 |
| 448 void GeneralPageView::HighlightGroup(OptionsGroup highlight_group) { | 462 void GeneralPageView::HighlightGroup(OptionsGroup highlight_group) { |
| 449 if (highlight_group == OPTIONS_GROUP_DEFAULT_SEARCH) | 463 if (highlight_group == OPTIONS_GROUP_DEFAULT_SEARCH) |
| 450 default_search_group_->SetHighlighted(true); | 464 default_search_group_->SetHighlighted(true); |
| 451 } | 465 } |
| 452 | 466 |
| 453 void GeneralPageView::LinkActivated(views::Link* source, int event_flags) { | 467 void GeneralPageView::LinkActivated(views::Link* source, int event_flags) { |
| 454 DCHECK(source == instant_link_); | 468 DCHECK(source == instant_link_); |
| 455 browser::ShowOptionsURL(profile(), | 469 browser::ShowOptionsURL(profile(), |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 new views::Combobox(default_search_engines_model_.get()); | 662 new views::Combobox(default_search_engines_model_.get()); |
| 649 default_search_engines_model_->SetCombobox(default_search_engine_combobox_); | 663 default_search_engines_model_->SetCombobox(default_search_engine_combobox_); |
| 650 default_search_engine_combobox_->set_listener(this); | 664 default_search_engine_combobox_->set_listener(this); |
| 651 | 665 |
| 652 default_search_manage_engines_button_ = new views::NativeButton( | 666 default_search_manage_engines_button_ = new views::NativeButton( |
| 653 this, | 667 this, |
| 654 l10n_util::GetString(IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES_LINK)); | 668 l10n_util::GetString(IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES_LINK)); |
| 655 | 669 |
| 656 instant_checkbox_ = new views::Checkbox( | 670 instant_checkbox_ = new views::Checkbox( |
| 657 l10n_util::GetString(IDS_INSTANT_PREF)); | 671 l10n_util::GetString(IDS_INSTANT_PREF)); |
| 658 instant_checkbox_->SetMultiLine(true); | 672 instant_checkbox_->SetMultiLine(false); |
| 659 instant_checkbox_->set_listener(this); | 673 instant_checkbox_->set_listener(this); |
| 660 | 674 |
| 675 instant_type_label_ = new views::Label(); |
| 676 |
| 661 instant_link_ = new views::Link(l10n_util::GetString(IDS_LEARN_MORE)); | 677 instant_link_ = new views::Link(l10n_util::GetString(IDS_LEARN_MORE)); |
| 662 instant_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 678 instant_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 663 instant_link_->SetController(this); | 679 instant_link_->SetController(this); |
| 664 | 680 |
| 665 using views::GridLayout; | 681 using views::GridLayout; |
| 666 using views::ColumnSet; | 682 using views::ColumnSet; |
| 667 | 683 |
| 668 views::View* contents = new views::View; | 684 views::View* contents = new views::View; |
| 669 GridLayout* layout = new GridLayout(contents); | 685 GridLayout* layout = new GridLayout(contents); |
| 670 contents->SetLayoutManager(layout); | 686 contents->SetLayoutManager(layout); |
| 671 | 687 |
| 672 const int double_column_view_set_id = 0; | 688 const int double_column_view_set_id = 0; |
| 673 ColumnSet* column_set = layout->AddColumnSet(double_column_view_set_id); | 689 ColumnSet* column_set = layout->AddColumnSet(double_column_view_set_id); |
| 674 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 690 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 675 GridLayout::USE_PREF, 0, 0); | 691 GridLayout::USE_PREF, 0, 0); |
| 676 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 692 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 677 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 693 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 678 GridLayout::USE_PREF, 0, 0); | 694 GridLayout::USE_PREF, 0, 0); |
| 679 | 695 |
| 680 const int single_column_view_set_id = 1; | 696 const int checkbox_column_view_set_id = 1; |
| 681 column_set = layout->AddColumnSet(single_column_view_set_id); | 697 column_set = layout->AddColumnSet(checkbox_column_view_set_id); |
| 682 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | 698 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 699 GridLayout::USE_PREF, 0, 0); |
| 700 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 683 GridLayout::USE_PREF, 0, 0); | 701 GridLayout::USE_PREF, 0, 0); |
| 684 | 702 |
| 685 const int link_column_set_id = 2; | 703 const int link_column_set_id = 2; |
| 686 column_set = layout->AddColumnSet(link_column_set_id); | 704 column_set = layout->AddColumnSet(link_column_set_id); |
| 687 // TODO(sky): this isn't right, we need a method to determine real indent. | 705 // TODO(sky): this isn't right, we need a method to determine real indent. |
| 688 column_set->AddPaddingColumn(0, views::Checkbox::GetTextIndent() + 3); | 706 column_set->AddPaddingColumn(0, views::Checkbox::GetTextIndent() + 3); |
| 689 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 707 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 690 GridLayout::USE_PREF, 0, 0); | 708 GridLayout::USE_PREF, 0, 0); |
| 691 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 709 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 692 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 710 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 693 GridLayout::USE_PREF, 0, 0); | 711 GridLayout::USE_PREF, 0, 0); |
| 694 | 712 |
| 695 layout->StartRow(0, double_column_view_set_id); | 713 layout->StartRow(0, double_column_view_set_id); |
| 696 layout->AddView(default_search_engine_combobox_); | 714 layout->AddView(default_search_engine_combobox_); |
| 697 layout->AddView(default_search_manage_engines_button_); | 715 layout->AddView(default_search_manage_engines_button_); |
| 698 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); | 716 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); |
| 699 | 717 |
| 700 layout->StartRow(0, single_column_view_set_id); | 718 layout->StartRow(0, checkbox_column_view_set_id); |
| 701 layout->AddView(instant_checkbox_); | 719 layout->AddView(instant_checkbox_); |
| 720 layout->AddView(instant_type_label_); |
| 702 layout->AddPaddingRow(0, 0); | 721 layout->AddPaddingRow(0, 0); |
| 703 | 722 |
| 704 layout->StartRow(0, link_column_set_id); | 723 layout->StartRow(0, link_column_set_id); |
| 705 layout->AddView( | 724 layout->AddView( |
| 706 new views::Label(l10n_util::GetString(IDS_INSTANT_PREF_WARNING))); | 725 new views::Label(l10n_util::GetString(IDS_INSTANT_PREF_WARNING))); |
| 707 layout->AddView(instant_link_); | 726 layout->AddView(instant_link_); |
| 708 | 727 |
| 709 default_search_group_ = new OptionsGroupView( | 728 default_search_group_ = new OptionsGroupView( |
| 710 contents, l10n_util::GetString(IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME), | 729 contents, l10n_util::GetString(IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME), |
| 711 std::wstring(), true); | 730 std::wstring(), true); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 } | 893 } |
| 875 homepage_use_url_textfield_->SetEnabled(enabled); | 894 homepage_use_url_textfield_->SetEnabled(enabled); |
| 876 homepage_use_url_textfield_->SetReadOnly(!enabled); | 895 homepage_use_url_textfield_->SetReadOnly(!enabled); |
| 877 } | 896 } |
| 878 | 897 |
| 879 void GeneralPageView::SetDefaultSearchProvider() { | 898 void GeneralPageView::SetDefaultSearchProvider() { |
| 880 const int index = default_search_engine_combobox_->selected_item(); | 899 const int index = default_search_engine_combobox_->selected_item(); |
| 881 default_search_engines_model_->model()->SetDefaultSearchProvider( | 900 default_search_engines_model_->model()->SetDefaultSearchProvider( |
| 882 default_search_engines_model_->GetTemplateURLAt(index)); | 901 default_search_engines_model_->GetTemplateURLAt(index)); |
| 883 } | 902 } |
| OLD | NEW |