Index: ui/gfx/display_change_notifier.cc |
diff --git a/ui/gfx/display_change_notifier.cc b/ui/gfx/display_change_notifier.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2fa73cf383f90b650cdc256ac378a109931cc0c1 |
--- /dev/null |
+++ b/ui/gfx/display_change_notifier.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/display_change_notifier.h" |
+ |
+#include "ui/gfx/display.h" |
+ |
+DisplayChangeNotifier::DisplayChangeNotifier() { |
+} |
+ |
+DisplayChangeNotifier::~DisplayChangeNotifier() { |
+} |
+ |
+void DisplayChangeNotifier::AddObserver(gfx::DisplayObserver* obs) { |
+ observer_list_.AddObserver(obs); |
+} |
+ |
+void DisplayChangeNotifier::RemoveObserver(gfx::DisplayObserver* obs) { |
+ observer_list_.RemoveObserver(obs); |
+} |
+ |
+void DisplayChangeNotifier::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; |
+ 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)); |
+ } |
+ } |
+} |