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

Unified Diff: ui/gfx/screen_win.h

Issue 1679393002: Multiple DPI Tracking for ScreenWin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/screen_win.h
diff --git a/ui/gfx/screen_win.h b/ui/gfx/screen_win.h
index 2849e6623de312f412e32cc5a544a69080a9717b..6cb9e34660b91ea443b288c6349316e3f2bca993 100644
--- a/ui/gfx/screen_win.h
+++ b/ui/gfx/screen_win.h
@@ -21,6 +21,7 @@ namespace gfx {
class Display;
class Point;
class Rect;
+class Size;
namespace win {
@@ -34,6 +35,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 point 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 pixel point.
+ // The DPI scale is performed relative to |hwnd| using an origin of (0, 0).
+ static Point DIPToClientPoint(HWND hwnd, const Point& dip_point);
+
+ // 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);
+
// Returns the HWND associated with the NativeView.
virtual HWND GetHWNDFromNativeView(NativeView window) const;
@@ -53,6 +109,10 @@ class GFX_EXPORT ScreenWin : public Screen {
gfx::Display GetPrimaryDisplay() const override;
void AddObserver(DisplayObserver* observer) override;
void RemoveObserver(DisplayObserver* observer) override;
+ gfx::Rect ScreenToDIPRectInWindow(
+ NativeView view, const gfx::Rect& screen_rect) const override;
+ gfx::Rect DIPToScreenRectInWindow(
+ NativeView view, const gfx::Rect& dip_rect) const override;
void UpdateFromDisplayInfos(
const std::vector<gfx::win::DisplayInfo>& display_infos);
@@ -81,12 +141,28 @@ class GFX_EXPORT ScreenWin : public Screen {
gfx::win::ScreenWinDisplay GetScreenWinDisplayNearestScreenPoint(
const Point& screen_point) const;
+ // Returns the ScreenWinDisplay closest to or enclosing |dip_point|.
+ gfx::win::ScreenWinDisplay GetScreenWinDisplayNearestDIPPoint(
+ const Point& dip_point) const;
+
+ // Returns the ScreenWinDisplay closest to or enclosing |dip_rect|.
+ gfx::win::ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestDIPRect(
+ const Rect& dip_rect) const;
+
// Returns the ScreenWinDisplay corresponding to the primary monitor.
gfx::win::ScreenWinDisplay GetPrimaryScreenWinDisplay() const;
gfx::win::ScreenWinDisplay GetScreenWinDisplay(
const MONITORINFOEX& monitor_info) const;
+ static float GetScaleFactorForHWND(HWND hwnd);
+
+ // Returns the result of calling |getter| with |value| on the global
+ // ScreenWin if it exists, otherwise return the default ScreenWinDisplay.
+ template <typename Getter, typename GetterType>
+ static gfx::win::ScreenWinDisplay GetScreenWinDisplayVia(Getter getter,
+ GetterType value);
+
// Helper implementing the DisplayObserver handling.
gfx::DisplayChangeNotifier change_notifier_;
« no previous file with comments | « ui/gfx/gfx_tests.gyp ('k') | ui/gfx/screen_win.cc » ('j') | ui/gfx/screen_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698