Make DOM classes start with a reference count of 1, like all other RefCounted
        
Patch by Darin Adler <darin@apple.com> on 2009-08-22
Reviewed by Oliver Hunt.

Next step: Element, HTMLElement, HTMLAnchorElement, HTMLAppletElement,
HTMLAreaElement, HTMLEmbedElement, HTMLFrameElement, HTMLIFrameElement,
HTMLObjectElement, HTMLPlugInElement, HTMLPlugInImageElement.

* DerivedSources.make: Fix error seen every time we build by escaping the $
in the build rule, since you have to use $$ for that in make.

* WebCore.base.exp: Updated.

* bindings/objc/DOM.mm:
Added now-needed include of SVGNames.h.

* dom/Document.cpp: Added now-needed include of SVGNames.h.
(WebCore::Document::createElement): Use create instead of new.

* dom/Element.cpp:
(WebCore::Element::Element): Added ConstructionType argument so the caller
can determine whether this starts with a reference count of either 0 or 1.
Later we will remove this again once they are all 1.
(WebCore::Element::create): Added.

* dom/Element.h: Added create and made constructor protected.

* dom/StyledElement.cpp:
(WebCore::StyledElement::StyledElement): Added ConstructionType argument.
* dom/StyledElement.h: Made many functions protected or private, including
the constructor.

* dom/make_names.pl: Use create to create the base elements HTMLElement,
SVGElement, and WMLElement.

* editing/CreateLinkCommand.cpp:
(WebCore::CreateLinkCommand::doApply): Use create instead of new.
* editing/UnlinkCommand.cpp:
(WebCore::UnlinkCommand::doApply): Ditto.

* html/HTMLAnchorElement.cpp:
(WebCore::HTMLAnchorElement::create): Added.
* html/HTMLAnchorElement.h: Made constructor protected and added create.
Also made m_rootEditableElementForSelectionOnMouseDown a RefPtr.

* html/HTMLAppletElement.cpp:
(WebCore::HTMLAppletElement::create): Added.
* html/HTMLAppletElement.h: Made constructor private and added create.

* html/HTMLAreaElement.cpp:
(WebCore::HTMLAreaElement::create): Added.
* html/HTMLAreaElement.h: Made constructor private and added create.

* html/HTMLElement.cpp:
(WebCore::HTMLElement::create): Added.
* html/HTMLElement.h: Made constructor protected and added create.
Made other functions protected and private. Also added inline
definition of constructor.

* html/HTMLEmbedElement.cpp:
(WebCore::HTMLEmbedElement::create): Added.
* html/HTMLEmbedElement.h: Made constructor private and added create.
Made other functions private.

* html/HTMLFrameElement.cpp:
(WebCore::HTMLFrameElement::create): Added.
(WebCore::HTMLFrameElement::parseMappedAttribute):
* html/HTMLFrameElement.h: Made constructor private and added create.
Made other functions private.

* html/HTMLFrameElementBase.h: Made functions protected and private.

* html/HTMLFrameOwnerElement.cpp:
(WebCore::HTMLFrameOwnerElement::HTMLFrameOwnerElement): Pass
CreateElement so reference count starts at 1.

* html/HTMLFrameOwnerElement.h: Made functions protected and private.

* html/HTMLIFrameElement.cpp:
(WebCore::HTMLIFrameElement::create): Added.
* html/HTMLIFrameElement.h: Made constructor private and added create.
Made other functions private.

* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::create): Added.
(WebCore::HTMLObjectElement::containsJavaApplet): Changed while loop
into a for loop and tweaked formatting.

* html/HTMLObjectElement.h: Made constructor private and added create.
Made other functions private.

* html/HTMLPlugInElement.h: Made constructor protected.
Made other functions protected and private.

* html/HTMLPlugInImageElement.h: Made constructor and another function
protected.

* html/HTMLTagNames.in: Removed createWithNew from all classes that
now have create functions. Moved conditional noscript to a separate
paragraph.

* html/HTMLViewSourceDocument.cpp:
(WebCore::HTMLViewSourceDocument::addSpanWithClassName): Use create.
(WebCore::HTMLViewSourceDocument::addLink): Ditto.
* page/DragController.cpp:
(WebCore::documentFragmentFromDragData): Ditto.

* svg/SVGElement.cpp:
(WebCore::SVGElement::SVGElement): Pass CreateElementZeroRefCount
so reference count still starts at 0. Will change this class later.
(WebCore::SVGElement::create): Added.
* svg/SVGElement.h: Added create, made constructor protected, and
made other functions protected and private. Removed unneeded
SVGNames.h include.

* svg/SVGExternalResourcesRequired.h: Added now-needed SVGNames.h
include.

* svg/SVGStopElement.h: Added now-needed SVGNames.h include.
Made functions private.

* wml/WMLElement.cpp:
(WebCore::WMLElement::WMLElement): Pass CreateElementZeroRefCount
so reference count still starts at 0. Will change this class later.
(WebCore::WMLElement::create): Added.
* wml/WMLElement.h: Added create and made constructor protected.

* wml/WMLTagNames.in: Removed createWithNew from WMLElement.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@47688 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 7c9ceab1..419d454 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,134 @@
+2009-08-22  Darin Adler  <darin@apple.com>
+
+        Reviewed by Oliver Hunt.
+
+        Make DOM classes start with a reference count of 1, like all other RefCounted
+        
+        Next step: Element, HTMLElement, HTMLAnchorElement, HTMLAppletElement,
+        HTMLAreaElement, HTMLEmbedElement, HTMLFrameElement, HTMLIFrameElement,
+        HTMLObjectElement, HTMLPlugInElement, HTMLPlugInImageElement.
+
+        * DerivedSources.make: Fix error seen every time we build by escaping the $
+        in the build rule, since you have to use $$ for that in make.
+
+        * WebCore.base.exp: Updated.
+
+        * bindings/objc/DOM.mm:
+        Added now-needed include of SVGNames.h.
+
+        * dom/Document.cpp: Added now-needed include of SVGNames.h.
+        (WebCore::Document::createElement): Use create instead of new.
+
+        * dom/Element.cpp:
+        (WebCore::Element::Element): Added ConstructionType argument so the caller
+        can determine whether this starts with a reference count of either 0 or 1.
+        Later we will remove this again once they are all 1.
+        (WebCore::Element::create): Added.
+
+        * dom/Element.h: Added create and made constructor protected.
+
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::StyledElement): Added ConstructionType argument.
+        * dom/StyledElement.h: Made many functions protected or private, including
+        the constructor.
+
+        * dom/make_names.pl: Use create to create the base elements HTMLElement,
+        SVGElement, and WMLElement.
+
+        * editing/CreateLinkCommand.cpp:
+        (WebCore::CreateLinkCommand::doApply): Use create instead of new.
+        * editing/UnlinkCommand.cpp:
+        (WebCore::UnlinkCommand::doApply): Ditto.
+
+        * html/HTMLAnchorElement.cpp:
+        (WebCore::HTMLAnchorElement::create): Added.
+        * html/HTMLAnchorElement.h: Made constructor protected and added create.
+        Also made m_rootEditableElementForSelectionOnMouseDown a RefPtr.
+
+        * html/HTMLAppletElement.cpp:
+        (WebCore::HTMLAppletElement::create): Added.
+        * html/HTMLAppletElement.h: Made constructor private and added create.
+
+        * html/HTMLAreaElement.cpp:
+        (WebCore::HTMLAreaElement::create): Added.
+        * html/HTMLAreaElement.h: Made constructor private and added create.
+
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::create): Added.
+        * html/HTMLElement.h: Made constructor protected and added create.
+        Made other functions protected and private. Also added inline
+        definition of constructor.
+
+        * html/HTMLEmbedElement.cpp:
+        (WebCore::HTMLEmbedElement::create): Added.
+        * html/HTMLEmbedElement.h: Made constructor private and added create.
+        Made other functions private.
+
+        * html/HTMLFrameElement.cpp:
+        (WebCore::HTMLFrameElement::create): Added.
+        (WebCore::HTMLFrameElement::parseMappedAttribute):
+        * html/HTMLFrameElement.h: Made constructor private and added create.
+        Made other functions private.
+
+        * html/HTMLFrameElementBase.h: Made functions protected and private.
+
+        * html/HTMLFrameOwnerElement.cpp:
+        (WebCore::HTMLFrameOwnerElement::HTMLFrameOwnerElement): Pass
+        CreateElement so reference count starts at 1.
+
+        * html/HTMLFrameOwnerElement.h: Made functions protected and private.
+
+        * html/HTMLIFrameElement.cpp:
+        (WebCore::HTMLIFrameElement::create): Added.
+        * html/HTMLIFrameElement.h: Made constructor private and added create.
+        Made other functions private.
+
+        * html/HTMLObjectElement.cpp:
+        (WebCore::HTMLObjectElement::create): Added.
+        (WebCore::HTMLObjectElement::containsJavaApplet): Changed while loop
+        into a for loop and tweaked formatting.
+
+        * html/HTMLObjectElement.h: Made constructor private and added create.
+        Made other functions private.
+
+        * html/HTMLPlugInElement.h: Made constructor protected.
+        Made other functions protected and private.
+
+        * html/HTMLPlugInImageElement.h: Made constructor and another function
+        protected.
+
+        * html/HTMLTagNames.in: Removed createWithNew from all classes that
+        now have create functions. Moved conditional noscript to a separate
+        paragraph.
+
+        * html/HTMLViewSourceDocument.cpp:
+        (WebCore::HTMLViewSourceDocument::addSpanWithClassName): Use create.
+        (WebCore::HTMLViewSourceDocument::addLink): Ditto.
+        * page/DragController.cpp:
+        (WebCore::documentFragmentFromDragData): Ditto.
+
+        * svg/SVGElement.cpp:
+        (WebCore::SVGElement::SVGElement): Pass CreateElementZeroRefCount
+        so reference count still starts at 0. Will change this class later.
+        (WebCore::SVGElement::create): Added.
+        * svg/SVGElement.h: Added create, made constructor protected, and
+        made other functions protected and private. Removed unneeded
+        SVGNames.h include.
+
+        * svg/SVGExternalResourcesRequired.h: Added now-needed SVGNames.h
+        include.
+
+        * svg/SVGStopElement.h: Added now-needed SVGNames.h include.
+        Made functions private.
+
+        * wml/WMLElement.cpp:
+        (WebCore::WMLElement::WMLElement): Pass CreateElementZeroRefCount
+        so reference count still starts at 0. Will change this class later.
+        (WebCore::WMLElement::create): Added.
+        * wml/WMLElement.h: Added create and made constructor protected.
+
+        * wml/WMLTagNames.in: Removed createWithNew from WMLElement.
+
 2009-08-22  Adele Peterson  <adele@apple.com>
 
         Reviewed by Anders Carlsson.
