Index: ui/gfx/screen_win.cc |
diff --git a/ui/gfx/screen_win.cc b/ui/gfx/screen_win.cc |
index 7dff9e90d8c686a899b75dfc1df303eb4f85d53b..f330f06555576b7ddb063b0f9ba5557482fb8e5c 100644 |
--- a/ui/gfx/screen_win.cc |
+++ b/ui/gfx/screen_win.cc |
@@ -24,7 +24,6 @@ MONITORINFOEX GetMonitorInfoForMonitor(HMONITOR monitor) { |
} |
gfx::Display GetDisplay(MONITORINFOEX& monitor_info) { |
- // TODO(oshima): Implement Observer. |
int64 id = static_cast<int64>( |
base::Hash(base::WideToUTF8(monitor_info.szDevice))); |
gfx::Rect bounds = gfx::Rect(monitor_info.rcMonitor); |
@@ -79,9 +78,12 @@ BOOL CALLBACK EnumMonitorCallback(HMONITOR monitor, |
namespace gfx { |
ScreenWin::ScreenWin() { |
+ displays_ = BuildDisplays(); |
sky
2014/07/22 17:41:18
Move to member initializer list.
mlamouri (slow - plz ping)
2014/07/22 17:52:50
Done.
|
+ SingletonHwnd::GetInstance()->AddObserver(this); |
} |
ScreenWin::~ScreenWin() { |
+ SingletonHwnd::GetInstance()->RemoveObserver(this); |
} |
bool ScreenWin::IsDIPEnabled() { |
@@ -111,10 +113,7 @@ int ScreenWin::GetNumDisplays() const { |
} |
std::vector<gfx::Display> ScreenWin::GetAllDisplays() const { |
- std::vector<gfx::Display> all_displays; |
- EnumDisplayMonitors(NULL, NULL, EnumMonitorCallback, |
- reinterpret_cast<LPARAM>(&all_displays)); |
- return all_displays; |
+ return displays_; |
} |
gfx::Display ScreenWin::GetDisplayNearestWindow(gfx::NativeView window) const { |
@@ -166,11 +165,24 @@ gfx::Display ScreenWin::GetPrimaryDisplay() const { |
} |
void ScreenWin::AddObserver(DisplayObserver* observer) { |
- // TODO(oshima): crbug.com/122863. |
+ change_notifier_.AddObserver(observer); |
} |
void ScreenWin::RemoveObserver(DisplayObserver* observer) { |
- // TODO(oshima): crbug.com/122863. |
+ change_notifier_.RemoveObserver(observer); |
+} |
+ |
+void ScreenWin::OnWndProc(HWND hwnd, |
+ UINT message, |
+ WPARAM wparam, |
+ LPARAM lparam) { |
+ if (message != WM_DISPLAYCHANGE) |
+ return; |
+ |
+ std::vector<gfx::Display> old_displays = displays_; |
+ displays_ = BuildDisplays(); |
+ |
+ change_notifier_.NotifyDisplaysChanged(old_displays, displays_); |
} |
HWND ScreenWin::GetHWNDFromNativeView(NativeView window) const { |
@@ -183,4 +195,11 @@ NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { |
return NULL; |
} |
+std::vector<gfx::Display> ScreenWin::BuildDisplays() const { |
sky
2014/07/22 17:41:18
Since this doesn't need anything from ScreenWin mo
mlamouri (slow - plz ping)
2014/07/22 17:52:51
Done.
|
+ std::vector<gfx::Display> all_displays; |
+ EnumDisplayMonitors(NULL, NULL, EnumMonitorCallback, |
+ reinterpret_cast<LPARAM>(&all_displays)); |
+ return all_displays; |
+} |
+ |
} // namespace gfx |