Unreviewed, rolling out r103473.
authorkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Dec 2011 01:36:40 +0000 (01:36 +0000)
committerkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Dec 2011 01:36:40 +0000 (01:36 +0000)
http://trac.webkit.org/changeset/103473
https://bugs.webkit.org/show_bug.cgi?id=74991

Overestimated my superpowers a bit here.

* dom/Element.cpp:
(WebCore::Element::attributeChanged):
(WebCore::Element::insertedIntoDocument):
(WebCore::Element::removedFromDocument):
* dom/Element.h:
(WebCore::Element::updateId):
(WebCore::Element::willModifyAttribute):
* dom/NamedNodeMap.cpp:
(WebCore::NamedNodeMap::setAttributes):
* dom/Node.h:
* html/HTMLAppletElement.cpp:
(WebCore::HTMLAppletElement::parseMappedAttribute):
(WebCore::HTMLAppletElement::insertedIntoDocument):
(WebCore::HTMLAppletElement::removedFromDocument):
* html/HTMLAppletElement.h:
* html/HTMLEmbedElement.cpp:
(WebCore::HTMLEmbedElement::parseMappedAttribute):
(WebCore::HTMLEmbedElement::insertedIntoDocument):
(WebCore::HTMLEmbedElement::removedFromDocument):
* html/HTMLEmbedElement.h:
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::insertedIntoDocument):
(WebCore::HTMLFormElement::removedFromDocument):
(WebCore::HTMLFormElement::parseMappedAttribute):
* html/HTMLFormElement.h:
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::parseMappedAttribute):
(WebCore::HTMLImageElement::insertedIntoDocument):
(WebCore::HTMLImageElement::removedFromDocument):
* html/HTMLImageElement.h:
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::parseMappedAttribute):
(WebCore::HTMLObjectElement::insertedIntoDocument):
(WebCore::HTMLObjectElement::removedFromDocument):
(WebCore::HTMLObjectElement::updateDocNamedItem):
(WebCore::HTMLObjectElement::formControlName):
* html/HTMLObjectElement.h:
* html/HTMLPlugInElement.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@103478 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/NamedNodeMap.cpp
Source/WebCore/dom/Node.h
Source/WebCore/html/HTMLAppletElement.cpp
Source/WebCore/html/HTMLAppletElement.h
Source/WebCore/html/HTMLEmbedElement.cpp
Source/WebCore/html/HTMLEmbedElement.h
Source/WebCore/html/HTMLFormElement.cpp
Source/WebCore/html/HTMLFormElement.h
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLImageElement.h
Source/WebCore/html/HTMLObjectElement.cpp
Source/WebCore/html/HTMLObjectElement.h
Source/WebCore/html/HTMLPlugInElement.h

