Created
December 7, 2010 01:38
-
-
Save harthur/731332 to your computer and use it in GitHub Desktop.
mozmill drag and drop shared module WIP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var EventUtils = {}; Components.utils.import('resource://mozmill/stdlib/EventUtils.js', EventUtils); | |
var dragBy = function(element, offsetX, offsetY, contentWindow) { | |
var rect = element.getBoundingClientRect(); | |
var startX = (rect.right - rect.left)/2; | |
var startY = (rect.bottom - rect.top)/2; | |
var incrementX = offsetX / 2; | |
var incrementY = offsetY / 2; | |
EventUtils.synthesizeMouse( | |
element, startX, startY, { type: "mousedown" }, contentWindow); | |
for (var i = 1; i <= 2; i++) { | |
EventUtils.synthesizeMouse( | |
element, (startX + incrementX * i), (startY + incrementY * i), | |
{ type: "mousemove" }, contentWindow); | |
} | |
EventUtils.synthesizeMouse( | |
element, (startX + incrementX * 2), (startY + incrementY * 2), | |
{ type: "mouseup" }, contentWindow); | |
} | |
exports.dragBy = dragBy; | |
exports.dragToElement = function (element, dest, contentWindow) { | |
var rect = element.getBoundingClientRect(); | |
var startX = (rect.right - rect.left)/2; | |
var startY = (rect.bottom - rect.top)/2; | |
var destRect = dest.getBoundingClientRect(); | |
var endX = (destRect.right - destRect.left)/2; | |
var endY = (destRect.bottom - destRect.top)/2; | |
dragBy(element, endX - startX, endY - startY, contentWindow); | |
} | |
exports.dragTo2 = function(element, dest, win, dropEffect) { | |
var data = [[ | |
{ type : "text/plain", | |
data : "test data" } | |
]]; | |
EventUtils.synthesizeDrop(element, dest, data, dropEffect, win, 300, 300); | |
} | |
/* old stuff */ | |
var events = {}; Components.utils.import('resource://mozmill/modules/events.js', events); | |
exports.dragDropElemToElem = function (drag, dest) { | |
var dragCoords = drag.getBoundingClientRect(); | |
var destCoords = dest.getBoundingClientRect(); | |
//Do the initial move to the drag element position | |
events.triggerMouseEvent(drag.parentNode, 'mousemove', true, dragCoords.left, dragCoords.top); | |
events.triggerMouseEvent(drag, 'mousedown', true, dragCoords.left, dragCoords.top); //do the mousedown | |
events.triggerMouseEvent(drag.parentNode, 'mousemove', true, destCoords.left, destCoords.top); | |
events.triggerMouseEvent(dest, 'mouseup', true, destCoords.left, destCoords.top); | |
//events.triggerMouseEvent(dest, 'click', true, destCoords.left, destCoords.top); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment