<?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>20149</bug_id>
          
          <creation_ts>2012-11-29 05:09:29 +0000</creation_ts>
          <short_desc>[Shadow]: Specify the order of stylesheets in different tree scopes for apply-author-styles.</short_desc>
          <delta_ts>2012-12-10 09:44:25 +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>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</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>18428</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Takashi Sakamoto">tasak</reporter>
          <assigned_to name="Dimitri Glazkov">dglazkov</assigned_to>
          <cc>jackalmage</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>79089</commentid>
    <comment_count>0</comment_count>
    <who name="Takashi Sakamoto">tasak</who>
    <bug_when>2012-11-29 05:09:29 +0000</bug_when>
    <thetext>If some shadow root&apos;s apply-author-styles is true, styles in a different tree scope, e.g. document, will be applied to elements in the shadow dom tree.

In this case, we need to compare document positions of styles in a document tree and styles in the shadow dom tree. (also need to consider styles in an enclosing shadow tree).

I&apos;m not sure whether it is ok to use a document position of a shadow host to solve the above case or not.
If ok, I&apos;m thinking of the following algorithm:

Suppose that two nodes, A and B. A is in some shadow dom tree and B is in another shadow dom tree. B&apos;s tree scope is an ancestor tree scope of A&apos;s.

To compare document position of A and B:
(1) going up from node A to the shadow host C in B&apos;s tree scope. I mean, A&apos;s host -&gt; A&apos;s host&apos;s host... to reach B&apos;s tree scope.
(2) compare C with B (by using Node::compareDocumentPosition).

In general, 
(1) finding a common ancestor node of A and B. 

(2) comparing immediate children of the common ancestor, A&apos; and B&apos;. A&apos; is an ancestor node of A and B&apos; is an ancestor node of B.

(3) if A&apos; and B&apos; are in the same tree scope, just compare A&apos; with B&apos; in the original compareDocumentPosition&apos;s way.

(4) if A&apos; is a shadow root and B&apos; is not a shadow root, treat A&apos; as a shadow host. Since B&apos; is a child of the shadow host, B&apos; is following A&apos;. So B is following A.

(5) if both A&apos; and B&apos; are shadow roots, see which is a younger shadow root and follow the rule defined in shadow dom spec: 
&quot;When a shadow host has multiple shadow roots, the sorting order of CSS rules, defined in shadow roow style sheets, in ascending order of precedence must match the order of the tree stack, ending with the youngest tree.&quot;

Best regards,
Takashi Sakamoto</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79664</commentid>
    <comment_count>1</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2012-12-07 19:29:12 +0000</bug_when>
    <thetext>This is good, but Tab pointed out that he already has the main bits of plumbing specified here: http://dev.w3.org/csswg/css3-cascade/#cascade

And for shadow DOM, we just need to specify that out of two declarations, one in a tree A and another in tree B, and A encloses B, then a declaration B wins.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79672</commentid>
    <comment_count>2</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2012-12-07 21:26:36 +0000</bug_when>
    <thetext>http://dvcs.w3.org/hg/webcomponents/rev/5882b6827736</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79817</commentid>
    <comment_count>3</comment_count>
    <who name="Takashi Sakamoto">tasak</who>
    <bug_when>2012-12-10 09:44:25 +0000</bug_when>
    <thetext>(In reply to comment #2)
&gt; http://dvcs.w3.org/hg/webcomponents/rev/5882b6827736

Thank you for updating the spec.

I will update WebKit bugs related to this.

Best regards,
Takashi Sakamoto</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>