| 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 a36a9b1f252662b0457bd0507bbff40b44787f85..c522654a1cee8049c846f72afc65e906362e25ac 100644
|
| --- a/services/ui/ws/window_manager_state.cc
|
| +++ b/services/ui/ws/window_manager_state.cc
|
| @@ -15,6 +15,7 @@
|
| #include "services/ui/ws/display.h"
|
| #include "services/ui/ws/display_creation_config.h"
|
| #include "services/ui/ws/display_manager.h"
|
| +#include "services/ui/ws/event_targeter.h"
|
| #include "services/ui/ws/platform_display.h"
|
| #include "services/ui/ws/server_window.h"
|
| #include "services/ui/ws/user_display_manager.h"
|
| @@ -74,7 +75,7 @@ const ServerWindow* GetEmbedRoot(const ServerWindow* window) {
|
|
|
| } // namespace
|
|
|
| -WindowManagerState::InFlightEventDetails::InFlightEventDetails(
|
| +WindowManagerState::InFlightEventDispatchDetails::InFlightEventDispatchDetails(
|
| WindowManagerState* window_manager_state,
|
| WindowTree* tree,
|
| int64_t display_id,
|
| @@ -86,7 +87,8 @@ WindowManagerState::InFlightEventDetails::InFlightEventDetails(
|
| phase(phase),
|
| weak_factory(window_manager_state) {}
|
|
|
| -WindowManagerState::InFlightEventDetails::~InFlightEventDetails() {}
|
| +WindowManagerState::InFlightEventDispatchDetails::
|
| + ~InFlightEventDispatchDetails() {}
|
|
|
| class WindowManagerState::ProcessedEventTarget {
|
| public:
|
| @@ -199,10 +201,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.";
|
| @@ -257,13 +260,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);
|
| }
|
| @@ -301,7 +305,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_.event_targeter()->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(
|
| @@ -319,12 +324,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());
|
| @@ -398,9 +403,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) {
|
| @@ -415,16 +420,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_.event_targeter()->IsHitTestInFlight());
|
| // Debug accelerators are always checked and don't interfere with processing.
|
| ProcessDebugAccelerator(event, display_id);
|
| event_dispatcher_.ProcessEvent(event, display_id,
|
| @@ -442,32 +450,15 @@ 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->display_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 int64_t display_id,
|
| const ui::Event& event,
|
| base::WeakPtr<Accelerator> accelerator) {
|
| + DCHECK(!in_flight_event_dispatch_details_);
|
| DCHECK(target);
|
| if (target->parent() == nullptr)
|
| target = GetWindowManagerRootForDisplayRoot(target);
|
| @@ -481,17 +472,18 @@ void WindowManagerState::DispatchInputEventToWindowImpl(
|
| DCHECK(tree);
|
| ScheduleInputEventTimeout(tree, target, display_id, 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() {
|
| @@ -538,9 +530,9 @@ void WindowManagerState::ScheduleInputEventTimeout(WindowTree* tree,
|
| const int64_t display_id,
|
| const Event& event,
|
| EventDispatchPhase phase) {
|
| - std::unique_ptr<InFlightEventDetails> details =
|
| - base::MakeUnique<InFlightEventDetails>(this, tree, display_id, event,
|
| - phase);
|
| + std::unique_ptr<InFlightEventDispatchDetails> details =
|
| + base::MakeUnique<InFlightEventDispatchDetails>(this, tree, display_id,
|
| + event, phase);
|
|
|
| // TOOD(sad): Adjust this delay, possibly make this dynamic.
|
| const base::TimeDelta max_delay = base::debug::BeingDebugged()
|
| @@ -550,7 +542,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);
|
| }
|
|
|
| bool WindowManagerState::ConvertPointToScreen(const int64_t display_id,
|
| @@ -577,12 +569,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, display_id, 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));
|
| }
|
| @@ -661,7 +653,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), display_id);
|
| @@ -675,6 +667,33 @@ void WindowManagerState::DispatchInputEventToWindow(ServerWindow* target,
|
| 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_.event_targeter()->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->display_id,
|
| + *queued_event->event, queued_event->processed_target->accelerator());
|
| + return;
|
| + }
|
| + }
|
| +}
|
| +
|
| ClientSpecificId WindowManagerState::GetEventTargetClientId(
|
| const ServerWindow* window,
|
| bool in_nonclient_area) {
|
|
|