- Revision
- 130547
- Author
- commit-qu...@webkit.org
- Date
- 2012-10-05 13:45:25 -0700 (Fri, 05 Oct 2012)
Log 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 <oli...@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 <oli...@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.
Modified Paths
Added Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (130546 => 130547)
--- trunk/Source/WebCore/ChangeLog 2012-10-05 20:33:15 UTC (rev 130546)
+++ trunk/Source/WebCore/ChangeLog 2012-10-05 20:45:25 UTC (rev 130547)
@@ -1,3 +1,25 @@
+2012-10-05 Oli Lan <oli...@chromium.org>
+
+ Allow EventHandler to handle longpress gestures, including longpress selection on Android.
+ https://bugs.webkit.org/show_bug.cgi?id=98173
+
+ 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):
+
2012-10-05 Tab Atkins <jackalm...@gmail.com>
<marquee> element forces itself to be at least 1em high, regardless of 'height' declaration
Modified: trunk/Source/WebCore/page/EventHandler.cpp (130546 => 130547)
--- trunk/Source/WebCore/page/EventHandler.cpp 2012-10-05 20:33:15 UTC (rev 130546)
+++ trunk/Source/WebCore/page/EventHandler.cpp 2012-10-05 20:45:25 UTC (rev 130547)
@@ -430,25 +430,33 @@
return true;
}
-void EventHandler::selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults& result)
+void EventHandler::selectClosestWordFromHitTestResult(const HitTestResult& result, AppendTrailingWhitespace appendTrailingWhitespace)
{
Node* innerNode = result.targetNode();
VisibleSelection newSelection;
- if (innerNode && innerNode->renderer() && m_mouseDownMayStartSelect) {
+ if (innerNode && innerNode->renderer()) {
VisiblePosition pos(innerNode->renderer()->positionForPoint(result.localPoint()));
if (pos.isNotNull()) {
newSelection = VisibleSelection(pos);
newSelection.expandUsingGranularity(WordGranularity);
}
- if (newSelection.isRange() && result.event().clickCount() == 2 && m_frame->editor()->isSelectTrailingWhitespaceEnabled())
+ if (appendTrailingWhitespace == ShouldAppendTrailingWhitespace && newSelection.isRange())
newSelection.appendTrailingWhitespace();
updateSelectionForMouseDownDispatchingSelectStart(innerNode, newSelection, WordGranularity);
}
}
+void EventHandler::selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults& result)
+{
+ if (m_mouseDownMayStartSelect) {
+ selectClosestWordFromHitTestResult(result.hitTestResult(),
+ (result.event().clickCount() == 2 && m_frame->editor()->isSelectTrailingWhitespaceEnabled()) ? ShouldAppendTrailingWhitespace : DontAppendTrailingWhitespace);
+ }
+}
+
void EventHandler::selectClosestWordOrLinkFromMouseEvent(const MouseEventWithHitTestResults& result)
{
if (!result.hitTestResult().isLiveLink())
@@ -2513,8 +2521,9 @@
return handleGestureTap(gestureEvent);
case PlatformEvent::GestureTapDown:
return handleGestureTapDown();
+ case PlatformEvent::GestureLongPress:
+ return handleGestureLongPress(gestureEvent);
case PlatformEvent::GestureDoubleTap:
- case PlatformEvent::GestureLongPress:
case PlatformEvent::GesturePinchBegin:
case PlatformEvent::GesturePinchEnd:
case PlatformEvent::GesturePinchUpdate:
@@ -2561,6 +2570,21 @@
return defaultPrevented;
}
+bool EventHandler::handleGestureLongPress(const PlatformGestureEvent& gestureEvent)
+{
+#if OS(ANDROID)
+ IntPoint hitTestPoint = m_frame->view()->windowToContents(gestureEvent.position());
+ HitTestResult result = hitTestResultAtPoint(hitTestPoint, true);
+ Node* innerNode = result.targetNode();
+ if (!result.isLiveLink() && innerNode && (innerNode->isContentEditable() || innerNode->isTextNode())) {
+ selectClosestWordFromHitTestResult(result, DontAppendTrailingWhitespace);
+ if (m_frame->selection()->isRange())
+ return true;
+ }
+#endif
+ return sendContextMenuEventForGesture(gestureEvent);
+}
+
bool EventHandler::handleGestureScrollUpdate(const PlatformGestureEvent& gestureEvent)
{
return handleGestureScrollCore(gestureEvent, ScrollByPixelWheelEvent, true);
Modified: trunk/Source/WebCore/page/EventHandler.h (130546 => 130547)
--- trunk/Source/WebCore/page/EventHandler.h 2012-10-05 20:33:15 UTC (rev 130546)
+++ trunk/Source/WebCore/page/EventHandler.h 2012-10-05 20:45:25 UTC (rev 130547)
@@ -89,6 +89,7 @@
#endif // ENABLE(DRAG_SUPPORT)
enum HitTestScrollbars { ShouldHitTestScrollbars, DontHitTestScrollbars };
+enum AppendTrailingWhitespace { ShouldAppendTrailingWhitespace, DontAppendTrailingWhitespace };
class EventHandler {
WTF_MAKE_NONCOPYABLE(EventHandler);
@@ -166,6 +167,7 @@
#if ENABLE(GESTURE_EVENTS)
bool handleGestureEvent(const PlatformGestureEvent&);
bool handleGestureTap(const PlatformGestureEvent&);
+ bool handleGestureLongPress(const PlatformGestureEvent&);
bool handleGestureScrollUpdate(const PlatformGestureEvent&);
#endif
@@ -241,6 +243,7 @@
bool eventActivatedView(const PlatformMouseEvent&) const;
bool updateSelectionForMouseDownDispatchingSelectStart(Node*, const VisibleSelection&, TextGranularity);
+ void selectClosestWordFromHitTestResult(const HitTestResult&, AppendTrailingWhitespace);
void selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults&);
void selectClosestWordOrLinkFromMouseEvent(const MouseEventWithHitTestResults&);
Modified: trunk/Source/WebKit/chromium/ChangeLog (130546 => 130547)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-10-05 20:33:15 UTC (rev 130546)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-10-05 20:45:25 UTC (rev 130547)
@@ -1,3 +1,23 @@
+2012-10-05 Oli Lan <oli...@chromium.org>
+
+ Allow EventHandler to handle longpress gestures, including longpress selection on Android.
+ https://bugs.webkit.org/show_bug.cgi?id=98173
+
+ 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.
+
2012-10-05 Yusuf Ozuysal <yus...@google.com>
[chromium] Support zooming focused node for mobile devices
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (130546 => 130547)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2012-10-05 20:33:15 UTC (rev 130546)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2012-10-05 20:45:25 UTC (rev 130547)
@@ -742,7 +742,18 @@
break;
}
- case WebInputEvent::GestureTwoFingerTap:
+ case WebInputEvent::GestureTwoFingerTap: {
+ if (!mainFrameImpl() || !mainFrameImpl()->frameView())
+ break;
+
+ m_page->contextMenuController()->clearContextMenu();
+ m_contextMenuAllowed = true;
+ PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), event);
+ eventSwallowed = mainFrameImpl()->frame()->eventHandler()->sendContextMenuEventForGesture(platformEvent);
+ m_contextMenuAllowed = false;
+
+ break;
+ }
case WebInputEvent::GestureLongPress: {
if (!mainFrameImpl() || !mainFrameImpl()->frameView())
break;
@@ -756,7 +767,7 @@
m_page->contextMenuController()->clearContextMenu();
m_contextMenuAllowed = true;
PlatformGestureEventBuilder platformEvent(mainFrameImpl()->frameView(), event);
- eventSwallowed = mainFrameImpl()->frame()->eventHandler()->sendContextMenuEventForGesture(platformEvent);
+ eventSwallowed = mainFrameImpl()->frame()->eventHandler()->handleGestureEvent(platformEvent);
m_contextMenuAllowed = false;
break;
Modified: trunk/Source/WebKit/chromium/tests/WebViewTest.cpp (130546 => 130547)
--- trunk/Source/WebKit/chromium/tests/WebViewTest.cpp 2012-10-05 20:33:15 UTC (rev 130546)
+++ trunk/Source/WebKit/chromium/tests/WebViewTest.cpp 2012-10-05 20:45:25 UTC (rev 130547)
@@ -647,4 +647,26 @@
webView->close();
}
+#if OS(ANDROID)
+TEST_F(WebViewTest, LongPressSelection)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("longpress_selection.html"));
+
+ WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "longpress_selection.html", true);
+ webView->resize(WebSize(500, 300));
+ webView->layout();
+ webkit_support::RunAllPendingMessages();
+
+ WebString target = WebString::fromUTF8("target");
+ WebString _onselectstartfalse_ = WebString::fromUTF8("onselectstartfalse");
+ WebFrameImpl* frame = static_cast<WebFrameImpl*>(webView->mainFrame());
+
+ EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, onselectstartfalse));
+ EXPECT_EQ("", std::string(frame->selectionAsText().utf8().data()));
+ EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, target));
+ EXPECT_EQ("testword", std::string(frame->selectionAsText().utf8().data()));
+ webView->close();
}
+#endif
+
+}
Added: trunk/Source/WebKit/chromium/tests/data/longpress_selection.html (0 => 130547)
--- trunk/Source/WebKit/chromium/tests/data/longpress_selection.html (rev 0)
+++ trunk/Source/WebKit/chromium/tests/data/longpress_selection.html 2012-10-05 20:45:25 UTC (rev 130547)
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+span {
+ font-size: 300%;
+}
+</style>
+</head>
+<body>
+Hello this is some text for testing. Here is a
+<span id="target">
+testword
+</span>
+that we should be able to select by longpressing.
+
+To test onselectstart, here is
+<span id="onselectstartfalse" _onselectstart_="return false;">
+anotherbitoftext
+</span>
+that we should not be able to select.
+</body>
+</html>