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 559 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_sourceData; |
|
lushnikov
2015/06/23 10:26:10
unused
| |
| 651 if (sourceData && sourceData->styleSourceData) { | 655 if (m_sourceData && m_sourceData->styleSourceData) { |
| 652 WillBeHeapVector<CSSPropertySourceData>& sourcePropertyData = sourceData ->styleSourceData->propertyData; | 656 WillBeHeapVector<CSSPropertySourceData>& sourcePropertyData = m_sourceDa ta->styleSourceData->propertyData; |
| 653 for (const auto& data : sourcePropertyData) { | 657 for (const auto& data : sourcePropertyData) { |
| 654 InspectorStyleProperty p(data, true); | 658 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()); | 659 sourcePropertyNames.add(data.name.lower()); |
| 659 } | 660 } |
| 660 } | 661 } |
| 661 | 662 |
| 662 for (int i = 0, size = m_style->length(); i < size; ++i) { | 663 for (int i = 0, size = m_style->length(); i < size; ++i) { |
| 663 String name = m_style->item(i); | 664 String name = m_style->item(i); |
| 664 if (!sourcePropertyNames.add(name.lower()).isNewEntry) | 665 if (!sourcePropertyNames.add(name.lower()).isNewEntry) |
| 665 continue; | 666 continue; |
| 666 | 667 |
| 667 String value = m_style->getPropertyValue(name); | 668 String value = m_style->getPropertyValue(name); |
| 668 if (value.isEmpty()) | 669 if (value.isEmpty()) |
| 669 continue; | 670 continue; |
| 670 result.append(InspectorStyleProperty(CSSPropertySourceData(name, value, !m_style->getPropertyPriority(name).isEmpty(), false, true, SourceRange()), fals e)); | 671 result.append(CSSPropertySourceData(name, value, !m_style->getPropertyPr iority(name).isEmpty(), false, true, SourceRange())); |
| 671 } | 672 } |
| 672 } | 673 } |
| 673 | 674 |
| 674 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::styleWithProperties() con st | 675 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::styleWithProperties() con st |
| 675 { | 676 { |
| 676 RefPtr<Array<TypeBuilder::CSS::CSSProperty> > propertiesObject = Array<TypeB uilder::CSS::CSSProperty>::create(); | 677 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(); | 678 RefPtr<Array<TypeBuilder::CSS::ShorthandEntry> > shorthandEntries = Array<Ty peBuilder::CSS::ShorthandEntry>::create(); |
| 678 HashSet<String> foundShorthands; | 679 HashSet<String> foundShorthands; |
| 679 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); | |
| 680 | 680 |
| 681 WillBeHeapVector<InspectorStyleProperty> properties; | 681 WillBeHeapVector<CSSPropertySourceData> properties; |
| 682 populateAllProperties(properties); | 682 populateAllProperties(properties); |
| 683 | 683 |
| 684 for (auto& styleProperty : properties) { | 684 for (auto& styleProperty : properties) { |
| 685 const CSSPropertySourceData& propertyEntry = styleProperty.sourceData; | 685 const CSSPropertySourceData& propertyEntry = styleProperty; |
| 686 const String& name = propertyEntry.name; | 686 const String& name = propertyEntry.name; |
| 687 | 687 |
| 688 RefPtr<TypeBuilder::CSS::CSSProperty> property = TypeBuilder::CSS::CSSPr operty::create() | 688 RefPtr<TypeBuilder::CSS::CSSProperty> property = TypeBuilder::CSS::CSSPr operty::create() |
| 689 .setName(name) | 689 .setName(name) |
| 690 .setValue(propertyEntry.value); | 690 .setValue(propertyEntry.value); |
| 691 propertiesObject->addItem(property); | 691 propertiesObject->addItem(property); |
| 692 | 692 |
| 693 // Default "parsedOk" == true. | 693 // Default "parsedOk" == true. |
| 694 if (!propertyEntry.parsedOk) | 694 if (!propertyEntry.parsedOk) |
| 695 property->setParsedOk(false); | 695 property->setParsedOk(false); |
| 696 if (styleProperty.hasRawText()) | 696 String text; |
| 697 property->setText(styleProperty.rawText); | 697 if (styleProperty.range.length() && textForRange(styleProperty.range, &t ext)) |
| 698 | 698 property->setText(text); |
| 699 if (propertyEntry.important) | 699 if (propertyEntry.important) |
| 700 property->setImportant(true); | 700 property->setImportant(true); |
| 701 if (styleProperty.hasSource) { | 701 if (styleProperty.range.length()) { |
| 702 property->setRange(buildSourceRangeObject(propertyEntry.range, m_par entStyleSheet ? m_parentStyleSheet->lineEndings() : nullptr)); | 702 property->setRange(buildSourceRangeObject(propertyEntry.range, m_par entStyleSheet ? m_parentStyleSheet->lineEndings() : nullptr)); |
| 703 if (!propertyEntry.disabled) { | 703 if (!propertyEntry.disabled) { |
| 704 ASSERT_UNUSED(sourceData, sourceData); | |
| 705 property->setImplicit(false); | 704 property->setImplicit(false); |
| 706 } | 705 } |
| 707 property->setDisabled(propertyEntry.disabled); | 706 property->setDisabled(propertyEntry.disabled); |
| 708 } else if (!propertyEntry.disabled) { | 707 } else if (!propertyEntry.disabled) { |
| 709 bool implicit = m_style->isPropertyImplicit(name); | 708 bool implicit = m_style->isPropertyImplicit(name); |
| 710 // Default "implicit" == false. | 709 // Default "implicit" == false. |
| 711 if (implicit) | 710 if (implicit) |
| 712 property->setImplicit(true); | 711 property->setImplicit(true); |
| 713 | 712 |
| 714 String shorthand = m_style->getPropertyShorthand(name); | 713 String shorthand = m_style->getPropertyShorthand(name); |
| 715 if (!shorthand.isEmpty()) { | 714 if (!shorthand.isEmpty()) { |
| 716 if (foundShorthands.add(shorthand).isNewEntry) { | 715 if (foundShorthands.add(shorthand).isNewEntry) { |
| 717 RefPtr<TypeBuilder::CSS::ShorthandEntry> entry = TypeBuilder ::CSS::ShorthandEntry::create() | 716 RefPtr<TypeBuilder::CSS::ShorthandEntry> entry = TypeBuilder ::CSS::ShorthandEntry::create() |
| 718 .setName(shorthand) | 717 .setName(shorthand) |
| 719 .setValue(shorthandValue(shorthand)); | 718 .setValue(shorthandValue(shorthand)); |
| 720 shorthandEntries->addItem(entry); | 719 shorthandEntries->addItem(entry); |
| 721 } | 720 } |
| 722 } | 721 } |
| 723 } | 722 } |
| 724 } | 723 } |
| 725 | 724 |
| 726 RefPtr<TypeBuilder::CSS::CSSStyle> result = TypeBuilder::CSS::CSSStyle::crea te() | 725 RefPtr<TypeBuilder::CSS::CSSStyle> result = TypeBuilder::CSS::CSSStyle::crea te() |
| 727 .setCssProperties(propertiesObject) | 726 .setCssProperties(propertiesObject) |
| 728 .setShorthandEntries(shorthandEntries); | 727 .setShorthandEntries(shorthandEntries); |
| 729 return result.release(); | 728 return result.release(); |
| 730 } | 729 } |
| 731 | 730 |
| 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 | 731 String InspectorStyle::shorthandValue(const String& shorthandProperty) const |
| 740 { | 732 { |
| 741 String value = m_style->getPropertyValue(shorthandProperty); | 733 String value = m_style->getPropertyValue(shorthandProperty); |
| 742 if (value.isEmpty()) { | 734 if (value.isEmpty()) { |
| 743 StringBuilder builder; | 735 StringBuilder builder; |
| 744 | 736 |
| 745 for (unsigned i = 0; i < m_style->length(); ++i) { | 737 for (unsigned i = 0; i < m_style->length(); ++i) { |
| 746 String individualProperty = m_style->item(i); | 738 String individualProperty = m_style->item(i); |
| 747 if (m_style->getPropertyShorthand(individualProperty) != shorthandPr operty) | 739 if (m_style->getPropertyShorthand(individualProperty) != shorthandPr operty) |
| 748 continue; | 740 continue; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 761 return value; | 753 return value; |
| 762 } | 754 } |
| 763 | 755 |
| 764 Document* InspectorStyle::ownerDocument() const | 756 Document* InspectorStyle::ownerDocument() const |
| 765 { | 757 { |
| 766 return m_parentStyleSheet->ownerDocument(); | 758 return m_parentStyleSheet->ownerDocument(); |
| 767 } | 759 } |
| 768 | 760 |
| 769 DEFINE_TRACE(InspectorStyle) | 761 DEFINE_TRACE(InspectorStyle) |
| 770 { | 762 { |
| 763 visitor->trace(m_sourceData); | |
| 771 visitor->trace(m_style); | 764 visitor->trace(m_style); |
| 772 visitor->trace(m_parentStyleSheet); | 765 visitor->trace(m_parentStyleSheet); |
| 773 } | 766 } |
| 774 | 767 |
| 775 InspectorStyleSheetBase::InspectorStyleSheetBase(const String& id, Listener* lis tener) | 768 InspectorStyleSheetBase::InspectorStyleSheetBase(const String& id, Listener* lis tener) |
| 776 : m_id(id) | 769 : m_id(id) |
| 777 , m_listener(listener) | 770 , m_listener(listener) |
| 778 , m_lineEndings(adoptPtr(new LineEndings())) | 771 , m_lineEndings(adoptPtr(new LineEndings())) |
| 779 { | 772 { |
| 780 } | 773 } |
| 781 | 774 |
| 782 void InspectorStyleSheetBase::onStyleSheetTextChanged() | 775 void InspectorStyleSheetBase::onStyleSheetTextChanged() |
| 783 { | 776 { |
| 784 m_lineEndings = adoptPtr(new LineEndings()); | 777 m_lineEndings = adoptPtr(new LineEndings()); |
| 785 if (listener()) | 778 if (listener()) |
| 786 listener()->styleSheetChanged(this); | 779 listener()->styleSheetChanged(this); |
| 787 } | 780 } |
| 788 | 781 |
| 789 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheetBase::buildObjectForSt yle(CSSStyleDeclaration* style) | 782 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheetBase::buildObjectForSt yle(CSSStyleDeclaration* style) |
| 790 { | 783 { |
| 791 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; | 784 RefPtrWillBeRawPtr<InspectorStyle> is = inspectorStyle(style); |
| 792 unsigned ruleIndex = indexOf(style); | 785 RefPtr<TypeBuilder::CSS::CSSStyle> result = is->buildObjectForStyle(); |
| 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(); | 786 return result.release(); |
| 816 } | 787 } |
| 817 | 788 |
| 818 const LineEndings* InspectorStyleSheetBase::lineEndings() | 789 const LineEndings* InspectorStyleSheetBase::lineEndings() |
| 819 { | 790 { |
| 820 if (m_lineEndings->size() > 0) | 791 if (m_lineEndings->size() > 0) |
| 821 return m_lineEndings.get(); | 792 return m_lineEndings.get(); |
| 822 String text; | 793 String text; |
| 823 if (getText(&text)) | 794 if (getText(&text)) |
| 824 m_lineEndings = WTF::lineEndings(text); | 795 m_lineEndings = WTF::lineEndings(text); |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1223 simpleSelector->setRange(buildSourceRangeObject(range, lineEndings())); | 1194 simpleSelector->setRange(buildSourceRangeObject(range, lineEndings())); |
| 1224 result->addItem(simpleSelector.release()); | 1195 result->addItem(simpleSelector.release()); |
| 1225 } | 1196 } |
| 1226 return result.release(); | 1197 return result.release(); |
| 1227 } | 1198 } |
| 1228 | 1199 |
| 1229 PassRefPtr<TypeBuilder::CSS::SelectorList> InspectorStyleSheet::buildObjectForSe lectorList(CSSStyleRule* rule) | 1200 PassRefPtr<TypeBuilder::CSS::SelectorList> InspectorStyleSheet::buildObjectForSe lectorList(CSSStyleRule* rule) |
| 1230 { | 1201 { |
| 1231 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; | 1202 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; |
| 1232 unsigned ruleIndex = indexOf(rule->style()); | 1203 unsigned ruleIndex = indexOf(rule->style()); |
| 1233 if (ruleIndex != UINT_MAX && ensureParsedDataReady()) | 1204 if (ruleIndex != UINT_MAX && ensureParsedDataReady()) { |
| 1234 sourceData = ruleSourceDataAt(ruleIndex); | 1205 sourceData = m_parsedStyleSheet->ruleSourceDataAt(ruleIndex); |
| 1206 } | |
| 1235 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectors; | 1207 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectors; |
| 1236 | 1208 |
| 1237 // This intentionally does not rely on the source data to avoid catching the trailing comments (before the declaration starting '{'). | 1209 // This intentionally does not rely on the source data to avoid catching the trailing comments (before the declaration starting '{'). |
| 1238 String selectorText = rule->selectorText(); | 1210 String selectorText = rule->selectorText(); |
| 1239 | 1211 |
| 1240 if (sourceData) | 1212 if (sourceData) |
| 1241 selectors = selectorsFromSource(sourceData.get(), m_parsedStyleSheet->te xt()); | 1213 selectors = selectorsFromSource(sourceData.get(), m_parsedStyleSheet->te xt()); |
| 1242 else { | 1214 else { |
| 1243 selectors = TypeBuilder::Array<TypeBuilder::CSS::Selector>::create(); | 1215 selectors = TypeBuilder::Array<TypeBuilder::CSS::Selector>::create(); |
| 1244 const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); | 1216 const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1322 return nullptr; | 1294 return nullptr; |
| 1323 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleS ourceDataAt(static_cast<unsigned>(index)); | 1295 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleS ourceDataAt(static_cast<unsigned>(index)); |
| 1324 if (!sourceData->mediaSourceData || mediaQueryIndex >= sourceData->mediaSour ceData->queryData.size()) | 1296 if (!sourceData->mediaSourceData || mediaQueryIndex >= sourceData->mediaSour ceData->queryData.size()) |
| 1325 return nullptr; | 1297 return nullptr; |
| 1326 RefPtrWillBeRawPtr<CSSMediaQuerySourceData> mediaQueryData = sourceData->med iaSourceData->queryData.at(mediaQueryIndex); | 1298 RefPtrWillBeRawPtr<CSSMediaQuerySourceData> mediaQueryData = sourceData->med iaSourceData->queryData.at(mediaQueryIndex); |
| 1327 if (mediaQueryExpIndex >= mediaQueryData->expData.size()) | 1299 if (mediaQueryExpIndex >= mediaQueryData->expData.size()) |
| 1328 return nullptr; | 1300 return nullptr; |
| 1329 return buildSourceRangeObject(mediaQueryData->expData.at(mediaQueryExpIndex) .valueRange, lineEndings()); | 1301 return buildSourceRangeObject(mediaQueryData->expData.at(mediaQueryExpIndex) .valueRange, lineEndings()); |
| 1330 } | 1302 } |
| 1331 | 1303 |
| 1332 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheet::inspectorStyleAt(uns igned ruleIndex) | 1304 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheet::inspectorStyle(RefPt rWillBeRawPtr<CSSStyleDeclaration> style) |
| 1333 { | 1305 { |
| 1334 CSSStyleDeclaration* style = styleAt(ruleIndex); | |
| 1335 if (!style) | 1306 if (!style) |
| 1336 return nullptr; | 1307 return nullptr; |
| 1337 | 1308 |
| 1338 return InspectorStyle::create(ruleIndex, style, this); | 1309 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; |
| 1310 unsigned ruleIndex = indexOf(style.get()); | |
| 1311 if (ruleIndex != UINT_MAX && ensureParsedDataReady()) | |
| 1312 sourceData = m_parsedStyleSheet->ruleSourceDataAt(ruleIndex); | |
| 1313 | |
| 1314 if (ruleIndex == UINT_MAX) { | |
| 1315 // Any rule coming from User Agent and not from DefaultStyleSheet will n ot have id. | |
| 1316 // See InspectorCSSAgent::buildObjectForRule for details. | |
| 1317 return InspectorStyle::create(style, nullptr, this); | |
| 1318 } | |
| 1319 | |
| 1320 return InspectorStyle::create(style, sourceData, this); | |
| 1339 } | 1321 } |
| 1340 | 1322 |
| 1341 unsigned InspectorStyleSheet::ruleCount() | 1323 unsigned InspectorStyleSheet::ruleCount() |
| 1342 { | 1324 { |
| 1343 return m_parsedStyleSheet->ruleCount(); | 1325 return m_parsedStyleSheet->ruleCount(); |
| 1344 } | 1326 } |
| 1345 | 1327 |
| 1346 String InspectorStyleSheet::sourceURL() const | 1328 String InspectorStyleSheet::sourceURL() const |
| 1347 { | 1329 { |
| 1348 if (!m_sourceURL.isNull()) | 1330 if (!m_sourceURL.isNull()) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1429 return UINT_MAX; | 1411 return UINT_MAX; |
| 1430 } | 1412 } |
| 1431 | 1413 |
| 1432 bool InspectorStyleSheet::findRuleByHeaderRange(const SourceRange& sourceRange, CSSRule** pRule, CSSRuleSourceData** pSourceData) | 1414 bool InspectorStyleSheet::findRuleByHeaderRange(const SourceRange& sourceRange, CSSRule** pRule, CSSRuleSourceData** pSourceData) |
| 1433 { | 1415 { |
| 1434 if (!ensureParsedDataReady()) | 1416 if (!ensureParsedDataReady()) |
| 1435 return false; | 1417 return false; |
| 1436 ensureFlatRules(); | 1418 ensureFlatRules(); |
| 1437 | 1419 |
| 1438 for (size_t i = 0; i < ruleCount() && i < m_flatRules.size(); ++i) { | 1420 for (size_t i = 0; i < ruleCount() && i < m_flatRules.size(); ++i) { |
| 1439 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i); | 1421 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_parsedStyleShee t->ruleSourceDataAt(i); |
| 1440 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) { | 1422 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) { |
| 1441 *pRule = m_flatRules.at(i).get(); | 1423 *pRule = m_flatRules.at(i).get(); |
| 1442 if (!(*pRule)->parentStyleSheet()) | 1424 if (!(*pRule)->parentStyleSheet()) |
| 1443 return false; | 1425 return false; |
| 1444 *pSourceData = ruleSourceData.get(); | 1426 *pSourceData = ruleSourceData.get(); |
| 1445 return true; | 1427 return true; |
| 1446 } | 1428 } |
| 1447 } | 1429 } |
| 1448 return false; | 1430 return false; |
| 1449 } | 1431 } |
| 1450 | 1432 |
| 1451 bool InspectorStyleSheet::findRuleByBodyRange(const SourceRange& sourceRange, CS SRule** pRule, CSSRuleSourceData** pSourceData) | 1433 bool InspectorStyleSheet::findRuleByBodyRange(const SourceRange& sourceRange, CS SRule** pRule, CSSRuleSourceData** pSourceData) |
| 1452 { | 1434 { |
| 1453 if (!ensureParsedDataReady()) | 1435 if (!ensureParsedDataReady()) |
| 1454 return false; | 1436 return false; |
| 1455 ensureFlatRules(); | 1437 ensureFlatRules(); |
| 1456 | 1438 |
| 1457 for (size_t i = 0; i < ruleCount() && i < m_flatRules.size(); ++i) { | 1439 for (size_t i = 0; i < ruleCount() && i < m_flatRules.size(); ++i) { |
| 1458 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i); | 1440 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = m_parsedStyleShee t->ruleSourceDataAt(i); |
| 1459 if (ruleSourceData->ruleBodyRange.start == sourceRange.start && ruleSour ceData->ruleBodyRange.end == sourceRange.end) { | 1441 if (ruleSourceData->ruleBodyRange.start == sourceRange.start && ruleSour ceData->ruleBodyRange.end == sourceRange.end) { |
| 1460 *pRule = m_flatRules.at(i).get(); | 1442 *pRule = m_flatRules.at(i).get(); |
| 1461 if (!(*pRule)->parentStyleSheet()) | 1443 if (!(*pRule)->parentStyleSheet()) |
| 1462 return false; | 1444 return false; |
| 1463 *pSourceData = ruleSourceData.get(); | 1445 *pSourceData = ruleSourceData.get(); |
| 1464 return true; | 1446 return true; |
| 1465 } | 1447 } |
| 1466 } | 1448 } |
| 1467 return false; | 1449 return false; |
| 1468 } | 1450 } |
| 1469 | 1451 |
| 1470 const CSSRuleVector& InspectorStyleSheet::flatRules() | 1452 const CSSRuleVector& InspectorStyleSheet::flatRules() |
| 1471 { | 1453 { |
| 1472 ensureFlatRules(); | 1454 ensureFlatRules(); |
| 1473 return m_flatRules; | 1455 return m_flatRules; |
| 1474 } | 1456 } |
| 1475 | 1457 |
| 1476 Document* InspectorStyleSheet::ownerDocument() const | 1458 Document* InspectorStyleSheet::ownerDocument() const |
| 1477 { | 1459 { |
| 1478 return m_pageStyleSheet->ownerDocument(); | 1460 return m_pageStyleSheet->ownerDocument(); |
| 1479 } | 1461 } |
| 1480 | 1462 |
| 1481 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataAt( unsigned ruleIndex) const | |
| 1482 { | |
| 1483 return m_parsedStyleSheet->ruleSourceDataAt(ruleIndex); | |
| 1484 } | |
| 1485 | |
| 1486 bool InspectorStyleSheet::ensureParsedDataReady() | 1463 bool InspectorStyleSheet::ensureParsedDataReady() |
| 1487 { | 1464 { |
| 1488 return ensureText() && m_parsedStyleSheet->ensureSourceData(); | 1465 return ensureText() && m_parsedStyleSheet->ensureSourceData(); |
| 1489 } | 1466 } |
| 1490 | 1467 |
| 1491 bool InspectorStyleSheet::ensureText() const | 1468 bool InspectorStyleSheet::ensureText() const |
| 1492 { | 1469 { |
| 1493 if (m_parsedStyleSheet->hasText()) | 1470 if (m_parsedStyleSheet->hasText()) |
| 1494 return true; | 1471 return true; |
| 1495 | 1472 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1594 } | 1571 } |
| 1595 | 1572 |
| 1596 PassRefPtrWillBeRawPtr<InspectorStyleSheetForInlineStyle> InspectorStyleSheetFor InlineStyle::create(const String& id, PassRefPtrWillBeRawPtr<Element> element, L istener* listener) | 1573 PassRefPtrWillBeRawPtr<InspectorStyleSheetForInlineStyle> InspectorStyleSheetFor InlineStyle::create(const String& id, PassRefPtrWillBeRawPtr<Element> element, L istener* listener) |
| 1597 { | 1574 { |
| 1598 return adoptRefWillBeNoop(new InspectorStyleSheetForInlineStyle(id, element, listener)); | 1575 return adoptRefWillBeNoop(new InspectorStyleSheetForInlineStyle(id, element, listener)); |
| 1599 } | 1576 } |
| 1600 | 1577 |
| 1601 InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(const Strin g& id, PassRefPtrWillBeRawPtr<Element> element, Listener* listener) | 1578 InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(const Strin g& id, PassRefPtrWillBeRawPtr<Element> element, Listener* listener) |
| 1602 : InspectorStyleSheetBase(id, listener) | 1579 : InspectorStyleSheetBase(id, listener) |
| 1603 , m_element(element) | 1580 , m_element(element) |
| 1604 , m_ruleSourceData(nullptr) | |
| 1605 , m_isStyleTextValid(false) | |
| 1606 { | 1581 { |
| 1607 ASSERT(m_element); | 1582 ASSERT(m_element); |
| 1608 m_inspectorStyle = InspectorStyle::create(0, inlineStyle(), this); | |
| 1609 m_styleText = m_element->isStyledElement() ? m_element->getAttribute("style" ).string() : String(); | |
| 1610 } | 1583 } |
| 1611 | 1584 |
| 1612 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute() | 1585 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute() |
| 1613 { | 1586 { |
| 1614 m_isStyleTextValid = false; | 1587 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 } | 1588 } |
| 1619 | 1589 |
| 1620 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta te& exceptionState) | 1590 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta te& exceptionState) |
| 1621 { | 1591 { |
| 1622 if (!verifyStyleText(ownerDocument(), text)) { | 1592 if (!verifyStyleText(ownerDocument(), text)) { |
| 1623 exceptionState.throwDOMException(SyntaxError, "Style text is not valid." ); | 1593 exceptionState.throwDOMException(SyntaxError, "Style text is not valid." ); |
| 1624 return false; | 1594 return false; |
| 1625 } | 1595 } |
| 1626 | 1596 |
| 1627 { | 1597 { |
| 1628 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own erDocument()); | 1598 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own erDocument()); |
| 1629 m_element->setAttribute("style", AtomicString(text), exceptionState); | 1599 m_element->setAttribute("style", AtomicString(text), exceptionState); |
| 1630 } | 1600 } |
| 1631 if (!exceptionState.hadException()) { | 1601 if (!exceptionState.hadException()) |
| 1632 m_styleText = text; | |
| 1633 m_isStyleTextValid = true; | |
| 1634 m_ruleSourceData.clear(); | |
| 1635 onStyleSheetTextChanged(); | 1602 onStyleSheetTextChanged(); |
| 1636 } | |
| 1637 return !exceptionState.hadException(); | 1603 return !exceptionState.hadException(); |
| 1638 } | 1604 } |
| 1639 | 1605 |
| 1640 bool InspectorStyleSheetForInlineStyle::getText(String* result) const | 1606 bool InspectorStyleSheetForInlineStyle::getText(String* result) const |
| 1641 { | 1607 { |
| 1642 if (!m_isStyleTextValid) { | 1608 *result = elementStyleText(); |
| 1643 m_styleText = elementStyleText(); | |
| 1644 m_isStyleTextValid = true; | |
| 1645 } | |
| 1646 *result = m_styleText; | |
| 1647 return true; | 1609 return true; |
| 1648 } | 1610 } |
| 1649 | 1611 |
| 1650 Document* InspectorStyleSheetForInlineStyle::ownerDocument() const | 1612 Document* InspectorStyleSheetForInlineStyle::ownerDocument() const |
| 1651 { | 1613 { |
| 1652 return &m_element->document(); | 1614 return &m_element->document(); |
| 1653 } | 1615 } |
| 1654 | 1616 |
| 1655 bool InspectorStyleSheetForInlineStyle::ensureParsedDataReady() | 1617 bool InspectorStyleSheetForInlineStyle::ensureParsedDataReady() |
| 1656 { | 1618 { |
| 1657 // The "style" property value can get changed indirectly, e.g. via element.s tyle.borderWidth = "2px". | |
| 1658 const String& currentStyleText = elementStyleText(); | |
| 1659 if (m_styleText != currentStyleText) { | |
| 1660 m_ruleSourceData.clear(); | |
| 1661 m_styleText = currentStyleText; | |
| 1662 m_isStyleTextValid = true; | |
| 1663 } | |
| 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; | 1619 return true; |
| 1677 } | 1620 } |
| 1678 | 1621 |
| 1679 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheetForInlineStyle::inspec torStyleAt(unsigned ruleIndex) | 1622 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheetForInlineStyle::inspec torStyle(RefPtrWillBeRawPtr<CSSStyleDeclaration> style) |
| 1680 { | 1623 { |
| 1681 ASSERT_UNUSED(ruleIndex, !ruleIndex); | 1624 if (!m_inspectorStyle) { |
| 1625 const String& text = elementStyleText(); | |
| 1626 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData; | |
| 1627 if (text.isEmpty()) { | |
| 1628 ruleSourceData = CSSRuleSourceData::create(StyleRule::Style); | |
| 1629 ruleSourceData->ruleBodyRange.start = 0; | |
| 1630 ruleSourceData->ruleBodyRange.end = 0; | |
| 1631 } else { | |
| 1632 RuleSourceDataList ruleSourceDataResult; | |
| 1633 StyleSheetHandler handler(text, &m_element->document(), &ruleSourceD ataResult); | |
| 1634 CSSParser::parseDeclarationListForInspector(parserContextForDocument (&m_element->document()), text, handler); | |
| 1635 ruleSourceData = ruleSourceDataResult.first().release(); | |
| 1636 } | |
| 1637 m_inspectorStyle = InspectorStyle::create(m_element->style(), ruleSource Data, this); | |
| 1638 } | |
| 1682 return m_inspectorStyle; | 1639 return m_inspectorStyle; |
| 1683 } | 1640 } |
| 1684 | 1641 |
| 1685 CSSStyleDeclaration* InspectorStyleSheetForInlineStyle::inlineStyle() const | 1642 CSSStyleDeclaration* InspectorStyleSheetForInlineStyle::inlineStyle() const |
| 1686 { | 1643 { |
| 1687 return m_element->style(); | 1644 return m_element->style(); |
| 1688 } | 1645 } |
| 1689 | 1646 |
| 1690 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const | 1647 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const |
| 1691 { | 1648 { |
| 1692 return m_element->getAttribute("style").string(); | 1649 return m_element->getAttribute("style").string(); |
| 1693 } | 1650 } |
| 1694 | 1651 |
| 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) | 1652 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) |
| 1714 { | 1653 { |
| 1715 visitor->trace(m_element); | 1654 visitor->trace(m_element); |
| 1716 visitor->trace(m_ruleSourceData); | |
| 1717 visitor->trace(m_inspectorStyle); | 1655 visitor->trace(m_inspectorStyle); |
| 1718 InspectorStyleSheetBase::trace(visitor); | 1656 InspectorStyleSheetBase::trace(visitor); |
| 1719 } | 1657 } |
| 1720 | 1658 |
| 1721 } // namespace blink | 1659 } // namespace blink |
| OLD | NEW |