Title: [126355] trunk/Source/WebCore
Revision
126355
Author
[email protected]
Date
2012-08-22 14:55:10 -0700 (Wed, 22 Aug 2012)

Log Message

HTMLTreeBuilder::furthestBlockForFormattingElement should belong to HTMLElementStack
https://bugs.webkit.org/show_bug.cgi?id=93857

Patch by Kwang Yul Seo <[email protected]> on 2012-08-22
Reviewed by Eric Seidel.

HTMLTreeBuilder::furthestBlockForFormattingElement should belong to
HTMLElementStack because it traverses the element stack and finds the
furthest block for the given formatting element.

Currently, it belongs to HTMLTreeBuilder just because
isSpecialNode(const HTMLStackItem*) function used by
furthestBlockForFormattingElement is internal to HTMLTreeBuilder.

Moved isSpecialNode to HTMLStackItem and changed
furthestBlockForFormattingElement to be a method of HTMLElementStack.

No behavior change. Just a refactoring.

* html/parser/HTMLElementStack.cpp:
(WebCore):
(WebCore::HTMLElementStack::popUntilNumberedHeaderElementPopped):
(WebCore::HTMLElementStack::hasNumberedHeaderElementInScope):
(WebCore::HTMLElementStack::furthestBlockForFormattingElement):
* html/parser/HTMLElementStack.h:
(HTMLElementStack):
* html/parser/HTMLStackItem.h:
(WebCore::HTMLStackItem::isInHTMLNamespace):
(HTMLStackItem):
(WebCore::HTMLStackItem::isNumberedHeaderElement):
(WebCore::HTMLStackItem::isTableBodyContextElement):
(WebCore::HTMLStackItem::isSpecialNode):
* html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::constructTreeFromAtomicToken):
(WebCore::HTMLTreeBuilder::processCloseWhenNestedTag):
(WebCore::HTMLTreeBuilder::processStartTagForInBody):
(WebCore::HTMLTreeBuilder::processAnyOtherEndTagForInBody):
(WebCore::HTMLTreeBuilder::callTheAdoptionAgency):
(WebCore::HTMLTreeBuilder::shouldProcessTokenInForeignContent):
(WebCore::HTMLTreeBuilder::processTokenInForeignContent):
* html/parser/HTMLTreeBuilder.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (126354 => 126355)


--- trunk/Source/WebCore/ChangeLog	2012-08-22 21:49:16 UTC (rev 126354)
+++ trunk/Source/WebCore/ChangeLog	2012-08-22 21:55:10 UTC (rev 126355)
@@ -1,3 +1,46 @@
+2012-08-22  Kwang Yul Seo  <[email protected]>
+
+        HTMLTreeBuilder::furthestBlockForFormattingElement should belong to HTMLElementStack
+        https://bugs.webkit.org/show_bug.cgi?id=93857
+
+        Reviewed by Eric Seidel.
+
+        HTMLTreeBuilder::furthestBlockForFormattingElement should belong to
+        HTMLElementStack because it traverses the element stack and finds the
+        furthest block for the given formatting element.
+
+        Currently, it belongs to HTMLTreeBuilder just because
+        isSpecialNode(const HTMLStackItem*) function used by
+        furthestBlockForFormattingElement is internal to HTMLTreeBuilder.
+
+        Moved isSpecialNode to HTMLStackItem and changed
+        furthestBlockForFormattingElement to be a method of HTMLElementStack.
+
+        No behavior change. Just a refactoring.
+
+        * html/parser/HTMLElementStack.cpp:
+        (WebCore):
+        (WebCore::HTMLElementStack::popUntilNumberedHeaderElementPopped):
+        (WebCore::HTMLElementStack::hasNumberedHeaderElementInScope):
+        (WebCore::HTMLElementStack::furthestBlockForFormattingElement):
+        * html/parser/HTMLElementStack.h:
+        (HTMLElementStack):
+        * html/parser/HTMLStackItem.h:
+        (WebCore::HTMLStackItem::isInHTMLNamespace):
+        (HTMLStackItem):
+        (WebCore::HTMLStackItem::isNumberedHeaderElement):
+        (WebCore::HTMLStackItem::isTableBodyContextElement):
+        (WebCore::HTMLStackItem::isSpecialNode):
+        * html/parser/HTMLTreeBuilder.cpp:
+        (WebCore::HTMLTreeBuilder::constructTreeFromAtomicToken):
+        (WebCore::HTMLTreeBuilder::processCloseWhenNestedTag):
+        (WebCore::HTMLTreeBuilder::processStartTagForInBody):
+        (WebCore::HTMLTreeBuilder::processAnyOtherEndTagForInBody):
+        (WebCore::HTMLTreeBuilder::callTheAdoptionAgency):
+        (WebCore::HTMLTreeBuilder::shouldProcessTokenInForeignContent):
+        (WebCore::HTMLTreeBuilder::processTokenInForeignContent):
+        * html/parser/HTMLTreeBuilder.h:
+
 2012-08-22  Alexandre Elias  <[email protected]>
 
         [chromium] Add software bitmap resources to CCResourceProvider

