Title: [120469] trunk/Source/WebCore
Revision
120469
Author
[email protected]
Date
2012-06-15 09:36:17 -0700 (Fri, 15 Jun 2012)

Log Message

Web Inspector: CSSParser::parseSheet() should provide ready-to-use source data
https://bugs.webkit.org/show_bug.cgi?id=88646

Reviewed by Antti Koivisto.

This change moves the post-processing step from InspectorStyleSheet into CSSParser, so that
CSSParser::parseSheet() will return a ready-to-use list with style rule source code data.
Also, universal data structures are introduced, which allow for the full rule source data tree building.

No new tests, as this is a refactoring.

* css/CSSParser.cpp: Use universal data structures, which can be used for building the full rule tree.
(WebCore::CSSParser::CSSParser):
(WebCore::CSSParser::setupParser):
(WebCore::CSSParser::parseSheet): Return ready-to-use source code data entries rather than an intermediate structure.
(WebCore::CSSParser::parseDeclaration):
(WebCore::CSSParser::addNewRuleToSourceTree):
(WebCore):
(WebCore::CSSParser::popRuleData):
(WebCore::CSSParser::createStyleRule):
(WebCore::CSSParser::fixUnparsedPropertyRanges): Moved in from InspectorStyleSheet.
(WebCore::CSSParser::markSelectorListStart):
(WebCore::CSSParser::markSelectorListEnd):
(WebCore::CSSParser::markRuleBodyStart):
(WebCore::CSSParser::markRuleBodyEnd):
(WebCore::CSSParser::markPropertyEnd):
* css/CSSParser.h:
(CSSParser):
(WebCore::CSSParser::resetPropertyRange): Renamed.
(WebCore::CSSParser::isExtractingSourceData): A convenience check.
* css/CSSPropertySourceData.h: Introduce the RuleSourceDataList typedef.
(WebCore):
* inspector/InspectorStyleSheet.cpp: Make use of RuleSourceDataList and follow the CSSParser::parse*() API changes.
(ParsedStyleSheet::sourceData):
(ParsedStyleSheet):
(ParsedStyleSheet::setSourceData):
(WebCore::InspectorStyleSheet::ensureSourceData): Remove source data postprocessing, follow the new parseSheet() API.
* inspector/InspectorStyleSheet.h:
(WebCore::InspectorCSSId::InspectorCSSId): Drive-by: uninitialized field fix.
(WebCore::InspectorStyleProperty::InspectorStyleProperty): Ditto.
(InspectorStyleSheet):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (120468 => 120469)