index 9a1e3da..e95c3f3 100644 (file)
@@ -1,3 +1,50 @@
+2011-12-21  Andreas Kling  <kling@webkit.org>
+
+        Unreviewed, rolling out r103473.
+        http://trac.webkit.org/changeset/103473
+        https://bugs.webkit.org/show_bug.cgi?id=74991
+
+        Overestimated my superpowers a bit here.
+
+        * dom/Element.cpp:
+        (WebCore::Element::attributeChanged):
+        (WebCore::Element::insertedIntoDocument):
+        (WebCore::Element::removedFromDocument):
+        * dom/Element.h:
+        (WebCore::Element::updateId):
+        (WebCore::Element::willModifyAttribute):
+        * dom/NamedNodeMap.cpp:
+        (WebCore::NamedNodeMap::setAttributes):
+        * dom/Node.h:
+        * html/HTMLAppletElement.cpp:
+        (WebCore::HTMLAppletElement::parseMappedAttribute):
+        (WebCore::HTMLAppletElement::insertedIntoDocument):
+        (WebCore::HTMLAppletElement::removedFromDocument):
+        * html/HTMLAppletElement.h:
+        * html/HTMLEmbedElement.cpp:
+        (WebCore::HTMLEmbedElement::parseMappedAttribute):
+        (WebCore::HTMLEmbedElement::insertedIntoDocument):
+        (WebCore::HTMLEmbedElement::removedFromDocument):
+        * html/HTMLEmbedElement.h:
+        * html/HTMLFormElement.cpp:
+        (WebCore::HTMLFormElement::insertedIntoDocument):
+        (WebCore::HTMLFormElement::removedFromDocument):
+        (WebCore::HTMLFormElement::parseMappedAttribute):
+        * html/HTMLFormElement.h:
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::parseMappedAttribute):
+        (WebCore::HTMLImageElement::insertedIntoDocument):
+        (WebCore::HTMLImageElement::removedFromDocument):
+        * html/HTMLImageElement.h:
+        * html/HTMLObjectElement.cpp:
+        (WebCore::HTMLObjectElement::parseMappedAttribute):
+        (WebCore::HTMLObjectElement::insertedIntoDocument):
+        (WebCore::HTMLObjectElement::removedFromDocument):
+        (WebCore::HTMLObjectElement::updateDocNamedItem):
+        (WebCore::HTMLObjectElement::formControlName):
+        * html/HTMLObjectElement.h:
+        * html/HTMLPlugInElement.h:
+
 2011-12-21  Simon Fraser  <simon.fraser@apple.com>
 
         Clean up RenderLayer code that applies filters and transforms
index a17cc63..250531f 100644 (file)
@@ -43,7 +43,6 @@
 #include "FocusController.h"
 #include "Frame.h"
 #include "FrameView.h"
-#include "HTMLDocument.h"
 #include "HTMLElement.h"
 #include "HTMLFrameOwnerElement.h"
 #include "HTMLNames.h"
@@ -705,8 +704,6 @@ void Element::attributeChanged(Attribute* attr, bool)
 {
     if (isIdAttributeName(attr->name()))
         idAttributeChanged(attr);
-    else if (attr->name() == HTMLNames::nameAttr)
-        setHasName(!attr->isNull());
     recalcStyleIfNeededAfterAttributeChanged(attr);
     updateAfterAttributeChanged(attr);
 }
@@ -919,33 +916,23 @@ void Element::insertedIntoDocument()
     if (ShadowRoot* shadow = shadowRoot())
         shadow->insertedIntoDocument();
 