Modified: trunk/Source/WebCore/html/parser/HTMLElementStack.cpp (126354 => 126355)


--- trunk/Source/WebCore/html/parser/HTMLElementStack.cpp	2012-08-22 21:49:16 UTC (rev 126354)
+++ trunk/Source/WebCore/html/parser/HTMLElementStack.cpp	2012-08-22 21:55:10 UTC (rev 126355)
@@ -38,16 +38,6 @@
 
 using namespace HTMLNames;
 
-static inline bool isNumberedHeaderElement(HTMLStackItem* item)
-{
-    return item->hasTagName(h1Tag)
-        || item->hasTagName(h2Tag)
-        || item->hasTagName(h3Tag)
-        || item->hasTagName(h4Tag)
-        || item->hasTagName(h5Tag)
-        || item->hasTagName(h6Tag);
-}
-    
 static inline bool isRootNode(HTMLStackItem* item)
 {
     return item->isDocumentFragmentNode()
@@ -108,7 +98,7 @@
 {
     return HTMLElementStack::isMathMLTextIntegrationPoint(item)
         || HTMLElementStack::isHTMLIntegrationPoint(item)
-        || isInHTMLNamespace(item);
+        || item->isInHTMLNamespace();
 }
 
 inline bool isButtonScopeMarker(HTMLStackItem* item)
@@ -231,7 +221,7 @@
 
 void HTMLElementStack::popUntilNumberedHeaderElementPopped()
 {
-    while (!isNumberedHeaderElement(topStackItem()))
+    while (!topStackItem()->isNumberedHeaderElement())
         pop();
     pop();
 }
@@ -460,7 +450,7 @@
 {
     for (ElementRecord* record = m_top.get(); record; record = record->next()) {
         HTMLStackItem* item = record->stackItem().get();
-        if (isNumberedHeaderElement(item))
+        if (item->isNumberedHeaderElement())
             return true;
         if (isScopeMarker(item))
             return false;
@@ -598,6 +588,19 @@
     ASSERT_NOT_REACHED();
 }
 
+HTMLElementStack::ElementRecord* HTMLElementStack::furthestBlockForFormattingElement(Element* formattingElement) const
+{
+    ElementRecord* furthestBlock = 0;
+    for (ElementRecord* pos = m_top.get(); pos; pos = pos->next()) {
+        if (pos->element() == formattingElement)
+            return furthestBlock;
+        if (pos->stackItem()->isSpecialNode())
+            furthestBlock = pos;
+    }
+    ASSERT_NOT_REACHED();
+    return 0;
+}
+
 #ifndef NDEBUG
 
 void HTMLElementStack::show()

Modified: trunk/Source/WebCore/html/parser/HTMLElementStack.h (126354 => 126355)


--- trunk/Source/WebCore/html/parser/HTMLElementStack.h	2012-08-22 21:49:16 UTC (rev 126354)
+++ trunk/Source/WebCore/html/parser/HTMLElementStack.h	2012-08-22 21:55:10 UTC (rev 126355)
@@ -101,6 +101,7 @@
     HTMLStackItem* oneBelowTop() const;
     ElementRecord* topRecord() const;
     ElementRecord* find(Element*) const;
+    ElementRecord* furthestBlockForFormattingElement(Element*) const;
     ElementRecord* topmost(const AtomicString& tagName) const;
 
     void insertAbove(PassRefPtr<HTMLStackItem>, ElementRecord*);
@@ -180,15 +181,6 @@
     unsigned m_stackDepth;
 };
     
-inline bool isInHTMLNamespace(const HTMLStackItem* item)
-{
-    // A DocumentFragment takes the place of the document element when parsing
-    // fragments and should be considered in the HTML namespace.
-    return item->namespaceURI() == HTMLNames::xhtmlNamespaceURI
-        || item->isDocumentFragmentNode(); // FIXME: Does this also apply to ShadowRoot?
-}
-
-
 } // namespace WebCore
 
 #endif // HTMLElementStack_h

