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

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: remove debug code 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
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();
738 746
739 int width = 0; 747 if (GetTitle().size() == 0 && child_count() == 1) {
740 for (int i = 0; i < child_count(); ++i) { 748 View* child = GetChildViewAt(0);
741 if (i) 749 return child->GetPreferredSize();
742 width += kChildXPadding; 750 } else {
sky 2011/07/08 21:01:44 no else (since you returned early).
sail 2011/07/08 21:53:57 Done.
743 width += GetChildViewAt(i)->GetPreferredSize().width(); 751 int width = 0;
752 for (int i = 0; i < child_count(); ++i) {
753 if (i)
754 width += kChildXPadding;
755 width += GetChildViewAt(i)->GetPreferredSize().width();
756 }
757 return gfx::Size(width, 0);
sky 2011/07/08 21:01:44 Document why its ok to return a height of 0 here.
sail 2011/07/08 21:53:57 Done.
744 } 758 }
745 return width;
746 } 759 }
747 760
748 string16 MenuItemView::GetAcceleratorText() { 761 string16 MenuItemView::GetAcceleratorText() {
749 if (id() == kEmptyMenuItemViewID) { 762 if (id() == kEmptyMenuItemViewID) {
750 // Don't query the delegate for menus that represent no children. 763 // Don't query the delegate for menus that represent no children.
751 return string16(); 764 return string16();
752 } 765 }
753 766
754 Accelerator accelerator; 767 Accelerator accelerator;
755 return (GetDelegate() && 768 return (GetDelegate() &&
756 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? 769 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ?
757 accelerator.GetShortcutText() : string16(); 770 accelerator.GetShortcutText() : string16();
758 } 771 }
759 772
760 } // namespace views 773 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698