Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1901: stopPropagation doesn't work for gesturemovestart when minTim... #1902

Open
wants to merge 1 commit into
base: dev-master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/event-gestures/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Gestures Change History
@VERSION@
------

* No changes.
* [#1901][]: stopPropagation doesn't work for gesturemovestart when minTime or minDistance is set (@mairatma)

3.17.2
------
Expand Down
36 changes: 36 additions & 0 deletions src/event-gestures/js/Move.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,54 @@ define(GESTURE_MOVE_START, {
}
},

/**
* Checks if the given event should be fired or not.
*
* @method _shouldFireEvent
* @param {EventFacade}
* @protected
*/
_shouldFireEvent: function(e) {
if (e._event.stopped === 2) {
// Don't fire the event if it has been completely stopped.
return false;
}

if (e._event.stopped === 1 &&
!e.currentTarget.compareTo(e._event.stoppedTarget)) {

// Don't fire the event if it has been propagated when propagation
// should have been stopped.
return false;
}

return true;
},

_start : function(e, node, ce, params) {

if (params) {
this._cancel(params);
}

if (!this._shouldFireEvent(e)) {
return;
}

e.type = GESTURE_MOVE_START;

Y.log("gesturemovestart: Firing start: " + new Date().getTime(), "event-gestures");

node.setData(_MOVE_START, e);
ce.fire(e);

if (e.stopped) {
// If the event was stopped, add a flag to the event that triggered it,
// so we can prevent any subsequent events related to it from firing
// as well.
e._event.stopped = e.stopped;
e._event.stoppedTarget = e.currentTarget;
}
},

MIN_TIME : 0,
Expand Down
86 changes: 83 additions & 3 deletions src/event-gestures/tests/unit/assets/gesture-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ YUI.add('gesture-tests', function(Y) {
screenX: 100,
screenY: 100
}
]
],
_event: {}
},

eventNoTouch = {
target: node,
currentTarget: node
currentTarget: node,
_event: {}
},
suite = new Y.Test.Suite('Gesture Event Suite');

Expand Down Expand Up @@ -87,6 +89,84 @@ YUI.add('gesture-tests', function(Y) {
Assert.areEqual(1, e.button, 'e.button is not set');
}
});
},

'test: stopPropagation should work as expected': function() {
var currentEvent,
mock = new Y.Mock(),
node1 = Y.Node.create('<div />'),
node2 = Y.Node.create('<div />');

node2.append(node1);
currentEvent = {
currentTarget: node1,
touches: event.touches,
target: node1,
_event: {}
};

eventData.start._start(currentEvent, node1, {
fire: function(e) {
Assert.areSame('gesturemovestart', e.type, 'Event type not correct');
e.stopped = 1;
}
});

Y.Mock.expect(mock, {
callCount: 1,
method: 'fire1',
args: [Y.Mock.Value.Object]
});
eventData.start._start(currentEvent, node1, {fire: Y.bind(mock.fire1, mock)});
Y.Mock.verify(mock);

Y.Mock.expect(mock, {
callCount: 0,
method: 'fire2',
args: [Y.Mock.Value.Object]
});
currentEvent.currentTarget = node2;
eventData.start._start(currentEvent, node2, {fire: Y.bind(mock.fire2, mock)});
Y.Mock.verify(mock);
},

'test: stopImmediatePropagation should work as expected': function() {
var currentEvent,
mock = new Y.Mock(),
node1 = Y.Node.create('<div />'),
node2 = Y.Node.create('<div />');

node2.append(node1);
currentEvent = {
currentTarget: node1,
touches: event.touches,
target: node1,
_event: {}
};

eventData.start._start(currentEvent, node1, {
fire: function(e) {
Assert.areSame('gesturemovestart', e.type, 'Event type not correct');
e.stopped = 2;
}
});

Y.Mock.expect(mock, {
callCount: 0,
method: 'fire1',
args: [Y.Mock.Value.Object]
});
eventData.start._start(currentEvent, node1, {fire: Y.bind(mock.fire1, mock)});
Y.Mock.verify(mock);

Y.Mock.expect(mock, {
callCount: 0,
method: 'fire2',
args: [Y.Mock.Value.Object]
});
currentEvent.currentTarget = node2;
eventData.start._start(currentEvent, node2, {fire: Y.bind(mock.fire2, mock)});
Y.Mock.verify(mock);
}
}));

Expand Down Expand Up @@ -392,4 +472,4 @@ YUI.add('gesture-tests', function(Y) {

Y.Test.Runner.add(suite);

});
}, '', {requires:['test', 'node']});