Changeset 121551 in webkit
- Timestamp:
- Jun 29, 2012, 5:06:11 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r121549 r121551 1 2012-06-25 Alexander Pavlov <apavlov@chromium.org> 2 3 Web Inspector: Provide source data for all known rule types in CSSParser, except "keyframe" and "region" 4 https://bugs.webkit.org/show_bug.cgi?id=88420 5 6 Reviewed by Antti Koivisto. 7 8 This change transitions the CSS source code model from a flat list of style rules to a tree of all types of CSS rules 9 (some of them lack actual source code data), which is crucial to model-based CSS stylesheet source editing 10 (add/remove CSS rule) and navigation. 11 As a side effect, the CSS parsing performance on PerformanceTests/Parser/css-parser-yui.html is improved roughly by 2%: 12 - originally: median= 282.051282051 runs/s, stdev= 1.51236798322 runs/s, min= 278.481012658 runs/s, max= 283.870967742 runs/s 13 - with patch applied: median= 287.206266319 runs/s, stdev= 1.31518320219 runs/s, min= 282.051282051 runs/s, max= 288.713910761 runs/s 14 15 No new tests, as there is no client-visible behavior change. Existing Inspector tests will be modified 16 to test the new data provided, along with the necessary Inspector plumbing. 17 18 * css/CSSGrammar.y: 19 * css/CSSMediaRule.cpp: 20 (WebCore::CSSMediaRule::reattach): Check for mediaQueries() validity before reattaching. 21 * css/CSSParser.cpp: Unless explicitly specified below, the method changes are related to the extension of the 22 source-based CSS model provided by the parser. 23 (WebCore::CSSParser::CSSParser): 24 (WebCore::CSSParser::setupParser): 25 (WebCore::CSSParser::parseDeclaration): Accept a CSSRuleSourceData for filling, since it now contains 26 the related style source range. 27 (WebCore::CSSParser::createImportRule): 28 (WebCore::CSSParser::createMediaRule): Create CSSMediaRule even if media and rules are empty, 29 which is consistent with Mozilla. 30 (WebCore::CSSParser::processAndAddNewRuleToSourceTreeIfNeeded): 31 (WebCore): 32 (WebCore::CSSParser::addNewRuleToSourceTree): 33 (WebCore::CSSParser::createKeyframesRule): 34 (WebCore::CSSParser::createStyleRule): 35 (WebCore::CSSParser::createFontFaceRule): 36 (WebCore::CSSParser::createPageRule): 37 (WebCore::CSSParser::createRegionRule): 38 (WebCore::CSSParser::fixUnparsedPropertyRanges): 39 (WebCore::CSSParser::markRuleHeaderStart): 40 (WebCore::CSSParser::markRuleHeaderEnd): 41 (WebCore::CSSParser::markRuleBodyStart): 42 (WebCore::CSSParser::markRuleBodyEnd): 43 (WebCore::CSSParser::markPropertyStart): 44 (WebCore::CSSParser::markPropertyEnd): 45 * css/CSSParser.h: 46 (CSSParser): 47 * css/CSSPropertySourceData.h: Extend the model to handle more types of rules and their containments. 48 (WebCore): 49 (WebCore::CSSRuleSourceData::create): 50 (WebCore::CSSRuleSourceData::createUnknown): 51 (CSSRuleSourceData): 52 (WebCore::CSSRuleSourceData::CSSRuleSourceData): 53 * inspector/InspectorStyleSheet.cpp: Follow the CSSParser API changes but retain the flat stored CSS rules structure. 54 (ParsedStyleSheet): 55 (flattenSourceData): Flatten the rule tree to retain the existing rule-handling code intact. 56 (ParsedStyleSheet::setSourceData): 57 (ParsedStyleSheet::ruleSourceDataAt): 58 (WebCore::InspectorStyle::buildObjectForStyle): 59 (WebCore::InspectorStyle::setPropertyText): 60 (WebCore::InspectorStyle::styleText): 61 (WebCore::InspectorStyleSheet::setRuleSelector): 62 (WebCore::InspectorStyleSheet::deleteRule): 63 (WebCore::InspectorStyleSheet::buildObjectForRule): 64 (WebCore::InspectorStyleSheet::buildObjectForStyle): 65 (WebCore::InspectorStyleSheet::ensureSourceData): 66 (WebCore::InspectorStyleSheet::styleSheetTextWithChangedStyle): 67 (WebCore::InspectorStyleSheetForInlineStyle::ensureParsedDataReady): 68 (WebCore::InspectorStyleSheetForInlineStyle::getStyleAttributeRanges): 69 * inspector/InspectorStyleSheet.h: 70 1 71 2012-06-29 Vsevolod Vlasov <vsevik@chromium.org> 2 72 -
trunk/Source/WebCore/css/CSSGrammar.y
r121531 r121551 388 388 if (p->m_styleSheet) 389 389 p->m_styleSheet->parserSetEncodingFromCharsetRule($3); 390 if (p->isExtractingSourceData() && p->m_currentRuleDataStack->isEmpty() && p->m_ruleSourceDataResult) 391 p->addNewRuleToSourceTree(CSSRuleSourceData::createUnknown()); 390 392 $$ = 0; 391 393 } … … 463 465 ; 464 466 467 at_import_header_end_maybe_space: 468 maybe_space { 469 CSSParser* p = static_cast<CSSParser*>(parser); 470 p->markRuleHeaderEnd(); 471 p->markRuleBodyStart(); 472 } 473 ; 474 475 before_import_rule: 476 /* empty */ { 477 static_cast<CSSParser*>(parser)->markRuleHeaderStart(CSSRuleSourceData::IMPORT_RULE); 478 } 479 ; 465 480 466 481 import: 467 IMPORT_SYM maybe_space string_or_uri maybe_space maybe_media_list ';' { 468 $$ = static_cast<CSSParser*>(parser)->createImportRule($3, $5); 469 } 470 | IMPORT_SYM maybe_space string_or_uri maybe_space maybe_media_list TOKEN_EOF { 471 $$ = static_cast<CSSParser*>(parser)->createImportRule($3, $5); 472 } 473 | IMPORT_SYM maybe_space string_or_uri maybe_space maybe_media_list invalid_block { 474 $$ = 0; 475 } 476 | IMPORT_SYM error ';' { 477 $$ = 0; 478 } 479 | IMPORT_SYM error invalid_block { 480 $$ = 0; 482 before_import_rule IMPORT_SYM at_import_header_end_maybe_space string_or_uri maybe_space maybe_media_list ';' { 483 $$ = static_cast<CSSParser*>(parser)->createImportRule($4, $6); 484 } 485 | before_import_rule IMPORT_SYM at_import_header_end_maybe_space string_or_uri maybe_space maybe_media_list TOKEN_EOF { 486 $$ = static_cast<CSSParser*>(parser)->createImportRule($4, $6); 487 } 488 | before_import_rule IMPORT_SYM at_import_header_end_maybe_space string_or_uri maybe_space maybe_media_list invalid_block { 489 $$ = 0; 490 static_cast<CSSParser*>(parser)->popRuleData(); 491 } 492 | before_import_rule IMPORT_SYM error ';' { 493 $$ = 0; 494 static_cast<CSSParser*>(parser)->popRuleData(); 495 } 496 | before_import_rule IMPORT_SYM error invalid_block { 497 $$ = 0; 498 static_cast<CSSParser*>(parser)->popRuleData(); 481 499 } 482 500 ; … … 603 621 ; 604 622 623 at_rule_body_start: 624 /* empty */ { 625 static_cast<CSSParser*>(parser)->markRuleBodyStart(); 626 } 627 ; 628 629 before_media_rule: 630 /* empty */ { 631 static_cast<CSSParser*>(parser)->markRuleHeaderStart(CSSRuleSourceData::MEDIA_RULE); 632 } 633 ; 634 635 at_rule_header_end_maybe_space: 636 maybe_space { 637 static_cast<CSSParser*>(parser)->markRuleHeaderEnd(); 638 } 639 ; 640 605 641 media: 606 MEDIA_SYM maybe_space media_list '{' maybe_space block_rule_list save_block { 607 $$ = static_cast<CSSParser*>(parser)->createMediaRule($3, $6); 608 } 609 | MEDIA_SYM maybe_space '{' maybe_space block_rule_list save_block { 610 $$ = static_cast<CSSParser*>(parser)->createMediaRule(0, $5); 611 } 612 | MEDIA_SYM maybe_space ';' { 613 $$ = 0; 642 before_media_rule MEDIA_SYM maybe_space media_list at_rule_header_end '{' at_rule_body_start maybe_space block_rule_list save_block { 643 $$ = static_cast<CSSParser*>(parser)->createMediaRule($4, $9); 644 } 645 | before_media_rule MEDIA_SYM at_rule_header_end_maybe_space '{' at_rule_body_start maybe_space block_rule_list save_block { 646 $$ = static_cast<CSSParser*>(parser)->createMediaRule(0, $7); 647 } 648 | before_media_rule MEDIA_SYM at_rule_header_end_maybe_space ';' { 649 $$ = 0; 650 static_cast<CSSParser*>(parser)->popRuleData(); 614 651 } 615 652 ; … … 621 658 ; 622 659 660 before_keyframes_rule: 661 /* empty */ { 662 static_cast<CSSParser*>(parser)->markRuleHeaderStart(CSSRuleSourceData::KEYFRAMES_RULE); 663 } 664 ; 665 623 666 keyframes: 624 WEBKIT_KEYFRAMES_SYM maybe_space keyframe_name maybe_space '{'maybe_space keyframes_rule closing_brace {625 $$ = static_cast<CSSParser*>(parser)->createKeyframesRule($ 3, static_cast<CSSParser*>(parser)->sinkFloatingKeyframeVector($7));667 before_keyframes_rule WEBKIT_KEYFRAMES_SYM maybe_space keyframe_name at_rule_header_end_maybe_space '{' at_rule_body_start maybe_space keyframes_rule closing_brace { 668 $$ = static_cast<CSSParser*>(parser)->createKeyframesRule($4, static_cast<CSSParser*>(parser)->sinkFloatingKeyframeVector($9)); 626 669 } 627 670 ; … … 675 718 ; 676 719 720 before_page_rule: 721 /* empty */ { 722 static_cast<CSSParser*>(parser)->markRuleHeaderStart(CSSRuleSourceData::PAGE_RULE); 723 } 724 ; 725 677 726 page: 678 PAGE_SYM maybe_space page_selectormaybe_space679 '{' maybe_spacedeclarations_and_margins closing_brace {680 CSSParser* p = static_cast<CSSParser*>(parser); 681 if ($ 3)682 $$ = p->createPageRule(p->sinkFloatingSelector($ 3));727 before_page_rule PAGE_SYM maybe_space page_selector at_rule_header_end_maybe_space 728 '{' at_rule_body_start maybe_space_before_declaration declarations_and_margins closing_brace { 729 CSSParser* p = static_cast<CSSParser*>(parser); 730 if ($4) 731 $$ = p->createPageRule(p->sinkFloatingSelector($4)); 683 732 else { 684 733 // Clear properties in the invalid @page rule. … … 686 735 // Also clear margin at-rules here once we fully implement margin at-rules parsing. 687 736 $$ = 0; 737 static_cast<CSSParser*>(parser)->popRuleData(); 688 738 } 689 739 } 690 | PAGE_SYM error invalid_block { 740 | before_page_rule PAGE_SYM error invalid_block { 741 static_cast<CSSParser*>(parser)->popRuleData(); 691 742 $$ = 0; 692 743 } 693 | PAGE_SYM error ';' { 744 | before_page_rule PAGE_SYM error ';' { 745 static_cast<CSSParser*>(parser)->popRuleData(); 694 746 $$ = 0; 695 747 } … … 787 839 ; 788 840 841 before_font_face_rule: 842 /* empty */ { 843 static_cast<CSSParser*>(parser)->markRuleHeaderStart(CSSRuleSourceData::FONT_FACE_RULE); 844 } 845 ; 846 789 847 font_face: 790 FONT_FACE_SYMmaybe_space791 '{' maybe_spacedeclaration_list closing_brace {848 before_font_face_rule FONT_FACE_SYM at_rule_header_end_maybe_space 849 '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace { 792 850 $$ = static_cast<CSSParser*>(parser)->createFontFaceRule(); 793 851 } 794 | FONT_FACE_SYM error invalid_block {852 | before_font_face_rule FONT_FACE_SYM error invalid_block { 795 853 $$ = 0; 796 } 797 | FONT_FACE_SYM error ';' { 854 static_cast<CSSParser*>(parser)->popRuleData(); 855 } 856 | before_font_face_rule FONT_FACE_SYM error ';' { 798 857 $$ = 0; 858 static_cast<CSSParser*>(parser)->popRuleData(); 799 859 } 800 860 ; … … 838 898 maybe_space_before_declaration: 839 899 maybe_space { 840 CSSParser* p = static_cast<CSSParser*>(parser); 841 p->markPropertyStart(); 900 static_cast<CSSParser*>(parser)->markPropertyStart(); 842 901 } 843 902 ; … … 845 904 before_selector_list: 846 905 /* empty */ { 847 CSSParser* p = static_cast<CSSParser*>(parser); 848 p->markSelectorListStart(); 849 } 850 ; 851 852 before_rule_opening_brace: 906 static_cast<CSSParser*>(parser)->markRuleHeaderStart(CSSRuleSourceData::STYLE_RULE); 907 } 908 ; 909 910 at_rule_header_end: 853 911 /* empty */ { 854 CSSParser* p = static_cast<CSSParser*>(parser); 855 p->markSelectorListEnd(); 912 static_cast<CSSParser*>(parser)->markRuleHeaderEnd(); 856 913 } 857 914 ; 858 915 859 916 ruleset: 860 before_selector_list selector_list before_rule_opening_brace'{' maybe_space_before_declaration declaration_list closing_brace {917 before_selector_list selector_list at_rule_header_end '{' maybe_space_before_declaration declaration_list closing_brace { 861 918 CSSParser* p = static_cast<CSSParser*>(parser); 862 919 $$ = p->createStyleRule($2); -
trunk/Source/WebCore/css/CSSMediaRule.cpp
r118194 r121551 167 167 ASSERT(rule); 168 168 m_mediaRule = rule; 169 if (m_mediaCSSOMWrapper )169 if (m_mediaCSSOMWrapper && m_mediaRule->mediaQueries()) 170 170 m_mediaCSSOMWrapper->reattach(m_mediaRule->mediaQueries()); 171 171 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { -
trunk/Source/WebCore/css/CSSParser.cpp
r121531 r121551 252 252 , m_defaultNamespace(starAtom) 253 253 , m_parsedTextPrefixLength(0) 254 , m_inStyleRuleOrDeclaration(false)255 , m_selectorListRange(0, 0)256 , m_ruleBodyRange(0, 0)257 254 , m_propertyRange(UINT_MAX, UINT_MAX) 258 255 , m_ruleSourceDataResult(0) … … 318 315 319 316 m_currentCharacter = m_tokenStart = m_dataStart.get(); 320 resetRuleBodyMarks();321 317 } 322 318 … … 1222 1218 } 1223 1219 1224 bool CSSParser::parseDeclaration(StylePropertySet* declaration, const String& string, PassRefPtr<CSS StyleSourceData> prpStyleSourceData, StyleSheetContents* contextStyleSheet)1220 bool CSSParser::parseDeclaration(StylePropertySet* declaration, const String& string, PassRefPtr<CSSRuleSourceData> prpRuleSourceData, StyleSheetContents* contextStyleSheet) 1225 1221 { 1226 1222 // Length of the "@-webkit-decls{" prefix. … … 1229 1225 setStyleSheet(contextStyleSheet); 1230 1226 1231 RefPtr<CSS StyleSourceData> styleSourceData = prpStyleSourceData;1232 if ( styleSourceData) {1227 RefPtr<CSSRuleSourceData> ruleSourceData = prpRuleSourceData; 1228 if (ruleSourceData) { 1233 1229 m_currentRuleDataStack = adoptPtr(new RuleSourceDataList()); 1234 RefPtr<CSSRuleSourceData> data = CSSRuleSourceData::create(); 1235 data->styleSourceData = styleSourceData; 1236 m_currentRuleDataStack->append(data); 1237 m_inStyleRuleOrDeclaration = true; 1230 m_currentRuleDataStack->append(ruleSourceData); 1238 1231 } 1239 1232 … … 1251 1244 } 1252 1245 1253 if (styleSourceData) { 1254 ASSERT(!m_currentRuleDataStack->isEmpty()); 1255 CSSRuleSourceData* ruleData = m_currentRuleDataStack->last().get(); 1256 ruleData->styleSourceData->styleBodyRange.start = 0; 1257 ruleData->styleSourceData->styleBodyRange.end = string.length(); 1258 for (size_t i = 0, size = ruleData->styleSourceData->propertyData.size(); i < size; ++i) { 1259 CSSPropertySourceData& propertyData = ruleData->styleSourceData->propertyData.at(i); 1246 if (ruleSourceData) { 1247 ASSERT(m_currentRuleDataStack->size() == 1); 1248 ruleSourceData->ruleBodyRange.start = 0; 1249 ruleSourceData->ruleBodyRange.end = string.length(); 1250 for (size_t i = 0, size = ruleSourceData->styleSourceData->propertyData.size(); i < size; ++i) { 1251 CSSPropertySourceData& propertyData = ruleSourceData->styleSourceData->propertyData.at(i); 1260 1252 propertyData.range.start -= prefixLength; 1261 1253 propertyData.range.end -= prefixLength; 1262 1254 } 1263 fixUnparsedPropertyRanges(ruleData); 1264 1255 1256 fixUnparsedPropertyRanges(ruleSourceData.get()); 1265 1257 m_currentRuleDataStack.clear(); 1266 m_inStyleRuleOrDeclaration = false;1267 1258 } 1268 1259 … … 9402 9393 StyleRuleImport* result = rule.get(); 9403 9394 m_parsedRules.append(rule.release()); 9395 processAndAddNewRuleToSourceTreeIfNeeded(); 9404 9396 return result; 9405 9397 } … … 9407 9399 StyleRuleBase* CSSParser::createMediaRule(MediaQuerySet* media, RuleList* rules) 9408 9400 { 9409 if (!media || !rules)9410 return 0;9411 9401 m_allowImportRules = m_allowNamespaceDeclarations = false; 9412 RefPtr<StyleRuleMedia> rule = StyleRuleMedia::create(media, *rules); 9402 RefPtr<StyleRuleMedia> rule; 9403 if (rules) 9404 rule = StyleRuleMedia::create(media, *rules); 9405 else { 9406 RuleList emptyRules; 9407 rule = StyleRuleMedia::create(media, emptyRules); 9408 } 9413 9409 StyleRuleMedia* result = rule.get(); 9414 9410 m_parsedRules.append(rule.release()); 9411 processAndAddNewRuleToSourceTreeIfNeeded(); 9415 9412 return result; 9416 9413 } … … 9423 9420 m_parsedRuleLists.append(list.release()); 9424 9421 return listPtr; 9422 } 9423 9424 void CSSParser::processAndAddNewRuleToSourceTreeIfNeeded() 9425 { 9426 if (!isExtractingSourceData()) 9427 return; 9428 markRuleBodyEnd(); 9429 RefPtr<CSSRuleSourceData> rule = popRuleData(); 9430 fixUnparsedPropertyRanges(rule.get()); 9431 addNewRuleToSourceTree(rule.release()); 9425 9432 } 9426 9433 … … 9430 9437 if (!m_ruleSourceDataResult) 9431 9438 return; 9432 9433 // FIXME: This temporarily builds a flat style rule data list, to avoid the client code breakage. 9434 m_ruleSourceDataResult->append(rule); 9439 if (m_currentRuleDataStack->isEmpty()) 9440 m_ruleSourceDataResult->append(rule); 9441 else 9442 m_currentRuleDataStack->last()->childRules.append(rule); 9435 9443 } 9436 9444 … … 9456 9464 StyleRuleKeyframes* rulePtr = rule.get(); 9457 9465 m_parsedRules.append(rule.release()); 9466 processAndAddNewRuleToSourceTreeIfNeeded(); 9458 9467 return rulePtr; 9459 9468 } … … 9462 9471 { 9463 9472 StyleRule* result = 0; 9464 markRuleBodyEnd();9465 9473 if (selectors) { 9466 9474 m_allowImportRules = m_allowNamespaceDeclarations = false; … … 9472 9480 result = rule.get(); 9473 9481 m_parsedRules.append(rule.release()); 9474 if (isExtractingSourceData()) { 9475 RefPtr<CSSRuleSourceData> currentRuleData = popRuleData(); 9476 currentRuleData->styleSourceData->styleBodyRange = m_ruleBodyRange; 9477 currentRuleData->selectorListRange = m_selectorListRange; 9478 fixUnparsedPropertyRanges(currentRuleData.get()); 9479 addNewRuleToSourceTree(currentRuleData.release()); 9480 m_inStyleRuleOrDeclaration = false; 9481 } 9482 } 9483 if (isExtractingSourceData()) { 9484 resetSelectorListMarks(); 9485 resetRuleBodyMarks(); 9482 processAndAddNewRuleToSourceTreeIfNeeded(); 9486 9483 } 9487 9484 clearProperties(); … … 9510 9507 StyleRuleFontFace* result = rule.get(); 9511 9508 m_parsedRules.append(rule.release()); 9509 processAndAddNewRuleToSourceTreeIfNeeded(); 9512 9510 return result; 9513 9511 } … … 9589 9587 pageRule = rule.get(); 9590 9588 m_parsedRules.append(rule.release()); 9589 processAndAddNewRuleToSourceTreeIfNeeded(); 9591 9590 } 9592 9591 clearProperties(); … … 9611 9610 StyleRuleRegion* result = regionRule.get(); 9612 9611 m_parsedRules.append(regionRule.release()); 9612 if (isExtractingSourceData()) 9613 addNewRuleToSourceTree(CSSRuleSourceData::createUnknown()); 9613 9614 9614 9615 return result; … … 9692 9693 void CSSParser::fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData) 9693 9694 { 9695 if (!ruleData->styleSourceData) 9696 return; 9694 9697 Vector<CSSPropertySourceData>& propertyData = ruleData->styleSourceData->propertyData; 9695 9698 unsigned size = propertyData.size(); … … 9697 9700 return; 9698 9701 9699 unsigned styleStart = ruleData-> styleSourceData->styleBodyRange.start;9702 unsigned styleStart = ruleData->ruleBodyRange.start; 9700 9703 const UChar* characters = m_dataStart.get() + m_parsedTextPrefixLength; 9701 9704 CSSPropertySourceData* nextData = &(propertyData.at(0)); … … 9711 9714 unsigned propertyEndInStyleSheet; 9712 9715 if (!nextData) 9713 propertyEndInStyleSheet = ruleData-> styleSourceData->styleBodyRange.end - 1;9716 propertyEndInStyleSheet = ruleData->ruleBodyRange.end - 1; 9714 9717 else 9715 9718 propertyEndInStyleSheet = styleStart + nextData->range.start - 1; … … 9735 9738 } 9736 9739 9737 void CSSParser::mark SelectorListStart()9740 void CSSParser::markRuleHeaderStart(CSSRuleSourceData::Type ruleType) 9738 9741 { 9739 9742 if (!isExtractingSourceData()) 9740 9743 return; 9741 m_selectorListRange.start = m_tokenStart - m_dataStart.get(); 9742 } 9743 9744 void CSSParser::markSelectorListEnd() 9744 RefPtr<CSSRuleSourceData> data = CSSRuleSourceData::create(ruleType); 9745 data->ruleHeaderRange.start = m_tokenStart - m_dataStart.get(); 9746 m_currentRuleDataStack->append(data.release()); 9747 } 9748 9749 void CSSParser::markRuleHeaderEnd() 9745 9750 { 9746 9751 if (!isExtractingSourceData()) 9747 9752 return; 9753 ASSERT(!m_currentRuleDataStack->isEmpty()); 9748 9754 UChar* listEnd = m_tokenStart; 9749 9755 while (listEnd > m_dataStart.get() + 1) { … … 9753 9759 break; 9754 9760 } 9755 m_selectorListRange.end = listEnd - m_dataStart.get(); 9756 RefPtr<CSSRuleSourceData> data = CSSRuleSourceData::create(); 9757 data->styleSourceData = CSSStyleSourceData::create(); 9758 m_currentRuleDataStack->append(data); 9761 m_currentRuleDataStack->last()->ruleHeaderRange.end = listEnd - m_dataStart.get(); 9759 9762 } 9760 9763 … … 9766 9769 if (*m_tokenStart == '{') 9767 9770 ++offset; // Skip the rule body opening brace. 9768 if (offset > m_ruleBodyRange.start) 9769 m_ruleBodyRange.start = offset; 9770 m_inStyleRuleOrDeclaration = true; 9771 ASSERT(!m_currentRuleDataStack->isEmpty()); 9772 m_currentRuleDataStack->last()->ruleBodyRange.start = offset; 9771 9773 } 9772 9774 9773 9775 void CSSParser::markRuleBodyEnd() 9776 { 9777 // Precondition: (!isExtractingSourceData()) 9778 unsigned offset = m_tokenStart - m_dataStart.get(); 9779 ASSERT(!m_currentRuleDataStack->isEmpty()); 9780 m_currentRuleDataStack->last()->ruleBodyRange.end = offset; 9781 } 9782 9783 void CSSParser::markPropertyStart() 9774 9784 { 9775 9785 if (!isExtractingSourceData()) 9776 9786 return; 9777 unsigned offset = m_tokenStart - m_dataStart.get(); 9778 if (offset > m_ruleBodyRange.end) 9779 m_ruleBodyRange.end = offset; 9780 } 9781 9782 void CSSParser::markPropertyStart() 9783 { 9784 if (!m_inStyleRuleOrDeclaration) 9787 if (m_currentRuleDataStack->isEmpty() || !m_currentRuleDataStack->last()->styleSourceData) 9785 9788 return; 9789 9786 9790 m_propertyRange.start = m_tokenStart - m_dataStart.get(); 9787 9791 } … … 9789 9793 void CSSParser::markPropertyEnd(bool isImportantFound, bool isPropertyParsed) 9790 9794 { 9791 if (!m_inStyleRuleOrDeclaration) 9795 if (!isExtractingSourceData()) 9796 return; 9797 if (m_currentRuleDataStack->isEmpty() || !m_currentRuleDataStack->last()->styleSourceData) 9792 9798 return; 9793 9799 … … 9810 9816 String value = propertyString.substring(colonIndex + 1, propertyString.length()).stripWhiteSpace(); 9811 9817 // The property range is relative to the declaration start offset. 9818 SourceRange& topRuleBodyRange = m_currentRuleDataStack->last()->ruleBodyRange; 9812 9819 m_currentRuleDataStack->last()->styleSourceData->propertyData.append( 9813 CSSPropertySourceData(name, value, isImportantFound, isPropertyParsed, SourceRange(start - m_ruleBodyRange.start, end - m_ruleBodyRange.start)));9820 CSSPropertySourceData(name, value, isImportantFound, isPropertyParsed, SourceRange(start - topRuleBodyRange.start, end - topRuleBodyRange.start))); 9814 9821 } 9815 9822 resetPropertyRange(); -
trunk/Source/WebCore/css/CSSParser.h
r121531 r121551 79 79 static PassRefPtr<CSSValueList> parseFontFaceValue(const AtomicString&); 80 80 PassRefPtr<CSSPrimitiveValue> parseValidPrimitive(int ident, CSSParserValue*); 81 bool parseDeclaration(StylePropertySet*, const String&, PassRefPtr<CSS StyleSourceData>, StyleSheetContents* contextStyleSheet);81 bool parseDeclaration(StylePropertySet*, const String&, PassRefPtr<CSSRuleSourceData>, StyleSheetContents* contextStyleSheet); 82 82 PassOwnPtr<MediaQuery> parseMediaQuery(const String&); 83 83 … … 325 325 // tokenizer methods and data 326 326 size_t m_parsedTextPrefixLength; 327 bool m_inStyleRuleOrDeclaration;328 SourceRange m_selectorListRange;329 SourceRange m_ruleBodyRange;330 327 SourceRange m_propertyRange; 331 328 OwnPtr<RuleSourceDataList> m_currentRuleDataStack; … … 333 330 334 331 void fixUnparsedPropertyRanges(CSSRuleSourceData*); 335 void mark StyleRuleHeaderStart();332 void markRuleHeaderStart(CSSRuleSourceData::Type); 336 333 void markRuleHeaderEnd(); 337 338 void markSelectorListStart();339 void markSelectorListEnd();340 334 void markRuleBodyStart(); 341 335 void markRuleBodyEnd(); 342 336 void markPropertyStart(); 343 337 void markPropertyEnd(bool isImportantFound, bool isPropertyParsed); 338 void processAndAddNewRuleToSourceTreeIfNeeded(); 344 339 void addNewRuleToSourceTree(PassRefPtr<CSSRuleSourceData>); 345 340 PassRefPtr<CSSRuleSourceData> popRuleData(); 346 void resetSelectorListMarks() { m_selectorListRange.start = m_selectorListRange.end = 0; }347 void resetRuleBodyMarks() { m_ruleBodyRange.start = m_ruleBodyRange.end = 0; }348 341 void resetPropertyRange() { m_propertyRange.start = m_propertyRange.end = UINT_MAX; } 349 342 bool isExtractingSourceData() const { return !!m_currentRuleDataStack; } -
trunk/Source/WebCore/css/CSSPropertySourceData.h
r120474 r121551 41 41 namespace WebCore { 42 42 43 class StyleRule ;43 class StyleRuleBase; 44 44 45 45 struct SourceRange { … … 79 79 } 80 80 81 // Range of the style text in the enclosing source.82 SourceRange styleBodyRange;83 81 Vector<CSSPropertySourceData> propertyData; 84 82 }; … … 88 86 89 87 struct CSSRuleSourceData : public RefCounted<CSSRuleSourceData> { 90 static PassRefPtr<CSSRuleSourceData> create() 88 enum Type { 89 UNKNOWN_RULE, 90 STYLE_RULE, 91 CHARSET_RULE, 92 IMPORT_RULE, 93 MEDIA_RULE, 94 FONT_FACE_RULE, 95 PAGE_RULE, 96 KEYFRAMES_RULE 97 }; 98 99 static PassRefPtr<CSSRuleSourceData> create(Type type) 91 100 { 92 return adoptRef(new CSSRuleSourceData( ));101 return adoptRef(new CSSRuleSourceData(type)); 93 102 } 94 103 104 static PassRefPtr<CSSRuleSourceData> createUnknown() 105 { 106 return adoptRef(new CSSRuleSourceData(UNKNOWN_RULE)); 107 } 108 109 CSSRuleSourceData(Type type) 110 : type(type) 111 { 112 if (type == STYLE_RULE || type == FONT_FACE_RULE || type == PAGE_RULE) 113 styleSourceData = CSSStyleSourceData::create(); 114 } 115 116 Type type; 117 95 118 // Range of the selector list in the enclosing source. 96 SourceRange selectorListRange; 119 SourceRange ruleHeaderRange; 120 121 // Range of the rule body (e.g. style text for style rules) in the enclosing source. 122 SourceRange ruleBodyRange; 123 124 // Only for CSSStyleRules, CSSFontFaceRules, and CSSPageRules. 97 125 RefPtr<CSSStyleSourceData> styleSourceData; 126 127 // Only for CSSMediaRules. 128 RuleSourceDataList childRules; 98 129 }; 99 typedef HashMap<StyleRule*, RefPtr<CSSRuleSourceData> > StyleRuleRangeMap;100 130 101 131 } // namespace WebCore -
trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp
r120469 r121551 51 51 #include "StyleResolver.h" 52 52 #include "StyleRule.h" 53 #include "StyleRuleImport.h" 53 54 #include "StyleSheetContents.h" 54 55 #include "StyleSheetList.h" … … 62 63 using WebCore::TypeBuilder::Array; 63 64 using WebCore::RuleSourceDataList; 65 using WebCore::CSSRuleSourceData; 64 66 65 67 class ParsedStyleSheet { … … 74 76 void setSourceData(PassOwnPtr<RuleSourceDataList>); 75 77 bool hasSourceData() const { return m_sourceData; } 76 RefPtr<WebCore::CSSRuleSourceData> ruleSourceDataAt(unsigned index) const;78 PassRefPtr<WebCore::CSSRuleSourceData> ruleSourceDataAt(unsigned) const; 77 79 78 80 private: … … 98 100 } 99 101 102 static void flattenSourceData(RuleSourceDataList* dataList, RuleSourceDataList* target) 103 { 104 for (size_t i = 0; i < dataList->size(); ++i) { 105 RefPtr<CSSRuleSourceData>& data = dataList->at(i); 106 if (data->type == CSSRuleSourceData::STYLE_RULE) 107 target->append(data); 108 else if (data->type == CSSRuleSourceData::MEDIA_RULE) 109 flattenSourceData(&data->childRules, target); 110 } 111 } 112 100 113 void ParsedStyleSheet::setSourceData(PassOwnPtr<RuleSourceDataList> sourceData) 101 114 { 102 m_sourceData = sourceData; 103 } 104 105 RefPtr<WebCore::CSSRuleSourceData> ParsedStyleSheet::ruleSourceDataAt(unsigned index) const 115 if (!sourceData) { 116 m_sourceData.clear(); 117 return; 118 } 119 120 m_sourceData = adoptPtr(new RuleSourceDataList()); 121 122 // FIXME: This is a temporary solution to retain the original flat sourceData structure 123 // containing only style rules, even though CSSParser now provides the full rule source data tree. 124 // Normally, we should just assign m_sourceData = sourceData; 125 flattenSourceData(sourceData.get(), m_sourceData.get()); 126 } 127 128 PassRefPtr<WebCore::CSSRuleSourceData> ParsedStyleSheet::ruleSourceDataAt(unsigned index) const 106 129 { 107 130 if (!hasSourceData() || index >= m_sourceData->size()) … … 272 295 RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet ? m_parentStyleSheet->ruleSourceDataFor(m_style.get()) : 0; 273 296 if (sourceData) 274 result->setRange(buildSourceRangeObject(sourceData-> styleSourceData->styleBodyRange));297 result->setRange(buildSourceRangeObject(sourceData->ruleBodyRange)); 275 298 276 299 return result.release(); … … 315 338 if (propertyText.stripWhiteSpace().length()) { 316 339 RefPtr<StylePropertySet> tempMutableStyle = StylePropertySet::create(); 317 RefPtr<CSS StyleSourceData> sourceData = CSSStyleSourceData::create();340 RefPtr<CSSRuleSourceData> sourceData = CSSRuleSourceData::create(CSSRuleSourceData::STYLE_RULE); 318 341 CSSParser p(CSSStrictMode); 319 342 p.parseDeclaration(tempMutableStyle.get(), propertyText + " " + bogusPropertyName + ": none", sourceData, m_style->parentStyleSheet()->contents()); 320 Vector<CSSPropertySourceData>& propertyData = sourceData-> propertyData;343 Vector<CSSPropertySourceData>& propertyData = sourceData->styleSourceData->propertyData; 321 344 unsigned propertyCount = propertyData.size(); 322 345 … … 356 379 editor.replaceProperty(index, propertyText); 357 380 } else 358 editor.insertProperty(index, propertyText, sourceData-> styleSourceData->styleBodyRange.length());381 editor.insertProperty(index, propertyText, sourceData->ruleBodyRange.length()); 359 382 360 383 return applyStyleText(editor.styleText()); … … 414 437 return false; 415 438 416 SourceRange& bodyRange = sourceData-> styleSourceData->styleBodyRange;439 SourceRange& bodyRange = sourceData->ruleBodyRange; 417 440 *result = styleSheetText.substring(bodyRange.start, bodyRange.end - bodyRange.start); 418 441 return true; … … 772 795 773 796 String sheetText = m_parsedStyleSheet->text(); 774 sheetText.replace(sourceData-> selectorListRange.start, sourceData->selectorListRange.end - sourceData->selectorListRange.start, selector);797 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderRange.length(), selector); 775 798 m_parsedStyleSheet->setText(sheetText); 776 799 fireStyleSheetChanged(); … … 831 854 832 855 String sheetText = m_parsedStyleSheet->text(); 833 sheetText.remove(sourceData-> selectorListRange.start, sourceData->styleSourceData->styleBodyRange.end - sourceData->selectorListRange.start + 1);856 sheetText.remove(sourceData->ruleHeaderRange.start, sourceData->ruleBodyRange.end - sourceData->ruleHeaderRange.start + 1); 834 857 m_parsedStyleSheet->setText(sheetText); 835 858 fireStyleSheetChanged(); … … 912 935 if (ensureParsedDataReady()) 913 936 sourceData = ruleSourceDataFor(rule->style()); 914 if (sourceData) { 915 RefPtr<TypeBuilder::CSS::SourceRange> selectorRange = TypeBuilder::CSS::SourceRange::create() 916 .setStart(sourceData->selectorListRange.start) 917 .setEnd(sourceData->selectorListRange.end); 918 result->setSelectorRange(selectorRange.release()); 919 } 937 if (sourceData) 938 result->setSelectorRange(buildSourceRangeObject(sourceData->ruleHeaderRange)); 920 939 921 940 RefPtr<Array<TypeBuilder::CSS::CSSMedia> > mediaArray = Array<TypeBuilder::CSS::CSSMedia>::create(); … … 949 968 bool success = getText(&sheetText); 950 969 if (success) { 951 const SourceRange& bodyRange = sourceData-> styleSourceData->styleBodyRange;970 const SourceRange& bodyRange = sourceData->ruleBodyRange; 952 971 result->setCssText(sheetText.substring(bodyRange.start, bodyRange.end - bodyRange.start)); 953 972 } … … 1099 1118 RefPtr<StyleSheetContents> newStyleSheet = StyleSheetContents::create(); 1100 1119 CSSParser p(CSSStrictMode); 1101 OwnPtr<RuleSourceDataList> r angesVector(adoptPtr(new RuleSourceDataList()));1102 p.parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), 0, r angesVector.get());1103 m_parsedStyleSheet->setSourceData(r angesVector.release());1120 OwnPtr<RuleSourceDataList> ruleSourceDataResult = adoptPtr(new RuleSourceDataList()); 1121 p.parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), 0, ruleSourceDataResult.get()); 1122 m_parsedStyleSheet->setSourceData(ruleSourceDataResult.release()); 1104 1123 return m_parsedStyleSheet->hasSourceData(); 1105 1124 } … … 1145 1164 1146 1165 RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(style); 1147 unsigned bodyStart = sourceData-> styleSourceData->styleBodyRange.start;1148 unsigned bodyEnd = sourceData-> styleSourceData->styleBodyRange.end;1166 unsigned bodyStart = sourceData->ruleBodyRange.start; 1167 unsigned bodyEnd = sourceData->ruleBodyRange.end; 1149 1168 ASSERT(bodyStart <= bodyEnd); 1150 1169 … … 1327 1346 return true; 1328 1347 1329 m_ruleSourceData = CSSRuleSourceData::create(); 1330 RefPtr<CSSStyleSourceData> sourceData = CSSStyleSourceData::create(); 1331 bool success = getStyleAttributeRanges(&sourceData); 1348 m_ruleSourceData = CSSRuleSourceData::create(CSSRuleSourceData::STYLE_RULE); 1349 bool success = getStyleAttributeRanges(m_ruleSourceData.get()); 1332 1350 if (!success) 1333 1351 return false; 1334 1352 1335 m_ruleSourceData->styleSourceData = sourceData.release();1336 1353 return true; 1337 1354 } … … 1353 1370 } 1354 1371 1355 bool InspectorStyleSheetForInlineStyle::getStyleAttributeRanges( RefPtr<CSSStyleSourceData>* result) const1372 bool InspectorStyleSheetForInlineStyle::getStyleAttributeRanges(CSSRuleSourceData* result) const 1356 1373 { 1357 1374 if (!m_element->isStyledElement()) … … 1359 1376 1360 1377 if (m_styleText.isEmpty()) { 1361 (*result)->styleBodyRange.start = 0;1362 (*result)->styleBodyRange.end = 0;1378 result->ruleBodyRange.start = 0; 1379 result->ruleBodyRange.end = 0; 1363 1380 return true; 1364 1381 } … … 1366 1383 RefPtr<StylePropertySet> tempDeclaration = StylePropertySet::create(); 1367 1384 CSSParser p(m_element->document()); 1368 p.parseDeclaration(tempDeclaration.get(), m_styleText, *result, m_element->document()->elementSheet()->contents());1385 p.parseDeclaration(tempDeclaration.get(), m_styleText, result, m_element->document()->elementSheet()->contents()); 1369 1386 return true; 1370 1387 } -
trunk/Source/WebCore/inspector/InspectorStyleSheet.h
r120469 r121551 273 273 CSSStyleDeclaration* inlineStyle() const; 274 274 const String& elementStyleText() const; 275 bool getStyleAttributeRanges( RefPtr<CSSStyleSourceData>* result) const;275 bool getStyleAttributeRanges(CSSRuleSourceData* result) const; 276 276 277 277 RefPtr<Element> m_element;
Note:
See TracChangeset
for help on using the changeset viewer.