diff options
-rw-r--r-- | ui/gfx/native_theme.h | 27 | ||||
-rw-r--r-- | ui/gfx/native_theme_win.cc | 223 | ||||
-rw-r--r-- | ui/gfx/native_theme_win.h | 126 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view.h | 14 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view_win.cc | 93 | ||||
-rw-r--r-- | views/controls/menu/menu_scroll_view_container.cc | 29 | ||||
-rw-r--r-- | views/controls/menu/menu_separator_win.cc | 34 | ||||
-rw-r--r-- | webkit/glue/webthemeengine_impl_win.cc | 358 |
8 files changed, 628 insertions, 276 deletions
diff --git a/ui/gfx/native_theme.h b/ui/gfx/native_theme.h index 77a9f04..9c2f83f 100644 --- a/ui/gfx/native_theme.h +++ b/ui/gfx/native_theme.h @@ -46,6 +46,13 @@ class NativeTheme { kPushButton, kTextField, kMenuList, + kMenuCheck, + kMenuCheckBackground, + kMenuPopupArrow, + kMenuPopupBackground, + kMenuPopupGutter, + kMenuPopupSeparator, + kMenuItemBackground, kSliderTrack, kSliderThumb, kInnerSpinButton, @@ -87,6 +94,18 @@ class NativeTheme { SkColor background_color; }; + struct MenuArrowExtraParams { + bool pointing_right; + }; + + struct MenuCheckExtraParams { + bool is_radio; + }; + + struct MenuItemExtraParams { + bool is_selected; + }; + struct MenuListExtraParams { bool has_border; bool has_border_radius; @@ -95,6 +114,10 @@ class NativeTheme { SkColor background_color; }; + struct MenuSeparatorExtraParams { + bool has_gutter; + }; + struct SliderExtraParams { bool vertical; bool in_drag; @@ -116,7 +139,11 @@ class NativeTheme { union ExtraParams { ScrollbarTrackExtraParams scrollbar_track; ButtonExtraParams button; + MenuArrowExtraParams menu_arrow; + MenuCheckExtraParams menu_check; + MenuItemExtraParams menu_item; MenuListExtraParams menu_list; + MenuSeparatorExtraParams menu_separator; SliderExtraParams slider; TextFieldExtraParams text_field; InnerSpinButtonExtraParams inner_spin; diff --git a/ui/gfx/native_theme_win.cc b/ui/gfx/native_theme_win.cc index e0364b7..e61ed17 100644 --- a/ui/gfx/native_theme_win.cc +++ b/ui/gfx/native_theme_win.cc @@ -140,6 +140,29 @@ void NativeThemeWin::Paint(SkCanvas* canvas, case kPushButton: PaintPushButton(hdc, part, state, rect, extra.button); break; + case kMenuPopupArrow: + PaintMenuArrow(hdc, state, rect, extra.menu_arrow); + break; + case kMenuPopupGutter: + PaintMenuGutter(hdc, rect); + break; + case kMenuPopupSeparator: + PaintMenuSeparator(hdc, rect, extra.menu_separator); + break; + case kMenuPopupBackground: + PaintMenuBackground(hdc, rect); + break; + case kMenuCheck: + PaintMenuCheck(hdc, state, rect, extra.menu_check); + break; + case kMenuCheckBackground: + PaintMenuCheckBackground(hdc, state, rect); + break; + case kMenuItemBackground: + PaintMenuItemBackground(hdc, state, rect, extra.menu_item); + break; + + case kMenuList: case kScrollbarDownArrow: case kScrollbarUpArrow: case kScrollbarLeftArrow: @@ -149,7 +172,6 @@ void NativeThemeWin::Paint(SkCanvas* canvas, case kScrollbarHorizontalTrack: case kScrollbarVerticalTrack: case kTextField: - case kMenuList: case kSliderTrack: case kSliderThumb: case kInnerSpinButton: @@ -354,50 +376,27 @@ HRESULT NativeThemeWin::PaintButton(HDC hdc, return S_OK; } -HRESULT NativeThemeWin::PaintDialogBackground(HDC hdc, bool active, - RECT* rect) const { - HANDLE handle = GetThemeHandle(WINDOW); - if (handle && draw_theme_) { - return draw_theme_(handle, hdc, WP_DIALOG, - active ? FS_ACTIVE : FS_INACTIVE, rect, NULL); - } - - // Classic just renders a flat color background. - FillRect(hdc, rect, reinterpret_cast<HBRUSH>(COLOR_3DFACE + 1)); - return S_OK; -} +HRESULT NativeThemeWin::PaintMenuArrow(HDC hdc, + State state, + const gfx::Rect& rect, + const MenuArrowExtraParams& extra) + const { + int state_id = MSM_NORMAL; + if (state == kDisabled) + state_id = MSM_DISABLED; -HRESULT NativeThemeWin::PaintListBackground(HDC hdc, - bool enabled, - RECT* rect) const { - HANDLE handle = GetThemeHandle(LIST); - if (handle && draw_theme_) - return draw_theme_(handle, hdc, 1, TS_NORMAL, rect, NULL); - - // Draw it manually. - HBRUSH bg_brush = GetSysColorBrush(COLOR_WINDOW); - FillRect(hdc, rect, bg_brush); - DrawEdge(hdc, rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST); - return S_OK; -} - -HRESULT NativeThemeWin::PaintMenuArrow(ThemeName theme, - HDC hdc, - int part_id, - int state_id, - RECT* rect, - MenuArrowDirection arrow_direction, - ControlState control_state) const { HANDLE handle = GetThemeHandle(MENU); + RECT rect_win = rect.ToRECT(); if (handle && draw_theme_) { - if (arrow_direction == RIGHT_POINTING_ARROW) { - return draw_theme_(handle, hdc, part_id, state_id, rect, NULL); + if (extra.pointing_right) { + return draw_theme_(handle, hdc, MENU_POPUPSUBMENU, state_id, &rect_win, + NULL); } else { // There is no way to tell the uxtheme API to draw a left pointing arrow; // it doesn't have a flag equivalent to DFCS_MENUARROWRIGHT. But they // are needed for RTL locales on Vista. So use a memory DC and mirror // the region with GDI's StretchBlt. - Rect r(*rect); + Rect r(rect); base::win::ScopedHDC mem_dc(CreateCompatibleDC(hdc)); base::win::ScopedBitmap mem_bitmap(CreateCompatibleBitmap(hdc, r.width(), r.height())); @@ -408,7 +407,7 @@ HRESULT NativeThemeWin::PaintMenuArrow(ThemeName theme, hdc, r.right()-1, r.y(), -r.width(), r.height(), SRCCOPY); // Draw the arrow. RECT theme_rect = {0, 0, r.width(), r.height()}; - HRESULT result = draw_theme_(handle, mem_dc, part_id, + HRESULT result = draw_theme_(handle, mem_dc, MENU_POPUPSUBMENU, state_id, &theme_rect, NULL); // Copy and mirror the result back into mem_dc. StretchBlt(hdc, r.x(), r.y(), r.width(), r.height(), @@ -421,77 +420,101 @@ HRESULT NativeThemeWin::PaintMenuArrow(ThemeName theme, // For some reason, Windows uses the name DFCS_MENUARROWRIGHT to indicate a // left pointing arrow. This makes the following 'if' statement slightly // counterintuitive. - UINT state; - if (arrow_direction == RIGHT_POINTING_ARROW) - state = DFCS_MENUARROW; + UINT pfc_state; + if (extra.pointing_right) + pfc_state = DFCS_MENUARROW; else - state = DFCS_MENUARROWRIGHT; - return PaintFrameControl(hdc, rect, DFC_MENU, state, control_state); + pfc_state = DFCS_MENUARROWRIGHT; + return PaintFrameControl(hdc, rect, DFC_MENU, pfc_state, state); } -HRESULT NativeThemeWin::PaintMenuBackground(ThemeName theme, - HDC hdc, - int part_id, - int state_id, - RECT* rect) const { +HRESULT NativeThemeWin::PaintMenuBackground(HDC hdc, + const gfx::Rect& rect) const { HANDLE handle = GetThemeHandle(MENU); + RECT rect_win = rect.ToRECT(); if (handle && draw_theme_) { - HRESULT result = draw_theme_(handle, hdc, part_id, state_id, rect, NULL); - FrameRect(hdc, rect, GetSysColorBrush(COLOR_3DSHADOW)); + HRESULT result = draw_theme_(handle, hdc, MENU_POPUPBACKGROUND, 0, + &rect_win, NULL); + FrameRect(hdc, &rect_win, GetSysColorBrush(COLOR_3DSHADOW)); return result; } - FillRect(hdc, rect, GetSysColorBrush(COLOR_MENU)); - DrawEdge(hdc, rect, EDGE_RAISED, BF_RECT); + FillRect(hdc, &rect_win, GetSysColorBrush(COLOR_MENU)); + DrawEdge(hdc, &rect_win, EDGE_RAISED, BF_RECT); return S_OK; } -HRESULT NativeThemeWin::PaintMenuCheckBackground(ThemeName theme, - HDC hdc, - int part_id, - int state_id, - RECT* rect) const { +HRESULT NativeThemeWin::PaintMenuCheckBackground(HDC hdc, + State state, + const gfx::Rect& rect) const { HANDLE handle = GetThemeHandle(MENU); + int state_id = state == kDisabled ? MCB_DISABLED : MCB_NORMAL; + RECT rect_win = rect.ToRECT(); if (handle && draw_theme_) - return draw_theme_(handle, hdc, part_id, state_id, rect, NULL); + return draw_theme_(handle, hdc, MENU_POPUPCHECKBACKGROUND, state_id, + &rect_win, NULL); // Nothing to do for background. return S_OK; } -HRESULT NativeThemeWin::PaintMenuCheck(ThemeName theme, - HDC hdc, - int part_id, - int state_id, - RECT* rect, - ControlState control_state) const { +HRESULT NativeThemeWin::PaintMenuCheck( + HDC hdc, + State state, + const gfx::Rect& rect, + const MenuCheckExtraParams& extra) const { HANDLE handle = GetThemeHandle(MENU); - if (handle && draw_theme_) { - return draw_theme_(handle, hdc, part_id, state_id, rect, NULL); + int state_id; + if (extra.is_radio) { + state_id = state == kDisabled ? MC_BULLETDISABLED : MC_BULLETNORMAL; + } else { + state_id = state == kDisabled ? MC_CHECKMARKDISABLED : MC_CHECKMARKNORMAL; } - return PaintFrameControl(hdc, rect, DFC_MENU, DFCS_MENUCHECK, control_state); + + RECT rect_win = rect.ToRECT(); + 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); } HRESULT NativeThemeWin::PaintMenuGutter(HDC hdc, - int part_id, - int state_id, - RECT* rect) const { + const gfx::Rect& rect) const { + RECT rect_win = rect.ToRECT(); HANDLE handle = GetThemeHandle(MENU); if (handle && draw_theme_) - return draw_theme_(handle, hdc, part_id, state_id, rect, NULL); + return draw_theme_(handle, hdc, MENU_POPUPGUTTER, MPI_NORMAL, &rect_win, + NULL); return E_NOTIMPL; } -HRESULT NativeThemeWin::PaintMenuItemBackground(ThemeName theme, - HDC hdc, - int part_id, - int state_id, - bool selected, - RECT* rect) const { +HRESULT NativeThemeWin::PaintMenuItemBackground( + HDC hdc, + State state, + const gfx::Rect& rect, + const MenuItemExtraParams& extra) const { HANDLE handle = GetThemeHandle(MENU); + RECT rect_win = rect.ToRECT(); + int state_id; + switch(state) { + case kNormal: + state_id = MPI_NORMAL; + break; + case kDisabled: + state_id = MPI_DISABLED; + break; + case kHovered: + state_id = MPI_HOT; + break; + default: + NOTREACHED() << "Invalid state " << state; + break; + } + if (handle && draw_theme_) - return draw_theme_(handle, hdc, part_id, state_id, rect, NULL); - if (selected) - FillRect(hdc, rect, GetSysColorBrush(COLOR_HIGHLIGHT)); + return draw_theme_(handle, hdc, MENU_POPUPITEM, state_id, &rect_win, NULL); + + if (extra.is_selected) + FillRect(hdc, &rect_win, GetSysColorBrush(COLOR_HIGHLIGHT)); return S_OK; } @@ -509,14 +532,24 @@ HRESULT NativeThemeWin::PaintMenuList(HDC hdc, return S_OK; } -HRESULT NativeThemeWin::PaintMenuSeparator(HDC hdc, - int part_id, - int state_id, - RECT* rect) const { +HRESULT NativeThemeWin::PaintMenuSeparator( + HDC hdc, + const gfx::Rect& rect, + const MenuSeparatorExtraParams& extra) const { + RECT rect_win = rect.ToRECT(); + if (!extra.has_gutter) + rect_win.top = rect.y() + rect.height() / 3 + 1; + HANDLE handle = GetThemeHandle(MENU); - if (handle && draw_theme_) - return draw_theme_(handle, hdc, part_id, state_id, rect, NULL); - DrawEdge(hdc, rect, EDGE_ETCHED, BF_TOP); + if (handle && draw_theme_) { + // Delta is needed for non-classic to move separator up slightly. + --rect_win.top; + --rect_win.bottom; + return draw_theme_(handle, hdc, MENU_POPUPSEPARATOR, MPI_NORMAL, &rect_win, + NULL); + } + + DrawEdge(hdc, &rect_win, EDGE_ETCHED, BF_TOP); return S_OK; } @@ -951,12 +984,12 @@ void NativeThemeWin::DisableTheming() const { } HRESULT NativeThemeWin::PaintFrameControl(HDC hdc, - RECT* rect, + const gfx::Rect& rect, UINT type, UINT state, - ControlState control_state) const { - const int width = rect->right - rect->left; - const int height = rect->bottom - rect->top; + State control_state) const { + const int width = rect.width(); + const int height = rect.height(); // DrawFrameControl for menu arrow/check wants a monochrome bitmap. base::win::ScopedBitmap mask_bitmap(CreateBitmap(width, height, 1, 1, NULL)); @@ -976,15 +1009,15 @@ HRESULT NativeThemeWin::PaintFrameControl(HDC hdc, int bg_color_key; int text_color_key; switch (control_state) { - case CONTROL_HIGHLIGHTED: + case gfx::NativeTheme::kHovered: bg_color_key = COLOR_HIGHLIGHT; text_color_key = COLOR_HIGHLIGHTTEXT; break; - case CONTROL_NORMAL: + case gfx::NativeTheme::kNormal: bg_color_key = COLOR_MENU; text_color_key = COLOR_MENUTEXT; break; - case CONTROL_DISABLED: + case gfx::NativeTheme::kDisabled: bg_color_key = COLOR_MENU; text_color_key = COLOR_GRAYTEXT; break; @@ -996,7 +1029,7 @@ HRESULT NativeThemeWin::PaintFrameControl(HDC hdc, } COLORREF old_bg_color = SetBkColor(hdc, GetSysColor(bg_color_key)); COLORREF old_text_color = SetTextColor(hdc, GetSysColor(text_color_key)); - BitBlt(hdc, rect->left, rect->top, width, height, bitmap_dc, 0, 0, SRCCOPY); + BitBlt(hdc, rect.x(), rect.y(), width, height, bitmap_dc, 0, 0, SRCCOPY); SetBkColor(hdc, old_bg_color); SetTextColor(hdc, old_text_color); diff --git a/ui/gfx/native_theme_win.h b/ui/gfx/native_theme_win.h index d92ba58..3e8faeb 100644 --- a/ui/gfx/native_theme_win.h +++ b/ui/gfx/native_theme_win.h @@ -100,23 +100,6 @@ class NativeThemeWin : public NativeTheme { // Gets our singleton instance. static const NativeThemeWin* instance(); - // The PaintXXX methods below this point should be private or be deleted, - // but remain public while NativeThemeWin is transitioned over to use the - // single Paint() entry point. Do not make new calls to these methods. - - // This enumeration is used within PaintMenuArrow in order to indicate the - // direction the menu arrow should point to. - enum MenuArrowDirection { - LEFT_POINTING_ARROW, - RIGHT_POINTING_ARROW - }; - - enum ControlState { - CONTROL_NORMAL, - CONTROL_HIGHLIGHTED, - CONTROL_DISABLED - }; - typedef HRESULT (WINAPI* DrawThemeBackgroundPtr)(HANDLE theme, HDC hdc, int part_id, @@ -159,66 +142,9 @@ class NativeThemeWin : public NativeTheme { int prop_id, int *value); - // This method is deprecated and will be removed in the near future. - HRESULT PaintButton(HDC hdc, - int part_id, - int state_id, - int classic_state, - RECT* rect) const; - - // This method is deprecated and will be removed in the near future. - HRESULT PaintDialogBackground(HDC dc, bool active, RECT* rect) const; - - // This method is deprecated and will be removed in the near future. - HRESULT PaintListBackground(HDC dc, bool enabled, RECT* rect) const; - - // This method is deprecated and will be removed in the near future. - // |arrow_direction| determines whether the arrow is pointing to the left or - // to the right. In RTL locales, sub-menus open from right to left and - // therefore the menu arrow should point to the left and not to the right. - HRESULT PaintMenuArrow(ThemeName theme, - HDC hdc, - int part_id, - int state_id, - RECT* rect, - MenuArrowDirection arrow_direction, - ControlState state) const; - - // This method is deprecated and will be removed in the near future. - HRESULT PaintMenuBackground(ThemeName theme, - HDC hdc, - int part_id, - int state_id, - RECT* rect) const; - - // This method is deprecated and will be removed in the near future. - HRESULT PaintMenuCheck(ThemeName theme, - HDC hdc, - int part_id, - int state_id, - RECT* rect, - ControlState state) const; - - // This method is deprecated and will be removed in the near future. - HRESULT PaintMenuCheckBackground(ThemeName theme, - HDC hdc, - int part_id, - int state_id, - RECT* rect) const; - - // This method is deprecated and will be removed in the near future. - HRESULT PaintMenuGutter(HDC hdc, - int part_id, - int state_id, - RECT* rect) const; - - // This method is deprecated and will be removed in the near future. - HRESULT PaintMenuItemBackground(ThemeName theme, - HDC hdc, - int part_id, - int state_id, - bool selected, - RECT* rect) const; + // The PaintXXX methods below this point should be private or be deleted, + // but remain public while NativeThemeWin is transitioned over to use the + // single Paint() entry point. Do not make new calls to these methods. // This method is deprecated and will be removed in the near future. HRESULT PaintMenuList(HDC hdc, @@ -228,12 +154,6 @@ class NativeThemeWin : public NativeTheme { RECT* rect) const; // This method is deprecated and will be removed in the near future. - HRESULT PaintMenuSeparator(HDC hdc, - int part_id, - int state_id, - RECT* rect) const; - - // This method is deprecated and will be removed in the near future. // Paints a scrollbar arrow. |classic_state| should have the appropriate // classic part number ORed in already. HRESULT PaintScrollbarArrow(HDC hdc, @@ -316,6 +236,42 @@ class NativeThemeWin : public NativeTheme { const gfx::Rect& rect, const ExtraParams& extra) const; + HRESULT PaintButton(HDC hdc, + int part_id, + int state_id, + int classic_state, + RECT* rect) const; + + HRESULT PaintMenuSeparator(HDC hdc, + const gfx::Rect& rect, + const MenuSeparatorExtraParams& extra) const; + + HRESULT PaintMenuGutter(HDC hdc, const gfx::Rect& rect) const; + + // |arrow_direction| determines whether the arrow is pointing to the left or + // to the right. In RTL locales, sub-menus open from right to left and + // therefore the menu arrow should point to the left and not to the right. + HRESULT PaintMenuArrow(HDC hdc, + State state, + const gfx::Rect& rect, + const MenuArrowExtraParams& extra) const; + + HRESULT PaintMenuBackground(HDC hdc, const gfx::Rect& rect) const; + + HRESULT PaintMenuCheck(HDC hdc, + State state, + const gfx::Rect& rect, + const MenuCheckExtraParams& extra) const; + + HRESULT PaintMenuCheckBackground(HDC hdc, + State state, + const gfx::Rect& rect) const; + + HRESULT PaintMenuItemBackground(HDC hdc, + State state, + const gfx::Rect& rect, + const MenuItemExtraParams& extra) const; + // Paints a scrollbar arrow. |classic_state| should have the appropriate // classic part number ORed in already. HRESULT PaintScrollbarArrow(HDC hdc, @@ -353,10 +309,10 @@ class NativeThemeWin : public NativeTheme { static int GetWindowsPart(Part part); HRESULT PaintFrameControl(HDC hdc, - RECT* rect, + const gfx::Rect& rect, UINT type, UINT state, - ControlState control_state) const; + State control_state) const; // Returns a handle to the theme data. HANDLE GetThemeHandle(ThemeName theme_name) const; diff --git a/views/controls/menu/menu_item_view.h b/views/controls/menu/menu_item_view.h index 936f857..980f2d6 100644 --- a/views/controls/menu/menu_item_view.h +++ b/views/controls/menu/menu_item_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -18,7 +18,7 @@ #include "views/view.h" #if defined(OS_WIN) -#include "ui/gfx/native_theme_win.h" +#include "ui/gfx/native_theme.h" #endif namespace ui { @@ -32,6 +32,8 @@ class MenuController; class MenuDelegate; class SubmenuView; +struct MenuConfig; + // MenuItemView -------------------------------------------------------------- // MenuItemView represents a single menu item with a label and optional icon. @@ -334,11 +336,9 @@ class MenuItemView : public View { #if defined(OS_WIN) // Paints the check/radio button indicator. |part_id| is the id passed to the // native theme drawing routines. - void PaintCheck(HDC dc, - int part_id, - gfx::NativeThemeWin::ControlState control_state, - int icon_width, - int icon_height); + void PaintCheck(gfx::Canvas* canvas, + gfx::NativeTheme::State state, + const MenuConfig& config); #endif // Paints the accelerator. diff --git a/views/controls/menu/menu_item_view_win.cc b/views/controls/menu/menu_item_view_win.cc index 41fdad8..e71f8c1 100644 --- a/views/controls/menu/menu_item_view_win.cc +++ b/views/controls/menu/menu_item_view_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,7 +13,7 @@ #include "views/controls/menu/menu_config.h" #include "views/controls/menu/submenu_view.h" -using gfx::NativeThemeWin; +using gfx::NativeTheme; namespace views { @@ -33,14 +33,13 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { !has_children()); int state = render_selection ? MPI_HOT : (IsEnabled() ? MPI_NORMAL : MPI_DISABLED); - HDC dc = canvas->BeginPlatformPaint(); - NativeThemeWin::ControlState control_state; + NativeTheme::State control_state; if (!IsEnabled()) { - control_state = NativeThemeWin::CONTROL_DISABLED; + control_state = NativeTheme::kDisabled; } else { - control_state = render_selection ? NativeThemeWin::CONTROL_HIGHLIGHTED : - NativeThemeWin::CONTROL_NORMAL; + control_state = render_selection ? NativeTheme::kHovered: + NativeTheme::kNormal; } // The gutter is rendered before the background. @@ -49,31 +48,30 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { config.gutter_width, 0, config.gutter_width, height()); AdjustBoundsForRTLUI(&gutter_bounds); - RECT gutter_rect = gutter_bounds.ToRECT(); - NativeThemeWin::instance()->PaintMenuGutter(dc, MENU_POPUPGUTTER, - MPI_NORMAL, &gutter_rect); + NativeTheme::ExtraParams extra; + NativeTheme::instance()->Paint(canvas->AsCanvasSkia(), + NativeTheme::kMenuPopupGutter, + NativeTheme::kNormal, + gutter_bounds, + extra); } // Render the background. if (mode == PB_NORMAL) { gfx::Rect item_bounds(0, 0, width(), height()); + NativeTheme::ExtraParams extra; + extra.menu_item.is_selected = render_selection; AdjustBoundsForRTLUI(&item_bounds); - RECT item_rect = item_bounds.ToRECT(); - NativeThemeWin::instance()->PaintMenuItemBackground( - NativeThemeWin::MENU, dc, MENU_POPUPITEM, state, render_selection, - &item_rect); + NativeTheme::instance()->Paint(canvas->AsCanvasSkia(), + NativeTheme::kMenuItemBackground, control_state, item_bounds, extra); } int top_margin = GetTopMargin(); int bottom_margin = GetBottomMargin(); - if (type_ == CHECKBOX && GetDelegate()->IsItemChecked(GetCommand())) { - PaintCheck(dc, - IsEnabled() ? MC_CHECKMARKNORMAL : MC_CHECKMARKDISABLED, - control_state, config.check_height, config.check_width); - } else if (type_ == RADIO && GetDelegate()->IsItemChecked(GetCommand())) { - PaintCheck(dc, IsEnabled() ? MC_BULLETNORMAL : MC_BULLETDISABLED, - control_state, config.radio_height, config.radio_width); + if ((type_ == RADIO || type_ == CHECKBOX) && + GetDelegate()->IsItemChecked(GetCommand())) { + PaintCheck(canvas, control_state, config); } // Render the foreground. @@ -81,8 +79,8 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { // get color. int default_sys_color = render_selection ? COLOR_HIGHLIGHTTEXT : (IsEnabled() ? COLOR_MENUTEXT : COLOR_GRAYTEXT); - SkColor fg_color = NativeThemeWin::instance()->GetThemeColorWithDefault( - NativeThemeWin::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR, + SkColor fg_color = gfx::NativeThemeWin::instance()->GetThemeColorWithDefault( + gfx::NativeThemeWin::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR, default_sys_color); const gfx::Font& font = MenuConfig::instance().font; int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); @@ -127,45 +125,44 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { // If our sub menus open from right to left (which is the case when the // locale is RTL) then we should make sure the menu arrow points to the // right direction. - NativeThemeWin::MenuArrowDirection arrow_direction; - if (base::i18n::IsRTL()) - arrow_direction = NativeThemeWin::LEFT_POINTING_ARROW; - else - arrow_direction = NativeThemeWin::RIGHT_POINTING_ARROW; - - RECT arrow_rect = arrow_bounds.ToRECT(); - NativeThemeWin::instance()->PaintMenuArrow( - NativeThemeWin::MENU, dc, MENU_POPUPSUBMENU, state_id, &arrow_rect, - arrow_direction, control_state); + gfx::NativeTheme::ExtraParams extra; + extra.menu_arrow.pointing_right = !base::i18n::IsRTL(); + gfx::NativeTheme::instance()->Paint(canvas->AsCanvasSkia(), + gfx::NativeTheme::kMenuPopupArrow, control_state, arrow_bounds, extra); } - canvas->EndPlatformPaint(); } -void MenuItemView::PaintCheck(HDC dc, - int state_id, - NativeThemeWin::ControlState control_state, - int icon_width, - int icon_height) { +void MenuItemView::PaintCheck(gfx::Canvas* canvas, + NativeTheme::State state, + const MenuConfig& config) { + int icon_width; + int icon_height; + if (type_ == RADIO) { + icon_width = config.radio_width; + icon_height = config.radio_height; + } else { + icon_width = config.check_width; + icon_height = config.check_height; + } + int top_margin = GetTopMargin(); int icon_x = MenuConfig::instance().item_left_margin; int icon_y = top_margin + (height() - top_margin - GetBottomMargin() - icon_height) / 2; + NativeTheme::ExtraParams extra; + extra.menu_check.is_radio = type_ == RADIO; + // Draw the background. gfx::Rect bg_bounds(0, 0, icon_x + icon_width, height()); - int bg_state = IsEnabled() ? MCB_NORMAL : MCB_DISABLED; AdjustBoundsForRTLUI(&bg_bounds); - RECT bg_rect = bg_bounds.ToRECT(); - NativeThemeWin::instance()->PaintMenuCheckBackground( - NativeThemeWin::MENU, dc, MENU_POPUPCHECKBACKGROUND, bg_state, - &bg_rect); + NativeTheme::instance()->Paint(canvas->AsCanvasSkia(), + NativeTheme::kMenuCheckBackground, state, bg_bounds, extra); // And the check. gfx::Rect icon_bounds(icon_x / 2, icon_y, icon_width, icon_height); AdjustBoundsForRTLUI(&icon_bounds); - RECT icon_rect = icon_bounds.ToRECT(); - NativeThemeWin::instance()->PaintMenuCheck( - NativeThemeWin::MENU, dc, MENU_POPUPCHECK, state_id, &icon_rect, - control_state); + NativeTheme::instance()->Paint(canvas->AsCanvasSkia(), + NativeTheme::kMenuCheck, state, bg_bounds, extra); } } // namespace views diff --git a/views/controls/menu/menu_scroll_view_container.cc b/views/controls/menu/menu_scroll_view_container.cc index 94bd75b..6aed7cf 100644 --- a/views/controls/menu/menu_scroll_view_container.cc +++ b/views/controls/menu/menu_scroll_view_container.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -21,11 +21,9 @@ #include "views/controls/menu/submenu_view.h" #if defined(OS_WIN) -#include "ui/gfx/native_theme_win.h" -#endif +#include "ui/gfx/native_theme.h" -#if defined(OS_WIN) -using gfx::NativeThemeWin; +using gfx::NativeTheme; #endif // Height of the scroll arrow. @@ -84,15 +82,13 @@ class MenuScrollButton : public View { const MenuConfig& config = MenuConfig::instance(); #if defined(OS_WIN) - HDC dc = canvas->BeginPlatformPaint(); - // The background. - RECT item_bounds = { 0, 0, width(), height() }; - NativeThemeWin::instance()->PaintMenuItemBackground( - NativeThemeWin::MENU, dc, MENU_POPUPITEM, MPI_NORMAL, false, - &item_bounds); - canvas->EndPlatformPaint(); - + gfx::Rect item_bounds(0, 0, width(), height()); + NativeTheme::ExtraParams extra; + extra.menu_item.is_selected = false; + NativeTheme::instance()->Paint(canvas->AsCanvasSkia(), + NativeTheme::kMenuItemBackground, + NativeTheme::kNormal, item_bounds, extra); SkColor arrow_color = color_utils::GetSysSkColor(COLOR_MENUTEXT); #else SkColor arrow_color = SK_ColorBLACK; @@ -188,9 +184,10 @@ void MenuScrollViewContainer::OnPaintBackground(gfx::Canvas* canvas) { #if defined(OS_WIN) HDC dc = canvas->BeginPlatformPaint(); - RECT bounds = {0, 0, width(), height()}; - NativeThemeWin::instance()->PaintMenuBackground( - NativeThemeWin::MENU, dc, MENU_POPUPBACKGROUND, 0, &bounds); + gfx::Rect bounds(0, 0, width(), height()); + NativeTheme::ExtraParams extra; + NativeTheme::instance()->Paint(canvas->AsCanvasSkia(), + NativeTheme::kMenuPopupBackground, NativeTheme::kNormal, bounds, extra); canvas->EndPlatformPaint(); #elif defined(OS_CHROMEOS) static const SkColor kGradientColors[2] = { diff --git a/views/controls/menu/menu_separator_win.cc b/views/controls/menu/menu_separator_win.cc index d997dbd..e089149 100644 --- a/views/controls/menu/menu_separator_win.cc +++ b/views/controls/menu/menu_separator_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,7 +9,8 @@ #include <Vssym32.h> #include "ui/gfx/canvas_skia.h" -#include "ui/gfx/native_theme_win.h" +#include "ui/gfx/native_theme.h" +#include "ui/gfx/rect.h" #include "views/controls/menu/menu_config.h" #include "views/controls/menu/menu_item_view.h" @@ -19,27 +20,24 @@ void MenuSeparator::OnPaint(gfx::Canvas* canvas) { const MenuConfig& config = MenuConfig::instance(); // The gutter is rendered before the background. int start_x = 0; - int start_y = height() / 3 + 1; // +1 makes separator centered. - HDC dc = canvas->BeginPlatformPaint(); - const gfx::NativeThemeWin* theme = gfx::NativeThemeWin::instance(); - // Delta is needed for non-classic to move separator up slightly. - int delta = theme->IsClassicTheme(gfx::NativeThemeWin::MENU) ? 0 : 1; + const gfx::NativeTheme* theme = gfx::NativeTheme::instance(); if (config.render_gutter) { // If render_gutter is true, we're on Vista and need to render the // gutter, then indent the separator from the gutter. - RECT gutter_bounds = { MenuItemView::label_start() - - config.gutter_to_label - config.gutter_width, 0, 0, - height() }; - gutter_bounds.right = gutter_bounds.left + config.gutter_width; - theme->PaintMenuGutter(dc, MENU_POPUPGUTTER, MPI_NORMAL, &gutter_bounds); - start_x = gutter_bounds.left + config.gutter_width; - start_y = -delta; + gfx::Rect gutter_bounds(MenuItemView::label_start() - + config.gutter_to_label - config.gutter_width, 0, + config.gutter_width, height()); + gfx::NativeTheme::ExtraParams extra; + theme->Paint(canvas->AsCanvasSkia(), gfx::NativeTheme::kMenuPopupGutter, + gfx::NativeTheme::kNormal, gutter_bounds, extra); + start_x = gutter_bounds.x() + config.gutter_width; } - RECT separator_bounds = { start_x, start_y, width(), height() - delta }; - theme->PaintMenuSeparator( - dc, MENU_POPUPSEPARATOR, MPI_NORMAL, &separator_bounds); - canvas->EndPlatformPaint(); + gfx::Rect separator_bounds(start_x, 0, width(), height()); + gfx::NativeTheme::ExtraParams extra; + extra.menu_separator.has_gutter = config.render_gutter; + theme->Paint(canvas->AsCanvasSkia(), gfx::NativeTheme::kMenuPopupSeparator, + gfx::NativeTheme::kNormal, separator_bounds, extra); } gfx::Size MenuSeparator::GetPreferredSize() { diff --git a/webkit/glue/webthemeengine_impl_win.cc b/webkit/glue/webthemeengine_impl_win.cc index 61e78ca..5f5d089b 100644 --- a/webkit/glue/webthemeengine_impl_win.cc +++ b/webkit/glue/webthemeengine_impl_win.cc @@ -4,6 +4,9 @@ #include "webkit/glue/webthemeengine_impl_win.h" +#include <vsstyle.h> // To convert to gfx::NativeTheme::State + +#include "base/logging.h" #include "skia/ext/platform_canvas.h" #include "skia/ext/skia_utils_win.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" @@ -24,16 +27,357 @@ static RECT WebRectToRECT(const WebRect& rect) { return result; } +static gfx::NativeTheme::State WebButtonStateToGfx( + int part, + int state, + gfx::NativeTheme::ButtonExtraParams* extra) { + gfx::NativeTheme::State gfx_state = gfx::NativeTheme::kNormal; + + if (part == BP_PUSHBUTTON) { + switch(state) { + case PBS_NORMAL: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case PBS_HOT: + gfx_state = gfx::NativeTheme::kHovered; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case PBS_PRESSED: + gfx_state = gfx::NativeTheme::kPressed; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case PBS_DISABLED: + gfx_state = gfx::NativeTheme::kDisabled; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case PBS_DEFAULTED: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = true; + break; + case PBS_DEFAULTED_ANIMATING: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = true; + break; + default: + NOTREACHED() << "Invalid state: " << state; + } + } else if (part == BP_RADIOBUTTON) { + switch(state) { + case RBS_UNCHECKEDNORMAL: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case RBS_UNCHECKEDHOT: + gfx_state = gfx::NativeTheme::kHovered; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case RBS_UNCHECKEDPRESSED: + gfx_state = gfx::NativeTheme::kPressed; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case RBS_UNCHECKEDDISABLED: + gfx_state = gfx::NativeTheme::kDisabled; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case RBS_CHECKEDNORMAL: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = true; + extra->indeterminate = false; + extra->is_default = false; + break; + case RBS_CHECKEDHOT: + gfx_state = gfx::NativeTheme::kHovered; + extra->checked = true; + extra->indeterminate = false; + extra->is_default = false; + break; + case RBS_CHECKEDPRESSED: + gfx_state = gfx::NativeTheme::kPressed; + extra->checked = true; + extra->indeterminate = false; + extra->is_default = false; + break; + case RBS_CHECKEDDISABLED: + gfx_state = gfx::NativeTheme::kDisabled; + extra->checked = true; + extra->indeterminate = false; + extra->is_default = false; + break; + default: + NOTREACHED() << "Invalid state: " << state; + break; + } + } else if (part == BP_CHECKBOX) { + switch(state) { + case CBS_UNCHECKEDNORMAL: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CBS_UNCHECKEDHOT: + gfx_state = gfx::NativeTheme::kHovered; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CBS_UNCHECKEDPRESSED: + gfx_state = gfx::NativeTheme::kPressed; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CBS_UNCHECKEDDISABLED: + gfx_state = gfx::NativeTheme::kDisabled; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CBS_CHECKEDNORMAL: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = true; + extra->indeterminate = false; + extra->is_default = false; + break; + case CBS_CHECKEDHOT: + gfx_state = gfx::NativeTheme::kHovered; + extra->checked = true; + extra->indeterminate = false; + extra->is_default = false; + break; + case CBS_CHECKEDPRESSED: + gfx_state = gfx::NativeTheme::kPressed; + extra->checked = true; + extra->indeterminate = false; + extra->is_default = false; + break; + case CBS_CHECKEDDISABLED: + gfx_state = gfx::NativeTheme::kDisabled; + extra->checked = true; + extra->indeterminate = false; + extra->is_default = false; + break; + case CBS_MIXEDNORMAL: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = false; + extra->indeterminate = true; + extra->is_default = false; + break; + case CBS_MIXEDHOT: + gfx_state = gfx::NativeTheme::kHovered; + extra->checked = false; + extra->indeterminate = true; + extra->is_default = false; + break; + case CBS_MIXEDPRESSED: + gfx_state = gfx::NativeTheme::kPressed; + extra->checked = false; + extra->indeterminate = true; + extra->is_default = false; + break; + case CBS_MIXEDDISABLED: + gfx_state = gfx::NativeTheme::kDisabled; + extra->checked = false; + extra->indeterminate = true; + extra->is_default = false; + break; + case CBS_IMPLICITNORMAL: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CBS_IMPLICITHOT: + gfx_state = gfx::NativeTheme::kHovered; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CBS_IMPLICITPRESSED: + gfx_state = gfx::NativeTheme::kPressed; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CBS_IMPLICITDISABLED: + gfx_state = gfx::NativeTheme::kDisabled; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CBS_EXCLUDEDNORMAL: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CBS_EXCLUDEDHOT: + gfx_state = gfx::NativeTheme::kHovered; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CBS_EXCLUDEDPRESSED: + gfx_state = gfx::NativeTheme::kPressed; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CBS_EXCLUDEDDISABLED: + gfx_state = gfx::NativeTheme::kDisabled; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + default: + NOTREACHED() << "Invalid state: " << state; + break; + } + } else if (part == BP_GROUPBOX) { + switch(state) { + case GBS_NORMAL: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case GBS_DISABLED: + gfx_state = gfx::NativeTheme::kDisabled; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + default: + NOTREACHED() << "Invalid state: " << state; + break; + } + } else if (part == BP_COMMANDLINK) { + switch(state) { + case CMDLS_NORMAL: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CMDLS_HOT: + gfx_state = gfx::NativeTheme::kHovered; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CMDLS_PRESSED: + gfx_state = gfx::NativeTheme::kPressed; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CMDLS_DISABLED: + gfx_state = gfx::NativeTheme::kDisabled; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CMDLS_DEFAULTED: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = true; + break; + case CMDLS_DEFAULTED_ANIMATING: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = true; + break; + default: + NOTREACHED() << "Invalid state: " << state; + break; + } + } else if (part == BP_COMMANDLINKGLYPH) { + switch(state) { + case CMDLGS_NORMAL: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CMDLGS_HOT: + gfx_state = gfx::NativeTheme::kHovered; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CMDLGS_PRESSED: + gfx_state = gfx::NativeTheme::kPressed; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CMDLGS_DISABLED: + gfx_state = gfx::NativeTheme::kDisabled; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = false; + break; + case CMDLGS_DEFAULTED: + gfx_state = gfx::NativeTheme::kNormal; + extra->checked = false; + extra->indeterminate = false; + extra->is_default = true; + break; + default: + NOTREACHED() << "Invalid state: " << state; + break; + } + } + return gfx_state; +} + void WebThemeEngineImpl::paintButton( WebCanvas* canvas, int part, int state, int classic_state, const WebRect& rect) { - HDC hdc = skia::BeginPlatformPaint(canvas); - - RECT native_rect = WebRectToRECT(rect); - gfx::NativeThemeWin::instance()->PaintButton( - hdc, part, state, classic_state, &native_rect); - - skia::EndPlatformPaint(canvas); + gfx::NativeTheme::Part native_part = gfx::NativeTheme::kPushButton; + switch(part) { + case BP_PUSHBUTTON: + native_part = gfx::NativeTheme::kPushButton; + break; + case BP_CHECKBOX: + native_part = gfx::NativeTheme::kCheckbox; + break; + case BP_RADIOBUTTON: + native_part = gfx::NativeTheme::kRadio; + break; + default: + break; + } + gfx::NativeTheme::ExtraParams extra; + gfx::NativeTheme::State native_state = WebButtonStateToGfx(part, state, + &extra.button); + extra.button.classic_state = classic_state; + gfx::Rect gfx_rect(rect.x, rect.y, rect.width, rect.height); + gfx::NativeTheme::instance()->Paint(canvas, native_part, + native_state, gfx_rect, extra); } void WebThemeEngineImpl::paintMenuList( |