mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 12:38:00 +01:00
Fix createEvent/init*Event insanity.
This commit is contained in:
@@ -1069,14 +1069,13 @@ function Buffer() //{{{
|
|||||||
|
|
||||||
elem.focus();
|
elem.focus();
|
||||||
|
|
||||||
let evt = doc.createEvent("MouseEvents");
|
|
||||||
let x = 0;
|
let x = 0;
|
||||||
let y = 0;
|
let y = 0;
|
||||||
// for imagemap
|
// for imagemap
|
||||||
if (elemTagName == "area")
|
if (elemTagName == "area")
|
||||||
[x, y] = elem.getAttribute("coords").split(",").map(Number);
|
[x, y] = elem.getAttribute("coords").split(",").map(Number);
|
||||||
|
|
||||||
evt.initMouseEvent("mouseover", true, true, doc.defaultView, 1, x, y, 0, 0, 0, 0, 0, 0, 0, null);
|
let evt = events.create(doc, "mouseover", { screenX: x, screenY: y });
|
||||||
elem.dispatchEvent(evt);
|
elem.dispatchEvent(evt);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -1159,19 +1158,18 @@ function Buffer() //{{{
|
|||||||
let offsetX = 1;
|
let offsetX = 1;
|
||||||
let offsetY = 1;
|
let offsetY = 1;
|
||||||
|
|
||||||
let localName = elem.localName.toLowerCase();
|
if (elem instanceof HTMLFrameElement || elem instanceof HTMLIFrameElement)
|
||||||
if (localName == "frame" || localName == "iframe") // broken?
|
|
||||||
{
|
{
|
||||||
elem.contentWindow.focus();
|
elem.contentWindow.focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (localName == "area") // for imagemap
|
else if (elem instanceof HTMLAreaElement) // for imagemap
|
||||||
{
|
{
|
||||||
let coords = elem.getAttribute("coords").split(",");
|
let coords = elem.getAttribute("coords").split(",");
|
||||||
offsetX = Number(coords[0]) + 1;
|
offsetX = Number(coords[0]) + 1;
|
||||||
offsetY = Number(coords[1]) + 1;
|
offsetY = Number(coords[1]) + 1;
|
||||||
}
|
}
|
||||||
else if (localName == "input" && elem.type.toLowerCase() == "file")
|
else if (elem instanceof HTMLInputElement && elem.type == "file")
|
||||||
{
|
{
|
||||||
openUploadPrompt(elem);
|
openUploadPrompt(elem);
|
||||||
return;
|
return;
|
||||||
@@ -1196,12 +1194,13 @@ function Buffer() //{{{
|
|||||||
|
|
||||||
elem.focus();
|
elem.focus();
|
||||||
|
|
||||||
let evt = doc.createEvent("MouseEvents");
|
|
||||||
options.withContext(function () {
|
options.withContext(function () {
|
||||||
options.setPref("browser.tabs.loadInBackground", true);
|
options.setPref("browser.tabs.loadInBackground", true);
|
||||||
["mousedown", "mouseup", "click"].forEach(function (event) {
|
["mousedown", "mouseup", "click"].forEach(function (event) {
|
||||||
evt.initMouseEvent(event, true, true, view, 1, offsetX, offsetY, 0, 0,
|
let evt = events.create(doc, event, {
|
||||||
ctrlKey, /*altKey*/0, shiftKey, /*metaKey*/ ctrlKey, 0, null);
|
screenX: offsetX, screenY: offsetY,
|
||||||
|
ctrlKey: ctrlKey, shiftKey: shiftKey, metaKey: ctrlKey
|
||||||
|
});
|
||||||
elem.dispatchEvent(evt);
|
elem.dispatchEvent(evt);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -970,8 +970,10 @@ function Events() //{{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
let elem = liberator.focus || window.content;
|
let elem = liberator.focus || window.content;
|
||||||
let evt = doc.createEvent("KeyEvents");
|
let evt = events.create(doc, "keypress", {
|
||||||
evt.initKeyEvent("keypress", true, true, view, ctrl, alt, shift, meta, keyCode, charCode);
|
ctrlKey: ctrl, altKey: alt, shiftKey: shift, metaKey: meta ,
|
||||||
|
keyCode: keyCode, charCode: charCode
|
||||||
|
});
|
||||||
if (typeof noremap == "object")
|
if (typeof noremap == "object")
|
||||||
for (let [k, v] in Iterator(noremap))
|
for (let [k, v] in Iterator(noremap))
|
||||||
evt[k] = v;
|
evt[k] = v;
|
||||||
@@ -1012,6 +1014,40 @@ function Events() //{{{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
create: function (doc, type, opts)
|
||||||
|
{
|
||||||
|
var DEFAULTS = {
|
||||||
|
Key: {
|
||||||
|
type: type,
|
||||||
|
bubbles: true, cancelable: true,
|
||||||
|
view: doc.defaultView,
|
||||||
|
ctrlKey: false, altKey: false, shiftKey: false, metaKey: false,
|
||||||
|
keyCode: 0, charCode: 0
|
||||||
|
},
|
||||||
|
Mouse: {
|
||||||
|
type: type,
|
||||||
|
bubbles: true, cancelable: true,
|
||||||
|
view: doc.defaultView,
|
||||||
|
detail: 1,
|
||||||
|
screenX: 0, screenY: 0,
|
||||||
|
clientX: 0, clientY: 0,
|
||||||
|
ctrlKey: false, altKey: false, shiftKey: false, metaKey: false,
|
||||||
|
button: 0,
|
||||||
|
relatedTarget: null
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const TYPES = {
|
||||||
|
click: "Mouse", mousedown: "Mouse", mouseup: "Mouse",
|
||||||
|
mouseover: "Mouse", mouseout: "Mouse",
|
||||||
|
keypress: "Key", keyup: "Key", keydown: "Key"
|
||||||
|
};
|
||||||
|
var t = TYPES[type];
|
||||||
|
var evt = doc.createEvent(t + "Events");
|
||||||
|
evt["init" + t + "Event"].apply(evt,
|
||||||
|
[v for ([k, v] in Iterator(util.extend(DEFAULTS[t], opts)))]);
|
||||||
|
return evt;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the specified key event to a string in liberator key-code
|
* Converts the specified key event to a string in liberator key-code
|
||||||
* notation. Returns null for an unknown key event.
|
* notation. Returns null for an unknown key event.
|
||||||
|
|||||||
Reference in New Issue
Block a user