OLD | NEW |
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/win/display_info.h" | 11 #include "ui/display/win/display_info.h" |
| 12 #include "ui/display/win/dpi.h" |
12 #include "ui/display/win/screen_win_display.h" | 13 #include "ui/display/win/screen_win_display.h" |
13 #include "ui/gfx/display.h" | 14 #include "ui/gfx/display.h" |
14 #include "ui/gfx/geometry/point.h" | 15 #include "ui/gfx/geometry/point.h" |
15 #include "ui/gfx/geometry/point_conversions.h" | 16 #include "ui/gfx/geometry/point_conversions.h" |
16 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
17 #include "ui/gfx/geometry/rect_conversions.h" | 18 #include "ui/gfx/geometry/rect_conversions.h" |
18 #include "ui/gfx/geometry/size_conversions.h" | 19 #include "ui/gfx/geometry/size_conversions.h" |
19 #include "ui/gfx/win/dpi.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) |
(...skipping 20 matching lines...) Expand all Loading... |
50 } | 50 } |
51 | 51 |
52 BOOL CALLBACK EnumMonitorCallback(HMONITOR monitor, | 52 BOOL CALLBACK EnumMonitorCallback(HMONITOR monitor, |
53 HDC hdc, | 53 HDC hdc, |
54 LPRECT rect, | 54 LPRECT rect, |
55 LPARAM data) { | 55 LPARAM data) { |
56 std::vector<DisplayInfo>* display_infos = | 56 std::vector<DisplayInfo>* display_infos = |
57 reinterpret_cast<std::vector<DisplayInfo>*>(data); | 57 reinterpret_cast<std::vector<DisplayInfo>*>(data); |
58 DCHECK(display_infos); | 58 DCHECK(display_infos); |
59 display_infos->push_back(DisplayInfo(MonitorInfoFromHMONITOR(monitor), | 59 display_infos->push_back(DisplayInfo(MonitorInfoFromHMONITOR(monitor), |
60 gfx::GetDPIScale())); | 60 GetDPIScale())); |
61 return TRUE; | 61 return TRUE; |
62 } | 62 } |
63 | 63 |
64 std::vector<DisplayInfo> GetDisplayInfosFromSystem() { | 64 std::vector<DisplayInfo> GetDisplayInfosFromSystem() { |
65 std::vector<DisplayInfo> display_infos; | 65 std::vector<DisplayInfo> display_infos; |
66 EnumDisplayMonitors(nullptr, nullptr, EnumMonitorCallback, | 66 EnumDisplayMonitors(nullptr, nullptr, EnumMonitorCallback, |
67 reinterpret_cast<LPARAM>(&display_infos)); | 67 reinterpret_cast<LPARAM>(&display_infos)); |
68 DCHECK_EQ(static_cast<size_t>(::GetSystemMetrics(SM_CMONITORS)), | 68 DCHECK_EQ(static_cast<size_t>(::GetSystemMetrics(SM_CMONITORS)), |
69 display_infos.size()); | 69 display_infos.size()); |
70 return display_infos; | 70 return display_infos; |
71 } | 71 } |
72 | 72 |
73 } // namespace | 73 } // namespace |
74 | 74 |
75 ScreenWin::ScreenWin() { | 75 ScreenWin::ScreenWin() { |
76 Initialize(); | 76 Initialize(); |
77 } | 77 } |
78 | 78 |
79 ScreenWin::~ScreenWin() = default; | 79 ScreenWin::~ScreenWin() = default; |
80 | 80 |
81 // static | 81 // static |
82 gfx::Point ScreenWin::ScreenToDIPPoint(const gfx::Point& pixel_point) { | 82 gfx::Point ScreenWin::ScreenToDIPPoint(const gfx::Point& pixel_point) { |
83 return ScaleToFlooredPoint(pixel_point, 1.0f / gfx::GetDPIScale()); | 83 return ScaleToFlooredPoint(pixel_point, 1.0f / GetDPIScale()); |
84 } | 84 } |
85 | 85 |
86 // static | 86 // static |
87 gfx::Point ScreenWin::DIPToScreenPoint(const gfx::Point& dip_point) { | 87 gfx::Point ScreenWin::DIPToScreenPoint(const gfx::Point& dip_point) { |
88 return ScaleToFlooredPoint(dip_point, gfx::GetDPIScale()); | 88 return ScaleToFlooredPoint(dip_point, GetDPIScale()); |
89 } | 89 } |
90 | 90 |
91 // static | 91 // static |
92 gfx::Point ScreenWin::ClientToDIPPoint(HWND hwnd, | 92 gfx::Point ScreenWin::ClientToDIPPoint(HWND hwnd, |
93 const gfx::Point& client_point) { | 93 const gfx::Point& client_point) { |
94 // TODO(robliao): Get the scale factor from |hwnd|. | 94 // TODO(robliao): Get the scale factor from |hwnd|. |
95 return ScreenToDIPPoint(client_point); | 95 return ScreenToDIPPoint(client_point); |
96 } | 96 } |
97 | 97 |
98 // static | 98 // static |
(...skipping 28 matching lines...) Expand all Loading... |
127 // static | 127 // static |
128 gfx::Rect ScreenWin::DIPToClientRect(HWND hwnd, const gfx::Rect& dip_bounds) { | 128 gfx::Rect ScreenWin::DIPToClientRect(HWND hwnd, const gfx::Rect& dip_bounds) { |
129 return DIPToScreenRect(hwnd, dip_bounds); | 129 return DIPToScreenRect(hwnd, dip_bounds); |
130 } | 130 } |
131 | 131 |
132 // static | 132 // static |
133 gfx::Size ScreenWin::ScreenToDIPSize(HWND hwnd, | 133 gfx::Size ScreenWin::ScreenToDIPSize(HWND hwnd, |
134 const gfx::Size& size_in_pixels) { | 134 const gfx::Size& size_in_pixels) { |
135 // Always ceil sizes. Otherwise we may be leaving off part of the bounds. | 135 // Always ceil sizes. Otherwise we may be leaving off part of the bounds. |
136 // TODO(robliao): Get the scale factor from |hwnd|. | 136 // TODO(robliao): Get the scale factor from |hwnd|. |
137 return ScaleToCeiledSize(size_in_pixels, 1.0f / gfx::GetDPIScale()); | 137 return ScaleToCeiledSize(size_in_pixels, 1.0f / GetDPIScale()); |
138 } | 138 } |
139 | 139 |
140 // static | 140 // static |
141 gfx::Size ScreenWin::DIPToScreenSize(HWND hwnd, const gfx::Size& dip_size) { | 141 gfx::Size ScreenWin::DIPToScreenSize(HWND hwnd, const gfx::Size& dip_size) { |
142 // Always ceil sizes. Otherwise we may be leaving off part of the bounds. | 142 // Always ceil sizes. Otherwise we may be leaving off part of the bounds. |
143 // TODO(robliao): Get the scale factor from |hwnd|. | 143 // TODO(robliao): Get the scale factor from |hwnd|. |
144 return ScaleToCeiledSize(dip_size, gfx::GetDPIScale()); | 144 return ScaleToCeiledSize(dip_size, GetDPIScale()); |
145 } | 145 } |
146 | 146 |
147 HWND ScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const { | 147 HWND ScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const { |
148 NOTREACHED(); | 148 NOTREACHED(); |
149 return nullptr; | 149 return nullptr; |
150 } | 150 } |
151 | 151 |
152 gfx::NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { | 152 gfx::NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { |
153 NOTREACHED(); | 153 NOTREACHED(); |
154 return nullptr; | 154 return nullptr; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 } | 302 } |
303 // There is 1:1 correspondence between MONITORINFOEX and ScreenWinDisplay. | 303 // 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 | 304 // If we make it here, it means we have no displays and we should hand out the |
305 // default display. | 305 // default display. |
306 DCHECK_EQ(screen_win_displays_.size(), 0u); | 306 DCHECK_EQ(screen_win_displays_.size(), 0u); |
307 return ScreenWinDisplay(); | 307 return ScreenWinDisplay(); |
308 } | 308 } |
309 | 309 |
310 } // namespace win | 310 } // namespace win |
311 } // namespace display | 311 } // namespace display |
OLD | NEW |