Title: [124252] trunk/Source/WebKit/chromium
Revision
124252
Author
[email protected]
Date
2012-07-31 14:29:31 -0700 (Tue, 31 Jul 2012)

Log Message

[Chromium-Android] We should hueristically detect content intents on touch
https://bugs.webkit.org/show_bug.cgi?id=92346

Reviewed by Nate Chapin.

On Android, when the user touches a block of text, we run a bunch of
OS-provided hueristics to detect content intents, such as telephone
numbers and mailing addresses.

This patch introduces the WebViewClient functions and the
detectContentIntentOnTouch function, but does not wire the code into
the event system. There are some decisions to make about how to wire it
into the event system, we'll tackle in the next patch.

* public/WebViewClient.h:
(WebKit::WebViewClient::detectContentIntentAround):
(WebViewClient):
(WebKit::WebViewClient::scheduleContentIntent):
(WebKit::WebViewClient::cancelScheduledContentIntents):
* src/WebViewImpl.cpp:
(WebKit):
(WebKit::tapHighlightColorForNode):
(WebKit::WebViewImpl::showTouchHighlightQuads):
(WebKit::WebViewImpl::detectContentIntentOnTouch):
* src/WebViewImpl.h:
(WebViewImpl):

Modified Paths

Diff

Modified: trunk/Source/WebKit/chromium/ChangeLog (124251 => 124252)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-07-31 21:29:03 UTC (rev 124251)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-07-31 21:29:31 UTC (rev 124252)
@@ -1,3 +1,32 @@
+2012-07-31  Adam Barth  <[email protected]>
+
+        [Chromium-Android] We should hueristically detect content intents on touch
+        https://bugs.webkit.org/show_bug.cgi?id=92346
+
+        Reviewed by Nate Chapin.
+
+        On Android, when the user touches a block of text, we run a bunch of
+        OS-provided hueristics to detect content intents, such as telephone
+        numbers and mailing addresses.
+
+        This patch introduces the WebViewClient functions and the
+        detectContentIntentOnTouch function, but does not wire the code into
+        the event system. There are some decisions to make about how to wire it
+        into the event system, we'll tackle in the next patch.
+
+        * public/WebViewClient.h:
+        (WebKit::WebViewClient::detectContentIntentAround):
+        (WebViewClient):
+        (WebKit::WebViewClient::scheduleContentIntent):
+        (WebKit::WebViewClient::cancelScheduledContentIntents):
+        * src/WebViewImpl.cpp:
+        (WebKit):
+        (WebKit::tapHighlightColorForNode):
+        (WebKit::WebViewImpl::showTouchHighlightQuads):
+        (WebKit::WebViewImpl::detectContentIntentOnTouch):
+        * src/WebViewImpl.h:
+        (WebViewImpl):
+
 2012-07-31  Ian Vollick  <[email protected]>
 
         [chromium] Use WebAnimation and related classes in GraphicsLayerChromium and AnimTranslationUtil

Modified: trunk/Source/WebKit/chromium/public/WebViewClient.h (124251 => 124252)


--- trunk/Source/WebKit/chromium/public/WebViewClient.h	2012-07-31 21:29:03 UTC (rev 124251)
+++ trunk/Source/WebKit/chromium/public/WebViewClient.h	2012-07-31 21:29:31 UTC (rev 124252)
@@ -373,8 +373,14 @@
     // around a hit test result. The embedder should use platform-specific
     // content detectors (e.g., from the Android intent system) to analyze the
     // region around the hit test result.
-    virtual WebContentDetectionResult detectContentAround(const WebHitTestResult&) { return WebContentDetectionResult(); }
+    virtual WebContentDetectionResult detectContentIntentAround(const WebHitTestResult&) { return WebContentDetectionResult(); }
 
+    // Schedules a new content intent with the provided url.
+    virtual void scheduleContentIntent(const WebURL&) { }
+
+    // Cancels any previously scheduled content intents that have not yet launched.
+    virtual void cancelScheduledContentIntents() { }
+
 protected:
     ~WebViewClient() { }
 };

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (124251 => 124252)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2012-07-31 21:29:03 UTC (rev 124251)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2012-07-31 21:29:31 UTC (rev 124252)
@@ -227,6 +227,16 @@
     return deferrerStack;
 }
 
+#if ENABLE(TOUCH_EVENTS)
+static Color tapHighlightColorForNode(const Node* node)
+{
+    Color tapHighlightColor = RenderStyle::initialTapHighlightColor().rgb();
+    if (node && node->renderer())
+        tapHighlightColor = node->renderer()->style()->tapHighlightColor().rgb();
+    return tapHighlightColor;
+}
+#endif
+
 // Ensure that the WebDragOperation enum values stay in sync with the original
 // DragOperation constants.
 #define COMPILE_ASSERT_MATCHING_ENUM(coreName) \
