Chromium Code Reviews| Index: ui/gfx/screen_win.h |
| diff --git a/ui/gfx/screen_win.h b/ui/gfx/screen_win.h |
| index 9ece286e919750ac1e1ec8bf167d4548aeec364f..17b37f54a668043f2600285ccb72e88b8570a863 100644 |
| --- a/ui/gfx/screen_win.h |
| +++ b/ui/gfx/screen_win.h |
| @@ -8,6 +8,9 @@ |
| #include "base/compiler_specific.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "ui/gfx/display_change_notifier.h" |
| +#include "ui/gfx/geometry/point.h" |
| +#include "ui/gfx/geometry/rect.h" |
| +#include "ui/gfx/geometry/size.h" |
| #include "ui/gfx/gfx_export.h" |
| #include "ui/gfx/screen.h" |
| #include "ui/gfx/win/singleton_hwnd_observer.h" |
| @@ -19,6 +22,61 @@ class GFX_EXPORT ScreenWin : public Screen { |
| ScreenWin(); |
| ~ScreenWin() override; |
| + // Converts a screen pixel point to a DIP point. |
| + // The DPI scale is performed relative to the display containing the screen |
| + // pixel point maintaining a constant origin on both Screen and DIP (same as |
| + // Windows). |
| + static Point ScreenToDIPPoint(const Point& pixel_point); |
| + |
| + // Converts a DIP point to a screen pixel point. |
| + // The DPI scale is performed relative to the display containing the DIP point |
| + // maintaining a constant origin on both Screen and DIP (same as Windows). |
| + static Point DIPToScreenPoint(const Point& dip_point); |
| + |
| + // Converts a client pixel relative to |hwnd| to a DIP point. |
| + // The DPI scale is performed relative to |hwnd| using an origin of (0, 0). |
| + static Point ClientToDIPPoint(HWND hwnd, const Point& client_point); |
| + |
| + // Converts a client DIP point relative to |hwnd| to a client point. |
|
scottmg
2015/10/28 18:48:21
Is this point or pixel?
robliao
2015/10/29 00:30:24
pixel point for consistency with the above. As par
|
| + // The DPI scale is performed relative to |hwnd| using an origin of (0, 0). |
| + static Point DIPToClientPoint(HWND hwnd, const Point& dip_pount); |
|
scottmg
2015/10/28 18:48:21
"pount"
robliao
2015/10/29 00:30:24
Done.
|
| + |
| + // WARNING: there is no right way to scale sizes and rects. The implementation |
| + // of these strives to maintain a constant size by scaling the size |
| + // independent of the origin. An alternative is to get the enclosing rect, |
| + // which is the right way for some situations. Understand which you need |
| + // before blindly assuming this is the right way. |
| + |
| + // Converts a screen rect to a DIP rect. |
| + // The DPI scale is performed relative to the display nearest to |hwnd| |
| + // maintaining a constant origin on both Screen and DIP (same as Windows). |
| + // If |hwnd| is null, scaling will be performed to the display nearest to |
| + // |pixel_bounds|. |
| + static Rect ScreenToDIPRect(HWND hwnd, const Rect& pixel_bounds); |
| + |
| + // Converts a DIP rect to a screen rect. |
| + // The DPI scale is performed relative to the display nearest to |hwnd| |
| + // maintaining a constant origin on both Screen and DIP (same as Windows). |
| + // If |hwnd| is null, scaling will be performed to the display nearest to |
| + // |dip_bounds|. |
| + static Rect DIPToScreenRect(HWND hwnd, const Rect& dip_bounds); |
| + |
| + // Converts a client rect to a DIP rect. |
| + // The DPI scale is performed relative to |hwnd| using an origin of (0, 0). |
| + static Rect ClientToDIPRect(HWND hwnd, const Rect& pixel_bounds); |
| + |
| + // Converts a DIP rect to a client rect. |
| + // The DPI scale is performed relative to |hwnd| using an origin of (0, 0). |
| + static Rect DIPToClientRect(HWND hwnd, const Rect& dip_bounds); |
| + |
| + // Converts a screen size to a DIP size. |
| + // The DPI scale is performed relative to the display nearest to |hwnd|. |
| + static Size ScreenToDIPSize(HWND hwnd, const Size& size_in_pixels); |
| + |
| + // Converts a DIP size to a screen size. |
| + // The DPI scale is performed relative to the display nearest to |hwnd|. |
| + static Size DIPToScreenSize(HWND hwnd, const Size& dip_size); |
| + |
| protected: |
| // Overridden from gfx::Screen: |
| gfx::Point GetCursorScreenPoint() override; |
| @@ -40,6 +98,12 @@ class GFX_EXPORT ScreenWin : public Screen { |
| virtual NativeWindow GetNativeWindowFromHWND(HWND hwnd) const; |
| private: |
| + static gfx::Display GetDisplayNearestHWND(HWND hwnd); |
| + static gfx::Display GetDisplayNearestRect(const Rect& rect); |
| + static gfx::Display GetDisplayNearestScreenPoint(const Point& screen_point); |
| + static float GetScaleFactorForHWND(HWND hwnd); |
| + static float GetScaleFactorForScreenPoint(const Point& screen_point); |
| + |
| void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); |
| // Helper implementing the DisplayObserver handling. |