diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-09 22:22:08 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-09 22:22:08 +0000 |
commit | 99e4d4c0c61ca0d7548097520fb4dbeb998086f9 (patch) | |
tree | d9ca68fe9ae6c242acc8663a6d34ef485de7b377 /views | |
parent | 8a4751337e754922bf46834b8b3c277a4dcdb44b (diff) | |
download | chromium_src-99e4d4c0c61ca0d7548097520fb4dbeb998086f9.zip chromium_src-99e4d4c0c61ca0d7548097520fb4dbeb998086f9.tar.gz chromium_src-99e4d4c0c61ca0d7548097520fb4dbeb998086f9.tar.bz2 |
Multi-Profiles: Add icon chooser to profiles menu
This change adds an icon chooser grid to the profiles menu. This is only implemented for toolkit views for now.
Screenshots: http://www.dropmocks.com/mXGba
BUG=
TEST=
Review URL: http://codereview.chromium.org/7331017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91958 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/menu/menu_item_view.cc | 37 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view.h | 4 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view_gtk.cc | 6 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view_win.cc | 6 |
4 files changed, 36 insertions, 17 deletions
diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc index a47e5d3..a20e725 100644 --- a/views/controls/menu/menu_item_view.cc +++ b/views/controls/menu/menu_item_view.cc @@ -484,14 +484,22 @@ void MenuItemView::Layout() { if (!has_children()) return; - // Child views are laid out right aligned and given the full height. To right - // align start with the last view and progress to the first. - for (int i = child_count() - 1, x = width() - item_right_margin_; i >= 0; - --i) { - View* child = GetChildViewAt(i); - int width = child->GetPreferredSize().width(); - child->SetBounds(x - width, 0, width, height()); - x -= width - kChildXPadding; + if (child_count() == 1 && GetTitle().size() == 0) { + // We only have one child and no title so let the view take over all the + // space. + View* child = GetChildViewAt(0); + gfx::Size size = child->GetPreferredSize(); + child->SetBounds(label_start_, GetTopMargin(), size.width(), size.height()); + } else { + // Child views are laid out right aligned and given the full height. To + // right align start with the last view and progress to the first. + for (int i = child_count() - 1, x = width() - item_right_margin_; i >= 0; + --i) { + View* child = GetChildViewAt(i); + int width = child->GetPreferredSize().width(); + child->SetBounds(x - width, 0, width, height()); + x -= width - kChildXPadding; + } } } @@ -732,9 +740,14 @@ int MenuItemView::GetBottomMargin() { MenuConfig::instance().item_no_icon_bottom_margin; } -int MenuItemView::GetChildPreferredWidth() { +gfx::Size MenuItemView::GetChildPreferredSize() { if (!has_children()) - return 0; + return gfx::Size(); + + if (GetTitle().size() == 0 && child_count() == 1) { + View* child = GetChildViewAt(0); + return child->GetPreferredSize(); + } int width = 0; for (int i = 0; i < child_count(); ++i) { @@ -742,7 +755,9 @@ int MenuItemView::GetChildPreferredWidth() { width += kChildXPadding; width += GetChildViewAt(i)->GetPreferredSize().width(); } - return width; + // Return a height of 0 to indicate that we should use the title height + // instead. + return gfx::Size(width, 0); } string16 MenuItemView::GetAcceleratorText() { diff --git a/views/controls/menu/menu_item_view.h b/views/controls/menu/menu_item_view.h index 9f5c9b3..3f952f7 100644 --- a/views/controls/menu/menu_item_view.h +++ b/views/controls/menu/menu_item_view.h @@ -406,8 +406,8 @@ class MenuItemView : public View { int GetTopMargin(); int GetBottomMargin(); - // Returns the preferred width (and padding) of any children. - int GetChildPreferredWidth(); + // Returns the preferred size (and padding) of any children. + gfx::Size GetChildPreferredSize(); // Calculates the preferred size. gfx::Size CalculatePreferredSize(); diff --git a/views/controls/menu/menu_item_view_gtk.cc b/views/controls/menu/menu_item_view_gtk.cc index 9ff9ca1..d6dbd35 100644 --- a/views/controls/menu/menu_item_view_gtk.cc +++ b/views/controls/menu/menu_item_view_gtk.cc @@ -35,10 +35,12 @@ gfx::Size MenuItemView::CalculatePreferredSize() { #else int height = font.GetHeight(); #endif + gfx::Size child_size = GetChildPreferredSize(); return gfx::Size( font.GetStringWidth(title_) + label_start_ + - item_right_margin_ + GetChildPreferredWidth(), - height + GetBottomMargin() + GetTopMargin()); + item_right_margin_ + child_size.width(), + std::max(height, child_size.height()) + GetBottomMargin() + + GetTopMargin()); } void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { diff --git a/views/controls/menu/menu_item_view_win.cc b/views/controls/menu/menu_item_view_win.cc index 92d7384..923e268 100644 --- a/views/controls/menu/menu_item_view_win.cc +++ b/views/controls/menu/menu_item_view_win.cc @@ -18,11 +18,13 @@ using gfx::NativeTheme; namespace views { gfx::Size MenuItemView::CalculatePreferredSize() { + gfx::Size child_size = GetChildPreferredSize(); const gfx::Font& font = GetFont(); return gfx::Size( font.GetStringWidth(title_) + label_start_ + item_right_margin_ + - GetChildPreferredWidth(), - font.GetHeight() + GetBottomMargin() + GetTopMargin()); + child_size.width(), + std::max(child_size.height(), font.GetHeight()) + GetBottomMargin() + + GetTopMargin()); } void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { |