| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 virtual void startSelector(unsigned) OVERRIDE; | 84 virtual void startSelector(unsigned) OVERRIDE; |
| 85 virtual void endSelector(unsigned) OVERRIDE; | 85 virtual void endSelector(unsigned) OVERRIDE; |
| 86 virtual void startRuleBody(unsigned) OVERRIDE; | 86 virtual void startRuleBody(unsigned) OVERRIDE; |
| 87 virtual void endRuleBody(unsigned, bool) OVERRIDE; | 87 virtual void endRuleBody(unsigned, bool) OVERRIDE; |
| 88 virtual void startEndUnknownRule() OVERRIDE { addNewRuleToSourceTree(CSSRule
SourceData::createUnknown()); } | 88 virtual void startEndUnknownRule() OVERRIDE { addNewRuleToSourceTree(CSSRule
SourceData::createUnknown()); } |
| 89 virtual void startProperty(unsigned) OVERRIDE; | 89 virtual void startProperty(unsigned) OVERRIDE; |
| 90 virtual void endProperty(bool, bool, unsigned, CSSParserError) OVERRIDE; | 90 virtual void endProperty(bool, bool, unsigned, CSSParserError) OVERRIDE; |
| 91 virtual void startComment(unsigned) OVERRIDE; | 91 virtual void startComment(unsigned) OVERRIDE; |
| 92 virtual void endComment(unsigned) OVERRIDE; | 92 virtual void endComment(unsigned) OVERRIDE; |
| 93 | 93 |
| 94 void addNewRuleToSourceTree(PassRefPtr<CSSRuleSourceData>); | 94 void addNewRuleToSourceTree(PassRefPtrWillBeRawPtr<CSSRuleSourceData>); |
| 95 PassRefPtr<CSSRuleSourceData> popRuleData(); | 95 PassRefPtrWillBeRawPtr<CSSRuleSourceData> popRuleData(); |
| 96 template <typename CharacterType> inline void setRuleHeaderEnd(const Charact
erType*, unsigned); | 96 template <typename CharacterType> inline void setRuleHeaderEnd(const Charact
erType*, unsigned); |
| 97 void fixUnparsedPropertyRanges(CSSRuleSourceData*); | 97 void fixUnparsedPropertyRanges(CSSRuleSourceData*); |
| 98 | 98 |
| 99 const String& m_parsedText; | 99 const String& m_parsedText; |
| 100 Document* m_document; | 100 Document* m_document; |
| 101 StyleSheetContents* m_styleSheetContents; | 101 StyleSheetContents* m_styleSheetContents; |
| 102 RuleSourceDataList* m_result; | 102 RawPtrWillBeMember<RuleSourceDataList> m_result; |
| 103 RuleSourceDataList m_currentRuleDataStack; | 103 RuleSourceDataList m_currentRuleDataStack; |
| 104 RefPtr<CSSRuleSourceData> m_currentRuleData; | 104 RefPtrWillBeMember<CSSRuleSourceData> m_currentRuleData; |
| 105 BisonCSSParser m_commentParser; | 105 BisonCSSParser m_commentParser; |
| 106 unsigned m_propertyRangeStart; | 106 unsigned m_propertyRangeStart; |
| 107 unsigned m_selectorRangeStart; | 107 unsigned m_selectorRangeStart; |
| 108 unsigned m_commentRangeStart; | 108 unsigned m_commentRangeStart; |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 void StyleSheetHandler::startRuleHeader(CSSRuleSourceData::Type type, unsigned o
ffset) | 111 void StyleSheetHandler::startRuleHeader(CSSRuleSourceData::Type type, unsigned o
ffset) |
| 112 { | 112 { |
| 113 // Pop off data for a previous invalid rule. | 113 // Pop off data for a previous invalid rule. |
| 114 if (m_currentRuleData) | 114 if (m_currentRuleData) |
| 115 m_currentRuleDataStack.removeLast(); | 115 m_currentRuleDataStack.removeLast(); |
| 116 | 116 |
| 117 RefPtr<CSSRuleSourceData> data = CSSRuleSourceData::create(type); | 117 RefPtrWillBeRawPtr<CSSRuleSourceData> data = CSSRuleSourceData::create(type)
; |
| 118 data->ruleHeaderRange.start = offset; | 118 data->ruleHeaderRange.start = offset; |
| 119 m_currentRuleData = data; | 119 m_currentRuleData = data; |
| 120 m_currentRuleDataStack.append(data.release()); | 120 m_currentRuleDataStack.append(data.release()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 template <typename CharacterType> | 123 template <typename CharacterType> |
| 124 inline void StyleSheetHandler::setRuleHeaderEnd(const CharacterType* dataStart,
unsigned listEndOffset) | 124 inline void StyleSheetHandler::setRuleHeaderEnd(const CharacterType* dataStart,
unsigned listEndOffset) |
| 125 { | 125 { |
| 126 while (listEndOffset > 1) { | 126 while (listEndOffset > 1) { |
| 127 if (isHTMLSpace<CharacterType>(*(dataStart + listEndOffset - 1))) | 127 if (isHTMLSpace<CharacterType>(*(dataStart + listEndOffset - 1))) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 if (m_parsedText[offset] == '{') | 164 if (m_parsedText[offset] == '{') |
| 165 ++offset; // Skip the rule body opening brace. | 165 ++offset; // Skip the rule body opening brace. |
| 166 m_currentRuleDataStack.last()->ruleBodyRange.start = offset; | 166 m_currentRuleDataStack.last()->ruleBodyRange.start = offset; |
| 167 } | 167 } |
| 168 | 168 |
| 169 void StyleSheetHandler::endRuleBody(unsigned offset, bool error) | 169 void StyleSheetHandler::endRuleBody(unsigned offset, bool error) |
| 170 { | 170 { |
| 171 ASSERT(!m_currentRuleDataStack.isEmpty()); | 171 ASSERT(!m_currentRuleDataStack.isEmpty()); |
| 172 m_currentRuleDataStack.last()->ruleBodyRange.end = offset; | 172 m_currentRuleDataStack.last()->ruleBodyRange.end = offset; |
| 173 m_propertyRangeStart = UINT_MAX; | 173 m_propertyRangeStart = UINT_MAX; |
| 174 RefPtr<CSSRuleSourceData> rule = popRuleData(); | 174 RefPtrWillBeRawPtr<CSSRuleSourceData> rule = popRuleData(); |
| 175 if (error) | 175 if (error) |
| 176 return; | 176 return; |
| 177 | 177 |
| 178 fixUnparsedPropertyRanges(rule.get()); | 178 fixUnparsedPropertyRanges(rule.get()); |
| 179 addNewRuleToSourceTree(rule.release()); | 179 addNewRuleToSourceTree(rule.release()); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void StyleSheetHandler::addNewRuleToSourceTree(PassRefPtr<CSSRuleSourceData> rul
e) | 182 void StyleSheetHandler::addNewRuleToSourceTree(PassRefPtrWillBeRawPtr<CSSRuleSou
rceData> rule) |
| 183 { | 183 { |
| 184 if (m_currentRuleDataStack.isEmpty()) | 184 if (m_currentRuleDataStack.isEmpty()) |
| 185 m_result->append(rule); | 185 m_result->append(rule); |
| 186 else | 186 else |
| 187 m_currentRuleDataStack.last()->childRules.append(rule); | 187 m_currentRuleDataStack.last()->childRules.append(rule); |
| 188 } | 188 } |
| 189 | 189 |
| 190 PassRefPtr<CSSRuleSourceData> StyleSheetHandler::popRuleData() | 190 PassRefPtrWillBeRawPtr<CSSRuleSourceData> StyleSheetHandler::popRuleData() |
| 191 { | 191 { |
| 192 ASSERT(!m_currentRuleDataStack.isEmpty()); | 192 ASSERT(!m_currentRuleDataStack.isEmpty()); |
| 193 m_currentRuleData.clear(); | 193 m_currentRuleData.clear(); |
| 194 RefPtr<CSSRuleSourceData> data = m_currentRuleDataStack.last(); | 194 RefPtrWillBeRawPtr<CSSRuleSourceData> data = m_currentRuleDataStack.last(); |
| 195 m_currentRuleDataStack.removeLast(); | 195 m_currentRuleDataStack.removeLast(); |
| 196 return data.release(); | 196 return data.release(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 template <typename CharacterType> | 199 template <typename CharacterType> |
| 200 static inline void fixUnparsedProperties(const CharacterType* characters, CSSRul
eSourceData* ruleData) | 200 static inline void fixUnparsedProperties(const CharacterType* characters, CSSRul
eSourceData* ruleData) |
| 201 { | 201 { |
| 202 Vector<CSSPropertySourceData>& propertyData = ruleData->styleSourceData->pro
pertyData; | 202 WillBeHeapVector<CSSPropertySourceData>& propertyData = ruleData->styleSourc
eData->propertyData; |
| 203 unsigned size = propertyData.size(); | 203 unsigned size = propertyData.size(); |
| 204 if (!size) | 204 if (!size) |
| 205 return; | 205 return; |
| 206 | 206 |
| 207 unsigned styleStart = ruleData->ruleBodyRange.start; | 207 unsigned styleStart = ruleData->ruleBodyRange.start; |
| 208 CSSPropertySourceData* nextData = &(propertyData.at(0)); | 208 CSSPropertySourceData* nextData = &(propertyData.at(0)); |
| 209 for (unsigned i = 0; i < size; ++i) { | 209 for (unsigned i = 0; i < size; ++i) { |
| 210 CSSPropertySourceData* currentData = nextData; | 210 CSSPropertySourceData* currentData = nextData; |
| 211 nextData = i < size - 1 ? &(propertyData.at(i + 1)) : 0; | 211 nextData = i < size - 1 ? &(propertyData.at(i + 1)) : 0; |
| 212 | 212 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 return; | 329 return; |
| 330 | 330 |
| 331 // FIXME: Use the actual rule type rather than STYLE_RULE? | 331 // FIXME: Use the actual rule type rather than STYLE_RULE? |
| 332 RuleSourceDataList sourceData; | 332 RuleSourceDataList sourceData; |
| 333 | 333 |
| 334 // FIXME: Use another subclass of BisonCSSParser::SourceDataHandler and asse
rt that | 334 // FIXME: Use another subclass of BisonCSSParser::SourceDataHandler and asse
rt that |
| 335 // no comments are encountered (will not need m_document and m_styleSheetCon
tents). | 335 // no comments are encountered (will not need m_document and m_styleSheetCon
tents). |
| 336 StyleSheetHandler handler(commentText, m_document, m_styleSheetContents, &so
urceData); | 336 StyleSheetHandler handler(commentText, m_document, m_styleSheetContents, &so
urceData); |
| 337 RefPtrWillBeRawPtr<MutableStylePropertySet> tempMutableStyle = MutableStyleP
ropertySet::create(); | 337 RefPtrWillBeRawPtr<MutableStylePropertySet> tempMutableStyle = MutableStyleP
ropertySet::create(); |
| 338 m_commentParser.parseDeclaration(tempMutableStyle.get(), commentText, &handl
er, m_styleSheetContents); | 338 m_commentParser.parseDeclaration(tempMutableStyle.get(), commentText, &handl
er, m_styleSheetContents); |
| 339 Vector<CSSPropertySourceData>& commentPropertyData = sourceData.first()->sty
leSourceData->propertyData; | 339 WillBeHeapVector<CSSPropertySourceData>& commentPropertyData = sourceData.fi
rst()->styleSourceData->propertyData; |
| 340 if (commentPropertyData.size() != 1) | 340 if (commentPropertyData.size() != 1) |
| 341 return; | 341 return; |
| 342 CSSPropertySourceData& propertyData = commentPropertyData.at(0); | 342 CSSPropertySourceData& propertyData = commentPropertyData.at(0); |
| 343 if (propertyData.range.length() != commentText.length()) | 343 if (propertyData.range.length() != commentText.length()) |
| 344 return; | 344 return; |
| 345 | 345 |
| 346 unsigned topRuleBodyRangeStart = m_currentRuleDataStack.last()->ruleBodyRang
e.start; | 346 unsigned topRuleBodyRangeStart = m_currentRuleDataStack.last()->ruleBodyRang
e.start; |
| 347 m_currentRuleDataStack.last()->styleSourceData->propertyData.append( | 347 m_currentRuleDataStack.last()->styleSourceData->propertyData.append( |
| 348 CSSPropertySourceData(propertyData.name, propertyData.value, false, true
, true, SourceRange(startOffset - topRuleBodyRangeStart, offset - topRuleBodyRan
geStart))); | 348 CSSPropertySourceData(propertyData.name, propertyData.value, false, true
, true, SourceRange(startOffset - topRuleBodyRangeStart, offset - topRuleBodyRan
geStart))); |
| 349 } | 349 } |
| 350 | 350 |
| 351 } // namespace | 351 } // namespace |
| 352 | 352 |
| 353 class ParsedStyleSheet { | 353 class ParsedStyleSheet { |
| 354 WTF_MAKE_FAST_ALLOCATED; | 354 WTF_MAKE_FAST_ALLOCATED; |
| 355 public: | 355 public: |
| 356 ParsedStyleSheet(CSSStyleSheet* pageStyleSheet); | 356 ParsedStyleSheet(CSSStyleSheet* pageStyleSheet); |
| 357 | 357 |
| 358 const String& text() const { ASSERT(m_hasText); return m_text; } | 358 const String& text() const { ASSERT(m_hasText); return m_text; } |
| 359 void setText(const String&); | 359 void setText(const String&); |
| 360 bool hasText() const { return m_hasText; } | 360 bool hasText() const { return m_hasText; } |
| 361 bool ensureSourceData(); | 361 bool ensureSourceData(); |
| 362 bool hasSourceData() const { return m_sourceData; } | 362 bool hasSourceData() const { return m_sourceData; } |
| 363 PassRefPtr<WebCore::CSSRuleSourceData> ruleSourceDataAt(unsigned) const; | 363 PassRefPtrWillBeRawPtr<WebCore::CSSRuleSourceData> ruleSourceDataAt(unsigned
) const; |
| 364 | 364 |
| 365 private: | 365 private: |
| 366 void flattenSourceData(RuleSourceDataList*); | 366 void flattenSourceData(RuleSourceDataList*); |
| 367 void setSourceData(PassOwnPtr<RuleSourceDataList>); | 367 void setSourceData(PassOwnPtrWillBeRawPtr<RuleSourceDataList>); |
| 368 | 368 |
| 369 String m_text; | 369 String m_text; |
| 370 bool m_hasText; | 370 bool m_hasText; |
| 371 OwnPtr<RuleSourceDataList> m_sourceData; | 371 OwnPtrWillBePersistent<RuleSourceDataList> m_sourceData; |
| 372 RefPtrWillBePersistent<CSSStyleSheet> m_pageStyleSheet; | 372 RefPtrWillBePersistent<CSSStyleSheet> m_pageStyleSheet; |
| 373 }; | 373 }; |
| 374 | 374 |
| 375 ParsedStyleSheet::ParsedStyleSheet(CSSStyleSheet* pageStyleSheet) | 375 ParsedStyleSheet::ParsedStyleSheet(CSSStyleSheet* pageStyleSheet) |
| 376 : m_hasText(false) | 376 : m_hasText(false) |
| 377 , m_pageStyleSheet(pageStyleSheet) | 377 , m_pageStyleSheet(pageStyleSheet) |
| 378 { | 378 { |
| 379 } | 379 } |
| 380 | 380 |
| 381 void ParsedStyleSheet::setText(const String& text) | 381 void ParsedStyleSheet::setText(const String& text) |
| 382 { | 382 { |
| 383 m_hasText = true; | 383 m_hasText = true; |
| 384 m_text = text; | 384 m_text = text; |
| 385 setSourceData(nullptr); | 385 setSourceData(nullptr); |
| 386 } | 386 } |
| 387 | 387 |
| 388 void ParsedStyleSheet::flattenSourceData(RuleSourceDataList* dataList) | 388 void ParsedStyleSheet::flattenSourceData(RuleSourceDataList* dataList) |
| 389 { | 389 { |
| 390 for (size_t i = 0; i < dataList->size(); ++i) { | 390 for (size_t i = 0; i < dataList->size(); ++i) { |
| 391 RefPtr<CSSRuleSourceData>& data = dataList->at(i); | 391 RefPtrWillBeMember<CSSRuleSourceData>& data = dataList->at(i); |
| 392 if (data->type == CSSRuleSourceData::STYLE_RULE) { | 392 if (data->type == CSSRuleSourceData::STYLE_RULE) { |
| 393 m_sourceData->append(data); | 393 m_sourceData->append(data); |
| 394 } else if (data->type == CSSRuleSourceData::IMPORT_RULE) { | 394 } else if (data->type == CSSRuleSourceData::IMPORT_RULE) { |
| 395 m_sourceData->append(data); | 395 m_sourceData->append(data); |
| 396 } else if (data->type == CSSRuleSourceData::MEDIA_RULE) { | 396 } else if (data->type == CSSRuleSourceData::MEDIA_RULE) { |
| 397 m_sourceData->append(data); | 397 m_sourceData->append(data); |
| 398 flattenSourceData(&data->childRules); | 398 flattenSourceData(&data->childRules); |
| 399 } else if (data->type == CSSRuleSourceData::SUPPORTS_RULE) { | 399 } else if (data->type == CSSRuleSourceData::SUPPORTS_RULE) { |
| 400 flattenSourceData(&data->childRules); | 400 flattenSourceData(&data->childRules); |
| 401 } | 401 } |
| 402 } | 402 } |
| 403 } | 403 } |
| 404 | 404 |
| 405 bool ParsedStyleSheet::ensureSourceData() | 405 bool ParsedStyleSheet::ensureSourceData() |
| 406 { | 406 { |
| 407 if (hasSourceData()) | 407 if (hasSourceData()) |
| 408 return true; | 408 return true; |
| 409 | 409 |
| 410 if (!hasText()) | 410 if (!hasText()) |
| 411 return false; | 411 return false; |
| 412 | 412 |
| 413 RefPtrWillBeRawPtr<StyleSheetContents> newStyleSheet = StyleSheetContents::c
reate(strictCSSParserContext()); | 413 RefPtrWillBeRawPtr<StyleSheetContents> newStyleSheet = StyleSheetContents::c
reate(strictCSSParserContext()); |
| 414 OwnPtr<RuleSourceDataList> result = adoptPtr(new RuleSourceDataList()); | 414 OwnPtrWillBeRawPtr<RuleSourceDataList> result = adoptPtrWillBeNoop(new RuleS
ourceDataList()); |
| 415 StyleSheetHandler handler(text(), m_pageStyleSheet->ownerDocument(), newStyl
eSheet.get(), result.get()); | 415 StyleSheetHandler handler(text(), m_pageStyleSheet->ownerDocument(), newStyl
eSheet.get(), result.get()); |
| 416 BisonCSSParser(m_pageStyleSheet->ownerDocument()).parseSheet(newStyleSheet.g
et(), text(), TextPosition::minimumPosition(), &handler); | 416 BisonCSSParser(m_pageStyleSheet->ownerDocument()).parseSheet(newStyleSheet.g
et(), text(), TextPosition::minimumPosition(), &handler); |
| 417 setSourceData(result.release()); | 417 setSourceData(result.release()); |
| 418 return hasSourceData(); | 418 return hasSourceData(); |
| 419 } | 419 } |
| 420 | 420 |
| 421 void ParsedStyleSheet::setSourceData(PassOwnPtr<RuleSourceDataList> sourceData) | 421 void ParsedStyleSheet::setSourceData(PassOwnPtrWillBeRawPtr<RuleSourceDataList>
sourceData) |
| 422 { | 422 { |
| 423 if (!sourceData) { | 423 if (!sourceData) { |
| 424 m_sourceData.clear(); | 424 m_sourceData.clear(); |
| 425 return; | 425 return; |
| 426 } | 426 } |
| 427 | 427 |
| 428 m_sourceData = adoptPtr(new RuleSourceDataList()); | 428 m_sourceData = adoptPtrWillBeNoop(new RuleSourceDataList()); |
| 429 | 429 |
| 430 // FIXME: This is a temporary solution to retain the original flat sourceDat
a structure | 430 // FIXME: This is a temporary solution to retain the original flat sourceDat
a structure |
| 431 // containing only style rules, even though BisonCSSParser now provides the
full rule source data tree. | 431 // containing only style rules, even though BisonCSSParser now provides the
full rule source data tree. |
| 432 // Normally, we should just assign m_sourceData = sourceData; | 432 // Normally, we should just assign m_sourceData = sourceData; |
| 433 flattenSourceData(sourceData.get()); | 433 flattenSourceData(sourceData.get()); |
| 434 } | 434 } |
| 435 | 435 |
| 436 PassRefPtr<WebCore::CSSRuleSourceData> ParsedStyleSheet::ruleSourceDataAt(unsign
ed index) const | 436 PassRefPtrWillBeRawPtr<WebCore::CSSRuleSourceData> ParsedStyleSheet::ruleSourceD
ataAt(unsigned index) const |
| 437 { | 437 { |
| 438 if (!hasSourceData() || index >= m_sourceData->size()) | 438 if (!hasSourceData() || index >= m_sourceData->size()) |
| 439 return nullptr; | 439 return nullptr; |
| 440 | 440 |
| 441 return m_sourceData->at(index); | 441 return m_sourceData->at(index); |
| 442 } | 442 } |
| 443 | 443 |
| 444 namespace WebCore { | 444 namespace WebCore { |
| 445 | 445 |
| 446 enum MediaListSource { | 446 enum MediaListSource { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 { | 511 { |
| 512 ASSERT(m_style); | 512 ASSERT(m_style); |
| 513 } | 513 } |
| 514 | 514 |
| 515 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::buildObjectForStyle() con
st | 515 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::buildObjectForStyle() con
st |
| 516 { | 516 { |
| 517 RefPtr<TypeBuilder::CSS::CSSStyle> result = styleWithProperties(); | 517 RefPtr<TypeBuilder::CSS::CSSStyle> result = styleWithProperties(); |
| 518 if (!m_styleId.isEmpty()) | 518 if (!m_styleId.isEmpty()) |
| 519 result->setStyleId(m_styleId.asProtocolValue<TypeBuilder::CSS::CSSStyleI
d>()); | 519 result->setStyleId(m_styleId.asProtocolValue<TypeBuilder::CSS::CSSStyleI
d>()); |
| 520 | 520 |
| 521 RefPtr<CSSRuleSourceData> sourceData = extractSourceData(); | 521 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); |
| 522 if (sourceData) | 522 if (sourceData) |
| 523 result->setRange(buildSourceRangeObject(sourceData->ruleBodyRange, m_par
entStyleSheet->lineEndings().get())); | 523 result->setRange(buildSourceRangeObject(sourceData->ruleBodyRange, m_par
entStyleSheet->lineEndings().get())); |
| 524 | 524 |
| 525 return result.release(); | 525 return result.release(); |
| 526 } | 526 } |
| 527 | 527 |
| 528 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> > Insp
ectorStyle::buildArrayForComputedStyle() const | 528 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> > Insp
ectorStyle::buildArrayForComputedStyle() const |
| 529 { | 529 { |
| 530 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> > resu
lt = TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty>::create(); | 530 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> > resu
lt = TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty>::create(); |
| 531 Vector<InspectorStyleProperty> properties; | 531 WillBeHeapVector<InspectorStyleProperty> properties; |
| 532 populateAllProperties(properties); | 532 populateAllProperties(properties); |
| 533 | 533 |
| 534 for (Vector<InspectorStyleProperty>::iterator it = properties.begin(), itEnd
= properties.end(); it != itEnd; ++it) { | 534 for (WillBeHeapVector<InspectorStyleProperty>::iterator it = properties.begi
n(), itEnd = properties.end(); it != itEnd; ++it) { |
| 535 const CSSPropertySourceData& propertyEntry = it->sourceData; | 535 const CSSPropertySourceData& propertyEntry = it->sourceData; |
| 536 RefPtr<TypeBuilder::CSS::CSSComputedStyleProperty> entry = TypeBuilder::
CSS::CSSComputedStyleProperty::create() | 536 RefPtr<TypeBuilder::CSS::CSSComputedStyleProperty> entry = TypeBuilder::
CSS::CSSComputedStyleProperty::create() |
| 537 .setName(propertyEntry.name) | 537 .setName(propertyEntry.name) |
| 538 .setValue(propertyEntry.value); | 538 .setValue(propertyEntry.value); |
| 539 result->addItem(entry); | 539 result->addItem(entry); |
| 540 } | 540 } |
| 541 | 541 |
| 542 return result.release(); | 542 return result.release(); |
| 543 } | 543 } |
| 544 | 544 |
| 545 bool InspectorStyle::verifyPropertyText(const String& propertyText, bool canOmit
Semicolon) | 545 bool InspectorStyle::verifyPropertyText(const String& propertyText, bool canOmit
Semicolon) |
| 546 { | 546 { |
| 547 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); | 547 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); |
| 548 RefPtrWillBeRawPtr<MutableStylePropertySet> tempMutableStyle = MutableStyleP
ropertySet::create(); | 548 RefPtrWillBeRawPtr<MutableStylePropertySet> tempMutableStyle = MutableStyleP
ropertySet::create(); |
| 549 RuleSourceDataList sourceData; | 549 RuleSourceDataList sourceData; |
| 550 RefPtrWillBeRawPtr<StyleSheetContents> styleSheetContents = StyleSheetConten
ts::create(strictCSSParserContext()); | 550 RefPtrWillBeRawPtr<StyleSheetContents> styleSheetContents = StyleSheetConten
ts::create(strictCSSParserContext()); |
| 551 String declarationText = propertyText + (canOmitSemicolon ? ";" : " ") + bog
usPropertyName + ": none"; | 551 String declarationText = propertyText + (canOmitSemicolon ? ";" : " ") + bog
usPropertyName + ": none"; |
| 552 StyleSheetHandler handler(declarationText, ownerDocument(), styleSheetConten
ts.get(), &sourceData); | 552 StyleSheetHandler handler(declarationText, ownerDocument(), styleSheetConten
ts.get(), &sourceData); |
| 553 BisonCSSParser(ownerDocument()).parseDeclaration(tempMutableStyle.get(), dec
larationText, &handler, styleSheetContents.get()); | 553 BisonCSSParser(ownerDocument()).parseDeclaration(tempMutableStyle.get(), dec
larationText, &handler, styleSheetContents.get()); |
| 554 Vector<CSSPropertySourceData>& propertyData = sourceData.first()->styleSourc
eData->propertyData; | 554 WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.first()->
styleSourceData->propertyData; |
| 555 unsigned propertyCount = propertyData.size(); | 555 unsigned propertyCount = propertyData.size(); |
| 556 | 556 |
| 557 // At least one property + the bogus property added just above should be pre
sent. | 557 // At least one property + the bogus property added just above should be pre
sent. |
| 558 if (propertyCount < 2) | 558 if (propertyCount < 2) |
| 559 return false; | 559 return false; |
| 560 | 560 |
| 561 // Check for the proper propertyText termination (the parser could at least
restore to the PROPERTY_NAME state). | 561 // Check for the proper propertyText termination (the parser could at least
restore to the PROPERTY_NAME state). |
| 562 if (propertyData.at(propertyCount - 1).name != bogusPropertyName) | 562 if (propertyData.at(propertyCount - 1).name != bogusPropertyName) |
| 563 return false; | 563 return false; |
| 564 | 564 |
| 565 return true; | 565 return true; |
| 566 } | 566 } |
| 567 | 567 |
| 568 bool InspectorStyle::setPropertyText(unsigned index, const String& propertyText,
bool overwrite, ExceptionState& exceptionState) | 568 bool InspectorStyle::setPropertyText(unsigned index, const String& propertyText,
bool overwrite, ExceptionState& exceptionState) |
| 569 { | 569 { |
| 570 ASSERT(m_parentStyleSheet); | 570 ASSERT(m_parentStyleSheet); |
| 571 | 571 |
| 572 if (!m_parentStyleSheet->ensureParsedDataReady()) { | 572 if (!m_parentStyleSheet->ensureParsedDataReady()) { |
| 573 exceptionState.throwDOMException(NotFoundError, "The parent style sheet'
s data hasn't been processed."); | 573 exceptionState.throwDOMException(NotFoundError, "The parent style sheet'
s data hasn't been processed."); |
| 574 return false; | 574 return false; |
| 575 } | 575 } |
| 576 | 576 |
| 577 if (!propertyText.stripWhiteSpace().isEmpty()) { | 577 if (!propertyText.stripWhiteSpace().isEmpty()) { |
| 578 if (!verifyPropertyText(propertyText, false) && !verifyPropertyText(prop
ertyText, true)) { | 578 if (!verifyPropertyText(propertyText, false) && !verifyPropertyText(prop
ertyText, true)) { |
| 579 exceptionState.throwDOMException(SyntaxError, "The property '" + pro
pertyText + "' could not be set."); | 579 exceptionState.throwDOMException(SyntaxError, "The property '" + pro
pertyText + "' could not be set."); |
| 580 return false; | 580 return false; |
| 581 } | 581 } |
| 582 } | 582 } |
| 583 | 583 |
| 584 RefPtr<CSSRuleSourceData> sourceData = extractSourceData(); | 584 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); |
| 585 if (!sourceData) { | 585 if (!sourceData) { |
| 586 exceptionState.throwDOMException(NotFoundError, "The property '" + prope
rtyText + "' could not be set."); | 586 exceptionState.throwDOMException(NotFoundError, "The property '" + prope
rtyText + "' could not be set."); |
| 587 return false; | 587 return false; |
| 588 } | 588 } |
| 589 | 589 |
| 590 String text; | 590 String text; |
| 591 bool success = styleText(&text); | 591 bool success = styleText(&text); |
| 592 if (!success) { | 592 if (!success) { |
| 593 exceptionState.throwDOMException(NotFoundError, "The property '" + prope
rtyText + "' could not be set."); | 593 exceptionState.throwDOMException(NotFoundError, "The property '" + prope
rtyText + "' could not be set."); |
| 594 return false; | 594 return false; |
| 595 } | 595 } |
| 596 | 596 |
| 597 Vector<InspectorStyleProperty> allProperties; | 597 WillBeHeapVector<InspectorStyleProperty> allProperties; |
| 598 populateAllProperties(allProperties); | 598 populateAllProperties(allProperties); |
| 599 | 599 |
| 600 InspectorStyleTextEditor editor(&allProperties, text, newLineAndWhitespaceDe
limiters()); | 600 InspectorStyleTextEditor editor(&allProperties, text, newLineAndWhitespaceDe
limiters()); |
| 601 if (overwrite) { | 601 if (overwrite) { |
| 602 if (index >= allProperties.size()) { | 602 if (index >= allProperties.size()) { |
| 603 exceptionState.throwDOMException(IndexSizeError, "The index provided
(" + String::number(index) + ") is greater than or equal to the maximum bound (
" + String::number(allProperties.size()) + ")."); | 603 exceptionState.throwDOMException(IndexSizeError, "The index provided
(" + String::number(index) + ") is greater than or equal to the maximum bound (
" + String::number(allProperties.size()) + ")."); |
| 604 return false; | 604 return false; |
| 605 } | 605 } |
| 606 editor.replaceProperty(index, propertyText); | 606 editor.replaceProperty(index, propertyText); |
| 607 } else { | 607 } else { |
| 608 editor.insertProperty(index, propertyText, sourceData->ruleBodyRange.len
gth()); | 608 editor.insertProperty(index, propertyText, sourceData->ruleBodyRange.len
gth()); |
| 609 } | 609 } |
| 610 | 610 |
| 611 return m_parentStyleSheet->setStyleText(m_styleId, editor.styleText()); | 611 return m_parentStyleSheet->setStyleText(m_styleId, editor.styleText()); |
| 612 } | 612 } |
| 613 | 613 |
| 614 bool InspectorStyle::styleText(String* result) const | 614 bool InspectorStyle::styleText(String* result) const |
| 615 { | 615 { |
| 616 RefPtr<CSSRuleSourceData> sourceData = extractSourceData(); | 616 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); |
| 617 if (!sourceData) | 617 if (!sourceData) |
| 618 return false; | 618 return false; |
| 619 | 619 |
| 620 String styleSheetText; | 620 String styleSheetText; |
| 621 bool success = m_parentStyleSheet->getText(&styleSheetText); | 621 bool success = m_parentStyleSheet->getText(&styleSheetText); |
| 622 if (!success) | 622 if (!success) |
| 623 return false; | 623 return false; |
| 624 | 624 |
| 625 SourceRange& bodyRange = sourceData->ruleBodyRange; | 625 SourceRange& bodyRange = sourceData->ruleBodyRange; |
| 626 *result = styleSheetText.substring(bodyRange.start, bodyRange.end - bodyRang
e.start); | 626 *result = styleSheetText.substring(bodyRange.start, bodyRange.end - bodyRang
e.start); |
| 627 return true; | 627 return true; |
| 628 } | 628 } |
| 629 | 629 |
| 630 void InspectorStyle::populateAllProperties(Vector<InspectorStyleProperty>& resul
t) const | 630 void InspectorStyle::populateAllProperties(WillBeHeapVector<InspectorStyleProper
ty>& result) const |
| 631 { | 631 { |
| 632 HashSet<String> sourcePropertyNames; | 632 HashSet<String> sourcePropertyNames; |
| 633 | 633 |
| 634 RefPtr<CSSRuleSourceData> sourceData = extractSourceData(); | 634 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); |
| 635 if (sourceData) { | 635 if (sourceData) { |
| 636 String styleDeclaration; | 636 String styleDeclaration; |
| 637 bool isStyleTextKnown = styleText(&styleDeclaration); | 637 bool isStyleTextKnown = styleText(&styleDeclaration); |
| 638 ASSERT_UNUSED(isStyleTextKnown, isStyleTextKnown); | 638 ASSERT_UNUSED(isStyleTextKnown, isStyleTextKnown); |
| 639 Vector<CSSPropertySourceData>& sourcePropertyData = sourceData->styleSou
rceData->propertyData; | 639 WillBeHeapVector<CSSPropertySourceData>& sourcePropertyData = sourceData
->styleSourceData->propertyData; |
| 640 for (Vector<CSSPropertySourceData>::const_iterator it = sourcePropertyDa
ta.begin(); it != sourcePropertyData.end(); ++it) { | 640 for (WillBeHeapVector<CSSPropertySourceData>::const_iterator it = source
PropertyData.begin(); it != sourcePropertyData.end(); ++it) { |
| 641 InspectorStyleProperty p(*it, true); | 641 InspectorStyleProperty p(*it, true); |
| 642 p.setRawTextFromStyleDeclaration(styleDeclaration); | 642 p.setRawTextFromStyleDeclaration(styleDeclaration); |
| 643 result.append(p); | 643 result.append(p); |
| 644 sourcePropertyNames.add(it->name.lower()); | 644 sourcePropertyNames.add(it->name.lower()); |
| 645 } | 645 } |
| 646 } | 646 } |
| 647 | 647 |
| 648 for (int i = 0, size = m_style->length(); i < size; ++i) { | 648 for (int i = 0, size = m_style->length(); i < size; ++i) { |
| 649 String name = m_style->item(i); | 649 String name = m_style->item(i); |
| 650 if (!sourcePropertyNames.add(name.lower()).isNewEntry) | 650 if (!sourcePropertyNames.add(name.lower()).isNewEntry) |
| 651 continue; | 651 continue; |
| 652 | 652 |
| 653 result.append(InspectorStyleProperty(CSSPropertySourceData(name, m_style
->getPropertyValue(name), !m_style->getPropertyPriority(name).isEmpty(), false,
true, SourceRange()), false)); | 653 result.append(InspectorStyleProperty(CSSPropertySourceData(name, m_style
->getPropertyValue(name), !m_style->getPropertyPriority(name).isEmpty(), false,
true, SourceRange()), false)); |
| 654 } | 654 } |
| 655 } | 655 } |
| 656 | 656 |
| 657 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::styleWithProperties() con
st | 657 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::styleWithProperties() con
st |
| 658 { | 658 { |
| 659 RefPtr<Array<TypeBuilder::CSS::CSSProperty> > propertiesObject = Array<TypeB
uilder::CSS::CSSProperty>::create(); | 659 RefPtr<Array<TypeBuilder::CSS::CSSProperty> > propertiesObject = Array<TypeB
uilder::CSS::CSSProperty>::create(); |
| 660 RefPtr<Array<TypeBuilder::CSS::ShorthandEntry> > shorthandEntries = Array<Ty
peBuilder::CSS::ShorthandEntry>::create(); | 660 RefPtr<Array<TypeBuilder::CSS::ShorthandEntry> > shorthandEntries = Array<Ty
peBuilder::CSS::ShorthandEntry>::create(); |
| 661 HashSet<String> foundShorthands; | 661 HashSet<String> foundShorthands; |
| 662 OwnPtr<Vector<unsigned> > lineEndings(m_parentStyleSheet ? m_parentStyleShee
t->lineEndings() : PassOwnPtr<Vector<unsigned> >()); | 662 OwnPtr<Vector<unsigned> > lineEndings(m_parentStyleSheet ? m_parentStyleShee
t->lineEndings() : PassOwnPtr<Vector<unsigned> >()); |
| 663 RefPtr<CSSRuleSourceData> sourceData = extractSourceData(); | 663 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); |
| 664 unsigned ruleBodyRangeStart = sourceData ? sourceData->ruleBodyRange.start :
0; | 664 unsigned ruleBodyRangeStart = sourceData ? sourceData->ruleBodyRange.start :
0; |
| 665 | 665 |
| 666 Vector<InspectorStyleProperty> properties; | 666 WillBeHeapVector<InspectorStyleProperty> properties; |
| 667 populateAllProperties(properties); | 667 populateAllProperties(properties); |
| 668 | 668 |
| 669 for (Vector<InspectorStyleProperty>::iterator it = properties.begin(), itEnd
= properties.end(); it != itEnd; ++it) { | 669 for (WillBeHeapVector<InspectorStyleProperty>::iterator it = properties.begi
n(), itEnd = properties.end(); it != itEnd; ++it) { |
| 670 const CSSPropertySourceData& propertyEntry = it->sourceData; | 670 const CSSPropertySourceData& propertyEntry = it->sourceData; |
| 671 const String& name = propertyEntry.name; | 671 const String& name = propertyEntry.name; |
| 672 | 672 |
| 673 RefPtr<TypeBuilder::CSS::CSSProperty> property = TypeBuilder::CSS::CSSPr
operty::create() | 673 RefPtr<TypeBuilder::CSS::CSSProperty> property = TypeBuilder::CSS::CSSPr
operty::create() |
| 674 .setName(name) | 674 .setName(name) |
| 675 .setValue(propertyEntry.value); | 675 .setValue(propertyEntry.value); |
| 676 propertiesObject->addItem(property); | 676 propertiesObject->addItem(property); |
| 677 | 677 |
| 678 // Default "parsedOk" == true. | 678 // Default "parsedOk" == true. |
| 679 if (!propertyEntry.parsedOk) | 679 if (!propertyEntry.parsedOk) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 } | 713 } |
| 714 } | 714 } |
| 715 } | 715 } |
| 716 | 716 |
| 717 RefPtr<TypeBuilder::CSS::CSSStyle> result = TypeBuilder::CSS::CSSStyle::crea
te() | 717 RefPtr<TypeBuilder::CSS::CSSStyle> result = TypeBuilder::CSS::CSSStyle::crea
te() |
| 718 .setCssProperties(propertiesObject) | 718 .setCssProperties(propertiesObject) |
| 719 .setShorthandEntries(shorthandEntries); | 719 .setShorthandEntries(shorthandEntries); |
| 720 return result.release(); | 720 return result.release(); |
| 721 } | 721 } |
| 722 | 722 |
| 723 PassRefPtr<CSSRuleSourceData> InspectorStyle::extractSourceData() const | 723 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyle::extractSourceData() co
nst |
| 724 { | 724 { |
| 725 if (!m_parentStyleSheet || !m_parentStyleSheet->ensureParsedDataReady()) | 725 if (!m_parentStyleSheet || !m_parentStyleSheet->ensureParsedDataReady()) |
| 726 return nullptr; | 726 return nullptr; |
| 727 return m_parentStyleSheet->ruleSourceDataFor(m_style.get()); | 727 return m_parentStyleSheet->ruleSourceDataFor(m_style.get()); |
| 728 } | 728 } |
| 729 | 729 |
| 730 String InspectorStyle::shorthandValue(const String& shorthandProperty) const | 730 String InspectorStyle::shorthandValue(const String& shorthandProperty) const |
| 731 { | 731 { |
| 732 String value = m_style->getPropertyValue(shorthandProperty); | 732 String value = m_style->getPropertyValue(shorthandProperty); |
| 733 if (value.isEmpty()) { | 733 if (value.isEmpty()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 752 return value; | 752 return value; |
| 753 } | 753 } |
| 754 | 754 |
| 755 NewLineAndWhitespace& InspectorStyle::newLineAndWhitespaceDelimiters() const | 755 NewLineAndWhitespace& InspectorStyle::newLineAndWhitespaceDelimiters() const |
| 756 { | 756 { |
| 757 DEFINE_STATIC_LOCAL(String, defaultPrefix, (" ")); | 757 DEFINE_STATIC_LOCAL(String, defaultPrefix, (" ")); |
| 758 | 758 |
| 759 if (m_formatAcquired) | 759 if (m_formatAcquired) |
| 760 return m_format; | 760 return m_format; |
| 761 | 761 |
| 762 RefPtr<CSSRuleSourceData> sourceData = extractSourceData(); | 762 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); |
| 763 Vector<CSSPropertySourceData>* sourcePropertyData = sourceData ? &(sourceDat
a->styleSourceData->propertyData) : 0; | 763 WillBeHeapVector<CSSPropertySourceData>* sourcePropertyData = sourceData ? &
(sourceData->styleSourceData->propertyData) : 0; |
| 764 int propertyCount; | 764 int propertyCount; |
| 765 if (!sourcePropertyData || !(propertyCount = sourcePropertyData->size())) { | 765 if (!sourcePropertyData || !(propertyCount = sourcePropertyData->size())) { |
| 766 m_format.first = "\n"; | 766 m_format.first = "\n"; |
| 767 m_format.second = defaultPrefix; | 767 m_format.second = defaultPrefix; |
| 768 return m_format; // Do not remember the default formatting and attempt t
o acquire it later. | 768 return m_format; // Do not remember the default formatting and attempt t
o acquire it later. |
| 769 } | 769 } |
| 770 | 770 |
| 771 String text; | 771 String text; |
| 772 bool success = styleText(&text); | 772 bool success = styleText(&text); |
| 773 ASSERT_UNUSED(success, success); | 773 ASSERT_UNUSED(success, success); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 } | 847 } |
| 848 | 848 |
| 849 void InspectorStyleSheetBase::fireStyleSheetChanged() | 849 void InspectorStyleSheetBase::fireStyleSheetChanged() |
| 850 { | 850 { |
| 851 if (listener()) | 851 if (listener()) |
| 852 listener()->styleSheetChanged(this); | 852 listener()->styleSheetChanged(this); |
| 853 } | 853 } |
| 854 | 854 |
| 855 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheetBase::buildObjectForSt
yle(CSSStyleDeclaration* style) | 855 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheetBase::buildObjectForSt
yle(CSSStyleDeclaration* style) |
| 856 { | 856 { |
| 857 RefPtr<CSSRuleSourceData> sourceData; | 857 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData; |
| 858 if (ensureParsedDataReady()) | 858 if (ensureParsedDataReady()) |
| 859 sourceData = ruleSourceDataFor(style); | 859 sourceData = ruleSourceDataFor(style); |
| 860 | 860 |
| 861 InspectorCSSId id = styleId(style); | 861 InspectorCSSId id = styleId(style); |
| 862 if (id.isEmpty()) { | 862 if (id.isEmpty()) { |
| 863 // Any rule coming from User Agent and not from DefaultStyleSheet will n
ot have id. | 863 // Any rule coming from User Agent and not from DefaultStyleSheet will n
ot have id. |
| 864 // See InspectorCSSAgent::buildObjectForRule for details. | 864 // See InspectorCSSAgent::buildObjectForRule for details. |
| 865 RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(id, style
, this); | 865 RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(id, style
, this); |
| 866 return inspectorStyle->buildObjectForStyle(); | 866 return inspectorStyle->buildObjectForStyle(); |
| 867 } | 867 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 exceptionState.throwDOMException(NotFoundError, "No rule was found for t
he given ID."); | 965 exceptionState.throwDOMException(NotFoundError, "No rule was found for t
he given ID."); |
| 966 return false; | 966 return false; |
| 967 } | 967 } |
| 968 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); | 968 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); |
| 969 if (!styleSheet || !ensureParsedDataReady()) { | 969 if (!styleSheet || !ensureParsedDataReady()) { |
| 970 exceptionState.throwDOMException(NotFoundError, "No stylesheet could be
found in which to set the selector."); | 970 exceptionState.throwDOMException(NotFoundError, "No stylesheet could be
found in which to set the selector."); |
| 971 return false; | 971 return false; |
| 972 } | 972 } |
| 973 | 973 |
| 974 rule->setSelectorText(selector); | 974 rule->setSelectorText(selector); |
| 975 RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(rule->style()); | 975 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(rule->s
tyle()); |
| 976 if (!sourceData) { | 976 if (!sourceData) { |
| 977 exceptionState.throwDOMException(NotFoundError, "The selector '" + selec
tor + "' could not be set."); | 977 exceptionState.throwDOMException(NotFoundError, "The selector '" + selec
tor + "' could not be set."); |
| 978 return false; | 978 return false; |
| 979 } | 979 } |
| 980 | 980 |
| 981 String sheetText = m_parsedStyleSheet->text(); | 981 String sheetText = m_parsedStyleSheet->text(); |
| 982 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR
ange.length(), selector); | 982 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR
ange.length(), selector); |
| 983 m_parsedStyleSheet->setText(sheetText); | 983 m_parsedStyleSheet->setText(sheetText); |
| 984 fireStyleSheetChanged(); | 984 fireStyleSheetChanged(); |
| 985 return true; | 985 return true; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 if (!rule) { | 1044 if (!rule) { |
| 1045 exceptionState.throwDOMException(NotFoundError, "No style rule could be
found for the provided ID."); | 1045 exceptionState.throwDOMException(NotFoundError, "No style rule could be
found for the provided ID."); |
| 1046 return false; | 1046 return false; |
| 1047 } | 1047 } |
| 1048 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); | 1048 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); |
| 1049 if (!styleSheet || !ensureParsedDataReady()) { | 1049 if (!styleSheet || !ensureParsedDataReady()) { |
| 1050 exceptionState.throwDOMException(NotFoundError, "No parent stylesheet co
uld be found."); | 1050 exceptionState.throwDOMException(NotFoundError, "No parent stylesheet co
uld be found."); |
| 1051 return false; | 1051 return false; |
| 1052 } | 1052 } |
| 1053 | 1053 |
| 1054 RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(rule->style()); | 1054 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(rule->s
tyle()); |
| 1055 if (!sourceData) { | 1055 if (!sourceData) { |
| 1056 exceptionState.throwDOMException(NotFoundError, "No style rule could be
found for the provided ID."); | 1056 exceptionState.throwDOMException(NotFoundError, "No style rule could be
found for the provided ID."); |
| 1057 return false; | 1057 return false; |
| 1058 } | 1058 } |
| 1059 | 1059 |
| 1060 styleSheet->deleteRule(id.ordinal(), exceptionState); | 1060 styleSheet->deleteRule(id.ordinal(), exceptionState); |
| 1061 // |rule| MAY NOT be addressed after this line! | 1061 // |rule| MAY NOT be addressed after this line! |
| 1062 | 1062 |
| 1063 if (exceptionState.hadException()) | 1063 if (exceptionState.hadException()) |
| 1064 return false; | 1064 return false; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1125 RefPtr<TypeBuilder::CSS::Selector> simpleSelector = TypeBuilder::CSS::Se
lector::create() | 1125 RefPtr<TypeBuilder::CSS::Selector> simpleSelector = TypeBuilder::CSS::Se
lector::create() |
| 1126 .setValue(selector.stripWhiteSpace()); | 1126 .setValue(selector.stripWhiteSpace()); |
| 1127 simpleSelector->setRange(buildSourceRangeObject(range, lineEndings().get
())); | 1127 simpleSelector->setRange(buildSourceRangeObject(range, lineEndings().get
())); |
| 1128 result->addItem(simpleSelector.release()); | 1128 result->addItem(simpleSelector.release()); |
| 1129 } | 1129 } |
| 1130 return result.release(); | 1130 return result.release(); |
| 1131 } | 1131 } |
| 1132 | 1132 |
| 1133 PassRefPtr<TypeBuilder::CSS::SelectorList> InspectorStyleSheet::buildObjectForSe
lectorList(CSSStyleRule* rule) | 1133 PassRefPtr<TypeBuilder::CSS::SelectorList> InspectorStyleSheet::buildObjectForSe
lectorList(CSSStyleRule* rule) |
| 1134 { | 1134 { |
| 1135 RefPtr<CSSRuleSourceData> sourceData; | 1135 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData; |
| 1136 if (ensureParsedDataReady()) | 1136 if (ensureParsedDataReady()) |
| 1137 sourceData = ruleSourceDataFor(rule->style()); | 1137 sourceData = ruleSourceDataFor(rule->style()); |
| 1138 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectors; | 1138 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectors; |
| 1139 | 1139 |
| 1140 // This intentionally does not rely on the source data to avoid catching the
trailing comments (before the declaration starting '{'). | 1140 // This intentionally does not rely on the source data to avoid catching the
trailing comments (before the declaration starting '{'). |
| 1141 String selectorText = rule->selectorText(); | 1141 String selectorText = rule->selectorText(); |
| 1142 | 1142 |
| 1143 if (sourceData) | 1143 if (sourceData) |
| 1144 selectors = selectorsFromSource(sourceData.get(), m_parsedStyleSheet->te
xt()); | 1144 selectors = selectorsFromSource(sourceData.get(), m_parsedStyleSheet->te
xt()); |
| 1145 else { | 1145 else { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1206 | 1206 |
| 1207 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR
ange(const CSSRule* rule) | 1207 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR
ange(const CSSRule* rule) |
| 1208 { | 1208 { |
| 1209 if (!ensureParsedDataReady()) | 1209 if (!ensureParsedDataReady()) |
| 1210 return nullptr; | 1210 return nullptr; |
| 1211 | 1211 |
| 1212 ensureFlatRules(); | 1212 ensureFlatRules(); |
| 1213 size_t index = m_flatRules.find(rule); | 1213 size_t index = m_flatRules.find(rule); |
| 1214 if (index == kNotFound) | 1214 if (index == kNotFound) |
| 1215 return nullptr; | 1215 return nullptr; |
| 1216 RefPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleSourceDataAt(
static_cast<unsigned>(index)); | 1216 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleS
ourceDataAt(static_cast<unsigned>(index)); |
| 1217 return buildSourceRangeObject(sourceData->ruleHeaderRange, lineEndings().get
()); | 1217 return buildSourceRangeObject(sourceData->ruleHeaderRange, lineEndings().get
()); |
| 1218 } | 1218 } |
| 1219 | 1219 |
| 1220 PassRefPtr<InspectorStyle> InspectorStyleSheet::inspectorStyleForId(const Inspec
torCSSId& id) | 1220 PassRefPtr<InspectorStyle> InspectorStyleSheet::inspectorStyleForId(const Inspec
torCSSId& id) |
| 1221 { | 1221 { |
| 1222 CSSStyleDeclaration* style = styleForId(id); | 1222 CSSStyleDeclaration* style = styleForId(id); |
| 1223 if (!style) | 1223 if (!style) |
| 1224 return nullptr; | 1224 return nullptr; |
| 1225 | 1225 |
| 1226 return InspectorStyle::create(id, style, this); | 1226 return InspectorStyle::create(id, style, this); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1307 if (index != UINT_MAX) | 1307 if (index != UINT_MAX) |
| 1308 return InspectorCSSId(id(), index); | 1308 return InspectorCSSId(id(), index); |
| 1309 return InspectorCSSId(); | 1309 return InspectorCSSId(); |
| 1310 } | 1310 } |
| 1311 | 1311 |
| 1312 Document* InspectorStyleSheet::ownerDocument() const | 1312 Document* InspectorStyleSheet::ownerDocument() const |
| 1313 { | 1313 { |
| 1314 return m_pageStyleSheet->ownerDocument(); | 1314 return m_pageStyleSheet->ownerDocument(); |
| 1315 } | 1315 } |
| 1316 | 1316 |
| 1317 PassRefPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataFor(CSSStyleDec
laration* style) const | 1317 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataFor
(CSSStyleDeclaration* style) const |
| 1318 { | 1318 { |
| 1319 return m_parsedStyleSheet->ruleSourceDataAt(ruleIndexByStyle(style)); | 1319 return m_parsedStyleSheet->ruleSourceDataAt(ruleIndexByStyle(style)); |
| 1320 } | 1320 } |
| 1321 | 1321 |
| 1322 unsigned InspectorStyleSheet::ruleIndexByStyle(CSSStyleDeclaration* pageStyle) c
onst | 1322 unsigned InspectorStyleSheet::ruleIndexByStyle(CSSStyleDeclaration* pageStyle) c
onst |
| 1323 { | 1323 { |
| 1324 ensureFlatRules(); | 1324 ensureFlatRules(); |
| 1325 for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) { | 1325 for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) { |
| 1326 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(m_flatRules.
at(i).get()); | 1326 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(m_flatRules.
at(i).get()); |
| 1327 if (styleRule && styleRule->style() == pageStyle) | 1327 if (styleRule && styleRule->style() == pageStyle) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1406 return !exceptionState.hadException(); | 1406 return !exceptionState.hadException(); |
| 1407 } | 1407 } |
| 1408 | 1408 |
| 1409 bool InspectorStyleSheet::styleSheetTextWithChangedStyle(CSSStyleDeclaration* st
yle, const String& newStyleText, String* result) | 1409 bool InspectorStyleSheet::styleSheetTextWithChangedStyle(CSSStyleDeclaration* st
yle, const String& newStyleText, String* result) |
| 1410 { | 1410 { |
| 1411 if (!style) | 1411 if (!style) |
| 1412 return false; | 1412 return false; |
| 1413 if (!ensureParsedDataReady()) | 1413 if (!ensureParsedDataReady()) |
| 1414 return false; | 1414 return false; |
| 1415 | 1415 |
| 1416 RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(style); | 1416 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(style); |
| 1417 unsigned bodyStart = sourceData->ruleBodyRange.start; | 1417 unsigned bodyStart = sourceData->ruleBodyRange.start; |
| 1418 unsigned bodyEnd = sourceData->ruleBodyRange.end; | 1418 unsigned bodyEnd = sourceData->ruleBodyRange.end; |
| 1419 ASSERT(bodyStart <= bodyEnd); | 1419 ASSERT(bodyStart <= bodyEnd); |
| 1420 | 1420 |
| 1421 String text = m_parsedStyleSheet->text(); | 1421 String text = m_parsedStyleSheet->text(); |
| 1422 ASSERT_WITH_SECURITY_IMPLICATION(bodyEnd <= text.length()); // bodyEnd is ex
clusive | 1422 ASSERT_WITH_SECURITY_IMPLICATION(bodyEnd <= text.length()); // bodyEnd is ex
clusive |
| 1423 | 1423 |
| 1424 text.replace(bodyStart, bodyEnd - bodyStart, newStyleText); | 1424 text.replace(bodyStart, bodyEnd - bodyStart, newStyleText); |
| 1425 *result = text; | 1425 *result = text; |
| 1426 return true; | 1426 return true; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1568 CSSStyleDeclaration* InspectorStyleSheetForInlineStyle::inlineStyle() const | 1568 CSSStyleDeclaration* InspectorStyleSheetForInlineStyle::inlineStyle() const |
| 1569 { | 1569 { |
| 1570 return m_element->style(); | 1570 return m_element->style(); |
| 1571 } | 1571 } |
| 1572 | 1572 |
| 1573 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const | 1573 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const |
| 1574 { | 1574 { |
| 1575 return m_element->getAttribute("style").string(); | 1575 return m_element->getAttribute("style").string(); |
| 1576 } | 1576 } |
| 1577 | 1577 |
| 1578 PassRefPtr<CSSRuleSourceData> InspectorStyleSheetForInlineStyle::getStyleAttribu
teData() const | 1578 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheetForInlineStyle::get
StyleAttributeData() const |
| 1579 { | 1579 { |
| 1580 if (!m_element->isStyledElement()) | 1580 if (!m_element->isStyledElement()) |
| 1581 return nullptr; | 1581 return nullptr; |
| 1582 | 1582 |
| 1583 if (m_styleText.isEmpty()) { | 1583 if (m_styleText.isEmpty()) { |
| 1584 RefPtr<CSSRuleSourceData> result = CSSRuleSourceData::create(CSSRuleSour
ceData::STYLE_RULE); | 1584 RefPtrWillBeRawPtr<CSSRuleSourceData> result = CSSRuleSourceData::create
(CSSRuleSourceData::STYLE_RULE); |
| 1585 result->ruleBodyRange.start = 0; | 1585 result->ruleBodyRange.start = 0; |
| 1586 result->ruleBodyRange.end = 0; | 1586 result->ruleBodyRange.end = 0; |
| 1587 return result.release(); | 1587 return result.release(); |
| 1588 } | 1588 } |
| 1589 | 1589 |
| 1590 RefPtrWillBeRawPtr<MutableStylePropertySet> tempDeclaration = MutableStylePr
opertySet::create(); | 1590 RefPtrWillBeRawPtr<MutableStylePropertySet> tempDeclaration = MutableStylePr
opertySet::create(); |
| 1591 RuleSourceDataList ruleSourceDataResult; | 1591 RuleSourceDataList ruleSourceDataResult; |
| 1592 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do
cument().elementSheet().contents(), &ruleSourceDataResult); | 1592 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do
cument().elementSheet().contents(), &ruleSourceDataResult); |
| 1593 BisonCSSParser(&m_element->document()).parseDeclaration(tempDeclaration.get(
), m_styleText, &handler, m_element->document().elementSheet().contents()); | 1593 BisonCSSParser(&m_element->document()).parseDeclaration(tempDeclaration.get(
), m_styleText, &handler, m_element->document().elementSheet().contents()); |
| 1594 return ruleSourceDataResult.first().release(); | 1594 return ruleSourceDataResult.first().release(); |
| 1595 } | 1595 } |
| 1596 | 1596 |
| 1597 } // namespace WebCore | 1597 } // namespace WebCore |
| 1598 | 1598 |
| OLD | NEW |