Commit d72a19c1 authored by eric@webkit.org's avatar eric@webkit.org

2010-02-25 Ben Murdoch <benm@google.com>

        Reviewed by Kenneth Rohde Christiansen.

        The target element of a Touch should be the target where that touch originated, not where it is now.
        https://bugs.webkit.org/show_bug.cgi?id=34585

        * fast/events/touch/basic-single-touch-events-expected.txt: Update expected target element.
        * fast/events/touch/script-tests/basic-single-touch-events.js: ditto.
        * fast/events/touch/script-tests/touch-target.js: Added.
        * fast/events/touch/touch-target-expected.txt: Added.
        * fast/events/touch/touch-target.html: Added.
2010-02-25  Ben Murdoch  <benm@google.com>

        Reviewed by Kenneth Rohde Christiansen.

        The target element of a Touch should be the target where that touch originated, not where it is now.
        https://bugs.webkit.org/show_bug.cgi?id=34585

        Currently the target of a touch is set to the resulting node of the hit test where the touch currently
        is. This does not match the behavior of iPhone or Android. This patch uses a hashmap on the EventHandler
        to keep track of the target element when a touch is first started. This target is then used as the target
        for subsequent touches with the same id. This matches observed behavior on iPhone and Android.

        Tests:
        fast/events/touch/touch-target.html: Added.
        fast/events/touch/basic-single-touch-events.html: Updated.

        * page/EventHandler.cpp:
        (WebCore::EventHandler::handleTouchEvent): Store the originating target element of a touch in a hashmap
            so that we can reuse that target for future events caused by that touch. This matches observed behavior
            on iPhone and Android.
        * page/EventHandler.h: Add hashmap as a member.
        * platform/PlatformTouchPoint.h:
        (WebCore::PlatformTouchPoint::id): Store the touch point id as unsigned.
        * platform/qt/PlatformTouchPointQt.cpp:
        (WebCore::PlatformTouchPoint::PlatformTouchPoint): Cast platform touch id from signed to unsigned. Qt API
            docs state that it will always be >= 0.
2010-02-25  Ben Murdoch  <benm@google.com>

        Reviewed by Kenneth Rohde Christiansen.

        The target element of a Touch should be the target where that touch originated, not where it is now.
        https://bugs.webkit.org/show_bug.cgi?id=34585

        * DumpRenderTree/qt/EventSenderQt.cpp:
        (EventSender::addTouchPoint): Fix a bug where touch points were not being given unique ids.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@55230 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent feaa2a70
