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

Side by Side Diff: ui/gfx/win/display_info.cc

Issue 1426933002: Refactor Windows DPI Point, Rect, and Size for Multiple Monitor DPI Awareness (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Other Unit Tests - Moved Inner Classes Outside 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/gfx/win/display_info.h"
6
7 #include "base/hash.h"
8 #include "base/strings/utf_string_conversions.h"
9
10 namespace {
11
12 gfx::Display::Rotation GetRotationForDevice(const wchar_t* device_name) {
13 DEVMODE mode;
14 ::ZeroMemory(&mode, sizeof(mode));
15 mode.dmSize = sizeof(DEVMODE);
16 mode.dmDriverExtra = 0;
17 if (::EnumDisplaySettings(device_name, ENUM_CURRENT_SETTINGS, &mode)) {
18 switch (mode.dmDisplayOrientation) {
19 case DMDO_DEFAULT:
20 return gfx::Display::ROTATE_0;
21 case DMDO_90:
22 return gfx::Display::ROTATE_90;
23 case DMDO_180:
24 return gfx::Display::ROTATE_180;
25 case DMDO_270:
26 return gfx::Display::ROTATE_270;
27 default:
28 NOTREACHED();
29 }
30 }
31 return gfx::Display::ROTATE_0;
32 }
33
34 } // namespace
35
36 namespace gfx {
37 namespace win {
38
39 int64_t DisplayInfo::HashDeviceName(const wchar_t* device_name) {
40 return static_cast<int64_t>(base::Hash(base::WideToUTF8(device_name)));
41 }
42
43 DisplayInfo::DisplayInfo(HMONITOR monitor, float device_scale_factor)
44 : device_scale_factor_(device_scale_factor){
45 MONITORINFOEX monitor_info;
46 ::ZeroMemory(&monitor_info, sizeof(monitor_info));
47 monitor_info.cbSize = sizeof(monitor_info);
48 ::GetMonitorInfo(monitor, &monitor_info);
49 InitializeFromMonitorInfo(monitor_info);
50 }
51
52 DisplayInfo::DisplayInfo(const MONITORINFOEX& monitor_info,
53 gfx::Display::Rotation rotation,
54 float device_scale_factor)
55 : rotation_(rotation),
56 device_scale_factor_(device_scale_factor) {
57 InitializeFromMonitorInfo(monitor_info);
58 }
59
60 int64_t DisplayInfo::id() const {
61 return id_;
62 }
63
64 gfx::Display::Rotation DisplayInfo::rotation() const {
65 return rotation_;
66 }
67
68 const gfx::Rect& DisplayInfo::screen_rect() const {
69 return screen_rect_;
70 }
71
72 const gfx::Rect& DisplayInfo::screen_work_rect() const {
73 return screen_work_rect_;
74 }
75
76 float DisplayInfo::device_scale_factor() const {
77 return device_scale_factor_;
78 }
79
80 void DisplayInfo::InitializeFromMonitorInfo(const MONITORINFOEX& monitor_info) {
81 id_ = HashDeviceName(monitor_info.szDevice);
82 screen_rect_ = gfx::Rect(monitor_info.rcMonitor);
83 screen_work_rect_ = gfx::Rect(monitor_info.rcWork);
84 rotation_ = GetRotationForDevice(monitor_info.szDevice);
85 }
86
87 } // namespace win
88 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698