From ebcd546db95b36b38fd9f9734e10fcc6567f3177 Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Fri, 26 Jul 2019 16:11:42 +0000 Subject: [PATCH] Bug 1517880 - Add a flag for l10n elements created from prototype. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D36067 --HG-- extra : moz-landing-system : lando --- dom/base/Element.cpp | 7 +++++++ dom/base/nsINode.h | 13 +++++++++++++ dom/prototype/PrototypeDocumentContentSink.cpp | 1 + 3 files changed, 21 insertions(+) diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 96ccd812c4ca..1b2bdbd6b111 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -1894,6 +1894,7 @@ void Element::UnbindFromTree(bool aNullParent) { ClearInDocument(); SetIsConnected(false); + ClearElementCreatedFromPrototypeAndHasUnmodifiedL10n(); if (aNullParent || !mParent->IsInShadowTree()) { UnsetFlags(NODE_IS_IN_SHADOW_TREE); @@ -2468,6 +2469,12 @@ nsresult Element::SetAttrAndNotify( } } + if (HasElementCreatedFromPrototypeAndHasUnmodifiedL10n() && + aNamespaceID == kNameSpaceID_None && + (aName == nsGkAtoms::datal10nid || aName == nsGkAtoms::datal10nargs)) { + ClearElementCreatedFromPrototypeAndHasUnmodifiedL10n(); + } + CustomElementDefinition* definition = GetCustomElementDefinition(); // Only custom element which is in `custom` state could get the // CustomElementDefinition. diff --git a/dom/base/nsINode.h b/dom/base/nsINode.h index 556b28534b92..4643275eb351 100644 --- a/dom/base/nsINode.h +++ b/dom/base/nsINode.h @@ -1474,6 +1474,9 @@ class nsINode : public mozilla::dom::EventTarget { ElementMayHaveAnonymousChildren, // Set if element has CustomElementData. ElementHasCustomElementData, + // Set if the element was created from prototype cache and + // its l10n attributes haven't been changed. + ElementCreatedFromPrototypeAndHasUnmodifiedL10n, // Guard value BooleanFlagCount }; @@ -1611,6 +1614,16 @@ class nsINode : public mozilla::dom::EventTarget { return GetBoolFlag(ElementHasCustomElementData); } + void SetElementCreatedFromPrototypeAndHasUnmodifiedL10n() { + SetBoolFlag(ElementCreatedFromPrototypeAndHasUnmodifiedL10n); + } + bool HasElementCreatedFromPrototypeAndHasUnmodifiedL10n() { + return GetBoolFlag(ElementCreatedFromPrototypeAndHasUnmodifiedL10n); + } + void ClearElementCreatedFromPrototypeAndHasUnmodifiedL10n() { + ClearBoolFlag(ElementCreatedFromPrototypeAndHasUnmodifiedL10n); + } + protected: void SetParentIsContent(bool aValue) { SetBoolFlag(ParentIsContent, aValue); } void SetIsInDocument() { SetBoolFlag(IsInDocument); } diff --git a/dom/prototype/PrototypeDocumentContentSink.cpp b/dom/prototype/PrototypeDocumentContentSink.cpp index ff5a24440df5..e9e0da9abd3a 100644 --- a/dom/prototype/PrototypeDocumentContentSink.cpp +++ b/dom/prototype/PrototypeDocumentContentSink.cpp @@ -1054,6 +1054,7 @@ nsresult PrototypeDocumentContentSink::CreateElementFromPrototype( } } + result->SetElementCreatedFromPrototypeAndHasUnmodifiedL10n(); result.forget(aResult); return NS_OK;