W3C home > Mailing lists > Public > public-css-archive@w3.org > December 2016

Re: [csswg-drafts] HTMLElement.prototype.offsetParent leaks a node inside a shadow tree

From: Ryosuke Niwa via GitHub <sysbot+gh@w3.org>
Date: Wed, 14 Dec 2016 08:24:09 +0000
To: public-css-archive@w3.org
Message-ID: <issue_comment.created-266972341-1481703848-sysbot+gh@w3.org>
@TakayoshiKochi: Something along the line of the code below should do 
the trick.  Basically, you want to walk up the tree up until the 
“retargeted” `offsetParent`, and return `offsetParent` of a node 
assigned to the deepest slot that’s different from the original 
`offsetParent`.  **Note**: I didn’t think through every edge case so 
the code’s mostly certainly a bug in the code.

function composedParentNode(node) {
    let offsetParent = node.offsetParent;
    let ancestor = node;
    let foundInsideSlot = false;
    while (ancestor && ancestor != offsetParent) {
        let assignedSlot = ancestor.assignedSlot;
        if (assignedSlot) {
            ancestor = assignedSlot;
            let newOffsetParent = assignedSlot.offsetParent;
            if (offsetParent != newOffsetParent)
                foundInsideSlot = true;
        } else if (ancestor.host && foundInsideSlot)
        ancestor = ancestor.host || ancestor.parentNode;
    return offsetParent;

GitHub Notification of comment by rniwa
Please view or discuss this issue at 
using your GitHub account
Received on Wednesday, 14 December 2016 08:24:15 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 19 October 2021 01:30:27 UTC