From 922ddb8a252cdae63f368f7cc5da486f7e278eb8 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 22 Mar 2012 00:10:51 -0400 Subject: [PATCH] Bug 700981 part 2. Get rid of nsStyledElement::BindToTree/UnbindFromTree. r=smaug --- content/base/src/nsGenericElement.cpp | 27 ++++++++++++++++ content/base/src/nsStyledElement.cpp | 45 --------------------------- content/base/src/nsStyledElement.h | 7 ++--- 3 files changed, 29 insertions(+), 50 deletions(-) diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 762de2d82e59..072467c1d589 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -159,6 +159,8 @@ #include "mozilla/CORSMode.h" +#include "nsStyledElement.h" + using namespace mozilla; using namespace mozilla::dom; @@ -3214,6 +3216,28 @@ nsGenericElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, nsNodeUtils::ParentChainChanged(this); + if (aDocument && HasID() && !aBindingParent) { + aDocument->AddToIdTable(this, DoGetID()); + } + + if (MayHaveStyle() && !IsXUL()) { + // XXXbz if we already have a style attr parsed, this won't do + // anything... need to fix that. + // If MayHaveStyle() is true, we must be an nsStyledElement + static_cast(this)->ReparseStyleAttribute(false); + } + + if (aDocument) { + // If we're in a document now, let our mapped attrs know what their new + // sheet is. This is safe to run for non-mapped-attribute elements too; + // it'll just do a small bit of unnecessary work. But most elements in + // practice are mapped-attribute elements. + nsHTMLStyleSheet* sheet = aDocument->GetAttributeStyleSheet(); + if (sheet) { + mAttrsAndChildren.SetMappedAttrStyleSheet(sheet); + } + } + // XXXbz script execution during binding can trigger some of these // postcondition asserts.... But we do want that, since things will // generally be quite broken when that happens. @@ -3231,6 +3255,9 @@ nsGenericElement::UnbindFromTree(bool aDeep, bool aNullParent) NS_PRECONDITION(aDeep || (!GetCurrentDoc() && !GetBindingParent()), "Shallow unbind won't clear document and binding parent on " "kids!"); + + RemoveFromIdTable(); + // Make sure to unbind this node before doing the kids nsIDocument *document = HasFlag(NODE_FORCE_XBL_BINDINGS) ? OwnerDoc() : GetCurrentDoc(); diff --git a/content/base/src/nsStyledElement.cpp b/content/base/src/nsStyledElement.cpp index 59c9cb0a1276..30527ffd7e21 100644 --- a/content/base/src/nsStyledElement.cpp +++ b/content/base/src/nsStyledElement.cpp @@ -220,51 +220,6 @@ nsStyledElementNotElementCSSInlineStyle::GetInlineStyleRule() return nsnull; } -nsresult -nsStyledElementNotElementCSSInlineStyle::BindToTree(nsIDocument* aDocument, - nsIContent* aParent, - nsIContent* aBindingParent, - bool aCompileEventHandlers) -{ - nsresult rv = nsStyledElementBase::BindToTree(aDocument, aParent, - aBindingParent, - aCompileEventHandlers); - NS_ENSURE_SUCCESS(rv, rv); - - if (aDocument && HasID() && !GetBindingParent()) { - aDocument->AddToIdTable(this, DoGetID()); - } - - if (!IsXUL()) { - // XXXbz if we already have a style attr parsed, this won't do - // anything... need to fix that. - ReparseStyleAttribute(false); - } - - if (aDocument) { - // If we're in a document now, let our mapped attrs know what their new - // sheet is. This is safe to run for non-mapped-attribute elements too; - // it'll just do a small bit of unnecessary work. But most elements in - // practice are mapped-attribute elements. - nsHTMLStyleSheet* sheet = aDocument->GetAttributeStyleSheet(); - if (sheet) { - mAttrsAndChildren.SetMappedAttrStyleSheet(sheet); - } - } - - return NS_OK; -} - -void -nsStyledElementNotElementCSSInlineStyle::UnbindFromTree(bool aDeep, - bool aNullParent) -{ - RemoveFromIdTable(); - - nsStyledElementBase::UnbindFromTree(aDeep, aNullParent); -} - - // --------------------------------------------------------------- // Others and helpers diff --git a/content/base/src/nsStyledElement.h b/content/base/src/nsStyledElement.h index 373a4e54a5a5..172ad27afa64 100644 --- a/content/base/src/nsStyledElement.h +++ b/content/base/src/nsStyledElement.h @@ -76,11 +76,6 @@ public: virtual mozilla::css::StyleRule* GetInlineStyleRule(); NS_IMETHOD SetInlineStyleRule(mozilla::css::StyleRule* aStyleRule, bool aNotify); - virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, - nsIContent* aBindingParent, - bool aCompileEventHandlers); - virtual void UnbindFromTree(bool aDeep, bool aNullParent); - virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute, bool aNotify); virtual nsresult AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute, @@ -104,6 +99,8 @@ protected: virtual bool ParseAttribute(PRInt32 aNamespaceID, nsIAtom* aAttribute, const nsAString& aValue, nsAttrValue& aResult); + friend class nsGenericElement; + /** * Create the style struct from the style attr. Used when an element is * first put into a document. Only has an effect if the old value is a