⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 120469 in webkit


Ignore:
Timestamp:
Jun 15, 2012, 9:36:17 AM (14 years ago)
Author:
apavlov@chromium.org
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):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r120468 r120469  
     12012-06-08  Alexander Pavlov  <apavlov@chromium.org>
     2
     3        Web Inspector: CSSParser::parseSheet() should provide ready-to-use source data
     4        https://bugs.webkit.org/show_bug.cgi?id=88646
     5
     6        Reviewed by Antti Koivisto.
     7
     8        This change moves the post-processing step from InspectorStyleSheet into CSSParser, so that
     9        CSSParser::parseSheet() will return a ready-to-use list with style rule source code data.
     10        Also, universal data structures are introduced, which allow for the full rule source data tree building.
     11
     12        No new tests, as this is a refactoring.
     13
     14        * css/CSSParser.cpp: Use universal data structures, which can be used for building the full rule tree.
     15        (WebCore::CSSParser::CSSParser):
     16        (WebCore::CSSParser::setupParser):
     17        (WebCore::CSSParser::parseSheet): Return ready-to-use source code data entries rather than an intermediate structure.
     18        (WebCore::CSSParser::parseDeclaration):
     19        (WebCore::CSSParser::addNewRuleToSourceTree):
     20        (WebCore):
     21        (WebCore::CSSParser::popRuleData):
     22        (WebCore::CSSParser::createStyleRule):
     23        (WebCore::CSSParser::fixUnparsedPropertyRanges): Moved in from InspectorStyleSheet.
     24        (WebCore::CSSParser::markSelectorListStart):
     25        (WebCore::CSSParser::markSelectorListEnd):
     26        (WebCore::CSSParser::markRuleBodyStart):
     27        (WebCore::CSSParser::markRuleBodyEnd):
     28        (WebCore::CSSParser::markPropertyEnd):
     29        * css/CSSParser.h:
     30        (CSSParser):
     31        (WebCore::CSSParser::resetPropertyRange): Renamed.
     32        (WebCore::CSSParser::isExtractingSourceData): A convenience check.
     33        * css/CSSPropertySourceData.h: Introduce the RuleSourceDataList typedef.
     34        (WebCore):
     35        * inspector/InspectorStyleSheet.cpp: Make use of RuleSourceDataList and follow the CSSParser::parse*() API changes.
     36        (ParsedStyleSheet::sourceData):
     37        (ParsedStyleSheet):
     38        (ParsedStyleSheet::setSourceData):
     39        (WebCore::InspectorStyleSheet::ensureSourceData): Remove source data postprocessing, follow the new parseSheet() API.
     40        * inspector/InspectorStyleSheet.h:
     41        (WebCore::InspectorCSSId::InspectorCSSId): Drive-by: uninitialized field fix.
     42        (WebCore::InspectorStyleProperty::InspectorStyleProperty): Ditto.
     43        (InspectorStyleSheet):
     44
    1452012-06-15  Pavel Feldman  <pfeldman@chromium.org>
    246
  • trunk/Source/WebCore/css/CSSParser.cpp

    r120308 r120469  
    239239    , m_hadSyntacticallyValidCSSRule(false)
    240240    , m_defaultNamespace(starAtom)
     241    , m_parsedTextPrefixLength(0)
    241242    , m_inStyleRuleOrDeclaration(false)
    242243    , m_selectorListRange(0, 0)
    243244    , m_ruleBodyRange(0, 0)
    244245    , m_propertyRange(UINT_MAX, UINT_MAX)
    245     , m_ruleRangeMap(0)
    246     , m_currentRuleData(0)
     246    , m_ruleSourceDataResult(0)
    247247    , m_parsingMode(NormalMode)
    248248    , m_currentCharacter(0)
     
    289289void CSSParser::setupParser(const char* prefix, const String& string, const char* suffix)
    290290{
    291     int length = string.length() + strlen(prefix) + strlen(suffix) + 1;
     291    m_parsedTextPrefixLength = strlen(prefix);
     292    int length = string.length() + m_parsedTextPrefixLength + strlen(suffix) + 1;
    292293
    293294    m_dataStart = adoptArrayPtr(new UChar[length]);
    294     for (unsigned i = 0; i < strlen(prefix); i++)
     295    for (unsigned i = 0; i < m_parsedTextPrefixLength; i++)
    295296        m_dataStart[i] = prefix[i];
    296297
    297     memcpy(m_dataStart.get() + strlen(prefix), string.characters(), string.length() * sizeof(UChar));
    298 
    299     unsigned start = strlen(prefix) + string.length();
     298    memcpy(m_dataStart.get() + m_parsedTextPrefixLength, string.characters(), string.length() * sizeof(UChar));
     299
     300    unsigned start = m_parsedTextPrefixLength + string.length();
    300301    unsigned end = start + strlen(suffix);
    301302    for (unsigned i = start; i < end; i++)
     
    308309}
    309310
    310 void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, int startLineNumber, StyleRuleRangeMap* ruleRangeMap)
     311void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, int startLineNumber, RuleSourceDataList* ruleSourceDataResult)
    311312{
    312313    setStyleSheet(sheet);
    313314    m_defaultNamespace = starAtom; // Reset the default namespace.
    314     m_ruleRangeMap = ruleRangeMap;
    315     if (ruleRangeMap) {
    316         m_currentRuleData = CSSRuleSourceData::create();
    317         m_currentRuleData->styleSourceData = CSSStyleSourceData::create();
    318     }
     315    if (ruleSourceDataResult)
     316        m_currentRuleDataStack = adoptPtr(new RuleSourceDataList());
     317    m_ruleSourceDataResult = ruleSourceDataResult;
    319318
    320319    m_lineNumber = startLineNumber;
    321320    setupParser("", string, "");
    322321    cssyyparse(this);
    323     m_ruleRangeMap = 0;
    324     m_currentRuleData = 0;
     322    m_currentRuleDataStack.clear();
     323    m_ruleSourceDataResult = 0;
    325324    m_rule = 0;
    326325}
     
    11271126}
    11281127
    1129 bool CSSParser::parseDeclaration(StylePropertySet* declaration, const String& string, RefPtr<CSSStyleSourceData>* styleSourceData, StyleSheetContents* contextStyleSheet)
     1128bool CSSParser::parseDeclaration(StylePropertySet* declaration, const String& string, PassRefPtr<CSSStyleSourceData> prpStyleSourceData, StyleSheetContents* contextStyleSheet)
    11301129{
    11311130    // Length of the "@-webkit-decls{" prefix.
     
    11341133    setStyleSheet(contextStyleSheet);
    11351134
     1135    RefPtr<CSSStyleSourceData> styleSourceData = prpStyleSourceData;
    11361136    if (styleSourceData) {
    1137         m_currentRuleData = CSSRuleSourceData::create();
    1138         m_currentRuleData->styleSourceData = CSSStyleSourceData::create();
     1137        m_currentRuleDataStack = adoptPtr(new RuleSourceDataList());
     1138        RefPtr<CSSRuleSourceData> data = CSSRuleSourceData::create();
     1139        data->styleSourceData = styleSourceData;
     1140        m_currentRuleDataStack->append(data);
    11391141        m_inStyleRuleOrDeclaration = true;
    11401142    }
     
    11531155    }
    11541156
    1155     if (m_currentRuleData) {
    1156         m_currentRuleData->styleSourceData->styleBodyRange.start = 0;
    1157         m_currentRuleData->styleSourceData->styleBodyRange.end = string.length();
    1158         for (Vector<CSSPropertySourceData>::iterator it = m_currentRuleData->styleSourceData->propertyData.begin(), endIt = m_currentRuleData->styleSourceData->propertyData.end(); it != endIt; ++it) {
    1159             (*it).range.start -= prefixLength;
    1160             (*it).range.end -= prefixLength;
    1161         }
    1162     }
    1163 
    11641157    if (styleSourceData) {
    1165         *styleSourceData = m_currentRuleData->styleSourceData.release();
    1166         m_currentRuleData = 0;
     1158        ASSERT(!m_currentRuleDataStack->isEmpty());
     1159        CSSRuleSourceData* ruleData = m_currentRuleDataStack->last().get();
     1160        ruleData->styleSourceData->styleBodyRange.start = 0;
     1161        ruleData->styleSourceData->styleBodyRange.end = string.length();
     1162        for (size_t i = 0, size = ruleData->styleSourceData->propertyData.size(); i < size; ++i) {
     1163            CSSPropertySourceData& propertyData = ruleData->styleSourceData->propertyData.at(i);
     1164            propertyData.range.start -= prefixLength;
     1165            propertyData.range.end -= prefixLength;
     1166        }
     1167        fixUnparsedPropertyRanges(ruleData);
     1168
     1169        m_currentRuleDataStack.clear();
    11671170        m_inStyleRuleOrDeclaration = false;
    11681171    }
     1172
    11691173    return ok;
    11701174}
     
    92589262}
    92599263
     9264void CSSParser::addNewRuleToSourceTree(PassRefPtr<CSSRuleSourceData> rule)
     9265{
     9266    // Precondition: (isExtractingSourceData()).
     9267    if (!m_ruleSourceDataResult)
     9268        return;
     9269
     9270    // FIXME: This temporarily builds a flat style rule data list, to avoid the client code breakage.
     9271    m_ruleSourceDataResult->append(rule);
     9272}
     9273
     9274PassRefPtr<CSSRuleSourceData> CSSParser::popRuleData()
     9275{
     9276    if (!m_ruleSourceDataResult)
     9277        return 0;
     9278
     9279    ASSERT(!m_currentRuleDataStack->isEmpty());
     9280    RefPtr<CSSRuleSourceData> data = m_currentRuleDataStack->last();
     9281    m_currentRuleDataStack->removeLast();
     9282    return data.release();
     9283}
     9284
    92609285StyleRuleKeyframes* CSSParser::createKeyframesRule()
    92619286{
     
    92809305        result = rule.get();
    92819306        m_parsedRules.append(rule.release());
    9282         if (m_ruleRangeMap) {
    9283             ASSERT(m_currentRuleData);
    9284             m_currentRuleData->styleSourceData->styleBodyRange = m_ruleBodyRange;
    9285             m_currentRuleData->selectorListRange = m_selectorListRange;
    9286             m_ruleRangeMap->set(result, m_currentRuleData.release());
    9287             m_currentRuleData = CSSRuleSourceData::create();
    9288             m_currentRuleData->styleSourceData = CSSStyleSourceData::create();
     9307        if (isExtractingSourceData()) {
     9308            RefPtr<CSSRuleSourceData> currentRuleData = popRuleData();
     9309            currentRuleData->styleSourceData->styleBodyRange = m_ruleBodyRange;
     9310            currentRuleData->selectorListRange = m_selectorListRange;
     9311            fixUnparsedPropertyRanges(currentRuleData.get());
     9312            addNewRuleToSourceTree(currentRuleData.release());
    92899313            m_inStyleRuleOrDeclaration = false;
    92909314        }
    92919315    }
    9292     resetSelectorListMarks();
    9293     resetRuleBodyMarks();
     9316    if (isExtractingSourceData()) {
     9317        resetSelectorListMarks();
     9318        resetRuleBodyMarks();
     9319    }
    92949320    clearProperties();
    92959321    return result;
     
    94979523}
    94989524
     9525void CSSParser::fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData)
     9526{
     9527    Vector<CSSPropertySourceData>& propertyData = ruleData->styleSourceData->propertyData;
     9528    unsigned size = propertyData.size();
     9529    if (!size)
     9530        return;
     9531
     9532    unsigned styleStart = ruleData->styleSourceData->styleBodyRange.start;
     9533    const UChar* characters = m_dataStart.get() + m_parsedTextPrefixLength;
     9534    CSSPropertySourceData* nextData = &(propertyData.at(0));
     9535    for (unsigned i = 0; i < size; ++i) {
     9536        CSSPropertySourceData* currentData = nextData;
     9537        nextData = i < size - 1 ? &(propertyData.at(i + 1)) : 0;
     9538
     9539        if (currentData->parsedOk)
     9540            continue;
     9541        if (currentData->range.end > 0 && characters[styleStart + currentData->range.end - 1] == ';')
     9542            continue;
     9543
     9544        unsigned propertyEndInStyleSheet;
     9545        if (!nextData)
     9546            propertyEndInStyleSheet = ruleData->styleSourceData->styleBodyRange.end - 1;
     9547        else
     9548            propertyEndInStyleSheet = styleStart + nextData->range.start - 1;
     9549
     9550        while (isHTMLSpace(characters[propertyEndInStyleSheet]))
     9551            --propertyEndInStyleSheet;
     9552
     9553        // propertyEndInStyleSheet points at the last property text character.
     9554        unsigned newPropertyEnd = propertyEndInStyleSheet - styleStart + 1; // Exclusive of the last property text character.
     9555        if (currentData->range.end != newPropertyEnd) {
     9556            currentData->range.end = newPropertyEnd;
     9557            unsigned valueStartInStyleSheet = styleStart + currentData->range.start + currentData->name.length();
     9558            while (valueStartInStyleSheet < propertyEndInStyleSheet && characters[valueStartInStyleSheet] != ':')
     9559                ++valueStartInStyleSheet;
     9560            if (valueStartInStyleSheet < propertyEndInStyleSheet)
     9561                ++valueStartInStyleSheet; // Shift past the ':'.
     9562            while (valueStartInStyleSheet < propertyEndInStyleSheet && isHTMLSpace(characters[valueStartInStyleSheet]))
     9563                ++valueStartInStyleSheet;
     9564            // Need to exclude the trailing ';' from the property value.
     9565            currentData->value = String(characters + valueStartInStyleSheet, propertyEndInStyleSheet - valueStartInStyleSheet + (characters[propertyEndInStyleSheet] == ';' ? 0 : 1));
     9566        }
     9567    }
     9568}
     9569
    94999570void CSSParser::markSelectorListStart()
    95009571{
     9572    if (!isExtractingSourceData())
     9573        return;
    95019574    m_selectorListRange.start = m_tokenStart - m_dataStart.get();
    95029575}
     
    95049577void CSSParser::markSelectorListEnd()
    95059578{
    9506     if (!m_currentRuleData)
     9579    if (!isExtractingSourceData())
    95079580        return;
    95089581    UChar* listEnd = m_tokenStart;
     
    95149587    }
    95159588    m_selectorListRange.end = listEnd - m_dataStart.get();
     9589    RefPtr<CSSRuleSourceData> data = CSSRuleSourceData::create();
     9590    data->styleSourceData = CSSStyleSourceData::create();
     9591    m_currentRuleDataStack->append(data);
    95169592}
    95179593
    95189594void CSSParser::markRuleBodyStart()
    95199595{
     9596    if (!isExtractingSourceData())
     9597        return;
    95209598    unsigned offset = m_tokenStart - m_dataStart.get();
    95219599    if (*m_tokenStart == '{')
     
    95289606void CSSParser::markRuleBodyEnd()
    95299607{
     9608    if (!isExtractingSourceData())
     9609        return;
    95309610    unsigned offset = m_tokenStart - m_dataStart.get();
    95319611    if (offset > m_ruleBodyRange.end)
     
    95449624    if (!m_inStyleRuleOrDeclaration)
    95459625        return;
     9626
    95469627    unsigned offset = m_tokenStart - m_dataStart.get();
    95479628    if (*m_tokenStart == ';') // Include semicolon into the property text.
    95489629        ++offset;
    95499630    m_propertyRange.end = offset;
    9550     if (m_propertyRange.start != UINT_MAX && m_currentRuleData) {
     9631    if (m_propertyRange.start != UINT_MAX && !m_currentRuleDataStack->isEmpty()) {
    95519632        // This stuff is only executed when the style data retrieval is requested by client.
    95529633        const unsigned start = m_propertyRange.start;
     
    95629643        String value = propertyString.substring(colonIndex + 1, propertyString.length()).stripWhiteSpace();
    95639644        // The property range is relative to the declaration start offset.
    9564         m_currentRuleData->styleSourceData->propertyData.append(
     9645        m_currentRuleDataStack->last()->styleSourceData->propertyData.append(
    95659646            CSSPropertySourceData(name, value, isImportantFound, isPropertyParsed, SourceRange(start - m_ruleBodyRange.start, end - m_ruleBodyRange.start)));
    95669647    }
    9567     resetPropertyMarks();
     9648    resetPropertyRange();
    95689649}
    95699650
  • trunk/Source/WebCore/css/CSSParser.h

    r120154 r120469  
    7171    ~CSSParser();
    7272
    73     void parseSheet(StyleSheetContents*, const String&, int startLineNumber = 0, StyleRuleRangeMap* = 0);
     73    void parseSheet(StyleSheetContents*, const String&, int startLineNumber = 0, RuleSourceDataList* = 0);
    7474    PassRefPtr<StyleRuleBase> parseRule(StyleSheetContents*, const String&);
    7575    PassRefPtr<StyleKeyframe> parseKeyframeRule(StyleSheetContents*, const String&);
     
    7979    static PassRefPtr<CSSValueList> parseFontFaceValue(const AtomicString&);
    8080    PassRefPtr<CSSPrimitiveValue> parseValidPrimitive(int ident, CSSParserValue*);
    81     bool parseDeclaration(StylePropertySet*, const String&, RefPtr<CSSStyleSourceData>*, StyleSheetContents* contextStyleSheet);
     81    bool parseDeclaration(StylePropertySet*, const String&, PassRefPtr<CSSStyleSourceData>, StyleSheetContents* contextStyleSheet);
    8282    PassOwnPtr<MediaQuery> parseMediaQuery(const String&);
    8383
     
    319319
    320320    // tokenizer methods and data
     321    size_t m_parsedTextPrefixLength;
    321322    bool m_inStyleRuleOrDeclaration;
    322323    SourceRange m_selectorListRange;
    323324    SourceRange m_ruleBodyRange;
    324325    SourceRange m_propertyRange;
    325     StyleRuleRangeMap* m_ruleRangeMap;
    326     RefPtr<CSSRuleSourceData> m_currentRuleData;
     326    OwnPtr<RuleSourceDataList> m_currentRuleDataStack;
     327    RuleSourceDataList* m_ruleSourceDataResult;
     328
     329    void fixUnparsedPropertyRanges(CSSRuleSourceData*);
     330    void markStyleRuleHeaderStart();
     331    void markRuleHeaderEnd();
     332
    327333    void markSelectorListStart();
    328334    void markSelectorListEnd();
     
    331337    void markPropertyStart();
    332338    void markPropertyEnd(bool isImportantFound, bool isPropertyParsed);
     339    void addNewRuleToSourceTree(PassRefPtr<CSSRuleSourceData>);
     340    PassRefPtr<CSSRuleSourceData> popRuleData();
    333341    void resetSelectorListMarks() { m_selectorListRange.start = m_selectorListRange.end = 0; }
    334342    void resetRuleBodyMarks() { m_ruleBodyRange.start = m_ruleBodyRange.end = 0; }
    335     void resetPropertyMarks() { m_propertyRange.start = m_propertyRange.end = UINT_MAX; }
     343    void resetPropertyRange() { m_propertyRange.start = m_propertyRange.end = UINT_MAX; }
     344    bool isExtractingSourceData() const { return !!m_currentRuleDataStack; }
    336345    int lex(void* yylval);
    337346    int token() { return m_token; }
  • trunk/Source/WebCore/css/CSSPropertySourceData.h

    r112923 r120469  
    8484};
    8585
     86class CSSRuleSourceData;
     87typedef Vector<RefPtr<CSSRuleSourceData> > RuleSourceDataList;
     88
    8689struct CSSRuleSourceData : public RefCounted<CSSRuleSourceData> {
    8790    static PassRefPtr<CSSRuleSourceData> create()
  • trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp

    r118538 r120469  
    6161
    6262using WebCore::TypeBuilder::Array;
     63using WebCore::RuleSourceDataList;
    6364
    6465class ParsedStyleSheet {
    6566public:
    66     typedef Vector<RefPtr<WebCore::CSSRuleSourceData> > SourceData;
    6767    ParsedStyleSheet();
    6868
     
    7171    void setText(const String& text);
    7272    bool hasText() const { return m_hasText; }
    73     SourceData* sourceData() const { return m_sourceData.get(); }
    74     void setSourceData(PassOwnPtr<SourceData> sourceData);
     73    RuleSourceDataList* sourceData() const { return m_sourceData.get(); }
     74    void setSourceData(PassOwnPtr<RuleSourceDataList>);
    7575    bool hasSourceData() const { return m_sourceData; }
    7676    RefPtr<WebCore::CSSRuleSourceData> ruleSourceDataAt(unsigned index) const;
     
    8282    String m_text;
    8383    bool m_hasText;
    84     OwnPtr<SourceData> m_sourceData;
     84    OwnPtr<RuleSourceDataList> m_sourceData;
    8585};
    8686
     
    9898}
    9999
    100 void ParsedStyleSheet::setSourceData(PassOwnPtr<SourceData> sourceData)
     100void ParsedStyleSheet::setSourceData(PassOwnPtr<RuleSourceDataList> sourceData)
    101101{
    102102    m_sourceData = sourceData;
     
    317317        RefPtr<CSSStyleSourceData> sourceData = CSSStyleSourceData::create();
    318318        CSSParser p(CSSStrictMode);
    319         p.parseDeclaration(tempMutableStyle.get(), propertyText + " " + bogusPropertyName + ": none", &sourceData, m_style->parentStyleSheet()->contents());
     319        p.parseDeclaration(tempMutableStyle.get(), propertyText + " " + bogusPropertyName + ": none", sourceData, m_style->parentStyleSheet()->contents());
    320320        Vector<CSSPropertySourceData>& propertyData = sourceData->propertyData;
    321321        unsigned propertyCount = propertyData.size();
     
    10991099    RefPtr<StyleSheetContents> newStyleSheet = StyleSheetContents::create();
    11001100    CSSParser p(CSSStrictMode);
    1101     StyleRuleRangeMap ruleRangeMap;
    1102     p.parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), 0, &ruleRangeMap);
    1103     OwnPtr<ParsedStyleSheet::SourceData> rangesVector(adoptPtr(new ParsedStyleSheet::SourceData));
    1104 
    1105     Vector<CSSStyleRule*> rules;
    1106     RefPtr<CSSRuleList> ruleList = asCSSRuleList(CSSStyleSheet::create(newStyleSheet).get());
    1107     collectFlatRules(ruleList, &rules);
    1108     for (unsigned i = 0, size = rules.size(); i < size; ++i) {
    1109         StyleRuleRangeMap::iterator it = ruleRangeMap.find(rules.at(i)->styleRule());
    1110         if (it != ruleRangeMap.end()) {
    1111             fixUnparsedPropertyRanges(it->second.get(), m_parsedStyleSheet->text());
    1112             rangesVector->append(it->second);
    1113         }
    1114     }
    1115 
     1101    OwnPtr<RuleSourceDataList> rangesVector(adoptPtr(new RuleSourceDataList()));
     1102    p.parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), 0, rangesVector.get());
    11161103    m_parsedStyleSheet->setSourceData(rangesVector.release());
    11171104    return m_parsedStyleSheet->hasSourceData();
     
    12541241}
    12551242
    1256 void InspectorStyleSheet::fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData, const String& styleSheetText)
    1257 {
    1258     Vector<CSSPropertySourceData>& propertyData = ruleData->styleSourceData->propertyData;
    1259     unsigned size = propertyData.size();
    1260     if (!size)
    1261         return;
    1262 
    1263     unsigned styleStart = ruleData->styleSourceData->styleBodyRange.start;
    1264     const UChar* characters = styleSheetText.characters();
    1265     CSSPropertySourceData* nextData = &(propertyData.at(0));
    1266     for (unsigned i = 0; i < size; ++i) {
    1267         CSSPropertySourceData* currentData = nextData;
    1268         nextData = i < size - 1 ? &(propertyData.at(i + 1)) : 0;
    1269 
    1270         if (currentData->parsedOk)
    1271             continue;
    1272         if (currentData->range.end > 0 && characters[styleStart + currentData->range.end - 1] == ';')
    1273             continue;
    1274 
    1275         unsigned propertyEndInStyleSheet;
    1276         if (!nextData)
    1277             propertyEndInStyleSheet = ruleData->styleSourceData->styleBodyRange.end - 1;
    1278         else
    1279             propertyEndInStyleSheet = styleStart + nextData->range.start - 1;
    1280 
    1281         while (isHTMLSpace(characters[propertyEndInStyleSheet]))
    1282             --propertyEndInStyleSheet;
    1283 
    1284         // propertyEndInStyleSheet points at the last property text character.
    1285         unsigned newPropertyEnd = propertyEndInStyleSheet - styleStart + 1; // Exclusive of the last property text character.
    1286         if (currentData->range.end != newPropertyEnd) {
    1287             currentData->range.end = newPropertyEnd;
    1288             unsigned valueStartInStyleSheet = styleStart + currentData->range.start + currentData->name.length();
    1289             while (valueStartInStyleSheet < propertyEndInStyleSheet && characters[valueStartInStyleSheet] != ':')
    1290                 ++valueStartInStyleSheet;
    1291             if (valueStartInStyleSheet < propertyEndInStyleSheet)
    1292                 ++valueStartInStyleSheet; // Shift past the ':'.
    1293             while (valueStartInStyleSheet < propertyEndInStyleSheet && isHTMLSpace(characters[valueStartInStyleSheet]))
    1294                 ++valueStartInStyleSheet;
    1295             // Need to exclude the trailing ';' from the property value.
    1296             currentData->value = styleSheetText.substring(valueStartInStyleSheet, propertyEndInStyleSheet - valueStartInStyleSheet + (characters[propertyEndInStyleSheet] == ';' ? 0 : 1));
    1297         }
    1298     }
    1299 }
    1300 
    13011243void InspectorStyleSheet::collectFlatRules(PassRefPtr<CSSRuleList> ruleList, Vector<CSSStyleRule*>* result)
    13021244{
     
    14241366    RefPtr<StylePropertySet> tempDeclaration = StylePropertySet::create();
    14251367    CSSParser p(m_element->document());
    1426     p.parseDeclaration(tempDeclaration.get(), m_styleText, result, m_element->document()->elementSheet()->contents());
     1368    p.parseDeclaration(tempDeclaration.get(), m_styleText, *result, m_element->document()->elementSheet()->contents());
    14271369    return true;
    14281370}
  • trunk/Source/WebCore/inspector/InspectorStyleSheet.h

    r118533 r120469  
    6060class InspectorCSSId {
    6161public:
    62     InspectorCSSId() { }
     62    InspectorCSSId()
     63        : m_ordinal(0)
     64    {
     65    }
    6366
    6467    explicit InspectorCSSId(RefPtr<InspectorObject> value)
     
    103106struct InspectorStyleProperty {
    104107    InspectorStyleProperty()
     108        : hasSource(false)
     109        , disabled(false)
    105110    {
    106111    }
     
    220225    friend class InspectorStyle;
    221226
    222     static void fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData, const String& styleSheetText);
    223227    static void collectFlatRules(PassRefPtr<CSSRuleList>, Vector<CSSStyleRule*>* result);
    224228    bool ensureText() const;
Note: See TracChangeset for help on using the changeset viewer.