2010-02-25 Ben Murdoch <benm@google.com>
Reviewed by Kenneth Rohde Christiansen.
The target element of a Touch should be the target where that touch originated, not where it is now.
https://bugs.webkit.org/show_bug.cgi?id=34585
* fast/events/touch/basic-single-touch-events-expected.txt: Update expected target element.
* fast/events/touch/script-tests/basic-single-touch-events.js: ditto.
* fast/events/touch/script-tests/touch-target.js: Added.
* fast/events/touch/touch-target-expected.txt: Added.
* fast/events/touch/touch-target.html: Added.
2010-02-25 Xan Lopez <xlopez@igalia.com>
Reviewed by Gustavo Noronha.
......
......@@ -67,7 +67,7 @@ PASS lastEvent.changedTouches.length is 1
PASS lastEvent.targetTouches.length is 0
PASS lastEvent.pageX is 0
PASS lastEvent.pageY is 0
PASS lastEvent.touches[0].target.tagName is "HTML"
PASS lastEvent.touches[0].target.tagName is "DIV"
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -80,7 +80,7 @@ function verifyTouch(which) {
break;
case 4:
verifyTouchEvent("touchmove", 1, 1, 0);
shouldBeEqualToString("lastEvent.touches[0].target.tagName", "HTML");
shouldBeEqualToString("lastEvent.touches[0].target.tagName", "DIV");
break;
default: testFailed("Wrong number of touch events! (" + which + ")");
......
var div1 = document.createElement("div");
div1.id = "targetA";
div1.style.width = "100px";
div1.style.height = "100px";
div1.style.backgroundColor = "blue";
var div2 = document.createElement("div");
div2.id = "targetB";
div2.style.width = "100px";
div2.style.height = "100px";
div2.style.backgroundColor = "green";
var touchStartCount = 0;
var touchMoveCount = 0;
document.getElementById('targetsDiv').appendChild(div1);
document.getElementById('targetsDiv').appendChild(document.createElement('br'));
document.getElementById('targetsDiv').appendChild(div2);
function touchStartHandler()
{
shouldBeEqualToString('event.type', 'touchstart');
switch (touchStartCount) {
case 0:
shouldBeEqualToString('event.touches[0].target.id', div1.id);
shouldBeEqualToString('event.touches[1].target.id', div2.id);
break;
case 1:
shouldBeEqualToString('event.touches[0].target.id', div2.id);
shouldBeEqualToString('event.touches[1].target.id', div1.id);
break;
}
touchStartCount++;
}
function touchMoveHandler()
{
shouldBeEqualToString('event.type', 'touchmove');
switch (touchMoveCount) {
case 0:
case 1:
shouldBeEqualToString('event.touches[0].target.id', div1.id);
shouldBeEqualToString('event.touches[1].target.id', div2.id);
break;
case 2:
shouldBeEqualToString('event.touches[0].target.id', div2.id);
shouldBeEqualToString('event.touches[1].target.id', div1.id);
break;
}
if (++touchMoveCount == 3)
{
successfullyParsed = true;
layoutTestController.notifyDone();
isSuccessfullyParsed();
}
}
div1.addEventListener("touchstart", touchStartHandler, false);
div1.addEventListener("touchmove", touchMoveHandler, false);
div2.addEventListener("touchstart", touchStartHandler, false);
div2.addEventListener("touchmove", touchMoveHandler, false);
description("Tests that the target of touches match the element where the event originated, not where the touch is currently occurring.");
if (window.layoutTestController) {
layoutTestController.waitUntilDone();
}
if (window.eventSender) {
eventSender.clearTouchPoints();
eventSender.addTouchPoint(50, 150);
eventSender.addTouchPoint(50, 250);
eventSender.touchStart();
eventSender.updateTouchPoint(0, 50, 250);
eventSender.updateTouchPoint(1, 50, 150);
eventSender.touchMove();
eventSender.updateTouchPoint(0, 1000, 1000);
eventSender.updateTouchPoint(1, 1000, 1000);
eventSender.touchMove();
eventSender.releaseTouchPoint(0);
eventSender.touchEnd();
eventSender.addTouchPoint(50,150);
eventSender.touchStart();
eventSender.updateTouchPoint(0, 500, 500);
eventSender.updateTouchPoint(1, 500, 500);
eventSender.touchMove();
} else
debug('This test requires DRT.');
Tests that the target of touches match the element where the event originated, not where the touch is currently occurring.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS event.type is "touchstart"
PASS event.touches[0].target.id is "targetA"
PASS event.touches[1].target.id is "targetB"
PASS event.type is "touchmove"
PASS event.touches[0].target.id is "targetA"
PASS event.touches[1].target.id is "targetB"
PASS event.type is "touchmove"
PASS event.touches[0].target.id is "targetA"
PASS event.touches[1].target.id is "targetB"
PASS event.type is "touchstart"
PASS event.touches[0].target.id is "targetB"
PASS event.touches[1].target.id is "targetA"
PASS event.type is "touchmove"
PASS event.touches[0].target.id is "targetB"
PASS event.touches[1].target.id is "targetA"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../../js/resources/js-test-style.css">
<script src="../../js/resources/js-test-pre.js"></script>
<script src="../../js/resources/js-test-post-function.js"></script>
</head>
<body>
<p id="description"></p>
<div id="targetsDiv"></div>
<div id="console"></div>
<script src="script-tests/touch-target.js"></script>
</body>
</html>
2010-02-25 Ben Murdoch <benm@google.com>
Reviewed by Kenneth Rohde Christiansen.
The target element of a Touch should be the target where that touch originated, not where it is now.
https://bugs.webkit.org/show_bug.cgi?id=34585
Currently the target of a touch is set to the resulting node of the hit test where the touch currently
is. This does not match the behavior of iPhone or Android. This patch uses a hashmap on the EventHandler
to keep track of the target element when a touch is first started. This target is then used as the target
for subsequent touches with the same id. This matches observed behavior on iPhone and Android.
Tests:
fast/events/touch/touch-target.html: Added.
fast/events/touch/basic-single-touch-events.html: Updated.
* page/EventHandler.cpp:
(WebCore::EventHandler::handleTouchEvent): Store the originating target element of a touch in a hashmap
so that we can reuse that target for future events caused by that touch. This matches observed behavior
on iPhone and Android.
* page/EventHandler.h: Add hashmap as a member.
* platform/PlatformTouchPoint.h:
(WebCore::PlatformTouchPoint::id): Store the touch point id as unsigned.
* platform/qt/PlatformTouchPointQt.cpp:
(WebCore::PlatformTouchPoint::PlatformTouchPoint): Cast platform touch id from signed to unsigned. Qt API
docs state that it will always be >= 0.
2010-02-24 Antonio Gomes <tonikitoo@webkit.org>
Reviewed by Simon Fraser.
......
......@@ -2583,7 +2583,23 @@ bool EventHandler::handleTouchEvent(const PlatformTouchEvent& event)
int adjustedPageX = lroundf(pagePoint.x() / m_frame->pageZoomFactor());
int adjustedPageY = lroundf(pagePoint.y() / m_frame->pageZoomFactor());
RefPtr<Touch> touch = Touch::create(doc->frame(), target, point.id(),
// Increment the platform touch id by 1 to avoid storing a key of 0 in the hashmap.
unsigned touchPointTargetKey = point.id() + 1;
EventTarget* touchTarget = 0;
if (point.state() == PlatformTouchPoint::TouchPressed) {
m_originatingTouchPointTargets.set(touchPointTargetKey, target);
touchTarget = target;
} else if (point.state() == PlatformTouchPoint::TouchReleased || point.state() == PlatformTouchPoint::TouchCancelled) {
// The target should be the original target for this touch, so get it from the hashmap. As it's a release or cancel
// we also remove it from the map.
touchTarget = m_originatingTouchPointTargets.take(touchPointTargetKey).get();
} else
touchTarget = m_originatingTouchPointTargets.get(touchPointTargetKey).get();
if (!touchTarget)
continue;
RefPtr<Touch> touch = Touch::create(doc->frame(), touchTarget, point.id(),
point.screenPos().x(), point.screenPos().y(),
adjustedPageX, adjustedPageY);
......
......@@ -37,12 +37,17 @@
class NSView;
#endif
#if ENABLE(TOUCH_EVENTS)
#include <wtf/HashMap.h>
#endif
namespace WebCore {
class AtomicString;
class Clipboard;
class Cursor;
class Event;
class EventTarget;
class FloatPoint;
class Frame;
class HitTestRequest;
......@@ -408,6 +413,8 @@ private:
int m_activationEventNumber;
#endif
#if ENABLE(TOUCH_EVENTS)
typedef HashMap<int, RefPtr<EventTarget> > TouchTargetMap;
TouchTargetMap m_originatingTouchPointTargets;
RefPtr<Node> m_touchEventTarget;
#endif
};
......
......@@ -50,13 +50,13 @@ public:
PlatformTouchPoint(const IntPoint& windowPos, State);
#endif
int id() const { return m_id; }
unsigned id() const { return m_id; }
State state() const { return m_state; }
IntPoint screenPos() const { return m_screenPos; }
IntPoint pos() const { return m_pos; }
private:
int m_id;
unsigned m_id;
State m_state;
IntPoint m_screenPos;
IntPoint m_pos;
......
......@@ -29,7 +29,8 @@ namespace WebCore {
PlatformTouchPoint::PlatformTouchPoint(const QTouchEvent::TouchPoint& point)
{
m_id = point.id();
// The QTouchEvent::TouchPoint API states that ids will be >= 0.
m_id = static_cast<unsigned>(point.id());
switch (point.state()) {
case Qt::TouchPointReleased: m_state = TouchReleased; break;
case Qt::TouchPointMoved: m_state = TouchMoved; break;
......
2010-02-25 Ben Murdoch <benm@google.com>
Reviewed by Kenneth Rohde Christiansen.
The target element of a Touch should be the target where that touch originated, not where it is now.
https://bugs.webkit.org/show_bug.cgi?id=34585
* DumpRenderTree/qt/EventSenderQt.cpp:
(EventSender::addTouchPoint): Fix a bug where touch points were not being given unique ids.
2010-02-24 Jesus Sanchez-Palencia <jesus.palencia@openbossa.org>
Reviewed by Kenneth Rohde Christiansen.
......
......@@ -289,11 +289,15 @@ void EventSender::scheduleAsynchronousClick()
void EventSender::addTouchPoint(int x, int y)
{
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
int id = m_touchPoints.count();
// Use index to refer to the position in the vector that this touch
// is stored. We then create a unique id for the touch that will be
// passed into WebCore.
int index = m_touchPoints.count();
int id = m_touchPoints.isEmpty() ? 0 : m_touchPoints.last().id() + 1;
QTouchEvent::TouchPoint point(id);
m_touchPoints.append(point);
updateTouchPoint(id, x, y);
m_touchPoints[id].setState(Qt::TouchPointPressed);
updateTouchPoint(index, x, y);
m_touchPoints[index].setState(Qt::TouchPointPressed);
#endif
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment