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

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

Issue 1092183005: Fix Up SingletonHwnd Observer Lifetime Issues (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Convert to scoped_ptr Created 5 years, 7 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 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 EnumDisplayMonitors(NULL, NULL, EnumMonitorCallback, 80 EnumDisplayMonitors(NULL, NULL, EnumMonitorCallback,
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 singleton_hwnd_observer_(new SingletonHwndObserver(
90 } 92 base::Bind(&ScreenWin::OnDisplayChange, base::Unretained(this)))) {}
91 93
92 ScreenWin::~ScreenWin() { 94 ScreenWin::~ScreenWin() {}
93 SingletonHwnd::GetInstance()->RemoveObserver(this);
94 }
95 95
96 gfx::Point ScreenWin::GetCursorScreenPoint() { 96 gfx::Point ScreenWin::GetCursorScreenPoint() {
97 POINT pt; 97 POINT pt;
98 GetCursorPos(&pt); 98 GetCursorPos(&pt);
99 gfx::Point cursor_pos_pixels(pt); 99 gfx::Point cursor_pos_pixels(pt);
100 return gfx::win::ScreenToDIPPoint(cursor_pos_pixels); 100 return gfx::win::ScreenToDIPPoint(cursor_pos_pixels);
101 } 101 }
102 102
103 gfx::NativeWindow ScreenWin::GetWindowUnderCursor() { 103 gfx::NativeWindow ScreenWin::GetWindowUnderCursor() {
104 POINT cursor_loc; 104 POINT cursor_loc;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 169 }
170 170
171 void ScreenWin::AddObserver(DisplayObserver* observer) { 171 void ScreenWin::AddObserver(DisplayObserver* observer) {
172 change_notifier_.AddObserver(observer); 172 change_notifier_.AddObserver(observer);
173 } 173 }
174 174
175 void ScreenWin::RemoveObserver(DisplayObserver* observer) { 175 void ScreenWin::RemoveObserver(DisplayObserver* observer) {
176 change_notifier_.RemoveObserver(observer); 176 change_notifier_.RemoveObserver(observer);
177 } 177 }
178 178
179 void ScreenWin::OnWndProc(HWND hwnd, 179 void ScreenWin::OnDisplayChange(HWND hwnd,
180 UINT message, 180 UINT message,
181 WPARAM wparam, 181 WPARAM wparam,
182 LPARAM lparam) { 182 LPARAM lparam) {
183 if (message != WM_DISPLAYCHANGE) 183 if (message != WM_DISPLAYCHANGE)
184 return; 184 return;
185 185
186 std::vector<gfx::Display> old_displays = displays_; 186 std::vector<gfx::Display> old_displays = displays_;
187 displays_ = GetDisplays(); 187 displays_ = GetDisplays();
188 188
189 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); 189 change_notifier_.NotifyDisplaysChanged(old_displays, displays_);
190 } 190 }
191 191
192 HWND ScreenWin::GetHWNDFromNativeView(NativeView window) const { 192 HWND ScreenWin::GetHWNDFromNativeView(NativeView window) const {
193 NOTREACHED(); 193 NOTREACHED();
194 return NULL; 194 return NULL;
195 } 195 }
196 196
197 NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { 197 NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const {
198 NOTREACHED(); 198 NOTREACHED();
199 return NULL; 199 return NULL;
200 } 200 }
201 201
202 } // namespace gfx 202 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698