| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 page().animator().serviceScriptedAnimations( | 127 page().animator().serviceScriptedAnimations( |
| 128 WTF::monotonicallyIncreasingTime()); | 128 WTF::monotonicallyIncreasingTime()); |
| 129 | 129 |
| 130 WebMouseEvent mouseUpEvent( | 130 WebMouseEvent mouseUpEvent( |
| 131 WebMouseEvent::MouseUp, WebFloatPoint(100, 50), WebFloatPoint(200, 250), | 131 WebMouseEvent::MouseUp, WebFloatPoint(100, 50), WebFloatPoint(200, 250), |
| 132 WebPointerProperties::Button::Left, 1, WebInputEvent::NoModifiers, | 132 WebPointerProperties::Button::Left, 1, WebInputEvent::NoModifiers, |
| 133 WebInputEvent::TimeStampForTesting); | 133 WebInputEvent::TimeStampForTesting); |
| 134 mouseUpEvent.setFrameScale(1); | 134 mouseUpEvent.setFrameScale(1); |
| 135 document().frame()->eventHandler().handleMouseReleaseEvent(mouseUpEvent); | 135 document().frame()->eventHandler().handleMouseReleaseEvent(mouseUpEvent); |
| 136 | 136 |
| 137 ASSERT_TRUE(selection().isRange()); | 137 ASSERT_TRUE( |
| 138 selection().computeVisibleSelectionInDOMTreeDeprecated().isRange()); |
| 138 Range* range = createRange(selection() | 139 Range* range = createRange(selection() |
| 139 .computeVisibleSelectionInDOMTreeDeprecated() | 140 .computeVisibleSelectionInDOMTreeDeprecated() |
| 140 .toNormalizedEphemeralRange()); | 141 .toNormalizedEphemeralRange()); |
| 141 ASSERT_TRUE(range); | 142 ASSERT_TRUE(range); |
| 142 EXPECT_EQ("Line 1\nLine 2", range->text()); | 143 EXPECT_EQ("Line 1\nLine 2", range->text()); |
| 143 } | 144 } |
| 144 | 145 |
| 145 TEST_F(EventHandlerTest, multiClickSelectionFromTap) { | 146 TEST_F(EventHandlerTest, multiClickSelectionFromTap) { |
| 146 setHtmlInnerHTML( | 147 setHtmlInnerHTML( |
| 147 "<style> body { margin: 0px; } .line { display: block; width: 300px; " | 148 "<style> body { margin: 0px; } .line { display: block; width: 300px; " |
| 148 "height: 30px; } </style>" | 149 "height: 30px; } </style>" |
| 149 "<body contenteditable='true'><span class='line' id='line'>One Two " | 150 "<body contenteditable='true'><span class='line' id='line'>One Two " |
| 150 "Three</span></body>"); | 151 "Three</span></body>"); |
| 151 | 152 |
| 152 Node* line = document().getElementById("line")->firstChild(); | 153 Node* line = document().getElementById("line")->firstChild(); |
| 153 | 154 |
| 154 TapEventBuilder singleTapEvent(IntPoint(0, 0), 1); | 155 TapEventBuilder singleTapEvent(IntPoint(0, 0), 1); |
| 155 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); | 156 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); |
| 156 ASSERT_TRUE( | 157 ASSERT_TRUE( |
| 157 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); | 158 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 158 EXPECT_EQ(Position(line, 0), selection().start()); | 159 EXPECT_EQ(Position(line, 0), selection().start()); |
| 159 | 160 |
| 160 // Multi-tap events on editable elements should trigger selection, just | 161 // Multi-tap events on editable elements should trigger selection, just |
| 161 // like multi-click events. | 162 // like multi-click events. |
| 162 TapEventBuilder doubleTapEvent(IntPoint(0, 0), 2); | 163 TapEventBuilder doubleTapEvent(IntPoint(0, 0), 2); |
| 163 document().frame()->eventHandler().handleGestureEvent(doubleTapEvent); | 164 document().frame()->eventHandler().handleGestureEvent(doubleTapEvent); |
| 164 ASSERT_TRUE(selection().isRange()); | 165 ASSERT_TRUE( |
| 166 selection().computeVisibleSelectionInDOMTreeDeprecated().isRange()); |
| 165 EXPECT_EQ(Position(line, 0), selection().start()); | 167 EXPECT_EQ(Position(line, 0), selection().start()); |
| 166 if (document().frame()->editor().isSelectTrailingWhitespaceEnabled()) { | 168 if (document().frame()->editor().isSelectTrailingWhitespaceEnabled()) { |
| 167 EXPECT_EQ(Position(line, 4), | 169 EXPECT_EQ(Position(line, 4), |
| 168 selection().computeVisibleSelectionInDOMTreeDeprecated().end()); | 170 selection().computeVisibleSelectionInDOMTreeDeprecated().end()); |
| 169 EXPECT_EQ("One ", WebString(selection().selectedText()).utf8()); | 171 EXPECT_EQ("One ", WebString(selection().selectedText()).utf8()); |
| 170 } else { | 172 } else { |
| 171 EXPECT_EQ(Position(line, 3), | 173 EXPECT_EQ(Position(line, 3), |
| 172 selection().computeVisibleSelectionInDOMTreeDeprecated().end()); | 174 selection().computeVisibleSelectionInDOMTreeDeprecated().end()); |
| 173 EXPECT_EQ("One", WebString(selection().selectedText()).utf8()); | 175 EXPECT_EQ("One", WebString(selection().selectedText()).utf8()); |
| 174 } | 176 } |
| 175 | 177 |
| 176 TapEventBuilder tripleTapEvent(IntPoint(0, 0), 3); | 178 TapEventBuilder tripleTapEvent(IntPoint(0, 0), 3); |
| 177 document().frame()->eventHandler().handleGestureEvent(tripleTapEvent); | 179 document().frame()->eventHandler().handleGestureEvent(tripleTapEvent); |
| 178 ASSERT_TRUE(selection().isRange()); | 180 ASSERT_TRUE( |
| 181 selection().computeVisibleSelectionInDOMTreeDeprecated().isRange()); |
| 179 EXPECT_EQ(Position(line, 0), selection().start()); | 182 EXPECT_EQ(Position(line, 0), selection().start()); |
| 180 EXPECT_EQ(Position(line, 13), | 183 EXPECT_EQ(Position(line, 13), |
| 181 selection().computeVisibleSelectionInDOMTreeDeprecated().end()); | 184 selection().computeVisibleSelectionInDOMTreeDeprecated().end()); |
| 182 EXPECT_EQ("One Two Three", WebString(selection().selectedText()).utf8()); | 185 EXPECT_EQ("One Two Three", WebString(selection().selectedText()).utf8()); |
| 183 } | 186 } |
| 184 | 187 |
| 185 TEST_F(EventHandlerTest, multiClickSelectionFromTapDisabledIfNotEditable) { | 188 TEST_F(EventHandlerTest, multiClickSelectionFromTapDisabledIfNotEditable) { |
| 186 setHtmlInnerHTML( | 189 setHtmlInnerHTML( |
| 187 "<style> body { margin: 0px; } .line { display: block; width: 300px; " | 190 "<style> body { margin: 0px; } .line { display: block; width: 300px; " |
| 188 "height: 30px; } </style>" | 191 "height: 30px; } </style>" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 | 397 |
| 395 ASSERT_TRUE( | 398 ASSERT_TRUE( |
| 396 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); | 399 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 397 ASSERT_FALSE(selection().isHandleVisible()); | 400 ASSERT_FALSE(selection().isHandleVisible()); |
| 398 | 401 |
| 399 MousePressEventBuilder doubleClickMousePressEvent( | 402 MousePressEventBuilder doubleClickMousePressEvent( |
| 400 IntPoint(200, 200), 2, WebPointerProperties::Button::Left); | 403 IntPoint(200, 200), 2, WebPointerProperties::Button::Left); |
| 401 document().frame()->eventHandler().handleMousePressEvent( | 404 document().frame()->eventHandler().handleMousePressEvent( |
| 402 doubleClickMousePressEvent); | 405 doubleClickMousePressEvent); |
| 403 | 406 |
| 404 ASSERT_TRUE(selection().isRange()); | 407 ASSERT_TRUE( |
| 408 selection().computeVisibleSelectionInDOMTreeDeprecated().isRange()); |
| 405 ASSERT_FALSE(selection().isHandleVisible()); | 409 ASSERT_FALSE(selection().isHandleVisible()); |
| 406 | 410 |
| 407 MousePressEventBuilder tripleClickMousePressEvent( | 411 MousePressEventBuilder tripleClickMousePressEvent( |
| 408 IntPoint(200, 200), 3, WebPointerProperties::Button::Left); | 412 IntPoint(200, 200), 3, WebPointerProperties::Button::Left); |
| 409 document().frame()->eventHandler().handleMousePressEvent( | 413 document().frame()->eventHandler().handleMousePressEvent( |
| 410 tripleClickMousePressEvent); | 414 tripleClickMousePressEvent); |
| 411 | 415 |
| 412 ASSERT_TRUE(selection().isRange()); | 416 ASSERT_TRUE( |
| 417 selection().computeVisibleSelectionInDOMTreeDeprecated().isRange()); |
| 413 ASSERT_FALSE(selection().isHandleVisible()); | 418 ASSERT_FALSE(selection().isHandleVisible()); |
| 414 } | 419 } |
| 415 | 420 |
| 416 TEST_F(EventHandlerTest, dragEndInNewDrag) { | 421 TEST_F(EventHandlerTest, dragEndInNewDrag) { |
| 417 setHtmlInnerHTML( | 422 setHtmlInnerHTML( |
| 418 "<style>.box { width: 100px; height: 100px; display: block; }</style>" | 423 "<style>.box { width: 100px; height: 100px; display: block; }</style>" |
| 419 "<a class='box' href=''>Drag me</a>"); | 424 "<a class='box' href=''>Drag me</a>"); |
| 420 | 425 |
| 421 WebMouseEvent mouseDownEvent( | 426 WebMouseEvent mouseDownEvent( |
| 422 WebInputEvent::MouseDown, WebFloatPoint(50, 50), WebFloatPoint(50, 50), | 427 WebInputEvent::MouseDown, WebFloatPoint(50, 50), WebFloatPoint(50, 50), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 444 WebPointerProperties::Button::Left, 1, WebInputEvent::NoModifiers, | 449 WebPointerProperties::Button::Left, 1, WebInputEvent::NoModifiers, |
| 445 TimeTicks::Now().InSeconds()); | 450 TimeTicks::Now().InSeconds()); |
| 446 mouseUpEvent.setFrameScale(1); | 451 mouseUpEvent.setFrameScale(1); |
| 447 document().frame()->eventHandler().dragSourceEndedAt(mouseUpEvent, | 452 document().frame()->eventHandler().dragSourceEndedAt(mouseUpEvent, |
| 448 DragOperationNone); | 453 DragOperationNone); |
| 449 | 454 |
| 450 // This test passes if it doesn't crash. | 455 // This test passes if it doesn't crash. |
| 451 } | 456 } |
| 452 | 457 |
| 453 } // namespace blink | 458 } // namespace blink |
| OLD | NEW |