Index: ui/base/win/dpi.cc |
diff --git a/ui/base/win/dpi.cc b/ui/base/win/dpi.cc |
index c9982924bd5ad0139f07313bb0478ecbf930f8ae..2a2e61a1d65a79f9bb9ca54c99825b5ba75d28cf 100644 |
--- a/ui/base/win/dpi.cc |
+++ b/ui/base/win/dpi.cc |
@@ -7,12 +7,25 @@ |
#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::GetForcedDeviceScaleFactor(); |
+#else |
+ return 1.0f; |
+#endif |
+} |
+ |
} // namespace |
namespace ui { |
@@ -52,4 +65,33 @@ void EnableHighDPISupport() { |
set_process_dpi_aware_func(); |
} |
+namespace win { |
+ |
+gfx::Point ScreenToDIPPoint(const gfx::Point& pixel_point) { |
+ return gfx::ToFlooredPoint( |
+ gfx::ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactorImpl())); |
+} |
+ |
+gfx::Rect ScreenToDIPRect(const gfx::Rect& pixel_bounds) { |
+ return gfx::ToFlooredRectDeprecated( |
pkotwicz
2013/01/23 19:39:23
Nit: Add TODO to use gfx::ToNearestRect().
kevers
2013/01/23 21:37:00
Based on description of method, ToNearestRect migh
|
+ gfx::ScaleRect(pixel_bounds, 1.0f / GetDeviceScaleFactorImpl())); |
+} |
+ |
+gfx::Rect DIPToScreenRect(const gfx::Rect& dip_bounds) { |
+ return gfx::ToFlooredRectDeprecated( |
+ gfx::ScaleRect(dip_bounds, GetDeviceScaleFactorImpl())); |
+} |
+ |
+gfx::Size ScreenToDIPSize(const gfx::Size& size_in_pixels) { |
+ return gfx::ToFlooredSize( |
+ gfx::ScaleSize(size_in_pixels, 1.0f / GetDeviceScaleFactorImpl())); |
+} |
+ |
+gfx::Size DIPToScreenSize(const gfx::Size& dip_size) { |
+ return gfx::ToFlooredSize( |
+ gfx::ScaleSize(dip_size, GetDeviceScaleFactorImpl())); |
+} |
+ |
+} // namespace win |
+ |
} // namespace ui |