OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <windows.h> | 7 #include <windows.h> |
8 #include <uxtheme.h> | 8 #include <uxtheme.h> |
9 #include <Vssym32.h> | 9 #include <Vssym32.h> |
10 | 10 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 | 89 |
90 // Render the foreground. | 90 // Render the foreground. |
91 // Menu color is specific to Vista, fallback to classic colors if can't | 91 // Menu color is specific to Vista, fallback to classic colors if can't |
92 // get color. | 92 // get color. |
93 int default_sys_color = render_selection ? COLOR_HIGHLIGHTTEXT : | 93 int default_sys_color = render_selection ? COLOR_HIGHLIGHTTEXT : |
94 (IsEnabled() ? COLOR_MENUTEXT : COLOR_GRAYTEXT); | 94 (IsEnabled() ? COLOR_MENUTEXT : COLOR_GRAYTEXT); |
95 SkColor fg_color = NativeTheme::instance()->GetThemeColorWithDefault( | 95 SkColor fg_color = NativeTheme::instance()->GetThemeColorWithDefault( |
96 NativeTheme::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR, | 96 NativeTheme::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR, |
97 default_sys_color); | 97 default_sys_color); |
98 int width = this->width() - item_right_margin_ - label_start_; | |
99 const gfx::Font& font = GetChildViewCount() > 0 ? | 98 const gfx::Font& font = GetChildViewCount() > 0 ? |
100 MenuConfig::instance().font_with_controls : MenuConfig::instance().font; | 99 MenuConfig::instance().font_with_controls : MenuConfig::instance().font; |
| 100 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); |
| 101 int width = this->width() - item_right_margin_ - label_start_ - accel_width; |
101 gfx::Rect text_bounds(label_start_, top_margin, width, font.height()); | 102 gfx::Rect text_bounds(label_start_, top_margin, width, font.height()); |
102 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); | 103 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); |
103 if (for_drag) { | 104 if (for_drag) { |
104 // With different themes, it's difficult to tell what the correct | 105 // With different themes, it's difficult to tell what the correct |
105 // foreground and background colors are for the text to draw the correct | 106 // foreground and background colors are for the text to draw the correct |
106 // halo. Instead, just draw black on white, which will look good in most | 107 // halo. Instead, just draw black on white, which will look good in most |
107 // cases. | 108 // cases. |
108 canvas->DrawStringWithHalo(GetTitle(), font, 0x00000000, 0xFFFFFFFF, | 109 canvas->DrawStringWithHalo(GetTitle(), font, 0x00000000, 0xFFFFFFFF, |
109 text_bounds.x(), text_bounds.y(), | 110 text_bounds.x(), text_bounds.y(), |
110 text_bounds.width(), text_bounds.height(), | 111 text_bounds.width(), text_bounds.height(), |
111 GetRootMenuItem()->GetDrawStringFlags()); | 112 GetRootMenuItem()->GetDrawStringFlags()); |
112 } else { | 113 } else { |
113 canvas->DrawStringInt(GetTitle(), font, fg_color, | 114 canvas->DrawStringInt(GetTitle(), font, fg_color, |
114 text_bounds.x(), text_bounds.y(), text_bounds.width(), | 115 text_bounds.x(), text_bounds.y(), text_bounds.width(), |
115 text_bounds.height(), | 116 text_bounds.height(), |
116 GetRootMenuItem()->GetDrawStringFlags()); | 117 GetRootMenuItem()->GetDrawStringFlags()); |
117 } | 118 } |
118 | 119 |
| 120 PaintAccelerator(canvas); |
| 121 |
119 if (icon_.width() > 0) { | 122 if (icon_.width() > 0) { |
120 gfx::Rect icon_bounds(config.item_left_margin, | 123 gfx::Rect icon_bounds(config.item_left_margin, |
121 top_margin + (height() - top_margin - | 124 top_margin + (height() - top_margin - |
122 bottom_margin - icon_.height()) / 2, | 125 bottom_margin - icon_.height()) / 2, |
123 icon_.width(), | 126 icon_.width(), |
124 icon_.height()); | 127 icon_.height()); |
125 icon_bounds.set_x(MirroredLeftPointForRect(icon_bounds)); | 128 icon_bounds.set_x(MirroredLeftPointForRect(icon_bounds)); |
126 canvas->DrawBitmapInt(icon_, icon_bounds.x(), icon_bounds.y()); | 129 canvas->DrawBitmapInt(icon_, icon_bounds.x(), icon_bounds.y()); |
127 } | 130 } |
128 | 131 |
(...skipping 15 matching lines...) Expand all Loading... |
144 | 147 |
145 RECT arrow_rect = arrow_bounds.ToRECT(); | 148 RECT arrow_rect = arrow_bounds.ToRECT(); |
146 NativeTheme::instance()->PaintMenuArrow( | 149 NativeTheme::instance()->PaintMenuArrow( |
147 NativeTheme::MENU, dc, MENU_POPUPSUBMENU, state_id, &arrow_rect, | 150 NativeTheme::MENU, dc, MENU_POPUPSUBMENU, state_id, &arrow_rect, |
148 arrow_direction, render_selection); | 151 arrow_direction, render_selection); |
149 } | 152 } |
150 canvas->endPlatformPaint(); | 153 canvas->endPlatformPaint(); |
151 } | 154 } |
152 | 155 |
153 } // namespace views | 156 } // namespace views |
OLD | NEW |