Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / ui_events_helper.cc
blob7aa038e1dcc9e5d7061ac3b8c3d088053b16edc8
1 // Copyright (c) 2012 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.
5 #include "content/browser/renderer_host/ui_events_helper.h"
7 #include "content/browser/renderer_host/input/web_input_event_util.h"
8 #include "content/common/input/web_touch_event_traits.h"
9 #include "third_party/WebKit/public/web/WebInputEvent.h"
10 #include "ui/events/blink/blink_event_util.h"
11 #include "ui/events/event.h"
12 #include "ui/events/event_constants.h"
14 namespace {
16 ui::EventType WebTouchPointStateToEventType(
17 blink::WebTouchPoint::State state) {
18 switch (state) {
19 case blink::WebTouchPoint::StateReleased:
20 return ui::ET_TOUCH_RELEASED;
22 case blink::WebTouchPoint::StatePressed:
23 return ui::ET_TOUCH_PRESSED;
25 case blink::WebTouchPoint::StateMoved:
26 return ui::ET_TOUCH_MOVED;
28 case blink::WebTouchPoint::StateCancelled:
29 return ui::ET_TOUCH_CANCELLED;
31 default:
32 return ui::ET_UNKNOWN;
36 } // namespace
38 namespace content {
40 bool MakeUITouchEventsFromWebTouchEvents(
41 const TouchEventWithLatencyInfo& touch_with_latency,
42 ScopedVector<ui::TouchEvent>* list,
43 TouchEventCoordinateSystem coordinate_system) {
44 const blink::WebTouchEvent& touch = touch_with_latency.event;
45 ui::EventType type = ui::ET_UNKNOWN;
46 switch (touch.type) {
47 case blink::WebInputEvent::TouchStart:
48 type = ui::ET_TOUCH_PRESSED;
49 break;
50 case blink::WebInputEvent::TouchEnd:
51 type = ui::ET_TOUCH_RELEASED;
52 break;
53 case blink::WebInputEvent::TouchMove:
54 type = ui::ET_TOUCH_MOVED;
55 break;
56 case blink::WebInputEvent::TouchCancel:
57 type = ui::ET_TOUCH_CANCELLED;
58 break;
59 default:
60 NOTREACHED();
61 return false;
64 int flags = WebEventModifiersToEventFlags(touch.modifiers);
65 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds(
66 static_cast<int64>(touch.timeStampSeconds * 1000000));
67 for (unsigned i = 0; i < touch.touchesLength; ++i) {
68 const blink::WebTouchPoint& point = touch.touches[i];
69 if (WebTouchPointStateToEventType(point.state) != type)
70 continue;
71 // ui events start in the co-ordinate space of the EventDispatcher.
72 gfx::PointF location;
73 if (coordinate_system == LOCAL_COORDINATES)
74 location = point.position;
75 else
76 location = point.screenPosition;
77 ui::TouchEvent* uievent = new ui::TouchEvent(type,
78 location,
79 flags,
80 point.id,
81 timestamp,
82 point.radiusX,
83 point.radiusY,
84 point.rotationAngle,
85 point.force);
86 uievent->set_latency(touch_with_latency.latency);
87 list->push_back(uievent);
89 return true;
92 blink::WebGestureEvent MakeWebGestureEventFromUIEvent(
93 const ui::GestureEvent& event) {
94 return ui::CreateWebGestureEvent(event.details(), event.time_stamp(),
95 event.location_f(), event.root_location_f(),
96 event.flags());
99 } // namespace content