Inserting a rule into an empty style sheet shouldn't trigger style recalc unless...
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 4 Aug 2013 15:57:13 +0000 (15:57 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 4 Aug 2013 15:57:13 +0000 (15:57 +0000)
commit37c44efe75a17c3bf6311cf25e616d686438dc83
treee6dacc5d9963c72ad9e3e9d38aee05f1607ad5ea
parent597393533aa06bcf1d3cba0cb0375399881c69c8
Inserting a rule into an empty style sheet shouldn't trigger style recalc unless necessary.
<http://webkit.org/b/119475>
<rdar://problem/14643481>

Reviewed by Antti Koivisto.

This is kind of a cheesy optimization, but it turns out that the use case is quite common.
The pattern goes like this:

    (1) Create <style> element.
    (2) Add it to the document's <head>.
    (3) .addRule() one rule through the CSSOM API.

Prior to this patch, (3) would always cause a full (deferred) style recalc.

Now that we exclude empty style sheets from the document's (effective) active set,
we can piggyback on the style invalidation analysis when transitioning from an empty
sheet to a single-rule sheet.

In other words, add a special code path for the first rule insertion into an empty,
in-document style sheet to minimize the amount of invalidation that happens.

* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::didMutateRules):
(WebCore::CSSStyleSheet::insertRule):
* css/CSSStyleSheet.h:
(WebCore::CSSStyleSheet::RuleMutationScope::RuleMutationScope):
(WebCore::CSSStyleSheet::RuleMutationScope::~RuleMutationScope):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@153699 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/css/CSSStyleSheet.cpp
Source/WebCore/css/CSSStyleSheet.h