-    if (m_attributeMap) {
-        if (hasID()) {
+    if (hasID()) {
+        if (m_attributeMap) {
             Attribute* idItem = m_attributeMap->getAttributeItem(document()->idAttributeName());
             if (idItem && !idItem->isNull())
                 updateId(nullAtom, idItem->value());
         }
-        if (hasName()) {
-            Attribute* nameItem = m_attributeMap->getAttributeItem(HTMLNames::nameAttr);
-            if (nameItem && !nameItem->isNull())
-                updateName(nullAtom, nameItem->value());
-        }
     }
 }
 
 void Element::removedFromDocument()
 {
-    if (m_attributeMap) {
-        if (hasID()) {
+    if (hasID()) {
+        if (m_attributeMap) {
             Attribute* idItem = m_attributeMap->getAttributeItem(document()->idAttributeName());
             if (idItem && !idItem->isNull())
                 updateId(idItem->value(), nullAtom);
         }
-        if (hasName()) {
-            Attribute* nameItem = m_attributeMap->getAttributeItem(HTMLNames::nameAttr);
-            if (nameItem && !nameItem->isNull())
-                updateName(nameItem->value(), nullAtom);
-        }
     }
 
     ContainerNode::removedFromDocument();
@@ -2005,28 +1992,4 @@ bool Element::fastAttributeLookupAllowed(const QualifiedName& name) const
 }
 #endif
 
-void Element::updateNamedItemRegistration(const AtomicString& oldName, const AtomicString& newName)
-{
-    if (!document()->isHTMLDocument())
-        return;
-
-    if (!oldName.isEmpty())
-        static_cast<HTMLDocument*>(document())->removeNamedItem(oldName);
-
-    if (!newName.isEmpty())
-        static_cast<HTMLDocument*>(document())->addNamedItem(newName);
-}
-
-void Element::updateExtraNamedItemRegistration(const AtomicString& oldId, const AtomicString& newId)
-{
-    if (!document()->isHTMLDocument())
-        return;
-
-    if (!oldId.isEmpty())
-        static_cast<HTMLDocument*>(document())->removeExtraNamedItem(oldId);
-
-    if (!newId.isEmpty())
-        static_cast<HTMLDocument*>(document())->addExtraNamedItem(newId);
-}
-
 } // namespace WebCore
index 836c7d0..a635f06 100644 (file)
@@ -27,7 +27,6 @@
 
 #include "Document.h"
 #include "FragmentScriptingPermission.h"
-#include "HTMLNames.h"
 #include "NamedNodeMap.h"
 #include "ScrollTypes.h"
 
@@ -266,7 +265,6 @@ public:
     virtual String title() const;
 
     void updateId(const AtomicString& oldId, const AtomicString& newId);
-    void updateName(const AtomicString& oldName, const AtomicString& newName);
     void willModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
 
     LayoutSize minimumSizeForResizing() const;
@@ -383,9 +381,6 @@ protected:
     virtual void didRecalcStyle(StyleChange) { }
     virtual PassRefPtr<RenderStyle> customStyleForRenderer();
 
-    virtual bool shouldRegisterAsNamedItem() const { return false; }
-    virtual bool shouldRegisterAsExtraNamedItem() const { return false; }
-
     // The implementation of Element::attributeChanged() calls the following two functions.
     // They are separated to allow a different flow of control in StyledElement::attributeChanged().
     void recalcStyleIfNeededAfterAttributeChanged(Attribute*);
@@ -442,9 +437,6 @@ private:
     void enqueueAttributesMutationRecordIfRequested(const QualifiedName&, const AtomicString& oldValue);
 #endif
 
-    void updateNamedItemRegistration(const AtomicString& oldName, const AtomicString& newName);
-    void updateExtraNamedItemRegistration(const AtomicString& oldName, const AtomicString& newName);
-
 private:
     mutable RefPtr<NamedNodeMap> m_attributeMap;
 };
@@ -524,29 +516,12 @@ inline void Element::updateId(const AtomicString& oldId, const AtomicString& new
         scope->removeElementById(oldId, this);
     if (!newId.isEmpty())
         scope->addElementById(newId, this);
-
-    if (shouldRegisterAsExtraNamedItem())
-        updateExtraNamedItemRegistration(oldId, newId);
-}
-
-inline void Element::updateName(const AtomicString& oldName, const AtomicString& newName)
-{
-    if (!inDocument())
-        return;
-
-    if (oldName == newName)
-        return;
-
-    if (shouldRegisterAsNamedItem())
-        updateNamedItemRegistration(oldName, newName);
 }
 
 inline void Element::willModifyAttribute(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue)
 {
     if (isIdAttributeName(name))
         updateId(oldValue, newValue);
-    else if (name == HTMLNames::nameAttr)
-        updateName(oldValue, newValue);
 
     // FIXME: Should probably call InspectorInstrumentation::willModifyDOMAttr here.
 
index b7d1b0a..83d5f03 100644 (file)
@@ -240,12 +240,6 @@ void NamedNodeMap::setAttributes(const NamedNodeMap& other)
     if (oldId || newId)
         m_element->updateId(oldId ? oldId->value() : nullAtom, newId ? newId->value() : nullAtom);
 
-    Attribute* oldName = getAttributeItem(HTMLNames::nameAttr);
-    Attribute* newName = other.getAttributeItem(HTMLNames::nameAttr);
-
-    if (oldName || newName)
-        m_element->updateName(oldName ? oldName->value() : nullAtom, newName ? newName->value() : nullAtom);
-
     clearAttributes();
     unsigned newLength = other.length();
     m_attributes.resize(newLength);
index 09367f4..21955ad 100644 (file)
@@ -295,7 +295,6 @@ public:
     virtual bool sheetLoaded() { return true; }
     virtual void startLoadingDynamicSheet() { ASSERT_NOT_REACHED(); }
 
-    bool hasName() const { return getFlag(HasNameFlag); }
     bool hasID() const { return getFlag(HasIDFlag); }
     bool hasClass() const { return getFlag(HasClassFlag); }
     bool active() const { return getFlag(IsActiveFlag); }
@@ -310,7 +309,6 @@ public:
     bool childNeedsStyleRecalc() const { return getFlag(ChildNeedsStyleRecalcFlag); }
     bool isLink() const { return getFlag(IsLinkFlag); }
 
-    void setHasName(bool f) { setFlag(f, HasNameFlag); }
     void setHasID(bool f) { setFlag(f, HasIDFlag); }
     void setHasClass(bool f) { setFlag(f, HasClassFlag); }
     void setChildNeedsStyleRecalc() { setFlag(ChildNeedsStyleRecalcFlag); }
@@ -647,8 +645,6 @@ private:
         HasCustomWillOrDidRecalcStyleFlag = 1 << 28,
         HasCustomStyleForRendererFlag = 1 << 29,
 
-        HasNameFlag = 1 << 30,
-
 #if ENABLE(SVG)
         DefaultNodeFlags = IsParsingChildrenFinishedFlag | IsStyleAttributeValidFlag | AreSVGAttributesValidFlag
 #else
@@ -656,7 +652,7 @@ private:
 #endif
     };
 
-    // 1 bit remaining
+    // 2 bits remaining
 
     bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; }
     void setFlag(bool f, NodeFlags mask) const { m_nodeFlags = (m_nodeFlags & ~mask) | (-(int32_t)f & mask); } 
