| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/display/display_list.h" | 5 #include "ui/display/display_list.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "ui/display/display_observer.h" | 8 #include "ui/display/display_observer.h" |
| 9 | 9 |
| 10 namespace display { | 10 namespace display { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 if (local_display->rotation() != display.rotation()) { | 85 if (local_display->rotation() != display.rotation()) { |
| 86 local_display->set_rotation(display.rotation()); | 86 local_display->set_rotation(display.rotation()); |
| 87 changed_values |= display::DisplayObserver::DISPLAY_METRIC_ROTATION; | 87 changed_values |= display::DisplayObserver::DISPLAY_METRIC_ROTATION; |
| 88 } | 88 } |
| 89 if (local_display->device_scale_factor() != display.device_scale_factor()) { | 89 if (local_display->device_scale_factor() != display.device_scale_factor()) { |
| 90 local_display->set_device_scale_factor(display.device_scale_factor()); | 90 local_display->set_device_scale_factor(display.device_scale_factor()); |
| 91 changed_values |= | 91 changed_values |= |
| 92 display::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; | 92 display::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; |
| 93 } | 93 } |
| 94 if (should_notify_observers()) { | 94 if (should_notify_observers()) { |
| 95 FOR_EACH_OBSERVER(display::DisplayObserver, observers_, | 95 for (display::DisplayObserver& observer : observers_) |
| 96 OnDisplayMetricsChanged(*local_display, changed_values)); | 96 observer.OnDisplayMetricsChanged(*local_display, changed_values); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 void DisplayList::AddDisplay(const display::Display& display, Type type) { | 100 void DisplayList::AddDisplay(const display::Display& display, Type type) { |
| 101 DCHECK(displays_.end() == FindDisplayById(display.id())); | 101 DCHECK(displays_.end() == FindDisplayById(display.id())); |
| 102 displays_.push_back(display); | 102 displays_.push_back(display); |
| 103 if (type == Type::PRIMARY) | 103 if (type == Type::PRIMARY) |
| 104 primary_display_index_ = static_cast<int>(displays_.size()) - 1; | 104 primary_display_index_ = static_cast<int>(displays_.size()) - 1; |
| 105 if (should_notify_observers()) { | 105 if (should_notify_observers()) { |
| 106 FOR_EACH_OBSERVER(display::DisplayObserver, observers_, | 106 for (display::DisplayObserver& observer : observers_) |
| 107 OnDisplayAdded(display)); | 107 observer.OnDisplayAdded(display); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 void DisplayList::RemoveDisplay(int64_t id) { | 111 void DisplayList::RemoveDisplay(int64_t id) { |
| 112 auto iter = FindDisplayById(id); | 112 auto iter = FindDisplayById(id); |
| 113 DCHECK(displays_.end() != iter); | 113 DCHECK(displays_.end() != iter); |
| 114 if (primary_display_index_ == static_cast<int>(iter - displays_.begin())) { | 114 if (primary_display_index_ == static_cast<int>(iter - displays_.begin())) { |
| 115 // The primary display can only be removed if it is the last display. | 115 // The primary display can only be removed if it is the last display. |
| 116 // Users must choose a new primary before removing an old primary display. | 116 // Users must choose a new primary before removing an old primary display. |
| 117 DCHECK_EQ(1u, displays_.size()); | 117 DCHECK_EQ(1u, displays_.size()); |
| 118 primary_display_index_ = -1; | 118 primary_display_index_ = -1; |
| 119 } else if (primary_display_index_ > | 119 } else if (primary_display_index_ > |
| 120 static_cast<int>(iter - displays_.begin())) { | 120 static_cast<int>(iter - displays_.begin())) { |
| 121 primary_display_index_--; | 121 primary_display_index_--; |
| 122 } | 122 } |
| 123 const display::Display display = *iter; | 123 const display::Display display = *iter; |
| 124 displays_.erase(iter); | 124 displays_.erase(iter); |
| 125 if (should_notify_observers()) { | 125 if (should_notify_observers()) { |
| 126 FOR_EACH_OBSERVER(display::DisplayObserver, observers_, | 126 for (display::DisplayObserver& observer : observers_) |
| 127 OnDisplayRemoved(display)); | 127 observer.OnDisplayRemoved(display); |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 | 130 |
| 131 void DisplayList::IncrementObserverSuspendLockCount() { | 131 void DisplayList::IncrementObserverSuspendLockCount() { |
| 132 observer_suspend_lock_count_++; | 132 observer_suspend_lock_count_++; |
| 133 } | 133 } |
| 134 | 134 |
| 135 void DisplayList::DecrementObserverSuspendLockCount() { | 135 void DisplayList::DecrementObserverSuspendLockCount() { |
| 136 DCHECK_GT(observer_suspend_lock_count_, 0); | 136 DCHECK_GT(observer_suspend_lock_count_, 0); |
| 137 observer_suspend_lock_count_--; | 137 observer_suspend_lock_count_--; |
| 138 } | 138 } |
| 139 | 139 |
| 140 } // namespace display | 140 } // namespace display |
| OLD | NEW |