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

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

Issue 12114049: Fix painting of scaled themes in Windows in high-DPI mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Check return type. Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « ui/native_theme/native_theme_win.h ('k') | no next file » | 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>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_handle.h" 14 #include "base/memory/scoped_handle.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/win/scoped_gdi_object.h" 16 #include "base/win/scoped_gdi_object.h"
17 #include "base/win/scoped_hdc.h" 17 #include "base/win/scoped_hdc.h"
18 #include "base/win/scoped_select_object.h" 18 #include "base/win/scoped_select_object.h"
19 #include "base/win/windows_version.h" 19 #include "base/win/windows_version.h"
20 #include "skia/ext/bitmap_platform_device.h" 20 #include "skia/ext/bitmap_platform_device.h"
21 #include "skia/ext/platform_canvas.h" 21 #include "skia/ext/platform_canvas.h"
22 #include "skia/ext/skia_utils_win.h" 22 #include "skia/ext/skia_utils_win.h"
23 #include "third_party/skia/include/core/SkCanvas.h" 23 #include "third_party/skia/include/core/SkCanvas.h"
24 #include "third_party/skia/include/core/SkColorPriv.h" 24 #include "third_party/skia/include/core/SkColorPriv.h"
25 #include "third_party/skia/include/core/SkShader.h" 25 #include "third_party/skia/include/core/SkShader.h"
26 #include "ui/base/win/dpi.h"
26 #include "ui/gfx/color_utils.h" 27 #include "ui/gfx/color_utils.h"
27 #include "ui/gfx/gdi_util.h" 28 #include "ui/gfx/gdi_util.h"
28 #include "ui/gfx/rect.h" 29 #include "ui/gfx/rect.h"
30 #include "ui/gfx/rect_conversions.h"
29 #include "ui/native_theme/common_theme.h" 31 #include "ui/native_theme/common_theme.h"
30 32
31 // This was removed from Winvers.h but is still used. 33 // This was removed from Winvers.h but is still used.
32 #if !defined(COLOR_MENUHIGHLIGHT) 34 #if !defined(COLOR_MENUHIGHLIGHT)
33 #define COLOR_MENUHIGHLIGHT 29 35 #define COLOR_MENUHIGHLIGHT 29
34 #endif 36 #endif
35 37
36 namespace { 38 namespace {
37 39
38 // TODO: Obtain the correct colors using GetSysColor. 40 // TODO: Obtain the correct colors using GetSysColor.
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 state_id = ABS_RIGHTHOVER; 1066 state_id = ABS_RIGHTHOVER;
1065 break; 1067 break;
1066 case kScrollbarUpArrow: 1068 case kScrollbarUpArrow:
1067 state_id = ABS_UPHOVER; 1069 state_id = ABS_UPHOVER;
1068 break; 1070 break;
1069 default: 1071 default:
1070 NOTREACHED() << "Invalid part: " << part; 1072 NOTREACHED() << "Invalid part: " << part;
1071 break; 1073 break;
1072 } 1074 }
1073 } 1075 }
1074 1076 return PaintScaledTheme(handle, hdc, SBP_ARROWBTN, state_id, rect);
1075 return draw_theme_(handle, hdc, SBP_ARROWBTN, state_id, &rect_win, NULL);
1076 } 1077 }
1077 1078
1078 int classic_state = DFCS_SCROLLDOWN; 1079 int classic_state = DFCS_SCROLLDOWN;
1079 switch (part) { 1080 switch (part) {
1080 case kScrollbarDownArrow: 1081 case kScrollbarDownArrow:
1081 classic_state = DFCS_SCROLLDOWN; 1082 classic_state = DFCS_SCROLLDOWN;
1082 break; 1083 break;
1083 case kScrollbarLeftArrow: 1084 case kScrollbarLeftArrow:
1084 classic_state = DFCS_SCROLLLEFT; 1085 classic_state = DFCS_SCROLLLEFT;
1085 break; 1086 break;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 break; 1155 break;
1155 case kPressed: 1156 case kPressed:
1156 state_id = SCRBS_PRESSED; 1157 state_id = SCRBS_PRESSED;
1157 break; 1158 break;
1158 default: 1159 default:
1159 NOTREACHED() << "Invalid state: " << state; 1160 NOTREACHED() << "Invalid state: " << state;
1160 break; 1161 break;
1161 } 1162 }
1162 1163
1163 if (handle && draw_theme_) 1164 if (handle && draw_theme_)
1164 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); 1165 return PaintScaledTheme(handle, hdc, part_id, state_id, rect);
1165 1166
1166 // Draw it manually. 1167 // Draw it manually.
1167 if ((part_id == SBP_THUMBBTNHORZ) || (part_id == SBP_THUMBBTNVERT)) 1168 if ((part_id == SBP_THUMBBTNHORZ) || (part_id == SBP_THUMBBTNVERT))
1168 DrawEdge(hdc, &rect_win, EDGE_RAISED, BF_RECT | BF_MIDDLE); 1169 DrawEdge(hdc, &rect_win, EDGE_RAISED, BF_RECT | BF_MIDDLE);
1169 // Classic mode doesn't have a gripper. 1170 // Classic mode doesn't have a gripper.
1170 return S_OK; 1171 return S_OK;
1171 } 1172 }
1172 1173
1173 HRESULT NativeThemeWin::PaintScrollbarTrack( 1174 HRESULT NativeThemeWin::PaintScrollbarTrack(
1174 SkCanvas* canvas, 1175 SkCanvas* canvas,
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 if (fill_content_area) { 1585 if (fill_content_area) {
1585 FillRect(hdc, rect, (classic_state & DFCS_INACTIVE) ? 1586 FillRect(hdc, rect, (classic_state & DFCS_INACTIVE) ?
1586 reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1) : bg_brush); 1587 reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1) : bg_brush);
1587 } 1588 }
1588 hr = S_OK; 1589 hr = S_OK;
1589 } 1590 }
1590 DeleteObject(bg_brush); 1591 DeleteObject(bg_brush);
1591 return hr; 1592 return hr;
1592 } 1593 }
1593 1594
1595 HRESULT NativeThemeWin::PaintScaledTheme(HANDLE theme,
1596 HDC hdc,
1597 int part_id,
1598 int state_id,
1599 const gfx::Rect& rect) const {
1600 // Correct the scaling and positioning of sub-components such as scrollbar
1601 // arrows and thumb grippers in the event that the world transform applies
1602 // scaling (e.g. in high-DPI mode).
1603 XFORM save_transform;
1604 if (GetWorldTransform(hdc, &save_transform)) {
1605 float scale = save_transform.eM11;
1606 if (scale != 1 && save_transform.eM12 == 0) {
1607 ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
1608 gfx::Rect scaled_rect = gfx::ToEnclosedRect(
1609 gfx::ScaleRect(rect, scale));
1610 RECT bounds = gfx::Rect(scaled_rect.x() + save_transform.eDx,
1611 scaled_rect.y() + save_transform.eDy,
1612 scaled_rect.width(),
1613 scaled_rect.height()).ToRECT();
1614 HRESULT result = draw_theme_(theme, hdc, part_id, state_id, &bounds,
1615 NULL);
1616 SetWorldTransform(hdc, &save_transform);
1617 return result;
1618 }
1619 }
1620 RECT bounds = rect.ToRECT();
1621 return draw_theme_(theme, hdc, part_id, state_id, &bounds, NULL);
1622 }
1623
1594 // static 1624 // static
1595 NativeThemeWin::ThemeName NativeThemeWin::GetThemeName(Part part) { 1625 NativeThemeWin::ThemeName NativeThemeWin::GetThemeName(Part part) {
1596 ThemeName name; 1626 ThemeName name;
1597 switch (part) { 1627 switch (part) {
1598 case kCheckbox: 1628 case kCheckbox:
1599 case kRadio: 1629 case kRadio:
1600 case kPushButton: 1630 case kPushButton:
1601 name = BUTTON; 1631 name = BUTTON;
1602 break; 1632 break;
1603 case kInnerSpinButton: 1633 case kInnerSpinButton:
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
2027 handle = open_theme_(NULL, L"Spin"); 2057 handle = open_theme_(NULL, L"Spin");
2028 break; 2058 break;
2029 default: 2059 default:
2030 NOTREACHED(); 2060 NOTREACHED();
2031 } 2061 }
2032 theme_handles_[theme_name] = handle; 2062 theme_handles_[theme_name] = handle;
2033 return handle; 2063 return handle;
2034 } 2064 }
2035 2065
2036 } // namespace ui 2066 } // namespace ui
OLDNEW
« no previous file with comments | « ui/native_theme/native_theme_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698