index 14ba11f..cf6cc84 100644 (file)
@@ -56,10 +56,50 @@ void HTMLAppletElement::parseMappedAttribute(Attribute* attr)
         attr->name() == mayscriptAttr ||
         attr->name() == objectAttr) {
         // Do nothing.
+    } else if (attr->name() == nameAttr) {
+        const AtomicString& newName = attr->value();
+        if (inDocument() && document()->isHTMLDocument()) {
+            HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+            document->removeNamedItem(m_name);
+            document->addNamedItem(newName);
+        }
+        m_name = newName;
+    } else if (isIdAttributeName(attr->name())) {
+        const AtomicString& newId = attr->value();
+        if (inDocument() && document()->isHTMLDocument()) {
+            HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+            document->removeExtraNamedItem(m_id);
+            document->addExtraNamedItem(newId);
+        }
+        m_id = newId;
+        // also call superclass
+        HTMLPlugInElement::parseMappedAttribute(attr);
     } else
         HTMLPlugInElement::parseMappedAttribute(attr);
 }
 
+void HTMLAppletElement::insertedIntoDocument()
+{
+    if (document()->isHTMLDocument()) {
+        HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+        document->addNamedItem(m_name);
+        document->addExtraNamedItem(m_id);
+    }
+
+    HTMLPlugInElement::insertedIntoDocument();
+}
+
+void HTMLAppletElement::removedFromDocument()
+{
+    if (document()->isHTMLDocument()) {
+        HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+        document->removeNamedItem(m_name);
+        document->removeExtraNamedItem(m_id);
+    }
+
+    HTMLPlugInElement::removedFromDocument();
+}
+
 bool HTMLAppletElement::rendererIsNeeded(const NodeRenderingContext& context)
 {
     if (!fastHasAttribute(codeAttr))
index e5387d9..d813ee3 100644 (file)
@@ -47,8 +47,10 @@ private:
     void setupApplet() const;
     bool canEmbedJava() const;
 
-    virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return true; }
-    virtual bool shouldRegisterAsExtraNamedItem() const OVERRIDE { return true; }
+    virtual void insertedIntoDocument();
+    virtual void removedFromDocument();
+
+    AtomicString m_id;
 };
 
 }
