Bug 110797 - Shadow DOM styles appear to be over-eagerly shared
Summary: Shadow DOM styles appear to be over-eagerly shared
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Takashi Sakamoto
URL: http://jsfiddle.net/AwXD8/
Keywords:
Depends on:
Blocks: 72352
  Show dependency treegraph
 
Reported: 2013-02-25 14:11 PST by Dimitri Glazkov (Google)
Modified: 2013-02-26 02:53 PST (History)
9 users (show)

See Also:


Attachments
Patch (4.75 KB, patch)
2013-02-25 18:18 PST, Takashi Sakamoto
no flags Details | Formatted Diff | Diff
Patch (4.78 KB, patch)
2013-02-25 18:29 PST, Takashi Sakamoto
no flags Details | Formatted Diff | Diff
Patch (5.01 KB, patch)
2013-02-25 20:20 PST, Takashi Sakamoto
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitri Glazkov (Google) 2013-02-25 14:11:44 PST
Check out the example in URL. BAR, the next sibling of FOO that has shadow DOM appears to acquire the same styles as FOO. That seems bad.
Comment 1 Takashi Sakamoto 2013-02-25 15:34:05 PST
I think, StyleResolver::canShareStyleWithElement should check whether a given element is distributed or not.
Comment 2 Takashi Sakamoto 2013-02-25 15:39:10 PST
Or modify StyleResolver::locateCousinList not to return children of a shadow host.
Comment 3 Takashi Sakamoto 2013-02-25 18:18:13 PST
Created attachment 190172 [details]
Patch
Comment 4 Takashi Sakamoto 2013-02-25 18:21:38 PST
Comment on attachment 190172 [details]
Patch

Or just modifying WebCore::StyleResolver::locateCousinList,

line 887:
            if (currentNode->renderStyle() == parentStyle && currentNode->lastC\
hild()
!               && currentNode->isElementNode() && !parentElementPreventsSharin\
g(toElement(currentNode))) {
---
!                && currentNode->isElementNode() && !parentElementPreventsSharin\
g(toElement(currentNode))
+               && !toElement(currentNode)->shadow()) {
Comment 5 Takashi Sakamoto 2013-02-25 18:29:45 PST
Created attachment 190178 [details]
Patch
Comment 6 Dimitri Glazkov (Google) 2013-02-25 19:02:23 PST
Comment on attachment 190178 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=190178&action=review

> Source/WebCore/css/StyleResolver.cpp:1102
> +    if (element->parentElement() && element->parentElement()->shadow() && element->parentElement()->shadow()->distributor().findInsertionPointFor(element))

Isn't this super-slow? We need to keep an eye out for better-performing way of doing this.
Comment 7 Takashi Sakamoto 2013-02-25 20:20:52 PST
Created attachment 190193 [details]
Patch
Comment 8 Takashi Sakamoto 2013-02-25 20:22:58 PST
Comment on attachment 190178 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=190178&action=review

>> Source/WebCore/css/StyleResolver.cpp:1102
>> +    if (element->parentElement() && element->parentElement()->shadow() && element->parentElement()->shadow()->distributor().findInsertionPointFor(element))
> 
> Isn't this super-slow? We need to keep an eye out for better-performing way of doing this.

Yeah, I think, we don't need to check whether the element is really distributed or not.
I moved the logic to locateCousinList and just checked whether a given element is a shadow host or not.
Comment 9 Takashi Sakamoto 2013-02-25 20:26:48 PST
Comment on attachment 190178 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=190178&action=review

>>> Source/WebCore/css/StyleResolver.cpp:1102
>>> +    if (element->parentElement() && element->parentElement()->shadow() && element->parentElement()->shadow()->distributor().findInsertionPointFor(element))
>> 
>> Isn't this super-slow? We need to keep an eye out for better-performing way of doing this.
> 
> Yeah, I think, we don't need to check whether the element is really distributed or not.
> I moved the logic to locateCousinList and just checked whether a given element is a shadow host or not.

I mean,
- if a given element is distributed, we cannot share the element's style.
- if a given element is not distributed but a child of a shadow host, we don't render the element and we don't have the element's render style.
Comment 10 Takashi Sakamoto 2013-02-25 20:27:43 PST
Comment on attachment 190193 [details]
Patch

Thank you for reviewing.
Comment 11 WebKit Review Bot 2013-02-26 02:53:49 PST
Comment on attachment 190193 [details]
Patch

Clearing flags on attachment: 190193

Committed r144031: <http://trac.webkit.org/changeset/144031>
Comment 12 WebKit Review Bot 2013-02-26 02:53:54 PST
All reviewed patches have been landed.  Closing bug.