Pass the mapping object to the ol.pointer.EventSource constructor

Conflicts:
	src/ol/pointer/mssource.js
This commit is contained in:
Frederic Junod
2014-03-10 12:25:25 +01:00
committed by tsauerwein
parent 4468d96a13
commit 028a183d11
5 changed files with 49 additions and 110 deletions

View File

@@ -2,18 +2,27 @@
goog.provide('ol.pointer.EventSource');
goog.require('goog.events.BrowserEvent');
goog.require('goog.object');
/**
* @param {ol.pointer.PointerEventHandler} dispatcher
* @param {Object.<string, function(goog.events.BrowserEvent)>} mapping
* @constructor
*/
ol.pointer.EventSource = function(dispatcher) {
ol.pointer.EventSource = function(dispatcher, mapping) {
/**
* @type {ol.pointer.PointerEventHandler}
*/
this.dispatcher = dispatcher;
/**
* @private
* @const
* @type {Object.<string, function(goog.events.BrowserEvent)>}
*/
this.mapping_ = mapping;
};
@@ -21,7 +30,9 @@ ol.pointer.EventSource = function(dispatcher) {
* List of events supported by this source.
* @return {Array.<string>} Event names
*/
ol.pointer.EventSource.prototype.getEvents = goog.abstractMethod;
ol.pointer.EventSource.prototype.getEvents = function() {
return goog.object.getKeys(this.mapping_);
};
/**
@@ -30,7 +41,9 @@ ol.pointer.EventSource.prototype.getEvents = goog.abstractMethod;
* @return {Object.<string, function(goog.events.BrowserEvent)>}
* Event/Handler mapping
*/
ol.pointer.EventSource.prototype.getMapping = goog.abstractMethod;
ol.pointer.EventSource.prototype.getMapping = function() {
return this.mapping_;
};
/**
@@ -39,5 +52,5 @@ ol.pointer.EventSource.prototype.getMapping = goog.abstractMethod;
* @return {function(goog.events.BrowserEvent)} Handler
*/
ol.pointer.EventSource.prototype.getHandlerForEvent = function(eventType) {
return this.getMapping()[eventType];
return this.mapping_[eventType];
};

View File

@@ -30,7 +30,6 @@
goog.provide('ol.pointer.MouseSource');
goog.require('goog.object');
goog.require('ol.pointer.EventSource');
@@ -41,26 +40,20 @@ goog.require('ol.pointer.EventSource');
* @extends {ol.pointer.EventSource}
*/
ol.pointer.MouseSource = function(dispatcher) {
goog.base(this, dispatcher);
/**
* @const
* @type {goog.structs.Map}
*/
this.pointerMap = dispatcher.pointerMap;
/**
* @private
* @const
* @type {Object.<string, function(goog.events.BrowserEvent)>}
*/
this.mapping_ = {
var mapping = {
'mousedown': this.mousedown,
'mousemove': this.mousemove,
'mouseup': this.mouseup,
'mouseover': this.mouseover,
'mouseout': this.mouseout
};
goog.base(this, dispatcher, mapping);
/**
* @const
* @type {goog.structs.Map}
*/
this.pointerMap = dispatcher.pointerMap;
/**
* @const
@@ -94,18 +87,6 @@ ol.pointer.MouseSource.POINTER_TYPE = 'mouse';
ol.pointer.MouseSource.DEDUP_DIST = 25;
/** @inheritDoc */
ol.pointer.MouseSource.prototype.getEvents = function() {
return goog.object.getKeys(this.mapping_);
};
/** @inheritDoc */
ol.pointer.MouseSource.prototype.getMapping = function() {
return this.mapping_;
};
/**
* Detect if a mouse event was simulated from a touch by
* checking if previously there was a touch event at the

View File

@@ -30,7 +30,6 @@
goog.provide('ol.pointer.MsSource');
goog.require('goog.object');
goog.require('ol.pointer.EventSource');
@@ -41,20 +40,7 @@ goog.require('ol.pointer.EventSource');
* @extends {ol.pointer.EventSource}
*/
ol.pointer.MsSource = function(dispatcher) {
goog.base(this, dispatcher);
/**
* @const
* @type {goog.structs.Map}
*/
this.pointerMap = dispatcher.pointerMap;
/**
* @private
* @const
* @type {Object.<string, function(goog.events.BrowserEvent)>}
*/
this.mapping_ = {
var mapping = {
'MSPointerDown': this.msPointerDown,
'MSPointerMove': this.msPointerMove,
'MSPointerUp': this.msPointerUp,
@@ -64,6 +50,13 @@ ol.pointer.MsSource = function(dispatcher) {
'MSGotPointerCapture': this.msGotPointerCapture,
'MSLostPointerCapture': this.msLostPointerCapture
};
goog.base(this, dispatcher, mapping);
/**
* @const
* @type {goog.structs.Map}
*/
this.pointerMap = dispatcher.pointerMap;
/**
* @const
@@ -80,18 +73,6 @@ ol.pointer.MsSource = function(dispatcher) {
goog.inherits(ol.pointer.MsSource, ol.pointer.EventSource);
/** @inheritDoc */
ol.pointer.MsSource.prototype.getEvents = function() {
return goog.object.getKeys(this.mapping_);
};
/** @inheritDoc */
ol.pointer.MsSource.prototype.getMapping = function() {
return this.mapping_;
};
/**
* Creates a copy of the original event that will be used
* for the fake pointer event.

View File

@@ -41,20 +41,7 @@ goog.require('ol.pointer.EventSource');
* @extends {ol.pointer.EventSource}
*/
ol.pointer.NativeSource = function(dispatcher) {
goog.base(this, dispatcher);
/**
* @const
* @type {goog.structs.Map}
*/
this.pointerMap = dispatcher.pointerMap;
/**
* @private
* @const
* @type {Object.<string, function(goog.events.BrowserEvent)>}
*/
this.mapping_ = {
var mapping = {
'pointerdown': this.pointerDown,
'pointermove': this.pointerMove,
'pointerup': this.pointerUp,
@@ -64,22 +51,18 @@ ol.pointer.NativeSource = function(dispatcher) {
'gotpointercapture': this.gotPointerCapture,
'lostpointercapture': this.lostPointerCapture
};
goog.base(this, dispatcher, mapping);
/**
* @const
* @type {goog.structs.Map}
*/
this.pointerMap = dispatcher.pointerMap;
};
goog.inherits(ol.pointer.NativeSource, ol.pointer.EventSource);
/** @inheritDoc */
ol.pointer.NativeSource.prototype.getEvents = function() {
return goog.object.getKeys(this.mapping_);
};
/** @inheritDoc */
ol.pointer.NativeSource.prototype.getMapping = function() {
return this.mapping_;
};
/**
* Handler for `pointerdown`.
*

View File

@@ -32,7 +32,6 @@ goog.provide('ol.pointer.TouchSource');
goog.require('goog.array');
goog.require('goog.math.Coordinate');
goog.require('goog.object');
goog.require('ol.pointer.EventSource');
@@ -44,7 +43,13 @@ goog.require('ol.pointer.EventSource');
* @extends {ol.pointer.EventSource}
*/
ol.pointer.TouchSource = function(dispatcher, mouseSource) {
goog.base(this, dispatcher);
var mapping = {
'touchstart': this.touchstart,
'touchmove': this.touchmove,
'touchend': this.touchend,
'touchcancel': this.touchcancel
};
goog.base(this, dispatcher, mapping);
/**
* @const
@@ -89,18 +94,6 @@ ol.pointer.TouchSource = function(dispatcher, mouseSource) {
* @type {?number}
*/
this.resetId_ = null;
/**
* @private
* @const
* @type {Object.<string, function(goog.events.BrowserEvent)>}
*/
this.mapping_ = {
'touchstart': this.touchstart,
'touchmove': this.touchmove,
'touchend': this.touchend,
'touchcancel': this.touchcancel
};
};
goog.inherits(ol.pointer.TouchSource, ol.pointer.EventSource);
@@ -112,18 +105,6 @@ goog.inherits(ol.pointer.TouchSource, ol.pointer.EventSource);
ol.pointer.TouchSource.POINTER_TYPE = 'touch';
/** @inheritDoc */
ol.pointer.TouchSource.prototype.getEvents = function() {
return goog.object.getKeys(this.mapping_);
};
/** @inheritDoc */
ol.pointer.TouchSource.prototype.getMapping = function() {
return this.mapping_;
};
/**
* @private
* @param {Touch} inTouch