Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-8779] Implemented late binding of gestures. #2306

Merged
merged 5 commits into from Jun 2, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions mobileweb/titanium/Ti/UI/TableViewRow.js
Expand Up @@ -37,6 +37,9 @@ define(["Ti/_/declare", "Ti/_/lang", "Ti/UI/View", "Ti/_/dom", "Ti/_/css", "Ti/_
width: UI.SIZE,
height: UI.SIZE
}));

// Force single tap to be processed.
this.addEventListener("singletap");
},

_defaultWidth: UI.INHERIT,
Expand Down
3 changes: 3 additions & 0 deletions mobileweb/titanium/Ti/UI/TableViewSection.js
Expand Up @@ -19,6 +19,9 @@ define(["Ti/_/declare", "Ti/_/lang", "Ti/_/UI/Widget", "Ti/_/style","Ti/UI/Mobil

// Create the parts out of Ti controls so we can make use of the layout system
this.layout = UI._LAYOUT_CONSTRAINING_VERTICAL;

// Force single tap to be processed.
this.addEventListener("singletap");
},

_defaultWidth: UI.INHERIT,
Expand Down
5 changes: 0 additions & 5 deletions mobileweb/titanium/Ti/XML.js
Expand Up @@ -49,11 +49,6 @@ define(["Ti/_/Evented", "Ti/_/lang"], function(Evented, lang) {
f && lang.generateAccessors(f, e[1], e[2]);
});

Object.defineProperty(Element.prototype, "text", {
get: function() { return this.textContent; },
enumerable: true
});

return lang.setObject("Ti.XML", Evented, {

parseString: function(xml) {
Expand Down
2 changes: 1 addition & 1 deletion mobileweb/titanium/Ti/_/Evented.js
Expand Up @@ -19,7 +19,7 @@ define(function() {
var i = 0,
events = this.listeners[name],
l = events && events.length || 0;

for (; i < l; i++) {
events[i] === handler && events.splice(i, 1);
}
Expand Down
93 changes: 54 additions & 39 deletions mobileweb/titanium/Ti/_/UI/Element.js
@@ -1,11 +1,7 @@
define(
["Ti/_/browser", "Ti/_/css", "Ti/_/declare", "Ti/_/dom", "Ti/_/event", "Ti/_/lang", "Ti/_/style", "Ti/_/Evented",
"Ti/UI", "Ti/_/Gestures/DoubleTap","Ti/_/Gestures/LongPress","Ti/_/Gestures/Pinch","Ti/_/Gestures/SingleTap",
"Ti/_/Gestures/Swipe","Ti/_/Gestures/TouchCancel","Ti/_/Gestures/TouchEnd","Ti/_/Gestures/TouchMove",
"Ti/_/Gestures/TouchStart","Ti/_/Gestures/TwoFingerTap", "Ti/_/Promise"],
function(browser, css, declare, dom, event, lang, style, Evented, UI,
DoubleTap, LongPress, Pinch, SingleTap, Swipe, TouchCancel, TouchEnd,
TouchMove, TouchStart, TwoFingerTap, Promise) {
"Ti/UI", "Ti/_/Promise", "Ti/_/string"],
function(browser, css, declare, dom, event, lang, style, Evented, UI, Promise, string) {

var unitize = dom.unitize,
computeSize = dom.computeSize,
Expand Down Expand Up @@ -36,7 +32,21 @@ define(
postLayoutProp = {
set: postLayoutPropFunction
},
pixelUnits = "px";
pixelUnits = "px",
gestureMapping = {
pinch: "Pinch",
swipe: "Swipe",
twofingertap: "TwoFingerTap",
doubletap: "DoubleTap",
longpress: "LongPress",
singletap: "SingleTap",
click: "SingleTap",
doubleclick: "DoubleTap",
touchstart: "TouchStart",
touchend: "TouchEnd",
touchmove: "TouchMove",
touchcancel: "TouchCancel"
};

return declare("Ti._.UI.Element", Evented, {

Expand All @@ -54,37 +64,15 @@ define(
})),

// Handle click/touch/gestures
recognizers = this._gestureRecognizers = {
Pinch: new Pinch,
Swipe: new Swipe,
TwoFingerTap: new TwoFingerTap,
DoubleTap: new DoubleTap,
LongPress: new LongPress,
SingleTap: new SingleTap,
TouchStart: new TouchStart,
TouchEnd: new TouchEnd,
TouchMove: new TouchMove,
TouchCancel: new TouchCancel
},

// Each event could require a slightly different precedence of execution, which is why we have these separate lists.
// For now they are the same, but I suspect they will be different once the android-iphone parity is determined.
touchRecognizers = {
Start: recognizers,
Move: recognizers,
End: recognizers,
Cancel: recognizers
},
recognizers = this._gestureRecognizers = {},

useTouch = "ontouchstart" in window,
bg = lang.hitch(this, "_doBackground");

require.has("devmode") && args && args._debug && dom.attr.set(node, "data-debug", args._debug);
function processTouchEvent(eventType, evt) {
var i,
gestureRecognizers = touchRecognizers[eventType],
touches = evt.changedTouches;
eventType = "Touch" + eventType + "Event";
if (this._preventDefaultTouchEvent) {
this._preventDefaultTouchEvent && evt.preventDefault && evt.preventDefault();
for (i in touches) {
Expand All @@ -96,11 +84,11 @@ define(
targetTouches: [],
changedTouches: [evt]
});
for (i in gestureRecognizers) {
gestureRecognizers[i]["process" + eventType](evt, self);
for (i in recognizers) {
recognizers[i].recognizer["process" + eventType](evt, self);
}
for (i in gestureRecognizers) {
gestureRecognizers[i]["finalize" + eventType]();
for (i in recognizers) {
recognizers[i].recognizer["finalize" + eventType]();
}
}

Expand All @@ -113,24 +101,24 @@ define(
on(window, useTouch ? "touchmove" : "mousemove", function(evt){
if (!touchMoveBlocked) {
touchMoveBlocked = true;
(useTouch || self._touching) && processTouchEvent("Move", evt);
(useTouch || self._touching) && processTouchEvent("TouchMoveEvent", evt);
setTimeout(function(){
touchMoveBlocked = false;
}, 30);
}
}),
on(window, useTouch ? "touchend" : "mouseup", function(evt){
self._touching = false;
processTouchEvent("End", evt);
processTouchEvent("TouchEndEvent", evt);
event.off(handles);
}),
useTouch && on(window, "touchcancel", function(evt){
processTouchEvent("Cancel", evt);
processTouchEvent("TouchCancelEvent", evt);
event.off(handles);
})
];
self._touching = true;
processTouchEvent("Start", evt);
processTouchEvent("TouchStartEvent", evt);
});

this.addEventListener("touchstart", bg);
Expand Down Expand Up @@ -184,10 +172,37 @@ define(
};
},

addEventListener: function(name, handler) {
if (name in gestureMapping) {
var gestureRecognizers = this._gestureRecognizers,
gestureRecognizer;

if (!(name in gestureRecognizers)) {
gestureRecognizers[name] = {
count: 0,
recognizer: new (require("Ti/_/Gestures/" + gestureMapping[name]))
};
}

gestureRecognizers[name].count++;
}
handler && Evented.addEventListener.apply(this, arguments);
},

removeEventListener: function(name) {
if (name in gestureMapping) {
var gestureRecognizers = this._gestureRecognizers;
if (name in gestureRecognizers && !(--gestureRecognizers[name].count)) {
delete gestureRecognizers[name];
}
}
Evented.removeEventListener.apply(this, arguments);
},

_setParent: function(view) {
this._parent = view;
},

_add: function(view, hidden) {

view._hidden = hidden;
Expand Down
11 changes: 11 additions & 0 deletions support/mobileweb/compiler.py
Expand Up @@ -720,6 +720,17 @@ def find_project_dependencies(self):
'Ti/Filesystem/File',
'Ti/Filesystem/FileStream',
'Ti/Gesture',
'Ti/_/Gestures/GestureRecognizer',
'Ti/_/Gestures/DoubleTap',
'Ti/_/Gestures/LongPress',
'Ti/_/Gestures/Pinch',
'Ti/_/Gestures/SingleTap',
'Ti/_/Gestures/Swipe',
'Ti/_/Gestures/TouchCancel',
'Ti/_/Gestures/TouchEnd',
'Ti/_/Gestures/TouchMove',
'Ti/_/Gestures/TouchStart',
'Ti/_/Gestures/TwoFingerTap',
'Ti/Geolocation',
'Ti/IOStream',
'Ti/Locale',
Expand Down