Changeset 130547 in webkit
- Timestamp:
- Oct 5, 2012, 1:45:25 PM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r130541 r130547 1 2012-10-05 Oli Lan <olilan@chromium.org> 2 3 Allow EventHandler to handle longpress gestures, including longpress selection on Android. 4 https://bugs.webkit.org/show_bug.cgi?id=98173 5 6 Reviewed by Ryosuke Niwa. 7 8 Adds handling for GestureLongPress to EventHandler::handleGestureEvent, with a new 9 handleGestureLongPress method. On Android, this method selects the closest word 10 if the gesture event was over non-link text. 11 12 This is tested via a new chromium test WebViewTest.LongPressSelection. 13 14 * page/EventHandler.cpp: 15 (WebCore::EventHandler::selectClosestWordFromHitTestResult): 16 (WebCore::EventHandler::selectClosestWordFromMouseEvent): 17 (WebCore): 18 (WebCore::EventHandler::handleGestureEvent): 19 (WebCore::EventHandler::handleGestureLongPress): 20 * page/EventHandler.h: 21 (EventHandler): 22 1 23 2012-10-05 Tab Atkins <jackalmage@gmail.com> 2 24 -
trunk/Source/WebCore/page/EventHandler.cpp
r130449 r130547 431 431 } 432 432 433 void EventHandler::selectClosestWordFrom MouseEvent(const MouseEventWithHitTestResults& result)433 void EventHandler::selectClosestWordFromHitTestResult(const HitTestResult& result, AppendTrailingWhitespace appendTrailingWhitespace) 434 434 { 435 435 Node* innerNode = result.targetNode(); 436 436 VisibleSelection newSelection; 437 437 438 if (innerNode && innerNode->renderer() && m_mouseDownMayStartSelect) {438 if (innerNode && innerNode->renderer()) { 439 439 VisiblePosition pos(innerNode->renderer()->positionForPoint(result.localPoint())); 440 440 if (pos.isNotNull()) { … … 443 443 } 444 444 445 if ( newSelection.isRange() && result.event().clickCount() == 2 && m_frame->editor()->isSelectTrailingWhitespaceEnabled())445 if (appendTrailingWhitespace == ShouldAppendTrailingWhitespace && newSelection.isRange()) 446 446 newSelection.appendTrailingWhitespace(); 447 447 448 448 updateSelectionForMouseDownDispatchingSelectStart(innerNode, newSelection, WordGranularity); 449 } 450 } 451 452 void EventHandler::selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults& result) 453 { 454 if (m_mouseDownMayStartSelect) { 455 selectClosestWordFromHitTestResult(result.hitTestResult(), 456 (result.event().clickCount() == 2 && m_frame->editor()->isSelectTrailingWhitespaceEnabled()) ? ShouldAppendTrailingWhitespace : DontAppendTrailingWhitespace); 449 457 } 450 458 } … … 2514 2522 case PlatformEvent::GestureTapDown: 2515 2523 return handleGestureTapDown(); 2524 case PlatformEvent::GestureLongPress: 2525 return handleGestureLongPress(gestureEvent); 2516 2526 case PlatformEvent::GestureDoubleTap: 2517 case PlatformEvent::GestureLongPress:2518 2527 case PlatformEvent::GesturePinchBegin: 2519 2528 case PlatformEvent::GesturePinchEnd: … … 2560 2569 2561 2570 return defaultPrevented; 2571 } 2572 2573 bool EventHandler::handleGestureLongPress(const PlatformGestureEvent& gestureEvent) 2574 { 2575 #if OS(ANDROID) 2576 IntPoint hitTestPoint = m_frame->view()->windowToContents(gestureEvent.position()); 2577 HitTestResult result = hitTestResultAtPoint(hitTestPoint, true); 2578 Node* innerNode = result.targetNode(); 2579 if (!result.isLiveLink() && innerNode && (innerNode->isContentEditable() || innerNode->isTextNode())) { 2580 selectClosestWordFromHitTestResult(result, DontAppendTrailingWhitespace); 2581 if (m_frame->selection()->isRange()) 2582 return true; 2583 } 2584 #endif 2585 return sendContextMenuEventForGesture(gestureEvent); 2562 2586 } 2563 2587 -
trunk/Source/WebCore/page/EventHandler.h
r130226 r130547 90 90 91 91 enum HitTestScrollbars { ShouldHitTestScrollbars, DontHitTestScrollbars }; 92 enum AppendTrailingWhitespace { ShouldAppendTrailingWhitespace, DontAppendTrailingWhitespace }; 92 93 93 94 class EventHandler { … … 167 168 bool handleGestureEvent(const PlatformGestureEvent&); 168 169 bool handleGestureTap(const PlatformGestureEvent&); 170 bool handleGestureLongPress(const PlatformGestureEvent&); 169 171 bool handleGestureScrollUpdate(const PlatformGestureEvent&); 170 172 #endif … … 242 244 bool eventActivatedView(const PlatformMouseEvent&) const; 243 245 bool updateSelectionForMouseDownDispatchingSelectStart(Node*, const VisibleSelection&, TextGranularity); 246 void selectClosestWordFromHitTestResult(const HitTestResult&, AppendTrailingWhitespace); 244 247 void selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults&); 245 248 void selectClosestWordOrLinkFromMouseEvent(const MouseEventWithHitTestResults&); -
trunk/Source/WebKit/chromium/ChangeLog
r130545 r130547 1 2012-10-05 Oli Lan <olilan@chromium.org> 2 3 Allow EventHandler to handle longpress gestures, including longpress selection on Android. 4 https://bugs.webkit.org/show_bug.cgi?id=98173 5 6 Reviewed by Ryosuke Niwa. 7 8 This patch changes the longpress gesture handling code in WebViewImpl to call EventHandler::handleGestureEvent. 9 The WebCore part of this patch adds longpress handling to that method, including the long press selection behaviour 10 required for Android. This means that a long press gesture performed on word (that is not part of a link) 11 selects the word, without generating a context menu event. 12 13 A new test, WebViewTest.LongPressSelection has been added to test this. 14 15 * src/WebViewImpl.cpp: 16 (WebKit::WebViewImpl::handleGestureEvent): 17 (WebViewImpl): 18 * tests/WebViewTest.cpp: 19 * tests/data/longpress_selection.html: Added. 20 1 21 2012-10-05 Yusuf Ozuysal <yusufo@google.com> 2 22 -
trunk/Source/WebKit/chromium/src/WebViewImpl.cpp
r130545 r130547 743 743 break; 744 744 } 745 case WebInputEvent::GestureTwoFingerTap: 745 case WebInputEvent::GestureTwoFingerTap: { 746 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 747 break; 748 749 m_page->contextMenuController()->clearContextMenu(); 750 m_contextMenuAllowed = true; 751 PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), event); 752 eventSwallowed = mainFrameImpl()->frame()->eventHandler()->sendContextMenuEventForGesture(platformEvent); 753 m_contextMenuAllowed = false; 754 755 break; 756 } 746 757 case WebInputEvent::GestureLongPress: { 747 758 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) … … 757 768 m_contextMenuAllowed = true; 758 769 PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), event); 759 eventSwallowed = mainFrameImpl()->frame()->eventHandler()-> sendContextMenuEventForGesture(platformEvent);770 eventSwallowed = mainFrameImpl()->frame()->eventHandler()->handleGestureEvent(platformEvent); 760 771 m_contextMenuAllowed = false; 761 772 -
trunk/Source/WebKit/chromium/tests/WebViewTest.cpp
r129029 r130547 648 648 } 649 649 650 } 650 #if OS(ANDROID) 651 TEST_F(WebViewTest, LongPressSelection) 652 { 653 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("longpress_selection.html")); 654 655 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "longpress_selection.html", true); 656 webView->resize(WebSize(500, 300)); 657 webView->layout(); 658 webkit_support::RunAllPendingMessages(); 659 660 WebString target = WebString::fromUTF8("target"); 661 WebString onselectstartfalse = WebString::fromUTF8("onselectstartfalse"); 662 WebFrameImpl* frame = static_cast<WebFrameImpl*>(webView->mainFrame()); 663 664 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, onselectstartfalse)); 665 EXPECT_EQ("", std::string(frame->selectionAsText().utf8().data())); 666 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, target)); 667 EXPECT_EQ("testword", std::string(frame->selectionAsText().utf8().data())); 668 webView->close(); 669 } 670 #endif 671 672 }
Note:
See TracChangeset
for help on using the changeset viewer.