This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
I would like to confirm two things: (1) whether we use DOCUMENT_POSITION_DISCONNECTED when comparing elements in different shadow trees whose document root is the same or not If document roots of different shadow trees are different, we should use DOCUMENT_POSITION_DISCONNECTED. (2) whether we use the followings instead of DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC when comparing elements in different shadow trees: DOCUMENT_POSITION_PRECEDING 2 DOCUMENT_POSITION_FOLLOWING 4 DOCUMENT_POSITION_CONTAINS 8 DOCUMENT_POSITION_CONTAINED_BY 16 (2) will make it easier to solve styles in different shadow trees, i.e. multiple and nested shadow trees. For example, ---- var a = document.createElement('div'); var b = document.createElement('div'); var c = document.createElement('div'); // #document // <div id=a> // <div id=b> // #shadow-root // <div id=c> document.body.appendChild(a); document.body.appendChild(b); b.createShadowRoot().appendChild(c); ---- Currently a.compareDocumentPosition(c) returns DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC So, which a.compareDocumentPosition(c) should return? (a) DOCUMENT_POSITION_FOLLOWINGS or (b) DOCUMENT_POSITION_FOLLOWINGS | DOCUMENT_POSITION_DISCONNECTED or (c) DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
My first reaction is that it should return DOCUMENT_POSITION_DISCONNECTED, since document tree and shadow tree are two disconnected trees. Can you explain why it may be good to do something different?
Sure. I will explain what I want. So currently Blink does: (1) all style elements are sorted in document order by using compareDocumentPosition. (2) rules are picked up in (1)'s order and inserted into StyleResolver. And I'm planning to implement a scoped style tree. So if I can always rely on the above (1) and (2) (including style elements in shadow dom trees), when creating a new node and inserting the node into a scoped style tree, I can also assume that all parent nodes have been inserted into the tree. This assumption would make code simpler. So is it ok to use DOCUMENT_POSITION_FOLLOWINGS | DOCUMENT_POSITION_DISCONNECTED for a.compareDocumentPosition(c)?
Takashi, that sounds like an implementation detail, not something that need to be exposed to web.
(In reply to comment #3) > Takashi, that sounds like an implementation detail, not something that need > to be exposed to web. FWIW, I agree. Just to play devil's advocate against my own opinion: one could see the disparity of what internal API says vs. what external API reports as undesirable, since it creates more magic in the platform.
Thank you. I see. I will implement an internal API.