Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: ui/native_theme/native_theme_win.cc

Issue 606453002: Remove implicit HANDLE conversions from ui. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/platform_font_win.cc ('k') | ui/snapshot/snapshot_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/native_theme/native_theme_win.h" 5 #include "ui/native_theme/native_theme_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <uxtheme.h> 8 #include <uxtheme.h>
9 #include <vsstyle.h> 9 #include <vsstyle.h>
10 #include <vssym32.h> 10 #include <vssym32.h>
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 NULL); 867 NULL);
868 } 868 }
869 // There is no way to tell the uxtheme API to draw a left pointing arrow; it 869 // There is no way to tell the uxtheme API to draw a left pointing arrow; it
870 // doesn't have a flag equivalent to DFCS_MENUARROWRIGHT. But they are 870 // doesn't have a flag equivalent to DFCS_MENUARROWRIGHT. But they are
871 // needed for RTL locales on Vista. So use a memory DC and mirror the 871 // needed for RTL locales on Vista. So use a memory DC and mirror the
872 // region with GDI's StretchBlt. 872 // region with GDI's StretchBlt.
873 gfx::Rect r(rect); 873 gfx::Rect r(rect);
874 base::win::ScopedCreateDC mem_dc(CreateCompatibleDC(hdc)); 874 base::win::ScopedCreateDC mem_dc(CreateCompatibleDC(hdc));
875 base::win::ScopedBitmap mem_bitmap(CreateCompatibleBitmap(hdc, r.width(), 875 base::win::ScopedBitmap mem_bitmap(CreateCompatibleBitmap(hdc, r.width(),
876 r.height())); 876 r.height()));
877 base::win::ScopedSelectObject select_bitmap(mem_dc, mem_bitmap); 877 base::win::ScopedSelectObject select_bitmap(mem_dc.Get(), mem_bitmap);
878 // Copy and horizontally mirror the background from hdc into mem_dc. Use 878 // Copy and horizontally mirror the background from hdc into mem_dc. Use
879 // a negative-width source rect, starting at the rightmost pixel. 879 // a negative-width source rect, starting at the rightmost pixel.
880 StretchBlt(mem_dc, 0, 0, r.width(), r.height(), 880 StretchBlt(mem_dc.Get(), 0, 0, r.width(), r.height(),
881 hdc, r.right()-1, r.y(), -r.width(), r.height(), SRCCOPY); 881 hdc, r.right()-1, r.y(), -r.width(), r.height(), SRCCOPY);
882 // Draw the arrow. 882 // Draw the arrow.
883 RECT theme_rect = {0, 0, r.width(), r.height()}; 883 RECT theme_rect = {0, 0, r.width(), r.height()};
884 HRESULT result = draw_theme_(handle, mem_dc, MENU_POPUPSUBMENU, 884 HRESULT result = draw_theme_(handle, mem_dc.Get(), MENU_POPUPSUBMENU,
885 state_id, &theme_rect, NULL); 885 state_id, &theme_rect, NULL);
886 // Copy and mirror the result back into mem_dc. 886 // Copy and mirror the result back into mem_dc.
887 StretchBlt(hdc, r.x(), r.y(), r.width(), r.height(), 887 StretchBlt(hdc, r.x(), r.y(), r.width(), r.height(),
888 mem_dc, r.width()-1, 0, -r.width(), r.height(), SRCCOPY); 888 mem_dc.Get(), r.width()-1, 0, -r.width(), r.height(), SRCCOPY);
889 return result; 889 return result;
890 } 890 }
891 891
892 // For some reason, Windows uses the name DFCS_MENUARROWRIGHT to indicate a 892 // For some reason, Windows uses the name DFCS_MENUARROWRIGHT to indicate a
893 // left pointing arrow. This makes the following statement counterintuitive. 893 // left pointing arrow. This makes the following statement counterintuitive.
894 UINT pfc_state = extra.pointing_right ? DFCS_MENUARROW : DFCS_MENUARROWRIGHT; 894 UINT pfc_state = extra.pointing_right ? DFCS_MENUARROW : DFCS_MENUARROWRIGHT;
895 return PaintFrameControl(hdc, rect, DFC_MENU, pfc_state, extra.is_selected, 895 return PaintFrameControl(hdc, rect, DFC_MENU, pfc_state, extra.is_selected,
896 state); 896 state);
897 } 897 }
898 898
(...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after
1969 const int width = rect.width(); 1969 const int width = rect.width();
1970 const int height = rect.height(); 1970 const int height = rect.height();
1971 1971
1972 // DrawFrameControl for menu arrow/check wants a monochrome bitmap. 1972 // DrawFrameControl for menu arrow/check wants a monochrome bitmap.
1973 base::win::ScopedBitmap mask_bitmap(CreateBitmap(width, height, 1, 1, NULL)); 1973 base::win::ScopedBitmap mask_bitmap(CreateBitmap(width, height, 1, 1, NULL));
1974 1974
1975 if (mask_bitmap == NULL) 1975 if (mask_bitmap == NULL)
1976 return E_OUTOFMEMORY; 1976 return E_OUTOFMEMORY;
1977 1977
1978 base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(NULL)); 1978 base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(NULL));
1979 base::win::ScopedSelectObject select_bitmap(bitmap_dc, mask_bitmap); 1979 base::win::ScopedSelectObject select_bitmap(bitmap_dc.Get(), mask_bitmap);
1980 RECT local_rect = { 0, 0, width, height }; 1980 RECT local_rect = { 0, 0, width, height };
1981 DrawFrameControl(bitmap_dc, &local_rect, type, state); 1981 DrawFrameControl(bitmap_dc.Get(), &local_rect, type, state);
1982 1982
1983 // We're going to use BitBlt with a b&w mask. This results in using the dest 1983 // We're going to use BitBlt with a b&w mask. This results in using the dest
1984 // dc's text color for the black bits in the mask, and the dest dc's 1984 // dc's text color for the black bits in the mask, and the dest dc's
1985 // background color for the white bits in the mask. DrawFrameControl draws the 1985 // background color for the white bits in the mask. DrawFrameControl draws the
1986 // check in black, and the background in white. 1986 // check in black, and the background in white.
1987 int bg_color_key = COLOR_MENU; 1987 int bg_color_key = COLOR_MENU;
1988 int text_color_key = COLOR_MENUTEXT; 1988 int text_color_key = COLOR_MENUTEXT;
1989 switch (control_state) { 1989 switch (control_state) {
1990 case kDisabled: 1990 case kDisabled:
1991 bg_color_key = is_selected ? COLOR_HIGHLIGHT : COLOR_MENU; 1991 bg_color_key = is_selected ? COLOR_HIGHLIGHT : COLOR_MENU;
1992 text_color_key = COLOR_GRAYTEXT; 1992 text_color_key = COLOR_GRAYTEXT;
1993 break; 1993 break;
1994 case kHovered: 1994 case kHovered:
1995 bg_color_key = COLOR_HIGHLIGHT; 1995 bg_color_key = COLOR_HIGHLIGHT;
1996 text_color_key = COLOR_HIGHLIGHTTEXT; 1996 text_color_key = COLOR_HIGHLIGHTTEXT;
1997 break; 1997 break;
1998 case kNormal: 1998 case kNormal:
1999 break; 1999 break;
2000 case kPressed: 2000 case kPressed:
2001 case kNumStates: 2001 case kNumStates:
2002 NOTREACHED(); 2002 NOTREACHED();
2003 break; 2003 break;
2004 } 2004 }
2005 COLORREF old_bg_color = SetBkColor(hdc, GetSysColor(bg_color_key)); 2005 COLORREF old_bg_color = SetBkColor(hdc, GetSysColor(bg_color_key));
2006 COLORREF old_text_color = SetTextColor(hdc, GetSysColor(text_color_key)); 2006 COLORREF old_text_color = SetTextColor(hdc, GetSysColor(text_color_key));
2007 BitBlt(hdc, rect.x(), rect.y(), width, height, bitmap_dc, 0, 0, SRCCOPY); 2007 BitBlt(hdc, rect.x(), rect.y(), width, height, bitmap_dc.Get(), 0, 0,
2008 SRCCOPY);
2008 SetBkColor(hdc, old_bg_color); 2009 SetBkColor(hdc, old_bg_color);
2009 SetTextColor(hdc, old_text_color); 2010 SetTextColor(hdc, old_text_color);
2010 2011
2011 return S_OK; 2012 return S_OK;
2012 } 2013 }
2013 2014
2014 HANDLE NativeThemeWin::GetThemeHandle(ThemeName theme_name) const { 2015 HANDLE NativeThemeWin::GetThemeHandle(ThemeName theme_name) const {
2015 if (!open_theme_ || theme_name < 0 || theme_name >= LAST) 2016 if (!open_theme_ || theme_name < 0 || theme_name >= LAST)
2016 return 0; 2017 return 0;
2017 2018
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2059 break; 2060 break;
2060 case LAST: 2061 case LAST:
2061 NOTREACHED(); 2062 NOTREACHED();
2062 break; 2063 break;
2063 } 2064 }
2064 theme_handles_[theme_name] = handle; 2065 theme_handles_[theme_name] = handle;
2065 return handle; 2066 return handle;
2066 } 2067 }
2067 2068
2068 } // namespace ui 2069 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/platform_font_win.cc ('k') | ui/snapshot/snapshot_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698