Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: views/controls/menu/menu_item_view.cc

Issue 7331017: Multi-Profiles: Add icon chooser to profiles menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Multi-Profiles: Add icon chooser to profiles menu Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/menu/menu_item_view.h ('k') | views/controls/menu/menu_item_view_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "views/controls/menu/menu_item_view.h" 5 #include "views/controls/menu/menu_item_view.h"
6 6
7 #include "base/i18n/case_conversion.h" 7 #include "base/i18n/case_conversion.h"
8 #include "base/stl_util-inl.h" 8 #include "base/stl_util-inl.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "grit/ui_strings.h" 10 #include "grit/ui_strings.h"
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 } 477 }
478 } 478 }
479 479
480 STLDeleteElements(&removed_items_); 480 STLDeleteElements(&removed_items_);
481 } 481 }
482 482
483 void MenuItemView::Layout() { 483 void MenuItemView::Layout() {
484 if (!has_children()) 484 if (!has_children())
485 return; 485 return;
486 486
487 // Child views are laid out right aligned and given the full height. To right 487 if (child_count() == 1 && GetTitle().size() == 0) {
488 // align start with the last view and progress to the first. 488 // We only have one child and no title so let the view take over all the
489 for (int i = child_count() - 1, x = width() - item_right_margin_; i >= 0; 489 // space.
490 --i) { 490 View* child = GetChildViewAt(0);
491 View* child = GetChildViewAt(i); 491 gfx::Size size = child->GetPreferredSize();
492 int width = child->GetPreferredSize().width(); 492 child->SetBounds(label_start_, GetTopMargin(), size.width(), size.height());
493 child->SetBounds(x - width, 0, width, height()); 493 } else {
494 x -= width - kChildXPadding; 494 // Child views are laid out right aligned and given the full height. To
495 // right align start with the last view and progress to the first.
496 for (int i = child_count() - 1, x = width() - item_right_margin_; i >= 0;
497 --i) {
498 View* child = GetChildViewAt(i);
499 int width = child->GetPreferredSize().width();
500 child->SetBounds(x - width, 0, width, height());
501 x -= width - kChildXPadding;
502 }
495 } 503 }
496 } 504 }
497 505
498 int MenuItemView::GetAcceleratorTextWidth() { 506 int MenuItemView::GetAcceleratorTextWidth() {
499 string16 text = GetAcceleratorText(); 507 string16 text = GetAcceleratorText();
500 return text.empty() ? 0 : GetFont().GetStringWidth(text); 508 return text.empty() ? 0 : GetFont().GetStringWidth(text);
501 } 509 }
502 510
503 MenuItemView::MenuItemView(MenuItemView* parent, 511 MenuItemView::MenuItemView(MenuItemView* parent,
504 int command, 512 int command,
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 int MenuItemView::GetBottomMargin() { 733 int MenuItemView::GetBottomMargin() {
726 if (bottom_margin_ >= 0) 734 if (bottom_margin_ >= 0)
727 return bottom_margin_; 735 return bottom_margin_;
728 736
729 MenuItemView* root = GetRootMenuItem(); 737 MenuItemView* root = GetRootMenuItem();
730 return root && root->has_icons_ 738 return root && root->has_icons_
731 ? MenuConfig::instance().item_bottom_margin : 739 ? MenuConfig::instance().item_bottom_margin :
732 MenuConfig::instance().item_no_icon_bottom_margin; 740 MenuConfig::instance().item_no_icon_bottom_margin;
733 } 741 }
734 742
735 int MenuItemView::GetChildPreferredWidth() { 743 gfx::Size MenuItemView::GetChildPreferredSize() {
736 if (!has_children()) 744 if (!has_children())
737 return 0; 745 return gfx::Size();
746
747 if (GetTitle().size() == 0 && child_count() == 1) {
748 View* child = GetChildViewAt(0);
749 return child->GetPreferredSize();
750 }
738 751
739 int width = 0; 752 int width = 0;
740 for (int i = 0; i < child_count(); ++i) { 753 for (int i = 0; i < child_count(); ++i) {
741 if (i) 754 if (i)
742 width += kChildXPadding; 755 width += kChildXPadding;
743 width += GetChildViewAt(i)->GetPreferredSize().width(); 756 width += GetChildViewAt(i)->GetPreferredSize().width();
744 } 757 }
745 return width; 758 // Return a height of 0 to indicate that we should use the title height
759 // instead.
760 return gfx::Size(width, 0);
746 } 761 }
747 762
748 string16 MenuItemView::GetAcceleratorText() { 763 string16 MenuItemView::GetAcceleratorText() {
749 if (id() == kEmptyMenuItemViewID) { 764 if (id() == kEmptyMenuItemViewID) {
750 // Don't query the delegate for menus that represent no children. 765 // Don't query the delegate for menus that represent no children.
751 return string16(); 766 return string16();
752 } 767 }
753 768
754 Accelerator accelerator; 769 Accelerator accelerator;
755 return (GetDelegate() && 770 return (GetDelegate() &&
756 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? 771 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ?
757 accelerator.GetShortcutText() : string16(); 772 accelerator.GetShortcutText() : string16();
758 } 773 }
759 774
760 } // namespace views 775 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/menu/menu_item_view.h ('k') | views/controls/menu/menu_item_view_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698