diff --git a/WebCore/DerivedSources.make b/WebCore/DerivedSources.make
index 4cdde30..578ec79 100644
--- a/WebCore/DerivedSources.make
+++ b/WebCore/DerivedSources.make
@@ -463,14 +463,14 @@
 # 2. Lines containing only whitespace
 # These two types of lines will be ignored by make{prop,values}.pl.
 CSSPropertyNames.h : $(WEBCORE_CSS_PROPERTY_NAMES) css/makeprop.pl
-	if sort $(WEBCORE_CSS_PROPERTY_NAMES) | uniq -d | grep -E -v '(^#)|(^[[:space:]]*$)'; then echo 'Duplicate value!'; exit 1; fi
+	if sort $(WEBCORE_CSS_PROPERTY_NAMES) | uniq -d | grep -E -v '(^#)|(^[[:space:]]*$$)'; then echo 'Duplicate value!'; exit 1; fi
 	cat $(WEBCORE_CSS_PROPERTY_NAMES) > CSSPropertyNames.in
 	perl "$(WebCore)/css/makeprop.pl"
 
 CSSValueKeywords.h : $(WEBCORE_CSS_VALUE_KEYWORDS) css/makevalues.pl
 	# Lower case all the values, as CSS values are case-insensitive
 	perl -ne 'print lc' $(WEBCORE_CSS_VALUE_KEYWORDS) > CSSValueKeywords.in
-	if sort CSSValueKeywords.in | uniq -d | grep -E -v '(^#)|(^[[:space:]]*$)'; then echo 'Duplicate value!'; exit 1; fi
+	if sort CSSValueKeywords.in | uniq -d | grep -E -v '(^#)|(^[[:space:]]*$$)'; then echo 'Duplicate value!'; exit 1; fi
 	perl "$(WebCore)/css/makevalues.pl"
 
 # --------
diff --git a/WebCore/WebCore.base.exp b/WebCore/WebCore.base.exp
index 90ff377..a013d6a 100644
--- a/WebCore/WebCore.base.exp
+++ b/WebCore/WebCore.base.exp
@@ -399,6 +399,7 @@
 __ZN7WebCore16threadGlobalDataEv
 __ZN7WebCore17DOMImplementation14isTextMIMETypeERKNS_6StringE
 __ZN7WebCore17GlyphPageTreeNode18treeGlyphPageCountEv
+__ZN7WebCore17HTMLPlugInElement11getNPObjectEv
 __ZN7WebCore17equalIgnoringCaseEPNS_10StringImplES1_
 __ZN7WebCore18deprecatedParseURLERKNS_6StringE
 __ZN7WebCore18isStartOfParagraphERKNS_15VisiblePositionE
diff --git a/WebCore/bindings/objc/DOM.mm b/WebCore/bindings/objc/DOM.mm
index 18c80bc..8d552e2 100644
--- a/WebCore/bindings/objc/DOM.mm
+++ b/WebCore/bindings/objc/DOM.mm
@@ -44,6 +44,7 @@
 #if ENABLE(SVG_DOM_OBJC_BINDINGS)
 #import "DOMSVG.h"
 #import "SVGElementInstance.h"
+#import "SVGNames.h"
 #endif
 
 using namespace JSC;
diff --git a/WebCore/dom/Document.cpp b/WebCore/dom/Document.cpp
index b7d910c..db8c92d 100644
--- a/WebCore/dom/Document.cpp
+++ b/WebCore/dom/Document.cpp
@@ -101,6 +101,7 @@
 #include "RenderTextControl.h"
 #include "RenderView.h"
 #include "RenderWidget.h"
+#include "SVGNames.h"
 #include "ScriptController.h"
 #include "ScriptElement.h"
 #include "ScriptEventListener.h"
@@ -795,7 +796,7 @@
 #endif
     
     if (!e)
-        e = new Element(qName, document());
+        e = Element::create(qName, document());
 
     // <image> uses imgTag so we need a special rule.
 #if ENABLE(WML)
diff --git a/WebCore/dom/Element.cpp b/WebCore/dom/Element.cpp
index 7aee10c..c4c23f0 100644
--- a/WebCore/dom/Element.cpp
+++ b/WebCore/dom/Element.cpp
@@ -57,12 +57,17 @@
 using namespace HTMLNames;
 using namespace XMLNames;
     
-Element::Element(const QualifiedName& tagName, Document* document)
-    : ContainerNode(document, CreateElementZeroRefCount)
+Element::Element(const QualifiedName& tagName, Document* document, ConstructionType type)
+    : ContainerNode(document, type)
     , m_tagName(tagName)
 {
 }
 
+PassRefPtr<Element> Element::create(const QualifiedName& tagName, Document* document)
+{
+    return adoptRef(new Element(tagName, document, CreateElement));
+}
+
 Element::~Element()
 {
     if (namedAttrMap)
diff --git a/WebCore/dom/Element.h b/WebCore/dom/Element.h
index 553e88a..e7a910c 100644
--- a/WebCore/dom/Element.h
+++ b/WebCore/dom/Element.h
@@ -41,7 +41,7 @@
 
 class Element : public ContainerNode {
 public:
-    Element(const QualifiedName&, Document*);
+    static PassRefPtr<Element> create(const QualifiedName&, Document*);
     virtual ~Element();
 
     const AtomicString& getIDAttribute() const;
@@ -208,6 +208,8 @@
     virtual void dispatchFormControlChangeEvent() { }
 
 protected:
+    Element(const QualifiedName&, Document*, ConstructionType);
+
     virtual void insertedIntoDocument();
     virtual void removedFromDocument();
     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
diff --git a/WebCore/dom/StyledElement.cpp b/WebCore/dom/StyledElement.cpp
index 6d77734..5212380 100644
--- a/WebCore/dom/StyledElement.cpp
+++ b/WebCore/dom/StyledElement.cpp
@@ -111,8 +111,8 @@
     m_synchronizingStyleAttribute = false;
 }
 
-StyledElement::StyledElement(const QualifiedName& name, Document *doc)
-    : Element(name, doc)
+StyledElement::StyledElement(const QualifiedName& name, Document* document, ConstructionType type)
+    : Element(name, document, type)
 {
 }
 
diff --git a/WebCore/dom/StyledElement.h b/WebCore/dom/StyledElement.h
index b4d6227..85fa7a7 100644
--- a/WebCore/dom/StyledElement.h
+++ b/WebCore/dom/StyledElement.h
@@ -3,7 +3,7 @@
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2001 Peter Kelly (pmk@post.com)
  *           (C) 2001 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -38,13 +38,11 @@
 
 class StyledElement : public Element {
 public:
-    StyledElement(const QualifiedName&, Document*);
     virtual ~StyledElement();
 
-    virtual bool isStyledElement() const { return true; }
-
     NamedMappedAttrMap* mappedAttributes() { return static_cast<NamedMappedAttrMap*>(namedAttrMap.get()); }
     const NamedMappedAttrMap* mappedAttributes() const { return static_cast<NamedMappedAttrMap*>(namedAttrMap.get()); }
+
     bool hasMappedAttributes() const { return namedAttrMap && mappedAttributes()->hasMappedAttributes(); }
     bool isMappedAttribute(const QualifiedName& name) const { MappedAttributeEntry res = eNone; mapToEntry(name, res); return res != eNone; }
 
@@ -53,38 +51,36 @@
     void addCSSProperty(MappedAttribute*, int id, int value);
     void addCSSImageProperty(MappedAttribute*, int propertyID, const String& url);
     void addCSSColor(MappedAttribute*, int id, const String& color);
-    void createMappedDecl(MappedAttribute*);
-    
+
     static CSSMappedAttributeDeclaration* getMappedAttributeDecl(MappedAttributeEntry, const QualifiedName& name, const AtomicString& value);
     static void setMappedAttributeDecl(MappedAttributeEntry, const QualifiedName& name, const AtomicString& value, CSSMappedAttributeDeclaration*);
     static void removeMappedAttributeDecl(MappedAttributeEntry, const QualifiedName& name, const AtomicString& value);
 
     static CSSMappedAttributeDeclaration* getMappedAttributeDecl(MappedAttributeEntry, Attribute*);
     static void setMappedAttributeDecl(MappedAttributeEntry, Attribute*, CSSMappedAttributeDeclaration*);
-    
+
     CSSMutableStyleDeclaration* inlineStyleDecl() const { return m_inlineStyleDecl.get(); }
     virtual bool canHaveAdditionalAttributeStyleDecls() const { return false; }
     virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&) {};
     CSSMutableStyleDeclaration* getInlineStyleDecl();
     CSSStyleDeclaration* style();
-    void createInlineStyleDecl();
-    void destroyInlineStyleDecl();
     void invalidateStyleAttribute();
-    virtual void updateStyleAttribute() const;
-    
+
     const ClassNames& classNames() const { ASSERT(hasClass()); ASSERT(mappedAttributes()); return mappedAttributes()->classNames(); }
 
+    virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
+
+    virtual PassRefPtr<Attribute> createAttribute(const QualifiedName&, const AtomicString& value);
+
+protected:
+    StyledElement(const QualifiedName&, Document*, ConstructionType);
+
     virtual void attributeChanged(Attribute*, bool preserveDecls = false);
     virtual void parseMappedAttribute(MappedAttribute*);
-    virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
-    virtual void createAttributeMap() const;
-    virtual PassRefPtr<Attribute> createAttribute(const QualifiedName&, const AtomicString& value);
-
     virtual void copyNonAttributeProperties(const Element*);
 
     virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
 
-protected:
     // classAttributeChanged() exists to share code between
     // parseMappedAttribute (called via setAttribute()) and
     // svgAttributeChanged (called when element.className.baseValue is set)
@@ -92,6 +88,17 @@
     
     virtual void didMoveToNewOwnerDocument();
 
+private:
+    virtual bool isStyledElement() const { return true; }
+
+    void createMappedDecl(MappedAttribute*);
+
+    void createInlineStyleDecl();
+    void destroyInlineStyleDecl();
+    virtual void updateStyleAttribute() const;
+
+    virtual void createAttributeMap() const;
+
     RefPtr<CSSMutableStyleDeclaration> m_inlineStyleDecl;
 };
 
