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

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

Issue 2884463002: Make event-targeting asynchronous in window server. (Closed)
Patch Set: std::move Created 3 years, 7 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"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 const ServerWindow* GetEmbedRoot(const ServerWindow* window) { 65 const ServerWindow* GetEmbedRoot(const ServerWindow* window) {
66 DCHECK(window); 66 DCHECK(window);
67 const ServerWindow* embed_root = window->parent(); 67 const ServerWindow* embed_root = window->parent();
68 while (embed_root && embed_root->id().client_id == window->id().client_id) 68 while (embed_root && embed_root->id().client_id == window->id().client_id)
69 embed_root = embed_root->parent(); 69 embed_root = embed_root->parent();
70 return embed_root; 70 return embed_root;
71 } 71 }
72 72
73 } // namespace 73 } // namespace
74 74
75 WindowManagerState::InFlightEventDetails::InFlightEventDetails( 75 WindowManagerState::InFlightEventDispatchDetails::InFlightEventDispatchDetails(
76 WindowManagerState* window_manager_state, 76 WindowManagerState* window_manager_state,
77 WindowTree* tree, 77 WindowTree* tree,
78 int64_t display_id, 78 int64_t display_id,
79 const Event& event, 79 const Event& event,
80 EventDispatchPhase phase) 80 EventDispatchPhase phase)
81 : tree(tree), 81 : tree(tree),
82 display_id(display_id), 82 display_id(display_id),
83 event(Event::Clone(event)), 83 event(Event::Clone(event)),
84 phase(phase), 84 phase(phase),
85 weak_factory(window_manager_state) {} 85 weak_factory(window_manager_state) {}
86 86
87 WindowManagerState::InFlightEventDetails::~InFlightEventDetails() {} 87 WindowManagerState::InFlightEventDispatchDetails::
88 ~InFlightEventDispatchDetails() {}
88 89
89 class WindowManagerState::ProcessedEventTarget { 90 class WindowManagerState::ProcessedEventTarget {
90 public: 91 public:
91 ProcessedEventTarget(ServerWindow* window, 92 ProcessedEventTarget(ServerWindow* window,
92 ClientSpecificId client_id, 93 ClientSpecificId client_id,
93 Accelerator* accelerator) 94 Accelerator* accelerator)
94 : client_id_(client_id) { 95 : client_id_(client_id) {
95 tracker_.Add(window); 96 tracker_.Add(window);
96 if (accelerator) 97 if (accelerator)
97 accelerator_ = accelerator->GetWeakPtr(); 98 accelerator_ = accelerator->GetWeakPtr();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 event_dispatcher_.ReleaseCaptureBlockedByAnyModalWindow(); 186 event_dispatcher_.ReleaseCaptureBlockedByAnyModalWindow();
186 } 187 }
187 188
188 void WindowManagerState::SetDragDropSourceWindow( 189 void WindowManagerState::SetDragDropSourceWindow(
189 DragSource* drag_source, 190 DragSource* drag_source,
190 ServerWindow* window, 191 ServerWindow* window,
191 DragTargetConnection* source_connection, 192 DragTargetConnection* source_connection,
192 const std::unordered_map<std::string, std::vector<uint8_t>>& drag_data, 193 const std::unordered_map<std::string, std::vector<uint8_t>>& drag_data,
193 uint32_t drag_operation) { 194 uint32_t drag_operation) {
194 int32_t drag_pointer = MouseEvent::kMousePointerId; 195 int32_t drag_pointer = MouseEvent::kMousePointerId;
195 if (in_flight_event_details_ && 196 if (in_flight_event_dispatch_details_ &&
196 in_flight_event_details_->event->IsPointerEvent()) { 197 in_flight_event_dispatch_details_->event->IsPointerEvent()) {
197 drag_pointer = 198 drag_pointer = in_flight_event_dispatch_details_->event->AsPointerEvent()
198 in_flight_event_details_->event->AsPointerEvent()->pointer_details().id; 199 ->pointer_details()
200 .id;
199 } else { 201 } else {
200 NOTIMPLEMENTED() << "Set drag drop set up during something other than a " 202 NOTIMPLEMENTED() << "Set drag drop set up during something other than a "
201 << "pointer event; rejecting drag."; 203 << "pointer event; rejecting drag.";
202 drag_source->OnDragCompleted(false, ui::mojom::kDropEffectNone); 204 drag_source->OnDragCompleted(false, ui::mojom::kDropEffectNone);
203 return; 205 return;
204 } 206 }
205 207
206 event_dispatcher_.SetDragDropSourceWindow(drag_source, window, 208 event_dispatcher_.SetDragDropSourceWindow(drag_source, window,
207 source_connection, drag_pointer, 209 source_connection, drag_pointer,
208 drag_data, drag_operation); 210 drag_data, drag_operation);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 NOTREACHED(); 245 NOTREACHED();
244 } 246 }
245 247
246 const UserId& WindowManagerState::user_id() const { 248 const UserId& WindowManagerState::user_id() const {
247 return window_tree_->user_id(); 249 return window_tree_->user_id();
248 } 250 }
249 251
250 void WindowManagerState::OnWillDestroyTree(WindowTree* tree) { 252 void WindowManagerState::OnWillDestroyTree(WindowTree* tree) {
251 event_dispatcher_.OnWillDestroyDragTargetConnection(tree); 253 event_dispatcher_.OnWillDestroyDragTargetConnection(tree);
252 254
253 if (!in_flight_event_details_ || in_flight_event_details_->tree != tree) 255 if (!in_flight_event_dispatch_details_ ||
256 in_flight_event_dispatch_details_->tree != tree)
254 return; 257 return;
255 258
256 // The WindowTree is dying. So it's not going to ack the event. 259 // The WindowTree is dying. So it's not going to ack the event.
257 // If the dying tree matches the root |tree_| mark as handled so we don't 260 // If the dying tree matches the root |tree_| mark as handled so we don't
258 // notify it of accelerators. 261 // notify it of accelerators.
259 OnEventAck(in_flight_event_details_->tree, 262 OnEventAck(in_flight_event_dispatch_details_->tree,
260 tree == window_tree_ ? mojom::EventResult::HANDLED 263 tree == window_tree_ ? mojom::EventResult::HANDLED
261 : mojom::EventResult::UNHANDLED); 264 : mojom::EventResult::UNHANDLED);
262 } 265 }
263 266
264 ServerWindow* WindowManagerState::GetOrphanedRootWithId(const WindowId& id) { 267 ServerWindow* WindowManagerState::GetOrphanedRootWithId(const WindowId& id) {
265 for (auto& display_root_ptr : orphaned_window_manager_display_roots_) { 268 for (auto& display_root_ptr : orphaned_window_manager_display_roots_) {
266 if (display_root_ptr->root()->id() == id) 269 if (display_root_ptr->root()->id() == id)
267 return display_root_ptr->root(); 270 return display_root_ptr->root();
268 } 271 }
269 return nullptr; 272 return nullptr;
(...skipping 15 matching lines...) Expand all
285 // The tree is no longer active, so no point in dispatching any further 288 // The tree is no longer active, so no point in dispatching any further
286 // events. 289 // events.
287 std::queue<std::unique_ptr<QueuedEvent>> event_queue; 290 std::queue<std::unique_ptr<QueuedEvent>> event_queue;
288 event_queue.swap(event_queue_); 291 event_queue.swap(event_queue_);
289 } 292 }
290 293
291 void WindowManagerState::ProcessEvent(const ui::Event& event, 294 void WindowManagerState::ProcessEvent(const ui::Event& event,
292 int64_t display_id) { 295 int64_t display_id) {
293 // If this is still waiting for an ack from a previously sent event, then 296 // If this is still waiting for an ack from a previously sent event, then
294 // queue up the event to be dispatched once the ack is received. 297 // queue up the event to be dispatched once the ack is received.
295 if (in_flight_event_details_) { 298 if (event_dispatcher_.IsHitTestInFlight() ||
299 in_flight_event_dispatch_details_) {
296 if (!event_queue_.empty() && !event_queue_.back()->processed_target && 300 if (!event_queue_.empty() && !event_queue_.back()->processed_target &&
297 EventsCanBeCoalesced(*event_queue_.back()->event, event)) { 301 EventsCanBeCoalesced(*event_queue_.back()->event, event)) {
298 event_queue_.back()->event = CoalesceEvents( 302 event_queue_.back()->event = CoalesceEvents(
299 std::move(event_queue_.back()->event), ui::Event::Clone(event)); 303 std::move(event_queue_.back()->event), ui::Event::Clone(event));
300 event_queue_.back()->display_id = display_id; 304 event_queue_.back()->display_id = display_id;
301 return; 305 return;
302 } 306 }
303 QueueEvent(event, nullptr, display_id); 307 QueueEvent(event, nullptr, display_id);
304 return; 308 return;
305 } 309 }
306 310
307 ProcessEventImpl(event, display_id); 311 ProcessEventImpl(event, display_id);
308 } 312 }
309 313
310 void WindowManagerState::OnAcceleratorAck( 314 void WindowManagerState::OnAcceleratorAck(
311 mojom::EventResult result, 315 mojom::EventResult result,
312 const std::unordered_map<std::string, std::vector<uint8_t>>& properties) { 316 const std::unordered_map<std::string, std::vector<uint8_t>>& properties) {
313 DCHECK(in_flight_event_details_); 317 DCHECK(in_flight_event_dispatch_details_);
314 DCHECK_EQ(EventDispatchPhase::PRE_TARGET_ACCELERATOR, 318 DCHECK_EQ(EventDispatchPhase::PRE_TARGET_ACCELERATOR,
315 in_flight_event_details_->phase); 319 in_flight_event_dispatch_details_->phase);
316 320
317 std::unique_ptr<InFlightEventDetails> details = 321 std::unique_ptr<InFlightEventDispatchDetails> details =
318 std::move(in_flight_event_details_); 322 std::move(in_flight_event_dispatch_details_);
319 323
320 if (result == mojom::EventResult::UNHANDLED) { 324 if (result == mojom::EventResult::UNHANDLED) {
321 DCHECK(details->event->IsKeyEvent()); 325 DCHECK(details->event->IsKeyEvent());
322 if (!properties.empty()) 326 if (!properties.empty())
323 details->event->AsKeyEvent()->SetProperties(properties); 327 details->event->AsKeyEvent()->SetProperties(properties);
324 event_processing_display_id_ = details->display_id; 328 event_processing_display_id_ = details->display_id;
325 event_dispatcher_.ProcessEvent( 329 event_dispatcher_.ProcessEvent(
326 *details->event, EventDispatcher::AcceleratorMatchPhase::POST_ONLY); 330 *details->event, EventDispatcher::AcceleratorMatchPhase::POST_ONLY);
327 } else { 331 } else {
328 // We're not going to process the event any further, notify event observers. 332 // 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
382 for (auto& display_root_ptr : window_manager_display_roots_) { 386 for (auto& display_root_ptr : window_manager_display_roots_) {
383 if (display_root_ptr->root()->parent() == window) 387 if (display_root_ptr->root()->parent() == window)
384 return display_root_ptr->GetClientVisibleRoot(); 388 return display_root_ptr->GetClientVisibleRoot();
385 } 389 }
386 NOTREACHED(); 390 NOTREACHED();
387 return nullptr; 391 return nullptr;
388 } 392 }
389 393
390 void WindowManagerState::OnEventAck(mojom::WindowTree* tree, 394 void WindowManagerState::OnEventAck(mojom::WindowTree* tree,
391 mojom::EventResult result) { 395 mojom::EventResult result) {
392 DCHECK(in_flight_event_details_); 396 DCHECK(in_flight_event_dispatch_details_);
393 std::unique_ptr<InFlightEventDetails> details = 397 std::unique_ptr<InFlightEventDispatchDetails> details =
394 std::move(in_flight_event_details_); 398 std::move(in_flight_event_dispatch_details_);
395 399
396 if (result == mojom::EventResult::UNHANDLED && 400 if (result == mojom::EventResult::UNHANDLED &&
397 details->post_target_accelerator) { 401 details->post_target_accelerator) {
398 OnAccelerator(details->post_target_accelerator->id(), *details->event, 402 OnAccelerator(details->post_target_accelerator->id(), *details->event,
399 AcceleratorPhase::POST); 403 AcceleratorPhase::POST);
400 } 404 }
401 405
402 ProcessNextEventFromQueue(); 406 ProcessNextEventFromQueue();
403 } 407 }
404 408
405 void WindowManagerState::OnEventAckTimeout(ClientSpecificId client_id) { 409 void WindowManagerState::OnEventAckTimeout(ClientSpecificId client_id) {
406 WindowTree* hung_tree = window_server()->GetTreeWithId(client_id); 410 WindowTree* hung_tree = window_server()->GetTreeWithId(client_id);
407 if (hung_tree && !hung_tree->janky()) 411 if (hung_tree && !hung_tree->janky())
408 window_tree_->ClientJankinessChanged(hung_tree); 412 window_tree_->ClientJankinessChanged(hung_tree);
409 if (in_flight_event_details_->phase == 413 if (in_flight_event_dispatch_details_->phase ==
410 EventDispatchPhase::PRE_TARGET_ACCELERATOR) { 414 EventDispatchPhase::PRE_TARGET_ACCELERATOR) {
411 OnAcceleratorAck(mojom::EventResult::UNHANDLED, KeyEvent::Properties()); 415 OnAcceleratorAck(mojom::EventResult::UNHANDLED, KeyEvent::Properties());
412 } else { 416 } else {
413 OnEventAck(in_flight_event_details_->tree, mojom::EventResult::UNHANDLED); 417 OnEventAck(in_flight_event_dispatch_details_->tree,
418 mojom::EventResult::UNHANDLED);
414 } 419 }
415 } 420 }
416 421
417 void WindowManagerState::ProcessEventImpl(const ui::Event& event, 422 void WindowManagerState::ProcessEventImpl(const ui::Event& event,
418 int64_t display_id) { 423 int64_t display_id) {
424 DCHECK(!in_flight_event_dispatch_details_ &&
425 !event_dispatcher_.IsHitTestInFlight());
419 // Debug accelerators are always checked and don't interfere with processing. 426 // Debug accelerators are always checked and don't interfere with processing.
420 ProcessDebugAccelerator(event); 427 ProcessDebugAccelerator(event);
421 event_processing_display_id_ = display_id; 428 event_processing_display_id_ = display_id;
422 event_dispatcher_.ProcessEvent(event, 429 event_dispatcher_.ProcessEvent(event,
423 EventDispatcher::AcceleratorMatchPhase::ANY); 430 EventDispatcher::AcceleratorMatchPhase::ANY);
424 } 431 }
425 432
426 void WindowManagerState::QueueEvent( 433 void WindowManagerState::QueueEvent(
427 const ui::Event& event, 434 const ui::Event& event,
428 std::unique_ptr<ProcessedEventTarget> processed_event_target, 435 std::unique_ptr<ProcessedEventTarget> processed_event_target,
429 int64_t display_id) { 436 int64_t display_id) {
430 std::unique_ptr<QueuedEvent> queued_event(new QueuedEvent); 437 std::unique_ptr<QueuedEvent> queued_event(new QueuedEvent);
431 queued_event->event = ui::Event::Clone(event); 438 queued_event->event = ui::Event::Clone(event);
432 queued_event->processed_target = std::move(processed_event_target); 439 queued_event->processed_target = std::move(processed_event_target);
433 queued_event->display_id = display_id; 440 queued_event->display_id = display_id;
434 event_queue_.push(std::move(queued_event)); 441 event_queue_.push(std::move(queued_event));
435 } 442 }
436 443
437 void WindowManagerState::ProcessNextEventFromQueue() { 444 // TODO(riajiang): We might want to do event targeting for the next event while
438 // Loop through |event_queue_| stopping after dispatching the first valid 445 // waiting for the current event to be dispatched. crbug.com/724521
439 // event.
440 while (!event_queue_.empty()) {
441 std::unique_ptr<QueuedEvent> queued_event = std::move(event_queue_.front());
442 event_queue_.pop();
443 if (!queued_event->processed_target) {
444 ProcessEventImpl(*queued_event->event, queued_event->display_id);
445 return;
446 }
447 if (queued_event->processed_target->IsValid()) {
448 DispatchInputEventToWindowImpl(
449 queued_event->processed_target->window(),
450 queued_event->processed_target->client_id(), *queued_event->event,
451 queued_event->processed_target->accelerator());
452 return;
453 }
454 }
455 }
456
457 void WindowManagerState::DispatchInputEventToWindowImpl( 446 void WindowManagerState::DispatchInputEventToWindowImpl(
458 ServerWindow* target, 447 ServerWindow* target,
459 ClientSpecificId client_id, 448 ClientSpecificId client_id,
460 const ui::Event& event, 449 const ui::Event& event,
461 base::WeakPtr<Accelerator> accelerator) { 450 base::WeakPtr<Accelerator> accelerator) {
451 DCHECK(!in_flight_event_dispatch_details_);
462 DCHECK(target); 452 DCHECK(target);
463 if (target->parent() == nullptr) 453 if (target->parent() == nullptr)
464 target = GetWindowManagerRootForDisplayRoot(target); 454 target = GetWindowManagerRootForDisplayRoot(target);
465 455
466 if (event.IsMousePointerEvent()) { 456 if (event.IsMousePointerEvent()) {
467 DCHECK(event_dispatcher_.mouse_cursor_source_window()); 457 DCHECK(event_dispatcher_.mouse_cursor_source_window());
468 UpdateNativeCursorFromDispatcher(); 458 UpdateNativeCursorFromDispatcher();
469 } 459 }
470 460
471 WindowTree* tree = window_server()->GetTreeWithId(client_id); 461 WindowTree* tree = window_server()->GetTreeWithId(client_id);
472 DCHECK(tree); 462 DCHECK(tree);
473 ScheduleInputEventTimeout(tree, target, event, EventDispatchPhase::TARGET); 463 ScheduleInputEventTimeout(tree, target, event, EventDispatchPhase::TARGET);
474 in_flight_event_details_->post_target_accelerator = accelerator; 464 in_flight_event_dispatch_details_->post_target_accelerator = accelerator;
475 465
476 // Ignore |tree| because it will receive the event via normal dispatch. 466 // Ignore |tree| because it will receive the event via normal dispatch.
477 window_server()->SendToPointerWatchers(event, user_id(), target, tree, 467 window_server()->SendToPointerWatchers(
478 in_flight_event_details_->display_id); 468 event, user_id(), target, tree,
469 in_flight_event_dispatch_details_->display_id);
479 470
480 tree->DispatchInputEvent( 471 tree->DispatchInputEvent(
481 target, event, 472 target, event,
482 base::BindOnce(&WindowManagerState::OnEventAck, 473 base::BindOnce(
483 in_flight_event_details_->weak_factory.GetWeakPtr(), 474 &WindowManagerState::OnEventAck,
484 tree)); 475 in_flight_event_dispatch_details_->weak_factory.GetWeakPtr(), tree));
485 } 476 }
486 477
487 void WindowManagerState::AddDebugAccelerators() { 478 void WindowManagerState::AddDebugAccelerators() {
488 const DebugAccelerator accelerator = { 479 const DebugAccelerator accelerator = {
489 DebugAcceleratorType::PRINT_WINDOWS, ui::VKEY_S, 480 DebugAcceleratorType::PRINT_WINDOWS, ui::VKEY_S,
490 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN}; 481 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN};
491 debug_accelerators_.push_back(accelerator); 482 debug_accelerators_.push_back(accelerator);
492 } 483 }
493 484
494 void WindowManagerState::ProcessDebugAccelerator(const ui::Event& event) { 485 void WindowManagerState::ProcessDebugAccelerator(const ui::Event& event) {
(...skipping 23 matching lines...) Expand all
518 ServerWindow* focused_window = GetFocusedWindowForEventDispatcher(); 509 ServerWindow* focused_window = GetFocusedWindowForEventDispatcher();
519 LOG(ERROR) << "Focused window: " 510 LOG(ERROR) << "Focused window: "
520 << (focused_window ? focused_window->id().ToString() : "(null)"); 511 << (focused_window ? focused_window->id().ToString() : "(null)");
521 #endif 512 #endif
522 } 513 }
523 514
524 void WindowManagerState::ScheduleInputEventTimeout(WindowTree* tree, 515 void WindowManagerState::ScheduleInputEventTimeout(WindowTree* tree,
525 ServerWindow* target, 516 ServerWindow* target,
526 const Event& event, 517 const Event& event,
527 EventDispatchPhase phase) { 518 EventDispatchPhase phase) {
528 std::unique_ptr<InFlightEventDetails> details = 519 std::unique_ptr<InFlightEventDispatchDetails> details =
529 base::MakeUnique<InFlightEventDetails>( 520 base::MakeUnique<InFlightEventDispatchDetails>(
530 this, tree, event_processing_display_id_, event, phase); 521 this, tree, event_processing_display_id_, event, phase);
531 522
532 // TOOD(sad): Adjust this delay, possibly make this dynamic. 523 // TOOD(sad): Adjust this delay, possibly make this dynamic.
533 const base::TimeDelta max_delay = base::debug::BeingDebugged() 524 const base::TimeDelta max_delay = base::debug::BeingDebugged()
534 ? base::TimeDelta::FromDays(1) 525 ? base::TimeDelta::FromDays(1)
535 : GetDefaultAckTimerDelay(); 526 : GetDefaultAckTimerDelay();
536 details->timer.Start( 527 details->timer.Start(
537 FROM_HERE, max_delay, 528 FROM_HERE, max_delay,
538 base::Bind(&WindowManagerState::OnEventAckTimeout, 529 base::Bind(&WindowManagerState::OnEventAckTimeout,
539 details->weak_factory.GetWeakPtr(), tree->id())); 530 details->weak_factory.GetWeakPtr(), tree->id()));
540 in_flight_event_details_ = std::move(details); 531 in_flight_event_dispatch_details_ = std::move(details);
541 } 532 }
542 533
543 //////////////////////////////////////////////////////////////////////////////// 534 ////////////////////////////////////////////////////////////////////////////////
544 // EventDispatcherDelegate: 535 // EventDispatcherDelegate:
545 536
546 void WindowManagerState::OnAccelerator(uint32_t accelerator_id, 537 void WindowManagerState::OnAccelerator(uint32_t accelerator_id,
547 const ui::Event& event, 538 const ui::Event& event,
548 AcceleratorPhase phase) { 539 AcceleratorPhase phase) {
549 DCHECK(IsActive()); 540 DCHECK(IsActive());
550 const bool needs_ack = phase == AcceleratorPhase::PRE; 541 const bool needs_ack = phase == AcceleratorPhase::PRE;
551 WindowTree::AcceleratorCallback ack_callback; 542 WindowTree::AcceleratorCallback ack_callback;
552 if (needs_ack) { 543 if (needs_ack) {
553 DCHECK(!in_flight_event_details_); 544 DCHECK(!in_flight_event_dispatch_details_);
554 ScheduleInputEventTimeout(window_tree_, nullptr, event, 545 ScheduleInputEventTimeout(window_tree_, nullptr, event,
555 EventDispatchPhase::PRE_TARGET_ACCELERATOR); 546 EventDispatchPhase::PRE_TARGET_ACCELERATOR);
556 ack_callback = 547 ack_callback = base::BindOnce(
557 base::BindOnce(&WindowManagerState::OnAcceleratorAck, 548 &WindowManagerState::OnAcceleratorAck,
558 in_flight_event_details_->weak_factory.GetWeakPtr()); 549 in_flight_event_dispatch_details_->weak_factory.GetWeakPtr());
559 } 550 }
560 window_tree_->OnAccelerator(accelerator_id, event, std::move(ack_callback)); 551 window_tree_->OnAccelerator(accelerator_id, event, std::move(ack_callback));
561 } 552 }
562 553
563 void WindowManagerState::SetFocusedWindowFromEventDispatcher( 554 void WindowManagerState::SetFocusedWindowFromEventDispatcher(
564 ServerWindow* new_focused_window) { 555 ServerWindow* new_focused_window) {
565 DCHECK(IsActive()); 556 DCHECK(IsActive());
566 window_server()->SetFocusedWindow(new_focused_window); 557 window_server()->SetFocusedWindow(new_focused_window);
567 } 558 }
568 559
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 ->OnMouseCursorLocationChanged(point); 609 ->OnMouseCursorLocationChanged(point);
619 } 610 }
620 611
621 void WindowManagerState::DispatchInputEventToWindow(ServerWindow* target, 612 void WindowManagerState::DispatchInputEventToWindow(ServerWindow* target,
622 ClientSpecificId client_id, 613 ClientSpecificId client_id,
623 const ui::Event& event, 614 const ui::Event& event,
624 Accelerator* accelerator) { 615 Accelerator* accelerator) {
625 DCHECK(IsActive()); 616 DCHECK(IsActive());
626 // TODO(sky): this needs to see if another wms has capture and if so forward 617 // TODO(sky): this needs to see if another wms has capture and if so forward
627 // to it. 618 // to it.
628 if (in_flight_event_details_) { 619 if (in_flight_event_dispatch_details_) {
629 std::unique_ptr<ProcessedEventTarget> processed_event_target( 620 std::unique_ptr<ProcessedEventTarget> processed_event_target(
630 new ProcessedEventTarget(target, client_id, accelerator)); 621 new ProcessedEventTarget(target, client_id, accelerator));
631 QueueEvent(event, std::move(processed_event_target), 622 QueueEvent(event, std::move(processed_event_target),
632 event_processing_display_id_); 623 event_processing_display_id_);
633 return; 624 return;
634 } 625 }
635 626
636 base::WeakPtr<Accelerator> weak_accelerator; 627 base::WeakPtr<Accelerator> weak_accelerator;
637 if (accelerator) 628 if (accelerator)
638 weak_accelerator = accelerator->GetWeakPtr(); 629 weak_accelerator = accelerator->GetWeakPtr();
639 DispatchInputEventToWindowImpl(target, client_id, event, weak_accelerator); 630 DispatchInputEventToWindowImpl(target, client_id, event, weak_accelerator);
640 } 631 }
641 632
633 void WindowManagerState::ProcessNextEventFromQueue() {
634 // Loop through |event_queue_| stopping after dispatching the first valid
635 // event.
636 while (!event_queue_.empty()) {
637 if (in_flight_event_dispatch_details_)
638 return;
639
640 if (!event_queue_.front()->processed_target &&
641 event_dispatcher_.IsHitTestInFlight())
642 return;
643
644 std::unique_ptr<QueuedEvent> queued_event = std::move(event_queue_.front());
645 event_queue_.pop();
646 if (!queued_event->processed_target) {
647 ProcessEventImpl(*queued_event->event, queued_event->display_id);
648 return;
649 }
650 if (queued_event->processed_target->IsValid()) {
651 DispatchInputEventToWindowImpl(
652 queued_event->processed_target->window(),
653 queued_event->processed_target->client_id(), *queued_event->event,
654 queued_event->processed_target->accelerator());
655 return;
656 }
657 }
658 }
659
642 ClientSpecificId WindowManagerState::GetEventTargetClientId( 660 ClientSpecificId WindowManagerState::GetEventTargetClientId(
643 const ServerWindow* window, 661 const ServerWindow* window,
644 bool in_nonclient_area) { 662 bool in_nonclient_area) {
645 if (in_nonclient_area) { 663 if (in_nonclient_area) {
646 // Events in the non-client area always go to the window manager. 664 // Events in the non-client area always go to the window manager.
647 return window_tree_->id(); 665 return window_tree_->id();
648 } 666 }
649 667
650 // If the window is an embed root, it goes to the tree embedded in the window. 668 // If the window is an embed root, it goes to the tree embedded in the window.
651 WindowTree* tree = window_server()->GetTreeWithRoot(window); 669 WindowTree* tree = window_server()->GetTreeWithRoot(window);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 window->RemoveObserver(this); 731 window->RemoveObserver(this);
714 orphaned_window_manager_display_roots_.erase(iter); 732 orphaned_window_manager_display_roots_.erase(iter);
715 return; 733 return;
716 } 734 }
717 } 735 }
718 NOTREACHED(); 736 NOTREACHED();
719 } 737 }
720 738
721 } // namespace ws 739 } // namespace ws
722 } // namespace ui 740 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698