Title: [124463] trunk
Revision
124463
Author
[email protected]
Date
2012-08-02 09:08:48 -0700 (Thu, 02 Aug 2012)

Log Message

Inline stylesheets can confuse style sharing
https://bugs.webkit.org/show_bug.cgi?id=92970

Reviewed by Dan Bernstein.

Source/WebCore: 

Consider document 
        
<div class="i30"></div>
<style>.i30 { background-color:green; }</style>
<div class="i30"></div>
        
When processing the <style> element the scope optimization marks the first div as needing style recalc. 
Next the parser adds the second div to the tree and immediately calculates its style. Since it looks exactly 
like the first div the style sharing optimization copies the style from there. The pending recalc of the
first div is resolved by a timer but the second div is left with the old style.
        
Fix by disallowing style sharing from elements with pending style recalc.

Test: fast/css/style-sharing-inline-stylesheet.html

* css/StyleResolver.cpp:
(WebCore::StyleResolver::canShareStyleWithElement):

LayoutTests: 

* fast/css/style-sharing-inline-stylesheet-expected.txt: Added.
* fast/css/style-sharing-inline-stylesheet.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (124462 => 124463)


--- trunk/LayoutTests/ChangeLog	2012-08-02 16:07:01 UTC (rev 124462)
+++ trunk/LayoutTests/ChangeLog	2012-08-02 16:08:48 UTC (rev 124463)
@@ -1,3 +1,13 @@
+2012-08-02  Antti Koivisto  <[email protected]>
+
+        Inline stylesheets can confuse style sharing
+        https://bugs.webkit.org/show_bug.cgi?id=92970
+
+        Reviewed by Dan Bernstein.
+
+        * fast/css/style-sharing-inline-stylesheet-expected.txt: Added.
+        * fast/css/style-sharing-inline-stylesheet.html: Added.
+
 2012-08-02  Dominik Röttsches  <[email protected]>
 
         [Cairo] Add complex font drawing using HarfbuzzNG

Added: trunk/LayoutTests/fast/css/style-sharing-inline-stylesheet-expected.txt (0 => 124463)


--- trunk/LayoutTests/fast/css/style-sharing-inline-stylesheet-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/style-sharing-inline-stylesheet-expected.txt	2012-08-02 16:08:48 UTC (rev 124463)
@@ -0,0 +1,11 @@
+Test that inline stylesheet does not confuse style sharing.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS window.getComputedStyle(document.getElementsByClassName("testclass")[1]).backgroundColor is "rgb(0, 128, 0)"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+first div
+second div

Added: trunk/LayoutTests/fast/css/style-sharing-inline-stylesheet.html (0 => 124463)


--- trunk/LayoutTests/fast/css/style-sharing-inline-stylesheet.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/style-sharing-inline-stylesheet.html	2012-08-02 16:08:48 UTC (rev 124463)
@@ -0,0 +1,20 @@
+<html lang=en>
+<head>
+<script src=""
+<style>
+.testclass { background-color: red; }
+</style>
+</head>
+<body>
+<div class=testclass>first div</div>
+<style>
+.testclass { background-color: green; }
+</style>
+<div class=testclass>second div</div>
+
+<script>
+description("Test that inline stylesheet does not confuse style sharing.");
+shouldBe('window.getComputedStyle(document.getElementsByClassName("testclass")[1]).backgroundColor','"rgb(0, 128, 0)"');
+</script>
+<script src=""
+</body>

Modified: trunk/Source/WebCore/ChangeLog (124462 => 124463)


--- trunk/Source/WebCore/ChangeLog	2012-08-02 16:07:01 UTC (rev 124462)
+++ trunk/Source/WebCore/ChangeLog	2012-08-02 16:08:48 UTC (rev 124463)
@@ -1,3 +1,28 @@
+2012-08-02  Antti Koivisto  <[email protected]>
+
+        Inline stylesheets can confuse style sharing
+        https://bugs.webkit.org/show_bug.cgi?id=92970
+
+        Reviewed by Dan Bernstein.
+
+        Consider document 
+        
+        <div class="i30"></div>
+        <style>.i30 { background-color:green; }</style>
+        <div class="i30"></div>
+        
+        When processing the <style> element the scope optimization marks the first div as needing style recalc. 
+        Next the parser adds the second div to the tree and immediately calculates its style. Since it looks exactly 
+        like the first div the style sharing optimization copies the style from there. The pending recalc of the
+        first div is resolved by a timer but the second div is left with the old style.
+        
+        Fix by disallowing style sharing from elements with pending style recalc.
+
+        Test: fast/css/style-sharing-inline-stylesheet.html
+
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::canShareStyleWithElement):
+
 2012-08-02  Tommy Widenflycht  <[email protected]>
 
         MediaStream API: Add RTCPeerConnectionHandler infrastructure

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (124462 => 124463)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2012-08-02 16:07:01 UTC (rev 124462)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2012-08-02 16:08:48 UTC (rev 124463)
@@ -1393,6 +1393,8 @@
         return false;
     if (element->inlineStyle())
         return false;
+    if (element->needsStyleRecalc())
+        return false;
 #if ENABLE(SVG)
     if (element->isSVGElement() && static_cast<SVGElement*>(element)->animatedSMILStyleProperties())
         return false;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to