diff --git a/WebCore/dom/make_names.pl b/WebCore/dom/make_names.pl
index ba20c8a..6b5ddb4 100755
--- a/WebCore/dom/make_names.pl
+++ b/WebCore/dom/make_names.pl
@@ -282,7 +282,7 @@
     if ($tags{$tagName}{wrapperOnlyIfMediaIsAvailable}) {
         print F <<END
     if (!MediaPlayer::isAvailable())
-        return new HTMLElement($constructorTagName, document);
+        return HTMLElement::create($constructorTagName, document);
 END
 ;
     }
@@ -756,7 +756,7 @@
     print F "        return function(qName, document, createdByParser);\n";
 }
 
-print F "    return new $parameters{namespace}Element(qName, document);\n";
+print F "    return $parameters{namespace}Element::create(qName, document);\n";
 
 if ($parameters{guardFactoryWith}) {
 
diff --git a/WebCore/editing/CreateLinkCommand.cpp b/WebCore/editing/CreateLinkCommand.cpp
index 98d6c6d..8499246 100644
--- a/WebCore/editing/CreateLinkCommand.cpp
+++ b/WebCore/editing/CreateLinkCommand.cpp
@@ -43,7 +43,7 @@
     if (endingSelection().isNone())
         return;
         
-    RefPtr<HTMLAnchorElement> anchorElement = new HTMLAnchorElement(document());
+    RefPtr<HTMLAnchorElement> anchorElement = HTMLAnchorElement::create(document());
     anchorElement->setHref(m_url);
     
     if (endingSelection().isRange()) {
diff --git a/WebCore/editing/UnlinkCommand.cpp b/WebCore/editing/UnlinkCommand.cpp
index 0ba9a06..7234a3b 100644
--- a/WebCore/editing/UnlinkCommand.cpp
+++ b/WebCore/editing/UnlinkCommand.cpp
@@ -37,14 +37,13 @@
 
 void UnlinkCommand::doApply()
 {
-    // FIXME: If a caret is inside a link, remove it.
+    // FIXME: If a caret is inside a link, we should remove it, but currently we don't.
     if (!endingSelection().isRange())
         return;
         
     pushPartiallySelectedAnchorElementsDown();
 
-    HTMLAnchorElement* anchorElement = new HTMLAnchorElement(document());
-    removeStyledElement(anchorElement);
+    removeStyledElement(HTMLAnchorElement::create(document()));
 }
 
 }
diff --git a/WebCore/html/HTMLAnchorElement.cpp b/WebCore/html/HTMLAnchorElement.cpp
index 1515460..0d3546d 100644
--- a/WebCore/html/HTMLAnchorElement.cpp
+++ b/WebCore/html/HTMLAnchorElement.cpp
@@ -40,18 +40,20 @@
 
 using namespace HTMLNames;
 
-HTMLAnchorElement::HTMLAnchorElement(Document* document)
-    : HTMLElement(aTag, document)
-    , m_rootEditableElementForSelectionOnMouseDown(0)
+HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tagName, Document* document)
+    : HTMLElement(tagName, document, CreateElement)
     , m_wasShiftKeyDownOnMouseDown(false)
 {
 }
 
-HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tagName, Document* document)
-    : HTMLElement(tagName, document)
-    , m_rootEditableElementForSelectionOnMouseDown(0)
-    , m_wasShiftKeyDownOnMouseDown(false)
+PassRefPtr<HTMLAnchorElement> HTMLAnchorElement::create(Document* document)
 {
+    return adoptRef(new HTMLAnchorElement(aTag, document));
+}
+
+PassRefPtr<HTMLAnchorElement> HTMLAnchorElement::create(const QualifiedName& tagName, Document* document)
+{
+    return adoptRef(new HTMLAnchorElement(tagName, document));
 }
 
 bool HTMLAnchorElement::supportsFocus() const
diff --git a/WebCore/html/HTMLAnchorElement.h b/WebCore/html/HTMLAnchorElement.h
index 3c73118..ab037c7 100644
--- a/WebCore/html/HTMLAnchorElement.h
+++ b/WebCore/html/HTMLAnchorElement.h
@@ -30,8 +30,8 @@
 
 class HTMLAnchorElement : public HTMLElement {
 public:
-    HTMLAnchorElement(Document*);
-    HTMLAnchorElement(const QualifiedName&, Document*);
+    static PassRefPtr<HTMLAnchorElement> create(Document*);
+    static PassRefPtr<HTMLAnchorElement> create(const QualifiedName&, Document*);
 
     KURL href() const;
     void setHref(const AtomicString&);
@@ -52,6 +52,8 @@
     bool isLiveLink() const;
 
 protected:
+    HTMLAnchorElement(const QualifiedName&, Document*);
+
     virtual void parseMappedAttribute(MappedAttribute*);
 
 private:
@@ -70,7 +72,7 @@
     virtual short tabIndex() const;
     virtual bool draggable() const;
 
-    Element* m_rootEditableElementForSelectionOnMouseDown;
+    RefPtr<Element> m_rootEditableElementForSelectionOnMouseDown;
     bool m_wasShiftKeyDownOnMouseDown;
 };
 
diff --git a/WebCore/html/HTMLAppletElement.cpp b/WebCore/html/HTMLAppletElement.cpp
index dfa2597..46045d6f 100644
--- a/WebCore/html/HTMLAppletElement.cpp
+++ b/WebCore/html/HTMLAppletElement.cpp
@@ -34,12 +34,17 @@
 
 using namespace HTMLNames;
 
-HTMLAppletElement::HTMLAppletElement(const QualifiedName& tagName, Document* doc)
-    : HTMLPlugInElement(tagName, doc)
+inline HTMLAppletElement::HTMLAppletElement(const QualifiedName& tagName, Document* document)
+    : HTMLPlugInElement(tagName, document)
 {
     ASSERT(hasTagName(appletTag));
 }
 
