forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents_ozone.cc
62 lines (54 loc) · 1.96 KB
/
events_ozone.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2013 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/events/ozone/events_ozone.h"
#include "ui/events/event.h"
namespace ui {
namespace {
bool dispatch_disabled = false;
}
bool DispatchEventFromNativeUiEvent(
const PlatformEvent& event,
base::OnceCallback<void(ui::Event*)> callback) {
// If it's disabled for test, just return as if it's handled.
if (dispatch_disabled)
return true;
// NB: ui::Events are constructed here using the overload that takes a
// const PlatformEvent& (here ui::Event* const&) rather than the copy
// constructor. This has side effects and cannot be changed to use the
// copy constructor or Event::Clone.
bool handled = false;
if (event->IsKeyEvent()) {
ui::KeyEvent key_event(event);
std::move(callback).Run(&key_event);
handled = key_event.handled();
} else if (event->IsMouseWheelEvent()) {
ui::MouseWheelEvent wheel_event(event);
std::move(callback).Run(&wheel_event);
handled = wheel_event.handled();
} else if (event->IsMouseEvent()) {
ui::MouseEvent mouse_event(event);
std::move(callback).Run(&mouse_event);
handled = mouse_event.handled();
} else if (event->IsTouchEvent()) {
ui::TouchEvent touch_event(event);
std::move(callback).Run(&touch_event);
handled = touch_event.handled();
} else if (event->IsScrollEvent()) {
ui::ScrollEvent scroll_event(event);
std::move(callback).Run(&scroll_event);
handled = scroll_event.handled();
} else if (event->IsGestureEvent()) {
std::move(callback).Run(event);
handled = event->handled();
// TODO(mohsen): Use the same pattern for scroll/touch/wheel events.
// Apparently, there is no need for them to wrap the |event|.
} else {
NOTREACHED();
}
return handled;
}
EVENTS_EXPORT void DisableNativeUiEventDispatchForTest() {
dispatch_disabled = true;
}
} // namespace ui