Changeset 127095 in webkit


Ignore:
Timestamp:
Aug 29, 2012 9:08:37 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[chromium] Implement disambiguation popup (a.k.a. Link Preview)
https://bugs.webkit.org/show_bug.cgi?id=94182

Patch by Tien-Ren Chen <trchen@chromium.org> on 2012-08-29
Reviewed by Adam Barth.

In this new implementation, we add a new WebViewClient::handleDisambiguationPopup delegate.
The disambiguation sequence will be initiated by the gesture event handler
in WebViewImpl if an ambiguous tap is detected, then
m_client->handleDisambiguationPopup will be called, so the embedder can
decide whether to swallow the touch event and show a popup.

New test: WebFrameTest.DisambiguationPopupTest

  • WebKit.gyp:
  • features.gypi:
  • public/WebInputEvent.h:

(WebGestureEvent):
(WebKit::WebGestureEvent::WebGestureEvent):

  • public/WebTouchCandidatesInfo.h: Removed.
  • public/WebView.h:

(WebKit):

  • public/WebViewClient.h:

(WebKit):
(WebViewClient):
(WebKit::WebViewClient::triggersLinkPreview):

  • src/WebInputEvent.cpp:

(SameSizeAsWebGestureEvent):

  • src/WebViewImpl.cpp:

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

  • src/WebViewImpl.h:

(WebViewImpl):

