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

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: 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..a115a104752411eb7d0858c9b181717b75789d8e 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);
@@ -74,14 +73,24 @@ BOOL CALLBACK EnumMonitorCallback(HMONITOR monitor,
return TRUE;
}
+std::vector<gfx::Display> GetDisplays() {
+ std::vector<gfx::Display> displays;
+ EnumDisplayMonitors(NULL, NULL, EnumMonitorCallback,
+ reinterpret_cast<LPARAM>(&displays));
+ return displays;
+}
+
} // namespace
namespace gfx {
-ScreenWin::ScreenWin() {
+ScreenWin::ScreenWin()
+ : displays_(GetDisplays()) {
+ SingletonHwnd::GetInstance()->AddObserver(this);
}
ScreenWin::~ScreenWin() {
+ SingletonHwnd::GetInstance()->RemoveObserver(this);
}
bool ScreenWin::IsDIPEnabled() {
@@ -111,10 +120,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 +172,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_ = GetDisplays();
+
+ change_notifier_.NotifyDisplaysChanged(old_displays, displays_);
}
HWND ScreenWin::GetHWNDFromNativeView(NativeView window) const {
« 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