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

Unified Diff: ui/aura/event_injector.cc

Issue 2869273010: aura: Introduce EventInjector. (Closed)
Patch Set: . 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/aura/event_injector.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/event_injector.cc
diff --git a/ui/aura/event_injector.cc b/ui/aura/event_injector.cc
new file mode 100644
index 0000000000000000000000000000000000000000..09019d0d6a6e87529c0b19aa7433b19452309099
--- /dev/null
+++ b/ui/aura/event_injector.cc
@@ -0,0 +1,61 @@
+// Copyright 2017 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 "ui/aura/event_injector.h"
+
+#include "services/service_manager/public/cpp/connector.h"
+#include "services/ui/public/interfaces/constants.mojom.h"
+#include "ui/aura/env.h"
+#include "ui/aura/mus/window_tree_client.h"
+#include "ui/aura/window_tree_host.h"
+#include "ui/display/display.h"
+#include "ui/display/screen.h"
+#include "ui/events/event.h"
+#include "ui/events/event_sink.h"
+
+namespace {
+std::unique_ptr<ui::Event> MapEvent(const ui::Event& event) {
+ if (event.IsScrollEvent()) {
+ return base::MakeUnique<ui::PointerEvent>(
+ ui::MouseWheelEvent(*event.AsScrollEvent()));
+ }
+
+ if (event.IsMouseEvent())
+ return base::MakeUnique<ui::PointerEvent>(*event.AsMouseEvent());
+
+ if (event.IsTouchEvent())
+ return base::MakeUnique<ui::PointerEvent>(*event.AsTouchEvent());
+
+ return ui::Event::Clone(event);
+}
+
+} // namespace
+
+namespace aura {
+
+EventInjector::EventInjector() {}
+
+EventInjector::~EventInjector() {}
+
+ui::EventDispatchDetails EventInjector::Inject(WindowTreeHost* host,
+ ui::Event* event) {
+ Env* env = Env::GetInstance();
+ DCHECK(env);
+ DCHECK(host);
+ DCHECK(event);
+
+ if (env->mode() == Env::Mode::LOCAL)
+ return host->event_sink()->OnEventFromSource(event);
+ if (!window_server_ptr_) {
+ env->window_tree_client_->connector()->BindInterface(
+ ui::mojom::kServiceName, &window_server_ptr_);
+ }
+ display::Screen* screen = display::Screen::GetScreen();
+ window_server_ptr_->DispatchEvent(
+ screen->GetDisplayNearestWindow(host->window()).id(), MapEvent(*event),
+ base::Bind([](bool result) { DCHECK(result); }));
+ return ui::EventDispatchDetails();
+}
+
+} // namespace aura
« no previous file with comments | « ui/aura/event_injector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698