OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/chrome_menu.h" | 5 #include "views/controls/menu/chrome_menu.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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // Are mnemonics shown? This is updated before the menus are shown. | 119 // Are mnemonics shown? This is updated before the menus are shown. |
120 static bool show_mnemonics; | 120 static bool show_mnemonics; |
121 | 121 |
122 using gfx::NativeTheme; | 122 using gfx::NativeTheme; |
123 | 123 |
124 namespace views { | 124 namespace views { |
125 | 125 |
126 namespace { | 126 namespace { |
127 | 127 |
128 // Returns the font menus are to use. | 128 // Returns the font menus are to use. |
129 ChromeFont GetMenuFont() { | 129 gfx::Font GetMenuFont() { |
130 NONCLIENTMETRICS metrics; | 130 NONCLIENTMETRICS metrics; |
131 win_util::GetNonClientMetrics(&metrics); | 131 win_util::GetNonClientMetrics(&metrics); |
132 | 132 |
133 l10n_util::AdjustUIFont(&(metrics.lfMenuFont)); | 133 l10n_util::AdjustUIFont(&(metrics.lfMenuFont)); |
134 HFONT font = CreateFontIndirect(&metrics.lfMenuFont); | 134 HFONT font = CreateFontIndirect(&metrics.lfMenuFont); |
135 DLOG_ASSERT(font); | 135 DLOG_ASSERT(font); |
136 return ChromeFont::CreateFont(font); | 136 return gfx::Font::CreateFont(font); |
137 } | 137 } |
138 | 138 |
139 // Calculates all sizes that we can from the OS. | 139 // Calculates all sizes that we can from the OS. |
140 // | 140 // |
141 // This is invoked prior to Running a menu. | 141 // This is invoked prior to Running a menu. |
142 void UpdateMenuPartSizes(bool has_icons) { | 142 void UpdateMenuPartSizes(bool has_icons) { |
143 HDC dc = GetDC(NULL); | 143 HDC dc = GetDC(NULL); |
144 RECT bounds = { 0, 0, 200, 200 }; | 144 RECT bounds = { 0, 0, 200, 200 }; |
145 SIZE check_size; | 145 SIZE check_size; |
146 if (NativeTheme::instance()->GetThemePartSize( | 146 if (NativeTheme::instance()->GetThemePartSize( |
(...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 void MenuItemView::SetIcon(const SkBitmap& icon) { | 1208 void MenuItemView::SetIcon(const SkBitmap& icon) { |
1209 icon_ = icon; | 1209 icon_ = icon; |
1210 SchedulePaint(); | 1210 SchedulePaint(); |
1211 } | 1211 } |
1212 | 1212 |
1213 void MenuItemView::Paint(ChromeCanvas* canvas) { | 1213 void MenuItemView::Paint(ChromeCanvas* canvas) { |
1214 Paint(canvas, false); | 1214 Paint(canvas, false); |
1215 } | 1215 } |
1216 | 1216 |
1217 gfx::Size MenuItemView::GetPreferredSize() { | 1217 gfx::Size MenuItemView::GetPreferredSize() { |
1218 ChromeFont& font = GetRootMenuItem()->font_; | 1218 gfx::Font& font = GetRootMenuItem()->font_; |
1219 return gfx::Size( | 1219 return gfx::Size( |
1220 font.GetStringWidth(title_) + label_start + item_right_margin, | 1220 font.GetStringWidth(title_) + label_start + item_right_margin, |
1221 font.height() + GetBottomMargin() + GetTopMargin()); | 1221 font.height() + GetBottomMargin() + GetTopMargin()); |
1222 } | 1222 } |
1223 | 1223 |
1224 MenuController* MenuItemView::GetMenuController() { | 1224 MenuController* MenuItemView::GetMenuController() { |
1225 return GetRootMenuItem()->controller_; | 1225 return GetRootMenuItem()->controller_; |
1226 } | 1226 } |
1227 | 1227 |
1228 MenuDelegate* MenuItemView::GetDelegate() { | 1228 MenuDelegate* MenuItemView::GetDelegate() { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 | 1480 |
1481 // Render the foreground. | 1481 // Render the foreground. |
1482 // Menu color is specific to Vista, fallback to classic colors if can't | 1482 // Menu color is specific to Vista, fallback to classic colors if can't |
1483 // get color. | 1483 // get color. |
1484 int default_sys_color = render_selection ? COLOR_HIGHLIGHTTEXT : | 1484 int default_sys_color = render_selection ? COLOR_HIGHLIGHTTEXT : |
1485 (IsEnabled() ? COLOR_MENUTEXT : COLOR_GRAYTEXT); | 1485 (IsEnabled() ? COLOR_MENUTEXT : COLOR_GRAYTEXT); |
1486 SkColor fg_color = NativeTheme::instance()->GetThemeColorWithDefault( | 1486 SkColor fg_color = NativeTheme::instance()->GetThemeColorWithDefault( |
1487 NativeTheme::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR, | 1487 NativeTheme::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR, |
1488 default_sys_color); | 1488 default_sys_color); |
1489 int width = this->width() - item_right_margin - label_start; | 1489 int width = this->width() - item_right_margin - label_start; |
1490 ChromeFont& font = GetRootMenuItem()->font_; | 1490 gfx::Font& font = GetRootMenuItem()->font_; |
1491 gfx::Rect text_bounds(label_start, top_margin, width, font.height()); | 1491 gfx::Rect text_bounds(label_start, top_margin, width, font.height()); |
1492 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); | 1492 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); |
1493 if (for_drag) { | 1493 if (for_drag) { |
1494 // With different themes, it's difficult to tell what the correct foreground | 1494 // With different themes, it's difficult to tell what the correct foreground |
1495 // and background colors are for the text to draw the correct halo. Instead, | 1495 // and background colors are for the text to draw the correct halo. Instead, |
1496 // just draw black on white, which will look good in most cases. | 1496 // just draw black on white, which will look good in most cases. |
1497 canvas->DrawStringWithHalo(GetTitle(), font, 0x00000000, 0xFFFFFFFF, | 1497 canvas->DrawStringWithHalo(GetTitle(), font, 0x00000000, 0xFFFFFFFF, |
1498 text_bounds.x(), text_bounds.y(), | 1498 text_bounds.x(), text_bounds.y(), |
1499 text_bounds.width(), text_bounds.height(), | 1499 text_bounds.width(), text_bounds.height(), |
1500 GetRootMenuItem()->GetDrawStringFlags()); | 1500 GetRootMenuItem()->GetDrawStringFlags()); |
(...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2811 if (!scroll_task_.get()) | 2811 if (!scroll_task_.get()) |
2812 scroll_task_.reset(new MenuScrollTask()); | 2812 scroll_task_.reset(new MenuScrollTask()); |
2813 scroll_task_->Update(part); | 2813 scroll_task_->Update(part); |
2814 } | 2814 } |
2815 | 2815 |
2816 void MenuController::StopScrolling() { | 2816 void MenuController::StopScrolling() { |
2817 scroll_task_.reset(NULL); | 2817 scroll_task_.reset(NULL); |
2818 } | 2818 } |
2819 | 2819 |
2820 } // namespace views | 2820 } // namespace views |
OLD | NEW |