Source/WebKit/chromium/ChangeLog

 12012-10-02 Oli Lan <olilan@chromium.org>
 2
 3 [chromium] Allow long press to select word on Android.
 4 https://bugs.webkit.org/show_bug.cgi?id=98173
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 This patch implements the long press selection behaviour required for Android. This means
 9 that a long press gesture performed on an unselected word (that is not part of a link)
 10 selects the word, without generating a context menu event).
 11
 12 A new test, WebViewTest.LongPressSelection has been added to test this.
 13
 14 * src/WebViewImpl.cpp:
 15 (WebKit::WebViewImpl::handleGestureEvent):
 16 (WebKit::WebViewImpl::selectNonLinkWordAroundWindowPoint):
 17 (WebKit):
 18 * src/WebViewImpl.h:
 19 (WebViewImpl):
 20 * tests/WebViewTest.cpp:
 21 * tests/data/longpress_selection.html: Added.
 22
1232012-09-29 Ilya Tikhonovsky <loislo@chromium.org>
224
325 Web Inspector: NMI make String* instrumentation non intrusive

Source/WebKit/chromium/src/WebViewImpl.cpp

@@bool WebViewImpl::handleGestureEvent(const WebGestureEvent& event)
725725 eventSwallowed = true;
726726 break;
727727 }
 728#if OS(ANDROID)
 729 if (selectNonLinkWordAroundWindowPoint(WebPoint(event.x, event.y))) {
 730 eventSwallowed = true;
 731 break;
 732 }
 733#endif
728734
729735 m_page->contextMenuController()->clearContextMenu();
730736 m_contextMenuAllowed = true;

@@bool WebViewImpl::detectContentOnTouch(const WebPoint& position, WebInputEvent::
40564062 return true;
40574063}
40584064
 4065bool WebViewImpl::selectNonLinkWordAroundWindowPoint(const WebPoint& windowPoint)
 4066{
 4067 Frame* focusedFrame = page()->focusController()->focusedOrMainFrame();
 4068 IntPoint point = focusedFrame->view()->windowToContents(windowPoint);
 4069 HitTestRequest request(HitTestRequest::Active);
 4070 HitTestResult result(point);
 4071 focusedFrame->document()->renderView()->layer()->hitTest(request, result);
 4072
 4073 Node* node = result.innerNonSharedNode();
 4074 if (!node)
 4075 return false;
 4076
 4077 FrameSelection* fs = focusedFrame->selection();
 4078 if (node->renderer() && !fs->contains(point) && (node->isContentEditable() || node->isTextNode()) && !result.isLiveLink()
 4079 && node->dispatchEvent(Event::create(eventNames().selectstartEvent, true, true))) {
 4080 VisiblePosition pos(node->renderer()->positionForPoint(result.localPoint()));
 4081 WebFrameImpl::selectWordAroundPosition(focusedFrame, pos);
 4082 if (fs->isRange())
 4083 return true;
 4084 }
 4085
 4086 return false;
 4087}
 4088
40594089void WebViewImpl::setVisibilityState(WebPageVisibilityState visibilityState,
40604090 bool isInitialState) {
40614091 if (!page())

Source/WebKit/chromium/src/WebViewImpl.h

@@public:
393393 void mouseDoubleClick(const WebMouseEvent&);
394394
395395 bool detectContentOnTouch(const WebPoint&, WebInputEvent::Type);
 396 bool selectNonLinkWordAroundWindowPoint(const WebPoint&);
396397 void startPageScaleAnimation(const WebCore::IntPoint& targetPosition, bool useAnchor, float newScale, double durationInSeconds);
397398
398399 void numberOfWheelEventHandlersChanged(unsigned);

Source/WebKit/chromium/tests/WebViewTest.cpp

@@TEST_F(WebViewTest, ClientTapHandling)
647647 webView->close();
648648}
649649
 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
650672}

Source/WebKit/chromium/tests/data/longpress_selection.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<style>
 5span {
 6 font-size: 300%;
 7}
 8</style>
 9</head>
 10<body>
 11Hello this is some text for testing. Here is a
 12<span id="target">
 13testword
 14</span>
 15that we should be able to select by longpressing.
 16
 17To test onselectstart, here is
 18<span id="onselectstartfalse" onselectstart="return false;">
 19anotherbitoftext
 20</span>
 21that we should not be able to select.
 22</body>
 23</html>