[Qt] Implement tap feedback respecting -webkit-tap-highlight-color
authorkenneth@webkit.org <kenneth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Jan 2012 18:18:47 +0000 (18:18 +0000)
committerkenneth@webkit.org <kenneth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Jan 2012 18:18:47 +0000 (18:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76914

Reviewed by Simon Hausmann.

.:

Add a manual test.

* ManualTests/qt/tap-highlighting.html: Added.

Source/WebCore:

Implement highlighting of dom nodes with a rounded rect, respecting
the color of -webkit-tap-highlight-color and any transform applied
to the element.

Tested with manual test.

* Target.pri:
* page/GestureTapHighlighter.cpp: Added.
(WebCore::GestureTapHighlighter::pathForNodeHighlight):
* page/GestureTapHighlighter.h: Added.

Source/WebKit2:

Implement tap highlighting for Qt. When a touch press is issued,
which is not handled by the web page, then we highlight any
activatable node below. In all otehr cases, we hide any highlights.

The highlighting itself is painted on an accelerated PageOverlay,
on the web process side.

* Target.pri:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::handlePotentialActivation):
* UIProcess/WebPageProxy.h:
* UIProcess/qt/QtTapGestureRecognizer.cpp:
(WebKit::QtTapGestureRecognizer::recognize):
* UIProcess/qt/QtWebPageEventHandler.cpp:
(QtWebPageEventHandler::handlePotentialSingleTapEvent):
* UIProcess/qt/QtWebPageEventHandler.h:
* WebProcess/WebPage/TapHighlightController.cpp: Added.
(WebKit::TapHighlightController::TapHighlightController):
(WebKit::TapHighlightController::~TapHighlightController):
(WebKit::TapHighlightController::highlight):
(WebKit::TapHighlightController::hideHighlight):
(WebKit::TapHighlightController::pageOverlayDestroyed):
(WebKit::TapHighlightController::willMoveToWebPage):
(WebKit::TapHighlightController::didMoveToWebPage):
(WebKit::highlightColor):
(WebKit::TapHighlightController::drawRect):
(WebKit::TapHighlightController::mouseEvent):
* WebProcess/WebPage/TapHighlightController.h: Added.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
(WebKit::WebPage::highlightPotentialActivation):
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::tapHighlightController):
* WebProcess/WebPage/WebPage.messages.in:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@105893 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
ChangeLog
ManualTests/qt/tap-highlighting.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Target.pri
Source/WebCore/page/GestureTapHighlighter.cpp [new file with mode: 0644]
Source/WebCore/page/GestureTapHighlighter.h [new file with mode: 0644]
Source/WebKit2/ChangeLog
Source/WebKit2/Target.pri
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/qt/QtTapGestureRecognizer.cpp
Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp
Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h
Source/WebKit2/WebProcess/WebPage/TapHighlightController.cpp [new file with mode: 0644]
Source/WebKit2/WebProcess/WebPage/TapHighlightController.h [new file with mode: 0644]
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

index 16f36de..1592466 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2012-01-25  Kenneth Rohde Christiansen  <kenneth@webkit.org>
+
+        [Qt] Implement tap feedback respecting -webkit-tap-highlight-color
+        https://bugs.webkit.org/show_bug.cgi?id=76914
+
+        Reviewed by Simon Hausmann.
+
+        Add a manual test.
+
+        * ManualTests/qt/tap-highlighting.html: Added.
+
 2012-01-25  Roland Steiner  <rolandsteiner@chromium.org>
 
         <style scoped>: Implement registering of <style scoped> with the scoping element