Modified: trunk/Source/WebCore/html/parser/HTMLStackItem.h (126354 => 126355)


--- trunk/Source/WebCore/html/parser/HTMLStackItem.h	2012-08-22 21:49:16 UTC (rev 126354)
+++ trunk/Source/WebCore/html/parser/HTMLStackItem.h	2012-08-22 21:55:10 UTC (rev 126355)
@@ -29,6 +29,8 @@
 #include "Element.h"
 #include "HTMLNames.h"
 #include "HTMLToken.h"
+#include "MathMLNames.h"
+#include "SVGNames.h"
 
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
@@ -79,6 +81,123 @@
             || hasTagName(HTMLNames::trTag);
     }
 
+    bool isInHTMLNamespace() const
+    {
+        // A DocumentFragment takes the place of the document element when parsing
+        // fragments and should be considered in the HTML namespace.
+        return namespaceURI() == HTMLNames::xhtmlNamespaceURI
+            || isDocumentFragmentNode(); // FIXME: Does this also apply to ShadowRoot?
+    }
+
+    bool isNumberedHeaderElement() const
+    {
+        return hasTagName(HTMLNames::h1Tag)
+            || hasTagName(HTMLNames::h2Tag)
+            || hasTagName(HTMLNames::h3Tag)
+            || hasTagName(HTMLNames::h4Tag)
+            || hasTagName(HTMLNames::h5Tag)
+            || hasTagName(HTMLNames::h6Tag);
+    }
+
+    bool isTableBodyContextElement() const
+    {
+        return hasTagName(HTMLNames::tbodyTag)
+            || hasTagName(HTMLNames::tfootTag)
+            || hasTagName(HTMLNames::theadTag);
+    }
+
+    // http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#special
+    bool isSpecialNode() const
+    {
+        if (hasTagName(MathMLNames::miTag)
+            || hasTagName(MathMLNames::moTag)
+            || hasTagName(MathMLNames::mnTag)
+            || hasTagName(MathMLNames::msTag)
+            || hasTagName(MathMLNames::mtextTag)
+            || hasTagName(MathMLNames::annotation_xmlTag)
+            || hasTagName(SVGNames::foreignObjectTag)
+            || hasTagName(SVGNames::descTag)
+            || hasTagName(SVGNames::titleTag))
+            return true;
+        if (isDocumentFragmentNode())
+            return true;
+        if (!isInHTMLNamespace())
+            return false;
+        const AtomicString& tagName = localName();
+        return tagName == HTMLNames::addressTag
+            || tagName == HTMLNames::appletTag
+            || tagName == HTMLNames::areaTag
+            || tagName == HTMLNames::articleTag
+            || tagName == HTMLNames::asideTag
+            || tagName == HTMLNames::baseTag
+            || tagName == HTMLNames::basefontTag
+            || tagName == HTMLNames::bgsoundTag
+            || tagName == HTMLNames::blockquoteTag
+            || tagName == HTMLNames::bodyTag
+            || tagName == HTMLNames::brTag
+            || tagName == HTMLNames::buttonTag
+            || tagName == HTMLNames::captionTag
+            || tagName == HTMLNames::centerTag
+            || tagName == HTMLNames::colTag
+            || tagName == HTMLNames::colgroupTag
+            || tagName == HTMLNames::commandTag
+            || tagName == HTMLNames::ddTag
+            || tagName == HTMLNames::detailsTag
+            || tagName == HTMLNames::dirTag
+            || tagName == HTMLNames::divTag
+            || tagName == HTMLNames::dlTag
+            || tagName == HTMLNames::dtTag
+            || tagName == HTMLNames::embedTag
+            || tagName == HTMLNames::fieldsetTag
+            || tagName == HTMLNames::figcaptionTag
+            || tagName == HTMLNames::figureTag
+            || tagName == HTMLNames::footerTag
+            || tagName == HTMLNames::formTag
+            || tagName == HTMLNames::frameTag
+            || tagName == HTMLNames::framesetTag
+            || isNumberedHeaderElement()
+            || tagName == HTMLNames::headTag
+            || tagName == HTMLNames::headerTag
+            || tagName == HTMLNames::hgroupTag
+            || tagName == HTMLNames::hrTag
+            || tagName == HTMLNames::htmlTag
+            || tagName == HTMLNames::iframeTag
+            || tagName == HTMLNames::imgTag
+            || tagName == HTMLNames::inputTag
+            || tagName == HTMLNames::isindexTag
+            || tagName == HTMLNames::liTag
+            || tagName == HTMLNames::linkTag
+            || tagName == HTMLNames::listingTag
+            || tagName == HTMLNames::marqueeTag
+            || tagName == HTMLNames::menuTag
+            || tagName == HTMLNames::metaTag
+            || tagName == HTMLNames::navTag
+            || tagName == HTMLNames::noembedTag
+            || tagName == HTMLNames::noframesTag
+            || tagName == HTMLNames::noscriptTag
+            || tagName == HTMLNames::objectTag
+            || tagName == HTMLNames::olTag
+            || tagName == HTMLNames::pTag
+            || tagName == HTMLNames::paramTag
+            || tagName == HTMLNames::plaintextTag
+            || tagName == HTMLNames::preTag
+            || tagName == HTMLNames::scriptTag
+            || tagName == HTMLNames::sectionTag
+            || tagName == HTMLNames::selectTag
+            || tagName == HTMLNames::styleTag
+            || tagName == HTMLNames::summaryTag
+            || tagName == HTMLNames::tableTag
+            || isTableBodyContextElement()
+            || tagName == HTMLNames::tdTag
+            || tagName == HTMLNames::textareaTag
+            || tagName == HTMLNames::thTag
+            || tagName == HTMLNames::titleTag
+            || tagName == HTMLNames::trTag
+            || tagName == HTMLNames::ulTag
+            || tagName == HTMLNames::wbrTag
+            || tagName == HTMLNames::xmpTag;
+    }
+
 private:
     HTMLStackItem(PassRefPtr<ContainerNode> node, ItemType type)
         : m_node(node)

