diff options
author | mhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-30 15:21:42 +0000 |
---|---|---|
committer | mhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-30 15:21:42 +0000 |
commit | 644a39b80d0c77fb9cf6c3763069d603c183fb79 (patch) | |
tree | b0ea9c03ffd11c23d092b2c1ef2b262c289ecdad /chrome/browser/views/options/content_page_view.cc | |
parent | d5bb49f89c538c191bca3993cd423784f47a90ec (diff) | |
download | chromium_src-644a39b80d0c77fb9cf6c3763069d603c183fb79.zip chromium_src-644a39b80d0c77fb9cf6c3763069d603c183fb79.tar.gz chromium_src-644a39b80d0c77fb9cf6c3763069d603c183fb79.tar.bz2 |
Create a "User data" tab and remove the "minor tweaks" tab. The mockup is included in the issue.
Add new option fields to the "User Data" tab and reorganize the "Under the Hood" to fit a better User Experience.
BUG=11435 (http://crbug.com/11435)
TEST=Opened the option dialog and checked if functional.
Review URL: http://codereview.chromium.org/113896
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17288 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/options/content_page_view.cc')
-rw-r--r-- | chrome/browser/views/options/content_page_view.cc | 406 |
1 files changed, 97 insertions, 309 deletions
diff --git a/chrome/browser/views/options/content_page_view.cc b/chrome/browser/views/options/content_page_view.cc index 639e0e7..adbd1d7 100644 --- a/chrome/browser/views/options/content_page_view.cc +++ b/chrome/browser/views/options/content_page_view.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,228 +13,51 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/command_line.h" -#include "base/file_util.h" #include "base/gfx/native_theme.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/shell_dialogs.h" -#include "chrome/browser/views/options/fonts_languages_window_view.h" +#include "chrome/browser/views/clear_browsing_data.h" +#include "chrome/browser/views/importer_view.h" #include "chrome/browser/views/options/options_group_view.h" #include "chrome/browser/views/options/passwords_exceptions_window_view.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" -#include "chrome/common/pref_service.h" -#include "grit/app_resources.h" #include "grit/generated_resources.h" -#include "skia/ext/skia_utils_win.h" -#include "third_party/skia/include/core/SkBitmap.h" #include "views/controls/button/radio_button.h" -#include "views/controls/textfield/textfield.h" #include "views/grid_layout.h" #include "views/standard_layout.h" #include "views/widget/widget.h" namespace { -static const int kPopupBlockingRadioGroup = 1; -static const int kPasswordSavingRadioGroup = 2; -static const int kFileIconSize = 16; -static const int kFileIconVerticalSpacing = 3; -static const int kFileIconHorizontalSpacing = 3; -static const int kFileIconTextfieldSpacing = 3; +const int kPopupBlockingRadioGroup = 1; +const int kPasswordSavingRadioGroup = 2; } // namespace -//////////////////////////////////////////////////////////////////////////////// -// FileDisplayArea - -class FileDisplayArea : public views::View { - public: - FileDisplayArea(); - virtual ~FileDisplayArea(); - - void SetFile(const FilePath& file_path); - - // views::View overrides: - virtual void Paint(gfx::Canvas* canvas); - virtual void Layout(); - virtual gfx::Size GetPreferredSize(); - - protected: - // views::View overrides: - virtual void ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child); - - private: - void Init(); - - views::Textfield* text_field_; - SkColor text_field_background_color_; - - gfx::Rect icon_bounds_; - - bool initialized_; - - static void InitClass(); - static SkBitmap default_folder_icon_; - - DISALLOW_EVIL_CONSTRUCTORS(FileDisplayArea); -}; - -// static -SkBitmap FileDisplayArea::default_folder_icon_; - -FileDisplayArea::FileDisplayArea() - : text_field_(new views::Textfield), - text_field_background_color_(0), - initialized_(false) { - InitClass(); -} - -FileDisplayArea::~FileDisplayArea() { -} - -void FileDisplayArea::SetFile(const FilePath& file_path) { - // Force file path to have LTR directionality. - if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { - string16 localized_file_path; - l10n_util::WrapPathWithLTRFormatting(file_path, &localized_file_path); - text_field_->SetText(UTF16ToWide(localized_file_path)); - } else { - text_field_->SetText(file_path.ToWStringHack()); - } -} - -void FileDisplayArea::Paint(gfx::Canvas* canvas) { - HDC dc = canvas->beginPlatformPaint(); - RECT rect = { 0, 0, width(), height() }; - gfx::NativeTheme::instance()->PaintTextField( - dc, EP_EDITTEXT, ETS_READONLY, 0, &rect, - skia::SkColorToCOLORREF(text_field_background_color_), true, true); - canvas->endPlatformPaint(); - // Mirror left point for icon_bounds_ to draw icon in RTL locales correctly. - canvas->DrawBitmapInt(default_folder_icon_, - MirroredLeftPointForRect(icon_bounds_), - icon_bounds_.y()); -} - -void FileDisplayArea::Layout() { - icon_bounds_.SetRect(kFileIconHorizontalSpacing, kFileIconVerticalSpacing, - kFileIconSize, kFileIconSize); - gfx::Size ps = text_field_->GetPreferredSize(); - text_field_->SetBounds(icon_bounds_.right() + kFileIconTextfieldSpacing, - (height() - ps.height()) / 2, - width() - icon_bounds_.right() - - kFileIconHorizontalSpacing - - kFileIconTextfieldSpacing, ps.height()); -} - -gfx::Size FileDisplayArea::GetPreferredSize() { - return gfx::Size(kFileIconSize + 2 * kFileIconVerticalSpacing, - kFileIconSize + 2 * kFileIconHorizontalSpacing); -} - -void FileDisplayArea::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - if (!initialized_ && is_add && GetWidget()) - Init(); -} - -void FileDisplayArea::Init() { - initialized_ = true; - AddChildView(text_field_); - text_field_background_color_ = - gfx::NativeTheme::instance()->GetThemeColorWithDefault( - gfx::NativeTheme::TEXTFIELD, EP_EDITTEXT, ETS_READONLY, - TMT_FILLCOLOR, COLOR_3DFACE); - text_field_->SetReadOnly(true); - text_field_->RemoveBorder(); - text_field_->SetBackgroundColor(text_field_background_color_); -} - -// static -void FileDisplayArea::InitClass() { - static bool initialized = false; - if (!initialized) { - // We'd prefer to use UILayoutIsRightToLeft() to perform the RTL - // environment check, but it's nonstatic, so, instead, we check whether the - // locale is RTL. - bool ui_is_rtl = l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT; - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - default_folder_icon_ = *rb.GetBitmapNamed(ui_is_rtl ? - IDR_FOLDER_CLOSED_RTL : - IDR_FOLDER_CLOSED); - initialized = true; - } -} - -//////////////////////////////////////////////////////////////////////////////// -// ContentPageView, public: - ContentPageView::ContentPageView(Profile* profile) - : download_location_group_(NULL), - download_default_download_location_display_(NULL), - download_browse_button_(NULL), - download_ask_for_save_location_checkbox_(NULL), - ALLOW_THIS_IN_INITIALIZER_LIST( - select_file_dialog_(SelectFileDialog::Create(this))), - passwords_exceptions_button_(NULL), + : passwords_exceptions_button_(NULL), passwords_group_(NULL), passwords_asktosave_radio_(NULL), passwords_neversave_radio_(NULL), - fonts_lang_group_(NULL), - fonts_and_languages_label_(NULL), themes_group_(NULL), themes_reset_button_(NULL), - change_content_fonts_button_(NULL), + import_group_(NULL), + import_label_(NULL), + import_button_(NULL), + clear_data_group_(NULL), + clear_data_label_(NULL), + clear_data_button_(NULL), OptionsPageView(profile) { } ContentPageView::~ContentPageView() { - select_file_dialog_->ListenerDestroyed(); -} - -//////////////////////////////////////////////////////////////////////////////// -// ContentPageView, SelectFileDialog::Listener implementation: - -void ContentPageView::FileSelected(const FilePath& path, - int index, void* params) { - UserMetricsRecordAction(L"Options_SetDownloadDirectory", - profile()->GetPrefs()); - default_download_location_.SetValue(path.ToWStringHack()); - // We need to call this manually here since because we're setting the value - // through the pref member which avoids notifying the listener that set the - // value. - UpdateDownloadDirectoryDisplay(); } /////////////////////////////////////////////////////////////////////////////// // ContentPageView, views::ButtonListener implementation: void ContentPageView::ButtonPressed(views::Button* sender) { - if (sender == download_browse_button_) { - const std::wstring dialog_title = - l10n_util::GetString(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE); - select_file_dialog_->SelectFile(SelectFileDialog::SELECT_FOLDER, - dialog_title, - FilePath::FromWStringHack( - profile()->GetPrefs()->GetString( - prefs::kDownloadDefaultDirectory)), - NULL, 0, std::wstring(), - GetWindow()->GetNativeWindow(), - NULL); - } else if (sender == download_ask_for_save_location_checkbox_) { - bool enabled = download_ask_for_save_location_checkbox_->checked(); - if (enabled) { - UserMetricsRecordAction(L"Options_AskForSaveLocation_Enable", - profile()->GetPrefs()); - } else { - UserMetricsRecordAction(L"Options_AskForSaveLocation_Disable", - profile()->GetPrefs()); - } - ask_for_save_location_.SetValue(enabled); - } else if (sender == passwords_asktosave_radio_ || - sender == passwords_neversave_radio_) { + if (sender == passwords_asktosave_radio_ || + sender == passwords_neversave_radio_) { bool enabled = passwords_asktosave_radio_->checked(); if (enabled) { UserMetricsRecordAction(L"Options_PasswordManager_Enable", @@ -257,24 +80,25 @@ void ContentPageView::ButtonPressed(views::Button* sender) { profile()->GetPrefs()); } form_autofill_.SetValue(enabled); - } else if (sender == change_content_fonts_button_) { - views::Window::CreateChromeWindow( - GetWindow()->GetNativeWindow(), - gfx::Rect(), - new FontsLanguagesWindowView(profile()))->Show(); } else if (sender == themes_reset_button_) { UserMetricsRecordAction(L"Options_ThemesReset", profile()->GetPrefs()); profile()->ClearTheme(); + } else if (sender == import_button_) { + views::Window::CreateChromeWindow( + GetWindow()->GetNativeWindow(), + gfx::Rect(), + new ImporterView(profile()))->Show(); + } else if (sender == clear_data_button_) { + views::Window::CreateChromeWindow( + GetWindow()->GetNativeWindow(), + gfx::Rect(), + new ClearBrowsingDataView(profile()))->Show(); } } //////////////////////////////////////////////////////////////////////////////// // ContentPageView, OptionsPageView implementation: -bool ContentPageView::CanClose() const { - return !select_file_dialog_->IsRunning(GetWindow()->GetNativeWindow()); -} - void ContentPageView::InitControlLayout() { using views::GridLayout; using views::ColumnSet; @@ -288,23 +112,23 @@ void ContentPageView::InitControlLayout() { column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, GridLayout::USE_PREF, 0, 0); layout->StartRow(0, single_column_view_set_id); - InitDownloadLocation(); - layout->AddView(download_location_group_); + InitPasswordSavingGroup(); + layout->AddView(passwords_group_); layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); layout->StartRow(0, single_column_view_set_id); - InitPasswordSavingGroup(); - layout->AddView(passwords_group_); + InitFormAutofillGroup(); + layout->AddView(form_autofill_group_); layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); layout->StartRow(0, single_column_view_set_id); - InitFontsLangGroup(); - layout->AddView(fonts_lang_group_); + InitImportGroup(); + layout->AddView(import_group_); layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); layout->StartRow(0, single_column_view_set_id); - InitFormAutofillGroup(); - layout->AddView(form_autofill_group_); + InitClearDataGroup(); + layout->AddView(clear_data_group_); layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); if (CommandLine::ForCurrentProcess()-> @@ -316,23 +140,12 @@ void ContentPageView::InitControlLayout() { } // Init member prefs so we can update the controls if prefs change. - default_download_location_.Init(prefs::kDownloadDefaultDirectory, - profile()->GetPrefs(), this); - ask_for_save_location_.Init(prefs::kPromptForDownload, - profile()->GetPrefs(), this); ask_to_save_passwords_.Init(prefs::kPasswordManagerEnabled, profile()->GetPrefs(), this); form_autofill_.Init(prefs::kFormAutofillEnabled, profile()->GetPrefs(), this); } void ContentPageView::NotifyPrefChanged(const std::wstring* pref_name) { - if (!pref_name || *pref_name == prefs::kDownloadDefaultDirectory) - UpdateDownloadDirectoryDisplay(); - - if (!pref_name || *pref_name == prefs::kPromptForDownload) { - download_ask_for_save_location_checkbox_->SetChecked( - ask_for_save_location_.GetValue()); - } if (!pref_name || *pref_name == prefs::kPasswordManagerEnabled) { if (ask_to_save_passwords_.GetValue()) { passwords_asktosave_radio_->SetChecked(true); @@ -351,14 +164,12 @@ void ContentPageView::NotifyPrefChanged(const std::wstring* pref_name) { void ContentPageView::Layout() { // We need to Layout twice - once to get the width of the contents box... View::Layout(); - download_ask_for_save_location_checkbox_->SetBounds( - 0, 0, download_location_group_->GetContentsWidth(), 0); passwords_asktosave_radio_->SetBounds( 0, 0, passwords_group_->GetContentsWidth(), 0); passwords_neversave_radio_->SetBounds( 0, 0, passwords_group_->GetContentsWidth(), 0); - fonts_and_languages_label_->SetBounds( - 0, 0, fonts_lang_group_->GetContentsWidth(), 0); + import_label_->SetBounds(0, 0, import_group_->GetContentsWidth(), 0); + clear_data_label_->SetBounds(0, 0, clear_data_group_->GetContentsWidth(), 0); // ... and twice to get the height of multi-line items correct. View::Layout(); } @@ -366,53 +177,6 @@ void ContentPageView::Layout() { /////////////////////////////////////////////////////////////////////////////// // ContentPageView, private: -void ContentPageView::InitDownloadLocation() { - download_default_download_location_display_ = new FileDisplayArea; - download_browse_button_ = new views::NativeButton( - this, l10n_util::GetString(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_BUTTON)); - - download_ask_for_save_location_checkbox_ = new views::Checkbox( - l10n_util::GetString(IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION)); - download_ask_for_save_location_checkbox_->set_listener(this); - download_ask_for_save_location_checkbox_->SetMultiLine(true); - - using views::GridLayout; - using views::ColumnSet; - - views::View* contents = new views::View; - GridLayout* layout = new GridLayout(contents); - contents->SetLayoutManager(layout); - - const int double_column_view_set_id = 0; - ColumnSet* column_set = layout->AddColumnSet(double_column_view_set_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, kUnrelatedControlHorizontalSpacing); - - layout->StartRow(0, double_column_view_set_id); - layout->AddView(download_default_download_location_display_, 1, 1, - GridLayout::FILL, GridLayout::CENTER); - layout->AddView(download_browse_button_); - - layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); - - const int single_column_view_set_id = 1; - column_set = layout->AddColumnSet(single_column_view_set_id); - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, single_column_view_set_id); - layout->AddView(download_ask_for_save_location_checkbox_); - - download_location_group_ = new OptionsGroupView( - contents, l10n_util::GetString(IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME), - std::wstring(), - true); -} - void ContentPageView::InitPasswordSavingGroup() { passwords_asktosave_radio_ = new views::RadioButton( l10n_util::GetString(IDS_OPTIONS_PASSWORDS_ASKTOSAVE), @@ -461,39 +225,6 @@ void ContentPageView::InitPasswordSavingGroup() { true); } -void ContentPageView::InitFontsLangGroup() { - fonts_and_languages_label_ = new views::Label( - l10n_util::GetString(IDS_OPTIONS_FONTSETTINGS_INFO)); - fonts_and_languages_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - fonts_and_languages_label_->SetMultiLine(true); - change_content_fonts_button_ = new views::NativeButton( - this, - l10n_util::GetString(IDS_OPTIONS_FONTSETTINGS_CONFIGUREFONTS_BUTTON)); - - using views::GridLayout; - using views::ColumnSet; - - views::View* contents = new views::View; - GridLayout* layout = new GridLayout(contents); - contents->SetLayoutManager(layout); - - const int single_column_view_set_id = 1; - ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); - - layout->StartRow(0, single_column_view_set_id); - layout->AddView(fonts_and_languages_label_); - layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); - layout->StartRow(0, single_column_view_set_id); - layout->AddView(change_content_fonts_button_); - - fonts_lang_group_ = new OptionsGroupView( - contents, - l10n_util::GetString(IDS_OPTIONS_FONTSANDLANGUAGES_GROUP_NAME), - L"", true); -} - void ContentPageView::InitFormAutofillGroup() { form_autofill_checkbox_ = new views::Checkbox( l10n_util::GetString(IDS_AUTOFILL_SAVEFORMS)); @@ -534,17 +265,74 @@ void ContentPageView::InitThemesGroup() { const int single_column_view_set_id = 1; ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, - GridLayout::USE_PREF, 0, 0); + GridLayout::USE_PREF, 0, 0); layout->StartRow(0, single_column_view_set_id); layout->AddView(themes_reset_button_); themes_group_ = new OptionsGroupView( - contents, l10n_util::GetString(IDS_THEMES_GROUP_NAME), - L"", false); + contents, l10n_util::GetString(IDS_THEMES_GROUP_NAME), + L"", false); +} + +void ContentPageView::InitClearDataGroup() { + clear_data_button_ = new views::NativeButton(this, + l10n_util::GetString(IDS_OPTIONS_CLEAR_DATA_BUTTON)); + clear_data_label_ = new views::Label( + l10n_util::GetString(IDS_OPTIONS_CLEAR_DATA_INFO)); + clear_data_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + clear_data_label_->SetMultiLine(true); + + using views::GridLayout; + using views::ColumnSet; + + views::View* contents = new views::View; + GridLayout* layout = new GridLayout(contents); + contents->SetLayoutManager(layout); + + const int single_column_view_set_id = 1; + ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); + column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, + GridLayout::USE_PREF, 0, 0); + + layout->StartRow(0, single_column_view_set_id); + layout->AddView(clear_data_label_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, single_column_view_set_id); + layout->AddView(clear_data_button_); + + clear_data_group_ = new OptionsGroupView( + contents, l10n_util::GetString(IDS_OPTIONS_CLEAR_DATA_GROUP_NAME), + L"", true); } -void ContentPageView::UpdateDownloadDirectoryDisplay() { - download_default_download_location_display_->SetFile( - FilePath::FromWStringHack(default_download_location_.GetValue())); +void ContentPageView::InitImportGroup() { + import_button_ = new views::NativeButton(this, + l10n_util::GetString(IDS_OPTIONS_IMPORT_DATA_BUTTON)); + import_label_ = new views::Label( + l10n_util::GetString(IDS_OPTIONS_IMPORT_DATA_INFO)); + import_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + import_label_->SetMultiLine(true); + + using views::GridLayout; + using views::ColumnSet; + + views::View* contents = new views::View; + GridLayout* layout = new GridLayout(contents); + contents->SetLayoutManager(layout); + + const int single_column_view_set_id = 1; + ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); + column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, + GridLayout::USE_PREF, 0, 0); + + layout->StartRow(0, single_column_view_set_id); + layout->AddView(import_label_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, single_column_view_set_id); + layout->AddView(import_button_); + + import_group_ = new OptionsGroupView( + contents, l10n_util::GetString(IDS_OPTIONS_IMPORT_DATA_GROUP_NAME), + L"", true); } |