From 028a183d1193223e70b93edd3fd150f7dc3216b1 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Mon, 10 Mar 2014 12:25:25 +0100 Subject: [PATCH] Pass the mapping object to the ol.pointer.EventSource constructor Conflicts: src/ol/pointer/mssource.js --- src/ol/pointer/eventsource.js | 21 ++++++++++++++++---- src/ol/pointer/mousesource.js | 35 ++++++++-------------------------- src/ol/pointer/mssource.js | 35 ++++++++-------------------------- src/ol/pointer/nativesource.js | 35 +++++++++------------------------- src/ol/pointer/touchsource.js | 33 +++++++------------------------- 5 files changed, 49 insertions(+), 110 deletions(-) diff --git a/src/ol/pointer/eventsource.js b/src/ol/pointer/eventsource.js index c2b69afbae..b26d49b09c 100644 --- a/src/ol/pointer/eventsource.js +++ b/src/ol/pointer/eventsource.js @@ -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.} mapping * @constructor */ -ol.pointer.EventSource = function(dispatcher) { +ol.pointer.EventSource = function(dispatcher, mapping) { /** * @type {ol.pointer.PointerEventHandler} */ this.dispatcher = dispatcher; + + /** + * @private + * @const + * @type {Object.} + */ + this.mapping_ = mapping; }; @@ -21,7 +30,9 @@ ol.pointer.EventSource = function(dispatcher) { * List of events supported by this source. * @return {Array.} 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.} * 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]; }; diff --git a/src/ol/pointer/mousesource.js b/src/ol/pointer/mousesource.js index 33b5c9b5ab..a8a5a2c929 100644 --- a/src/ol/pointer/mousesource.js +++ b/src/ol/pointer/mousesource.js @@ -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.} - */ - 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 diff --git a/src/ol/pointer/mssource.js b/src/ol/pointer/mssource.js index f14b568696..83fea3a0ee 100644 --- a/src/ol/pointer/mssource.js +++ b/src/ol/pointer/mssource.js @@ -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.} - */ - 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. diff --git a/src/ol/pointer/nativesource.js b/src/ol/pointer/nativesource.js index 0bfb8dcb26..783a877004 100644 --- a/src/ol/pointer/nativesource.js +++ b/src/ol/pointer/nativesource.js @@ -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.} - */ - 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`. * diff --git a/src/ol/pointer/touchsource.js b/src/ol/pointer/touchsource.js index 08197ded26..38c4fe5069 100644 --- a/src/ol/pointer/touchsource.js +++ b/src/ol/pointer/touchsource.js @@ -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.} - */ - 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