<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>21693</bug_id>
          
          <creation_ts>2013-04-15 06:38:40 +0000</creation_ts>
          <short_desc>[Shadow]: clarify compareDocumentPosition for elements in different shadow trees</short_desc>
          <delta_ts>2013-04-30 22:13:48 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>HISTORICAL - Component Model</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>14978</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Takashi Sakamoto">tasak</reporter>
          <assigned_to name="Dimitri Glazkov">dglazkov</assigned_to>
          <cc>bugs</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>86199</commentid>
    <comment_count>0</comment_count>
    <who name="Takashi Sakamoto">tasak</who>
    <bug_when>2013-04-15 06:38:40 +0000</bug_when>
    <thetext>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(&apos;div&apos;);
var b = document.createElement(&apos;div&apos;);
var c = document.createElement(&apos;div&apos;);

// #document
//   &lt;div id=a&gt;
//   &lt;div id=b&gt;
//      #shadow-root
//         &lt;div id=c&gt;

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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86312</commentid>
    <comment_count>1</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2013-04-16 18:28:52 +0000</bug_when>
    <thetext>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?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86322</commentid>
    <comment_count>2</comment_count>
    <who name="Takashi Sakamoto">tasak</who>
    <bug_when>2013-04-17 03:44:10 +0000</bug_when>
    <thetext>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)&apos;s order and inserted into StyleResolver.

And I&apos;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)?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86329</commentid>
    <comment_count>3</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2013-04-17 10:06:47 +0000</bug_when>
    <thetext>Takashi, that sounds like an implementation detail, not something that need
to be exposed to web.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86339</commentid>
    <comment_count>4</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2013-04-17 17:12:19 +0000</bug_when>
    <thetext>(In reply to comment #3)
&gt; Takashi, that sounds like an implementation detail, not something that need
&gt; to be exposed to web.

FWIW, I agree.

Just to play devil&apos;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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86351</commentid>
    <comment_count>5</comment_count>
    <who name="Takashi Sakamoto">tasak</who>
    <bug_when>2013-04-18 00:25:00 +0000</bug_when>
    <thetext>Thank you.

I see.
I will implement an internal API.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>