touch_emulator.cc revision 5f1c94371a64b3196d4be9466099bb892df9b88e
1a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Copyright 2014 The Chromium Authors. All rights reserved.
2a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// found in the LICENSE file.
4a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
5a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "content/browser/renderer_host/input/touch_emulator.h"
6a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
7a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "content/browser/renderer_host/input/motion_event_web.h"
8a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "content/browser/renderer_host/input/web_input_event_util.h"
95c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "content/common/input/web_touch_event_traits.h"
10a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "content/public/common/content_client.h"
11a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "content/public/common/content_switches.h"
12a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "grit/content_resources.h"
13a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "third_party/WebKit/public/platform/WebCursorInfo.h"
14a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/events/gesture_detection/gesture_config_helper.h"
15a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/gfx/image/image.h"
160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "ui/gfx/screen.h"
17a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
18a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochusing blink::WebGestureEvent;
19a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochusing blink::WebInputEvent;
20a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochusing blink::WebKeyboardEvent;
21a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochusing blink::WebMouseEvent;
22a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochusing blink::WebMouseWheelEvent;
23a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochusing blink::WebTouchEvent;
24a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochusing blink::WebTouchPoint;
25a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
26a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochnamespace content {
27a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
28a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochnamespace {
29a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
30a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochui::GestureProvider::Config GetGestureProviderConfig() {
31a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // TODO(dgozman): Use different configs to emulate mobile/desktop as
32a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // requested by renderer.
33a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  ui::GestureProvider::Config config = ui::DefaultGestureProviderConfig();
34a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  config.gesture_begin_end_types_enabled = false;
35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  config.gesture_detector_config.swipe_enabled = false;
36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  config.gesture_detector_config.two_finger_tap_enabled = false;
37a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return config;
38a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
39a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
40a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Time between two consecutive mouse moves, during which second mouse move
41a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// is not converted to touch.
42a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochconst double kMouseMoveDropIntervalSeconds = 5.f / 1000;
43a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
44a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} // namespace
45a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
46a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochTouchEmulator::TouchEmulator(TouchEmulatorClient* client)
47a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    : client_(client),
48a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      gesture_provider_(GetGestureProviderConfig(), this),
49a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      enabled_(false),
505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      allow_pinch_(false),
515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      emulated_stream_active_sequence_count_(0),
525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      native_stream_active_sequence_count_(0) {
53a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  DCHECK(client_);
54a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  ResetState();
55a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
560529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  bool use_2x = gfx::Screen::GetNativeScreen()->
570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      GetPrimaryDisplay().device_scale_factor() > 1.5f;
580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  float cursor_scale_factor = use_2x ? 2.f : 1.f;
59116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  cursor_size_ = InitCursorFromResource(&touch_cursor_,
600529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      cursor_scale_factor,
610529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      use_2x ? IDR_DEVTOOLS_TOUCH_CURSOR_ICON_2X :
620529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch          IDR_DEVTOOLS_TOUCH_CURSOR_ICON);
630529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  InitCursorFromResource(&pinch_cursor_,
640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      cursor_scale_factor,
650529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      use_2x ? IDR_DEVTOOLS_PINCH_CURSOR_ICON_2X :
660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch          IDR_DEVTOOLS_PINCH_CURSOR_ICON);
67a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
68a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  WebCursor::CursorInfo cursor_info;
69a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  cursor_info.type = blink::WebCursorInfo::TypePointer;
70a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pointer_cursor_.InitFromCursorInfo(cursor_info);
71a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
72a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // TODO(dgozman): Use synthetic secondary touch to support multi-touch.
730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  gesture_provider_.SetMultiTouchZoomSupportEnabled(false);
74a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // TODO(dgozman): Enable double tap if requested by the renderer.
75a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // TODO(dgozman): Don't break double-tap-based pinch with shift handling.
76a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false);
77a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
78a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
79a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochTouchEmulator::~TouchEmulator() {
80a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // We cannot cleanup properly in destructor, as we need roundtrip to the
81a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // renderer for ack. Instead, the owner should call Disable, and only
82a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // destroy this object when renderer is dead.
83a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
84a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
85a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid TouchEmulator::ResetState() {
86a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  last_mouse_event_was_move_ = false;
87a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  last_mouse_move_timestamp_ = 0;
88a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  mouse_pressed_ = false;
89a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  shift_pressed_ = false;
90a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  suppress_next_fling_cancel_ = false;
91a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pinch_scale_ = 1.f;
92a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pinch_gesture_active_ = false;
93a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
94a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
95a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid TouchEmulator::Enable(bool allow_pinch) {
96a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (!enabled_) {
97a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    enabled_ = true;
98a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    ResetState();
99a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  }
100a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  allow_pinch_ = allow_pinch;
101a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  UpdateCursor();
102a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
103a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
104a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid TouchEmulator::Disable() {
105a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (!enabled_)
106a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    return;
107a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
108a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  enabled_ = false;
109a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  UpdateCursor();
110a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  CancelTouch();
111a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
112a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
113116680a4aac90f2aa7413d9095a592090648e557Ben Murdochgfx::SizeF TouchEmulator::InitCursorFromResource(
1140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    WebCursor* cursor, float scale, int resource_id) {
115a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  gfx::Image& cursor_image =
116a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      content::GetContentClient()->GetNativeImageNamed(resource_id);
117a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  WebCursor::CursorInfo cursor_info;
118a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  cursor_info.type = blink::WebCursorInfo::TypeCustom;
1190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  cursor_info.image_scale_factor = scale;
120a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  cursor_info.custom_image = cursor_image.AsBitmap();
121a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  cursor_info.hotspot =
122a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      gfx::Point(cursor_image.Width() / 2, cursor_image.Height() / 2);
123a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#if defined(OS_WIN)
124a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  cursor_info.external_handle = 0;
125a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#endif
126a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
127a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  cursor->InitFromCursorInfo(cursor_info);
128116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return gfx::ScaleSize(cursor_image.Size(), 1.f / scale);
129a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
130a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
131a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochbool TouchEmulator::HandleMouseEvent(const WebMouseEvent& mouse_event) {
132a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (!enabled_)
133a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    return false;
134a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
1355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (mouse_event.button == WebMouseEvent::ButtonRight &&
1365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      mouse_event.type == WebInputEvent::MouseDown) {
1375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    client_->ShowContextMenuAtPoint(gfx::Point(mouse_event.x, mouse_event.y));
1385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  }
1395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
140a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (mouse_event.button != WebMouseEvent::ButtonLeft)
141a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    return true;
142a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
143a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (mouse_event.type == WebInputEvent::MouseMove) {
144a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    if (last_mouse_event_was_move_ &&
145a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        mouse_event.timeStampSeconds < last_mouse_move_timestamp_ +
146a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch            kMouseMoveDropIntervalSeconds)
147a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      return true;
148a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
149a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    last_mouse_event_was_move_ = true;
150a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    last_mouse_move_timestamp_ = mouse_event.timeStampSeconds;
151a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  } else {
152a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    last_mouse_event_was_move_ = false;
153a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  }
154a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
155a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (mouse_event.type == WebInputEvent::MouseDown)
156a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    mouse_pressed_ = true;
157a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  else if (mouse_event.type == WebInputEvent::MouseUp)
158a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    mouse_pressed_ = false;
159a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
160a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  UpdateShiftPressed((mouse_event.modifiers & WebInputEvent::ShiftKey) != 0);
161a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
162a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (FillTouchEventAndPoint(mouse_event) &&
163a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      gesture_provider_.OnTouchEvent(MotionEventWeb(touch_event_))) {
1645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    ForwardTouchEventToClient();
165a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  }
166a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
167a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // Do not pass mouse events to the renderer.
168a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return true;
169a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
170a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
171a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochbool TouchEmulator::HandleMouseWheelEvent(const WebMouseWheelEvent& event) {
172a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (!enabled_)
173a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    return false;
174a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
175cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Send mouse wheel for easy scrolling when there is no active touch.
1765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  return emulated_stream_active_sequence_count_ > 0;
177a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
178a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
179a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochbool TouchEmulator::HandleKeyboardEvent(const WebKeyboardEvent& event) {
180a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (!enabled_)
181a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    return false;
182a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
183a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (!UpdateShiftPressed((event.modifiers & WebInputEvent::ShiftKey) != 0))
184a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    return false;
185a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
186a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (!mouse_pressed_)
187a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    return false;
188a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
189a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // Note: The necessary pinch events will be lazily inserted by
190a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // |OnGestureEvent| depending on the state of |shift_pressed_|, using the
191a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // scroll stream as the event driver.
192a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (shift_pressed_) {
193a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    // TODO(dgozman): Add secondary touch point and set anchor.
194a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  } else {
195a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    // TODO(dgozman): Remove secondary touch point and anchor.
196a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  }
197a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
198a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // Never block keyboard events.
199a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return false;
200a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
201a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
2025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)bool TouchEmulator::HandleTouchEvent(const blink::WebTouchEvent& event) {
2035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Block native event when emulated touch stream is active.
2045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (emulated_stream_active_sequence_count_)
2055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    return true;
2065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  bool is_sequence_start = WebTouchEventTraits::IsTouchSequenceStart(event);
2085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Do not allow middle-sequence event to pass through, if start was blocked.
2095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (!native_stream_active_sequence_count_ && !is_sequence_start)
2105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    return true;
2115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (is_sequence_start)
2135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    native_stream_active_sequence_count_++;
2145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  return false;
2155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
2165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void TouchEmulator::ForwardTouchEventToClient() {
2185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  const bool event_consumed = true;
2195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Block emulated event when emulated native stream is active.
2205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (native_stream_active_sequence_count_) {
2215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    gesture_provider_.OnTouchEventAck(event_consumed);
2225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    return;
2235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  }
2245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  bool is_sequence_start =
2265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      WebTouchEventTraits::IsTouchSequenceStart(touch_event_);
2275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Do not allow middle-sequence event to pass through, if start was blocked.
2285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (!emulated_stream_active_sequence_count_ && !is_sequence_start) {
2295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    gesture_provider_.OnTouchEventAck(event_consumed);
2305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    return;
2315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  }
2325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (is_sequence_start)
2345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    emulated_stream_active_sequence_count_++;
2355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  client_->ForwardEmulatedTouchEvent(touch_event_);
2365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
2375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)bool TouchEmulator::HandleTouchEventAck(
2395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    const blink::WebTouchEvent& event, InputEventAckState ack_result) {
2405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  bool is_sequence_end = WebTouchEventTraits::IsTouchSequenceEnd(event);
2415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (emulated_stream_active_sequence_count_) {
2425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    if (is_sequence_end)
2435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      emulated_stream_active_sequence_count_--;
2445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    const bool event_consumed = ack_result == INPUT_EVENT_ACK_STATE_CONSUMED;
2465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    gesture_provider_.OnTouchEventAck(event_consumed);
2475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    return true;
2485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  }
2495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // We may have not seen native touch sequence start (when created in the
2515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // middle of a sequence), so don't decrement sequence count below zero.
2525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (is_sequence_end && native_stream_active_sequence_count_)
2535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    native_stream_active_sequence_count_--;
2545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  return false;
255a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
256a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
257a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid TouchEmulator::OnGestureEvent(const ui::GestureEventData& gesture) {
258a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  WebGestureEvent gesture_event =
259a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      CreateWebGestureEventFromGestureEventData(gesture);
260a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
261a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  switch (gesture_event.type) {
262cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    case WebInputEvent::Undefined:
263cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      NOTREACHED() << "Undefined WebInputEvent type";
264cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      // Bail without sending the junk event to the client.
265cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      return;
266cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
267a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    case WebInputEvent::GestureScrollBegin:
268a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      client_->ForwardGestureEvent(gesture_event);
269a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      // PinchBegin must always follow ScrollBegin.
270a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      if (InPinchGestureMode())
271a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        PinchBegin(gesture_event);
272a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      break;
273a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
274a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    case WebInputEvent::GestureScrollUpdate:
275a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      if (InPinchGestureMode()) {
276a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        // Convert scrolls to pinches while shift is pressed.
277a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        if (!pinch_gesture_active_)
278a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch          PinchBegin(gesture_event);
279a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        else
280a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch          PinchUpdate(gesture_event);
281a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      } else {
282a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        // Pass scroll update further. If shift was released, end the pinch.
283a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        if (pinch_gesture_active_)
284a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch          PinchEnd(gesture_event);
285a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        client_->ForwardGestureEvent(gesture_event);
286a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      }
287a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      break;
288a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
289a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    case WebInputEvent::GestureScrollEnd:
290a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      // PinchEnd must precede ScrollEnd.
291a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      if (pinch_gesture_active_)
292a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        PinchEnd(gesture_event);
293a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      client_->ForwardGestureEvent(gesture_event);
294a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      break;
295a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
296a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    case WebInputEvent::GestureFlingStart:
297a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      // PinchEnd must precede FlingStart.
298a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      if (pinch_gesture_active_)
299a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        PinchEnd(gesture_event);
300a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      if (InPinchGestureMode()) {
301a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        // No fling in pinch mode. Forward scroll end instead of fling start.
302a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        suppress_next_fling_cancel_ = true;
303a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        ScrollEnd(gesture_event);
304a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      } else {
305a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        suppress_next_fling_cancel_ = false;
306a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        client_->ForwardGestureEvent(gesture_event);
307a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      }
308a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      break;
309a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
310a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    case WebInputEvent::GestureFlingCancel:
311a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      // If fling start was suppressed, we should not send fling cancel either.
312a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      if (!suppress_next_fling_cancel_)
313a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        client_->ForwardGestureEvent(gesture_event);
314a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      suppress_next_fling_cancel_ = false;
315a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      break;
316a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
317a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    default:
318a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      // Everything else goes through.
319a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      client_->ForwardGestureEvent(gesture_event);
320a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  }
321a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
322a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
323a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid TouchEmulator::CancelTouch() {
3245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (!emulated_stream_active_sequence_count_)
325a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    return;
326a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
3275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  WebTouchEventTraits::ResetTypeAndTouchStates(
3285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      WebInputEvent::TouchCancel,
3295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(),
3305c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      &touch_event_);
331a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (gesture_provider_.OnTouchEvent(MotionEventWeb(touch_event_)))
3325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    ForwardTouchEventToClient();
333a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
334a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
335a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid TouchEmulator::UpdateCursor() {
336a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (!enabled_)
337a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    client_->SetCursor(pointer_cursor_);
338a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  else
339a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    client_->SetCursor(InPinchGestureMode() ? pinch_cursor_ : touch_cursor_);
340a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
341a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
342a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochbool TouchEmulator::UpdateShiftPressed(bool shift_pressed) {
343a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (shift_pressed_ == shift_pressed)
344a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    return false;
345a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  shift_pressed_ = shift_pressed;
346a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  UpdateCursor();
347a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return true;
348a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
349a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
350a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid TouchEmulator::PinchBegin(const WebGestureEvent& event) {
351a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  DCHECK(InPinchGestureMode());
352a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  DCHECK(!pinch_gesture_active_);
353a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pinch_gesture_active_ = true;
354a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pinch_anchor_ = gfx::Point(event.x, event.y);
355a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pinch_scale_ = 1.f;
356a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  FillPinchEvent(event);
357a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pinch_event_.type = WebInputEvent::GesturePinchBegin;
358a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  client_->ForwardGestureEvent(pinch_event_);
359a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
360a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
361a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid TouchEmulator::PinchUpdate(const WebGestureEvent& event) {
362a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  DCHECK(pinch_gesture_active_);
363a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  int dy = pinch_anchor_.y() - event.y;
364a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  float scale = exp(dy * 0.002f);
365a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  FillPinchEvent(event);
366a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pinch_event_.type = WebInputEvent::GesturePinchUpdate;
367a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pinch_event_.data.pinchUpdate.scale = scale / pinch_scale_;
368a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  client_->ForwardGestureEvent(pinch_event_);
369a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pinch_scale_ = scale;
370a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
371a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
372a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid TouchEmulator::PinchEnd(const WebGestureEvent& event) {
373a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  DCHECK(pinch_gesture_active_);
374a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pinch_gesture_active_ = false;
375a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  FillPinchEvent(event);
376a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pinch_event_.type = WebInputEvent::GesturePinchEnd;
377a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  client_->ForwardGestureEvent(pinch_event_);
378a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
379a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
380a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid TouchEmulator::FillPinchEvent(const WebInputEvent& event) {
381a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pinch_event_.timeStampSeconds = event.timeStampSeconds;
382a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pinch_event_.modifiers = event.modifiers;
38346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  pinch_event_.sourceDevice = blink::WebGestureDeviceTouchscreen;
384a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pinch_event_.x = pinch_anchor_.x();
385a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pinch_event_.y = pinch_anchor_.y();
386a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
387a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
388a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid TouchEmulator::ScrollEnd(const WebGestureEvent& event) {
389a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  WebGestureEvent scroll_event;
390a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  scroll_event.timeStampSeconds = event.timeStampSeconds;
391a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  scroll_event.modifiers = event.modifiers;
39246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  scroll_event.sourceDevice = blink::WebGestureDeviceTouchscreen;
393a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  scroll_event.type = WebInputEvent::GestureScrollEnd;
394a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  client_->ForwardGestureEvent(scroll_event);
395a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
396a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
397a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochbool TouchEmulator::FillTouchEventAndPoint(const WebMouseEvent& mouse_event) {
398a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (mouse_event.type != WebInputEvent::MouseDown &&
399a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      mouse_event.type != WebInputEvent::MouseMove &&
400a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch      mouse_event.type != WebInputEvent::MouseUp) {
401a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    return false;
402a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  }
403a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
4045c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  WebInputEvent::Type eventType;
4055c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  switch (mouse_event.type) {
4065c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    case WebInputEvent::MouseDown:
4075c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      eventType = WebInputEvent::TouchStart;
4085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      break;
4095c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    case WebInputEvent::MouseMove:
4105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      eventType = WebInputEvent::TouchMove;
4115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      break;
4125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    case WebInputEvent::MouseUp:
4135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      eventType = WebInputEvent::TouchEnd;
4145c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      break;
4155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    default:
4165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      eventType = WebInputEvent::Undefined;
4175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      NOTREACHED();
4185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  }
419a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  touch_event_.touchesLength = 1;
420a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  touch_event_.modifiers = mouse_event.modifiers;
4215c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  WebTouchEventTraits::ResetTypeAndTouchStates(
4225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      eventType, mouse_event.timeStampSeconds, &touch_event_);
423a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
424a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  WebTouchPoint& point = touch_event_.touches[0];
425a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  point.id = 0;
426116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  point.radiusX = 0.5f * cursor_size_.width();
427116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  point.radiusY = 0.5f * cursor_size_.height();
428a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  point.force = 1.f;
429a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  point.rotationAngle = 0.f;
430a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  point.position.x = mouse_event.x;
431a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  point.screenPosition.x = mouse_event.globalX;
432a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  point.position.y = mouse_event.y;
433a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  point.screenPosition.y = mouse_event.globalY;
434a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
435a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return true;
436a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
437a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
438a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochbool TouchEmulator::InPinchGestureMode() const {
439a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return shift_pressed_ && allow_pinch_;
440a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
441a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
442a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}  // namespace content
443