| 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/gfx/screen_win.h" | 5 #include "ui/gfx/screen_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" |
| 9 #include "base/hash.h" | 11 #include "base/hash.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/win/win_util.h" | 14 #include "base/win/win_util.h" |
| 13 #include "ui/gfx/display.h" | 15 #include "ui/gfx/display.h" |
| 14 #include "ui/gfx/win/dpi.h" | 16 #include "ui/gfx/win/dpi.h" |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 MONITORINFOEX GetMonitorInfoForMonitor(HMONITOR monitor) { | 20 MONITORINFOEX GetMonitorInfoForMonitor(HMONITOR monitor) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 reinterpret_cast<LPARAM>(&displays)); | 81 reinterpret_cast<LPARAM>(&displays)); |
| 80 return displays; | 82 return displays; |
| 81 } | 83 } |
| 82 | 84 |
| 83 } // namespace | 85 } // namespace |
| 84 | 86 |
| 85 namespace gfx { | 87 namespace gfx { |
| 86 | 88 |
| 87 ScreenWin::ScreenWin() | 89 ScreenWin::ScreenWin() |
| 88 : displays_(GetDisplays()) { | 90 : displays_(GetDisplays()) { |
| 89 SingletonHwnd::GetInstance()->AddObserver(this); | 91 singletonHwndObserver_.SetWndProc( |
| 92 base::Bind(&ScreenWin::OnDisplayChange, base::Unretained(this))); |
| 90 } | 93 } |
| 91 | 94 |
| 92 ScreenWin::~ScreenWin() { | 95 ScreenWin::~ScreenWin() {} |
| 93 SingletonHwnd::GetInstance()->RemoveObserver(this); | |
| 94 } | |
| 95 | 96 |
| 96 gfx::Point ScreenWin::GetCursorScreenPoint() { | 97 gfx::Point ScreenWin::GetCursorScreenPoint() { |
| 97 POINT pt; | 98 POINT pt; |
| 98 GetCursorPos(&pt); | 99 GetCursorPos(&pt); |
| 99 gfx::Point cursor_pos_pixels(pt); | 100 gfx::Point cursor_pos_pixels(pt); |
| 100 return gfx::win::ScreenToDIPPoint(cursor_pos_pixels); | 101 return gfx::win::ScreenToDIPPoint(cursor_pos_pixels); |
| 101 } | 102 } |
| 102 | 103 |
| 103 gfx::NativeWindow ScreenWin::GetWindowUnderCursor() { | 104 gfx::NativeWindow ScreenWin::GetWindowUnderCursor() { |
| 104 POINT cursor_loc; | 105 POINT cursor_loc; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } | 170 } |
| 170 | 171 |
| 171 void ScreenWin::AddObserver(DisplayObserver* observer) { | 172 void ScreenWin::AddObserver(DisplayObserver* observer) { |
| 172 change_notifier_.AddObserver(observer); | 173 change_notifier_.AddObserver(observer); |
| 173 } | 174 } |
| 174 | 175 |
| 175 void ScreenWin::RemoveObserver(DisplayObserver* observer) { | 176 void ScreenWin::RemoveObserver(DisplayObserver* observer) { |
| 176 change_notifier_.RemoveObserver(observer); | 177 change_notifier_.RemoveObserver(observer); |
| 177 } | 178 } |
| 178 | 179 |
| 179 void ScreenWin::OnWndProc(HWND hwnd, | 180 void ScreenWin::OnDisplayChange(HWND hwnd, |
| 180 UINT message, | 181 UINT message, |
| 181 WPARAM wparam, | 182 WPARAM wparam, |
| 182 LPARAM lparam) { | 183 LPARAM lparam) { |
| 183 if (message != WM_DISPLAYCHANGE) | 184 if (message != WM_DISPLAYCHANGE) |
| 184 return; | 185 return; |
| 185 | 186 |
| 186 std::vector<gfx::Display> old_displays = displays_; | 187 std::vector<gfx::Display> old_displays = displays_; |
| 187 displays_ = GetDisplays(); | 188 displays_ = GetDisplays(); |
| 188 | 189 |
| 189 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); | 190 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); |
| 190 } | 191 } |
| 191 | 192 |
| 192 HWND ScreenWin::GetHWNDFromNativeView(NativeView window) const { | 193 HWND ScreenWin::GetHWNDFromNativeView(NativeView window) const { |
| 193 NOTREACHED(); | 194 NOTREACHED(); |
| 194 return NULL; | 195 return NULL; |
| 195 } | 196 } |
| 196 | 197 |
| 197 NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { | 198 NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { |
| 198 NOTREACHED(); | 199 NOTREACHED(); |
| 199 return NULL; | 200 return NULL; |
| 200 } | 201 } |
| 201 | 202 |
| 202 } // namespace gfx | 203 } // namespace gfx |
| OLD | NEW |