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

Unified Diff: ui/gfx/screen_display_observer_delegate.cc

Issue 341983008: Listen to Display reconfiguration and notify DisplayObservers on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mac_display
Patch Set: plug to RWHVMac Created 6 years, 6 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
Index: ui/gfx/screen_display_observer_delegate.cc
diff --git a/ui/gfx/screen_display_observer_delegate.cc b/ui/gfx/screen_display_observer_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4fc388e1bd70c88abe439741f6933ab3074129a1
--- /dev/null
+++ b/ui/gfx/screen_display_observer_delegate.cc
@@ -0,0 +1,81 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/screen_display_observer_delegate.h"
+
+#include "ui/gfx/display.h"
+
+ScreenDisplayObserverDelegate::ScreenDisplayObserverDelegate() {
+}
+
+ScreenDisplayObserverDelegate::~ScreenDisplayObserverDelegate() {
+}
+
+void ScreenDisplayObserverDelegate::AddObserver(gfx::DisplayObserver* obs) {
+ observer_list_.AddObserver(obs);
+}
+
+void ScreenDisplayObserverDelegate::RemoveObserver(gfx::DisplayObserver* obs) {
+ observer_list_.RemoveObserver(obs);
+}
+
+void ScreenDisplayObserverDelegate::NotifyDisplaysChanged(
+ const std::vector<gfx::Display>& old_displays,
+ const std::vector<gfx::Display>& new_displays) {
+ typedef std::vector<gfx::Display>::const_iterator DisplayIt;
+ std::vector<gfx::Display>::const_iterator old_it = old_displays.begin();
+ for (; old_it != old_displays.end(); ++old_it) {
+ bool found = false;
oshima 2014/07/09 17:12:51 can you use std::find_if ? I usualyl prefer loop o
mlamouri (slow - plz ping) 2014/07/10 12:54:34 Unfortunately, std::find() will compare the items
oshima 2014/07/10 18:11:58 Yes, I meant std:find_if (sorry I mentioned find_i
+ for (std::vector<gfx::Display>::const_iterator new_it =
+ new_displays.begin(); new_it != new_displays.end(); ++new_it) {
+ if (old_it->id() == new_it->id()) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ FOR_EACH_OBSERVER(gfx::DisplayObserver, observer_list_,
+ OnDisplayRemoved(*old_it));
+ }
+ }
+
+ for (std::vector<gfx::Display>::const_iterator new_it =
+ new_displays.begin(); new_it != new_displays.end(); ++new_it) {
+ bool found = false;
+ for (std::vector<gfx::Display>::const_iterator old_it =
+ old_displays.begin(); old_it != old_displays.end(); ++old_it) {
+ if (new_it->id() != old_it->id())
+ continue;
+
+ uint32_t metrics = gfx::DisplayObserver::DISPLAY_METRIC_NONE;
+
+ if (new_it->bounds() != old_it->bounds())
+ metrics |= gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS;
+
+ if (new_it->rotation() != old_it->rotation())
+ metrics |= gfx::DisplayObserver::DISPLAY_METRIC_ROTATION;
+
+ if (new_it->work_area() != old_it->work_area())
+ metrics |= gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA;
+
+ if (new_it->device_scale_factor() != old_it->device_scale_factor())
+ metrics |= gfx::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR;
+
+ if (metrics != gfx::DisplayObserver::DISPLAY_METRIC_NONE) {
+ FOR_EACH_OBSERVER(gfx::DisplayObserver,
+ observer_list_,
+ OnDisplayMetricsChanged(*new_it, metrics));
+ }
+
+ found = true;
+ break;
+ }
+
+ if (!found) {
+ FOR_EACH_OBSERVER(gfx::DisplayObserver, observer_list_,
+ OnDisplayAdded(*new_it));
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698