Commit aafec8e7 authored by James Forshaw's avatar James Forshaw Committed by Commit Bot

[Win] Statically link in uxtheme for Windows Native Theme.

This CL removes the dynamic linking of Vista-era APIs in preference to
static linking. To prevent the uxtheme DLL being loaded unnecessarily the
DLL is added marked as delay loaded.

Bug: 986625
Change-Id: I29987f493b7fdf92633b3ba4dde61573b5543bc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1720905Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: James Forshaw <forshaw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683176}
parent 66e44af1
...@@ -466,6 +466,7 @@ if (is_win) { ...@@ -466,6 +466,7 @@ if (is_win) {
"/DELAYLOAD:user32.dll", "/DELAYLOAD:user32.dll",
"/DELAYLOAD:userenv.dll", "/DELAYLOAD:userenv.dll",
"/DELAYLOAD:usp10.dll", "/DELAYLOAD:usp10.dll",
"/DELAYLOAD:uxtheme.dll",
"/DELAYLOAD:wer.dll", "/DELAYLOAD:wer.dll",
"/DELAYLOAD:wevtapi.dll", "/DELAYLOAD:wevtapi.dll",
"/DELAYLOAD:winhttp.dll", "/DELAYLOAD:winhttp.dll",
......
...@@ -83,6 +83,8 @@ if (is_win) { ...@@ -83,6 +83,8 @@ if (is_win) {
"//ui/display", "//ui/display",
"//ui/gfx", "//ui/gfx",
] ]
libs = [ "uxtheme.lib" ]
} }
} else { } else {
jumbo_source_set("native_theme_browser") { jumbo_source_set("native_theme_browser") {
......
...@@ -189,10 +189,11 @@ gfx::Size NativeThemeWin::GetPartSize(Part part, ...@@ -189,10 +189,11 @@ gfx::Size NativeThemeWin::GetPartSize(Part part,
int part_id = GetWindowsPart(part, state, extra); int part_id = GetWindowsPart(part, state, extra);
int state_id = GetWindowsState(part, state, extra); int state_id = GetWindowsState(part, state, extra);
base::win::ScopedGetDC screen_dc(NULL); base::win::ScopedGetDC screen_dc(nullptr);
SIZE size; SIZE size;
if (SUCCEEDED(GetThemePartSize(GetThemeName(part), screen_dc, part_id, HANDLE handle = GetThemeHandle(GetThemeName(part));
state_id, NULL, TS_TRUE, &size))) if (handle && SUCCEEDED(GetThemePartSize(handle, screen_dc, part_id, state_id,
nullptr, TS_TRUE, &size)))
return gfx::Size(size.cx, size.cy); return gfx::Size(size.cx, size.cy);
// TODO(rogerta): For now, we need to support radio buttons and checkboxes // TODO(rogerta): For now, we need to support radio buttons and checkboxes
...@@ -231,30 +232,7 @@ void NativeThemeWin::Paint(cc::PaintCanvas* canvas, ...@@ -231,30 +232,7 @@ void NativeThemeWin::Paint(cc::PaintCanvas* canvas,
} }
} }
NativeThemeWin::NativeThemeWin() NativeThemeWin::NativeThemeWin() : color_change_listener_(this) {
: draw_theme_(NULL),
draw_theme_ex_(NULL),
get_theme_content_rect_(NULL),
get_theme_part_size_(NULL),
open_theme_(NULL),
close_theme_(NULL),
theme_dll_(LoadLibrary(L"uxtheme.dll")),
color_change_listener_(this) {
if (theme_dll_) {
draw_theme_ = reinterpret_cast<DrawThemeBackgroundPtr>(
GetProcAddress(theme_dll_, "DrawThemeBackground"));
draw_theme_ex_ = reinterpret_cast<DrawThemeBackgroundExPtr>(
GetProcAddress(theme_dll_, "DrawThemeBackgroundEx"));
get_theme_content_rect_ = reinterpret_cast<GetThemeContentRectPtr>(
GetProcAddress(theme_dll_, "GetThemeBackgroundContentRect"));
get_theme_part_size_ = reinterpret_cast<GetThemePartSizePtr>(
GetProcAddress(theme_dll_, "GetThemePartSize"));
open_theme_ = reinterpret_cast<OpenThemeDataPtr>(
GetProcAddress(theme_dll_, "OpenThemeData"));
close_theme_ = reinterpret_cast<CloseThemeDataPtr>(
GetProcAddress(theme_dll_, "CloseThemeData"));
}
// If there's no sequenced task runner handle, we can't be called back for // If there's no sequenced task runner handle, we can't be called back for
// dark mode changes. This generally happens in tests. As a result, ignore // dark mode changes. This generally happens in tests. As a result, ignore
// dark mode in this case. // dark mode in this case.
...@@ -293,12 +271,9 @@ NativeThemeWin::NativeThemeWin() ...@@ -293,12 +271,9 @@ NativeThemeWin::NativeThemeWin()
} }
NativeThemeWin::~NativeThemeWin() { NativeThemeWin::~NativeThemeWin() {
if (theme_dll_) {
// TODO(https://crbug.com/787692): Calling CloseHandles() here breaks // TODO(https://crbug.com/787692): Calling CloseHandles() here breaks
// certain tests and the reliability bots. // certain tests and the reliability bots.
// CloseHandles(); // CloseHandles();
FreeLibrary(theme_dll_);
}
} }
bool NativeThemeWin::IsUsingHighContrastThemeInternal() const { bool NativeThemeWin::IsUsingHighContrastThemeInternal() const {
...@@ -309,12 +284,9 @@ bool NativeThemeWin::IsUsingHighContrastThemeInternal() const { ...@@ -309,12 +284,9 @@ bool NativeThemeWin::IsUsingHighContrastThemeInternal() const {
} }
void NativeThemeWin::CloseHandlesInternal() { void NativeThemeWin::CloseHandlesInternal() {
if (!close_theme_)
return;
for (int i = 0; i < LAST; ++i) { for (int i = 0; i < LAST; ++i) {
if (theme_handles_[i]) { if (theme_handles_[i]) {
close_theme_(theme_handles_[i]); CloseThemeData(theme_handles_[i]);
theme_handles_[i] = nullptr; theme_handles_[i] = nullptr;
} }
} }
...@@ -726,19 +698,6 @@ void NativeThemeWin::PaintIndirect(cc::PaintCanvas* destination_canvas, ...@@ -726,19 +698,6 @@ void NativeThemeWin::PaintIndirect(cc::PaintCanvas* destination_canvas,
rect.y()); rect.y());
} }
HRESULT NativeThemeWin::GetThemePartSize(ThemeName theme_name,
HDC hdc,
int part_id,
int state_id,
RECT* rect,
int ts,
SIZE* size) const {
HANDLE handle = GetThemeHandle(theme_name);
return (handle && get_theme_part_size_) ?
get_theme_part_size_(handle, hdc, part_id, state_id, rect, ts, size) :
E_NOTIMPL;
}
HRESULT NativeThemeWin::PaintButton(HDC hdc, HRESULT NativeThemeWin::PaintButton(HDC hdc,
State state, State state,
const ButtonExtraParams& extra, const ButtonExtraParams& extra,
...@@ -746,8 +705,8 @@ HRESULT NativeThemeWin::PaintButton(HDC hdc, ...@@ -746,8 +705,8 @@ HRESULT NativeThemeWin::PaintButton(HDC hdc,
int state_id, int state_id,
RECT* rect) const { RECT* rect) const {
HANDLE handle = GetThemeHandle(BUTTON); HANDLE handle = GetThemeHandle(BUTTON);
if (handle && draw_theme_) if (handle)
return draw_theme_(handle, hdc, part_id, state_id, rect, NULL); return DrawThemeBackground(handle, hdc, part_id, state_id, rect, nullptr);
// Adjust classic_state based on part, state, and extras. // Adjust classic_state based on part, state, and extras.
int classic_state = extra.classic_state; int classic_state = extra.classic_state;
...@@ -804,8 +763,8 @@ HRESULT NativeThemeWin::PaintButton(HDC hdc, ...@@ -804,8 +763,8 @@ HRESULT NativeThemeWin::PaintButton(HDC hdc,
if ((BP_PUSHBUTTON == part_id) && focused) { if ((BP_PUSHBUTTON == part_id) && focused) {
// The focus rect is inside the button. The exact number of pixels depends // The focus rect is inside the button. The exact number of pixels depends
// on whether we're in classic mode or using uxtheme. // on whether we're in classic mode or using uxtheme.
if (handle && get_theme_content_rect_) { if (handle) {
get_theme_content_rect_(handle, hdc, part_id, state_id, rect, rect); GetThemeBackgroundContentRect(handle, hdc, part_id, state_id, rect, rect);
} else { } else {
InflateRect(rect, -GetSystemMetrics(SM_CXEDGE), InflateRect(rect, -GetSystemMetrics(SM_CXEDGE),
-GetSystemMetrics(SM_CYEDGE)); -GetSystemMetrics(SM_CYEDGE));
...@@ -838,10 +797,10 @@ HRESULT NativeThemeWin::PaintMenuArrow( ...@@ -838,10 +797,10 @@ HRESULT NativeThemeWin::PaintMenuArrow(
HANDLE handle = GetThemeHandle(MENU); HANDLE handle = GetThemeHandle(MENU);
RECT rect_win = rect.ToRECT(); RECT rect_win = rect.ToRECT();
if (handle && draw_theme_) { if (handle) {
if (extra.pointing_right) { if (extra.pointing_right) {
return draw_theme_(handle, hdc, MENU_POPUPSUBMENU, state_id, &rect_win, return DrawThemeBackground(handle, hdc, MENU_POPUPSUBMENU, state_id,
NULL); &rect_win, nullptr);
} }
// There is no way to tell the uxtheme API to draw a left pointing arrow; it // 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 // doesn't have a flag equivalent to DFCS_MENUARROWRIGHT. But they are
...@@ -858,8 +817,9 @@ HRESULT NativeThemeWin::PaintMenuArrow( ...@@ -858,8 +817,9 @@ HRESULT NativeThemeWin::PaintMenuArrow(
hdc, r.right()-1, r.y(), -r.width(), r.height(), SRCCOPY); hdc, r.right()-1, r.y(), -r.width(), r.height(), SRCCOPY);
// Draw the arrow. // Draw the arrow.
RECT theme_rect = {0, 0, r.width(), r.height()}; RECT theme_rect = {0, 0, r.width(), r.height()};
HRESULT result = draw_theme_(handle, mem_dc.Get(), MENU_POPUPSUBMENU, HRESULT result =
state_id, &theme_rect, NULL); DrawThemeBackground(handle, mem_dc.Get(), MENU_POPUPSUBMENU, state_id,
&theme_rect, nullptr);
// Copy and mirror the result back into mem_dc. // Copy and mirror the result back into mem_dc.
StretchBlt(hdc, r.x(), r.y(), r.width(), r.height(), StretchBlt(hdc, r.x(), r.y(), r.width(), r.height(),
mem_dc.Get(), r.width()-1, 0, -r.width(), r.height(), SRCCOPY); mem_dc.Get(), r.width()-1, 0, -r.width(), r.height(), SRCCOPY);
...@@ -879,12 +839,13 @@ HRESULT NativeThemeWin::PaintMenuCheck( ...@@ -879,12 +839,13 @@ HRESULT NativeThemeWin::PaintMenuCheck(
const gfx::Rect& rect, const gfx::Rect& rect,
const MenuCheckExtraParams& extra) const { const MenuCheckExtraParams& extra) const {
HANDLE handle = GetThemeHandle(MENU); HANDLE handle = GetThemeHandle(MENU);
if (handle && draw_theme_) { if (handle) {
const int state_id = extra.is_radio ? const int state_id = extra.is_radio ?
((state == kDisabled) ? MC_BULLETDISABLED : MC_BULLETNORMAL) : ((state == kDisabled) ? MC_BULLETDISABLED : MC_BULLETNORMAL) :
((state == kDisabled) ? MC_CHECKMARKDISABLED : MC_CHECKMARKNORMAL); ((state == kDisabled) ? MC_CHECKMARKDISABLED : MC_CHECKMARKNORMAL);
RECT rect_win = rect.ToRECT(); RECT rect_win = rect.ToRECT();
return draw_theme_(handle, hdc, MENU_POPUPCHECK, state_id, &rect_win, NULL); return DrawThemeBackground(handle, hdc, MENU_POPUPCHECK, state_id,
&rect_win, nullptr);
} }
return PaintFrameControl(hdc, rect, DFC_MENU, return PaintFrameControl(hdc, rect, DFC_MENU,
...@@ -896,13 +857,13 @@ HRESULT NativeThemeWin::PaintMenuCheckBackground(HDC hdc, ...@@ -896,13 +857,13 @@ HRESULT NativeThemeWin::PaintMenuCheckBackground(HDC hdc,
State state, State state,
const gfx::Rect& rect) const { const gfx::Rect& rect) const {
HANDLE handle = GetThemeHandle(MENU); HANDLE handle = GetThemeHandle(MENU);
if (!handle || !draw_theme_) if (!handle)
return S_OK; // Nothing to do for background. return S_OK; // Nothing to do for background.
int state_id = state == kDisabled ? MCB_DISABLED : MCB_NORMAL; int state_id = state == kDisabled ? MCB_DISABLED : MCB_NORMAL;
RECT rect_win = rect.ToRECT(); RECT rect_win = rect.ToRECT();
return draw_theme_(handle, hdc, MENU_POPUPCHECKBACKGROUND, state_id, return DrawThemeBackground(handle, hdc, MENU_POPUPCHECKBACKGROUND, state_id,
&rect_win, NULL); &rect_win, nullptr);
} }
HRESULT NativeThemeWin::PaintPushButton(HDC hdc, HRESULT NativeThemeWin::PaintPushButton(HDC hdc,
...@@ -1018,9 +979,10 @@ HRESULT NativeThemeWin::PaintMenuList(HDC hdc, ...@@ -1018,9 +979,10 @@ HRESULT NativeThemeWin::PaintMenuList(HDC hdc,
break; break;
} }
if (handle && draw_theme_) if (handle) {
return draw_theme_(handle, hdc, CP_DROPDOWNBUTTON, state_id, &rect_win, return DrawThemeBackground(handle, hdc, CP_DROPDOWNBUTTON, state_id,
NULL); &rect_win, nullptr);
}
// Draw it manually. // Draw it manually.
DrawFrameControl(hdc, &rect_win, DFC_SCROLL, DrawFrameControl(hdc, &rect_win, DFC_SCROLL,
...@@ -1042,7 +1004,7 @@ HRESULT NativeThemeWin::PaintScrollbarArrow( ...@@ -1042,7 +1004,7 @@ HRESULT NativeThemeWin::PaintScrollbarArrow(
}; };
HANDLE handle = GetThemeHandle(SCROLLBAR); HANDLE handle = GetThemeHandle(SCROLLBAR);
RECT rect_win = rect.ToRECT(); RECT rect_win = rect.ToRECT();
if (handle && draw_theme_) { if (handle) {
int index = part - kScrollbarDownArrow; int index = part - kScrollbarDownArrow;
DCHECK_GE(index, 0); DCHECK_GE(index, 0);
DCHECK_LT(static_cast<size_t>(index), base::size(state_id_matrix)); DCHECK_LT(static_cast<size_t>(index), base::size(state_id_matrix));
...@@ -1155,7 +1117,7 @@ HRESULT NativeThemeWin::PaintScrollbarThumb( ...@@ -1155,7 +1117,7 @@ HRESULT NativeThemeWin::PaintScrollbarThumb(
break; break;
} }
if (handle && draw_theme_) if (handle)
return PaintScaledTheme(handle, hdc, part_id, state_id, rect); return PaintScaledTheme(handle, hdc, part_id, state_id, rect);
// Draw it manually. // Draw it manually.
...@@ -1199,8 +1161,10 @@ HRESULT NativeThemeWin::PaintScrollbarTrack( ...@@ -1199,8 +1161,10 @@ HRESULT NativeThemeWin::PaintScrollbarTrack(
break; break;
} }
if (handle && draw_theme_) if (handle) {
return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); return DrawThemeBackground(handle, hdc, part_id, state_id, &rect_win,
nullptr);
}
// Draw it manually. // Draw it manually.
if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) && if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) &&
...@@ -1245,8 +1209,11 @@ HRESULT NativeThemeWin::PaintSpinButton( ...@@ -1245,8 +1209,11 @@ HRESULT NativeThemeWin::PaintSpinButton(
break; break;
} }
if (handle && draw_theme_) if (handle) {
return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); return DrawThemeBackground(handle, hdc, part_id, state_id, &rect_win,
nullptr);
}
DrawFrameControl(hdc, &rect_win, DFC_SCROLL, extra.classic_state); DrawFrameControl(hdc, &rect_win, DFC_SCROLL, extra.classic_state);
return S_OK; return S_OK;
} }
...@@ -1296,8 +1263,10 @@ HRESULT NativeThemeWin::PaintTrackbar(SkCanvas* canvas, ...@@ -1296,8 +1263,10 @@ HRESULT NativeThemeWin::PaintTrackbar(SkCanvas* canvas,
} // else this isn't actually a channel, so |channel_rect| == |rect|. } // else this isn't actually a channel, so |channel_rect| == |rect|.
HANDLE handle = GetThemeHandle(TRACKBAR); HANDLE handle = GetThemeHandle(TRACKBAR);
if (handle && draw_theme_) if (handle) {
return draw_theme_(handle, hdc, part_id, state_id, &channel_rect, NULL); return DrawThemeBackground(handle, hdc, part_id, state_id, &channel_rect,
nullptr);
}
// Classic mode, draw it manually. // Classic mode, draw it manually.
if ((part_id == TKP_TRACK) || (part_id == TKP_TRACKVERT)) { if ((part_id == TKP_TRACK) || (part_id == TKP_TRACKVERT)) {
...@@ -1375,14 +1344,14 @@ HRESULT NativeThemeWin::PaintProgressBar( ...@@ -1375,14 +1344,14 @@ HRESULT NativeThemeWin::PaintProgressBar(
extra.value_rect_height).ToRECT(); extra.value_rect_height).ToRECT();
HANDLE handle = GetThemeHandle(PROGRESS); HANDLE handle = GetThemeHandle(PROGRESS);
if (!handle || !draw_theme_ || !draw_theme_ex_) { if (!handle) {
FillRect(hdc, &bar_rect, GetSysColorBrush(COLOR_BTNFACE)); FillRect(hdc, &bar_rect, GetSysColorBrush(COLOR_BTNFACE));
FillRect(hdc, &value_rect, GetSysColorBrush(COLOR_BTNSHADOW)); FillRect(hdc, &value_rect, GetSysColorBrush(COLOR_BTNSHADOW));
DrawEdge(hdc, &bar_rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST); DrawEdge(hdc, &bar_rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
return S_OK; return S_OK;
} }
draw_theme_(handle, hdc, PP_BAR, 0, &bar_rect, NULL); DrawThemeBackground(handle, hdc, PP_BAR, 0, &bar_rect, nullptr);
int bar_width = bar_rect.right - bar_rect.left; int bar_width = bar_rect.right - bar_rect.left;
if (!extra.determinate) { if (!extra.determinate) {
...@@ -1396,7 +1365,8 @@ HRESULT NativeThemeWin::PaintProgressBar( ...@@ -1396,7 +1365,8 @@ HRESULT NativeThemeWin::PaintProgressBar(
width_with_margin, overlay_width, kIndeterminateOverlayPixelsPerSecond, width_with_margin, overlay_width, kIndeterminateOverlayPixelsPerSecond,
extra.animated_seconds); extra.animated_seconds);
overlay_rect.right = overlay_rect.left + overlay_width; overlay_rect.right = overlay_rect.left + overlay_width;
draw_theme_(handle, hdc, PP_MOVEOVERLAY, 0, &overlay_rect, &bar_rect); DrawThemeBackground(handle, hdc, PP_MOVEOVERLAY, 0, &overlay_rect,
&bar_rect);
return S_OK; return S_OK;
} }
...@@ -1413,14 +1383,16 @@ HRESULT NativeThemeWin::PaintProgressBar( ...@@ -1413,14 +1383,16 @@ HRESULT NativeThemeWin::PaintProgressBar(
// On Vista or later, the progress bar part has a single-block value part // On Vista or later, the progress bar part has a single-block value part
// and a glossy effect. The value part has exactly same height as the bar // and a glossy effect. The value part has exactly same height as the bar
// part, so we don't need to shrink the rect. // part, so we don't need to shrink the rect.
draw_theme_ex_(handle, hdc, PP_FILL, 0, &value_rect, &value_draw_options); DrawThemeBackgroundEx(handle, hdc, PP_FILL, 0, &value_rect,
&value_draw_options);
RECT overlay_rect = value_rect; RECT overlay_rect = value_rect;
overlay_rect.left += ComputeAnimationProgress( overlay_rect.left += ComputeAnimationProgress(
bar_width, kDeterminateOverlayWidth, kDeterminateOverlayPixelsPerSecond, bar_width, kDeterminateOverlayWidth, kDeterminateOverlayPixelsPerSecond,
extra.animated_seconds); extra.animated_seconds);
overlay_rect.right = overlay_rect.left + kDeterminateOverlayWidth; overlay_rect.right = overlay_rect.left + kDeterminateOverlayWidth;
draw_theme_(handle, hdc, PP_MOVEOVERLAY, 0, &overlay_rect, &value_rect); DrawThemeBackground(handle, hdc, PP_MOVEOVERLAY, 0, &overlay_rect,
&value_rect);
return S_OK; return S_OK;
} }
...@@ -1428,11 +1400,11 @@ HRESULT NativeThemeWin::PaintWindowResizeGripper(HDC hdc, ...@@ -1428,11 +1400,11 @@ HRESULT NativeThemeWin::PaintWindowResizeGripper(HDC hdc,
const gfx::Rect& rect) const { const gfx::Rect& rect) const {
HANDLE handle = GetThemeHandle(STATUS); HANDLE handle = GetThemeHandle(STATUS);
RECT rect_win = rect.ToRECT(); RECT rect_win = rect.ToRECT();
if (handle && draw_theme_) { if (handle) {
// Paint the status bar gripper. There doesn't seem to be a standard // Paint the status bar gripper. There doesn't seem to be a standard
// gripper in Windows for the space between scrollbars. This is pretty // gripper in Windows for the space between scrollbars. This is pretty
// close, but it's supposed to be painted over a status bar. // close, but it's supposed to be painted over a status bar.
return draw_theme_(handle, hdc, SP_GRIPPER, 0, &rect_win, NULL); return DrawThemeBackground(handle, hdc, SP_GRIPPER, 0, &rect_win, nullptr);
} }
// Draw a windows classic scrollbar gripper. // Draw a windows classic scrollbar gripper.
...@@ -1444,8 +1416,8 @@ HRESULT NativeThemeWin::PaintTabPanelBackground(HDC hdc, ...@@ -1444,8 +1416,8 @@ HRESULT NativeThemeWin::PaintTabPanelBackground(HDC hdc,
const gfx::Rect& rect) const { const gfx::Rect& rect) const {
HANDLE handle = GetThemeHandle(TAB); HANDLE handle = GetThemeHandle(TAB);
RECT rect_win = rect.ToRECT(); RECT rect_win = rect.ToRECT();
if (handle && draw_theme_) if (handle)
return draw_theme_(handle, hdc, TABP_BODY, 0, &rect_win, NULL); return DrawThemeBackground(handle, hdc, TABP_BODY, 0, &rect_win, nullptr);
// Classic just renders a flat color background. // Classic just renders a flat color background.
FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_3DFACE + 1)); FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_3DFACE + 1));
...@@ -1503,9 +1475,7 @@ HRESULT NativeThemeWin::PaintTextField(HDC hdc, ...@@ -1503,9 +1475,7 @@ HRESULT NativeThemeWin::PaintTextField(HDC hdc,
// and if not, just use the system color? // and if not, just use the system color?
// CreateSolidBrush() accepts a RGB value but alpha must be 0. // CreateSolidBrush() accepts a RGB value but alpha must be 0.
base::win::ScopedGDIObject<HBRUSH> bg_brush(CreateSolidBrush(color)); base::win::ScopedGDIObject<HBRUSH> bg_brush(CreateSolidBrush(color));
// DrawThemeBackgroundEx was introduced in XP SP2, so that it's possible if (!handle) {
// draw_theme_ex_ is NULL and draw_theme_ is non-null.
if (!handle || (!draw_theme_ex_ && (!draw_theme_ || !draw_edges))) {
// Draw it manually. // Draw it manually.
if (draw_edges) if (draw_edges)
DrawEdge(hdc, rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST); DrawEdge(hdc, rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
...@@ -1523,15 +1493,13 @@ HRESULT NativeThemeWin::PaintTextField(HDC hdc, ...@@ -1523,15 +1493,13 @@ HRESULT NativeThemeWin::PaintTextField(HDC hdc,
DTBG_OMITBORDER, DTBG_OMITBORDER,
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
HRESULT hr = draw_theme_ex_ ? HRESULT hr =
draw_theme_ex_(handle, hdc, part_id, state_id, rect, DrawThemeBackgroundEx(handle, hdc, part_id, state_id, rect,
draw_edges ? NULL : &omit_border_options) : draw_edges ? nullptr : &omit_border_options);
draw_theme_(handle, hdc, part_id, state_id, rect, NULL);
// TODO(maruel): Need to be fixed if get_theme_content_rect_ is NULL. if (fill_content_area) {
if (fill_content_area && get_theme_content_rect_) {
RECT content_rect; RECT content_rect;
hr = get_theme_content_rect_(handle, hdc, part_id, state_id, rect, hr = GetThemeBackgroundContentRect(handle, hdc, part_id, state_id, rect,
&content_rect); &content_rect);
FillRect(hdc, &content_rect, bg_brush.get()); FillRect(hdc, &content_rect, bg_brush.get());
} }
...@@ -1554,14 +1522,14 @@ HRESULT NativeThemeWin::PaintScaledTheme(HANDLE theme, ...@@ -1554,14 +1522,14 @@ HRESULT NativeThemeWin::PaintScaledTheme(HANDLE theme,
gfx::Rect scaled_rect = gfx::ScaleToEnclosedRect(rect, scale); gfx::Rect scaled_rect = gfx::ScaleToEnclosedRect(rect, scale);
scaled_rect.Offset(save_transform.eDx, save_transform.eDy); scaled_rect.Offset(save_transform.eDx, save_transform.eDy);
RECT bounds = scaled_rect.ToRECT(); RECT bounds = scaled_rect.ToRECT();
HRESULT result = draw_theme_(theme, hdc, part_id, state_id, &bounds, HRESULT result =
NULL); DrawThemeBackground(theme, hdc, part_id, state_id, &bounds, nullptr);
SetWorldTransform(hdc, &save_transform); SetWorldTransform(hdc, &save_transform);
return result; return result;
} }
} }
RECT bounds = rect.ToRECT(); RECT bounds = rect.ToRECT();
return draw_theme_(theme, hdc, part_id, state_id, &bounds, NULL); return DrawThemeBackground(theme, hdc, part_id, state_id, &bounds, nullptr);
} }
// static // static
...@@ -1902,50 +1870,50 @@ HRESULT NativeThemeWin::PaintFrameControl(HDC hdc, ...@@ -1902,50 +1870,50 @@ HRESULT NativeThemeWin::PaintFrameControl(HDC hdc,
} }
HANDLE NativeThemeWin::GetThemeHandle(ThemeName theme_name) const { HANDLE NativeThemeWin::GetThemeHandle(ThemeName theme_name) const {
if (!open_theme_ || theme_name < 0 || theme_name >= LAST) if (theme_name < 0 || theme_name >= LAST)
return 0; return nullptr;
if (theme_handles_[theme_name]) if (theme_handles_[theme_name])
return theme_handles_[theme_name]; return theme_handles_[theme_name];
// Not found, try to load it. // Not found, try to load it.
HANDLE handle = 0; HANDLE handle = nullptr;
switch (theme_name) { switch (theme_name) {
case BUTTON: case BUTTON:
handle = open_theme_(NULL, L"Button"); handle = OpenThemeData(nullptr, L"Button");
break; break;
case LIST: case LIST:
handle = open_theme_(NULL, L"Listview"); handle = OpenThemeData(nullptr, L"Listview");
break; break;
case MENU: case MENU:
handle = open_theme_(NULL, L"Menu"); handle = OpenThemeData(nullptr, L"Menu");
break; break;
case MENULIST: case MENULIST:
handle = open_theme_(NULL, L"Combobox"); handle = OpenThemeData(nullptr, L"Combobox");
break; break;
case SCROLLBAR: case SCROLLBAR:
handle = open_theme_(NULL, L"Scrollbar"); handle = OpenThemeData(nullptr, L"Scrollbar");
break; break;
case STATUS: case STATUS:
handle = open_theme_(NULL, L"Status"); handle = OpenThemeData(nullptr, L"Status");
break; break;
case TAB: case TAB:
handle = open_theme_(NULL, L"Tab"); handle = OpenThemeData(nullptr, L"Tab");
break; break;
case TEXTFIELD: case TEXTFIELD:
handle = open_theme_(NULL, L"Edit"); handle = OpenThemeData(nullptr, L"Edit");
break; break;
case TRACKBAR: case TRACKBAR:
handle = open_theme_(NULL, L"Trackbar"); handle = OpenThemeData(nullptr, L"Trackbar");
break; break;
case WINDOW: case WINDOW:
handle = open_theme_(NULL, L"Window"); handle = OpenThemeData(nullptr, L"Window");
break; break;
case PROGRESS: case PROGRESS:
handle = open_theme_(NULL, L"Progress"); handle = OpenThemeData(nullptr, L"Progress");
break; break;
case SPIN: case SPIN:
handle = open_theme_(NULL, L"Spin"); handle = OpenThemeData(nullptr, L"Spin");
break; break;
case LAST: case LAST:
NOTREACHED(); NOTREACHED();
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include <map> #include <map>
#include <windows.h> #include <windows.h>
#include <uxtheme.h>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -135,14 +134,6 @@ class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme, ...@@ -135,14 +134,6 @@ class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme,
const gfx::Rect& rect, const gfx::Rect& rect,
const ExtraParams& extra) const; const ExtraParams& extra) const;
HRESULT GetThemePartSize(ThemeName themeName,
HDC hdc,
int part_id,
int state_id,
RECT* rect,
int ts,
SIZE* size) const;
HRESULT PaintButton(HDC hdc, HRESULT PaintButton(HDC hdc,
State state, State state,
const ButtonExtraParams& extra, const ButtonExtraParams& extra,
...@@ -274,60 +265,6 @@ class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme, ...@@ -274,60 +265,6 @@ class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme,
void RegisterThemeRegkeyObserver(); void RegisterThemeRegkeyObserver();
void UpdateDarkModeStatus(); void UpdateDarkModeStatus();
typedef HRESULT (WINAPI* DrawThemeBackgroundPtr)(HANDLE theme,
HDC hdc,
int part_id,
int state_id,
const RECT* rect,
const RECT* clip_rect);
typedef HRESULT (WINAPI* DrawThemeBackgroundExPtr)(HANDLE theme,
HDC hdc,
int part_id,
int state_id,
const RECT* rect,
const DTBGOPTS* opts);
typedef HRESULT (WINAPI* GetThemeColorPtr)(HANDLE hTheme,
int part_id,
int state_id,
int prop_id,
COLORREF* color);
typedef HRESULT (WINAPI* GetThemeContentRectPtr)(HANDLE hTheme,
HDC hdc,
int part_id,
int state_id,
const RECT* rect,
RECT* content_rect);
typedef HRESULT (WINAPI* GetThemePartSizePtr)(HANDLE hTheme,
HDC hdc,
int part_id,
int state_id,
RECT* rect,
int ts,
SIZE* size);
typedef HANDLE (WINAPI* OpenThemeDataPtr)(HWND window,
LPCWSTR class_list);
typedef HRESULT (WINAPI* CloseThemeDataPtr)(HANDLE theme);
typedef void (WINAPI* SetThemeAppPropertiesPtr) (DWORD flags);
typedef BOOL (WINAPI* IsThemeActivePtr)();
typedef HRESULT (WINAPI* GetThemeIntPtr)(HANDLE hTheme,
int part_id,
int state_id,
int prop_id,
int *value);
// Function pointers into uxtheme.dll.
DrawThemeBackgroundPtr draw_theme_;
DrawThemeBackgroundExPtr draw_theme_ex_;
GetThemeColorPtr get_theme_color_;
GetThemeContentRectPtr get_theme_content_rect_;
GetThemePartSizePtr get_theme_part_size_;
OpenThemeDataPtr open_theme_;
CloseThemeDataPtr close_theme_;
// Handle to uxtheme.dll.
HMODULE theme_dll_;
// Dark Mode registry key. // Dark Mode registry key.
base::win::RegKey hkcu_themes_regkey_; base::win::RegKey hkcu_themes_regkey_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment