summaryrefslogtreecommitdiff
path: root/Source/WebCore/html/parser
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/html/parser')
-rw-r--r--Source/WebCore/html/parser/HTMLElementStack.cpp29
-rw-r--r--Source/WebCore/html/parser/HTMLElementStack.h10
-rw-r--r--Source/WebCore/html/parser/HTMLStackItem.h119
-rw-r--r--Source/WebCore/html/parser/HTMLTreeBuilder.cpp123
-rw-r--r--Source/WebCore/html/parser/HTMLTreeBuilder.h1
5 files changed, 144 insertions, 138 deletions
diff --git a/Source/WebCore/html/parser/HTMLElementStack.cpp b/Source/WebCore/html/parser/HTMLElementStack.cpp
index 62ed6f4e3..6c220c973 100644
--- a/Source/WebCore/html/parser/HTMLElementStack.cpp
+++ b/Source/WebCore/html/parser/HTMLElementStack.cpp
@@ -38,16 +38,6 @@ namespace WebCore {
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 @@ inline bool isForeignContentScopeMarker(HTMLStackItem* item)
{
return HTMLElementStack::isMathMLTextIntegrationPoint(item)
|| HTMLElementStack::isHTMLIntegrationPoint(item)
- || isInHTMLNamespace(item);
+ || item->isInHTMLNamespace();
}
inline bool isButtonScopeMarker(HTMLStackItem* item)
@@ -231,7 +221,7 @@ void HTMLElementStack::popUntilPopped(const AtomicString& tagName)
void HTMLElementStack::popUntilNumberedHeaderElementPopped()
{
- while (!isNumberedHeaderElement(topStackItem()))
+ while (!topStackItem()->isNumberedHeaderElement())
pop();
pop();
}
@@ -460,7 +450,7 @@ bool HTMLElementStack::hasNumberedHeaderElementInScope() const
{
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 @@ void HTMLElementStack::removeNonTopCommon(Element* element)
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()
diff --git a/Source/WebCore/html/parser/HTMLElementStack.h b/Source/WebCore/html/parser/HTMLElementStack.h
index 620c5a194..1aaa20448 100644
--- a/Source/WebCore/html/parser/HTMLElementStack.h
+++ b/Source/WebCore/html/parser/HTMLElementStack.h
@@ -101,6 +101,7 @@ public:
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 @@ private:
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
diff --git a/Source/WebCore/html/parser/HTMLStackItem.h b/Source/WebCore/html/parser/HTMLStackItem.h
index 371ac43f4..0a183bc26 100644
--- a/Source/WebCore/html/parser/HTMLStackItem.h
+++ b/Source/WebCore/html/parser/HTMLStackItem.h
@@ -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 @@ public:
|| 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)
diff --git a/Source/WebCore/html/parser/HTMLTreeBuilder.cpp b/Source/WebCore/html/parser/HTMLTreeBuilder.cpp
index 9e91b5381..522a4409b 100644
--- a/Source/WebCore/html/parser/HTMLTreeBuilder.cpp
+++ b/Source/WebCore/html/parser/HTMLTreeBuilder.cpp
@@ -110,98 +110,6 @@ static bool isTableBodyContextTag(const AtomicString& tagName)
|| 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 @@ void HTMLTreeBuilder::constructTreeFromAtomicToken(AtomicHTMLToken* token)
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 @@ void HTMLTreeBuilder::processCloseWhenNestedTag(AtomicHTMLToken* token)
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 @@ void HTMLTreeBuilder::processStartTagForInBody(AtomicHTMLToken* token)
}
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 @@ void HTMLTreeBuilder::processAnyOtherEndTagForInBody(AtomicHTMLToken* token)
m_tree.openElements()->popUntilPopped(item->element());
return;
}
- if (isSpecialNode(item.get())) {
+ if (item->isSpecialNode()) {
parseError(token);
return;
}
@@ -1502,21 +1410,6 @@ void HTMLTreeBuilder::processAnyOtherEndTagForInBody(AtomicHTMLToken* token)
}
}
-// 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 @@ void HTMLTreeBuilder::callTheAdoptionAgency(AtomicHTMLToken* token)
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 @@ bool HTMLTreeBuilder::shouldProcessTokenInForeignContent(AtomicHTMLToken* token)
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 @@ void HTMLTreeBuilder::processTokenInForeignContent(AtomicHTMLToken* token)
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 @@ void HTMLTreeBuilder::processTokenInForeignContent(AtomicHTMLToken* token)
}
nodeRecord = nodeRecord->next();
- if (isInHTMLNamespace(nodeRecord->stackItem().get()))
+ if (nodeRecord->stackItem()->isInHTMLNamespace())
break;
}
}
diff --git a/Source/WebCore/html/parser/HTMLTreeBuilder.h b/Source/WebCore/html/parser/HTMLTreeBuilder.h
index 86d229de0..c57362783 100644
--- a/Source/WebCore/html/parser/HTMLTreeBuilder.h
+++ b/Source/WebCore/html/parser/HTMLTreeBuilder.h
@@ -174,7 +174,6 @@ private:
Vector<Attribute> attributesForIsindexInput(AtomicHTMLToken*);
- HTMLElementStack::ElementRecord* furthestBlockForFormattingElement(Element*);
void callTheAdoptionAgency(AtomicHTMLToken*);
void closeTheCell();