--- trunk/Source/WebCore/ChangeLog	2012-06-15 16:03:35 UTC (rev 120468)
+++ trunk/Source/WebCore/ChangeLog	2012-06-15 16:36:17 UTC (rev 120469)
@@ -1,3 +1,47 @@
+2012-06-08  Alexander Pavlov  <[email protected]>
+
+        Web Inspector: CSSParser::parseSheet() should provide ready-to-use source data
+        https://bugs.webkit.org/show_bug.cgi?id=88646
+
+        Reviewed by Antti Koivisto.
+
+        This change moves the post-processing step from InspectorStyleSheet into CSSParser, so that
+        CSSParser::parseSheet() will return a ready-to-use list with style rule source code data.
+        Also, universal data structures are introduced, which allow for the full rule source data tree building.
+
+        No new tests, as this is a refactoring.
+
+        * css/CSSParser.cpp: Use universal data structures, which can be used for building the full rule tree.
+        (WebCore::CSSParser::CSSParser):
+        (WebCore::CSSParser::setupParser):
+        (WebCore::CSSParser::parseSheet): Return ready-to-use source code data entries rather than an intermediate structure.
+        (WebCore::CSSParser::parseDeclaration):
+        (WebCore::CSSParser::addNewRuleToSourceTree):
+        (WebCore):
+        (WebCore::CSSParser::popRuleData):
+        (WebCore::CSSParser::createStyleRule):
+        (WebCore::CSSParser::fixUnparsedPropertyRanges): Moved in from InspectorStyleSheet.
+        (WebCore::CSSParser::markSelectorListStart):
+        (WebCore::CSSParser::markSelectorListEnd):
+        (WebCore::CSSParser::markRuleBodyStart):
+        (WebCore::CSSParser::markRuleBodyEnd):
+        (WebCore::CSSParser::markPropertyEnd):
+        * css/CSSParser.h:
+        (CSSParser):
+        (WebCore::CSSParser::resetPropertyRange): Renamed.
+        (WebCore::CSSParser::isExtractingSourceData): A convenience check.
+        * css/CSSPropertySourceData.h: Introduce the RuleSourceDataList typedef.
+        (WebCore):
+        * inspector/InspectorStyleSheet.cpp: Make use of RuleSourceDataList and follow the CSSParser::parse*() API changes.
+        (ParsedStyleSheet::sourceData):
+        (ParsedStyleSheet):
+        (ParsedStyleSheet::setSourceData):
+        (WebCore::InspectorStyleSheet::ensureSourceData): Remove source data postprocessing, follow the new parseSheet() API.
+        * inspector/InspectorStyleSheet.h:
+        (WebCore::InspectorCSSId::InspectorCSSId): Drive-by: uninitialized field fix.
+        (WebCore::InspectorStyleProperty::InspectorStyleProperty): Ditto.
+        (InspectorStyleSheet):
+
 2012-06-15  Pavel Feldman  <[email protected]>
 
         Web Inspector: Long frame urls make all/errors/warnings/logs buttons inaccessible.

Modified: trunk/Source/WebCore/css/CSSParser.cpp (120468 => 120469)


--- trunk/Source/WebCore/css/CSSParser.cpp	2012-06-15 16:03:35 UTC (rev 120468)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2012-06-15 16:36:17 UTC (rev 120469)
@@ -238,12 +238,12 @@
     , m_hasFontFaceOnlyValues(false)
     , m_hadSyntacticallyValidCSSRule(false)
     , m_defaultNamespace(starAtom)
+    , m_parsedTextPrefixLength(0)
     , m_inStyleRuleOrDeclaration(false)
     , m_selectorListRange(0, 0)
     , m_ruleBodyRange(0, 0)
     , m_propertyRange(UINT_MAX, UINT_MAX)
-    , m_ruleRangeMap(0)
-    , m_currentRuleData(0)
+    , m_ruleSourceDataResult(0)
     , m_parsingMode(NormalMode)
     , m_currentCharacter(0)
     , m_tokenStart(0)
@@ -288,15 +288,16 @@
 
 void CSSParser::setupParser(const char* prefix, const String& string, const char* suffix)
 {
-    int length = string.length() + strlen(prefix) + strlen(suffix) + 1;
+    m_parsedTextPrefixLength = strlen(prefix);
+    int length = string.length() + m_parsedTextPrefixLength + strlen(suffix) + 1;
 
     m_dataStart = adoptArrayPtr(new UChar[length]);
-    for (unsigned i = 0; i < strlen(prefix); i++)
+    for (unsigned i = 0; i < m_parsedTextPrefixLength; i++)
         m_dataStart[i] = prefix[i];
 
-    memcpy(m_dataStart.get() + strlen(prefix), string.characters(), string.length() * sizeof(UChar));
+    memcpy(m_dataStart.get() + m_parsedTextPrefixLength, string.characters(), string.length() * sizeof(UChar));
 
-    unsigned start = strlen(prefix) + string.length();
+    unsigned start = m_parsedTextPrefixLength + string.length();
     unsigned end = start + strlen(suffix);
     for (unsigned i = start; i < end; i++)
         m_dataStart[i] = suffix[i - start];
@@ -307,21 +308,19 @@
     resetRuleBodyMarks();
 }
 
