summaryrefslogtreecommitdiffstats
path: root/ui/native_theme
diff options
context:
space:
mode:
authorkevers@chromium.org <kevers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-04 17:03:13 +0000
committerkevers@chromium.org <kevers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-04 17:03:13 +0000
commit1ca1eebb7837fb94f2f2108a5ebe684333981891 (patch)
treea5e585f8b97afebbc3c44f4678373fa9052d66ae /ui/native_theme
parent10923c1d89b7f60ab5f775b34a4c3ae124a28732 (diff)
downloadchromium_src-1ca1eebb7837fb94f2f2108a5ebe684333981891.zip
chromium_src-1ca1eebb7837fb94f2f2108a5ebe684333981891.tar.gz
chromium_src-1ca1eebb7837fb94f2f2108a5ebe684333981891.tar.bz2
Fix painting of scaled themes in Windows in high-DPI mode.
BUG=149881 Review URL: https://chromiumcodereview.appspot.com/12114049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180431 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/native_theme')
-rw-r--r--ui/native_theme/native_theme_win.cc36
-rw-r--r--ui/native_theme/native_theme_win.h10
2 files changed, 43 insertions, 3 deletions
diff --git a/ui/native_theme/native_theme_win.cc b/ui/native_theme/native_theme_win.cc
index 3e04dcb..b3d09a4 100644
--- a/ui/native_theme/native_theme_win.cc
+++ b/ui/native_theme/native_theme_win.cc
@@ -23,9 +23,11 @@
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColorPriv.h"
#include "third_party/skia/include/core/SkShader.h"
+#include "ui/base/win/dpi.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/gdi_util.h"
#include "ui/gfx/rect.h"
+#include "ui/gfx/rect_conversions.h"
#include "ui/native_theme/common_theme.h"
// This was removed from Winvers.h but is still used.
@@ -1071,8 +1073,7 @@ HRESULT NativeThemeWin::PaintScrollbarArrow(
break;
}
}
-
- return draw_theme_(handle, hdc, SBP_ARROWBTN, state_id, &rect_win, NULL);
+ return PaintScaledTheme(handle, hdc, SBP_ARROWBTN, state_id, rect);
}
int classic_state = DFCS_SCROLLDOWN;
@@ -1161,7 +1162,7 @@ HRESULT NativeThemeWin::PaintScrollbarThumb(
}
if (handle && draw_theme_)
- return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL);
+ return PaintScaledTheme(handle, hdc, part_id, state_id, rect);
// Draw it manually.
if ((part_id == SBP_THUMBBTNHORZ) || (part_id == SBP_THUMBBTNVERT))
@@ -1591,6 +1592,35 @@ HRESULT NativeThemeWin::PaintTextField(HDC hdc,
return hr;
}
+HRESULT NativeThemeWin::PaintScaledTheme(HANDLE theme,
+ HDC hdc,
+ int part_id,
+ int state_id,
+ const gfx::Rect& rect) const {
+ // Correct the scaling and positioning of sub-components such as scrollbar
+ // arrows and thumb grippers in the event that the world transform applies
+ // scaling (e.g. in high-DPI mode).
+ XFORM save_transform;
+ if (GetWorldTransform(hdc, &save_transform)) {
+ float scale = save_transform.eM11;
+ if (scale != 1 && save_transform.eM12 == 0) {
+ ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
+ gfx::Rect scaled_rect = gfx::ToEnclosedRect(
+ gfx::ScaleRect(rect, scale));
+ RECT bounds = gfx::Rect(scaled_rect.x() + save_transform.eDx,
+ scaled_rect.y() + save_transform.eDy,
+ scaled_rect.width(),
+ scaled_rect.height()).ToRECT();
+ HRESULT result = draw_theme_(theme, hdc, part_id, state_id, &bounds,
+ NULL);
+ SetWorldTransform(hdc, &save_transform);
+ return result;
+ }
+ }
+ RECT bounds = rect.ToRECT();
+ return draw_theme_(theme, hdc, part_id, state_id, &bounds, NULL);
+}
+
// static
NativeThemeWin::ThemeName NativeThemeWin::GetThemeName(Part part) {
ThemeName name;
diff --git a/ui/native_theme/native_theme_win.h b/ui/native_theme/native_theme_win.h
index d4bdea7..5542f20 100644
--- a/ui/native_theme/native_theme_win.h
+++ b/ui/native_theme/native_theme_win.h
@@ -257,6 +257,16 @@ class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme,
const gfx::Rect& rect,
const TextFieldExtraParams& extra) const;
+ // Paints a theme part, with support for scene scaling in high-DPI mode.
+ // |theme| is the theme handle. |hdc| is the handle for the device context.
+ // |part_id| is the identifier for the part (e.g. thumb gripper). |state_id|
+ // is the identifier for the rendering state of the part (e.g. hover). |rect|
+ // is the bounds for rendering, expressed in logical coordinates.
+ HRESULT PaintScaledTheme(HANDLE theme,
+ HDC hdc,
+ int part_id,
+ int state_id,
+ const gfx::Rect& rect) const;
// Get the windows theme name/part/state. These three helper functions are
// used only by GetPartSize(), as each of the corresponding PaintXXX()