OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "gfx/canvas_skia.h" | 8 #include "gfx/canvas_skia.h" |
9 #include "gfx/favicon_size.h" | 9 #include "gfx/favicon_size.h" |
10 #include "grit/app_resources.h" | 10 #include "grit/app_resources.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 static const SkColor kRadioButtonIndicatorGradient1 = | 37 static const SkColor kRadioButtonIndicatorGradient1 = |
38 SkColorSetRGB(0x83, 0x83, 0x83); | 38 SkColorSetRGB(0x83, 0x83, 0x83); |
39 | 39 |
40 static const SkColor kIndicatorStroke = SkColorSetRGB(0, 0, 0); | 40 static const SkColor kIndicatorStroke = SkColorSetRGB(0, 0, 0); |
41 | 41 |
42 gfx::Size MenuItemView::GetPreferredSize() { | 42 gfx::Size MenuItemView::GetPreferredSize() { |
43 const gfx::Font& font = MenuConfig::instance().font; | 43 const gfx::Font& font = MenuConfig::instance().font; |
44 // TODO(sky): this is a workaround until I figure out why font.height() | 44 // TODO(sky): this is a workaround until I figure out why font.height() |
45 // isn't returning the right thing. We really only want to include | 45 // isn't returning the right thing. We really only want to include |
46 // kFavIconSize if we're showing icons. | 46 // kFavIconSize if we're showing icons. |
47 int content_height = std::max(kFavIconSize, font.height()); | 47 int content_height = std::max(kFavIconSize, font.GetHeight()); |
48 return gfx::Size( | 48 return gfx::Size( |
49 font.GetStringWidth(title_) + label_start_ + item_right_margin_ + | 49 font.GetStringWidth(title_) + label_start_ + item_right_margin_ + |
50 GetChildPreferredWidth(), | 50 GetChildPreferredWidth(), |
51 content_height + GetBottomMargin() + GetTopMargin()); | 51 content_height + GetBottomMargin() + GetTopMargin()); |
52 } | 52 } |
53 | 53 |
54 void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { | 54 void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { |
55 const MenuConfig& config = MenuConfig::instance(); | 55 const MenuConfig& config = MenuConfig::instance(); |
56 bool render_selection = | 56 bool render_selection = |
57 (!for_drag && IsSelected() && | 57 (!for_drag && IsSelected() && |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 SkColor fg_color = | 148 SkColor fg_color = |
149 IsEnabled() ? SK_ColorBLACK : SkColorSetRGB(0x80, 0x80, 0x80); | 149 IsEnabled() ? SK_ColorBLACK : SkColorSetRGB(0x80, 0x80, 0x80); |
150 #else | 150 #else |
151 SkColor fg_color = | 151 SkColor fg_color = |
152 IsEnabled() ? TextButton::kEnabledColor : TextButton::kDisabledColor; | 152 IsEnabled() ? TextButton::kEnabledColor : TextButton::kDisabledColor; |
153 #endif | 153 #endif |
154 const gfx::Font& font = MenuConfig::instance().font; | 154 const gfx::Font& font = MenuConfig::instance().font; |
155 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); | 155 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); |
156 int width = this->width() - item_right_margin_ - label_start_ - accel_width; | 156 int width = this->width() - item_right_margin_ - label_start_ - accel_width; |
157 gfx::Rect text_bounds(label_start_, top_margin + | 157 gfx::Rect text_bounds(label_start_, top_margin + |
158 (available_height - font.height()) / 2, width, | 158 (available_height - font.GetHeight()) / 2, width, |
159 font.height()); | 159 font.GetHeight()); |
160 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); | 160 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); |
161 canvas->DrawStringInt(GetTitle(), font, fg_color, | 161 canvas->DrawStringInt(GetTitle(), font, fg_color, |
162 text_bounds.x(), text_bounds.y(), text_bounds.width(), | 162 text_bounds.x(), text_bounds.y(), text_bounds.width(), |
163 text_bounds.height(), | 163 text_bounds.height(), |
164 GetRootMenuItem()->GetDrawStringFlags()); | 164 GetRootMenuItem()->GetDrawStringFlags()); |
165 | 165 |
166 PaintAccelerator(canvas); | 166 PaintAccelerator(canvas); |
167 | 167 |
168 // Render the icon. | 168 // Render the icon. |
169 if (icon_.width() > 0) { | 169 if (icon_.width() > 0) { |
(...skipping 14 matching lines...) Expand all Loading... |
184 config.arrow_width) / 2, | 184 config.arrow_width) / 2, |
185 config.arrow_width, height()); | 185 config.arrow_width, height()); |
186 AdjustBoundsForRTLUI(&arrow_bounds); | 186 AdjustBoundsForRTLUI(&arrow_bounds); |
187 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 187 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
188 canvas->DrawBitmapInt(*rb.GetBitmapNamed(IDR_MENU_ARROW), | 188 canvas->DrawBitmapInt(*rb.GetBitmapNamed(IDR_MENU_ARROW), |
189 arrow_bounds.x(), arrow_bounds.y()); | 189 arrow_bounds.x(), arrow_bounds.y()); |
190 } | 190 } |
191 } | 191 } |
192 | 192 |
193 } // namespace views | 193 } // namespace views |
OLD | NEW |