2010-07-02 Adam Barth <abarth@webkit.org>
[WebKit-https.git] / WebCore / html / HTMLTreeBuilder.cpp
index 2fc8206..c29a4b7 100644 (file)
@@ -564,6 +564,15 @@ void HTMLTreeBuilder::processStartTag(AtomicHTMLToken& token)
         reconstructTheActiveFormattingElements();
         insertElement(token);
         break;
+    case AfterBodyMode:
+        ASSERT(insertionMode() == AfterBodyMode);
+        if (token.name() == htmlTag) {
+            insertHTMLStartTagInBody(token);
+            return;
+        }
+        m_insertionMode = InBodyMode;
+        processStartTag(token);
+        break;
     case InHeadNoscriptMode:
         ASSERT(insertionMode() == InHeadNoscriptMode);
         if (token.name() == htmlTag) {
@@ -749,7 +758,9 @@ void HTMLTreeBuilder::processEndTag(AtomicHTMLToken& token)
         if (token.name() == brTag) {
             parseError(token);
             reconstructTheActiveFormattingElements();
-            insertSelfClosingElement(token);
+            // Notice that we lose the attributes.
+            AtomicHTMLToken startBr(HTMLToken::StartTag, token.name());
+            insertSelfClosingElement(startBr);
             m_framesetOk = false;
             return;
         }
@@ -761,6 +772,19 @@ void HTMLTreeBuilder::processEndTag(AtomicHTMLToken& token)
         m_openElements.popUntil(token.name());
         m_openElements.pop();
         break;
+    case AfterBodyMode:
+        ASSERT(insertionMode() == AfterBodyMode);
+        if (token.name() == htmlTag) {
+            if (m_isParsingFragment) {
+                parseError(token);
+                return;
+            }
+            m_insertionMode = AfterAfterBodyMode;
+            return;
+        }
+        m_insertionMode = InBodyMode;
+        processEndTag(token);
+        break;
     case InHeadNoscriptMode:
         ASSERT(insertionMode() == InHeadNoscriptMode);
         if (token.name() == noscriptTag) {
@@ -801,6 +825,10 @@ void HTMLTreeBuilder::processComment(AtomicHTMLToken& token)
         insertCommentOnDocument(token);
         return;
     }
+    if (m_insertionMode == AfterBodyMode) {
+        insertCommentOnHTMLHtmlElement(token);
+        return;
+    }
     insertComment(token);
 }
 
@@ -838,6 +866,10 @@ void HTMLTreeBuilder::processCharacter(AtomicHTMLToken& token)
         notImplemented();
         insertTextNode(token);
         break;
+    case AfterBodyMode:
+        ASSERT(insertionMode() == AfterBodyMode);
+        m_insertionMode = InBodyMode;
+        processCharacter(token);
     case TextMode:
         notImplemented();
         insertTextNode(token);
@@ -879,6 +911,10 @@ void HTMLTreeBuilder::processEndOfFile(AtomicHTMLToken& token)
         ASSERT(insertionMode() == InBodyMode);
         notImplemented();
         break;
+    case AfterBodyMode:
+        ASSERT(insertionMode() == AfterBodyMode);
+        notImplemented();
+        break;
     case InHeadNoscriptMode:
         ASSERT(insertionMode() == InHeadNoscriptMode);
         processDefaultForInHeadNoscriptMode(token);
@@ -990,6 +1026,12 @@ void HTMLTreeBuilder::insertCommentOnDocument(AtomicHTMLToken& token)
     attach(m_document, Comment::create(m_document, token.comment()));
 }
 
+void HTMLTreeBuilder::insertCommentOnHTMLHtmlElement(AtomicHTMLToken& token)
+{
+    ASSERT(token.type() == HTMLToken::Comment);
+    attach(m_openElements.htmlElement(), Comment::create(m_document, token.comment()));
+}
+
 PassRefPtr<Element> HTMLTreeBuilder::createElementAndAttachToCurrent(AtomicHTMLToken& token)
 {
     ASSERT(token.type() == HTMLToken::StartTag);