summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-27 19:23:48 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-27 19:23:48 +0000
commit85f4dea28703717a1744722aecb7de30afc0de80 (patch)
tree9d13c30acf22cf75deb971fbcee8559987edc797
parent811d61a6fda8a160464c71fbafe42743e797a6d0 (diff)
downloadchromium_src-85f4dea28703717a1744722aecb7de30afc0de80.zip
chromium_src-85f4dea28703717a1744722aecb7de30afc0de80.tar.gz
chromium_src-85f4dea28703717a1744722aecb7de30afc0de80.tar.bz2
Makes rendering of selected disabled menu items match what windows does. As well as disallowing opening disabled child menus by way of the keyboard.
BUG=80837 TEST=none R=ben@chromium.org Review URL: http://codereview.chromium.org/7062031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87064 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/gfx/native_theme.h6
-rw-r--r--ui/gfx/native_theme_win.cc11
-rw-r--r--ui/gfx/native_theme_win.h1
-rw-r--r--views/controls/menu/menu_config_win.cc1
-rw-r--r--views/controls/menu/menu_controller.cc2
-rw-r--r--views/controls/menu/menu_item_view.h6
-rw-r--r--views/controls/menu/menu_item_view_win.cc29
7 files changed, 40 insertions, 16 deletions
diff --git a/ui/gfx/native_theme.h b/ui/gfx/native_theme.h
index 0d41767..650e2d1 100644
--- a/ui/gfx/native_theme.h
+++ b/ui/gfx/native_theme.h
@@ -99,10 +99,16 @@ class NativeTheme {
struct MenuArrowExtraParams {
bool pointing_right;
+ // Used for the disabled state to indicate if the item is both disabled and
+ // selected.
+ bool is_selected;
};
struct MenuCheckExtraParams {
bool is_radio;
+ // Used for the disabled state to indicate if the item is both disabled and
+ // selected.
+ bool is_selected;
};
struct MenuItemExtraParams {
diff --git a/ui/gfx/native_theme_win.cc b/ui/gfx/native_theme_win.cc
index 09a4140..3a54938 100644
--- a/ui/gfx/native_theme_win.cc
+++ b/ui/gfx/native_theme_win.cc
@@ -595,7 +595,8 @@ HRESULT NativeThemeWin::PaintMenuArrow(HDC hdc,
pfc_state = DFCS_MENUARROW;
else
pfc_state = DFCS_MENUARROWRIGHT;
- return PaintFrameControl(hdc, rect, DFC_MENU, pfc_state, state);
+ return PaintFrameControl(hdc, rect, DFC_MENU, pfc_state, extra.is_selected,
+ state);
}
HRESULT NativeThemeWin::PaintMenuBackground(HDC hdc,
@@ -644,7 +645,8 @@ HRESULT NativeThemeWin::PaintMenuCheck(
if (handle && draw_theme_)
return draw_theme_(handle, hdc, MENU_POPUPCHECK, state_id, &rect_win, NULL);
- return PaintFrameControl(hdc, rect, DFC_MENU, DFCS_MENUCHECK, state);
+ return PaintFrameControl(hdc, rect, DFC_MENU, DFCS_MENUCHECK,
+ extra.is_selected, state);
}
HRESULT NativeThemeWin::PaintMenuGutter(HDC hdc,
@@ -670,7 +672,7 @@ HRESULT NativeThemeWin::PaintMenuItemBackground(
state_id = MPI_NORMAL;
break;
case kDisabled:
- state_id = MPI_DISABLED;
+ state_id = extra.is_selected ? MPI_DISABLEDHOT : MPI_DISABLED;
break;
case kHovered:
state_id = MPI_HOT;
@@ -1208,6 +1210,7 @@ HRESULT NativeThemeWin::PaintFrameControl(HDC hdc,
const gfx::Rect& rect,
UINT type,
UINT state,
+ bool is_selected,
State control_state) const {
const int width = rect.width();
const int height = rect.height();
@@ -1239,7 +1242,7 @@ HRESULT NativeThemeWin::PaintFrameControl(HDC hdc,
text_color_key = COLOR_MENUTEXT;
break;
case gfx::NativeTheme::kDisabled:
- bg_color_key = COLOR_MENU;
+ bg_color_key = is_selected ? COLOR_HIGHLIGHT : COLOR_MENU;
text_color_key = COLOR_GRAYTEXT;
break;
default:
diff --git a/ui/gfx/native_theme_win.h b/ui/gfx/native_theme_win.h
index f192126..534990e 100644
--- a/ui/gfx/native_theme_win.h
+++ b/ui/gfx/native_theme_win.h
@@ -247,6 +247,7 @@ class NativeThemeWin : public NativeTheme {
const gfx::Rect& rect,
UINT type,
UINT state,
+ bool is_selected,
State control_state) const;
// Returns a handle to the theme data.
diff --git a/views/controls/menu/menu_config_win.cc b/views/controls/menu/menu_config_win.cc
index f272dc2..fce04ab 100644
--- a/views/controls/menu/menu_config_win.cc
+++ b/views/controls/menu/menu_config_win.cc
@@ -35,6 +35,7 @@ MenuConfig* MenuConfig::Create() {
NativeTheme::ExtraParams extra;
extra.menu_check.is_radio = false;
+ extra.menu_check.is_selected = false;
gfx::Size check_size = NativeTheme::instance()->GetPartSize(
NativeTheme::kMenuCheck, NativeTheme::kNormal, extra);
if (!check_size.IsEmpty()) {
diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc
index 022f176..a7227b5 100644
--- a/views/controls/menu/menu_controller.cc
+++ b/views/controls/menu/menu_controller.cc
@@ -1593,7 +1593,7 @@ MenuItemView* MenuController::FindNextSelectableMenuItem(MenuItemView* parent,
void MenuController::OpenSubmenuChangeSelectionIfCan() {
MenuItemView* item = pending_state_.item;
- if (item->HasSubmenu()) {
+ if (item->HasSubmenu() && item->IsEnabled()) {
if (item->GetSubmenu()->GetMenuItemCount() > 0) {
SetSelection(item->GetSubmenu()->GetMenuItemAt(0),
SELECTION_UPDATE_IMMEDIATELY);
diff --git a/views/controls/menu/menu_item_view.h b/views/controls/menu/menu_item_view.h
index 6fc945e..30747b9 100644
--- a/views/controls/menu/menu_item_view.h
+++ b/views/controls/menu/menu_item_view.h
@@ -363,10 +363,12 @@ class MenuItemView : public View {
void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode);
#if defined(OS_WIN)
- // Paints the check/radio button indicator. |part_id| is the id passed to the
- // native theme drawing routines.
+ enum SelectionState { SELECTED, UNSELECTED };
+
+ // Paints the check/radio button indicator.
void PaintCheck(gfx::Canvas* canvas,
gfx::NativeTheme::State state,
+ SelectionState selection_state,
const MenuConfig& config);
#endif
diff --git a/views/controls/menu/menu_item_view_win.cc b/views/controls/menu/menu_item_view_win.cc
index 82f1c0d..dd3807c 100644
--- a/views/controls/menu/menu_item_view_win.cc
+++ b/views/controls/menu/menu_item_view_win.cc
@@ -31,15 +31,24 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
(mode == PB_NORMAL && IsSelected() &&
parent_menu_item_->GetSubmenu()->GetShowSelection(this) &&
!has_children());
- int state = render_selection ? MPI_HOT :
- (IsEnabled() ? MPI_NORMAL : MPI_DISABLED);
+ int default_sys_color;
+ int state;
NativeTheme::State control_state;
- if (!IsEnabled()) {
- control_state = NativeTheme::kDisabled;
+ if (IsEnabled()) {
+ if (render_selection) {
+ control_state = NativeTheme::kHovered;
+ state = MPI_HOT;
+ default_sys_color = COLOR_HIGHLIGHTTEXT;
+ } else {
+ control_state = NativeTheme::kNormal;
+ state = MPI_NORMAL;
+ default_sys_color = COLOR_MENUTEXT;
+ }
} else {
- control_state = render_selection ? NativeTheme::kHovered:
- NativeTheme::kNormal;
+ state = MPI_DISABLED;
+ default_sys_color = COLOR_GRAYTEXT;
+ control_state = NativeTheme::kDisabled;
}
// The gutter is rendered before the background.
@@ -71,14 +80,13 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
if ((type_ == RADIO || type_ == CHECKBOX) &&
GetDelegate()->IsItemChecked(GetCommand())) {
- PaintCheck(canvas, control_state, config);
+ PaintCheck(canvas, control_state, render_selection ? SELECTED : UNSELECTED,
+ config);
}
// Render the foreground.
// Menu color is specific to Vista, fallback to classic colors if can't
// get color.
- int default_sys_color = render_selection ? COLOR_HIGHLIGHTTEXT :
- (IsEnabled() ? COLOR_MENUTEXT : COLOR_GRAYTEXT);
SkColor fg_color = gfx::NativeThemeWin::instance()->GetThemeColorWithDefault(
gfx::NativeThemeWin::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR,
default_sys_color);
@@ -127,6 +135,7 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
// right direction.
gfx::NativeTheme::ExtraParams extra;
extra.menu_arrow.pointing_right = !base::i18n::IsRTL();
+ extra.menu_arrow.is_selected = render_selection;
gfx::NativeTheme::instance()->Paint(canvas->AsCanvasSkia(),
gfx::NativeTheme::kMenuPopupArrow, control_state, arrow_bounds, extra);
}
@@ -134,6 +143,7 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
void MenuItemView::PaintCheck(gfx::Canvas* canvas,
NativeTheme::State state,
+ SelectionState selection_state,
const MenuConfig& config) {
int icon_width;
int icon_height;
@@ -151,6 +161,7 @@ void MenuItemView::PaintCheck(gfx::Canvas* canvas,
(height() - top_margin - GetBottomMargin() - icon_height) / 2;
NativeTheme::ExtraParams extra;
extra.menu_check.is_radio = type_ == RADIO;
+ extra.menu_check.is_selected = selection_state == SELECTED;
// Draw the background.
gfx::Rect bg_bounds(0, 0, icon_x + icon_width, height());