Modified: trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp (126354 => 126355)


--- trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp	2012-08-22 21:49:16 UTC (rev 126354)
+++ trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp	2012-08-22 21:55:10 UTC (rev 126355)
@@ -110,98 +110,6 @@
         || tagName == theadTag;
 }
 
-// http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#special
-static bool isSpecialNode(const HTMLStackItem* item)
-{
-    if (item->hasTagName(MathMLNames::miTag)
-        || item->hasTagName(MathMLNames::moTag)
-        || item->hasTagName(MathMLNames::mnTag)
-        || item->hasTagName(MathMLNames::msTag)
-        || item->hasTagName(MathMLNames::mtextTag)
-        || item->hasTagName(MathMLNames::annotation_xmlTag)
-        || item->hasTagName(SVGNames::foreignObjectTag)
-        || item->hasTagName(SVGNames::descTag)
-        || item->hasTagName(SVGNames::titleTag))
-        return true;
-    if (item->isDocumentFragmentNode())
-        return true;
-    if (!isInHTMLNamespace(item))
-        return false;
-    const AtomicString& tagName = item->localName();
-    return tagName == addressTag
-        || tagName == appletTag
-        || tagName == areaTag
-        || tagName == articleTag
-        || tagName == asideTag
-        || tagName == baseTag
-        || tagName == basefontTag
-        || tagName == bgsoundTag
-        || tagName == blockquoteTag
-        || tagName == bodyTag
-        || tagName == brTag
-        || tagName == buttonTag
-        || tagName == captionTag
-        || tagName == centerTag
-        || tagName == colTag
-        || tagName == colgroupTag
-        || tagName == commandTag
-        || tagName == ddTag
-        || tagName == detailsTag
-        || tagName == dirTag
-        || tagName == divTag
-        || tagName == dlTag
-        || tagName == dtTag
-        || tagName == embedTag
-        || tagName == fieldsetTag
-        || tagName == figcaptionTag
-        || tagName == figureTag
-        || tagName == footerTag
-        || tagName == formTag
-        || tagName == frameTag
-        || tagName == framesetTag
-        || isNumberedHeaderTag(tagName)
-        || tagName == headTag
-        || tagName == headerTag
-        || tagName == hgroupTag
-        || tagName == hrTag
-        || tagName == htmlTag
-        || tagName == iframeTag
-        || tagName == imgTag
-        || tagName == inputTag
-        || tagName == isindexTag
-        || tagName == liTag
-        || tagName == linkTag
-        || tagName == listingTag
-        || tagName == marqueeTag
-        || tagName == menuTag
-        || tagName == metaTag
-        || tagName == navTag
-        || tagName == noembedTag
-        || tagName == noframesTag
-        || tagName == noscriptTag
-        || tagName == objectTag
-        || tagName == olTag
-        || tagName == pTag
-        || tagName == paramTag
-        || tagName == plaintextTag
-        || tagName == preTag
-        || tagName == scriptTag
-        || tagName == sectionTag
-        || tagName == selectTag
-        || tagName == styleTag
-        || tagName == summaryTag
-        || tagName == tableTag
-        || isTableBodyContextTag(tagName)
-        || tagName == tdTag
-        || tagName == textareaTag
-        || tagName == thTag
-        || tagName == titleTag
-        || tagName == trTag
-        || tagName == ulTag
-        || tagName == wbrTag
-        || tagName == xmpTag;
-}
-
 static bool isNonAnchorNonNobrFormattingTag(const AtomicString& tagName)
 {
     return tagName == bTag
@@ -481,7 +389,7 @@
         processToken(token);
 
     bool inForeignContent = !m_tree.isEmpty()
-        && !isInHTMLNamespace(m_tree.currentStackItem())
+        && !m_tree.currentStackItem()->isInHTMLNamespace()
         && !HTMLElementStack::isHTMLIntegrationPoint(m_tree.currentStackItem())
         && !HTMLElementStack::isMathMLTextIntegrationPoint(m_tree.currentStackItem());
 
@@ -640,7 +548,7 @@
             processFakeEndTag(item->localName());
             break;
         }
