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

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

Powered by Google App Engine
This is Rietveld 408576698