index d0bd344..4d0a215 100644 (file)
@@ -111,6 +111,13 @@ void HTMLEmbedElement::parseMappedAttribute(Attribute* attr)
             addCSSLength(attr, CSSPropertyWidth, "0");
             addCSSLength(attr, CSSPropertyHeight, "0");
         }
+    } else if (attr->name() == nameAttr) {
+        if (inDocument() && document()->isHTMLDocument()) {
+            HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+            document->removeNamedItem(m_name);
+            document->addNamedItem(value);
+        }
+        m_name = value;
     } else
         HTMLPlugInImageElement::parseMappedAttribute(attr);
 }
@@ -212,6 +219,9 @@ void HTMLEmbedElement::insertedIntoDocument()
     if (!inDocument())
         return;
 
+    if (document()->isHTMLDocument())
+        static_cast<HTMLDocument*>(document())->addNamedItem(m_name);
+
     String width = getAttribute(widthAttr);
     String height = getAttribute(heightAttr);
     if (!width.isEmpty() || !height.isEmpty()) {
@@ -227,6 +237,14 @@ void HTMLEmbedElement::insertedIntoDocument()
     }
 }
 
+void HTMLEmbedElement::removedFromDocument()
+{
+    if (document()->isHTMLDocument())
+        static_cast<HTMLDocument*>(document())->removeNamedItem(m_name);
+
+    HTMLPlugInImageElement::removedFromDocument();
+}
+
 void HTMLEmbedElement::attributeChanged(Attribute* attr, bool preserveDecls)
 {
     HTMLPlugInImageElement::attributeChanged(attr, preserveDecls);
index bd6764d..4485e09 100644 (file)
@@ -39,6 +39,7 @@ private:
 
     virtual bool rendererIsNeeded(const NodeRenderingContext&);
     virtual void insertedIntoDocument();
+    virtual void removedFromDocument();
     virtual void attributeChanged(Attribute*, bool preserveDecls = false);
 
     virtual bool isURLAttribute(Attribute*) const;
@@ -56,8 +57,6 @@ private:
     virtual String itemValueText() const OVERRIDE;
     virtual void setItemValueText(const String&, ExceptionCode&) OVERRIDE;
 #endif
-
-    virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return true; }
 };
 
 }
index e1a3fbe..5a8eca3 100644 (file)
@@ -132,6 +132,9 @@ bool HTMLFormElement::rendererIsNeeded(const NodeRenderingContext& context)
 
 void HTMLFormElement::insertedIntoDocument()
 {
+    if (document()->isHTMLDocument())
+        static_cast<HTMLDocument*>(document())->addNamedItem(m_name);
+
     HTMLElement::insertedIntoDocument();
 
     if (hasID())
@@ -140,6 +143,9 @@ void HTMLFormElement::insertedIntoDocument()
 
 void HTMLFormElement::removedFromDocument()
 {
+    if (document()->isHTMLDocument())
+        static_cast<HTMLDocument*>(document())->removeNamedItem(m_name);
+
     HTMLElement::removedFromDocument();
 
     if (hasID())
@@ -378,7 +384,15 @@ void HTMLFormElement::parseMappedAttribute(Attribute* attr)
         setAttributeEventListener(eventNames().submitEvent, createAttributeEventListener(this, attr));
     else if (attr->name() == onresetAttr)
         setAttributeEventListener(eventNames().resetEvent, createAttributeEventListener(this, attr));
-    else
+    else if (attr->name() == nameAttr) {
+        const AtomicString& newName = attr->value();
+        if (inDocument() && document()->isHTMLDocument()) {
+            HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+            document->removeNamedItem(m_name);
+            document->addNamedItem(newName);
+        }
+        m_name = newName;
+    } else
         HTMLElement::parseMappedAttribute(attr);
 }
 
index 430870b..30125fa 100644 (file)
@@ -131,8 +131,6 @@ private:
     virtual void willMoveToNewOwnerDocument();
     virtual void didMoveToNewOwnerDocument();
 
-    virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return true; }
-
     void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger);
 
     unsigned formElementIndexWithFormAttribute(Element*);
