Re: Mutation events replacement

On 7/20/11 11:43 AM, Dave Raggett wrote:
> Perhaps we need to distinguish auto generated attributes from those that
> are set by markup or scripts.

I'm not sure what you mean.

> Could you please clarify for me the
> difference between the html "style" attribute and the one you are
> referring to?

There isn't one.

> My understanding is that the html style attribute is set
> via markup or scripts and *doesn't* reflect all of the computed style
> properties for this DOM node.

That's correct.

Let me give you a concrete testcase:

   <!DOCTYPE html>
   <body style="margin: 0;">
   <script>
     document.body.style.marginLeft = "5px";
     document.body.style.marginRight = "5px";
     document.body.style.top = "17px";
     alert(document.body.getAttribute("style"));
   </script>

This alerts "margin: 0pt 5px; top: 17px" in Gecko, "margin-top: 0px; 
margin-bottom: 0px; margin-left: 5px; margin-right: 5px; top: 17px" in 
WebKit and Presto.  So the value of the style attribute changes when you 
modify inline style via the CSS2Properties and CSSDeclaration 
interfaces.  Not only that, but what's stored are the longhand property 
names and values, with shorthand generation happening at serialization 
time in at least some UAs.

It's pretty common to have situations where lots (10-20) of properties 
are set in inline style, especially in cases where the inline style is 
being changed via CSS2Properties from script (think animations and the 
like, where the objects being animated tend to have width, height, 
various margin/border/padding/background properties, top, left, etc all 
set).  Those are precisely the cases that are most performance-sensitive 
and where the overhead of serializing the style attribute on every 
mutation is highest due to the large number of properties set.

-Boris

Received on Wednesday, 20 July 2011 17:24:20 UTC