diff options
author | kevers@chromium.org <kevers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-31 17:24:42 +0000 |
---|---|---|
committer | kevers@chromium.org <kevers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-31 17:24:42 +0000 |
commit | 7408e92fafcfa8c839c49953a9d3d10f6948098d (patch) | |
tree | ac64446c921220256bbba2824edce38d73889416 /ui/base/win | |
parent | 4623bfce16966ddf87053875b2756002590a3911 (diff) | |
download | chromium_src-7408e92fafcfa8c839c49953a9d3d10f6948098d.zip chromium_src-7408e92fafcfa8c839c49953a9d3d10f6948098d.tar.gz chromium_src-7408e92fafcfa8c839c49953a9d3d10f6948098d.tar.bz2 |
Fix high-DPI on Windows to make use of DIP scaling in WebKit.
BUG=149881
Review URL: https://chromiumcodereview.appspot.com/11953054
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179899 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/win')
-rw-r--r-- | ui/base/win/dpi.cc | 49 | ||||
-rw-r--r-- | ui/base/win/dpi.h | 20 |
2 files changed, 69 insertions, 0 deletions
diff --git a/ui/base/win/dpi.cc b/ui/base/win/dpi.cc index 9c56af0..ecfb3e7 100644 --- a/ui/base/win/dpi.cc +++ b/ui/base/win/dpi.cc @@ -7,12 +7,26 @@ #include <windows.h> #include "base/win/scoped_hdc.h" +#include "ui/gfx/display.h" +#include "ui/gfx/point_conversions.h" +#include "ui/gfx/rect_conversions.h" +#include "ui/gfx/size_conversions.h" namespace { int kDefaultDPIX = 96; int kDefaultDPIY = 96; + +float GetDeviceScaleFactorImpl() { +#if defined(ENABLE_HIDPI) + return gfx::Display::HasForceDeviceScaleFactor() ? + gfx::Display::GetForcedDeviceScaleFactor() : ui::GetDPIScale(); +#else + return 1.0f; +#endif +} + } // namespace namespace ui { @@ -53,4 +67,39 @@ void EnableHighDPISupport() { set_process_dpi_aware_func(); } +namespace win { + +float GetDeviceScaleFactor() { + static const float device_scale_factor = GetDeviceScaleFactorImpl(); + return device_scale_factor; +} + +gfx::Point ScreenToDIPPoint(const gfx::Point& pixel_point) { + return gfx::ToFlooredPoint( + gfx::ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactor())); +} + +gfx::Rect ScreenToDIPRect(const gfx::Rect& pixel_bounds) { + // TODO(kevers): Switch to non-deprecated method for float to int conversions. + return gfx::ToFlooredRectDeprecated( + gfx::ScaleRect(pixel_bounds, 1.0f / GetDeviceScaleFactor())); +} + +gfx::Rect DIPToScreenRect(const gfx::Rect& dip_bounds) { + // TODO(kevers): Switch to non-deprecated method for float to int conversions. + return gfx::ToFlooredRectDeprecated( + gfx::ScaleRect(dip_bounds, GetDeviceScaleFactor())); +} + +gfx::Size ScreenToDIPSize(const gfx::Size& size_in_pixels) { + return gfx::ToFlooredSize( + gfx::ScaleSize(size_in_pixels, 1.0f / GetDeviceScaleFactor())); +} + +gfx::Size DIPToScreenSize(const gfx::Size& dip_size) { + return gfx::ToFlooredSize(gfx::ScaleSize(dip_size, GetDeviceScaleFactor())); +} + +} // namespace win + } // namespace ui diff --git a/ui/base/win/dpi.h b/ui/base/win/dpi.h index 930922a..99252c7 100644 --- a/ui/base/win/dpi.h +++ b/ui/base/win/dpi.h @@ -5,6 +5,8 @@ #ifndef UI_BASE_WIN_DPI_H_ #define UI_BASE_WIN_DPI_H_ +#include "ui/gfx/point.h" +#include "ui/gfx/rect.h" #include "ui/gfx/size.h" #include "ui/base/ui_export.h" @@ -20,6 +22,24 @@ UI_EXPORT bool IsInHighDPIMode(); UI_EXPORT void EnableHighDPISupport(); +// TODO(kevers|girard): Move above methods into win namespace. + +namespace win { + +UI_EXPORT float GetDeviceScaleFactor(); + +UI_EXPORT gfx::Point ScreenToDIPPoint(const gfx::Point& pixel_point); + +UI_EXPORT gfx::Rect ScreenToDIPRect(const gfx::Rect& pixel_bounds); + +UI_EXPORT gfx::Rect DIPToScreenRect(const gfx::Rect& dip_bounds); + +UI_EXPORT gfx::Size ScreenToDIPSize(const gfx::Size& size_in_pixels); + +UI_EXPORT gfx::Size DIPToScreenSize(const gfx::Size& dip_size); + +} // namespace win + } // namespace ui #endif // UI_BASE_WIN_DPI_H_ |