summaryrefslogtreecommitdiffstats
path: root/dom/base/nsStyledElement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/base/nsStyledElement.cpp')
-rw-r--r--dom/base/nsStyledElement.cpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/dom/base/nsStyledElement.cpp b/dom/base/nsStyledElement.cpp
index 03d1187ab..8cd448d47 100644
--- a/dom/base/nsStyledElement.cpp
+++ b/dom/base/nsStyledElement.cpp
@@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsStyledElement.h"
+#include "mozAutoDocUpdate.h"
#include "nsGkAtoms.h"
#include "nsAttrValue.h"
#include "nsAttrValueInlines.h"
@@ -39,7 +40,6 @@ nsStyledElement::ParseAttribute(int32_t aNamespaceID,
nsAttrValue& aResult)
{
if (aAttribute == nsGkAtoms::style && aNamespaceID == kNameSpaceID_None) {
- SetMayHaveStyle();
ParseStyleAttribute(aValue, aResult, false);
return true;
}
@@ -49,6 +49,22 @@ nsStyledElement::ParseAttribute(int32_t aNamespaceID,
}
nsresult
+nsStyledElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
+ const nsAttrValueOrString* aValue, bool aNotify)
+{
+ if (aNamespaceID == kNameSpaceID_None) {
+ if (aName == nsGkAtoms::style) {
+ if (aValue) {
+ SetMayHaveStyle();
+ }
+ }
+ }
+
+ return nsStyledElementBase::BeforeSetAttr(aNamespaceID, aName, aValue,
+ aNotify);
+}
+
+nsresult
nsStyledElement::SetInlineStyleDeclaration(DeclarationBlock* aDeclaration,
const nsAString* aSerialized,
bool aNotify)
@@ -56,6 +72,7 @@ nsStyledElement::SetInlineStyleDeclaration(DeclarationBlock* aDeclaration,
SetMayHaveStyle();
bool modification = false;
nsAttrValue oldValue;
+ bool oldValueSet = false;
bool hasListeners = aNotify &&
nsContentUtils::HasMutationListeners(this,
@@ -75,6 +92,7 @@ nsStyledElement::SetInlineStyleDeclaration(DeclarationBlock* aDeclaration,
oldValueStr);
if (modification) {
oldValue.SetTo(oldValueStr);
+ oldValueSet = true;
}
}
else if (aNotify && IsInUncomposedDoc()) {
@@ -88,9 +106,12 @@ nsStyledElement::SetInlineStyleDeclaration(DeclarationBlock* aDeclaration,
static_cast<uint8_t>(nsIDOMMutationEvent::MODIFICATION) :
static_cast<uint8_t>(nsIDOMMutationEvent::ADDITION);
+ nsIDocument* document = GetComposedDoc();
+ mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, aNotify);
return SetAttrAndNotify(kNameSpaceID_None, nsGkAtoms::style, nullptr,
- oldValue, attrValue, modType, hasListeners,
- aNotify, kDontCallAfterSetAttr);
+ oldValueSet ? &oldValue : nullptr, attrValue, modType,
+ hasListeners, aNotify, kDontCallAfterSetAttr,
+ document, updateBatch);
}
DeclarationBlock*
@@ -141,7 +162,9 @@ nsStyledElement::ReparseStyleAttribute(bool aForceInDataDoc)
ParseStyleAttribute(stringValue, attrValue, aForceInDataDoc);
// Don't bother going through SetInlineStyleDeclaration; we don't
// want to fire off mutation events or document notifications anyway
- nsresult rv = mAttrsAndChildren.SetAndSwapAttr(nsGkAtoms::style, attrValue);
+ bool oldValueSet;
+ nsresult rv = mAttrsAndChildren.SetAndSwapAttr(nsGkAtoms::style, attrValue,
+ &oldValueSet);
NS_ENSURE_SUCCESS(rv, rv);
}