Optimizing touch device handling

The native event of the touchstart/mousedown event needs to be cloned; change includes some compiler optimizations.
This commit is contained in:
ahocevar
2012-09-25 18:30:23 +02:00
parent ce977e5364
commit 5a97655983
+18 -21
View File
@@ -96,10 +96,10 @@ ol.MapBrowserEventHandler = function(map) {
this.dragged_ = false; this.dragged_ = false;
/** /**
* @type {number|undefined} * @type {number}
* @private * @private
*/ */
this.timestamp_; this.timestamp_ = 0;
/** /**
* @type {Array.<number>} * @type {Array.<number>}
@@ -160,9 +160,9 @@ ol.MapBrowserEventHandler.prototype.touchEnableBrowserEvent_ =
*/ */
ol.MapBrowserEventHandler.prototype.click_ = function(browserEvent) { ol.MapBrowserEventHandler.prototype.click_ = function(browserEvent) {
if (!this.dragged_) { if (!this.dragged_) {
this.touchEnableBrowserEvent_(browserEvent); this.touchEnableBrowserEvent_(this.down_);
var newEvent = new ol.MapBrowserEvent( var newEvent = new ol.MapBrowserEvent(
ol.MapBrowserEvent.EventType.CLICK, this.map_, browserEvent); ol.MapBrowserEvent.EventType.CLICK, this.map_, this.down_);
this.down_ = null; this.down_ = null;
this.dispatchEvent(newEvent); this.dispatchEvent(newEvent);
} }
@@ -179,7 +179,7 @@ ol.MapBrowserEventHandler.prototype.dblclick_ = function(browserEvent) {
if (!this.timestamp_ || now - this.timestamp_ > 250) { if (!this.timestamp_ || now - this.timestamp_ > 250) {
this.timestamp_ = now; this.timestamp_ = now;
} else { } else {
this.timestamp_ = undefined; this.timestamp_ = 0;
this.touchEnableBrowserEvent_(this.down_); this.touchEnableBrowserEvent_(this.down_);
var newEvent = new ol.MapBrowserEvent( var newEvent = new ol.MapBrowserEvent(
ol.MapBrowserEvent.EventType.DBLCLICK, this.map_, this.down_); ol.MapBrowserEvent.EventType.DBLCLICK, this.map_, this.down_);
@@ -196,28 +196,25 @@ ol.MapBrowserEventHandler.prototype.dblclick_ = function(browserEvent) {
*/ */
ol.MapBrowserEventHandler.prototype.dragstart_ = function(browserEvent) { ol.MapBrowserEventHandler.prototype.dragstart_ = function(browserEvent) {
if (!this.previous_) { if (!this.previous_) {
this.down_ = new goog.events.BrowserEvent(browserEvent.getBrowserEvent());
this.touchEnableBrowserEvent_(browserEvent); this.touchEnableBrowserEvent_(browserEvent);
this.previous_ = { this.previous_ = {
clientX: browserEvent.clientX, clientX: browserEvent.clientX,
clientY: browserEvent.clientY clientY: browserEvent.clientY
}; };
this.down_ = browserEvent;
this.dragged_ = false; this.dragged_ = false;
if (this.isTouch_) { this.dragListenerKeys_ = [
this.dragListenerKeys_ = [ goog.events.listen(document,
goog.events.listen(document, this.isTouch_ ?
goog.events.EventType.TOUCHMOVE, this.drag_, false, this), goog.events.EventType.TOUCHMOVE :
goog.events.listen(document, goog.events.EventType.MOUSEMOVE,
goog.events.EventType.TOUCHEND, this.dragend_, false, this) this.drag_, false, this),
]; goog.events.listen(document,
} else { this.isTouch_ ?
this.dragListenerKeys_ = [ goog.events.EventType.TOUCHEND :
goog.events.listen(document, goog.events.EventType.MOUSEUP,
goog.events.EventType.MOUSEMOVE, this.drag_, false, this), this.dragend_, false, this)
goog.events.listen(document, ];
goog.events.EventType.MOUSEUP, this.dragend_, false, this)
];
}
var newEvent = new ol.MapBrowserEvent( var newEvent = new ol.MapBrowserEvent(
ol.MapBrowserEvent.EventType.DRAGSTART, this.map_, browserEvent); ol.MapBrowserEvent.EventType.DRAGSTART, this.map_, browserEvent);
this.dispatchEvent(newEvent); this.dispatchEvent(newEvent);