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

Side by Side Diff: ui/display/win/screen_win.cc

Issue 1913613002: Add place holder to move gfx::Display/Screen to ui/display (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « ui/display/win/screen_win.h ('k') | ui/display/win/screen_win_display.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "ui/display/win/screen_win.h" 5 #include "ui/display/win/screen_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "ui/display/display.h"
11 #include "ui/display/win/display_info.h" 12 #include "ui/display/win/display_info.h"
12 #include "ui/display/win/dpi.h" 13 #include "ui/display/win/dpi.h"
13 #include "ui/display/win/screen_win_display.h" 14 #include "ui/display/win/screen_win_display.h"
14 #include "ui/gfx/display.h"
15 #include "ui/gfx/geometry/point.h" 15 #include "ui/gfx/geometry/point.h"
16 #include "ui/gfx/geometry/point_conversions.h" 16 #include "ui/gfx/geometry/point_conversions.h"
17 #include "ui/gfx/geometry/rect.h" 17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/geometry/rect_conversions.h" 18 #include "ui/gfx/geometry/rect_conversions.h"
19 #include "ui/gfx/geometry/size_conversions.h" 19 #include "ui/gfx/geometry/size_conversions.h"
20 20
21 namespace display { 21 namespace display {
22 namespace win { 22 namespace win {
23 23
24 namespace { 24 namespace {
25 25
26 std::vector<ScreenWinDisplay> DisplayInfosToScreenWinDisplays( 26 std::vector<ScreenWinDisplay> DisplayInfosToScreenWinDisplays(
27 const std::vector<DisplayInfo>& display_infos) { 27 const std::vector<DisplayInfo>& display_infos) {
28 std::vector<ScreenWinDisplay> screen_win_displays; 28 std::vector<ScreenWinDisplay> screen_win_displays;
29 for (const auto& display_info : display_infos) 29 for (const auto& display_info : display_infos)
30 screen_win_displays.push_back(ScreenWinDisplay(display_info)); 30 screen_win_displays.push_back(ScreenWinDisplay(display_info));
31 31
32 return screen_win_displays; 32 return screen_win_displays;
33 } 33 }
34 34
35 std::vector<gfx::Display> ScreenWinDisplaysToDisplays( 35 std::vector<display::Display> ScreenWinDisplaysToDisplays(
36 const std::vector<ScreenWinDisplay>& screen_win_displays) { 36 const std::vector<ScreenWinDisplay>& screen_win_displays) {
37 std::vector<gfx::Display> displays; 37 std::vector<display::Display> displays;
38 for (const auto& screen_win_display : screen_win_displays) 38 for (const auto& screen_win_display : screen_win_displays)
39 displays.push_back(screen_win_display.display()); 39 displays.push_back(screen_win_display.display());
40 40
41 return displays; 41 return displays;
42 } 42 }
43 43
44 MONITORINFOEX MonitorInfoFromHMONITOR(HMONITOR monitor) { 44 MONITORINFOEX MonitorInfoFromHMONITOR(HMONITOR monitor) {
45 MONITORINFOEX monitor_info; 45 MONITORINFOEX monitor_info;
46 ::ZeroMemory(&monitor_info, sizeof(monitor_info)); 46 ::ZeroMemory(&monitor_info, sizeof(monitor_info));
47 monitor_info.cbSize = sizeof(monitor_info); 47 monitor_info.cbSize = sizeof(monitor_info);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 170
171 gfx::NativeWindow ScreenWin::GetWindowAtScreenPoint(const gfx::Point& point) { 171 gfx::NativeWindow ScreenWin::GetWindowAtScreenPoint(const gfx::Point& point) {
172 gfx::Point point_in_pixels = DIPToScreenPoint(point); 172 gfx::Point point_in_pixels = DIPToScreenPoint(point);
173 return GetNativeWindowFromHWND(WindowFromPoint(point_in_pixels.ToPOINT())); 173 return GetNativeWindowFromHWND(WindowFromPoint(point_in_pixels.ToPOINT()));
174 } 174 }
175 175
176 int ScreenWin::GetNumDisplays() const { 176 int ScreenWin::GetNumDisplays() const {
177 return static_cast<int>(screen_win_displays_.size()); 177 return static_cast<int>(screen_win_displays_.size());
178 } 178 }
179 179
180 std::vector<gfx::Display> ScreenWin::GetAllDisplays() const { 180 std::vector<display::Display> ScreenWin::GetAllDisplays() const {
181 return ScreenWinDisplaysToDisplays(screen_win_displays_); 181 return ScreenWinDisplaysToDisplays(screen_win_displays_);
182 } 182 }
183 183
184 gfx::Display ScreenWin::GetDisplayNearestWindow(gfx::NativeView window) const { 184 display::Display ScreenWin::GetDisplayNearestWindow(
185 gfx::NativeView window) const {
185 HWND window_hwnd = GetHWNDFromNativeView(window); 186 HWND window_hwnd = GetHWNDFromNativeView(window);
186 if (!window_hwnd) { 187 if (!window_hwnd) {
187 // When |window| isn't rooted to a display, we should just return the 188 // When |window| isn't rooted to a display, we should just return the
188 // default display so we get some correct display information like the 189 // default display so we get some correct display information like the
189 // scaling factor. 190 // scaling factor.
190 return GetPrimaryDisplay(); 191 return GetPrimaryDisplay();
191 } 192 }
192 ScreenWinDisplay screen_win_display = 193 ScreenWinDisplay screen_win_display =
193 GetScreenWinDisplayNearestHWND(window_hwnd); 194 GetScreenWinDisplayNearestHWND(window_hwnd);
194 return screen_win_display.display(); 195 return screen_win_display.display();
195 } 196 }
196 197
197 gfx::Display ScreenWin::GetDisplayNearestPoint(const gfx::Point& point) const { 198 Display ScreenWin::GetDisplayNearestPoint(const gfx::Point& point) const {
198 gfx::Point screen_point(DIPToScreenPoint(point)); 199 gfx::Point screen_point(DIPToScreenPoint(point));
199 ScreenWinDisplay screen_win_display = 200 ScreenWinDisplay screen_win_display =
200 GetScreenWinDisplayNearestScreenPoint(screen_point); 201 GetScreenWinDisplayNearestScreenPoint(screen_point);
201 return screen_win_display.display(); 202 return screen_win_display.display();
202 } 203 }
203 204
204 gfx::Display ScreenWin::GetDisplayMatching(const gfx::Rect& match_rect) const { 205 display::Display ScreenWin::GetDisplayMatching(
206 const gfx::Rect& match_rect) const {
205 ScreenWinDisplay screen_win_display = 207 ScreenWinDisplay screen_win_display =
206 GetScreenWinDisplayNearestScreenRect(match_rect); 208 GetScreenWinDisplayNearestScreenRect(match_rect);
207 return screen_win_display.display(); 209 return screen_win_display.display();
208 } 210 }
209 211
210 gfx::Display ScreenWin::GetPrimaryDisplay() const { 212 display::Display ScreenWin::GetPrimaryDisplay() const {
211 return GetPrimaryScreenWinDisplay().display(); 213 return GetPrimaryScreenWinDisplay().display();
212 } 214 }
213 215
214 void ScreenWin::AddObserver(gfx::DisplayObserver* observer) { 216 void ScreenWin::AddObserver(display::DisplayObserver* observer) {
215 change_notifier_.AddObserver(observer); 217 change_notifier_.AddObserver(observer);
216 } 218 }
217 219
218 void ScreenWin::RemoveObserver(gfx::DisplayObserver* observer) { 220 void ScreenWin::RemoveObserver(display::DisplayObserver* observer) {
219 change_notifier_.RemoveObserver(observer); 221 change_notifier_.RemoveObserver(observer);
220 } 222 }
221 223
222 void ScreenWin::UpdateFromDisplayInfos( 224 void ScreenWin::UpdateFromDisplayInfos(
223 const std::vector<DisplayInfo>& display_infos) { 225 const std::vector<DisplayInfo>& display_infos) {
224 screen_win_displays_ = DisplayInfosToScreenWinDisplays(display_infos); 226 screen_win_displays_ = DisplayInfosToScreenWinDisplays(display_infos);
225 } 227 }
226 228
227 void ScreenWin::Initialize() { 229 void ScreenWin::Initialize() {
228 singleton_hwnd_observer_.reset( 230 singleton_hwnd_observer_.reset(
(...skipping 25 matching lines...) Expand all
254 return ::GetAncestor(hwnd, GA_ROOT); 256 return ::GetAncestor(hwnd, GA_ROOT);
255 } 257 }
256 258
257 void ScreenWin::OnWndProc(HWND hwnd, 259 void ScreenWin::OnWndProc(HWND hwnd,
258 UINT message, 260 UINT message,
259 WPARAM wparam, 261 WPARAM wparam,
260 LPARAM lparam) { 262 LPARAM lparam) {
261 if (message != WM_DISPLAYCHANGE) 263 if (message != WM_DISPLAYCHANGE)
262 return; 264 return;
263 265
264 std::vector<gfx::Display> old_displays = GetAllDisplays(); 266 std::vector<display::Display> old_displays = GetAllDisplays();
265 UpdateFromDisplayInfos(GetDisplayInfosFromSystem()); 267 UpdateFromDisplayInfos(GetDisplayInfosFromSystem());
266 change_notifier_.NotifyDisplaysChanged(old_displays, GetAllDisplays()); 268 change_notifier_.NotifyDisplaysChanged(old_displays, GetAllDisplays());
267 } 269 }
268 270
269 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestHWND(HWND hwnd) 271 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestHWND(HWND hwnd)
270 const { 272 const {
271 return GetScreenWinDisplay(MonitorInfoFromWindow(hwnd, 273 return GetScreenWinDisplay(MonitorInfoFromWindow(hwnd,
272 MONITOR_DEFAULTTONEAREST)); 274 MONITOR_DEFAULTTONEAREST));
273 } 275 }
274 276
275 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestScreenRect( 277 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestScreenRect(
276 const gfx::Rect& screen_rect) const { 278 const gfx::Rect& screen_rect) const {
277 return GetScreenWinDisplay(MonitorInfoFromScreenRect(screen_rect)); 279 return GetScreenWinDisplay(MonitorInfoFromScreenRect(screen_rect));
278 } 280 }
279 281
280 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestScreenPoint( 282 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestScreenPoint(
281 const gfx::Point& screen_point) const { 283 const gfx::Point& screen_point) const {
282 return GetScreenWinDisplay(MonitorInfoFromScreenPoint(screen_point)); 284 return GetScreenWinDisplay(MonitorInfoFromScreenPoint(screen_point));
283 } 285 }
284 286
285 ScreenWinDisplay ScreenWin::GetPrimaryScreenWinDisplay() const { 287 ScreenWinDisplay ScreenWin::GetPrimaryScreenWinDisplay() const {
286 MONITORINFOEX monitor_info = MonitorInfoFromWindow(nullptr, 288 MONITORINFOEX monitor_info = MonitorInfoFromWindow(nullptr,
287 MONITOR_DEFAULTTOPRIMARY); 289 MONITOR_DEFAULTTOPRIMARY);
288 ScreenWinDisplay screen_win_display = GetScreenWinDisplay(monitor_info); 290 ScreenWinDisplay screen_win_display = GetScreenWinDisplay(monitor_info);
289 gfx::Display display = screen_win_display.display(); 291 display::Display display = screen_win_display.display();
290 // The Windows primary monitor is defined to have an origin of (0, 0). 292 // The Windows primary monitor is defined to have an origin of (0, 0).
291 DCHECK_EQ(0, display.bounds().origin().x()); 293 DCHECK_EQ(0, display.bounds().origin().x());
292 DCHECK_EQ(0, display.bounds().origin().y()); 294 DCHECK_EQ(0, display.bounds().origin().y());
293 return screen_win_display; 295 return screen_win_display;
294 } 296 }
295 297
296 ScreenWinDisplay ScreenWin::GetScreenWinDisplay( 298 ScreenWinDisplay ScreenWin::GetScreenWinDisplay(
297 const MONITORINFOEX& monitor_info) const { 299 const MONITORINFOEX& monitor_info) const {
298 int64_t id = DisplayInfo::DeviceIdFromDeviceName(monitor_info.szDevice); 300 int64_t id = DisplayInfo::DeviceIdFromDeviceName(monitor_info.szDevice);
299 for (const auto& screen_win_display : screen_win_displays_) { 301 for (const auto& screen_win_display : screen_win_displays_) {
300 if (screen_win_display.display().id() == id) 302 if (screen_win_display.display().id() == id)
301 return screen_win_display; 303 return screen_win_display;
302 } 304 }
303 // There is 1:1 correspondence between MONITORINFOEX and ScreenWinDisplay. 305 // There is 1:1 correspondence between MONITORINFOEX and ScreenWinDisplay.
304 // If we make it here, it means we have no displays and we should hand out the 306 // If we make it here, it means we have no displays and we should hand out the
305 // default display. 307 // default display.
306 DCHECK_EQ(screen_win_displays_.size(), 0u); 308 DCHECK_EQ(screen_win_displays_.size(), 0u);
307 return ScreenWinDisplay(); 309 return ScreenWinDisplay();
308 } 310 }
309 311
310 } // namespace win 312 } // namespace win
311 } // namespace display 313 } // namespace display
OLDNEW
« no previous file with comments | « ui/display/win/screen_win.h ('k') | ui/display/win/screen_win_display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698