OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 118 |
119 // FIXME: This is a temporary solution to retain the original flat sourceDat
a structure | 119 // FIXME: This is a temporary solution to retain the original flat sourceDat
a structure |
120 // containing only style rules, even though BisonCSSParser now provides the
full rule source data tree. | 120 // containing only style rules, even though BisonCSSParser now provides the
full rule source data tree. |
121 // Normally, we should just assign m_sourceData = sourceData; | 121 // Normally, we should just assign m_sourceData = sourceData; |
122 flattenSourceData(sourceData.get()); | 122 flattenSourceData(sourceData.get()); |
123 } | 123 } |
124 | 124 |
125 PassRefPtr<WebCore::CSSRuleSourceData> ParsedStyleSheet::ruleSourceDataAt(unsign
ed index) const | 125 PassRefPtr<WebCore::CSSRuleSourceData> ParsedStyleSheet::ruleSourceDataAt(unsign
ed index) const |
126 { | 126 { |
127 if (!hasSourceData() || index >= m_sourceData->size()) | 127 if (!hasSourceData() || index >= m_sourceData->size()) |
128 return 0; | 128 return nullptr; |
129 | 129 |
130 return m_sourceData->at(index); | 130 return m_sourceData->at(index); |
131 } | 131 } |
132 | 132 |
133 namespace WebCore { | 133 namespace WebCore { |
134 | 134 |
135 static PassOwnPtr<BisonCSSParser> createCSSParser(Document* document) | 135 static PassOwnPtr<BisonCSSParser> createCSSParser(Document* document) |
136 { | 136 { |
137 return adoptPtr(new BisonCSSParser(document ? CSSParserContext(*document, 0)
: strictCSSParserContext())); | 137 return adoptPtr(new BisonCSSParser(document ? CSSParserContext(*document, 0)
: strictCSSParserContext())); |
138 } | 138 } |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 enum MediaListSource { | 430 enum MediaListSource { |
431 MediaListSourceLinkedSheet, | 431 MediaListSourceLinkedSheet, |
432 MediaListSourceInlineSheet, | 432 MediaListSourceInlineSheet, |
433 MediaListSourceMediaRule, | 433 MediaListSourceMediaRule, |
434 MediaListSourceImportRule | 434 MediaListSourceImportRule |
435 }; | 435 }; |
436 | 436 |
437 static PassRefPtr<TypeBuilder::CSS::SourceRange> buildSourceRangeObject(const So
urceRange& range, Vector<unsigned>* lineEndings) | 437 static PassRefPtr<TypeBuilder::CSS::SourceRange> buildSourceRangeObject(const So
urceRange& range, Vector<unsigned>* lineEndings) |
438 { | 438 { |
439 if (!lineEndings) | 439 if (!lineEndings) |
440 return 0; | 440 return nullptr; |
441 TextPosition start = TextPosition::fromOffsetAndLineEndings(range.start, *li
neEndings); | 441 TextPosition start = TextPosition::fromOffsetAndLineEndings(range.start, *li
neEndings); |
442 TextPosition end = TextPosition::fromOffsetAndLineEndings(range.end, *lineEn
dings); | 442 TextPosition end = TextPosition::fromOffsetAndLineEndings(range.end, *lineEn
dings); |
443 | 443 |
444 RefPtr<TypeBuilder::CSS::SourceRange> result = TypeBuilder::CSS::SourceRange
::create() | 444 RefPtr<TypeBuilder::CSS::SourceRange> result = TypeBuilder::CSS::SourceRange
::create() |
445 .setStartLine(start.m_line.zeroBasedInt()) | 445 .setStartLine(start.m_line.zeroBasedInt()) |
446 .setStartColumn(start.m_column.zeroBasedInt()) | 446 .setStartColumn(start.m_column.zeroBasedInt()) |
447 .setEndLine(end.m_line.zeroBasedInt()) | 447 .setEndLine(end.m_line.zeroBasedInt()) |
448 .setEndColumn(end.m_column.zeroBasedInt()); | 448 .setEndColumn(end.m_column.zeroBasedInt()); |
449 return result.release(); | 449 return result.release(); |
450 } | 450 } |
451 | 451 |
452 static PassRefPtr<CSSRuleList> asCSSRuleList(CSSStyleSheet* styleSheet) | 452 static PassRefPtr<CSSRuleList> asCSSRuleList(CSSStyleSheet* styleSheet) |
453 { | 453 { |
454 if (!styleSheet) | 454 if (!styleSheet) |
455 return 0; | 455 return nullptr; |
456 | 456 |
457 RefPtr<StaticCSSRuleList> list = StaticCSSRuleList::create(); | 457 RefPtr<StaticCSSRuleList> list = StaticCSSRuleList::create(); |
458 Vector<RefPtr<CSSRule> >& listRules = list->rules(); | 458 Vector<RefPtr<CSSRule> >& listRules = list->rules(); |
459 for (unsigned i = 0, size = styleSheet->length(); i < size; ++i) { | 459 for (unsigned i = 0, size = styleSheet->length(); i < size; ++i) { |
460 CSSRule* item = styleSheet->item(i); | 460 CSSRule* item = styleSheet->item(i); |
461 if (item->type() == CSSRule::CHARSET_RULE) | 461 if (item->type() == CSSRule::CHARSET_RULE) |
462 continue; | 462 continue; |
463 listRules.append(item); | 463 listRules.append(item); |
464 } | 464 } |
465 return list.release(); | 465 return list.release(); |
466 } | 466 } |
467 | 467 |
468 static PassRefPtr<CSSRuleList> asCSSRuleList(CSSRule* rule) | 468 static PassRefPtr<CSSRuleList> asCSSRuleList(CSSRule* rule) |
469 { | 469 { |
470 if (!rule) | 470 if (!rule) |
471 return 0; | 471 return nullptr; |
472 | 472 |
473 if (rule->type() == CSSRule::MEDIA_RULE) | 473 if (rule->type() == CSSRule::MEDIA_RULE) |
474 return toCSSMediaRule(rule)->cssRules(); | 474 return toCSSMediaRule(rule)->cssRules(); |
475 | 475 |
476 if (rule->type() == CSSRule::KEYFRAMES_RULE) | 476 if (rule->type() == CSSRule::KEYFRAMES_RULE) |
477 return toCSSKeyframesRule(rule)->cssRules(); | 477 return toCSSKeyframesRule(rule)->cssRules(); |
478 | 478 |
479 if (rule->type() == CSSRule::SUPPORTS_RULE) | 479 if (rule->type() == CSSRule::SUPPORTS_RULE) |
480 return toCSSSupportsRule(rule)->cssRules(); | 480 return toCSSSupportsRule(rule)->cssRules(); |
481 | 481 |
482 return 0; | 482 return nullptr; |
483 } | 483 } |
484 | 484 |
485 PassRefPtr<InspectorStyle> InspectorStyle::create(const InspectorCSSId& styleId,
PassRefPtr<CSSStyleDeclaration> style, InspectorStyleSheet* parentStyleSheet) | 485 PassRefPtr<InspectorStyle> InspectorStyle::create(const InspectorCSSId& styleId,
PassRefPtr<CSSStyleDeclaration> style, InspectorStyleSheet* parentStyleSheet) |
486 { | 486 { |
487 return adoptRef(new InspectorStyle(styleId, style, parentStyleSheet)); | 487 return adoptRef(new InspectorStyle(styleId, style, parentStyleSheet)); |
488 } | 488 } |
489 | 489 |
490 InspectorStyle::InspectorStyle(const InspectorCSSId& styleId, PassRefPtr<CSSStyl
eDeclaration> style, InspectorStyleSheet* parentStyleSheet) | 490 InspectorStyle::InspectorStyle(const InspectorCSSId& styleId, PassRefPtr<CSSStyl
eDeclaration> style, InspectorStyleSheet* parentStyleSheet) |
491 : m_styleId(styleId) | 491 : m_styleId(styleId) |
492 , m_style(style) | 492 , m_style(style) |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 | 746 |
747 RefPtr<TypeBuilder::CSS::CSSStyle> result = TypeBuilder::CSS::CSSStyle::crea
te() | 747 RefPtr<TypeBuilder::CSS::CSSStyle> result = TypeBuilder::CSS::CSSStyle::crea
te() |
748 .setCssProperties(propertiesObject) | 748 .setCssProperties(propertiesObject) |
749 .setShorthandEntries(shorthandEntries); | 749 .setShorthandEntries(shorthandEntries); |
750 return result.release(); | 750 return result.release(); |
751 } | 751 } |
752 | 752 |
753 PassRefPtr<CSSRuleSourceData> InspectorStyle::extractSourceData() const | 753 PassRefPtr<CSSRuleSourceData> InspectorStyle::extractSourceData() const |
754 { | 754 { |
755 if (!m_parentStyleSheet || !m_parentStyleSheet->ensureParsedDataReady()) | 755 if (!m_parentStyleSheet || !m_parentStyleSheet->ensureParsedDataReady()) |
756 return 0; | 756 return nullptr; |
757 return m_parentStyleSheet->ruleSourceDataFor(m_style.get()); | 757 return m_parentStyleSheet->ruleSourceDataFor(m_style.get()); |
758 } | 758 } |
759 | 759 |
760 bool InspectorStyle::applyStyleText(const String& text) | 760 bool InspectorStyle::applyStyleText(const String& text) |
761 { | 761 { |
762 return m_parentStyleSheet->setStyleText(m_style.get(), text); | 762 return m_parentStyleSheet->setStyleText(m_style.get(), text); |
763 } | 763 } |
764 | 764 |
765 String InspectorStyle::shorthandValue(const String& shorthandProperty) const | 765 String InspectorStyle::shorthandValue(const String& shorthandProperty) const |
766 { | 766 { |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 | 1121 |
1122 ASSERT(!id.isEmpty()); | 1122 ASSERT(!id.isEmpty()); |
1123 ensureFlatRules(); | 1123 ensureFlatRules(); |
1124 return InspectorCSSAgent::asCSSStyleRule(id.ordinal() >= m_flatRules.size()
? 0 : m_flatRules.at(id.ordinal()).get()); | 1124 return InspectorCSSAgent::asCSSStyleRule(id.ordinal() >= m_flatRules.size()
? 0 : m_flatRules.at(id.ordinal()).get()); |
1125 } | 1125 } |
1126 | 1126 |
1127 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> InspectorStyleSheet::buildObje
ctForStyleSheetInfo() const | 1127 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> InspectorStyleSheet::buildObje
ctForStyleSheetInfo() const |
1128 { | 1128 { |
1129 CSSStyleSheet* styleSheet = pageStyleSheet(); | 1129 CSSStyleSheet* styleSheet = pageStyleSheet(); |
1130 if (!styleSheet) | 1130 if (!styleSheet) |
1131 return 0; | 1131 return nullptr; |
1132 | 1132 |
1133 Document* document = styleSheet->ownerDocument(); | 1133 Document* document = styleSheet->ownerDocument(); |
1134 Frame* frame = document ? document->frame() : 0; | 1134 Frame* frame = document ? document->frame() : 0; |
1135 | 1135 |
1136 RefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> result = TypeBuilder::CSS::CSS
StyleSheetHeader::create() | 1136 RefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> result = TypeBuilder::CSS::CSS
StyleSheetHeader::create() |
1137 .setStyleSheetId(id()) | 1137 .setStyleSheetId(id()) |
1138 .setOrigin(m_origin) | 1138 .setOrigin(m_origin) |
1139 .setDisabled(styleSheet->disabled()) | 1139 .setDisabled(styleSheet->disabled()) |
1140 .setSourceURL(url()) | 1140 .setSourceURL(url()) |
1141 .setTitle(styleSheet->title()) | 1141 .setTitle(styleSheet->title()) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 .setSelectors(selectors) | 1198 .setSelectors(selectors) |
1199 .setText(selectorText) | 1199 .setText(selectorText) |
1200 .release(); | 1200 .release(); |
1201 return result.release(); | 1201 return result.release(); |
1202 } | 1202 } |
1203 | 1203 |
1204 PassRefPtr<TypeBuilder::CSS::CSSRule> InspectorStyleSheet::buildObjectForRule(CS
SStyleRule* rule, PassRefPtr<Array<TypeBuilder::CSS::CSSMedia> > mediaStack) | 1204 PassRefPtr<TypeBuilder::CSS::CSSRule> InspectorStyleSheet::buildObjectForRule(CS
SStyleRule* rule, PassRefPtr<Array<TypeBuilder::CSS::CSSMedia> > mediaStack) |
1205 { | 1205 { |
1206 CSSStyleSheet* styleSheet = pageStyleSheet(); | 1206 CSSStyleSheet* styleSheet = pageStyleSheet(); |
1207 if (!styleSheet) | 1207 if (!styleSheet) |
1208 return 0; | 1208 return nullptr; |
1209 | 1209 |
1210 RefPtr<TypeBuilder::CSS::CSSRule> result = TypeBuilder::CSS::CSSRule::create
() | 1210 RefPtr<TypeBuilder::CSS::CSSRule> result = TypeBuilder::CSS::CSSRule::create
() |
1211 .setSelectorList(buildObjectForSelectorList(rule)) | 1211 .setSelectorList(buildObjectForSelectorList(rule)) |
1212 .setOrigin(m_origin) | 1212 .setOrigin(m_origin) |
1213 .setStyle(buildObjectForStyle(rule->style())); | 1213 .setStyle(buildObjectForStyle(rule->style())); |
1214 | 1214 |
1215 String url = this->url(); | 1215 String url = this->url(); |
1216 if (!url.isEmpty()) | 1216 if (!url.isEmpty()) |
1217 result->setSourceURL(url); | 1217 result->setSourceURL(url); |
1218 | 1218 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 | 1312 |
1313 void InspectorStyleSheet::fireStyleSheetChanged() | 1313 void InspectorStyleSheet::fireStyleSheetChanged() |
1314 { | 1314 { |
1315 if (m_listener) | 1315 if (m_listener) |
1316 m_listener->styleSheetChanged(this); | 1316 m_listener->styleSheetChanged(this); |
1317 } | 1317 } |
1318 | 1318 |
1319 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR
ange(const CSSRule* rule) | 1319 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR
ange(const CSSRule* rule) |
1320 { | 1320 { |
1321 if (!ensureParsedDataReady()) | 1321 if (!ensureParsedDataReady()) |
1322 return 0; | 1322 return nullptr; |
1323 | 1323 |
1324 RefPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleSourceDataAt(
ruleIndexByRule(rule)); | 1324 RefPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleSourceDataAt(
ruleIndexByRule(rule)); |
1325 if (!sourceData) | 1325 if (!sourceData) |
1326 return 0; | 1326 return nullptr; |
1327 return buildSourceRangeObject(sourceData->ruleHeaderRange, lineEndings().get
()); | 1327 return buildSourceRangeObject(sourceData->ruleHeaderRange, lineEndings().get
()); |
1328 } | 1328 } |
1329 | 1329 |
1330 PassRefPtr<InspectorStyle> InspectorStyleSheet::inspectorStyleForId(const Inspec
torCSSId& id) | 1330 PassRefPtr<InspectorStyle> InspectorStyleSheet::inspectorStyleForId(const Inspec
torCSSId& id) |
1331 { | 1331 { |
1332 CSSStyleDeclaration* style = styleForId(id); | 1332 CSSStyleDeclaration* style = styleForId(id); |
1333 if (!style) | 1333 if (!style) |
1334 return 0; | 1334 return nullptr; |
1335 | 1335 |
1336 return InspectorStyle::create(id, style, this); | 1336 return InspectorStyle::create(id, style, this); |
1337 } | 1337 } |
1338 | 1338 |
1339 String InspectorStyleSheet::sourceURL() const | 1339 String InspectorStyleSheet::sourceURL() const |
1340 { | 1340 { |
1341 if (!m_sourceURL.isNull()) | 1341 if (!m_sourceURL.isNull()) |
1342 return m_sourceURL; | 1342 return m_sourceURL; |
1343 if (m_origin != TypeBuilder::CSS::StyleSheetOrigin::Regular) { | 1343 if (m_origin != TypeBuilder::CSS::StyleSheetOrigin::Regular) { |
1344 m_sourceURL = ""; | 1344 m_sourceURL = ""; |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1611 *result = ownerElement->textContent(); | 1611 *result = ownerElement->textContent(); |
1612 return true; | 1612 return true; |
1613 } | 1613 } |
1614 | 1614 |
1615 PassRefPtr<InspectorStyleSheetForInlineStyle> InspectorStyleSheetForInlineStyle:
:create(InspectorPageAgent* pageAgent, InspectorResourceAgent* resourceAgent, co
nst String& id, PassRefPtr<Element> element, TypeBuilder::CSS::StyleSheetOrigin:
:Enum origin, Listener* listener) | 1615 PassRefPtr<InspectorStyleSheetForInlineStyle> InspectorStyleSheetForInlineStyle:
:create(InspectorPageAgent* pageAgent, InspectorResourceAgent* resourceAgent, co
nst String& id, PassRefPtr<Element> element, TypeBuilder::CSS::StyleSheetOrigin:
:Enum origin, Listener* listener) |
1616 { | 1616 { |
1617 return adoptRef(new InspectorStyleSheetForInlineStyle(pageAgent, resourceAge
nt, id, element, origin, listener)); | 1617 return adoptRef(new InspectorStyleSheetForInlineStyle(pageAgent, resourceAge
nt, id, element, origin, listener)); |
1618 } | 1618 } |
1619 | 1619 |
1620 InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(InspectorPa
geAgent* pageAgent, InspectorResourceAgent* resourceAgent, const String& id, Pas
sRefPtr<Element> element, TypeBuilder::CSS::StyleSheetOrigin::Enum origin, Liste
ner* listener) | 1620 InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(InspectorPa
geAgent* pageAgent, InspectorResourceAgent* resourceAgent, const String& id, Pas
sRefPtr<Element> element, TypeBuilder::CSS::StyleSheetOrigin::Enum origin, Liste
ner* listener) |
1621 : InspectorStyleSheet(pageAgent, resourceAgent, id, 0, origin, "", listener) | 1621 : InspectorStyleSheet(pageAgent, resourceAgent, id, nullptr, origin, "", lis
tener) |
1622 , m_element(element) | 1622 , m_element(element) |
1623 , m_ruleSourceData(0) | 1623 , m_ruleSourceData(nullptr) |
1624 , m_isStyleTextValid(false) | 1624 , m_isStyleTextValid(false) |
1625 { | 1625 { |
1626 ASSERT(m_element); | 1626 ASSERT(m_element); |
1627 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id, 0), inlineStyle
(), this); | 1627 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id, 0), inlineStyle
(), this); |
1628 m_styleText = m_element->isStyledElement() ? m_element->getAttribute("style"
).string() : String(); | 1628 m_styleText = m_element->isStyledElement() ? m_element->getAttribute("style"
).string() : String(); |
1629 } | 1629 } |
1630 | 1630 |
1631 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute() | 1631 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute() |
1632 { | 1632 { |
1633 m_isStyleTextValid = false; | 1633 m_isStyleTextValid = false; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1721 } | 1721 } |
1722 | 1722 |
1723 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const | 1723 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const |
1724 { | 1724 { |
1725 return m_element->getAttribute("style").string(); | 1725 return m_element->getAttribute("style").string(); |
1726 } | 1726 } |
1727 | 1727 |
1728 PassRefPtr<CSSRuleSourceData> InspectorStyleSheetForInlineStyle::getStyleAttribu
teData() const | 1728 PassRefPtr<CSSRuleSourceData> InspectorStyleSheetForInlineStyle::getStyleAttribu
teData() const |
1729 { | 1729 { |
1730 if (!m_element->isStyledElement()) | 1730 if (!m_element->isStyledElement()) |
1731 return 0; | 1731 return nullptr; |
1732 | 1732 |
1733 if (m_styleText.isEmpty()) { | 1733 if (m_styleText.isEmpty()) { |
1734 RefPtr<CSSRuleSourceData> result = CSSRuleSourceData::create(CSSRuleSour
ceData::STYLE_RULE); | 1734 RefPtr<CSSRuleSourceData> result = CSSRuleSourceData::create(CSSRuleSour
ceData::STYLE_RULE); |
1735 result->ruleBodyRange.start = 0; | 1735 result->ruleBodyRange.start = 0; |
1736 result->ruleBodyRange.end = 0; | 1736 result->ruleBodyRange.end = 0; |
1737 return result.release(); | 1737 return result.release(); |
1738 } | 1738 } |
1739 | 1739 |
1740 RefPtr<MutableStylePropertySet> tempDeclaration = MutableStylePropertySet::c
reate(); | 1740 RefPtr<MutableStylePropertySet> tempDeclaration = MutableStylePropertySet::c
reate(); |
1741 RuleSourceDataList ruleSourceDataResult; | 1741 RuleSourceDataList ruleSourceDataResult; |
1742 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do
cument().elementSheet()->contents(), &ruleSourceDataResult); | 1742 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do
cument().elementSheet()->contents(), &ruleSourceDataResult); |
1743 createCSSParser(&m_element->document())->parseDeclaration(tempDeclaration.ge
t(), m_styleText, &handler, m_element->document().elementSheet()->contents()); | 1743 createCSSParser(&m_element->document())->parseDeclaration(tempDeclaration.ge
t(), m_styleText, &handler, m_element->document().elementSheet()->contents()); |
1744 return ruleSourceDataResult.first().release(); | 1744 return ruleSourceDataResult.first().release(); |
1745 } | 1745 } |
1746 | 1746 |
1747 } // namespace WebCore | 1747 } // namespace WebCore |
1748 | 1748 |
OLD | NEW |