Add exclamation and question mark to the accent keys.
[chromium-blink-merge.git] / ui / gfx / screen_win.cc
blob06c14bd173283af2cfa8add19013848cc6a3e2c1
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
3 // found in the LICENSE file.
5 #include "ui/gfx/screen_win.h"
7 #include <windows.h>
9 #include "base/logging.h"
10 #include "ui/base/win/dpi.h"
11 #include "ui/gfx/display.h"
13 namespace {
15 MONITORINFO GetMonitorInfoForMonitor(HMONITOR monitor) {
16 MONITORINFO monitor_info = { 0 };
17 monitor_info.cbSize = sizeof(monitor_info);
18 GetMonitorInfo(monitor, &monitor_info);
19 return monitor_info;
22 gfx::Display GetDisplay(MONITORINFO& monitor_info) {
23 // TODO(oshima): Implement ID and Observer.
24 gfx::Rect bounds = gfx::Rect(monitor_info.rcMonitor);
25 gfx::Display display(0, bounds);
26 display.set_work_area(gfx::Rect(monitor_info.rcWork));
27 display.SetScaleAndBounds(ui::win::GetDeviceScaleFactor(), bounds);
28 return display;
31 } // namespace
33 namespace gfx {
35 ScreenWin::ScreenWin() {
38 ScreenWin::~ScreenWin() {
41 bool ScreenWin::IsDIPEnabled() {
42 return ui::IsInHighDPIMode();
45 gfx::Point ScreenWin::GetCursorScreenPoint() {
46 POINT pt;
47 GetCursorPos(&pt);
48 return gfx::Point(pt);
51 gfx::NativeWindow ScreenWin::GetWindowAtCursorScreenPoint() {
52 POINT location;
53 HWND window_hwnd = GetCursorPos(&location) ? WindowFromPoint(location) : NULL;
54 return GetNativeWindowFromHWND(window_hwnd);
57 int ScreenWin::GetNumDisplays() {
58 return GetSystemMetrics(SM_CMONITORS);
61 gfx::Display ScreenWin::GetDisplayNearestWindow(gfx::NativeView window) const {
62 HWND window_hwnd = GetHWNDFromNativeView(window);
63 if (!window_hwnd) {
64 // When |window| isn't rooted to a display, we should just return the
65 // default display so we get some correct display information like the
66 // scaling factor.
67 return GetPrimaryDisplay();
70 MONITORINFO monitor_info;
71 monitor_info.cbSize = sizeof(monitor_info);
72 GetMonitorInfo(MonitorFromWindow(window_hwnd, MONITOR_DEFAULTTONEAREST),
73 &monitor_info);
74 return GetDisplay(monitor_info);
77 gfx::Display ScreenWin::GetDisplayNearestPoint(const gfx::Point& point) const {
78 POINT initial_loc = { point.x(), point.y() };
79 HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST);
80 MONITORINFO mi = {0};
81 mi.cbSize = sizeof(mi);
82 if (monitor && GetMonitorInfo(monitor, &mi))
83 return GetDisplay(mi);
84 return gfx::Display();
87 gfx::Display ScreenWin::GetDisplayMatching(const gfx::Rect& match_rect) const {
88 RECT other_bounds_rect = match_rect.ToRECT();
89 MONITORINFO monitor_info = GetMonitorInfoForMonitor(MonitorFromRect(
90 &other_bounds_rect, MONITOR_DEFAULTTONEAREST));
91 return GetDisplay(monitor_info);
94 gfx::Display ScreenWin::GetPrimaryDisplay() const {
95 MONITORINFO mi = GetMonitorInfoForMonitor(
96 MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY));
97 gfx::Display display = GetDisplay(mi);
98 // TODO(kevers|girard): Test if these checks can be reintroduced for high-DIP
99 // once more of the app is DIP-aware.
100 if (!ui::IsInHighDPIMode()) {
101 DCHECK_EQ(GetSystemMetrics(SM_CXSCREEN), display.size().width());
102 DCHECK_EQ(GetSystemMetrics(SM_CYSCREEN), display.size().height());
104 return display;
107 void ScreenWin::AddObserver(DisplayObserver* observer) {
108 // TODO(oshima): crbug.com/122863.
111 void ScreenWin::RemoveObserver(DisplayObserver* observer) {
112 // TODO(oshima): crbug.com/122863.
115 HWND ScreenWin::GetHWNDFromNativeView(NativeView window) const {
116 #if defined(USE_AURA)
117 NOTREACHED();
118 return NULL;
119 #else
120 return window;
121 #endif // USE_AURA
124 NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const {
125 #if defined(USE_AURA)
126 NOTREACHED();
127 return NULL;
128 #else
129 return hwnd;
130 #endif // USE_AURA
133 #if !defined(USE_AURA)
134 Screen* CreateNativeScreen() {
135 return new ScreenWin;
137 #endif // !USE_AURA
139 } // namespace gfx