| 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/input/EventHandler.h" | 5 #include "core/input/EventHandler.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/Range.h" | 8 #include "core/dom/Range.h" |
| 9 #include "core/editing/Editor.h" | 9 #include "core/editing/Editor.h" |
| 10 #include "core/editing/FrameSelection.h" | 10 #include "core/editing/FrameSelection.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 33 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 class TapEventBuilder : public PlatformGestureEvent { | 36 class TapEventBuilder : public PlatformGestureEvent { |
| 37 public: | 37 public: |
| 38 TapEventBuilder(IntPoint position, int tapCount) | 38 TapEventBuilder(IntPoint position, int tapCount) |
| 39 : PlatformGestureEvent(PlatformEvent::GestureTap, | 39 : PlatformGestureEvent(PlatformEvent::GestureTap, |
| 40 position, | 40 position, |
| 41 position, | 41 position, |
| 42 IntSize(5, 5), | 42 IntSize(5, 5), |
| 43 WTF::monotonicallyIncreasingTime(), | 43 TimeTicks::Now(), |
| 44 static_cast<PlatformEvent::Modifiers>(0), | 44 static_cast<PlatformEvent::Modifiers>(0), |
| 45 PlatformGestureSourceTouchscreen) { | 45 PlatformGestureSourceTouchscreen) { |
| 46 m_data.m_tap.m_tapCount = tapCount; | 46 m_data.m_tap.m_tapCount = tapCount; |
| 47 } | 47 } |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 void EventHandlerTest::SetUp() { | 50 void EventHandlerTest::SetUp() { |
| 51 m_dummyPageHolder = DummyPageHolder::create(IntSize(300, 400)); | 51 m_dummyPageHolder = DummyPageHolder::create(IntSize(300, 400)); |
| 52 } | 52 } |
| 53 | 53 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 71 "class='line'>Line 10</span>" | 71 "class='line'>Line 10</span>" |
| 72 "</div>"); | 72 "</div>"); |
| 73 | 73 |
| 74 FrameView* frameView = document().view(); | 74 FrameView* frameView = document().view(); |
| 75 frameView->layoutViewportScrollableArea()->setScrollOffset( | 75 frameView->layoutViewportScrollableArea()->setScrollOffset( |
| 76 ScrollOffset(0, 400), ProgrammaticScroll); | 76 ScrollOffset(0, 400), ProgrammaticScroll); |
| 77 | 77 |
| 78 PlatformMouseEvent mouseDownEvent( | 78 PlatformMouseEvent mouseDownEvent( |
| 79 IntPoint(0, 0), IntPoint(100, 200), WebPointerProperties::Button::Left, | 79 IntPoint(0, 0), IntPoint(100, 200), WebPointerProperties::Button::Left, |
| 80 PlatformEvent::MousePressed, 1, PlatformEvent::Modifiers::LeftButtonDown, | 80 PlatformEvent::MousePressed, 1, PlatformEvent::Modifiers::LeftButtonDown, |
| 81 WTF::monotonicallyIncreasingTime()); | 81 TimeTicks::Now()); |
| 82 document().frame()->eventHandler().handleMousePressEvent(mouseDownEvent); | 82 document().frame()->eventHandler().handleMousePressEvent(mouseDownEvent); |
| 83 | 83 |
| 84 PlatformMouseEvent mouseMoveEvent( | 84 PlatformMouseEvent mouseMoveEvent( |
| 85 IntPoint(100, 50), IntPoint(200, 250), WebPointerProperties::Button::Left, | 85 IntPoint(100, 50), IntPoint(200, 250), WebPointerProperties::Button::Left, |
| 86 PlatformEvent::MouseMoved, 1, PlatformEvent::Modifiers::LeftButtonDown, | 86 PlatformEvent::MouseMoved, 1, PlatformEvent::Modifiers::LeftButtonDown, |
| 87 WTF::monotonicallyIncreasingTime()); | 87 TimeTicks::Now()); |
| 88 document().frame()->eventHandler().handleMouseMoveEvent( | 88 document().frame()->eventHandler().handleMouseMoveEvent( |
| 89 mouseMoveEvent, Vector<PlatformMouseEvent>()); | 89 mouseMoveEvent, Vector<PlatformMouseEvent>()); |
| 90 | 90 |
| 91 page().autoscrollController().animate(WTF::monotonicallyIncreasingTime()); | 91 page().autoscrollController().animate(WTF::monotonicallyIncreasingTime()); |
| 92 page().animator().serviceScriptedAnimations( | 92 page().animator().serviceScriptedAnimations( |
| 93 WTF::monotonicallyIncreasingTime()); | 93 WTF::monotonicallyIncreasingTime()); |
| 94 | 94 |
| 95 PlatformMouseEvent mouseUpEvent( | 95 PlatformMouseEvent mouseUpEvent( |
| 96 IntPoint(100, 50), IntPoint(200, 250), WebPointerProperties::Button::Left, | 96 IntPoint(100, 50), IntPoint(200, 250), WebPointerProperties::Button::Left, |
| 97 PlatformEvent::MouseReleased, 1, static_cast<PlatformEvent::Modifiers>(0), | 97 PlatformEvent::MouseReleased, 1, static_cast<PlatformEvent::Modifiers>(0), |
| 98 WTF::monotonicallyIncreasingTime()); | 98 TimeTicks::Now()); |
| 99 document().frame()->eventHandler().handleMouseReleaseEvent(mouseUpEvent); | 99 document().frame()->eventHandler().handleMouseReleaseEvent(mouseUpEvent); |
| 100 | 100 |
| 101 FrameSelection& selection = document().frame()->selection(); | 101 FrameSelection& selection = document().frame()->selection(); |
| 102 ASSERT_TRUE(selection.isRange()); | 102 ASSERT_TRUE(selection.isRange()); |
| 103 Range* range = | 103 Range* range = |
| 104 createRange(selection.selection().toNormalizedEphemeralRange()); | 104 createRange(selection.selection().toNormalizedEphemeralRange()); |
| 105 ASSERT_TRUE(range); | 105 ASSERT_TRUE(range); |
| 106 EXPECT_EQ("Line 1\nLine 2", range->text()); | 106 EXPECT_EQ("Line 1\nLine 2", range->text()); |
| 107 } | 107 } |
| 108 | 108 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 "body { margin: 0px; }" | 175 "body { margin: 0px; }" |
| 176 ".line { font-family: sans-serif; background: blue; width: 300px; " | 176 ".line { font-family: sans-serif; background: blue; width: 300px; " |
| 177 "height: 30px; font-size: 40px; margin-left: 250px; }" | 177 "height: 30px; font-size: 40px; margin-left: 250px; }" |
| 178 "</style>" | 178 "</style>" |
| 179 "<div style='width: 300px; height: 100px;'>" | 179 "<div style='width: 300px; height: 100px;'>" |
| 180 "<span class='line' draggable='true'>abcd</span>" | 180 "<span class='line' draggable='true'>abcd</span>" |
| 181 "</div>"); | 181 "</div>"); |
| 182 PlatformMouseEvent mouseDownEvent( | 182 PlatformMouseEvent mouseDownEvent( |
| 183 IntPoint(262, 29), IntPoint(329, 67), WebPointerProperties::Button::Left, | 183 IntPoint(262, 29), IntPoint(329, 67), WebPointerProperties::Button::Left, |
| 184 PlatformEvent::MousePressed, 1, PlatformEvent::Modifiers::LeftButtonDown, | 184 PlatformEvent::MousePressed, 1, PlatformEvent::Modifiers::LeftButtonDown, |
| 185 WTF::monotonicallyIncreasingTime()); | 185 TimeTicks::Now()); |
| 186 document().frame()->eventHandler().handleMousePressEvent(mouseDownEvent); | 186 document().frame()->eventHandler().handleMousePressEvent(mouseDownEvent); |
| 187 | 187 |
| 188 PlatformMouseEvent mouseMoveEvent(IntPoint(618, 298), IntPoint(685, 436), | 188 PlatformMouseEvent mouseMoveEvent( |
| 189 WebPointerProperties::Button::Left, | 189 IntPoint(618, 298), IntPoint(685, 436), |
| 190 PlatformEvent::MouseMoved, 1, | 190 WebPointerProperties::Button::Left, PlatformEvent::MouseMoved, 1, |
| 191 PlatformEvent::Modifiers::LeftButtonDown, | 191 PlatformEvent::Modifiers::LeftButtonDown, TimeTicks::Now()); |
| 192 WTF::monotonicallyIncreasingTime()); | |
| 193 document().frame()->eventHandler().handleMouseMoveEvent( | 192 document().frame()->eventHandler().handleMouseMoveEvent( |
| 194 mouseMoveEvent, Vector<PlatformMouseEvent>()); | 193 mouseMoveEvent, Vector<PlatformMouseEvent>()); |
| 195 | 194 |
| 196 EXPECT_EQ( | 195 EXPECT_EQ( |
| 197 IntPoint(12, 29), | 196 IntPoint(12, 29), |
| 198 document().frame()->eventHandler().dragDataTransferLocationForTesting()); | 197 document().frame()->eventHandler().dragDataTransferLocationForTesting()); |
| 199 } | 198 } |
| 200 | 199 |
| 201 TEST_F(EventHandlerTest, draggedSVGImagePositionTest) { | 200 TEST_F(EventHandlerTest, draggedSVGImagePositionTest) { |
| 202 setHtmlInnerHTML( | 201 setHtmlInnerHTML( |
| 203 "<style>" | 202 "<style>" |
| 204 "body { margin: 0px; }" | 203 "body { margin: 0px; }" |
| 205 "[draggable] {" | 204 "[draggable] {" |
| 206 "-webkit-user-select: none; user-select: none; -webkit-user-drag: " | 205 "-webkit-user-select: none; user-select: none; -webkit-user-drag: " |
| 207 "element; }" | 206 "element; }" |
| 208 "</style>" | 207 "</style>" |
| 209 "<div style='width: 300px; height: 100px;'>" | 208 "<div style='width: 300px; height: 100px;'>" |
| 210 "<svg width='500' height='500'>" | 209 "<svg width='500' height='500'>" |
| 211 "<rect x='100' y='100' width='100px' height='100px' fill='blue' " | 210 "<rect x='100' y='100' width='100px' height='100px' fill='blue' " |
| 212 "draggable='true'/>" | 211 "draggable='true'/>" |
| 213 "</svg>" | 212 "</svg>" |
| 214 "</div>"); | 213 "</div>"); |
| 215 PlatformMouseEvent mouseDownEvent(IntPoint(145, 144), IntPoint(212, 282), | 214 PlatformMouseEvent mouseDownEvent( |
| 216 WebPointerProperties::Button::Left, | 215 IntPoint(145, 144), IntPoint(212, 282), |
| 217 PlatformEvent::MousePressed, 1, | 216 WebPointerProperties::Button::Left, PlatformEvent::MousePressed, 1, |
| 218 PlatformEvent::Modifiers::LeftButtonDown, | 217 PlatformEvent::Modifiers::LeftButtonDown, TimeTicks::Now()); |
| 219 WTF::monotonicallyIncreasingTime()); | |
| 220 document().frame()->eventHandler().handleMousePressEvent(mouseDownEvent); | 218 document().frame()->eventHandler().handleMousePressEvent(mouseDownEvent); |
| 221 | 219 |
| 222 PlatformMouseEvent mouseMoveEvent(IntPoint(618, 298), IntPoint(685, 436), | 220 PlatformMouseEvent mouseMoveEvent( |
| 223 WebPointerProperties::Button::Left, | 221 IntPoint(618, 298), IntPoint(685, 436), |
| 224 PlatformEvent::MouseMoved, 1, | 222 WebPointerProperties::Button::Left, PlatformEvent::MouseMoved, 1, |
| 225 PlatformEvent::Modifiers::LeftButtonDown, | 223 PlatformEvent::Modifiers::LeftButtonDown, TimeTicks::Now()); |
| 226 WTF::monotonicallyIncreasingTime()); | |
| 227 document().frame()->eventHandler().handleMouseMoveEvent( | 224 document().frame()->eventHandler().handleMouseMoveEvent( |
| 228 mouseMoveEvent, Vector<PlatformMouseEvent>()); | 225 mouseMoveEvent, Vector<PlatformMouseEvent>()); |
| 229 | 226 |
| 230 EXPECT_EQ( | 227 EXPECT_EQ( |
| 231 IntPoint(45, 44), | 228 IntPoint(45, 44), |
| 232 document().frame()->eventHandler().dragDataTransferLocationForTesting()); | 229 document().frame()->eventHandler().dragDataTransferLocationForTesting()); |
| 233 } | 230 } |
| 234 | 231 |
| 235 // Regression test for http://crbug.com/641403 to verify we use up-to-date | 232 // Regression test for http://crbug.com/641403 to verify we use up-to-date |
| 236 // layout tree for dispatching "contextmenu" event. | 233 // layout tree for dispatching "contextmenu" event. |
| 237 TEST_F(EventHandlerTest, sendContextMenuEventWithHover) { | 234 TEST_F(EventHandlerTest, sendContextMenuEventWithHover) { |
| 238 setHtmlInnerHTML( | 235 setHtmlInnerHTML( |
| 239 "<style>*:hover { color: red; }</style>" | 236 "<style>*:hover { color: red; }</style>" |
| 240 "<div>foo</div>"); | 237 "<div>foo</div>"); |
| 241 document().settings()->setScriptEnabled(true); | 238 document().settings()->setScriptEnabled(true); |
| 242 Element* script = document().createElement("script"); | 239 Element* script = document().createElement("script"); |
| 243 script->setInnerHTML( | 240 script->setInnerHTML( |
| 244 "document.addEventListener('contextmenu', event => " | 241 "document.addEventListener('contextmenu', event => " |
| 245 "event.preventDefault());"); | 242 "event.preventDefault());"); |
| 246 document().body()->appendChild(script); | 243 document().body()->appendChild(script); |
| 247 document().updateStyleAndLayout(); | 244 document().updateStyleAndLayout(); |
| 248 document().frame()->selection().setSelection( | 245 document().frame()->selection().setSelection( |
| 249 SelectionInDOMTree::Builder() | 246 SelectionInDOMTree::Builder() |
| 250 .collapse(Position(document().body(), 0)) | 247 .collapse(Position(document().body(), 0)) |
| 251 .build()); | 248 .build()); |
| 252 PlatformMouseEvent mouseDownEvent( | 249 PlatformMouseEvent mouseDownEvent( |
| 253 IntPoint(0, 0), IntPoint(100, 200), WebPointerProperties::Button::Right, | 250 IntPoint(0, 0), IntPoint(100, 200), WebPointerProperties::Button::Right, |
| 254 PlatformEvent::MousePressed, 1, PlatformEvent::Modifiers::RightButtonDown, | 251 PlatformEvent::MousePressed, 1, PlatformEvent::Modifiers::RightButtonDown, |
| 255 WTF::monotonicallyIncreasingTime()); | 252 TimeTicks::Now()); |
| 256 EXPECT_EQ( | 253 EXPECT_EQ( |
| 257 WebInputEventResult::HandledApplication, | 254 WebInputEventResult::HandledApplication, |
| 258 document().frame()->eventHandler().sendContextMenuEvent(mouseDownEvent)); | 255 document().frame()->eventHandler().sendContextMenuEvent(mouseDownEvent)); |
| 259 } | 256 } |
| 260 | 257 |
| 261 } // namespace blink | 258 } // namespace blink |
| OLD | NEW |