Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <uxtheme.h> | 7 #include <uxtheme.h> |
| 8 #include <Vssym32.h> | 8 #include <Vssym32.h> |
| 9 | 9 |
| 10 #include "grit/ui_strings.h" | 10 #include "grit/ui_strings.h" |
| 11 #include "ui/base/native_theme/native_theme_win.h" | 11 #include "ui/base/native_theme/native_theme_win.h" |
| 12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 13 #include "ui/views/controls/menu/menu_config.h" | 13 #include "ui/views/controls/menu/menu_config.h" |
| 14 #include "ui/views/controls/menu/submenu_view.h" | 14 #include "ui/views/controls/menu/submenu_view.h" |
| 15 | 15 |
| 16 using ui::NativeTheme; | 16 using ui::NativeTheme; |
| 17 | 17 |
| 18 namespace views { | 18 namespace views { |
| 19 | 19 |
| 20 void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { | 20 void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { |
| 21 const MenuConfig& config = MenuConfig::instance(); | 21 const MenuConfig& config = MenuConfig::instance(); |
| 22 | |
| 22 bool render_selection = | 23 bool render_selection = |
| 23 (mode == PB_NORMAL && IsSelected() && | 24 (mode == PB_NORMAL && IsSelected() && |
| 24 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && | 25 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && |
| 25 !has_children()); | 26 !HasNonIconChildViews()); |
| 26 int default_sys_color; | 27 int default_sys_color; |
| 27 int state; | 28 int state; |
| 28 NativeTheme::State control_state; | 29 NativeTheme::State control_state; |
| 29 | 30 |
| 30 if (enabled()) { | 31 if (enabled()) { |
| 31 if (render_selection) { | 32 if (render_selection) { |
| 32 control_state = NativeTheme::kHovered; | 33 control_state = NativeTheme::kHovered; |
| 33 state = MPI_HOT; | 34 state = MPI_HOT; |
| 34 default_sys_color = COLOR_HIGHLIGHTTEXT; | 35 default_sys_color = COLOR_HIGHLIGHTTEXT; |
| 35 } else { | 36 } else { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 | 79 |
| 79 // Render the foreground. | 80 // Render the foreground. |
| 80 // Menu color is specific to Vista, fallback to classic colors if can't | 81 // Menu color is specific to Vista, fallback to classic colors if can't |
| 81 // get color. | 82 // get color. |
| 82 SkColor fg_color = ui::NativeThemeWin::instance()->GetThemeColorWithDefault( | 83 SkColor fg_color = ui::NativeThemeWin::instance()->GetThemeColorWithDefault( |
| 83 ui::NativeThemeWin::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR, | 84 ui::NativeThemeWin::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR, |
| 84 default_sys_color); | 85 default_sys_color); |
| 85 const gfx::Font& font = GetFont(); | 86 const gfx::Font& font = GetFont(); |
| 86 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); | 87 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); |
| 87 int width = this->width() - item_right_margin_ - label_start_ - accel_width; | 88 int width = this->width() - item_right_margin_ - label_start_ - accel_width; |
| 88 gfx::Rect text_bounds(label_start_, top_margin, width, font.GetHeight()); | 89 // To keep backward compatibility. |
| 90 int height = has_icon_view_ ? this->height() : font.GetHeight(); | |
|
Aaron Boodman
2012/06/19 00:06:33
Can you combine the two cases by doing max(this->h
yefimt
2012/06/20 16:53:04
Done.
| |
| 91 int flags = (has_icon_view_ ? gfx::Canvas::TEXT_VALIGN_MIDDLE : 0) | | |
|
Aaron Boodman
2012/06/19 00:06:33
It seems like it would still be correct to do TEXT
yefimt
2012/06/20 16:53:04
Done.
| |
| 92 GetRootMenuItem()->GetDrawStringFlags(); | |
| 93 gfx::Rect text_bounds(label_start_, top_margin, width, height); | |
| 89 text_bounds.set_x(GetMirroredXForRect(text_bounds)); | 94 text_bounds.set_x(GetMirroredXForRect(text_bounds)); |
| 90 if (mode == PB_FOR_DRAG) { | 95 if (mode == PB_FOR_DRAG) { |
| 91 // With different themes, it's difficult to tell what the correct | 96 // With different themes, it's difficult to tell what the correct |
| 92 // foreground and background colors are for the text to draw the correct | 97 // foreground and background colors are for the text to draw the correct |
| 93 // halo. Instead, just draw black on white, which will look good in most | 98 // halo. Instead, just draw black on white, which will look good in most |
| 94 // cases. | 99 // cases. |
| 95 canvas->DrawStringWithHalo(title(), font, 0x00000000, 0xFFFFFFFF, | 100 canvas->DrawStringWithHalo(title(), font, 0x00000000, 0xFFFFFFFF, |
| 96 text_bounds.x(), text_bounds.y(), text_bounds.width(), | 101 text_bounds.x(), text_bounds.y(), text_bounds.width(), |
| 97 text_bounds.height(), GetRootMenuItem()->GetDrawStringFlags()); | 102 text_bounds.height(), flags); |
| 98 } else { | 103 } else { |
| 99 canvas->DrawStringInt(title(), font, fg_color, | 104 canvas->DrawStringInt(title(), font, fg_color, |
| 100 text_bounds.x(), text_bounds.y(), text_bounds.width(), | 105 text_bounds.x(), text_bounds.y(), text_bounds.width(), |
| 101 text_bounds.height(), | 106 text_bounds.height(), flags); |
| 102 GetRootMenuItem()->GetDrawStringFlags()); | |
| 103 } | 107 } |
| 104 | 108 |
| 105 PaintAccelerator(canvas); | 109 PaintAccelerator(canvas); |
| 106 | 110 |
| 107 if (icon_.width() > 0) { | 111 if (icon_.width() > 0) { |
| 108 gfx::Rect icon_bounds(config.item_left_margin, | 112 gfx::Rect icon_bounds(config.item_left_margin, |
| 109 top_margin + (height() - top_margin - | 113 top_margin + (this->height() - top_margin - |
| 110 bottom_margin - icon_.height()) / 2, | 114 bottom_margin - icon_.height()) / 2, |
| 111 icon_.width(), | 115 icon_.width(), |
| 112 icon_.height()); | 116 icon_.height()); |
| 113 icon_bounds.set_x(GetMirroredXForRect(icon_bounds)); | 117 icon_bounds.set_x(GetMirroredXForRect(icon_bounds)); |
| 114 canvas->DrawBitmapInt(icon_, icon_bounds.x(), icon_bounds.y()); | 118 canvas->DrawBitmapInt(icon_, icon_bounds.x(), icon_bounds.y()); |
| 115 } | 119 } |
| 116 | 120 |
| 117 if (HasSubmenu()) { | 121 if (HasSubmenu()) { |
| 118 int state_id = enabled() ? MSM_NORMAL : MSM_DISABLED; | 122 int state_id = enabled() ? MSM_NORMAL : MSM_DISABLED; |
| 119 gfx::Rect arrow_bounds(this->width() - item_right_margin_ + | 123 gfx::Rect arrow_bounds(this->width() - item_right_margin_ + |
| 120 config.label_to_arrow_padding, 0, | 124 config.label_to_arrow_padding, 0, |
| 121 config.arrow_width, height()); | 125 config.arrow_width, this->height()); |
| 122 AdjustBoundsForRTLUI(&arrow_bounds); | 126 AdjustBoundsForRTLUI(&arrow_bounds); |
| 123 | 127 |
| 124 // If our sub menus open from right to left (which is the case when the | 128 // If our sub menus open from right to left (which is the case when the |
| 125 // locale is RTL) then we should make sure the menu arrow points to the | 129 // locale is RTL) then we should make sure the menu arrow points to the |
| 126 // right direction. | 130 // right direction. |
| 127 ui::NativeTheme::ExtraParams extra; | 131 ui::NativeTheme::ExtraParams extra; |
| 128 extra.menu_arrow.pointing_right = !base::i18n::IsRTL(); | 132 extra.menu_arrow.pointing_right = !base::i18n::IsRTL(); |
| 129 extra.menu_arrow.is_selected = render_selection; | 133 extra.menu_arrow.is_selected = render_selection; |
| 130 ui::NativeTheme::instance()->Paint(canvas->sk_canvas(), | 134 ui::NativeTheme::instance()->Paint(canvas->sk_canvas(), |
| 131 ui::NativeTheme::kMenuPopupArrow, control_state, arrow_bounds, extra); | 135 ui::NativeTheme::kMenuPopupArrow, control_state, arrow_bounds, extra); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 161 NativeTheme::kMenuCheckBackground, state, bg_bounds, extra); | 165 NativeTheme::kMenuCheckBackground, state, bg_bounds, extra); |
| 162 | 166 |
| 163 // And the check. | 167 // And the check. |
| 164 gfx::Rect icon_bounds(icon_x / 2, icon_y, icon_width, icon_height); | 168 gfx::Rect icon_bounds(icon_x / 2, icon_y, icon_width, icon_height); |
| 165 AdjustBoundsForRTLUI(&icon_bounds); | 169 AdjustBoundsForRTLUI(&icon_bounds); |
| 166 NativeTheme::instance()->Paint(canvas->sk_canvas(), | 170 NativeTheme::instance()->Paint(canvas->sk_canvas(), |
| 167 NativeTheme::kMenuCheck, state, bg_bounds, extra); | 171 NativeTheme::kMenuCheck, state, bg_bounds, extra); |
| 168 } | 172 } |
| 169 | 173 |
| 170 } // namespace views | 174 } // namespace views |
| OLD | NEW |