-void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, int startLineNumber, StyleRuleRangeMap* ruleRangeMap)
+void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, int startLineNumber, RuleSourceDataList* ruleSourceDataResult)
 {
     setStyleSheet(sheet);
     m_defaultNamespace = starAtom; // Reset the default namespace.
-    m_ruleRangeMap = ruleRangeMap;
-    if (ruleRangeMap) {
-        m_currentRuleData = CSSRuleSourceData::create();
-        m_currentRuleData->styleSourceData = CSSStyleSourceData::create();
-    }
+    if (ruleSourceDataResult)
+        m_currentRuleDataStack = adoptPtr(new RuleSourceDataList());
+    m_ruleSourceDataResult = ruleSourceDataResult;
 
     m_lineNumber = startLineNumber;
     setupParser("", string, "");
     cssyyparse(this);
-    m_ruleRangeMap = 0;
-    m_currentRuleData = 0;
+    m_currentRuleDataStack.clear();
+    m_ruleSourceDataResult = 0;
     m_rule = 0;
 }
 
@@ -1126,16 +1125,19 @@
     m_selectorListForParseSelector = 0;
 }
 
-bool CSSParser::parseDeclaration(StylePropertySet* declaration, const String& string, RefPtr<CSSStyleSourceData>* styleSourceData, StyleSheetContents* contextStyleSheet)
+bool CSSParser::parseDeclaration(StylePropertySet* declaration, const String& string, PassRefPtr<CSSStyleSourceData> prpStyleSourceData, StyleSheetContents* contextStyleSheet)
 {
     // Length of the "@-webkit-decls{" prefix.
     static const unsigned prefixLength = 15;
 
     setStyleSheet(contextStyleSheet);
 
+    RefPtr<CSSStyleSourceData> styleSourceData = prpStyleSourceData;
     if (styleSourceData) {
-        m_currentRuleData = CSSRuleSourceData::create();
-        m_currentRuleData->styleSourceData = CSSStyleSourceData::create();
+        m_currentRuleDataStack = adoptPtr(new RuleSourceDataList());
+        RefPtr<CSSRuleSourceData> data = ""
+        data->styleSourceData = styleSourceData;
+        m_currentRuleDataStack->append(data);
         m_inStyleRuleOrDeclaration = true;
     }
 
@@ -1152,20 +1154,22 @@
         clearProperties();
     }
 
-    if (m_currentRuleData) {
-        m_currentRuleData->styleSourceData->styleBodyRange.start = 0;
-        m_currentRuleData->styleSourceData->styleBodyRange.end = string.length();
-        for (Vector<CSSPropertySourceData>::iterator it = m_currentRuleData->styleSourceData->propertyData.begin(), endIt = m_currentRuleData->styleSourceData->propertyData.end(); it != endIt; ++it) {
-            (*it).range.start -= prefixLength;
-            (*it).range.end -= prefixLength;
+    if (styleSourceData) {
+        ASSERT(!m_currentRuleDataStack->isEmpty());
+        CSSRuleSourceData* ruleData = m_currentRuleDataStack->last().get();
+        ruleData->styleSourceData->styleBodyRange.start = 0;
+        ruleData->styleSourceData->styleBodyRange.end = string.length();
+        for (size_t i = 0, size = ruleData->styleSourceData->propertyData.size(); i < size; ++i) {
+            CSSPropertySourceData& propertyData = ruleData->styleSourceData->propertyData.at(i);
+            propertyData.range.start -= prefixLength;
+            propertyData.range.end -= prefixLength;
         }
-    }
+        fixUnparsedPropertyRanges(ruleData);
 
-    if (styleSourceData) {
-        *styleSourceData = m_currentRuleData->styleSourceData.release();
-        m_currentRuleData = 0;
+        m_currentRuleDataStack.clear();
         m_inStyleRuleOrDeclaration = false;
     }
+
     return ok;
 }
 
@@ -9257,6 +9261,27 @@
     return listPtr;
 }
 
