Rename _ol_pointer_MouseSource_ to MouseSource

This commit is contained in:
Frederic Junod
2018-01-17 11:57:39 +01:00
parent d97151b825
commit 107362b9fb
4 changed files with 37 additions and 37 deletions

View File

@@ -39,7 +39,7 @@ import EventSource from '../pointer/EventSource.js';
* @constructor * @constructor
* @extends {ol.pointer.EventSource} * @extends {ol.pointer.EventSource}
*/ */
const _ol_pointer_MouseSource_ = function(dispatcher) { const MouseSource = function(dispatcher) {
const mapping = { const mapping = {
'mousedown': this.mousedown, 'mousedown': this.mousedown,
'mousemove': this.mousemove, 'mousemove': this.mousemove,
@@ -62,21 +62,21 @@ const _ol_pointer_MouseSource_ = function(dispatcher) {
this.lastTouches = []; this.lastTouches = [];
}; };
inherits(_ol_pointer_MouseSource_, EventSource); inherits(MouseSource, EventSource);
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
_ol_pointer_MouseSource_.POINTER_ID = 1; MouseSource.POINTER_ID = 1;
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
_ol_pointer_MouseSource_.POINTER_TYPE = 'mouse'; MouseSource.POINTER_TYPE = 'mouse';
/** /**
@@ -85,7 +85,7 @@ _ol_pointer_MouseSource_.POINTER_TYPE = 'mouse';
* @const * @const
* @type {number} * @type {number}
*/ */
_ol_pointer_MouseSource_.DEDUP_DIST = 25; MouseSource.DEDUP_DIST = 25;
/** /**
@@ -112,7 +112,7 @@ _ol_pointer_MouseSource_.DEDUP_DIST = 25;
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
* @return {boolean} True, if the event was generated by a touch. * @return {boolean} True, if the event was generated by a touch.
*/ */
_ol_pointer_MouseSource_.prototype.isEventSimulatedFromTouch_ = function(inEvent) { MouseSource.prototype.isEventSimulatedFromTouch_ = function(inEvent) {
const lts = this.lastTouches; const lts = this.lastTouches;
const x = inEvent.clientX; const x = inEvent.clientX;
const y = inEvent.clientY; const y = inEvent.clientY;
@@ -120,8 +120,8 @@ _ol_pointer_MouseSource_.prototype.isEventSimulatedFromTouch_ = function(inEvent
// simulated mouse events will be swallowed near a primary touchend // simulated mouse events will be swallowed near a primary touchend
const dx = Math.abs(x - t[0]); const dx = Math.abs(x - t[0]);
const dy = Math.abs(y - t[1]); const dy = Math.abs(y - t[1]);
if (dx <= _ol_pointer_MouseSource_.DEDUP_DIST && if (dx <= MouseSource.DEDUP_DIST &&
dy <= _ol_pointer_MouseSource_.DEDUP_DIST) { dy <= MouseSource.DEDUP_DIST) {
return true; return true;
} }
} }
@@ -137,7 +137,7 @@ _ol_pointer_MouseSource_.prototype.isEventSimulatedFromTouch_ = function(inEvent
* @param {ol.pointer.PointerEventHandler} dispatcher Event handler. * @param {ol.pointer.PointerEventHandler} dispatcher Event handler.
* @return {Object} The copied event. * @return {Object} The copied event.
*/ */
_ol_pointer_MouseSource_.prepareEvent = function(inEvent, dispatcher) { MouseSource.prepareEvent = function(inEvent, dispatcher) {
const e = dispatcher.cloneEvent(inEvent, inEvent); const e = dispatcher.cloneEvent(inEvent, inEvent);
// forward mouse preventDefault // forward mouse preventDefault
@@ -147,9 +147,9 @@ _ol_pointer_MouseSource_.prepareEvent = function(inEvent, dispatcher) {
pd(); pd();
}; };
e.pointerId = _ol_pointer_MouseSource_.POINTER_ID; e.pointerId = MouseSource.POINTER_ID;
e.isPrimary = true; e.isPrimary = true;
e.pointerType = _ol_pointer_MouseSource_.POINTER_TYPE; e.pointerType = MouseSource.POINTER_TYPE;
return e; return e;
}; };
@@ -160,15 +160,15 @@ _ol_pointer_MouseSource_.prepareEvent = function(inEvent, dispatcher) {
* *
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
_ol_pointer_MouseSource_.prototype.mousedown = function(inEvent) { MouseSource.prototype.mousedown = function(inEvent) {
if (!this.isEventSimulatedFromTouch_(inEvent)) { if (!this.isEventSimulatedFromTouch_(inEvent)) {
// TODO(dfreedman) workaround for some elements not sending mouseup // TODO(dfreedman) workaround for some elements not sending mouseup
// http://crbug/149091 // http://crbug/149091
if (_ol_pointer_MouseSource_.POINTER_ID.toString() in this.pointerMap) { if (MouseSource.POINTER_ID.toString() in this.pointerMap) {
this.cancel(inEvent); this.cancel(inEvent);
} }
const e = _ol_pointer_MouseSource_.prepareEvent(inEvent, this.dispatcher); const e = MouseSource.prepareEvent(inEvent, this.dispatcher);
this.pointerMap[_ol_pointer_MouseSource_.POINTER_ID.toString()] = inEvent; this.pointerMap[MouseSource.POINTER_ID.toString()] = inEvent;
this.dispatcher.down(e, inEvent); this.dispatcher.down(e, inEvent);
} }
}; };
@@ -179,9 +179,9 @@ _ol_pointer_MouseSource_.prototype.mousedown = function(inEvent) {
* *
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
_ol_pointer_MouseSource_.prototype.mousemove = function(inEvent) { MouseSource.prototype.mousemove = function(inEvent) {
if (!this.isEventSimulatedFromTouch_(inEvent)) { if (!this.isEventSimulatedFromTouch_(inEvent)) {
const e = _ol_pointer_MouseSource_.prepareEvent(inEvent, this.dispatcher); const e = MouseSource.prepareEvent(inEvent, this.dispatcher);
this.dispatcher.move(e, inEvent); this.dispatcher.move(e, inEvent);
} }
}; };
@@ -192,12 +192,12 @@ _ol_pointer_MouseSource_.prototype.mousemove = function(inEvent) {
* *
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
_ol_pointer_MouseSource_.prototype.mouseup = function(inEvent) { MouseSource.prototype.mouseup = function(inEvent) {
if (!this.isEventSimulatedFromTouch_(inEvent)) { if (!this.isEventSimulatedFromTouch_(inEvent)) {
const p = this.pointerMap[_ol_pointer_MouseSource_.POINTER_ID.toString()]; const p = this.pointerMap[MouseSource.POINTER_ID.toString()];
if (p && p.button === inEvent.button) { if (p && p.button === inEvent.button) {
const e = _ol_pointer_MouseSource_.prepareEvent(inEvent, this.dispatcher); const e = MouseSource.prepareEvent(inEvent, this.dispatcher);
this.dispatcher.up(e, inEvent); this.dispatcher.up(e, inEvent);
this.cleanupMouse(); this.cleanupMouse();
} }
@@ -210,9 +210,9 @@ _ol_pointer_MouseSource_.prototype.mouseup = function(inEvent) {
* *
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
_ol_pointer_MouseSource_.prototype.mouseover = function(inEvent) { MouseSource.prototype.mouseover = function(inEvent) {
if (!this.isEventSimulatedFromTouch_(inEvent)) { if (!this.isEventSimulatedFromTouch_(inEvent)) {
const e = _ol_pointer_MouseSource_.prepareEvent(inEvent, this.dispatcher); const e = MouseSource.prepareEvent(inEvent, this.dispatcher);
this.dispatcher.enterOver(e, inEvent); this.dispatcher.enterOver(e, inEvent);
} }
}; };
@@ -223,9 +223,9 @@ _ol_pointer_MouseSource_.prototype.mouseover = function(inEvent) {
* *
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
_ol_pointer_MouseSource_.prototype.mouseout = function(inEvent) { MouseSource.prototype.mouseout = function(inEvent) {
if (!this.isEventSimulatedFromTouch_(inEvent)) { if (!this.isEventSimulatedFromTouch_(inEvent)) {
const e = _ol_pointer_MouseSource_.prepareEvent(inEvent, this.dispatcher); const e = MouseSource.prepareEvent(inEvent, this.dispatcher);
this.dispatcher.leaveOut(e, inEvent); this.dispatcher.leaveOut(e, inEvent);
} }
}; };
@@ -236,8 +236,8 @@ _ol_pointer_MouseSource_.prototype.mouseout = function(inEvent) {
* *
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
_ol_pointer_MouseSource_.prototype.cancel = function(inEvent) { MouseSource.prototype.cancel = function(inEvent) {
const e = _ol_pointer_MouseSource_.prepareEvent(inEvent, this.dispatcher); const e = MouseSource.prepareEvent(inEvent, this.dispatcher);
this.dispatcher.cancel(e, inEvent); this.dispatcher.cancel(e, inEvent);
this.cleanupMouse(); this.cleanupMouse();
}; };
@@ -246,7 +246,7 @@ _ol_pointer_MouseSource_.prototype.cancel = function(inEvent) {
/** /**
* Remove the mouse from the list of active pointers. * Remove the mouse from the list of active pointers.
*/ */
_ol_pointer_MouseSource_.prototype.cleanupMouse = function() { MouseSource.prototype.cleanupMouse = function() {
delete this.pointerMap[_ol_pointer_MouseSource_.POINTER_ID.toString()]; delete this.pointerMap[MouseSource.POINTER_ID.toString()];
}; };
export default _ol_pointer_MouseSource_; export default MouseSource;

View File

@@ -36,7 +36,7 @@ import _ol_events_ from '../events.js';
import EventTarget from '../events/EventTarget.js'; import EventTarget from '../events/EventTarget.js';
import _ol_has_ from '../has.js'; import _ol_has_ from '../has.js';
import PointerEventType from '../pointer/EventType.js'; import PointerEventType from '../pointer/EventType.js';
import _ol_pointer_MouseSource_ from '../pointer/MouseSource.js'; import MouseSource from '../pointer/MouseSource.js';
import _ol_pointer_MsSource_ from '../pointer/MsSource.js'; import _ol_pointer_MsSource_ from '../pointer/MsSource.js';
import _ol_pointer_NativeSource_ from '../pointer/NativeSource.js'; import _ol_pointer_NativeSource_ from '../pointer/NativeSource.js';
import PointerEvent from '../pointer/PointerEvent.js'; import PointerEvent from '../pointer/PointerEvent.js';
@@ -91,7 +91,7 @@ PointerEventHandler.prototype.registerSources = function() {
} else if (_ol_has_.MSPOINTER) { } else if (_ol_has_.MSPOINTER) {
this.registerSource('ms', new _ol_pointer_MsSource_(this)); this.registerSource('ms', new _ol_pointer_MsSource_(this));
} else { } else {
const mouseSource = new _ol_pointer_MouseSource_(this); const mouseSource = new MouseSource(this);
this.registerSource('mouse', mouseSource); this.registerSource('mouse', mouseSource);
if (_ol_has_.TOUCH) { if (_ol_has_.TOUCH) {
@@ -389,7 +389,7 @@ PointerEventHandler.prototype.fireNativeEvent = function(event) {
*/ */
PointerEventHandler.prototype.wrapMouseEvent = function(eventType, event) { PointerEventHandler.prototype.wrapMouseEvent = function(eventType, event) {
const pointerEvent = this.makeEvent( const pointerEvent = this.makeEvent(
eventType, _ol_pointer_MouseSource_.prepareEvent(event, this), event); eventType, MouseSource.prepareEvent(event, this), event);
return pointerEvent; return pointerEvent;
}; };

View File

@@ -34,7 +34,7 @@
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import {remove} from '../array.js'; import {remove} from '../array.js';
import EventSource from '../pointer/EventSource.js'; import EventSource from '../pointer/EventSource.js';
import _ol_pointer_MouseSource_ from '../pointer/MouseSource.js'; import MouseSource from '../pointer/MouseSource.js';
/** /**
* @constructor * @constructor
@@ -126,7 +126,7 @@ _ol_pointer_TouchSource_.prototype.isPrimaryTouch_ = function(inTouch) {
_ol_pointer_TouchSource_.prototype.setPrimaryTouch_ = function(inTouch) { _ol_pointer_TouchSource_.prototype.setPrimaryTouch_ = function(inTouch) {
const count = Object.keys(this.pointerMap).length; const count = Object.keys(this.pointerMap).length;
if (count === 0 || (count === 1 && if (count === 0 || (count === 1 &&
_ol_pointer_MouseSource_.POINTER_ID.toString() in this.pointerMap)) { MouseSource.POINTER_ID.toString() in this.pointerMap)) {
this.firstTouchId_ = inTouch.identifier; this.firstTouchId_ = inTouch.identifier;
this.cancelResetClickCount_(); this.cancelResetClickCount_();
} }
@@ -277,7 +277,7 @@ _ol_pointer_TouchSource_.prototype.vacuumTouches_ = function(inEvent) {
// Never remove pointerId == 1, which is mouse. // Never remove pointerId == 1, which is mouse.
// Touch identifiers are 2 smaller than their pointerId, which is the // Touch identifiers are 2 smaller than their pointerId, which is the
// index in pointermap. // index in pointermap.
if (key != _ol_pointer_MouseSource_.POINTER_ID && if (key != MouseSource.POINTER_ID &&
!this.findTouch_(touchList, key - 2)) { !this.findTouch_(touchList, key - 2)) {
d.push(value.out); d.push(value.out);
} }

View File

@@ -1,7 +1,7 @@
import _ol_events_ from '../../../../src/ol/events.js'; import _ol_events_ from '../../../../src/ol/events.js';
import EventTarget from '../../../../src/ol/events/EventTarget.js'; import EventTarget from '../../../../src/ol/events/EventTarget.js';
import _ol_has_ from '../../../../src/ol/has.js'; import _ol_has_ from '../../../../src/ol/has.js';
import _ol_pointer_MouseSource_ from '../../../../src/ol/pointer/MouseSource.js'; import MouseSource from '../../../../src/ol/pointer/MouseSource.js';
import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js'; import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js';
import PointerEventHandler from '../../../../src/ol/pointer/PointerEventHandler.js'; import PointerEventHandler from '../../../../src/ol/pointer/PointerEventHandler.js';
@@ -30,7 +30,7 @@ describe('ol.pointer.PointerEventHandler', function() {
describe('constructor', function() { describe('constructor', function() {
it('registers a least one event source', function() { it('registers a least one event source', function() {
expect(handler.eventSourceList_.length).to.be.greaterThan(0); expect(handler.eventSourceList_.length).to.be.greaterThan(0);
expect(handler.eventSourceList_[0]).to.be.a(_ol_pointer_MouseSource_); expect(handler.eventSourceList_[0]).to.be.a(MouseSource);
}); });
}); });