| 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/views/mus/screen_mus.h" | 5 #include "ui/views/mus/screen_mus.h" |
| 6 | 6 |
| 7 // #include "components/mus/public/interfaces/window_manager_constants.mojom.h" | |
| 8 #include "mojo/converters/geometry/geometry_type_converters.h" | 7 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 9 #include "mojo/shell/public/cpp/connection.h" | 8 #include "mojo/shell/public/cpp/connection.h" |
| 10 #include "mojo/shell/public/cpp/connector.h" | 9 #include "mojo/shell/public/cpp/connector.h" |
| 11 #include "ui/gfx/display_finder.h" | 10 #include "ui/gfx/display_finder.h" |
| 12 #include "ui/gfx/display_observer.h" | 11 #include "ui/gfx/display_observer.h" |
| 13 #include "ui/views/mus/screen_mus_delegate.h" | 12 #include "ui/views/mus/screen_mus_delegate.h" |
| 14 #include "ui/views/mus/window_manager_frame_values.h" | 13 #include "ui/views/mus/window_manager_frame_values.h" |
| 15 | 14 |
| 16 namespace mojo { | 15 namespace mojo { |
| 17 | 16 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 74 |
| 76 ScreenMus::~ScreenMus() {} | 75 ScreenMus::~ScreenMus() {} |
| 77 | 76 |
| 78 void ScreenMus::Init(mojo::Connector* connector) { | 77 void ScreenMus::Init(mojo::Connector* connector) { |
| 79 gfx::Screen::SetScreenInstance(this); | 78 gfx::Screen::SetScreenInstance(this); |
| 80 | 79 |
| 81 connector->ConnectToInterface("mojo:mus", &display_manager_); | 80 connector->ConnectToInterface("mojo:mus", &display_manager_); |
| 82 | 81 |
| 83 display_manager_->AddObserver( | 82 display_manager_->AddObserver( |
| 84 display_manager_observer_binding_.CreateInterfacePtrAndBind()); | 83 display_manager_observer_binding_.CreateInterfacePtrAndBind()); |
| 84 |
| 85 // We need the set of displays before we can continue. Wait for it. | 85 // We need the set of displays before we can continue. Wait for it. |
| 86 display_manager_observer_binding_.WaitForIncomingMethodCall(); | 86 wait_for_displays_loop_.reset(new base::RunLoop); |
| 87 wait_for_displays_loop_->Run(); |
| 87 | 88 |
| 88 // The WaitForIncomingMethodCall() should have supplied the set of Displays. | 89 // The WaitForIncomingMethodCall() should have supplied the set of Displays. |
| 89 DCHECK(displays_.size()); | 90 DCHECK(displays_.size()); |
| 90 } | 91 } |
| 91 | 92 |
| 92 int ScreenMus::FindDisplayIndexById(int64_t id) const { | 93 int ScreenMus::FindDisplayIndexById(int64_t id) const { |
| 93 for (size_t i = 0; i < displays_.size(); ++i) { | 94 for (size_t i = 0; i < displays_.size(); ++i) { |
| 94 if (displays_[i].id() == id) | 95 if (displays_[i].id() == id) |
| 95 return static_cast<int>(i); | 96 return static_cast<int>(i); |
| 96 } | 97 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 displays_ = displays.To<std::vector<gfx::Display>>(); | 197 displays_ = displays.To<std::vector<gfx::Display>>(); |
| 197 for (size_t i = 0; i < displays.size(); ++i) { | 198 for (size_t i = 0; i < displays.size(); ++i) { |
| 198 if (displays[i]->is_primary) { | 199 if (displays[i]->is_primary) { |
| 199 primary_display_index_ = static_cast<int>(i); | 200 primary_display_index_ = static_cast<int>(i); |
| 200 // TODO(sky): Make WindowManagerFrameValues per display. | 201 // TODO(sky): Make WindowManagerFrameValues per display. |
| 201 WindowManagerFrameValues frame_values = | 202 WindowManagerFrameValues frame_values = |
| 202 displays[i]->frame_decoration_values.To<WindowManagerFrameValues>(); | 203 displays[i]->frame_decoration_values.To<WindowManagerFrameValues>(); |
| 203 WindowManagerFrameValues::SetInstance(frame_values); | 204 WindowManagerFrameValues::SetInstance(frame_values); |
| 204 } | 205 } |
| 205 } | 206 } |
| 207 |
| 208 DCHECK(wait_for_displays_loop_); |
| 209 wait_for_displays_loop_->Quit(); |
| 206 } | 210 } |
| 207 | 211 |
| 208 void ScreenMus::OnDisplaysChanged( | 212 void ScreenMus::OnDisplaysChanged( |
| 209 mojo::Array<mus::mojom::DisplayPtr> transport_displays) { | 213 mojo::Array<mus::mojom::DisplayPtr> transport_displays) { |
| 210 for (size_t i = 0; i < transport_displays.size(); ++i) { | 214 for (size_t i = 0; i < transport_displays.size(); ++i) { |
| 211 const bool is_primary = transport_displays[i]->is_primary; | 215 const bool is_primary = transport_displays[i]->is_primary; |
| 212 ProcessDisplayChanged(transport_displays[i].To<gfx::Display>(), is_primary); | 216 ProcessDisplayChanged(transport_displays[i].To<gfx::Display>(), is_primary); |
| 213 if (is_primary) { | 217 if (is_primary) { |
| 214 WindowManagerFrameValues frame_values = | 218 WindowManagerFrameValues frame_values = |
| 215 transport_displays[i] | 219 transport_displays[i] |
| 216 ->frame_decoration_values.To<WindowManagerFrameValues>(); | 220 ->frame_decoration_values.To<WindowManagerFrameValues>(); |
| 217 WindowManagerFrameValues::SetInstance(frame_values); | 221 WindowManagerFrameValues::SetInstance(frame_values); |
| 218 delegate_->OnWindowManagerFrameValuesChanged(); | 222 delegate_->OnWindowManagerFrameValuesChanged(); |
| 219 } | 223 } |
| 220 } | 224 } |
| 221 } | 225 } |
| 222 | 226 |
| 223 void ScreenMus::OnDisplayRemoved(int64_t id) { | 227 void ScreenMus::OnDisplayRemoved(int64_t id) { |
| 224 const int index = FindDisplayIndexById(id); | 228 const int index = FindDisplayIndexById(id); |
| 225 DCHECK_NE(-1, index); | 229 DCHECK_NE(-1, index); |
| 226 // Another display must become primary before the existing primary is | 230 // Another display must become primary before the existing primary is |
| 227 // removed. | 231 // removed. |
| 228 DCHECK_NE(index, primary_display_index_); | 232 DCHECK_NE(index, primary_display_index_); |
| 229 const gfx::Display display = displays_[index]; | 233 const gfx::Display display = displays_[index]; |
| 230 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_, | 234 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_, |
| 231 OnDisplayRemoved(display)); | 235 OnDisplayRemoved(display)); |
| 232 } | 236 } |
| 233 | 237 |
| 234 } // namespace views | 238 } // namespace views |
| OLD | NEW |