2010-07-21 Adam Barth <abarth@webkit.org>
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Jul 2010 12:53:21 +0000 (12:53 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Jul 2010 12:53:21 +0000 (12:53 +0000)
        Reviewed by Eric Seidel.

        Associate elements with the active form
        https://bugs.webkit.org/show_bug.cgi?id=42728

        This patch fixes fast/forms/formmove3.html.  The test still doesn't
        pass due to some render tree differences, but it works as intended now.

        To fix this test, I needed to deviate from the spec slight.  Minefield
        seems to have the same deviation:
          - http://www.w3.org/Bugs/Public/show_bug.cgi?id=10216

        * html/HTMLConstructionSite.cpp:
        (WebCore::HTMLConstructionSite::takeForm):
        (WebCore::HTMLConstructionSite::setForm):
        (WebCore::HTMLConstructionSite::createHTMLElement):
        * html/HTMLConstructionSite.h:
        (WebCore::HTMLConstructionSite::form):
        * html/HTMLTreeBuilder.cpp:
        (WebCore::HTMLTreeBuilder::processStartTagForInBody):

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

WebCore/ChangeLog
WebCore/html/HTMLConstructionSite.cpp
WebCore/html/HTMLConstructionSite.h
WebCore/html/HTMLTreeBuilder.cpp

index c2526f7..ff0bbad 100644 (file)
@@ -2,6 +2,29 @@
 
         Reviewed by Eric Seidel.
 
+        Associate elements with the active form
+        https://bugs.webkit.org/show_bug.cgi?id=42728
+
+        This patch fixes fast/forms/formmove3.html.  The test still doesn't
+        pass due to some render tree differences, but it works as intended now.
+
+        To fix this test, I needed to deviate from the spec slight.  Minefield
+        seems to have the same deviation:
+          - http://www.w3.org/Bugs/Public/show_bug.cgi?id=10216
+
+        * html/HTMLConstructionSite.cpp:
+        (WebCore::HTMLConstructionSite::takeForm):
+        (WebCore::HTMLConstructionSite::setForm):
+        (WebCore::HTMLConstructionSite::createHTMLElement):
+        * html/HTMLConstructionSite.h:
+        (WebCore::HTMLConstructionSite::form):
+        * html/HTMLTreeBuilder.cpp:
+        (WebCore::HTMLTreeBuilder::processStartTagForInBody):
+
+2010-07-21  Adam Barth  <abarth@webkit.org>
+
+        Reviewed by Eric Seidel.
+
         The adoption agency doesn't properly attach()
         https://bugs.webkit.org/show_bug.cgi?id=42727
 
index 13a6d36..e9bb762 100644 (file)
@@ -32,6 +32,8 @@
 #include "Element.h"
 #include "Frame.h"
 #include "HTMLDocument.h"
+#include "HTMLElementFactory.h"
+#include "HTMLFormElement.h"
 #include "HTMLHtmlElement.h"
 #include "HTMLNames.h"
 #include "HTMLScriptElement.h"
@@ -141,6 +143,11 @@ HTMLConstructionSite::~HTMLConstructionSite()
 {
 }
 
+PassRefPtr<HTMLFormElement> HTMLConstructionSite::takeForm()
+{
+    return m_form.release();
+}
+
 void HTMLConstructionSite::dispatchDocumentElementAvailableIfNeeded()
 {
     if (m_document->frame() && !m_isParsingFragment)
@@ -234,6 +241,14 @@ void HTMLConstructionSite::insertHTMLBodyElement(AtomicHTMLToken& token)
     m_openElements.pushHTMLBodyElement(attachToCurrent(createHTMLElement(token)));
 }
 
+void HTMLConstructionSite::insertHTMLFormElement(AtomicHTMLToken& token)
+{
+    insertHTMLElement(token);
+    ASSERT(currentElement()->isHTMLElement());
+    ASSERT(currentElement()->hasTagName(formTag));
+    m_form = static_cast<HTMLFormElement*>(currentElement());
+}
+
 void HTMLConstructionSite::insertHTMLElement(AtomicHTMLToken& token)
 {
     m_openElements.push(attachToCurrent(createHTMLElement(token)));
@@ -307,7 +322,12 @@ PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken& token,
 
 PassRefPtr<Element> HTMLConstructionSite::createHTMLElement(AtomicHTMLToken& token)
 {
-    RefPtr<Element> element = createElement(token, xhtmlNamespaceURI);
+    QualifiedName tagName(nullAtom, token.name(), xhtmlNamespaceURI);
+    // FIXME: This can't use HTMLConstructionSite::createElement because we
+    // have to pass the current form element.  We should rework form association
+    // to occur after construction to allow better code sharing here.
+    RefPtr<Element> element = HTMLElementFactory::createHTMLElement(tagName, m_document, form(), true);
+    element->setAttributeMap(token.takeAtributes(), m_fragmentScriptingPermission);
     ASSERT(element->isHTMLElement());
     return element.release();
 }
index 176433b..d9c8ac5 100644 (file)
@@ -55,6 +55,7 @@ public:
     void insertHTMLHtmlElement(AtomicHTMLToken&);
     void insertHTMLHeadElement(AtomicHTMLToken&);
     void insertHTMLBodyElement(AtomicHTMLToken&);
+    void insertHTMLFormElement(AtomicHTMLToken&);
     void insertScriptElement(AtomicHTMLToken&);
     void insertTextNode(const String&);
     void insertForeignElement(AtomicHTMLToken&, const AtomicString& namespaceURI);
@@ -83,10 +84,8 @@ public:
 
     Element* head() const { return m_head.get(); }
 
-    Element* form() const { return m_form.get(); }
-    PassRefPtr<Element> takeForm() { return m_form.release(); }
-
-    void setForm(PassRefPtr<Element> form) { m_form = form; }
+    HTMLFormElement* form() const { return m_form.get(); }
+    PassRefPtr<HTMLFormElement> takeForm();
 
     class RedirectToFosterParentGuard : public Noncopyable {
     public:
@@ -128,7 +127,7 @@ private:
 
     Document* m_document;
     RefPtr<Element> m_head;
-    RefPtr<Element> m_form;
+    RefPtr<HTMLFormElement> m_form;
     mutable HTMLElementStack m_openElements;
     mutable HTMLFormattingElementList m_activeFormattingElements;
 
index a926a8b..cc24339 100644 (file)
@@ -33,6 +33,7 @@
 #include "Frame.h"
 #include "HTMLDocument.h"
 #include "HTMLElementFactory.h"
+#include "HTMLFormElement.h"
 #include "HTMLHtmlElement.h"
 #include "HTMLNames.h"
 #include "HTMLScriptElement.h"
@@ -845,8 +846,7 @@ void HTMLTreeBuilder::processStartTagForInBody(AtomicHTMLToken& token)
             return;
         }
         processFakePEndTagIfPInScope();
-        m_tree.insertHTMLElement(token);
-        m_tree.setForm(m_tree.currentElement());
+        m_tree.insertHTMLFormElement(token);
         return;
     }
     if (token.name() == liTag) {
@@ -1142,7 +1142,10 @@ void HTMLTreeBuilder::processStartTagForInTable(AtomicHTMLToken& token)
         parseError(token);
         if (m_tree.form())
             return;
-        m_tree.insertSelfClosingHTMLElement(token);
+        // FIXME: This deviates from the spec:
+        //        http://www.w3.org/Bugs/Public/show_bug.cgi?id=10216
+        m_tree.insertHTMLFormElement(token);
+        m_tree.openElements()->pop();
         return;
     }
     parseError(token);