This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 21391 - [Shadow]: allow @host rules to match nodes in the host scope not just the host node
Summary: [Shadow]: allow @host rules to match nodes in the host scope not just the hos...
Status: RESOLVED DUPLICATE of bug 22390
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Component Model (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Dimitri Glazkov
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 14978 21499
  Show dependency treegraph
 
Reported: 2013-03-25 19:44 UTC by Steve Orvell
Modified: 2013-07-17 22:14 UTC (History)
2 users (show)

See Also:


Attachments

Description Steve Orvell 2013-03-25 19:44:15 UTC
At a recent discussion, it was proposed that the @host rule would be much more powerful if it could match the host's tree rather than only the host node.

The @host rule would match only the host element or one of its descendants.

The rule would apply in the scope of the host element. This would allow matching the host element based on some ancestor match. The :scope pseudo-selector would be used to reference the host element itself. For example:

@host {
  /* match host elements with an ancestor matching .foo */
  .foo :scope {
    ...
  }
}

Issue: The host itself may be inside a shadowDOM. It would be nice to allow some way to specify rules that can reach to the global css scope. This would allow for shadowDOM styling based on some master theme selector, for example.


In addition, the @host rule could function as a short-hand method (in lieu of ::distributed) for targeting any distributed content. For example,

@host {
  /* match any distributed nodes */
  :scope > * {
    ...
  }

  /* match .bar distributed nodes if the host matches .foo */
  .foo:scope > .bar {
    ...
  }

}
Comment 1 Dimitri Glazkov 2013-05-14 17:15:07 UTC
I remember that there was also a discussion about ::light() pseudo-element function? Can you add some details on that?
Comment 2 Takashi Sakamoto 2013-05-15 10:36:02 UTC
I would like to confirm whether the following should work or not, because an old @host @-rules depends on insertion points.


<div id="host">
    #shadow-root
        <style>
        @host { div::x-my-pseudo { color: blue } }
        </style>
        <div pseudo="x-my-pseudo">Hello</div>
</div>

If a new @host @-rules also depends on insertion points, "Hello"'s color is not blue, because the #shadow-root has neither <content> nor <shadow>.
Comment 3 Takashi Sakamoto 2013-05-15 10:42:28 UTC
(In reply to comment #2)
> I would like to confirm whether the following should work or not, because an
> old @host @-rules depends on insertion points.
> 
> 
> <div id="host">
>     #shadow-root
>         <style>
>         @host { div::x-my-pseudo { color: blue } }
>         </style>
>         <div pseudo="x-my-pseudo">Hello</div>
> </div>
> 
> If a new @host @-rules also depends on insertion points, "Hello"'s color is
> not blue, because the #shadow-root has neither <content> nor <shadow>.

The @host @-rule should work, because the shadow tree is not inert.

... I found a bug of @host @-rules.
Comment 4 Dominic Cooney 2013-06-02 01:12:32 UTC
I think a nice summary of this proposal is here:

<http://lists.w3.org/Archives/Public/public-webapps/2013JanMar/0661.html>

There were no responses on public-webapps at that time. FWIW I think this is a good idea from a web developer ergonomics point of view.

I have a question about the proposed semantics in the case of nested shadows: Are @host rules applied to the host's DOM, or to that DOM with distribution done to its insertion points? For example, given this:

<div id="a">
  <div id="b">x</div>
</div>

<template id="t"> <!-- will be applied to #a -->
  <div id="c">
    <content></content>
  </div>
</template>

<template id="u"> <!-- will be applied to #c -->
  <style>
    @host {
      #b { color: green; }
    }
  </style>
  <content></content>
</template>

<script>
// Add a ShadowRoot to #a populated with #t
var root = document.querySelector('#a').createShadowRoot();
root.appendChild(document.querySelector('#t').content);

// Add a ShadowRoot to #c populated with #u
root.querySelector('#c').createShadowRoot()
.appendChild(document.querySelector('#u').content);
</script>

In this case, does the "x" appear in green or not?

My fear is that, based on the same rationale behind reprojection, the selectors should be run on the result of distribution. But unlike the select attribute, @host rules have access to the full power of CSS selectors. That will make doing a high-performance implementation more difficult.
Comment 5 Dimitri Glazkov 2013-07-17 22:14:08 UTC

*** This bug has been marked as a duplicate of bug 22390 ***