| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/input/touch_emulator.h" | 5 #include "content/browser/renderer_host/input/touch_emulator.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "content/browser/renderer_host/input/motion_event_web.h" | 8 #include "content/browser/renderer_host/input/motion_event_web.h" |
| 9 #include "content/common/input/web_touch_event_traits.h" | 9 #include "content/common/input/web_touch_event_traits.h" |
| 10 #include "content/grit/content_resources.h" | 10 #include "content/grit/content_resources.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 ui::GetGestureProviderConfig(config_type); | 34 ui::GetGestureProviderConfig(config_type); |
| 35 config.gesture_begin_end_types_enabled = false; | 35 config.gesture_begin_end_types_enabled = false; |
| 36 config.gesture_detector_config.swipe_enabled = false; | 36 config.gesture_detector_config.swipe_enabled = false; |
| 37 config.gesture_detector_config.two_finger_tap_enabled = false; | 37 config.gesture_detector_config.two_finger_tap_enabled = false; |
| 38 return config; | 38 return config; |
| 39 } | 39 } |
| 40 | 40 |
| 41 int ModifiersWithoutMouseButtons(const WebInputEvent& event) { | 41 int ModifiersWithoutMouseButtons(const WebInputEvent& event) { |
| 42 const int all_buttons = WebInputEvent::LeftButtonDown | | 42 const int all_buttons = WebInputEvent::LeftButtonDown | |
| 43 WebInputEvent::MiddleButtonDown | WebInputEvent::RightButtonDown; | 43 WebInputEvent::MiddleButtonDown | WebInputEvent::RightButtonDown; |
| 44 return event.modifiers & ~all_buttons; | 44 return event.modifiers() & ~all_buttons; |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Time between two consecutive mouse moves, during which second mouse move | 47 // Time between two consecutive mouse moves, during which second mouse move |
| 48 // is not converted to touch. | 48 // is not converted to touch. |
| 49 const double kMouseMoveDropIntervalSeconds = 5.f / 1000; | 49 const double kMouseMoveDropIntervalSeconds = 5.f / 1000; |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 TouchEmulator::TouchEmulator(TouchEmulatorClient* client, | 53 TouchEmulator::TouchEmulator(TouchEmulatorClient* client, |
| 54 float device_scale_factor) | 54 float device_scale_factor) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 cursor->InitFromCursorInfo(cursor_info); | 150 cursor->InitFromCursorInfo(cursor_info); |
| 151 return gfx::ScaleSize(gfx::SizeF(cursor_image.Size()), 1.f / scale); | 151 return gfx::ScaleSize(gfx::SizeF(cursor_image.Size()), 1.f / scale); |
| 152 } | 152 } |
| 153 | 153 |
| 154 bool TouchEmulator::HandleMouseEvent(const WebMouseEvent& mouse_event) { | 154 bool TouchEmulator::HandleMouseEvent(const WebMouseEvent& mouse_event) { |
| 155 if (!enabled()) | 155 if (!enabled()) |
| 156 return false; | 156 return false; |
| 157 | 157 |
| 158 if (mouse_event.button == WebMouseEvent::Button::Right && | 158 if (mouse_event.button == WebMouseEvent::Button::Right && |
| 159 mouse_event.type == WebInputEvent::MouseDown) { | 159 mouse_event.type() == WebInputEvent::MouseDown) { |
| 160 client_->ShowContextMenuAtPoint(gfx::Point(mouse_event.x, mouse_event.y)); | 160 client_->ShowContextMenuAtPoint(gfx::Point(mouse_event.x, mouse_event.y)); |
| 161 } | 161 } |
| 162 | 162 |
| 163 if (mouse_event.button != WebMouseEvent::Button::Left) | 163 if (mouse_event.button != WebMouseEvent::Button::Left) |
| 164 return true; | 164 return true; |
| 165 | 165 |
| 166 if (mouse_event.type == WebInputEvent::MouseMove) { | 166 if (mouse_event.type() == WebInputEvent::MouseMove) { |
| 167 if (last_mouse_event_was_move_ && | 167 if (last_mouse_event_was_move_ && |
| 168 mouse_event.timeStampSeconds < last_mouse_move_timestamp_ + | 168 mouse_event.timeStampSeconds() < |
| 169 kMouseMoveDropIntervalSeconds) | 169 last_mouse_move_timestamp_ + kMouseMoveDropIntervalSeconds) |
| 170 return true; | 170 return true; |
| 171 | 171 |
| 172 last_mouse_event_was_move_ = true; | 172 last_mouse_event_was_move_ = true; |
| 173 last_mouse_move_timestamp_ = mouse_event.timeStampSeconds; | 173 last_mouse_move_timestamp_ = mouse_event.timeStampSeconds(); |
| 174 } else { | 174 } else { |
| 175 last_mouse_event_was_move_ = false; | 175 last_mouse_event_was_move_ = false; |
| 176 } | 176 } |
| 177 | 177 |
| 178 if (mouse_event.type == WebInputEvent::MouseDown) | 178 if (mouse_event.type() == WebInputEvent::MouseDown) |
| 179 mouse_pressed_ = true; | 179 mouse_pressed_ = true; |
| 180 else if (mouse_event.type == WebInputEvent::MouseUp) | 180 else if (mouse_event.type() == WebInputEvent::MouseUp) |
| 181 mouse_pressed_ = false; | 181 mouse_pressed_ = false; |
| 182 | 182 |
| 183 UpdateShiftPressed((mouse_event.modifiers & WebInputEvent::ShiftKey) != 0); | 183 UpdateShiftPressed((mouse_event.modifiers() & WebInputEvent::ShiftKey) != 0); |
| 184 | 184 |
| 185 if (mouse_event.type != WebInputEvent::MouseDown && | 185 if (mouse_event.type() != WebInputEvent::MouseDown && |
| 186 mouse_event.type != WebInputEvent::MouseMove && | 186 mouse_event.type() != WebInputEvent::MouseMove && |
| 187 mouse_event.type != WebInputEvent::MouseUp) { | 187 mouse_event.type() != WebInputEvent::MouseUp) { |
| 188 return true; | 188 return true; |
| 189 } | 189 } |
| 190 | 190 |
| 191 FillTouchEventAndPoint(mouse_event); | 191 FillTouchEventAndPoint(mouse_event); |
| 192 HandleEmulatedTouchEvent(touch_event_); | 192 HandleEmulatedTouchEvent(touch_event_); |
| 193 | 193 |
| 194 // Do not pass mouse events to the renderer. | 194 // Do not pass mouse events to the renderer. |
| 195 return true; | 195 return true; |
| 196 } | 196 } |
| 197 | 197 |
| 198 bool TouchEmulator::HandleMouseWheelEvent(const WebMouseWheelEvent& event) { | 198 bool TouchEmulator::HandleMouseWheelEvent(const WebMouseWheelEvent& event) { |
| 199 if (!enabled()) | 199 if (!enabled()) |
| 200 return false; | 200 return false; |
| 201 | 201 |
| 202 // Send mouse wheel for easy scrolling when there is no active touch. | 202 // Send mouse wheel for easy scrolling when there is no active touch. |
| 203 return emulated_stream_active_sequence_count_ > 0; | 203 return emulated_stream_active_sequence_count_ > 0; |
| 204 } | 204 } |
| 205 | 205 |
| 206 bool TouchEmulator::HandleKeyboardEvent(const WebKeyboardEvent& event) { | 206 bool TouchEmulator::HandleKeyboardEvent(const WebKeyboardEvent& event) { |
| 207 if (!enabled()) | 207 if (!enabled()) |
| 208 return false; | 208 return false; |
| 209 | 209 |
| 210 if (!UpdateShiftPressed((event.modifiers & WebInputEvent::ShiftKey) != 0)) | 210 if (!UpdateShiftPressed((event.modifiers() & WebInputEvent::ShiftKey) != 0)) |
| 211 return false; | 211 return false; |
| 212 | 212 |
| 213 if (!mouse_pressed_) | 213 if (!mouse_pressed_) |
| 214 return false; | 214 return false; |
| 215 | 215 |
| 216 // Note: The necessary pinch events will be lazily inserted by | 216 // Note: The necessary pinch events will be lazily inserted by |
| 217 // |OnGestureEvent| depending on the state of |shift_pressed_|, using the | 217 // |OnGestureEvent| depending on the state of |shift_pressed_|, using the |
| 218 // scroll stream as the event driver. | 218 // scroll stream as the event driver. |
| 219 if (shift_pressed_) { | 219 if (shift_pressed_) { |
| 220 // TODO(dgozman): Add secondary touch point and set anchor. | 220 // TODO(dgozman): Add secondary touch point and set anchor. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 // middle of a sequence), so don't decrement sequence count below zero. | 289 // middle of a sequence), so don't decrement sequence count below zero. |
| 290 if (is_sequence_end && native_stream_active_sequence_count_) | 290 if (is_sequence_end && native_stream_active_sequence_count_) |
| 291 native_stream_active_sequence_count_--; | 291 native_stream_active_sequence_count_--; |
| 292 return false; | 292 return false; |
| 293 } | 293 } |
| 294 | 294 |
| 295 void TouchEmulator::OnGestureEvent(const ui::GestureEventData& gesture) { | 295 void TouchEmulator::OnGestureEvent(const ui::GestureEventData& gesture) { |
| 296 WebGestureEvent gesture_event = | 296 WebGestureEvent gesture_event = |
| 297 ui::CreateWebGestureEventFromGestureEventData(gesture); | 297 ui::CreateWebGestureEventFromGestureEventData(gesture); |
| 298 | 298 |
| 299 switch (gesture_event.type) { | 299 switch (gesture_event.type()) { |
| 300 case WebInputEvent::Undefined: | 300 case WebInputEvent::Undefined: |
| 301 NOTREACHED() << "Undefined WebInputEvent type"; | 301 NOTREACHED() << "Undefined WebInputEvent type"; |
| 302 // Bail without sending the junk event to the client. | 302 // Bail without sending the junk event to the client. |
| 303 return; | 303 return; |
| 304 | 304 |
| 305 case WebInputEvent::GestureScrollBegin: | 305 case WebInputEvent::GestureScrollBegin: |
| 306 client_->ForwardEmulatedGestureEvent(gesture_event); | 306 client_->ForwardEmulatedGestureEvent(gesture_event); |
| 307 // PinchBegin must always follow ScrollBegin. | 307 // PinchBegin must always follow ScrollBegin. |
| 308 if (InPinchGestureMode()) | 308 if (InPinchGestureMode()) |
| 309 PinchBegin(gesture_event); | 309 PinchBegin(gesture_event); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 DCHECK(pinch_gesture_active_); | 411 DCHECK(pinch_gesture_active_); |
| 412 pinch_gesture_active_ = false; | 412 pinch_gesture_active_ = false; |
| 413 WebGestureEvent pinch_event = | 413 WebGestureEvent pinch_event = |
| 414 GetPinchGestureEvent(WebInputEvent::GesturePinchEnd, event); | 414 GetPinchGestureEvent(WebInputEvent::GesturePinchEnd, event); |
| 415 client_->ForwardEmulatedGestureEvent(pinch_event); | 415 client_->ForwardEmulatedGestureEvent(pinch_event); |
| 416 } | 416 } |
| 417 | 417 |
| 418 void TouchEmulator::ScrollEnd(const WebGestureEvent& event) { | 418 void TouchEmulator::ScrollEnd(const WebGestureEvent& event) { |
| 419 WebGestureEvent scroll_event(WebInputEvent::GestureScrollEnd, | 419 WebGestureEvent scroll_event(WebInputEvent::GestureScrollEnd, |
| 420 ModifiersWithoutMouseButtons(event), | 420 ModifiersWithoutMouseButtons(event), |
| 421 event.timeStampSeconds); | 421 event.timeStampSeconds()); |
| 422 scroll_event.sourceDevice = blink::WebGestureDeviceTouchscreen; | 422 scroll_event.sourceDevice = blink::WebGestureDeviceTouchscreen; |
| 423 client_->ForwardEmulatedGestureEvent(scroll_event); | 423 client_->ForwardEmulatedGestureEvent(scroll_event); |
| 424 } | 424 } |
| 425 | 425 |
| 426 WebGestureEvent TouchEmulator::GetPinchGestureEvent( | 426 WebGestureEvent TouchEmulator::GetPinchGestureEvent( |
| 427 WebInputEvent::Type type, | 427 WebInputEvent::Type type, |
| 428 const WebInputEvent& original_event) { | 428 const WebInputEvent& original_event) { |
| 429 WebGestureEvent event(type, ModifiersWithoutMouseButtons(original_event), | 429 WebGestureEvent event(type, ModifiersWithoutMouseButtons(original_event), |
| 430 original_event.timeStampSeconds); | 430 original_event.timeStampSeconds()); |
| 431 event.sourceDevice = blink::WebGestureDeviceTouchscreen; | 431 event.sourceDevice = blink::WebGestureDeviceTouchscreen; |
| 432 event.x = pinch_anchor_.x(); | 432 event.x = pinch_anchor_.x(); |
| 433 event.y = pinch_anchor_.y(); | 433 event.y = pinch_anchor_.y(); |
| 434 return event; | 434 return event; |
| 435 } | 435 } |
| 436 | 436 |
| 437 void TouchEmulator::FillTouchEventAndPoint(const WebMouseEvent& mouse_event) { | 437 void TouchEmulator::FillTouchEventAndPoint(const WebMouseEvent& mouse_event) { |
| 438 WebInputEvent::Type eventType; | 438 WebInputEvent::Type eventType; |
| 439 switch (mouse_event.type) { | 439 switch (mouse_event.type()) { |
| 440 case WebInputEvent::MouseDown: | 440 case WebInputEvent::MouseDown: |
| 441 eventType = WebInputEvent::TouchStart; | 441 eventType = WebInputEvent::TouchStart; |
| 442 break; | 442 break; |
| 443 case WebInputEvent::MouseMove: | 443 case WebInputEvent::MouseMove: |
| 444 eventType = WebInputEvent::TouchMove; | 444 eventType = WebInputEvent::TouchMove; |
| 445 break; | 445 break; |
| 446 case WebInputEvent::MouseUp: | 446 case WebInputEvent::MouseUp: |
| 447 eventType = WebInputEvent::TouchEnd; | 447 eventType = WebInputEvent::TouchEnd; |
| 448 break; | 448 break; |
| 449 default: | 449 default: |
| 450 eventType = WebInputEvent::Undefined; | 450 eventType = WebInputEvent::Undefined; |
| 451 NOTREACHED() << "Invalid event for touch emulation: " << mouse_event.type; | 451 NOTREACHED() << "Invalid event for touch emulation: " |
| 452 << mouse_event.type(); |
| 452 } | 453 } |
| 453 touch_event_.touchesLength = 1; | 454 touch_event_.touchesLength = 1; |
| 454 touch_event_.setModifiers(ModifiersWithoutMouseButtons(mouse_event)); | 455 touch_event_.setModifiers(ModifiersWithoutMouseButtons(mouse_event)); |
| 455 WebTouchEventTraits::ResetTypeAndTouchStates( | 456 WebTouchEventTraits::ResetTypeAndTouchStates( |
| 456 eventType, mouse_event.timeStampSeconds, &touch_event_); | 457 eventType, mouse_event.timeStampSeconds(), &touch_event_); |
| 457 WebTouchPoint& point = touch_event_.touches[0]; | 458 WebTouchPoint& point = touch_event_.touches[0]; |
| 458 point.id = 0; | 459 point.id = 0; |
| 459 point.radiusX = 0.5f * cursor_size_.width(); | 460 point.radiusX = 0.5f * cursor_size_.width(); |
| 460 point.radiusY = 0.5f * cursor_size_.height(); | 461 point.radiusY = 0.5f * cursor_size_.height(); |
| 461 point.force = 1.f; | 462 point.force = 1.f; |
| 462 point.rotationAngle = 0.f; | 463 point.rotationAngle = 0.f; |
| 463 point.position.x = mouse_event.x; | 464 point.position.x = mouse_event.x; |
| 464 point.screenPosition.x = mouse_event.globalX; | 465 point.screenPosition.x = mouse_event.globalX; |
| 465 point.position.y = mouse_event.y; | 466 point.position.y = mouse_event.y; |
| 466 point.screenPosition.y = mouse_event.globalY; | 467 point.screenPosition.y = mouse_event.globalY; |
| 467 point.tiltX = 0; | 468 point.tiltX = 0; |
| 468 point.tiltY = 0; | 469 point.tiltY = 0; |
| 469 point.pointerType = blink::WebPointerProperties::PointerType::Touch; | 470 point.pointerType = blink::WebPointerProperties::PointerType::Touch; |
| 470 } | 471 } |
| 471 | 472 |
| 472 bool TouchEmulator::InPinchGestureMode() const { | 473 bool TouchEmulator::InPinchGestureMode() const { |
| 473 return shift_pressed_; | 474 return shift_pressed_; |
| 474 } | 475 } |
| 475 | 476 |
| 476 } // namespace content | 477 } // namespace content |
| OLD | NEW |