-        if (isSpecialNode(item.get()) && !item->hasTagName(addressTag) && !item->hasTagName(divTag) && !item->hasTagName(pTag))
+        if (item->isSpecialNode() && !item->hasTagName(addressTag) && !item->hasTagName(divTag) && !item->hasTagName(pTag))
             break;
         nodeRecord = nodeRecord->next();
     }
@@ -816,7 +724,7 @@
     }
     if (isNumberedHeaderTag(token->name())) {
         processFakePEndTagIfPInButtonScope();
-        if (isNumberedHeaderTag(m_tree.currentStackItem()->localName())) {
+        if (m_tree.currentStackItem()->isNumberedHeaderElement()) {
             parseError(token);
             m_tree.openElements()->pop();
         }
@@ -1494,7 +1402,7 @@
             m_tree.openElements()->popUntilPopped(item->element());
             return;
         }
-        if (isSpecialNode(item.get())) {
+        if (item->isSpecialNode()) {
             parseError(token);
             return;
         }
@@ -1502,21 +1410,6 @@
     }
 }
 
-// FIXME: This probably belongs on HTMLElementStack.
-HTMLElementStack::ElementRecord* HTMLTreeBuilder::furthestBlockForFormattingElement(Element* formattingElement)
-{
-    HTMLElementStack::ElementRecord* furthestBlock = 0;
-    HTMLElementStack::ElementRecord* record = m_tree.openElements()->topRecord();
-    for (; record; record = record->next()) {
-        if (record->element() == formattingElement)
-            return furthestBlock;
-        if (isSpecialNode(record->stackItem().get()))
-            furthestBlock = record;
-    }
-    ASSERT_NOT_REACHED();
-    return 0;
-}
-
 // http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#parsing-main-inbody
 void HTMLTreeBuilder::callTheAdoptionAgency(AtomicHTMLToken* token)
 {
@@ -1544,7 +1437,7 @@
         if (formattingElement != m_tree.currentElement())
             parseError(token);
         // 2.
-        HTMLElementStack::ElementRecord* furthestBlock = furthestBlockForFormattingElement(formattingElement);
+        HTMLElementStack::ElementRecord* furthestBlock = m_tree.openElements()->furthestBlockForFormattingElement(formattingElement);
         // 3.
         if (!furthestBlock) {
             m_tree.openElements()->popUntilPopped(formattingElement);
@@ -2656,7 +2549,7 @@
     if (m_tree.isEmpty())
         return false;
     HTMLStackItem* item = m_tree.currentStackItem();
-    if (isInHTMLNamespace(item))
+    if (item->isInHTMLNamespace())
         return false;
     if (HTMLElementStack::isMathMLTextIntegrationPoint(item)) {
         if (token->type() == HTMLTokenTypes::StartTag
@@ -2756,7 +2649,7 @@
             m_tree.openElements()->pop();
             return;
         }
-        if (!isInHTMLNamespace(m_tree.currentStackItem())) {
+        if (!m_tree.currentStackItem()->isInHTMLNamespace()) {
             // FIXME: This code just wants an Element* iterator, instead of an ElementRecord*
             HTMLElementStack::ElementRecord* nodeRecord = m_tree.openElements()->topRecord();
             if (!nodeRecord->stackItem()->hasLocalName(token->name()))
@@ -2768,7 +2661,7 @@
                 }
                 nodeRecord = nodeRecord->next();
 
-                if (isInHTMLNamespace(nodeRecord->stackItem().get()))
+                if (nodeRecord->stackItem()->isInHTMLNamespace())
                     break;
             }
         }

Modified: trunk/Source/WebCore/html/parser/HTMLTreeBuilder.h (126354 => 126355)


--- trunk/Source/WebCore/html/parser/HTMLTreeBuilder.h	2012-08-22 21:49:16 UTC (rev 126354)
+++ trunk/Source/WebCore/html/parser/HTMLTreeBuilder.h	2012-08-22 21:55:10 UTC (rev 126355)
@@ -174,7 +174,6 @@
 
     Vector<Attribute> attributesForIsindexInput(AtomicHTMLToken*);
 
-    HTMLElementStack::ElementRecord* furthestBlockForFormattingElement(Element*);
     void callTheAdoptionAgency(AtomicHTMLToken*);
 
     void closeTheCell();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to