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

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

Issue 2759703003: DevTools: add support for polling for coverage data in CSS agent (Closed)
Patch Set: moved ranges sorting so it also works for CSS ranges Created 3 years, 8 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
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 1496 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 .build(); 1507 .build();
1508 } 1508 }
1509 1509
1510 static bool canBind(const String& origin) { 1510 static bool canBind(const String& origin) {
1511 return origin != protocol::CSS::StyleSheetOriginEnum::UserAgent && 1511 return origin != protocol::CSS::StyleSheetOriginEnum::UserAgent &&
1512 origin != protocol::CSS::StyleSheetOriginEnum::Injected; 1512 origin != protocol::CSS::StyleSheetOriginEnum::Injected;
1513 } 1513 }
1514 1514
1515 std::unique_ptr<protocol::CSS::CSSRule> 1515 std::unique_ptr<protocol::CSS::CSSRule>
1516 InspectorStyleSheet::buildObjectForRuleWithoutMedia(CSSStyleRule* rule) { 1516 InspectorStyleSheet::buildObjectForRuleWithoutMedia(CSSStyleRule* rule) {
1517 CSSStyleSheet* styleSheet = pageStyleSheet();
1518 if (!styleSheet)
1519 return nullptr;
1520
1521 std::unique_ptr<protocol::CSS::CSSRule> result = 1517 std::unique_ptr<protocol::CSS::CSSRule> result =
1522 protocol::CSS::CSSRule::create() 1518 protocol::CSS::CSSRule::create()
1523 .setSelectorList(buildObjectForSelectorList(rule)) 1519 .setSelectorList(buildObjectForSelectorList(rule))
1524 .setOrigin(m_origin) 1520 .setOrigin(m_origin)
1525 .setStyle(buildObjectForStyle(rule->style())) 1521 .setStyle(buildObjectForStyle(rule->style()))
1526 .build(); 1522 .build();
1527 1523
1528 if (canBind(m_origin)) { 1524 if (canBind(m_origin)) {
1529 if (!id().isEmpty()) 1525 if (!id().isEmpty())
1530 result->setStyleSheetId(id()); 1526 result->setStyleSheetId(id());
1531 } 1527 }
1532 1528
1533 return result; 1529 return result;
1534 } 1530 }
1535 1531
1536 std::unique_ptr<protocol::CSS::RuleUsage> 1532 std::unique_ptr<protocol::CSS::RuleUsage>
1537 InspectorStyleSheet::buildObjectForRuleUsage(CSSRule* rule, bool wasUsed) { 1533 InspectorStyleSheet::buildObjectForRuleUsage(CSSRule* rule, bool wasUsed) {
1538 CSSStyleSheet* styleSheet = pageStyleSheet();
1539 if (!styleSheet)
1540 return nullptr;
1541
1542 CSSRuleSourceData* sourceData = sourceDataForRule(rule); 1534 CSSRuleSourceData* sourceData = sourceDataForRule(rule);
1543 1535
1544 if (!sourceData) 1536 if (!sourceData)
1545 return nullptr; 1537 return nullptr;
1546 1538
1547 SourceRange wholeRuleRange(sourceData->ruleHeaderRange.start, 1539 SourceRange wholeRuleRange(sourceData->ruleHeaderRange.start,
1548 sourceData->ruleBodyRange.end + 1); 1540 sourceData->ruleBodyRange.end + 1);
1549 std::unique_ptr<protocol::CSS::RuleUsage> result = 1541 std::unique_ptr<protocol::CSS::RuleUsage> result =
1550 protocol::CSS::RuleUsage::create() 1542 protocol::CSS::RuleUsage::create()
1551 .setStyleSheetId(id()) 1543 .setStyleSheetId(id())
1552 .setStartOffset(wholeRuleRange.start) 1544 .setStartOffset(wholeRuleRange.start)
1553 .setEndOffset(wholeRuleRange.end) 1545 .setEndOffset(wholeRuleRange.end)
1554 .setUsed(wasUsed) 1546 .setUsed(wasUsed)
1555 .build(); 1547 .build();
1556 1548
1557 return result; 1549 return result;
1558 } 1550 }
1559 1551
1560 std::unique_ptr<protocol::CSS::CSSKeyframeRule> 1552 std::unique_ptr<protocol::CSS::CSSKeyframeRule>
1561 InspectorStyleSheet::buildObjectForKeyframeRule(CSSKeyframeRule* keyframeRule) { 1553 InspectorStyleSheet::buildObjectForKeyframeRule(CSSKeyframeRule* keyframeRule) {
1562 CSSStyleSheet* styleSheet = pageStyleSheet();
1563 if (!styleSheet)
1564 return nullptr;
1565
1566 std::unique_ptr<protocol::CSS::Value> keyText = 1554 std::unique_ptr<protocol::CSS::Value> keyText =
1567 protocol::CSS::Value::create().setText(keyframeRule->keyText()).build(); 1555 protocol::CSS::Value::create().setText(keyframeRule->keyText()).build();
1568 CSSRuleSourceData* sourceData = sourceDataForRule(keyframeRule); 1556 CSSRuleSourceData* sourceData = sourceDataForRule(keyframeRule);
1569 if (sourceData) 1557 if (sourceData)
1570 keyText->setRange(buildSourceRangeObject(sourceData->ruleHeaderRange)); 1558 keyText->setRange(buildSourceRangeObject(sourceData->ruleHeaderRange));
1571 std::unique_ptr<protocol::CSS::CSSKeyframeRule> result = 1559 std::unique_ptr<protocol::CSS::CSSKeyframeRule> result =
1572 protocol::CSS::CSSKeyframeRule::create() 1560 protocol::CSS::CSSKeyframeRule::create()
1573 // TODO(samli): keyText() normalises 'from' and 'to' keyword values. 1561 // TODO(samli): keyText() normalises 'from' and 'to' keyword values.
1574 .setKeyText(std::move(keyText)) 1562 .setKeyText(std::move(keyText))
1575 .setOrigin(m_origin) 1563 .setOrigin(m_origin)
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 IndexMap::iterator it = m_ruleToSourceData.find(index); 1740 IndexMap::iterator it = m_ruleToSourceData.find(index);
1753 if (it == m_ruleToSourceData.end()) 1741 if (it == m_ruleToSourceData.end())
1754 return nullptr; 1742 return nullptr;
1755 1743
1756 ASSERT(it->value < m_sourceData->size()); 1744 ASSERT(it->value < m_sourceData->size());
1757 1745
1758 // Check that CSSOM did not mutate this rule. 1746 // Check that CSSOM did not mutate this rule.
1759 CSSRule* parsedRule = m_parsedFlatRules.at(it->value); 1747 CSSRule* parsedRule = m_parsedFlatRules.at(it->value);
1760 if (canonicalCSSText(rule) != canonicalCSSText(parsedRule)) 1748 if (canonicalCSSText(rule) != canonicalCSSText(parsedRule))
1761 return nullptr; 1749 return nullptr;
1762
1763 return m_sourceData->at(it->value).get(); 1750 return m_sourceData->at(it->value).get();
1764 } 1751 }
1765 1752
1766 void InspectorStyleSheet::remapSourceDataToCSSOMIfNecessary() { 1753 void InspectorStyleSheet::remapSourceDataToCSSOMIfNecessary() {
1767 CSSRuleVector cssomRules; 1754 CSSRuleVector cssomRules;
1768 collectFlatRules(m_pageStyleSheet.get(), &cssomRules); 1755 collectFlatRules(m_pageStyleSheet.get(), &cssomRules);
1769 1756
1770 if (cssomRules.size() != m_cssomFlatRules.size()) { 1757 if (cssomRules.size() != m_cssomFlatRules.size()) {
1771 mapSourceDataToCSSOM(); 1758 mapSourceDataToCSSOM();
1772 return; 1759 return;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 return m_element->getAttribute("style").getString(); 1923 return m_element->getAttribute("style").getString();
1937 } 1924 }
1938 1925
1939 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) { 1926 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) {
1940 visitor->trace(m_element); 1927 visitor->trace(m_element);
1941 visitor->trace(m_inspectorStyle); 1928 visitor->trace(m_inspectorStyle);
1942 InspectorStyleSheetBase::trace(visitor); 1929 InspectorStyleSheetBase::trace(visitor);
1943 } 1930 }
1944 1931
1945 } // namespace blink 1932 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698