Do less work while processing touch events
This commit is contained in:
@@ -218,17 +218,18 @@ ol.pointer.TouchSource.prototype.touchToPointer_ =
|
||||
*/
|
||||
ol.pointer.TouchSource.prototype.processTouches_ =
|
||||
function(inEvent, inFunction) {
|
||||
var tl = inEvent.getBrowserEvent().changedTouches;
|
||||
var touchesCopy = goog.array.clone(tl);
|
||||
var pointers = goog.array.map(touchesCopy,
|
||||
goog.partial(this.touchToPointer_, inEvent), this);
|
||||
// forward touch preventDefaults
|
||||
goog.array.forEach(pointers, function(p) {
|
||||
p.preventDefault = function() {
|
||||
inEvent.preventDefault();
|
||||
};
|
||||
}, this);
|
||||
goog.array.forEach(pointers, goog.partial(inFunction, inEvent), this);
|
||||
var touches = inEvent.getBrowserEvent().changedTouches.slice();
|
||||
var count = touches.length;
|
||||
function preventDefault() {
|
||||
inEvent.preventDefault();
|
||||
}
|
||||
var i, pointer;
|
||||
for (i = 0; i < count; ++i) {
|
||||
pointer = this.touchToPointer_(inEvent, touches[i]);
|
||||
// forward touch preventDefaults
|
||||
pointer.preventDefault = preventDefault;
|
||||
inFunction.call(this, inEvent, pointer);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -266,9 +267,14 @@ ol.pointer.TouchSource.prototype.vacuumTouches_ = function(inEvent) {
|
||||
var touchList = inEvent.getBrowserEvent().touches;
|
||||
// pointerMap.getCount() should be < touchList.length here,
|
||||
// as the touchstart has not been processed yet.
|
||||
if (goog.object.getCount(this.pointerMap) >= touchList.length) {
|
||||
var keys = goog.object.getKeys(this.pointerMap);
|
||||
var count = keys.length;
|
||||
if (count >= touchList.length) {
|
||||
var d = [];
|
||||
goog.object.forEach(this.pointerMap, function(value, key) {
|
||||
var i, key, value;
|
||||
for (i = 0; i < count; ++i) {
|
||||
key = keys[i];
|
||||
value = this.pointerMap[key];
|
||||
// Never remove pointerId == 1, which is mouse.
|
||||
// Touch identifiers are 2 smaller than their pointerId, which is the
|
||||
// index in pointermap.
|
||||
@@ -276,8 +282,10 @@ ol.pointer.TouchSource.prototype.vacuumTouches_ = function(inEvent) {
|
||||
!this.findTouch_(touchList, key - 2)) {
|
||||
d.push(value.out);
|
||||
}
|
||||
}, this);
|
||||
goog.array.forEach(d, goog.partial(this.cancelOut_, inEvent), this);
|
||||
}
|
||||
for (i = 0; i < d.length; ++i) {
|
||||
this.cancelOut_(inEvent, d[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user