Add mouse simulation using native touch events

This commit is contained in:
Ross Boucher authored and tlrobinson committed 2009-02-22 17:17:42 -08:00
1 parent 12459aae1e
commit 9eab840f37
2 files changed
+84

No files matched your search

+11
View File
@@ -130,6 +130,13 @@ CPOtherMouseUp = 26;
@group CPEventType
*/
CPOtherMouseDragged = 27;
// iPhone Event Types
CPTouchStart = 28;
CPTouchMove = 29;
CPTouchEnd = 30;
CPTouchCancel = 31;
CPAlphaShiftKeyMask = 1 << 16;
CPShiftKeyMask = 1 << 17;
@@ -175,6 +182,10 @@ CPDOMEventKeyPress = "keypress";
CPDOMEventCopy = "copy";
CPDOMEventPaste = "paste";
CPDOMEventScrollWheel = "mousewheel";
CPDOMEventTouchStart = "touchstart";
CPDOMEventTouchMove = "touchmove";
CPDOMEventTouchEnd = "touchend";
CPDOMEventTouchCancel = "touchcancel";
var _CPEventPeriodicEventPeriod = 0,
_CPEventPeriodicEventTimer = nil;
+73
View File
@@ -149,6 +149,10 @@ var CPDOMWindowGetFrame,
resizeEventImplementation = class_getMethodImplementation(theClass, resizeEventSelector),
resizeEventCallback = function (anEvent) { resizeEventImplementation(self, nil, anEvent); },
touchEventSelector = @selector(_bridgeTouchEvent:),
touchEventImplementation = class_getMethodImplementation(theClass, touchEventSelector),
touchEventCallback = function (anEvent) { touchEventImplementation(self, nil, anEvent); },
theDocument = _DOMWindow.document;
if (document.addEventListener)
@@ -163,6 +167,12 @@ var CPDOMWindowGetFrame,
theDocument.addEventListener(CPDOMEventKeyDown, keyEventCallback, NO);
theDocument.addEventListener(CPDOMEventKeyPress, keyEventCallback, NO);
theDocument.addEventListener(CPDOMEventTouchStart, touchEventCallback, NO);
theDocument.addEventListener(CPDOMEventTouchEnd, touchEventCallback, NO);
theDocument.addEventListener(CPDOMEventTouchMove, touchEventCallback, NO);
theDocument.addEventListener(CPDOMEventTouchCancel, touchEventCallback, NO);
//FIXME: does firefox really need a different value?
_DOMWindow.addEventListener("DOMMouseScroll", scrollEventCallback, NO);
_DOMWindow.addEventListener(CPDOMEventScrollWheel, scrollEventCallback, NO);
@@ -856,6 +866,69 @@ var CTRL_KEY_CODE = 17;
}
}
// DOM event properties used in mouse bridge code
// type
// clientX
// clientY
// timestamp
// target/srcElement
// shiftKey,ctrlKey,altKey,metaKey
/* @ignore */
- (void)_bridgeTouchEvent:(DOMEvent)aDOMEvent
{
try
{
if (aDOMEvent.touches && aDOMEvent.touches.length == 1)
{
var newEvent = {};
switch(aDOMEvent.type)
{
case CPDOMEventTouchStart: newEvent.type = CPDOMEventMouseDown;
break;
case CPDOMEventTouchEnd: newEvent.type = CPDOMEventMouseUp;
break;
case CPDOMEventTouchMove: newEvent.type = CPDOMEventMouseMoved;
break;
case CPDOMEventTouchCancel: newEvent.type = CPDOMEventMouseUp;
break;
}
newEvent.clientX = aDOMEvent.touches[0].clientX;
newEvent.clientY = aDOMEvent.touches[0].clientY;
newEvent.timestamp = aDOMEvent.timestamp;
newEvent.target = aDOMEvent.target;
newEvent.shiftKey = newEvent.ctrlKey = newEvent.altKey = newEvent.metaKey = false;
if (aDOMEvent.type == CPDOMEventTouchMove)
{
newEvent.preventDefault = function(){if(aDOMEvent.preventDefault) aDOMEvent.preventDefault()};
newEvent.stopPropagation = function(){if(aDOMEvent.stopPropagation) aDOMEvent.stopPropagation()};
}
[self _bridgeMouseEvent:newEvent];
/*if (aDOMEvent.preventDefault)
aDOMEvent.preventDefault();
if (aDOMEvent.stopPropagation)
aDOMEvent.stopPropagation();*/
return;
}
}
catch(e)
{
alert(e);
}
// handle touch cases specifically
}
/* @ignore */
- (void)_checkPasteboardElement
{