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

Unified Diff: third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp

Issue 1577723002: Devtools: Add editable keyframes to the styles sidebar pane (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp
diff --git a/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp
index 3ef64c48df5a1d2ced864c86c082be72bec7a6ac..22694ea4f77536e26aced00fc4c7848c581023fa 100644
--- a/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp
+++ b/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp
@@ -372,7 +372,8 @@ public:
enum Type {
SetRuleSelector,
SetStyleText,
- SetMediaRuleText
+ SetMediaRuleText,
+ SetKeyframeKey
};
ModifyRuleAction(Type type, InspectorStyleSheet* styleSheet, const SourceRange& range, const String& text)
@@ -399,6 +400,8 @@ public:
return m_styleSheet->setStyleText(m_newRange, m_oldText, nullptr, nullptr, exceptionState);
case SetMediaRuleText:
return m_styleSheet->setMediaRuleText(m_newRange, m_oldText, nullptr, nullptr, exceptionState);
+ case SetKeyframeKey:
+ return m_styleSheet->setKeyframeKey(m_newRange, m_oldText, nullptr, nullptr, exceptionState);
default:
ASSERT_NOT_REACHED();
}
@@ -417,6 +420,9 @@ public:
case SetMediaRuleText:
m_cssRule = m_styleSheet->setMediaRuleText(m_oldRange, m_newText, &m_newRange, &m_oldText, exceptionState);
break;
+ case SetKeyframeKey:
+ m_cssRule = m_styleSheet->setKeyframeKey(m_oldRange, m_newText, &m_newRange, &m_oldText, exceptionState);
+ break;
default:
ASSERT_NOT_REACHED();
}
@@ -839,7 +845,7 @@ void InspectorCSSAgent::getMediaQueries(ErrorString* errorString, RefPtr<TypeBui
}
}
-void InspectorCSSAgent::getMatchedStylesForNode(ErrorString* errorString, int nodeId, RefPtr<TypeBuilder::CSS::CSSStyle>& inlineStyle, RefPtr<TypeBuilder::CSS::CSSStyle>& attributesStyle, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch>>& matchedCSSRules, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::PseudoElementMatches>>& pseudoIdMatches, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry>>& inheritedEntries)
+void InspectorCSSAgent::getMatchedStylesForNode(ErrorString* errorString, int nodeId, RefPtr<TypeBuilder::CSS::CSSStyle>& inlineStyle, RefPtr<TypeBuilder::CSS::CSSStyle>& attributesStyle, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch>>& matchedCSSRules, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::PseudoElementMatches>>& pseudoIdMatches, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry>>& inheritedEntries, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSKeyframesRule>>& cssKeyframesRules)
{
Element* element = elementForId(errorString, nodeId);
if (!element) {
@@ -915,6 +921,8 @@ void InspectorCSSAgent::getMatchedStylesForNode(ErrorString* errorString, int no
parentElement = parentElement->parentOrShadowHostElement();
}
inheritedEntries = entries.release();
+
+ cssKeyframesRules = animationsForNode(element);
}
template<class CSSRuleCollection>
@@ -937,33 +945,15 @@ static CSSKeyframesRule* findKeyframesRule(CSSRuleCollection* cssRules, StyleRul
return result;
}
-void InspectorCSSAgent::getCSSAnimationsForNode(ErrorString* errorString, int nodeId, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSKeyframesRule>>& cssKeyframesRules)
+PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSKeyframesRule>> InspectorCSSAgent::animationsForNode(Element* element)
{
- Element* element = elementForId(errorString, nodeId);
- if (!element) {
- *errorString = "Node not found";
- return;
- }
-
- PseudoId elementPseudoId = element->pseudoId();
- if (elementPseudoId) {
- element = element->parentOrShadowHostElement();
- if (!element) {
- *errorString = "Pseudo element has no parent";
- return;
- }
- }
-
- cssKeyframesRules = TypeBuilder::Array<TypeBuilder::CSS::CSSKeyframesRule>::create();
+ RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSKeyframesRule>> cssKeyframesRules = TypeBuilder::Array<TypeBuilder::CSS::CSSKeyframesRule>::create();
Document* ownerDocument = element->ownerDocument();
- // A non-active document has no styles.
- if (!ownerDocument->isActive())
- return;
StyleResolver& styleResolver = ownerDocument->ensureStyleResolver();
RefPtr<ComputedStyle> style = styleResolver.styleForElement(element);
if (!style)
- return;
+ return cssKeyframesRules;
const CSSAnimationData* animationData = style->animations();
for (size_t i = 0; animationData && i < animationData->nameList().size(); ++i) {
AtomicString animationName(animationData->nameList()[i]);
@@ -987,8 +977,10 @@ void InspectorCSSAgent::getCSSAnimationsForNode(ErrorString* errorString, int no
continue;
RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSKeyframeRule>> keyframes = TypeBuilder::Array<TypeBuilder::CSS::CSSKeyframeRule>::create();
- for (unsigned j = 0; j < cssKeyframesRule->length(); ++j)
- keyframes->addItem(buildObjectForKeyframeRule(cssKeyframesRule->item(j)));
+ for (unsigned j = 0; j < cssKeyframesRule->length(); ++j) {
+ InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(cssKeyframesRule->parentStyleSheet());
+ keyframes->addItem(inspectorStyleSheet->buildObjectForKeyframeRule(cssKeyframesRule->item(j)));
+ }
InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(cssKeyframesRule->parentStyleSheet());
RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = inspectorStyleSheet->sourceDataForRule(cssKeyframesRule);
@@ -999,6 +991,7 @@ void InspectorCSSAgent::getCSSAnimationsForNode(ErrorString* errorString, int no
.setKeyframes(keyframes);
cssKeyframesRules->addItem(keyframesRuleObject);
}
+ return cssKeyframesRules;
}
void InspectorCSSAgent::getInlineStylesForNode(ErrorString* errorString, int nodeId, RefPtr<TypeBuilder::CSS::CSSStyle>& inlineStyle, RefPtr<TypeBuilder::CSS::CSSStyle>& attributesStyle)
@@ -1184,6 +1177,36 @@ void InspectorCSSAgent::setRuleSelector(ErrorString* errorString, const String&
*errorString = InspectorDOMAgent::toErrorString(exceptionState);
}
+void InspectorCSSAgent::setKeyframeKey(ErrorString* errorString, const String& styleSheetId, const RefPtr<JSONObject>& range, const String& keyText, RefPtr<TypeBuilder::CSS::Value>& result)
+{
+ FrontendOperationScope scope;
+ InspectorStyleSheet* inspectorStyleSheet = assertInspectorStyleSheetForId(errorString, styleSheetId);
+ if (!inspectorStyleSheet) {
+ *errorString = "Stylesheet not found";
+ return;
+ }
+ SourceRange keyRange;
+ if (!jsonRangeToSourceRange(errorString, inspectorStyleSheet, range, &keyRange))
+ return;
+
+ TrackExceptionState exceptionState;
+ RefPtrWillBeRawPtr<ModifyRuleAction> action = adoptRefWillBeNoop(new ModifyRuleAction(ModifyRuleAction::SetKeyframeKey, inspectorStyleSheet, keyRange, keyText));
+ bool success = m_domAgent->history()->perform(action, exceptionState);
+ if (success) {
+ RefPtrWillBeRawPtr<CSSKeyframeRule> rule = toCSSKeyframeRule(action->takeRule().get());
+ InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(rule->parentStyleSheet());
+ if (!inspectorStyleSheet) {
+ *errorString = "Failed to get inspector style sheet for rule.";
+ return;
+ }
+
+ RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = inspectorStyleSheet->sourceDataForRule(rule);
+ result = TypeBuilder::CSS::Value::create().setText(rule->keyText());
+ result->setRange(inspectorStyleSheet->buildSourceRangeObject(sourceData->ruleHeaderRange));
+ }
+ *errorString = InspectorDOMAgent::toErrorString(exceptionState);
+}
+
void InspectorCSSAgent::setStyleText(ErrorString* errorString, const String& styleSheetId, const RefPtr<JSONObject>& range, const String& text, RefPtr<TypeBuilder::CSS::CSSStyle>& result)
{
FrontendOperationScope scope;
@@ -1721,19 +1744,6 @@ PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > InspectorCSSAgent::
return result;
}
-PassRefPtr<TypeBuilder::CSS::CSSKeyframeRule> InspectorCSSAgent::buildObjectForKeyframeRule(CSSKeyframeRule* keyframeRule)
-{
- InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(keyframeRule->parentStyleSheet());
- RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = inspectorStyleSheet->sourceDataForRule(keyframeRule);
- RefPtr<TypeBuilder::CSS::Value> keyText = TypeBuilder::CSS::Value::create().setText(keyframeRule->keyText());
- keyText->setRange(inspectorStyleSheet->buildSourceRangeObject(sourceData->ruleHeaderRange));
- RefPtr<TypeBuilder::CSS::CSSKeyframeRule> object = TypeBuilder::CSS::CSSKeyframeRule::create()
- // TODO(samli): keyText() normalises 'from' and 'to' keyword values.
- .setKeyText(keyText)
- .setStyle(inspectorStyleSheet->buildObjectForStyle(keyframeRule->style()));
- return object;
-}
-
PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorCSSAgent::buildObjectForAttributesStyle(Element* element)
{
if (!element->isStyledElement())

Powered by Google App Engine
This is Rietveld 408576698