| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 event.type == WebInputEvent::TouchCancel | 70 event.type == WebInputEvent::TouchCancel |
| 71 ? WebInputEvent::EventNonBlocking | 71 ? WebInputEvent::EventNonBlocking |
| 72 : WebInputEvent::Blocking; | 72 : WebInputEvent::Blocking; |
| 73 EXPECT_EQ(expected_dispatch_type, event.dispatchType); | 73 EXPECT_EQ(expected_dispatch_type, event.dispatchType); |
| 74 if (ack_touches_synchronously_) { | 74 if (ack_touches_synchronously_) { |
| 75 emulator()->HandleTouchEventAck( | 75 emulator()->HandleTouchEventAck( |
| 76 event, INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 76 event, INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 void SetCursor(const WebCursor& cursor) override {} | 80 void SetCursor(const WebCursor& cursor) override { |
| 81 cursor_ = cursor; |
| 82 } |
| 81 | 83 |
| 82 void ShowContextMenuAtPoint(const gfx::Point& point) override {} | 84 void ShowContextMenuAtPoint(const gfx::Point& point) override {} |
| 83 | 85 |
| 84 protected: | 86 protected: |
| 85 TouchEmulator* emulator() const { | 87 TouchEmulator* emulator() const { |
| 86 return emulator_.get(); | 88 return emulator_.get(); |
| 87 } | 89 } |
| 88 | 90 |
| 89 int modifiers() const { | 91 int modifiers() const { |
| 90 return (shift_pressed_ ? WebInputEvent::ShiftKey : 0) | | 92 return (shift_pressed_ ? WebInputEvent::ShiftKey : 0) | |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 DCHECK(touch_events_to_ack_.size()); | 236 DCHECK(touch_events_to_ack_.size()); |
| 235 WebTouchEvent event = touch_events_to_ack_[0]; | 237 WebTouchEvent event = touch_events_to_ack_[0]; |
| 236 touch_events_to_ack_.erase(touch_events_to_ack_.begin()); | 238 touch_events_to_ack_.erase(touch_events_to_ack_.begin()); |
| 237 // Emulator should not handle ack from native stream. | 239 // Emulator should not handle ack from native stream. |
| 238 EXPECT_FALSE(emulator()->HandleTouchEventAck( | 240 EXPECT_FALSE(emulator()->HandleTouchEventAck( |
| 239 event, INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS)); | 241 event, INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS)); |
| 240 } | 242 } |
| 241 | 243 |
| 242 void DisableSynchronousTouchAck() { ack_touches_synchronously_ = false; } | 244 void DisableSynchronousTouchAck() { ack_touches_synchronously_ = false; } |
| 243 | 245 |
| 246 float GetCursorScaleFactor() { |
| 247 WebCursor::CursorInfo info; |
| 248 cursor_.GetCursorInfo(&info); |
| 249 return info.image_scale_factor; |
| 250 } |
| 251 |
| 244 private: | 252 private: |
| 245 std::unique_ptr<TouchEmulator> emulator_; | 253 std::unique_ptr<TouchEmulator> emulator_; |
| 246 std::vector<WebInputEvent::Type> forwarded_events_; | 254 std::vector<WebInputEvent::Type> forwarded_events_; |
| 247 double last_event_time_seconds_; | 255 double last_event_time_seconds_; |
| 248 double event_time_delta_seconds_; | 256 double event_time_delta_seconds_; |
| 249 bool shift_pressed_; | 257 bool shift_pressed_; |
| 250 bool mouse_pressed_; | 258 bool mouse_pressed_; |
| 251 bool ack_touches_synchronously_; | 259 bool ack_touches_synchronously_; |
| 252 int last_mouse_x_; | 260 int last_mouse_x_; |
| 253 int last_mouse_y_; | 261 int last_mouse_y_; |
| 254 std::vector<WebTouchEvent> touch_events_to_ack_; | 262 std::vector<WebTouchEvent> touch_events_to_ack_; |
| 255 base::MessageLoopForUI message_loop_; | 263 base::MessageLoopForUI message_loop_; |
| 264 WebCursor cursor_; |
| 256 }; | 265 }; |
| 257 | 266 |
| 258 | 267 |
| 259 TEST_F(TouchEmulatorTest, NoTouches) { | 268 TEST_F(TouchEmulatorTest, NoTouches) { |
| 260 MouseMove(100, 200); | 269 MouseMove(100, 200); |
| 261 MouseMove(300, 300); | 270 MouseMove(300, 300); |
| 262 EXPECT_EQ("", ExpectedEvents()); | 271 EXPECT_EQ("", ExpectedEvents()); |
| 263 } | 272 } |
| 264 | 273 |
| 265 TEST_F(TouchEmulatorTest, Touch) { | 274 TEST_F(TouchEmulatorTest, Touch) { |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 MouseDown(100, 200); | 571 MouseDown(100, 200); |
| 563 emulator()->Disable(); | 572 emulator()->Disable(); |
| 564 EXPECT_EQ("TouchStart TouchCancel", ExpectedEvents()); | 573 EXPECT_EQ("TouchStart TouchCancel", ExpectedEvents()); |
| 565 emulator()->CancelTouch(); | 574 emulator()->CancelTouch(); |
| 566 } | 575 } |
| 567 | 576 |
| 568 TEST_F(TouchEmulatorTest, ConstructorWithHighDeviceScaleDoesNotCrash) { | 577 TEST_F(TouchEmulatorTest, ConstructorWithHighDeviceScaleDoesNotCrash) { |
| 569 TouchEmulator(this, 4.0f); | 578 TouchEmulator(this, 4.0f); |
| 570 } | 579 } |
| 571 | 580 |
| 581 TEST_F(TouchEmulatorTest, CursorScaleFactor) { |
| 582 EXPECT_EQ(1.0f, GetCursorScaleFactor()); |
| 583 emulator()->SetDeviceScaleFactor(3.0f); |
| 584 EXPECT_EQ(2.0f, GetCursorScaleFactor()); |
| 585 emulator()->SetDeviceScaleFactor(1.33f); |
| 586 EXPECT_EQ(1.0f, GetCursorScaleFactor()); |
| 587 emulator()->Disable(); |
| 588 EXPECT_EQ(1.0f, GetCursorScaleFactor()); |
| 589 emulator()->SetDeviceScaleFactor(3.0f); |
| 590 EXPECT_EQ(1.0f, GetCursorScaleFactor()); |
| 591 emulator()->Enable(ui::GestureProviderConfigType::GENERIC_MOBILE); |
| 592 EXPECT_EQ(2.0f, GetCursorScaleFactor()); |
| 593 emulator()->SetDeviceScaleFactor(1.0f); |
| 594 EXPECT_EQ(1.0f, GetCursorScaleFactor()); |
| 595 |
| 596 TouchEmulator another(this, 4.0f); |
| 597 EXPECT_EQ(1.0f, GetCursorScaleFactor()); |
| 598 another.Enable(ui::GestureProviderConfigType::GENERIC_MOBILE); |
| 599 EXPECT_EQ(2.0f, GetCursorScaleFactor()); |
| 600 } |
| 601 |
| 572 } // namespace content | 602 } // namespace content |
| OLD | NEW |