refactoring, type annotations
This commit is contained in:
@@ -160,6 +160,11 @@ ol.MapBrowserEventHandler = function(map) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.activePointers_ = 0;
|
this.activePointers_ = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Object.<number, boolean>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
this.trackedTouches_ = {};
|
this.trackedTouches_ = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -167,6 +172,7 @@ ol.MapBrowserEventHandler = function(map) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.pointerEventHandler_ = new ol.pointer.PointerEventHandler(element);
|
this.pointerEventHandler_ = new ol.pointer.PointerEventHandler(element);
|
||||||
|
|
||||||
this.pointerdownListenerKey_ = goog.events.listen(this.pointerEventHandler_,
|
this.pointerdownListenerKey_ = goog.events.listen(this.pointerEventHandler_,
|
||||||
ol.pointer.EventType.POINTERDOWN,
|
ol.pointer.EventType.POINTERDOWN,
|
||||||
this.handlePointerDown_, false, this);
|
this.handlePointerDown_, false, this);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
goog.provide('ol.pointer.EventSource');
|
goog.provide('ol.pointer.EventSource');
|
||||||
|
|
||||||
|
goog.require('goog.events.BrowserEvent');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,7 +27,8 @@ ol.pointer.EventSource.prototype.getEvents = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* Returns a mapping between the supported event types and
|
* Returns a mapping between the supported event types and
|
||||||
* the handlers that should handle an event.
|
* the handlers that should handle an event.
|
||||||
* @return {Object.<string, function(Event)>} Event/Handler mapping
|
* @return {Object.<string, function(goog.events.BrowserEvent)>}
|
||||||
|
* Event/Handler mapping
|
||||||
*/
|
*/
|
||||||
ol.pointer.EventSource.prototype.getMapping = goog.abstractMethod;
|
ol.pointer.EventSource.prototype.getMapping = goog.abstractMethod;
|
||||||
|
|
||||||
@@ -33,7 +36,7 @@ ol.pointer.EventSource.prototype.getMapping = goog.abstractMethod;
|
|||||||
/**
|
/**
|
||||||
* Returns the handler that should handle a given event type.
|
* Returns the handler that should handle a given event type.
|
||||||
* @param {string} eventType
|
* @param {string} eventType
|
||||||
* @return {function(Event)} Handler
|
* @return {function(goog.events.BrowserEvent)} Handler
|
||||||
*/
|
*/
|
||||||
ol.pointer.EventSource.prototype.getHandlerForEvent = function(eventType) {
|
ol.pointer.EventSource.prototype.getHandlerForEvent = function(eventType) {
|
||||||
return this.getMapping()[eventType];
|
return this.getMapping()[eventType];
|
||||||
|
|||||||
@@ -42,14 +42,36 @@ goog.require('ol.pointer.EventSource');
|
|||||||
ol.pointer.MouseSource = function(dispatcher) {
|
ol.pointer.MouseSource = function(dispatcher) {
|
||||||
goog.base(this, dispatcher);
|
goog.base(this, dispatcher);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {goog.structs.Map}
|
||||||
|
*/
|
||||||
this.pointerMap = dispatcher.pointerMap;
|
this.pointerMap = dispatcher.pointerMap;
|
||||||
|
|
||||||
// radius around touchend that swallows mouse events
|
/**
|
||||||
|
* Radius around touchend that swallows mouse events.
|
||||||
|
*
|
||||||
|
* @const
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.DEDUP_DIST = 25;
|
this.DEDUP_DIST = 25;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.POINTER_ID = 1;
|
this.POINTER_ID = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
this.POINTER_TYPE = 'mouse';
|
this.POINTER_TYPE = 'mouse';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Array.<string>}
|
||||||
|
*/
|
||||||
this.events = [
|
this.events = [
|
||||||
'mousedown',
|
'mousedown',
|
||||||
'mousemove',
|
'mousemove',
|
||||||
@@ -57,6 +79,11 @@ ol.pointer.MouseSource = function(dispatcher) {
|
|||||||
'mouseover',
|
'mouseover',
|
||||||
'mouseout'
|
'mouseout'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Object.<string, function(goog.events.BrowserEvent)>}
|
||||||
|
*/
|
||||||
this.mapping = {
|
this.mapping = {
|
||||||
'mousedown': this.mousedown,
|
'mousedown': this.mousedown,
|
||||||
'mousemove': this.mousemove,
|
'mousemove': this.mousemove,
|
||||||
@@ -65,6 +92,10 @@ ol.pointer.MouseSource = function(dispatcher) {
|
|||||||
'mouseout': this.mouseout
|
'mouseout': this.mouseout
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Array.<goog.math.Coordinate>}
|
||||||
|
*/
|
||||||
this.lastTouches = [];
|
this.lastTouches = [];
|
||||||
};
|
};
|
||||||
goog.inherits(ol.pointer.MouseSource, ol.pointer.EventSource);
|
goog.inherits(ol.pointer.MouseSource, ol.pointer.EventSource);
|
||||||
|
|||||||
@@ -42,10 +42,22 @@ goog.require('ol.pointer.EventSource');
|
|||||||
ol.pointer.MsSource = function(dispatcher) {
|
ol.pointer.MsSource = function(dispatcher) {
|
||||||
goog.base(this, dispatcher);
|
goog.base(this, dispatcher);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {goog.structs.Map}
|
||||||
|
*/
|
||||||
this.pointerMap = dispatcher.pointerMap;
|
this.pointerMap = dispatcher.pointerMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
this.HAS_BITMAP_TYPE = this.hasBitmapType();
|
this.HAS_BITMAP_TYPE = this.hasBitmapType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Array.<string>}
|
||||||
|
*/
|
||||||
this.events = [
|
this.events = [
|
||||||
'MSPointerDown',
|
'MSPointerDown',
|
||||||
'MSPointerMove',
|
'MSPointerMove',
|
||||||
@@ -56,6 +68,11 @@ ol.pointer.MsSource = function(dispatcher) {
|
|||||||
'MSGotPointerCapture',
|
'MSGotPointerCapture',
|
||||||
'MSLostPointerCapture'
|
'MSLostPointerCapture'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Object.<string, function(goog.events.BrowserEvent)>}
|
||||||
|
*/
|
||||||
this.mapping = {
|
this.mapping = {
|
||||||
'MSPointerDown': this.msPointerDown,
|
'MSPointerDown': this.msPointerDown,
|
||||||
'MSPointerMove': this.msPointerMove,
|
'MSPointerMove': this.msPointerMove,
|
||||||
@@ -67,6 +84,10 @@ ol.pointer.MsSource = function(dispatcher) {
|
|||||||
'MSLostPointerCapture': this.msLostPointerCapture
|
'MSLostPointerCapture': this.msLostPointerCapture
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Array.<string>}
|
||||||
|
*/
|
||||||
this.POINTER_TYPES = [
|
this.POINTER_TYPES = [
|
||||||
'',
|
'',
|
||||||
'unavailable',
|
'unavailable',
|
||||||
|
|||||||
@@ -42,8 +42,16 @@ goog.require('ol.pointer.EventSource');
|
|||||||
ol.pointer.NativeSource = function(dispatcher) {
|
ol.pointer.NativeSource = function(dispatcher) {
|
||||||
goog.base(this, dispatcher);
|
goog.base(this, dispatcher);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {goog.structs.Map}
|
||||||
|
*/
|
||||||
this.pointerMap = dispatcher.pointerMap;
|
this.pointerMap = dispatcher.pointerMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Array.<string>}
|
||||||
|
*/
|
||||||
this.events = [
|
this.events = [
|
||||||
'pointerdown',
|
'pointerdown',
|
||||||
'pointermove',
|
'pointermove',
|
||||||
@@ -54,6 +62,11 @@ ol.pointer.NativeSource = function(dispatcher) {
|
|||||||
'gotpointercapture',
|
'gotpointercapture',
|
||||||
'lostpointercapture'
|
'lostpointercapture'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Object.<string, function(goog.events.BrowserEvent)>}
|
||||||
|
*/
|
||||||
this.mapping = {
|
this.mapping = {
|
||||||
'pointerdown': this.pointerDown,
|
'pointerdown': this.pointerDown,
|
||||||
'pointermove': this.pointerMove,
|
'pointermove': this.pointerMove,
|
||||||
|
|||||||
@@ -65,53 +65,130 @@ ol.pointer.PointerEvent = function(type, browserEvent, opt_eventDict) {
|
|||||||
this.originalEvent = browserEvent.getBrowserEvent();
|
this.originalEvent = browserEvent.getBrowserEvent();
|
||||||
|
|
||||||
var eventDict = goog.isDef(opt_eventDict) ? opt_eventDict : {};
|
var eventDict = goog.isDef(opt_eventDict) ? opt_eventDict : {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.buttons = this.getButtons_(eventDict);
|
this.buttons = this.getButtons_(eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.pressure = this.getPressure_(eventDict, this.buttons);
|
this.pressure = this.getPressure_(eventDict, this.buttons);
|
||||||
|
|
||||||
// MouseEvent related properties
|
// MouseEvent related properties
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
this.bubbles = this.getValue_('bubbles', eventDict);
|
this.bubbles = this.getValue_('bubbles', eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
this.cancelable = this.getValue_('cancelable', eventDict);
|
this.cancelable = this.getValue_('cancelable', eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Object}
|
||||||
|
*/
|
||||||
this.view = this.getValue_('view', eventDict);
|
this.view = this.getValue_('view', eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.detail = this.getValue_('detail', eventDict);
|
this.detail = this.getValue_('detail', eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.screenX = this.getValue_('screenX', eventDict);
|
this.screenX = this.getValue_('screenX', eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.screenY = this.getValue_('screenY', eventDict);
|
this.screenY = this.getValue_('screenY', eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.clientX = this.getValue_('clientX', eventDict);
|
this.clientX = this.getValue_('clientX', eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.clientY = this.getValue_('clientY', eventDict);
|
this.clientY = this.getValue_('clientY', eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
this.ctrlKey = this.getValue_('ctrlKey', eventDict);
|
this.ctrlKey = this.getValue_('ctrlKey', eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
this.altKey = this.getValue_('altKey', eventDict);
|
this.altKey = this.getValue_('altKey', eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
this.shiftKey = this.getValue_('shiftKey', eventDict);
|
this.shiftKey = this.getValue_('shiftKey', eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
this.metaKey = this.getValue_('metaKey', eventDict);
|
this.metaKey = this.getValue_('metaKey', eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.button = this.getValue_('button', eventDict);
|
this.button = this.getValue_('button', eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Node}
|
||||||
|
*/
|
||||||
this.relatedTarget = this.getValue_('relatedTarget', eventDict);
|
this.relatedTarget = this.getValue_('relatedTarget', eventDict);
|
||||||
|
|
||||||
// PointerEvent related properties
|
// PointerEvent related properties
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.pointerId = this.getValueOr_('pointerId', 0, eventDict);
|
this.pointerId = this.getValueOr_('pointerId', 0, eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.width = this.getValueOr_('width', 0, eventDict);
|
this.width = this.getValueOr_('width', 0, eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.height = this.getValueOr_('height', 0, eventDict);
|
this.height = this.getValueOr_('height', 0, eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.tiltX = this.getValueOr_('tiltX', 0, eventDict);
|
this.tiltX = this.getValueOr_('tiltX', 0, eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.tiltY = this.getValueOr_('tiltY', 0, eventDict);
|
this.tiltY = this.getValueOr_('tiltY', 0, eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
this.pointerType = this.getValueOr_('pointerType', '', eventDict);
|
this.pointerType = this.getValueOr_('pointerType', '', eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.hwTimestamp = this.getValueOr_('hwTimestamp', 0, eventDict);
|
this.hwTimestamp = this.getValueOr_('hwTimestamp', 0, eventDict);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
this.isPrimary = this.getValueOr_('isPrimary', false, eventDict);
|
this.isPrimary = this.getValueOr_('isPrimary', false, eventDict);
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -122,7 +199,7 @@ goog.inherits(ol.pointer.PointerEvent, goog.events.Event);
|
|||||||
* @private
|
* @private
|
||||||
* @param {string} key
|
* @param {string} key
|
||||||
* @param {Object.<string, ?>} eventDict
|
* @param {Object.<string, ?>} eventDict
|
||||||
* @return {*}
|
* @return {string|number|?}
|
||||||
*/
|
*/
|
||||||
ol.pointer.PointerEvent.prototype.getValue_ = function(key, eventDict) {
|
ol.pointer.PointerEvent.prototype.getValue_ = function(key, eventDict) {
|
||||||
return goog.isDefAndNotNull(eventDict[key]) ?
|
return goog.isDefAndNotNull(eventDict[key]) ?
|
||||||
@@ -136,7 +213,7 @@ ol.pointer.PointerEvent.prototype.getValue_ = function(key, eventDict) {
|
|||||||
* @param {string} key
|
* @param {string} key
|
||||||
* @param {*} defaultValue
|
* @param {*} defaultValue
|
||||||
* @param {Object.<string, ?>} eventDict
|
* @param {Object.<string, ?>} eventDict
|
||||||
* @return {*}
|
* @return {string|number|?}
|
||||||
*/
|
*/
|
||||||
ol.pointer.PointerEvent.prototype.getValueOr_ =
|
ol.pointer.PointerEvent.prototype.getValueOr_ =
|
||||||
function(key, defaultValue, eventDict) {
|
function(key, defaultValue, eventDict) {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
goog.provide('ol.pointer.PointerEventHandler');
|
goog.provide('ol.pointer.PointerEventHandler');
|
||||||
|
|
||||||
|
|
||||||
goog.require('goog.debug.Console');
|
goog.require('goog.array');
|
||||||
goog.require('goog.events');
|
goog.require('goog.events');
|
||||||
goog.require('goog.events.BrowserEvent');
|
goog.require('goog.events.BrowserEvent');
|
||||||
goog.require('goog.events.Event');
|
goog.require('goog.events.Event');
|
||||||
@@ -67,15 +67,17 @@ ol.pointer.PointerEventHandler = function(element) {
|
|||||||
*/
|
*/
|
||||||
this.pointerMap = new goog.structs.Map();
|
this.pointerMap = new goog.structs.Map();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Object.<string, function(goog.events.BrowserEvent)>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.eventMap_ = {};
|
||||||
|
|
||||||
this.eventMap = {};
|
/**
|
||||||
|
* @type {Array.<ol.pointer.EventSource>}
|
||||||
// Scope objects for native events.
|
* @private
|
||||||
// This exists for ease of testing.
|
*/
|
||||||
this.eventSources = {};
|
this.eventSourceList_ = [];
|
||||||
this.eventSourceList = [];
|
|
||||||
|
|
||||||
this.boundHandler_ = goog.bind(this.eventHandler_, this);
|
|
||||||
|
|
||||||
this.registerSources();
|
this.registerSources();
|
||||||
};
|
};
|
||||||
@@ -151,15 +153,14 @@ ol.pointer.PointerEventHandler.prototype.registerSource =
|
|||||||
var newEvents = s.getEvents();
|
var newEvents = s.getEvents();
|
||||||
|
|
||||||
if (newEvents) {
|
if (newEvents) {
|
||||||
newEvents.forEach(function(e) {
|
goog.array.forEach(newEvents, function(e) {
|
||||||
var handler = s.getHandlerForEvent(e);
|
var handler = s.getHandlerForEvent(e);
|
||||||
|
|
||||||
if (handler) {
|
if (handler) {
|
||||||
this.eventMap[e] = goog.bind(handler, s);
|
this.eventMap_[e] = goog.bind(handler, s);
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
this.eventSources[name] = s;
|
this.eventSourceList_.push(s);
|
||||||
this.eventSourceList.push(s);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -169,8 +170,8 @@ ol.pointer.PointerEventHandler.prototype.registerSource =
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.pointer.PointerEventHandler.prototype.register_ = function() {
|
ol.pointer.PointerEventHandler.prototype.register_ = function() {
|
||||||
var l = this.eventSourceList.length;
|
var l = this.eventSourceList_.length;
|
||||||
for (var i = 0, es; (i < l) && (es = this.eventSourceList[i]); i++) {
|
for (var i = 0, es; (i < l) && (es = this.eventSourceList_[i]); i++) {
|
||||||
this.addEvents_(es.getEvents());
|
this.addEvents_(es.getEvents());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -181,8 +182,8 @@ ol.pointer.PointerEventHandler.prototype.register_ = function() {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.pointer.PointerEventHandler.prototype.unregister_ = function() {
|
ol.pointer.PointerEventHandler.prototype.unregister_ = function() {
|
||||||
var l = this.eventSourceList.length;
|
var l = this.eventSourceList_.length;
|
||||||
for (var i = 0, es; (i < l) && (es = this.eventSourceList[i]); i++) {
|
for (var i = 0, es; (i < l) && (es = this.eventSourceList_[i]); i++) {
|
||||||
this.removeEvents_(es.getEvents());
|
this.removeEvents_(es.getEvents());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -195,7 +196,7 @@ ol.pointer.PointerEventHandler.prototype.unregister_ = function() {
|
|||||||
*/
|
*/
|
||||||
ol.pointer.PointerEventHandler.prototype.eventHandler_ = function(inEvent) {
|
ol.pointer.PointerEventHandler.prototype.eventHandler_ = function(inEvent) {
|
||||||
var type = inEvent.type;
|
var type = inEvent.type;
|
||||||
var handler = this.eventMap[type];
|
var handler = this.eventMap_[type];
|
||||||
if (handler) {
|
if (handler) {
|
||||||
handler(inEvent);
|
handler(inEvent);
|
||||||
}
|
}
|
||||||
@@ -222,10 +223,10 @@ ol.pointer.PointerEventHandler.prototype.eventHandler_ = function(inEvent) {
|
|||||||
*/
|
*/
|
||||||
ol.pointer.PointerEventHandler.prototype.listenOnDocument = function(
|
ol.pointer.PointerEventHandler.prototype.listenOnDocument = function(
|
||||||
type, listener, opt_useCapture, opt_listenerScope) {
|
type, listener, opt_useCapture, opt_listenerScope) {
|
||||||
var l = this.eventSourceList.length;
|
var l = this.eventSourceList_.length;
|
||||||
var eventSource;
|
var eventSource;
|
||||||
for (var i = 0; i < l; i++) {
|
for (var i = 0; i < l; i++) {
|
||||||
eventSource = this.eventSourceList[i];
|
eventSource = this.eventSourceList_[i];
|
||||||
eventSource.listenOnDocument(type);
|
eventSource.listenOnDocument(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,10 +250,10 @@ ol.pointer.PointerEventHandler.prototype.listenOnDocument = function(
|
|||||||
*/
|
*/
|
||||||
ol.pointer.PointerEventHandler.prototype.unlistenOnDocument = function(
|
ol.pointer.PointerEventHandler.prototype.unlistenOnDocument = function(
|
||||||
type, listener, opt_useCapture, opt_listenerScope) {
|
type, listener, opt_useCapture, opt_listenerScope) {
|
||||||
var l = this.eventSourceList.length;
|
var l = this.eventSourceList_.length;
|
||||||
var eventSource;
|
var eventSource;
|
||||||
for (var i = 0; i < l; i++) {
|
for (var i = 0; i < l; i++) {
|
||||||
eventSource = this.eventSourceList[i];
|
eventSource = this.eventSourceList_[i];
|
||||||
eventSource.listenOnDocument(type);
|
eventSource.listenOnDocument(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,9 +268,9 @@ ol.pointer.PointerEventHandler.prototype.unlistenOnDocument = function(
|
|||||||
* @param {Array.<string>} events List of events.
|
* @param {Array.<string>} events List of events.
|
||||||
*/
|
*/
|
||||||
ol.pointer.PointerEventHandler.prototype.addEvents_ = function(events) {
|
ol.pointer.PointerEventHandler.prototype.addEvents_ = function(events) {
|
||||||
events.forEach(function(eventName) {
|
goog.array.forEach(events, function(eventName) {
|
||||||
goog.events.listen(this.element_, eventName,
|
goog.events.listen(this.element_, eventName,
|
||||||
this.boundHandler_);
|
this.eventHandler_, false, this);
|
||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -283,7 +284,7 @@ ol.pointer.PointerEventHandler.prototype.addEvent = function(
|
|||||||
eventName, opt_element) {
|
eventName, opt_element) {
|
||||||
var element = goog.isDef(opt_element) ? opt_element : this.element_;
|
var element = goog.isDef(opt_element) ? opt_element : this.element_;
|
||||||
goog.events.listen(element, eventName,
|
goog.events.listen(element, eventName,
|
||||||
this.boundHandler_);
|
this.eventHandler_, false, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -293,9 +294,9 @@ ol.pointer.PointerEventHandler.prototype.addEvent = function(
|
|||||||
* @param {Array.<string>} events List of events.
|
* @param {Array.<string>} events List of events.
|
||||||
*/
|
*/
|
||||||
ol.pointer.PointerEventHandler.prototype.removeEvents_ = function(events) {
|
ol.pointer.PointerEventHandler.prototype.removeEvents_ = function(events) {
|
||||||
events.forEach(function(e) {
|
goog.array.forEach(events, function(e) {
|
||||||
goog.events.unlisten(this.element_, e,
|
goog.events.unlisten(this.element_, e,
|
||||||
this.boundHandler_);
|
this.eventHandler_, false, this);
|
||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -309,7 +310,7 @@ ol.pointer.PointerEventHandler.prototype.removeEvent = function(
|
|||||||
eventName, opt_element) {
|
eventName, opt_element) {
|
||||||
var element = goog.isDef(opt_element) ? opt_element : this.element_;
|
var element = goog.isDef(opt_element) ? opt_element : this.element_;
|
||||||
goog.events.unlisten(element, eventName,
|
goog.events.unlisten(element, eventName,
|
||||||
this.boundHandler_);
|
this.eventHandler_, false, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -524,7 +525,8 @@ ol.pointer.PointerEventHandler.prototype.fireEvent =
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Re-fires a native pointer event.
|
* Creates a pointer event from a native pointer event
|
||||||
|
* and dispatches this event.
|
||||||
* @param {goog.events.BrowserEvent} nativeEvent A platform event with a target.
|
* @param {goog.events.BrowserEvent} nativeEvent A platform event with a target.
|
||||||
*/
|
*/
|
||||||
ol.pointer.PointerEventHandler.prototype.fireNativeEvent =
|
ol.pointer.PointerEventHandler.prototype.fireNativeEvent =
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
goog.provide('ol.pointer.TouchSource');
|
goog.provide('ol.pointer.TouchSource');
|
||||||
|
|
||||||
goog.require('goog.array');
|
goog.require('goog.array');
|
||||||
|
goog.require('goog.math.Coordinate');
|
||||||
goog.require('ol.pointer.EventSource');
|
goog.require('ol.pointer.EventSource');
|
||||||
|
|
||||||
|
|
||||||
@@ -56,20 +57,59 @@ ol.pointer.TouchSource = function(dispatcher, mouseSource) {
|
|||||||
*/
|
*/
|
||||||
this.mouseSource = mouseSource;
|
this.mouseSource = mouseSource;
|
||||||
|
|
||||||
// This should be long enough to ignore compat mouse events made by touch
|
/**
|
||||||
|
* Mouse event timeout: This should be long enough to
|
||||||
|
* ignore compat mouse events made by touch.
|
||||||
|
* @const
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.DEDUP_TIMEOUT = 2500;
|
this.DEDUP_TIMEOUT = 2500;
|
||||||
this.CLICK_COUNT_TIMEOUT = 200;
|
|
||||||
this.POINTER_TYPE = 'touch';
|
|
||||||
this.firstTouch = null;
|
|
||||||
this.clickCount = 0;
|
|
||||||
this.resetId = null;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.CLICK_COUNT_TIMEOUT = 200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
this.POINTER_TYPE = 'touch';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {?number}
|
||||||
|
*/
|
||||||
|
this.firstTouchId_ = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.clickCount_ = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {?number}
|
||||||
|
*/
|
||||||
|
this.resetId_ = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Array.<string>}
|
||||||
|
*/
|
||||||
this.events = [
|
this.events = [
|
||||||
'touchstart',
|
'touchstart',
|
||||||
'touchmove',
|
'touchmove',
|
||||||
'touchend',
|
'touchend',
|
||||||
'touchcancel'
|
'touchcancel'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Object.<string, function(goog.events.BrowserEvent)>}
|
||||||
|
*/
|
||||||
this.mapping = {
|
this.mapping = {
|
||||||
'touchstart': this.touchstart,
|
'touchstart': this.touchstart,
|
||||||
'touchmove': this.touchmove,
|
'touchmove': this.touchmove,
|
||||||
@@ -98,7 +138,7 @@ ol.pointer.TouchSource.prototype.getMapping = function() {
|
|||||||
* @return {boolean} True, if this is the primary touch.
|
* @return {boolean} True, if this is the primary touch.
|
||||||
*/
|
*/
|
||||||
ol.pointer.TouchSource.prototype.isPrimaryTouch_ = function(inTouch) {
|
ol.pointer.TouchSource.prototype.isPrimaryTouch_ = function(inTouch) {
|
||||||
return this.firstTouch === inTouch.identifier;
|
return this.firstTouchId_ === inTouch.identifier;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -110,7 +150,7 @@ ol.pointer.TouchSource.prototype.isPrimaryTouch_ = function(inTouch) {
|
|||||||
ol.pointer.TouchSource.prototype.setPrimaryTouch_ = function(inTouch) {
|
ol.pointer.TouchSource.prototype.setPrimaryTouch_ = function(inTouch) {
|
||||||
if (this.pointerMap.getCount() === 0 ||
|
if (this.pointerMap.getCount() === 0 ||
|
||||||
(this.pointerMap.getCount() === 1 && this.pointerMap.containsKey(1))) {
|
(this.pointerMap.getCount() === 1 && this.pointerMap.containsKey(1))) {
|
||||||
this.firstTouch = inTouch.identifier;
|
this.firstTouchId_ = inTouch.identifier;
|
||||||
this.firstXY = {X: inTouch.clientX, Y: inTouch.clientY};
|
this.firstXY = {X: inTouch.clientX, Y: inTouch.clientY};
|
||||||
this.cancelResetClickCount_();
|
this.cancelResetClickCount_();
|
||||||
}
|
}
|
||||||
@@ -123,7 +163,7 @@ ol.pointer.TouchSource.prototype.setPrimaryTouch_ = function(inTouch) {
|
|||||||
*/
|
*/
|
||||||
ol.pointer.TouchSource.prototype.removePrimaryPointer_ = function(inPointer) {
|
ol.pointer.TouchSource.prototype.removePrimaryPointer_ = function(inPointer) {
|
||||||
if (inPointer.isPrimary) {
|
if (inPointer.isPrimary) {
|
||||||
this.firstTouch = null;
|
this.firstTouchId_ = null;
|
||||||
this.firstXY = null;
|
this.firstXY = null;
|
||||||
this.resetClickCount_();
|
this.resetClickCount_();
|
||||||
}
|
}
|
||||||
@@ -135,10 +175,11 @@ ol.pointer.TouchSource.prototype.removePrimaryPointer_ = function(inPointer) {
|
|||||||
*/
|
*/
|
||||||
ol.pointer.TouchSource.prototype.resetClickCount_ = function() {
|
ol.pointer.TouchSource.prototype.resetClickCount_ = function() {
|
||||||
var fn = function() {
|
var fn = function() {
|
||||||
this.clickCount = 0;
|
this.clickCount_ = 0;
|
||||||
this.resetId = null;
|
this.resetId_ = null;
|
||||||
};
|
};
|
||||||
this.resetId = setTimeout(goog.bind(fn, this), this.CLICK_COUNT_TIMEOUT);
|
this.resetId_ = goog.global.setTimeout(goog.bind(fn, this),
|
||||||
|
this.CLICK_COUNT_TIMEOUT);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -146,8 +187,8 @@ ol.pointer.TouchSource.prototype.resetClickCount_ = function() {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.pointer.TouchSource.prototype.cancelResetClickCount_ = function() {
|
ol.pointer.TouchSource.prototype.cancelResetClickCount_ = function() {
|
||||||
if (this.resetId) {
|
if (this.resetId_) {
|
||||||
clearTimeout(this.resetId);
|
goog.global.clearTimeout(this.resetId_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -169,7 +210,7 @@ ol.pointer.TouchSource.prototype.touchToPointer_ =
|
|||||||
//e.target = findTarget(e);
|
//e.target = findTarget(e);
|
||||||
e.bubbles = true;
|
e.bubbles = true;
|
||||||
e.cancelable = true;
|
e.cancelable = true;
|
||||||
e.detail = this.clickCount;
|
e.detail = this.clickCount_;
|
||||||
e.button = 0;
|
e.button = 0;
|
||||||
e.buttons = 1;
|
e.buttons = 1;
|
||||||
e.width = inTouch['webkitRadiusX'] || inTouch['radiusX'] || 0;
|
e.width = inTouch['webkitRadiusX'] || inTouch['radiusX'] || 0;
|
||||||
@@ -193,13 +234,13 @@ ol.pointer.TouchSource.prototype.processTouches_ =
|
|||||||
var pointers = goog.array.map(tl,
|
var pointers = goog.array.map(tl,
|
||||||
goog.partial(this.touchToPointer_, inEvent), this);
|
goog.partial(this.touchToPointer_, inEvent), this);
|
||||||
// forward touch preventDefaults
|
// forward touch preventDefaults
|
||||||
pointers.forEach(function(p) {
|
goog.array.forEach(pointers, function(p) {
|
||||||
p.preventDefault = function() {
|
p.preventDefault = function() {
|
||||||
this.firstXY = null;
|
this.firstXY = null;
|
||||||
inEvent.preventDefault();
|
inEvent.preventDefault();
|
||||||
};
|
};
|
||||||
}, this);
|
}, this);
|
||||||
pointers.forEach(goog.partial(inFunction, inEvent), this);
|
goog.array.forEach(pointers, goog.partial(inFunction, inEvent), this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -245,7 +286,7 @@ ol.pointer.TouchSource.prototype.vacuumTouches_ = function(inEvent) {
|
|||||||
d.push(this.touchToPointer_(p));
|
d.push(this.touchToPointer_(p));
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
d.forEach(goog.partial(this.cancelOut_, inEvent), this);
|
goog.array.forEach(d, goog.partial(this.cancelOut_, inEvent), this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -257,7 +298,7 @@ ol.pointer.TouchSource.prototype.vacuumTouches_ = function(inEvent) {
|
|||||||
* @param {Object} thisArg
|
* @param {Object} thisArg
|
||||||
*/
|
*/
|
||||||
ol.pointer.TouchSource.prototype.forEach_ = function(map, callback, thisArg) {
|
ol.pointer.TouchSource.prototype.forEach_ = function(map, callback, thisArg) {
|
||||||
map.getValues().forEach(function(value) {
|
goog.array.forEach(map.getValues(), function(value) {
|
||||||
callback.call(thisArg, value, map.get(value));
|
callback.call(thisArg, value, map.get(value));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -273,7 +314,7 @@ ol.pointer.TouchSource.prototype.touchstart = function(inEvent) {
|
|||||||
this.vacuumTouches_(inEvent);
|
this.vacuumTouches_(inEvent);
|
||||||
this.setPrimaryTouch_(inEvent.getBrowserEvent().changedTouches[0]);
|
this.setPrimaryTouch_(inEvent.getBrowserEvent().changedTouches[0]);
|
||||||
this.dedupSynthMouse_(inEvent);
|
this.dedupSynthMouse_(inEvent);
|
||||||
this.clickCount++;
|
this.clickCount_++;
|
||||||
this.processTouches_(inEvent, this.overDown_);
|
this.processTouches_(inEvent, this.overDown_);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -414,7 +455,7 @@ ol.pointer.TouchSource.prototype.dedupSynthMouse_ = function(inEvent) {
|
|||||||
// only the primary finger will synth mouse events
|
// only the primary finger will synth mouse events
|
||||||
if (this.isPrimaryTouch_(t)) {
|
if (this.isPrimaryTouch_(t)) {
|
||||||
// remember x/y of last touch
|
// remember x/y of last touch
|
||||||
var lt = {x: t.clientX, y: t.clientY};
|
var lt = new goog.math.Coordinate(t.clientX, t.clientY);
|
||||||
lts.push(lt);
|
lts.push(lt);
|
||||||
var fn = goog.bind(function(lts, lt) {
|
var fn = goog.bind(function(lts, lt) {
|
||||||
var i = lts.indexOf(lt);
|
var i = lts.indexOf(lt);
|
||||||
@@ -422,6 +463,6 @@ ol.pointer.TouchSource.prototype.dedupSynthMouse_ = function(inEvent) {
|
|||||||
lts.splice(i, 1);
|
lts.splice(i, 1);
|
||||||
}
|
}
|
||||||
}, null, lts, lt);
|
}, null, lts, lt);
|
||||||
setTimeout(fn, this.DEDUP_TIMEOUT);
|
goog.global.setTimeout(fn, this.DEDUP_TIMEOUT);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user