| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "core/events/PointerEventFactory.h" | 5 #include "core/events/PointerEventFactory.h" |
| 6 | 6 |
| 7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
| 8 #include "core/page/Page.h" | 8 #include "core/page/Page.h" |
| 9 #include "public/platform/WebPointerProperties.h" | 9 #include "public/platform/WebPointerProperties.h" |
| 10 #include <climits> | 10 #include <climits> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 void SetUp() override; | 37 void SetUp() override; |
| 38 PointerEvent* createAndCheckTouchCancel(WebPointerProperties::PointerType, | 38 PointerEvent* createAndCheckTouchCancel(WebPointerProperties::PointerType, |
| 39 int rawId, | 39 int rawId, |
| 40 int uniqueId, | 40 int uniqueId, |
| 41 bool isPrimary); | 41 bool isPrimary); |
| 42 PointerEvent* createAndCheckTouchEvent( | 42 PointerEvent* createAndCheckTouchEvent( |
| 43 WebPointerProperties::PointerType, | 43 WebPointerProperties::PointerType, |
| 44 int rawId, | 44 int rawId, |
| 45 int uniqueId, | 45 int uniqueId, |
| 46 bool isPrimary, | 46 bool isPrimary, |
| 47 PlatformTouchPoint::TouchState = PlatformTouchPoint::TouchPressed, | 47 WebTouchPoint::State = WebTouchPoint::StatePressed, |
| 48 size_t coalescedEventCount = 0); | 48 size_t coalescedEventCount = 0); |
| 49 PointerEvent* createAndCheckMouseEvent( | 49 PointerEvent* createAndCheckMouseEvent( |
| 50 WebPointerProperties::PointerType, | 50 WebPointerProperties::PointerType, |
| 51 int rawId, | 51 int rawId, |
| 52 int uniqueId, | 52 int uniqueId, |
| 53 bool isPrimary, | 53 bool isPrimary, |
| 54 PlatformEvent::Modifiers = PlatformEvent::NoModifiers, | 54 PlatformEvent::Modifiers = PlatformEvent::NoModifiers, |
| 55 size_t coalescedEventCount = 0); | 55 size_t coalescedEventCount = 0); |
| 56 void createAndCheckPointerTransitionEvent(PointerEvent*, const AtomicString&); | 56 void createAndCheckPointerTransitionEvent(PointerEvent*, const AtomicString&); |
| 57 | 57 |
| 58 PointerEventFactory m_pointerEventFactory; | 58 PointerEventFactory m_pointerEventFactory; |
| 59 unsigned m_expectedMouseId; | 59 unsigned m_expectedMouseId; |
| 60 unsigned m_mappedIdStart; | 60 unsigned m_mappedIdStart; |
| 61 | 61 |
| 62 class PlatformTouchPointBuilder : public PlatformTouchPoint { | 62 class WebTouchPointBuilder : public WebTouchPoint { |
| 63 public: | 63 public: |
| 64 PlatformTouchPointBuilder(WebPointerProperties::PointerType, | 64 WebTouchPointBuilder(WebPointerProperties::PointerType, |
| 65 int, | 65 int, |
| 66 PlatformTouchPoint::TouchState); | 66 WebTouchPoint::State); |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 class PlatformMouseEventBuilder : public PlatformMouseEvent { | 69 class PlatformMouseEventBuilder : public PlatformMouseEvent { |
| 70 public: | 70 public: |
| 71 PlatformMouseEventBuilder(WebPointerProperties::PointerType, | 71 PlatformMouseEventBuilder(WebPointerProperties::PointerType, |
| 72 int, | 72 int, |
| 73 PlatformEvent::Modifiers); | 73 PlatformEvent::Modifiers); |
| 74 }; | 74 }; |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 void PointerEventFactoryTest::SetUp() { | 77 void PointerEventFactoryTest::SetUp() { |
| 78 m_expectedMouseId = 1; | 78 m_expectedMouseId = 1; |
| 79 m_mappedIdStart = 2; | 79 m_mappedIdStart = 2; |
| 80 } | 80 } |
| 81 | 81 |
| 82 PointerEventFactoryTest::PlatformTouchPointBuilder::PlatformTouchPointBuilder( | 82 PointerEventFactoryTest::WebTouchPointBuilder::WebTouchPointBuilder( |
| 83 WebPointerProperties::PointerType pointerType, | 83 WebPointerProperties::PointerType pointerTypeParam, |
| 84 int id, | 84 int idParam, |
| 85 PlatformTouchPoint::TouchState state) { | 85 WebTouchPoint::State stateParam) { |
| 86 m_pointerProperties.id = id; | 86 id = idParam; |
| 87 m_pointerProperties.pointerType = pointerType; | 87 pointerType = pointerTypeParam; |
| 88 m_pointerProperties.force = 1.0; | 88 force = 1.0; |
| 89 m_state = state; | 89 state = stateParam; |
| 90 } | 90 } |
| 91 | 91 |
| 92 PointerEventFactoryTest::PlatformMouseEventBuilder::PlatformMouseEventBuilder( | 92 PointerEventFactoryTest::PlatformMouseEventBuilder::PlatformMouseEventBuilder( |
| 93 WebPointerProperties::PointerType pointerType, | 93 WebPointerProperties::PointerType pointerType, |
| 94 int id, | 94 int id, |
| 95 PlatformEvent::Modifiers modifiers) { | 95 PlatformEvent::Modifiers modifiers) { |
| 96 m_pointerProperties.pointerType = pointerType; | 96 m_pointerProperties.pointerType = pointerType; |
| 97 m_pointerProperties.id = id; | 97 m_pointerProperties.id = id; |
| 98 m_modifiers = modifiers; | 98 m_modifiers = modifiers; |
| 99 } | 99 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 122 EXPECT_EQ(clonePointerEvent->pointerId(), pointerEvent->pointerId()); | 122 EXPECT_EQ(clonePointerEvent->pointerId(), pointerEvent->pointerId()); |
| 123 EXPECT_EQ(clonePointerEvent->isPrimary(), pointerEvent->isPrimary()); | 123 EXPECT_EQ(clonePointerEvent->isPrimary(), pointerEvent->isPrimary()); |
| 124 EXPECT_EQ(clonePointerEvent->type(), type); | 124 EXPECT_EQ(clonePointerEvent->type(), type); |
| 125 } | 125 } |
| 126 | 126 |
| 127 PointerEvent* PointerEventFactoryTest::createAndCheckTouchEvent( | 127 PointerEvent* PointerEventFactoryTest::createAndCheckTouchEvent( |
| 128 WebPointerProperties::PointerType pointerType, | 128 WebPointerProperties::PointerType pointerType, |
| 129 int rawId, | 129 int rawId, |
| 130 int uniqueId, | 130 int uniqueId, |
| 131 bool isPrimary, | 131 bool isPrimary, |
| 132 PlatformTouchPoint::TouchState state, | 132 WebTouchPoint::State state, |
| 133 size_t coalescedEventCount) { | 133 size_t coalescedEventCount) { |
| 134 Vector<PlatformTouchPoint> coalescedEvents; | 134 Vector<WebTouchPoint> coalescedEvents; |
| 135 for (size_t i = 0; i < coalescedEventCount; i++) { | 135 for (size_t i = 0; i < coalescedEventCount; i++) { |
| 136 coalescedEvents.push_back( | 136 coalescedEvents.push_back(PointerEventFactoryTest::WebTouchPointBuilder( |
| 137 PointerEventFactoryTest::PlatformTouchPointBuilder(pointerType, rawId, | 137 pointerType, rawId, state)); |
| 138 state)); | |
| 139 } | 138 } |
| 140 PointerEvent* pointerEvent = m_pointerEventFactory.create( | 139 PointerEvent* pointerEvent = m_pointerEventFactory.create( |
| 141 PointerEventFactoryTest::PlatformTouchPointBuilder(pointerType, rawId, | 140 PointerEventFactoryTest::WebTouchPointBuilder(pointerType, rawId, state), |
| 142 state), | 141 coalescedEvents, WebInputEvent::NoModifiers, nullptr, nullptr); |
| 143 coalescedEvents, PlatformEvent::NoModifiers, nullptr, nullptr); | |
| 144 EXPECT_EQ(uniqueId, pointerEvent->pointerId()); | 142 EXPECT_EQ(uniqueId, pointerEvent->pointerId()); |
| 145 EXPECT_EQ(isPrimary, pointerEvent->isPrimary()); | 143 EXPECT_EQ(isPrimary, pointerEvent->isPrimary()); |
| 146 const char* expectedPointerType = | 144 const char* expectedPointerType = |
| 147 pointerTypeNameForWebPointPointerType(pointerType); | 145 pointerTypeNameForWebPointPointerType(pointerType); |
| 148 EXPECT_EQ(expectedPointerType, pointerEvent->pointerType()); | 146 EXPECT_EQ(expectedPointerType, pointerEvent->pointerType()); |
| 149 EXPECT_EQ(coalescedEventCount, pointerEvent->getCoalescedEvents().size()); | 147 EXPECT_EQ(coalescedEventCount, pointerEvent->getCoalescedEvents().size()); |
| 150 for (size_t i = 0; i < coalescedEventCount; i++) { | 148 for (size_t i = 0; i < coalescedEventCount; i++) { |
| 151 EXPECT_EQ(uniqueId, pointerEvent->getCoalescedEvents()[i]->pointerId()); | 149 EXPECT_EQ(uniqueId, pointerEvent->getCoalescedEvents()[i]->pointerId()); |
| 152 EXPECT_EQ(isPrimary, pointerEvent->getCoalescedEvents()[i]->isPrimary()); | 150 EXPECT_EQ(isPrimary, pointerEvent->getCoalescedEvents()[i]->isPrimary()); |
| 153 EXPECT_EQ(expectedPointerType, pointerEvent->pointerType()); | 151 EXPECT_EQ(expectedPointerType, pointerEvent->pointerType()); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 282 |
| 285 PointerEvent* pointerEvent1 = createAndCheckTouchEvent( | 283 PointerEvent* pointerEvent1 = createAndCheckTouchEvent( |
| 286 WebPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); | 284 WebPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); |
| 287 PointerEvent* pointerEvent2 = createAndCheckTouchEvent( | 285 PointerEvent* pointerEvent2 = createAndCheckTouchEvent( |
| 288 WebPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); | 286 WebPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); |
| 289 | 287 |
| 290 EXPECT_TRUE(m_pointerEventFactory.isActive(m_mappedIdStart)); | 288 EXPECT_TRUE(m_pointerEventFactory.isActive(m_mappedIdStart)); |
| 291 EXPECT_TRUE(m_pointerEventFactory.isActiveButtonsState(m_mappedIdStart)); | 289 EXPECT_TRUE(m_pointerEventFactory.isActiveButtonsState(m_mappedIdStart)); |
| 292 | 290 |
| 293 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, | 291 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, |
| 294 m_mappedIdStart, true, | 292 m_mappedIdStart, true, WebTouchPoint::StateReleased); |
| 295 PlatformTouchPoint::TouchReleased); | |
| 296 | 293 |
| 297 EXPECT_TRUE(m_pointerEventFactory.isActive(m_mappedIdStart)); | 294 EXPECT_TRUE(m_pointerEventFactory.isActive(m_mappedIdStart)); |
| 298 EXPECT_FALSE(m_pointerEventFactory.isActiveButtonsState(m_mappedIdStart)); | 295 EXPECT_FALSE(m_pointerEventFactory.isActiveButtonsState(m_mappedIdStart)); |
| 299 | 296 |
| 300 m_pointerEventFactory.remove(pointerEvent1->pointerId()); | 297 m_pointerEventFactory.remove(pointerEvent1->pointerId()); |
| 301 m_pointerEventFactory.remove(pointerEvent2->pointerId()); | 298 m_pointerEventFactory.remove(pointerEvent2->pointerId()); |
| 302 | 299 |
| 303 EXPECT_FALSE(m_pointerEventFactory.isActive(m_mappedIdStart)); | 300 EXPECT_FALSE(m_pointerEventFactory.isActive(m_mappedIdStart)); |
| 304 EXPECT_FALSE(m_pointerEventFactory.isActiveButtonsState(m_mappedIdStart)); | 301 EXPECT_FALSE(m_pointerEventFactory.isActiveButtonsState(m_mappedIdStart)); |
| 305 | 302 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 } | 441 } |
| 445 createAndCheckTouchCancel(WebPointerProperties::PointerType::Mouse, 0, | 442 createAndCheckTouchCancel(WebPointerProperties::PointerType::Mouse, 0, |
| 446 m_expectedMouseId, true); | 443 m_expectedMouseId, true); |
| 447 } | 444 } |
| 448 | 445 |
| 449 TEST_F(PointerEventFactoryTest, CoalescedEvents) { | 446 TEST_F(PointerEventFactoryTest, CoalescedEvents) { |
| 450 createAndCheckMouseEvent(WebPointerProperties::PointerType::Mouse, 0, | 447 createAndCheckMouseEvent(WebPointerProperties::PointerType::Mouse, 0, |
| 451 m_expectedMouseId, true, PlatformEvent::NoModifiers, | 448 m_expectedMouseId, true, PlatformEvent::NoModifiers, |
| 452 4); | 449 4); |
| 453 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, | 450 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, |
| 454 m_mappedIdStart, true, | 451 m_mappedIdStart, true, WebTouchPoint::StateMoved, 3); |
| 455 PlatformTouchPoint::TouchMoved, 3); | |
| 456 } | 452 } |
| 457 | 453 |
| 458 } // namespace blink | 454 } // namespace blink |
| OLD | NEW |