diff --git a/ManualTests/qt/tap-highlighting.html b/ManualTests/qt/tap-highlighting.html
new file mode 100644 (file)
index 0000000..feabdf2
--- /dev/null
@@ -0,0 +1,11 @@
+<h1>
+<input style='position:absolute; left:10px; top:10px;' type='text'>
+<input style='position:absolute; left:0px; top:300px; -webkit-transform:skew(30deg) rotate(-40deg) scale(1.2);' type='text'>
+<input style='position:absolute; left:100px; top:100px; -webkit-transform: rotate(-20deg) scale(1.5);' type='button' value='hest#1'>
+<div style='position:absolute; left:400px; top:200px; -webkit-transform:rotate(10deg);'><a href='#'>hest#2</a></div>
+<div style='position:absolute; left:300px; top:100px; -webkit-transform:rotate(70deg);'><div style=' -webkit-transform:rotate(10deg);'><a href='#'>hest#3</a></div></div>
+<div style='-webkit-transform:rotate(70deg); width:200px'><div style='position:absolute; left:400px; top:-100px; -webkit-transform:rotate(10deg);'><a href='#'>hest#4</a></div></div>
+<div><div style='position:absolute; left:400px; top:400px; -webkit-transform:rotate(10deg);'><a href='#'>hest#4a</a></div></div>
+<a href='#' style='position:absolute;left:500px'>hest#5</a>
+<div style='position:absolute;left:640px'><a href='#'>hest#6</a>
+</h1>
index dfbc59d..7333859 100644 (file)
@@ -1,3 +1,21 @@
+2012-01-25  Kenneth Rohde Christiansen  <kenneth@webkit.org>
+
+        [Qt] Implement tap feedback respecting -webkit-tap-highlight-color
+        https://bugs.webkit.org/show_bug.cgi?id=76914
+
+        Reviewed by Simon Hausmann.
+
+        Implement highlighting of dom nodes with a rounded rect, respecting
+        the color of -webkit-tap-highlight-color and any transform applied
+        to the element.
+
+        Tested with manual test.
+
+        * Target.pri:
+        * page/GestureTapHighlighter.cpp: Added.
+        (WebCore::GestureTapHighlighter::pathForNodeHighlight):
+        * page/GestureTapHighlighter.h: Added.
+
 2012-01-25  Joshua Bell  <jsbell@chromium.org>
 
         IndexedDB: Need to distinguish key paths that don't yield value vs. yield invalid key
index 8c85831..a645ed6 100644 (file)
@@ -986,6 +986,7 @@ SOURCES += \
     page/FrameView.cpp \
     page/Geolocation.cpp \
     page/GeolocationController.cpp \
+    page/GestureTapHighlighter.cpp \
     page/GroupSettings.cpp \
     page/History.cpp \
     page/Location.cpp \
@@ -2044,6 +2045,7 @@ HEADERS += \
     page/FrameView.h \
     page/Geolocation.h \
     page/Geoposition.h \
+    page/GestureTapHighlighter.h\
     page/GroupSettings.h \
     page/History.h \
     page/Location.h \
