Changeset 130547 in webkit


Ignore:
Timestamp:
Oct 5, 2012, 1:45:25 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

Source/WebCore: Allow EventHandler to handle longpress gestures, including longpress selection on Android.
https://bugs.webkit.org/show_bug.cgi?id=98173

Patch by Oli Lan <olilan@chromium.org> on 2012-10-05
Reviewed by Ryosuke Niwa.

Adds handling for GestureLongPress to EventHandler::handleGestureEvent, with a new
handleGestureLongPress method. On Android, this method selects the closest word
if the gesture event was over non-link text.

This is tested via a new chromium test WebViewTest.LongPressSelection.

  • page/EventHandler.cpp:

(WebCore::EventHandler::selectClosestWordFromHitTestResult):
(WebCore::EventHandler::selectClosestWordFromMouseEvent):
(WebCore):
(WebCore::EventHandler::handleGestureEvent):
(WebCore::EventHandler::handleGestureLongPress):

  • page/EventHandler.h:

(EventHandler):

Source/WebKit/chromium: Allow EventHandler to handle longpress gestures, including longpress selection on Android.
https://bugs.webkit.org/show_bug.cgi?id=98173

Patch by Oli Lan <olilan@chromium.org> on 2012-10-05
Reviewed by Ryosuke Niwa.

This patch changes the longpress gesture handling code in WebViewImpl to call EventHandler::handleGestureEvent.
The WebCore part of this patch adds longpress handling to that method, including the long press selection behaviour
required for Android. This means that a long press gesture performed on word (that is not part of a link)
selects the word, without generating a context menu event.

A new test, WebViewTest.LongPressSelection has been added to test this.

  • src/WebViewImpl.cpp:

(WebKit::WebViewImpl::handleGestureEvent):
(WebViewImpl):

  • tests/WebViewTest.cpp:
  • tests/data/longpress_selection.html: Added.
Location:
trunk/Source
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r130541 r130547  
     12012-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
    1232012-10-05  Tab Atkins  <jackalmage@gmail.com>
    224
  • trunk/Source/WebCore/page/EventHandler.cpp

    r130449 r130547  
    431431}
    432432
    433 void EventHandler::selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults& result)
     433void EventHandler::selectClosestWordFromHitTestResult(const HitTestResult& result, AppendTrailingWhitespace appendTrailingWhitespace)
    434434{
    435435    Node* innerNode = result.targetNode();
    436436    VisibleSelection newSelection;
    437437
    438     if (innerNode && innerNode->renderer() && m_mouseDownMayStartSelect) {
     438    if (innerNode && innerNode->renderer()) {
    439439        VisiblePosition pos(innerNode->renderer()->positionForPoint(result.localPoint()));
    440440        if (pos.isNotNull()) {
     
    443443        }
    444444
    445         if (newSelection.isRange() && result.event().clickCount() == 2 && m_frame->editor()->isSelectTrailingWhitespaceEnabled())
     445        if (appendTrailingWhitespace == ShouldAppendTrailingWhitespace && newSelection.isRange())
    446446            newSelection.appendTrailingWhitespace();
    447447
    448448        updateSelectionForMouseDownDispatchingSelectStart(innerNode, newSelection, WordGranularity);
     449    }
     450}
     451
     452void 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);
    449457    }
    450458}
     
    25142522    case PlatformEvent::GestureTapDown:
    25152523        return handleGestureTapDown();
     2524    case PlatformEvent::GestureLongPress:
     2525        return handleGestureLongPress(gestureEvent);
    25162526    case PlatformEvent::GestureDoubleTap:
    2517     case PlatformEvent::GestureLongPress:
    25182527    case PlatformEvent::GesturePinchBegin:
    25192528    case PlatformEvent::GesturePinchEnd:
     
    25602569
    25612570    return defaultPrevented;
     2571}
     2572
     2573bool 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);
    25622586}
    25632587
  • trunk/Source/WebCore/page/EventHandler.h

    r130226 r130547  
    9090
    9191enum HitTestScrollbars { ShouldHitTestScrollbars, DontHitTestScrollbars };
     92enum AppendTrailingWhitespace { ShouldAppendTrailingWhitespace, DontAppendTrailingWhitespace };
    9293
    9394class EventHandler {
     
    167168    bool handleGestureEvent(const PlatformGestureEvent&);
    168169    bool handleGestureTap(const PlatformGestureEvent&);
     170    bool handleGestureLongPress(const PlatformGestureEvent&);
    169171    bool handleGestureScrollUpdate(const PlatformGestureEvent&);
    170172#endif
     
    242244    bool eventActivatedView(const PlatformMouseEvent&) const;
    243245    bool updateSelectionForMouseDownDispatchingSelectStart(Node*, const VisibleSelection&, TextGranularity);
     246    void selectClosestWordFromHitTestResult(const HitTestResult&, AppendTrailingWhitespace);
    244247    void selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults&);
    245248    void selectClosestWordOrLinkFromMouseEvent(const MouseEventWithHitTestResults&);
  • trunk/Source/WebKit/chromium/ChangeLog

    r130545 r130547  
     12012-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
    1212012-10-05  Yusuf Ozuysal  <yusufo@google.com>
    222
  • trunk/Source/WebKit/chromium/src/WebViewImpl.cpp

    r130545 r130547  
    743743        break;
    744744    }
    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    }
    746757    case WebInputEvent::GestureLongPress: {
    747758        if (!mainFrameImpl() || !mainFrameImpl()->frameView())
     
    757768        m_contextMenuAllowed = true;
    758769        PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), event);
    759         eventSwallowed = mainFrameImpl()->frame()->eventHandler()->sendContextMenuEventForGesture(platformEvent);
     770        eventSwallowed = mainFrameImpl()->frame()->eventHandler()->handleGestureEvent(platformEvent);
    760771        m_contextMenuAllowed = false;
    761772
  • trunk/Source/WebKit/chromium/tests/WebViewTest.cpp

    r129029 r130547  
    648648}
    649649
    650 }
     650#if OS(ANDROID)
     651TEST_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.