Remove almost all clients of isHTMLElement

This CL is progress towards deleting the concept of an HTMLElement entirely. We
won't actually get all the way there in this CL series, but we're getting
closer. This CL also will let us make custom elements just be Elements instead
of HTMLElements.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/942933003
This commit is contained in:
Adam Barth 2015-02-20 12:06:15 -08:00
parent a42e249b69
commit 178be1d89d
17 changed files with 22 additions and 68 deletions

View File

@ -71,7 +71,7 @@ static void create{{namespace}}FunctionMap()
g_constructors->set(data[i].tag.localName(), data[i].func);
}
PassRefPtr<{{namespace}}Element> {{namespace}}ElementFactory::create{{namespace}}Element(
PassRefPtr<Element> {{namespace}}ElementFactory::createElement(
const AtomicString& localName,
Document& document,
bool createdByParser)
@ -81,11 +81,8 @@ PassRefPtr<{{namespace}}Element> {{namespace}}ElementFactory::create{{namespace}
if (ConstructorFunction function = g_constructors->get(localName))
return function(document, createdByParser);
if (CustomElement::isValidName(localName)) {
RefPtr<Element> element = document.registrationContext().createCustomTagElement(document, QualifiedName(localName));
ASSERT_WITH_SECURITY_IMPLICATION(element->is{{namespace}}Element());
return static_pointer_cast<{{namespace}}Element>(element.release());
}
if (CustomElement::isValidName(localName))
return document.registrationContext().createCustomTagElement(document, QualifiedName(localName));
return {{fallback_interface}}::create(QualifiedName(localName), document);
}

View File

@ -10,11 +10,11 @@
namespace blink {
class Document;
class {{namespace}}Element;
class Element;
class {{namespace}}ElementFactory {
public:
static PassRefPtr<{{namespace}}Element> create{{namespace}}Element(
static PassRefPtr<Element> createElement(
const AtomicString& localName,
Document&,
bool createdByParser = true);

View File

@ -415,7 +415,7 @@ PassRefPtr<Element> Document::createElement(const AtomicString& name, ExceptionS
return nullptr;
}
return HTMLElementFactory::createHTMLElement(name, *this, false);
return HTMLElementFactory::createElement(name, *this, false);
}
PassRefPtr<DartValue> Document::registerElement(DartState*, const AtomicString& name, ExceptionState& exceptionState)
@ -585,7 +585,7 @@ PassRefPtr<Node> Document::adoptNode(PassRefPtr<Node> source, ExceptionState& ex
PassRefPtr<Element> Document::createElement(const QualifiedName& qName, bool createdByParser)
{
// FIXME(sky): This should only take a local name.
return HTMLElementFactory::createHTMLElement(qName.localName(), *this, createdByParser);
return HTMLElementFactory::createElement(qName.localName(), *this, createdByParser);
}
String Document::readyState() const

View File

@ -173,10 +173,6 @@ PassRefPtr<Element> Element::cloneElementWithChildren()
PassRefPtr<Element> Element::cloneElementWithoutChildren()
{
RefPtr<Element> clone = cloneElementWithoutAttributesAndChildren();
// This will catch HTML elements in the wrong namespace that are not correctly copied.
// This is a sanity check as HTML overloads some of the DOM methods.
ASSERT(isHTMLElement() == clone->isHTMLElement());
clone->cloneDataFromElement(*this);
return clone.release();
}

View File

@ -135,7 +135,6 @@ public:
String tagName() const { return nodeName(); }
bool hasTagName(const QualifiedName& tagName) const { return m_tagName == tagName; }
bool hasTagName(const HTMLQualifiedName& name) const { return hasLocalName(name.localName()); }
// A fast function for checking the local name against another atomic string.
bool hasLocalName(const AtomicString& other) const { return m_tagName.localName() == other; }
@ -521,11 +520,6 @@ inline ShadowRoot* Node::shadowRoot() const
return toElement(this)->shadowRoot();
}
inline bool Node::hasTagName(const HTMLQualifiedName& name) const
{
return isHTMLElement() && toElement(*this).hasTagName(name);
}
inline void Element::invalidateStyleAttribute()
{
ASSERT(elementData());

View File

@ -461,7 +461,7 @@ bool Node::hasEditableStyle(EditableLevel editableLevel, UserSelectAllTreatment
// would fire in the middle of Document::setFocusedNode().
for (const Node* node = this; node; node = node->parentNode()) {
if (node->isHTMLElement() && node->renderer()) {
if (node->isElementNode() && node->renderer()) {
// Elements with user-select: all style are considered atomic
// therefore non editable.
if (Position::nodeIsUserSelectAll(node) && treatment == UserSelectAllIsAlwaysNonEditable)
@ -1626,7 +1626,7 @@ void Node::setCustomElementState(CustomElementState newState)
break;
}
ASSERT(isHTMLElement());
ASSERT(isElementNode());
setFlag(CustomElementFlag);
setFlag(newState == Upgraded, CustomElementUpgradedFlag);
}

View File

@ -53,7 +53,6 @@ class EventListener;
class ExceptionState;
class FloatPoint;
class LocalFrame;
class HTMLQualifiedName;
class IntRect;
class KeyboardEvent;
class NSResolver;
@ -134,7 +133,6 @@ public:
// DOM methods & attributes for Node
bool hasTagName(const HTMLQualifiedName&) const;
virtual String nodeName() const = 0;
virtual NodeType nodeType() const = 0;
ContainerNode* parentNode() const;
@ -197,7 +195,7 @@ public:
// PseudoElements and VTTElements. It's possible we can just eliminate all the checks
// since those elements will never have class names, inline style, or other things that
// this apparently guards against.
bool isStyledElement() const { return isHTMLElement(); }
bool isStyledElement() const { return isElementNode(); }
bool isDocumentNode() const;
bool isTreeScope() const;

View File

@ -230,12 +230,4 @@ VisiblePosition ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfN
return VisiblePosition(Position(text.get(), position.offsetInContainerNode() - 1));
}
PassRefPtr<HTMLElement> ApplyBlockElementCommand::createBlockElement() const
{
RefPtr<HTMLElement> element = createHTMLElement(document(), m_tagName);
if (m_inlineStyle.length())
element->setAttribute(HTMLNames::styleAttr, m_inlineStyle);
return element.release();
}
}

View File

@ -42,7 +42,6 @@ protected:
ApplyBlockElementCommand(Document&, const QualifiedName& tagName);
virtual void formatSelection(const VisiblePosition& startOfSelection, const VisiblePosition& endOfSelection);
PassRefPtr<HTMLElement> createBlockElement() const;
const QualifiedName tagName() const { return m_tagName; }
private:

View File

@ -459,7 +459,7 @@ static const Vector<OwnPtr<HTMLAttributeEquivalent> >& htmlAttributeEquivalents(
return HTMLAttributeEquivalents;
}
bool EditingStyle::elementIsStyledSpanOrHTMLEquivalent(const HTMLElement* element)
bool EditingStyle::elementIsStyledSpanOrHTMLEquivalent(const Element* element)
{
ASSERT(element);
bool elementIsSpanOrElementEquivalent = false;

View File

@ -104,7 +104,7 @@ public:
void removeBlockProperties();
static bool elementIsStyledSpanOrHTMLEquivalent(const HTMLElement*);
static bool elementIsStyledSpanOrHTMLEquivalent(const Element*);
void mergeTypingStyle(Document*);

View File

@ -489,12 +489,12 @@ static bool isInlineHTMLElementWithStyle(const Node* node)
if (isBlock(node))
return false;
if (!node->isHTMLElement())
if (!node->isElementNode())
return false;
// We can skip over elements whose class attribute is
// one of our internal classes.
const HTMLElement* element = toHTMLElement(node);
const Element* element = toElement(node);
const AtomicString& classAttributeValue = element->getAttribute(HTMLNames::classAttr);
if (classAttributeValue == AppleTabSpanClass)
return true;

View File

@ -390,7 +390,7 @@ bool isSpecialHTMLElement(const Node* n)
if (!n)
return false;
if (!n->isHTMLElement())
if (!n->isElementNode())
return false;
if (n->isLink())
@ -608,7 +608,7 @@ Element* enclosingAnchorElement(const Position& p)
bool canMergeLists(Element* firstList, Element* secondList)
{
if (!firstList || !secondList || !firstList->isHTMLElement() || !secondList->isHTMLElement())
if (!firstList || !secondList)
return false;
return firstList->hasTagName(secondList->tagQName()) // make sure the list types match (ol vs. ul)
@ -633,16 +633,6 @@ PassRefPtr<HTMLElement> createDefaultParagraphElement(Document& document)
return nullptr;
}
PassRefPtr<HTMLElement> createHTMLElement(Document& document, const QualifiedName& name)
{
return createHTMLElement(document, name.localName());
}
PassRefPtr<HTMLElement> createHTMLElement(Document& document, const AtomicString& tagName)
{
return HTMLElementFactory::createHTMLElement(tagName, document, false);
}
bool isNodeRendered(const Node *node)
{
return node && node->renderer();

View File

@ -198,8 +198,6 @@ PassRefPtr<Range> createRange(Document&, const VisiblePosition& start, const Vis
// Functions returning HTMLElement
PassRefPtr<HTMLElement> createDefaultParagraphElement(Document&);
PassRefPtr<HTMLElement> createHTMLElement(Document&, const QualifiedName&);
PassRefPtr<HTMLElement> createHTMLElement(Document&, const AtomicString&);
// -------------------------------------------------------------------------
// Element

View File

@ -56,8 +56,7 @@ inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document& document
#define DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType) \
inline bool is##thisType(const thisType* element); \
inline bool is##thisType(const thisType& element); \
inline bool is##thisType(const HTMLElement* element) { return element && is##thisType(*element); } \
inline bool is##thisType(const Node& node) { return node.isHTMLElement() ? is##thisType(toHTMLElement(node)) : false; } \
inline bool is##thisType(const Node& node) { return node.isElementNode() ? is##thisType(toElement(node)) : false; } \
inline bool is##thisType(const Node* node) { return node && is##thisType(*node); } \
inline bool is##thisType(const Element* element) { return element && is##thisType(*element); } \
template<typename T> inline bool is##thisType(const PassRefPtr<T>& node) { return is##thisType(node.get()); } \

View File

@ -275,7 +275,7 @@ void HTMLConstructionSite::finishedParsing()
void HTMLConstructionSite::insertHTMLElement(AtomicHTMLToken* token)
{
RefPtr<HTMLElement> element = createHTMLElement(token);
RefPtr<Element> element = createElement(token);
attachLater(currentNode(), element);
m_openElements.push(element.release());
}
@ -286,7 +286,7 @@ void HTMLConstructionSite::insertSelfClosingHTMLElement(AtomicHTMLToken* token)
// Normally HTMLElementStack is responsible for calling finishParsingChildren,
// but self-closing elements are never in the element stack so the stack
// doesn't get a chance to tell them that we're done parsing their children.
attachLater(currentNode(), createHTMLElement(token), true);
attachLater(currentNode(), createElement(token), true);
// FIXME: Do we want to acknowledge the token's self-closing flag?
// http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#acknowledge-self-closing-flag
}
@ -316,14 +316,6 @@ void HTMLConstructionSite::insertTextNode(const String& string)
m_pendingText.append(dummyTask.parent, string);
}
PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token, const AtomicString& namespaceURI)
{
QualifiedName tagName(token->name());
RefPtr<Element> element = ownerDocumentForCurrentNode().createElement(tagName, true);
setAttributes(element.get(), token);
return element.release();
}
inline Document& HTMLConstructionSite::ownerDocumentForCurrentNode()
{
if (isHTMLTemplateElement(*currentNode()))
@ -331,10 +323,10 @@ inline Document& HTMLConstructionSite::ownerDocumentForCurrentNode()
return currentNode()->document();
}
PassRefPtr<HTMLElement> HTMLConstructionSite::createHTMLElement(AtomicHTMLToken* token)
PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token)
{
Document& document = ownerDocumentForCurrentNode();
RefPtr<HTMLElement> element = HTMLElementFactory::createHTMLElement(token->name(), document, true);
RefPtr<Element> element = HTMLElementFactory::createElement(token->name(), document, true);
setAttributes(element.get(), token);
return element.release();
}

View File

@ -120,8 +120,7 @@ private:
void attachLater(ContainerNode* parent, PassRefPtr<Node> child, bool selfClosing = false);
PassRefPtr<HTMLElement> createHTMLElement(AtomicHTMLToken*);
PassRefPtr<Element> createElement(AtomicHTMLToken*, const AtomicString& namespaceURI);
PassRefPtr<Element> createElement(AtomicHTMLToken*);
void queueTask(const HTMLConstructionSiteTask&);