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

Unified Diff: ui/gfx/screen_win.cc

Issue 401313003: ScreenWin notifies DisplayObserver's when displays changed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sky review comments Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/screen_win.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « ui/gfx/screen_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698