| Index: Source/core/inspector/InspectorStyleSheet.cpp
|
| diff --git a/Source/core/inspector/InspectorStyleSheet.cpp b/Source/core/inspector/InspectorStyleSheet.cpp
|
| index 492dc879c2ea88c15443570f35f3759d9ba52372..d454b2569fba9b7f0abac2b1f96fe741bc9f4e97 100644
|
| --- a/Source/core/inspector/InspectorStyleSheet.cpp
|
| +++ b/Source/core/inspector/InspectorStyleSheet.cpp
|
| @@ -1007,7 +1007,7 @@ bool InspectorStyleSheet::setText(const String& text, ExceptionState& exceptionS
|
| return true;
|
| }
|
|
|
| -CSSStyleRule* InspectorStyleSheet::setRuleSelector(const SourceRange& range, const String& text, SourceRange* newRange, String* oldText, ExceptionState& exceptionState)
|
| +RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::setRuleSelector(const SourceRange& range, const String& text, SourceRange* newRange, String* oldText, ExceptionState& exceptionState)
|
| {
|
| if (!verifySelectorText(text)) {
|
| exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid.");
|
| @@ -1021,7 +1021,7 @@ CSSStyleRule* InspectorStyleSheet::setRuleSelector(const SourceRange& range, con
|
| return nullptr;
|
| }
|
|
|
| - CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(rule);
|
| + RefPtrWillBeRawPtr<CSSStyleRule> styleRule = InspectorCSSAgent::asCSSStyleRule(rule);
|
| styleRule->setSelectorText(text);
|
|
|
| replaceText(sourceData->ruleHeaderRange, text, newRange, oldText);
|
| @@ -1030,7 +1030,30 @@ CSSStyleRule* InspectorStyleSheet::setRuleSelector(const SourceRange& range, con
|
| return styleRule;
|
| }
|
|
|
| -CSSMediaRule* InspectorStyleSheet::setMediaRuleText(const SourceRange& range, const String& text, SourceRange* newRange, String* oldText, ExceptionState& exceptionState)
|
| +RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::setStyleText(const SourceRange& range, const String& text, SourceRange* newRange, String* oldText, ExceptionState& exceptionState)
|
| +{
|
| + if (!verifyRuleText("div {" + text + "}")) {
|
| + exceptionState.throwDOMException(SyntaxError, "Style text is not valid.");
|
| + return nullptr;
|
| + }
|
| +
|
| + CSSRule* rule = nullptr;
|
| + CSSRuleSourceData* sourceData = nullptr;
|
| + if (!findRuleByBodyRange(range, &rule, &sourceData) || !sourceData->styleSourceData || rule->type() != CSSRule::STYLE_RULE) {
|
| + exceptionState.throwDOMException(NotFoundError, "Source range didn't match existing style source range");
|
| + return nullptr;
|
| + }
|
| +
|
| + RefPtrWillBeRawPtr<CSSStyleRule> styleRule = InspectorCSSAgent::asCSSStyleRule(rule);
|
| + styleRule->style()->setCSSText(text, exceptionState);
|
| +
|
| + replaceText(sourceData->ruleBodyRange, text, newRange, oldText);
|
| + onStyleSheetTextChanged();
|
| +
|
| + return styleRule;
|
| +}
|
| +
|
| +RefPtrWillBeRawPtr<CSSMediaRule> InspectorStyleSheet::setMediaRuleText(const SourceRange& range, const String& text, SourceRange* newRange, String* oldText, ExceptionState& exceptionState)
|
| {
|
| if (!verifyMediaText(text)) {
|
| exceptionState.throwDOMException(SyntaxError, "Selector or media text is not valid.");
|
| @@ -1044,7 +1067,7 @@ CSSMediaRule* InspectorStyleSheet::setMediaRuleText(const SourceRange& range, co
|
| return nullptr;
|
| }
|
|
|
| - CSSMediaRule* mediaRule = InspectorCSSAgent::asCSSMediaRule(rule);
|
| + RefPtrWillBeRawPtr<CSSMediaRule> mediaRule = InspectorCSSAgent::asCSSMediaRule(rule);
|
| mediaRule->media()->setMediaText(text);
|
|
|
| replaceText(sourceData->ruleHeaderRange, text, newRange, oldText);
|
| @@ -1212,7 +1235,7 @@ bool InspectorStyleSheet::verifyMediaText(const String& mediaText)
|
| return true;
|
| }
|
|
|
| -CSSStyleRule* InspectorStyleSheet::addRule(const String& ruleText, const SourceRange& location, SourceRange* addedRange, ExceptionState& exceptionState)
|
| +RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::addRule(const String& ruleText, const SourceRange& location, SourceRange* addedRange, ExceptionState& exceptionState)
|
| {
|
| if (location.start != location.end) {
|
| exceptionState.throwDOMException(NotFoundError, "Source range must be collapsed.");
|
| @@ -1230,7 +1253,7 @@ CSSStyleRule* InspectorStyleSheet::addRule(const String& ruleText, const SourceR
|
| }
|
| ensureFlatRules();
|
|
|
| - CSSStyleRule* styleRule = insertCSSOMRuleBySourceRange(location, ruleText, exceptionState);
|
| + RefPtrWillBeRawPtr<CSSStyleRule> styleRule = insertCSSOMRuleBySourceRange(location, ruleText, exceptionState);
|
| if (exceptionState.hadException())
|
| return nullptr;
|
|
|
| @@ -1614,6 +1637,25 @@ bool InspectorStyleSheet::findRuleByHeaderRange(const SourceRange& sourceRange,
|
| return false;
|
| }
|
|
|
| +bool InspectorStyleSheet::findRuleByBodyRange(const SourceRange& sourceRange, CSSRule** pRule, CSSRuleSourceData** pSourceData)
|
| +{
|
| + if (!ensureParsedDataReady())
|
| + return false;
|
| + ensureFlatRules();
|
| +
|
| + for (size_t i = 0; i < ruleCount() && i < m_flatRules.size(); ++i) {
|
| + RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt(i);
|
| + if (ruleSourceData->ruleBodyRange.start == sourceRange.start && ruleSourceData->ruleBodyRange.end == sourceRange.end) {
|
| + *pRule = m_flatRules.at(i).get();
|
| + if (!(*pRule)->parentStyleSheet())
|
| + return false;
|
| + *pSourceData = ruleSourceData.get();
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| +}
|
| +
|
| const CSSRuleVector& InspectorStyleSheet::flatRules()
|
| {
|
| ensureFlatRules();
|
|
|