2010-11-22 Alexander Pavlov <apavlov@chromium.org>
authorapavlov@chromium.org <apavlov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Nov 2010 18:26:59 +0000 (18:26 +0000)
committerapavlov@chromium.org <apavlov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Nov 2010 18:26:59 +0000 (18:26 +0000)
        Reviewed by Pavel Feldman.

        Web Inspector: [REGRESSION] Contents of rules inside @media not displayed/editable
        https://bugs.webkit.org/show_bug.cgi?id=49804

        WebCore:
        * css/CSSImportRule.cpp:
        (WebCore::CSSImportRule::insertedIntoParent):
        * inspector/InspectorCSSAgent.cpp:
        (WebCore::InspectorCSSAgent::setStyleSheetText2):
        * inspector/InspectorStyleSheet.cpp:
        (WebCore::asCSSRuleList):
        (WebCore::InspectorStyleSheet::reparseStyleSheet):
        (WebCore::InspectorStyleSheet::setText):
        (WebCore::InspectorStyleSheet::addRule):
        (WebCore::InspectorStyleSheet::ruleForId):
        (WebCore::InspectorStyleSheet::ruleIndexByStyle):
        (WebCore::InspectorStyleSheet::ensureText):
        (WebCore::InspectorStyleSheet::ensureSourceData):
        (WebCore::InspectorStyleSheet::ensureFlatRules):
        (WebCore::InspectorStyleSheet::revalidateStyle):
        (WebCore::InspectorStyleSheet::buildArrayForRuleList):
        (WebCore::InspectorStyleSheet::fixUnparsedPropertyRanges):
        (WebCore::InspectorStyleSheet::collectFlatRules):
        * inspector/InspectorStyleSheet.h:

        LayoutTests:
        * inspector/resources/styles-new-API-1.css: Added.
        (@page):
        (@page :first):
        (#absent-id):
        (body):
        * inspector/resources/styles-new-API.css:
        * inspector/styles-new-API-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@72540 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/inspector/resources/styles-new-API-1.css [new file with mode: 0755]
LayoutTests/inspector/resources/styles-new-API.css
LayoutTests/inspector/styles-new-API-expected.txt
WebCore/ChangeLog
WebCore/css/CSSImportRule.cpp
WebCore/inspector/InspectorCSSAgent.cpp
WebCore/inspector/InspectorStyleSheet.cpp
WebCore/inspector/InspectorStyleSheet.h

index dc944ef..3bbe473 100644 (file)
@@ -1,3 +1,18 @@
+2010-11-22  Alexander Pavlov  <apavlov@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: [REGRESSION] Contents of rules inside @media not displayed/editable
+        https://bugs.webkit.org/show_bug.cgi?id=49804
+
+        * inspector/resources/styles-new-API-1.css: Added.
+        (@page):
+        (@page :first):
+        (#absent-id):
+        (body):
+        * inspector/resources/styles-new-API.css:
+        * inspector/styles-new-API-expected.txt:
+
 2010-11-22  Anton Muhin  <antonm@chromium.org>
 
         Not reviewed.  Amending expectations for Chromium.
diff --git a/LayoutTests/inspector/resources/styles-new-API-1.css b/LayoutTests/inspector/resources/styles-new-API-1.css
new file mode 100755 (executable)
index 0000000..7679ae8
--- /dev/null
@@ -0,0 +1,16 @@
+@page { margin: 2cm } /* All margins set to 2cm */
+
+@page :first {
+  margin-top: 10cm    /* Top margin on first page 10cm */
+}
+
+@media screen {
+
+#absent-id {
+}
+
+body {
+    property: imported-media-screen-stylesheet;
+}
+
+}
index 7b7b8e3..f4af03c 100644 (file)
@@ -1,7 +1,10 @@
+@import url("styles-new-API-1.css");
+
 html {
     font-weight: 400;
 }
 
+@media screen {
 body {
     font-size: 12px;
     foo: bar !
@@ -16,6 +19,7 @@ body {
 /* comment before selector */body.main1/* comment after selector */{/* comment */color: #F00BAA;zoo:moo /* not an !important unrecognized property */}/* comment */
 
 body.main2{background: green /* value !important comment */ !important /* no semicolon, very !important */}
+}
 
 body::after  {
     content: "After body";
index b62e03e..d6422cb 100644 (file)
@@ -18,6 +18,10 @@ body: [user-agent]
 
 rule
 body: []
+['property':'imported-media-screen-stylesheet' non-parsed] @[5-48] active
+
+rule
+body: []
 ['font-size':'12px'] @[5-21] active
 ['foo':'bar !
 
@@ -84,10 +88,13 @@ raw style
 
 === All stylesheets ===
 
-StyleSheet: 'html {
+StyleSheet: '@import url("styles-new-API-1.css");
+
+html {
     font-weight: 400;
 }
 
+@media screen {
 body {
     font-size: 12px;
     foo: bar !
@@ -102,6 +109,7 @@ body {
 /* comment before selector */body.main1/* comment after selector */{/* comment */color: #F00BAA;zoo:moo /* not an !important unrecognized property */}/* comment */
 
 body.main2{background: green /* value !important comment */ !important /* no semicolon, very !important */}
+}
 
 body::after  {
     content: "After body";
@@ -244,6 +252,10 @@ body: [user-agent]
 
 rule
 body: []
+['property':'imported-media-screen-stylesheet' non-parsed] @[5-48] active
+
+rule
+body: []
 ['font-size':'12px'] @[5-21] active
 ['foo':'bar !
 
index 352ea28..dbdb1b7 100644 (file)
@@ -1,3 +1,30 @@
+2010-11-22  Alexander Pavlov  <apavlov@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: [REGRESSION] Contents of rules inside @media not displayed/editable
+        https://bugs.webkit.org/show_bug.cgi?id=49804
+
+        * css/CSSImportRule.cpp:
+        (WebCore::CSSImportRule::insertedIntoParent):
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::setStyleSheetText2):
+        * inspector/InspectorStyleSheet.cpp:
+        (WebCore::asCSSRuleList):
+        (WebCore::InspectorStyleSheet::reparseStyleSheet):
+        (WebCore::InspectorStyleSheet::setText):
+        (WebCore::InspectorStyleSheet::addRule):
+        (WebCore::InspectorStyleSheet::ruleForId):
+        (WebCore::InspectorStyleSheet::ruleIndexByStyle):
+        (WebCore::InspectorStyleSheet::ensureText):
+        (WebCore::InspectorStyleSheet::ensureSourceData):
+        (WebCore::InspectorStyleSheet::ensureFlatRules):
+        (WebCore::InspectorStyleSheet::revalidateStyle):
+        (WebCore::InspectorStyleSheet::buildArrayForRuleList):
+        (WebCore::InspectorStyleSheet::fixUnparsedPropertyRanges):
+        (WebCore::InspectorStyleSheet::collectFlatRules):
+        * inspector/InspectorStyleSheet.h:
+
 2010-11-22  Ilya Tikhonovsky  <loislo@chromium.org>
 
         Reviewed by Pavel Feldman.
index e02d244..81ade39 100644 (file)
@@ -112,7 +112,7 @@ bool CSSImportRule::isLoading() const
 void CSSImportRule::insertedIntoParent()
 {
     CSSStyleSheet* parentSheet = parentStyleSheet();
-    if (!parentSheet)
+    if (!parentSheet || !parentSheet->document())
         return;
 
     CachedResourceLoader* cachedResourceLoader = parentSheet->document()->cachedResourceLoader();
index 37bf2b3..abc983e 100644 (file)
@@ -282,7 +282,9 @@ void InspectorCSSAgent::setStyleSheetText2(const String& styleSheetId, const Str
     if (!inspectorStyleSheet)
         return;
 
-    inspectorStyleSheet->setText(text);
+    bool success = inspectorStyleSheet->setText(text);
+    if (success)
+        inspectorStyleSheet->reparseStyleSheet(text);
 }
 
 void InspectorCSSAgent::setPropertyText2(const String& fullStyleId, long propertyIndex, const String& text, bool overwrite, RefPtr<InspectorValue>* result)
index a5b2dfe..9f4ca37 100644 (file)
@@ -27,6 +27,8 @@
 
 #if ENABLE(INSPECTOR)
 
+#include "CSSImportRule.h"
+#include "CSSMediaRule.h"
 #include "CSSParser.h"
 #include "CSSPropertySourceData.h"
 #include "CSSRule.h"
@@ -43,6 +45,7 @@
 #include "InspectorValues.h"
 #include "Node.h"
 #include "StyleSheetList.h"
+#include "WebKitCSSKeyframesRule.h"
 
 #include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
@@ -99,6 +102,35 @@ RefPtr<WebCore::CSSRuleSourceData> ParsedStyleSheet::ruleSourceDataAt(unsigned i
 
 namespace WebCore {
 
+static PassRefPtr<CSSRuleList> asCSSRuleList(StyleBase* styleBase)
+{
+    if (!styleBase)
+        return 0;
+
+    if (styleBase->isCSSStyleSheet())
+        return CSSRuleList::create(static_cast<CSSStyleSheet*>(styleBase), true);
+    if (styleBase->isRule()) {
+        unsigned ruleType = static_cast<CSSRule*>(styleBase)->type();
+        RefPtr<CSSRuleList> result = 0;
+
+        switch (ruleType) {
+        case CSSRule::MEDIA_RULE:
+            result = static_cast<CSSMediaRule*>(styleBase)->cssRules();
+            break;
+        case CSSRule::WEBKIT_KEYFRAMES_RULE:
+            result = static_cast<WebKitCSSKeyframesRule*>(styleBase)->cssRules();
+            break;
+        case CSSRule::IMPORT_RULE:
+        case CSSRule::PAGE_RULE:
+        default:
+            return 0;
+        }
+
+        return result.release();
+    }
+    return 0;
+}
+
 PassRefPtr<InspectorObject> InspectorStyle::buildObjectForStyle() const
 {
     RefPtr<InspectorObject> result = InspectorObject::create();
@@ -529,17 +561,22 @@ InspectorStyleSheet::~InspectorStyleSheet()
     delete m_parsedStyleSheet;
 }
 
+void InspectorStyleSheet::reparseStyleSheet(const String& text)
+{
+    for (unsigned i = 0, size = m_pageStyleSheet->length(); i < size; ++i)
+        m_pageStyleSheet->remove(i);
+    m_pageStyleSheet->parseString(text, m_pageStyleSheet->useStrictParsing());
+    m_inspectorStyles.clear();
+}
+
 bool InspectorStyleSheet::setText(const String& text)
 {
     if (!m_parsedStyleSheet)
         return false;
 
     m_parsedStyleSheet->setText(text);
-    for (unsigned i = 0, size = m_pageStyleSheet->length(); i < size; ++i)
-        m_pageStyleSheet->remove(i);
-    m_inspectorStyles.clear();
+    m_flatRules.clear();
 
-    m_pageStyleSheet->parseString(text, m_pageStyleSheet->useStrictParsing());
     return true;
 }
 
@@ -584,7 +621,8 @@ CSSStyleRule* InspectorStyleSheet::addRule(const String& selector)
 
     styleSheetText += selector;
     styleSheetText += " {}";
-    m_parsedStyleSheet->setText(styleSheetText);
+    // Using setText() as this operation changes the style sheet rule set.
+    setText(styleSheetText);
 
     return rule;
 }
@@ -600,17 +638,9 @@ CSSStyleRule* InspectorStyleSheet::ruleForId(const InspectorCSSId& id) const
     if (!ok)
         return 0;
 
-    unsigned currentIndex = 0;
-    for (unsigned i = 0, size = m_pageStyleSheet->length(); i < size; ++i) {
-        CSSStyleRule* rule = InspectorCSSAgent::asCSSStyleRule(m_pageStyleSheet->item(i));
-        if (!rule)
-            continue;
-        if (index == currentIndex)
-            return rule;
+    ensureFlatRules();
+    return index >= m_flatRules.size() ? 0 : m_flatRules.at(index);
 
-        ++currentIndex;
-    }
-    return 0;
 }
 
 PassRefPtr<InspectorObject> InspectorStyleSheet::buildObjectForStyleSheet()
@@ -767,51 +797,6 @@ InspectorCSSId InspectorStyleSheet::ruleOrStyleId(CSSStyleDeclaration* style) co
     return InspectorCSSId();
 }
 
-void InspectorStyleSheet::fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData, const String& styleSheetText)
-{
-    Vector<CSSPropertySourceData>& propertyData = ruleData->styleSourceData->propertyData;
-    unsigned size = propertyData.size();
-    if (!size)
-        return;
-
-    unsigned styleStart = ruleData->styleSourceData->styleBodyRange.start;
-    const UChar* characters = styleSheetText.characters();
-    CSSPropertySourceData* nextData = &(propertyData.at(0));
-    for (unsigned i = 0; i < size; ++i) {
-        CSSPropertySourceData* currentData = nextData;
-        nextData = i < size - 1 ? &(propertyData.at(i + 1)) : 0;
-
-        if (currentData->parsedOk)
-            continue;
-        if (currentData->range.end > 0 && characters[styleStart + currentData->range.end - 1] == ';')
-            continue;
-
-        unsigned propertyEndInStyleSheet;
-        if (!nextData)
-            propertyEndInStyleSheet = ruleData->styleSourceData->styleBodyRange.end - 1;
-        else
-            propertyEndInStyleSheet = styleStart + nextData->range.start - 1;
-
-        while (isHTMLSpace(characters[propertyEndInStyleSheet]))
-            --propertyEndInStyleSheet;
-
-        // propertyEndInStyleSheet points at the last property text character.
-        unsigned newPropertyEnd = propertyEndInStyleSheet - styleStart + 1; // Exclusive of the last property text character.
-        if (currentData->range.end != newPropertyEnd) {
-            currentData->range.end = newPropertyEnd;
-            unsigned valueStartInStyleSheet = styleStart + currentData->range.start + currentData->name.length();
-            while (valueStartInStyleSheet < propertyEndInStyleSheet && characters[valueStartInStyleSheet] != ':')
-                ++valueStartInStyleSheet;
-            if (valueStartInStyleSheet < propertyEndInStyleSheet)
-                ++valueStartInStyleSheet; // Shift past the ':'.
-            while (valueStartInStyleSheet < propertyEndInStyleSheet && isHTMLSpace(characters[valueStartInStyleSheet]))
-                ++valueStartInStyleSheet;
-            // Need to exclude the trailing ';' from the property value.
-            currentData->value = styleSheetText.substring(valueStartInStyleSheet, propertyEndInStyleSheet - valueStartInStyleSheet + (characters[propertyEndInStyleSheet] == ';' ? 0 : 1));
-        }
-    }
-}
-
 Document* InspectorStyleSheet::ownerDocument() const
 {
     return m_pageStyleSheet->document();
@@ -824,12 +809,10 @@ RefPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataFor(CSSStyleDeclara
 
 unsigned InspectorStyleSheet::ruleIndexByStyle(CSSStyleDeclaration* pageStyle) const
 {
+    ensureFlatRules();
     unsigned index = 0;
-    for (unsigned i = 0, size = m_pageStyleSheet->length(); i < size; ++i) {
-        CSSStyleRule* rule = InspectorCSSAgent::asCSSStyleRule(m_pageStyleSheet->item(i));
-        if (!rule)
-            continue;
-        if (rule->style() == pageStyle)
+    for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) {
+        if (m_flatRules.at(i)->style() == pageStyle)
             return index;
 
         ++index;
@@ -861,6 +844,7 @@ bool InspectorStyleSheet::ensureText() const
     bool success = originalStyleSheetText(&text);
     if (success)
         m_parsedStyleSheet->setText(text);
+    // No need to clear m_flatRules here - it's empty.
 
     return success;
 }
@@ -873,17 +857,17 @@ bool InspectorStyleSheet::ensureSourceData()
     if (!m_parsedStyleSheet->hasText())
         return false;
 
-    RefPtr<CSSStyleSheet> newStyleSheet = CSSStyleSheet::create(pageStyleSheet() ? pageStyleSheet()->document() : 0);
+    RefPtr<CSSStyleSheet> newStyleSheet = CSSStyleSheet::create();
     CSSParser p;
     StyleRuleRangeMap ruleRangeMap;
     p.parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), 0, &ruleRangeMap);
     OwnPtr<ParsedStyleSheet::SourceData> rangesVector(new ParsedStyleSheet::SourceData());
 
-    for (unsigned i = 0, length = newStyleSheet->length(); i < length; ++i) {
-        CSSStyleRule* rule = InspectorCSSAgent::asCSSStyleRule(newStyleSheet->item(i));
-        if (!rule)
-            continue;
-        StyleRuleRangeMap::iterator it = ruleRangeMap.find(rule);
+    Vector<CSSStyleRule*> rules;
+    RefPtr<CSSRuleList> ruleList = asCSSRuleList(newStyleSheet.get());
+    collectFlatRules(ruleList, &rules);
+    for (unsigned i = 0, size = rules.size(); i < size; ++i) {
+        StyleRuleRangeMap::iterator it = ruleRangeMap.find(rules.at(i));
         if (it != ruleRangeMap.end()) {
             fixUnparsedPropertyRanges(it->second.get(), m_parsedStyleSheet->text());
             rangesVector->append(it->second);
@@ -894,6 +878,13 @@ bool InspectorStyleSheet::ensureSourceData()
     return m_parsedStyleSheet->hasSourceData();
 }
 
+void InspectorStyleSheet::ensureFlatRules() const
+{
+    // We are fine with redoing this for empty stylesheets as this will run fast.
+    if (m_flatRules.isEmpty())
+        collectFlatRules(asCSSRuleList(pageStyleSheet()), &m_flatRules);
+}
+
 bool InspectorStyleSheet::setStyleText(CSSStyleDeclaration* style, const String& text)
 {
     if (!pageStyleSheet())
@@ -939,18 +930,6 @@ bool InspectorStyleSheet::styleSheetTextWithChangedStyle(CSSStyleDeclaration* st
     return true;
 }
 
-CSSStyleRule* InspectorStyleSheet::findPageRuleWithStyle(CSSStyleDeclaration* style)
-{
-    for (unsigned i = 0, size = m_pageStyleSheet->length(); i < size; ++i) {
-        CSSStyleRule* rule = InspectorCSSAgent::asCSSStyleRule(m_pageStyleSheet->item(i));
-        if (!rule)
-            continue;
-        if (rule->style() == style)
-            return rule;
-    }
-    return 0;
-}
-
 InspectorCSSId InspectorStyleSheet::ruleId(CSSStyleRule* rule) const
 {
     return ruleOrStyleId(rule->style());
@@ -962,12 +941,9 @@ void InspectorStyleSheet::revalidateStyle(CSSStyleDeclaration* pageStyle)
         return;
 
     m_isRevalidating = true;
-    CSSStyleSheet* parsedSheet = m_parsedStyleSheet->cssStyleSheet();
-    for (unsigned i = 0, size = parsedSheet->length(); i < size; ++i) {
-        StyleBase* styleBase = parsedSheet->item(i);
-        CSSStyleRule* parsedRule = InspectorCSSAgent::asCSSStyleRule(styleBase);
-        if (!parsedRule)
-            continue;
+    ensureFlatRules();
+    for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) {
+        CSSStyleRule* parsedRule = m_flatRules.at(i);
         if (parsedRule->style() == pageStyle) {
             if (parsedRule->style()->cssText() != pageStyle->cssText()) {
                 // Clear the disabled properties for the invalid style here.
@@ -1020,14 +996,77 @@ PassRefPtr<InspectorArray> InspectorStyleSheet::buildArrayForRuleList(CSSRuleLis
     if (!ruleList)
         return result.release();
 
-    for (unsigned i = 0, size = ruleList->length(); i < size; ++i) {
-        CSSStyleRule* rule = InspectorCSSAgent::asCSSStyleRule(ruleList->item(i));
-        if (!rule)
+    RefPtr<CSSRuleList> refRuleList = ruleList;
+    Vector<CSSStyleRule*> rules;
+    collectFlatRules(refRuleList, &rules);
+
+    for (unsigned i = 0, size = rules.size(); i < size; ++i)
+        result->pushObject(buildObjectForRule(rules.at(i)));
+
+    return result.release();
+}
+
+void InspectorStyleSheet::fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData, const String& styleSheetText)
+{
+    Vector<CSSPropertySourceData>& propertyData = ruleData->styleSourceData->propertyData;
+    unsigned size = propertyData.size();
+    if (!size)
+        return;
+
+    unsigned styleStart = ruleData->styleSourceData->styleBodyRange.start;
+    const UChar* characters = styleSheetText.characters();
+    CSSPropertySourceData* nextData = &(propertyData.at(0));
+    for (unsigned i = 0; i < size; ++i) {
+        CSSPropertySourceData* currentData = nextData;
+        nextData = i < size - 1 ? &(propertyData.at(i + 1)) : 0;
+
+        if (currentData->parsedOk)
             continue;
+        if (currentData->range.end > 0 && characters[styleStart + currentData->range.end - 1] == ';')
+            continue;
+
+        unsigned propertyEndInStyleSheet;
+        if (!nextData)
+            propertyEndInStyleSheet = ruleData->styleSourceData->styleBodyRange.end - 1;
+        else
+            propertyEndInStyleSheet = styleStart + nextData->range.start - 1;
+
+        while (isHTMLSpace(characters[propertyEndInStyleSheet]))
+            --propertyEndInStyleSheet;
 
-        result->pushObject(buildObjectForRule(rule));
+        // propertyEndInStyleSheet points at the last property text character.
+        unsigned newPropertyEnd = propertyEndInStyleSheet - styleStart + 1; // Exclusive of the last property text character.
+        if (currentData->range.end != newPropertyEnd) {
+            currentData->range.end = newPropertyEnd;
+            unsigned valueStartInStyleSheet = styleStart + currentData->range.start + currentData->name.length();
+            while (valueStartInStyleSheet < propertyEndInStyleSheet && characters[valueStartInStyleSheet] != ':')
+                ++valueStartInStyleSheet;
+            if (valueStartInStyleSheet < propertyEndInStyleSheet)
+                ++valueStartInStyleSheet; // Shift past the ':'.
+            while (valueStartInStyleSheet < propertyEndInStyleSheet && isHTMLSpace(characters[valueStartInStyleSheet]))
+                ++valueStartInStyleSheet;
+            // Need to exclude the trailing ';' from the property value.
+            currentData->value = styleSheetText.substring(valueStartInStyleSheet, propertyEndInStyleSheet - valueStartInStyleSheet + (characters[propertyEndInStyleSheet] == ';' ? 0 : 1));
+        }
+    }
+}
+
+void InspectorStyleSheet::collectFlatRules(PassRefPtr<CSSRuleList> ruleList, Vector<CSSStyleRule*>* result)
+{
+    if (!ruleList)
+        return;
+
+    for (unsigned i = 0, size = ruleList->length(); i < size; ++i) {
+        CSSRule* rule = ruleList->item(i);
+        CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(rule);
+        if (styleRule)
+            result->append(styleRule);
+        else {
+            RefPtr<CSSRuleList> childRuleList = asCSSRuleList(rule);
+            if (childRuleList)
+                collectFlatRules(childRuleList, result);
+        }
     }
-    return result.release();
 }
 
 
index 2a14bb9..a0622fe 100644 (file)
@@ -158,6 +158,7 @@ public:
 
     const String& id() const { return m_id; }
     CSSStyleSheet* pageStyleSheet() const { return m_pageStyleSheet; }
+    void reparseStyleSheet(const String&);
     bool setText(const String&);
     bool setRuleSelector(const InspectorCSSId&, const String& selector);
     CSSStyleRule* addRule(const String& selector);
@@ -173,7 +174,6 @@ public:
 protected:
     bool canBind() const { return m_origin != "userAgent" && m_origin != "user"; }
     InspectorCSSId ruleOrStyleId(CSSStyleDeclaration* style) const;
-    void fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData, const String& styleSheetText);
     virtual bool text(String* result) const;
     virtual Document* ownerDocument() const;
     virtual RefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* style) const;
@@ -187,10 +187,12 @@ protected:
     virtual bool setStyleText(CSSStyleDeclaration*, const String&);
 
 private:
+    static void fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData, const String& styleSheetText);
+    static void collectFlatRules(PassRefPtr<CSSRuleList>, Vector<CSSStyleRule*>* result);
     bool ensureText() const;
     bool ensureSourceData();
+    void ensureFlatRules() const;
     bool styleSheetTextWithChangedStyle(CSSStyleDeclaration*, const String& newStyleText, String* result);
-    CSSStyleRule* findPageRuleWithStyle(CSSStyleDeclaration*);
     InspectorCSSId ruleId(CSSStyleRule* rule) const;
     InspectorCSSId styleId(CSSStyleDeclaration* style) const { return ruleOrStyleId(style); }
     void revalidateStyle(CSSStyleDeclaration*);
@@ -199,7 +201,6 @@ private:
     bool inlineStyleSheetText(String* result) const;
     PassRefPtr<InspectorArray> buildArrayForRuleList(CSSRuleList*);
 
-
     String m_id;
     CSSStyleSheet* m_pageStyleSheet;
     String m_origin;
@@ -207,6 +208,7 @@ private:
     bool m_isRevalidating;
     ParsedStyleSheet* m_parsedStyleSheet;
     InspectorStyleMap m_inspectorStyles;
+    mutable Vector<CSSStyleRule*> m_flatRules;
 
     friend class InspectorStyle;
 };