@@ -169,6 +167,8 @@ private:
 
     bool m_wasMalformed;
     bool m_wasDemoted;
+
+    AtomicString m_name;
 };
 
 } // namespace WebCore
index 4568183..42a4e78 100644 (file)
@@ -133,6 +133,24 @@ void HTMLImageElement::parseMappedAttribute(Attribute* attr)
     else if (attrName == compositeAttr) {
         if (!parseCompositeOperator(attr->value(), m_compositeOperator))
             m_compositeOperator = CompositeSourceOver;
+    } else if (attrName == nameAttr) {
+        const AtomicString& newName = attr->value();
+        if (inDocument() && document()->isHTMLDocument()) {
+            HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+            document->removeNamedItem(m_name);
+            document->addNamedItem(newName);
+        }
+        m_name = newName;
+    } else if (isIdAttributeName(attr->name())) {
+        const AtomicString& newId = attr->value();
+        if (inDocument() && document()->isHTMLDocument()) {
+            HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+            document->removeExtraNamedItem(m_id);
+            document->addExtraNamedItem(newId);
+        }
+        m_id = newId;
+        // also call superclass
+        HTMLElement::parseMappedAttribute(attr);
     } else
         HTMLElement::parseMappedAttribute(attr);
 }
@@ -179,6 +197,12 @@ void HTMLImageElement::attach()
 
 void HTMLImageElement::insertedIntoDocument()
 {
+    if (document()->isHTMLDocument()) {
+        HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+        document->addNamedItem(m_name);
+        document->addExtraNamedItem(m_id);
+    }
+
     // If we have been inserted from a renderer-less document,
     // our loader may have not fetched the image, so do it now.
     if (!m_imageLoader.image())
@@ -187,6 +211,17 @@ void HTMLImageElement::insertedIntoDocument()
     HTMLElement::insertedIntoDocument();
 }
 
+void HTMLImageElement::removedFromDocument()
+{
+    if (document()->isHTMLDocument()) {
+        HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+        document->removeNamedItem(m_name);
+        document->removeExtraNamedItem(m_id);
+    }
+
+    HTMLElement::removedFromDocument();
+}
+
 void HTMLImageElement::insertedIntoTree(bool deep)
 {
     if (!m_form) {
index 60618c5..9bec9d8 100644 (file)
@@ -98,12 +98,10 @@ private:
     virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
 
     virtual void insertedIntoDocument();
+    virtual void removedFromDocument();
     virtual void insertedIntoTree(bool deep);
     virtual void removedFromTree(bool deep);
 
-    virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return true; }
-    virtual bool shouldRegisterAsExtraNamedItem() const OVERRIDE { return true; }
-
 #if ENABLE(MICRODATA)
     virtual String itemValueText() const OVERRIDE;
     virtual void setItemValueText(const String&, ExceptionCode&) OVERRIDE;
@@ -111,6 +109,8 @@ private:
 
     HTMLImageLoader m_imageLoader;
     HTMLFormElement* m_form;
+    AtomicString m_name;
+    AtomicString m_id;
     CompositeOperator m_compositeOperator;
 };
 
index e72e7c7..a9e1f04 100644 (file)
@@ -114,9 +114,27 @@ void HTMLObjectElement::parseMappedAttribute(Attribute* attr)
         setAttributeEventListener(eventNames().loadEvent, createAttributeEventListener(this, attr));
     else if (attr->name() == onbeforeloadAttr)
         setAttributeEventListener(eventNames().beforeloadEvent, createAttributeEventListener(this, attr));
