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

Side by Side 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 unified diff | Download patch
« ui/aura/event_injector.h ('K') | « ui/aura/event_injector.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/aura/event_injector.h"
6
7 #include "services/service_manager/public/cpp/connector.h"
8 #include "services/ui/public/interfaces/constants.mojom.h"
9 #include "ui/aura/env.h"
10 #include "ui/aura/mus/window_tree_client.h"
11 #include "ui/aura/window_tree_host.h"
12 #include "ui/display/display.h"
13 #include "ui/display/screen.h"
14 #include "ui/events/event.h"
15 #include "ui/events/event_sink.h"
16
17 namespace {
18 std::unique_ptr<ui::Event> MapEvent(const ui::Event& event) {
19 if (event.IsScrollEvent()) {
20 return base::MakeUnique<ui::PointerEvent>(
21 ui::MouseWheelEvent(*event.AsScrollEvent()));
22 }
23
24 if (event.IsMouseEvent())
25 return base::MakeUnique<ui::PointerEvent>(*event.AsMouseEvent());
26
27 if (event.IsTouchEvent())
28 return base::MakeUnique<ui::PointerEvent>(*event.AsTouchEvent());
29
30 return ui::Event::Clone(event);
31 }
32
33 } // namespace
34
35 namespace aura {
36
37 EventInjector::EventInjector() {}
38
39 EventInjector::~EventInjector() {}
40
41 ui::EventDispatchDetails EventInjector::Inject(WindowTreeHost* host,
42 ui::Event* event) {
43 Env* env = Env::GetInstance();
44 DCHECK(env);
45 DCHECK(host);
46 DCHECK(event);
47
48 if (env->mode() == Env::Mode::LOCAL)
49 return host->event_sink()->OnEventFromSource(event);
50 if (!window_server_ptr_) {
51 env->window_tree_client_->connector()->BindInterface(
52 ui::mojom::kServiceName, &window_server_ptr_);
53 }
54 display::Screen* screen = display::Screen::GetScreen();
55 window_server_ptr_->DispatchEvent(
56 screen->GetPrimaryDisplay().id(), MapEvent(*event),
sky 2017/05/12 12:11:51 Do we end up doing the right thing with multiple d
sadrul 2017/05/12 21:26:08 Telemetry tests currently do not have tests for mu
57 base::Bind([](bool result) { DCHECK(result); }));
58 return ui::EventDispatchDetails();
59 }
60
61 } // namespace aura
OLDNEW
« ui/aura/event_injector.h ('K') | « ui/aura/event_injector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698