зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1354211 - Use element.findClosest in element.getContainer. r=automatedtester
element.findClosest is a more generalised version of findAncestralElement, which is limited to a list of element tag names. By using element.findClosest and CSS matching we also avoid a redundant iteration. MozReview-Commit-ID: 32QwmkwiGf5 --HG-- extra : rebase_source : 5197971bd950cd0d90514a12bacb4642779a9090
This commit is contained in:
Родитель
662639d9ba
Коммит
d5a964bb11
|
@ -874,26 +874,15 @@ element.inViewport = function(el, x = undefined, y = undefined) {
|
||||||
* Container element of <var>el</var>.
|
* Container element of <var>el</var>.
|
||||||
*/
|
*/
|
||||||
element.getContainer = function(el) {
|
element.getContainer = function(el) {
|
||||||
function findAncestralElement(startNode, validAncestors) {
|
|
||||||
let node = startNode;
|
|
||||||
while (node.parentNode) {
|
|
||||||
node = node.parentNode;
|
|
||||||
if (validAncestors.includes(node.localName)) {
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return startNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Does <option> or <optgroup> have a valid context,
|
// Does <option> or <optgroup> have a valid context,
|
||||||
// meaning is it a child of <datalist> or <select>?
|
// meaning is it a child of <datalist> or <select>?
|
||||||
if (["option", "optgroup"].includes(el.localName)) {
|
if (["option", "optgroup"].includes(el.localName)) {
|
||||||
return findAncestralElement(el, ["datalist", "select"]);
|
return element.findClosest(el, "datalist,select") || el;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Child nodes of button will not be part of the element tree for
|
// Child nodes of button will not be part of the element tree for
|
||||||
// elementsFromPoint until bug 1089326 is fixed.
|
// elementsFromPoint until bug 1089326 is fixed.
|
||||||
return findAncestralElement(el, ["button"]);
|
return element.findClosest(el, "button") || el;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Загрузка…
Ссылка в новой задаче