Chromium Code Reviews| Index: third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp |
| diff --git a/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp b/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp |
| index ab8a65045d90f6d22913eef4949d64bfcaaaae52..48363caade63f2e51ec30facd957897ca0bcd3d9 100644 |
| --- a/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp |
| +++ b/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp |
| @@ -371,6 +371,29 @@ bool verifyStyleText(Document* document, const String& text) |
| return verifyRuleText(document, "div {" + text + "}"); |
| } |
| +bool verifyKeyframeKeyText(Document* document, const String& keyText) |
| +{ |
| + DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); |
| + RefPtrWillBeRawPtr<StyleSheetContents> styleSheet = StyleSheetContents::create(strictCSSParserContext()); |
| + RuleSourceDataList sourceData; |
| + String text = "@keyframes boguzAnim { " + keyText + " { " + bogusPropertyName + ": none; } }"; |
|
pfeldman
2016/01/13 00:08:19
Just inline bogusPropertyName it here and below.
samli
2016/01/13 00:53:37
In the other methods too? They check the property
|
| + StyleSheetHandler handler(text, document, &sourceData); |
| + CSSParser::parseSheetForInspector(parserContextForDocument(document), styleSheet.get(), text, handler); |
| + |
| + // Exactly two should be parsed. |
| + unsigned ruleCount = sourceData.size(); |
| + if (ruleCount != 2 || sourceData.at(0)->type != StyleRule::Keyframes || sourceData.at(1)->type != StyleRule::Keyframe) |
| + return false; |
| + |
| + // Exactly one property should be in keyframe rule. |
| + WillBeHeapVector<CSSPropertySourceData>& propertyData = sourceData.at(1)->styleSourceData->propertyData; |
| + unsigned propertyCount = propertyData.size(); |
| + if (propertyCount != 1) |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| bool verifySelectorText(Document* document, const String& selectorText) |
| { |
| DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); |
| @@ -995,6 +1018,34 @@ RefPtrWillBeRawPtr<CSSStyleRule> InspectorStyleSheet::setRuleSelector(const Sour |
| return styleRule; |
| } |
| +PassRefPtrWillBeRawPtr<CSSKeyframeRule> InspectorStyleSheet::setKeyframeKey(const SourceRange& range, const String& text, SourceRange* newRange, String* oldText, ExceptionState& exceptionState) |
| +{ |
| + if (!verifyKeyframeKeyText(m_pageStyleSheet->ownerDocument(), text)) { |
| + exceptionState.throwDOMException(SyntaxError, "Keyframe key text is not valid."); |
| + return nullptr; |
| + } |
| + |
| + RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = findRuleByHeaderRange(range); |
| + if (!sourceData || !sourceData->styleSourceData) { |
| + exceptionState.throwDOMException(NotFoundError, "Source range didn't match existing source range"); |
| + return nullptr; |
| + } |
| + |
| + RefPtrWillBeRawPtr<CSSRule> rule = ruleForSourceData(sourceData); |
| + if (!rule || !rule->parentStyleSheet() || rule->type() != CSSRule::KEYFRAME_RULE) { |
| + exceptionState.throwDOMException(NotFoundError, "Source range didn't match existing style source range"); |
| + return nullptr; |
| + } |
| + |
| + RefPtrWillBeRawPtr<CSSKeyframeRule> keyframeRule = toCSSKeyframeRule(rule.get()); |
| + keyframeRule->setKeyText(text, exceptionState); |
| + |
| + replaceText(sourceData->ruleHeaderRange, text, newRange, oldText); |
| + onStyleSheetTextChanged(); |
| + |
| + return keyframeRule; |
| +} |
| + |
| PassRefPtrWillBeRawPtr<CSSRule> InspectorStyleSheet::setStyleText(const SourceRange& range, const String& text, SourceRange* newRange, String* oldText, ExceptionState& exceptionState) |
| { |
| if (!verifyStyleText(m_pageStyleSheet->ownerDocument(), text)) { |
| @@ -1369,6 +1420,24 @@ PassRefPtr<TypeBuilder::CSS::CSSRule> InspectorStyleSheet::buildObjectForRuleWit |
| return result.release(); |
| } |
| +PassRefPtr<TypeBuilder::CSS::CSSKeyframeRule> InspectorStyleSheet::buildObjectForKeyframeRule(CSSKeyframeRule* keyframeRule) |
| +{ |
| + CSSStyleSheet* styleSheet = pageStyleSheet(); |
| + if (!styleSheet) |
| + return nullptr; |
| + |
| + RefPtr<TypeBuilder::CSS::Value> keyText = TypeBuilder::CSS::Value::create().setText(keyframeRule->keyText()); |
| + keyText->setRange(buildSourceRangeObject(sourceDataForRule(keyframeRule)->ruleHeaderRange)); |
| + RefPtr<TypeBuilder::CSS::CSSKeyframeRule> result = TypeBuilder::CSS::CSSKeyframeRule::create() |
| + // TODO(samli): keyText() normalises 'from' and 'to' keyword values. |
| + .setKeyText(keyText) |
| + .setOrigin(m_origin) |
| + .setStyle(buildObjectForStyle(keyframeRule->style())); |
| + if (canBind(m_origin) && !id().isEmpty()) |
| + result->setStyleSheetId(id()); |
| + return result.release(); |
| +} |
| + |
| bool InspectorStyleSheet::getText(String* result) |
| { |
| if (m_sourceData) { |