Commit 80e32d25 authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Optimize / clean up hasTagName() call sites

Optimize / clean up hasTagName() call sites so that they call when possible
and in this order:
- HTMLElement::hasTagName(HTMLQualifiedName) / SVGElement::hasTagName(SVGQualifiedName)
- Node::hasTagName(HTMLQualifiedName) / Node::hasTagName(SVGQualifiedName)
- Element::hasTagName(QualifiedName)

Also use isHTML*Element() helpers in a couple of places to improve readability.

This is a follow-up to:
https://src.chromium.org/viewvc/blink?view=rev&revision=178540

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/405973004

git-svn-id: svn://svn.chromium.org/blink/trunk@178581 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 79d683e3
......@@ -37,6 +37,7 @@
#include "core/html/HTMLInputElement.h"
#include "core/html/HTMLLabelElement.h"
#include "core/html/HTMLLegendElement.h"
#include "core/html/HTMLPlugInElement.h"
#include "core/html/HTMLSelectElement.h"
#include "core/html/HTMLTextAreaElement.h"
#include "core/rendering/RenderObject.h"
......@@ -224,7 +225,7 @@ AccessibilityRole AXNodeObject::determineAccessibilityRole()
return GroupRole;
if (isHTMLAnchorElement(*node()) && isClickable())
return LinkRole;
if (node()->hasTagName(iframeTag))
if (isHTMLIFrameElement(*node()))
return IframeRole;
if (isEmbeddedObject())
return EmbeddedObjectRole;
......@@ -477,9 +478,7 @@ bool AXNodeObject::isControl() const
bool AXNodeObject::isEmbeddedObject() const
{
return node()
&& (node()->hasTagName(objectTag) || node()->hasTagName(embedTag)
|| node()->hasTagName(appletTag));
return isHTMLPlugInElement(node());
}
bool AXNodeObject::isFieldset() const
......@@ -814,27 +813,31 @@ int AXNodeObject::headingLevel() const
// headings can be in block flow and non-block flow
Node* node = this->node();
if (!node)
return false;
return 0;
if (ariaRoleAttribute() == HeadingRole)
return getAttribute(aria_levelAttr).toInt();
if (node->hasTagName(h1Tag))
if (!node->isHTMLElement())
return 0;
HTMLElement& element = toHTMLElement(*node);
if (element.hasTagName(h1Tag))
return 1;
if (node->hasTagName(h2Tag))
if (element.hasTagName(h2Tag))
return 2;
if (node->hasTagName(h3Tag))
if (element.hasTagName(h3Tag))
return 3;
if (node->hasTagName(h4Tag))
if (element.hasTagName(h4Tag))
return 4;
if (node->hasTagName(h5Tag))
if (element.hasTagName(h5Tag))
return 5;
if (node->hasTagName(h6Tag))
if (element.hasTagName(h6Tag))
return 6;
return 0;
......
......@@ -1991,7 +1991,7 @@ RenderObject* AXRenderObject::renderParentObject() const
return parent;
}
bool AXRenderObject::isDescendantOfElementType(const QualifiedName& tagName) const
bool AXRenderObject::isDescendantOfElementType(const HTMLQualifiedName& tagName) const
{
for (RenderObject* parent = m_renderer->parent(); parent; parent = parent->parent()) {
if (parent->node() && parent->node()->hasTagName(tagName))
......
......@@ -209,7 +209,7 @@ private:
AXObject* accessibilityImageMapHitTest(HTMLAreaElement*, const IntPoint&) const;
bool renderObjectIsObservable(RenderObject*) const;
RenderObject* renderParentObject() const;
bool isDescendantOfElementType(const QualifiedName& tagName) const;
bool isDescendantOfElementType(const HTMLQualifiedName& tagName) const;
bool isSVGImage() const;
void detachRemoteSVGRoot();
AXSVGRoot* remoteSVGRootElement() const;
......
......@@ -144,7 +144,7 @@ bool AXTable::isDataTable() const
Element* rowElement = rows->item(rowIndex);
if (elementHasAriaRole(rowElement))
return false;
if (rowElement->hasTagName(trTag)) {
if (isHTMLTableRowElement(*rowElement)) {
RefPtrWillBeRawPtr<HTMLCollection> cells = toHTMLTableRowElement(rowElement)->cells();
for (unsigned cellIndex = 0; cellIndex < cells->length(); ++cellIndex) {
if (elementHasAriaRole(cells->item(cellIndex)))
......
......@@ -24,7 +24,7 @@ class AffectedByFocusTest : public ::testing::Test {
protected:
struct ElementResult {
const blink::QualifiedName tag;
const blink::HTMLQualifiedName tag;
bool affectedBy;
bool childrenOrSiblingsAffectedBy;
};
......
......@@ -157,7 +157,7 @@ class HTMLElementEquivalent : public NoBaseWillBeGarbageCollected<HTMLElementEqu
WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(HTMLElementEquivalent);
public:
static PassOwnPtrWillBeRawPtr<HTMLElementEquivalent> create(CSSPropertyID propertyID, CSSValueID primitiveValue, const QualifiedName& tagName)
static PassOwnPtrWillBeRawPtr<HTMLElementEquivalent> create(CSSPropertyID propertyID, CSSValueID primitiveValue, const HTMLQualifiedName& tagName)
{
return adoptPtrWillBeNoop(new HTMLElementEquivalent(propertyID, primitiveValue, tagName));
}
......@@ -172,11 +172,11 @@ public:
protected:
HTMLElementEquivalent(CSSPropertyID);
HTMLElementEquivalent(CSSPropertyID, const QualifiedName& tagName);
HTMLElementEquivalent(CSSPropertyID, CSSValueID primitiveValue, const QualifiedName& tagName);
HTMLElementEquivalent(CSSPropertyID, const HTMLQualifiedName& tagName);
HTMLElementEquivalent(CSSPropertyID, CSSValueID primitiveValue, const HTMLQualifiedName& tagName);
const CSSPropertyID m_propertyID;
const RefPtrWillBeMember<CSSPrimitiveValue> m_primitiveValue;
const QualifiedName* m_tagName; // We can store a pointer because HTML tag names are const global.
const HTMLQualifiedName* m_tagName; // We can store a pointer because HTML tag names are const global.
};
DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(HTMLElementEquivalent);
......@@ -187,13 +187,13 @@ HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id)
{
}
HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, const QualifiedName& tagName)
HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, const HTMLQualifiedName& tagName)
: m_propertyID(id)
, m_tagName(&tagName)
{
}
HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, CSSValueID primitiveValue, const QualifiedName& tagName)
HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, CSSValueID primitiveValue, const HTMLQualifiedName& tagName)
: m_propertyID(id)
, m_primitiveValue(CSSPrimitiveValue::createIdentifier(primitiveValue))
, m_tagName(&tagName)
......@@ -214,7 +214,7 @@ void HTMLElementEquivalent::addToStyle(Element*, EditingStyle* style) const
class HTMLTextDecorationEquivalent FINAL : public HTMLElementEquivalent {
public:
static PassOwnPtrWillBeRawPtr<HTMLElementEquivalent> create(CSSValueID primitiveValue, const QualifiedName& tagName)
static PassOwnPtrWillBeRawPtr<HTMLElementEquivalent> create(CSSValueID primitiveValue, const HTMLQualifiedName& tagName)
{
return adoptPtrWillBeNoop(new HTMLTextDecorationEquivalent(primitiveValue, tagName));
}
......@@ -224,10 +224,10 @@ public:
virtual void trace(Visitor* visitor) OVERRIDE { HTMLElementEquivalent::trace(visitor); }
private:
HTMLTextDecorationEquivalent(CSSValueID primitiveValue, const QualifiedName& tagName);
HTMLTextDecorationEquivalent(CSSValueID primitiveValue, const HTMLQualifiedName& tagName);
};
HTMLTextDecorationEquivalent::HTMLTextDecorationEquivalent(CSSValueID primitiveValue, const QualifiedName& tagName)
HTMLTextDecorationEquivalent::HTMLTextDecorationEquivalent(CSSValueID primitiveValue, const HTMLQualifiedName& tagName)
: HTMLElementEquivalent(textDecorationPropertyForEditing(), primitiveValue, tagName)
// m_propertyID is used in HTMLElementEquivalent::addToStyle
{
......@@ -249,7 +249,7 @@ bool HTMLTextDecorationEquivalent::valueIsPresentInStyle(Element* element, Style
class HTMLAttributeEquivalent : public HTMLElementEquivalent {
public:
static PassOwnPtrWillBeRawPtr<HTMLAttributeEquivalent> create(CSSPropertyID propertyID, const QualifiedName& tagName, const QualifiedName& attrName)
static PassOwnPtrWillBeRawPtr<HTMLAttributeEquivalent> create(CSSPropertyID propertyID, const HTMLQualifiedName& tagName, const QualifiedName& attrName)
{
return adoptPtrWillBeNoop(new HTMLAttributeEquivalent(propertyID, tagName, attrName));
}
......@@ -268,12 +268,12 @@ public:
virtual void trace(Visitor* visitor) OVERRIDE { HTMLElementEquivalent::trace(visitor); }
protected:
HTMLAttributeEquivalent(CSSPropertyID, const QualifiedName& tagName, const QualifiedName& attrName);
HTMLAttributeEquivalent(CSSPropertyID, const HTMLQualifiedName& tagName, const QualifiedName& attrName);
HTMLAttributeEquivalent(CSSPropertyID, const QualifiedName& attrName);
const QualifiedName& m_attrName; // We can store a reference because HTML attribute names are const global.
};
HTMLAttributeEquivalent::HTMLAttributeEquivalent(CSSPropertyID id, const QualifiedName& tagName, const QualifiedName& attrName)
HTMLAttributeEquivalent::HTMLAttributeEquivalent(CSSPropertyID id, const HTMLQualifiedName& tagName, const QualifiedName& attrName)
: HTMLElementEquivalent(id, tagName)
, m_attrName(attrName)
{
......
......@@ -80,7 +80,7 @@ PassRefPtrWillBeRawPtr<HTMLElement> InsertListCommand::mergeWithNeighboringLists
return list.release();
}
bool InsertListCommand::selectionHasListOfType(const VisibleSelection& selection, const QualifiedName& listTag)
bool InsertListCommand::selectionHasListOfType(const VisibleSelection& selection, const HTMLQualifiedName& listTag)
{
VisiblePosition start = selection.visibleStart();
......@@ -317,7 +317,7 @@ void InsertListCommand::unlistifyParagraph(const VisiblePosition& originalStart,
moveParagraphs(start, end, insertionPoint, /* preserveSelection */ true, /* preserveStyle */ true, listChildNode);
}
static Element* adjacentEnclosingList(const VisiblePosition& pos, const VisiblePosition& adjacentPos, const QualifiedName& listTag)
static Element* adjacentEnclosingList(const VisiblePosition& pos, const VisiblePosition& adjacentPos, const HTMLQualifiedName& listTag)
{
Element* listNode = outermostEnclosingList(adjacentPos.deepEquivalent().deprecatedNode());
......@@ -336,7 +336,7 @@ static Element* adjacentEnclosingList(const VisiblePosition& pos, const VisibleP
return listNode;
}
PassRefPtrWillBeRawPtr<HTMLElement> InsertListCommand::listifyParagraph(const VisiblePosition& originalStart, const QualifiedName& listTag)
PassRefPtrWillBeRawPtr<HTMLElement> InsertListCommand::listifyParagraph(const VisiblePosition& originalStart, const HTMLQualifiedName& listTag)
{
VisiblePosition start = startOfParagraph(originalStart, CanSkipOverEditingBoundary);
VisiblePosition end = endOfParagraph(start, CanSkipOverEditingBoundary);
......
......@@ -52,11 +52,11 @@ private:
virtual EditAction editingAction() const OVERRIDE { return EditActionInsertList; }
HTMLElement* fixOrphanedListChild(Node*);
bool selectionHasListOfType(const VisibleSelection& selection, const QualifiedName&);
bool selectionHasListOfType(const VisibleSelection&, const HTMLQualifiedName&);
PassRefPtrWillBeRawPtr<HTMLElement> mergeWithNeighboringLists(PassRefPtrWillBeRawPtr<HTMLElement>);
void doApplyForSingleParagraph(bool forceCreateList, const HTMLQualifiedName&, Range& currentSelection);
void unlistifyParagraph(const VisiblePosition& originalStart, HTMLElement* listNode, Node* listChildNode);
PassRefPtrWillBeRawPtr<HTMLElement> listifyParagraph(const VisiblePosition& originalStart, const QualifiedName& listTag);
PassRefPtrWillBeRawPtr<HTMLElement> listifyParagraph(const VisiblePosition& originalStart, const HTMLQualifiedName& listTag);
RefPtrWillBeMember<HTMLElement> m_listElement;
Type m_type;
......
......@@ -125,9 +125,9 @@ String MarkupAccumulator::serializeNodes(Node& targetNode, EChildrenOnly childre
void MarkupAccumulator::serializeNodesWithNamespaces(Node& targetNode, EChildrenOnly childrenOnly, const Namespaces* namespaces, Vector<QualifiedName>* tagNamesToSkip)
{
if (tagNamesToSkip) {
if (tagNamesToSkip && targetNode.isElementNode()) {
for (size_t i = 0; i < tagNamesToSkip->size(); ++i) {
if (targetNode.hasTagName(tagNamesToSkip->at(i)))
if (toElement(targetNode).hasTagName(tagNamesToSkip->at(i)))
return;
}
}
......
......@@ -437,15 +437,16 @@ static bool isMailPasteAsQuotationNode(const Node* node)
static bool isHeaderElement(const Node* a)
{
if (!a)
if (!a || !a->isHTMLElement())
return false;
return a->hasTagName(h1Tag)
|| a->hasTagName(h2Tag)
|| a->hasTagName(h3Tag)
|| a->hasTagName(h4Tag)
|| a->hasTagName(h5Tag)
|| a->hasTagName(h6Tag);
const HTMLElement& element = toHTMLElement(*a);
return element.hasTagName(h1Tag)
|| element.hasTagName(h2Tag)
|| element.hasTagName(h3Tag)
|| element.hasTagName(h4Tag)
|| element.hasTagName(h5Tag)
|| element.hasTagName(h6Tag);
}
static bool haveSameTagName(Node* a, Node* b)
......@@ -460,8 +461,8 @@ bool ReplaceSelectionCommand::shouldMerge(const VisiblePosition& source, const V
Node* sourceNode = source.deepEquivalent().deprecatedNode();
Node* destinationNode = destination.deepEquivalent().deprecatedNode();
Node* sourceBlock = enclosingBlock(sourceNode);
Node* destinationBlock = enclosingBlock(destinationNode);
Element* sourceBlock = enclosingBlock(sourceNode);
Element* destinationBlock = enclosingBlock(destinationNode);
return !enclosingNodeOfType(source.deepEquivalent(), &isMailPasteAsQuotationNode) &&
sourceBlock && (!sourceBlock->hasTagName(blockquoteTag) || isMailBlockquote(sourceBlock)) &&
enclosingListChild(sourceBlock) == enclosingListChild(destinationNode) &&
......
......@@ -77,7 +77,7 @@ void HTMLTableElement::setCaption(PassRefPtrWillBeRawPtr<HTMLTableCaptionElement
HTMLTableSectionElement* HTMLTableElement::tHead() const
{
for (Element* child = ElementTraversal::firstWithin(*this); child; child = ElementTraversal::nextSibling(*child)) {
for (HTMLElement* child = Traversal<HTMLElement>::firstWithin(*this); child; child = Traversal<HTMLElement>::nextSibling(*child)) {
if (child->hasTagName(theadTag))
return toHTMLTableSectionElement(child);
}
......@@ -88,8 +88,8 @@ void HTMLTableElement::setTHead(PassRefPtrWillBeRawPtr<HTMLTableSectionElement>
{
deleteTHead();
Element* child;
for (child = ElementTraversal::firstWithin(*this); child; child = ElementTraversal::nextSibling(*child)) {
HTMLElement* child;
for (child = Traversal<HTMLElement>::firstWithin(*this); child; child = Traversal<HTMLElement>::nextSibling(*child)) {
if (!child->hasTagName(captionTag) && !child->hasTagName(colgroupTag))
break;
}
......@@ -99,7 +99,7 @@ void HTMLTableElement::setTHead(PassRefPtrWillBeRawPtr<HTMLTableSectionElement>
HTMLTableSectionElement* HTMLTableElement::tFoot() const
{
for (Element* child = ElementTraversal::firstWithin(*this); child; child = ElementTraversal::nextSibling(*child)) {
for (HTMLElement* child = Traversal<HTMLElement>::firstWithin(*this); child; child = Traversal<HTMLElement>::nextSibling(*child)) {
if (child->hasTagName(tfootTag))
return toHTMLTableSectionElement(child);
}
......@@ -110,8 +110,8 @@ void HTMLTableElement::setTFoot(PassRefPtrWillBeRawPtr<HTMLTableSectionElement>
{
deleteTFoot();
Element* child;
for (child = ElementTraversal::firstWithin(*this); child; child = ElementTraversal::nextSibling(*child)) {
HTMLElement* child;
for (child = Traversal<HTMLElement>::firstWithin(*this); child; child = Traversal<HTMLElement>::nextSibling(*child)) {
if (!child->hasTagName(captionTag) && !child->hasTagName(colgroupTag) && !child->hasTagName(theadTag))
break;
}
......@@ -172,7 +172,7 @@ void HTMLTableElement::deleteCaption()
HTMLTableSectionElement* HTMLTableElement::lastBody() const
{
for (Node* child = lastChild(); child; child = child->previousSibling()) {
for (HTMLElement* child = Traversal<HTMLElement>::lastChild(*this); child; child = Traversal<HTMLElement>::previousSibling(*child)) {
if (child->hasTagName(tbodyTag))
return toHTMLTableSectionElement(child);
}
......
......@@ -80,7 +80,7 @@ int HTMLTableRowElement::rowIndex() const
}
}
for (Element* child = ElementTraversal::firstWithin(*table); child; child = ElementTraversal::nextSibling(*child)) {
for (HTMLElement* child = Traversal<HTMLElement>::firstWithin(*table); child; child = Traversal<HTMLElement>::nextSibling(*child)) {
if (child->hasTagName(tbodyTag)) {
HTMLTableSectionElement* section = toHTMLTableSectionElement(child);
for (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::firstChild(*section); row; row = Traversal<HTMLTableRowElement>::nextSibling(*row)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment