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

Side by Side Diff: components/test_runner/event_sender.cc

Issue 1260693003: Add eventSender support for web pointer properties in touch points. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added TODO comments Created 5 years, 4 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
« no previous file with comments | « components/test_runner/event_sender.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/test_runner/event_sender.h" 5 #include "components/test_runner/event_sender.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 event.windowsKeyCode != ui::VKEY_B && 342 event.windowsKeyCode != ui::VKEY_B &&
343 event.windowsKeyCode != ui::VKEY_I; 343 event.windowsKeyCode != ui::VKEY_I;
344 #else 344 #else
345 return !!(event.modifiers & WebInputEvent::AltKey); 345 return !!(event.modifiers & WebInputEvent::AltKey);
346 #endif 346 #endif
347 } 347 }
348 348
349 const char* kSourceDeviceStringTouchpad = "touchpad"; 349 const char* kSourceDeviceStringTouchpad = "touchpad";
350 const char* kSourceDeviceStringTouchscreen = "touchscreen"; 350 const char* kSourceDeviceStringTouchscreen = "touchscreen";
351 351
352 const char* kPointerTypeStringUnknown = "";
353 const char* kPointerTypeStringMouse = "mouse";
354 const char* kPointerTypeStringPen = "pen";
355 const char* kPointerTypeStringTouch = "touch";
356
352 } // namespace 357 } // namespace
353 358
354 class EventSenderBindings : public gin::Wrappable<EventSenderBindings> { 359 class EventSenderBindings : public gin::Wrappable<EventSenderBindings> {
355 public: 360 public:
356 static gin::WrapperInfo kWrapperInfo; 361 static gin::WrapperInfo kWrapperInfo;
357 362
358 static void Install(base::WeakPtr<EventSender> sender, 363 static void Install(base::WeakPtr<EventSender> sender,
359 blink::WebFrame* frame); 364 blink::WebFrame* frame);
360 365
361 private: 366 private:
362 explicit EventSenderBindings(base::WeakPtr<EventSender> sender); 367 explicit EventSenderBindings(base::WeakPtr<EventSender> sender);
363 ~EventSenderBindings() override; 368 ~EventSenderBindings() override;
364 369
365 // gin::Wrappable: 370 // gin::Wrappable:
366 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( 371 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
367 v8::Isolate* isolate) override; 372 v8::Isolate* isolate) override;
368 373
369 // Bound methods: 374 // Bound methods:
370 void EnableDOMUIEventLogging(); 375 void EnableDOMUIEventLogging();
371 void FireKeyboardEventsToElement(); 376 void FireKeyboardEventsToElement();
372 void ClearKillRing(); 377 void ClearKillRing();
373 std::vector<std::string> ContextClick(); 378 std::vector<std::string> ContextClick();
374 void TextZoomIn(); 379 void TextZoomIn();
375 void TextZoomOut(); 380 void TextZoomOut();
376 void ZoomPageIn(); 381 void ZoomPageIn();
377 void ZoomPageOut(); 382 void ZoomPageOut();
378 void SetPageZoomFactor(double factor); 383 void SetPageZoomFactor(double factor);
379 void ClearTouchPoints(); 384 void ClearTouchPoints();
380 void ReleaseTouchPoint(unsigned index); 385 void ReleaseTouchPoint(unsigned index);
381 void UpdateTouchPoint(unsigned index, double x, double y); 386 void UpdateTouchPoint(unsigned index,
387 double x,
388 double y,
389 gin::Arguments* args);
382 void CancelTouchPoint(unsigned index); 390 void CancelTouchPoint(unsigned index);
383 void SetTouchModifier(const std::string& key_name, bool set_mask); 391 void SetTouchModifier(const std::string& key_name, bool set_mask);
384 void SetTouchCancelable(bool cancelable); 392 void SetTouchCancelable(bool cancelable);
385 void DumpFilenameBeingDragged(); 393 void DumpFilenameBeingDragged();
386 void GestureFlingCancel(); 394 void GestureFlingCancel();
387 void GestureFlingStart(float x, 395 void GestureFlingStart(float x,
388 float y, 396 float y,
389 float velocity_x, 397 float velocity_x,
390 float velocity_y, 398 float velocity_y,
391 gin::Arguments* args); 399 gin::Arguments* args);
392 void GestureScrollFirstPoint(int x, int y); 400 void GestureScrollFirstPoint(int x, int y);
393 void TouchStart(); 401 void TouchStart();
394 void TouchMove(); 402 void TouchMove();
395 void TouchMoveCausingScrollIfUncanceled(); 403 void TouchMoveCausingScrollIfUncanceled();
396 void TouchCancel(); 404 void TouchCancel();
397 void TouchEnd(); 405 void TouchEnd();
398 void LeapForward(int milliseconds); 406 void LeapForward(int milliseconds);
399 void BeginDragWithFiles(const std::vector<std::string>& files); 407 void BeginDragWithFiles(const std::vector<std::string>& files);
400 void AddTouchPoint(gin::Arguments* args); 408 void AddTouchPoint(double x, double y, gin::Arguments* args);
401 void MouseDragBegin(); 409 void MouseDragBegin();
402 void MouseDragEnd(); 410 void MouseDragEnd();
403 void GestureScrollBegin(gin::Arguments* args); 411 void GestureScrollBegin(gin::Arguments* args);
404 void GestureScrollEnd(gin::Arguments* args); 412 void GestureScrollEnd(gin::Arguments* args);
405 void GestureScrollUpdate(gin::Arguments* args); 413 void GestureScrollUpdate(gin::Arguments* args);
406 void GesturePinchBegin(gin::Arguments* args); 414 void GesturePinchBegin(gin::Arguments* args);
407 void GesturePinchEnd(gin::Arguments* args); 415 void GesturePinchEnd(gin::Arguments* args);
408 void GesturePinchUpdate(gin::Arguments* args); 416 void GesturePinchUpdate(gin::Arguments* args);
409 void GestureTap(gin::Arguments* args); 417 void GestureTap(gin::Arguments* args);
410 void GestureTapDown(gin::Arguments* args); 418 void GestureTapDown(gin::Arguments* args);
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 void EventSenderBindings::ClearTouchPoints() { 653 void EventSenderBindings::ClearTouchPoints() {
646 if (sender_) 654 if (sender_)
647 sender_->ClearTouchPoints(); 655 sender_->ClearTouchPoints();
648 } 656 }
649 657
650 void EventSenderBindings::ReleaseTouchPoint(unsigned index) { 658 void EventSenderBindings::ReleaseTouchPoint(unsigned index) {
651 if (sender_) 659 if (sender_)
652 sender_->ReleaseTouchPoint(index); 660 sender_->ReleaseTouchPoint(index);
653 } 661 }
654 662
655 void EventSenderBindings::UpdateTouchPoint(unsigned index, double x, double y) { 663 void EventSenderBindings::UpdateTouchPoint(unsigned index,
664 double x,
665 double y,
666 gin::Arguments* args) {
656 if (sender_) { 667 if (sender_) {
657 sender_->UpdateTouchPoint(index, static_cast<float>(x), 668 sender_->UpdateTouchPoint(index, static_cast<float>(x),
658 static_cast<float>(y)); 669 static_cast<float>(y), args);
659 } 670 }
660 } 671 }
661 672
662 void EventSenderBindings::CancelTouchPoint(unsigned index) { 673 void EventSenderBindings::CancelTouchPoint(unsigned index) {
663 if (sender_) 674 if (sender_)
664 sender_->CancelTouchPoint(index); 675 sender_->CancelTouchPoint(index);
665 } 676 }
666 677
667 void EventSenderBindings::SetTouchModifier(const std::string& key_name, 678 void EventSenderBindings::SetTouchModifier(const std::string& key_name,
668 bool set_mask) { 679 bool set_mask) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 if (sender_) 739 if (sender_)
729 sender_->LeapForward(milliseconds); 740 sender_->LeapForward(milliseconds);
730 } 741 }
731 742
732 void EventSenderBindings::BeginDragWithFiles( 743 void EventSenderBindings::BeginDragWithFiles(
733 const std::vector<std::string>& files) { 744 const std::vector<std::string>& files) {
734 if (sender_) 745 if (sender_)
735 sender_->BeginDragWithFiles(files); 746 sender_->BeginDragWithFiles(files);
736 } 747 }
737 748
738 void EventSenderBindings::AddTouchPoint(gin::Arguments* args) { 749 void EventSenderBindings::AddTouchPoint(double x,
750 double y,
751 gin::Arguments* args) {
739 if (sender_) 752 if (sender_)
740 sender_->AddTouchPoint(args); 753 sender_->AddTouchPoint(static_cast<float>(x), static_cast<float>(y), args);
741 } 754 }
742 755
743 void EventSenderBindings::MouseDragBegin() { 756 void EventSenderBindings::MouseDragBegin() {
744 if (sender_) 757 if (sender_)
745 sender_->MouseDragBegin(); 758 sender_->MouseDragBegin();
746 } 759 }
747 760
748 void EventSenderBindings::MouseDragEnd() { 761 void EventSenderBindings::MouseDragEnd() {
749 if (sender_) 762 if (sender_)
750 sender_->MouseDragEnd(); 763 sender_->MouseDragEnd();
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 void EventSender::ReleaseTouchPoint(unsigned index) { 1563 void EventSender::ReleaseTouchPoint(unsigned index) {
1551 if (index >= touch_points_.size()) { 1564 if (index >= touch_points_.size()) {
1552 ThrowTouchPointError(); 1565 ThrowTouchPointError();
1553 return; 1566 return;
1554 } 1567 }
1555 1568
1556 WebTouchPoint* touch_point = &touch_points_[index]; 1569 WebTouchPoint* touch_point = &touch_points_[index];
1557 touch_point->state = WebTouchPoint::StateReleased; 1570 touch_point->state = WebTouchPoint::StateReleased;
1558 } 1571 }
1559 1572
1560 void EventSender::UpdateTouchPoint(unsigned index, float x, float y) { 1573 void EventSender::UpdateTouchPoint(unsigned index,
1574 float x,
1575 float y,
1576 gin::Arguments* args) {
1561 if (index >= touch_points_.size()) { 1577 if (index >= touch_points_.size()) {
1562 ThrowTouchPointError(); 1578 ThrowTouchPointError();
1563 return; 1579 return;
1564 } 1580 }
1565 1581
1566 WebTouchPoint* touch_point = &touch_points_[index]; 1582 WebTouchPoint* touch_point = &touch_points_[index];
1567 touch_point->state = WebTouchPoint::StateMoved; 1583 touch_point->state = WebTouchPoint::StateMoved;
1568 touch_point->position = WebFloatPoint(x, y); 1584 touch_point->position = WebFloatPoint(x, y);
1569 touch_point->screenPosition = touch_point->position; 1585 touch_point->screenPosition = touch_point->position;
1586
1587 InitPointerProperties(args, touch_point, &touch_point->radiusX,
1588 &touch_point->radiusY);
1570 } 1589 }
1571 1590
1572 void EventSender::CancelTouchPoint(unsigned index) { 1591 void EventSender::CancelTouchPoint(unsigned index) {
1573 if (index >= touch_points_.size()) { 1592 if (index >= touch_points_.size()) {
1574 ThrowTouchPointError(); 1593 ThrowTouchPointError();
1575 return; 1594 return;
1576 } 1595 }
1577 1596
1578 WebTouchPoint* touch_point = &touch_points_[index]; 1597 WebTouchPoint* touch_point = &touch_points_[index];
1579 touch_point->state = WebTouchPoint::StateCancelled; 1598 touch_point->state = WebTouchPoint::StateCancelled;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 current_drag_effects_allowed_, 1740 current_drag_effects_allowed_,
1722 0); 1741 0);
1723 // |is_drag_mode_| saves events and then replays them later. We don't 1742 // |is_drag_mode_| saves events and then replays them later. We don't
1724 // need/want that. 1743 // need/want that.
1725 is_drag_mode_ = false; 1744 is_drag_mode_ = false;
1726 1745
1727 // Make the rest of eventSender think a drag is in progress. 1746 // Make the rest of eventSender think a drag is in progress.
1728 pressed_button_ = WebMouseEvent::ButtonLeft; 1747 pressed_button_ = WebMouseEvent::ButtonLeft;
1729 } 1748 }
1730 1749
1731 void EventSender::AddTouchPoint(gin::Arguments* args) { 1750 void EventSender::AddTouchPoint(float x, float y, gin::Arguments* args) {
1732 double x;
1733 double y;
1734 if (!args->GetNext(&x) || !args->GetNext(&y)) {
1735 args->ThrowError();
1736 return;
1737 }
1738
1739 WebTouchPoint touch_point; 1751 WebTouchPoint touch_point;
1740 touch_point.state = WebTouchPoint::StatePressed; 1752 touch_point.state = WebTouchPoint::StatePressed;
1741 touch_point.position = WebFloatPoint(static_cast<float>(x), 1753 touch_point.position = WebFloatPoint(x, y);
1742 static_cast<float>(y));
1743 touch_point.screenPosition = touch_point.position; 1754 touch_point.screenPosition = touch_point.position;
1744 1755
1745 if (!args->PeekNext().IsEmpty()) { 1756 // TODO(e_hakkinen): Make this algorithm more robust so that it handles
1746 double radius_x; 1757 // touch points which are not sorted by their ids, too.
1747 if (!args->GetNext(&radius_x)) {
1748 args->ThrowError();
1749 return;
1750 }
1751
1752 double radius_y = radius_x;
1753 if (!args->PeekNext().IsEmpty()) {
1754 if (!args->GetNext(&radius_y)) {
1755 args->ThrowError();
1756 return;
1757 }
1758 }
1759
1760 touch_point.radiusX = static_cast<float>(radius_x);
1761 touch_point.radiusY = static_cast<float>(radius_y);
1762 }
1763
1764 int lowest_id = 0; 1758 int lowest_id = 0;
1765 for (size_t i = 0; i < touch_points_.size(); i++) { 1759 for (size_t i = 0; i < touch_points_.size(); i++) {
1766 if (touch_points_[i].id == lowest_id) 1760 if (touch_points_[i].id == lowest_id)
1767 lowest_id++; 1761 lowest_id++;
1768 } 1762 }
1769 touch_point.id = lowest_id; 1763 touch_point.id = lowest_id;
1764
1765 InitPointerProperties(args, &touch_point, &touch_point.radiusX,
1766 &touch_point.radiusY);
1767
1770 touch_points_.push_back(touch_point); 1768 touch_points_.push_back(touch_point);
1771 } 1769 }
1772 1770
1773 void EventSender::MouseDragBegin() { 1771 void EventSender::MouseDragBegin() {
1774 WebMouseWheelEvent event; 1772 WebMouseWheelEvent event;
1775 InitMouseEvent(WebInputEvent::MouseWheel, 1773 InitMouseEvent(WebInputEvent::MouseWheel,
1776 WebMouseEvent::ButtonNone, 1774 WebMouseEvent::ButtonNone,
1777 last_mouse_pos_, 1775 last_mouse_pos_,
1778 GetCurrentEventTimeSec(), 1776 GetCurrentEventTimeSec(),
1779 click_count_, 1777 click_count_,
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
2374 event->canScroll = can_scroll; 2372 event->canScroll = can_scroll;
2375 if (continuous) { 2373 if (continuous) {
2376 event->wheelTicksX /= kScrollbarPixelsPerTick; 2374 event->wheelTicksX /= kScrollbarPixelsPerTick;
2377 event->wheelTicksY /= kScrollbarPixelsPerTick; 2375 event->wheelTicksY /= kScrollbarPixelsPerTick;
2378 } else { 2376 } else {
2379 event->deltaX *= kScrollbarPixelsPerTick; 2377 event->deltaX *= kScrollbarPixelsPerTick;
2380 event->deltaY *= kScrollbarPixelsPerTick; 2378 event->deltaY *= kScrollbarPixelsPerTick;
2381 } 2379 }
2382 } 2380 }
2383 2381
2382 // Radius fields radius_x and radius_y should eventually be moved to
2383 // WebPointerProperties.
2384 // TODO(e_hakkinen): Drop radius_{x,y}_pointer parameters once that happens.
2385 void EventSender::InitPointerProperties(gin::Arguments* args,
2386 blink::WebPointerProperties* e,
2387 float* radius_x_pointer,
2388 float* radius_y_pointer) {
2389 if (!args->PeekNext().IsEmpty()) {
2390 double radius_x;
2391 if (!args->GetNext(&radius_x)) {
2392 args->ThrowError();
2393 return;
2394 }
2395
2396 double radius_y = radius_x;
2397 if (!args->PeekNext().IsEmpty()) {
2398 if (!args->GetNext(&radius_y)) {
2399 args->ThrowError();
2400 return;
2401 }
2402 }
2403
2404 *radius_x_pointer = static_cast<float>(radius_x);
2405 *radius_y_pointer = static_cast<float>(radius_y);
2406 }
2407
2408 if (!args->PeekNext().IsEmpty()) {
2409 double force;
2410 if (!args->GetNext(&force)) {
2411 args->ThrowError();
2412 return;
2413 }
2414 e->force = static_cast<float>(force);
2415 }
2416
2417 if (!args->PeekNext().IsEmpty()) {
2418 int tiltX, tiltY;
2419 if (!args->GetNext(&tiltX) || !args->GetNext(&tiltY)) {
2420 args->ThrowError();
2421 return;
2422 }
2423 e->tiltX = tiltX;
2424 e->tiltY = tiltY;
2425 }
2426
2427 if (!args->PeekNext().IsEmpty()) {
2428 std::string pointer_type_string;
2429 if (!args->GetNext(&pointer_type_string)) {
2430 args->ThrowError();
2431 return;
2432 }
2433 if (pointer_type_string == kPointerTypeStringUnknown) {
2434 e->pointerType = WebMouseEvent::PointerTypeUnknown;
2435 } else if (pointer_type_string == kPointerTypeStringMouse) {
2436 e->pointerType = WebMouseEvent::PointerTypeMouse;
2437 } else if (pointer_type_string == kPointerTypeStringPen) {
2438 e->pointerType = WebMouseEvent::PointerTypePen;
2439 } else if (pointer_type_string == kPointerTypeStringTouch) {
2440 e->pointerType = WebMouseEvent::PointerTypeTouch;
2441 } else {
2442 args->ThrowError();
2443 return;
2444 }
2445 }
2446 }
2447
2384 void EventSender::FinishDragAndDrop(const WebMouseEvent& e, 2448 void EventSender::FinishDragAndDrop(const WebMouseEvent& e,
2385 blink::WebDragOperation drag_effect) { 2449 blink::WebDragOperation drag_effect) {
2386 WebPoint client_point(e.x, e.y); 2450 WebPoint client_point(e.x, e.y);
2387 WebPoint screen_point(e.globalX, e.globalY); 2451 WebPoint screen_point(e.globalX, e.globalY);
2388 current_drag_effect_ = drag_effect; 2452 current_drag_effect_ = drag_effect;
2389 if (current_drag_effect_) { 2453 if (current_drag_effect_) {
2390 // Specifically pass any keyboard modifiers to the drop method. This allows 2454 // Specifically pass any keyboard modifiers to the drop method. This allows
2391 // tests to control the drop type (i.e. copy or move). 2455 // tests to control the drop type (i.e. copy or move).
2392 view_->dragTargetDrop(client_point, screen_point, e.modifiers); 2456 view_->dragTargetDrop(client_point, screen_point, e.modifiers);
2393 } else { 2457 } else {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2481 2545
2482 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { 2546 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) {
2483 if (WebPagePopup* popup = view_->pagePopup()) { 2547 if (WebPagePopup* popup = view_->pagePopup()) {
2484 if (!WebInputEvent::isKeyboardEventType(event.type)) 2548 if (!WebInputEvent::isKeyboardEventType(event.type))
2485 return popup->handleInputEvent(event); 2549 return popup->handleInputEvent(event);
2486 } 2550 }
2487 return view_->handleInputEvent(event); 2551 return view_->handleInputEvent(event);
2488 } 2552 }
2489 2553
2490 } // namespace test_runner 2554 } // namespace test_runner
OLDNEW
« no previous file with comments | « components/test_runner/event_sender.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698