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

Side by Side 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: Add rect_util_unittests to GN 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_GFX_SCREEN_WIN_H_ 5 #ifndef UI_GFX_SCREEN_WIN_H_
6 #define UI_GFX_SCREEN_WIN_H_ 6 #define UI_GFX_SCREEN_WIN_H_
7 7
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "ui/gfx/display_change_notifier.h" 13 #include "ui/gfx/display_change_notifier.h"
14 #include "ui/gfx/gfx_export.h" 14 #include "ui/gfx/gfx_export.h"
15 #include "ui/gfx/native_widget_types.h" 15 #include "ui/gfx/native_widget_types.h"
16 #include "ui/gfx/screen.h" 16 #include "ui/gfx/screen.h"
17 #include "ui/gfx/win/singleton_hwnd_observer.h" 17 #include "ui/gfx/win/singleton_hwnd_observer.h"
18 18
19 namespace gfx { 19 namespace gfx {
20 20
21 class Display; 21 class Display;
22 class Point; 22 class Point;
23 class Rect; 23 class Rect;
24 class Size;
24 25
25 namespace win { 26 namespace win {
26 27
27 class DisplayInfo; 28 class DisplayInfo;
28 class ScreenWinDisplay; 29 class ScreenWinDisplay;
29 30
30 } // namespace win 31 } // namespace win
31 32
32 class GFX_EXPORT ScreenWin : public Screen { 33 class GFX_EXPORT ScreenWin : public Screen {
33 public: 34 public:
34 ScreenWin(); 35 ScreenWin();
35 ~ScreenWin() override; 36 ~ScreenWin() override;
36 37
38 // Converts a screen pixel point to a DIP point.
39 // The DPI scale is performed relative to the display containing the screen
40 // pixel point maintaining a constant origin on both Screen and DIP (same as
41 // Windows).
42 static Point ScreenToDIPPoint(const Point& pixel_point);
43
44 // Converts a DIP point to a screen pixel point.
45 // The DPI scale is performed relative to the display containing the DIP point
46 // maintaining a constant origin on both Screen and DIP (same as Windows).
47 static Point DIPToScreenPoint(const Point& dip_point);
48
49 // Converts a client pixel point relative to |hwnd| to a DIP point.
50 // The DPI scale is performed relative to |hwnd| using an origin of (0, 0).
51 static Point ClientToDIPPoint(HWND hwnd, const Point& client_point);
52
53 // Converts a client DIP point relative to |hwnd| to a client pixel point.
54 // The DPI scale is performed relative to |hwnd| using an origin of (0, 0).
55 static Point DIPToClientPoint(HWND hwnd, const Point& dip_point);
56
57 // WARNING: there is no right way to scale sizes and rects. The implementation
58 // of these strives to maintain a constant size by scaling the size
59 // independent of the origin. An alternative is to get the enclosing rect,
oshima 2016/02/11 22:59:58 The comment isn't clear to me. can you elaborate?
robliao 2016/02/12 01:52:53 This was taken from the original DPI scaling code.
60 // which is the right way for some situations. Understand which you need
61 // before blindly assuming this is the right way.
62
63 // Converts a screen rect to a DIP rect.
64 // The DPI scale is performed relative to the display nearest to |hwnd|
65 // maintaining a constant origin on both Screen and DIP (same as Windows).
66 // If |hwnd| is null, scaling will be performed to the display nearest to
67 // |pixel_bounds|.
68 static Rect ScreenToDIPRect(HWND hwnd, const Rect& pixel_bounds);
69
70 // Converts a DIP rect to a screen rect.
71 // The DPI scale is performed relative to the display nearest to |hwnd|
72 // maintaining a constant origin on both Screen and DIP (same as Windows).
73 // If |hwnd| is null, scaling will be performed to the display nearest to
74 // |dip_bounds|.
75 static Rect DIPToScreenRect(HWND hwnd, const Rect& dip_bounds);
76
77 // Converts a client rect to a DIP rect.
78 // The DPI scale is performed relative to |hwnd| using an origin of (0, 0).
79 static Rect ClientToDIPRect(HWND hwnd, const Rect& pixel_bounds);
80
81 // Converts a DIP rect to a client rect.
82 // The DPI scale is performed relative to |hwnd| using an origin of (0, 0).
83 static Rect DIPToClientRect(HWND hwnd, const Rect& dip_bounds);
84
85 // Converts a screen size to a DIP size.
86 // The DPI scale is performed relative to the display nearest to |hwnd|.
87 static Size ScreenToDIPSize(HWND hwnd, const Size& size_in_pixels);
88
89 // Converts a DIP size to a screen size.
90 // The DPI scale is performed relative to the display nearest to |hwnd|.
91 static Size DIPToScreenSize(HWND hwnd, const Size& dip_size);
92
37 // Returns the HWND associated with the NativeView. 93 // Returns the HWND associated with the NativeView.
38 virtual HWND GetHWNDFromNativeView(NativeView window) const; 94 virtual HWND GetHWNDFromNativeView(NativeView window) const;
39 95
40 // Returns the NativeView associated with the HWND. 96 // Returns the NativeView associated with the HWND.
41 virtual NativeWindow GetNativeWindowFromHWND(HWND hwnd) const; 97 virtual NativeWindow GetNativeWindowFromHWND(HWND hwnd) const;
42 98
43 protected: 99 protected:
44 // gfx::Screen: 100 // gfx::Screen:
45 gfx::Point GetCursorScreenPoint() override; 101 gfx::Point GetCursorScreenPoint() override;
46 gfx::NativeWindow GetWindowUnderCursor() override; 102 gfx::NativeWindow GetWindowUnderCursor() override;
47 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; 103 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override;
48 int GetNumDisplays() const override; 104 int GetNumDisplays() const override;
49 std::vector<gfx::Display> GetAllDisplays() const override; 105 std::vector<gfx::Display> GetAllDisplays() const override;
50 gfx::Display GetDisplayNearestWindow(gfx::NativeView window) const override; 106 gfx::Display GetDisplayNearestWindow(gfx::NativeView window) const override;
51 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override; 107 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override;
52 gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override; 108 gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override;
53 gfx::Display GetPrimaryDisplay() const override; 109 gfx::Display GetPrimaryDisplay() const override;
54 void AddObserver(DisplayObserver* observer) override; 110 void AddObserver(DisplayObserver* observer) override;
55 void RemoveObserver(DisplayObserver* observer) override; 111 void RemoveObserver(DisplayObserver* observer) override;
112 gfx::Rect ScreenToDIPRectInWindow(
113 NativeView view, const gfx::Rect& screen_rect) const override;
114 gfx::Rect DIPToScreenRectInWindow(
115 NativeView view, const gfx::Rect& dip_rect) const override;
56 116
57 void UpdateFromDisplayInfos( 117 void UpdateFromDisplayInfos(
58 const std::vector<gfx::win::DisplayInfo>& display_infos); 118 const std::vector<gfx::win::DisplayInfo>& display_infos);
59 119
60 // Virtual to support mocking by unit tests. 120 // Virtual to support mocking by unit tests.
61 virtual void Initialize(); 121 virtual void Initialize();
62 virtual MONITORINFOEX MonitorInfoFromScreenPoint( 122 virtual MONITORINFOEX MonitorInfoFromScreenPoint(
63 const gfx::Point& screen_point) const; 123 const gfx::Point& screen_point) const;
64 virtual MONITORINFOEX MonitorInfoFromScreenRect(const gfx::Rect& screen_rect) 124 virtual MONITORINFOEX MonitorInfoFromScreenRect(const gfx::Rect& screen_rect)
65 const; 125 const;
66 virtual MONITORINFOEX MonitorInfoFromWindow(HWND hwnd, DWORD default_options) 126 virtual MONITORINFOEX MonitorInfoFromWindow(HWND hwnd, DWORD default_options)
67 const; 127 const;
68 virtual HWND GetRootWindow(HWND hwnd) const; 128 virtual HWND GetRootWindow(HWND hwnd) const;
69 129
70 private: 130 private:
71 void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); 131 void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
72 132
73 // Returns the ScreenWinDisplay closest to or enclosing |hwnd|. 133 // Returns the ScreenWinDisplay closest to or enclosing |hwnd|.
74 gfx::win::ScreenWinDisplay GetScreenWinDisplayNearestHWND(HWND hwnd) const; 134 gfx::win::ScreenWinDisplay GetScreenWinDisplayNearestHWND(HWND hwnd) const;
75 135
76 // Returns the ScreenWinDisplay closest to or enclosing |screen_rect|. 136 // Returns the ScreenWinDisplay closest to or enclosing |screen_rect|.
77 gfx::win::ScreenWinDisplay GetScreenWinDisplayNearestScreenRect( 137 gfx::win::ScreenWinDisplay GetScreenWinDisplayNearestScreenRect(
78 const Rect& screen_rect) const; 138 const Rect& screen_rect) const;
79 139
80 // Returns the ScreenWinDisplay closest to or enclosing |screen_point|. 140 // Returns the ScreenWinDisplay closest to or enclosing |screen_point|.
81 gfx::win::ScreenWinDisplay GetScreenWinDisplayNearestScreenPoint( 141 gfx::win::ScreenWinDisplay GetScreenWinDisplayNearestScreenPoint(
82 const Point& screen_point) const; 142 const Point& screen_point) const;
83 143
144 // Returns the ScreenWinDisplay closest to or enclosing |dip_point|.
145 gfx::win::ScreenWinDisplay GetScreenWinDisplayNearestDIPPoint(
146 const Point& dip_point) const;
147
148 // Returns the ScreenWinDisplay closest to or enclosing |dip_rect|.
149 gfx::win::ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestDIPRect(
150 const Rect& dip_rect) const;
151
84 // Returns the ScreenWinDisplay corresponding to the primary monitor. 152 // Returns the ScreenWinDisplay corresponding to the primary monitor.
85 gfx::win::ScreenWinDisplay GetPrimaryScreenWinDisplay() const; 153 gfx::win::ScreenWinDisplay GetPrimaryScreenWinDisplay() const;
86 154
87 gfx::win::ScreenWinDisplay GetScreenWinDisplay( 155 gfx::win::ScreenWinDisplay GetScreenWinDisplay(
88 const MONITORINFOEX& monitor_info) const; 156 const MONITORINFOEX& monitor_info) const;
89 157
158 static float GetScaleFactorForHWND(HWND hwnd);
159
160 // Returns the result of calling |getter| with |value| on the global
161 // ScreenWin if it exists, otherwise return the default ScreenWinDisplay.
162 template <typename Getter, typename GetterType>
163 static gfx::win::ScreenWinDisplay GetScreenWinDisplayVia(Getter getter,
164 GetterType value);
165
90 // Helper implementing the DisplayObserver handling. 166 // Helper implementing the DisplayObserver handling.
91 gfx::DisplayChangeNotifier change_notifier_; 167 gfx::DisplayChangeNotifier change_notifier_;
92 168
93 scoped_ptr<SingletonHwndObserver> singleton_hwnd_observer_; 169 scoped_ptr<SingletonHwndObserver> singleton_hwnd_observer_;
94 170
95 // Current list of ScreenWinDisplays. 171 // Current list of ScreenWinDisplays.
96 std::vector<gfx::win::ScreenWinDisplay> screen_win_displays_; 172 std::vector<gfx::win::ScreenWinDisplay> screen_win_displays_;
97 173
98 DISALLOW_COPY_AND_ASSIGN(ScreenWin); 174 DISALLOW_COPY_AND_ASSIGN(ScreenWin);
99 }; 175 };
100 176
101 } // namespace gfx 177 } // namespace gfx
102 178
103 #endif // UI_GFX_SCREEN_WIN_H_ 179 #endif // UI_GFX_SCREEN_WIN_H_
OLDNEW
« 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