Index: Source/core/html/HTMLCollection.cpp |
diff --git a/Source/core/html/HTMLCollection.cpp b/Source/core/html/HTMLCollection.cpp |
index 12f8a1f315d3e24606a41efcf65dddd311fcf9c9..85be33adee94189b9952e65dfb4460c1a65eada2 100644 |
--- a/Source/core/html/HTMLCollection.cpp |
+++ b/Source/core/html/HTMLCollection.cpp |
@@ -1,7 +1,7 @@ |
/* |
* Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
* (C) 1999 Antti Koivisto (koivisto@kde.org) |
- * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserved. |
+ * Copyright (C) 2003-2008, 2011, 2012, 2014 Apple Inc. All rights reserved. |
* Copyright (C) 2014 Samsung Electronics. All rights reserved. |
* |
* This library is free software; you can redistribute it and/or |
@@ -191,70 +191,42 @@ void HTMLCollection::invalidateCache(Document* oldDocument) const |
invalidateIdNameCacheMaps(oldDocument); |
} |
-template <class NodeListType> |
-inline bool isMatchingElement(const NodeListType&, const Element&); |
- |
-template <> inline bool isMatchingElement(const HTMLCollection& htmlCollection, const Element& element) |
+static inline bool isMatchingHTMLElement(const HTMLCollection& htmlCollection, const HTMLElement& element) |
{ |
- CollectionType type = htmlCollection.type(); |
- |
- // These collections apply to any kind of Elements, not just HTMLElements. |
- switch (type) { |
- case DocAll: |
- case NodeChildren: |
- return true; |
- case ClassCollectionType: |
- return toClassCollection(htmlCollection).elementMatches(element); |
- case TagCollectionType: |
- return toTagCollection(htmlCollection).elementMatches(element); |
- case HTMLTagCollectionType: |
- return toHTMLTagCollection(htmlCollection).elementMatches(element); |
- case DocumentNamedItems: |
- return toDocumentNameCollection(htmlCollection).elementMatches(element); |
- case WindowNamedItems: |
- return toWindowNameCollection(htmlCollection).elementMatches(element); |
- default: |
- break; |
- } |
- |
- // The following only applies to HTMLElements. |
- if (!element.isHTMLElement()) |
- return false; |
- |
- switch (type) { |
+ switch (htmlCollection.type()) { |
case DocImages: |
- return element.hasLocalName(imgTag); |
+ return element.hasTagName(imgTag); |
case DocScripts: |
- return element.hasLocalName(scriptTag); |
+ return element.hasTagName(scriptTag); |
case DocForms: |
- return element.hasLocalName(formTag); |
+ return element.hasTagName(formTag); |
case TableTBodies: |
- return element.hasLocalName(tbodyTag); |
+ return element.hasTagName(tbodyTag); |
case TRCells: |
- return element.hasLocalName(tdTag) || element.hasLocalName(thTag); |
+ return element.hasTagName(tdTag) || element.hasTagName(thTag); |
case TSectionRows: |
- return element.hasLocalName(trTag); |
+ return element.hasTagName(trTag); |
case SelectOptions: |
- return element.hasLocalName(optionTag); |
+ return element.hasTagName(optionTag); |
case SelectedOptions: |
- return element.hasLocalName(optionTag) && toHTMLOptionElement(element).selected(); |
+ return isHTMLOptionElement(element) && toHTMLOptionElement(element).selected(); |
case DataListOptions: |
- if (element.hasLocalName(optionTag)) { |
+ if (isHTMLOptionElement(element)) { |
const HTMLOptionElement& option = toHTMLOptionElement(element); |
if (!option.isDisabledFormControl() && !option.value().isEmpty()) |
return true; |
} |
return false; |
case MapAreas: |
- return element.hasLocalName(areaTag); |
+ return element.hasTagName(areaTag); |
case DocApplets: |
- return element.hasLocalName(appletTag) || (element.hasLocalName(objectTag) && toHTMLObjectElement(element).containsJavaApplet()); |
+ return element.hasTagName(appletTag) || (isHTMLObjectElement(element) && toHTMLObjectElement(element).containsJavaApplet()); |
case DocEmbeds: |
- return element.hasLocalName(embedTag); |
+ return element.hasTagName(embedTag); |
case DocLinks: |
- return (element.hasLocalName(aTag) || element.hasLocalName(areaTag)) && element.fastHasAttribute(hrefAttr); |
+ return (element.hasTagName(aTag) || element.hasTagName(areaTag)) && element.fastHasAttribute(hrefAttr); |
case DocAnchors: |
- return element.hasLocalName(aTag) && element.fastHasAttribute(nameAttr); |
+ return element.hasTagName(aTag) && element.fastHasAttribute(nameAttr); |
case ClassCollectionType: |
case TagCollectionType: |
case HTMLTagCollectionType: |
@@ -273,6 +245,34 @@ template <> inline bool isMatchingElement(const HTMLCollection& htmlCollection, |
return false; |
} |
+template <class NodeListType> |
+inline bool isMatchingElement(const NodeListType&, const Element&); |
+ |
+template <> inline bool isMatchingElement(const HTMLCollection& htmlCollection, const Element& element) |
+{ |
+ // These collections apply to any kind of Elements, not just HTMLElements. |
+ switch (htmlCollection.type()) { |
+ case DocAll: |
+ case NodeChildren: |
+ return true; |
+ case ClassCollectionType: |
+ return toClassCollection(htmlCollection).elementMatches(element); |
+ case TagCollectionType: |
+ return toTagCollection(htmlCollection).elementMatches(element); |
+ case HTMLTagCollectionType: |
+ return toHTMLTagCollection(htmlCollection).elementMatches(element); |
+ case DocumentNamedItems: |
+ return toDocumentNameCollection(htmlCollection).elementMatches(element); |
+ case WindowNamedItems: |
+ return toWindowNameCollection(htmlCollection).elementMatches(element); |
+ default: |
+ break; |
+ } |
+ |
+ // The following only applies to HTMLElements. |
+ return element.isHTMLElement() && isMatchingHTMLElement(htmlCollection, toHTMLElement(element)); |
+} |
+ |
template <> inline bool isMatchingElement(const ClassCollection& collection, const Element& element) |
{ |
return collection.elementMatches(element); |
@@ -294,18 +294,18 @@ static inline bool nameShouldBeVisibleInDocumentAll(const HTMLElement& element) |
// http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#dom-htmlallcollection-nameditem: |
// The document.all collection returns only certain types of elements by name, |
// although it returns any type of element by id. |
- return element.hasLocalName(aTag) |
- || element.hasLocalName(appletTag) |
- || element.hasLocalName(areaTag) |
- || element.hasLocalName(embedTag) |
- || element.hasLocalName(formTag) |
- || element.hasLocalName(frameTag) |
- || element.hasLocalName(framesetTag) |
- || element.hasLocalName(iframeTag) |
- || element.hasLocalName(imgTag) |
- || element.hasLocalName(inputTag) |
- || element.hasLocalName(objectTag) |
- || element.hasLocalName(selectTag); |
+ return element.hasTagName(aTag) |
+ || element.hasTagName(appletTag) |
+ || element.hasTagName(areaTag) |
+ || element.hasTagName(embedTag) |
+ || element.hasTagName(formTag) |
+ || element.hasTagName(frameTag) |
+ || element.hasTagName(framesetTag) |
+ || element.hasTagName(iframeTag) |
+ || element.hasTagName(imgTag) |
+ || element.hasTagName(inputTag) |
+ || element.hasTagName(objectTag) |
+ || element.hasTagName(selectTag); |
} |
inline Element* firstMatchingChildElement(const HTMLCollection& nodeList) |