+void CSSParser::addNewRuleToSourceTree(PassRefPtr<CSSRuleSourceData> rule)
+{
+    // Precondition: (isExtractingSourceData()).
+    if (!m_ruleSourceDataResult)
+        return;
+
+    // FIXME: This temporarily builds a flat style rule data list, to avoid the client code breakage.
+    m_ruleSourceDataResult->append(rule);
+}
+
+PassRefPtr<CSSRuleSourceData> CSSParser::popRuleData()
+{
+    if (!m_ruleSourceDataResult)
+        return 0;
+
+    ASSERT(!m_currentRuleDataStack->isEmpty());
+    RefPtr<CSSRuleSourceData> data = ""
+    m_currentRuleDataStack->removeLast();
+    return data.release();
+}
+
 StyleRuleKeyframes* CSSParser::createKeyframesRule()
 {
     m_allowImportRules = m_allowNamespaceDeclarations = false;
@@ -9279,18 +9304,19 @@
         rule->setProperties(createStylePropertySet());
         result = rule.get();
         m_parsedRules.append(rule.release());
-        if (m_ruleRangeMap) {
-            ASSERT(m_currentRuleData);
-            m_currentRuleData->styleSourceData->styleBodyRange = m_ruleBodyRange;
-            m_currentRuleData->selectorListRange = m_selectorListRange;
-            m_ruleRangeMap->set(result, m_currentRuleData.release());
-            m_currentRuleData = CSSRuleSourceData::create();
-            m_currentRuleData->styleSourceData = CSSStyleSourceData::create();
+        if (isExtractingSourceData()) {
+            RefPtr<CSSRuleSourceData> currentRuleData = popRuleData();
+            currentRuleData->styleSourceData->styleBodyRange = m_ruleBodyRange;
+            currentRuleData->selectorListRange = m_selectorListRange;
+            fixUnparsedPropertyRanges(currentRuleData.get());
+            addNewRuleToSourceTree(currentRuleData.release());
             m_inStyleRuleOrDeclaration = false;
         }
     }
-    resetSelectorListMarks();
-    resetRuleBodyMarks();
+    if (isExtractingSourceData()) {
+        resetSelectorListMarks();
+        resetRuleBodyMarks();
+    }
     clearProperties();
     return result;
 }
@@ -9496,14 +9522,61 @@
     media->setLastLine(m_lineNumber);
 }
 
