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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// Copyright (c) 2012 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 "content/browser/renderer_host/ui_events_helper.h"
#include "content/browser/renderer_host/input/web_input_event_util.h"
#include "content/common/input/web_touch_event_traits.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/events/blink/blink_event_util.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
namespace {
ui::EventType WebTouchPointStateToEventType(
blink::WebTouchPoint::State state) {
switch (state) {
case blink::WebTouchPoint::StateReleased:
return ui::ET_TOUCH_RELEASED;
case blink::WebTouchPoint::StatePressed:
return ui::ET_TOUCH_PRESSED;
case blink::WebTouchPoint::StateMoved:
return ui::ET_TOUCH_MOVED;
case blink::WebTouchPoint::StateCancelled:
return ui::ET_TOUCH_CANCELLED;
default:
return ui::ET_UNKNOWN;
}
}
} // namespace
namespace content {
bool MakeUITouchEventsFromWebTouchEvents(
const TouchEventWithLatencyInfo& touch_with_latency,
ScopedVector<ui::TouchEvent>* list,
TouchEventCoordinateSystem coordinate_system) {
const blink::WebTouchEvent& touch = touch_with_latency.event;
ui::EventType type = ui::ET_UNKNOWN;
switch (touch.type) {
case blink::WebInputEvent::TouchStart:
type = ui::ET_TOUCH_PRESSED;
break;
case blink::WebInputEvent::TouchEnd:
type = ui::ET_TOUCH_RELEASED;
break;
case blink::WebInputEvent::TouchMove:
type = ui::ET_TOUCH_MOVED;
break;
case blink::WebInputEvent::TouchCancel:
type = ui::ET_TOUCH_CANCELLED;
break;
default:
NOTREACHED();
return false;
}
int flags = WebEventModifiersToEventFlags(touch.modifiers);
base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds(
static_cast<int64>(touch.timeStampSeconds * 1000000));
for (unsigned i = 0; i < touch.touchesLength; ++i) {
const blink::WebTouchPoint& point = touch.touches[i];
if (WebTouchPointStateToEventType(point.state) != type)
continue;
// ui events start in the co-ordinate space of the EventDispatcher.
gfx::PointF location;
if (coordinate_system == LOCAL_COORDINATES)
location = point.position;
else
location = point.screenPosition;
ui::TouchEvent* uievent = new ui::TouchEvent(type,
location,
flags,
point.id,
timestamp,
point.radiusX,
point.radiusY,
point.rotationAngle,
point.force);
uievent->set_latency(touch_with_latency.latency);
list->push_back(uievent);
}
return true;
}
blink::WebGestureEvent MakeWebGestureEventFromUIEvent(
const ui::GestureEvent& event) {
return ui::CreateWebGestureEvent(event.details(), event.time_stamp(),
event.location_f(), event.root_location_f(),
event.flags());
}
} // namespace content
|