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

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

Issue 1406403007: Eliminate HICON leaks caused by creating icons from bitmap image. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use ScopedGeneric to define ScopedGDIObject. Created 5 years, 1 month 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
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 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 NULL); 873 NULL);
874 } 874 }
875 // There is no way to tell the uxtheme API to draw a left pointing arrow; it 875 // There is no way to tell the uxtheme API to draw a left pointing arrow; it
876 // doesn't have a flag equivalent to DFCS_MENUARROWRIGHT. But they are 876 // doesn't have a flag equivalent to DFCS_MENUARROWRIGHT. But they are
877 // needed for RTL locales on Vista. So use a memory DC and mirror the 877 // needed for RTL locales on Vista. So use a memory DC and mirror the
878 // region with GDI's StretchBlt. 878 // region with GDI's StretchBlt.
879 gfx::Rect r(rect); 879 gfx::Rect r(rect);
880 base::win::ScopedCreateDC mem_dc(CreateCompatibleDC(hdc)); 880 base::win::ScopedCreateDC mem_dc(CreateCompatibleDC(hdc));
881 base::win::ScopedBitmap mem_bitmap(CreateCompatibleBitmap(hdc, r.width(), 881 base::win::ScopedBitmap mem_bitmap(CreateCompatibleBitmap(hdc, r.width(),
882 r.height())); 882 r.height()));
883 base::win::ScopedSelectObject select_bitmap(mem_dc.Get(), mem_bitmap); 883 base::win::ScopedSelectObject select_bitmap(mem_dc.Get(), mem_bitmap.get());
884 // Copy and horizontally mirror the background from hdc into mem_dc. Use 884 // Copy and horizontally mirror the background from hdc into mem_dc. Use
885 // a negative-width source rect, starting at the rightmost pixel. 885 // a negative-width source rect, starting at the rightmost pixel.
886 StretchBlt(mem_dc.Get(), 0, 0, r.width(), r.height(), 886 StretchBlt(mem_dc.Get(), 0, 0, r.width(), r.height(),
887 hdc, r.right()-1, r.y(), -r.width(), r.height(), SRCCOPY); 887 hdc, r.right()-1, r.y(), -r.width(), r.height(), SRCCOPY);
888 // Draw the arrow. 888 // Draw the arrow.
889 RECT theme_rect = {0, 0, r.width(), r.height()}; 889 RECT theme_rect = {0, 0, r.width(), r.height()};
890 HRESULT result = draw_theme_(handle, mem_dc.Get(), MENU_POPUPSUBMENU, 890 HRESULT result = draw_theme_(handle, mem_dc.Get(), MENU_POPUPSUBMENU,
891 state_id, &theme_rect, NULL); 891 state_id, &theme_rect, NULL);
892 // Copy and mirror the result back into mem_dc. 892 // Copy and mirror the result back into mem_dc.
893 StretchBlt(hdc, r.x(), r.y(), r.width(), r.height(), 893 StretchBlt(hdc, r.x(), r.y(), r.width(), r.height(),
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 // CreateSolidBrush() accepts a RGB value but alpha must be 0. 1600 // CreateSolidBrush() accepts a RGB value but alpha must be 0.
1601 base::win::ScopedGDIObject<HBRUSH> bg_brush(CreateSolidBrush(color)); 1601 base::win::ScopedGDIObject<HBRUSH> bg_brush(CreateSolidBrush(color));
1602 // DrawThemeBackgroundEx was introduced in XP SP2, so that it's possible 1602 // DrawThemeBackgroundEx was introduced in XP SP2, so that it's possible
1603 // draw_theme_ex_ is NULL and draw_theme_ is non-null. 1603 // draw_theme_ex_ is NULL and draw_theme_ is non-null.
1604 if (!handle || (!draw_theme_ex_ && (!draw_theme_ || !draw_edges))) { 1604 if (!handle || (!draw_theme_ex_ && (!draw_theme_ || !draw_edges))) {
1605 // Draw it manually. 1605 // Draw it manually.
1606 if (draw_edges) 1606 if (draw_edges)
1607 DrawEdge(hdc, rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST); 1607 DrawEdge(hdc, rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
1608 1608
1609 if (fill_content_area) { 1609 if (fill_content_area) {
1610 FillRect(hdc, rect, (classic_state & DFCS_INACTIVE) ? 1610 FillRect(hdc, rect, (classic_state & DFCS_INACTIVE)
1611 reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1) : bg_brush); 1611 ? reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1)
1612 : bg_brush.get());
1612 } 1613 }
1613 return S_OK; 1614 return S_OK;
1614 } 1615 }
1615 1616
1616 static const DTBGOPTS omit_border_options = { 1617 static const DTBGOPTS omit_border_options = {
1617 sizeof(DTBGOPTS), 1618 sizeof(DTBGOPTS),
1618 DTBG_OMITBORDER, 1619 DTBG_OMITBORDER,
1619 { 0, 0, 0, 0 } 1620 { 0, 0, 0, 0 }
1620 }; 1621 };
1621 HRESULT hr = draw_theme_ex_ ? 1622 HRESULT hr = draw_theme_ex_ ?
1622 draw_theme_ex_(handle, hdc, part_id, state_id, rect, 1623 draw_theme_ex_(handle, hdc, part_id, state_id, rect,
1623 draw_edges ? NULL : &omit_border_options) : 1624 draw_edges ? NULL : &omit_border_options) :
1624 draw_theme_(handle, hdc, part_id, state_id, rect, NULL); 1625 draw_theme_(handle, hdc, part_id, state_id, rect, NULL);
1625 1626
1626 // TODO(maruel): Need to be fixed if get_theme_content_rect_ is NULL. 1627 // TODO(maruel): Need to be fixed if get_theme_content_rect_ is NULL.
1627 if (fill_content_area && get_theme_content_rect_) { 1628 if (fill_content_area && get_theme_content_rect_) {
1628 RECT content_rect; 1629 RECT content_rect;
1629 hr = get_theme_content_rect_(handle, hdc, part_id, state_id, rect, 1630 hr = get_theme_content_rect_(handle, hdc, part_id, state_id, rect,
1630 &content_rect); 1631 &content_rect);
1631 FillRect(hdc, &content_rect, bg_brush); 1632 FillRect(hdc, &content_rect, bg_brush.get());
1632 } 1633 }
1633 return hr; 1634 return hr;
1634 } 1635 }
1635 1636
1636 HRESULT NativeThemeWin::PaintScaledTheme(HANDLE theme, 1637 HRESULT NativeThemeWin::PaintScaledTheme(HANDLE theme,
1637 HDC hdc, 1638 HDC hdc,
1638 int part_id, 1639 int part_id,
1639 int state_id, 1640 int state_id,
1640 const gfx::Rect& rect) const { 1641 const gfx::Rect& rect) const {
1641 // Correct the scaling and positioning of sub-components such as scrollbar 1642 // Correct the scaling and positioning of sub-components such as scrollbar
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1975 const int width = rect.width(); 1976 const int width = rect.width();
1976 const int height = rect.height(); 1977 const int height = rect.height();
1977 1978
1978 // DrawFrameControl for menu arrow/check wants a monochrome bitmap. 1979 // DrawFrameControl for menu arrow/check wants a monochrome bitmap.
1979 base::win::ScopedBitmap mask_bitmap(CreateBitmap(width, height, 1, 1, NULL)); 1980 base::win::ScopedBitmap mask_bitmap(CreateBitmap(width, height, 1, 1, NULL));
1980 1981
1981 if (mask_bitmap == NULL) 1982 if (mask_bitmap == NULL)
1982 return E_OUTOFMEMORY; 1983 return E_OUTOFMEMORY;
1983 1984
1984 base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(NULL)); 1985 base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(NULL));
1985 base::win::ScopedSelectObject select_bitmap(bitmap_dc.Get(), mask_bitmap); 1986 base::win::ScopedSelectObject select_bitmap(bitmap_dc.Get(),
1987 mask_bitmap.get());
1986 RECT local_rect = { 0, 0, width, height }; 1988 RECT local_rect = { 0, 0, width, height };
1987 DrawFrameControl(bitmap_dc.Get(), &local_rect, type, state); 1989 DrawFrameControl(bitmap_dc.Get(), &local_rect, type, state);
1988 1990
1989 // We're going to use BitBlt with a b&w mask. This results in using the dest 1991 // We're going to use BitBlt with a b&w mask. This results in using the dest
1990 // dc's text color for the black bits in the mask, and the dest dc's 1992 // dc's text color for the black bits in the mask, and the dest dc's
1991 // background color for the white bits in the mask. DrawFrameControl draws the 1993 // background color for the white bits in the mask. DrawFrameControl draws the
1992 // check in black, and the background in white. 1994 // check in black, and the background in white.
1993 int bg_color_key = COLOR_MENU; 1995 int bg_color_key = COLOR_MENU;
1994 int text_color_key = COLOR_MENUTEXT; 1996 int text_color_key = COLOR_MENUTEXT;
1995 switch (control_state) { 1997 switch (control_state) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 break; 2068 break;
2067 case LAST: 2069 case LAST:
2068 NOTREACHED(); 2070 NOTREACHED();
2069 break; 2071 break;
2070 } 2072 }
2071 theme_handles_[theme_name] = handle; 2073 theme_handles_[theme_name] = handle;
2072 return handle; 2074 return handle;
2073 } 2075 }
2074 2076
2075 } // namespace ui 2077 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698