diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 01:03:53 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 01:03:53 +0000 |
commit | 5dfe0dcc0e08a38284f66b6b882ce6f215ebc120 (patch) | |
tree | d1e60eba92f36ae9370f295bdf6de0666d383f40 /chrome | |
parent | 49cc504342b6b60f152d999f410e59c728925a17 (diff) | |
download | chromium_src-5dfe0dcc0e08a38284f66b6b882ce6f215ebc120.zip chromium_src-5dfe0dcc0e08a38284f66b6b882ce6f215ebc120.tar.gz chromium_src-5dfe0dcc0e08a38284f66b6b882ce6f215ebc120.tar.bz2 |
Windows: Replace tabs in content settings with a listbox.
Depends on http://codereview.chromium.org/2815034
BUG=45546
TEST=Open content settings dialog. Should have a list on the left instead of tabs on top. Other than that, the dialog should work as before.
Review URL: http://codereview.chromium.org/2799042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51205 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
3 files changed, 103 insertions, 62 deletions
diff --git a/chrome/browser/views/options/content_filter_page_view.cc b/chrome/browser/views/options/content_filter_page_view.cc index 0327206..58f7c63 100644 --- a/chrome/browser/views/options/content_filter_page_view.cc +++ b/chrome/browser/views/options/content_filter_page_view.cc @@ -35,7 +35,6 @@ void ContentFilterPageView::InitControlLayout() { using views::GridLayout; GridLayout* layout = new GridLayout(this); - layout->SetInsets(5, 5, 5, 5); SetLayoutManager(layout); const int single_column_set_id = 0; diff --git a/chrome/browser/views/options/content_settings_window_view.cc b/chrome/browser/views/options/content_settings_window_view.cc index 36ba610..cece814 100644 --- a/chrome/browser/views/options/content_settings_window_view.cc +++ b/chrome/browser/views/options/content_settings_window_view.cc @@ -6,6 +6,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "base/stl_util-inl.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" @@ -19,14 +20,16 @@ #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" -#include "views/controls/tabbed_pane/tabbed_pane.h" +#include "views/controls/label.h" #include "views/widget/root_view.h" #include "views/window/dialog_delegate.h" #include "views/window/window.h" static ContentSettingsWindowView* instance_ = NULL; // Content setting dialog bounds padding. -static const int kDialogPadding = 7; +const int kDialogPadding = 7; +// Width of the page selector lisbox. +const int kListboxWidth = 100; namespace browser { @@ -52,14 +55,17 @@ ContentSettingsWindowView::ContentSettingsWindowView(Profile* profile) // Always show preferences for the original profile. Most state when off // the record comes from the original profile, but we explicitly use // the original profile to avoid potential problems. - : tabs_(NULL), - profile_(profile->GetOriginalProfile()) { + : profile_(profile->GetOriginalProfile()), + label_(NULL), + listbox_(NULL), + current_page_(0) { // We don't need to observe changes in this value. last_selected_page_.Init(prefs::kContentSettingsWindowLastTabIndex, profile->GetPrefs(), NULL); } ContentSettingsWindowView::~ContentSettingsWindowView() { + STLDeleteElements(&pages_); } void ContentSettingsWindowView::ShowContentSettingsTab( @@ -74,10 +80,11 @@ void ContentSettingsWindowView::ShowContentSettingsTab( page = CONTENT_SETTINGS_TYPE_COOKIES; } // If the page number is out of bounds, reset to the first tab. - if (page < 0 || page >= tabs_->GetTabCount()) + if (page < 0 || page >= listbox_->GetRowCount()) page = CONTENT_SETTINGS_TYPE_COOKIES; - tabs_->SelectTabAt(static_cast<int>(page)); + listbox_->SelectRow(static_cast<int>(page)); + ShowSettingsPage(listbox_->SelectedRow()); } /////////////////////////////////////////////////////////////////////////////// @@ -100,19 +107,36 @@ views::View* ContentSettingsWindowView::GetContentsView() { } /////////////////////////////////////////////////////////////////////////////// -// ContentSettingsWindowView, views::TabbedPane::Listener implementation: +// ContentSettingsWindowView, views::Listbox::Listener implementation: -void ContentSettingsWindowView::TabSelectedAt(int index) { - last_selected_page_.SetValue(index); +void ContentSettingsWindowView::ListboxSelectionChanged( + views::Listbox* sender) { + DCHECK_EQ(listbox_, sender); + ShowSettingsPage(listbox_->SelectedRow()); + last_selected_page_.SetValue(current_page_); } /////////////////////////////////////////////////////////////////////////////// // ContentSettingsWindowView, views::View overrides: void ContentSettingsWindowView::Layout() { - tabs_->SetBounds(kDialogPadding, kDialogPadding, - width() - (2 * kDialogPadding), - height() - (2 * kDialogPadding)); + label_->SetBounds(kDialogPadding, + kDialogPadding, + kListboxWidth, + label_->GetPreferredSize().height()); + + listbox_->SetBounds(kDialogPadding, + 2 * kDialogPadding + label_->height(), + kListboxWidth, + height() - (3 * kDialogPadding) - label_->height()); + + if (pages_[current_page_]->GetParent()) { + pages_[current_page_]->SetBounds( + 2 * kDialogPadding + kListboxWidth, + 2 * kDialogPadding + label_->height(), + width() - (3 * kDialogPadding) - kListboxWidth, + height() - (2 * kDialogPadding)); + } } gfx::Size ContentSettingsWindowView::GetPreferredSize() { @@ -135,50 +159,50 @@ void ContentSettingsWindowView::ViewHierarchyChanged(bool is_add, void ContentSettingsWindowView::Init() { // Make sure we don't leak memory by calling this twice. - DCHECK(!tabs_); - tabs_ = new views::TabbedPane; - tabs_->SetListener(this); - AddChildView(tabs_); - int tab_index = 0; - - CookieFilterPageView* cookie_page = new CookieFilterPageView(profile_); - tabs_->AddTabAtIndex(tab_index++, - l10n_util::GetString(IDS_COOKIES_TAB_LABEL), - cookie_page, false); - - ContentFilterPageView* image_page = - new ContentFilterPageView(profile_, CONTENT_SETTINGS_TYPE_IMAGES); - tabs_->AddTabAtIndex(tab_index++, - l10n_util::GetString(IDS_IMAGES_TAB_LABEL), - image_page, false); - - ContentFilterPageView* javascript_page = - new ContentFilterPageView(profile_, CONTENT_SETTINGS_TYPE_JAVASCRIPT); - tabs_->AddTabAtIndex(tab_index++, - l10n_util::GetString(IDS_JAVASCRIPT_TAB_LABEL), - javascript_page, false); - - PluginFilterPageView* plugin_page = new PluginFilterPageView(profile_); - tabs_->AddTabAtIndex(tab_index++, - l10n_util::GetString(IDS_PLUGIN_TAB_LABEL), - plugin_page, false); - - ContentFilterPageView* popup_page = - new ContentFilterPageView(profile_, CONTENT_SETTINGS_TYPE_POPUPS); - tabs_->AddTabAtIndex(tab_index++, - l10n_util::GetString(IDS_POPUP_TAB_LABEL), - popup_page, false); - - ContentFilterPageView* geolocation_page = - new ContentFilterPageView(profile_, CONTENT_SETTINGS_TYPE_GEOLOCATION); - tabs_->AddTabAtIndex(tab_index++, - l10n_util::GetString(IDS_GEOLOCATION_TAB_LABEL), - geolocation_page, false); - - DCHECK_EQ(tabs_->GetTabCount(), CONTENT_SETTINGS_NUM_TYPES); + DCHECK(!listbox_); + + label_ = new views::Label( + l10n_util::GetStringUTF16(IDS_CONTENT_SETTINGS_FEATURES_LABEL)); + label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + AddChildView(label_); + + pages_.push_back(new CookieFilterPageView(profile_)); + pages_.push_back( + new ContentFilterPageView(profile_, CONTENT_SETTINGS_TYPE_IMAGES)); + pages_.push_back( + new ContentFilterPageView(profile_, CONTENT_SETTINGS_TYPE_JAVASCRIPT)); + pages_.push_back(new PluginFilterPageView(profile_)); + pages_.push_back( + new ContentFilterPageView(profile_, CONTENT_SETTINGS_TYPE_POPUPS)); + pages_.push_back( + new ContentFilterPageView(profile_, CONTENT_SETTINGS_TYPE_GEOLOCATION)); + for (size_t i = 0; i < pages_.size(); ++i) { + pages_[i]->set_parent_owned(false); + } + DCHECK_EQ(static_cast<int>(pages_.size()), CONTENT_SETTINGS_NUM_TYPES); + + std::vector<string16> strings; + strings.push_back(l10n_util::GetStringUTF16(IDS_COOKIES_TAB_LABEL)); + strings.push_back(l10n_util::GetStringUTF16(IDS_IMAGES_TAB_LABEL)); + strings.push_back(l10n_util::GetStringUTF16(IDS_JAVASCRIPT_TAB_LABEL)); + strings.push_back(l10n_util::GetStringUTF16(IDS_PLUGIN_TAB_LABEL)); + strings.push_back(l10n_util::GetStringUTF16(IDS_POPUP_TAB_LABEL)); + strings.push_back(l10n_util::GetStringUTF16(IDS_GEOLOCATION_TAB_LABEL)); + listbox_ = new views::Listbox(strings, this); + AddChildView(listbox_); + CHECK_EQ(strings.size(), pages_.size()); +} + +void ContentSettingsWindowView::ShowSettingsPage(int page) { + if (pages_[current_page_]->GetParent()) + RemoveChildView(pages_[current_page_]); + current_page_ = page; + AddChildView(pages_[current_page_]); + Layout(); + SchedulePaint(); } const OptionsPageView* ContentSettingsWindowView::GetCurrentContentSettingsTabView() const { - return static_cast<OptionsPageView*>(tabs_->GetSelectedTab()); + return static_cast<OptionsPageView*>(pages_[current_page_]); } diff --git a/chrome/browser/views/options/content_settings_window_view.h b/chrome/browser/views/options/content_settings_window_view.h index 60b190c..f97f219 100644 --- a/chrome/browser/views/options/content_settings_window_view.h +++ b/chrome/browser/views/options/content_settings_window_view.h @@ -7,7 +7,7 @@ #include "chrome/browser/pref_member.h" #include "chrome/common/content_settings_types.h" -#include "views/controls/tabbed_pane/tabbed_pane.h" +#include "views/controls/listbox/listbox.h" #include "views/view.h" #include "views/window/dialog_delegate.h" @@ -15,6 +15,10 @@ class Profile; class MessageLoop; class OptionsPageView; +namespace views { +class Label; +} // namespace views + /////////////////////////////////////////////////////////////////////////////// // ContentSettingsWindowView // @@ -22,7 +26,7 @@ class OptionsPageView; // class ContentSettingsWindowView : public views::View, public views::DialogDelegate, - public views::TabbedPane::Listener { + public views::Listbox::Listener { public: explicit ContentSettingsWindowView(Profile* profile); virtual ~ContentSettingsWindowView(); @@ -47,25 +51,39 @@ class ContentSettingsWindowView : public views::View, virtual bool Cancel(); virtual views::View* GetContentsView(); - // views::TabbedPane::Listener implementation: - virtual void TabSelectedAt(int index); + // views::Listbox::Listener implementation: + virtual void ListboxSelectionChanged(views::Listbox* sender); private: // Initializes the view. void Init(); + // Makes |pages_[page]| the currently visible page. + void ShowSettingsPage(int page); + // Returns the currently selected OptionsPageView. const OptionsPageView* GetCurrentContentSettingsTabView() const; - // The Tab view that contains all of the options pages. - views::TabbedPane* tabs_; - // The Profile associated with these options. Profile* profile_; + // The label above the left box. + views::Label* label_; + + // The listbox used to select a page. + views::Listbox* listbox_; + // The last page the user was on when they opened the Options window. IntegerPrefMember last_selected_page_; + // Stores the index of the currently visible page. + int current_page_; + + // Stores the possible content pages displayed on the right. + // |pages_[current_page_]| is the currently displayed page, and it's the only + // parented View in |pages_|. + std::vector<View*> pages_; + DISALLOW_COPY_AND_ASSIGN(ContentSettingsWindowView); }; |