+void CSSParser::fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData)
+{
+    Vector<CSSPropertySourceData>& propertyData = ruleData->styleSourceData->propertyData;
+    unsigned size = propertyData.size();
+    if (!size)
+        return;
+
+    unsigned styleStart = ruleData->styleSourceData->styleBodyRange.start;
+    const UChar* characters = m_dataStart.get() + m_parsedTextPrefixLength;
+    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 = String(characters + valueStartInStyleSheet, propertyEndInStyleSheet - valueStartInStyleSheet + (characters[propertyEndInStyleSheet] == ';' ? 0 : 1));
+        }
+    }
+}
+
 void CSSParser::markSelectorListStart()
 {
+    if (!isExtractingSourceData())
+        return;
     m_selectorListRange.start = m_tokenStart - m_dataStart.get();
 }
 
 void CSSParser::markSelectorListEnd()
 {
-    if (!m_currentRuleData)
+    if (!isExtractingSourceData())
         return;
     UChar* listEnd = m_tokenStart;
     while (listEnd > m_dataStart.get() + 1) {
@@ -9513,10 +9586,15 @@
             break;
     }
     m_selectorListRange.end = listEnd - m_dataStart.get();
+    RefPtr<CSSRuleSourceData> data = ""
+    data->styleSourceData = CSSStyleSourceData::create();
+    m_currentRuleDataStack->append(data);
 }
 
 void CSSParser::markRuleBodyStart()
 {
+    if (!isExtractingSourceData())
+        return;
     unsigned offset = m_tokenStart - m_dataStart.get();
     if (*m_tokenStart == '{')
         ++offset; // Skip the rule body opening brace.
@@ -9527,6 +9605,8 @@
 
 void CSSParser::markRuleBodyEnd()
 {
+    if (!isExtractingSourceData())
+        return;
     unsigned offset = m_tokenStart - m_dataStart.get();
     if (offset > m_ruleBodyRange.end)
         m_ruleBodyRange.end = offset;
@@ -9543,11 +9623,12 @@
 {
     if (!m_inStyleRuleOrDeclaration)
         return;
+
     unsigned offset = m_tokenStart - m_dataStart.get();
     if (*m_tokenStart == ';') // Include semicolon into the property text.
         ++offset;
     m_propertyRange.end = offset;
-    if (m_propertyRange.start != UINT_MAX && m_currentRuleData) {
+    if (m_propertyRange.start != UINT_MAX && !m_currentRuleDataStack->isEmpty()) {
         // This stuff is only executed when the style data retrieval is requested by client.
         const unsigned start = m_propertyRange.start;
         const unsigned end = m_propertyRange.end;
@@ -9561,10 +9642,10 @@
         String name = propertyString.left(colonIndex).stripWhiteSpace();
         String value = propertyString.substring(colonIndex + 1, propertyString.length()).stripWhiteSpace();
         // The property range is relative to the declaration start offset.
-        m_currentRuleData->styleSourceData->propertyData.append(
+        m_currentRuleDataStack->last()->styleSourceData->propertyData.append(
             CSSPropertySourceData(name, value, isImportantFound, isPropertyParsed, SourceRange(start - m_ruleBodyRange.start, end - m_ruleBodyRange.start)));
     }
-    resetPropertyMarks();
+    resetPropertyRange();
 }
 
 static CSSPropertyID cssPropertyID(const UChar* propertyName, unsigned length)

Modified: trunk/Source/WebCore/css/CSSParser.h (120468 => 120469)


--- trunk/Source/WebCore/css/CSSParser.h	2012-06-15 16:03:35 UTC (rev 120468)
+++ trunk/Source/WebCore/css/CSSParser.h	2012-06-15 16:36:17 UTC (rev 120469)
@@ -70,7 +70,7 @@
 
     ~CSSParser();
 
-    void parseSheet(StyleSheetContents*, const String&, int startLineNumber = 0, StyleRuleRangeMap* = 0);
+    void parseSheet(StyleSheetContents*, const String&, int startLineNumber = 0, RuleSourceDataList* = 0);
     PassRefPtr<StyleRuleBase> parseRule(StyleSheetContents*, const String&);
     PassRefPtr<StyleKeyframe> parseKeyframeRule(StyleSheetContents*, const String&);
     static bool parseValue(StylePropertySet*, CSSPropertyID, const String&, bool important, CSSParserMode, StyleSheetContents*);
@@ -78,7 +78,7 @@
     static bool parseSystemColor(RGBA32& color, const String&, Document*);
     static PassRefPtr<CSSValueList> parseFontFaceValue(const AtomicString&);
     PassRefPtr<CSSPrimitiveValue> parseValidPrimitive(int ident, CSSParserValue*);
-    bool parseDeclaration(StylePropertySet*, const String&, RefPtr<CSSStyleSourceData>*, StyleSheetContents* contextStyleSheet);
+    bool parseDeclaration(StylePropertySet*, const String&, PassRefPtr<CSSStyleSourceData>, StyleSheetContents* contextStyleSheet);
     PassOwnPtr<MediaQuery> parseMediaQuery(const String&);
 
     void addProperty(CSSPropertyID, PassRefPtr<CSSValue>, bool important, bool implicit = false);
@@ -318,21 +318,30 @@
     AtomicString m_defaultNamespace;
 
     // tokenizer methods and data
+    size_t m_parsedTextPrefixLength;
     bool m_inStyleRuleOrDeclaration;
     SourceRange m_selectorListRange;
     SourceRange m_ruleBodyRange;
     SourceRange m_propertyRange;
-    StyleRuleRangeMap* m_ruleRangeMap;
-    RefPtr<CSSRuleSourceData> m_currentRuleData;
+    OwnPtr<RuleSourceDataList> m_currentRuleDataStack;
+    RuleSourceDataList* m_ruleSourceDataResult;
+
+    void fixUnparsedPropertyRanges(CSSRuleSourceData*);
+    void markStyleRuleHeaderStart();
+    void markRuleHeaderEnd();
+
     void markSelectorListStart();
     void markSelectorListEnd();
     void markRuleBodyStart();
     void markRuleBodyEnd();
     void markPropertyStart();
     void markPropertyEnd(bool isImportantFound, bool isPropertyParsed);
+    void addNewRuleToSourceTree(PassRefPtr<CSSRuleSourceData>);
+    PassRefPtr<CSSRuleSourceData> popRuleData();
     void resetSelectorListMarks() { m_selectorListRange.start = m_selectorListRange.end = 0; }
     void resetRuleBodyMarks() { m_ruleBodyRange.start = m_ruleBodyRange.end = 0; }
-    void resetPropertyMarks() { m_propertyRange.start = m_propertyRange.end = UINT_MAX; }
+    void resetPropertyRange() { m_propertyRange.start = m_propertyRange.end = UINT_MAX; }
+    bool isExtractingSourceData() const { return !!m_currentRuleDataStack; }
     int lex(void* yylval);
     int token() { return m_token; }
 

Modified: trunk/Source/WebCore/css/CSSPropertySourceData.h (120468 => 120469)


--- trunk/Source/WebCore/css/CSSPropertySourceData.h	2012-06-15 16:03:35 UTC (rev 120468)
+++ trunk/Source/WebCore/css/CSSPropertySourceData.h	2012-06-15 16:36:17 UTC (rev 120469)
@@ -83,6 +83,9 @@
     Vector<CSSPropertySourceData> propertyData;
 };
 
+class CSSRuleSourceData;
+typedef Vector<RefPtr<CSSRuleSourceData> > RuleSourceDataList;
+
 struct CSSRuleSourceData : public RefCounted<CSSRuleSourceData> {
     static PassRefPtr<CSSRuleSourceData> create()
     {

Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp (120468 => 120469)


--- trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp	2012-06-15 16:03:35 UTC (rev 120468)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp	2012-06-15 16:36:17 UTC (rev 120469)
@@ -60,18 +60,18 @@
 #include <wtf/text/StringBuilder.h>
 
 using WebCore::TypeBuilder::Array;
+using WebCore::RuleSourceDataList;
 
 class ParsedStyleSheet {
 public:
-    typedef Vector<RefPtr<WebCore::CSSRuleSourceData> > SourceData;
     ParsedStyleSheet();
 
     WebCore::CSSStyleSheet* cssStyleSheet() const { return m_parserOutput; }
     const String& text() const { return m_text; }
     void setText(const String& text);
     bool hasText() const { return m_hasText; }
-    SourceData* sourceData() const { return m_sourceData.get(); }
-    void setSourceData(PassOwnPtr<SourceData> sourceData);
+    RuleSourceDataList* sourceData() const { return m_sourceData.get(); }
+    void setSourceData(PassOwnPtr<RuleSourceDataList>);
     bool hasSourceData() const { return m_sourceData; }
     RefPtr<WebCore::CSSRuleSourceData> ruleSourceDataAt(unsigned index) const;
 
@@ -81,7 +81,7 @@
     WebCore::CSSStyleSheet* m_parserOutput;
     String m_text;
     bool m_hasText;
-    OwnPtr<SourceData> m_sourceData;
+    OwnPtr<RuleSourceDataList> m_sourceData;
 };
 
 ParsedStyleSheet::ParsedStyleSheet()
@@ -97,7 +97,7 @@
     setSourceData(nullptr);
 }
 
-void ParsedStyleSheet::setSourceData(PassOwnPtr<SourceData> sourceData)
+void ParsedStyleSheet::setSourceData(PassOwnPtr<RuleSourceDataList> sourceData)
 {
     m_sourceData = sourceData;
 }
@@ -316,7 +316,7 @@
         RefPtr<StylePropertySet> tempMutableStyle = StylePropertySet::create();
         RefPtr<CSSStyleSourceData> sourceData = CSSStyleSourceData::create();
         CSSParser p(CSSStrictMode);
-        p.parseDeclaration(tempMutableStyle.get(), propertyText + " " + bogusPropertyName + ": none", &sourceData, m_style->parentStyleSheet()->contents());
+        p.parseDeclaration(tempMutableStyle.get(), propertyText + " " + bogusPropertyName + ": none", sourceData, m_style->parentStyleSheet()->contents());
         Vector<CSSPropertySourceData>& propertyData = sourceData->propertyData;
         unsigned propertyCount = propertyData.size();
 
@@ -1098,21 +1098,8 @@
 
     RefPtr<StyleSheetContents> newStyleSheet = StyleSheetContents::create();
     CSSParser p(CSSStrictMode);
-    StyleRuleRangeMap ruleRangeMap;
-    p.parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), 0, &ruleRangeMap);
-    OwnPtr<ParsedStyleSheet::SourceData> rangesVector(adoptPtr(new ParsedStyleSheet::SourceData));
-
-    Vector<CSSStyleRule*> rules;
-    RefPtr<CSSRuleList> ruleList = asCSSRuleList(CSSStyleSheet::create(newStyleSheet).get());
-    collectFlatRules(ruleList, &rules);
-    for (unsigned i = 0, size = rules.size(); i < size; ++i) {
-        StyleRuleRangeMap::iterator it = ruleRangeMap.find(rules.at(i)->styleRule());
-        if (it != ruleRangeMap.end()) {
-            fixUnparsedPropertyRanges(it->second.get(), m_parsedStyleSheet->text());
-            rangesVector->append(it->second);
-        }
-    }
-
+    OwnPtr<RuleSourceDataList> rangesVector(adoptPtr(new RuleSourceDataList()));
+    p.parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), 0, rangesVector.get());
     m_parsedStyleSheet->setSourceData(rangesVector.release());
     return m_parsedStyleSheet->hasSourceData();
 }
