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

Side by Side Diff: ui/gfx/screen_win.cc

Issue 1563183008: Added capability on Windows to get the physical dimensions of your attached monitors. Also added th… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments 2 Created 4 years, 11 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 #include "ui/gfx/screen_win.h" 5 #include "ui/gfx/screen_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <stdint.h>
9 8
10 #include "base/bind.h" 9 #include "base/bind.h"
11 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
12 #include "base/hash.h" 11 #include "base/hash.h"
13 #include "base/logging.h" 12 #include "base/logging.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "base/win/win_util.h" 14 #include "base/win/win_util.h"
16 #include "ui/gfx/display.h" 15 #include "ui/gfx/display.h"
17 #include "ui/gfx/win/dpi.h" 16 #include "ui/gfx/win/dpi.h"
17 #include "ui/gfx/win/physical_size.h"
18 18
19 namespace { 19 namespace {
20 20
21 MONITORINFOEX GetMonitorInfoForMonitor(HMONITOR monitor) { 21 MONITORINFOEX GetMonitorInfoForMonitor(HMONITOR monitor) {
22 MONITORINFOEX monitor_info; 22 MONITORINFOEX monitor_info;
23 ZeroMemory(&monitor_info, sizeof(MONITORINFOEX)); 23 ZeroMemory(&monitor_info, sizeof(MONITORINFOEX));
24 monitor_info.cbSize = sizeof(monitor_info); 24 monitor_info.cbSize = sizeof(monitor_info);
25 GetMonitorInfo(monitor, &monitor_info); 25 GetMonitorInfo(monitor, &monitor_info);
26 return monitor_info; 26 return monitor_info;
27 } 27 }
28 28
29 int64_t GenerateDisplayId(const std::string& str) {
30 return static_cast<int64_t>(base::Hash(str));
31 }
32
29 gfx::Display GetDisplay(const MONITORINFOEX& monitor_info) { 33 gfx::Display GetDisplay(const MONITORINFOEX& monitor_info) {
30 int64_t id = 34 int64_t id = GenerateDisplayId(base::WideToUTF8(monitor_info.szDevice));
31 static_cast<int64_t>(base::Hash(base::WideToUTF8(monitor_info.szDevice)));
32 gfx::Rect bounds = gfx::Rect(monitor_info.rcMonitor); 35 gfx::Rect bounds = gfx::Rect(monitor_info.rcMonitor);
33 gfx::Display display(id); 36 gfx::Display display(id);
34 display.set_bounds(gfx::win::ScreenToDIPRect(bounds)); 37 display.set_bounds(gfx::win::ScreenToDIPRect(bounds));
35 display.set_work_area( 38 display.set_work_area(
36 gfx::win::ScreenToDIPRect(gfx::Rect(monitor_info.rcWork))); 39 gfx::win::ScreenToDIPRect(gfx::Rect(monitor_info.rcWork)));
37 display.SetScaleAndBounds(gfx::GetDPIScale(), bounds); 40 display.SetScaleAndBounds(gfx::GetDPIScale(), bounds);
38 41
42 int width_mm = 0;
43 int height_mm = 0;
44 std::vector<gfx::PhysicalDisplaySize> display_sizes =
45 gfx::GetPhysicalSizeForDisplays();
46 for (const auto& display_size : display_sizes) {
47 int64_t interface_id = GenerateDisplayId(display_size.display_name);
48 if (interface_id == id) {
49 width_mm = display_size.width_mm;
50 height_mm = display_size.height_mm;
51 }
52 }
53 display.SetPhysicalSize(width_mm, height_mm);
54
39 DEVMODE mode; 55 DEVMODE mode;
40 memset(&mode, 0, sizeof(DEVMODE)); 56 memset(&mode, 0, sizeof(DEVMODE));
41 mode.dmSize = sizeof(DEVMODE); 57 mode.dmSize = sizeof(DEVMODE);
42 mode.dmDriverExtra = 0; 58 mode.dmDriverExtra = 0;
43 if (EnumDisplaySettings(monitor_info.szDevice, 59 if (EnumDisplaySettings(monitor_info.szDevice,
44 ENUM_CURRENT_SETTINGS, 60 ENUM_CURRENT_SETTINGS,
45 &mode)) { 61 &mode)) {
46 switch (mode.dmDisplayOrientation) { 62 switch (mode.dmDisplayOrientation) {
47 case DMDO_DEFAULT: 63 case DMDO_DEFAULT:
48 display.set_rotation(gfx::Display::ROTATE_0); 64 display.set_rotation(gfx::Display::ROTATE_0);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 std::vector<gfx::Display> ScreenWin::GetDisplaysForMonitorInfos( 223 std::vector<gfx::Display> ScreenWin::GetDisplaysForMonitorInfos(
208 const std::vector<MONITORINFOEX>& monitor_infos) { 224 const std::vector<MONITORINFOEX>& monitor_infos) {
209 std::vector<gfx::Display> displays; 225 std::vector<gfx::Display> displays;
210 for (const MONITORINFOEX& monitor_info : monitor_infos) 226 for (const MONITORINFOEX& monitor_info : monitor_infos)
211 displays.push_back(GetDisplay(monitor_info)); 227 displays.push_back(GetDisplay(monitor_info));
212 228
213 return displays; 229 return displays;
214 } 230 }
215 231
216 } // namespace gfx 232 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698