| 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 "components/mus/ws/window_server.h" | 5 #include "components/mus/ws/window_server.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "components/mus/ws/display.h" | 9 #include "components/mus/ws/display.h" |
| 10 #include "components/mus/ws/display_binding.h" | 10 #include "components/mus/ws/display_binding.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 void WindowServer::OnFirstWindowManagerFactorySet() { | 230 void WindowServer::OnFirstWindowManagerFactorySet() { |
| 231 if (display_manager_->has_active_or_pending_displays()) | 231 if (display_manager_->has_active_or_pending_displays()) |
| 232 return; | 232 return; |
| 233 | 233 |
| 234 // We've been supplied a WindowManagerFactory and no displays have been | 234 // We've been supplied a WindowManagerFactory and no displays have been |
| 235 // created yet. Treat this as a signal to create a Display. | 235 // created yet. Treat this as a signal to create a Display. |
| 236 // TODO(sky): we need a better way to determine this, most likely a switch. | 236 // TODO(sky): we need a better way to determine this, most likely a switch. |
| 237 delegate_->CreateDefaultDisplays(); | 237 delegate_->CreateDefaultDisplays(); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void WindowServer::SetFocusedWindow(ServerWindow* window) { | 240 bool WindowServer::SetFocusedWindow(ServerWindow* window) { |
| 241 // TODO(sky): this should fail if there is modal dialog active and |window| | 241 // TODO(sky): this should fail if there is modal dialog active and |window| |
| 242 // is outside that. | 242 // is outside that. |
| 243 ServerWindow* currently_focused = GetFocusedWindow(); | 243 ServerWindow* currently_focused = GetFocusedWindow(); |
| 244 Display* focused_display = | 244 Display* focused_display = |
| 245 currently_focused | 245 currently_focused |
| 246 ? display_manager_->GetDisplayContaining(currently_focused) | 246 ? display_manager_->GetDisplayContaining(currently_focused) |
| 247 : nullptr; | 247 : nullptr; |
| 248 if (!window) { | 248 if (!window) |
| 249 if (focused_display) | 249 return focused_display ? focused_display->SetFocusedWindow(nullptr) : true; |
| 250 focused_display->SetFocusedWindow(nullptr); | 250 |
| 251 return; | |
| 252 } | |
| 253 Display* display = display_manager_->GetDisplayContaining(window); | 251 Display* display = display_manager_->GetDisplayContaining(window); |
| 254 DCHECK(display); // It's assumed callers do validation before calling this. | 252 DCHECK(display); // It's assumed callers do validation before calling this. |
| 255 display->SetFocusedWindow(window); | 253 const bool result = display->SetFocusedWindow(window); |
| 256 // If the focus actually changed, and focus was in another display, then we | 254 // If the focus actually changed, and focus was in another display, then we |
| 257 // need to notify the previously focused display so that it cleans up state | 255 // need to notify the previously focused display so that it cleans up state |
| 258 // and notifies appropriately. | 256 // and notifies appropriately. |
| 259 if (window && display->GetFocusedWindow() && display != focused_display && | 257 if (result && display->GetFocusedWindow() && display != focused_display && |
| 260 focused_display) { | 258 focused_display) { |
| 261 focused_display->SetFocusedWindow(nullptr); | 259 const bool cleared_focus = focused_display->SetFocusedWindow(nullptr); |
| 260 DCHECK(cleared_focus); |
| 262 } | 261 } |
| 262 return result; |
| 263 } | 263 } |
| 264 | 264 |
| 265 ServerWindow* WindowServer::GetFocusedWindow() { | 265 ServerWindow* WindowServer::GetFocusedWindow() { |
| 266 for (Display* display : display_manager_->displays()) { | 266 for (Display* display : display_manager_->displays()) { |
| 267 ServerWindow* focused_window = display->GetFocusedWindow(); | 267 ServerWindow* focused_window = display->GetFocusedWindow(); |
| 268 if (focused_window) | 268 if (focused_window) |
| 269 return focused_window; | 269 return focused_window; |
| 270 } | 270 } |
| 271 return nullptr; | 271 return nullptr; |
| 272 } | 272 } |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 void WindowServer::OnFirstDisplayReady() { | 635 void WindowServer::OnFirstDisplayReady() { |
| 636 delegate_->OnFirstDisplayReady(); | 636 delegate_->OnFirstDisplayReady(); |
| 637 } | 637 } |
| 638 | 638 |
| 639 void WindowServer::OnNoMoreDisplays() { | 639 void WindowServer::OnNoMoreDisplays() { |
| 640 delegate_->OnNoMoreDisplays(); | 640 delegate_->OnNoMoreDisplays(); |
| 641 } | 641 } |
| 642 | 642 |
| 643 } // namespace ws | 643 } // namespace ws |
| 644 } // namespace mus | 644 } // namespace mus |
| OLD | NEW |