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

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

Issue 1181213007: DevTools: introduce CSS.setStyleText, we'll migrate setPropertyText to it later. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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
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 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 m_pageStyleSheet->contents()->parseString(text); 1000 m_pageStyleSheet->contents()->parseString(text);
1001 } 1001 }
1002 1002
1003 if (listener()) 1003 if (listener())
1004 listener()->didReparseStyleSheet(); 1004 listener()->didReparseStyleSheet();
1005 onStyleSheetTextChanged(); 1005 onStyleSheetTextChanged();
1006 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate); 1006 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate);
1007 return true; 1007 return true;
1008 } 1008 }
1009 1009
1010 CSSStyleRule* InspectorStyleSheet::setRuleSelector(const SourceRange& range, con st String& text, SourceRange* newRange, String* oldText, ExceptionState& excepti onState) 1010 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::setRuleSelector(const Sour ceRange& range, const String& text, SourceRange* newRange, String* oldText, Exce ptionState& exceptionState)
1011 { 1011 {
1012 if (!verifySelectorText(text)) { 1012 if (!verifySelectorText(text)) {
1013 exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid."); 1013 exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid.");
1014 return nullptr; 1014 return nullptr;
1015 } 1015 }
1016 1016
1017 CSSRule* rule = nullptr; 1017 CSSRule* rule = nullptr;
1018 CSSRuleSourceData* sourceData = nullptr; 1018 CSSRuleSourceData* sourceData = nullptr;
1019 if (!findRuleByHeaderRange(range, &rule, &sourceData) || !sourceData->styleS ourceData || rule->type() != CSSRule::STYLE_RULE) { 1019 if (!findRuleByHeaderRange(range, &rule, &sourceData) || !sourceData->styleS ourceData || rule->type() != CSSRule::STYLE_RULE) {
1020 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing source range"); 1020 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing source range");
1021 return nullptr; 1021 return nullptr;
1022 } 1022 }
1023 1023
1024 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(rule); 1024 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = InspectorCSSAgent::asCSSStyleR ule(rule);
1025 styleRule->setSelectorText(text); 1025 styleRule->setSelectorText(text);
1026 1026
1027 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText); 1027 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText);
1028 onStyleSheetTextChanged(); 1028 onStyleSheetTextChanged();
1029 1029
1030 return styleRule; 1030 return styleRule;
1031 } 1031 }
1032 1032
1033 CSSMediaRule* InspectorStyleSheet::setMediaRuleText(const SourceRange& range, co nst String& text, SourceRange* newRange, String* oldText, ExceptionState& except ionState) 1033 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::setStyleText(const SourceR ange& range, const String& text, SourceRange* newRange, String* oldText, Excepti onState& exceptionState)
1034 {
1035 if (!verifyRuleText("div {" + text + "}")) {
1036 exceptionState.throwDOMException(SyntaxError, "Style text is not valid." );
1037 return nullptr;
1038 }
1039
1040 CSSRule* rule = nullptr;
1041 CSSRuleSourceData* sourceData = nullptr;
1042 if (!findRuleByBodyRange(range, &rule, &sourceData) || !sourceData->styleSou rceData || rule->type() != CSSRule::STYLE_RULE) {
1043 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing style source range");
1044 return nullptr;
1045 }
1046
1047 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = InspectorCSSAgent::asCSSStyleRu le(rule);
1048 styleRule->style()->setCSSText(text, exceptionState);
1049
1050 replaceText(sourceData->ruleBodyRange, text, newRange, oldText);
1051 onStyleSheetTextChanged();
1052
1053 return styleRule;
1054 }
1055
1056 RefPtrWillBeRawPtr<CSSMediaRule> InspectorStyleSheet::setMediaRuleText(const Sou rceRange& range, const String& text, SourceRange* newRange, String* oldText, Exc eptionState& exceptionState)
1034 { 1057 {
1035 if (!verifyMediaText(text)) { 1058 if (!verifyMediaText(text)) {
1036 exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid."); 1059 exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid.");
1037 return nullptr; 1060 return nullptr;
1038 } 1061 }
1039 1062
1040 CSSRule* rule = nullptr; 1063 CSSRule* rule = nullptr;
1041 CSSRuleSourceData* sourceData = nullptr; 1064 CSSRuleSourceData* sourceData = nullptr;
1042 if (!findRuleByHeaderRange(range, &rule, &sourceData) || !sourceData->mediaS ourceData || rule->type() != CSSRule::MEDIA_RULE) { 1065 if (!findRuleByHeaderRange(range, &rule, &sourceData) || !sourceData->mediaS ourceData || rule->type() != CSSRule::MEDIA_RULE) {
1043 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing source range"); 1066 exceptionState.throwDOMException(NotFoundError, "Source range didn't mat ch existing source range");
1044 return nullptr; 1067 return nullptr;
1045 } 1068 }
1046 1069
1047 CSSMediaRule* mediaRule = InspectorCSSAgent::asCSSMediaRule(rule); 1070 RefPtrWillBeRawPtr<CSSMediaRule> mediaRule = InspectorCSSAgent::asCSSMediaR ule(rule);
1048 mediaRule->media()->setMediaText(text); 1071 mediaRule->media()->setMediaText(text);
1049 1072
1050 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText); 1073 replaceText(sourceData->ruleHeaderRange, text, newRange, oldText);
1051 onStyleSheetTextChanged(); 1074 onStyleSheetTextChanged();
1052 1075
1053 return mediaRule; 1076 return mediaRule;
1054 } 1077 }
1055 1078
1056 unsigned InspectorStyleSheet::ruleIndexBySourceRange(const CSSMediaRule* parentM ediaRule, const SourceRange& sourceRange) 1079 unsigned InspectorStyleSheet::ruleIndexBySourceRange(const CSSMediaRule* parentM ediaRule, const SourceRange& sourceRange)
1057 { 1080 {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 if (propertyCount != 1) 1228 if (propertyCount != 1)
1206 return false; 1229 return false;
1207 1230
1208 // Check for the property name. 1231 // Check for the property name.
1209 if (propertyData.at(0).name != bogusPropertyName) 1232 if (propertyData.at(0).name != bogusPropertyName)
1210 return false; 1233 return false;
1211 1234
1212 return true; 1235 return true;
1213 } 1236 }
1214 1237
1215 CSSStyleRule* InspectorStyleSheet::addRule(const String& ruleText, const SourceR ange& location, SourceRange* addedRange, ExceptionState& exceptionState) 1238 RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::addRule(const String& rule Text, const SourceRange& location, SourceRange* addedRange, ExceptionState& exce ptionState)
1216 { 1239 {
1217 if (location.start != location.end) { 1240 if (location.start != location.end) {
1218 exceptionState.throwDOMException(NotFoundError, "Source range must be co llapsed."); 1241 exceptionState.throwDOMException(NotFoundError, "Source range must be co llapsed.");
1219 return nullptr; 1242 return nullptr;
1220 } 1243 }
1221 1244
1222 if (!verifyRuleText(ruleText)) { 1245 if (!verifyRuleText(ruleText)) {
1223 exceptionState.throwDOMException(SyntaxError, "Rule text is not valid.") ; 1246 exceptionState.throwDOMException(SyntaxError, "Rule text is not valid.") ;
1224 return nullptr; 1247 return nullptr;
1225 } 1248 }
1226 1249
1227 if (!ensureParsedDataReady()) { 1250 if (!ensureParsedDataReady()) {
1228 exceptionState.throwDOMException(NotFoundError, "Cannot parse style shee t."); 1251 exceptionState.throwDOMException(NotFoundError, "Cannot parse style shee t.");
1229 return nullptr; 1252 return nullptr;
1230 } 1253 }
1231 ensureFlatRules(); 1254 ensureFlatRules();
1232 1255
1233 CSSStyleRule* styleRule = insertCSSOMRuleBySourceRange(location, ruleText, e xceptionState); 1256 RefPtrWillBeRawPtr<CSSStyleRule> styleRule = insertCSSOMRuleBySourceRange(lo cation, ruleText, exceptionState);
1234 if (exceptionState.hadException()) 1257 if (exceptionState.hadException())
1235 return nullptr; 1258 return nullptr;
1236 1259
1237 replaceText(location, ruleText, addedRange, nullptr); 1260 replaceText(location, ruleText, addedRange, nullptr);
1238 m_flatRules.clear(); 1261 m_flatRules.clear();
1239 1262
1240 onStyleSheetTextChanged(); 1263 onStyleSheetTextChanged();
1241 return styleRule; 1264 return styleRule;
1242 } 1265 }
1243 1266
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 *pRule = m_flatRules.at(i).get(); 1630 *pRule = m_flatRules.at(i).get();
1608 if (!(*pRule)->parentStyleSheet()) 1631 if (!(*pRule)->parentStyleSheet())
1609 return false; 1632 return false;
1610 *pSourceData = ruleSourceData.get(); 1633 *pSourceData = ruleSourceData.get();
1611 return true; 1634 return true;
1612 } 1635 }
1613 } 1636 }
1614 return false; 1637 return false;
1615 } 1638 }
1616 1639
1640 bool InspectorStyleSheet::findRuleByBodyRange(const SourceRange& sourceRange, CS SRule** pRule, CSSRuleSourceData** pSourceData)
1641 {
1642 if (!ensureParsedDataReady())
1643 return false;
1644 ensureFlatRules();
1645
1646 for (size_t i = 0; i < ruleCount() && i < m_flatRules.size(); ++i) {
1647 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i);
1648 if (ruleSourceData->ruleBodyRange.start == sourceRange.start && ruleSour ceData->ruleBodyRange.end == sourceRange.end) {
1649 *pRule = m_flatRules.at(i).get();
1650 if (!(*pRule)->parentStyleSheet())
1651 return false;
1652 *pSourceData = ruleSourceData.get();
1653 return true;
1654 }
1655 }
1656 return false;
1657 }
1658
1617 const CSSRuleVector& InspectorStyleSheet::flatRules() 1659 const CSSRuleVector& InspectorStyleSheet::flatRules()
1618 { 1660 {
1619 ensureFlatRules(); 1661 ensureFlatRules();
1620 return m_flatRules; 1662 return m_flatRules;
1621 } 1663 }
1622 1664
1623 Document* InspectorStyleSheet::ownerDocument() const 1665 Document* InspectorStyleSheet::ownerDocument() const
1624 { 1666 {
1625 return m_pageStyleSheet->ownerDocument(); 1667 return m_pageStyleSheet->ownerDocument();
1626 } 1668 }
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 1956
1915 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) 1957 DEFINE_TRACE(InspectorStyleSheetForInlineStyle)
1916 { 1958 {
1917 visitor->trace(m_element); 1959 visitor->trace(m_element);
1918 visitor->trace(m_ruleSourceData); 1960 visitor->trace(m_ruleSourceData);
1919 visitor->trace(m_inspectorStyle); 1961 visitor->trace(m_inspectorStyle);
1920 InspectorStyleSheetBase::trace(visitor); 1962 InspectorStyleSheetBase::trace(visitor);
1921 } 1963 }
1922 1964
1923 } // namespace blink 1965 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698