+PassRefPtr<HTMLAppletElement> HTMLAppletElement::create(const QualifiedName& tagName, Document* document)
+{
+    return adoptRef(new HTMLAppletElement(tagName, document));
+}
+
 void HTMLAppletElement::parseMappedAttribute(MappedAttribute* attr)
 {
     if (attr->name() == altAttr ||
diff --git a/WebCore/html/HTMLAppletElement.h b/WebCore/html/HTMLAppletElement.h
index 0813cc5..baaab38 100644
--- a/WebCore/html/HTMLAppletElement.h
+++ b/WebCore/html/HTMLAppletElement.h
@@ -29,7 +29,7 @@
 
 class HTMLAppletElement : public HTMLPlugInElement {
 public:
-    HTMLAppletElement(const QualifiedName&, Document*);
+    static PassRefPtr<HTMLAppletElement> create(const QualifiedName&, Document*);
 
     String hspace() const;
     void setHspace(const String&);
@@ -38,6 +38,8 @@
     void setVspace(const String&);
 
 private:
+    HTMLAppletElement(const QualifiedName&, Document*);
+
     virtual int tagPriority() const { return 1; }
 
     virtual void parseMappedAttribute(MappedAttribute*);
diff --git a/WebCore/html/HTMLAreaElement.cpp b/WebCore/html/HTMLAreaElement.cpp
index b2e4129..758fada 100644
--- a/WebCore/html/HTMLAreaElement.cpp
+++ b/WebCore/html/HTMLAreaElement.cpp
@@ -34,7 +34,7 @@
 
 using namespace HTMLNames;
 
-HTMLAreaElement::HTMLAreaElement(const QualifiedName& tagName, Document* document)
+inline HTMLAreaElement::HTMLAreaElement(const QualifiedName& tagName, Document* document)
     : HTMLAnchorElement(tagName, document)
     , m_coordsLen(0)
     , m_lastSize(-1, -1)
@@ -43,8 +43,9 @@
     ASSERT(hasTagName(areaTag));
 }
 
-HTMLAreaElement::~HTMLAreaElement()
+PassRefPtr<HTMLAreaElement> HTMLAreaElement::create(const QualifiedName& tagName, Document* document)
 {
+    return adoptRef(new HTMLAreaElement(tagName, document));
 }
 
 void HTMLAreaElement::parseMappedAttribute(MappedAttribute* attr)
diff --git a/WebCore/html/HTMLAreaElement.h b/WebCore/html/HTMLAreaElement.h
index fd308b6..a93bede 100644
--- a/WebCore/html/HTMLAreaElement.h
+++ b/WebCore/html/HTMLAreaElement.h
@@ -34,8 +34,7 @@
 
 class HTMLAreaElement : public HTMLAnchorElement {
 public:
-    HTMLAreaElement(const QualifiedName&, Document*);
-    virtual ~HTMLAreaElement();
+    static PassRefPtr<HTMLAreaElement> create(const QualifiedName&, Document*);
 
     bool isDefault() const { return m_shape == Default; }
 
@@ -49,6 +48,8 @@
     void setNoHref(bool);
 
 private:
+    HTMLAreaElement(const QualifiedName&, Document*);
+
     virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; }
     virtual int tagPriority() const { return 0; }
     virtual void parseMappedAttribute(MappedAttribute*);
diff --git a/WebCore/html/HTMLElement.cpp b/WebCore/html/HTMLElement.cpp
index 2964381..57f66e5 100644
--- a/WebCore/html/HTMLElement.cpp
+++ b/WebCore/html/HTMLElement.cpp
@@ -56,13 +56,9 @@
 using std::min;
 using std::max;
 
-HTMLElement::HTMLElement(const QualifiedName& tagName, Document *doc)
-    : StyledElement(tagName, doc)
+PassRefPtr<HTMLElement> HTMLElement::create(const QualifiedName& tagName, Document* document)
 {
-}
-
-HTMLElement::~HTMLElement()
-{
+    return adoptRef(new HTMLElement(tagName, document, CreateElement));
 }
 
 String HTMLElement::nodeName() const
diff --git a/WebCore/html/HTMLElement.h b/WebCore/html/HTMLElement.h
index d7485e8..fbce508 100644
--- a/WebCore/html/HTMLElement.h
+++ b/WebCore/html/HTMLElement.h
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -35,19 +35,12 @@
                        
 class HTMLElement : public StyledElement {
 public:
-    HTMLElement(const QualifiedName& tagName, Document*);
-    virtual ~HTMLElement();
-
-    virtual bool isHTMLElement() const { return true; }
-
-    virtual String nodeName() const;
-
-    virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
-    virtual void parseMappedAttribute(MappedAttribute*);
+    static PassRefPtr<HTMLElement> create(const QualifiedName& tagName, Document*);
 
     PassRefPtr<HTMLCollection> children();
     
     virtual String title() const;
+
     virtual short tabIndex() const;
     void setTabIndex(int);
 
@@ -63,12 +56,11 @@
     void insertAdjacentHTML(const String& where, const String& html, ExceptionCode&);
     void insertAdjacentText(const String& where, const String& text, ExceptionCode&);
 
-    virtual bool isFocusable() const;
     virtual bool isContentEditable() const;
     virtual bool isContentRichlyEditable() const;
-    virtual String contentEditable() const;
-    virtual void setContentEditable(MappedAttribute*);
-    virtual void setContentEditable(const String&);
+
+    String contentEditable() const;
+    void setContentEditable(const String&);
 
     virtual bool draggable() const;
     void setDraggable(bool);
@@ -79,31 +71,53 @@
 
     virtual HTMLTagStatus endTagRequirement() const;
     virtual int tagPriority() const;
-    virtual bool childAllowed(Node* newChild); // Error-checking during parsing that checks the DTD
-
-    // Helper function to check the DTD for a given child node.
-    virtual bool checkDTD(const Node*);
-    static bool inEitherTagList(const Node*);
-    static bool inInlineTagList(const Node*);
-    static bool inBlockTagList(const Node*);
-    static bool isRecognizedTagName(const QualifiedName&);
 
     virtual bool rendererIsNeeded(RenderStyle*);
     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
 
     HTMLFormElement* form() const { return virtualForm(); }
-    HTMLFormElement* findFormAncestor() const;
 
     static void addHTMLAlignmentToStyledElement(StyledElement*, MappedAttribute*);
 
 protected:
+    HTMLElement(const QualifiedName& tagName, Document*, ConstructionType = CreateElementZeroRefCount);
+
     void addHTMLAlignment(MappedAttribute*);
 
+    virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
+    virtual void parseMappedAttribute(MappedAttribute*);
+
+    virtual bool isFocusable() const;
+
+    virtual bool childAllowed(Node* newChild); // Error-checking during parsing that checks the DTD
+
+    // Helper function to check the DTD for a given child node.
+    virtual bool checkDTD(const Node*);
+
+    static bool inEitherTagList(const Node*);
+    static bool inInlineTagList(const Node*);
+    static bool inBlockTagList(const Node*);
+    static bool isRecognizedTagName(const QualifiedName&);
+
+    HTMLFormElement* findFormAncestor() const;
+
 private:
+    virtual bool isHTMLElement() const { return true; }
+
+    virtual String nodeName() const;
+
+    void setContentEditable(MappedAttribute*);
+
     virtual HTMLFormElement* virtualForm() const;
+
     Node* insertAdjacent(const String& where, Node* newChild, ExceptionCode&);
 };
 
+inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document* document, ConstructionType type)
+    : StyledElement(tagName, document, type)
+{
+}
+
 } // namespace WebCore
 
 #endif // HTMLElement_h
diff --git a/WebCore/html/HTMLEmbedElement.cpp b/WebCore/html/HTMLEmbedElement.cpp
index 54e56cc..81b88a4 100644
--- a/WebCore/html/HTMLEmbedElement.cpp
+++ b/WebCore/html/HTMLEmbedElement.cpp
@@ -2,7 +2,7 @@
  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2000 Stefan Schimanski (1Stein@gmx.de)
- * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved.
  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
  *
  * This library is free software; you can redistribute it and/or
@@ -42,13 +42,18 @@
 
 using namespace HTMLNames;
 
-HTMLEmbedElement::HTMLEmbedElement(const QualifiedName& tagName, Document* doc)
-    : HTMLPlugInImageElement(tagName, doc)
+inline HTMLEmbedElement::HTMLEmbedElement(const QualifiedName& tagName, Document* document)
+    : HTMLPlugInImageElement(tagName, document)
     , m_needWidgetUpdate(false)
 {
     ASSERT(hasTagName(embedTag));
 }
 
+PassRefPtr<HTMLEmbedElement> HTMLEmbedElement::create(const QualifiedName& tagName, Document* document)
+{
+    return adoptRef(new HTMLEmbedElement(tagName, document));
+}
+
 static inline RenderWidget* findWidgetRenderer(const Node* n) 
 {
     if (!n->renderer())
diff --git a/WebCore/html/HTMLEmbedElement.h b/WebCore/html/HTMLEmbedElement.h
index 19a1aa2..16f0893 100644
--- a/WebCore/html/HTMLEmbedElement.h
+++ b/WebCore/html/HTMLEmbedElement.h
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
- * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2006, 2008, 2009 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -29,6 +29,11 @@
 
 class HTMLEmbedElement : public HTMLPlugInImageElement {
 public:
+    static PassRefPtr<HTMLEmbedElement> create(const QualifiedName&, Document*);
+
+    void setNeedWidgetUpdate(bool needWidgetUpdate) { m_needWidgetUpdate = needWidgetUpdate; }
+
+private:
     HTMLEmbedElement(const QualifiedName&, Document*);
 
     virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; }
@@ -49,13 +54,11 @@
     virtual const QualifiedName& imageSourceAttributeName() const;
 
     virtual void updateWidget();
-    void setNeedWidgetUpdate(bool needWidgetUpdate) { m_needWidgetUpdate = needWidgetUpdate; }
 
     virtual RenderWidget* renderWidgetForJSBindings() const;
 
     virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
 
-private:
     bool m_needWidgetUpdate;
 };
 
diff --git a/WebCore/html/HTMLFrameElement.cpp b/WebCore/html/HTMLFrameElement.cpp
index d87386f..b456ac3 100644
--- a/WebCore/html/HTMLFrameElement.cpp
+++ b/WebCore/html/HTMLFrameElement.cpp
@@ -34,7 +34,7 @@
 
 using namespace HTMLNames;
 
