blob: a3abed0e08f66a54db3c960247e602e6418642f6 [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdint.h>
#include <vector>
#include "base/containers/circular_deque.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/ws/public/mojom/event_injector.mojom.h"
namespace aura {
class WindowTreeHost;
namespace ws {
class InjectedEventHandler;
class WindowService;
// See description in mojom for details on this.
: public mojom::EventInjector {
explicit EventInjector(WindowService* window_service);
~EventInjector() override;
void AddBinding(mojom::EventInjectorRequest request);
// Returns true if any injected events have been queued for dispatch.
bool HasQueuedEvents() const { return !queued_events_.empty(); }
struct EventAndHost;
struct QueuedEvent;
struct HandlerAndCallback;
void OnEventDispatched(InjectedEventHandler* handler);
// Determines the target WindowTreeHost and provides an mapping on |event|
// before dispatch. If the returned EventAndHost has a null |host|, there was
// a problem in conversion and the event should not be dispatched.
EventAndHost DetermineEventAndHost(int64_t display_id,
std::unique_ptr<ui::Event> event);
void DispatchNextQueuedEvent();
// Both InjectEventNoAck() implementations call to this.
void InjectEventNoAckImpl(int64_t display_id,
std::unique_ptr<ui::Event> event,
bool honor_rewriters);
// mojom::EventInjector:
void InjectEvent(int64_t display_id,
std::unique_ptr<ui::Event> event,
InjectEventCallback cb) override;
void InjectEventNoAck(int64_t display_id,
std::unique_ptr<ui::Event> event) override;
void InjectEventNoAckNoRewriters(int64_t display_id,
std::unique_ptr<ui::Event> event) override;
WindowService* window_service_;
// Each call to InjectEvent() results in creating and adding a new handler to
// |handlers_|. The callback in HandlerAndCallback is the callback supplied by
// the client. The handlers are removed once the event is processed.
std::vector<std::unique_ptr<HandlerAndCallback>> handlers_;
mojo::BindingSet<mojom::EventInjector> bindings_;
base::circular_deque<QueuedEvent> queued_events_;
} // namespace ws