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

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

Issue 1310923003: Devtools [LayoutEditor]: Patch values in the selected rule (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@medias
Patch Set: Rebase Created 5 years, 3 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: Source/core/inspector/InspectorCSSAgent.cpp
diff --git a/Source/core/inspector/InspectorCSSAgent.cpp b/Source/core/inspector/InspectorCSSAgent.cpp
index 09b3a882864f1167f861819cd8709cd95414bd79..56ed6fd5ec94d6aad90eaca23ac60a8a8e4fd1b7 100644
--- a/Source/core/inspector/InspectorCSSAgent.cpp
+++ b/Source/core/inspector/InspectorCSSAgent.cpp
@@ -1517,9 +1517,13 @@ void InspectorCSSAgent::resetPseudoStates()
PassRefPtrWillBeRawPtr<CSSStyleDeclaration> InspectorCSSAgent::findEffectiveDeclaration(Element* element, CSSPropertyID propertyId)
dgozman 2015/09/02 22:26:16 Can we kill this function?
sergeyv 2015/09/03 00:52:28 Done.
{
- PseudoId elementPseudoId = element->pseudoId();
- CSSStyleDeclaration* inlineStyle = element->style();
+ RefPtrWillBeRawPtr<CSSRuleList> ruleList = matchedRulesList(element);
+ return findEffectiveDeclaration(propertyId, ruleList.get(), element->pseudoId() ? nullptr : element->style());
dgozman 2015/09/02 22:26:17 Can we always call element->style()?
sergeyv 2015/09/03 00:52:27 Done.
+}
+PassRefPtrWillBeRawPtr<CSSRuleList> InspectorCSSAgent::matchedRulesList(Element* element)
+{
+ PseudoId elementPseudoId = element->pseudoId();
if (elementPseudoId) {
element = element->parentOrShadowHostElement();
if (!element)
@@ -1531,8 +1535,17 @@ PassRefPtrWillBeRawPtr<CSSStyleDeclaration> InspectorCSSAgent::findEffectiveDecl
if (!ownerDocument->isActive())
return nullptr;
- String longhand = getPropertyNameString(propertyId);
+ StyleResolver& styleResolver = ownerDocument->ensureStyleResolver();
+ element->updateDistribution();
+ return styleResolver.pseudoCSSRulesForElement(element, elementPseudoId, StyleResolver::AllCSSRules);
+}
+
+PassRefPtrWillBeRawPtr<CSSStyleDeclaration> InspectorCSSAgent::findEffectiveDeclaration(CSSPropertyID propertyId, CSSRuleList* ruleList, CSSStyleDeclaration* inlineStyle)
+{
+ if (!ruleList && !inlineStyle)
+ return nullptr;
+ String longhand = getPropertyNameString(propertyId);
RefPtrWillBeRawPtr<CSSStyleDeclaration> foundStyle = nullptr;
bool isImportant = false;
@@ -1541,10 +1554,6 @@ PassRefPtrWillBeRawPtr<CSSStyleDeclaration> InspectorCSSAgent::findEffectiveDecl
isImportant = inlineStyle->getPropertyPriority(longhand) == "important";
}
- StyleResolver& styleResolver = ownerDocument->ensureStyleResolver();
- element->updateDistribution();
- RefPtrWillBeRawPtr<CSSRuleList> ruleList = styleResolver.pseudoCSSRulesForElement(element, elementPseudoId, StyleResolver::AllCSSRules);
-
for (unsigned i = 0, size = ruleList ? ruleList->length() : 0; i < size; ++i) {
if (isImportant)
break;
@@ -1578,13 +1587,6 @@ void InspectorCSSAgent::setCSSPropertyValue(ErrorString* errorString, Element* e
*errorString = "Can't edit a node from a non-active document";
return;
}
-
- Vector<StylePropertyShorthand, 4> shorthands;
- getMatchingShorthandsForLonghand(propertyId, &shorthands);
-
- String shorthand = shorthands.size() > 0 ? getPropertyNameString(shorthands[0].id()) : String();
- String longhand = getPropertyNameString(propertyId);
-
RefPtrWillBeRawPtr<CSSStyleDeclaration> foundStyle = findEffectiveDeclaration(element, propertyId);
CSSStyleDeclaration* inlineStyle = element->style();
if (!foundStyle || !foundStyle->parentStyleSheet())
@@ -1595,15 +1597,18 @@ void InspectorCSSAgent::setCSSPropertyValue(ErrorString* errorString, Element* e
return;
}
+ setCSSPropertyValue(errorString, element, foundStyle.get(), propertyId, value);
+}
+
+void InspectorCSSAgent::setCSSPropertyValue(ErrorString* errorString, Element* element, CSSStyleDeclaration* style, CSSPropertyID propertyId, const String& value, bool forceImportant)
+{
InspectorStyleSheetBase* inspectorStyleSheet = nullptr;
RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr;
- if (foundStyle != inlineStyle) {
- InspectorStyleSheet* styleSheet = bindStyleSheet(foundStyle->parentStyleSheet());
+ if (style->parentRule()) {
dgozman 2015/09/02 22:26:16 Let's comment that this means inline style.
sergeyv 2015/09/03 00:52:27 Done.
+ InspectorStyleSheet* styleSheet = bindStyleSheet(style->parentStyleSheet());
inspectorStyleSheet = styleSheet;
- sourceData = styleSheet->sourceDataForRule(foundStyle->parentRule());
- }
-
- if (!sourceData) {
+ sourceData = styleSheet->sourceDataForRule(style->parentRule());
+ } else {
InspectorStyleSheetForInlineStyle* inlineStyleSheet = asInspectorStyleSheet(element);
inspectorStyleSheet = inlineStyleSheet;
sourceData = inlineStyleSheet->ruleSourceData();
@@ -1614,6 +1619,12 @@ void InspectorCSSAgent::setCSSPropertyValue(ErrorString* errorString, Element* e
return;
}
+ Vector<StylePropertyShorthand, 4> shorthands;
+ getMatchingShorthandsForLonghand(propertyId, &shorthands);
+
+ String shorthand = shorthands.size() > 0 ? getPropertyNameString(shorthands[0].id()) : String();
+ String longhand = getPropertyNameString(propertyId);
+
int foundIndex = -1;
WillBeHeapVector<CSSPropertySourceData> properties = sourceData->styleSourceData->propertyData;
for (unsigned i = 0; i < properties.size(); ++i) {
@@ -1638,8 +1649,7 @@ void InspectorCSSAgent::setCSSPropertyValue(ErrorString* errorString, Element* e
String styleText = styleSheetText.substring(bodyRange.start, bodyRange.length());
SourceRange changeRange;
if (foundIndex == -1) {
- bool isImportant = inlineStyle->getPropertyPriority(longhand) == "important";
- String newPropertyText = "\n" + longhand + ": " + value + (isImportant ? " !important" : "") + ";";
+ String newPropertyText = "\n" + longhand + ": " + value + (forceImportant ? " !important" : "") + ";";
if (!styleText.isEmpty() && !styleText.stripWhiteSpace().endsWith(';'))
newPropertyText = ";" + newPropertyText;
styleText.append(newPropertyText);
@@ -1649,11 +1659,11 @@ void InspectorCSSAgent::setCSSPropertyValue(ErrorString* errorString, Element* e
CSSPropertySourceData declaration = properties[foundIndex];
String newValueText;
if (declaration.name == shorthand)
- newValueText = createShorthandValue(ownerDocument, shorthand, declaration.value, longhand, value);
+ newValueText = createShorthandValue(element->ownerDocument(), shorthand, declaration.value, longhand, value);
else
newValueText = value;
- String newPropertyText = declaration.name + ": " + newValueText + (declaration.important ? " !important" : "") + ";";
+ String newPropertyText = declaration.name + ": " + newValueText + (declaration.important || forceImportant ? " !important" : "") + ";";
styleText.replace(declaration.range.start - bodyRange.start, declaration.range.length(), newPropertyText);
changeRange.start = declaration.range.start;
changeRange.end = changeRange.start + newPropertyText.length();
@@ -1679,6 +1689,34 @@ void InspectorCSSAgent::setEffectivePropertyValueForNode(ErrorString* errorStrin
setCSSPropertyValue(errorString, element, cssPropertyID(propertyName), value);
}
+void InspectorCSSAgent::setCSSPropertyValueInRule(ErrorString* errorString, Element* element, CSSStyleRule* rule, CSSPropertyID propertyId, const String& value)
dgozman 2015/09/02 22:26:16 This one can move to layout editor.
sergeyv 2015/09/03 00:52:28 Done.
+{
+ RefPtrWillBeRawPtr<CSSRuleList> ruleList = matchedRulesList(element);
+ RefPtrWillBeRawPtr<CSSStyleDeclaration> effectiveDeclaration = findEffectiveDeclaration(propertyId, ruleList.get(), element->pseudoId() ? nullptr : element->style());
+
+ CSSStyleRule* effectiveRule = nullptr;
+ if (effectiveDeclaration->parentRule() && effectiveDeclaration->parentRule()->type() == CSSRule::STYLE_RULE)
lushnikov 2015/09/02 23:00:43 effectiveDeclaration &&
sergeyv 2015/09/03 00:52:28 Done.
+ effectiveRule = toCSSStyleRule(effectiveDeclaration->parentRule());
+
+ String longhand = getPropertyNameString(propertyId);
+ bool forceImportant = effectiveDeclaration && effectiveDeclaration->getPropertyPriority(longhand) == "important";
+
+ if (effectiveDeclaration && rule) {
+ int effectiveRuleIndex = -1;
+ int ruleIndex = -1;
+ for (unsigned i = 0, size = ruleList ? ruleList->length() : 0; i < size; ++i) {
+ CSSRule* currentRule = ruleList->item(size - i - 1);
+ if (currentRule == effectiveRule)
+ effectiveRuleIndex = i;
+ if (currentRule == rule)
+ ruleIndex = i;
+ }
+ forceImportant |= effectiveRuleIndex < ruleIndex;
+ }
+
+ setCSSPropertyValue(errorString, element, rule ? rule->style() : element->style(), propertyId, value, forceImportant);
+}
+
DEFINE_TRACE(InspectorCSSAgent)
{
visitor->trace(m_domAgent);

Powered by Google App Engine
This is Rietveld 408576698