diff --git a/Source/WebCore/page/GestureTapHighlighter.cpp b/Source/WebCore/page/GestureTapHighlighter.cpp
new file mode 100644 (file)
index 0000000..03c66c0
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "GestureTapHighlighter.h"
+
+#include "Element.h"
+#include "Frame.h"
+#include "FrameView.h"
+#include "GraphicsContext.h"
+#include "GraphicsTypes.h"
+#include "Node.h"
+#include "Page.h"
+#include "RenderBoxModelObject.h"
+#include "RenderInline.h"
+#include "RenderLayer.h"
+#include "RenderObject.h"
+
+namespace WebCore {
+
+namespace {
+
+inline LayoutSize ownerFrameToMainFrameOffset(const RenderObject* o)
+{
+    ASSERT(o->node());
+    Frame* containingFrame = o->frame();
+    if (!containingFrame)
+        return LayoutSize();
+
+    Frame* mainFrame = containingFrame->page()->mainFrame();
+
+    LayoutPoint mainFramePoint = mainFrame->view()->rootViewToContents(containingFrame->view()->contentsToRootView(LayoutPoint()));
+    return toLayoutSize(mainFramePoint);
+}
+
+AffineTransform localToAbsoluteTransform(const RenderObject* o)
+{
+    AffineTransform transform;
+    LayoutPoint referencePoint;
+
+    while (o) {
+        RenderObject* nextContainer = o->container();
+        if (!nextContainer)
+            break;
+
+        LayoutSize containerOffset = o->offsetFromContainer(nextContainer, referencePoint);
+        TransformationMatrix t;
+        o->getTransformFromContainer(nextContainer, containerOffset, t);
+
+        transform = t.toAffineTransform() * transform;
+        referencePoint.move(containerOffset);
+        o = nextContainer;
+    }
+
+    return transform;
+}
+
+Path pathForRenderBox(RenderBox* o)
+{
+    ASSERT(o);
+
+    LayoutRect contentBox;
+    LayoutRect paddingBox;
+    LayoutRect borderBox;
+
+    contentBox = o->contentBoxRect();
+    paddingBox = LayoutRect(
+            contentBox.x() - o->paddingLeft(),
+            contentBox.y() - o->paddingTop(),
+            contentBox.width() + o->paddingLeft() + o->paddingRight(),
+            contentBox.height() + o->paddingTop() + o->paddingBottom());
+    borderBox = LayoutRect(
+            paddingBox.x() - o->borderLeft(),
+            paddingBox.y() - o->borderTop(),
+            paddingBox.width() + o->borderLeft() + o->borderRight(),
+            paddingBox.height() + o->borderTop() + o->borderBottom());
+
+    FloatRect rect(borderBox);
+    rect.inflate(5);
+
+    rect.move(ownerFrameToMainFrameOffset(o));
+
+    Path path;
+    path.addRoundedRect(rect, FloatSize(10, 10));
+
+    return path;
+}
+
+Path pathForRenderInline(RenderInline* o)
+{
+    // FIXME: Adapt this to not just use the bounding box.
+    LayoutRect borderBox = o->linesBoundingBox();
+
+    FloatRect rect(borderBox);
+    rect.inflate(5);
+
+    rect.move(ownerFrameToMainFrameOffset(o));
+
+    Path path;
+    path.addRoundedRect(rect, FloatSize(10, 10));
+
+    return path;
+}
+
+} // anonymous namespace
+
+namespace GestureTapHighlighter {
+
+Path pathForNodeHighlight(const Node* node)
+{
+    RenderObject* renderer = node->renderer();
+
+    Path path;
+    if (!renderer || (!renderer->isBox() && !renderer->isRenderInline()))
+        return path;
+
+    if (renderer->isBox())
+        path = pathForRenderBox(toRenderBox(renderer));
+    else
+        path = pathForRenderInline(toRenderInline(renderer));
+
+    path.transform(localToAbsoluteTransform(renderer));
+    return path;
+}
+
+} // namespace GestureTapHighlighter
+
+} // namespace WebCore
diff --git a/Source/WebCore/page/GestureTapHighlighter.h b/Source/WebCore/page/GestureTapHighlighter.h
new file mode 100644 (file)
index 0000000..1a47d71
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GestureTapHighlighter_h
+#define GestureTapHighlighter_h
+
+namespace WebCore {
+
+class AffineTransform;
+class Path;
+class Node;
+
+namespace GestureTapHighlighter {
+
+Path pathForNodeHighlight(const Node*);
+
+} // namespace GestureTapHighlighter
+
+} // namespace WebCore
+
+#endif // DOMNodeHighlighter_h
index 6214ddd..82f1035 100644 (file)
@@ -1,3 +1,45 @@
+2012-01-25  Kenneth Rohde Christiansen  <kenneth@webkit.org>
+
+        [Qt] Implement tap feedback respecting -webkit-tap-highlight-color
+        https://bugs.webkit.org/show_bug.cgi?id=76914
+
+        Reviewed by Simon Hausmann.
+
+        Implement tap highlighting for Qt. When a touch press is issued,
+        which is not handled by the web page, then we highlight any
+        activatable node below. In all otehr cases, we hide any highlights.
+
+        The highlighting itself is painted on an accelerated PageOverlay,
+        on the web process side.
+
+        * Target.pri:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::handlePotentialActivation):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/qt/QtTapGestureRecognizer.cpp:
+        (WebKit::QtTapGestureRecognizer::recognize):
+        * UIProcess/qt/QtWebPageEventHandler.cpp:
+        (QtWebPageEventHandler::handlePotentialSingleTapEvent):
+        * UIProcess/qt/QtWebPageEventHandler.h:
+        * WebProcess/WebPage/TapHighlightController.cpp: Added.
+        (WebKit::TapHighlightController::TapHighlightController):
+        (WebKit::TapHighlightController::~TapHighlightController):
+        (WebKit::TapHighlightController::highlight):
+        (WebKit::TapHighlightController::hideHighlight):
+        (WebKit::TapHighlightController::pageOverlayDestroyed):
+        (WebKit::TapHighlightController::willMoveToWebPage):
+        (WebKit::TapHighlightController::didMoveToWebPage):
+        (WebKit::highlightColor):
+        (WebKit::TapHighlightController::drawRect):
+        (WebKit::TapHighlightController::mouseEvent):
+        * WebProcess/WebPage/TapHighlightController.h: Added.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::WebPage):
+        (WebKit::WebPage::highlightPotentialActivation):
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::tapHighlightController):
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2012-01-25  NĂ¡ndor Huszka  <huszka.nandor@stud.u-szeged.hu>
 
         [WK2] WebKitTestRunner needs layoutTestController.setPopupBlockingEnabled
