1 // Copyright 2014 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EMULATOR_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EMULATOR_H_
8 #include "content/browser/renderer_host/input/touch_emulator_client.h"
9 #include "content/common/cursors/webcursor.h"
10 #include "content/common/input/input_event_ack_state.h"
11 #include "third_party/WebKit/public/web/WebInputEvent.h"
12 #include "ui/events/gesture_detection/filtered_gesture_provider.h"
16 // Emulates touch input with mouse and keyboard.
17 class CONTENT_EXPORT TouchEmulator
: public ui::GestureProviderClient
{
19 explicit TouchEmulator(TouchEmulatorClient
* client
);
20 virtual ~TouchEmulator();
22 void Enable(bool allow_pinch
);
25 // Returns |true| if the event was consumed.
26 // TODO(dgozman): maybe pass latency info together with events.
27 bool HandleMouseEvent(const blink::WebMouseEvent
& event
);
28 bool HandleMouseWheelEvent(const blink::WebMouseWheelEvent
& event
);
29 bool HandleKeyboardEvent(const blink::WebKeyboardEvent
& event
);
31 // Returns |true| if the event ack was consumed. Consumed ack should not
32 // propagate any further.
33 bool HandleTouchEventAck(InputEventAckState ack_result
);
35 // Cancel any touches, for example, when focus is lost.
39 // ui::GestureProviderClient implementation.
40 virtual void OnGestureEvent(const ui::GestureEventData
& gesture
) OVERRIDE
;
42 void InitCursorFromResource(WebCursor
* cursor
, float scale
, int resource_id
);
45 bool UpdateShiftPressed(bool shift_pressed
);
47 // Whether we should convert scrolls into pinches.
48 bool InPinchGestureMode() const;
50 bool FillTouchEventAndPoint(const blink::WebMouseEvent
& mouse_event
);
51 void FillPinchEvent(const blink::WebInputEvent
& event
);
53 // The following methods generate and pass gesture events to the renderer.
54 void PinchBegin(const blink::WebGestureEvent
& event
);
55 void PinchUpdate(const blink::WebGestureEvent
& event
);
56 void PinchEnd(const blink::WebGestureEvent
& event
);
57 void ScrollEnd(const blink::WebGestureEvent
& event
);
59 TouchEmulatorClient
* const client_
;
60 ui::FilteredGestureProvider gesture_provider_
;
62 // Disabled emulator does only process touch acks left from previous
63 // emulation. It does not intercept any events.
67 // While emulation is on, default cursor is touch. Pressing shift changes
68 // cursor to the pinch one.
69 WebCursor pointer_cursor_
;
70 WebCursor touch_cursor_
;
71 WebCursor pinch_cursor_
;
73 // These are used to drop extra mouse move events coming too quickly, so
74 // we don't handle too much touches in gesture provider.
75 bool last_mouse_event_was_move_
;
76 double last_mouse_move_timestamp_
;
81 blink::WebTouchEvent touch_event_
;
84 // Whether we should suppress next fling cancel. This may happen when we
85 // did not send fling start in pinch mode.
86 bool suppress_next_fling_cancel_
;
88 blink::WebGestureEvent pinch_event_
;
89 // Point which does not move while pinch-zooming.
90 gfx::Point pinch_anchor_
;
91 // The cumulative scale change from the start of pinch gesture.
93 bool pinch_gesture_active_
;
95 DISALLOW_COPY_AND_ASSIGN(TouchEmulator
);
98 } // namespace content
100 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EMULATOR_H_