| 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 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 IsWindowKnown(focused_window, &focused_window_id); | 111 IsWindowKnown(focused_window, &focused_window_id); |
| 112 | 112 |
| 113 const bool drawn = root->parent() && root->parent()->IsDrawn(); | 113 const bool drawn = root->parent() && root->parent()->IsDrawn(); |
| 114 client()->OnEmbed(id_, WindowToWindowData(to_send.front()), std::move(tree), | 114 client()->OnEmbed(id_, WindowToWindowData(to_send.front()), std::move(tree), |
| 115 display_id, focused_window_id.id, drawn); | 115 display_id, focused_window_id.id, drawn); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void WindowTree::ConfigureWindowManager() { | 118 void WindowTree::ConfigureWindowManager() { |
| 119 DCHECK(!window_manager_internal_); | 119 DCHECK(!window_manager_internal_); |
| 120 window_manager_internal_ = binding_->GetWindowManager(); | 120 window_manager_internal_ = binding_->GetWindowManager(); |
| 121 window_manager_internal_->OnConnect(id_); |
| 121 } | 122 } |
| 122 | 123 |
| 123 const ServerWindow* WindowTree::GetWindow(const WindowId& id) const { | 124 const ServerWindow* WindowTree::GetWindow(const WindowId& id) const { |
| 124 if (id_ == id.client_id) { | 125 if (id_ == id.client_id) { |
| 125 auto iter = created_window_map_.find(id); | 126 auto iter = created_window_map_.find(id); |
| 126 return iter == created_window_map_.end() ? nullptr : iter->second; | 127 return iter == created_window_map_.end() ? nullptr : iter->second; |
| 127 } | 128 } |
| 128 return window_server_->GetWindow(id); | 129 return window_server_->GetWindow(id); |
| 129 } | 130 } |
| 130 | 131 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 157 | 158 |
| 158 const WindowManagerState* WindowTree::GetWindowManagerState( | 159 const WindowManagerState* WindowTree::GetWindowManagerState( |
| 159 const ServerWindow* window) const { | 160 const ServerWindow* window) const { |
| 160 return window | 161 return window |
| 161 ? display_manager() | 162 ? display_manager() |
| 162 ->GetWindowManagerAndDisplay(window) | 163 ->GetWindowManagerAndDisplay(window) |
| 163 .window_manager_state | 164 .window_manager_state |
| 164 : nullptr; | 165 : nullptr; |
| 165 } | 166 } |
| 166 | 167 |
| 168 void WindowTree::AddRootForWindowManager(const ServerWindow* root) { |
| 169 DCHECK(window_manager_internal_); |
| 170 const ClientWindowId client_window_id(WindowIdToTransportId(root->id())); |
| 171 DCHECK_EQ(0u, client_id_to_window_id_map_.count(client_window_id)); |
| 172 client_id_to_window_id_map_[client_window_id] = root->id(); |
| 173 window_id_to_client_id_map_[root->id()] = client_window_id; |
| 174 roots_.insert(root); |
| 175 |
| 176 Display* display = GetDisplay(root); |
| 177 DCHECK(display); |
| 178 |
| 179 window_manager_internal_->WmNewDisplayAdded(display->ToMojomDisplay(), |
| 180 WindowToWindowData(root), |
| 181 root->parent()->IsDrawn()); |
| 182 } |
| 183 |
| 167 void WindowTree::OnWindowDestroyingTreeImpl(WindowTree* tree) { | 184 void WindowTree::OnWindowDestroyingTreeImpl(WindowTree* tree) { |
| 168 if (event_source_wms_ && event_source_wms_->tree() == tree) | 185 if (event_source_wms_ && event_source_wms_->tree() == tree) |
| 169 event_source_wms_ = nullptr; | 186 event_source_wms_ = nullptr; |
| 170 | 187 |
| 171 // Notify our client if |tree| was embedded in any of our views. | 188 // Notify our client if |tree| was embedded in any of our views. |
| 172 for (const auto* tree_root : tree->roots_) { | 189 for (const auto* tree_root : tree->roots_) { |
| 173 const bool owns_tree_root = tree_root->id().client_id == id_; | 190 const bool owns_tree_root = tree_root->id().client_id == id_; |
| 174 if (owns_tree_root) { | 191 if (owns_tree_root) { |
| 175 client()->OnEmbeddedAppDisconnected( | 192 client()->OnEmbeddedAppDisconnected( |
| 176 ClientWindowIdForWindow(tree_root).id); | 193 ClientWindowIdForWindow(tree_root).id); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 roots_.insert(window); | 393 roots_.insert(window); |
| 377 Display* display = GetDisplay(window); | 394 Display* display = GetDisplay(window); |
| 378 int64_t display_id = | 395 int64_t display_id = |
| 379 display ? display->id() : display::Display::kInvalidDisplayID; | 396 display ? display->id() : display::Display::kInvalidDisplayID; |
| 380 const bool drawn = window->parent() && window->parent()->IsDrawn(); | 397 const bool drawn = window->parent() && window->parent()->IsDrawn(); |
| 381 client()->OnTopLevelCreated(client_change_id, WindowToWindowData(window), | 398 client()->OnTopLevelCreated(client_change_id, WindowToWindowData(window), |
| 382 display_id, drawn); | 399 display_id, drawn); |
| 383 } | 400 } |
| 384 | 401 |
| 385 void WindowTree::AddActivationParent(const ClientWindowId& window_id) { | 402 void WindowTree::AddActivationParent(const ClientWindowId& window_id) { |
| 386 Display* host = GetDisplayForWindowManager(); | |
| 387 if (!host) | |
| 388 return; | |
| 389 ServerWindow* window = GetWindowByClientId(window_id); | 403 ServerWindow* window = GetWindowByClientId(window_id); |
| 390 if (window) | 404 if (window) { |
| 391 host->AddActivationParent(window); | 405 Display* display = GetDisplay(window); |
| 406 if (display) |
| 407 display->AddActivationParent(window); |
| 408 else |
| 409 DVLOG(1) << "AddActivationParent window not associated with display"; |
| 410 } else { |
| 411 DVLOG(1) << "AddActivationParent supplied invalid window id"; |
| 412 } |
| 392 } | 413 } |
| 393 | 414 |
| 394 void WindowTree::OnChangeCompleted(uint32_t change_id, bool success) { | 415 void WindowTree::OnChangeCompleted(uint32_t change_id, bool success) { |
| 395 client()->OnChangeCompleted(change_id, success); | 416 client()->OnChangeCompleted(change_id, success); |
| 396 } | 417 } |
| 397 | 418 |
| 398 void WindowTree::OnAccelerator(uint32_t accelerator_id, | 419 void WindowTree::OnAccelerator(uint32_t accelerator_id, |
| 399 const ui::Event& event) { | 420 const ui::Event& event) { |
| 400 DCHECK(window_manager_internal_); | 421 DCHECK(window_manager_internal_); |
| 401 // TODO(moshayedi): crbug.com/617167. Don't clone even once we map | 422 // TODO(moshayedi): crbug.com/617167. Don't clone even once we map |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 } | 676 } |
| 656 | 677 |
| 657 DisplayManager* WindowTree::display_manager() { | 678 DisplayManager* WindowTree::display_manager() { |
| 658 return window_server_->display_manager(); | 679 return window_server_->display_manager(); |
| 659 } | 680 } |
| 660 | 681 |
| 661 const DisplayManager* WindowTree::display_manager() const { | 682 const DisplayManager* WindowTree::display_manager() const { |
| 662 return window_server_->display_manager(); | 683 return window_server_->display_manager(); |
| 663 } | 684 } |
| 664 | 685 |
| 665 Display* WindowTree::GetDisplayForWindowManager() { | |
| 666 return GetWindowManagerStateForWindowManager()->display(); | |
| 667 } | |
| 668 | |
| 669 WindowManagerState* WindowTree::GetWindowManagerStateForWindowManager() { | 686 WindowManagerState* WindowTree::GetWindowManagerStateForWindowManager() { |
| 670 // The WindowTree for the wm has one and only one root. | |
| 671 CHECK_EQ(1u, roots_.size()); | |
| 672 | |
| 673 // Indicates the client is the wm. | 687 // Indicates the client is the wm. |
| 674 DCHECK(window_manager_internal_); | 688 DCHECK(window_manager_internal_); |
| 675 | 689 |
| 690 if (roots_.size() > 1) { |
| 691 // TODO(sky): fix the > 1 case, http://crbug.com/611563. |
| 692 NOTIMPLEMENTED(); |
| 693 } |
| 694 |
| 676 WindowManagerState* wms = display_manager() | 695 WindowManagerState* wms = display_manager() |
| 677 ->GetWindowManagerAndDisplay(*roots_.begin()) | 696 ->GetWindowManagerAndDisplay(*roots_.begin()) |
| 678 .window_manager_state; | 697 .window_manager_state; |
| 679 CHECK(wms); | 698 CHECK(wms); |
| 680 DCHECK_EQ(this, wms->tree()); | 699 DCHECK_EQ(this, wms->tree()); |
| 681 return wms; | 700 return wms; |
| 682 } | 701 } |
| 683 | 702 |
| 684 bool WindowTree::ShouldRouteToWindowManager(const ServerWindow* window) const { | 703 bool WindowTree::ShouldRouteToWindowManager(const ServerWindow* window) const { |
| 685 // If the client created this window, then do not route it through the WM. | 704 // If the client created this window, then do not route it through the WM. |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1398 void WindowTree::RemoveAccelerator(uint32_t id) { | 1417 void WindowTree::RemoveAccelerator(uint32_t id) { |
| 1399 WindowManagerState* wms = GetWindowManagerStateForWindowManager(); | 1418 WindowManagerState* wms = GetWindowManagerStateForWindowManager(); |
| 1400 wms->event_dispatcher()->RemoveAccelerator(id); | 1419 wms->event_dispatcher()->RemoveAccelerator(id); |
| 1401 } | 1420 } |
| 1402 | 1421 |
| 1403 void WindowTree::AddActivationParent(Id transport_window_id) { | 1422 void WindowTree::AddActivationParent(Id transport_window_id) { |
| 1404 AddActivationParent(ClientWindowId(transport_window_id)); | 1423 AddActivationParent(ClientWindowId(transport_window_id)); |
| 1405 } | 1424 } |
| 1406 | 1425 |
| 1407 void WindowTree::RemoveActivationParent(Id transport_window_id) { | 1426 void WindowTree::RemoveActivationParent(Id transport_window_id) { |
| 1408 Display* host = GetDisplayForWindowManager(); | |
| 1409 if (!host) | |
| 1410 return; | |
| 1411 ServerWindow* window = | 1427 ServerWindow* window = |
| 1412 GetWindowByClientId(ClientWindowId(transport_window_id)); | 1428 GetWindowByClientId(ClientWindowId(transport_window_id)); |
| 1413 if (window) | 1429 if (window) { |
| 1414 host->RemoveActivationParent(window); | 1430 Display* display = GetDisplay(window); |
| 1431 if (display) |
| 1432 display->RemoveActivationParent(window); |
| 1433 else |
| 1434 DVLOG(1) << "RemoveActivationParent window not associated with display"; |
| 1435 } else { |
| 1436 DVLOG(1) << "RemoveActivationParent supplied invalid window id"; |
| 1437 } |
| 1415 } | 1438 } |
| 1416 | 1439 |
| 1417 void WindowTree::ActivateNextWindow() { | 1440 void WindowTree::ActivateNextWindow() { |
| 1418 Display* display = GetDisplayForWindowManager(); | 1441 // TODO(sky): this needs to track active window. http://crbug.com/611563. |
| 1419 if (!display) | 1442 GetWindowManagerStateForWindowManager()->display()->ActivateNextWindow(); |
| 1420 return; | |
| 1421 display->ActivateNextWindow(); | |
| 1422 } | 1443 } |
| 1423 | 1444 |
| 1424 void WindowTree::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1445 void WindowTree::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1425 Id window_id, | 1446 Id window_id, |
| 1426 int32_t x_offset, | 1447 int32_t x_offset, |
| 1427 int32_t y_offset, | 1448 int32_t y_offset, |
| 1428 const gfx::Insets& hit_area) { | 1449 const gfx::Insets& hit_area) { |
| 1429 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); | 1450 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); |
| 1430 if (!window) | 1451 if (!window) |
| 1431 return; | 1452 return; |
| 1432 | 1453 |
| 1433 window->SetUnderlayOffset(gfx::Vector2d(x_offset, y_offset)); | 1454 window->SetUnderlayOffset(gfx::Vector2d(x_offset, y_offset)); |
| 1434 window->set_extended_hit_test_region(hit_area); | 1455 window->set_extended_hit_test_region(hit_area); |
| 1435 } | 1456 } |
| 1436 | 1457 |
| 1437 void WindowTree::WmResponse(uint32_t change_id, bool response) { | 1458 void WindowTree::WmResponse(uint32_t change_id, bool response) { |
| 1438 // TODO(sky): think about what else case means. | 1459 window_server_->WindowManagerChangeCompleted(change_id, response); |
| 1439 if (GetDisplayForWindowManager()) | |
| 1440 window_server_->WindowManagerChangeCompleted(change_id, response); | |
| 1441 } | 1460 } |
| 1442 | 1461 |
| 1443 void WindowTree::WmRequestClose(Id transport_window_id) { | 1462 void WindowTree::WmRequestClose(Id transport_window_id) { |
| 1444 // Only the WindowManager should be using this. | |
| 1445 Display* host = GetDisplayForWindowManager(); | |
| 1446 if (!host) | |
| 1447 return; | |
| 1448 | |
| 1449 ServerWindow* window = | 1463 ServerWindow* window = |
| 1450 GetWindowByClientId(ClientWindowId(transport_window_id)); | 1464 GetWindowByClientId(ClientWindowId(transport_window_id)); |
| 1451 WindowTree* tree = window_server_->GetTreeWithRoot(window); | 1465 WindowTree* tree = window_server_->GetTreeWithRoot(window); |
| 1452 if (tree && tree != this) { | 1466 if (tree && tree != this) { |
| 1453 tree->client()->RequestClose(tree->ClientWindowIdForWindow(window).id); | 1467 tree->client()->RequestClose(tree->ClientWindowIdForWindow(window).id); |
| 1454 } | 1468 } |
| 1455 // TODO(sky): think about what else case means. | 1469 // TODO(sky): think about what else case means. |
| 1456 } | 1470 } |
| 1457 | 1471 |
| 1458 void WindowTree::WmSetFrameDecorationValues( | 1472 void WindowTree::WmSetFrameDecorationValues( |
| 1459 mojom::FrameDecorationValuesPtr values) { | 1473 mojom::FrameDecorationValuesPtr values) { |
| 1460 WindowManagerState* wm_state = GetWindowManagerStateForWindowManager(); | 1474 WindowManagerState* wm_state = GetWindowManagerStateForWindowManager(); |
| 1461 if (wm_state) | 1475 if (wm_state) |
| 1462 wm_state->SetFrameDecorationValues(std::move(values)); | 1476 wm_state->SetFrameDecorationValues(std::move(values)); |
| 1463 } | 1477 } |
| 1464 | 1478 |
| 1465 void WindowTree::WmSetNonClientCursor(uint32_t window_id, | 1479 void WindowTree::WmSetNonClientCursor(uint32_t window_id, |
| 1466 mojom::Cursor cursor_id) { | 1480 mojom::Cursor cursor_id) { |
| 1467 WindowManagerState* wm_state = GetWindowManagerStateForWindowManager(); | 1481 WindowManagerState* wm_state = GetWindowManagerStateForWindowManager(); |
| 1468 if (wm_state) { | 1482 if (wm_state) { |
| 1469 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); | 1483 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); |
| 1470 if (window) | 1484 if (window) |
| 1471 window->SetNonClientCursor(cursor_id); | 1485 window->SetNonClientCursor(cursor_id); |
| 1472 } | 1486 } |
| 1473 } | 1487 } |
| 1474 | 1488 |
| 1475 void WindowTree::OnWmCreatedTopLevelWindow(uint32_t change_id, | 1489 void WindowTree::OnWmCreatedTopLevelWindow(uint32_t change_id, |
| 1476 Id transport_window_id) { | 1490 Id transport_window_id) { |
| 1477 if (GetDisplayForWindowManager()) { | 1491 ServerWindow* window = |
| 1478 ServerWindow* window = | 1492 GetWindowByClientId(ClientWindowId(transport_window_id)); |
| 1479 GetWindowByClientId(ClientWindowId(transport_window_id)); | 1493 if (window && window->id().client_id != id_) { |
| 1480 if (window && window->id().client_id != id_) { | 1494 DVLOG(1) << "OnWmCreatedTopLevelWindow supplied invalid window id"; |
| 1481 window_server_->WindowManagerSentBogusMessage(); | 1495 window_server_->WindowManagerSentBogusMessage(); |
| 1482 window = nullptr; | 1496 window = nullptr; |
| 1483 } | |
| 1484 window_server_->WindowManagerCreatedTopLevelWindow(this, change_id, window); | |
| 1485 } | 1497 } |
| 1486 // TODO(sky): think about what else case means. | 1498 window_server_->WindowManagerCreatedTopLevelWindow(this, change_id, window); |
| 1487 } | 1499 } |
| 1488 | 1500 |
| 1489 bool WindowTree::HasRootForAccessPolicy(const ServerWindow* window) const { | 1501 bool WindowTree::HasRootForAccessPolicy(const ServerWindow* window) const { |
| 1490 return HasRoot(window); | 1502 return HasRoot(window); |
| 1491 } | 1503 } |
| 1492 | 1504 |
| 1493 bool WindowTree::IsWindowKnownForAccessPolicy( | 1505 bool WindowTree::IsWindowKnownForAccessPolicy( |
| 1494 const ServerWindow* window) const { | 1506 const ServerWindow* window) const { |
| 1495 return IsWindowKnown(window); | 1507 return IsWindowKnown(window); |
| 1496 } | 1508 } |
| 1497 | 1509 |
| 1498 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( | 1510 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( |
| 1499 const ServerWindow* window) const { | 1511 const ServerWindow* window) const { |
| 1500 WindowTree* tree = window_server_->GetTreeWithRoot(window); | 1512 WindowTree* tree = window_server_->GetTreeWithRoot(window); |
| 1501 return tree && tree != this; | 1513 return tree && tree != this; |
| 1502 } | 1514 } |
| 1503 | 1515 |
| 1504 } // namespace ws | 1516 } // namespace ws |
| 1505 } // namespace mus | 1517 } // namespace mus |
| OLD | NEW |