-    else if (attr->name() == borderAttr)
+    else if (attr->name() == nameAttr) {
+        const AtomicString& newName = attr->value();
+        if (isDocNamedItem() && inDocument() && document()->isHTMLDocument()) {
+            HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+            document->removeNamedItem(m_name);
+            document->addNamedItem(newName);
+        }
+        m_name = newName;
+    } else if (attr->name() == borderAttr)
         applyBorderAttribute(attr);
-    else
+    else if (isIdAttributeName(attr->name())) {
+        const AtomicString& newId = attr->value();
+        if (isDocNamedItem() && inDocument() && document()->isHTMLDocument()) {
+            HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+            document->removeExtraNamedItem(m_id);
+            document->addExtraNamedItem(newId);
+        }
+        m_id = newId;
+        // also call superclass
+        HTMLPlugInImageElement::parseMappedAttribute(attr);
+    } else
         HTMLPlugInImageElement::parseMappedAttribute(attr);
 }
 
@@ -328,11 +346,26 @@ bool HTMLObjectElement::rendererIsNeeded(const NodeRenderingContext& context)
 void HTMLObjectElement::insertedIntoDocument()
 {
     HTMLPlugInImageElement::insertedIntoDocument();
+    if (!inDocument())
+        return;
+
+    if (isDocNamedItem() && document()->isHTMLDocument()) {
+        HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+        document->addNamedItem(m_name);
+        document->addExtraNamedItem(m_id);
+    }
+
     FormAssociatedElement::insertedIntoDocument();
 }
 
 void HTMLObjectElement::removedFromDocument()
 {
+    if (isDocNamedItem() && document()->isHTMLDocument()) {
+        HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+        document->removeNamedItem(m_name);
+        document->removeExtraNamedItem(m_id);
+    }
+
     HTMLPlugInImageElement::removedFromDocument();
     FormAssociatedElement::removedFromDocument();
 }
@@ -433,11 +466,11 @@ void HTMLObjectElement::updateDocNamedItem()
     if (isNamedItem != wasNamedItem && document()->isHTMLDocument()) {
         HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
         if (isNamedItem) {
-            document->addNamedItem(fastGetAttribute(nameAttr));
-            document->addExtraNamedItem(getIdAttribute());
+            document->addNamedItem(m_name);
+            document->addExtraNamedItem(m_id);
         } else {
-            document->removeNamedItem(fastGetAttribute(nameAttr));
-            document->removeExtraNamedItem(getIdAttribute());
+            document->removeNamedItem(m_name);
+            document->removeExtraNamedItem(m_id);
         }
     }
     m_docNamedItem = isNamedItem;
@@ -511,8 +544,7 @@ bool HTMLObjectElement::appendFormData(FormDataList& encoding, bool)
 
 const AtomicString& HTMLObjectElement::formControlName() const
 {
-    const AtomicString& name = fastGetAttribute(nameAttr);
-    return name.isNull() ? emptyAtom : name;
+    return m_name.isNull() ? emptyAtom : m_name;
 }
 
 HTMLFormElement* HTMLObjectElement::virtualForm() const
index d56647b..dcec5cf 100644 (file)
@@ -107,9 +107,7 @@ private:
     virtual void setItemValueText(const String&, ExceptionCode&) OVERRIDE;
 #endif
 
-    virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return isDocNamedItem(); }
-    virtual bool shouldRegisterAsExtraNamedItem() const OVERRIDE { return isDocNamedItem(); }
-
+    AtomicString m_id;
     String m_classId;
     bool m_docNamedItem : 1;
     bool m_useFallbackContent : 1;
index 7dadfda..2e33c66 100644 (file)
@@ -68,6 +68,9 @@ private:
 
     virtual RenderWidget* renderWidgetForJSBindings() = 0;
 
+protected:
+    AtomicString m_name;
+
 private:
     mutable ScriptInstance m_instance;
 #if ENABLE(NETSCAPE_PLUGIN_API)