| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 void ForwardEmulatedGestureEvent( | 56 void ForwardEmulatedGestureEvent( |
| 57 const blink::WebGestureEvent& event) override { | 57 const blink::WebGestureEvent& event) override { |
| 58 forwarded_events_.push_back(event.type); | 58 forwarded_events_.push_back(event.type); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void ForwardEmulatedTouchEvent(const blink::WebTouchEvent& event) override { | 61 void ForwardEmulatedTouchEvent(const blink::WebTouchEvent& event) override { |
| 62 forwarded_events_.push_back(event.type); | 62 forwarded_events_.push_back(event.type); |
| 63 EXPECT_EQ(1U, event.touchesLength); | 63 EXPECT_EQ(1U, event.touchesLength); |
| 64 EXPECT_EQ(last_mouse_x_, event.touches[0].position.x); | 64 EXPECT_EQ(last_mouse_x_, event.touches[0].position.x); |
| 65 EXPECT_EQ(last_mouse_y_, event.touches[0].position.y); | 65 EXPECT_EQ(last_mouse_y_, event.touches[0].position.y); |
| 66 const int all_buttons = WebInputEvent::LeftButtonDown | |
| 67 WebInputEvent::MiddleButtonDown | WebInputEvent::RightButtonDown; |
| 68 EXPECT_EQ(0, event.modifiers & all_buttons); |
| 66 WebInputEvent::DispatchType expected_dispatch_type = | 69 WebInputEvent::DispatchType expected_dispatch_type = |
| 67 event.type == WebInputEvent::TouchCancel | 70 event.type == WebInputEvent::TouchCancel |
| 68 ? WebInputEvent::EventNonBlocking | 71 ? WebInputEvent::EventNonBlocking |
| 69 : WebInputEvent::Blocking; | 72 : WebInputEvent::Blocking; |
| 70 EXPECT_EQ(expected_dispatch_type, event.dispatchType); | 73 EXPECT_EQ(expected_dispatch_type, event.dispatchType); |
| 71 if (ack_touches_synchronously_) { | 74 if (ack_touches_synchronously_) { |
| 72 emulator()->HandleTouchEventAck( | 75 emulator()->HandleTouchEventAck( |
| 73 event, INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 76 event, INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 74 } | 77 } |
| 75 } | 78 } |
| 76 | 79 |
| 77 void SetCursor(const WebCursor& cursor) override {} | 80 void SetCursor(const WebCursor& cursor) override {} |
| 78 | 81 |
| 79 void ShowContextMenuAtPoint(const gfx::Point& point) override {} | 82 void ShowContextMenuAtPoint(const gfx::Point& point) override {} |
| 80 | 83 |
| 81 protected: | 84 protected: |
| 82 TouchEmulator* emulator() const { | 85 TouchEmulator* emulator() const { |
| 83 return emulator_.get(); | 86 return emulator_.get(); |
| 84 } | 87 } |
| 85 | 88 |
| 86 int modifiers() const { | 89 int modifiers() const { |
| 87 return shift_pressed_ ? WebInputEvent::ShiftKey : 0; | 90 return (shift_pressed_ ? WebInputEvent::ShiftKey : 0) | |
| 91 (mouse_pressed_ ? WebInputEvent::LeftButtonDown : 0); |
| 88 } | 92 } |
| 89 | 93 |
| 90 std::string ExpectedEvents() { | 94 std::string ExpectedEvents() { |
| 91 std::string result; | 95 std::string result; |
| 92 for (size_t i = 0; i < forwarded_events_.size(); ++i) { | 96 for (size_t i = 0; i < forwarded_events_.size(); ++i) { |
| 93 if (i != 0) | 97 if (i != 0) |
| 94 result += " "; | 98 result += " "; |
| 95 result += WebInputEventTraits::GetName(forwarded_events_[i]); | 99 result += WebInputEventTraits::GetName(forwarded_events_[i]); |
| 96 } | 100 } |
| 97 forwarded_events_.clear(); | 101 forwarded_events_.clear(); |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 emulator()->Disable(); | 563 emulator()->Disable(); |
| 560 EXPECT_EQ("TouchStart TouchCancel", ExpectedEvents()); | 564 EXPECT_EQ("TouchStart TouchCancel", ExpectedEvents()); |
| 561 emulator()->CancelTouch(); | 565 emulator()->CancelTouch(); |
| 562 } | 566 } |
| 563 | 567 |
| 564 TEST_F(TouchEmulatorTest, ConstructorWithHighDeviceScaleDoesNotCrash) { | 568 TEST_F(TouchEmulatorTest, ConstructorWithHighDeviceScaleDoesNotCrash) { |
| 565 TouchEmulator(this, 4.0f); | 569 TouchEmulator(this, 4.0f); |
| 566 } | 570 } |
| 567 | 571 |
| 568 } // namespace content | 572 } // namespace content |
| OLD | NEW |