| 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 "components/mus/ws/window_manager_state.h" | 5 #include "components/mus/ws/window_manager_state.h" |
| 6 | 6 |
| 7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
| 8 #include "components/mus/common/event_matcher_util.h" | 8 #include "components/mus/common/event_matcher_util.h" |
| 9 #include "components/mus/ws/accelerator.h" | 9 #include "components/mus/ws/accelerator.h" |
| 10 #include "components/mus/ws/display_manager.h" | 10 #include "components/mus/ws/display_manager.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 std::unique_ptr<ui::Event> CoalesceEvents(std::unique_ptr<ui::Event> first, | 49 std::unique_ptr<ui::Event> CoalesceEvents(std::unique_ptr<ui::Event> first, |
| 50 std::unique_ptr<ui::Event> second) { | 50 std::unique_ptr<ui::Event> second) { |
| 51 DCHECK(first->type() == ui::ET_POINTER_MOVED) | 51 DCHECK(first->type() == ui::ET_POINTER_MOVED) |
| 52 << " Non-move events cannot be merged yet."; | 52 << " Non-move events cannot be merged yet."; |
| 53 // For mouse moves, the new event just replaces the old event. | 53 // For mouse moves, the new event just replaces the old event. |
| 54 return second; | 54 return second; |
| 55 } | 55 } |
| 56 | 56 |
| 57 const ServerWindow* GetEmbedRoot(const ServerWindow* window) { |
| 58 DCHECK(window); |
| 59 const ServerWindow* embed_root = window->parent(); |
| 60 while (embed_root && embed_root->id().client_id == window->id().client_id) |
| 61 embed_root = embed_root->parent(); |
| 62 return embed_root; |
| 63 } |
| 64 |
| 57 } // namespace | 65 } // namespace |
| 58 | 66 |
| 59 class WindowManagerState::ProcessedEventTarget { | 67 class WindowManagerState::ProcessedEventTarget { |
| 60 public: | 68 public: |
| 61 ProcessedEventTarget(ServerWindow* window, | 69 ProcessedEventTarget(ServerWindow* window, |
| 62 ClientSpecificId client_id, | 70 ClientSpecificId client_id, |
| 63 Accelerator* accelerator) | 71 Accelerator* accelerator) |
| 64 : client_id_(client_id) { | 72 : client_id_(client_id) { |
| 65 tracker_.Add(window); | 73 tracker_.Add(window); |
| 66 if (accelerator) | 74 if (accelerator) |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 | 429 |
| 422 base::WeakPtr<Accelerator> weak_accelerator; | 430 base::WeakPtr<Accelerator> weak_accelerator; |
| 423 if (accelerator) | 431 if (accelerator) |
| 424 weak_accelerator = accelerator->GetWeakPtr(); | 432 weak_accelerator = accelerator->GetWeakPtr(); |
| 425 DispatchInputEventToWindowImpl(target, client_id, event, weak_accelerator); | 433 DispatchInputEventToWindowImpl(target, client_id, event, weak_accelerator); |
| 426 } | 434 } |
| 427 | 435 |
| 428 ClientSpecificId WindowManagerState::GetEventTargetClientId( | 436 ClientSpecificId WindowManagerState::GetEventTargetClientId( |
| 429 const ServerWindow* window, | 437 const ServerWindow* window, |
| 430 bool in_nonclient_area) { | 438 bool in_nonclient_area) { |
| 431 WindowTree* tree = | 439 // If the event is in the non-client area the event goes to the owner of |
| 432 in_nonclient_area ? window_server()->GetTreeWithId(window->id().client_id) | 440 // the window. |
| 433 : window_server()->GetTreeWithRoot(window); | 441 WindowTree* tree = nullptr; |
| 442 if (in_nonclient_area) { |
| 443 tree = window_server()->GetTreeWithId(window->id().client_id); |
| 444 } else { |
| 445 // If the window is an embed root, forward to the embedded window. |
| 446 tree = window_server()->GetTreeWithRoot(window); |
| 447 if (!tree) |
| 448 tree = window_server()->GetTreeWithId(window->id().client_id); |
| 449 } |
| 450 |
| 451 const ServerWindow* embed_root = |
| 452 tree->HasRoot(window) ? window : GetEmbedRoot(window); |
| 453 while (tree && tree->embedder_intercepts_events()) { |
| 454 DCHECK(tree->HasRoot(embed_root)); |
| 455 tree = window_server()->GetTreeWithId(embed_root->id().client_id); |
| 456 embed_root = GetEmbedRoot(embed_root); |
| 457 } |
| 458 |
| 434 if (!tree) { | 459 if (!tree) { |
| 435 if (in_nonclient_area) { | 460 DCHECK(in_nonclient_area); |
| 436 // Being the root of the tree means we may get events outside the bounds | 461 tree = window_tree_; |
| 437 // of the platform window. Because the root has a client id of 0, | |
| 438 // no WindowTree is found for it and we have to special case it here. | |
| 439 tree = window_tree_; | |
| 440 } else { | |
| 441 tree = window_server()->GetTreeWithId(window->id().client_id); | |
| 442 } | |
| 443 } | 462 } |
| 444 return tree->id(); | 463 return tree->id(); |
| 445 } | 464 } |
| 446 | 465 |
| 447 ServerWindow* WindowManagerState::GetRootWindowContaining( | 466 ServerWindow* WindowManagerState::GetRootWindowContaining( |
| 448 const gfx::Point& location) { | 467 const gfx::Point& location) { |
| 449 if (display_manager()->displays().empty()) | 468 if (display_manager()->displays().empty()) |
| 450 return nullptr; | 469 return nullptr; |
| 451 | 470 |
| 452 // TODO(sky): this isn't right. To correctly implement need bounds of | 471 // TODO(sky): this isn't right. To correctly implement need bounds of |
| 453 // Display, which we aren't tracking yet. For now, use the first display. | 472 // Display, which we aren't tracking yet. For now, use the first display. |
| 454 Display* display = *(display_manager()->displays().begin()); | 473 Display* display = *(display_manager()->displays().begin()); |
| 455 WindowManagerDisplayRoot* display_root = | 474 WindowManagerDisplayRoot* display_root = |
| 456 display->GetWindowManagerDisplayRootForUser(user_id()); | 475 display->GetWindowManagerDisplayRootForUser(user_id()); |
| 457 return display_root ? display_root->root() : nullptr; | 476 return display_root ? display_root->root() : nullptr; |
| 458 } | 477 } |
| 459 | 478 |
| 460 void WindowManagerState::OnEventTargetNotFound(const ui::Event& event) { | 479 void WindowManagerState::OnEventTargetNotFound(const ui::Event& event) { |
| 461 window_server()->SendToEventObservers(event, user_id(), | 480 window_server()->SendToEventObservers(event, user_id(), |
| 462 nullptr /* ignore_tree */); | 481 nullptr /* ignore_tree */); |
| 463 } | 482 } |
| 464 | 483 |
| 465 } // namespace ws | 484 } // namespace ws |
| 466 } // namespace mus | 485 } // namespace mus |
| OLD | NEW |