| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/views/mus/display_list.h" |
| 6 |
| 7 #include "ui/display/display_finder.h" |
| 8 #include "ui/display/display_observer.h" |
| 9 |
| 10 namespace views { |
| 11 |
| 12 DisplayList::DisplayList() {} |
| 13 |
| 14 DisplayList::~DisplayList() {} |
| 15 |
| 16 void DisplayList::AddObserver(display::DisplayObserver* observer) { |
| 17 observers_.AddObserver(observer); |
| 18 } |
| 19 |
| 20 void DisplayList::RemoveObserver(display::DisplayObserver* observer) { |
| 21 observers_.RemoveObserver(observer); |
| 22 } |
| 23 |
| 24 DisplayList::Displays::const_iterator DisplayList::FindDisplayById( |
| 25 int64_t id) const { |
| 26 for (auto iter = displays_.begin(); iter != displays_.end(); ++iter) { |
| 27 if (iter->id() == id) |
| 28 return iter; |
| 29 } |
| 30 return displays_.end(); |
| 31 } |
| 32 |
| 33 DisplayList::Displays::iterator DisplayList::FindDisplayById(int64_t id) { |
| 34 for (auto iter = displays_.begin(); iter != displays_.end(); ++iter) { |
| 35 if (iter->id() == id) |
| 36 return iter; |
| 37 } |
| 38 return displays_.end(); |
| 39 } |
| 40 |
| 41 DisplayList::Displays::const_iterator DisplayList::GetPrimaryDisplayIterator() |
| 42 const { |
| 43 return primary_display_index_ == -1 |
| 44 ? displays_.end() |
| 45 : displays_.begin() + primary_display_index_; |
| 46 } |
| 47 |
| 48 void DisplayList::UpdateDisplay(const display::Display& display, Type type) { |
| 49 auto iter = FindDisplayById(display.id()); |
| 50 DCHECK(iter != displays_.end()); |
| 51 |
| 52 display::Display* local_display = &(*iter); |
| 53 uint32_t changed_values = 0; |
| 54 if (type == Type::PRIMARY && |
| 55 static_cast<int>(iter - displays_.begin()) != |
| 56 static_cast<int>(GetPrimaryDisplayIterator() - displays_.begin())) { |
| 57 primary_display_index_ = static_cast<int>(iter - displays_.begin()); |
| 58 // ash::DisplayManager only notifies for the Display gaining primary, not |
| 59 // the one losing it. |
| 60 changed_values |= display::DisplayObserver::DISPLAY_METRIC_PRIMARY; |
| 61 } |
| 62 if (local_display->bounds() != display.bounds()) { |
| 63 local_display->set_bounds(display.bounds()); |
| 64 changed_values |= display::DisplayObserver::DISPLAY_METRIC_BOUNDS; |
| 65 } |
| 66 if (local_display->work_area() != display.work_area()) { |
| 67 local_display->set_work_area(display.work_area()); |
| 68 changed_values |= display::DisplayObserver::DISPLAY_METRIC_WORK_AREA; |
| 69 } |
| 70 if (local_display->rotation() != display.rotation()) { |
| 71 local_display->set_rotation(display.rotation()); |
| 72 changed_values |= display::DisplayObserver::DISPLAY_METRIC_ROTATION; |
| 73 } |
| 74 if (local_display->device_scale_factor() != display.device_scale_factor()) { |
| 75 local_display->set_device_scale_factor(display.device_scale_factor()); |
| 76 changed_values |= |
| 77 display::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; |
| 78 } |
| 79 FOR_EACH_OBSERVER(display::DisplayObserver, observers_, |
| 80 OnDisplayMetricsChanged(*local_display, changed_values)); |
| 81 } |
| 82 |
| 83 void DisplayList::AddDisplay(const display::Display& display, Type type) { |
| 84 DCHECK(displays_.end() == FindDisplayById(display.id())); |
| 85 displays_.push_back(display); |
| 86 if (type == Type::PRIMARY) |
| 87 primary_display_index_ = static_cast<int>(displays_.size()) - 1; |
| 88 FOR_EACH_OBSERVER(display::DisplayObserver, observers_, |
| 89 OnDisplayAdded(display)); |
| 90 } |
| 91 |
| 92 void DisplayList::RemoveDisplay(int64_t id) { |
| 93 auto iter = FindDisplayById(id); |
| 94 DCHECK(displays_.end() != iter); |
| 95 if (primary_display_index_ == static_cast<int>(iter - displays_.begin())) { |
| 96 // We expect the primary to change before removing it. The only case we |
| 97 // allow removal of the primary is if it is the list display. |
| 98 DCHECK_EQ(1u, displays_.size()); |
| 99 primary_display_index_ = -1; |
| 100 } else if (primary_display_index_ > |
| 101 static_cast<int>(iter - displays_.begin())) { |
| 102 primary_display_index_--; |
| 103 } |
| 104 const display::Display display = *iter; |
| 105 displays_.erase(iter); |
| 106 FOR_EACH_OBSERVER(display::DisplayObserver, observers_, |
| 107 OnDisplayRemoved(display)); |
| 108 } |
| 109 } // namespace views |
| OLD | NEW |