@@ -1253,51 +1240,6 @@
     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;
-
-        // 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)
@@ -1423,7 +1365,7 @@
 
     RefPtr<StylePropertySet> tempDeclaration = StylePropertySet::create();
     CSSParser p(m_element->document());
-    p.parseDeclaration(tempDeclaration.get(), m_styleText, result, m_element->document()->elementSheet()->contents());
+    p.parseDeclaration(tempDeclaration.get(), m_styleText, *result, m_element->document()->elementSheet()->contents());
     return true;
 }
 

Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.h (120468 => 120469)


--- trunk/Source/WebCore/inspector/InspectorStyleSheet.h	2012-06-15 16:03:35 UTC (rev 120468)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.h	2012-06-15 16:36:17 UTC (rev 120469)
@@ -59,7 +59,10 @@
 
 class InspectorCSSId {
 public:
-    InspectorCSSId() { }
+    InspectorCSSId()
+        : m_ordinal(0)
+    {
+    }
 
     explicit InspectorCSSId(RefPtr<InspectorObject> value)
     {
@@ -102,6 +105,8 @@
 
 struct InspectorStyleProperty {
     InspectorStyleProperty()
+        : hasSource(false)
+        , disabled(false)
     {
     }
 
@@ -219,7 +224,6 @@
 private:
     friend class InspectorStyle;
 
-    static void fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData, const String& styleSheetText);
     static void collectFlatRules(PassRefPtr<CSSRuleList>, Vector<CSSStyleRule*>* result);
     bool ensureText() const;
     bool ensureSourceData();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to