#ifndef HTMLStackItem_h
#define HTMLStackItem_h
#include "HTMLNames.h"
#include "MathMLNames.h"
#include "SVGNames.h"
#include "core/dom/Element.h"
#include "core/html/parser/AtomicHTMLToken.h"
#include "wtf/RefCounted.h"
#include "wtf/RefPtr.h"
#include "wtf/text/AtomicString.h"
namespace WebCore {
class ContainerNode;
class HTMLStackItem : public RefCounted<HTMLStackItem> {
public:
enum ItemType {
ItemForContextElement,
ItemForDocumentFragmentNode
};
static PassRefPtr<HTMLStackItem> create(PassRefPtr<ContainerNode> node, ItemType type)
{
return adoptRef(new HTMLStackItem(node, type));
}
static PassRefPtr<HTMLStackItem> create(PassRefPtr<ContainerNode> node, AtomicHTMLToken* token, const AtomicString& namespaceURI = HTMLNames::xhtmlNamespaceURI)
{
return adoptRef(new HTMLStackItem(node, token, namespaceURI));
}
Element* element() const { return toElement(m_node.get()); }
ContainerNode* node() const { return m_node.get(); }
bool isDocumentFragmentNode() const { return m_isDocumentFragmentNode; }
bool isElementNode() const { return !m_isDocumentFragmentNode; }
const AtomicString& namespaceURI() const { return m_namespaceURI; }
const AtomicString& localName() const { return m_tokenLocalName; }
const Vector<Attribute>& attributes() const { ASSERT(m_tokenLocalName); return m_tokenAttributes; }
Attribute* getAttributeItem(const QualifiedName& attributeName)
{
ASSERT(m_tokenLocalName);
return findAttributeInVector(m_tokenAttributes, attributeName);
}
bool hasLocalName(const AtomicString& name) const { return m_tokenLocalName == name; }
bool hasTagName(const QualifiedName& name) const { return m_tokenLocalName == name.localName() && m_namespaceURI == name.namespaceURI(); }
bool matchesHTMLTag(const AtomicString& name) const { return m_tokenLocalName == name && m_namespaceURI == HTMLNames::xhtmlNamespaceURI; }
bool matchesHTMLTag(const QualifiedName& name) const { return m_tokenLocalName == name && m_namespaceURI == HTMLNames::xhtmlNamespaceURI; }
bool causesFosterParenting()
{
return hasTagName(HTMLNames::tableTag)
|| hasTagName(HTMLNames::tbodyTag)
|| hasTagName(HTMLNames::tfootTag)
|| hasTagName(HTMLNames::theadTag)
|| hasTagName(HTMLNames::trTag);
}
bool isInHTMLNamespace() const
{
return namespaceURI() == HTMLNames::xhtmlNamespaceURI
|| isDocumentFragmentNode();
}
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);
}
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::liTag
|| tagName == HTMLNames::linkTag
|| tagName == HTMLNames::listingTag
|| tagName == HTMLNames::mainTag
|| 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::templateTag
|| 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)
{
switch (type) {
case ItemForDocumentFragmentNode:
m_isDocumentFragmentNode = true;
break;
case ItemForContextElement:
m_tokenLocalName = m_node->localName();
m_namespaceURI = m_node->namespaceURI();
m_isDocumentFragmentNode = false;
break;
}
}
HTMLStackItem(PassRefPtr<ContainerNode> node, AtomicHTMLToken* token, const AtomicString& namespaceURI = HTMLNames::xhtmlNamespaceURI)
: m_node(node)
, m_tokenLocalName(token->name())
, m_tokenAttributes(token->attributes())
, m_namespaceURI(namespaceURI)
, m_isDocumentFragmentNode(false)
{
}
RefPtr<ContainerNode> m_node;
AtomicString m_tokenLocalName;
Vector<Attribute> m_tokenAttributes;
AtomicString m_namespaceURI;
bool m_isDocumentFragmentNode;
};
}
#endif