Chromium Code Reviews| 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 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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) | |
|
lushnikov
2015/07/01 08:36:26
nit
RefPtr<CSSStyleRule> styleRule = toCSSStyleRu
| |
| 605 return rule->cssText(); | |
| 606 | |
| 607 Vector<String> propertyNames; | |
| 608 HashSet<String> propertyNameSet; | |
| 609 CSSStyleDeclaration* style = toCSSStyleRule(rule.get())->style(); | |
| 610 for (unsigned i = 0; i < style->length(); ++i) { | |
| 611 String name = style->item(i); | |
| 612 String shorthand = style->getPropertyShorthand(name); | |
| 613 if (!shorthand.isEmpty()) | |
| 614 name = shorthand; | |
| 615 if (propertyNameSet.contains(name)) | |
| 616 continue; | |
| 617 propertyNames.append(name); | |
| 618 propertyNameSet.add(name); | |
| 619 } | |
| 620 std::sort(propertyNames.begin(), propertyNames.end(), WTF::codePointCompareL essThan); | |
| 621 | |
| 622 StringBuilder builder; | |
| 623 builder.append(toCSSStyleRule(rule.get())->selectorText()); | |
| 624 builder.append("{"); | |
| 625 for (unsigned i = 0; i < propertyNames.size(); ++i) { | |
| 626 String name = propertyNames.at(i); | |
| 627 builder.append(" "); | |
| 628 builder.append(name); | |
| 629 builder.append(":"); | |
| 630 builder.append(style->getPropertyValue(name)); | |
| 631 if (!style->getPropertyPriority(name).isEmpty()) { | |
| 632 builder.append(" "); | |
| 633 builder.append(style->getPropertyPriority(name)); | |
| 634 } | |
| 635 builder.append(";"); | |
| 636 } | |
| 637 builder.append("}"); | |
| 638 | |
| 639 return builder.toString(); | |
| 640 } | |
| 641 | |
| 602 } // namespace | 642 } // namespace |
| 603 | 643 |
| 604 namespace blink { | 644 namespace blink { |
| 605 | 645 |
| 606 enum MediaListSource { | 646 enum MediaListSource { |
| 607 MediaListSourceLinkedSheet, | 647 MediaListSourceLinkedSheet, |
| 608 MediaListSourceInlineSheet, | 648 MediaListSourceInlineSheet, |
| 609 MediaListSourceMediaRule, | 649 MediaListSourceMediaRule, |
| 610 MediaListSourceImportRule | 650 MediaListSourceImportRule |
| 611 }; | 651 }; |
| (...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1474 if (index == kNotFound) | 1514 if (index == kNotFound) |
| 1475 return nullptr; | 1515 return nullptr; |
| 1476 IndexMap::iterator it = m_sourceDataToRule.find(index); | 1516 IndexMap::iterator it = m_sourceDataToRule.find(index); |
| 1477 if (it == m_sourceDataToRule.end()) | 1517 if (it == m_sourceDataToRule.end()) |
| 1478 return nullptr; | 1518 return nullptr; |
| 1479 | 1519 |
| 1480 ASSERT(it->value < m_cssomFlatRules.size()); | 1520 ASSERT(it->value < m_cssomFlatRules.size()); |
| 1481 | 1521 |
| 1482 // Check that CSSOM did not mutate this rule. | 1522 // Check that CSSOM did not mutate this rule. |
| 1483 RefPtrWillBeRawPtr<CSSRule> result = m_cssomFlatRules.at(it->value); | 1523 RefPtrWillBeRawPtr<CSSRule> result = m_cssomFlatRules.at(it->value); |
| 1484 if (m_parsedFlatRules.at(index)->cssText() != result->cssText()) | 1524 if (canonicalCSSText(m_parsedFlatRules.at(index)) != canonicalCSSText(result )) |
| 1485 return nullptr; | 1525 return nullptr; |
| 1486 return result; | 1526 return result; |
| 1487 } | 1527 } |
| 1488 | 1528 |
| 1489 RefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheet::sourceDataForRule(Ref PtrWillBeRawPtr<CSSRule> rule) | 1529 RefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheet::sourceDataForRule(Ref PtrWillBeRawPtr<CSSRule> rule) |
| 1490 { | 1530 { |
| 1491 if (!m_sourceData || !rule) | 1531 if (!m_sourceData || !rule) |
| 1492 return nullptr; | 1532 return nullptr; |
| 1493 | 1533 |
| 1494 remapSourceDataToCSSOMIfNecessary(); | 1534 remapSourceDataToCSSOMIfNecessary(); |
| 1495 | 1535 |
| 1496 size_t index = m_cssomFlatRules.find(rule.get()); | 1536 size_t index = m_cssomFlatRules.find(rule.get()); |
| 1497 if (index == kNotFound) | 1537 if (index == kNotFound) |
| 1498 return nullptr; | 1538 return nullptr; |
| 1499 IndexMap::iterator it = m_ruleToSourceData.find(index); | 1539 IndexMap::iterator it = m_ruleToSourceData.find(index); |
| 1500 if (it == m_ruleToSourceData.end()) | 1540 if (it == m_ruleToSourceData.end()) |
| 1501 return nullptr; | 1541 return nullptr; |
| 1502 | 1542 |
| 1503 ASSERT(it->value < m_sourceData->size()); | 1543 ASSERT(it->value < m_sourceData->size()); |
| 1504 | 1544 |
| 1505 // Check that CSSOM did not mutate this rule. | 1545 // Check that CSSOM did not mutate this rule. |
| 1506 RefPtrWillBeRawPtr<CSSRule> parsedRule = m_parsedFlatRules.at(it->value); | 1546 RefPtrWillBeRawPtr<CSSRule> parsedRule = m_parsedFlatRules.at(it->value); |
| 1507 if (rule->cssText() != parsedRule->cssText()) | 1547 if (canonicalCSSText(rule) != canonicalCSSText(parsedRule)) |
| 1508 return nullptr; | 1548 return nullptr; |
| 1509 | 1549 |
| 1510 return m_sourceData->at(it->value); | 1550 return m_sourceData->at(it->value); |
| 1511 } | 1551 } |
| 1512 | 1552 |
| 1513 void InspectorStyleSheet::remapSourceDataToCSSOMIfNecessary() | 1553 void InspectorStyleSheet::remapSourceDataToCSSOMIfNecessary() |
| 1514 { | 1554 { |
| 1515 CSSRuleVector cssomRules; | 1555 CSSRuleVector cssomRules; |
| 1516 collectFlatRules(m_pageStyleSheet.get(), &cssomRules); | 1556 collectFlatRules(m_pageStyleSheet.get(), &cssomRules); |
| 1517 | 1557 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1538 collectFlatRules(m_pageStyleSheet.get(), &cssomRules); | 1578 collectFlatRules(m_pageStyleSheet.get(), &cssomRules); |
| 1539 | 1579 |
| 1540 if (!m_sourceData) | 1580 if (!m_sourceData) |
| 1541 return; | 1581 return; |
| 1542 | 1582 |
| 1543 CSSRuleVector& parsedRules = m_parsedFlatRules; | 1583 CSSRuleVector& parsedRules = m_parsedFlatRules; |
| 1544 | 1584 |
| 1545 Vector<String> cssomRulesText = Vector<String>(); | 1585 Vector<String> cssomRulesText = Vector<String>(); |
| 1546 Vector<String> parsedRulesText = Vector<String>(); | 1586 Vector<String> parsedRulesText = Vector<String>(); |
| 1547 for (size_t i = 0; i < cssomRules.size(); ++i) | 1587 for (size_t i = 0; i < cssomRules.size(); ++i) |
| 1548 cssomRulesText.append(cssomRules.at(i)->cssText()); | 1588 cssomRulesText.append(canonicalCSSText(cssomRules.at(i))); |
| 1549 for (size_t j = 0; j < parsedRules.size(); ++j) | 1589 for (size_t j = 0; j < parsedRules.size(); ++j) |
| 1550 parsedRulesText.append(parsedRules.at(j)->cssText()); | 1590 parsedRulesText.append(canonicalCSSText(parsedRules.at(j))); |
| 1551 | 1591 |
| 1552 diff(cssomRulesText, parsedRulesText, &m_ruleToSourceData, &m_sourceDataToRu le); | 1592 diff(cssomRulesText, parsedRulesText, &m_ruleToSourceData, &m_sourceDataToRu le); |
| 1553 } | 1593 } |
| 1554 | 1594 |
| 1555 const CSSRuleVector& InspectorStyleSheet::flatRules() | 1595 const CSSRuleVector& InspectorStyleSheet::flatRules() |
| 1556 { | 1596 { |
| 1557 remapSourceDataToCSSOMIfNecessary(); | 1597 remapSourceDataToCSSOMIfNecessary(); |
| 1558 return m_cssomFlatRules; | 1598 return m_cssomFlatRules; |
| 1559 } | 1599 } |
| 1560 | 1600 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1668 } | 1708 } |
| 1669 | 1709 |
| 1670 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) | 1710 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) |
| 1671 { | 1711 { |
| 1672 visitor->trace(m_element); | 1712 visitor->trace(m_element); |
| 1673 visitor->trace(m_inspectorStyle); | 1713 visitor->trace(m_inspectorStyle); |
| 1674 InspectorStyleSheetBase::trace(visitor); | 1714 InspectorStyleSheetBase::trace(visitor); |
| 1675 } | 1715 } |
| 1676 | 1716 |
| 1677 } // namespace blink | 1717 } // namespace blink |
| OLD | NEW |