Ejemplo n.º 1
0
bool InspectorStyleSheet::ensureSourceData(Node* ownerNode)
{
    if (m_parsedStyleSheet->hasSourceData())
        return true;

    if (!m_parsedStyleSheet->hasText())
        return false;

    RefPtr<CSSStyleSheet> newStyleSheet = CSSStyleSheet::create(ownerNode);
    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);
        if (it != ruleRangeMap.end())
            rangesVector->append(it->second);
    }

    m_parsedStyleSheet->setSourceData(rangesVector.release());
    return m_parsedStyleSheet->hasSourceData();
}
Ejemplo n.º 2
0
HashMap<long, SourceRange> InspectorCSSStore::getRuleRangesForStyleSheet(CSSStyleSheet* styleSheet)
{
    if (!styleSheet)
        return HashMap<long, SourceRange>();
    RefPtr<CSSRuleList> originalRuleList = CSSRuleList::create(styleSheet, false);
    StyleSheetToOffsetsMap::iterator it = m_styleSheetToOffsets.find(styleSheet);
    HashMap<long, SourceRange> result;
    Vector<SourceRange>* offsetVector = 0;
    if (it == m_styleSheetToOffsets.end()) {
        InspectorResource* resource = m_inspectorController->resourceForURL(styleSheet->finalURL().string());
        if (resource) {
            offsetVector = new Vector<SourceRange>;
            RefPtr<CSSStyleSheet> newStyleSheet = CSSStyleSheet::create(styleSheet->ownerNode());
            CSSParser p;
            CSSParser::StyleRuleRanges ruleRangeMap;
            p.parseSheet(newStyleSheet.get(), resource->sourceString(), &ruleRangeMap);
            for (unsigned i = 0, length = newStyleSheet->length(); i < length; ++i) {
                CSSStyleRule* rule = asCSSStyleRule(newStyleSheet->item(i));
                if (!rule)
                    continue;
                HashMap<CSSStyleRule*, std::pair<unsigned, unsigned> >::iterator it = ruleRangeMap.find(rule);
                if (it != ruleRangeMap.end())
                    offsetVector->append(it->second);
            }
            m_styleSheetToOffsets.set(styleSheet, offsetVector);
        }
    } else
        offsetVector = it->second;
    if (!offsetVector)
        return HashMap<long, SourceRange>();
    unsigned ruleIndex = 0;
    for (unsigned i = 0, length = styleSheet->length(); i < length; ++i) {
        ASSERT(ruleIndex < offsetVector->size());
        CSSStyleRule* rule = asCSSStyleRule(styleSheet->item(i));
        if (!rule)
            continue;
        result.set(bindRule(rule), offsetVector->at(ruleIndex));
        ruleIndex++;
    }
    return result;
}