| 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 | 
|  | 62 class MousePressEventBuilder : public PlatformMouseEvent { | 
|  | 63  public: | 
|  | 64   MousePressEventBuilder(IntPoint position, | 
|  | 65                          int clickCount, | 
|  | 66                          WebMouseEvent::Button button) | 
|  | 67       : PlatformMouseEvent(position, | 
|  | 68                            position, | 
|  | 69                            button, | 
|  | 70                            PlatformEvent::MousePressed, | 
|  | 71                            clickCount, | 
|  | 72                            static_cast<PlatformEvent::Modifiers>(0), | 
|  | 73                            WTF::monotonicallyIncreasingTime()) {} | 
|  | 74 }; | 
|  | 75 | 
| 50 void EventHandlerTest::SetUp() { | 76 void EventHandlerTest::SetUp() { | 
| 51   m_dummyPageHolder = DummyPageHolder::create(IntSize(300, 400)); | 77   m_dummyPageHolder = DummyPageHolder::create(IntSize(300, 400)); | 
| 52 } | 78 } | 
| 53 | 79 | 
| 54 void EventHandlerTest::setHtmlInnerHTML(const char* htmlContent) { | 80 void EventHandlerTest::setHtmlInnerHTML(const char* htmlContent) { | 
| 55   document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), | 81   document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), | 
| 56                                              ASSERT_NO_EXCEPTION); | 82                                              ASSERT_NO_EXCEPTION); | 
| 57   document().view()->updateAllLifecyclePhases(); | 83   document().view()->updateAllLifecyclePhases(); | 
| 58 } | 84 } | 
| 59 | 85 | 
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 248       createVisibleSelection(Position(document().body(), 0))); | 274       createVisibleSelection(Position(document().body(), 0))); | 
| 249   PlatformMouseEvent mouseDownEvent( | 275   PlatformMouseEvent mouseDownEvent( | 
| 250       IntPoint(0, 0), IntPoint(100, 200), WebPointerProperties::Button::Right, | 276       IntPoint(0, 0), IntPoint(100, 200), WebPointerProperties::Button::Right, | 
| 251       PlatformEvent::MousePressed, 1, PlatformEvent::Modifiers::RightButtonDown, | 277       PlatformEvent::MousePressed, 1, PlatformEvent::Modifiers::RightButtonDown, | 
| 252       WTF::monotonicallyIncreasingTime()); | 278       WTF::monotonicallyIncreasingTime()); | 
| 253   EXPECT_EQ( | 279   EXPECT_EQ( | 
| 254       WebInputEventResult::HandledApplication, | 280       WebInputEventResult::HandledApplication, | 
| 255       document().frame()->eventHandler().sendContextMenuEvent(mouseDownEvent)); | 281       document().frame()->eventHandler().sendContextMenuEvent(mouseDownEvent)); | 
| 256 } | 282 } | 
| 257 | 283 | 
|  | 284 TEST_F(EventHandlerTest, EmptyTextfieldInsertionOnTap) { | 
|  | 285   setHtmlInnerHTML("<textarea cols=50 rows=50></textarea>"); | 
|  | 286 | 
|  | 287   FrameSelection& selection = document().frame()->selection(); | 
|  | 288 | 
|  | 289   TapEventBuilder singleTapEvent(IntPoint(200, 200), 1); | 
|  | 290   document().frame()->eventHandler().handleGestureEvent(singleTapEvent); | 
|  | 291 | 
|  | 292   ASSERT_TRUE(selection.isCaret()); | 
|  | 293   ASSERT_FALSE(selection.isHandleVisible()); | 
|  | 294 } | 
|  | 295 | 
|  | 296 TEST_F(EventHandlerTest, NonEmptyTextfieldInsertionOnTap) { | 
|  | 297   setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>"); | 
|  | 298 | 
|  | 299   FrameSelection& selection = document().frame()->selection(); | 
|  | 300 | 
|  | 301   TapEventBuilder singleTapEvent(IntPoint(200, 200), 1); | 
|  | 302   document().frame()->eventHandler().handleGestureEvent(singleTapEvent); | 
|  | 303 | 
|  | 304   ASSERT_TRUE(selection.isCaret()); | 
|  | 305   ASSERT_TRUE(selection.isHandleVisible()); | 
|  | 306 } | 
|  | 307 | 
|  | 308 TEST_F(EventHandlerTest, EmptyTextfieldInsertionOnLongPress) { | 
|  | 309   setHtmlInnerHTML("<textarea cols=50 rows=50></textarea>"); | 
|  | 310 | 
|  | 311   FrameSelection& selection = document().frame()->selection(); | 
|  | 312 | 
|  | 313   LongPressEventBuilder longPressEvent(IntPoint(200, 200)); | 
|  | 314   document().frame()->eventHandler().handleGestureEvent(longPressEvent); | 
|  | 315 | 
|  | 316   ASSERT_TRUE(selection.isCaret()); | 
|  | 317   ASSERT_TRUE(selection.isHandleVisible()); | 
|  | 318 | 
|  | 319   // Single Tap on an empty edit field should clear insertion handle | 
|  | 320   TapEventBuilder singleTapEvent(IntPoint(200, 200), 1); | 
|  | 321   document().frame()->eventHandler().handleGestureEvent(singleTapEvent); | 
|  | 322 | 
|  | 323   ASSERT_TRUE(selection.isCaret()); | 
|  | 324   ASSERT_FALSE(selection.isHandleVisible()); | 
|  | 325 } | 
|  | 326 | 
|  | 327 TEST_F(EventHandlerTest, NonEmptyTextfieldInsertionOnLongPress) { | 
|  | 328   setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>"); | 
|  | 329 | 
|  | 330   FrameSelection& selection = document().frame()->selection(); | 
|  | 331 | 
|  | 332   LongPressEventBuilder longPressEvent(IntPoint(200, 200)); | 
|  | 333   document().frame()->eventHandler().handleGestureEvent(longPressEvent); | 
|  | 334 | 
|  | 335   ASSERT_TRUE(selection.selection().isCaret()); | 
|  | 336   ASSERT_TRUE(selection.isHandleVisible()); | 
|  | 337 } | 
|  | 338 | 
|  | 339 TEST_F(EventHandlerTest, ClearHandleAfterTap) { | 
|  | 340   setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>"); | 
|  | 341 | 
|  | 342   FrameSelection& selection = document().frame()->selection(); | 
|  | 343 | 
|  | 344   // Show handle | 
|  | 345   LongPressEventBuilder longPressEvent(IntPoint(200, 200)); | 
|  | 346   document().frame()->eventHandler().handleGestureEvent(longPressEvent); | 
|  | 347 | 
|  | 348   ASSERT_TRUE(selection.selection().isCaret()); | 
|  | 349   ASSERT_TRUE(selection.isHandleVisible()); | 
|  | 350 | 
|  | 351   // Tap away from text area should clear handle | 
|  | 352   TapEventBuilder singleTapEvent(IntPoint(700, 700), 1); | 
|  | 353   document().frame()->eventHandler().handleGestureEvent(singleTapEvent); | 
|  | 354 | 
|  | 355   ASSERT_TRUE(selection.isNone()); | 
|  | 356   ASSERT_FALSE(selection.isHandleVisible()); | 
|  | 357 } | 
|  | 358 | 
|  | 359 TEST_F(EventHandlerTest, HandleNotShownOnMouseEvents) { | 
|  | 360   setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>"); | 
|  | 361 | 
|  | 362   FrameSelection& selection = document().frame()->selection(); | 
|  | 363 | 
|  | 364   MousePressEventBuilder leftMousePressEvent( | 
|  | 365       IntPoint(200, 200), 1, WebPointerProperties::Button::Left); | 
|  | 366   document().frame()->eventHandler().handleMousePressEvent(leftMousePressEvent); | 
|  | 367 | 
|  | 368   ASSERT_TRUE(selection.isCaret()); | 
|  | 369   ASSERT_FALSE(selection.isHandleVisible()); | 
|  | 370 | 
|  | 371   MousePressEventBuilder rightMousePressEvent( | 
|  | 372       IntPoint(200, 200), 1, WebPointerProperties::Button::Right); | 
|  | 373   document().frame()->eventHandler().handleMousePressEvent( | 
|  | 374       rightMousePressEvent); | 
|  | 375 | 
|  | 376   ASSERT_TRUE(selection.isCaret()); | 
|  | 377   ASSERT_FALSE(selection.isHandleVisible()); | 
|  | 378 | 
|  | 379   MousePressEventBuilder doubleClickMousePressEvent( | 
|  | 380       IntPoint(200, 200), 2, WebPointerProperties::Button::Left); | 
|  | 381   document().frame()->eventHandler().handleMousePressEvent( | 
|  | 382       doubleClickMousePressEvent); | 
|  | 383 | 
|  | 384   ASSERT_TRUE(selection.isRange()); | 
|  | 385   ASSERT_FALSE(selection.isHandleVisible()); | 
|  | 386 | 
|  | 387   MousePressEventBuilder tripleClickMousePressEvent( | 
|  | 388       IntPoint(200, 200), 3, WebPointerProperties::Button::Left); | 
|  | 389   document().frame()->eventHandler().handleMousePressEvent( | 
|  | 390       tripleClickMousePressEvent); | 
|  | 391 | 
|  | 392   ASSERT_TRUE(selection.isRange()); | 
|  | 393   ASSERT_FALSE(selection.isHandleVisible()); | 
|  | 394 } | 
|  | 395 | 
| 258 }  // namespace blink | 396 }  // namespace blink | 
| OLD | NEW | 
|---|