index b10f610..0c91ee0 100644 (file)
@@ -347,6 +347,7 @@ HEADERS += \
     WebProcess/WebPage/DrawingAreaImpl.h \
     WebProcess/WebPage/EventDispatcher.h \
     WebProcess/WebPage/FindController.h \
+    WebProcess/WebPage/TapHighlightController.h \
     WebProcess/WebPage/PageOverlay.h \
     WebProcess/WebPage/WebContextMenu.h \
     WebProcess/WebPage/WebFrame.h \
@@ -699,6 +700,7 @@ SOURCES += \
     WebProcess/WebPage/EncoderAdapter.cpp \
     WebProcess/WebPage/EventDispatcher.cpp \
     WebProcess/WebPage/FindController.cpp \
+    WebProcess/WebPage/TapHighlightController.cpp \
     WebProcess/WebPage/LayerTreeHost.cpp \
     WebProcess/WebPage/PageOverlay.cpp \
     WebProcess/WebPage/TiledBackingStoreRemoteTile.cpp \
index ac5d4ae..4dce224 100644 (file)
@@ -977,6 +977,13 @@ void WebPageProxy::handleGestureEvent(const WebGestureEvent& event)
 #endif
 
 #if ENABLE(TOUCH_EVENTS)
+#if PLATFORM(QT)
+void WebPageProxy::handlePotentialActivation(const IntPoint& layoutPoint)
+{
+    process()->send(Messages::WebPage::HighlightPotentialActivation(layoutPoint), m_pageID);
+}
+#endif
+
 void WebPageProxy::handleTouchEvent(const NativeWebTouchEvent& event)
 {
     if (!isValid())
index 241d70f..2dcce0e 100644 (file)
@@ -382,6 +382,9 @@ public:
 #endif
 #if ENABLE(TOUCH_EVENTS)
     void handleTouchEvent(const NativeWebTouchEvent&);
+#if PLATFORM(QT)
+    void handlePotentialActivation(const WebCore::IntPoint&);
+#endif
 #endif
 
     void scrollBy(WebCore::ScrollDirection, WebCore::ScrollGranularity);
index 2ed773c..45a73fb 100644 (file)
@@ -68,6 +68,11 @@ bool QtTapGestureRecognizer::recognize(const QTouchEvent* event, qint64 eventTim
         } else
             m_tapState = SingleTapStarted;
         m_touchBeginEventForTap = adoptPtr(new QTouchEvent(*event));
+
+        if (m_tapState == SingleTapStarted) {
+            const QTouchEvent::TouchPoint& touchPoint = event->touchPoints().first();
+            m_eventHandler->handlePotentialSingleTapEvent(touchPoint);
+        }
         break;
     case QEvent::TouchUpdate:
         // If the touch point moves further than the threshold, we cancel the tap gesture.
@@ -111,6 +116,10 @@ bool QtTapGestureRecognizer::recognize(const QTouchEvent* event, qint64 eventTim
     default:
         break;
     }
+
+    if (m_tapState == NoTap)
+        m_eventHandler->handlePotentialSingleTapEvent(QTouchEvent::TouchPoint());
+
     return false;
 }
 
index f557ee9..09f8960 100644 (file)
@@ -286,6 +286,12 @@ bool QtWebPageEventHandler::handleDropEvent(QDropEvent* ev)
     return accepted;
 }
 
