W3C home > Mailing lists > Public > public-css-archive@w3.org > February 2018

Re: [csswg-drafts] [cssom] [css-display] [css-values] Clarify behavior of window.getComputedStyle on detached subtrees, and the definition of "the root element".

From: François REMY via GitHub <sysbot+gh@w3.org>
Date: Tue, 06 Feb 2018 22:19:01 +0000
To: public-css-archive@w3.org
Message-ID: <issue_comment.created-363584249-1517955541-sysbot+gh@w3.org>
<blockquote><details><summary><b>Click here for the full-length explaination of Edge's behavior for font-size</b></summary>

<aside>

FWIW, Edge resolves the REM unit against the root of the current document (like Stylo does). 

The difference however is that root of the document is not the `<html>` element but a `<::root>` pseudo-element (think of it as the "document" node) which therefore is not affected by the style applied to the `<html>` element using the `:root` rule. We therefore do not need to prevent the html element from becoming inline, though I guess we maybe should to prevent interop issues (who would do that, though?). 

> https://wptest.center/#/vur7k5 (test case showing an inline `<html>` in Edge)
> 
> ![image](https://user-images.githubusercontent.com/364405/35885508-e6a42086-0b42-11e8-840a-31c5ec3ba7a1.png)
</aside></details></blockquote>

That being said, I don't believe the real question here is the details of how things work for font-size with rem units; the real question is: 

**Question 1**
> Is it okay for getComputedStyle() to return an object that returns an empty string for each property value when an element is not part of the tree, or should you always return some form of default style?

**Question 2**
> If you return some default style, how do you compute it?

**Current results**
> https://wptest.center/#/2firn0 (only default styles)
> https://wptest.center/#/o41af0 (includes author rules)
>
> Edge:
>    * returns the style resulting from:
>        * applying the default stylesheet and inline styles, but 
>        * ignoring any author styles. 
> 
> Firefox:
>    * returns the style resulting from:
>       * applying all css rules and inline styles. 
> 
> Chrome and Safari:
>    * return empty strings.
> 

**Moving forward**

My personal point of view is that returning the default style is a very nice feature but, while Webkit's solution is lazy, it is also very simple to implement. We would really like Chrome to support computing styles on detached subtrees but if the Chrome team isn't interested in pursuing this, the easiest path to interop is for us to stop computing this default styles and return empty strings.

I think Edge's behavior is interesting because you can use it to determine the minimum subset of inline styles you need to add to an element to create a proper copy/paste. You compute the styles of all the elements, then you clone then, get the computedStyles of the cloned root and add inline styles for anything that has changed, and continue to do so in dom order until you have processed all elements.

I cannot imagine another use case for this on top of my head.

Pinging @tabatkins -- what are your thoughts here?

-- 
GitHub Notification of comment by FremyCompany
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/1548#issuecomment-363584249 using your GitHub account
Received on Tuesday, 6 February 2018 22:19:11 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 06:41:24 UTC