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 <uxtheme.h> | 7 #include <uxtheme.h> |
8 #include <Vssym32.h> | 8 #include <Vssym32.h> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
11 #include "gfx/canvas_skia.h" | 11 #include "gfx/canvas.h" |
12 #include "gfx/native_theme_win.h" | 12 #include "gfx/native_theme_win.h" |
13 #include "grit/app_strings.h" | 13 #include "grit/app_strings.h" |
14 #include "views/controls/menu/menu_config.h" | 14 #include "views/controls/menu/menu_config.h" |
15 #include "views/controls/menu/submenu_view.h" | 15 #include "views/controls/menu/submenu_view.h" |
16 | 16 |
17 using gfx::NativeTheme; | 17 using gfx::NativeTheme; |
18 | 18 |
19 namespace views { | 19 namespace views { |
20 | 20 |
21 gfx::Size MenuItemView::GetPreferredSize() { | 21 gfx::Size MenuItemView::GetPreferredSize() { |
22 const gfx::Font& font = MenuConfig::instance().font; | 22 const gfx::Font& font = MenuConfig::instance().font; |
23 return gfx::Size( | 23 return gfx::Size( |
24 font.GetStringWidth(title_) + label_start_ + item_right_margin_ + | 24 font.GetStringWidth(title_) + label_start_ + item_right_margin_ + |
25 GetChildPreferredWidth(), | 25 GetChildPreferredWidth(), |
26 font.height() + GetBottomMargin() + GetTopMargin()); | 26 font.height() + GetBottomMargin() + GetTopMargin()); |
27 } | 27 } |
28 | 28 |
29 void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { | 29 void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { |
30 const MenuConfig& config = MenuConfig::instance(); | 30 const MenuConfig& config = MenuConfig::instance(); |
31 bool render_selection = | 31 bool render_selection = |
32 (!for_drag && IsSelected() && | 32 (!for_drag && IsSelected() && |
33 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && | 33 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && |
34 GetChildViewCount() == 0); | 34 GetChildViewCount() == 0); |
35 int state = render_selection ? MPI_HOT : | 35 int state = render_selection ? MPI_HOT : |
36 (IsEnabled() ? MPI_NORMAL : MPI_DISABLED); | 36 (IsEnabled() ? MPI_NORMAL : MPI_DISABLED); |
37 HDC dc = canvas->AsCanvasSkia()->beginPlatformPaint(); | 37 HDC dc = canvas->beginPlatformPaint(); |
38 | 38 |
39 // The gutter is rendered before the background. | 39 // The gutter is rendered before the background. |
40 if (config.render_gutter && !for_drag) { | 40 if (config.render_gutter && !for_drag) { |
41 gfx::Rect gutter_bounds(label_start_ - config.gutter_to_label - | 41 gfx::Rect gutter_bounds(label_start_ - config.gutter_to_label - |
42 config.gutter_width, 0, config.gutter_width, | 42 config.gutter_width, 0, config.gutter_width, |
43 height()); | 43 height()); |
44 AdjustBoundsForRTLUI(&gutter_bounds); | 44 AdjustBoundsForRTLUI(&gutter_bounds); |
45 RECT gutter_rect = gutter_bounds.ToRECT(); | 45 RECT gutter_rect = gutter_bounds.ToRECT(); |
46 NativeTheme::instance()->PaintMenuGutter(dc, MENU_POPUPGUTTER, MPI_NORMAL, | 46 NativeTheme::instance()->PaintMenuGutter(dc, MENU_POPUPGUTTER, MPI_NORMAL, |
47 &gutter_rect); | 47 &gutter_rect); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 const gfx::Font& font = MenuConfig::instance().font; | 80 const gfx::Font& font = MenuConfig::instance().font; |
81 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); | 81 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); |
82 int width = this->width() - item_right_margin_ - label_start_ - accel_width; | 82 int width = this->width() - item_right_margin_ - label_start_ - accel_width; |
83 gfx::Rect text_bounds(label_start_, top_margin, width, font.height()); | 83 gfx::Rect text_bounds(label_start_, top_margin, width, font.height()); |
84 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); | 84 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); |
85 if (for_drag) { | 85 if (for_drag) { |
86 // With different themes, it's difficult to tell what the correct | 86 // With different themes, it's difficult to tell what the correct |
87 // foreground and background colors are for the text to draw the correct | 87 // foreground and background colors are for the text to draw the correct |
88 // halo. Instead, just draw black on white, which will look good in most | 88 // halo. Instead, just draw black on white, which will look good in most |
89 // cases. | 89 // cases. |
90 canvas->AsCanvasSkia()->DrawStringWithHalo( | 90 canvas->DrawStringWithHalo(GetTitle(), font, 0x00000000, 0xFFFFFFFF, |
91 GetTitle(), font, 0x00000000, 0xFFFFFFFF, text_bounds.x(), | 91 text_bounds.x(), text_bounds.y(), |
92 text_bounds.y(), text_bounds.width(), text_bounds.height(), | 92 text_bounds.width(), text_bounds.height(), |
93 GetRootMenuItem()->GetDrawStringFlags()); | 93 GetRootMenuItem()->GetDrawStringFlags()); |
94 } else { | 94 } else { |
95 canvas->DrawStringInt(GetTitle(), font, fg_color, | 95 canvas->DrawStringInt(GetTitle(), font, fg_color, |
96 text_bounds.x(), text_bounds.y(), text_bounds.width(), | 96 text_bounds.x(), text_bounds.y(), text_bounds.width(), |
97 text_bounds.height(), | 97 text_bounds.height(), |
98 GetRootMenuItem()->GetDrawStringFlags()); | 98 GetRootMenuItem()->GetDrawStringFlags()); |
99 } | 99 } |
100 | 100 |
101 PaintAccelerator(canvas); | 101 PaintAccelerator(canvas); |
102 | 102 |
103 if (icon_.width() > 0) { | 103 if (icon_.width() > 0) { |
(...skipping 20 matching lines...) Expand all Loading... |
124 if (base::i18n::IsRTL()) | 124 if (base::i18n::IsRTL()) |
125 arrow_direction = NativeTheme::LEFT_POINTING_ARROW; | 125 arrow_direction = NativeTheme::LEFT_POINTING_ARROW; |
126 else | 126 else |
127 arrow_direction = NativeTheme::RIGHT_POINTING_ARROW; | 127 arrow_direction = NativeTheme::RIGHT_POINTING_ARROW; |
128 | 128 |
129 RECT arrow_rect = arrow_bounds.ToRECT(); | 129 RECT arrow_rect = arrow_bounds.ToRECT(); |
130 NativeTheme::instance()->PaintMenuArrow( | 130 NativeTheme::instance()->PaintMenuArrow( |
131 NativeTheme::MENU, dc, MENU_POPUPSUBMENU, state_id, &arrow_rect, | 131 NativeTheme::MENU, dc, MENU_POPUPSUBMENU, state_id, &arrow_rect, |
132 arrow_direction, render_selection); | 132 arrow_direction, render_selection); |
133 } | 133 } |
134 canvas->AsCanvasSkia()->endPlatformPaint(); | 134 canvas->endPlatformPaint(); |
135 } | 135 } |
136 void MenuItemView::PaintCheck(HDC dc, | 136 void MenuItemView::PaintCheck(HDC dc, |
137 int state_id, | 137 int state_id, |
138 bool render_selection, | 138 bool render_selection, |
139 int icon_width, | 139 int icon_width, |
140 int icon_height) { | 140 int icon_height) { |
141 int top_margin = GetTopMargin(); | 141 int top_margin = GetTopMargin(); |
142 int icon_x = MenuConfig::instance().item_left_margin; | 142 int icon_x = MenuConfig::instance().item_left_margin; |
143 int icon_y = top_margin + | 143 int icon_y = top_margin + |
144 (height() - top_margin - GetBottomMargin() - icon_height) / 2; | 144 (height() - top_margin - GetBottomMargin() - icon_height) / 2; |
145 // Draw the background. | 145 // Draw the background. |
146 gfx::Rect bg_bounds(0, 0, icon_x + icon_width, height()); | 146 gfx::Rect bg_bounds(0, 0, icon_x + icon_width, height()); |
147 int bg_state = IsEnabled() ? MCB_NORMAL : MCB_DISABLED; | 147 int bg_state = IsEnabled() ? MCB_NORMAL : MCB_DISABLED; |
148 AdjustBoundsForRTLUI(&bg_bounds); | 148 AdjustBoundsForRTLUI(&bg_bounds); |
149 RECT bg_rect = bg_bounds.ToRECT(); | 149 RECT bg_rect = bg_bounds.ToRECT(); |
150 NativeTheme::instance()->PaintMenuCheckBackground( | 150 NativeTheme::instance()->PaintMenuCheckBackground( |
151 NativeTheme::MENU, dc, MENU_POPUPCHECKBACKGROUND, bg_state, | 151 NativeTheme::MENU, dc, MENU_POPUPCHECKBACKGROUND, bg_state, |
152 &bg_rect); | 152 &bg_rect); |
153 | 153 |
154 // And the check. | 154 // And the check. |
155 gfx::Rect icon_bounds(icon_x / 2, icon_y, icon_width, icon_height); | 155 gfx::Rect icon_bounds(icon_x / 2, icon_y, icon_width, icon_height); |
156 AdjustBoundsForRTLUI(&icon_bounds); | 156 AdjustBoundsForRTLUI(&icon_bounds); |
157 RECT icon_rect = icon_bounds.ToRECT(); | 157 RECT icon_rect = icon_bounds.ToRECT(); |
158 NativeTheme::instance()->PaintMenuCheck( | 158 NativeTheme::instance()->PaintMenuCheck( |
159 NativeTheme::MENU, dc, MENU_POPUPCHECK, state_id, &icon_rect, | 159 NativeTheme::MENU, dc, MENU_POPUPCHECK, state_id, &icon_rect, |
160 render_selection); | 160 render_selection); |
161 } | 161 } |
162 | 162 |
163 } // namespace views | 163 } // namespace views |
OLD | NEW |