Changeset 208886 in webkit
- Timestamp:
- Nov 18, 2016, 11:09:13 AM (9 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r208884 r208886 1 2016-11-18 Dave Hyatt <[email protected]> 2 3 [CSS Parser] Hook up InspectorStyleSheet to the new CSS parser. 4 https://bugs.webkit.org/show_bug.cgi?id=164886 5 6 Reviewed by Dean Jackson. 7 8 * css/CSSGrammar.y.in: 9 Get rid of the CSSRuleSourceData type enum, since StyleRule's type 10 enum is exactly the same. 11 12 * css/CSSPropertySourceData.cpp: 13 (WebCore::CSSPropertySourceData::CSSPropertySourceData): 14 * css/CSSPropertySourceData.h: 15 Add a concept of disabled to CSSPropertySourceData. This is used for 16 commented out properties. 17 18 (WebCore::CSSRuleSourceData::create): 19 (WebCore::CSSRuleSourceData::createUnknown): 20 (WebCore::CSSRuleSourceData::CSSRuleSourceData): 21 Get rid of the CSSRuleSourceData type enum, since StyleRule's type 22 enum is exactly the same. 23 24 * css/parser/CSSParser.cpp: 25 (WebCore::CSSParserContext::CSSParserContext): 26 (WebCore::CSSParser::parseSheetForInspector): 27 (WebCore::CSSParser::parseDeclarationForInspector): 28 (WebCore::CSSParser::markSupportsRuleHeaderStart): 29 (WebCore::CSSParser::markRuleHeaderStart): 30 (WebCore::CSSParser::markPropertyEnd): 31 * css/parser/CSSParser.h: 32 Add functions that represent the new API for inspector sheet 33 and declaration parsing. Patch the old parse code to use StyleRule::Type 34 now that the CSSRuleSourceData type is gone. 35 36 * css/parser/CSSParserObserver.h: 37 Tweak the API for our memory management. 38 39 * inspector/InspectorStyleSheet.cpp: 40 (flattenSourceData): 41 (WebCore::parserContextForDocument): 42 (WebCore::StyleSheetHandler::StyleSheetHandler): 43 (WebCore::StyleSheetHandler::startRuleHeader): 44 (WebCore::StyleSheetHandler::setRuleHeaderEnd): 45 (WebCore::StyleSheetHandler::endRuleHeader): 46 (WebCore::StyleSheetHandler::observeSelector): 47 (WebCore::StyleSheetHandler::startRuleBody): 48 (WebCore::StyleSheetHandler::endRuleBody): 49 (WebCore::StyleSheetHandler::popRuleData): 50 (WebCore::fixUnparsedProperties): 51 (WebCore::StyleSheetHandler::fixUnparsedPropertyRanges): 52 (WebCore::StyleSheetHandler::observeProperty): 53 (WebCore::StyleSheetHandler::observeComment): 54 (WebCore::InspectorStyle::populateAllProperties): 55 (WebCore::isValidSelectorListString): 56 (WebCore::InspectorStyleSheet::ensureSourceData): 57 (WebCore::InspectorStyleSheetForInlineStyle::ensureParsedDataReady): 58 (WebCore::InspectorStyleSheetForInlineStyle::ruleSourceData): 59 (WebCore::createCSSParser): Deleted. 60 (WebCore::InspectorStyleSheetForInlineStyle::getStyleAttributeRanges): Deleted. 61 * inspector/InspectorStyleSheet.h: 62 (WebCore::InspectorStyleProperty::setRawTextFromStyleDeclaration): 63 Add the new implementation. This involves duplicating most of the old 64 parser code for this into a new class, StyleSheetHandler, that implements 65 the observer interface and builds up the same data structures as the old 66 parser did in response to the callbacks. 67 1 68 2016-11-18 Dan Bernstein <[email protected]> 2 69 -
trunk/Source/WebCore/css/CSSGrammar.y.in
r206641 r208886 517 517 before_import_rule: 518 518 /* empty */ { 519 parser->markRuleHeaderStart( CSSRuleSourceData::IMPORT_RULE);519 parser->markRuleHeaderStart(StyleRule::Import); 520 520 } 521 521 ; … … 655 655 before_media_rule: 656 656 /* empty */ { 657 parser->markRuleHeaderStart( CSSRuleSourceData::MEDIA_RULE);657 parser->markRuleHeaderStart(StyleRule::Media); 658 658 } 659 659 ; … … 700 700 before_supports_rule: 701 701 /* empty */ { 702 parser->markRuleHeaderStart( CSSRuleSourceData::SUPPORTS_RULE);702 parser->markRuleHeaderStart(StyleRule::Supports); 703 703 parser->markSupportsRuleHeaderStart(); 704 704 } … … 768 768 before_keyframes_rule: 769 769 /* empty */ { 770 parser->markRuleHeaderStart( CSSRuleSourceData::KEYFRAMES_RULE);770 parser->markRuleHeaderStart(StyleRule::Keyframe); 771 771 } 772 772 ; … … 830 830 before_page_rule: 831 831 /* empty */ { 832 parser->markRuleHeaderStart( CSSRuleSourceData::PAGE_RULE);832 parser->markRuleHeaderStart(StyleRule::Page); 833 833 } 834 834 ; … … 943 943 before_font_face_rule: 944 944 /* empty */ { 945 parser->markRuleHeaderStart( CSSRuleSourceData::FONT_FACE_RULE);945 parser->markRuleHeaderStart(StyleRule::FontFace); 946 946 } 947 947 ; … … 966 966 /* empty */ { 967 967 parser->markViewportRuleBodyStart(); 968 parser->markRuleHeaderStart( CSSRuleSourceData::VIEWPORT_RULE);968 parser->markRuleHeaderStart(StyleRule::Viewport); 969 969 } 970 970 ; … … 992 992 before_region_rule: 993 993 /* empty */ { 994 parser->markRuleHeaderStart( CSSRuleSourceData::REGION_RULE);994 parser->markRuleHeaderStart(StyleRule::Region); 995 995 } 996 996 ; … … 1025 1025 before_selector_list: 1026 1026 { 1027 parser->markRuleHeaderStart( CSSRuleSourceData::STYLE_RULE);1027 parser->markRuleHeaderStart(StyleRule::Style); 1028 1028 parser->markSelectorStart(); 1029 1029 } -
trunk/Source/WebCore/css/CSSPropertySourceData.cpp
r203322 r208886 56 56 } 57 57 58 CSSPropertySourceData::CSSPropertySourceData(const String& name, const String& value, bool important, bool parsedOk, const SourceRange& range)58 CSSPropertySourceData::CSSPropertySourceData(const String& name, const String& value, bool important, bool disabled, bool parsedOk, const SourceRange& range) 59 59 : name(name) 60 60 , value(value) 61 61 , important(important) 62 , disabled(disabled) 62 63 , parsedOk(parsedOk) 63 64 , range(range) … … 69 70 , value(other.value) 70 71 , important(other.important) 72 , disabled(other.disabled) 71 73 , parsedOk(other.parsedOk) 72 74 , range(other.range) … … 78 80 , value(emptyString()) 79 81 , important(false) 82 , disabled(false) 80 83 , parsedOk(false) 81 84 , range(SourceRange(0, 0)) -
trunk/Source/WebCore/css/CSSPropertySourceData.h
r208668 r208886 31 31 #pragma once 32 32 33 #include "StyleRule.h" 33 34 #include <utility> 34 35 #include <wtf/Forward.h> … … 52 53 53 54 struct CSSPropertySourceData { 54 CSSPropertySourceData(const String& name, const String& value, bool important, bool parsedOk, const SourceRange& range);55 CSSPropertySourceData(const String& name, const String& value, bool important, bool disabled, bool parsedOk, const SourceRange&); 55 56 CSSPropertySourceData(const CSSPropertySourceData& other); 56 57 CSSPropertySourceData(); … … 62 63 String value; 63 64 bool important; 65 bool disabled; 64 66 bool parsedOk; 65 67 SourceRange range; … … 80 82 81 83 struct CSSRuleSourceData : public RefCounted<CSSRuleSourceData> { 82 enum Type { 83 UNKNOWN_RULE, 84 STYLE_RULE, 85 IMPORT_RULE, 86 MEDIA_RULE, 87 FONT_FACE_RULE, 88 PAGE_RULE, 89 KEYFRAMES_RULE, 90 REGION_RULE, 91 HOST_RULE, 92 VIEWPORT_RULE, 93 SUPPORTS_RULE, 94 }; 95 96 static Ref<CSSRuleSourceData> create(Type type) 84 static Ref<CSSRuleSourceData> create(StyleRule::Type type) 97 85 { 98 86 return adoptRef(*new CSSRuleSourceData(type)); … … 101 89 static Ref<CSSRuleSourceData> createUnknown() 102 90 { 103 return adoptRef(*new CSSRuleSourceData( UNKNOWN_RULE));91 return adoptRef(*new CSSRuleSourceData(StyleRule::Unknown)); 104 92 } 105 93 106 CSSRuleSourceData( Type type)94 CSSRuleSourceData(StyleRule::Type type) 107 95 : type(type) 108 96 { 109 if (type == S TYLE_RULE || type == FONT_FACE_RULE || type == PAGE_RULE)97 if (type == StyleRule::Style || type == StyleRule::FontFace || type == StyleRule::Page) 110 98 styleSourceData = CSSStyleSourceData::create(); 111 99 } 112 100 113 Type type;101 StyleRule::Type type; 114 102 115 103 // Range of the selector list in the enclosing source. -
trunk/Source/WebCore/css/parser/CSSParser.cpp
r208847 r208886 59 59 #include "CSSParserFastPaths.h" 60 60 #include "CSSParserImpl.h" 61 #include "CSSParserObserver.h" 61 62 #include "CSSPendingSubstitutionValue.h" 62 63 #include "CSSPrimitiveValue.h" … … 393 394 } 394 395 396 void CSSParser::parseSheetForInspector(const CSSParserContext& context, StyleSheetContents* sheet, const String& string, CSSParserObserver& observer) 397 { 398 return CSSParserImpl::parseStyleSheetForInspector(string, context, sheet, observer); 399 } 400 395 401 RefPtr<StyleRuleBase> CSSParser::parseRule(StyleSheetContents* sheet, const String& string) 396 402 { … … 1514 1520 1515 1521 return ok; 1522 } 1523 1524 void CSSParser::parseDeclarationForInspector(const CSSParserContext& context, const String& string, CSSParserObserver& observer) 1525 { 1526 CSSParserImpl::parseDeclarationListForInspector(string, context, observer); 1516 1527 } 1517 1528 … … 12926 12937 m_supportsRuleDataStack = std::make_unique<RuleSourceDataList>(); 12927 12938 12928 auto data = CSSRuleSourceData::create( CSSRuleSourceData::SUPPORTS_RULE);12939 auto data = CSSRuleSourceData::create(StyleRule::Supports); 12929 12940 data->ruleHeaderRange.start = tokenStartOffset(); 12930 12941 m_supportsRuleDataStack->append(WTFMove(data)); … … 13326 13337 } 13327 13338 13328 void CSSParser::markRuleHeaderStart( CSSRuleSourceData::Type ruleType)13339 void CSSParser::markRuleHeaderStart(StyleRule::Type ruleType) 13329 13340 { 13330 13341 if (!isExtractingSourceData()) … … 13451 13462 SourceRange& topRuleBodyRange = m_currentRuleDataStack->last()->ruleBodyRange; 13452 13463 m_currentRuleDataStack->last()->styleSourceData->propertyData.append( 13453 CSSPropertySourceData(name, value, isImportantFound, isPropertyParsed, SourceRange(start - topRuleBodyRange.start, end - topRuleBodyRange.start)));13464 CSSPropertySourceData(name, value, isImportantFound, false, isPropertyParsed, SourceRange(start - topRuleBodyRange.start, end - topRuleBodyRange.start))); 13454 13465 } 13455 13466 resetPropertyRange(); -
trunk/Source/WebCore/css/parser/CSSParser.h
r208847 r208886 51 51 class CSSBorderImageSliceValue; 52 52 class CSSContentDistributionValue; 53 class CSSParserObserver; 53 54 class CSSPrimitiveValue; 54 55 class CSSSelectorList; … … 133 134 bool parseSupportsCondition(const String&); 134 135 136 static void parseSheetForInspector(const CSSParserContext&, StyleSheetContents*, const String&, CSSParserObserver&); 137 static void parseDeclarationForInspector(const CSSParserContext&, const String&, CSSParserObserver&); 138 135 139 static ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important, const CSSParserContext&, StyleSheetContents*); 136 140 static ParseResult parseCustomPropertyValue(MutableStyleProperties&, const AtomicString& propertyName, const String&, bool important, const CSSParserContext&, StyleSheetContents* contextStyleSheet); … … 142 146 RefPtr<CSSPrimitiveValue> parseValidPrimitive(CSSValueID ident, ValueWithCalculation&); 143 147 148 // FIXME-NEWPARSER: Can remove the last two arguments once the new parser is turned on. 144 149 WEBCORE_EXPORT bool parseDeclaration(MutableStyleProperties&, const String&, RefPtr<CSSRuleSourceData>&&, StyleSheetContents* contextStyleSheet); 145 150 static Ref<ImmutableStyleProperties> parseInlineStyleDeclaration(const String&, Element*); … … 457 462 458 463 void fixUnparsedPropertyRanges(CSSRuleSourceData&); 459 void markRuleHeaderStart( CSSRuleSourceData::Type);464 void markRuleHeaderStart(StyleRule::Type); 460 465 void markRuleHeaderEnd(); 461 466 -
trunk/Source/WebCore/css/parser/CSSParserObserver.h
r208668 r208886 43 43 virtual void observeProperty(unsigned startOffset, unsigned endOffset, bool isImportant, bool isParsed) = 0; 44 44 virtual void observeComment(unsigned startOffset, unsigned endOffset) = 0; 45 // FIXME: Unused, should be removed46 virtual void startMediaQueryExp(unsigned offset) = 0;47 virtual void endMediaQueryExp(unsigned offset) = 0;48 virtual void startMediaQuery() = 0;49 virtual void endMediaQuery() = 0;50 45 }; 51 46 -
trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp
r208688 r208886 30 30 #include "CSSMediaRule.h" 31 31 #include "CSSParser.h" 32 #include "CSSParserObserver.h" 32 33 #include "CSSPropertyNames.h" 33 34 #include "CSSPropertySourceData.h" … … 101 102 { 102 103 for (auto& data : dataList) { 103 if (data->type == CSSRuleSourceData::STYLE_RULE)104 if (data->type == WebCore::StyleRule::Style) 104 105 target.append(data.copyRef()); 105 else if (data->type == CSSRuleSourceData::MEDIA_RULE)106 else if (data->type == WebCore::StyleRule::Media) 106 107 flattenSourceData(data->childRules, target); 107 else if (data->type == CSSRuleSourceData::SUPPORTS_RULE)108 else if (data->type == WebCore::StyleRule::Supports) 108 109 flattenSourceData(data->childRules, target); 109 110 } … … 136 137 137 138 namespace WebCore { 139 140 static CSSParserContext parserContextForDocument(Document* document) 141 { 142 return document ? CSSParserContext(*document) : strictCSSParserContext(); 143 } 144 145 class StyleSheetHandler : public CSSParserObserver { 146 public: 147 StyleSheetHandler(const String& parsedText, Document* document, RuleSourceDataList* result) 148 : m_parsedText(parsedText) 149 , m_document(document) 150 , m_ruleSourceDataResult(result) 151 { 152 ASSERT(m_ruleSourceDataResult); 153 } 154 155 private: 156 void startRuleHeader(StyleRule::Type, unsigned) override; 157 void endRuleHeader(unsigned) override; 158 void observeSelector(unsigned startOffset, unsigned endOffset) override; 159 void startRuleBody(unsigned) override; 160 void endRuleBody(unsigned) override; 161 void observeProperty(unsigned startOffset, unsigned endOffset, bool isImportant, bool isParsed) override; 162 void observeComment(unsigned startOffset, unsigned endOffset) override; 163 164 Ref<CSSRuleSourceData> popRuleData(); 165 template <typename CharacterType> inline void setRuleHeaderEnd(const CharacterType*, unsigned); 166 void fixUnparsedPropertyRanges(CSSRuleSourceData*); 167 168 const String& m_parsedText; 169 Document* m_document; 170 171 RuleSourceDataList m_currentRuleDataStack; 172 RefPtr<CSSRuleSourceData> m_currentRuleData; 173 RuleSourceDataList* m_ruleSourceDataResult { nullptr }; 174 }; 175 176 void StyleSheetHandler::startRuleHeader(StyleRule::Type type, unsigned offset) 177 { 178 // Pop off data for a previous invalid rule. 179 if (m_currentRuleData) 180 m_currentRuleDataStack.removeLast(); 181 182 auto data = CSSRuleSourceData::create(type); 183 data->ruleHeaderRange.start = offset; 184 m_currentRuleData = data.copyRef(); 185 m_currentRuleDataStack.append(WTFMove(data)); 186 } 187 188 template <typename CharacterType> inline void StyleSheetHandler::setRuleHeaderEnd(const CharacterType* dataStart, unsigned listEndOffset) 189 { 190 while (listEndOffset > 1) { 191 if (isHTMLSpace<CharacterType>(*(dataStart + listEndOffset - 1))) 192 --listEndOffset; 193 else 194 break; 195 } 196 197 m_currentRuleDataStack.last()->ruleHeaderRange.end = listEndOffset; 198 if (!m_currentRuleDataStack.last()->selectorRanges.isEmpty()) 199 m_currentRuleDataStack.last()->selectorRanges.last().end = listEndOffset; 200 } 201 202 void StyleSheetHandler::endRuleHeader(unsigned offset) 203 { 204 ASSERT(!m_currentRuleDataStack.isEmpty()); 205 206 if (m_parsedText.is8Bit()) 207 setRuleHeaderEnd<LChar>(m_parsedText.characters8(), offset); 208 else 209 setRuleHeaderEnd<UChar>(m_parsedText.characters16(), offset); 210 } 211 212 void StyleSheetHandler::observeSelector(unsigned startOffset, unsigned endOffset) 213 { 214 ASSERT(m_currentRuleDataStack.size()); 215 m_currentRuleDataStack.last()->selectorRanges.append(SourceRange(startOffset, endOffset)); 216 } 217 218 void StyleSheetHandler::startRuleBody(unsigned offset) 219 { 220 m_currentRuleData = nullptr; 221 ASSERT(!m_currentRuleDataStack.isEmpty()); 222 223 // Skip the rule body opening brace. 224 if (m_parsedText[offset] == '{') 225 ++offset; 226 227 m_currentRuleDataStack.last()->ruleBodyRange.start = offset; 228 } 229 230 void StyleSheetHandler::endRuleBody(unsigned offset) 231 { 232 ASSERT(!m_currentRuleDataStack.isEmpty()); 233 m_currentRuleDataStack.last()->ruleBodyRange.end = offset; 234 auto rule = popRuleData(); 235 fixUnparsedPropertyRanges(rule.ptr()); 236 if (m_currentRuleDataStack.isEmpty()) 237 m_ruleSourceDataResult->append(WTFMove(rule)); 238 else 239 m_currentRuleDataStack.last()->childRules.append(WTFMove(rule)); 240 } 241 242 Ref<CSSRuleSourceData> StyleSheetHandler::popRuleData() 243 { 244 ASSERT(!m_currentRuleDataStack.isEmpty()); 245 m_currentRuleData = nullptr; 246 auto data = WTFMove(m_currentRuleDataStack.last()); 247 m_currentRuleDataStack.removeLast(); 248 return data; 249 } 250 251 template <typename CharacterType> 252 static inline void fixUnparsedProperties(const CharacterType* characters, CSSRuleSourceData* ruleData) 253 { 254 Vector<CSSPropertySourceData>& propertyData = ruleData->styleSourceData->propertyData; 255 unsigned size = propertyData.size(); 256 if (!size) 257 return; 258 259 unsigned styleStart = ruleData->ruleBodyRange.start; 260 261 CSSPropertySourceData* nextData = &(propertyData.at(0)); 262 for (unsigned i = 0; i < size; ++i) { 263 CSSPropertySourceData* currentData = nextData; 264 nextData = i < size - 1 ? &(propertyData.at(i + 1)) : nullptr; 265 266 if (currentData->parsedOk) 267 continue; 268 if (currentData->range.end > 0 && characters[styleStart + currentData->range.end - 1] == ';') 269 continue; 270 271 unsigned propertyEnd; 272 if (!nextData) 273 propertyEnd = ruleData->ruleBodyRange.end - 1; 274 else 275 propertyEnd = styleStart + nextData->range.start - 1; 276 277 while (isHTMLSpace<CharacterType>(characters[propertyEnd])) 278 --propertyEnd; 279 280 // propertyEnd points at the last property text character. 281 unsigned newPropertyEnd = propertyEnd + styleStart + 1; 282 if (currentData->range.end != newPropertyEnd) { 283 currentData->range.end = newPropertyEnd; 284 unsigned valueStart = styleStart + currentData->range.start + currentData->name.length(); 285 while (valueStart < propertyEnd && characters[valueStart] != ':') 286 ++valueStart; 287 288 // Shift past the ':'. 289 if (valueStart < propertyEnd) 290 ++valueStart; 291 292 while (valueStart < propertyEnd && isHTMLSpace<CharacterType>(characters[valueStart])) 293 ++valueStart; 294 295 // Need to exclude the trailing ';' from the property value. 296 currentData->value = String(characters + valueStart, propertyEnd - valueStart + (characters[propertyEnd] == ';' ? 0 : 1)); 297 } 298 } 299 } 300 301 void StyleSheetHandler::fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData) 302 { 303 if (!ruleData->styleSourceData) 304 return; 305 306 if (m_parsedText.is8Bit()) { 307 fixUnparsedProperties<LChar>(m_parsedText.characters8(), ruleData); 308 return; 309 } 310 311 fixUnparsedProperties<UChar>(m_parsedText.characters16(), ruleData); 312 } 313 314 void StyleSheetHandler::observeProperty(unsigned startOffset, unsigned endOffset, bool isImportant, bool isParsed) 315 { 316 if (m_currentRuleDataStack.isEmpty() || !m_currentRuleDataStack.last()->styleSourceData) 317 return; 318 319 ASSERT(endOffset <= m_parsedText.length()); 320 321 // Include semicolon in the property text. 322 if (endOffset < m_parsedText.length() && m_parsedText[endOffset] == ';') 323 ++endOffset; 324 325 ASSERT(startOffset < endOffset); 326 String propertyString = m_parsedText.substring(startOffset, endOffset - startOffset).stripWhiteSpace(); 327 if (propertyString.endsWith(';')) 328 propertyString = propertyString.left(propertyString.length() - 1); 329 size_t colonIndex = propertyString.find(':'); 330 ASSERT(colonIndex != notFound); 331 332 String name = propertyString.left(colonIndex).stripWhiteSpace(); 333 String value = propertyString.substring(colonIndex + 1, propertyString.length()).stripWhiteSpace(); 334 335 // FIXME-NEWPARSER: The property range is relative to the declaration start offset, but no 336 // good reason for it, and it complicates fixUnparsedProperties. 337 SourceRange& topRuleBodyRange = m_currentRuleDataStack.last()->ruleBodyRange; 338 m_currentRuleDataStack.last()->styleSourceData->propertyData.append(CSSPropertySourceData(name, value, isImportant, false, isParsed, SourceRange(startOffset - topRuleBodyRange.start, endOffset - topRuleBodyRange.start))); 339 } 340 341 void StyleSheetHandler::observeComment(unsigned startOffset, unsigned endOffset) 342 { 343 ASSERT(endOffset <= m_parsedText.length()); 344 345 if (m_currentRuleDataStack.isEmpty() || !m_currentRuleDataStack.last()->ruleHeaderRange.end || !m_currentRuleDataStack.last()->styleSourceData) 346 return; 347 348 // The lexer is not inside a property AND it is scanning a declaration-aware 349 // rule body. 350 String commentText = m_parsedText.substring(startOffset, endOffset - startOffset); 351 352 ASSERT(commentText.startsWith("/*")); 353 commentText = commentText.substring(2); 354 355 // Require well-formed comments. 356 if (!commentText.endsWith("*/")) 357 return; 358 commentText = commentText.substring(0, commentText.length() - 2).stripWhiteSpace(); 359 if (commentText.isEmpty()) 360 return; 361 362 // FIXME: Use the actual rule type rather than STYLE_RULE? 363 RuleSourceDataList sourceData; 364 365 StyleSheetHandler handler(commentText, m_document, &sourceData); 366 CSSParser::parseDeclarationForInspector(parserContextForDocument(m_document), commentText, handler); 367 Vector<CSSPropertySourceData>& commentPropertyData = sourceData.first()->styleSourceData->propertyData; 368 if (commentPropertyData.size() != 1) 369 return; 370 CSSPropertySourceData& propertyData = commentPropertyData.at(0); 371 bool parsedOk = propertyData.parsedOk || propertyData.name.startsWith("-moz-") || propertyData.name.startsWith("-o-") || propertyData.name.startsWith("-webkit-") || propertyData.name.startsWith("-ms-"); 372 if (!parsedOk || propertyData.range.length() != commentText.length()) 373 return; 374 375 // FIXME-NEWPARSER: The property range is relative to the declaration start offset, but no 376 // good reason for it, and it complicates fixUnparsedProperties. 377 SourceRange& topRuleBodyRange = m_currentRuleDataStack.last()->ruleBodyRange; 378 m_currentRuleDataStack.last()->styleSourceData->propertyData.append(CSSPropertySourceData(propertyData.name, propertyData.value, false, true, true, SourceRange(startOffset - topRuleBodyRange.start, endOffset - topRuleBodyRange.start))); 379 } 138 380 139 381 enum MediaListSource { … … 274 516 } 275 517 276 static std::unique_ptr<CSSParser> createCSSParser(Document* document)277 {278 return std::make_unique<CSSParser>(document ? CSSParserContext(*document) : strictCSSParserContext());279 }280 281 518 Ref<InspectorStyle> InspectorStyle::create(const InspectorCSSId& styleId, RefPtr<CSSStyleDeclaration>&& style, InspectorStyleSheet* parentStyleSheet) 282 519 { … … 364 601 String styleDeclaration = styleDeclarationOrException.hasException() ? emptyString() : styleDeclarationOrException.releaseReturnValue(); 365 602 for (auto& sourceData : *sourcePropertyData) { 366 InspectorStyleProperty p(sourceData, true, false);603 InspectorStyleProperty p(sourceData, true, sourceData.disabled); 367 604 p.setRawTextFromStyleDeclaration(styleDeclaration); 368 605 result->append(p); … … 374 611 String name = m_style->item(i); 375 612 if (sourcePropertyNames.add(lowercasePropertyName(name))) 376 result->append(InspectorStyleProperty(CSSPropertySourceData(name, m_style->getPropertyValue(name), !m_style->getPropertyPriority(name).isEmpty(), true, SourceRange()), false, false));613 result->append(InspectorStyleProperty(CSSPropertySourceData(name, m_style->getPropertyValue(name), !m_style->getPropertyPriority(name).isEmpty(), false, true, SourceRange()), false, false)); 377 614 } 378 615 } … … 636 873 { 637 874 CSSSelectorList selectorList; 638 createCSSParser(document)->parseSelector(selector, selectorList); 875 CSSParser parser(parserContextForDocument(document)); 876 parser.parseSelector(selector, selectorList); 639 877 return selectorList.isValid(); 640 878 } … … 1090 1328 RefPtr<StyleSheetContents> newStyleSheet = StyleSheetContents::create(); 1091 1329 auto ruleSourceDataResult = std::make_unique<RuleSourceDataList>(); 1092 createCSSParser(m_pageStyleSheet->ownerDocument())->parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), TextPosition(), ruleSourceDataResult.get(), false); 1330 1331 CSSParserContext context(parserContextForDocument(m_pageStyleSheet->ownerDocument())); 1332 if (context.useNewParser) { 1333 StyleSheetHandler handler(m_parsedStyleSheet->text(), m_pageStyleSheet->ownerDocument(), ruleSourceDataResult.get()); 1334 CSSParser::parseSheetForInspector(context, newStyleSheet.get(), m_parsedStyleSheet->text(), handler); 1335 } else 1336 CSSParser(context).parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), TextPosition(), ruleSourceDataResult.get(), false); 1093 1337 m_parsedStyleSheet->setSourceData(WTFMove(ruleSourceDataResult)); 1094 1338 return m_parsedStyleSheet->hasSourceData(); … … 1296 1540 return true; 1297 1541 1298 m_ruleSourceData = CSSRuleSourceData::create(CSSRuleSourceData::STYLE_RULE); 1299 bool success = getStyleAttributeRanges(m_ruleSourceData.get()); 1300 if (!success) 1542 if (!m_element->isStyledElement()) 1301 1543 return false; 1302 1544 1545 m_ruleSourceData = ruleSourceData(); 1303 1546 return true; 1304 1547 } … … 1320 1563 } 1321 1564 1322 bool InspectorStyleSheetForInlineStyle::getStyleAttributeRanges(CSSRuleSourceData* result) const 1323 { 1324 if (!m_element->isStyledElement()) 1325 return false; 1326 1565 Ref<CSSRuleSourceData> InspectorStyleSheetForInlineStyle::ruleSourceData() const 1566 { 1327 1567 if (m_styleText.isEmpty()) { 1568 auto result = CSSRuleSourceData::create(StyleRule::Style); 1328 1569 result->ruleBodyRange.start = 0; 1329 1570 result->ruleBodyRange.end = 0; 1330 return true; 1331 } 1332 1571 return result; 1572 } 1573 1574 CSSParserContext context(parserContextForDocument(&m_element->document())); 1575 if (context.useNewParser) { 1576 RuleSourceDataList ruleSourceDataResult; 1577 StyleSheetHandler handler(m_styleText, &m_element->document(), &ruleSourceDataResult); 1578 CSSParser::parseDeclarationForInspector(context, m_styleText, handler); 1579 return WTFMove(ruleSourceDataResult.first()); 1580 } 1581 1582 auto result = CSSRuleSourceData::create(StyleRule::Style); 1333 1583 auto tempDeclaration = MutableStyleProperties::create(); 1334 createCSSParser(&m_element->document())->parseDeclaration(tempDeclaration, m_styleText, result, nullptr);1335 return true;1584 CSSParser(context).parseDeclaration(tempDeclaration, m_styleText, result.ptr(), nullptr); 1585 return result; 1336 1586 } 1337 1587 -
trunk/Source/WebCore/inspector/InspectorStyleSheet.h
r208603 r208886 252 252 CSSStyleDeclaration* inlineStyle() const; 253 253 const String& elementStyleText() const; 254 bool getStyleAttributeRanges(CSSRuleSourceData* result) const;254 Ref<CSSRuleSourceData> ruleSourceData() const; 255 255 256 256 RefPtr<Element> m_element;
Note:
See TracChangeset
for help on using the changeset viewer.