| 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/general_page_view.h" | 5 #include "chrome/browser/views/options/general_page_view.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/gfx/png_decoder.h" | 9 #include "base/gfx/png_decoder.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 *index = static_cast<int>(i); | 375 *index = static_cast<int>(i); |
| 376 return &entries_[i]; | 376 return &entries_[i]; |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 return NULL; | 379 return NULL; |
| 380 } | 380 } |
| 381 | 381 |
| 382 /////////////////////////////////////////////////////////////////////////////// | 382 /////////////////////////////////////////////////////////////////////////////// |
| 383 // SearchEngineListModel | 383 // SearchEngineListModel |
| 384 | 384 |
| 385 class SearchEngineListModel : public views::ComboBox::Model, | 385 class SearchEngineListModel : public views::Combobox::Model, |
| 386 public TemplateURLModelObserver { | 386 public TemplateURLModelObserver { |
| 387 public: | 387 public: |
| 388 explicit SearchEngineListModel(Profile* profile); | 388 explicit SearchEngineListModel(Profile* profile); |
| 389 virtual ~SearchEngineListModel(); | 389 virtual ~SearchEngineListModel(); |
| 390 | 390 |
| 391 // Sets the ComboBox. SearchEngineListModel needs a handle to the ComboBox | 391 // Sets the Combobox. SearchEngineListModel needs a handle to the Combobox |
| 392 // so that when the TemplateURLModel changes the combobox can be updated. | 392 // so that when the TemplateURLModel changes the combobox can be updated. |
| 393 void SetComboBox(views::ComboBox* combo_box); | 393 void SetCombobox(views::Combobox* combobox); |
| 394 | 394 |
| 395 // views::ComboBox::Model overrides: | 395 // views::Combobox::Model overrides: |
| 396 virtual int GetItemCount(views::ComboBox* source); | 396 virtual int GetItemCount(views::Combobox* source); |
| 397 virtual std::wstring GetItemAt(views::ComboBox* source, int index); | 397 virtual std::wstring GetItemAt(views::Combobox* source, int index); |
| 398 | 398 |
| 399 // Returns the TemplateURL at the specified index. | 399 // Returns the TemplateURL at the specified index. |
| 400 const TemplateURL* GetTemplateURLAt(int index); | 400 const TemplateURL* GetTemplateURLAt(int index); |
| 401 | 401 |
| 402 TemplateURLModel* model() { return template_url_model_; } | 402 TemplateURLModel* model() { return template_url_model_; } |
| 403 | 403 |
| 404 private: | 404 private: |
| 405 // TemplateURLModelObserver methods. | 405 // TemplateURLModelObserver methods. |
| 406 virtual void OnTemplateURLModelChanged(); | 406 virtual void OnTemplateURLModelChanged(); |
| 407 | 407 |
| 408 // Recalculates the TemplateURLs to display and notifies the combobox. | 408 // Recalculates the TemplateURLs to display and notifies the combobox. |
| 409 void ResetContents(); | 409 void ResetContents(); |
| 410 | 410 |
| 411 // Resets the selection of the combobox based on the users selected search | 411 // Resets the selection of the combobox based on the users selected search |
| 412 // engine. | 412 // engine. |
| 413 void ChangeComboBoxSelection(); | 413 void ChangeComboboxSelection(); |
| 414 | 414 |
| 415 TemplateURLModel* template_url_model_; | 415 TemplateURLModel* template_url_model_; |
| 416 | 416 |
| 417 // The combobox hosting us. | 417 // The combobox hosting us. |
| 418 views::ComboBox* combo_box_; | 418 views::Combobox* combobox_; |
| 419 | 419 |
| 420 // The TemplateURLs we're showing. | 420 // The TemplateURLs we're showing. |
| 421 typedef std::vector<const TemplateURL*> TemplateURLs; | 421 typedef std::vector<const TemplateURL*> TemplateURLs; |
| 422 TemplateURLs template_urls_; | 422 TemplateURLs template_urls_; |
| 423 | 423 |
| 424 DISALLOW_COPY_AND_ASSIGN(SearchEngineListModel); | 424 DISALLOW_COPY_AND_ASSIGN(SearchEngineListModel); |
| 425 }; | 425 }; |
| 426 | 426 |
| 427 SearchEngineListModel::SearchEngineListModel(Profile* profile) | 427 SearchEngineListModel::SearchEngineListModel(Profile* profile) |
| 428 : template_url_model_(profile->GetTemplateURLModel()), | 428 : template_url_model_(profile->GetTemplateURLModel()), |
| 429 combo_box_(NULL) { | 429 combobox_(NULL) { |
| 430 if (template_url_model_) { | 430 if (template_url_model_) { |
| 431 template_url_model_->Load(); | 431 template_url_model_->Load(); |
| 432 template_url_model_->AddObserver(this); | 432 template_url_model_->AddObserver(this); |
| 433 } | 433 } |
| 434 ResetContents(); | 434 ResetContents(); |
| 435 } | 435 } |
| 436 | 436 |
| 437 SearchEngineListModel::~SearchEngineListModel() { | 437 SearchEngineListModel::~SearchEngineListModel() { |
| 438 if (template_url_model_) | 438 if (template_url_model_) |
| 439 template_url_model_->RemoveObserver(this); | 439 template_url_model_->RemoveObserver(this); |
| 440 } | 440 } |
| 441 | 441 |
| 442 void SearchEngineListModel::SetComboBox(views::ComboBox* combo_box) { | 442 void SearchEngineListModel::SetCombobox(views::Combobox* combobox) { |
| 443 combo_box_ = combo_box; | 443 combobox_ = combobox; |
| 444 if (template_url_model_ && template_url_model_->loaded()) | 444 if (template_url_model_ && template_url_model_->loaded()) |
| 445 ChangeComboBoxSelection(); | 445 ChangeComboboxSelection(); |
| 446 else | 446 else |
| 447 combo_box_->SetEnabled(false); | 447 combobox_->SetEnabled(false); |
| 448 } | 448 } |
| 449 | 449 |
| 450 int SearchEngineListModel::GetItemCount(views::ComboBox* source) { | 450 int SearchEngineListModel::GetItemCount(views::Combobox* source) { |
| 451 return static_cast<int>(template_urls_.size()); | 451 return static_cast<int>(template_urls_.size()); |
| 452 } | 452 } |
| 453 | 453 |
| 454 std::wstring SearchEngineListModel::GetItemAt(views::ComboBox* source, | 454 std::wstring SearchEngineListModel::GetItemAt(views::Combobox* source, |
| 455 int index) { | 455 int index) { |
| 456 DCHECK(index < GetItemCount(combo_box_)); | 456 DCHECK(index < GetItemCount(combobox_)); |
| 457 return template_urls_[index]->short_name(); | 457 return template_urls_[index]->short_name(); |
| 458 } | 458 } |
| 459 | 459 |
| 460 const TemplateURL* SearchEngineListModel::GetTemplateURLAt(int index) { | 460 const TemplateURL* SearchEngineListModel::GetTemplateURLAt(int index) { |
| 461 DCHECK(index >= 0 && index < static_cast<int>(template_urls_.size())); | 461 DCHECK(index >= 0 && index < static_cast<int>(template_urls_.size())); |
| 462 return template_urls_[static_cast<int>(index)]; | 462 return template_urls_[static_cast<int>(index)]; |
| 463 } | 463 } |
| 464 | 464 |
| 465 void SearchEngineListModel::OnTemplateURLModelChanged() { | 465 void SearchEngineListModel::OnTemplateURLModelChanged() { |
| 466 ResetContents(); | 466 ResetContents(); |
| 467 } | 467 } |
| 468 | 468 |
| 469 void SearchEngineListModel::ResetContents() { | 469 void SearchEngineListModel::ResetContents() { |
| 470 if (!template_url_model_ || !template_url_model_->loaded()) | 470 if (!template_url_model_ || !template_url_model_->loaded()) |
| 471 return; | 471 return; |
| 472 template_urls_.clear(); | 472 template_urls_.clear(); |
| 473 TemplateURLs model_urls = template_url_model_->GetTemplateURLs(); | 473 TemplateURLs model_urls = template_url_model_->GetTemplateURLs(); |
| 474 for (size_t i = 0; i < model_urls.size(); ++i) { | 474 for (size_t i = 0; i < model_urls.size(); ++i) { |
| 475 if (model_urls[i]->ShowInDefaultList()) | 475 if (model_urls[i]->ShowInDefaultList()) |
| 476 template_urls_.push_back(model_urls[i]); | 476 template_urls_.push_back(model_urls[i]); |
| 477 } | 477 } |
| 478 | 478 |
| 479 if (combo_box_) { | 479 if (combobox_) { |
| 480 combo_box_->ModelChanged(); | 480 combobox_->ModelChanged(); |
| 481 ChangeComboBoxSelection(); | 481 ChangeComboboxSelection(); |
| 482 } | 482 } |
| 483 } | 483 } |
| 484 | 484 |
| 485 void SearchEngineListModel::ChangeComboBoxSelection() { | 485 void SearchEngineListModel::ChangeComboboxSelection() { |
| 486 if (template_urls_.size()) { | 486 if (template_urls_.size()) { |
| 487 combo_box_->SetEnabled(true); | 487 combobox_->SetEnabled(true); |
| 488 | 488 |
| 489 const TemplateURL* default_search_provider = | 489 const TemplateURL* default_search_provider = |
| 490 template_url_model_->GetDefaultSearchProvider(); | 490 template_url_model_->GetDefaultSearchProvider(); |
| 491 if (default_search_provider) { | 491 if (default_search_provider) { |
| 492 TemplateURLs::iterator i = | 492 TemplateURLs::iterator i = |
| 493 find(template_urls_.begin(), template_urls_.end(), | 493 find(template_urls_.begin(), template_urls_.end(), |
| 494 default_search_provider); | 494 default_search_provider); |
| 495 if (i != template_urls_.end()) { | 495 if (i != template_urls_.end()) { |
| 496 combo_box_->SetSelectedItem( | 496 combobox_->SetSelectedItem( |
| 497 static_cast<int>(i - template_urls_.begin())); | 497 static_cast<int>(i - template_urls_.begin())); |
| 498 } | 498 } |
| 499 } | 499 } |
| 500 } else { | 500 } else { |
| 501 combo_box_->SetEnabled(false); | 501 combobox_->SetEnabled(false); |
| 502 } | 502 } |
| 503 } | 503 } |
| 504 | 504 |
| 505 /////////////////////////////////////////////////////////////////////////////// | 505 /////////////////////////////////////////////////////////////////////////////// |
| 506 // GeneralPageView, public: | 506 // GeneralPageView, public: |
| 507 | 507 |
| 508 GeneralPageView::GeneralPageView(Profile* profile) | 508 GeneralPageView::GeneralPageView(Profile* profile) |
| 509 : startup_group_(NULL), | 509 : startup_group_(NULL), |
| 510 startup_homepage_radio_(NULL), | 510 startup_homepage_radio_(NULL), |
| 511 startup_last_session_radio_(NULL), | 511 startup_last_session_radio_(NULL), |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 // If the user made Chrome the default browser, then he/she arguably wants | 588 // If the user made Chrome the default browser, then he/she arguably wants |
| 589 // to be notified when that changes. | 589 // to be notified when that changes. |
| 590 profile()->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, true); | 590 profile()->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, true); |
| 591 } else if (sender == default_search_manage_engines_button_) { | 591 } else if (sender == default_search_manage_engines_button_) { |
| 592 UserMetricsRecordAction(L"Options_ManageSearchEngines", NULL); | 592 UserMetricsRecordAction(L"Options_ManageSearchEngines", NULL); |
| 593 KeywordEditorView::Show(profile()); | 593 KeywordEditorView::Show(profile()); |
| 594 } | 594 } |
| 595 } | 595 } |
| 596 | 596 |
| 597 /////////////////////////////////////////////////////////////////////////////// | 597 /////////////////////////////////////////////////////////////////////////////// |
| 598 // GeneralPageView, views::ComboBox::Listener implementation: | 598 // GeneralPageView, views::Combobox::Listener implementation: |
| 599 | 599 |
| 600 void GeneralPageView::ItemChanged(views::ComboBox* combo_box, | 600 void GeneralPageView::ItemChanged(views::Combobox* combobox, |
| 601 int prev_index, int new_index) { | 601 int prev_index, int new_index) { |
| 602 if (combo_box == default_search_engine_combobox_) { | 602 if (combobox == default_search_engine_combobox_) { |
| 603 SetDefaultSearchProvider(); | 603 SetDefaultSearchProvider(); |
| 604 UserMetricsRecordAction(L"Options_SearchEngineChanged", NULL); | 604 UserMetricsRecordAction(L"Options_SearchEngineChanged", NULL); |
| 605 } | 605 } |
| 606 } | 606 } |
| 607 | 607 |
| 608 /////////////////////////////////////////////////////////////////////////////// | 608 /////////////////////////////////////////////////////////////////////////////// |
| 609 // GeneralPageView, views::Textfield::Controller implementation: | 609 // GeneralPageView, views::Textfield::Controller implementation: |
| 610 | 610 |
| 611 void GeneralPageView::ContentsChanged(views::Textfield* sender, | 611 void GeneralPageView::ContentsChanged(views::Textfield* sender, |
| 612 const std::wstring& new_contents) { | 612 const std::wstring& new_contents) { |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 | 913 |
| 914 homepage_group_ = new OptionsGroupView( | 914 homepage_group_ = new OptionsGroupView( |
| 915 contents, l10n_util::GetString(IDS_OPTIONS_HOMEPAGE_GROUP_NAME), | 915 contents, l10n_util::GetString(IDS_OPTIONS_HOMEPAGE_GROUP_NAME), |
| 916 EmptyWString(), true); | 916 EmptyWString(), true); |
| 917 } | 917 } |
| 918 | 918 |
| 919 | 919 |
| 920 void GeneralPageView::InitDefaultSearchGroup() { | 920 void GeneralPageView::InitDefaultSearchGroup() { |
| 921 default_search_engines_model_.reset(new SearchEngineListModel(profile())); | 921 default_search_engines_model_.reset(new SearchEngineListModel(profile())); |
| 922 default_search_engine_combobox_ = | 922 default_search_engine_combobox_ = |
| 923 new views::ComboBox(default_search_engines_model_.get()); | 923 new views::Combobox(default_search_engines_model_.get()); |
| 924 default_search_engines_model_->SetComboBox(default_search_engine_combobox_); | 924 default_search_engines_model_->SetCombobox(default_search_engine_combobox_); |
| 925 default_search_engine_combobox_->SetListener(this); | 925 default_search_engine_combobox_->set_listener(this); |
| 926 | 926 |
| 927 default_search_manage_engines_button_ = new views::NativeButton( | 927 default_search_manage_engines_button_ = new views::NativeButton( |
| 928 this, | 928 this, |
| 929 l10n_util::GetString(IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES_LINK)); | 929 l10n_util::GetString(IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES_LINK)); |
| 930 | 930 |
| 931 using views::GridLayout; | 931 using views::GridLayout; |
| 932 using views::ColumnSet; | 932 using views::ColumnSet; |
| 933 | 933 |
| 934 views::View* contents = new views::View; | 934 views::View* contents = new views::View; |
| 935 GridLayout* layout = new GridLayout(contents); | 935 GridLayout* layout = new GridLayout(contents); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 if (enabled) { | 1080 if (enabled) { |
| 1081 homepage_use_url_textfield_->SetEnabled(true); | 1081 homepage_use_url_textfield_->SetEnabled(true); |
| 1082 homepage_use_url_textfield_->SetReadOnly(false); | 1082 homepage_use_url_textfield_->SetReadOnly(false); |
| 1083 } else { | 1083 } else { |
| 1084 homepage_use_url_textfield_->SetEnabled(false); | 1084 homepage_use_url_textfield_->SetEnabled(false); |
| 1085 homepage_use_url_textfield_->SetReadOnly(true); | 1085 homepage_use_url_textfield_->SetReadOnly(true); |
| 1086 } | 1086 } |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 void GeneralPageView::SetDefaultSearchProvider() { | 1089 void GeneralPageView::SetDefaultSearchProvider() { |
| 1090 const int index = default_search_engine_combobox_->GetSelectedItem(); | 1090 const int index = default_search_engine_combobox_->selected_item(); |
| 1091 default_search_engines_model_->model()->SetDefaultSearchProvider( | 1091 default_search_engines_model_->model()->SetDefaultSearchProvider( |
| 1092 default_search_engines_model_->GetTemplateURLAt(index)); | 1092 default_search_engines_model_->GetTemplateURLAt(index)); |
| 1093 } | 1093 } |
| OLD | NEW |