@@ -3799,12 +3809,51 @@
     return GraphicsContext3DPrivate::extractWebGraphicsContext3D(SharedGraphicsContext3D::get().get());
 }
 
+void WebViewImpl::showTouchHighlightQuads(const WebVector<WebFloatQuad>& highlight, WebColor highlightColor)
+{
+    // FIXME: Upstream this function from the chromium-android branch.
+    notImplemented();
+}
+
 void WebViewImpl::selectAutofillSuggestionAtIndex(unsigned listIndex)
 {
     if (m_autofillPopupClient && listIndex < m_autofillPopupClient->getSuggestionsCount())
         m_autofillPopupClient->valueChanged(listIndex);
 }
 
+bool WebViewImpl::detectContentIntentOnTouch(const WebPoint& position, WebInputEvent::Type touchType)
+{
+    ASSERT(touchType == WebInputEvent::GestureTap || touchType == WebInputEvent::GestureLongPress);
+    HitTestResult touchHit = hitTestResultForWindowPos(position);
+
+    if (touchHit.isContentEditable())
+        return false;
+
+    Node* node = touchHit.innerNode();
+    if (!node || !node->isTextNode())
+        return false;
+
+    // FIXME: Should we not detect content intents in nodes that have event listeners?
+
+    WebContentDetectionResult content = m_client->detectContentIntentAround(touchHit);
+    if (!content.isValid())
+        return false;
+
+    if (touchType == WebInputEvent::GestureLongPress) {
+        // Select the detected content as a block.
+        focusedFrame()->selectRange(content.range());
+        return true;
+    }
+
+    // Temporarily highlight the content as we do with links.
+    Color tapHighlightColor = tapHighlightColorForNode(touchHit.innerNode());
+    WebVector<WebFloatQuad> quads = content.range().textQuads();
+    showTouchHighlightQuads(quads, tapHighlightColor.rgb());
+
+    m_client->scheduleContentIntent(content.intent());
+    return true;
+}
+
 void WebViewImpl::setVisibilityState(WebPageVisibilityState visibilityState,
                                      bool isInitialState) {
     if (!page())

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.h (124251 => 124252)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.h	2012-07-31 21:29:03 UTC (rev 124251)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.h	2012-07-31 21:29:31 UTC (rev 124252)
@@ -31,16 +31,6 @@
 #ifndef WebViewImpl_h
 #define WebViewImpl_h
 
-#include "WebNavigationPolicy.h"
-#include "platform/WebLayer.h"
-#include "platform/WebLayerTreeView.h"
-#include "platform/WebLayerTreeViewClient.h"
-#include "platform/WebPoint.h"
-#include "platform/WebRect.h"
-#include "platform/WebSize.h"
-#include "platform/WebString.h"
-#include "WebView.h"
-
 #include "ChromeClientImpl.h"
 #include "ContextMenuClientImpl.h"
 #include "DragClientImpl.h"
@@ -56,7 +46,18 @@
 #include "PageWidgetDelegate.h"
 #include "PlatformGestureCurveTarget.h"
 #include "UserMediaClientImpl.h"
+#include "WebInputEvent.h"
+#include "WebNavigationPolicy.h"
+#include "WebView.h"
 #include "WebViewBenchmarkSupportImpl.h"
+#include "platform/WebFloatQuad.h"
+#include "platform/WebLayer.h"
+#include "platform/WebLayerTreeView.h"
+#include "platform/WebLayerTreeViewClient.h"
+#include "platform/WebPoint.h"
+#include "platform/WebRect.h"
+#include "platform/WebSize.h"
+#include "platform/WebString.h"
 #include <wtf/OwnPtr.h>
 #include <wtf/RefCounted.h>
 
@@ -284,6 +285,8 @@
         const WebVector<int>& itemIDs,
         int separatorIndex);
     virtual void hidePopups();
+    // FIXME: Expose showTouchHighlightQuads in the public WebView API when it does something.
+    virtual void showTouchHighlightQuads(const WebVector<WebFloatQuad>& highlight, WebColor highlightColor);
     virtual void selectAutofillSuggestionAtIndex(unsigned listIndex);
     virtual void setScrollbarColors(unsigned inactiveColor,
                                     unsigned activeColor,
@@ -382,6 +385,8 @@
     // Event related methods:
     void mouseContextMenu(const WebMouseEvent&);
     void mouseDoubleClick(const WebMouseEvent&);
+
+    bool detectContentIntentOnTouch(const WebPoint&, WebInputEvent::Type);
     void startPageScaleAnimation(const WebCore::IntPoint& targetPosition, bool useAnchor, float newScale, double durationInSeconds);
 
     void numberOfWheelEventHandlersChanged(unsigned);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to