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

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

Issue 13482012: fix layout of requestAutocomplete suggestion dropdown menu on views (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: FIXME into comment Created 7 years, 8 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 | « ui/views/controls/menu/menu_item_view.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/controls/menu/menu_item_view.h" 5 #include "ui/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.h" 8 #include "base/stl_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "grit/ui_resources.h" 10 #include "grit/ui_resources.h"
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 enabled() ? ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor 831 enabled() ? ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor
832 : ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor); 832 : ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor);
833 SkColor override_foreground_color; 833 SkColor override_foreground_color;
834 if (delegate && delegate->GetForegroundColor(GetCommand(), 834 if (delegate && delegate->GetForegroundColor(GetCommand(),
835 render_selection, 835 render_selection,
836 &override_foreground_color)) 836 &override_foreground_color))
837 fg_color = override_foreground_color; 837 fg_color = override_foreground_color;
838 838
839 const gfx::Font& font = GetFont(); 839 const gfx::Font& font = GetFont();
840 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); 840 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width();
841 int label_start = label_start_ + left_icon_margin_ + right_icon_margin_; 841 int label_start = GetLabelStartForThisItem();
842 if ((type_ == CHECKBOX || type_ == RADIO) && icon_view_)
843 label_start += icon_view_->size().width() + config.icon_to_label_padding;
844 842
845 int width = this->width() - label_start - accel_width - 843 int width = this->width() - label_start - accel_width -
846 (!delegate || 844 (!delegate ||
847 delegate->ShouldReserveSpaceForSubmenuIndicator() ? 845 delegate->ShouldReserveSpaceForSubmenuIndicator() ?
848 item_right_margin_ : config.arrow_to_edge_padding); 846 item_right_margin_ : config.arrow_to_edge_padding);
849 gfx::Rect text_bounds(label_start, top_margin, width, available_height); 847 gfx::Rect text_bounds(label_start, top_margin, width, available_height);
850 text_bounds.set_x(GetMirroredXForRect(text_bounds)); 848 text_bounds.set_x(GetMirroredXForRect(text_bounds));
851 int flags = GetDrawStringFlags(); 849 int flags = GetDrawStringFlags();
852 if (mode == PB_FOR_DRAG) 850 if (mode == PB_FOR_DRAG)
853 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; 851 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 const MenuDelegate* delegate = GetDelegate(); 980 const MenuDelegate* delegate = GetDelegate();
983 if (delegate) { 981 if (delegate) {
984 delegate->GetHorizontalIconMargins(command_, 982 delegate->GetHorizontalIconMargins(command_,
985 icon_area_width_, 983 icon_area_width_,
986 &left_icon_margin_, 984 &left_icon_margin_,
987 &right_icon_margin_); 985 &right_icon_margin_);
988 } else { 986 } else {
989 left_icon_margin_ = 0; 987 left_icon_margin_ = 0;
990 right_icon_margin_ = 0; 988 right_icon_margin_ = 0;
991 } 989 }
992 int label_start = label_start_ + left_icon_margin_ + right_icon_margin_; 990 int label_start = GetLabelStartForThisItem();
993 991
994 dimensions.standard_width = font.GetStringWidth(title_) + label_start + 992 dimensions.standard_width = font.GetStringWidth(title_) + label_start +
995 item_right_margin_; 993 item_right_margin_;
996 // Determine the length of the accelerator text. 994 // Determine the length of the accelerator text.
997 string16 text = GetAcceleratorText(); 995 string16 text = GetAcceleratorText();
998 dimensions.accelerator_width = 996 dimensions.accelerator_width =
999 text.empty() ? 0 : GetFont().GetStringWidth(text); 997 text.empty() ? 0 : GetFont().GetStringWidth(text);
1000 998
1001 // Determine the height to use. 999 // Determine the height to use.
1002 dimensions.height = std::max(dimensions.height, 1000 dimensions.height = std::max(dimensions.height,
1003 font.GetHeight() + GetBottomMargin() + GetTopMargin()); 1001 font.GetHeight() + GetBottomMargin() + GetTopMargin());
1004 dimensions.height = std::max(dimensions.height, 1002 dimensions.height = std::max(dimensions.height,
1005 GetMenuConfig().item_min_height); 1003 GetMenuConfig().item_min_height);
1006 return dimensions; 1004 return dimensions;
1007 } 1005 }
1008 1006
1007 int MenuItemView::GetLabelStartForThisItem() {
1008 int label_start = label_start_ + left_icon_margin_ + right_icon_margin_;
1009 if ((type_ == CHECKBOX || type_ == RADIO) && icon_view_) {
1010 label_start += icon_view_->size().width() +
1011 GetMenuConfig().icon_to_label_padding;
1012 }
1013 return label_start;
1014 }
1015
1009 string16 MenuItemView::GetAcceleratorText() { 1016 string16 MenuItemView::GetAcceleratorText() {
1010 if (id() == kEmptyMenuItemViewID) { 1017 if (id() == kEmptyMenuItemViewID) {
1011 // Don't query the delegate for menus that represent no children. 1018 // Don't query the delegate for menus that represent no children.
1012 return string16(); 1019 return string16();
1013 } 1020 }
1014 1021
1015 if(!GetMenuConfig().show_accelerators) 1022 if(!GetMenuConfig().show_accelerators)
1016 return string16(); 1023 return string16();
1017 1024
1018 ui::Accelerator accelerator; 1025 ui::Accelerator accelerator;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 } else { 1064 } else {
1058 const Type& type = menu_item->GetType(); 1065 const Type& type = menu_item->GetType();
1059 if (type == CHECKBOX || type == RADIO) 1066 if (type == CHECKBOX || type == RADIO)
1060 return true; 1067 return true;
1061 } 1068 }
1062 } 1069 }
1063 return false; 1070 return false;
1064 } 1071 }
1065 1072
1066 } // namespace views 1073 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_item_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698