Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / extensions / display_info_provider_win.cc
blob8ddfbc075070c52971a354a41f92a72160562487
1 // Copyright 2014 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.
5 #include "chrome/browser/extensions/display_info_provider_win.h"
7 #include <windows.h>
9 #include "base/hash.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "base/win/win_util.h"
13 #include "extensions/common/api/system_display.h"
14 #include "ui/gfx/geometry/size.h"
15 #include "ui/gfx/screen.h"
16 #include "ui/gfx/win/dpi.h"
18 namespace extensions {
20 using api::system_display::DisplayUnitInfo;
22 namespace {
24 BOOL CALLBACK
25 EnumMonitorCallback(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data) {
26 DisplayInfo* all_displays = reinterpret_cast<DisplayInfo*>(data);
27 DCHECK(all_displays);
29 linked_ptr<DisplayUnitInfo> unit(new DisplayUnitInfo);
31 MONITORINFOEX monitor_info;
32 ZeroMemory(&monitor_info, sizeof(MONITORINFOEX));
33 monitor_info.cbSize = sizeof(monitor_info);
34 GetMonitorInfo(monitor, &monitor_info);
36 DISPLAY_DEVICE device;
37 device.cb = sizeof(device);
38 if (!EnumDisplayDevices(monitor_info.szDevice, 0, &device, 0))
39 return FALSE;
41 gfx::Size dpi(gfx::GetDPI());
42 unit->id =
43 base::Int64ToString(base::Hash(base::WideToUTF8(monitor_info.szDevice)));
44 unit->name = base::WideToUTF8(device.DeviceString);
45 unit->dpi_x = dpi.width();
46 unit->dpi_y = dpi.height();
47 all_displays->push_back(unit);
49 return TRUE;
52 } // namespace
54 DisplayInfoProviderWin::DisplayInfoProviderWin() {
57 DisplayInfoProviderWin::~DisplayInfoProviderWin() {
60 bool DisplayInfoProviderWin::SetInfo(
61 const std::string& display_id,
62 const api::system_display::DisplayProperties& info,
63 std::string* error) {
64 *error = "Not implemented";
65 return false;
68 void DisplayInfoProviderWin::UpdateDisplayUnitInfoForPlatform(
69 const gfx::Display& display,
70 extensions::api::system_display::DisplayUnitInfo* unit) {
71 DisplayInfo all_displays;
72 EnumDisplayMonitors(
73 NULL, NULL, EnumMonitorCallback, reinterpret_cast<LPARAM>(&all_displays));
74 for (size_t i = 0; i < all_displays.size(); ++i) {
75 if (unit->id == all_displays[i]->id) {
76 unit->name = all_displays[i]->name;
77 unit->dpi_x = all_displays[i]->dpi_x;
78 unit->dpi_y = all_displays[i]->dpi_y;
79 break;
84 gfx::Screen* DisplayInfoProviderWin::GetActiveScreen() {
85 // TODO(scottmg): native screen is wrong http://crbug.com/133312
86 return gfx::Screen::GetNativeScreen();
89 // static
90 DisplayInfoProvider* DisplayInfoProvider::Create() {
91 return new DisplayInfoProviderWin();
94 } // namespace extensions