| 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_tree.h" | 5 #include "components/mus/ws/window_tree.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 !access_policy_->CanChangeWindowVisibility(window)) { | 262 !access_policy_->CanChangeWindowVisibility(window)) { |
| 263 return false; | 263 return false; |
| 264 } | 264 } |
| 265 Operation op(this, window_server_, OperationType::SET_WINDOW_VISIBILITY); | 265 Operation op(this, window_server_, OperationType::SET_WINDOW_VISIBILITY); |
| 266 window->SetVisible(visible); | 266 window->SetVisible(visible); |
| 267 return true; | 267 return true; |
| 268 } | 268 } |
| 269 | 269 |
| 270 bool WindowTree::SetFocus(const ClientWindowId& window_id) { | 270 bool WindowTree::SetFocus(const ClientWindowId& window_id) { |
| 271 ServerWindow* window = GetWindowByClientId(window_id); | 271 ServerWindow* window = GetWindowByClientId(window_id); |
| 272 // TODO(beng): consider shifting non-policy drawn check logic to VTH's | 272 ServerWindow* currently_focused = window_server_->GetFocusedWindow(); |
| 273 // FocusController. | 273 if (!currently_focused && !window) |
| 274 // TODO(sky): this doesn't work to clear focus. That is because if window is | 274 return false; |
| 275 // null, then |host| is null and we fail. | 275 |
| 276 Display* display = GetDisplay(window); | 276 Display* display = GetDisplay(window); |
| 277 if (!window || !display || !window->IsDrawn() || !window->can_focus() || | 277 if (window && (!display || !window->can_focus() || !window->IsDrawn())) |
| 278 !access_policy_->CanSetFocus(window)) { | |
| 279 return false; | 278 return false; |
| 280 } | 279 |
| 280 if (!access_policy_->CanSetFocus(window)) |
| 281 return false; |
| 281 | 282 |
| 282 Operation op(this, window_server_, OperationType::SET_FOCUS); | 283 Operation op(this, window_server_, OperationType::SET_FOCUS); |
| 283 window_server_->SetFocusedWindow(window); | 284 window_server_->SetFocusedWindow(window); |
| 284 return true; | 285 return true; |
| 285 } | 286 } |
| 286 | 287 |
| 287 bool WindowTree::Embed(const ClientWindowId& window_id, | 288 bool WindowTree::Embed(const ClientWindowId& window_id, |
| 288 mojom::WindowTreeClientPtr client) { | 289 mojom::WindowTreeClientPtr client) { |
| 289 if (!client || !CanEmbed(window_id)) | 290 if (!client || !CanEmbed(window_id)) |
| 290 return false; | 291 return false; |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 } | 667 } |
| 667 | 668 |
| 668 ClientWindowId WindowTree::ClientWindowIdForWindow( | 669 ClientWindowId WindowTree::ClientWindowIdForWindow( |
| 669 const ServerWindow* window) const { | 670 const ServerWindow* window) const { |
| 670 auto iter = window_id_to_client_id_map_.find(window->id()); | 671 auto iter = window_id_to_client_id_map_.find(window->id()); |
| 671 DCHECK(iter != window_id_to_client_id_map_.end()); | 672 DCHECK(iter != window_id_to_client_id_map_.end()); |
| 672 return iter->second; | 673 return iter->second; |
| 673 } | 674 } |
| 674 | 675 |
| 675 bool WindowTree::IsValidIdForNewWindow(const ClientWindowId& id) const { | 676 bool WindowTree::IsValidIdForNewWindow(const ClientWindowId& id) const { |
| 677 // Reserve 0 to indicate a null window. |
| 676 return client_id_to_window_id_map_.count(id) == 0u && | 678 return client_id_to_window_id_map_.count(id) == 0u && |
| 677 access_policy_->IsValidIdForNewWindow(id); | 679 access_policy_->IsValidIdForNewWindow(id) && id != ClientWindowId(); |
| 678 } | 680 } |
| 679 | 681 |
| 680 WindowId WindowTree::GenerateNewWindowId() { | 682 WindowId WindowTree::GenerateNewWindowId() { |
| 681 // TODO(sky): deal with wrapping and uniqueness. | 683 // TODO(sky): deal with wrapping and uniqueness. |
| 682 return WindowId(id_, next_window_id_++); | 684 return WindowId(id_, next_window_id_++); |
| 683 } | 685 } |
| 684 | 686 |
| 685 bool WindowTree::CanReorderWindow(const ServerWindow* window, | 687 bool WindowTree::CanReorderWindow(const ServerWindow* window, |
| 686 const ServerWindow* relative_window, | 688 const ServerWindow* relative_window, |
| 687 mojom::OrderDirection direction) const { | 689 mojom::OrderDirection direction) const { |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1368 } | 1370 } |
| 1369 | 1371 |
| 1370 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( | 1372 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( |
| 1371 const ServerWindow* window) const { | 1373 const ServerWindow* window) const { |
| 1372 WindowTree* tree = window_server_->GetTreeWithRoot(window); | 1374 WindowTree* tree = window_server_->GetTreeWithRoot(window); |
| 1373 return tree && tree != this; | 1375 return tree && tree != this; |
| 1374 } | 1376 } |
| 1375 | 1377 |
| 1376 } // namespace ws | 1378 } // namespace ws |
| 1377 } // namespace mus | 1379 } // namespace mus |
| OLD | NEW |