Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: services/ui/ws/window_manager_state.cc

Issue 2884463002: Make event-targeting asynchronous in window server. (Closed)
Patch Set: cache; by value Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "services/ui/ws/window_manager_state.h" 5 #include "services/ui/ws/window_manager_state.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "services/service_manager/public/interfaces/connector.mojom.h" 11 #include "services/service_manager/public/interfaces/connector.mojom.h"
12 #include "services/ui/common/accelerator_util.h" 12 #include "services/ui/common/accelerator_util.h"
13 #include "services/ui/ws/accelerator.h" 13 #include "services/ui/ws/accelerator.h"
14 #include "services/ui/ws/cursor_location_manager.h" 14 #include "services/ui/ws/cursor_location_manager.h"
15 #include "services/ui/ws/display.h" 15 #include "services/ui/ws/display.h"
16 #include "services/ui/ws/display_creation_config.h" 16 #include "services/ui/ws/display_creation_config.h"
17 #include "services/ui/ws/display_manager.h" 17 #include "services/ui/ws/display_manager.h"
18 #include "services/ui/ws/event_targeter.h"
18 #include "services/ui/ws/platform_display.h" 19 #include "services/ui/ws/platform_display.h"
19 #include "services/ui/ws/server_window.h" 20 #include "services/ui/ws/server_window.h"
20 #include "services/ui/ws/user_display_manager.h" 21 #include "services/ui/ws/user_display_manager.h"
21 #include "services/ui/ws/user_id_tracker.h" 22 #include "services/ui/ws/user_id_tracker.h"
22 #include "services/ui/ws/window_manager_display_root.h" 23 #include "services/ui/ws/window_manager_display_root.h"
23 #include "services/ui/ws/window_server.h" 24 #include "services/ui/ws/window_server.h"
24 #include "services/ui/ws/window_tree.h" 25 #include "services/ui/ws/window_tree.h"
25 #include "ui/events/event.h" 26 #include "ui/events/event.h"
26 #include "ui/gfx/geometry/dip_util.h" 27 #include "ui/gfx/geometry/dip_util.h"
27 28
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const ServerWindow* GetEmbedRoot(const ServerWindow* window) { 68 const ServerWindow* GetEmbedRoot(const ServerWindow* window) {
68 DCHECK(window); 69 DCHECK(window);
69 const ServerWindow* embed_root = window->parent(); 70 const ServerWindow* embed_root = window->parent();
70 while (embed_root && embed_root->id().client_id == window->id().client_id) 71 while (embed_root && embed_root->id().client_id == window->id().client_id)
71 embed_root = embed_root->parent(); 72 embed_root = embed_root->parent();
72 return embed_root; 73 return embed_root;
73 } 74 }
74 75
75 } // namespace 76 } // namespace
76 77
77 WindowManagerState::InFlightEventDetails::InFlightEventDetails( 78 WindowManagerState::InFlightEventDispatchDetails::InFlightEventDispatchDetails(
78 WindowManagerState* window_manager_state, 79 WindowManagerState* window_manager_state,
79 WindowTree* tree, 80 WindowTree* tree,
80 int64_t display_id, 81 int64_t display_id,
81 const Event& event, 82 const Event& event,
82 EventDispatchPhase phase) 83 EventDispatchPhase phase)
83 : tree(tree), 84 : tree(tree),
84 display_id(display_id), 85 display_id(display_id),
85 event(Event::Clone(event)), 86 event(Event::Clone(event)),
86 phase(phase), 87 phase(phase),
87 weak_factory(window_manager_state) {} 88 weak_factory(window_manager_state) {}
88 89
89 WindowManagerState::InFlightEventDetails::~InFlightEventDetails() {} 90 WindowManagerState::InFlightEventDispatchDetails::
91 ~InFlightEventDispatchDetails() {}
90 92
91 class WindowManagerState::ProcessedEventTarget { 93 class WindowManagerState::ProcessedEventTarget {
92 public: 94 public:
93 ProcessedEventTarget(ServerWindow* window, 95 ProcessedEventTarget(ServerWindow* window,
94 ClientSpecificId client_id, 96 ClientSpecificId client_id,
95 Accelerator* accelerator) 97 Accelerator* accelerator)
96 : client_id_(client_id) { 98 : client_id_(client_id) {
97 tracker_.Add(window); 99 tracker_.Add(window);
98 if (accelerator) 100 if (accelerator)
99 accelerator_ = accelerator->GetWeakPtr(); 101 accelerator_ = accelerator->GetWeakPtr();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 event_dispatcher_.ReleaseCaptureBlockedByAnyModalWindow(); 194 event_dispatcher_.ReleaseCaptureBlockedByAnyModalWindow();
193 } 195 }
194 196
195 void WindowManagerState::SetDragDropSourceWindow( 197 void WindowManagerState::SetDragDropSourceWindow(
196 DragSource* drag_source, 198 DragSource* drag_source,
197 ServerWindow* window, 199 ServerWindow* window,
198 DragTargetConnection* source_connection, 200 DragTargetConnection* source_connection,
199 const std::unordered_map<std::string, std::vector<uint8_t>>& drag_data, 201 const std::unordered_map<std::string, std::vector<uint8_t>>& drag_data,
200 uint32_t drag_operation) { 202 uint32_t drag_operation) {
201 int32_t drag_pointer = MouseEvent::kMousePointerId; 203 int32_t drag_pointer = MouseEvent::kMousePointerId;
202 if (in_flight_event_details_ && 204 if (in_flight_event_dispatch_details_ &&
203 in_flight_event_details_->event->IsPointerEvent()) { 205 in_flight_event_dispatch_details_->event->IsPointerEvent()) {
204 drag_pointer = 206 drag_pointer = in_flight_event_dispatch_details_->event->AsPointerEvent()
205 in_flight_event_details_->event->AsPointerEvent()->pointer_details().id; 207 ->pointer_details()
208 .id;
206 } else { 209 } else {
207 NOTIMPLEMENTED() << "Set drag drop set up during something other than a " 210 NOTIMPLEMENTED() << "Set drag drop set up during something other than a "
208 << "pointer event; rejecting drag."; 211 << "pointer event; rejecting drag.";
209 drag_source->OnDragCompleted(false, ui::mojom::kDropEffectNone); 212 drag_source->OnDragCompleted(false, ui::mojom::kDropEffectNone);
210 return; 213 return;
211 } 214 }
212 215
213 event_dispatcher_.SetDragDropSourceWindow(drag_source, window, 216 event_dispatcher_.SetDragDropSourceWindow(drag_source, window,
214 source_connection, drag_pointer, 217 source_connection, drag_pointer,
215 drag_data, drag_operation); 218 drag_data, drag_operation);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 NOTREACHED(); 253 NOTREACHED();
251 } 254 }
252 255
253 const UserId& WindowManagerState::user_id() const { 256 const UserId& WindowManagerState::user_id() const {
254 return window_tree_->user_id(); 257 return window_tree_->user_id();
255 } 258 }
256 259
257 void WindowManagerState::OnWillDestroyTree(WindowTree* tree) { 260 void WindowManagerState::OnWillDestroyTree(WindowTree* tree) {
258 event_dispatcher_.OnWillDestroyDragTargetConnection(tree); 261 event_dispatcher_.OnWillDestroyDragTargetConnection(tree);
259 262
260 if (!in_flight_event_details_ || in_flight_event_details_->tree != tree) 263 if (!in_flight_event_dispatch_details_ ||
264 in_flight_event_dispatch_details_->tree != tree)
261 return; 265 return;
262 266
263 // The WindowTree is dying. So it's not going to ack the event. 267 // The WindowTree is dying. So it's not going to ack the event.
264 // If the dying tree matches the root |tree_| mark as handled so we don't 268 // If the dying tree matches the root |tree_| mark as handled so we don't
265 // notify it of accelerators. 269 // notify it of accelerators.
266 OnEventAck(in_flight_event_details_->tree, 270 OnEventAck(in_flight_event_dispatch_details_->tree,
267 tree == window_tree_ ? mojom::EventResult::HANDLED 271 tree == window_tree_ ? mojom::EventResult::HANDLED
268 : mojom::EventResult::UNHANDLED); 272 : mojom::EventResult::UNHANDLED);
269 } 273 }
270 274
271 ServerWindow* WindowManagerState::GetOrphanedRootWithId(const WindowId& id) { 275 ServerWindow* WindowManagerState::GetOrphanedRootWithId(const WindowId& id) {
272 for (auto& display_root_ptr : orphaned_window_manager_display_roots_) { 276 for (auto& display_root_ptr : orphaned_window_manager_display_roots_) {
273 if (display_root_ptr->root()->id() == id) 277 if (display_root_ptr->root()->id() == id)
274 return display_root_ptr->root(); 278 return display_root_ptr->root();
275 } 279 }
276 return nullptr; 280 return nullptr;
(...skipping 17 matching lines...) Expand all
294 // The tree is no longer active, so no point in dispatching any further 298 // The tree is no longer active, so no point in dispatching any further
295 // events. 299 // events.
296 std::queue<std::unique_ptr<QueuedEvent>> event_queue; 300 std::queue<std::unique_ptr<QueuedEvent>> event_queue;
297 event_queue.swap(event_queue_); 301 event_queue.swap(event_queue_);
298 } 302 }
299 303
300 void WindowManagerState::ProcessEvent(const ui::Event& event, 304 void WindowManagerState::ProcessEvent(const ui::Event& event,
301 int64_t display_id) { 305 int64_t display_id) {
302 // If this is still waiting for an ack from a previously sent event, then 306 // If this is still waiting for an ack from a previously sent event, then
303 // queue up the event to be dispatched once the ack is received. 307 // queue up the event to be dispatched once the ack is received.
304 if (in_flight_event_details_) { 308 if (event_dispatcher_.event_targeter()->IsHitTestInFlight() ||
309 in_flight_event_dispatch_details_) {
305 if (!event_queue_.empty() && !event_queue_.back()->processed_target && 310 if (!event_queue_.empty() && !event_queue_.back()->processed_target &&
306 EventsCanBeCoalesced(*event_queue_.back()->event, event)) { 311 EventsCanBeCoalesced(*event_queue_.back()->event, event)) {
307 event_queue_.back()->event = CoalesceEvents( 312 event_queue_.back()->event = CoalesceEvents(
308 std::move(event_queue_.back()->event), ui::Event::Clone(event)); 313 std::move(event_queue_.back()->event), ui::Event::Clone(event));
309 event_queue_.back()->display_id = display_id; 314 event_queue_.back()->display_id = display_id;
310 return; 315 return;
311 } 316 }
312 QueueEvent(event, nullptr, display_id); 317 QueueEvent(event, nullptr, display_id);
313 return; 318 return;
314 } 319 }
315 320
316 ProcessEventImpl(event, display_id); 321 ProcessEventImpl(event, display_id);
317 } 322 }
318 323
319 void WindowManagerState::OnAcceleratorAck( 324 void WindowManagerState::OnAcceleratorAck(
320 mojom::EventResult result, 325 mojom::EventResult result,
321 const std::unordered_map<std::string, std::vector<uint8_t>>& properties) { 326 const std::unordered_map<std::string, std::vector<uint8_t>>& properties) {
322 DCHECK(in_flight_event_details_); 327 DCHECK(in_flight_event_dispatch_details_);
323 DCHECK_EQ(EventDispatchPhase::PRE_TARGET_ACCELERATOR, 328 DCHECK_EQ(EventDispatchPhase::PRE_TARGET_ACCELERATOR,
324 in_flight_event_details_->phase); 329 in_flight_event_dispatch_details_->phase);
325 330
326 std::unique_ptr<InFlightEventDetails> details = 331 std::unique_ptr<InFlightEventDispatchDetails> details =
327 std::move(in_flight_event_details_); 332 std::move(in_flight_event_dispatch_details_);
328 333
329 if (result == mojom::EventResult::UNHANDLED) { 334 if (result == mojom::EventResult::UNHANDLED) {
330 DCHECK(details->event->IsKeyEvent()); 335 DCHECK(details->event->IsKeyEvent());
331 if (!properties.empty()) 336 if (!properties.empty())
332 details->event->AsKeyEvent()->SetProperties(properties); 337 details->event->AsKeyEvent()->SetProperties(properties);
333 event_dispatcher_.ProcessEvent( 338 event_dispatcher_.ProcessEvent(
334 *details->event, details->display_id, 339 *details->event, details->display_id,
335 EventDispatcher::AcceleratorMatchPhase::POST_ONLY); 340 EventDispatcher::AcceleratorMatchPhase::POST_ONLY);
336 } else { 341 } else {
337 // We're not going to process the event any further, notify event observers. 342 // We're not going to process the event any further, notify event observers.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 for (auto& display_root_ptr : window_manager_display_roots_) { 396 for (auto& display_root_ptr : window_manager_display_roots_) {
392 if (display_root_ptr->root()->parent() == window) 397 if (display_root_ptr->root()->parent() == window)
393 return display_root_ptr->GetClientVisibleRoot(); 398 return display_root_ptr->GetClientVisibleRoot();
394 } 399 }
395 NOTREACHED(); 400 NOTREACHED();
396 return nullptr; 401 return nullptr;
397 } 402 }
398 403
399 void WindowManagerState::OnEventAck(mojom::WindowTree* tree, 404 void WindowManagerState::OnEventAck(mojom::WindowTree* tree,
400 mojom::EventResult result) { 405 mojom::EventResult result) {
401 DCHECK(in_flight_event_details_); 406 DCHECK(in_flight_event_dispatch_details_);
402 std::unique_ptr<InFlightEventDetails> details = 407 std::unique_ptr<InFlightEventDispatchDetails> details =
403 std::move(in_flight_event_details_); 408 std::move(in_flight_event_dispatch_details_);
404 409
405 if (result == mojom::EventResult::UNHANDLED && 410 if (result == mojom::EventResult::UNHANDLED &&
406 details->post_target_accelerator) { 411 details->post_target_accelerator) {
407 OnAccelerator(details->post_target_accelerator->id(), details->display_id, 412 OnAccelerator(details->post_target_accelerator->id(), details->display_id,
408 *details->event, AcceleratorPhase::POST); 413 *details->event, AcceleratorPhase::POST);
409 } 414 }
410 415
411 ProcessNextEventFromQueue(); 416 ProcessNextEventFromQueue();
412 } 417 }
413 418
414 void WindowManagerState::OnEventAckTimeout(ClientSpecificId client_id) { 419 void WindowManagerState::OnEventAckTimeout(ClientSpecificId client_id) {
415 WindowTree* hung_tree = window_server()->GetTreeWithId(client_id); 420 WindowTree* hung_tree = window_server()->GetTreeWithId(client_id);
416 if (hung_tree && !hung_tree->janky()) 421 if (hung_tree && !hung_tree->janky())
417 window_tree_->ClientJankinessChanged(hung_tree); 422 window_tree_->ClientJankinessChanged(hung_tree);
418 if (in_flight_event_details_->phase == 423 if (in_flight_event_dispatch_details_->phase ==
419 EventDispatchPhase::PRE_TARGET_ACCELERATOR) { 424 EventDispatchPhase::PRE_TARGET_ACCELERATOR) {
420 OnAcceleratorAck(mojom::EventResult::UNHANDLED, KeyEvent::Properties()); 425 OnAcceleratorAck(mojom::EventResult::UNHANDLED, KeyEvent::Properties());
421 } else { 426 } else {
422 OnEventAck(in_flight_event_details_->tree, mojom::EventResult::UNHANDLED); 427 OnEventAck(in_flight_event_dispatch_details_->tree,
428 mojom::EventResult::UNHANDLED);
423 } 429 }
424 } 430 }
425 431
426 void WindowManagerState::ProcessEventImpl(const ui::Event& event, 432 void WindowManagerState::ProcessEventImpl(const ui::Event& event,
427 int64_t display_id) { 433 int64_t display_id) {
434 DCHECK(!in_flight_event_dispatch_details_ &&
435 !event_dispatcher_.event_targeter()->IsHitTestInFlight());
428 // Debug accelerators are always checked and don't interfere with processing. 436 // Debug accelerators are always checked and don't interfere with processing.
429 ProcessDebugAccelerator(event, display_id); 437 ProcessDebugAccelerator(event, display_id);
430 event_dispatcher_.ProcessEvent(event, display_id, 438 event_dispatcher_.ProcessEvent(event, display_id,
431 EventDispatcher::AcceleratorMatchPhase::ANY); 439 EventDispatcher::AcceleratorMatchPhase::ANY);
432 } 440 }
433 441
434 void WindowManagerState::QueueEvent( 442 void WindowManagerState::QueueEvent(
435 const ui::Event& event, 443 const ui::Event& event,
436 std::unique_ptr<ProcessedEventTarget> processed_event_target, 444 std::unique_ptr<ProcessedEventTarget> processed_event_target,
437 int64_t display_id) { 445 int64_t display_id) {
438 std::unique_ptr<QueuedEvent> queued_event(new QueuedEvent); 446 std::unique_ptr<QueuedEvent> queued_event(new QueuedEvent);
439 queued_event->event = ui::Event::Clone(event); 447 queued_event->event = ui::Event::Clone(event);
440 queued_event->processed_target = std::move(processed_event_target); 448 queued_event->processed_target = std::move(processed_event_target);
441 queued_event->display_id = display_id; 449 queued_event->display_id = display_id;
442 event_queue_.push(std::move(queued_event)); 450 event_queue_.push(std::move(queued_event));
443 } 451 }
444 452
445 void WindowManagerState::ProcessNextEventFromQueue() { 453 // TODO(riajiang): We might want to do event targeting for the next event while
446 // Loop through |event_queue_| stopping after dispatching the first valid 454 // waiting for the current event to be dispatched. crbug.com/724521
447 // event.
448 while (!event_queue_.empty()) {
449 std::unique_ptr<QueuedEvent> queued_event = std::move(event_queue_.front());
450 event_queue_.pop();
451 if (!queued_event->processed_target) {
452 ProcessEventImpl(*queued_event->event, queued_event->display_id);
453 return;
454 }
455 if (queued_event->processed_target->IsValid()) {
456 DispatchInputEventToWindowImpl(
457 queued_event->processed_target->window(),
458 queued_event->processed_target->client_id(), queued_event->display_id,
459 *queued_event->event, queued_event->processed_target->accelerator());
460 return;
461 }
462 }
463 }
464
465 void WindowManagerState::DispatchInputEventToWindowImpl( 455 void WindowManagerState::DispatchInputEventToWindowImpl(
466 ServerWindow* target, 456 ServerWindow* target,
467 ClientSpecificId client_id, 457 ClientSpecificId client_id,
468 const int64_t display_id, 458 const int64_t display_id,
469 const ui::Event& event, 459 const ui::Event& event,
470 base::WeakPtr<Accelerator> accelerator) { 460 base::WeakPtr<Accelerator> accelerator) {
461 DCHECK(!in_flight_event_dispatch_details_);
471 DCHECK(target); 462 DCHECK(target);
472 if (target->parent() == nullptr) 463 if (target->parent() == nullptr)
473 target = GetWindowManagerRootForDisplayRoot(target); 464 target = GetWindowManagerRootForDisplayRoot(target);
474 465
475 if (event.IsMousePointerEvent()) { 466 if (event.IsMousePointerEvent()) {
476 DCHECK(event_dispatcher_.mouse_cursor_source_window()); 467 DCHECK(event_dispatcher_.mouse_cursor_source_window());
477 UpdateNativeCursorFromDispatcher(); 468 UpdateNativeCursorFromDispatcher();
478 } 469 }
479 470
480 WindowTree* tree = window_server()->GetTreeWithId(client_id); 471 WindowTree* tree = window_server()->GetTreeWithId(client_id);
481 DCHECK(tree); 472 DCHECK(tree);
482 ScheduleInputEventTimeout(tree, target, display_id, event, 473 ScheduleInputEventTimeout(tree, target, display_id, event,
483 EventDispatchPhase::TARGET); 474 EventDispatchPhase::TARGET);
484 in_flight_event_details_->post_target_accelerator = accelerator; 475 in_flight_event_dispatch_details_->post_target_accelerator = accelerator;
485 476
486 // Ignore |tree| because it will receive the event via normal dispatch. 477 // Ignore |tree| because it will receive the event via normal dispatch.
487 window_server()->SendToPointerWatchers(event, user_id(), target, tree, 478 window_server()->SendToPointerWatchers(
488 in_flight_event_details_->display_id); 479 event, user_id(), target, tree,
480 in_flight_event_dispatch_details_->display_id);
489 481
490 tree->DispatchInputEvent( 482 tree->DispatchInputEvent(
491 target, event, 483 target, event,
492 base::BindOnce(&WindowManagerState::OnEventAck, 484 base::BindOnce(
493 in_flight_event_details_->weak_factory.GetWeakPtr(), 485 &WindowManagerState::OnEventAck,
494 tree)); 486 in_flight_event_dispatch_details_->weak_factory.GetWeakPtr(), tree));
495 } 487 }
496 488
497 void WindowManagerState::AddDebugAccelerators() { 489 void WindowManagerState::AddDebugAccelerators() {
498 const DebugAccelerator accelerator = { 490 const DebugAccelerator accelerator = {
499 DebugAcceleratorType::PRINT_WINDOWS, ui::VKEY_S, 491 DebugAcceleratorType::PRINT_WINDOWS, ui::VKEY_S,
500 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN}; 492 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN};
501 debug_accelerators_.push_back(accelerator); 493 debug_accelerators_.push_back(accelerator);
502 } 494 }
503 495
504 void WindowManagerState::ProcessDebugAccelerator(const ui::Event& event, 496 void WindowManagerState::ProcessDebugAccelerator(const ui::Event& event,
(...skipping 26 matching lines...) Expand all
531 LOG(ERROR) << "Focused window: " 523 LOG(ERROR) << "Focused window: "
532 << (focused_window ? focused_window->id().ToString() : "(null)"); 524 << (focused_window ? focused_window->id().ToString() : "(null)");
533 #endif 525 #endif
534 } 526 }
535 527
536 void WindowManagerState::ScheduleInputEventTimeout(WindowTree* tree, 528 void WindowManagerState::ScheduleInputEventTimeout(WindowTree* tree,
537 ServerWindow* target, 529 ServerWindow* target,
538 const int64_t display_id, 530 const int64_t display_id,
539 const Event& event, 531 const Event& event,
540 EventDispatchPhase phase) { 532 EventDispatchPhase phase) {
541 std::unique_ptr<InFlightEventDetails> details = 533 std::unique_ptr<InFlightEventDispatchDetails> details =
542 base::MakeUnique<InFlightEventDetails>(this, tree, display_id, event, 534 base::MakeUnique<InFlightEventDispatchDetails>(this, tree, display_id,
543 phase); 535 event, phase);
544 536
545 // TOOD(sad): Adjust this delay, possibly make this dynamic. 537 // TOOD(sad): Adjust this delay, possibly make this dynamic.
546 const base::TimeDelta max_delay = base::debug::BeingDebugged() 538 const base::TimeDelta max_delay = base::debug::BeingDebugged()
547 ? base::TimeDelta::FromDays(1) 539 ? base::TimeDelta::FromDays(1)
548 : GetDefaultAckTimerDelay(); 540 : GetDefaultAckTimerDelay();
549 details->timer.Start( 541 details->timer.Start(
550 FROM_HERE, max_delay, 542 FROM_HERE, max_delay,
551 base::Bind(&WindowManagerState::OnEventAckTimeout, 543 base::Bind(&WindowManagerState::OnEventAckTimeout,
552 details->weak_factory.GetWeakPtr(), tree->id())); 544 details->weak_factory.GetWeakPtr(), tree->id()));
553 in_flight_event_details_ = std::move(details); 545 in_flight_event_dispatch_details_ = std::move(details);
554 } 546 }
555 547
556 bool WindowManagerState::ConvertPointToScreen(const int64_t display_id, 548 bool WindowManagerState::ConvertPointToScreen(const int64_t display_id,
557 gfx::Point* point) { 549 gfx::Point* point) {
558 Display* display = display_manager()->GetDisplayById(display_id); 550 Display* display = display_manager()->GetDisplayById(display_id);
559 if (display) { 551 if (display) {
560 const display::Display& originated_display = display->GetDisplay(); 552 const display::Display& originated_display = display->GetDisplay();
561 *point = gfx::ConvertPointToDIP(originated_display.device_scale_factor(), 553 *point = gfx::ConvertPointToDIP(originated_display.device_scale_factor(),
562 *point); 554 *point);
563 *point += originated_display.bounds().origin().OffsetFromOrigin(); 555 *point += originated_display.bounds().origin().OffsetFromOrigin();
564 return true; 556 return true;
565 } 557 }
566 return false; 558 return false;
567 } 559 }
568 560
569 //////////////////////////////////////////////////////////////////////////////// 561 ////////////////////////////////////////////////////////////////////////////////
570 // EventDispatcherDelegate: 562 // EventDispatcherDelegate:
571 563
572 void WindowManagerState::OnAccelerator(uint32_t accelerator_id, 564 void WindowManagerState::OnAccelerator(uint32_t accelerator_id,
573 const int64_t display_id, 565 const int64_t display_id,
574 const ui::Event& event, 566 const ui::Event& event,
575 AcceleratorPhase phase) { 567 AcceleratorPhase phase) {
576 DCHECK(IsActive()); 568 DCHECK(IsActive());
577 const bool needs_ack = phase == AcceleratorPhase::PRE; 569 const bool needs_ack = phase == AcceleratorPhase::PRE;
578 WindowTree::AcceleratorCallback ack_callback; 570 WindowTree::AcceleratorCallback ack_callback;
579 if (needs_ack) { 571 if (needs_ack) {
580 DCHECK(!in_flight_event_details_); 572 DCHECK(!in_flight_event_dispatch_details_);
581 ScheduleInputEventTimeout(window_tree_, nullptr, display_id, event, 573 ScheduleInputEventTimeout(window_tree_, nullptr, display_id, event,
582 EventDispatchPhase::PRE_TARGET_ACCELERATOR); 574 EventDispatchPhase::PRE_TARGET_ACCELERATOR);
583 ack_callback = 575 ack_callback = base::BindOnce(
584 base::BindOnce(&WindowManagerState::OnAcceleratorAck, 576 &WindowManagerState::OnAcceleratorAck,
585 in_flight_event_details_->weak_factory.GetWeakPtr()); 577 in_flight_event_dispatch_details_->weak_factory.GetWeakPtr());
586 } 578 }
587 window_tree_->OnAccelerator(accelerator_id, event, std::move(ack_callback)); 579 window_tree_->OnAccelerator(accelerator_id, event, std::move(ack_callback));
588 } 580 }
589 581
590 void WindowManagerState::SetFocusedWindowFromEventDispatcher( 582 void WindowManagerState::SetFocusedWindowFromEventDispatcher(
591 ServerWindow* new_focused_window) { 583 ServerWindow* new_focused_window) {
592 DCHECK(IsActive()); 584 DCHECK(IsActive());
593 window_server()->SetFocusedWindow(new_focused_window); 585 window_server()->SetFocusedWindow(new_focused_window);
594 } 586 }
595 587
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 } 646 }
655 647
656 void WindowManagerState::DispatchInputEventToWindow(ServerWindow* target, 648 void WindowManagerState::DispatchInputEventToWindow(ServerWindow* target,
657 ClientSpecificId client_id, 649 ClientSpecificId client_id,
658 const int64_t display_id, 650 const int64_t display_id,
659 const ui::Event& event, 651 const ui::Event& event,
660 Accelerator* accelerator) { 652 Accelerator* accelerator) {
661 DCHECK(IsActive()); 653 DCHECK(IsActive());
662 // TODO(sky): this needs to see if another wms has capture and if so forward 654 // TODO(sky): this needs to see if another wms has capture and if so forward
663 // to it. 655 // to it.
664 if (in_flight_event_details_) { 656 if (in_flight_event_dispatch_details_) {
665 std::unique_ptr<ProcessedEventTarget> processed_event_target( 657 std::unique_ptr<ProcessedEventTarget> processed_event_target(
666 new ProcessedEventTarget(target, client_id, accelerator)); 658 new ProcessedEventTarget(target, client_id, accelerator));
667 QueueEvent(event, std::move(processed_event_target), display_id); 659 QueueEvent(event, std::move(processed_event_target), display_id);
668 return; 660 return;
669 } 661 }
670 662
671 base::WeakPtr<Accelerator> weak_accelerator; 663 base::WeakPtr<Accelerator> weak_accelerator;
672 if (accelerator) 664 if (accelerator)
673 weak_accelerator = accelerator->GetWeakPtr(); 665 weak_accelerator = accelerator->GetWeakPtr();
674 DispatchInputEventToWindowImpl(target, client_id, display_id, event, 666 DispatchInputEventToWindowImpl(target, client_id, display_id, event,
675 weak_accelerator); 667 weak_accelerator);
676 } 668 }
677 669
670 void WindowManagerState::ProcessNextEventFromQueue() {
671 // Loop through |event_queue_| stopping after dispatching the first valid
672 // event.
673 while (!event_queue_.empty()) {
674 if (in_flight_event_dispatch_details_)
675 return;
676
677 if (!event_queue_.front()->processed_target &&
678 event_dispatcher_.event_targeter()->IsHitTestInFlight())
679 return;
680
681 std::unique_ptr<QueuedEvent> queued_event = std::move(event_queue_.front());
682 event_queue_.pop();
683 if (!queued_event->processed_target) {
684 ProcessEventImpl(*queued_event->event, queued_event->display_id);
685 return;
686 }
687 if (queued_event->processed_target->IsValid()) {
688 DispatchInputEventToWindowImpl(
689 queued_event->processed_target->window(),
690 queued_event->processed_target->client_id(), queued_event->display_id,
691 *queued_event->event, queued_event->processed_target->accelerator());
692 return;
693 }
694 }
695 }
696
678 ClientSpecificId WindowManagerState::GetEventTargetClientId( 697 ClientSpecificId WindowManagerState::GetEventTargetClientId(
679 const ServerWindow* window, 698 const ServerWindow* window,
680 bool in_nonclient_area) { 699 bool in_nonclient_area) {
681 if (in_nonclient_area) { 700 if (in_nonclient_area) {
682 // Events in the non-client area always go to the window manager. 701 // Events in the non-client area always go to the window manager.
683 return window_tree_->id(); 702 return window_tree_->id();
684 } 703 }
685 704
686 // If the window is an embed root, it goes to the tree embedded in the window. 705 // If the window is an embed root, it goes to the tree embedded in the window.
687 WindowTree* tree = window_server()->GetTreeWithRoot(window); 706 WindowTree* tree = window_server()->GetTreeWithRoot(window);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 window->RemoveObserver(this); 779 window->RemoveObserver(this);
761 orphaned_window_manager_display_roots_.erase(iter); 780 orphaned_window_manager_display_roots_.erase(iter);
762 return; 781 return;
763 } 782 }
764 } 783 }
765 NOTREACHED(); 784 NOTREACHED();
766 } 785 }
767 786
768 } // namespace ws 787 } // namespace ws
769 } // namespace ui 788 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698