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

<blockquote><details><summary><b>Click here for the full-length explaination of Edge's behavior for font-size</b></summary>


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?). 

> (test case showing an inline `<html>` in Edge)
> ![image](

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**
> (only default styles)
> (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 using your GitHub account

Received on Tuesday, 6 February 2018 22:19:11 UTC