Chromium Code Reviews| 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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 if (propertyData.at(0).name != bogusPropertyName) | 423 if (propertyData.at(0).name != bogusPropertyName) |
| 424 return false; | 424 return false; |
| 425 | 425 |
| 426 return true; | 426 return true; |
| 427 } | 427 } |
| 428 | 428 |
| 429 } // namespace | 429 } // namespace |
| 430 | 430 |
| 431 class ParsedStyleSheet : public NoBaseWillBeGarbageCollectedFinalized<ParsedStyl eSheet> { | 431 class ParsedStyleSheet : public NoBaseWillBeGarbageCollectedFinalized<ParsedStyl eSheet> { |
| 432 public: | 432 public: |
| 433 static PassOwnPtrWillBeRawPtr<ParsedStyleSheet> create(CSSStyleSheet* pageSt yleSheet) | 433 static PassOwnPtrWillBeRawPtr<ParsedStyleSheet> create(Document* document) |
| 434 { | 434 { |
| 435 return adoptPtrWillBeNoop(new ParsedStyleSheet(pageStyleSheet)); | 435 return adoptPtrWillBeNoop(new ParsedStyleSheet(document)); |
| 436 } | 436 } |
| 437 | 437 |
| 438 const String& text() const { ASSERT(m_hasText); return m_text; } | 438 const String& text() const { ASSERT(m_hasText); return m_text; } |
| 439 void setText(const String&); | 439 void setText(const String&); |
| 440 bool hasText() const { return m_hasText; } | 440 bool hasText() const { return m_hasText; } |
| 441 bool ensureSourceData(); | 441 bool ensureSourceData(); |
| 442 bool hasSourceData() const { return m_sourceData; } | 442 bool hasSourceData() const { return m_sourceData; } |
| 443 PassRefPtrWillBeRawPtr<blink::CSSRuleSourceData> ruleSourceDataAt(unsigned) const; | 443 PassRefPtrWillBeRawPtr<blink::CSSRuleSourceData> ruleSourceDataAt(unsigned) const; |
| 444 unsigned ruleCount() { return m_sourceData->size(); } | 444 unsigned ruleCount() { return m_sourceData->size(); } |
| 445 | 445 |
| 446 DECLARE_TRACE(); | 446 DECLARE_TRACE(); |
| 447 | 447 |
| 448 private: | 448 private: |
| 449 explicit ParsedStyleSheet(CSSStyleSheet* pageStyleSheet); | 449 explicit ParsedStyleSheet(Document*); |
| 450 | 450 |
| 451 void flattenSourceData(RuleSourceDataList*); | 451 void flattenSourceData(RuleSourceDataList*); |
| 452 void setSourceData(PassOwnPtrWillBeRawPtr<RuleSourceDataList>); | 452 void setSourceData(PassOwnPtrWillBeRawPtr<RuleSourceDataList>); |
| 453 | 453 |
| 454 String m_text; | 454 String m_text; |
| 455 bool m_hasText; | 455 bool m_hasText; |
| 456 OwnPtrWillBeMember<RuleSourceDataList> m_sourceData; | 456 OwnPtrWillBeMember<RuleSourceDataList> m_sourceData; |
| 457 RefPtrWillBeMember<CSSStyleSheet> m_pageStyleSheet; | 457 RefPtrWillBeMember<Document> m_document; |
| 458 }; | 458 }; |
| 459 | 459 |
| 460 ParsedStyleSheet::ParsedStyleSheet(CSSStyleSheet* pageStyleSheet) | 460 ParsedStyleSheet::ParsedStyleSheet(Document* document) |
| 461 : m_hasText(false) | 461 : m_hasText(false) |
| 462 , m_pageStyleSheet(pageStyleSheet) | 462 , m_document(document) |
| 463 { | 463 { |
| 464 } | 464 } |
| 465 | 465 |
| 466 void ParsedStyleSheet::setText(const String& text) | 466 void ParsedStyleSheet::setText(const String& text) |
| 467 { | 467 { |
| 468 m_hasText = true; | 468 m_hasText = true; |
| 469 m_text = text; | 469 m_text = text; |
| 470 setSourceData(nullptr); | 470 setSourceData(nullptr); |
| 471 } | 471 } |
| 472 | 472 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 498 | 498 |
| 499 bool ParsedStyleSheet::ensureSourceData() | 499 bool ParsedStyleSheet::ensureSourceData() |
| 500 { | 500 { |
| 501 if (hasSourceData()) | 501 if (hasSourceData()) |
| 502 return true; | 502 return true; |
| 503 | 503 |
| 504 if (!hasText()) | 504 if (!hasText()) |
| 505 return false; | 505 return false; |
| 506 | 506 |
| 507 OwnPtrWillBeRawPtr<RuleSourceDataList> result = adoptPtrWillBeNoop(new RuleS ourceDataList()); | 507 OwnPtrWillBeRawPtr<RuleSourceDataList> result = adoptPtrWillBeNoop(new RuleS ourceDataList()); |
| 508 StyleSheetHandler handler(text(), m_pageStyleSheet->ownerDocument(), result. get()); | 508 StyleSheetHandler handler(text(), m_document.get(), result.get()); |
| 509 CSSParser::parseSheetForInspector(parserContextForDocument(m_pageStyleSheet- >ownerDocument()), text(), handler); | 509 CSSParser::parseSheetForInspector(parserContextForDocument(m_document.get()) , text(), handler); |
| 510 setSourceData(result.release()); | 510 setSourceData(result.release()); |
| 511 return hasSourceData(); | 511 return hasSourceData(); |
| 512 } | 512 } |
| 513 | 513 |
| 514 void ParsedStyleSheet::setSourceData(PassOwnPtrWillBeRawPtr<RuleSourceDataList> sourceData) | 514 void ParsedStyleSheet::setSourceData(PassOwnPtrWillBeRawPtr<RuleSourceDataList> sourceData) |
| 515 { | 515 { |
| 516 if (!sourceData) { | 516 if (!sourceData) { |
| 517 m_sourceData.clear(); | 517 m_sourceData.clear(); |
| 518 return; | 518 return; |
| 519 } | 519 } |
| 520 m_sourceData = adoptPtrWillBeNoop(new RuleSourceDataList()); | 520 m_sourceData = adoptPtrWillBeNoop(new RuleSourceDataList()); |
| 521 | 521 |
| 522 // FIXME: This is a temporary solution to retain the original flat sourceDat a structure | 522 // FIXME: This is a temporary solution to retain the original flat sourceDat a structure |
| 523 // containing only style rules, even though BisonCSSParser now provides the full rule source data tree. | 523 // containing only style rules, even though BisonCSSParser now provides the full rule source data tree. |
| 524 // Normally, we should just assign m_sourceData = sourceData; | 524 // Normally, we should just assign m_sourceData = sourceData; |
| 525 flattenSourceData(sourceData.get()); | 525 flattenSourceData(sourceData.get()); |
| 526 } | 526 } |
| 527 | 527 |
| 528 PassRefPtrWillBeRawPtr<blink::CSSRuleSourceData> ParsedStyleSheet::ruleSourceDat aAt(unsigned index) const | 528 PassRefPtrWillBeRawPtr<blink::CSSRuleSourceData> ParsedStyleSheet::ruleSourceDat aAt(unsigned index) const |
| 529 { | 529 { |
| 530 if (!hasSourceData() || index >= m_sourceData->size()) | 530 if (!hasSourceData() || index >= m_sourceData->size()) |
| 531 return nullptr; | 531 return nullptr; |
| 532 | 532 |
| 533 return m_sourceData->at(index); | 533 return m_sourceData->at(index); |
| 534 } | 534 } |
| 535 | 535 |
| 536 DEFINE_TRACE(ParsedStyleSheet) | 536 DEFINE_TRACE(ParsedStyleSheet) |
| 537 { | 537 { |
| 538 visitor->trace(m_sourceData); | 538 visitor->trace(m_sourceData); |
| 539 visitor->trace(m_pageStyleSheet); | 539 visitor->trace(m_document); |
| 540 } | 540 } |
| 541 | 541 |
| 542 namespace blink { | 542 namespace blink { |
| 543 | 543 |
| 544 enum MediaListSource { | 544 enum MediaListSource { |
| 545 MediaListSourceLinkedSheet, | 545 MediaListSourceLinkedSheet, |
| 546 MediaListSourceInlineSheet, | 546 MediaListSourceInlineSheet, |
| 547 MediaListSourceMediaRule, | 547 MediaListSourceMediaRule, |
| 548 MediaListSourceImportRule | 548 MediaListSourceImportRule |
| 549 }; | 549 }; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 570 | 570 |
| 571 if (rule->type() == CSSRule::MEDIA_RULE) | 571 if (rule->type() == CSSRule::MEDIA_RULE) |
| 572 return toCSSMediaRule(rule)->cssRules(); | 572 return toCSSMediaRule(rule)->cssRules(); |
| 573 | 573 |
| 574 if (rule->type() == CSSRule::SUPPORTS_RULE) | 574 if (rule->type() == CSSRule::SUPPORTS_RULE) |
| 575 return toCSSSupportsRule(rule)->cssRules(); | 575 return toCSSSupportsRule(rule)->cssRules(); |
| 576 | 576 |
| 577 return nullptr; | 577 return nullptr; |
| 578 } | 578 } |
| 579 | 579 |
| 580 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyle::create(unsigned ruleIndex , PassRefPtrWillBeRawPtr<CSSStyleDeclaration> style, InspectorStyleSheetBase* pa rentStyleSheet) | 580 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyle::create(PassRefPtrWillBeRa wPtr<CSSStyleDeclaration> style, PassRefPtrWillBeRawPtr<CSSRuleSourceData> sourc eData, InspectorStyleSheetBase* parentStyleSheet) |
| 581 { | 581 { |
| 582 return adoptRefWillBeNoop(new InspectorStyle(ruleIndex, style, parentStyleSh eet)); | 582 return adoptRefWillBeNoop(new InspectorStyle(style, sourceData, parentStyleS heet)); |
| 583 } | 583 } |
| 584 | 584 |
| 585 InspectorStyle::InspectorStyle(unsigned ruleIndex, PassRefPtrWillBeRawPtr<CSSSty leDeclaration> style, InspectorStyleSheetBase* parentStyleSheet) | 585 InspectorStyle::InspectorStyle(PassRefPtrWillBeRawPtr<CSSStyleDeclaration> style , PassRefPtrWillBeRawPtr<CSSRuleSourceData> sourceData, InspectorStyleSheetBase* parentStyleSheet) |
| 586 : m_ruleIndex(ruleIndex) | 586 : m_style(style) |
| 587 , m_style(style) | 587 , m_sourceData(sourceData) |
| 588 , m_parentStyleSheet(parentStyleSheet) | 588 , m_parentStyleSheet(parentStyleSheet) |
| 589 { | 589 { |
| 590 ASSERT(m_style); | 590 ASSERT(m_style); |
| 591 } | 591 } |
| 592 | 592 |
| 593 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::buildObjectForStyle() con st | 593 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::buildObjectForStyle() con st |
| 594 { | 594 { |
| 595 RefPtr<TypeBuilder::CSS::CSSStyle> result = styleWithProperties(); | 595 RefPtr<TypeBuilder::CSS::CSSStyle> result = styleWithProperties(); |
| 596 if (m_parentStyleSheet && !m_parentStyleSheet->id().isEmpty()) | 596 if (m_parentStyleSheet && !m_parentStyleSheet->id().isEmpty()) |
| 597 result->setStyleSheetId(m_parentStyleSheet->id()); | 597 result->setStyleSheetId(m_parentStyleSheet->id()); |
| 598 | 598 |
| 599 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); | 599 if (m_sourceData) { |
| 600 if (sourceData) | 600 result->setRange(buildSourceRangeObject(m_sourceData->ruleBodyRange, m_p arentStyleSheet->lineEndings())); |
| 601 result->setRange(buildSourceRangeObject(sourceData->ruleBodyRange, m_par entStyleSheet->lineEndings())); | 601 String sheetText; |
| 602 bool success = m_parentStyleSheet->getText(&sheetText); | |
| 603 if (success) { | |
| 604 const SourceRange& bodyRange = m_sourceData->ruleBodyRange; | |
| 605 result->setCssText(sheetText.substring(bodyRange.start, bodyRange.en d - bodyRange.start)); | |
| 606 } | |
| 607 } | |
| 602 | 608 |
| 603 return result.release(); | 609 return result.release(); |
| 604 } | 610 } |
| 605 | 611 |
| 606 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> > Insp ectorStyle::buildArrayForComputedStyle() const | 612 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> > Insp ectorStyle::buildArrayForComputedStyle() const |
| 607 { | 613 { |
| 608 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> > resu lt = TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty>::create(); | 614 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> > resu lt = TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty>::create(); |
| 609 WillBeHeapVector<InspectorStyleProperty> properties; | 615 WillBeHeapVector<CSSPropertySourceData> properties; |
| 610 populateAllProperties(properties); | 616 populateAllProperties(properties); |
| 611 | 617 |
| 612 for (auto& property : properties) { | 618 for (auto& property : properties) { |
| 613 const CSSPropertySourceData& propertyEntry = property.sourceData; | |
| 614 RefPtr<TypeBuilder::CSS::CSSComputedStyleProperty> entry = TypeBuilder:: CSS::CSSComputedStyleProperty::create() | 619 RefPtr<TypeBuilder::CSS::CSSComputedStyleProperty> entry = TypeBuilder:: CSS::CSSComputedStyleProperty::create() |
| 615 .setName(propertyEntry.name) | 620 .setName(property.name) |
| 616 .setValue(propertyEntry.value); | 621 .setValue(property.value); |
| 617 result->addItem(entry); | 622 result->addItem(entry); |
| 618 } | 623 } |
| 619 | 624 |
| 620 return result.release(); | 625 return result.release(); |
| 621 } | 626 } |
| 622 | 627 |
| 623 bool InspectorStyle::styleText(String* result) const | 628 bool InspectorStyle::styleText(String* result) const |
| 624 { | 629 { |
| 625 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); | 630 if (!m_sourceData) |
| 626 if (!sourceData) | |
| 627 return false; | 631 return false; |
| 628 | 632 |
| 629 return textForRange(sourceData->ruleBodyRange, result); | 633 return textForRange(m_sourceData->ruleBodyRange, result); |
| 630 } | 634 } |
| 631 | 635 |
| 632 bool InspectorStyle::textForRange(const SourceRange& range, String* result) cons t | 636 bool InspectorStyle::textForRange(const SourceRange& range, String* result) cons t |
| 633 { | 637 { |
| 634 String styleSheetText; | 638 String styleSheetText; |
| 635 bool success = m_parentStyleSheet->getText(&styleSheetText); | 639 bool success = m_parentStyleSheet->getText(&styleSheetText); |
| 636 if (!success) | 640 if (!success) |
| 637 return false; | 641 return false; |
| 638 | 642 |
| 639 ASSERT(0 <= range.start); | 643 ASSERT(0 <= range.start); |
| 640 ASSERT(range.start <= range.end); | 644 ASSERT(range.start <= range.end); |
| 641 ASSERT(range.end <= styleSheetText.length()); | 645 ASSERT(range.end <= styleSheetText.length()); |
| 642 *result = styleSheetText.substring(range.start, range.end - range.start); | 646 *result = styleSheetText.substring(range.start, range.end - range.start); |
| 643 return true; | 647 return true; |
| 644 } | 648 } |
| 645 | 649 |
| 646 void InspectorStyle::populateAllProperties(WillBeHeapVector<InspectorStyleProper ty>& result) const | 650 void InspectorStyle::populateAllProperties(WillBeHeapVector<CSSPropertySourceDat a>& result) const |
| 647 { | 651 { |
| 648 HashSet<String> sourcePropertyNames; | 652 HashSet<String> sourcePropertyNames; |
| 649 | 653 |
| 650 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); | 654 if (m_sourceData && m_sourceData->styleSourceData) { |
| 651 if (sourceData && sourceData->styleSourceData) { | 655 WillBeHeapVector<CSSPropertySourceData>& sourcePropertyData = m_sourceDa ta->styleSourceData->propertyData; |
| 652 WillBeHeapVector<CSSPropertySourceData>& sourcePropertyData = sourceData ->styleSourceData->propertyData; | |
| 653 for (const auto& data : sourcePropertyData) { | 656 for (const auto& data : sourcePropertyData) { |
| 654 InspectorStyleProperty p(data, true); | 657 result.append(data); |
| 655 bool isPropertyTextKnown = textForRange(p.sourceData.range, &p.rawTe xt); | |
| 656 ASSERT_UNUSED(isPropertyTextKnown, isPropertyTextKnown); | |
| 657 result.append(p); | |
| 658 sourcePropertyNames.add(data.name.lower()); | 658 sourcePropertyNames.add(data.name.lower()); |
| 659 } | 659 } |
| 660 } | 660 } |
| 661 | 661 |
| 662 for (int i = 0, size = m_style->length(); i < size; ++i) { | 662 for (int i = 0, size = m_style->length(); i < size; ++i) { |
| 663 String name = m_style->item(i); | 663 String name = m_style->item(i); |
| 664 if (!sourcePropertyNames.add(name.lower()).isNewEntry) | 664 if (!sourcePropertyNames.add(name.lower()).isNewEntry) |
| 665 continue; | 665 continue; |
| 666 | 666 |
| 667 String value = m_style->getPropertyValue(name); | 667 String value = m_style->getPropertyValue(name); |
| 668 if (value.isEmpty()) | 668 if (value.isEmpty()) |
| 669 continue; | 669 continue; |
| 670 result.append(InspectorStyleProperty(CSSPropertySourceData(name, value, !m_style->getPropertyPriority(name).isEmpty(), false, true, SourceRange()), fals e)); | 670 result.append(CSSPropertySourceData(name, value, !m_style->getPropertyPr iority(name).isEmpty(), false, true, SourceRange())); |
| 671 } | 671 } |
| 672 } | 672 } |
| 673 | 673 |
| 674 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::styleWithProperties() con st | 674 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::styleWithProperties() con st |
| 675 { | 675 { |
| 676 RefPtr<Array<TypeBuilder::CSS::CSSProperty> > propertiesObject = Array<TypeB uilder::CSS::CSSProperty>::create(); | 676 RefPtr<Array<TypeBuilder::CSS::CSSProperty> > propertiesObject = Array<TypeB uilder::CSS::CSSProperty>::create(); |
| 677 RefPtr<Array<TypeBuilder::CSS::ShorthandEntry> > shorthandEntries = Array<Ty peBuilder::CSS::ShorthandEntry>::create(); | 677 RefPtr<Array<TypeBuilder::CSS::ShorthandEntry> > shorthandEntries = Array<Ty peBuilder::CSS::ShorthandEntry>::create(); |
| 678 HashSet<String> foundShorthands; | 678 HashSet<String> foundShorthands; |
| 679 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); | |
| 680 | 679 |
| 681 WillBeHeapVector<InspectorStyleProperty> properties; | 680 WillBeHeapVector<CSSPropertySourceData> properties; |
| 682 populateAllProperties(properties); | 681 populateAllProperties(properties); |
| 683 | 682 |
| 684 for (auto& styleProperty : properties) { | 683 for (auto& styleProperty : properties) { |
| 685 const CSSPropertySourceData& propertyEntry = styleProperty.sourceData; | 684 const CSSPropertySourceData& propertyEntry = styleProperty; |
| 686 const String& name = propertyEntry.name; | 685 const String& name = propertyEntry.name; |
| 687 | 686 |
| 688 RefPtr<TypeBuilder::CSS::CSSProperty> property = TypeBuilder::CSS::CSSPr operty::create() | 687 RefPtr<TypeBuilder::CSS::CSSProperty> property = TypeBuilder::CSS::CSSPr operty::create() |
| 689 .setName(name) | 688 .setName(name) |
| 690 .setValue(propertyEntry.value); | 689 .setValue(propertyEntry.value); |
| 691 propertiesObject->addItem(property); | 690 propertiesObject->addItem(property); |
| 692 | 691 |
| 693 // Default "parsedOk" == true. | 692 // Default "parsedOk" == true. |
| 694 if (!propertyEntry.parsedOk) | 693 if (!propertyEntry.parsedOk) |
| 695 property->setParsedOk(false); | 694 property->setParsedOk(false); |
| 696 if (styleProperty.hasRawText()) | 695 String text; |
| 697 property->setText(styleProperty.rawText); | 696 if (styleProperty.range.length() && textForRange(styleProperty.range, &t ext)) |
| 698 | 697 property->setText(text); |
| 699 if (propertyEntry.important) | 698 if (propertyEntry.important) |
| 700 property->setImportant(true); | 699 property->setImportant(true); |
| 701 if (styleProperty.hasSource) { | 700 if (styleProperty.range.length()) { |
| 702 property->setRange(buildSourceRangeObject(propertyEntry.range, m_par entStyleSheet ? m_parentStyleSheet->lineEndings() : nullptr)); | 701 property->setRange(buildSourceRangeObject(propertyEntry.range, m_par entStyleSheet ? m_parentStyleSheet->lineEndings() : nullptr)); |
| 703 if (!propertyEntry.disabled) { | 702 if (!propertyEntry.disabled) { |
| 704 ASSERT_UNUSED(sourceData, sourceData); | |
| 705 property->setImplicit(false); | 703 property->setImplicit(false); |
| 706 } | 704 } |
| 707 property->setDisabled(propertyEntry.disabled); | 705 property->setDisabled(propertyEntry.disabled); |
| 708 } else if (!propertyEntry.disabled) { | 706 } else if (!propertyEntry.disabled) { |
| 709 bool implicit = m_style->isPropertyImplicit(name); | 707 bool implicit = m_style->isPropertyImplicit(name); |
| 710 // Default "implicit" == false. | 708 // Default "implicit" == false. |
| 711 if (implicit) | 709 if (implicit) |
| 712 property->setImplicit(true); | 710 property->setImplicit(true); |
| 713 | 711 |
| 714 String shorthand = m_style->getPropertyShorthand(name); | 712 String shorthand = m_style->getPropertyShorthand(name); |
| 715 if (!shorthand.isEmpty()) { | 713 if (!shorthand.isEmpty()) { |
| 716 if (foundShorthands.add(shorthand).isNewEntry) { | 714 if (foundShorthands.add(shorthand).isNewEntry) { |
| 717 RefPtr<TypeBuilder::CSS::ShorthandEntry> entry = TypeBuilder ::CSS::ShorthandEntry::create() | 715 RefPtr<TypeBuilder::CSS::ShorthandEntry> entry = TypeBuilder ::CSS::ShorthandEntry::create() |
| 718 .setName(shorthand) | 716 .setName(shorthand) |
| 719 .setValue(shorthandValue(shorthand)); | 717 .setValue(shorthandValue(shorthand)); |
| 720 shorthandEntries->addItem(entry); | 718 shorthandEntries->addItem(entry); |
| 721 } | 719 } |
| 722 } | 720 } |
| 723 } | 721 } |
| 724 } | 722 } |
| 725 | 723 |
| 726 RefPtr<TypeBuilder::CSS::CSSStyle> result = TypeBuilder::CSS::CSSStyle::crea te() | 724 RefPtr<TypeBuilder::CSS::CSSStyle> result = TypeBuilder::CSS::CSSStyle::crea te() |
| 727 .setCssProperties(propertiesObject) | 725 .setCssProperties(propertiesObject) |
| 728 .setShorthandEntries(shorthandEntries); | 726 .setShorthandEntries(shorthandEntries); |
| 729 return result.release(); | 727 return result.release(); |
| 730 } | 728 } |
| 731 | 729 |
| 732 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyle::extractSourceData() co nst | |
| 733 { | |
| 734 if (m_ruleIndex == UINT_MAX || !m_parentStyleSheet || !m_parentStyleSheet->e nsureParsedDataReady()) | |
| 735 return nullptr; | |
| 736 return m_parentStyleSheet->ruleSourceDataAt(m_ruleIndex); | |
| 737 } | |
| 738 | |
| 739 String InspectorStyle::shorthandValue(const String& shorthandProperty) const | 730 String InspectorStyle::shorthandValue(const String& shorthandProperty) const |
| 740 { | 731 { |
| 741 String value = m_style->getPropertyValue(shorthandProperty); | 732 String value = m_style->getPropertyValue(shorthandProperty); |
| 742 if (value.isEmpty()) { | 733 if (value.isEmpty()) { |
| 743 StringBuilder builder; | 734 StringBuilder builder; |
| 744 | 735 |
| 745 for (unsigned i = 0; i < m_style->length(); ++i) { | 736 for (unsigned i = 0; i < m_style->length(); ++i) { |
| 746 String individualProperty = m_style->item(i); | 737 String individualProperty = m_style->item(i); |
| 747 if (m_style->getPropertyShorthand(individualProperty) != shorthandPr operty) | 738 if (m_style->getPropertyShorthand(individualProperty) != shorthandPr operty) |
| 748 continue; | 739 continue; |
| 749 if (m_style->isPropertyImplicit(individualProperty)) | 740 if (m_style->isPropertyImplicit(individualProperty)) |
| 750 continue; | 741 continue; |
| 751 String individualValue = m_style->getPropertyValue(individualPropert y); | 742 String individualValue = m_style->getPropertyValue(individualPropert y); |
| 752 if (individualValue == "initial") | 743 if (individualValue == "initial") |
| 753 continue; | 744 continue; |
| 754 if (!builder.isEmpty()) | 745 if (!builder.isEmpty()) |
| 755 builder.append(' '); | 746 builder.append(' '); |
| 756 builder.append(individualValue); | 747 builder.append(individualValue); |
| 757 } | 748 } |
| 758 | 749 |
| 759 return builder.toString(); | 750 return builder.toString(); |
| 760 } | 751 } |
| 761 return value; | 752 return value; |
| 762 } | 753 } |
| 763 | 754 |
| 764 Document* InspectorStyle::ownerDocument() const | |
| 765 { | |
| 766 return m_parentStyleSheet->ownerDocument(); | |
| 767 } | |
| 768 | |
| 769 DEFINE_TRACE(InspectorStyle) | 755 DEFINE_TRACE(InspectorStyle) |
| 770 { | 756 { |
| 757 visitor->trace(m_sourceData); | |
| 771 visitor->trace(m_style); | 758 visitor->trace(m_style); |
| 772 visitor->trace(m_parentStyleSheet); | 759 visitor->trace(m_parentStyleSheet); |
| 773 } | 760 } |
| 774 | 761 |
| 775 InspectorStyleSheetBase::InspectorStyleSheetBase(const String& id, Listener* lis tener) | 762 InspectorStyleSheetBase::InspectorStyleSheetBase(const String& id, Listener* lis tener) |
| 776 : m_id(id) | 763 : m_id(id) |
| 777 , m_listener(listener) | 764 , m_listener(listener) |
| 778 , m_lineEndings(adoptPtr(new LineEndings())) | 765 , m_lineEndings(adoptPtr(new LineEndings())) |
| 779 { | 766 { |
| 780 } | 767 } |
| 781 | 768 |
| 782 void InspectorStyleSheetBase::onStyleSheetTextChanged() | 769 void InspectorStyleSheetBase::onStyleSheetTextChanged() |
| 783 { | 770 { |
| 784 m_lineEndings = adoptPtr(new LineEndings()); | 771 m_lineEndings = adoptPtr(new LineEndings()); |
| 785 if (listener()) | 772 if (listener()) |
| 786 listener()->styleSheetChanged(this); | 773 listener()->styleSheetChanged(this); |
| 787 } | 774 } |
| 788 | 775 |
| 789 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheetBase::buildObjectForSt yle(CSSStyleDeclaration* style) | 776 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheetBase::buildObjectForSt yle(CSSStyleDeclaration* style) |
| 790 { | 777 { |
| 791 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; | 778 RefPtrWillBeRawPtr<InspectorStyle> is = inspectorStyle(style); |
| 792 unsigned ruleIndex = indexOf(style); | 779 return is->buildObjectForStyle(); |
|
lushnikov
2015/06/23 10:26:11
inline "is"
| |
| 793 if (ruleIndex != UINT_MAX && ensureParsedDataReady()) | |
| 794 sourceData = ruleSourceDataAt(ruleIndex); | |
| 795 | |
| 796 if (ruleIndex == UINT_MAX) { | |
| 797 // Any rule coming from User Agent and not from DefaultStyleSheet will n ot have id. | |
| 798 // See InspectorCSSAgent::buildObjectForRule for details. | |
| 799 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = InspectorStyle::crea te(UINT_MAX, style, this); | |
| 800 return inspectorStyle->buildObjectForStyle(); | |
| 801 } | |
| 802 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleAt(ruleInd ex); | |
| 803 RefPtr<TypeBuilder::CSS::CSSStyle> result = inspectorStyle->buildObjectForSt yle(); | |
| 804 | |
| 805 // Style text cannot be retrieved without stylesheet, so set cssText here. | |
| 806 if (sourceData) { | |
| 807 String sheetText; | |
| 808 bool success = getText(&sheetText); | |
| 809 if (success) { | |
| 810 const SourceRange& bodyRange = sourceData->ruleBodyRange; | |
| 811 result->setCssText(sheetText.substring(bodyRange.start, bodyRange.en d - bodyRange.start)); | |
| 812 } | |
| 813 } | |
| 814 | |
| 815 return result.release(); | |
| 816 } | 780 } |
| 817 | 781 |
| 818 const LineEndings* InspectorStyleSheetBase::lineEndings() | 782 const LineEndings* InspectorStyleSheetBase::lineEndings() |
| 819 { | 783 { |
| 820 if (m_lineEndings->size() > 0) | 784 if (m_lineEndings->size() > 0) |
| 821 return m_lineEndings.get(); | 785 return m_lineEndings.get(); |
| 822 String text; | 786 String text; |
| 823 if (getText(&text)) | 787 if (getText(&text)) |
| 824 m_lineEndings = WTF::lineEndings(text); | 788 m_lineEndings = WTF::lineEndings(text); |
| 825 return m_lineEndings.get(); | 789 return m_lineEndings.get(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 844 } | 808 } |
| 845 | 809 |
| 846 InspectorStyleSheet::InspectorStyleSheet(InspectorResourceAgent* resourceAgent, const String& id, PassRefPtrWillBeRawPtr<CSSStyleSheet> pageStyleSheet, TypeBuil der::CSS::StyleSheetOrigin::Enum origin, const String& documentURL, InspectorCSS Agent* cssAgent) | 810 InspectorStyleSheet::InspectorStyleSheet(InspectorResourceAgent* resourceAgent, const String& id, PassRefPtrWillBeRawPtr<CSSStyleSheet> pageStyleSheet, TypeBuil der::CSS::StyleSheetOrigin::Enum origin, const String& documentURL, InspectorCSS Agent* cssAgent) |
| 847 : InspectorStyleSheetBase(id, cssAgent) | 811 : InspectorStyleSheetBase(id, cssAgent) |
| 848 , m_cssAgent(cssAgent) | 812 , m_cssAgent(cssAgent) |
| 849 , m_resourceAgent(resourceAgent) | 813 , m_resourceAgent(resourceAgent) |
| 850 , m_pageStyleSheet(pageStyleSheet) | 814 , m_pageStyleSheet(pageStyleSheet) |
| 851 , m_origin(origin) | 815 , m_origin(origin) |
| 852 , m_documentURL(documentURL) | 816 , m_documentURL(documentURL) |
| 853 { | 817 { |
| 854 m_parsedStyleSheet = ParsedStyleSheet::create(m_pageStyleSheet.get()); | 818 m_parsedStyleSheet = ParsedStyleSheet::create(m_pageStyleSheet->ownerDocumen t()); |
| 855 } | 819 } |
| 856 | 820 |
| 857 InspectorStyleSheet::~InspectorStyleSheet() | 821 InspectorStyleSheet::~InspectorStyleSheet() |
| 858 { | 822 { |
| 859 } | 823 } |
| 860 | 824 |
| 861 DEFINE_TRACE(InspectorStyleSheet) | 825 DEFINE_TRACE(InspectorStyleSheet) |
| 862 { | 826 { |
| 863 visitor->trace(m_cssAgent); | 827 visitor->trace(m_cssAgent); |
| 864 visitor->trace(m_resourceAgent); | 828 visitor->trace(m_resourceAgent); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 902 | 866 |
| 903 if (listener()) | 867 if (listener()) |
| 904 listener()->didReparseStyleSheet(); | 868 listener()->didReparseStyleSheet(); |
| 905 onStyleSheetTextChanged(); | 869 onStyleSheetTextChanged(); |
| 906 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate); | 870 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate); |
| 907 return true; | 871 return true; |
| 908 } | 872 } |
| 909 | 873 |
| 910 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::setRuleSelector(const Sour ceRange& range, const String& text, SourceRange* newRange, String* oldText, Exce ptionState& exceptionState) | 874 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::setRuleSelector(const Sour ceRange& range, const String& text, SourceRange* newRange, String* oldText, Exce ptionState& exceptionState) |
| 911 { | 875 { |
| 912 if (!verifySelectorText(ownerDocument(), text)) { | 876 if (!verifySelectorText(m_pageStyleSheet->ownerDocument(), text)) { |
| 913 exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid."); | 877 exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid."); |
| 914 return nullptr; | 878 return nullptr; |
| 915 } | 879 } |
| 916 | 880 |
| 917 CSSRule* rule = nullptr; | 881 CSSRule* rule = nullptr; |
| 918 CSSRuleSourceData* sourceData = nullptr; | 882 CSSRuleSourceData* sourceData = nullptr; |
| 919 if (!findRuleByHeaderRange(range, &rule, &sourceData) || !sourceData->styleS ourceData || rule->type() != CSSRule::STYLE_RULE) { | 883 if (!findRuleByHeaderRange(range, &rule, &sourceData) || !sourceData->styleS ourceData || rule->type() != CSSRule::STYLE_RULE) { |
| 920 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing source range"); | 884 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing source range"); |
| 921 return nullptr; | 885 return nullptr; |
| 922 } | 886 } |
| 923 | 887 |
| 924 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = InspectorCSSAgent::asCSSStyleR ule(rule); | 888 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = InspectorCSSAgent::asCSSStyleR ule(rule); |
| 925 styleRule->setSelectorText(text); | 889 styleRule->setSelectorText(text); |
| 926 | 890 |
| 927 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText); | 891 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText); |
| 928 onStyleSheetTextChanged(); | 892 onStyleSheetTextChanged(); |
| 929 | 893 |
| 930 return styleRule; | 894 return styleRule; |
| 931 } | 895 } |
| 932 | 896 |
| 933 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::setStyleText(const SourceR ange& range, const String& text, SourceRange* newRange, String* oldText, Excepti onState& exceptionState) | 897 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::setStyleText(const SourceR ange& range, const String& text, SourceRange* newRange, String* oldText, Excepti onState& exceptionState) |
| 934 { | 898 { |
| 935 if (!verifyStyleText(ownerDocument(), text)) { | 899 if (!verifyStyleText(m_pageStyleSheet->ownerDocument(), text)) { |
| 936 exceptionState.throwDOMException(SyntaxError, "Style text is not valid." ); | 900 exceptionState.throwDOMException(SyntaxError, "Style text is not valid." ); |
| 937 return nullptr; | 901 return nullptr; |
| 938 } | 902 } |
| 939 | 903 |
| 940 CSSRule* rule = nullptr; | 904 CSSRule* rule = nullptr; |
| 941 CSSRuleSourceData* sourceData = nullptr; | 905 CSSRuleSourceData* sourceData = nullptr; |
| 942 if (!findRuleByBodyRange(range, &rule, &sourceData) || !sourceData->styleSou rceData || rule->type() != CSSRule::STYLE_RULE) { | 906 if (!findRuleByBodyRange(range, &rule, &sourceData) || !sourceData->styleSou rceData || rule->type() != CSSRule::STYLE_RULE) { |
| 943 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing style source range"); | 907 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing style source range"); |
| 944 return nullptr; | 908 return nullptr; |
| 945 } | 909 } |
| 946 | 910 |
| 947 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = InspectorCSSAgent::asCSSStyleRu le(rule); | 911 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = InspectorCSSAgent::asCSSStyleRu le(rule); |
| 948 styleRule->style()->setCSSText(text, exceptionState); | 912 styleRule->style()->setCSSText(text, exceptionState); |
| 949 | 913 |
| 950 replaceText(sourceData->ruleBodyRange, text, newRange, oldText); | 914 replaceText(sourceData->ruleBodyRange, text, newRange, oldText); |
| 951 onStyleSheetTextChanged(); | 915 onStyleSheetTextChanged(); |
| 952 | 916 |
| 953 return styleRule; | 917 return styleRule; |
| 954 } | 918 } |
| 955 | 919 |
| 956 RefPtrWillBeRawPtr<CSSMediaRule> InspectorStyleSheet::setMediaRuleText(const Sou rceRange& range, const String& text, SourceRange* newRange, String* oldText, Exc eptionState& exceptionState) | 920 RefPtrWillBeRawPtr<CSSMediaRule> InspectorStyleSheet::setMediaRuleText(const Sou rceRange& range, const String& text, SourceRange* newRange, String* oldText, Exc eptionState& exceptionState) |
| 957 { | 921 { |
| 958 if (!verifyMediaText(ownerDocument(), text)) { | 922 if (!verifyMediaText(m_pageStyleSheet->ownerDocument(), text)) { |
| 959 exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid."); | 923 exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid."); |
| 960 return nullptr; | 924 return nullptr; |
| 961 } | 925 } |
| 962 | 926 |
| 963 CSSRule* rule = nullptr; | 927 CSSRule* rule = nullptr; |
| 964 CSSRuleSourceData* sourceData = nullptr; | 928 CSSRuleSourceData* sourceData = nullptr; |
| 965 if (!findRuleByHeaderRange(range, &rule, &sourceData) || !sourceData->mediaS ourceData || rule->type() != CSSRule::MEDIA_RULE) { | 929 if (!findRuleByHeaderRange(range, &rule, &sourceData) || !sourceData->mediaS ourceData || rule->type() != CSSRule::MEDIA_RULE) { |
| 966 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing source range"); | 930 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing source range"); |
| 967 return nullptr; | 931 return nullptr; |
| 968 } | 932 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1046 return insertCSSOMRuleInMediaRule(toCSSMediaRule(rule.get()), sourceRange, r uleText, exceptionState); | 1010 return insertCSSOMRuleInMediaRule(toCSSMediaRule(rule.get()), sourceRange, r uleText, exceptionState); |
| 1047 } | 1011 } |
| 1048 | 1012 |
| 1049 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::addRule(const String& rule Text, const SourceRange& location, SourceRange* addedRange, ExceptionState& exce ptionState) | 1013 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::addRule(const String& rule Text, const SourceRange& location, SourceRange* addedRange, ExceptionState& exce ptionState) |
| 1050 { | 1014 { |
| 1051 if (location.start != location.end) { | 1015 if (location.start != location.end) { |
| 1052 exceptionState.throwDOMException(NotFoundError, "Source range must be co llapsed."); | 1016 exceptionState.throwDOMException(NotFoundError, "Source range must be co llapsed."); |
| 1053 return nullptr; | 1017 return nullptr; |
| 1054 } | 1018 } |
| 1055 | 1019 |
| 1056 if (!verifyRuleText(ownerDocument(), ruleText)) { | 1020 if (!verifyRuleText(m_pageStyleSheet->ownerDocument(), ruleText)) { |
| 1057 exceptionState.throwDOMException(SyntaxError, "Rule text is not valid.") ; | 1021 exceptionState.throwDOMException(SyntaxError, "Rule text is not valid.") ; |
| 1058 return nullptr; | 1022 return nullptr; |
| 1059 } | 1023 } |
| 1060 | 1024 |
| 1061 if (!ensureParsedDataReady()) { | 1025 if (!ensureParsedDataReady()) { |
| 1062 exceptionState.throwDOMException(NotFoundError, "Cannot parse style shee t."); | 1026 exceptionState.throwDOMException(NotFoundError, "Cannot parse style shee t."); |
| 1063 return nullptr; | 1027 return nullptr; |
| 1064 } | 1028 } |
| 1065 ensureFlatRules(); | 1029 ensureFlatRules(); |
| 1066 | 1030 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1150 void InspectorStyleSheet::innerSetText(const String& newText) | 1114 void InspectorStyleSheet::innerSetText(const String& newText) |
| 1151 { | 1115 { |
| 1152 Element* element = ownerStyleElement(); | 1116 Element* element = ownerStyleElement(); |
| 1153 if (element) | 1117 if (element) |
| 1154 m_cssAgent->addEditedStyleElement(DOMNodeIds::idForNode(element), newTex t); | 1118 m_cssAgent->addEditedStyleElement(DOMNodeIds::idForNode(element), newTex t); |
| 1155 else | 1119 else |
| 1156 m_cssAgent->addEditedStyleSheet(finalURL(), newText); | 1120 m_cssAgent->addEditedStyleSheet(finalURL(), newText); |
| 1157 m_parsedStyleSheet->setText(newText); | 1121 m_parsedStyleSheet->setText(newText); |
| 1158 } | 1122 } |
| 1159 | 1123 |
| 1160 CSSStyleRule* InspectorStyleSheet::ruleAt(unsigned ruleIndex) const | |
| 1161 { | |
| 1162 ASSERT(!id().isEmpty()); | |
| 1163 ensureFlatRules(); | |
| 1164 return InspectorCSSAgent::asCSSStyleRule(ruleIndex >= m_flatRules.size() ? n ullptr : m_flatRules.at(ruleIndex).get()); | |
| 1165 } | |
| 1166 | |
| 1167 CSSMediaRule* InspectorStyleSheet::mediaRuleAt(unsigned ruleIndex) const | |
| 1168 { | |
| 1169 ASSERT(!id().isEmpty()); | |
| 1170 ensureFlatRules(); | |
| 1171 return InspectorCSSAgent::asCSSMediaRule(ruleIndex >= m_flatRules.size() ? n ullptr : m_flatRules.at(ruleIndex).get()); | |
| 1172 } | |
| 1173 | |
| 1174 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> InspectorStyleSheet::buildObje ctForStyleSheetInfo() const | 1124 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> InspectorStyleSheet::buildObje ctForStyleSheetInfo() const |
| 1175 { | 1125 { |
| 1176 CSSStyleSheet* styleSheet = pageStyleSheet(); | 1126 CSSStyleSheet* styleSheet = pageStyleSheet(); |
| 1177 if (!styleSheet) | 1127 if (!styleSheet) |
| 1178 return nullptr; | 1128 return nullptr; |
| 1179 | 1129 |
| 1180 Document* document = styleSheet->ownerDocument(); | 1130 Document* document = styleSheet->ownerDocument(); |
| 1181 LocalFrame* frame = document ? document->frame() : nullptr; | 1131 LocalFrame* frame = document ? document->frame() : nullptr; |
| 1182 | 1132 |
| 1183 RefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> result = TypeBuilder::CSS::CSS StyleSheetHeader::create() | 1133 RefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> result = TypeBuilder::CSS::CSS StyleSheetHeader::create() |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1223 simpleSelector->setRange(buildSourceRangeObject(range, lineEndings())); | 1173 simpleSelector->setRange(buildSourceRangeObject(range, lineEndings())); |
| 1224 result->addItem(simpleSelector.release()); | 1174 result->addItem(simpleSelector.release()); |
| 1225 } | 1175 } |
| 1226 return result.release(); | 1176 return result.release(); |
| 1227 } | 1177 } |
| 1228 | 1178 |
| 1229 PassRefPtr<TypeBuilder::CSS::SelectorList> InspectorStyleSheet::buildObjectForSe lectorList(CSSStyleRule* rule) | 1179 PassRefPtr<TypeBuilder::CSS::SelectorList> InspectorStyleSheet::buildObjectForSe lectorList(CSSStyleRule* rule) |
| 1230 { | 1180 { |
| 1231 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; | 1181 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; |
| 1232 unsigned ruleIndex = indexOf(rule->style()); | 1182 unsigned ruleIndex = indexOf(rule->style()); |
| 1233 if (ruleIndex != UINT_MAX && ensureParsedDataReady()) | 1183 if (ruleIndex != UINT_MAX && ensureParsedDataReady()) { |
| 1234 sourceData = ruleSourceDataAt(ruleIndex); | 1184 sourceData = m_parsedStyleSheet->ruleSourceDataAt(ruleIndex); |
| 1185 } | |
| 1235 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectors; | 1186 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectors; |
| 1236 | 1187 |
| 1237 // This intentionally does not rely on the source data to avoid catching the trailing comments (before the declaration starting '{'). | 1188 // This intentionally does not rely on the source data to avoid catching the trailing comments (before the declaration starting '{'). |
| 1238 String selectorText = rule->selectorText(); | 1189 String selectorText = rule->selectorText(); |
| 1239 | 1190 |
| 1240 if (sourceData) | 1191 if (sourceData) |
| 1241 selectors = selectorsFromSource(sourceData.get(), m_parsedStyleSheet->te xt()); | 1192 selectors = selectorsFromSource(sourceData.get(), m_parsedStyleSheet->te xt()); |
| 1242 else { | 1193 else { |
| 1243 selectors = TypeBuilder::Array<TypeBuilder::CSS::Selector>::create(); | 1194 selectors = TypeBuilder::Array<TypeBuilder::CSS::Selector>::create(); |
| 1244 const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); | 1195 const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1280 } | 1231 } |
| 1281 | 1232 |
| 1282 bool InspectorStyleSheet::getText(String* result) const | 1233 bool InspectorStyleSheet::getText(String* result) const |
| 1283 { | 1234 { |
| 1284 if (!ensureText()) | 1235 if (!ensureText()) |
| 1285 return false; | 1236 return false; |
| 1286 *result = m_parsedStyleSheet->text(); | 1237 *result = m_parsedStyleSheet->text(); |
| 1287 return true; | 1238 return true; |
| 1288 } | 1239 } |
| 1289 | 1240 |
| 1290 CSSStyleDeclaration* InspectorStyleSheet::styleAt(unsigned ruleIndex) const | |
| 1291 { | |
| 1292 CSSStyleRule* rule = ruleAt(ruleIndex); | |
| 1293 if (!rule) | |
| 1294 return nullptr; | |
| 1295 | |
| 1296 return rule->style(); | |
| 1297 } | |
| 1298 | |
| 1299 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR ange(const CSSRule* rule) | 1241 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR ange(const CSSRule* rule) |
| 1300 { | 1242 { |
| 1301 if (!ensureParsedDataReady()) | 1243 if (!ensureParsedDataReady()) |
| 1302 return nullptr; | 1244 return nullptr; |
| 1303 | 1245 |
| 1304 ensureFlatRules(); | 1246 ensureFlatRules(); |
| 1305 size_t index = m_flatRules.find(rule); | 1247 size_t index = m_flatRules.find(rule); |
| 1306 // FIXME(lusnikov): m_flatRules are not always aligned with the m_parsedStyl eSheet rule source | 1248 // FIXME(lusnikov): m_flatRules are not always aligned with the m_parsedStyl eSheet rule source |
| 1307 // datas due to the CSSOM operations that add/remove rules without changing source. | 1249 // datas due to the CSSOM operations that add/remove rules without changing source. |
| 1308 // This is a design issue. See crbug.com/178410 | 1250 // This is a design issue. See crbug.com/178410 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1322 return nullptr; | 1264 return nullptr; |
| 1323 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleS ourceDataAt(static_cast<unsigned>(index)); | 1265 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleS ourceDataAt(static_cast<unsigned>(index)); |
| 1324 if (!sourceData->mediaSourceData || mediaQueryIndex >= sourceData->mediaSour ceData->queryData.size()) | 1266 if (!sourceData->mediaSourceData || mediaQueryIndex >= sourceData->mediaSour ceData->queryData.size()) |
| 1325 return nullptr; | 1267 return nullptr; |
| 1326 RefPtrWillBeRawPtr<CSSMediaQuerySourceData> mediaQueryData = sourceData->med iaSourceData->queryData.at(mediaQueryIndex); | 1268 RefPtrWillBeRawPtr<CSSMediaQuerySourceData> mediaQueryData = sourceData->med iaSourceData->queryData.at(mediaQueryIndex); |
| 1327 if (mediaQueryExpIndex >= mediaQueryData->expData.size()) | 1269 if (mediaQueryExpIndex >= mediaQueryData->expData.size()) |
| 1328 return nullptr; | 1270 return nullptr; |
| 1329 return buildSourceRangeObject(mediaQueryData->expData.at(mediaQueryExpIndex) .valueRange, lineEndings()); | 1271 return buildSourceRangeObject(mediaQueryData->expData.at(mediaQueryExpIndex) .valueRange, lineEndings()); |
| 1330 } | 1272 } |
| 1331 | 1273 |
| 1332 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheet::inspectorStyleAt(uns igned ruleIndex) | 1274 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheet::inspectorStyle(RefPt rWillBeRawPtr<CSSStyleDeclaration> style) |
| 1333 { | 1275 { |
| 1334 CSSStyleDeclaration* style = styleAt(ruleIndex); | |
| 1335 if (!style) | 1276 if (!style) |
| 1336 return nullptr; | 1277 return nullptr; |
| 1337 | 1278 |
| 1338 return InspectorStyle::create(ruleIndex, style, this); | 1279 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; |
| 1339 } | 1280 unsigned ruleIndex = indexOf(style.get()); |
| 1281 if (ruleIndex != UINT_MAX && ensureParsedDataReady()) | |
| 1282 sourceData = m_parsedStyleSheet->ruleSourceDataAt(ruleIndex); | |
| 1340 | 1283 |
| 1341 unsigned InspectorStyleSheet::ruleCount() | 1284 if (ruleIndex == UINT_MAX) { |
| 1342 { | 1285 // Any rule coming from User Agent and not from DefaultStyleSheet will n ot have id. |
| 1343 return m_parsedStyleSheet->ruleCount(); | 1286 // See InspectorCSSAgent::buildObjectForRule for details. |
| 1287 return InspectorStyle::create(style, nullptr, this); | |
| 1288 } | |
| 1289 | |
| 1290 return InspectorStyle::create(style, sourceData, this); | |
| 1344 } | 1291 } |
| 1345 | 1292 |
| 1346 String InspectorStyleSheet::sourceURL() const | 1293 String InspectorStyleSheet::sourceURL() const |
| 1347 { | 1294 { |
| 1348 if (!m_sourceURL.isNull()) | 1295 if (!m_sourceURL.isNull()) |
| 1349 return m_sourceURL; | 1296 return m_sourceURL; |
| 1350 if (m_origin != TypeBuilder::CSS::StyleSheetOrigin::Regular) { | 1297 if (m_origin != TypeBuilder::CSS::StyleSheetOrigin::Regular) { |
| 1351 m_sourceURL = ""; | 1298 m_sourceURL = ""; |
| 1352 return m_sourceURL; | 1299 return m_sourceURL; |
| 1353 } | 1300 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1428 } | 1375 } |
| 1429 return UINT_MAX; | 1376 return UINT_MAX; |
| 1430 } | 1377 } |
| 1431 | 1378 |
| 1432 bool InspectorStyleSheet::findRuleByHeaderRange(const SourceRange& sourceRange, CSSRule** pRule, CSSRuleSourceData** pSourceData) | 1379 bool InspectorStyleSheet::findRuleByHeaderRange(const SourceRange& sourceRange, CSSRule** pRule, CSSRuleSourceData** pSourceData) |
| 1433 { | 1380 { |
| 1434 if (!ensureParsedDataReady()) | 1381 if (!ensureParsedDataReady()) |
| 1435 return false; | 1382 return false; |
| 1436 ensureFlatRules(); | 1383 ensureFlatRules(); |
| 1437 | 1384 |
| 1438 for (size_t i = 0; i < ruleCount() && i < m_flatRules.size(); ++i) { | 1385 for (size_t i = 0; i < m_parsedStyleSheet->ruleCount() && i < m_flatRules.si ze(); ++i) { |
| 1439 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i); | 1386 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_parsedStyleShee t->ruleSourceDataAt(i); |
| 1440 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) { | 1387 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) { |
| 1441 *pRule = m_flatRules.at(i).get(); | 1388 *pRule = m_flatRules.at(i).get(); |
| 1442 if (!(*pRule)->parentStyleSheet()) | 1389 if (!(*pRule)->parentStyleSheet()) |
| 1443 return false; | 1390 return false; |
| 1444 *pSourceData = ruleSourceData.get(); | 1391 *pSourceData = ruleSourceData.get(); |
| 1445 return true; | 1392 return true; |
| 1446 } | 1393 } |
| 1447 } | 1394 } |
| 1448 return false; | 1395 return false; |
| 1449 } | 1396 } |
| 1450 | 1397 |
| 1451 bool InspectorStyleSheet::findRuleByBodyRange(const SourceRange& sourceRange, CS SRule** pRule, CSSRuleSourceData** pSourceData) | 1398 bool InspectorStyleSheet::findRuleByBodyRange(const SourceRange& sourceRange, CS SRule** pRule, CSSRuleSourceData** pSourceData) |
| 1452 { | 1399 { |
| 1453 if (!ensureParsedDataReady()) | 1400 if (!ensureParsedDataReady()) |
| 1454 return false; | 1401 return false; |
| 1455 ensureFlatRules(); | 1402 ensureFlatRules(); |
| 1456 | 1403 |
| 1457 for (size_t i = 0; i < ruleCount() && i < m_flatRules.size(); ++i) { | 1404 for (size_t i = 0; i < m_parsedStyleSheet->ruleCount() && i < m_flatRules.si ze(); ++i) { |
| 1458 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i); | 1405 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_parsedStyleShee t->ruleSourceDataAt(i); |
| 1459 if (ruleSourceData->ruleBodyRange.start == sourceRange.start && ruleSour ceData->ruleBodyRange.end == sourceRange.end) { | 1406 if (ruleSourceData->ruleBodyRange.start == sourceRange.start && ruleSour ceData->ruleBodyRange.end == sourceRange.end) { |
| 1460 *pRule = m_flatRules.at(i).get(); | 1407 *pRule = m_flatRules.at(i).get(); |
| 1461 if (!(*pRule)->parentStyleSheet()) | 1408 if (!(*pRule)->parentStyleSheet()) |
| 1462 return false; | 1409 return false; |
| 1463 *pSourceData = ruleSourceData.get(); | 1410 *pSourceData = ruleSourceData.get(); |
| 1464 return true; | 1411 return true; |
| 1465 } | 1412 } |
| 1466 } | 1413 } |
| 1467 return false; | 1414 return false; |
| 1468 } | 1415 } |
| 1469 | 1416 |
| 1470 const CSSRuleVector& InspectorStyleSheet::flatRules() | 1417 const CSSRuleVector& InspectorStyleSheet::flatRules() |
| 1471 { | 1418 { |
| 1472 ensureFlatRules(); | 1419 ensureFlatRules(); |
| 1473 return m_flatRules; | 1420 return m_flatRules; |
| 1474 } | 1421 } |
| 1475 | 1422 |
| 1476 Document* InspectorStyleSheet::ownerDocument() const | |
| 1477 { | |
| 1478 return m_pageStyleSheet->ownerDocument(); | |
| 1479 } | |
| 1480 | |
| 1481 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataAt( unsigned ruleIndex) const | |
| 1482 { | |
| 1483 return m_parsedStyleSheet->ruleSourceDataAt(ruleIndex); | |
| 1484 } | |
| 1485 | |
| 1486 bool InspectorStyleSheet::ensureParsedDataReady() | 1423 bool InspectorStyleSheet::ensureParsedDataReady() |
| 1487 { | 1424 { |
| 1488 return ensureText() && m_parsedStyleSheet->ensureSourceData(); | 1425 return ensureText() && m_parsedStyleSheet->ensureSourceData(); |
| 1489 } | 1426 } |
| 1490 | 1427 |
| 1491 bool InspectorStyleSheet::ensureText() const | 1428 bool InspectorStyleSheet::ensureText() const |
| 1492 { | 1429 { |
| 1493 if (m_parsedStyleSheet->hasText()) | 1430 if (m_parsedStyleSheet->hasText()) |
| 1494 return true; | 1431 return true; |
| 1495 | 1432 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1533 } | 1470 } |
| 1534 } | 1471 } |
| 1535 | 1472 |
| 1536 void InspectorStyleSheet::ensureFlatRules() const | 1473 void InspectorStyleSheet::ensureFlatRules() const |
| 1537 { | 1474 { |
| 1538 // We are fine with redoing this for empty stylesheets as this will run fast . | 1475 // We are fine with redoing this for empty stylesheets as this will run fast . |
| 1539 if (m_flatRules.isEmpty()) | 1476 if (m_flatRules.isEmpty()) |
| 1540 collectFlatRules(pageStyleSheet(), &m_flatRules); | 1477 collectFlatRules(pageStyleSheet(), &m_flatRules); |
| 1541 } | 1478 } |
| 1542 | 1479 |
| 1543 unsigned InspectorStyleSheet::indexOf(CSSStyleRule* rule) const | |
| 1544 { | |
| 1545 return indexOf(rule->style()); | |
| 1546 } | |
| 1547 | |
| 1548 bool InspectorStyleSheet::originalStyleSheetText(String* result) const | 1480 bool InspectorStyleSheet::originalStyleSheetText(String* result) const |
| 1549 { | 1481 { |
| 1550 bool success = inlineStyleSheetText(result); | 1482 bool success = inlineStyleSheetText(result); |
| 1551 if (!success) | 1483 if (!success) |
| 1552 success = resourceStyleSheetText(result); | 1484 success = resourceStyleSheetText(result); |
| 1553 return success; | 1485 return success; |
| 1554 } | 1486 } |
| 1555 | 1487 |
| 1556 bool InspectorStyleSheet::resourceStyleSheetText(String* result) const | 1488 bool InspectorStyleSheet::resourceStyleSheetText(String* result) const |
| 1557 { | 1489 { |
| 1558 if (m_origin == TypeBuilder::CSS::StyleSheetOrigin::Injected || m_origin == TypeBuilder::CSS::StyleSheetOrigin::User_agent) | 1490 if (m_origin == TypeBuilder::CSS::StyleSheetOrigin::Injected || m_origin == TypeBuilder::CSS::StyleSheetOrigin::User_agent) |
| 1559 return false; | 1491 return false; |
| 1560 | 1492 |
| 1561 if (!ownerDocument()) | 1493 if (!m_pageStyleSheet->ownerDocument()) |
| 1562 return false; | 1494 return false; |
| 1563 | 1495 |
| 1564 KURL url(ParsedURLString, m_pageStyleSheet->href()); | 1496 KURL url(ParsedURLString, m_pageStyleSheet->href()); |
| 1565 if (m_cssAgent->getEditedStyleSheet(url, result)) | 1497 if (m_cssAgent->getEditedStyleSheet(url, result)) |
| 1566 return true; | 1498 return true; |
| 1567 | 1499 |
| 1568 bool base64Encoded; | 1500 bool base64Encoded; |
| 1569 bool success = m_resourceAgent->fetchResourceContent(ownerDocument(), url, r esult, &base64Encoded); | 1501 bool success = m_resourceAgent->fetchResourceContent(m_pageStyleSheet->owner Document(), url, result, &base64Encoded); |
| 1570 return success && !base64Encoded; | 1502 return success && !base64Encoded; |
| 1571 } | 1503 } |
| 1572 | 1504 |
| 1573 Element* InspectorStyleSheet::ownerStyleElement() const | 1505 Element* InspectorStyleSheet::ownerStyleElement() const |
| 1574 { | 1506 { |
| 1575 Node* ownerNode = m_pageStyleSheet->ownerNode(); | 1507 Node* ownerNode = m_pageStyleSheet->ownerNode(); |
| 1576 if (!ownerNode || !ownerNode->isElementNode()) | 1508 if (!ownerNode || !ownerNode->isElementNode()) |
| 1577 return nullptr; | 1509 return nullptr; |
| 1578 Element* ownerElement = toElement(ownerNode); | 1510 Element* ownerElement = toElement(ownerNode); |
| 1579 | 1511 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1594 } | 1526 } |
| 1595 | 1527 |
| 1596 PassRefPtrWillBeRawPtr<InspectorStyleSheetForInlineStyle> InspectorStyleSheetFor InlineStyle::create(const String& id, PassRefPtrWillBeRawPtr<Element> element, L istener* listener) | 1528 PassRefPtrWillBeRawPtr<InspectorStyleSheetForInlineStyle> InspectorStyleSheetFor InlineStyle::create(const String& id, PassRefPtrWillBeRawPtr<Element> element, L istener* listener) |
| 1597 { | 1529 { |
| 1598 return adoptRefWillBeNoop(new InspectorStyleSheetForInlineStyle(id, element, listener)); | 1530 return adoptRefWillBeNoop(new InspectorStyleSheetForInlineStyle(id, element, listener)); |
| 1599 } | 1531 } |
| 1600 | 1532 |
| 1601 InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(const Strin g& id, PassRefPtrWillBeRawPtr<Element> element, Listener* listener) | 1533 InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(const Strin g& id, PassRefPtrWillBeRawPtr<Element> element, Listener* listener) |
| 1602 : InspectorStyleSheetBase(id, listener) | 1534 : InspectorStyleSheetBase(id, listener) |
| 1603 , m_element(element) | 1535 , m_element(element) |
| 1604 , m_ruleSourceData(nullptr) | |
| 1605 , m_isStyleTextValid(false) | |
| 1606 { | 1536 { |
| 1607 ASSERT(m_element); | 1537 ASSERT(m_element); |
| 1608 m_inspectorStyle = InspectorStyle::create(0, inlineStyle(), this); | |
| 1609 m_styleText = m_element->isStyledElement() ? m_element->getAttribute("style" ).string() : String(); | |
| 1610 } | 1538 } |
| 1611 | 1539 |
| 1612 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute() | 1540 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute() |
| 1613 { | 1541 { |
| 1614 m_isStyleTextValid = false; | 1542 m_inspectorStyle.clear(); |
| 1615 if (m_element->isStyledElement() && m_element->style() != m_inspectorStyle-> cssStyle()) | |
| 1616 m_inspectorStyle = InspectorStyle::create(0, inlineStyle(), this); | |
| 1617 m_ruleSourceData.clear(); | |
| 1618 } | 1543 } |
| 1619 | 1544 |
| 1620 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta te& exceptionState) | 1545 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta te& exceptionState) |
| 1621 { | 1546 { |
| 1622 if (!verifyStyleText(ownerDocument(), text)) { | 1547 if (!verifyStyleText(&m_element->document(), text)) { |
| 1623 exceptionState.throwDOMException(SyntaxError, "Style text is not valid." ); | 1548 exceptionState.throwDOMException(SyntaxError, "Style text is not valid." ); |
| 1624 return false; | 1549 return false; |
| 1625 } | 1550 } |
| 1626 | 1551 |
| 1627 { | 1552 { |
| 1628 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own erDocument()); | 1553 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own erDocument()); |
| 1629 m_element->setAttribute("style", AtomicString(text), exceptionState); | 1554 m_element->setAttribute("style", AtomicString(text), exceptionState); |
| 1630 } | 1555 } |
| 1631 if (!exceptionState.hadException()) { | 1556 if (!exceptionState.hadException()) |
| 1632 m_styleText = text; | |
| 1633 m_isStyleTextValid = true; | |
| 1634 m_ruleSourceData.clear(); | |
| 1635 onStyleSheetTextChanged(); | 1557 onStyleSheetTextChanged(); |
| 1636 } | |
| 1637 return !exceptionState.hadException(); | 1558 return !exceptionState.hadException(); |
| 1638 } | 1559 } |
| 1639 | 1560 |
| 1640 bool InspectorStyleSheetForInlineStyle::getText(String* result) const | 1561 bool InspectorStyleSheetForInlineStyle::getText(String* result) const |
| 1641 { | 1562 { |
| 1642 if (!m_isStyleTextValid) { | 1563 *result = elementStyleText(); |
| 1643 m_styleText = elementStyleText(); | |
| 1644 m_isStyleTextValid = true; | |
| 1645 } | |
| 1646 *result = m_styleText; | |
| 1647 return true; | 1564 return true; |
| 1648 } | 1565 } |
| 1649 | 1566 |
| 1650 Document* InspectorStyleSheetForInlineStyle::ownerDocument() const | 1567 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheetForInlineStyle::inspec torStyle(RefPtrWillBeRawPtr<CSSStyleDeclaration> style) |
| 1651 { | 1568 { |
| 1652 return &m_element->document(); | 1569 if (!m_inspectorStyle) { |
| 1653 } | 1570 const String& text = elementStyleText(); |
| 1654 | 1571 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData; |
| 1655 bool InspectorStyleSheetForInlineStyle::ensureParsedDataReady() | 1572 if (text.isEmpty()) { |
| 1656 { | 1573 ruleSourceData = CSSRuleSourceData::create(StyleRule::Style); |
| 1657 // The "style" property value can get changed indirectly, e.g. via element.s tyle.borderWidth = "2px". | 1574 ruleSourceData->ruleBodyRange.start = 0; |
| 1658 const String& currentStyleText = elementStyleText(); | 1575 ruleSourceData->ruleBodyRange.end = 0; |
| 1659 if (m_styleText != currentStyleText) { | 1576 } else { |
| 1660 m_ruleSourceData.clear(); | 1577 RuleSourceDataList ruleSourceDataResult; |
| 1661 m_styleText = currentStyleText; | 1578 StyleSheetHandler handler(text, &m_element->document(), &ruleSourceD ataResult); |
| 1662 m_isStyleTextValid = true; | 1579 CSSParser::parseDeclarationListForInspector(parserContextForDocument (&m_element->document()), text, handler); |
| 1580 ruleSourceData = ruleSourceDataResult.first().release(); | |
| 1581 } | |
| 1582 m_inspectorStyle = InspectorStyle::create(m_element->style(), ruleSource Data, this); | |
| 1663 } | 1583 } |
| 1664 | |
| 1665 if (m_ruleSourceData) | |
| 1666 return true; | |
| 1667 | |
| 1668 m_ruleSourceData = getStyleAttributeData(); | |
| 1669 | |
| 1670 bool success = !!m_ruleSourceData; | |
| 1671 if (!success) { | |
| 1672 m_ruleSourceData = CSSRuleSourceData::create(StyleRule::Style); | |
| 1673 return false; | |
| 1674 } | |
| 1675 | |
| 1676 return true; | |
| 1677 } | |
| 1678 | |
| 1679 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheetForInlineStyle::inspec torStyleAt(unsigned ruleIndex) | |
| 1680 { | |
| 1681 ASSERT_UNUSED(ruleIndex, !ruleIndex); | |
| 1682 return m_inspectorStyle; | 1584 return m_inspectorStyle; |
| 1683 } | 1585 } |
| 1684 | 1586 |
| 1685 CSSStyleDeclaration* InspectorStyleSheetForInlineStyle::inlineStyle() const | 1587 CSSStyleDeclaration* InspectorStyleSheetForInlineStyle::inlineStyle() const |
| 1686 { | 1588 { |
| 1687 return m_element->style(); | 1589 return m_element->style(); |
| 1688 } | 1590 } |
| 1689 | 1591 |
| 1690 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const | 1592 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const |
| 1691 { | 1593 { |
| 1692 return m_element->getAttribute("style").string(); | 1594 return m_element->getAttribute("style").string(); |
| 1693 } | 1595 } |
| 1694 | 1596 |
| 1695 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheetForInlineStyle::get StyleAttributeData() const | |
| 1696 { | |
| 1697 if (!m_element->isStyledElement()) | |
| 1698 return nullptr; | |
| 1699 | |
| 1700 if (m_styleText.isEmpty()) { | |
| 1701 RefPtrWillBeRawPtr<CSSRuleSourceData> result = CSSRuleSourceData::create (StyleRule::Style); | |
| 1702 result->ruleBodyRange.start = 0; | |
| 1703 result->ruleBodyRange.end = 0; | |
| 1704 return result.release(); | |
| 1705 } | |
| 1706 | |
| 1707 RuleSourceDataList ruleSourceDataResult; | |
| 1708 StyleSheetHandler handler(m_styleText, &m_element->document(), &ruleSourceDa taResult); | |
| 1709 CSSParser::parseDeclarationListForInspector(parserContextForDocument(&m_elem ent->document()), m_styleText, handler); | |
| 1710 return ruleSourceDataResult.first().release(); | |
| 1711 } | |
| 1712 | |
| 1713 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) | 1597 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) |
| 1714 { | 1598 { |
| 1715 visitor->trace(m_element); | 1599 visitor->trace(m_element); |
| 1716 visitor->trace(m_ruleSourceData); | |
| 1717 visitor->trace(m_inspectorStyle); | 1600 visitor->trace(m_inspectorStyle); |
| 1718 InspectorStyleSheetBase::trace(visitor); | 1601 InspectorStyleSheetBase::trace(visitor); |
| 1719 } | 1602 } |
| 1720 | 1603 |
| 1721 } // namespace blink | 1604 } // namespace blink |
| OLD | NEW |