Bug 694976 - convert the rest of eventutils.js functions to use SpecialPowers. r=ted

This commit is contained in:
Joel Maher 2011-10-19 05:35:05 -04:00
Родитель 02379a7d61
Коммит da7cbf4f09
3 изменённых файлов: 17 добавлений и 12 удалений

Просмотреть файл

@ -127,8 +127,9 @@ function attachSpecialPowersToWindow(aWindow) {
(aWindow.parent !== null) &&
(aWindow.parent !== undefined) &&
(aWindow.parent.wrappedJSObject.SpecialPowers) &&
!(aWindow.wrappedJSObject.SpecialPowers)) {
aWindow.wrappedJSObject.SpecialPowers = aWindow.parent.SpecialPowers;
!(aWindow.wrappedJSObject.SpecialPowers) &&
aWindow.location.hostname == aWindow.parent.location.hostname) {
aWindow.wrappedJSObject.SpecialPowers = aWindow.parent.wrappedJSObject.SpecialPowers;
}
else if ((aWindow !== null) &&
(aWindow !== undefined) &&

Просмотреть файл

@ -44,9 +44,6 @@ function sendMouseEvent(aEvent, aTarget, aWindow) {
aTarget = aWindow.document.getElementById(aTarget);
}
// For events to trigger the UA's default actions they need to be "trusted"
netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserWrite');
var event = aWindow.document.createEvent('MouseEvent');
var typeArg = aEvent.type;
@ -72,7 +69,7 @@ function sendMouseEvent(aEvent, aTarget, aWindow) {
ctrlKeyArg, altKeyArg, shiftKeyArg, metaKeyArg,
buttonArg, relatedTargetArg);
aTarget.dispatchEvent(event);
SpecialPowers.dispatchEvent(aWindow, aTarget, event);
}
/**
@ -145,14 +142,11 @@ function __doEventDispatch(aTarget, aCharCode, aKeyCode, aHasShift) {
aTarget = "target";
}
// Make our events trusted
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var event = document.createEvent("KeyEvents");
event.initKeyEvent("keydown", true, true, document.defaultView,
false, false, aHasShift, false,
aKeyCode, 0);
var accepted = $(aTarget).dispatchEvent(event);
var accepted = SpecialPowers.dispatchEvent(window, aTarget, event);
// Preventing the default keydown action also prevents the default
// keypress action.
@ -169,14 +163,14 @@ function __doEventDispatch(aTarget, aCharCode, aKeyCode, aHasShift) {
if (!accepted) {
event.preventDefault();
}
accepted = $(aTarget).dispatchEvent(event);
accepted = SpecialPowers.dispatchEvent(window, aTarget, event);
// Always send keyup
var event = document.createEvent("KeyEvents");
event.initKeyEvent("keyup", true, true, document.defaultView,
false, false, aHasShift, false,
aKeyCode, 0);
$(aTarget).dispatchEvent(event);
SpecialPowers.dispatchEvent(window, aTarget, event);
return accepted;
}

Просмотреть файл

@ -723,5 +723,15 @@ SpecialPowersAPI.prototype = {
registerFactory);
return {'cid':cid, 'originalFactory':oldFactory};
},
_getElement: function(aWindow, id) {
return ((typeof(id) == "string") ?
aWindow.document.getElementById(id) : id);
},
dispatchEvent: function(aWindow, target, event) {
var el = this._getElement(aWindow, target);
return el.dispatchEvent(event);
},
};