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