Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: Source/core/inspector/InspectorStyleSheet.cpp

Issue 563893002: Revert of Revert of Split out CSSParser public API (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/html/canvas/CanvasStyle.cpp ('k') | Source/core/svg/SVGAnimateElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13 matching lines...) Expand all
24 24
25 #include "config.h" 25 #include "config.h"
26 #include "core/inspector/InspectorStyleSheet.h" 26 #include "core/inspector/InspectorStyleSheet.h"
27 27
28 #include "bindings/core/v8/ExceptionState.h" 28 #include "bindings/core/v8/ExceptionState.h"
29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
30 #include "bindings/core/v8/ScriptRegexp.h" 30 #include "bindings/core/v8/ScriptRegexp.h"
31 #include "core/CSSPropertyNames.h" 31 #include "core/CSSPropertyNames.h"
32 #include "core/css/CSSKeyframesRule.h" 32 #include "core/css/CSSKeyframesRule.h"
33 #include "core/css/CSSMediaRule.h" 33 #include "core/css/CSSMediaRule.h"
34 #include "core/css/parser/BisonCSSParser.h"
35 #include "core/css/CSSRuleList.h" 34 #include "core/css/CSSRuleList.h"
36 #include "core/css/CSSStyleRule.h" 35 #include "core/css/CSSStyleRule.h"
37 #include "core/css/CSSStyleSheet.h" 36 #include "core/css/CSSStyleSheet.h"
38 #include "core/css/CSSSupportsRule.h" 37 #include "core/css/CSSSupportsRule.h"
39 #include "core/css/StylePropertySet.h" 38 #include "core/css/StylePropertySet.h"
40 #include "core/css/StyleRule.h" 39 #include "core/css/StyleRule.h"
41 #include "core/css/StyleSheetContents.h" 40 #include "core/css/StyleSheetContents.h"
41 #include "core/css/parser/CSSParser.h"
42 #include "core/dom/Document.h" 42 #include "core/dom/Document.h"
43 #include "core/dom/Element.h" 43 #include "core/dom/Element.h"
44 #include "core/html/HTMLStyleElement.h" 44 #include "core/html/HTMLStyleElement.h"
45 #include "core/html/parser/HTMLParserIdioms.h" 45 #include "core/html/parser/HTMLParserIdioms.h"
46 #include "core/inspector/ContentSearchUtils.h" 46 #include "core/inspector/ContentSearchUtils.h"
47 #include "core/inspector/InspectorCSSAgent.h" 47 #include "core/inspector/InspectorCSSAgent.h"
48 #include "core/inspector/InspectorPageAgent.h" 48 #include "core/inspector/InspectorPageAgent.h"
49 #include "core/inspector/InspectorResourceAgent.h" 49 #include "core/inspector/InspectorResourceAgent.h"
50 #include "core/svg/SVGStyleElement.h" 50 #include "core/svg/SVGStyleElement.h"
51 #include "wtf/OwnPtr.h" 51 #include "wtf/OwnPtr.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 PassRefPtrWillBeRawPtr<CSSRuleSourceData> popRuleData(); 99 PassRefPtrWillBeRawPtr<CSSRuleSourceData> popRuleData();
100 template <typename CharacterType> inline void setRuleHeaderEnd(const Charact erType*, unsigned); 100 template <typename CharacterType> inline void setRuleHeaderEnd(const Charact erType*, unsigned);
101 void fixUnparsedPropertyRanges(CSSRuleSourceData*); 101 void fixUnparsedPropertyRanges(CSSRuleSourceData*);
102 102
103 const String& m_parsedText; 103 const String& m_parsedText;
104 Document* m_document; 104 Document* m_document;
105 StyleSheetContents* m_styleSheetContents; 105 StyleSheetContents* m_styleSheetContents;
106 RawPtrWillBeMember<RuleSourceDataList> m_result; 106 RawPtrWillBeMember<RuleSourceDataList> m_result;
107 RuleSourceDataList m_currentRuleDataStack; 107 RuleSourceDataList m_currentRuleDataStack;
108 RefPtrWillBeMember<CSSRuleSourceData> m_currentRuleData; 108 RefPtrWillBeMember<CSSRuleSourceData> m_currentRuleData;
109 BisonCSSParser m_commentParser; 109 CSSParser m_commentParser;
110 unsigned m_propertyRangeStart; 110 unsigned m_propertyRangeStart;
111 unsigned m_selectorRangeStart; 111 unsigned m_selectorRangeStart;
112 unsigned m_commentRangeStart; 112 unsigned m_commentRangeStart;
113 }; 113 };
114 114
115 void StyleSheetHandler::startRuleHeader(CSSRuleSourceData::Type type, unsigned o ffset) 115 void StyleSheetHandler::startRuleHeader(CSSRuleSourceData::Type type, unsigned o ffset)
116 { 116 {
117 // Pop off data for a previous invalid rule. 117 // Pop off data for a previous invalid rule.
118 if (m_currentRuleData) 118 if (m_currentRuleData)
119 m_currentRuleDataStack.removeLast(); 119 m_currentRuleDataStack.removeLast();
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // Require well-formed comments. 328 // Require well-formed comments.
329 if (!commentText.endsWith("*/")) 329 if (!commentText.endsWith("*/"))
330 return; 330 return;
331 commentText = commentText.substring(0, commentText.length() - 2).stripWhiteS pace(); 331 commentText = commentText.substring(0, commentText.length() - 2).stripWhiteS pace();
332 if (commentText.isEmpty()) 332 if (commentText.isEmpty())
333 return; 333 return;
334 334
335 // FIXME: Use the actual rule type rather than STYLE_RULE? 335 // FIXME: Use the actual rule type rather than STYLE_RULE?
336 RuleSourceDataList sourceData; 336 RuleSourceDataList sourceData;
337 337
338 // FIXME: Use another subclass of BisonCSSParser::SourceDataHandler and asse rt that 338 // FIXME: Use another subclass of CSSParserObserver and assert that
339 // no comments are encountered (will not need m_document and m_styleSheetCon tents). 339 // no comments are encountered (will not need m_document and m_styleSheetCon tents).
340 StyleSheetHandler handler(commentText, m_document, m_styleSheetContents, &so urceData); 340 StyleSheetHandler handler(commentText, m_document, m_styleSheetContents, &so urceData);
341 RefPtrWillBeRawPtr<MutableStylePropertySet> tempMutableStyle = MutableStyleP ropertySet::create(); 341 RefPtrWillBeRawPtr<MutableStylePropertySet> tempMutableStyle = MutableStyleP ropertySet::create();
342 m_commentParser.parseDeclaration(tempMutableStyle.get(), commentText, &handl er, m_styleSheetContents); 342 m_commentParser.parseDeclaration(tempMutableStyle.get(), commentText, &handl er, m_styleSheetContents);
343 WillBeHeapVector<CSSPropertySourceData>& commentPropertyData = sourceData.fi rst()->styleSourceData->propertyData; 343 WillBeHeapVector<CSSPropertySourceData>& commentPropertyData = sourceData.fi rst()->styleSourceData->propertyData;
344 if (commentPropertyData.size() != 1) 344 if (commentPropertyData.size() != 1)
345 return; 345 return;
346 CSSPropertySourceData& propertyData = commentPropertyData.at(0); 346 CSSPropertySourceData& propertyData = commentPropertyData.at(0);
347 if (propertyData.range.length() != commentText.length()) 347 if (propertyData.range.length() != commentText.length())
348 return; 348 return;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 { 411 {
412 if (hasSourceData()) 412 if (hasSourceData())
413 return true; 413 return true;
414 414
415 if (!hasText()) 415 if (!hasText())
416 return false; 416 return false;
417 417
418 RefPtrWillBeRawPtr<StyleSheetContents> newStyleSheet = StyleSheetContents::c reate(strictCSSParserContext()); 418 RefPtrWillBeRawPtr<StyleSheetContents> newStyleSheet = StyleSheetContents::c reate(strictCSSParserContext());
419 OwnPtrWillBeRawPtr<RuleSourceDataList> result = adoptPtrWillBeNoop(new RuleS ourceDataList()); 419 OwnPtrWillBeRawPtr<RuleSourceDataList> result = adoptPtrWillBeNoop(new RuleS ourceDataList());
420 StyleSheetHandler handler(text(), m_pageStyleSheet->ownerDocument(), newStyl eSheet.get(), result.get()); 420 StyleSheetHandler handler(text(), m_pageStyleSheet->ownerDocument(), newStyl eSheet.get(), result.get());
421 BisonCSSParser(parserContextForDocument(m_pageStyleSheet->ownerDocument())). parseSheet(newStyleSheet.get(), text(), TextPosition::minimumPosition(), &handle r); 421 CSSParser::parseSheet(parserContextForDocument(m_pageStyleSheet->ownerDocume nt()), newStyleSheet.get(), text(), TextPosition::minimumPosition(), &handler);
422 setSourceData(result.release()); 422 setSourceData(result.release());
423 return hasSourceData(); 423 return hasSourceData();
424 } 424 }
425 425
426 void ParsedStyleSheet::setSourceData(PassOwnPtrWillBeRawPtr<RuleSourceDataList> sourceData) 426 void ParsedStyleSheet::setSourceData(PassOwnPtrWillBeRawPtr<RuleSourceDataList> sourceData)
427 { 427 {
428 if (!sourceData) { 428 if (!sourceData) {
429 m_sourceData.clear(); 429 m_sourceData.clear();
430 return; 430 return;
431 } 431 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 } 547 }
548 548
549 bool InspectorStyle::verifyPropertyText(const String& propertyText, bool canOmit Semicolon) 549 bool InspectorStyle::verifyPropertyText(const String& propertyText, bool canOmit Semicolon)
550 { 550 {
551 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); 551 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee"));
552 RefPtrWillBeRawPtr<MutableStylePropertySet> tempMutableStyle = MutableStyleP ropertySet::create(); 552 RefPtrWillBeRawPtr<MutableStylePropertySet> tempMutableStyle = MutableStyleP ropertySet::create();
553 RuleSourceDataList sourceData; 553 RuleSourceDataList sourceData;
554 RefPtrWillBeRawPtr<StyleSheetContents> styleSheetContents = StyleSheetConten ts::create(strictCSSParserContext()); 554 RefPtrWillBeRawPtr<StyleSheetContents> styleSheetContents = StyleSheetConten ts::create(strictCSSParserContext());
555 String declarationText = propertyText + (canOmitSemicolon ? ";" : " ") + bog usPropertyName + ": none"; 555 String declarationText = propertyText + (canOmitSemicolon ? ";" : " ") + bog usPropertyName + ": none";
556 StyleSheetHandler handler(declarationText, ownerDocument(), styleSheetConten ts.get(), &sourceData); 556 StyleSheetHandler handler(declarationText, ownerDocument(), styleSheetConten ts.get(), &sourceData);
557 BisonCSSParser(parserContextForDocument(ownerDocument())).parseDeclaration(t empMutableStyle.get(), declarationText, &handler, styleSheetContents.get()); 557 CSSParser(parserContextForDocument(ownerDocument())).parseDeclaration(tempMu tableStyle.get(), declarationText, &handler, styleSheetContents.get());
558 WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.first()-> styleSourceData->propertyData; 558 WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.first()-> styleSourceData->propertyData;
559 unsigned propertyCount = propertyData.size(); 559 unsigned propertyCount = propertyData.size();
560 560
561 // At least one property + the bogus property added just above should be pre sent. 561 // At least one property + the bogus property added just above should be pre sent.
562 if (propertyCount < 2) 562 if (propertyCount < 2)
563 return false; 563 return false;
564 564
565 // Check for the proper propertyText termination (the parser could at least restore to the PROPERTY_NAME state). 565 // Check for the proper propertyText termination (the parser could at least restore to the PROPERTY_NAME state).
566 if (propertyData.at(propertyCount - 1).name != bogusPropertyName) 566 if (propertyData.at(propertyCount - 1).name != bogusPropertyName)
567 return false; 567 return false;
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 return insertCSSOMRuleInMediaRule(toCSSMediaRule(rule.get()), sourceRange, r uleText, exceptionState); 1127 return insertCSSOMRuleInMediaRule(toCSSMediaRule(rule.get()), sourceRange, r uleText, exceptionState);
1128 } 1128 }
1129 1129
1130 bool InspectorStyleSheet::verifyRuleText(const String& ruleText) 1130 bool InspectorStyleSheet::verifyRuleText(const String& ruleText)
1131 { 1131 {
1132 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); 1132 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee"));
1133 RuleSourceDataList sourceData; 1133 RuleSourceDataList sourceData;
1134 RefPtrWillBeRawPtr<StyleSheetContents> styleSheetContents = StyleSheetConten ts::create(strictCSSParserContext()); 1134 RefPtrWillBeRawPtr<StyleSheetContents> styleSheetContents = StyleSheetConten ts::create(strictCSSParserContext());
1135 String text = ruleText + " div { " + bogusPropertyName + ": none; }"; 1135 String text = ruleText + " div { " + bogusPropertyName + ": none; }";
1136 StyleSheetHandler handler(text, ownerDocument(), styleSheetContents.get(), & sourceData); 1136 StyleSheetHandler handler(text, ownerDocument(), styleSheetContents.get(), & sourceData);
1137 BisonCSSParser(parserContextForDocument(ownerDocument())).parseSheet(styleSh eetContents.get(), text, TextPosition::minimumPosition(), &handler); 1137 CSSParser::parseSheet(parserContextForDocument(ownerDocument()), styleSheetC ontents.get(), text, TextPosition::minimumPosition(), &handler);
1138 unsigned ruleCount = sourceData.size(); 1138 unsigned ruleCount = sourceData.size();
1139 1139
1140 // Exactly two rules should be parsed. 1140 // Exactly two rules should be parsed.
1141 if (ruleCount != 2) 1141 if (ruleCount != 2)
1142 return false; 1142 return false;
1143 1143
1144 // Added rule must be style rule. 1144 // Added rule must be style rule.
1145 if (!sourceData.at(0)->styleSourceData) 1145 if (!sourceData.at(0)->styleSourceData)
1146 return false; 1146 return false;
1147 1147
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 if (m_styleText.isEmpty()) { 1805 if (m_styleText.isEmpty()) {
1806 RefPtrWillBeRawPtr<CSSRuleSourceData> result = CSSRuleSourceData::create (CSSRuleSourceData::STYLE_RULE); 1806 RefPtrWillBeRawPtr<CSSRuleSourceData> result = CSSRuleSourceData::create (CSSRuleSourceData::STYLE_RULE);
1807 result->ruleBodyRange.start = 0; 1807 result->ruleBodyRange.start = 0;
1808 result->ruleBodyRange.end = 0; 1808 result->ruleBodyRange.end = 0;
1809 return result.release(); 1809 return result.release();
1810 } 1810 }
1811 1811
1812 RefPtrWillBeRawPtr<MutableStylePropertySet> tempDeclaration = MutableStylePr opertySet::create(); 1812 RefPtrWillBeRawPtr<MutableStylePropertySet> tempDeclaration = MutableStylePr opertySet::create();
1813 RuleSourceDataList ruleSourceDataResult; 1813 RuleSourceDataList ruleSourceDataResult;
1814 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do cument().elementSheet().contents(), &ruleSourceDataResult); 1814 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do cument().elementSheet().contents(), &ruleSourceDataResult);
1815 BisonCSSParser(parserContextForDocument(&m_element->document())).parseDeclar ation(tempDeclaration.get(), m_styleText, &handler, m_element->document().elemen tSheet().contents()); 1815 CSSParser(parserContextForDocument(&m_element->document())).parseDeclaration (tempDeclaration.get(), m_styleText, &handler, m_element->document().elementShee t().contents());
1816 return ruleSourceDataResult.first().release(); 1816 return ruleSourceDataResult.first().release();
1817 } 1817 }
1818 1818
1819 void InspectorStyleSheetForInlineStyle::trace(Visitor* visitor) 1819 void InspectorStyleSheetForInlineStyle::trace(Visitor* visitor)
1820 { 1820 {
1821 visitor->trace(m_element); 1821 visitor->trace(m_element);
1822 visitor->trace(m_ruleSourceData); 1822 visitor->trace(m_ruleSourceData);
1823 visitor->trace(m_inspectorStyle); 1823 visitor->trace(m_inspectorStyle);
1824 InspectorStyleSheetBase::trace(visitor); 1824 InspectorStyleSheetBase::trace(visitor);
1825 } 1825 }
1826 1826
1827 } // namespace blink 1827 } // namespace blink
1828 1828
OLDNEW
« no previous file with comments | « Source/core/html/canvas/CanvasStyle.cpp ('k') | Source/core/svg/SVGAnimateElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698