Revert of Output closure-compiled JavaScript files (patchset #10 id:180001 of https...
[chromium-blink-merge.git] / ui / gfx / display_change_notifier.cc
blob380c32ca9c3defa97f8c0992e815d88bf3256c5d
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/gfx/display_change_notifier.h"
7 #include "ui/gfx/display.h"
8 #include "ui/gfx/display_observer.h"
10 namespace gfx {
12 namespace {
14 class DisplayComparator {
15 public:
16 explicit DisplayComparator(const Display& display)
17 : display_id_(display.id())
20 bool operator()(const Display& display) const {
21 return display.id() == display_id_;
24 private:
25 int64 display_id_;
28 } // anonymous namespace
30 DisplayChangeNotifier::DisplayChangeNotifier() {
33 DisplayChangeNotifier::~DisplayChangeNotifier() {
36 void DisplayChangeNotifier::AddObserver(DisplayObserver* obs) {
37 observer_list_.AddObserver(obs);
40 void DisplayChangeNotifier::RemoveObserver(DisplayObserver* obs) {
41 observer_list_.RemoveObserver(obs);
44 void DisplayChangeNotifier::NotifyDisplaysChanged(
45 const std::vector<Display>& old_displays,
46 const std::vector<Display>& new_displays) {
47 // Display present in old_displays but not in new_displays has been removed.
48 std::vector<Display>::const_iterator old_it = old_displays.begin();
49 for (; old_it != old_displays.end(); ++old_it) {
50 if (std::find_if(new_displays.begin(), new_displays.end(),
51 DisplayComparator(*old_it)) == new_displays.end()) {
52 FOR_EACH_OBSERVER(DisplayObserver, observer_list_,
53 OnDisplayRemoved(*old_it));
57 // Display present in new_displays but not in old_displays has been added.
58 // Display present in both might have been modified.
59 for (std::vector<Display>::const_iterator new_it =
60 new_displays.begin(); new_it != new_displays.end(); ++new_it) {
61 std::vector<Display>::const_iterator old_it = std::find_if(
62 old_displays.begin(), old_displays.end(), DisplayComparator(*new_it));
64 if (old_it == old_displays.end()) {
65 FOR_EACH_OBSERVER(DisplayObserver, observer_list_,
66 OnDisplayAdded(*new_it));
67 continue;
70 uint32_t metrics = DisplayObserver::DISPLAY_METRIC_NONE;
72 if (new_it->bounds() != old_it->bounds())
73 metrics |= DisplayObserver::DISPLAY_METRIC_BOUNDS;
75 if (new_it->rotation() != old_it->rotation())
76 metrics |= DisplayObserver::DISPLAY_METRIC_ROTATION;
78 if (new_it->work_area() != old_it->work_area())
79 metrics |= DisplayObserver::DISPLAY_METRIC_WORK_AREA;
81 if (new_it->device_scale_factor() != old_it->device_scale_factor())
82 metrics |= DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR;
84 if (metrics != DisplayObserver::DISPLAY_METRIC_NONE) {
85 FOR_EACH_OBSERVER(DisplayObserver,
86 observer_list_,
87 OnDisplayMetricsChanged(*new_it, metrics));
92 } // namespace gfx