| 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 <queue> | 7 #include <queue> |
| 8 | 8 |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "components/mus/common/event_matcher_util.h" | 10 #include "components/mus/common/event_matcher_util.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 | 49 |
| 50 std::unique_ptr<ui::Event> CoalesceEvents(std::unique_ptr<ui::Event> first, | 50 std::unique_ptr<ui::Event> CoalesceEvents(std::unique_ptr<ui::Event> first, |
| 51 std::unique_ptr<ui::Event> second) { | 51 std::unique_ptr<ui::Event> second) { |
| 52 DCHECK(first->type() == ui::ET_POINTER_MOVED) | 52 DCHECK(first->type() == ui::ET_POINTER_MOVED) |
| 53 << " Non-move events cannot be merged yet."; | 53 << " Non-move events cannot be merged yet."; |
| 54 // For mouse moves, the new event just replaces the old event. | 54 // For mouse moves, the new event just replaces the old event. |
| 55 return second; | 55 return second; |
| 56 } | 56 } |
| 57 | 57 |
| 58 ServerWindow* GetEmbedRoot(ServerWindow* window) { |
| 59 DCHECK(window); |
| 60 ServerWindow* embed_root = window->parent(); |
| 61 while (embed_root && embed_root->id().client_id == window->id().client_id) |
| 62 embed_root = embed_root->parent(); |
| 63 return embed_root; |
| 64 } |
| 65 |
| 58 } // namespace | 66 } // namespace |
| 59 | 67 |
| 60 class WindowManagerState::ProcessedEventTarget { | 68 class WindowManagerState::ProcessedEventTarget { |
| 61 public: | 69 public: |
| 62 ProcessedEventTarget(ServerWindow* window, | 70 ProcessedEventTarget(ServerWindow* window, |
| 63 bool in_nonclient_area, | 71 bool in_nonclient_area, |
| 64 Accelerator* accelerator) | 72 Accelerator* accelerator) |
| 65 : in_nonclient_area_(in_nonclient_area) { | 73 : in_nonclient_area_(in_nonclient_area) { |
| 66 tracker_.Add(window); | 74 tracker_.Add(window); |
| 67 if (accelerator) | 75 if (accelerator) |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 298 |
| 291 if (event.IsMousePointerEvent()) { | 299 if (event.IsMousePointerEvent()) { |
| 292 DCHECK(event_dispatcher_.mouse_cursor_source_window()); | 300 DCHECK(event_dispatcher_.mouse_cursor_source_window()); |
| 293 | 301 |
| 294 int32_t cursor_id = 0; | 302 int32_t cursor_id = 0; |
| 295 if (event_dispatcher_.GetCurrentMouseCursor(&cursor_id)) | 303 if (event_dispatcher_.GetCurrentMouseCursor(&cursor_id)) |
| 296 display_->UpdateNativeCursor(cursor_id); | 304 display_->UpdateNativeCursor(cursor_id); |
| 297 } | 305 } |
| 298 | 306 |
| 299 // If the event is in the non-client area the event goes to the owner of | 307 // If the event is in the non-client area the event goes to the owner of |
| 300 // the window. Otherwise if the window is an embed root, forward to the | 308 // the window. |
| 301 // embedded window. | 309 WindowTree* tree = nullptr; |
| 302 WindowTree* tree = | 310 if (in_nonclient_area) { |
| 303 in_nonclient_area | 311 tree = window_server()->GetTreeWithId(target->id().client_id); |
| 304 ? window_server()->GetTreeWithId(target->id().client_id) | 312 } else { |
| 305 : window_server()->GetTreeWithRoot(target); | 313 // If the window is an embed root, forward to the embedded window. |
| 314 tree = window_server()->GetTreeWithRoot(target); |
| 315 if (!tree) |
| 316 tree = window_server()->GetTreeWithId(target->id().client_id); |
| 317 } |
| 318 |
| 319 ServerWindow* embed_root = |
| 320 tree->HasRoot(target) ? target : GetEmbedRoot(target); |
| 321 while (tree && tree->embedder_intercepts_events()) { |
| 322 DCHECK(tree->HasRoot(embed_root)); |
| 323 tree = window_server()->GetTreeWithId(embed_root->id().client_id); |
| 324 embed_root = GetEmbedRoot(embed_root); |
| 325 } |
| 326 |
| 306 if (!tree) { | 327 if (!tree) { |
| 307 if (in_nonclient_area) { | 328 DCHECK(in_nonclient_area); |
| 308 // Being the root of the tree means we may get events outside the bounds | 329 DCHECK_EQ(target, root_.get()); |
| 309 // of the platform window. Because the root has a client id of 0, | 330 tree = tree_; |
| 310 // no WindowTree is found for it and we have to special case it here. | |
| 311 DCHECK_EQ(target, root_.get()); | |
| 312 tree = tree_; | |
| 313 } else { | |
| 314 tree = window_server()->GetTreeWithId(target->id().client_id); | |
| 315 } | |
| 316 } | 331 } |
| 317 | 332 |
| 318 // TOOD(sad): Adjust this delay, possibly make this dynamic. | 333 // TOOD(sad): Adjust this delay, possibly make this dynamic. |
| 319 const base::TimeDelta max_delay = base::debug::BeingDebugged() | 334 const base::TimeDelta max_delay = base::debug::BeingDebugged() |
| 320 ? base::TimeDelta::FromDays(1) | 335 ? base::TimeDelta::FromDays(1) |
| 321 : GetDefaultAckTimerDelay(); | 336 : GetDefaultAckTimerDelay(); |
| 322 event_ack_timer_.Start( | 337 event_ack_timer_.Start( |
| 323 FROM_HERE, max_delay, | 338 FROM_HERE, max_delay, |
| 324 base::Bind(&WindowManagerState::OnEventAckTimeout, | 339 base::Bind(&WindowManagerState::OnEventAckTimeout, |
| 325 weak_factory_.GetWeakPtr(), tree->id())); | 340 weak_factory_.GetWeakPtr(), tree->id())); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 weak_accelerator); | 435 weak_accelerator); |
| 421 } | 436 } |
| 422 | 437 |
| 423 void WindowManagerState::OnEventTargetNotFound(const ui::Event& event) { | 438 void WindowManagerState::OnEventTargetNotFound(const ui::Event& event) { |
| 424 window_server()->SendToEventObservers(event, user_id_, | 439 window_server()->SendToEventObservers(event, user_id_, |
| 425 nullptr /* ignore_tree */); | 440 nullptr /* ignore_tree */); |
| 426 } | 441 } |
| 427 | 442 |
| 428 } // namespace ws | 443 } // namespace ws |
| 429 } // namespace mus | 444 } // namespace mus |
| OLD | NEW |