| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 setHtmlInnerHTML( | 146 setHtmlInnerHTML( |
| 147 "<style> body { margin: 0px; } .line { display: block; width: 300px; " | 147 "<style> body { margin: 0px; } .line { display: block; width: 300px; " |
| 148 "height: 30px; } </style>" | 148 "height: 30px; } </style>" |
| 149 "<body contenteditable='true'><span class='line' id='line'>One Two " | 149 "<body contenteditable='true'><span class='line' id='line'>One Two " |
| 150 "Three</span></body>"); | 150 "Three</span></body>"); |
| 151 | 151 |
| 152 Node* line = document().getElementById("line")->firstChild(); | 152 Node* line = document().getElementById("line")->firstChild(); |
| 153 | 153 |
| 154 TapEventBuilder singleTapEvent(IntPoint(0, 0), 1); | 154 TapEventBuilder singleTapEvent(IntPoint(0, 0), 1); |
| 155 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); | 155 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); |
| 156 ASSERT_TRUE(selection().isCaret()); | 156 ASSERT_TRUE( |
| 157 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 157 EXPECT_EQ(Position(line, 0), selection().start()); | 158 EXPECT_EQ(Position(line, 0), selection().start()); |
| 158 | 159 |
| 159 // Multi-tap events on editable elements should trigger selection, just | 160 // Multi-tap events on editable elements should trigger selection, just |
| 160 // like multi-click events. | 161 // like multi-click events. |
| 161 TapEventBuilder doubleTapEvent(IntPoint(0, 0), 2); | 162 TapEventBuilder doubleTapEvent(IntPoint(0, 0), 2); |
| 162 document().frame()->eventHandler().handleGestureEvent(doubleTapEvent); | 163 document().frame()->eventHandler().handleGestureEvent(doubleTapEvent); |
| 163 ASSERT_TRUE(selection().isRange()); | 164 ASSERT_TRUE(selection().isRange()); |
| 164 EXPECT_EQ(Position(line, 0), selection().start()); | 165 EXPECT_EQ(Position(line, 0), selection().start()); |
| 165 if (document().frame()->editor().isSelectTrailingWhitespaceEnabled()) { | 166 if (document().frame()->editor().isSelectTrailingWhitespaceEnabled()) { |
| 166 EXPECT_EQ(Position(line, 4), selection().end()); | 167 EXPECT_EQ(Position(line, 4), selection().end()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 181 TEST_F(EventHandlerTest, multiClickSelectionFromTapDisabledIfNotEditable) { | 182 TEST_F(EventHandlerTest, multiClickSelectionFromTapDisabledIfNotEditable) { |
| 182 setHtmlInnerHTML( | 183 setHtmlInnerHTML( |
| 183 "<style> body { margin: 0px; } .line { display: block; width: 300px; " | 184 "<style> body { margin: 0px; } .line { display: block; width: 300px; " |
| 184 "height: 30px; } </style>" | 185 "height: 30px; } </style>" |
| 185 "<span class='line' id='line'>One Two Three</span>"); | 186 "<span class='line' id='line'>One Two Three</span>"); |
| 186 | 187 |
| 187 Node* line = document().getElementById("line")->firstChild(); | 188 Node* line = document().getElementById("line")->firstChild(); |
| 188 | 189 |
| 189 TapEventBuilder singleTapEvent(IntPoint(0, 0), 1); | 190 TapEventBuilder singleTapEvent(IntPoint(0, 0), 1); |
| 190 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); | 191 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); |
| 191 ASSERT_TRUE(selection().isCaret()); | 192 ASSERT_TRUE( |
| 193 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 192 EXPECT_EQ(Position(line, 0), selection().start()); | 194 EXPECT_EQ(Position(line, 0), selection().start()); |
| 193 | 195 |
| 194 // As the text is readonly, multi-tap events should not trigger selection. | 196 // As the text is readonly, multi-tap events should not trigger selection. |
| 195 TapEventBuilder doubleTapEvent(IntPoint(0, 0), 2); | 197 TapEventBuilder doubleTapEvent(IntPoint(0, 0), 2); |
| 196 document().frame()->eventHandler().handleGestureEvent(doubleTapEvent); | 198 document().frame()->eventHandler().handleGestureEvent(doubleTapEvent); |
| 197 ASSERT_TRUE(selection().isCaret()); | 199 ASSERT_TRUE( |
| 200 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 198 EXPECT_EQ(Position(line, 0), selection().start()); | 201 EXPECT_EQ(Position(line, 0), selection().start()); |
| 199 | 202 |
| 200 TapEventBuilder tripleTapEvent(IntPoint(0, 0), 3); | 203 TapEventBuilder tripleTapEvent(IntPoint(0, 0), 3); |
| 201 document().frame()->eventHandler().handleGestureEvent(tripleTapEvent); | 204 document().frame()->eventHandler().handleGestureEvent(tripleTapEvent); |
| 202 ASSERT_TRUE(selection().isCaret()); | 205 ASSERT_TRUE( |
| 206 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 203 EXPECT_EQ(Position(line, 0), selection().start()); | 207 EXPECT_EQ(Position(line, 0), selection().start()); |
| 204 } | 208 } |
| 205 | 209 |
| 206 TEST_F(EventHandlerTest, draggedInlinePositionTest) { | 210 TEST_F(EventHandlerTest, draggedInlinePositionTest) { |
| 207 setHtmlInnerHTML( | 211 setHtmlInnerHTML( |
| 208 "<style>" | 212 "<style>" |
| 209 "body { margin: 0px; }" | 213 "body { margin: 0px; }" |
| 210 ".line { font-family: sans-serif; background: blue; width: 300px; " | 214 ".line { font-family: sans-serif; background: blue; width: 300px; " |
| 211 "height: 30px; font-size: 40px; margin-left: 250px; }" | 215 "height: 30px; font-size: 40px; margin-left: 250px; }" |
| 212 "</style>" | 216 "</style>" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 WebInputEventResult::HandledApplication, | 301 WebInputEventResult::HandledApplication, |
| 298 document().frame()->eventHandler().sendContextMenuEvent(mouseDownEvent)); | 302 document().frame()->eventHandler().sendContextMenuEvent(mouseDownEvent)); |
| 299 } | 303 } |
| 300 | 304 |
| 301 TEST_F(EventHandlerTest, EmptyTextfieldInsertionOnTap) { | 305 TEST_F(EventHandlerTest, EmptyTextfieldInsertionOnTap) { |
| 302 setHtmlInnerHTML("<textarea cols=50 rows=50></textarea>"); | 306 setHtmlInnerHTML("<textarea cols=50 rows=50></textarea>"); |
| 303 | 307 |
| 304 TapEventBuilder singleTapEvent(IntPoint(200, 200), 1); | 308 TapEventBuilder singleTapEvent(IntPoint(200, 200), 1); |
| 305 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); | 309 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); |
| 306 | 310 |
| 307 ASSERT_TRUE(selection().isCaret()); | 311 ASSERT_TRUE( |
| 312 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 308 ASSERT_FALSE(selection().isHandleVisible()); | 313 ASSERT_FALSE(selection().isHandleVisible()); |
| 309 } | 314 } |
| 310 | 315 |
| 311 TEST_F(EventHandlerTest, NonEmptyTextfieldInsertionOnTap) { | 316 TEST_F(EventHandlerTest, NonEmptyTextfieldInsertionOnTap) { |
| 312 setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>"); | 317 setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>"); |
| 313 | 318 |
| 314 TapEventBuilder singleTapEvent(IntPoint(200, 200), 1); | 319 TapEventBuilder singleTapEvent(IntPoint(200, 200), 1); |
| 315 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); | 320 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); |
| 316 | 321 |
| 317 ASSERT_TRUE(selection().isCaret()); | 322 ASSERT_TRUE( |
| 323 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 318 ASSERT_TRUE(selection().isHandleVisible()); | 324 ASSERT_TRUE(selection().isHandleVisible()); |
| 319 } | 325 } |
| 320 | 326 |
| 321 TEST_F(EventHandlerTest, EmptyTextfieldInsertionOnLongPress) { | 327 TEST_F(EventHandlerTest, EmptyTextfieldInsertionOnLongPress) { |
| 322 setHtmlInnerHTML("<textarea cols=50 rows=50></textarea>"); | 328 setHtmlInnerHTML("<textarea cols=50 rows=50></textarea>"); |
| 323 | 329 |
| 324 LongPressEventBuilder longPressEvent(IntPoint(200, 200)); | 330 LongPressEventBuilder longPressEvent(IntPoint(200, 200)); |
| 325 document().frame()->eventHandler().handleGestureEvent(longPressEvent); | 331 document().frame()->eventHandler().handleGestureEvent(longPressEvent); |
| 326 | 332 |
| 327 ASSERT_TRUE(selection().isCaret()); | 333 ASSERT_TRUE( |
| 334 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 328 ASSERT_TRUE(selection().isHandleVisible()); | 335 ASSERT_TRUE(selection().isHandleVisible()); |
| 329 | 336 |
| 330 // Single Tap on an empty edit field should clear insertion handle | 337 // Single Tap on an empty edit field should clear insertion handle |
| 331 TapEventBuilder singleTapEvent(IntPoint(200, 200), 1); | 338 TapEventBuilder singleTapEvent(IntPoint(200, 200), 1); |
| 332 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); | 339 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); |
| 333 | 340 |
| 334 ASSERT_TRUE(selection().isCaret()); | 341 ASSERT_TRUE( |
| 342 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 335 ASSERT_FALSE(selection().isHandleVisible()); | 343 ASSERT_FALSE(selection().isHandleVisible()); |
| 336 } | 344 } |
| 337 | 345 |
| 338 TEST_F(EventHandlerTest, NonEmptyTextfieldInsertionOnLongPress) { | 346 TEST_F(EventHandlerTest, NonEmptyTextfieldInsertionOnLongPress) { |
| 339 setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>"); | 347 setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>"); |
| 340 | 348 |
| 341 LongPressEventBuilder longPressEvent(IntPoint(200, 200)); | 349 LongPressEventBuilder longPressEvent(IntPoint(200, 200)); |
| 342 document().frame()->eventHandler().handleGestureEvent(longPressEvent); | 350 document().frame()->eventHandler().handleGestureEvent(longPressEvent); |
| 343 | 351 |
| 344 ASSERT_TRUE(selection().isCaret()); | 352 ASSERT_TRUE( |
| 353 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 345 ASSERT_TRUE(selection().isHandleVisible()); | 354 ASSERT_TRUE(selection().isHandleVisible()); |
| 346 } | 355 } |
| 347 | 356 |
| 348 TEST_F(EventHandlerTest, ClearHandleAfterTap) { | 357 TEST_F(EventHandlerTest, ClearHandleAfterTap) { |
| 349 setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>"); | 358 setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>"); |
| 350 | 359 |
| 351 // Show handle | 360 // Show handle |
| 352 LongPressEventBuilder longPressEvent(IntPoint(200, 200)); | 361 LongPressEventBuilder longPressEvent(IntPoint(200, 200)); |
| 353 document().frame()->eventHandler().handleGestureEvent(longPressEvent); | 362 document().frame()->eventHandler().handleGestureEvent(longPressEvent); |
| 354 | 363 |
| 355 ASSERT_TRUE(selection().isCaret()); | 364 ASSERT_TRUE( |
| 365 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 356 ASSERT_TRUE(selection().isHandleVisible()); | 366 ASSERT_TRUE(selection().isHandleVisible()); |
| 357 | 367 |
| 358 // Tap away from text area should clear handle | 368 // Tap away from text area should clear handle |
| 359 TapEventBuilder singleTapEvent(IntPoint(700, 700), 1); | 369 TapEventBuilder singleTapEvent(IntPoint(700, 700), 1); |
| 360 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); | 370 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); |
| 361 | 371 |
| 362 ASSERT_TRUE(selection().isNone()); | 372 ASSERT_TRUE(selection().isNone()); |
| 363 ASSERT_FALSE(selection().isHandleVisible()); | 373 ASSERT_FALSE(selection().isHandleVisible()); |
| 364 } | 374 } |
| 365 | 375 |
| 366 TEST_F(EventHandlerTest, HandleNotShownOnMouseEvents) { | 376 TEST_F(EventHandlerTest, HandleNotShownOnMouseEvents) { |
| 367 setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>"); | 377 setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>"); |
| 368 | 378 |
| 369 MousePressEventBuilder leftMousePressEvent( | 379 MousePressEventBuilder leftMousePressEvent( |
| 370 IntPoint(200, 200), 1, WebPointerProperties::Button::Left); | 380 IntPoint(200, 200), 1, WebPointerProperties::Button::Left); |
| 371 document().frame()->eventHandler().handleMousePressEvent(leftMousePressEvent); | 381 document().frame()->eventHandler().handleMousePressEvent(leftMousePressEvent); |
| 372 | 382 |
| 373 ASSERT_TRUE(selection().isCaret()); | 383 ASSERT_TRUE( |
| 384 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 374 ASSERT_FALSE(selection().isHandleVisible()); | 385 ASSERT_FALSE(selection().isHandleVisible()); |
| 375 | 386 |
| 376 MousePressEventBuilder rightMousePressEvent( | 387 MousePressEventBuilder rightMousePressEvent( |
| 377 IntPoint(200, 200), 1, WebPointerProperties::Button::Right); | 388 IntPoint(200, 200), 1, WebPointerProperties::Button::Right); |
| 378 document().frame()->eventHandler().handleMousePressEvent( | 389 document().frame()->eventHandler().handleMousePressEvent( |
| 379 rightMousePressEvent); | 390 rightMousePressEvent); |
| 380 | 391 |
| 381 ASSERT_TRUE(selection().isCaret()); | 392 ASSERT_TRUE( |
| 393 selection().computeVisibleSelectionInDOMTreeDeprecated().isCaret()); |
| 382 ASSERT_FALSE(selection().isHandleVisible()); | 394 ASSERT_FALSE(selection().isHandleVisible()); |
| 383 | 395 |
| 384 MousePressEventBuilder doubleClickMousePressEvent( | 396 MousePressEventBuilder doubleClickMousePressEvent( |
| 385 IntPoint(200, 200), 2, WebPointerProperties::Button::Left); | 397 IntPoint(200, 200), 2, WebPointerProperties::Button::Left); |
| 386 document().frame()->eventHandler().handleMousePressEvent( | 398 document().frame()->eventHandler().handleMousePressEvent( |
| 387 doubleClickMousePressEvent); | 399 doubleClickMousePressEvent); |
| 388 | 400 |
| 389 ASSERT_TRUE(selection().isRange()); | 401 ASSERT_TRUE(selection().isRange()); |
| 390 ASSERT_FALSE(selection().isHandleVisible()); | 402 ASSERT_FALSE(selection().isHandleVisible()); |
| 391 | 403 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 WebPointerProperties::Button::Left, 1, WebInputEvent::NoModifiers, | 441 WebPointerProperties::Button::Left, 1, WebInputEvent::NoModifiers, |
| 430 TimeTicks::Now().InSeconds()); | 442 TimeTicks::Now().InSeconds()); |
| 431 mouseUpEvent.setFrameScale(1); | 443 mouseUpEvent.setFrameScale(1); |
| 432 document().frame()->eventHandler().dragSourceEndedAt(mouseUpEvent, | 444 document().frame()->eventHandler().dragSourceEndedAt(mouseUpEvent, |
| 433 DragOperationNone); | 445 DragOperationNone); |
| 434 | 446 |
| 435 // This test passes if it doesn't crash. | 447 // This test passes if it doesn't crash. |
| 436 } | 448 } |
| 437 | 449 |
| 438 } // namespace blink | 450 } // namespace blink |
| OLD | NEW |