Bug 700981 part 2. Get rid of nsStyledElement::BindToTree/UnbindFromTree. r=smaug

This commit is contained in:
Boris Zbarsky 2012-03-22 00:10:51 -04:00
parent d787c15480
commit 0993b53f4e
3 changed files with 29 additions and 50 deletions

View File

@ -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<nsStyledElement*>(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();

View File

@ -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

View File

@ -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