lib/capybara/poltergeist/client/compiled/node.js in poltergeist-1.17.0 vs lib/capybara/poltergeist/client/compiled/node.js in poltergeist-1.18.0
- old
+ new
@@ -25,12 +25,15 @@
for (j = 0, len = ref.length; j < len; j++) {
name = ref[j];
fn(name);
}
- Node.prototype.mouseEventPosition = function() {
- var area_offset, image, middle, pos, res, viewport;
+ Node.prototype.mouseEventPosition = function(offset) {
+ var area_offset, image, middle, pos, viewport;
+ if (offset == null) {
+ offset = {};
+ }
viewport = this.page.viewportSize();
if (image = this._getAreaImage()) {
pos = image.position();
if (area_offset = this._getAreaOffsetRect()) {
pos.left = pos.left + area_offset.x;
@@ -42,30 +45,54 @@
pos = this.position();
}
middle = function(start, end, size) {
return start + ((Math.min(end, size) - start) / 2);
};
- return res = {
- x: middle(pos.left, pos.right, viewport.width),
- y: middle(pos.top, pos.bottom, viewport.height)
- };
+ if ((offset['x'] != null) && (offset['y'] != null)) {
+ return {
+ x: pos.left + offset['x'],
+ y: pos.top + offset['y']
+ };
+ } else {
+ return {
+ x: middle(pos.left, pos.right, viewport.width),
+ y: middle(pos.top, pos.bottom, viewport.height)
+ };
+ }
};
- Node.prototype.mouseEvent = function(name) {
- var area_image, pos, test;
+ Node.prototype.mouseEvent = function(name, keys, offset) {
+ var area_image, modifier_keys, modifiers_code, pos, scroll_pos, test;
if (area_image = this._getAreaImage()) {
area_image.scrollIntoView();
} else {
this.scrollIntoView();
}
- pos = this.mouseEventPosition();
+ pos = this.mouseEventPosition(offset);
test = this.mouseEventTest(pos.x, pos.y);
if (test.status === 'success') {
+ modifier_keys = (keys || []).join(',').replace('control', 'ctrl');
+ modifiers_code = this.page.keyModifierCode(modifier_keys);
if (name === 'rightclick') {
- this.page.mouseEvent('click', pos.x, pos.y, 'right');
- this.trigger('contextmenu');
+ this.page.mouseEvent('click', pos.x, pos.y, 'right', modifiers_code);
+ if (phantom.version.major === 2 && phantom.version.minor >= 1) {
+ this.page.sendEvent('contextmenu', pos.x, pos.y, 'right', modifiers_code);
+ } else {
+ scroll_pos = this.page.scrollPosition();
+ this.trigger('contextmenu', {
+ screenX: pos.x,
+ screenY: pos.y,
+ clientX: pos.x + scroll_pos['left'],
+ clientY: pos.y + scroll_pos['top'],
+ ctrlKey: modifier_keys.indexOf('ctrl') !== -1,
+ altKey: modifier_keys.indexOf('alt') !== -1,
+ metaKey: modifier_keys.indexOf('meta') !== -1,
+ shiftKey: modifier_keys.indexOf('shift') !== -1,
+ button: 2
+ });
+ }
} else {
- this.page.mouseEvent(name, pos.x, pos.y);
+ this.page.mouseEvent(name, pos.x, pos.y, 'left', modifiers_code);
}
return pos;
} else {
throw new Poltergeist.MouseEventFailed(name, test.selector, pos);
}