Skip to content

Commit

Permalink
Merge pull request #2317 from bryan-m-hughes/timob-9357
Browse files Browse the repository at this point in the history
[TIMOB-9357] Tweaked gesture events so that x,y coordinates are relative to the container.
  • Loading branch information
cb1kenobi committed Jun 5, 2012
2 parents 4e7e7cd + 569e10b commit a4256a2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
2 changes: 1 addition & 1 deletion mobileweb/titanium/Ti/UI/Picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ define(["Ti/_/declare", "Ti/UI/View", "Ti/_/UI/Widget", "Ti/UI", "Ti/_/lang", "T

value: {
set: function(value) {
this._dateTimeInput.value = value;
this._dateTimeInput && (this._dateTimeInput.value = value);
return value;
}
}
Expand Down
20 changes: 13 additions & 7 deletions mobileweb/titanium/Ti/_/Gestures/DoubleTap.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,21 @@ define(["Ti/_/declare", "Ti/_/lang","Ti/_/Gestures/GestureRecognizer"], function
this._firstTapTime = null;
if (elapsedTime < this._timeThreshold && Math.abs(this._firstTapLocation.x - x) < this._driftThreshold &&
Math.abs(this._firstTapLocation.y - y) < this._driftThreshold) {
var result = {
x: x,
y: y,
source: this.getSourceNode(e,element)
};
var source = this.getSourceNode(e,element);
if (!element._isGestureBlocked(this.name)) {
this.blocking.push("singletap");
lang.hitch(element,element._handleTouchEvent("dblclick",result));
lang.hitch(element,element._handleTouchEvent(this.name,result));
// We don't reuse the same results object because the values are modified before the event is fired.
// If we reused the object, they would be modified twice, which is incorrect.
lang.hitch(element,element._handleTouchEvent("dblclick", {
x: x,
y: y,
source: source
}));
lang.hitch(element,element._handleTouchEvent(this.name, {
x: x,
y: y,
source: source
}));
}
} else {
this.initTracker(x,y);
Expand Down
20 changes: 13 additions & 7 deletions mobileweb/titanium/Ti/_/Gestures/SingleTap.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ define(["Ti/_/declare", "Ti/_/lang","Ti/_/Gestures/GestureRecognizer"], function
if (Math.abs(this._touchStartLocation.x - x) < this._driftThreshold &&
Math.abs(this._touchStartLocation.y - y) < this._driftThreshold && !this._driftedOutsideThreshold) {
this._touchStartLocation = null;
var result = {
x: x,
y: y,
source: this.getSourceNode(e,element)
};
var source = this.getSourceNode(e,element);
// We don't reuse the same results object because the values are modified before the event is fired.
// If we reused the object, they would be modified twice, which is incorrect.
if (!element._isGestureBlocked(this.name)) {
lang.hitch(element,element._handleTouchEvent("click",result));
lang.hitch(element,element._handleTouchEvent(this.name,result));
lang.hitch(element,element._handleTouchEvent("click", {
x: x,
y: y,
source: source
}));
lang.hitch(element,element._handleTouchEvent(this.name, {
x: x,
y: y,
source: source
}));
}
}
}
Expand Down
16 changes: 15 additions & 1 deletion mobileweb/titanium/Ti/_/UI/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,21 @@ define(
},

_handleTouchEvent: function(type, e) {
this.enabled && this.fireEvent(type, e);
if (this.enabled) {
// Normalize the location of the event.
if (is(e.x, "Number") && is(e.y, "Number") && e.source) {
var pt = UI._container.convertPointToView({
x: e.x,
y: e.y
}, e.source);
e.x = pt.x;
e.y = pt.y;
} else {
e.x = void 0;
e.y = void 0;
}
this.fireEvent(type, e);
}
},

_defaultBackgroundColor: void 0,
Expand Down

0 comments on commit a4256a2

Please sign in to comment.