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.
4
5#ifndef CONTENT_BROWSER_RENDERER_HOST_UI_EVENTS_HELPER_H_
6#define CONTENT_BROWSER_RENDERER_HOST_UI_EVENTS_HELPER_H_
7
8#include "base/memory/scoped_vector.h"
9#include "content/browser/renderer_host/event_with_latency_info.h"
10#include "content/common/content_export.h"
11
12namespace blink {
13class WebGestureEvent;
14class WebTouchEvent;
15class WebTouchPoint;
16}
17
18namespace ui {
19class GestureEvent;
20class TouchEvent;
21}
22
23namespace content {
24
25enum TouchEventCoordinateSystem {
26  SCREEN_COORDINATES,
27  LOCAL_COORDINATES
28};
29
30// Creates a list of ui::TouchEvents out of a single WebTouchEvent.
31// A WebTouchEvent can contain information about a number of WebTouchPoints,
32// whereas a ui::TouchEvent contains information about a single touch-point. So
33// it is possible to create more than one ui::TouchEvents out of a single
34// WebTouchEvent. All the ui::TouchEvent in the list will carry the same
35// LatencyInfo the WebTouchEvent carries.
36// |coordinate_system| specifies which fields to use for the co-ordinates,
37// WebTouchPoint.position or WebTouchPoint.screenPosition.  Is's up to the
38// caller to do any co-ordinate system mapping (typically to get them into
39// the Aura EventDispatcher co-ordinate system).
40CONTENT_EXPORT bool MakeUITouchEventsFromWebTouchEvents(
41    const TouchEventWithLatencyInfo& touch,
42    ScopedVector<ui::TouchEvent>* list,
43    TouchEventCoordinateSystem coordinate_system);
44
45// Creates a WebGestureEvent from a ui::GestureEvent. Note that it does not
46// populate the event coordinates (i.e. |x|, |y|, |globalX|, and |globalY|). So
47// the caller must populate these fields.
48blink::WebGestureEvent MakeWebGestureEventFromUIEvent(
49    const ui::GestureEvent& event);
50
51int EventFlagsToWebEventModifiers(int flags);
52
53// Updates the WebTouchEvent based on the TouchEvent. It returns the updated
54// WebTouchPoint contained in the WebTouchEvent, or NULL if no point was
55// updated.
56blink::WebTouchPoint* UpdateWebTouchEventFromUIEvent(
57    const ui::TouchEvent& event,
58    blink::WebTouchEvent* web_event);
59}
60
61#endif  // CONTENT_BROWSER_RENDERER_HOST_UI_EVENTS_HELPER_H_
62