OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "ui/gfx/display_change_notifier.h" | |
6 | |
7 #include <stdint.h> | |
8 | |
9 #include "ui/gfx/display.h" | |
10 #include "ui/gfx/display_observer.h" | |
11 | |
12 namespace gfx { | |
13 | |
14 namespace { | |
15 | |
16 class DisplayComparator { | |
17 public: | |
18 explicit DisplayComparator(const Display& display) | |
19 : display_id_(display.id()) | |
20 {} | |
21 | |
22 bool operator()(const Display& display) const { | |
23 return display.id() == display_id_; | |
24 } | |
25 | |
26 private: | |
27 int64_t display_id_; | |
28 }; | |
29 | |
30 } // anonymous namespace | |
31 | |
32 DisplayChangeNotifier::DisplayChangeNotifier() { | |
33 } | |
34 | |
35 DisplayChangeNotifier::~DisplayChangeNotifier() { | |
36 } | |
37 | |
38 void DisplayChangeNotifier::AddObserver(DisplayObserver* obs) { | |
39 observer_list_.AddObserver(obs); | |
40 } | |
41 | |
42 void DisplayChangeNotifier::RemoveObserver(DisplayObserver* obs) { | |
43 observer_list_.RemoveObserver(obs); | |
44 } | |
45 | |
46 void DisplayChangeNotifier::NotifyDisplaysChanged( | |
47 const std::vector<Display>& old_displays, | |
48 const std::vector<Display>& new_displays) { | |
49 // Display present in old_displays but not in new_displays has been removed. | |
50 std::vector<Display>::const_iterator old_it = old_displays.begin(); | |
51 for (; old_it != old_displays.end(); ++old_it) { | |
52 if (std::find_if(new_displays.begin(), new_displays.end(), | |
53 DisplayComparator(*old_it)) == new_displays.end()) { | |
54 FOR_EACH_OBSERVER(DisplayObserver, observer_list_, | |
55 OnDisplayRemoved(*old_it)); | |
56 } | |
57 } | |
58 | |
59 // Display present in new_displays but not in old_displays has been added. | |
60 // Display present in both might have been modified. | |
61 for (std::vector<Display>::const_iterator new_it = | |
62 new_displays.begin(); new_it != new_displays.end(); ++new_it) { | |
63 std::vector<Display>::const_iterator old_it = std::find_if( | |
64 old_displays.begin(), old_displays.end(), DisplayComparator(*new_it)); | |
65 | |
66 if (old_it == old_displays.end()) { | |
67 FOR_EACH_OBSERVER(DisplayObserver, observer_list_, | |
68 OnDisplayAdded(*new_it)); | |
69 continue; | |
70 } | |
71 | |
72 uint32_t metrics = DisplayObserver::DISPLAY_METRIC_NONE; | |
73 | |
74 if (new_it->bounds() != old_it->bounds()) | |
75 metrics |= DisplayObserver::DISPLAY_METRIC_BOUNDS; | |
76 | |
77 if (new_it->rotation() != old_it->rotation()) | |
78 metrics |= DisplayObserver::DISPLAY_METRIC_ROTATION; | |
79 | |
80 if (new_it->work_area() != old_it->work_area()) | |
81 metrics |= DisplayObserver::DISPLAY_METRIC_WORK_AREA; | |
82 | |
83 if (new_it->device_scale_factor() != old_it->device_scale_factor()) | |
84 metrics |= DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; | |
85 | |
86 if (metrics != DisplayObserver::DISPLAY_METRIC_NONE) { | |
87 FOR_EACH_OBSERVER(DisplayObserver, | |
88 observer_list_, | |
89 OnDisplayMetricsChanged(*new_it, metrics)); | |
90 } | |
91 } | |
92 } | |
93 | |
94 } // namespace gfx | |
OLD | NEW |