Index: services/ui/ws/window_manager_state.cc |
diff --git a/services/ui/ws/window_manager_state.cc b/services/ui/ws/window_manager_state.cc |
index 6657f1500c52b9d070a88b1ef07e96d2023a9ba1..5bf4a0a79cab8d52b555c86dfd7b8315445abe28 100644 |
--- a/services/ui/ws/window_manager_state.cc |
+++ b/services/ui/ws/window_manager_state.cc |
@@ -72,7 +72,7 @@ const ServerWindow* GetEmbedRoot(const ServerWindow* window) { |
} // namespace |
-WindowManagerState::InFlightEventDetails::InFlightEventDetails( |
+WindowManagerState::InFlightEventDispatchDetails::InFlightEventDispatchDetails( |
WindowManagerState* window_manager_state, |
WindowTree* tree, |
int64_t display_id, |
@@ -84,7 +84,8 @@ WindowManagerState::InFlightEventDetails::InFlightEventDetails( |
phase(phase), |
weak_factory(window_manager_state) {} |
-WindowManagerState::InFlightEventDetails::~InFlightEventDetails() {} |
+WindowManagerState::InFlightEventDispatchDetails:: |
+ ~InFlightEventDispatchDetails() {} |
class WindowManagerState::ProcessedEventTarget { |
public: |
@@ -192,10 +193,11 @@ void WindowManagerState::SetDragDropSourceWindow( |
const std::unordered_map<std::string, std::vector<uint8_t>>& drag_data, |
uint32_t drag_operation) { |
int32_t drag_pointer = MouseEvent::kMousePointerId; |
- if (in_flight_event_details_ && |
- in_flight_event_details_->event->IsPointerEvent()) { |
- drag_pointer = |
- in_flight_event_details_->event->AsPointerEvent()->pointer_details().id; |
+ if (in_flight_event_dispatch_details_ && |
+ in_flight_event_dispatch_details_->event->IsPointerEvent()) { |
+ drag_pointer = in_flight_event_dispatch_details_->event->AsPointerEvent() |
+ ->pointer_details() |
+ .id; |
} else { |
NOTIMPLEMENTED() << "Set drag drop set up during something other than a " |
<< "pointer event; rejecting drag."; |
@@ -250,13 +252,14 @@ const UserId& WindowManagerState::user_id() const { |
void WindowManagerState::OnWillDestroyTree(WindowTree* tree) { |
event_dispatcher_.OnWillDestroyDragTargetConnection(tree); |
- if (!in_flight_event_details_ || in_flight_event_details_->tree != tree) |
+ if (!in_flight_event_dispatch_details_ || |
+ in_flight_event_dispatch_details_->tree != tree) |
return; |
// The WindowTree is dying. So it's not going to ack the event. |
// If the dying tree matches the root |tree_| mark as handled so we don't |
// notify it of accelerators. |
- OnEventAck(in_flight_event_details_->tree, |
+ OnEventAck(in_flight_event_dispatch_details_->tree, |
tree == window_tree_ ? mojom::EventResult::HANDLED |
: mojom::EventResult::UNHANDLED); |
} |
@@ -292,7 +295,8 @@ void WindowManagerState::ProcessEvent(const ui::Event& event, |
int64_t display_id) { |
// If this is still waiting for an ack from a previously sent event, then |
// queue up the event to be dispatched once the ack is received. |
- if (in_flight_event_details_) { |
+ if (event_dispatcher_.IsHitTestInFlight() || |
+ in_flight_event_dispatch_details_) { |
if (!event_queue_.empty() && !event_queue_.back()->processed_target && |
EventsCanBeCoalesced(*event_queue_.back()->event, event)) { |
event_queue_.back()->event = CoalesceEvents( |
@@ -310,12 +314,12 @@ void WindowManagerState::ProcessEvent(const ui::Event& event, |
void WindowManagerState::OnAcceleratorAck( |
mojom::EventResult result, |
const std::unordered_map<std::string, std::vector<uint8_t>>& properties) { |
- DCHECK(in_flight_event_details_); |
+ DCHECK(in_flight_event_dispatch_details_); |
DCHECK_EQ(EventDispatchPhase::PRE_TARGET_ACCELERATOR, |
- in_flight_event_details_->phase); |
+ in_flight_event_dispatch_details_->phase); |
- std::unique_ptr<InFlightEventDetails> details = |
- std::move(in_flight_event_details_); |
+ std::unique_ptr<InFlightEventDispatchDetails> details = |
+ std::move(in_flight_event_dispatch_details_); |
if (result == mojom::EventResult::UNHANDLED) { |
DCHECK(details->event->IsKeyEvent()); |
@@ -389,9 +393,9 @@ ServerWindow* WindowManagerState::GetWindowManagerRootForDisplayRoot( |
void WindowManagerState::OnEventAck(mojom::WindowTree* tree, |
mojom::EventResult result) { |
- DCHECK(in_flight_event_details_); |
- std::unique_ptr<InFlightEventDetails> details = |
- std::move(in_flight_event_details_); |
+ DCHECK(in_flight_event_dispatch_details_); |
+ std::unique_ptr<InFlightEventDispatchDetails> details = |
+ std::move(in_flight_event_dispatch_details_); |
if (result == mojom::EventResult::UNHANDLED && |
details->post_target_accelerator) { |
@@ -406,16 +410,19 @@ void WindowManagerState::OnEventAckTimeout(ClientSpecificId client_id) { |
WindowTree* hung_tree = window_server()->GetTreeWithId(client_id); |
if (hung_tree && !hung_tree->janky()) |
window_tree_->ClientJankinessChanged(hung_tree); |
- if (in_flight_event_details_->phase == |
+ if (in_flight_event_dispatch_details_->phase == |
EventDispatchPhase::PRE_TARGET_ACCELERATOR) { |
OnAcceleratorAck(mojom::EventResult::UNHANDLED, KeyEvent::Properties()); |
} else { |
- OnEventAck(in_flight_event_details_->tree, mojom::EventResult::UNHANDLED); |
+ OnEventAck(in_flight_event_dispatch_details_->tree, |
+ mojom::EventResult::UNHANDLED); |
} |
} |
void WindowManagerState::ProcessEventImpl(const ui::Event& event, |
int64_t display_id) { |
+ DCHECK(!in_flight_event_dispatch_details_ && |
+ !event_dispatcher_.IsHitTestInFlight()); |
// Debug accelerators are always checked and don't interfere with processing. |
ProcessDebugAccelerator(event); |
event_processing_display_id_ = display_id; |
@@ -434,31 +441,14 @@ void WindowManagerState::QueueEvent( |
event_queue_.push(std::move(queued_event)); |
} |
-void WindowManagerState::ProcessNextEventFromQueue() { |
- // Loop through |event_queue_| stopping after dispatching the first valid |
- // event. |
- while (!event_queue_.empty()) { |
- std::unique_ptr<QueuedEvent> queued_event = std::move(event_queue_.front()); |
- event_queue_.pop(); |
- if (!queued_event->processed_target) { |
- ProcessEventImpl(*queued_event->event, queued_event->display_id); |
- return; |
- } |
- if (queued_event->processed_target->IsValid()) { |
- DispatchInputEventToWindowImpl( |
- queued_event->processed_target->window(), |
- queued_event->processed_target->client_id(), *queued_event->event, |
- queued_event->processed_target->accelerator()); |
- return; |
- } |
- } |
-} |
- |
+// TODO(riajiang): We might want to do event targeting for the next event while |
+// waiting for the current event to be dispatched. crbug.com/724521 |
void WindowManagerState::DispatchInputEventToWindowImpl( |
ServerWindow* target, |
ClientSpecificId client_id, |
const ui::Event& event, |
base::WeakPtr<Accelerator> accelerator) { |
+ DCHECK(!in_flight_event_dispatch_details_); |
DCHECK(target); |
if (target->parent() == nullptr) |
target = GetWindowManagerRootForDisplayRoot(target); |
@@ -471,17 +461,18 @@ void WindowManagerState::DispatchInputEventToWindowImpl( |
WindowTree* tree = window_server()->GetTreeWithId(client_id); |
DCHECK(tree); |
ScheduleInputEventTimeout(tree, target, event, EventDispatchPhase::TARGET); |
- in_flight_event_details_->post_target_accelerator = accelerator; |
+ in_flight_event_dispatch_details_->post_target_accelerator = accelerator; |
// Ignore |tree| because it will receive the event via normal dispatch. |
- window_server()->SendToPointerWatchers(event, user_id(), target, tree, |
- in_flight_event_details_->display_id); |
+ window_server()->SendToPointerWatchers( |
+ event, user_id(), target, tree, |
+ in_flight_event_dispatch_details_->display_id); |
tree->DispatchInputEvent( |
target, event, |
- base::BindOnce(&WindowManagerState::OnEventAck, |
- in_flight_event_details_->weak_factory.GetWeakPtr(), |
- tree)); |
+ base::BindOnce( |
+ &WindowManagerState::OnEventAck, |
+ in_flight_event_dispatch_details_->weak_factory.GetWeakPtr(), tree)); |
} |
void WindowManagerState::AddDebugAccelerators() { |
@@ -525,8 +516,8 @@ void WindowManagerState::ScheduleInputEventTimeout(WindowTree* tree, |
ServerWindow* target, |
const Event& event, |
EventDispatchPhase phase) { |
- std::unique_ptr<InFlightEventDetails> details = |
- base::MakeUnique<InFlightEventDetails>( |
+ std::unique_ptr<InFlightEventDispatchDetails> details = |
+ base::MakeUnique<InFlightEventDispatchDetails>( |
this, tree, event_processing_display_id_, event, phase); |
// TOOD(sad): Adjust this delay, possibly make this dynamic. |
@@ -537,7 +528,7 @@ void WindowManagerState::ScheduleInputEventTimeout(WindowTree* tree, |
FROM_HERE, max_delay, |
base::Bind(&WindowManagerState::OnEventAckTimeout, |
details->weak_factory.GetWeakPtr(), tree->id())); |
- in_flight_event_details_ = std::move(details); |
+ in_flight_event_dispatch_details_ = std::move(details); |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -550,12 +541,12 @@ void WindowManagerState::OnAccelerator(uint32_t accelerator_id, |
const bool needs_ack = phase == AcceleratorPhase::PRE; |
WindowTree::AcceleratorCallback ack_callback; |
if (needs_ack) { |
- DCHECK(!in_flight_event_details_); |
+ DCHECK(!in_flight_event_dispatch_details_); |
ScheduleInputEventTimeout(window_tree_, nullptr, event, |
EventDispatchPhase::PRE_TARGET_ACCELERATOR); |
- ack_callback = |
- base::BindOnce(&WindowManagerState::OnAcceleratorAck, |
- in_flight_event_details_->weak_factory.GetWeakPtr()); |
+ ack_callback = base::BindOnce( |
+ &WindowManagerState::OnAcceleratorAck, |
+ in_flight_event_dispatch_details_->weak_factory.GetWeakPtr()); |
} |
window_tree_->OnAccelerator(accelerator_id, event, std::move(ack_callback)); |
} |
@@ -625,7 +616,7 @@ void WindowManagerState::DispatchInputEventToWindow(ServerWindow* target, |
DCHECK(IsActive()); |
// TODO(sky): this needs to see if another wms has capture and if so forward |
// to it. |
- if (in_flight_event_details_) { |
+ if (in_flight_event_dispatch_details_) { |
std::unique_ptr<ProcessedEventTarget> processed_event_target( |
new ProcessedEventTarget(target, client_id, accelerator)); |
QueueEvent(event, std::move(processed_event_target), |
@@ -639,6 +630,33 @@ void WindowManagerState::DispatchInputEventToWindow(ServerWindow* target, |
DispatchInputEventToWindowImpl(target, client_id, event, weak_accelerator); |
} |
+void WindowManagerState::ProcessNextEventFromQueue() { |
+ // Loop through |event_queue_| stopping after dispatching the first valid |
+ // event. |
+ while (!event_queue_.empty()) { |
+ if (in_flight_event_dispatch_details_) |
+ return; |
+ |
+ if (!event_queue_.front()->processed_target && |
+ event_dispatcher_.IsHitTestInFlight()) |
+ return; |
+ |
+ std::unique_ptr<QueuedEvent> queued_event = std::move(event_queue_.front()); |
+ event_queue_.pop(); |
+ if (!queued_event->processed_target) { |
+ ProcessEventImpl(*queued_event->event, queued_event->display_id); |
+ return; |
+ } |
+ if (queued_event->processed_target->IsValid()) { |
+ DispatchInputEventToWindowImpl( |
+ queued_event->processed_target->window(), |
+ queued_event->processed_target->client_id(), *queued_event->event, |
+ queued_event->processed_target->accelerator()); |
+ return; |
+ } |
+ } |
+} |
+ |
ClientSpecificId WindowManagerState::GetEventTargetClientId( |
const ServerWindow* window, |
bool in_nonclient_area) { |