Cleaned up ol/pointer classes

This commit is contained in:
Tim Schaub
2018-07-17 17:48:27 -06:00
parent d855f5ba0a
commit 069187859d
7 changed files with 460 additions and 453 deletions
+5 -2
View File
@@ -1,13 +1,15 @@
/** /**
* @module ol/pointer/EventSource * @module ol/pointer/EventSource
*/ */
class EventSource {
/** /**
* @param {module:ol/pointer/PointerEventHandler} dispatcher Event handler. * @param {module:ol/pointer/PointerEventHandler} dispatcher Event handler.
* @param {!Object.<string, function(Event)>} mapping Event mapping. * @param {!Object.<string, function(Event)>} mapping Event mapping.
* @constructor
*/ */
class EventSource {
constructor(dispatcher, mapping) { constructor(dispatcher, mapping) {
/** /**
* @type {module:ol/pointer/PointerEventHandler} * @type {module:ol/pointer/PointerEventHandler}
*/ */
@@ -37,6 +39,7 @@ class EventSource {
getHandlerForEvent(eventType) { getHandlerForEvent(eventType) {
return this.mapping_[eventType]; return this.mapping_[eventType];
} }
} }
export default EventSource; export default EventSource;
+85 -83
View File
@@ -1,6 +1,7 @@
/** /**
* @module ol/pointer/MouseSource * @module ol/pointer/MouseSource
*/ */
// Based on https://github.com/Polymer/PointerEvents // Based on https://github.com/Polymer/PointerEvents
// Copyright (c) 2013 The Polymer Authors. All rights reserved. // Copyright (c) 2013 The Polymer Authors. All rights reserved.
@@ -31,7 +32,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import {inherits} from '../util.js';
import EventSource from '../pointer/EventSource.js'; import EventSource from '../pointer/EventSource.js';
@@ -54,22 +54,97 @@ export const POINTER_TYPE = 'mouse';
*/ */
const DEDUP_DIST = 25; const DEDUP_DIST = 25;
/**
* Handler for `mousedown`.
*
* @this {module:ol/pointer/MouseSource}
* @param {MouseEvent} inEvent The in event.
*/
function mousedown(inEvent) {
if (!this.isEventSimulatedFromTouch_(inEvent)) {
// TODO(dfreedman) workaround for some elements not sending mouseup
// http://crbug/149091
if (POINTER_ID.toString() in this.pointerMap) {
this.cancel(inEvent);
}
const e = prepareEvent(inEvent, this.dispatcher);
this.pointerMap[POINTER_ID.toString()] = inEvent;
this.dispatcher.down(e, inEvent);
}
}
/**
* Handler for `mousemove`.
*
* @this {module:ol/pointer/MouseSource}
* @param {MouseEvent} inEvent The in event.
*/
function mousemove(inEvent) {
if (!this.isEventSimulatedFromTouch_(inEvent)) {
const e = prepareEvent(inEvent, this.dispatcher);
this.dispatcher.move(e, inEvent);
}
}
/**
* Handler for `mouseup`.
*
* @this {module:ol/pointer/MouseSource}
* @param {MouseEvent} inEvent The in event.
*/
function mouseup(inEvent) {
if (!this.isEventSimulatedFromTouch_(inEvent)) {
const p = this.pointerMap[POINTER_ID.toString()];
if (p && p.button === inEvent.button) {
const e = prepareEvent(inEvent, this.dispatcher);
this.dispatcher.up(e, inEvent);
this.cleanupMouse();
}
}
}
/**
* Handler for `mouseover`.
*
* @this {module:ol/pointer/MouseSource}
* @param {MouseEvent} inEvent The in event.
*/
function mouseover(inEvent) {
if (!this.isEventSimulatedFromTouch_(inEvent)) {
const e = prepareEvent(inEvent, this.dispatcher);
this.dispatcher.enterOver(e, inEvent);
}
}
/**
* Handler for `mouseout`.
*
* @this {module:ol/pointer/MouseSource}
* @param {MouseEvent} inEvent The in event.
*/
function mouseout(inEvent) {
if (!this.isEventSimulatedFromTouch_(inEvent)) {
const e = prepareEvent(inEvent, this.dispatcher);
this.dispatcher.leaveOut(e, inEvent);
}
}
class MouseSource extends EventSource {
/** /**
* @param {module:ol/pointer/PointerEventHandler} dispatcher Event handler. * @param {module:ol/pointer/PointerEventHandler} dispatcher Event handler.
* @constructor
* @extends {module:ol/pointer/EventSource}
*/ */
class MouseSource {
constructor(dispatcher) { constructor(dispatcher) {
const mapping = { const mapping = {
'mousedown': this.mousedown, 'mousedown': mousedown,
'mousemove': this.mousemove, 'mousemove': mousemove,
'mouseup': this.mouseup, 'mouseup': mouseup,
'mouseover': this.mouseover, 'mouseover': mouseover,
'mouseout': this.mouseout 'mouseout': mouseout
}; };
EventSource.call(this, dispatcher, mapping); super(dispatcher, mapping);
/** /**
* @const * @const
@@ -123,77 +198,6 @@ class MouseSource {
return false; return false;
} }
/**
* Handler for `mousedown`.
*
* @param {MouseEvent} inEvent The in event.
*/
mousedown(inEvent) {
if (!this.isEventSimulatedFromTouch_(inEvent)) {
// TODO(dfreedman) workaround for some elements not sending mouseup
// http://crbug/149091
if (POINTER_ID.toString() in this.pointerMap) {
this.cancel(inEvent);
}
const e = prepareEvent(inEvent, this.dispatcher);
this.pointerMap[POINTER_ID.toString()] = inEvent;
this.dispatcher.down(e, inEvent);
}
}
/**
* Handler for `mousemove`.
*
* @param {MouseEvent} inEvent The in event.
*/
mousemove(inEvent) {
if (!this.isEventSimulatedFromTouch_(inEvent)) {
const e = prepareEvent(inEvent, this.dispatcher);
this.dispatcher.move(e, inEvent);
}
}
/**
* Handler for `mouseup`.
*
* @param {MouseEvent} inEvent The in event.
*/
mouseup(inEvent) {
if (!this.isEventSimulatedFromTouch_(inEvent)) {
const p = this.pointerMap[POINTER_ID.toString()];
if (p && p.button === inEvent.button) {
const e = prepareEvent(inEvent, this.dispatcher);
this.dispatcher.up(e, inEvent);
this.cleanupMouse();
}
}
}
/**
* Handler for `mouseover`.
*
* @param {MouseEvent} inEvent The in event.
*/
mouseover(inEvent) {
if (!this.isEventSimulatedFromTouch_(inEvent)) {
const e = prepareEvent(inEvent, this.dispatcher);
this.dispatcher.enterOver(e, inEvent);
}
}
/**
* Handler for `mouseout`.
*
* @param {MouseEvent} inEvent The in event.
*/
mouseout(inEvent) {
if (!this.isEventSimulatedFromTouch_(inEvent)) {
const e = prepareEvent(inEvent, this.dispatcher);
this.dispatcher.leaveOut(e, inEvent);
}
}
/** /**
* Dispatches a `pointercancel` event. * Dispatches a `pointercancel` event.
* *
@@ -213,8 +217,6 @@ class MouseSource {
} }
} }
inherits(MouseSource, EventSource);
/** /**
* Creates a copy of the original event that will be used * Creates a copy of the original event that will be used
+101 -97
View File
@@ -31,7 +31,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import {inherits} from '../util.js';
import EventSource from '../pointer/EventSource.js'; import EventSource from '../pointer/EventSource.js';
@@ -47,25 +46,114 @@ const POINTER_TYPES = [
'mouse' 'mouse'
]; ];
/**
* Handler for `msPointerDown`.
*
* @this {module:ol/pointer/MsSource}
* @param {MSPointerEvent} inEvent The in event.
*/
function msPointerDown(inEvent) {
this.pointerMap[inEvent.pointerId.toString()] = inEvent;
const e = this.prepareEvent_(inEvent);
this.dispatcher.down(e, inEvent);
}
/**
* Handler for `msPointerMove`.
*
* @this {module:ol/pointer/MsSource}
* @param {MSPointerEvent} inEvent The in event.
*/
function msPointerMove(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.move(e, inEvent);
}
/**
* Handler for `msPointerUp`.
*
* @this {module:ol/pointer/MsSource}
* @param {MSPointerEvent} inEvent The in event.
*/
function msPointerUp(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.up(e, inEvent);
this.cleanup(inEvent.pointerId);
}
/**
* Handler for `msPointerOut`.
*
* @this {module:ol/pointer/MsSource}
* @param {MSPointerEvent} inEvent The in event.
*/
function msPointerOut(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.leaveOut(e, inEvent);
}
/**
* Handler for `msPointerOver`.
*
* @this {module:ol/pointer/MsSource}
* @param {MSPointerEvent} inEvent The in event.
*/
function msPointerOver(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.enterOver(e, inEvent);
}
/**
* Handler for `msPointerCancel`.
*
* @this {module:ol/pointer/MsSource}
* @param {MSPointerEvent} inEvent The in event.
*/
function msPointerCancel(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.cancel(e, inEvent);
this.cleanup(inEvent.pointerId);
}
/**
* Handler for `msLostPointerCapture`.
*
* @this {module:ol/pointer/MsSource}
* @param {MSPointerEvent} inEvent The in event.
*/
function msLostPointerCapture(inEvent) {
const e = this.dispatcher.makeEvent('lostpointercapture', inEvent, inEvent);
this.dispatcher.dispatchEvent(e);
}
/**
* Handler for `msGotPointerCapture`.
*
* @this {module:ol/pointer/MsSource}
* @param {MSPointerEvent} inEvent The in event.
*/
function msGotPointerCapture(inEvent) {
const e = this.dispatcher.makeEvent('gotpointercapture', inEvent, inEvent);
this.dispatcher.dispatchEvent(e);
}
class MsSource extends EventSource {
/** /**
* @param {module:ol/pointer/PointerEventHandler} dispatcher Event handler. * @param {module:ol/pointer/PointerEventHandler} dispatcher Event handler.
* @constructor
* @extends {module:ol/pointer/EventSource}
*/ */
class MsSource {
constructor(dispatcher) { constructor(dispatcher) {
const mapping = { const mapping = {
'MSPointerDown': this.msPointerDown, 'MSPointerDown': msPointerDown,
'MSPointerMove': this.msPointerMove, 'MSPointerMove': msPointerMove,
'MSPointerUp': this.msPointerUp, 'MSPointerUp': msPointerUp,
'MSPointerOut': this.msPointerOut, 'MSPointerOut': msPointerOut,
'MSPointerOver': this.msPointerOver, 'MSPointerOver': msPointerOver,
'MSPointerCancel': this.msPointerCancel, 'MSPointerCancel': msPointerCancel,
'MSGotPointerCapture': this.msGotPointerCapture, 'MSGotPointerCapture': msGotPointerCapture,
'MSLostPointerCapture': this.msLostPointerCapture 'MSLostPointerCapture': msLostPointerCapture
}; };
EventSource.call(this, dispatcher, mapping); super(dispatcher, mapping);
/** /**
* @const * @const
@@ -100,90 +188,6 @@ class MsSource {
delete this.pointerMap[pointerId.toString()]; delete this.pointerMap[pointerId.toString()];
} }
/**
* Handler for `msPointerDown`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerDown(inEvent) {
this.pointerMap[inEvent.pointerId.toString()] = inEvent;
const e = this.prepareEvent_(inEvent);
this.dispatcher.down(e, inEvent);
} }
/**
* Handler for `msPointerMove`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerMove(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.move(e, inEvent);
}
/**
* Handler for `msPointerUp`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerUp(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.up(e, inEvent);
this.cleanup(inEvent.pointerId);
}
/**
* Handler for `msPointerOut`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerOut(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.leaveOut(e, inEvent);
}
/**
* Handler for `msPointerOver`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerOver(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.enterOver(e, inEvent);
}
/**
* Handler for `msPointerCancel`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msPointerCancel(inEvent) {
const e = this.prepareEvent_(inEvent);
this.dispatcher.cancel(e, inEvent);
this.cleanup(inEvent.pointerId);
}
/**
* Handler for `msLostPointerCapture`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msLostPointerCapture(inEvent) {
const e = this.dispatcher.makeEvent('lostpointercapture', inEvent, inEvent);
this.dispatcher.dispatchEvent(e);
}
/**
* Handler for `msGotPointerCapture`.
*
* @param {MSPointerEvent} inEvent The in event.
*/
msGotPointerCapture(inEvent) {
const e = this.dispatcher.makeEvent('gotpointercapture', inEvent, inEvent);
this.dispatcher.dispatchEvent(e);
}
}
inherits(MsSource, EventSource);
export default MsSource; export default MsSource;
+36 -31
View File
@@ -1,6 +1,7 @@
/** /**
* @module ol/pointer/NativeSource * @module ol/pointer/NativeSource
*/ */
// Based on https://github.com/Polymer/PointerEvents // Based on https://github.com/Polymer/PointerEvents
// Copyright (c) 2013 The Polymer Authors. All rights reserved. // Copyright (c) 2013 The Polymer Authors. All rights reserved.
@@ -31,103 +32,107 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import {inherits} from '../util.js';
import EventSource from '../pointer/EventSource.js'; import EventSource from '../pointer/EventSource.js';
/**
* @param {module:ol/pointer/PointerEventHandler} dispatcher Event handler.
* @constructor
* @extends {module:ol/pointer/EventSource}
*/
class NativeSource {
constructor(dispatcher) {
const mapping = {
'pointerdown': this.pointerDown,
'pointermove': this.pointerMove,
'pointerup': this.pointerUp,
'pointerout': this.pointerOut,
'pointerover': this.pointerOver,
'pointercancel': this.pointerCancel,
'gotpointercapture': this.gotPointerCapture,
'lostpointercapture': this.lostPointerCapture
};
EventSource.call(this, dispatcher, mapping);
}
/** /**
* Handler for `pointerdown`. * Handler for `pointerdown`.
* *
* @this {module:ol/pointer/NativeSource}
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
pointerDown(inEvent) { function pointerDown(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
/** /**
* Handler for `pointermove`. * Handler for `pointermove`.
* *
* @this {module:ol/pointer/NativeSource}
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
pointerMove(inEvent) { function pointerMove(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
/** /**
* Handler for `pointerup`. * Handler for `pointerup`.
* *
* @this {module:ol/pointer/NativeSource}
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
pointerUp(inEvent) { function pointerUp(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
/** /**
* Handler for `pointerout`. * Handler for `pointerout`.
* *
* @this {module:ol/pointer/NativeSource}
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
pointerOut(inEvent) { function pointerOut(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
/** /**
* Handler for `pointerover`. * Handler for `pointerover`.
* *
* @this {module:ol/pointer/NativeSource}
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
pointerOver(inEvent) { function pointerOver(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
/** /**
* Handler for `pointercancel`. * Handler for `pointercancel`.
* *
* @this {module:ol/pointer/NativeSource}
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
pointerCancel(inEvent) { function pointerCancel(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
/** /**
* Handler for `lostpointercapture`. * Handler for `lostpointercapture`.
* *
* @this {module:ol/pointer/NativeSource}
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
lostPointerCapture(inEvent) { function lostPointerCapture(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
/** /**
* Handler for `gotpointercapture`. * Handler for `gotpointercapture`.
* *
* @this {module:ol/pointer/NativeSource}
* @param {Event} inEvent The in event. * @param {Event} inEvent The in event.
*/ */
gotPointerCapture(inEvent) { function gotPointerCapture(inEvent) {
this.dispatcher.fireNativeEvent(inEvent); this.dispatcher.fireNativeEvent(inEvent);
} }
class NativeSource extends EventSource {
/**
* @param {module:ol/pointer/PointerEventHandler} dispatcher Event handler.
*/
constructor(dispatcher) {
const mapping = {
'pointerdown': pointerDown,
'pointermove': pointerMove,
'pointerup': pointerUp,
'pointerout': pointerOut,
'pointerover': pointerOver,
'pointercancel': pointerCancel,
'gotpointercapture': gotPointerCapture,
'lostpointercapture': lostPointerCapture
};
super(dispatcher, mapping);
} }
inherits(NativeSource, EventSource); }
export default NativeSource; export default NativeSource;
+4 -7
View File
@@ -1,6 +1,7 @@
/** /**
* @module ol/pointer/PointerEvent * @module ol/pointer/PointerEvent
*/ */
// Based on https://github.com/Polymer/PointerEvents // Based on https://github.com/Polymer/PointerEvents
// Copyright (c) 2013 The Polymer Authors. All rights reserved. // Copyright (c) 2013 The Polymer Authors. All rights reserved.
@@ -31,7 +32,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import {inherits} from '../util.js';
import Event from '../events/Event.js'; import Event from '../events/Event.js';
@@ -42,22 +42,21 @@ import Event from '../events/Event.js';
let HAS_BUTTONS = false; let HAS_BUTTONS = false;
class PointerEvent extends Event {
/** /**
* A class for pointer events. * A class for pointer events.
* *
* This class is used as an abstraction for mouse events, * This class is used as an abstraction for mouse events,
* touch events and even native pointer events. * touch events and even native pointer events.
* *
* @constructor
* @extends {module:ol/events/Event}
* @param {string} type The type of the event to create. * @param {string} type The type of the event to create.
* @param {Event} originalEvent The event. * @param {Event} originalEvent The event.
* @param {Object.<string, ?>=} opt_eventDict An optional dictionary of * @param {Object.<string, ?>=} opt_eventDict An optional dictionary of
* initial event properties. * initial event properties.
*/ */
class PointerEvent {
constructor(type, originalEvent, opt_eventDict) { constructor(type, originalEvent, opt_eventDict) {
Event.call(this, type); super(type);
/** /**
* @const * @const
@@ -261,8 +260,6 @@ class PointerEvent {
} }
} }
inherits(PointerEvent, Event);
/** /**
* Checks if the `buttons` property is supported. * Checks if the `buttons` property is supported.
+4 -7
View File
@@ -1,6 +1,7 @@
/** /**
* @module ol/pointer/PointerEventHandler * @module ol/pointer/PointerEventHandler
*/ */
// Based on https://github.com/Polymer/PointerEvents // Based on https://github.com/Polymer/PointerEvents
// Copyright (c) 2013 The Polymer Authors. All rights reserved. // Copyright (c) 2013 The Polymer Authors. All rights reserved.
@@ -31,7 +32,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import {inherits} from '../util.js';
import {listen, unlisten} from '../events.js'; import {listen, unlisten} from '../events.js';
import EventTarget from '../events/EventTarget.js'; import EventTarget from '../events/EventTarget.js';
import {POINTER, MSPOINTER, TOUCH} from '../has.js'; import {POINTER, MSPOINTER, TOUCH} from '../has.js';
@@ -83,14 +83,13 @@ const CLONE_PROPS = [
]; ];
class PointerEventHandler extends EventTarget {
/** /**
* @constructor
* @extends {module:ol/events/EventTarget}
* @param {Element|HTMLDocument} element Viewport element. * @param {Element|HTMLDocument} element Viewport element.
*/ */
class PointerEventHandler {
constructor(element) { constructor(element) {
EventTarget.call(this); super();
/** /**
* @const * @const
@@ -416,6 +415,4 @@ class PointerEventHandler {
} }
} }
inherits(PointerEventHandler, EventTarget);
export default PointerEventHandler; export default PointerEventHandler;
+57 -58
View File
@@ -1,6 +1,7 @@
/** /**
* @module ol/pointer/TouchSource * @module ol/pointer/TouchSource
*/ */
// Based on https://github.com/Polymer/PointerEvents // Based on https://github.com/Polymer/PointerEvents
// Copyright (c) 2013 The Polymer Authors. All rights reserved. // Copyright (c) 2013 The Polymer Authors. All rights reserved.
@@ -31,7 +32,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import {inherits} from '../util.js';
import {remove} from '../array.js'; import {remove} from '../array.js';
import EventSource from '../pointer/EventSource.js'; import EventSource from '../pointer/EventSource.js';
import {POINTER_ID} from '../pointer/MouseSource.js'; import {POINTER_ID} from '../pointer/MouseSource.js';
@@ -42,28 +42,75 @@ import {POINTER_ID} from '../pointer/MouseSource.js';
*/ */
const CLICK_COUNT_TIMEOUT = 200; const CLICK_COUNT_TIMEOUT = 200;
/** /**
* @type {string} * @type {string}
*/ */
const POINTER_TYPE = 'touch'; const POINTER_TYPE = 'touch';
/**
* Handler for `touchstart`, triggers `pointerover`,
* `pointerenter` and `pointerdown` events.
*
* @this {module:ol/pointer/TouchSource}
* @param {TouchEvent} inEvent The in event.
*/
function touchstart(inEvent) {
this.vacuumTouches_(inEvent);
this.setPrimaryTouch_(inEvent.changedTouches[0]);
this.dedupSynthMouse_(inEvent);
this.clickCount_++;
this.processTouches_(inEvent, this.overDown_);
}
/**
* Handler for `touchmove`.
*
* @this {module:ol/pointer/TouchSource}
* @param {TouchEvent} inEvent The in event.
*/
function touchmove(inEvent) {
inEvent.preventDefault();
this.processTouches_(inEvent, this.moveOverOut_);
}
/**
* Handler for `touchend`, triggers `pointerup`,
* `pointerout` and `pointerleave` events.
*
* @this {module:ol/pointer/TouchSource}
* @param {TouchEvent} inEvent The event.
*/
function touchend(inEvent) {
this.dedupSynthMouse_(inEvent);
this.processTouches_(inEvent, this.upOut_);
}
/**
* Handler for `touchcancel`, triggers `pointercancel`,
* `pointerout` and `pointerleave` events.
*
* @this {module:ol/pointer/TouchSource}
* @param {TouchEvent} inEvent The in event.
*/
function touchcancel(inEvent) {
this.processTouches_(inEvent, this.cancelOut_);
}
class TouchSource extends EventSource {
/** /**
* @constructor
* @param {module:ol/pointer/PointerEventHandler} dispatcher The event handler. * @param {module:ol/pointer/PointerEventHandler} dispatcher The event handler.
* @param {module:ol/pointer/MouseSource} mouseSource Mouse source. * @param {module:ol/pointer/MouseSource} mouseSource Mouse source.
* @extends {module:ol/pointer/EventSource}
*/ */
class TouchSource {
constructor(dispatcher, mouseSource) { constructor(dispatcher, mouseSource) {
const mapping = { const mapping = {
'touchstart': this.touchstart, 'touchstart': touchstart,
'touchmove': this.touchmove, 'touchmove': touchmove,
'touchend': this.touchend, 'touchend': touchend,
'touchcancel': this.touchcancel 'touchcancel': touchcancel
}; };
EventSource.call(this, dispatcher, mapping); super(dispatcher, mapping);
/** /**
* @const * @const
@@ -269,20 +316,6 @@ class TouchSource {
} }
} }
/**
* Handler for `touchstart`, triggers `pointerover`,
* `pointerenter` and `pointerdown` events.
*
* @param {TouchEvent} inEvent The in event.
*/
touchstart(inEvent) {
this.vacuumTouches_(inEvent);
this.setPrimaryTouch_(inEvent.changedTouches[0]);
this.dedupSynthMouse_(inEvent);
this.clickCount_++;
this.processTouches_(inEvent, this.overDown_);
}
/** /**
* @private * @private
* @param {TouchEvent} browserEvent The event. * @param {TouchEvent} browserEvent The event.
@@ -299,16 +332,6 @@ class TouchSource {
this.dispatcher.down(inPointer, browserEvent); this.dispatcher.down(inPointer, browserEvent);
} }
/**
* Handler for `touchmove`.
*
* @param {TouchEvent} inEvent The in event.
*/
touchmove(inEvent) {
inEvent.preventDefault();
this.processTouches_(inEvent, this.moveOverOut_);
}
/** /**
* @private * @private
* @param {TouchEvent} browserEvent The event. * @param {TouchEvent} browserEvent The event.
@@ -343,17 +366,6 @@ class TouchSource {
pointer.outTarget = event.target; pointer.outTarget = event.target;
} }
/**
* Handler for `touchend`, triggers `pointerup`,
* `pointerout` and `pointerleave` events.
*
* @param {TouchEvent} inEvent The event.
*/
touchend(inEvent) {
this.dedupSynthMouse_(inEvent);
this.processTouches_(inEvent, this.upOut_);
}
/** /**
* @private * @private
* @param {TouchEvent} browserEvent An event. * @param {TouchEvent} browserEvent An event.
@@ -366,16 +378,6 @@ class TouchSource {
this.cleanUpPointer_(inPointer); this.cleanUpPointer_(inPointer);
} }
/**
* Handler for `touchcancel`, triggers `pointercancel`,
* `pointerout` and `pointerleave` events.
*
* @param {TouchEvent} inEvent The in event.
*/
touchcancel(inEvent) {
this.processTouches_(inEvent, this.cancelOut_);
}
/** /**
* @private * @private
* @param {TouchEvent} browserEvent The event. * @param {TouchEvent} browserEvent The event.
@@ -420,7 +422,4 @@ class TouchSource {
} }
} }
inherits(TouchSource, EventSource);
export default TouchSource; export default TouchSource;