diff --git a/src/ol/event/Drag.js b/src/ol/event/Drag.js index 82fbab5827..1d806f300c 100644 --- a/src/ol/event/Drag.js +++ b/src/ol/event/Drag.js @@ -1,5 +1,4 @@ goog.provide('ol.event.Drag'); -goog.provide('ol.event.DragEvent'); goog.require('ol.event.ISequence'); goog.require('ol.event.Events'); @@ -52,67 +51,38 @@ ol.event.Drag.prototype.dispatchEvent = function(e) { } else if (e.type === goog.fx.Dragger.EventType.END) { e.type = ol.event.Drag.EventType.DRAGEND; } + e.target = e.browserEvent.target; + e.dx = e.clientX - this.previousX_; + e.dy = e.clientY - this.previousY_; } - this.target_.dispatchEvent(/** @type {Event} */ (e)); + this.target_.triggerEvent(e.type, /** @type {Object} (e.type) */ (e)); return goog.base(this, 'dispatchEvent', e); }; /** @inheritDoc */ ol.event.Drag.prototype.startDrag = function(e) { + goog.base(this, 'startDrag', e); this.previousX_ = e.clientX; this.previousY_ = e.clientY; - goog.base(this, 'startDrag', e); -}; - -/** @inheritDoc */ -ol.event.Drag.prototype.doDrag = function(e, x, y, dragFromScroll) { - e.dx = e.clientX - this.previousX_; - e.dy = e.clientX - this.previousY_; - goog.base(this, 'doDrag', e, x, y, dragFromScroll); }; /** @override */ +ol.event.Drag.prototype.doDrag = function(e, x, y, dragFromScroll) { + goog.base(this, 'doDrag', e, x, y, dragFromScroll); + this.previousX_ = e.clientX; + this.previousY_ = e.clientY; +}; + +/** @inheritDoc */ ol.event.Drag.prototype.defaultAction = function(x, y) {}; /** @inheritDoc */ ol.event.Drag.prototype.destroy = ol.event.Drag.prototype.dispose; + ol.event.addSequenceProvider('drag', ol.event.Drag); -/** - * Object representing a drag event - * - * @param {string} type Event type. - * @param {goog.fx.Dragger} dragobj Drag object initiating event. - * @param {number} clientX X-coordinate relative to the viewport. - * @param {number} clientY Y-coordinate relative to the viewport. - * @param {goog.events.BrowserEvent} browserEvent Object representing the - * browser event that caused this drag event. - * @constructor - * @extends {goog.fx.DragEvent} - */ -ol.event.DragEvent = function(type, dragobj, clientX, clientY, browserEvent) { - - goog.base(this, type, dragobj, clientX, clientY, browserEvent); - - /** - * The move delta in X direction since the previous drag event - * - * @type {number} - */ - this.dx = 0; - - /** - * The move delta in Y direction since the previous drag event - * - * @type {number} - */ - this.dy = 0; -}; -goog.inherits(ol.event.DragEvent, goog.fx.DragEvent); - - /** * @type {Object.} */ diff --git a/src/ol/event/Events.js b/src/ol/event/Events.js index ca65cf4438..666ed0c60f 100644 --- a/src/ol/event/Events.js +++ b/src/ol/event/Events.js @@ -136,7 +136,7 @@ ol.event.Events.prototype.setElement = function(element) { for (t in types) { // register the event cross-browser goog.events.unlisten( - this.element_, types[t], this.dispatchEvent, true, this + this.element_, types[t], this.handleBrowserEvent, true, this ); } this.destroySequences(); @@ -148,7 +148,7 @@ ol.event.Events.prototype.setElement = function(element) { for (t in types) { // register the event cross-browser goog.events.listen( - element, types[t], this.dispatchEvent, true, this + element, types[t], this.handleBrowserEvent, true, this ); } } @@ -243,15 +243,14 @@ ol.event.Events.prototype.triggerEvent = function(type, opt_evt) { }; /** - * Basically just a wrapper to the parent's dispatchEvent() function, but takes - * care to set a property 'xy' on the event with the current mouse position and - * normalize clientX and clientY for multi-touch events. + * Prepares browser events before they are dispatched. This takes care to set a + * property 'xy' on the event with the current pointer position (if + * {@code includeXY} is set to true), and normalizes clientX and clientY for + * multi-touch events. * * @param {Event} evt Event object. - * @return {boolean} If anyone called preventDefault on the event object (or - * if any of the handlers returns false this will also return false. */ -ol.event.Events.prototype.dispatchEvent = function(evt) { +ol.event.Events.prototype.handleBrowserEvent = function(evt) { var type = evt.type, listeners = goog.events.getListeners(this.element_, type, false) .concat(goog.events.getListeners(this.element_, type, true)); @@ -276,7 +275,7 @@ ol.event.Events.prototype.dispatchEvent = function(evt) { evt.xy = goog.style.getRelativePosition(evt, this.element_); } } - return goog.base(this, 'dispatchEvent', evt); + this.triggerEvent(evt.type, evt); }; /** diff --git a/src/ol/event/ISequence.js b/src/ol/event/ISequence.js index 83f6103cfc..0b4cb60c83 100644 --- a/src/ol/event/ISequence.js +++ b/src/ol/event/ISequence.js @@ -4,10 +4,10 @@ goog.provide('ol.event.ISequence'); * Interface for event sequences. Event sequences map sequences of native * browser events to high level events that the sequence provides. * - * Implementations are expected to call dispatchEvent on the {@code target} to - * to fire their high level events. + * Implementations are expected to call {@code triggerEvent} on the + * {@code target} to to fire their high level events. * - * Implementations can expect the {@code target}'s {@code getElement()} method + * Implementations can expect the {@code target}'s {@code getElement} method * to return an {Element} at construction time. * * @interface diff --git a/test/spec/ol/Events.test.js b/test/spec/ol/Events.test.js index eda6930b4e..1275168503 100644 --- a/test/spec/ol/Events.test.js +++ b/test/spec/ol/Events.test.js @@ -71,6 +71,7 @@ describe("ol.event.Events", function() { events.triggerEvent("bar", evt); expect(log[0].scope).toBe(scope); expect(log[0].evt).toBe(evt); + expect(log[0].evt.object).toBe("foo"); }); it("respects event priority", function() {