Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: content/browser/renderer_host/input/touch_emulator.cc

Issue 2569273002: Add constructors to WebInputEvents and setters so we can work at cleaning up these public structs. (Closed)
Patch Set: Rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 client_->ForwardEmulatedGestureEvent(gesture_event); 357 client_->ForwardEmulatedGestureEvent(gesture_event);
358 } 358 }
359 } 359 }
360 360
361 void TouchEmulator::CancelTouch() { 361 void TouchEmulator::CancelTouch() {
362 if (!emulated_stream_active_sequence_count_ || !enabled()) 362 if (!emulated_stream_active_sequence_count_ || !enabled())
363 return; 363 return;
364 364
365 WebTouchEventTraits::ResetTypeAndTouchStates( 365 WebTouchEventTraits::ResetTypeAndTouchStates(
366 WebInputEvent::TouchCancel, 366 WebInputEvent::TouchCancel,
367 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(), 367 ui::EventTimeStampToSeconds(ui::EventTimeForNow()), &touch_event_);
368 &touch_event_);
369 DCHECK(gesture_provider_); 368 DCHECK(gesture_provider_);
370 if (gesture_provider_->GetCurrentDownEvent()) 369 if (gesture_provider_->GetCurrentDownEvent())
371 HandleEmulatedTouchEvent(touch_event_); 370 HandleEmulatedTouchEvent(touch_event_);
372 } 371 }
373 372
374 void TouchEmulator::UpdateCursor() { 373 void TouchEmulator::UpdateCursor() {
375 if (!enabled()) 374 if (!enabled())
376 client_->SetCursor(pointer_cursor_); 375 client_->SetCursor(pointer_cursor_);
377 else 376 else
378 client_->SetCursor(InPinchGestureMode() ? pinch_cursor_ : touch_cursor_); 377 client_->SetCursor(InPinchGestureMode() ? pinch_cursor_ : touch_cursor_);
379 } 378 }
380 379
381 bool TouchEmulator::UpdateShiftPressed(bool shift_pressed) { 380 bool TouchEmulator::UpdateShiftPressed(bool shift_pressed) {
382 if (shift_pressed_ == shift_pressed) 381 if (shift_pressed_ == shift_pressed)
383 return false; 382 return false;
384 shift_pressed_ = shift_pressed; 383 shift_pressed_ = shift_pressed;
385 UpdateCursor(); 384 UpdateCursor();
386 return true; 385 return true;
387 } 386 }
388 387
389 void TouchEmulator::PinchBegin(const WebGestureEvent& event) { 388 void TouchEmulator::PinchBegin(const WebGestureEvent& event) {
390 DCHECK(InPinchGestureMode()); 389 DCHECK(InPinchGestureMode());
391 DCHECK(!pinch_gesture_active_); 390 DCHECK(!pinch_gesture_active_);
392 pinch_gesture_active_ = true; 391 pinch_gesture_active_ = true;
393 pinch_anchor_ = gfx::Point(event.x, event.y); 392 pinch_anchor_ = gfx::Point(event.x, event.y);
394 pinch_scale_ = 1.f; 393 pinch_scale_ = 1.f;
395 FillPinchEvent(event); 394 WebGestureEvent pinch_event =
396 pinch_event_.type = WebInputEvent::GesturePinchBegin; 395 GetPinchGestureEvent(WebInputEvent::GesturePinchBegin, event);
397 client_->ForwardEmulatedGestureEvent(pinch_event_); 396 client_->ForwardEmulatedGestureEvent(pinch_event);
398 } 397 }
399 398
400 void TouchEmulator::PinchUpdate(const WebGestureEvent& event) { 399 void TouchEmulator::PinchUpdate(const WebGestureEvent& event) {
401 DCHECK(pinch_gesture_active_); 400 DCHECK(pinch_gesture_active_);
402 int dy = pinch_anchor_.y() - event.y; 401 int dy = pinch_anchor_.y() - event.y;
403 float scale = exp(dy * 0.002f); 402 float scale = exp(dy * 0.002f);
404 FillPinchEvent(event); 403 WebGestureEvent pinch_event =
405 pinch_event_.type = WebInputEvent::GesturePinchUpdate; 404 GetPinchGestureEvent(WebInputEvent::GesturePinchUpdate, event);
406 pinch_event_.data.pinchUpdate.scale = scale / pinch_scale_; 405 pinch_event.data.pinchUpdate.scale = scale / pinch_scale_;
407 client_->ForwardEmulatedGestureEvent(pinch_event_); 406 client_->ForwardEmulatedGestureEvent(pinch_event);
408 pinch_scale_ = scale; 407 pinch_scale_ = scale;
409 } 408 }
410 409
411 void TouchEmulator::PinchEnd(const WebGestureEvent& event) { 410 void TouchEmulator::PinchEnd(const WebGestureEvent& event) {
412 DCHECK(pinch_gesture_active_); 411 DCHECK(pinch_gesture_active_);
413 pinch_gesture_active_ = false; 412 pinch_gesture_active_ = false;
414 FillPinchEvent(event); 413 WebGestureEvent pinch_event =
415 pinch_event_.type = WebInputEvent::GesturePinchEnd; 414 GetPinchGestureEvent(WebInputEvent::GesturePinchEnd, event);
416 client_->ForwardEmulatedGestureEvent(pinch_event_); 415 client_->ForwardEmulatedGestureEvent(pinch_event);
417 }
418
419 void TouchEmulator::FillPinchEvent(const WebInputEvent& event) {
420 pinch_event_.timeStampSeconds = event.timeStampSeconds;
421 pinch_event_.modifiers = ModifiersWithoutMouseButtons(event);
422 pinch_event_.sourceDevice = blink::WebGestureDeviceTouchscreen;
423 pinch_event_.x = pinch_anchor_.x();
424 pinch_event_.y = pinch_anchor_.y();
425 } 416 }
426 417
427 void TouchEmulator::ScrollEnd(const WebGestureEvent& event) { 418 void TouchEmulator::ScrollEnd(const WebGestureEvent& event) {
428 WebGestureEvent scroll_event; 419 WebGestureEvent scroll_event(WebInputEvent::GestureScrollEnd,
429 scroll_event.timeStampSeconds = event.timeStampSeconds; 420 ModifiersWithoutMouseButtons(event),
430 scroll_event.modifiers = ModifiersWithoutMouseButtons(event); 421 event.timeStampSeconds);
431 scroll_event.sourceDevice = blink::WebGestureDeviceTouchscreen; 422 scroll_event.sourceDevice = blink::WebGestureDeviceTouchscreen;
432 scroll_event.type = WebInputEvent::GestureScrollEnd;
433 client_->ForwardEmulatedGestureEvent(scroll_event); 423 client_->ForwardEmulatedGestureEvent(scroll_event);
434 } 424 }
435 425
426 WebGestureEvent TouchEmulator::GetPinchGestureEvent(
427 WebInputEvent::Type type,
428 const WebInputEvent& original_event) {
429 WebGestureEvent event(type, ModifiersWithoutMouseButtons(original_event),
430 original_event.timeStampSeconds);
431 event.sourceDevice = blink::WebGestureDeviceTouchscreen;
432 event.x = pinch_anchor_.x();
433 event.y = pinch_anchor_.y();
434 return event;
435 }
436
436 void TouchEmulator::FillTouchEventAndPoint(const WebMouseEvent& mouse_event) { 437 void TouchEmulator::FillTouchEventAndPoint(const WebMouseEvent& mouse_event) {
437 WebInputEvent::Type eventType; 438 WebInputEvent::Type eventType;
438 switch (mouse_event.type) { 439 switch (mouse_event.type) {
439 case WebInputEvent::MouseDown: 440 case WebInputEvent::MouseDown:
440 eventType = WebInputEvent::TouchStart; 441 eventType = WebInputEvent::TouchStart;
441 break; 442 break;
442 case WebInputEvent::MouseMove: 443 case WebInputEvent::MouseMove:
443 eventType = WebInputEvent::TouchMove; 444 eventType = WebInputEvent::TouchMove;
444 break; 445 break;
445 case WebInputEvent::MouseUp: 446 case WebInputEvent::MouseUp:
446 eventType = WebInputEvent::TouchEnd; 447 eventType = WebInputEvent::TouchEnd;
447 break; 448 break;
448 default: 449 default:
449 eventType = WebInputEvent::Undefined; 450 eventType = WebInputEvent::Undefined;
450 NOTREACHED() << "Invalid event for touch emulation: " << mouse_event.type; 451 NOTREACHED() << "Invalid event for touch emulation: " << mouse_event.type;
451 } 452 }
452 touch_event_.touchesLength = 1; 453 touch_event_.touchesLength = 1;
453 touch_event_.modifiers = ModifiersWithoutMouseButtons(mouse_event); 454 touch_event_.setModifiers(ModifiersWithoutMouseButtons(mouse_event));
454 WebTouchEventTraits::ResetTypeAndTouchStates( 455 WebTouchEventTraits::ResetTypeAndTouchStates(
455 eventType, mouse_event.timeStampSeconds, &touch_event_); 456 eventType, mouse_event.timeStampSeconds, &touch_event_);
456
457 WebTouchPoint& point = touch_event_.touches[0]; 457 WebTouchPoint& point = touch_event_.touches[0];
458 point.id = 0; 458 point.id = 0;
459 point.radiusX = 0.5f * cursor_size_.width(); 459 point.radiusX = 0.5f * cursor_size_.width();
460 point.radiusY = 0.5f * cursor_size_.height(); 460 point.radiusY = 0.5f * cursor_size_.height();
461 point.force = 1.f; 461 point.force = 1.f;
462 point.rotationAngle = 0.f; 462 point.rotationAngle = 0.f;
463 point.position.x = mouse_event.x; 463 point.position.x = mouse_event.x;
464 point.screenPosition.x = mouse_event.globalX; 464 point.screenPosition.x = mouse_event.globalX;
465 point.position.y = mouse_event.y; 465 point.position.y = mouse_event.y;
466 point.screenPosition.y = mouse_event.globalY; 466 point.screenPosition.y = mouse_event.globalY;
467 point.tiltX = 0; 467 point.tiltX = 0;
468 point.tiltY = 0; 468 point.tiltY = 0;
469 point.pointerType = blink::WebPointerProperties::PointerType::Touch; 469 point.pointerType = blink::WebPointerProperties::PointerType::Touch;
470 } 470 }
471 471
472 bool TouchEmulator::InPinchGestureMode() const { 472 bool TouchEmulator::InPinchGestureMode() const {
473 return shift_pressed_; 473 return shift_pressed_;
474 } 474 }
475 475
476 } // namespace content 476 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698