-HTMLFrameElement::HTMLFrameElement(const QualifiedName& tagName, Document* document)
+inline HTMLFrameElement::HTMLFrameElement(const QualifiedName& tagName, Document* document)
     : HTMLFrameElementBase(tagName, document)
     , m_frameBorder(true)
     , m_frameBorderSet(false)
@@ -43,6 +43,11 @@
     ASSERT(hasTagName(frameTag));
 }
 
+PassRefPtr<HTMLFrameElement> HTMLFrameElement::create(const QualifiedName& tagName, Document* document)
+{
+    return adoptRef(new HTMLFrameElement(tagName, document));
+}
+
 bool HTMLFrameElement::rendererIsNeeded(RenderStyle*)
 {
     // For compatibility, frames render even when display: none is set.
@@ -56,9 +61,10 @@
 
 static inline HTMLFrameSetElement* containingFrameSetElement(Node* node)
 {
-    while ((node = node->parentNode()))
+    while ((node = node->parentNode())) {
         if (node->hasTagName(framesetTag))
             return static_cast<HTMLFrameSetElement*>(node);
+    }
     return 0;
 }
 
@@ -74,7 +80,7 @@
     }
 }
 
-void HTMLFrameElement::parseMappedAttribute(MappedAttribute *attr)
+void HTMLFrameElement::parseMappedAttribute(MappedAttribute* attr)
 {
     if (attr->name() == frameborderAttr) {
         m_frameBorder = attr->value().toInt();
diff --git a/WebCore/html/HTMLFrameElement.h b/WebCore/html/HTMLFrameElement.h
index c3d2478..4a8e16c 100644
--- a/WebCore/html/HTMLFrameElement.h
+++ b/WebCore/html/HTMLFrameElement.h
@@ -30,6 +30,14 @@
 
 class HTMLFrameElement : public HTMLFrameElementBase {
 public:
+    static PassRefPtr<HTMLFrameElement> create(const QualifiedName&, Document*);
+
+    bool hasFrameBorder() const { return m_frameBorder; }
+
+    bool noResize() const { return m_noResize; }
+    void setNoResize(bool);
+
+private:
     HTMLFrameElement(const QualifiedName&, Document*);
 
     virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; }
@@ -42,12 +50,6 @@
     
     virtual void parseMappedAttribute(MappedAttribute*);
 
-    bool hasFrameBorder() const { return m_frameBorder; }
-
-    bool noResize() const { return m_noResize; }
-    void setNoResize(bool);
-
-private:
     bool m_frameBorder;
     bool m_frameBorderSet;
 
diff --git a/WebCore/html/HTMLFrameElementBase.h b/WebCore/html/HTMLFrameElementBase.h
index f4ba868..22ff42a 100644
--- a/WebCore/html/HTMLFrameElementBase.h
+++ b/WebCore/html/HTMLFrameElementBase.h
@@ -31,22 +31,9 @@
 
 class HTMLFrameElementBase : public HTMLFrameOwnerElement {
 public:
-    virtual void parseMappedAttribute(MappedAttribute*);
-
-    virtual void insertedIntoDocument();
-    virtual void removedFromDocument();
-
-    virtual void attach();
-    virtual bool canLazyAttach() { return false; }
-
     KURL location() const;
     void setLocation(const String&);
 
-    virtual bool isFocusable() const;
-    virtual void setFocus(bool);
-    
-    virtual bool isURLAttribute(Attribute*) const;
-
     virtual ScrollbarMode scrollingMode() const { return m_scrolling; }
     
     int getMarginWidth() const { return m_marginWidth; }
@@ -55,12 +42,28 @@
     int width() const;
     int height() const;
 
-    bool viewSourceMode() const { return m_viewSource; }
-
 protected:
     HTMLFrameElementBase(const QualifiedName&, Document*);
 
     bool isURLAllowed() const;
+
+    virtual void parseMappedAttribute(MappedAttribute*);
+
+    virtual void insertedIntoDocument();
+    virtual void removedFromDocument();
+
+    virtual void attach();
+
+private:
+    virtual bool canLazyAttach() { return false; }
+
+    virtual bool isFocusable() const;
+    virtual void setFocus(bool);
+    
+    virtual bool isURLAttribute(Attribute*) const;
+
+    bool viewSourceMode() const { return m_viewSource; }
+
     void setNameAndOpenURL();
     void openURL();
 
diff --git a/WebCore/html/HTMLFrameOwnerElement.cpp b/WebCore/html/HTMLFrameOwnerElement.cpp
index a98a3df..84958c2 100644
--- a/WebCore/html/HTMLFrameOwnerElement.cpp
+++ b/WebCore/html/HTMLFrameOwnerElement.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -33,7 +33,7 @@
 namespace WebCore {
 
 HTMLFrameOwnerElement::HTMLFrameOwnerElement(const QualifiedName& tagName, Document* document)
-    : HTMLElement(tagName, document)
+    : HTMLElement(tagName, document, CreateElement)
     , m_contentFrame(0)
 {
 }
diff --git a/WebCore/html/HTMLFrameOwnerElement.h b/WebCore/html/HTMLFrameOwnerElement.h
index 3f50a02..1437e2c 100644
--- a/WebCore/html/HTMLFrameOwnerElement.h
+++ b/WebCore/html/HTMLFrameOwnerElement.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -27,36 +27,36 @@
 
 class DOMWindow;
 class Frame;
-class KeyboardEvent;
 
 #if ENABLE(SVG)
 class SVGDocument;
 #endif
 
 class HTMLFrameOwnerElement : public HTMLElement {
-protected:
-    HTMLFrameOwnerElement(const QualifiedName& tagName, Document*);
-
 public:
     virtual ~HTMLFrameOwnerElement();
 
-    virtual void willRemove();
-
     Frame* contentFrame() const { return m_contentFrame; }
     DOMWindow* contentWindow() const;
     Document* contentDocument() const;
 
-    virtual bool isFrameOwnerElement() const { return true; }
-    virtual bool isKeyboardFocusable(KeyboardEvent*) const { return m_contentFrame; }
-    
-    virtual ScrollbarMode scrollingMode() const { return ScrollbarAuto; }
-
 #if ENABLE(SVG)
     SVGDocument* getSVGDocument(ExceptionCode&) const;
 #endif
 
+    virtual ScrollbarMode scrollingMode() const { return ScrollbarAuto; }
+
+protected:
+    HTMLFrameOwnerElement(const QualifiedName& tagName, Document*);
+
 private:
     friend class Frame;
+
+    virtual bool isFrameOwnerElement() const { return true; }
+    virtual bool isKeyboardFocusable(KeyboardEvent*) const { return m_contentFrame; }
+    
+    virtual void willRemove();
+
     Frame* m_contentFrame;
 };
 
diff --git a/WebCore/html/HTMLIFrameElement.cpp b/WebCore/html/HTMLIFrameElement.cpp
index d02288ec..cae9b8d 100644
--- a/WebCore/html/HTMLIFrameElement.cpp
+++ b/WebCore/html/HTMLIFrameElement.cpp
@@ -35,12 +35,17 @@
 
 using namespace HTMLNames;
 
-HTMLIFrameElement::HTMLIFrameElement(const QualifiedName& tagName, Document* document)
+inline HTMLIFrameElement::HTMLIFrameElement(const QualifiedName& tagName, Document* document)
     : HTMLFrameElementBase(tagName, document)
 {
     ASSERT(hasTagName(iframeTag));
 }
 
+PassRefPtr<HTMLIFrameElement> HTMLIFrameElement::create(const QualifiedName& tagName, Document* document)
+{
+    return adoptRef(new HTMLIFrameElement(tagName, document));
+}
+
 bool HTMLIFrameElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
 {
     if (attrName == widthAttr || attrName == heightAttr) {
diff --git a/WebCore/html/HTMLIFrameElement.h b/WebCore/html/HTMLIFrameElement.h
index 4e9ab50..f1c6a35 100644
--- a/WebCore/html/HTMLIFrameElement.h
+++ b/WebCore/html/HTMLIFrameElement.h
@@ -2,7 +2,7 @@
  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2000 Simon Hausmann <hausmann@kde.org>
- * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2006, 2008, 2009 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -30,6 +30,9 @@
 
 class HTMLIFrameElement : public HTMLFrameElementBase {
 public:
+    static PassRefPtr<HTMLIFrameElement> create(const QualifiedName&, Document*);
+
+private:
     HTMLIFrameElement(const QualifiedName&, Document*);
 
     virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; }
@@ -48,7 +51,6 @@
     
     virtual bool isURLAttribute(Attribute*) const;
 
-private:
     AtomicString m_name;
 };
 
diff --git a/WebCore/html/HTMLObjectElement.cpp b/WebCore/html/HTMLObjectElement.cpp
index d3fdec7..9765c43 100644
--- a/WebCore/html/HTMLObjectElement.cpp
+++ b/WebCore/html/HTMLObjectElement.cpp
@@ -2,7 +2,7 @@
  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2000 Stefan Schimanski (1Stein@gmx.de)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
  *
  * This library is free software; you can redistribute it and/or
@@ -45,8 +45,8 @@
 
 using namespace HTMLNames;
 
-HTMLObjectElement::HTMLObjectElement(const QualifiedName& tagName, Document* doc, bool createdByParser) 
-    : HTMLPlugInImageElement(tagName, doc)
+inline HTMLObjectElement::HTMLObjectElement(const QualifiedName& tagName, Document* document, bool createdByParser) 
+    : HTMLPlugInImageElement(tagName, document)
     , m_docNamedItem(true)
     , m_needWidgetUpdate(!createdByParser)
     , m_useFallbackContent(false)
@@ -54,6 +54,11 @@
     ASSERT(hasTagName(objectTag));
 }
 
+PassRefPtr<HTMLObjectElement> HTMLObjectElement::create(const QualifiedName& tagName, Document* document, bool createdByParser)
+{
+    return adoptRef(new HTMLObjectElement(tagName, document, createdByParser));
+}
+
 RenderWidget* HTMLObjectElement::renderWidgetForJSBindings() const
 {
     RenderWidget* renderWidget = (renderer() && renderer()->isWidget()) ? toRenderWidget(renderer()) : 0;
@@ -328,18 +333,16 @@
     if (MIMETypeRegistry::isJavaAppletMIMEType(getAttribute(typeAttr)))
         return true;
         
-    Node* child = firstChild();
-    while (child) {
-        if (child->isElementNode()) {
-            Element* e = static_cast<Element*>(child);
-            if (e->hasTagName(paramTag) && equalIgnoringCase(e->getAttribute(nameAttr), "type") && MIMETypeRegistry::isJavaAppletMIMEType(e->getAttribute(valueAttr).string()))
-                return true;
-            else if (e->hasTagName(objectTag) && static_cast<HTMLObjectElement*>(e)->containsJavaApplet())
-                return true;
-            else if (e->hasTagName(appletTag))
-                return true;
-        }
-        child = child->nextSibling();
+    for (Element* child = firstElementChild(); child; child = child->nextElementSibling()) {
+        if (child->hasTagName(paramTag)
+                && equalIgnoringCase(child->getAttribute(nameAttr), "type")
+                && MIMETypeRegistry::isJavaAppletMIMEType(child->getAttribute(valueAttr).string()))
+            return true;
+        if (child->hasTagName(objectTag)
+                && static_cast<HTMLObjectElement*>(child)->containsJavaApplet())
+            return true;
+        if (child->hasTagName(appletTag))
+            return true;
     }
     
     return false;
diff --git a/WebCore/html/HTMLObjectElement.h b/WebCore/html/HTMLObjectElement.h
index 00b1020..ec1132f 100644
--- a/WebCore/html/HTMLObjectElement.h
+++ b/WebCore/html/HTMLObjectElement.h
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
- * Copyright (C) 2004, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -27,10 +27,30 @@
 
 namespace WebCore {
 
-class KURL;
-
 class HTMLObjectElement : public HTMLPlugInImageElement {
 public:
+    static PassRefPtr<HTMLObjectElement> create(const QualifiedName&, Document*, bool createdByParser);
+
+    void setNeedWidgetUpdate(bool needWidgetUpdate) { m_needWidgetUpdate = needWidgetUpdate; }
+
+    void renderFallbackContent();
+
+    bool declare() const;
+    void setDeclare(bool);
+
+    int hspace() const;
+    void setHspace(int);
+
+    int vspace() const;
+    void setVspace(int);
+
+    bool isDocNamedItem() const { return m_docNamedItem; }
+
+    const String& classId() const { return m_classId; }
+
+    bool containsJavaApplet() const;
+
+private:
     HTMLObjectElement(const QualifiedName&, Document*, bool createdByParser);
 
     virtual int tagPriority() const { return 5; }
@@ -53,30 +73,11 @@
     virtual const QualifiedName& imageSourceAttributeName() const;
 
     virtual void updateWidget();
-    void setNeedWidgetUpdate(bool needWidgetUpdate) { m_needWidgetUpdate = needWidgetUpdate; }
-
-    void renderFallbackContent();
 
     virtual RenderWidget* renderWidgetForJSBindings() const;
 
-    bool declare() const;
-    void setDeclare(bool);
-
-    int hspace() const;
-    void setHspace(int);
-
-    int vspace() const;
-    void setVspace(int);
-
-    bool isDocNamedItem() const { return m_docNamedItem; }
-
-    const String& classId() const { return m_classId; }
-
-    bool containsJavaApplet() const;
-
     virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
 
-private:
     void updateDocNamedItem();
 
     AtomicString m_id;
diff --git a/WebCore/html/HTMLPlugInElement.h b/WebCore/html/HTMLPlugInElement.h
index 93eee22..9d3dc6d 100644
--- a/WebCore/html/HTMLPlugInElement.h
+++ b/WebCore/html/HTMLPlugInElement.h
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
- * Copyright (C) 2004, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -36,37 +36,44 @@
 
 class HTMLPlugInElement : public HTMLFrameOwnerElement {
 public:
-    HTMLPlugInElement(const QualifiedName& tagName, Document*);
     virtual ~HTMLPlugInElement();
 
-    virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
-    virtual void parseMappedAttribute(MappedAttribute*);
-
-    virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; }
-    virtual bool checkDTD(const Node* newChild);
-
-    virtual void updateWidget() { }
-
     String height() const;
     void setHeight(const String&);
     
     String width() const;
     void setWidth(const String&);
 
-    virtual void defaultEventHandler(Event*);
-
-    virtual RenderWidget* renderWidgetForJSBindings() const = 0;
-    virtual void detach();
     PassScriptInstance getInstance() const;
 
 #if ENABLE(NETSCAPE_PLUGIN_API)
-    virtual NPObject* getNPObject();
+    NPObject* getNPObject();
 #endif
 
 protected:
+    HTMLPlugInElement(const QualifiedName& tagName, Document*);
+
+    virtual void detach();
+
     static void updateWidgetCallback(Node*);
 
+    virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
+    virtual void parseMappedAttribute(MappedAttribute*);
+
+private:
+    virtual void defaultEventHandler(Event*);
+
+    virtual RenderWidget* renderWidgetForJSBindings() const = 0;
+
+    virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; }
+    virtual bool checkDTD(const Node* newChild);
+
+    virtual void updateWidget() { }
+
+protected:
     AtomicString m_name;
+
+private:
     mutable ScriptInstance m_instance;
 #if ENABLE(NETSCAPE_PLUGIN_API)
     NPObject* m_NPObject;
diff --git a/WebCore/html/HTMLPlugInImageElement.h b/WebCore/html/HTMLPlugInImageElement.h
index ec3b258..7725a5a 100644
--- a/WebCore/html/HTMLPlugInImageElement.h
+++ b/WebCore/html/HTMLPlugInImageElement.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -30,15 +30,16 @@
 
 class HTMLPlugInImageElement : public HTMLPlugInElement {
 public:
-    HTMLPlugInImageElement(const QualifiedName& tagName, Document*);
     virtual ~HTMLPlugInImageElement();
 
-    bool isImageType();
-
     const String& serviceType() const { return m_serviceType; }
     const String& url() const { return m_url; }
 
 protected:
+    HTMLPlugInImageElement(const QualifiedName& tagName, Document*);
+
+    bool isImageType();
+
     OwnPtr<HTMLImageLoader> m_imageLoader;
     String m_serviceType;
     String m_url;
diff --git a/WebCore/html/HTMLTagNames.in b/WebCore/html/HTMLTagNames.in
index 34c9995..8842b23 100644
--- a/WebCore/html/HTMLTagNames.in
+++ b/WebCore/html/HTMLTagNames.in
@@ -2,27 +2,27 @@
 namespacePrefix="xhtml"
 namespaceURI="http://www.w3.org/1999/xhtml"
 
-a interfaceName=HTMLAnchorElement, createWithNew
-abbr interfaceName=HTMLElement, createWithNew
-acronym interfaceName=HTMLElement, createWithNew
-address interfaceName=HTMLElement, createWithNew
-applet createWithNew
-area createWithNew
+a interfaceName=HTMLAnchorElement
+abbr interfaceName=HTMLElement
+acronym interfaceName=HTMLElement
+address interfaceName=HTMLElement
+applet
+area
 audio wrapperOnlyIfMediaIsAvailable, conditional=VIDEO, createWithNew
-b interfaceName=HTMLElement, createWithNew
+b interfaceName=HTMLElement
 base createWithNew
 basefont interfaceName=HTMLBaseFontElement, createWithNew
-bdo interfaceName=HTMLElement, createWithNew
-big interfaceName=HTMLElement, createWithNew
+bdo interfaceName=HTMLElement
+big interfaceName=HTMLElement
 blockquote createWithNew
 body createWithNew
 br interfaceName=HTMLBRElement, createWithNew
 button constructorNeedsFormElement, createWithNew
 canvas createWithNew
 caption interfaceName=HTMLTableCaptionElement, createWithNew
-center interfaceName=HTMLElement, createWithNew
-cite interfaceName=HTMLElement, createWithNew
-code interfaceName=HTMLElement, createWithNew
+center interfaceName=HTMLElement
+cite interfaceName=HTMLElement
+code interfaceName=HTMLElement
 col interfaceName=HTMLTableColElement, createWithNew
 colgroup interfaceName=HTMLTableColElement, createWithNew
 datagrid interfaceName=HTMLDataGridElement, conditional=DATAGRID, createWithNew
@@ -30,40 +30,40 @@
 dcell interfaceName=HTMLDataGridCellElement, conditional=DATAGRID, createWithNew
 dcol interfaceName=HTMLDataGridColElement, conditional=DATAGRID, createWithNew
 drow interfaceName=HTMLDataGridRowElement, conditional=DATAGRID, createWithNew
-dd interfaceName=HTMLElement, createWithNew
+dd interfaceName=HTMLElement
 del interfaceName=HTMLModElement, createWithNew
-dfn interfaceName=HTMLElement, createWithNew
+dfn interfaceName=HTMLElement
 dir interfaceName=HTMLDirectoryElement, createWithNew
 div createWithNew
-dl interfaceName=HTMLDListElement, createWithNew
-dt interfaceName=HTMLElement, createWithNew
-em interfaceName=HTMLElement, createWithNew
-embed createWithNew
+dl interfaceName=HTMLDListElement, createWithNew, createWithNew
+dt interfaceName=HTMLElement
+em interfaceName=HTMLElement
+embed
 fieldset interfaceName=HTMLFieldSetElement, constructorNeedsFormElement, createWithNew
 font createWithNew
 form createWithNew
-frame createWithNew
+frame
 frameset interfaceName=HTMLFrameSetElement, createWithNew
-head createWithNew
 h1 interfaceName=HTMLHeadingElement, createWithNew
 h2 interfaceName=HTMLHeadingElement, createWithNew
 h3 interfaceName=HTMLHeadingElement, createWithNew
 h4 interfaceName=HTMLHeadingElement, createWithNew
 h5 interfaceName=HTMLHeadingElement, createWithNew
 h6 interfaceName=HTMLHeadingElement, createWithNew
+head createWithNew
 hr interfaceName=HTMLHRElement, createWithNew
 html createWithNew
-i interfaceName=HTMLElement, createWithNew
-iframe interfaceName=HTMLIFrameElement, createWithNew
+i interfaceName=HTMLElement
+iframe interfaceName=HTMLIFrameElement
 image mapToTagName=img, createWithNew
 img interfaceName=HTMLImageElement, constructorNeedsFormElement, createWithNew
 input constructorNeedsFormElement, createWithNew
 ins interfaceName=HTMLModElement, createWithNew
 isindex interfaceName=HTMLIsIndexElement, constructorNeedsFormElement, createWithNew
-kbd interfaceName=HTMLElement, createWithNew
+kbd interfaceName=HTMLElement
 keygen JSInterfaceName=HTMLSelectElement, constructorNeedsFormElement, createWithNew
 label createWithNew
-layer interfaceName=HTMLElement, createWithNew
+layer interfaceName=HTMLElement
 legend constructorNeedsFormElement, createWithNew
 li interfaceName=HTMLLIElement, createWithNew
 link constructorNeedsCreatedByParser, createWithNew
@@ -72,40 +72,35 @@
 marquee createWithNew
 menu createWithNew
 meta createWithNew
-nav interfaceName=HTMLElement, createWithNew
-nobr interfaceName=HTMLElement, createWithNew
-noembed interfaceName=HTMLElement, createWithNew
-noframes interfaceName=HTMLElement, createWithNew
-nolayer interfaceName=HTMLElement, createWithNew
-#if ENABLE_XHTMLMP
-noscript interfaceName=HTMLNoScriptElement, createWithNew
-#else
-noscript interfaceName=HTMLElement, createWithNew
-#endif
-object constructorNeedsCreatedByParser, createWithNew
+nav interfaceName=HTMLElement
+nobr interfaceName=HTMLElement
+noembed interfaceName=HTMLElement
+noframes interfaceName=HTMLElement
+nolayer interfaceName=HTMLElement
+object constructorNeedsCreatedByParser
 ol interfaceName=HTMLOListElement, createWithNew
 optgroup interfaceName=HTMLOptGroupElement, constructorNeedsFormElement, createWithNew
 option constructorNeedsFormElement, createWithNew
 p interfaceName=HTMLParagraphElement, createWithNew
 param createWithNew
-plaintext interfaceName=HTMLElement, createWithNew
+plaintext interfaceName=HTMLElement
 pre createWithNew
 q interfaceName=HTMLQuoteElement, createWithNew
-rp interfaceName=HTMLElement, createWithNew
-rt interfaceName=HTMLElement, createWithNew
-ruby interfaceName=HTMLElement, createWithNew
-s interfaceName=HTMLElement, createWithNew
-samp interfaceName=HTMLElement, createWithNew
+rp interfaceName=HTMLElement
+rt interfaceName=HTMLElement
+ruby interfaceName=HTMLElement
+s interfaceName=HTMLElement
+samp interfaceName=HTMLElement
 script constructorNeedsCreatedByParser, createWithNew
 select constructorNeedsFormElement, createWithNew
-small interfaceName=HTMLElement, createWithNew
+small interfaceName=HTMLElement
 source wrapperOnlyIfMediaIsAvailable, conditional=VIDEO, createWithNew
-span interfaceName=HTMLElement, createWithNew
-strike interfaceName=HTMLElement, createWithNew
-strong interfaceName=HTMLElement, createWithNew
+span interfaceName=HTMLElement
+strike interfaceName=HTMLElement
+strong interfaceName=HTMLElement
 style constructorNeedsCreatedByParser, createWithNew
-sub interfaceName=HTMLElement, createWithNew
-sup interfaceName=HTMLElement, createWithNew
+sub interfaceName=HTMLElement
+sup interfaceName=HTMLElement
 table createWithNew
 tbody interfaceName=HTMLTableSectionElement, createWithNew
 td interfaceName=HTMLTableCellElement, createWithNew
@@ -115,10 +110,16 @@
 thead interfaceName=HTMLTableSectionElement, createWithNew
 title createWithNew
 tr interfaceName=HTMLTableRowElement, createWithNew
-tt interfaceName=HTMLElement, createWithNew
-u interfaceName=HTMLElement, createWithNew
+tt interfaceName=HTMLElement
+u interfaceName=HTMLElement
 ul interfaceName=HTMLUListElement, createWithNew
-var interfaceName=HTMLElement, createWithNew
+var interfaceName=HTMLElement
 video wrapperOnlyIfMediaIsAvailable, conditional=VIDEO, createWithNew
-wbr interfaceName=HTMLElement, createWithNew
+wbr interfaceName=HTMLElement
 xmp interfaceName=HTMLPreElement, createWithNew
+
+#if ENABLE_XHTMLMP
+noscript interfaceName=HTMLNoScriptElement, createWithNew
+#else
+noscript interfaceName=HTMLElement
+#endif
diff --git a/WebCore/html/HTMLViewSourceDocument.cpp b/WebCore/html/HTMLViewSourceDocument.cpp
index 55c6df7..ba718d1 100644
--- a/WebCore/html/HTMLViewSourceDocument.cpp
+++ b/WebCore/html/HTMLViewSourceDocument.cpp
@@ -209,7 +209,7 @@
         return m_current;
     }
 
-    RefPtr<HTMLElement> span = new HTMLElement(spanTag, this);
+    RefPtr<HTMLElement> span = HTMLElement::create(spanTag, this);
     RefPtr<NamedMappedAttrMap> attrs = NamedMappedAttrMap::create();
     attrs->addAttribute(MappedAttribute::create(classAttr, className));
     span->setAttributeMap(attrs.release());
@@ -292,7 +292,7 @@
         addLine("webkit-html-tag");
     
     // Now create a link for the attribute value instead of a span.
-    RefPtr<HTMLAnchorElement> anchor = new HTMLAnchorElement(this);
+    RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create(this);
     RefPtr<NamedMappedAttrMap> attrs = NamedMappedAttrMap::create();
     const char* classValue;
     if (isAnchor)
diff --git a/WebCore/page/DragController.cpp b/WebCore/page/DragController.cpp
index 08fb872..97f53a5 100644
--- a/WebCore/page/DragController.cpp
+++ b/WebCore/page/DragController.cpp
@@ -107,7 +107,7 @@
             String title;
             String url = dragData->asURL(&title);
             if (!url.isEmpty()) {
-                RefPtr<HTMLAnchorElement> anchor = new HTMLAnchorElement(document);
+                RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create(document);
                 anchor->setHref(url);
                 ExceptionCode ec;
                 RefPtr<Node> anchorText = document->createTextNode(title);
diff --git a/WebCore/svg/SVGElement.cpp b/WebCore/svg/SVGElement.cpp
index 3a7d3d4..5c5d609 100644
--- a/WebCore/svg/SVGElement.cpp
+++ b/WebCore/svg/SVGElement.cpp
@@ -51,14 +51,19 @@
 
 using namespace HTMLNames;
 
-SVGElement::SVGElement(const QualifiedName& tagName, Document* doc)
-    : StyledElement(tagName, doc)
+SVGElement::SVGElement(const QualifiedName& tagName, Document* document)
+    : StyledElement(tagName, document, CreateElementZeroRefCount)
     , m_shadowParent(0)
     , m_cursorElement(0)
     , m_cursorImageValue(0)
 {
 }
 
+PassRefPtr<SVGElement> SVGElement::create(const QualifiedName& tagName, Document* document)
+{
+    return new SVGElement(tagName, document);
+}
+
 SVGElement::~SVGElement()
 {
     if (m_cursorElement)
diff --git a/WebCore/svg/SVGElement.h b/WebCore/svg/SVGElement.h
index aed7e59..3a17567 100644
--- a/WebCore/svg/SVGElement.h
+++ b/WebCore/svg/SVGElement.h
@@ -1,8 +1,7 @@
 /*
     Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
                   2004, 2005, 2006 Rob Buis <buis@kde.org>
-
-    This file is part of the KDE project
+    Copyright (C) 2009 Apple Inc. All rights reserved.
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -26,25 +25,22 @@
 #if ENABLE(SVG)
 #include "StyledElement.h"
 #include "SVGAnimatedProperty.h"
-#include "SVGNames.h"
 
 namespace WebCore {
 
-    class TransformationMatrix;
     class CSSCursorImageValue;
     class Document;
     class SVGCursorElement;
     class SVGDocumentExtensions;
     class SVGElementInstance;
     class SVGSVGElement;
+    class TransformationMatrix;
 
     class SVGElement : public StyledElement {
     public:
-        SVGElement(const QualifiedName&, Document*);
+        static PassRefPtr<SVGElement> create(const QualifiedName&, Document*);
         virtual ~SVGElement();
-        virtual bool isSVGElement() const { return true; }
-        virtual bool isSupported(StringImpl* feature, StringImpl* version) const;
-        
+
         String id() const;
         void setId(const String&, ExceptionCode&);
         String xmlbase() const;
@@ -52,6 +48,7 @@
 
         SVGSVGElement* ownerSVGElement() const;
         SVGElement* viewportElement() const;
+
         SVGDocumentExtensions* accessDocumentSVGExtensions() const;
 
         virtual void parseMappedAttribute(MappedAttribute*);
@@ -64,33 +61,53 @@
         virtual bool isGradientStop() const { return false; }
         virtual bool isTextContent() const { return false; }
 
-        virtual bool isShadowNode() const { return m_shadowParent; }
-        virtual Node* shadowParentNode() { return m_shadowParent; }
         void setShadowParentNode(ContainerNode* node) { m_shadowParent = node; }
-        virtual ContainerNode* eventParentNode();
 
         // For SVGTests
         virtual bool isValid() const { return true; }
-  
-        virtual void finishParsingChildren();
+
         virtual bool rendererIsNeeded(RenderStyle*) { return false; }
         virtual bool childShouldCreateRenderer(Node*) const;
 
-        virtual void insertedIntoDocument();
-        virtual void buildPendingResource() { }
-
         virtual void svgAttributeChanged(const QualifiedName&) { }
-        virtual void attributeChanged(Attribute*, bool preserveDecls = false);
 
         void sendSVGLoadEventIfPossible(bool sendParentLoadEvents = false);
         
         virtual TransformationMatrix* supplementalTransform() { return 0; }
 
-        virtual void updateAnimatedSVGAttribute(const String&) const;
         virtual void setSynchronizedSVGAttributes(bool) const;
 
         HashSet<SVGElementInstance*> instancesForElement() const;
- 
+
+        void addSVGPropertySynchronizer(const QualifiedName& attrName, const SVGAnimatedPropertyBase& base) const
+        {
+            m_svgPropertyMap.set(attrName.localName(), &base);
+        }
+
+        void setCursorElement(SVGCursorElement* cursorElement) { m_cursorElement = cursorElement; }
+        void setCursorImageValue(CSSCursorImageValue* cursorImageValue) { m_cursorImageValue = cursorImageValue; }
+
+    protected:
+        SVGElement(const QualifiedName&, Document*);
+
+        virtual void finishParsingChildren();
+        virtual void insertedIntoDocument();
+        virtual void attributeChanged(Attribute*, bool preserveDecls = false);
+        virtual void updateAnimatedSVGAttribute(const String&) const;
+
+    private:
+        friend class SVGElementInstance;
+
+        virtual bool isSVGElement() const { return true; }
+
+        virtual bool isSupported(StringImpl* feature, StringImpl* version) const;
+        
+        virtual bool isShadowNode() const { return m_shadowParent; }
+        virtual Node* shadowParentNode() { return m_shadowParent; }
+        virtual ContainerNode* eventParentNode();
+
+        virtual void buildPendingResource() { }
+
         // Inlined methods handling SVG property synchronization
         void invokeSVGPropertySynchronizer(const String& name) const
         {
@@ -114,17 +131,6 @@
             }
         }
 
-        void addSVGPropertySynchronizer(const QualifiedName& attrName, const SVGAnimatedPropertyBase& base) const
-        {
-            m_svgPropertyMap.set(attrName.localName(), &base);
-        }
-
-        void setCursorElement(SVGCursorElement* cursorElement) { m_cursorElement = cursorElement; }
-        void setCursorImageValue(CSSCursorImageValue* cursorImageValue) { m_cursorImageValue = cursorImageValue; }
-
-    private:
-        friend class SVGElementInstance;
-
         void mapInstanceToElement(SVGElementInstance*);
         void removeInstanceMapping(SVGElementInstance*);
 
diff --git a/WebCore/svg/SVGExternalResourcesRequired.h b/WebCore/svg/SVGExternalResourcesRequired.h
index 0ab6dc9..e491e4b 100644
--- a/WebCore/svg/SVGExternalResourcesRequired.h
+++ b/WebCore/svg/SVGExternalResourcesRequired.h
@@ -25,6 +25,7 @@
 
 #if ENABLE(SVG)
 #include "SVGElement.h"
+#include "SVGNames.h"
 
 namespace WebCore {
 
diff --git a/WebCore/svg/SVGStopElement.h b/WebCore/svg/SVGStopElement.h
index bbfd770..5d14a40 100644
--- a/WebCore/svg/SVGStopElement.h
+++ b/WebCore/svg/SVGStopElement.h
@@ -2,8 +2,6 @@
     Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
                   2004, 2005, 2006 Rob Buis <buis@kde.org>
 
-    This file is part of the KDE project
-
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
     License as published by the Free Software Foundation; either
@@ -24,6 +22,7 @@
 #define SVGStopElement_h
 
 #if ENABLE(SVG)
+#include "SVGNames.h"
 #include "SVGStyledElement.h"
 
 namespace WebCore {
@@ -33,13 +32,13 @@
         SVGStopElement(const QualifiedName&, Document*);
         virtual ~SVGStopElement();
 
+    private:
         virtual bool isGradientStop() const { return true; }
 
         virtual void parseMappedAttribute(MappedAttribute*);
 
         virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
 
-    private:
         ANIMATED_PROPERTY_DECLARATIONS(SVGStopElement, SVGNames::stopTagString, SVGNames::offsetAttrString, float, Offset, offset)
     };
 
diff --git a/WebCore/wml/WMLElement.cpp b/WebCore/wml/WMLElement.cpp
index a9e4b5d..a7b71e6 100644
--- a/WebCore/wml/WMLElement.cpp
+++ b/WebCore/wml/WMLElement.cpp
@@ -38,11 +38,16 @@
 
 using namespace WMLNames;
 
-WMLElement::WMLElement(const QualifiedName& tagName, Document* doc)
-    : StyledElement(tagName, doc)
+WMLElement::WMLElement(const QualifiedName& tagName, Document* document)
+    : StyledElement(tagName, document, CreateElementZeroRefCount)
 {
 }
 
+static PassRefPtr<WMLElement> WMLElement::create(const QualifiedName& tagName, Document* document)
+{
+    return new WMLElement(tagName, document);
+}
+
 bool WMLElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
 {
     if (attrName == HTMLNames::alignAttr) {
diff --git a/WebCore/wml/WMLElement.h b/WebCore/wml/WMLElement.h
index 46b0ff4..0bfaceb 100644
--- a/WebCore/wml/WMLElement.h
+++ b/WebCore/wml/WMLElement.h
@@ -29,7 +29,7 @@
 
 class WMLElement : public StyledElement {
 public:
-    WMLElement(const QualifiedName& tagName, Document*);
+    static PassRefPtr<WMLElement> create(const QualifiedName& tagName, Document*);
 
     virtual bool isWMLElement() const { return true; }
     virtual bool isWMLTaskElement() const { return false; }
@@ -43,6 +43,8 @@
     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
 
 protected:
+    WMLElement(const QualifiedName& tagName, Document*);
+
     // Helper function for derived classes
     String parseValueSubstitutingVariableReferences(const AtomicString&, WMLErrorCode defaultErrorCode = WMLErrorInvalidVariableReference) const;
     String parseValueForbiddingVariableReferences(const AtomicString&) const;
diff --git a/WebCore/wml/WMLTagNames.in b/WebCore/wml/WMLTagNames.in
index a21259b..1c24f42 100644
--- a/WebCore/wml/WMLTagNames.in
+++ b/WebCore/wml/WMLTagNames.in
@@ -10,7 +10,7 @@
 do createWithNew
 fieldset interfaceName=WMLFieldSetElement, createWithNew
 go createWithNew
-head interfaceName=WMLElement, createWithNew
+head interfaceName=WMLElement
 img interfaceName=WMLImageElement, createWithNew
 input createWithNew
 #if 0
@@ -29,7 +29,7 @@
 select createWithNew
 setvar createWithNew
 table createWithNew
-td interfaceName=WMLElement, createWithNew
+td interfaceName=WMLElement
 template createWithNew
 timer createWithNew
-tr interfaceName=WMLElement, createWithNew
+tr interfaceName=WMLElement