Bug 1435139 - Don't call SetCSSDeclaration when removing non-existing property. r?bz
MozReview-Commit-ID: 8jt1D5RULEy
--- a/layout/style/Declaration.cpp
+++ b/layout/style/Declaration.cpp
@@ -192,22 +192,24 @@ Declaration::GetPropertyIsImportant(cons
{
bool r = false;
DispatchPropertyOperation(aProperty,
[&](nsCSSPropertyID propID) { r = GetPropertyIsImportantByID(propID); },
[&](const nsAString& name) { r = GetVariableIsImportant(name); });
return r;
}
-void
+bool
Declaration::RemoveProperty(const nsAString& aProperty)
{
+ bool r = true;
DispatchPropertyOperation(aProperty,
- [&](nsCSSPropertyID propID) { RemovePropertyByID(propID); },
- [&](const nsAString& name) { RemoveVariable(name); });
+ [&](nsCSSPropertyID propID) { r = RemovePropertyByID(propID); },
+ [&](const nsAString& name) { r = RemoveVariable(name); });
+ return r;
}
bool
Declaration::RemovePropertyByID(nsCSSPropertyID aProperty)
{
MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT);
nsCSSExpandedDataBlock data;
@@ -1906,29 +1908,31 @@ Declaration::AddVariable(const nsAString
MOZ_ASSERT(false, "unexpected aType value");
}
uint32_t propertyIndex = index + eCSSProperty_COUNT;
mOrder.RemoveElement(propertyIndex);
mOrder.AppendElement(propertyIndex);
}
-void
+bool
Declaration::RemoveVariable(const nsAString& aName)
{
if (mVariables) {
mVariables->Remove(aName);
}
if (mImportantVariables) {
mImportantVariables->Remove(aName);
}
nsTArray<nsString>::index_type index = mVariableOrder.IndexOf(aName);
if (index != nsTArray<nsString>::NoIndex) {
mOrder.RemoveElement(index + eCSSProperty_COUNT);
+ return true;
}
+ return false;
}
bool
Declaration::GetVariableIsImportant(const nsAString& aName) const
{
return mImportantVariables && mImportantVariables->Has(aName);
}
--- a/layout/style/Declaration.h
+++ b/layout/style/Declaration.h
@@ -122,17 +122,19 @@ public:
* |mOrder| whenever a property is parsed into an expanded data block
* for this declaration. aProperty must not be a shorthand.
*/
void ValueAppended(nsCSSPropertyID aProperty);
void GetPropertyValue(const nsAString& aProperty, nsAString& aValue) const;
void GetPropertyValueByID(nsCSSPropertyID aPropID, nsAString& aValue) const;
bool GetPropertyIsImportant(const nsAString& aProperty) const;
- void RemoveProperty(const nsAString& aProperty);
+ // The two functions below returns whether there is any change to this
+ // declaration block, i.e. whether any property is actually removed.
+ bool RemoveProperty(const nsAString& aProperty);
bool RemovePropertyByID(nsCSSPropertyID aProperty);
bool HasProperty(nsCSSPropertyID aProperty) const;
bool HasImportantData() const {
return mImportantData || mImportantVariables;
}
@@ -149,21 +151,22 @@ public:
*/
void AddVariable(const nsAString& aName,
CSSVariableDeclarations::Type aType,
const nsString& aValue,
bool aIsImportant,
bool aOverrideImportant);
/**
- * Removes a custom property declaration from this object.
+ * Removes a custom property declaration from this object, and
+ * return whether the variable existed.
*
* @param aName The variable name (i.e., without the "--" prefix).
*/
- void RemoveVariable(const nsAString& aName);
+ bool RemoveVariable(const nsAString& aName);
/**
* Gets the string value for a custom property declaration of a variable
* with a given name.
*
* @param aName The variable name (i.e., without the "--" prefix).
* @param aValue Out parameter into which the variable's value will be
* stored. If the value is 'initial' or 'inherit', that exact string
--- a/layout/style/DeclarationBlock.h
+++ b/layout/style/DeclarationBlock.h
@@ -127,17 +127,18 @@ public:
inline uint32_t Count() const;
inline bool GetNthProperty(uint32_t aIndex, nsAString& aReturn) const;
inline void GetPropertyValue(const nsAString& aProperty,
nsAString& aValue) const;
inline void GetPropertyValueByID(nsCSSPropertyID aPropID,
nsAString& aValue) const;
inline bool GetPropertyIsImportant(const nsAString& aProperty) const;
- inline void RemoveProperty(const nsAString& aProperty);
+ // Returns whether the property was removed.
+ inline bool RemoveProperty(const nsAString& aProperty);
// Returns whether the property was removed.
inline bool RemovePropertyByID(nsCSSPropertyID aProperty);
private:
union {
// We only ever have one of these since we have an
// nsHTMLCSSStyleSheet only for style attributes, and style
// attributes never have an owning rule.
--- a/layout/style/DeclarationBlockInlines.h
+++ b/layout/style/DeclarationBlockInlines.h
@@ -102,17 +102,17 @@ DeclarationBlock::GetPropertyValueByID(n
}
bool
DeclarationBlock::GetPropertyIsImportant(const nsAString& aProperty) const
{
MOZ_STYLO_FORWARD(GetPropertyIsImportant, (aProperty))
}
-void
+bool
DeclarationBlock::RemoveProperty(const nsAString& aProperty)
{
MOZ_STYLO_FORWARD(RemoveProperty, (aProperty))
}
bool
DeclarationBlock::RemovePropertyByID(nsCSSPropertyID aProperty)
{
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -460,17 +460,17 @@ SERVO_BINDING_FUNC(Servo_DeclarationBloc
SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetPropertyById, bool,
RawServoDeclarationBlockBorrowed declarations,
nsCSSPropertyID property,
const nsACString* value, bool is_important,
RawGeckoURLExtraData* data,
mozilla::ParsingMode parsing_mode,
nsCompatibility quirks_mode,
mozilla::css::Loader* loader)
-SERVO_BINDING_FUNC(Servo_DeclarationBlock_RemoveProperty, void,
+SERVO_BINDING_FUNC(Servo_DeclarationBlock_RemoveProperty, bool,
RawServoDeclarationBlockBorrowed declarations,
const nsACString* property)
SERVO_BINDING_FUNC(Servo_DeclarationBlock_RemovePropertyById, bool,
RawServoDeclarationBlockBorrowed declarations,
nsCSSPropertyID property)
SERVO_BINDING_FUNC(Servo_DeclarationBlock_HasCSSWideKeyword, bool,
RawServoDeclarationBlockBorrowed declarations,
nsCSSPropertyID property)
--- a/layout/style/ServoDeclarationBlock.cpp
+++ b/layout/style/ServoDeclarationBlock.cpp
@@ -43,22 +43,22 @@ ServoDeclarationBlock::GetPropertyValueB
bool
ServoDeclarationBlock::GetPropertyIsImportant(const nsAString& aProperty) const
{
NS_ConvertUTF16toUTF8 property(aProperty);
return Servo_DeclarationBlock_GetPropertyIsImportant(mRaw, &property);
}
-void
+bool
ServoDeclarationBlock::RemoveProperty(const nsAString& aProperty)
{
AssertMutable();
NS_ConvertUTF16toUTF8 property(aProperty);
- Servo_DeclarationBlock_RemoveProperty(mRaw, &property);
+ return Servo_DeclarationBlock_RemoveProperty(mRaw, &property);
}
bool
ServoDeclarationBlock::RemovePropertyByID(nsCSSPropertyID aPropID)
{
AssertMutable();
return Servo_DeclarationBlock_RemovePropertyById(mRaw, aPropID);
}
--- a/layout/style/ServoDeclarationBlock.h
+++ b/layout/style/ServoDeclarationBlock.h
@@ -61,17 +61,18 @@ public:
bool GetNthProperty(uint32_t aIndex, nsAString& aReturn) const {
aReturn.Truncate();
return Servo_DeclarationBlock_GetNthProperty(mRaw, aIndex, &aReturn);
}
void GetPropertyValue(const nsAString& aProperty, nsAString& aValue) const;
void GetPropertyValueByID(nsCSSPropertyID aPropID, nsAString& aValue) const;
bool GetPropertyIsImportant(const nsAString& aProperty) const;
- void RemoveProperty(const nsAString& aProperty);
+ // The two functions blow return whether any property was removed.
+ bool RemoveProperty(const nsAString& aProperty);
bool RemovePropertyByID(nsCSSPropertyID aPropID);
private:
~ServoDeclarationBlock() {}
RefPtr<RawServoDeclarationBlock> mRaw;
};
--- a/layout/style/nsDOMCSSDeclaration.cpp
+++ b/layout/style/nsDOMCSSDeclaration.cpp
@@ -416,17 +416,19 @@ nsDOMCSSDeclaration::RemovePropertyInter
// For nsDOMCSSAttributeDeclaration, SetCSSDeclaration will lead to
// Attribute setting code, which leads in turn to BeginUpdate. We
// need to start the update now so that the old rule doesn't get used
// between when we mutate the declaration and when we set the new
// rule (see stack in bug 209575).
mozAutoDocConditionalContentUpdateBatch autoUpdate(DocToUpdate(), true);
RefPtr<DeclarationBlock> decl = olddecl->EnsureMutable();
- decl->RemovePropertyByID(aPropID);
+ if (!decl->RemovePropertyByID(aPropID)) {
+ return NS_OK;
+ }
return SetCSSDeclaration(decl);
}
nsresult
nsDOMCSSDeclaration::RemovePropertyInternal(const nsAString& aPropertyName)
{
DeclarationBlock* olddecl = GetCSSDeclaration(eOperation_RemoveProperty);
if (!olddecl) {
@@ -436,11 +438,13 @@ nsDOMCSSDeclaration::RemovePropertyInter
// For nsDOMCSSAttributeDeclaration, SetCSSDeclaration will lead to
// Attribute setting code, which leads in turn to BeginUpdate. We
// need to start the update now so that the old rule doesn't get used
// between when we mutate the declaration and when we set the new
// rule (see stack in bug 209575).
mozAutoDocConditionalContentUpdateBatch autoUpdate(DocToUpdate(), true);
RefPtr<DeclarationBlock> decl = olddecl->EnsureMutable();
- decl->RemoveProperty(aPropertyName);
+ if (!decl->RemoveProperty(aPropertyName)) {
+ return NS_OK;
+ }
return SetCSSDeclaration(decl);
}