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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 using WebCore::TypeBuilder::Array; | 61 using WebCore::TypeBuilder::Array; |
62 using WebCore::RuleSourceDataList; | 62 using WebCore::RuleSourceDataList; |
63 using WebCore::CSSRuleSourceData; | 63 using WebCore::CSSRuleSourceData; |
64 | 64 |
65 class ParsedStyleSheet { | 65 class ParsedStyleSheet { |
66 WTF_MAKE_FAST_ALLOCATED; | 66 WTF_MAKE_FAST_ALLOCATED; |
67 public: | 67 public: |
68 ParsedStyleSheet(); | 68 ParsedStyleSheet(); |
69 | 69 |
70 WebCore::CSSStyleSheet* cssStyleSheet() const { return m_parserOutput; } | |
71 const String& text() const { ASSERT(m_hasText); return m_text; } | 70 const String& text() const { ASSERT(m_hasText); return m_text; } |
72 void setText(const String& text); | 71 void setText(const String& text); |
73 bool hasText() const { return m_hasText; } | 72 bool hasText() const { return m_hasText; } |
74 void setSourceData(PassOwnPtr<RuleSourceDataList>); | 73 void setSourceData(PassOwnPtr<RuleSourceDataList>); |
75 bool hasSourceData() const { return m_sourceData; } | 74 bool hasSourceData() const { return m_sourceData; } |
76 PassRefPtr<WebCore::CSSRuleSourceData> ruleSourceDataAt(unsigned) const; | 75 PassRefPtr<WebCore::CSSRuleSourceData> ruleSourceDataAt(unsigned) const; |
77 | 76 |
78 private: | 77 private: |
79 void flattenSourceData(RuleSourceDataList*); | 78 void flattenSourceData(RuleSourceDataList*); |
80 | 79 |
81 // StyleSheet constructed while parsing m_text. | |
82 WebCore::CSSStyleSheet* m_parserOutput; | |
83 String m_text; | 80 String m_text; |
84 bool m_hasText; | 81 bool m_hasText; |
85 OwnPtr<RuleSourceDataList> m_sourceData; | 82 OwnPtr<RuleSourceDataList> m_sourceData; |
86 }; | 83 }; |
87 | 84 |
88 ParsedStyleSheet::ParsedStyleSheet() | 85 ParsedStyleSheet::ParsedStyleSheet() |
89 : m_parserOutput(0) | 86 : m_hasText(false) |
90 , m_hasText(false) | |
91 { | 87 { |
92 } | 88 } |
93 | 89 |
94 void ParsedStyleSheet::setText(const String& text) | 90 void ParsedStyleSheet::setText(const String& text) |
95 { | 91 { |
96 m_hasText = true; | 92 m_hasText = true; |
97 m_text = text; | 93 m_text = text; |
98 setSourceData(nullptr); | 94 setSourceData(nullptr); |
99 } | 95 } |
100 | 96 |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 bool InspectorStyle::setPropertyText(unsigned index, const String& propertyText,
bool overwrite, String* oldText, ExceptionCode& ec) | 549 bool InspectorStyle::setPropertyText(unsigned index, const String& propertyText,
bool overwrite, String* oldText, ExceptionCode& ec) |
554 { | 550 { |
555 ASSERT(m_parentStyleSheet); | 551 ASSERT(m_parentStyleSheet); |
556 DEFINE_STATIC_LOCAL(String, bogusPropertyName, (ASCIILiteral("-webkit-boguz-
propertee"))); | 552 DEFINE_STATIC_LOCAL(String, bogusPropertyName, (ASCIILiteral("-webkit-boguz-
propertee"))); |
557 | 553 |
558 if (!m_parentStyleSheet->ensureParsedDataReady()) { | 554 if (!m_parentStyleSheet->ensureParsedDataReady()) { |
559 ec = NotFoundError; | 555 ec = NotFoundError; |
560 return false; | 556 return false; |
561 } | 557 } |
562 | 558 |
563 Vector<InspectorStyleProperty> allProperties; | |
564 populateAllProperties(allProperties); | |
565 | |
566 if (!propertyText.stripWhiteSpace().isEmpty()) { | 559 if (!propertyText.stripWhiteSpace().isEmpty()) { |
567 RefPtr<MutableStylePropertySet> tempMutableStyle = MutableStylePropertyS
et::create(); | 560 RefPtr<MutableStylePropertySet> tempMutableStyle = MutableStylePropertyS
et::create(); |
568 String declarationText = propertyText + " " + bogusPropertyName + ": non
e"; | 561 String declarationText = propertyText + " " + bogusPropertyName + ": non
e"; |
569 RuleSourceDataList sourceData; | 562 RuleSourceDataList sourceData; |
570 StyleSheetHandler handler(declarationText, ownerDocument(), m_style->par
entStyleSheet()->contents(), &sourceData); | 563 StyleSheetHandler handler(declarationText, ownerDocument(), m_style->par
entStyleSheet()->contents(), &sourceData); |
571 createCSSParser(ownerDocument())->parseDeclaration(tempMutableStyle.get(
), declarationText, &handler, m_style->parentStyleSheet()->contents()); | 564 createCSSParser(ownerDocument())->parseDeclaration(tempMutableStyle.get(
), declarationText, &handler, m_style->parentStyleSheet()->contents()); |
572 Vector<CSSPropertySourceData>& propertyData = sourceData.first()->styleS
ourceData->propertyData; | 565 Vector<CSSPropertySourceData>& propertyData = sourceData.first()->styleS
ourceData->propertyData; |
573 unsigned propertyCount = propertyData.size(); | 566 unsigned propertyCount = propertyData.size(); |
574 | 567 |
575 // At least one property + the bogus property added just above should be
present. | 568 // At least one property + the bogus property added just above should be
present. |
(...skipping 15 matching lines...) Expand all Loading... |
591 return false; | 584 return false; |
592 } | 585 } |
593 | 586 |
594 String text; | 587 String text; |
595 bool success = styleText(&text); | 588 bool success = styleText(&text); |
596 if (!success) { | 589 if (!success) { |
597 ec = NotFoundError; | 590 ec = NotFoundError; |
598 return false; | 591 return false; |
599 } | 592 } |
600 | 593 |
| 594 Vector<InspectorStyleProperty> allProperties; |
| 595 populateAllProperties(allProperties); |
| 596 |
601 InspectorStyleTextEditor editor(&allProperties, text, newLineAndWhitespaceDe
limiters()); | 597 InspectorStyleTextEditor editor(&allProperties, text, newLineAndWhitespaceDe
limiters()); |
602 if (overwrite) { | 598 if (overwrite) { |
603 if (index >= allProperties.size()) { | 599 if (index >= allProperties.size()) { |
604 ec = IndexSizeError; | 600 ec = IndexSizeError; |
605 return false; | 601 return false; |
606 } | 602 } |
607 *oldText = allProperties.at(index).rawText; | 603 *oldText = allProperties.at(index).rawText; |
608 editor.replaceProperty(index, propertyText); | 604 editor.replaceProperty(index, propertyText); |
609 } else | 605 } else |
610 editor.insertProperty(index, propertyText, sourceData->ruleBodyRange.len
gth()); | 606 editor.insertProperty(index, propertyText, sourceData->ruleBodyRange.len
gth()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 if (!success) | 660 if (!success) |
665 return false; | 661 return false; |
666 | 662 |
667 SourceRange& bodyRange = sourceData->ruleBodyRange; | 663 SourceRange& bodyRange = sourceData->ruleBodyRange; |
668 *result = styleSheetText.substring(bodyRange.start, bodyRange.end - bodyRang
e.start); | 664 *result = styleSheetText.substring(bodyRange.start, bodyRange.end - bodyRang
e.start); |
669 return true; | 665 return true; |
670 } | 666 } |
671 | 667 |
672 void InspectorStyle::populateAllProperties(Vector<InspectorStyleProperty>& resul
t) const | 668 void InspectorStyle::populateAllProperties(Vector<InspectorStyleProperty>& resul
t) const |
673 { | 669 { |
674 HashSet<String> foundShorthands; | |
675 HashSet<String> sourcePropertyNames; | 670 HashSet<String> sourcePropertyNames; |
676 | 671 |
677 RefPtr<CSSRuleSourceData> sourceData = extractSourceData(); | 672 RefPtr<CSSRuleSourceData> sourceData = extractSourceData(); |
678 OwnPtr<CSSParser> cssParser; | |
679 if (sourceData) { | 673 if (sourceData) { |
680 String styleDeclaration; | 674 String styleDeclaration; |
681 bool isStyleTextKnown = styleText(&styleDeclaration); | 675 bool isStyleTextKnown = styleText(&styleDeclaration); |
682 ASSERT_UNUSED(isStyleTextKnown, isStyleTextKnown); | 676 ASSERT_UNUSED(isStyleTextKnown, isStyleTextKnown); |
683 Vector<CSSPropertySourceData>& sourcePropertyData = sourceData->styleSou
rceData->propertyData; | 677 Vector<CSSPropertySourceData>& sourcePropertyData = sourceData->styleSou
rceData->propertyData; |
684 for (Vector<CSSPropertySourceData>::const_iterator it = sourcePropertyDa
ta.begin(); it != sourcePropertyData.end(); ++it) { | 678 for (Vector<CSSPropertySourceData>::const_iterator it = sourcePropertyDa
ta.begin(); it != sourcePropertyData.end(); ++it) { |
685 InspectorStyleProperty p(*it, true); | 679 InspectorStyleProperty p(*it, true); |
686 p.setRawTextFromStyleDeclaration(styleDeclaration); | 680 p.setRawTextFromStyleDeclaration(styleDeclaration); |
687 result.append(p); | 681 result.append(p); |
688 sourcePropertyNames.add(it->name.lower()); | 682 sourcePropertyNames.add(it->name.lower()); |
689 } | 683 } |
690 } | 684 } |
691 | 685 |
692 for (int i = 0, size = m_style->length(); i < size; ++i) { | 686 for (int i = 0, size = m_style->length(); i < size; ++i) { |
693 String name = m_style->item(i); | 687 String name = m_style->item(i); |
694 if (!sourcePropertyNames.add(name.lower()).isNewEntry) | 688 if (!sourcePropertyNames.add(name.lower()).isNewEntry) |
695 continue; | 689 continue; |
696 | 690 |
697 result.append(InspectorStyleProperty(CSSPropertySourceData(name, m_style
->getPropertyValue(name), !m_style->getPropertyPriority(name).isEmpty(), false,
true, SourceRange()), false)); | 691 result.append(InspectorStyleProperty(CSSPropertySourceData(name, m_style
->getPropertyValue(name), !m_style->getPropertyPriority(name).isEmpty(), false,
true, SourceRange()), false)); |
698 } | 692 } |
699 } | 693 } |
700 | 694 |
701 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::styleWithProperties() con
st | 695 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::styleWithProperties() con
st |
702 { | 696 { |
703 Vector<InspectorStyleProperty> properties; | |
704 populateAllProperties(properties); | |
705 | |
706 RefPtr<Array<TypeBuilder::CSS::CSSProperty> > propertiesObject = Array<TypeB
uilder::CSS::CSSProperty>::create(); | 697 RefPtr<Array<TypeBuilder::CSS::CSSProperty> > propertiesObject = Array<TypeB
uilder::CSS::CSSProperty>::create(); |
707 RefPtr<Array<TypeBuilder::CSS::ShorthandEntry> > shorthandEntries = Array<Ty
peBuilder::CSS::ShorthandEntry>::create(); | 698 RefPtr<Array<TypeBuilder::CSS::ShorthandEntry> > shorthandEntries = Array<Ty
peBuilder::CSS::ShorthandEntry>::create(); |
708 HashMap<String, RefPtr<TypeBuilder::CSS::CSSProperty> > propertyNameToPrevio
usActiveProperty; | 699 HashMap<String, RefPtr<TypeBuilder::CSS::CSSProperty> > propertyNameToPrevio
usActiveProperty; |
709 HashSet<String> foundShorthands; | 700 HashSet<String> foundShorthands; |
710 String previousPriority; | 701 String previousPriority; |
711 String previousStatus; | 702 String previousStatus; |
712 OwnPtr<Vector<unsigned> > lineEndings(m_parentStyleSheet ? m_parentStyleShee
t->lineEndings() : PassOwnPtr<Vector<unsigned> >()); | 703 OwnPtr<Vector<unsigned> > lineEndings(m_parentStyleSheet ? m_parentStyleShee
t->lineEndings() : PassOwnPtr<Vector<unsigned> >()); |
713 RefPtr<CSSRuleSourceData> sourceData = extractSourceData(); | 704 RefPtr<CSSRuleSourceData> sourceData = extractSourceData(); |
714 unsigned ruleBodyRangeStart = sourceData ? sourceData->ruleBodyRange.start :
0; | 705 unsigned ruleBodyRangeStart = sourceData ? sourceData->ruleBodyRange.start :
0; |
715 | 706 |
| 707 Vector<InspectorStyleProperty> properties; |
| 708 populateAllProperties(properties); |
| 709 |
716 for (Vector<InspectorStyleProperty>::iterator it = properties.begin(), itEnd
= properties.end(); it != itEnd; ++it) { | 710 for (Vector<InspectorStyleProperty>::iterator it = properties.begin(), itEnd
= properties.end(); it != itEnd; ++it) { |
717 const CSSPropertySourceData& propertyEntry = it->sourceData; | 711 const CSSPropertySourceData& propertyEntry = it->sourceData; |
718 const String& name = propertyEntry.name; | 712 const String& name = propertyEntry.name; |
719 const bool disabled = it->sourceData.disabled; | 713 const bool disabled = it->sourceData.disabled; |
720 | 714 |
721 TypeBuilder::CSS::CSSProperty::Status::Enum status = disabled ? TypeBuil
der::CSS::CSSProperty::Status::Disabled : TypeBuilder::CSS::CSSProperty::Status:
:Active; | 715 TypeBuilder::CSS::CSSProperty::Status::Enum status = disabled ? TypeBuil
der::CSS::CSSProperty::Status::Disabled : TypeBuilder::CSS::CSSProperty::Status:
:Active; |
722 | 716 |
723 RefPtr<TypeBuilder::CSS::CSSProperty> property = TypeBuilder::CSS::CSSPr
operty::create() | 717 RefPtr<TypeBuilder::CSS::CSSProperty> property = TypeBuilder::CSS::CSSPr
operty::create() |
724 .setName(name) | 718 .setName(name) |
725 .setValue(propertyEntry.value); | 719 .setValue(propertyEntry.value); |
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 | 1809 |
1816 RefPtr<MutableStylePropertySet> tempDeclaration = MutableStylePropertySet::c
reate(); | 1810 RefPtr<MutableStylePropertySet> tempDeclaration = MutableStylePropertySet::c
reate(); |
1817 RuleSourceDataList ruleSourceDataResult; | 1811 RuleSourceDataList ruleSourceDataResult; |
1818 StyleSheetHandler handler(m_styleText, m_element->document(), m_element->doc
ument()->elementSheet()->contents(), &ruleSourceDataResult); | 1812 StyleSheetHandler handler(m_styleText, m_element->document(), m_element->doc
ument()->elementSheet()->contents(), &ruleSourceDataResult); |
1819 createCSSParser(m_element->document())->parseDeclaration(tempDeclaration.get
(), m_styleText, &handler, m_element->document()->elementSheet()->contents()); | 1813 createCSSParser(m_element->document())->parseDeclaration(tempDeclaration.get
(), m_styleText, &handler, m_element->document()->elementSheet()->contents()); |
1820 return ruleSourceDataResult.first().release(); | 1814 return ruleSourceDataResult.first().release(); |
1821 } | 1815 } |
1822 | 1816 |
1823 } // namespace WebCore | 1817 } // namespace WebCore |
1824 | 1818 |
OLD | NEW |