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 29 matching lines...) Expand all Loading... |
40 position, | 40 position, |
41 position, | 41 position, |
42 IntSize(5, 5), | 42 IntSize(5, 5), |
43 WTF::monotonicallyIncreasingTime(), | 43 WTF::monotonicallyIncreasingTime(), |
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 class LongPressEventBuilder : public PlatformGestureEvent { |
| 51 public: |
| 52 LongPressEventBuilder(IntPoint position) |
| 53 : PlatformGestureEvent(PlatformEvent::GestureLongPress, |
| 54 position, |
| 55 position, |
| 56 IntSize(5, 5), |
| 57 WTF::monotonicallyIncreasingTime(), |
| 58 static_cast<PlatformEvent::Modifiers>(0), |
| 59 PlatformGestureSourceTouchscreen) {} |
| 60 }; |
| 61 |
50 void EventHandlerTest::SetUp() { | 62 void EventHandlerTest::SetUp() { |
51 m_dummyPageHolder = DummyPageHolder::create(IntSize(300, 400)); | 63 m_dummyPageHolder = DummyPageHolder::create(IntSize(300, 400)); |
52 } | 64 } |
53 | 65 |
54 void EventHandlerTest::setHtmlInnerHTML(const char* htmlContent) { | 66 void EventHandlerTest::setHtmlInnerHTML(const char* htmlContent) { |
55 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), | 67 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), |
56 ASSERT_NO_EXCEPTION); | 68 ASSERT_NO_EXCEPTION); |
57 document().view()->updateAllLifecyclePhases(); | 69 document().view()->updateAllLifecyclePhases(); |
58 } | 70 } |
59 | 71 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 createVisibleSelection(Position(document().body(), 0))); | 259 createVisibleSelection(Position(document().body(), 0))); |
248 PlatformMouseEvent mouseDownEvent( | 260 PlatformMouseEvent mouseDownEvent( |
249 IntPoint(0, 0), IntPoint(100, 200), WebPointerProperties::Button::Right, | 261 IntPoint(0, 0), IntPoint(100, 200), WebPointerProperties::Button::Right, |
250 PlatformEvent::MousePressed, 1, PlatformEvent::Modifiers::RightButtonDown, | 262 PlatformEvent::MousePressed, 1, PlatformEvent::Modifiers::RightButtonDown, |
251 WTF::monotonicallyIncreasingTime()); | 263 WTF::monotonicallyIncreasingTime()); |
252 EXPECT_EQ( | 264 EXPECT_EQ( |
253 WebInputEventResult::HandledApplication, | 265 WebInputEventResult::HandledApplication, |
254 document().frame()->eventHandler().sendContextMenuEvent(mouseDownEvent)); | 266 document().frame()->eventHandler().sendContextMenuEvent(mouseDownEvent)); |
255 } | 267 } |
256 | 268 |
| 269 TEST_F(EventHandlerTest, EmptyTextfieldInsertionOnTap) { |
| 270 setHtmlInnerHTML("<textarea cols=50 rows=50></textarea>"); |
| 271 |
| 272 FrameSelection& selection = document().frame()->selection(); |
| 273 |
| 274 TapEventBuilder singleTapEvent(IntPoint(200, 200), 1); |
| 275 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); |
| 276 |
| 277 ASSERT_TRUE(selection.isCaret()); |
| 278 ASSERT_FALSE(selection.selection().isHandleVisible()); |
| 279 } |
| 280 |
| 281 TEST_F(EventHandlerTest, NonEmptyTextfieldInsertionOnTap) { |
| 282 setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>"); |
| 283 |
| 284 FrameSelection& selection = document().frame()->selection(); |
| 285 |
| 286 TapEventBuilder singleTapEvent(IntPoint(200, 200), 1); |
| 287 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); |
| 288 |
| 289 ASSERT_TRUE(selection.isCaret()); |
| 290 ASSERT_TRUE(selection.selection().isHandleVisible()); |
| 291 } |
| 292 |
| 293 TEST_F(EventHandlerTest, EmptyTextfieldInsertionOnLongPress) { |
| 294 setHtmlInnerHTML("<textarea cols=50 rows=50></textarea>"); |
| 295 |
| 296 FrameSelection& selection = document().frame()->selection(); |
| 297 |
| 298 LongPressEventBuilder longPressEvent(IntPoint(200, 200)); |
| 299 document().frame()->eventHandler().handleGestureEvent(longPressEvent); |
| 300 |
| 301 ASSERT_TRUE(selection.isCaret()); |
| 302 ASSERT_TRUE(selection.selection().isHandleVisible()); |
| 303 |
| 304 // Single Tap on an empty edit field should clear insertion handle |
| 305 TapEventBuilder singleTapEvent(IntPoint(200, 200), 1); |
| 306 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); |
| 307 |
| 308 ASSERT_TRUE(selection.isCaret()); |
| 309 ASSERT_FALSE(selection.selection().isHandleVisible()); |
| 310 } |
| 311 |
| 312 TEST_F(EventHandlerTest, NonEmptyTextfieldInsertionOnLongPress) { |
| 313 setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>"); |
| 314 |
| 315 FrameSelection& selection = document().frame()->selection(); |
| 316 |
| 317 LongPressEventBuilder longPressEvent(IntPoint(200, 200)); |
| 318 document().frame()->eventHandler().handleGestureEvent(longPressEvent); |
| 319 |
| 320 ASSERT_TRUE(selection.selection().isCaret()); |
| 321 ASSERT_TRUE(selection.selection().isHandleVisible()); |
| 322 } |
| 323 |
| 324 TEST_F(EventHandlerTest, ClearHandleAfterTap) { |
| 325 setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>"); |
| 326 |
| 327 FrameSelection& selection = document().frame()->selection(); |
| 328 |
| 329 // Show handle |
| 330 LongPressEventBuilder longPressEvent(IntPoint(200, 200)); |
| 331 document().frame()->eventHandler().handleGestureEvent(longPressEvent); |
| 332 |
| 333 ASSERT_TRUE(selection.selection().isCaret()); |
| 334 ASSERT_TRUE(selection.selection().isHandleVisible()); |
| 335 |
| 336 // Tap away from text area should clear handle |
| 337 TapEventBuilder singleTapEvent(IntPoint(700, 700), 1); |
| 338 document().frame()->eventHandler().handleGestureEvent(singleTapEvent); |
| 339 |
| 340 ASSERT_TRUE(selection.isNone()); |
| 341 ASSERT_FALSE(selection.selection().isHandleVisible()); |
| 342 } |
| 343 |
257 } // namespace blink | 344 } // namespace blink |
OLD | NEW |