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

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: Address comments 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..d0c889c420e50d3ac43c253b6bc51741a06b78a0 100644
--- a/Source/core/inspector/InspectorCSSAgent.cpp
+++ b/Source/core/inspector/InspectorCSSAgent.cpp
@@ -1515,11 +1515,9 @@ void InspectorCSSAgent::resetPseudoStates()
document->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::Inspector));
}
-PassRefPtrWillBeRawPtr<CSSStyleDeclaration> InspectorCSSAgent::findEffectiveDeclaration(Element* element, CSSPropertyID propertyId)
+PassRefPtrWillBeRawPtr<CSSRuleList> InspectorCSSAgent::matchedRulesList(Element* element)
{
PseudoId elementPseudoId = element->pseudoId();
- CSSStyleDeclaration* inlineStyle = element->style();
-
if (elementPseudoId) {
element = element->parentOrShadowHostElement();
if (!element)
@@ -1531,8 +1529,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 +1548,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;
@@ -1571,39 +1574,16 @@ PassRefPtrWillBeRawPtr<CSSStyleDeclaration> InspectorCSSAgent::findEffectiveDecl
return foundStyle.release();
}
-void InspectorCSSAgent::setCSSPropertyValue(ErrorString* errorString, Element* element, CSSPropertyID propertyId, const String& value)
+void InspectorCSSAgent::setCSSPropertyValue(ErrorString* errorString, Element* element, CSSStyleDeclaration* style, CSSPropertyID propertyId, const String& value, bool forceImportant)
dgozman 2015/09/03 20:42:14 RefPtrWillBeRawPtr<CSSStyleDeclaration>
sergeyv 2015/09/03 22:43:27 Done.
{
- Document* ownerDocument = element->ownerDocument();
- if (!ownerDocument->isActive()) {
- *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())
- foundStyle = inlineStyle;
-
- if (!foundStyle) {
- *errorString = "Can't find a style to edit";
- return;
- }
-
InspectorStyleSheetBase* inspectorStyleSheet = nullptr;
RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr;
- if (foundStyle != inlineStyle) {
- InspectorStyleSheet* styleSheet = bindStyleSheet(foundStyle->parentStyleSheet());
+ // An absence of the parent rule means that given style is an inline style.
+ if (style->parentRule()) {
+ InspectorStyleSheet* styleSheet = bindStyleSheet(style->parentStyleSheet());
dgozman 2015/09/03 20:42:14 nit: two spaces
sergeyv 2015/09/03 22:43:27 Done.
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 +1594,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 +1624,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 +1634,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();
@@ -1676,7 +1661,26 @@ void InspectorCSSAgent::setEffectivePropertyValueForNode(ErrorString* errorStrin
*errorString = "Invalid property name";
return;
}
- setCSSPropertyValue(errorString, element, cssPropertyID(propertyName), value);
+
+ Document* ownerDocument = element->ownerDocument();
+ if (!ownerDocument->isActive()) {
+ *errorString = "Can't edit a node from a non-active document";
+ return;
+ }
+
+ CSSPropertyID propertyId = cssPropertyID(propertyName);
+ CSSStyleDeclaration* inlineStyle = element->style();
dgozman 2015/09/03 20:42:14 nit: two spaces
sergeyv 2015/09/03 22:43:27 Done.
+ RefPtrWillBeRawPtr<CSSRuleList> ruleList = matchedRulesList(element);
+ RefPtrWillBeRawPtr<CSSStyleDeclaration> foundStyle = findEffectiveDeclaration(propertyId, ruleList.get(), inlineStyle);
+ if (!foundStyle || !foundStyle->parentStyleSheet())
+ foundStyle = inlineStyle;
+
+ if (!foundStyle) {
+ *errorString = "Can't find a style to edit";
+ return;
+ }
+
+ setCSSPropertyValue(errorString, element, foundStyle.get(), propertyId, value);
}
DEFINE_TRACE(InspectorCSSAgent)

Powered by Google App Engine
This is Rietveld 408576698