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 "ui/gfx/display.h" |
| 8 #include "ui/gfx/display_observer.h" |
| 9 |
| 10 namespace gfx { |
| 11 |
| 12 namespace { |
| 13 |
| 14 class DisplayComparator { |
| 15 public: |
| 16 explicit DisplayComparator(const Display& display) |
| 17 : display_id_(display.id()) |
| 18 {} |
| 19 |
| 20 bool operator()(const Display& display) const { |
| 21 return display.id() == display_id_; |
| 22 } |
| 23 |
| 24 private: |
| 25 int64 display_id_; |
| 26 }; |
| 27 |
| 28 } // anonymous namespace |
| 29 |
| 30 DisplayChangeNotifier::DisplayChangeNotifier() { |
| 31 } |
| 32 |
| 33 DisplayChangeNotifier::~DisplayChangeNotifier() { |
| 34 } |
| 35 |
| 36 void DisplayChangeNotifier::AddObserver(DisplayObserver* obs) { |
| 37 observer_list_.AddObserver(obs); |
| 38 } |
| 39 |
| 40 void DisplayChangeNotifier::RemoveObserver(DisplayObserver* obs) { |
| 41 observer_list_.RemoveObserver(obs); |
| 42 } |
| 43 |
| 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)); |
| 54 } |
| 55 } |
| 56 |
| 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)); |
| 63 |
| 64 if (old_it == old_displays.end()) { |
| 65 FOR_EACH_OBSERVER(DisplayObserver, observer_list_, |
| 66 OnDisplayAdded(*new_it)); |
| 67 continue; |
| 68 } |
| 69 |
| 70 uint32_t metrics = DisplayObserver::DISPLAY_METRIC_NONE; |
| 71 |
| 72 if (new_it->bounds() != old_it->bounds()) |
| 73 metrics |= DisplayObserver::DISPLAY_METRIC_BOUNDS; |
| 74 |
| 75 if (new_it->rotation() != old_it->rotation()) |
| 76 metrics |= DisplayObserver::DISPLAY_METRIC_ROTATION; |
| 77 |
| 78 if (new_it->work_area() != old_it->work_area()) |
| 79 metrics |= DisplayObserver::DISPLAY_METRIC_WORK_AREA; |
| 80 |
| 81 if (new_it->device_scale_factor() != old_it->device_scale_factor()) |
| 82 metrics |= DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; |
| 83 |
| 84 if (metrics != DisplayObserver::DISPLAY_METRIC_NONE) { |
| 85 FOR_EACH_OBSERVER(DisplayObserver, |
| 86 observer_list_, |
| 87 OnDisplayMetricsChanged(*new_it, metrics)); |
| 88 } |
| 89 } |
| 90 } |
| 91 |
| 92 } // namespace gfx |
OLD | NEW |