+void QtWebPageEventHandler::handlePotentialSingleTapEvent(const QTouchEvent::TouchPoint& point)
+{
+    QTransform fromItemTransform = m_webPage->transformFromItem();
+    m_webPageProxy->handlePotentialActivation(fromItemTransform.map(point.pos()).toPoint());
+}
+
 void QtWebPageEventHandler::handleSingleTapEvent(const QTouchEvent::TouchPoint& point)
 {
     m_postponeTextInputStateChanged = true;
index fd4aa0c..ebe95dd 100644 (file)
@@ -47,6 +47,7 @@ public:
 
     void setViewportInteractionEngine(QtViewportInteractionEngine*);
 
+    void handlePotentialSingleTapEvent(const QTouchEvent::TouchPoint&);
     void handleSingleTapEvent(const QTouchEvent::TouchPoint&);
     void handleDoubleTapEvent(const QTouchEvent::TouchPoint&);
 
diff --git a/Source/WebKit2/WebProcess/WebPage/TapHighlightController.cpp b/Source/WebKit2/WebProcess/WebPage/TapHighlightController.cpp
new file mode 100644 (file)
index 0000000..5408107
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "TapHighlightController.h"
+
+#include "ShareableBitmap.h"
+#include "WKPage.h"
+#include "WebCoreArgumentCoders.h"
+#include "WebPage.h"
+#include "WebPageProxyMessages.h"
+#include "WebProcess.h"
+#include <WebCore/FocusController.h>
+#include <WebCore/Frame.h>
+#include <WebCore/FrameView.h>
+#include <WebCore/GestureTapHighlighter.h>
+#include <WebCore/GraphicsContext.h>
+#include <WebCore/Page.h>
+
+#include <WebCore/RenderObject.h>
+
+using namespace std;
+using namespace WebCore;
+
+namespace WebKit {
+
+TapHighlightController::TapHighlightController(WebPage* webPage)
+    : m_webPage(webPage)
+    , m_overlay(0)
+{
+}
+
+TapHighlightController::~TapHighlightController()
+{
+}
+
+void TapHighlightController::highlight(Node* node)
+{
+    ASSERT(node);
+
+    m_path = GestureTapHighlighter::pathForNodeHighlight(node);
+    m_color = node->renderer()->style()->tapHighlightColor();
+
+    if (!m_overlay) {
+        RefPtr<PageOverlay> overlay = PageOverlay::create(this);
+        m_overlay = overlay.get();
+        m_webPage->installPageOverlay(overlay.release());
+    } else
+        m_overlay->setNeedsDisplay();
+}
+
+void TapHighlightController::hideHighlight()
+{
+    if (m_overlay)
+        m_webPage->uninstallPageOverlay(m_overlay, /* fadeout */ true);
+    ASSERT(!m_overlay);
+}
+
+void TapHighlightController::pageOverlayDestroyed(PageOverlay*)
+{
+}
+
+void TapHighlightController::willMoveToWebPage(PageOverlay*, WebPage* webPage)
+{
+    if (webPage)
+        return;
+
+    // The page overlay is moving away from the web page, reset it.
+    ASSERT(m_overlay);
+    m_overlay = 0;
+}
+
+void TapHighlightController::didMoveToWebPage(PageOverlay*, WebPage*)
+{
+}
+
+static Color highlightColor(Color baseColor, float fractionFadedIn)
+{
+    return Color(baseColor.red(), baseColor.green(), baseColor.blue(), int(baseColor.alpha() * fractionFadedIn));
+}
+
+void TapHighlightController::drawRect(PageOverlay* pageOverlay, GraphicsContext& context, const IntRect& dirtyRect)
+{
+    if (m_path.isEmpty())
+        return;
+
+    float fractionFadedIn = pageOverlay->fractionFadedIn();
+
+    {
+        GraphicsContextStateSaver stateSaver(context);
+        context.setFillColor(highlightColor(m_color, fractionFadedIn), ColorSpaceSRGB);
+        context.fillPath(m_path);
+    }
+}
+
+bool TapHighlightController::mouseEvent(PageOverlay*, const WebMouseEvent&)
+{
+    return false;
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit2/WebProcess/WebPage/TapHighlightController.h b/Source/WebKit2/WebProcess/WebPage/TapHighlightController.h
new file mode 100644 (file)
index 0000000..cb20858
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef TapHighlightController_h
+#define TapHighlightController_h
+
+#if ENABLE(TOUCH_EVENTS)
+
+#include "PageOverlay.h"
+#include <WebCore/Color.h>
+#include <WebCore/Path.h>
+#include <wtf/Forward.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+class Frame;
+class IntRect;
+class Node;
+}
+
+namespace WebKit {
+
+class WebPage;
+
+class TapHighlightController : private PageOverlay::Client {
+    WTF_MAKE_NONCOPYABLE(TapHighlightController);
+
+public:
+    explicit TapHighlightController(WebPage*);
+    virtual ~TapHighlightController();
+
+    void highlight(WebCore::Node*);
+    void hideHighlight();
+
+private:
+    // PageOverlay::Client.
+    virtual void pageOverlayDestroyed(PageOverlay*);
+    virtual void willMoveToWebPage(PageOverlay*, WebPage*);
+    virtual void didMoveToWebPage(PageOverlay*, WebPage*);
+    virtual bool mouseEvent(PageOverlay*, const WebMouseEvent&);
+    virtual void drawRect(PageOverlay*, WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect);
+
+private:
+    WebPage* m_webPage;
+    PageOverlay* m_overlay;
+
+    WebCore::Path m_path;
+    WebCore::Color m_color;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(TOUCH_EVENTS)
+
+#endif // TapHighlightController_h
index 722cad2..d036e56 100644 (file)
@@ -194,6 +194,9 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
 #endif
     , m_setCanStartMediaTimer(WebProcess::shared().runLoop(), this, &WebPage::setCanStartMediaTimerFired)
     , m_findController(this)
+#if PLATFORM(QT)
+    , m_tapHighlightController(this)
+#endif
     , m_geolocationPermissionRequestManager(this)
     , m_pageID(pageID)
     , m_canRunBeforeUnloadConfirmPanel(parameters.canRunBeforeUnloadConfirmPanel)
@@ -1424,6 +1427,27 @@ void WebPage::restoreSessionAndNavigateToCurrentItem(const SessionState& session
 }
 
 #if ENABLE(TOUCH_EVENTS)
+#if PLATFORM(QT)
+void WebPage::highlightPotentialActivation(const IntPoint& point)
+{
+    Node* activationNode = 0;
+    Frame* mainframe = m_page->mainFrame();
+
+    if (point != IntPoint::zero()) {
+        HitTestResult result = mainframe->eventHandler()->hitTestResultAtPoint(mainframe->view()->windowToContents(point), /*allowShadowContent*/ false, /*ignoreClipping*/ true);
+        activationNode = result.innerNode();
+
+        if (!activationNode->isFocusable())
+            activationNode = activationNode->enclosingLinkEventParentOrSelf();
+    }
+
+    if (activationNode)
+        tapHighlightController().highlight(activationNode);
+    else
+        tapHighlightController().hideHighlight();
+}
+#endif
+
 static bool handleTouchEvent(const WebTouchEvent& touchEvent, Page* page)
 {
     Frame* frame = page->mainFrame();
index a9c2130..216b608 100644 (file)
@@ -41,6 +41,7 @@
 #include "InjectedBundlePageResourceLoadClient.h"
 #include "InjectedBundlePageUIClient.h"
 #include "MessageSender.h"
+#include "TapHighlightController.h"
 #include "Plugin.h"
 #include "SandboxExtension.h"
 #include "ShareableBitmap.h"
@@ -316,6 +317,10 @@ public:
     static const WebEvent* currentEvent();
 
     FindController& findController() { return m_findController; }
+#if PLATFORM(QT)
+    TapHighlightController& tapHighlightController() { return m_tapHighlightController; }
+#endif
+
     GeolocationPermissionRequestManager& geolocationPermissionRequestManager() { return m_geolocationPermissionRequestManager; }
     NotificationPermissionRequestManager* notificationPermissionRequestManager();
 
@@ -544,6 +549,9 @@ private:
 #if ENABLE(TOUCH_EVENTS)
     void touchEvent(const WebTouchEvent&);
     void touchEventSyncForTesting(const WebTouchEvent&, bool& handled);
+#if PLATFORM(QT)
+    void highlightPotentialActivation(const WebCore::IntPoint&);
+#endif
 #endif
     void contextMenuHidden() { m_isShowingContextMenu = false; }
 
@@ -708,6 +716,9 @@ private:
 #endif
 
     FindController m_findController;
+#if PLATFORM(QT)
+    TapHighlightController m_tapHighlightController;
+#endif
     RefPtr<PageOverlay> m_pageOverlay;
 
     RefPtr<WebPage> m_underlayPage;
index 702479b..1bbc41f 100644 (file)
@@ -40,6 +40,9 @@ messages -> WebPage {
 #if ENABLE(TOUCH_EVENTS)
     TouchEvent(WebKit::WebTouchEvent event)
     TouchEventSyncForTesting(WebKit::WebTouchEvent event) -> (bool handled)
+#if PLATFORM(QT)
+    HighlightPotentialActivation(WebCore::IntPoint point)
+#endif
 #endif
 
     ContextMenuHidden()