| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 #include "wtf/OwnPtr.h" | 52 #include "wtf/OwnPtr.h" |
| 53 #include "wtf/PassOwnPtr.h" | 53 #include "wtf/PassOwnPtr.h" |
| 54 #include "wtf/text/StringBuilder.h" | 54 #include "wtf/text/StringBuilder.h" |
| 55 #include "wtf/text/TextPosition.h" | 55 #include "wtf/text/TextPosition.h" |
| 56 | 56 |
| 57 using WebCore::TypeBuilder::Array; | 57 using WebCore::TypeBuilder::Array; |
| 58 using WebCore::RuleSourceDataList; | 58 using WebCore::RuleSourceDataList; |
| 59 using WebCore::CSSRuleSourceData; | 59 using WebCore::CSSRuleSourceData; |
| 60 using WebCore::CSSStyleSheet; | 60 using WebCore::CSSStyleSheet; |
| 61 | 61 |
| 62 static PassOwnPtr<WebCore::BisonCSSParser> createCSSParser(WebCore::Document* do
cument) | |
| 63 { | |
| 64 return adoptPtr(new WebCore::BisonCSSParser(document ? WebCore::CSSParserCon
text(*document, 0) : WebCore::strictCSSParserContext())); | |
| 65 } | |
| 66 | |
| 67 namespace { | 62 namespace { |
| 68 | 63 |
| 69 using namespace WebCore; | 64 using namespace WebCore; |
| 70 | 65 |
| 71 class StyleSheetHandler FINAL : public CSSParserObserver { | 66 class StyleSheetHandler FINAL : public CSSParserObserver { |
| 72 public: | 67 public: |
| 73 StyleSheetHandler(const String& parsedText, Document* document, StyleSheetCo
ntents* styleSheetContents, RuleSourceDataList* result) | 68 StyleSheetHandler(const String& parsedText, Document* document, StyleSheetCo
ntents* styleSheetContents, RuleSourceDataList* result) |
| 74 : m_parsedText(parsedText) | 69 : m_parsedText(parsedText) |
| 75 , m_document(document) | 70 , m_document(document) |
| 76 , m_styleSheetContents(styleSheetContents) | 71 , m_styleSheetContents(styleSheetContents) |
| 77 , m_result(result) | 72 , m_result(result) |
| 73 , m_commentParser(document) |
| 78 , m_propertyRangeStart(UINT_MAX) | 74 , m_propertyRangeStart(UINT_MAX) |
| 79 , m_selectorRangeStart(UINT_MAX) | 75 , m_selectorRangeStart(UINT_MAX) |
| 80 , m_commentRangeStart(UINT_MAX) | 76 , m_commentRangeStart(UINT_MAX) |
| 81 { | 77 { |
| 82 ASSERT(m_result); | 78 ASSERT(m_result); |
| 83 } | 79 } |
| 84 | 80 |
| 85 private: | 81 private: |
| 86 virtual void startRuleHeader(CSSRuleSourceData::Type, unsigned) OVERRIDE; | 82 virtual void startRuleHeader(CSSRuleSourceData::Type, unsigned) OVERRIDE; |
| 87 virtual void endRuleHeader(unsigned) OVERRIDE; | 83 virtual void endRuleHeader(unsigned) OVERRIDE; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 99 PassRefPtr<CSSRuleSourceData> popRuleData(); | 95 PassRefPtr<CSSRuleSourceData> popRuleData(); |
| 100 template <typename CharacterType> inline void setRuleHeaderEnd(const Charact
erType*, unsigned); | 96 template <typename CharacterType> inline void setRuleHeaderEnd(const Charact
erType*, unsigned); |
| 101 void fixUnparsedPropertyRanges(CSSRuleSourceData*); | 97 void fixUnparsedPropertyRanges(CSSRuleSourceData*); |
| 102 | 98 |
| 103 const String& m_parsedText; | 99 const String& m_parsedText; |
| 104 Document* m_document; | 100 Document* m_document; |
| 105 StyleSheetContents* m_styleSheetContents; | 101 StyleSheetContents* m_styleSheetContents; |
| 106 RuleSourceDataList* m_result; | 102 RuleSourceDataList* m_result; |
| 107 RuleSourceDataList m_currentRuleDataStack; | 103 RuleSourceDataList m_currentRuleDataStack; |
| 108 RefPtr<CSSRuleSourceData> m_currentRuleData; | 104 RefPtr<CSSRuleSourceData> m_currentRuleData; |
| 109 OwnPtr<BisonCSSParser> m_commentParser; | 105 BisonCSSParser m_commentParser; |
| 110 unsigned m_propertyRangeStart; | 106 unsigned m_propertyRangeStart; |
| 111 unsigned m_selectorRangeStart; | 107 unsigned m_selectorRangeStart; |
| 112 unsigned m_commentRangeStart; | 108 unsigned m_commentRangeStart; |
| 113 }; | 109 }; |
| 114 | 110 |
| 115 void StyleSheetHandler::startRuleHeader(CSSRuleSourceData::Type type, unsigned o
ffset) | 111 void StyleSheetHandler::startRuleHeader(CSSRuleSourceData::Type type, unsigned o
ffset) |
| 116 { | 112 { |
| 117 // Pop off data for a previous invalid rule. | 113 // Pop off data for a previous invalid rule. |
| 118 if (m_currentRuleData) | 114 if (m_currentRuleData) |
| 119 m_currentRuleDataStack.removeLast(); | 115 m_currentRuleDataStack.removeLast(); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 commentText = commentText.substring(2); | 322 commentText = commentText.substring(2); |
| 327 | 323 |
| 328 // Require well-formed comments. | 324 // Require well-formed comments. |
| 329 if (!commentText.endsWith("*/")) | 325 if (!commentText.endsWith("*/")) |
| 330 return; | 326 return; |
| 331 commentText = commentText.substring(0, commentText.length() - 2).stripWhiteS
pace(); | 327 commentText = commentText.substring(0, commentText.length() - 2).stripWhiteS
pace(); |
| 332 if (commentText.isEmpty()) | 328 if (commentText.isEmpty()) |
| 333 return; | 329 return; |
| 334 | 330 |
| 335 // FIXME: Use the actual rule type rather than STYLE_RULE? | 331 // FIXME: Use the actual rule type rather than STYLE_RULE? |
| 336 if (!m_commentParser) | |
| 337 m_commentParser = createCSSParser(m_document); | |
| 338 RuleSourceDataList sourceData; | 332 RuleSourceDataList sourceData; |
| 339 | 333 |
| 340 // FIXME: Use another subclass of BisonCSSParser::SourceDataHandler and asse
rt that | 334 // FIXME: Use another subclass of BisonCSSParser::SourceDataHandler and asse
rt that |
| 341 // no comments are encountered (will not need m_document and m_styleSheetCon
tents). | 335 // no comments are encountered (will not need m_document and m_styleSheetCon
tents). |
| 342 StyleSheetHandler handler(commentText, m_document, m_styleSheetContents, &so
urceData); | 336 StyleSheetHandler handler(commentText, m_document, m_styleSheetContents, &so
urceData); |
| 343 RefPtrWillBeRawPtr<MutableStylePropertySet> tempMutableStyle = MutableStyleP
ropertySet::create(); | 337 RefPtrWillBeRawPtr<MutableStylePropertySet> tempMutableStyle = MutableStyleP
ropertySet::create(); |
| 344 m_commentParser->parseDeclaration(tempMutableStyle.get(), commentText, &hand
ler, m_styleSheetContents); | 338 m_commentParser.parseDeclaration(tempMutableStyle.get(), commentText, &handl
er, m_styleSheetContents); |
| 345 Vector<CSSPropertySourceData>& commentPropertyData = sourceData.first()->sty
leSourceData->propertyData; | 339 Vector<CSSPropertySourceData>& commentPropertyData = sourceData.first()->sty
leSourceData->propertyData; |
| 346 if (commentPropertyData.size() != 1) | 340 if (commentPropertyData.size() != 1) |
| 347 return; | 341 return; |
| 348 CSSPropertySourceData& propertyData = commentPropertyData.at(0); | 342 CSSPropertySourceData& propertyData = commentPropertyData.at(0); |
| 349 if (propertyData.range.length() != commentText.length()) | 343 if (propertyData.range.length() != commentText.length()) |
| 350 return; | 344 return; |
| 351 | 345 |
| 352 unsigned topRuleBodyRangeStart = m_currentRuleDataStack.last()->ruleBodyRang
e.start; | 346 unsigned topRuleBodyRangeStart = m_currentRuleDataStack.last()->ruleBodyRang
e.start; |
| 353 m_currentRuleDataStack.last()->styleSourceData->propertyData.append( | 347 m_currentRuleDataStack.last()->styleSourceData->propertyData.append( |
| 354 CSSPropertySourceData(propertyData.name, propertyData.value, false, true
, true, SourceRange(startOffset - topRuleBodyRangeStart, offset - topRuleBodyRan
geStart))); | 348 CSSPropertySourceData(propertyData.name, propertyData.value, false, true
, true, SourceRange(startOffset - topRuleBodyRangeStart, offset - topRuleBodyRan
geStart))); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 { | 406 { |
| 413 if (hasSourceData()) | 407 if (hasSourceData()) |
| 414 return true; | 408 return true; |
| 415 | 409 |
| 416 if (!hasText()) | 410 if (!hasText()) |
| 417 return false; | 411 return false; |
| 418 | 412 |
| 419 RefPtrWillBeRawPtr<StyleSheetContents> newStyleSheet = StyleSheetContents::c
reate(strictCSSParserContext()); | 413 RefPtrWillBeRawPtr<StyleSheetContents> newStyleSheet = StyleSheetContents::c
reate(strictCSSParserContext()); |
| 420 OwnPtr<RuleSourceDataList> result = adoptPtr(new RuleSourceDataList()); | 414 OwnPtr<RuleSourceDataList> result = adoptPtr(new RuleSourceDataList()); |
| 421 StyleSheetHandler handler(text(), m_pageStyleSheet->ownerDocument(), newStyl
eSheet.get(), result.get()); | 415 StyleSheetHandler handler(text(), m_pageStyleSheet->ownerDocument(), newStyl
eSheet.get(), result.get()); |
| 422 createCSSParser(m_pageStyleSheet->ownerDocument())->parseSheet(newStyleSheet
.get(), text(), TextPosition::minimumPosition(), &handler); | 416 BisonCSSParser(m_pageStyleSheet->ownerDocument()).parseSheet(newStyleSheet.g
et(), text(), TextPosition::minimumPosition(), &handler); |
| 423 setSourceData(result.release()); | 417 setSourceData(result.release()); |
| 424 return hasSourceData(); | 418 return hasSourceData(); |
| 425 } | 419 } |
| 426 | 420 |
| 427 void ParsedStyleSheet::setSourceData(PassOwnPtr<RuleSourceDataList> sourceData) | 421 void ParsedStyleSheet::setSourceData(PassOwnPtr<RuleSourceDataList> sourceData) |
| 428 { | 422 { |
| 429 if (!sourceData) { | 423 if (!sourceData) { |
| 430 m_sourceData.clear(); | 424 m_sourceData.clear(); |
| 431 return; | 425 return; |
| 432 } | 426 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 } | 543 } |
| 550 | 544 |
| 551 bool InspectorStyle::verifyPropertyText(const String& propertyText, bool canOmit
Semicolon) | 545 bool InspectorStyle::verifyPropertyText(const String& propertyText, bool canOmit
Semicolon) |
| 552 { | 546 { |
| 553 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); | 547 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); |
| 554 RefPtrWillBeRawPtr<MutableStylePropertySet> tempMutableStyle = MutableStyleP
ropertySet::create(); | 548 RefPtrWillBeRawPtr<MutableStylePropertySet> tempMutableStyle = MutableStyleP
ropertySet::create(); |
| 555 RuleSourceDataList sourceData; | 549 RuleSourceDataList sourceData; |
| 556 RefPtrWillBeRawPtr<StyleSheetContents> styleSheetContents = StyleSheetConten
ts::create(strictCSSParserContext()); | 550 RefPtrWillBeRawPtr<StyleSheetContents> styleSheetContents = StyleSheetConten
ts::create(strictCSSParserContext()); |
| 557 String declarationText = propertyText + (canOmitSemicolon ? ";" : " ") + bog
usPropertyName + ": none"; | 551 String declarationText = propertyText + (canOmitSemicolon ? ";" : " ") + bog
usPropertyName + ": none"; |
| 558 StyleSheetHandler handler(declarationText, ownerDocument(), styleSheetConten
ts.get(), &sourceData); | 552 StyleSheetHandler handler(declarationText, ownerDocument(), styleSheetConten
ts.get(), &sourceData); |
| 559 createCSSParser(ownerDocument())->parseDeclaration(tempMutableStyle.get(), d
eclarationText, &handler, styleSheetContents.get()); | 553 BisonCSSParser(ownerDocument()).parseDeclaration(tempMutableStyle.get(), dec
larationText, &handler, styleSheetContents.get()); |
| 560 Vector<CSSPropertySourceData>& propertyData = sourceData.first()->styleSourc
eData->propertyData; | 554 Vector<CSSPropertySourceData>& propertyData = sourceData.first()->styleSourc
eData->propertyData; |
| 561 unsigned propertyCount = propertyData.size(); | 555 unsigned propertyCount = propertyData.size(); |
| 562 | 556 |
| 563 // At least one property + the bogus property added just above should be pre
sent. | 557 // At least one property + the bogus property added just above should be pre
sent. |
| 564 if (propertyCount < 2) | 558 if (propertyCount < 2) |
| 565 return false; | 559 return false; |
| 566 | 560 |
| 567 // Check for the proper propertyText termination (the parser could at least
restore to the PROPERTY_NAME state). | 561 // Check for the proper propertyText termination (the parser could at least
restore to the PROPERTY_NAME state). |
| 568 if (propertyData.at(propertyCount - 1).name != bogusPropertyName) | 562 if (propertyData.at(propertyCount - 1).name != bogusPropertyName) |
| 569 return false; | 563 return false; |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 String sheetText = m_parsedStyleSheet->text(); | 981 String sheetText = m_parsedStyleSheet->text(); |
| 988 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR
ange.length(), selector); | 982 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR
ange.length(), selector); |
| 989 m_parsedStyleSheet->setText(sheetText); | 983 m_parsedStyleSheet->setText(sheetText); |
| 990 fireStyleSheetChanged(); | 984 fireStyleSheetChanged(); |
| 991 return true; | 985 return true; |
| 992 } | 986 } |
| 993 | 987 |
| 994 static bool checkStyleRuleSelector(Document* document, const String& selector) | 988 static bool checkStyleRuleSelector(Document* document, const String& selector) |
| 995 { | 989 { |
| 996 CSSSelectorList selectorList; | 990 CSSSelectorList selectorList; |
| 997 createCSSParser(document)->parseSelector(selector, selectorList); | 991 BisonCSSParser(document).parseSelector(selector, selectorList); |
| 998 return selectorList.isValid(); | 992 return selectorList.isValid(); |
| 999 } | 993 } |
| 1000 | 994 |
| 1001 CSSStyleRule* InspectorStyleSheet::addRule(const String& selector, ExceptionStat
e& exceptionState) | 995 CSSStyleRule* InspectorStyleSheet::addRule(const String& selector, ExceptionStat
e& exceptionState) |
| 1002 { | 996 { |
| 1003 if (!checkStyleRuleSelector(m_pageStyleSheet->ownerDocument(), selector)) { | 997 if (!checkStyleRuleSelector(m_pageStyleSheet->ownerDocument(), selector)) { |
| 1004 exceptionState.throwDOMException(SyntaxError, "The selector '" + selecto
r + "' could not be added."); | 998 exceptionState.throwDOMException(SyntaxError, "The selector '" + selecto
r + "' could not be added."); |
| 1005 return 0; | 999 return 0; |
| 1006 } | 1000 } |
| 1007 | 1001 |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1589 if (m_styleText.isEmpty()) { | 1583 if (m_styleText.isEmpty()) { |
| 1590 RefPtr<CSSRuleSourceData> result = CSSRuleSourceData::create(CSSRuleSour
ceData::STYLE_RULE); | 1584 RefPtr<CSSRuleSourceData> result = CSSRuleSourceData::create(CSSRuleSour
ceData::STYLE_RULE); |
| 1591 result->ruleBodyRange.start = 0; | 1585 result->ruleBodyRange.start = 0; |
| 1592 result->ruleBodyRange.end = 0; | 1586 result->ruleBodyRange.end = 0; |
| 1593 return result.release(); | 1587 return result.release(); |
| 1594 } | 1588 } |
| 1595 | 1589 |
| 1596 RefPtrWillBeRawPtr<MutableStylePropertySet> tempDeclaration = MutableStylePr
opertySet::create(); | 1590 RefPtrWillBeRawPtr<MutableStylePropertySet> tempDeclaration = MutableStylePr
opertySet::create(); |
| 1597 RuleSourceDataList ruleSourceDataResult; | 1591 RuleSourceDataList ruleSourceDataResult; |
| 1598 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do
cument().elementSheet().contents(), &ruleSourceDataResult); | 1592 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do
cument().elementSheet().contents(), &ruleSourceDataResult); |
| 1599 createCSSParser(&m_element->document())->parseDeclaration(tempDeclaration.ge
t(), m_styleText, &handler, m_element->document().elementSheet().contents()); | 1593 BisonCSSParser(&m_element->document()).parseDeclaration(tempDeclaration.get(
), m_styleText, &handler, m_element->document().elementSheet().contents()); |
| 1600 return ruleSourceDataResult.first().release(); | 1594 return ruleSourceDataResult.first().release(); |
| 1601 } | 1595 } |
| 1602 | 1596 |
| 1603 } // namespace WebCore | 1597 } // namespace WebCore |
| 1604 | 1598 |
| OLD | NEW |