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

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

Issue 1219713003: DevTools: [regression] compare canonical text when matching styles. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: awesome review comment addressed. Created 5 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « LayoutTests/inspector-protocol/css/css-set-style-text-expected.txt ('k') | no next file » | 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 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 } 592 }
593 593
594 for (int i = 0; i < n; ++i) { 594 for (int i = 0; i < n; ++i) {
595 delete [] diff[i]; 595 delete [] diff[i];
596 delete [] backtrack[i]; 596 delete [] backtrack[i];
597 } 597 }
598 delete [] diff; 598 delete [] diff;
599 delete [] backtrack; 599 delete [] backtrack;
600 } 600 }
601 601
602 String canonicalCSSText(RefPtrWillBeRawPtr<CSSRule> rule)
603 {
604 if (rule->type() != CSSRule::STYLE_RULE)
605 return rule->cssText();
606 RefPtr<CSSStyleRule> styleRule = toCSSStyleRule(rule.get());
607
608 Vector<String> propertyNames;
609 HashSet<String> propertyNameSet;
610 CSSStyleDeclaration* style = styleRule->style();
611 for (unsigned i = 0; i < style->length(); ++i) {
612 String name = style->item(i);
613 String shorthand = style->getPropertyShorthand(name);
614 if (!shorthand.isEmpty())
615 name = shorthand;
616 if (propertyNameSet.contains(name))
617 continue;
618 propertyNames.append(name);
619 propertyNameSet.add(name);
620 }
621 std::sort(propertyNames.begin(), propertyNames.end(), WTF::codePointCompareL essThan);
622
623 StringBuilder builder;
624 builder.append(styleRule->selectorText());
625 builder.append("{");
626 for (unsigned i = 0; i < propertyNames.size(); ++i) {
627 String name = propertyNames.at(i);
628 builder.append(" ");
629 builder.append(name);
630 builder.append(":");
631 builder.append(style->getPropertyValue(name));
632 if (!style->getPropertyPriority(name).isEmpty()) {
633 builder.append(" ");
634 builder.append(style->getPropertyPriority(name));
635 }
636 builder.append(";");
637 }
638 builder.append("}");
639
640 return builder.toString();
641 }
642
602 } // namespace 643 } // namespace
603 644
604 namespace blink { 645 namespace blink {
605 646
606 enum MediaListSource { 647 enum MediaListSource {
607 MediaListSourceLinkedSheet, 648 MediaListSourceLinkedSheet,
608 MediaListSourceInlineSheet, 649 MediaListSourceInlineSheet,
609 MediaListSourceMediaRule, 650 MediaListSourceMediaRule,
610 MediaListSourceImportRule 651 MediaListSourceImportRule
611 }; 652 };
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 if (index == kNotFound) 1515 if (index == kNotFound)
1475 return nullptr; 1516 return nullptr;
1476 IndexMap::iterator it = m_sourceDataToRule.find(index); 1517 IndexMap::iterator it = m_sourceDataToRule.find(index);
1477 if (it == m_sourceDataToRule.end()) 1518 if (it == m_sourceDataToRule.end())
1478 return nullptr; 1519 return nullptr;
1479 1520
1480 ASSERT(it->value < m_cssomFlatRules.size()); 1521 ASSERT(it->value < m_cssomFlatRules.size());
1481 1522
1482 // Check that CSSOM did not mutate this rule. 1523 // Check that CSSOM did not mutate this rule.
1483 RefPtrWillBeRawPtr<CSSRule> result = m_cssomFlatRules.at(it->value); 1524 RefPtrWillBeRawPtr<CSSRule> result = m_cssomFlatRules.at(it->value);
1484 if (m_parsedFlatRules.at(index)->cssText() != result->cssText()) 1525 if (canonicalCSSText(m_parsedFlatRules.at(index)) != canonicalCSSText(result ))
1485 return nullptr; 1526 return nullptr;
1486 return result; 1527 return result;
1487 } 1528 }
1488 1529
1489 RefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheet::sourceDataForRule(Ref PtrWillBeRawPtr<CSSRule> rule) 1530 RefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheet::sourceDataForRule(Ref PtrWillBeRawPtr<CSSRule> rule)
1490 { 1531 {
1491 if (!m_sourceData || !rule) 1532 if (!m_sourceData || !rule)
1492 return nullptr; 1533 return nullptr;
1493 1534
1494 remapSourceDataToCSSOMIfNecessary(); 1535 remapSourceDataToCSSOMIfNecessary();
1495 1536
1496 size_t index = m_cssomFlatRules.find(rule.get()); 1537 size_t index = m_cssomFlatRules.find(rule.get());
1497 if (index == kNotFound) 1538 if (index == kNotFound)
1498 return nullptr; 1539 return nullptr;
1499 IndexMap::iterator it = m_ruleToSourceData.find(index); 1540 IndexMap::iterator it = m_ruleToSourceData.find(index);
1500 if (it == m_ruleToSourceData.end()) 1541 if (it == m_ruleToSourceData.end())
1501 return nullptr; 1542 return nullptr;
1502 1543
1503 ASSERT(it->value < m_sourceData->size()); 1544 ASSERT(it->value < m_sourceData->size());
1504 1545
1505 // Check that CSSOM did not mutate this rule. 1546 // Check that CSSOM did not mutate this rule.
1506 RefPtrWillBeRawPtr<CSSRule> parsedRule = m_parsedFlatRules.at(it->value); 1547 RefPtrWillBeRawPtr<CSSRule> parsedRule = m_parsedFlatRules.at(it->value);
1507 if (rule->cssText() != parsedRule->cssText()) 1548 if (canonicalCSSText(rule) != canonicalCSSText(parsedRule))
1508 return nullptr; 1549 return nullptr;
1509 1550
1510 return m_sourceData->at(it->value); 1551 return m_sourceData->at(it->value);
1511 } 1552 }
1512 1553
1513 void InspectorStyleSheet::remapSourceDataToCSSOMIfNecessary() 1554 void InspectorStyleSheet::remapSourceDataToCSSOMIfNecessary()
1514 { 1555 {
1515 CSSRuleVector cssomRules; 1556 CSSRuleVector cssomRules;
1516 collectFlatRules(m_pageStyleSheet.get(), &cssomRules); 1557 collectFlatRules(m_pageStyleSheet.get(), &cssomRules);
1517 1558
(...skipping 20 matching lines...) Expand all
1538 collectFlatRules(m_pageStyleSheet.get(), &cssomRules); 1579 collectFlatRules(m_pageStyleSheet.get(), &cssomRules);
1539 1580
1540 if (!m_sourceData) 1581 if (!m_sourceData)
1541 return; 1582 return;
1542 1583
1543 CSSRuleVector& parsedRules = m_parsedFlatRules; 1584 CSSRuleVector& parsedRules = m_parsedFlatRules;
1544 1585
1545 Vector<String> cssomRulesText = Vector<String>(); 1586 Vector<String> cssomRulesText = Vector<String>();
1546 Vector<String> parsedRulesText = Vector<String>(); 1587 Vector<String> parsedRulesText = Vector<String>();
1547 for (size_t i = 0; i < cssomRules.size(); ++i) 1588 for (size_t i = 0; i < cssomRules.size(); ++i)
1548 cssomRulesText.append(cssomRules.at(i)->cssText()); 1589 cssomRulesText.append(canonicalCSSText(cssomRules.at(i)));
1549 for (size_t j = 0; j < parsedRules.size(); ++j) 1590 for (size_t j = 0; j < parsedRules.size(); ++j)
1550 parsedRulesText.append(parsedRules.at(j)->cssText()); 1591 parsedRulesText.append(canonicalCSSText(parsedRules.at(j)));
1551 1592
1552 diff(cssomRulesText, parsedRulesText, &m_ruleToSourceData, &m_sourceDataToRu le); 1593 diff(cssomRulesText, parsedRulesText, &m_ruleToSourceData, &m_sourceDataToRu le);
1553 } 1594 }
1554 1595
1555 const CSSRuleVector& InspectorStyleSheet::flatRules() 1596 const CSSRuleVector& InspectorStyleSheet::flatRules()
1556 { 1597 {
1557 remapSourceDataToCSSOMIfNecessary(); 1598 remapSourceDataToCSSOMIfNecessary();
1558 return m_cssomFlatRules; 1599 return m_cssomFlatRules;
1559 } 1600 }
1560 1601
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 } 1709 }
1669 1710
1670 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) 1711 DEFINE_TRACE(InspectorStyleSheetForInlineStyle)
1671 { 1712 {
1672 visitor->trace(m_element); 1713 visitor->trace(m_element);
1673 visitor->trace(m_inspectorStyle); 1714 visitor->trace(m_inspectorStyle);
1674 InspectorStyleSheetBase::trace(visitor); 1715 InspectorStyleSheetBase::trace(visitor);
1675 } 1716 }
1676 1717
1677 } // namespace blink 1718 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/inspector-protocol/css/css-set-style-text-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698