Location:
trunk/Source
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/WebCore.gypi

    r127046 r127095  
    31643164            'page/TouchAdjustment.cpp',
    31653165            'page/TouchAdjustment.h',
     3166            'page/TouchDisambiguation.cpp',
     3167            'page/TouchDisambiguation.h',
    31663168            'page/UserContentURLPattern.cpp',
    31673169            'page/WebKitAnimation.cpp',
  • trunk/Source/WebKit/chromium/ChangeLog

    r127084 r127095  
     12012-08-29  Tien-Ren Chen  <trchen@chromium.org>
     2
     3        [chromium] Implement disambiguation popup (a.k.a. Link Preview)
     4        https://bugs.webkit.org/show_bug.cgi?id=94182
     5
     6        Reviewed by Adam Barth.
     7
     8        In this new implementation, we add a new WebViewClient::handleDisambiguationPopup delegate.
     9        The disambiguation sequence will be initiated by the gesture event handler
     10        in WebViewImpl if an ambiguous tap is detected, then
     11        m_client->handleDisambiguationPopup will be called, so the embedder can
     12        decide whether to swallow the touch event and show a popup.
     13
     14        New test: WebFrameTest.DisambiguationPopupTest
     15
     16        * WebKit.gyp:
     17        * features.gypi:
     18        * public/WebInputEvent.h:
     19        (WebGestureEvent):
     20        (WebKit::WebGestureEvent::WebGestureEvent):
     21        * public/WebTouchCandidatesInfo.h: Removed.
     22        * public/WebView.h:
     23        (WebKit):
     24        * public/WebViewClient.h:
     25        (WebKit):
     26        (WebViewClient):
     27        (WebKit::WebViewClient::triggersLinkPreview):
     28        * src/WebInputEvent.cpp:
     29        (SameSizeAsWebGestureEvent):
     30        * src/WebViewImpl.cpp:
     31        (WebKit):
     32        (WebKit::WebViewImpl::handleGestureEventWithLinkPreview):
     33        (WebKit::WebViewImpl::handleGestureEvent):
     34        * src/WebViewImpl.h:
     35        (WebViewImpl):
     36
    1372012-08-29  Dominic Mazzoni  <dmazzoni@google.com>
    238
  • trunk/Source/WebKit/chromium/public/WebViewClient.h

    r126061 r127095  
    6363class WebGeolocationClient;
    6464class WebGeolocationService;
     65class WebGestureEvent;
    6566class WebHelperPlugin;
    6667class WebHitTestResult;
     
    7273class WebNotificationPresenter;
    7374class WebRange;
     75class WebRect;
    7476class WebSpeechInputController;
    7577class WebSpeechInputListener;
     
    286288    virtual void didUpdateLayout() { }
    287289
     290    // Return true to swallow the input event if the embedder will start a disambiguation popup
     291    virtual bool handleDisambiguationPopup(const WebGestureEvent&, const WebVector<WebRect>& targetRects) { return false; }
     292
    288293    // Session history -----------------------------------------------------
    289294
  • trunk/Source/WebKit/chromium/src/WebViewImpl.cpp

    r127076 r127095  
    170170#if ENABLE(GESTURE_EVENTS)
    171171#include "PlatformGestureEvent.h"
     172#include "TouchDisambiguation.h"
    172173#endif
    173174
     
    708709            return true;
    709710
    710         PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), event);
    711711        RefPtr<WebCore::PopupContainer> selectPopup;
    712712        selectPopup = m_selectPopup;
    713713        hideSelectPopup();
    714714        ASSERT(!m_selectPopup);
     715
     716        if (!event.boundingBox.isEmpty()) {
     717            Vector<IntRect> goodTargets;
     718            findGoodTouchTargets(event.boundingBox, mainFrameImpl()->frame(), pageScaleFactor(), goodTargets);
     719            // FIXME: replace touch adjustment code when numberOfGoodTargets == 1?
     720            // Single candidate case is currently handled by: https://bugs.webkit.org/show_bug.cgi?id=85101
     721            if (goodTargets.size() >= 2 && m_client && m_client->handleDisambiguationPopup(event, goodTargets))
     722                return true;
     723        }
     724
     725        PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), event);
    715726        bool gestureHandled = mainFrameImpl()->frame()->eventHandler()->handleGestureEvent(platformEvent);
     727
    716728        if (m_selectPopup && m_selectPopup == selectPopup) {
    717729            // That tap triggered a select popup which is the same as the one that
     
    721733            hideSelectPopup();
    722734        }
     735
    723736        return gestureHandled;
    724737    }
  • trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp

    r126204 r127095  
    10791079}
    10801080
     1081class DisambiguationPopupTestWebViewClient : public WebViewClient {
     1082public:
     1083    virtual bool handleDisambiguationPopup(const WebGestureEvent&, const WebVector<WebRect>& targetRects) OVERRIDE
     1084    {
     1085        EXPECT_GE(targetRects.size(), 2u);
     1086        m_triggered = true;
     1087        return true;
     1088    }
     1089
     1090    bool triggered() const { return m_triggered; }
     1091    void resetTriggered() { m_triggered = false; }
     1092    bool m_triggered;
     1093};
     1094
     1095static WebGestureEvent fatTap(int x, int y)
     1096{
     1097    WebGestureEvent event;
     1098    event.type = WebInputEvent::GestureTap;
     1099    event.x = x;
     1100    event.y = y;
     1101    event.boundingBox = WebCore::IntRect(x - 25, y - 25, 50, 50);
     1102    return event;
     1103}
     1104
     1105TEST_F(WebFrameTest, DisambiguationPopupTest)
     1106{
     1107    registerMockedHttpURLLoad("disambiguation_popup.html");
     1108
     1109    DisambiguationPopupTestWebViewClient client;
     1110
     1111    // Make sure we initialize to minimum scale, even if the window size
     1112    // only becomes available after the load begins.
     1113    WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "disambiguation_popup.html", true, 0, &client));
     1114    webViewImpl->resize(WebSize(1000, 1000));
     1115    webViewImpl->layout();
     1116
     1117    client.resetTriggered();
     1118    webViewImpl->handleInputEvent(fatTap(0, 0));
     1119    EXPECT_FALSE(client.triggered());
     1120
     1121    client.resetTriggered();
     1122    webViewImpl->handleInputEvent(fatTap(200, 115));
     1123    EXPECT_FALSE(client.triggered());
     1124
     1125    for (int i = 0; i <= 46; i++) {
     1126        client.resetTriggered();
     1127        webViewImpl->handleInputEvent(fatTap(120, 230 + i * 5));
     1128
     1129        int j = i % 10;
     1130        if (j >= 7 && j <= 9)
     1131            EXPECT_TRUE(client.triggered());
     1132        else
     1133            EXPECT_FALSE(client.triggered());
     1134    }
     1135
     1136    for (int i = 0; i <= 46; i++) {
     1137        client.resetTriggered();
     1138        webViewImpl->handleInputEvent(fatTap(10 + i * 5, 590));
     1139
     1140        int j = i % 10;
     1141        if (j >= 7 && j <= 9)
     1142            EXPECT_TRUE(client.triggered());
     1143        else
     1144            EXPECT_FALSE(client.triggered());
     1145    }
     1146
     1147}
     1148
    10811149} // namespace
Note: See TracChangeset for help on using the changeset viewer.