1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "core/html/DocumentNameCollection.h"
8 #include "core/html/HTMLEmbedElement.h"
9 #include "core/html/HTMLFormElement.h"
10 #include "core/html/HTMLObjectElement.h"
14 DocumentNameCollection::DocumentNameCollection(ContainerNode& document, const AtomicString& name)
15 : HTMLNameCollection(document, DocumentNamedItems, name)
19 bool DocumentNameCollection::elementMatches(const HTMLElement& element) const
21 // Match images, forms, applets, embeds, objects and iframes by name,
22 // applets and object by id, and images by id but only if they have
23 // a name attribute (this very strange rule matches IE)
24 if (isHTMLFormElement(element) || isHTMLIFrameElement(element) || (isHTMLEmbedElement(element) && toHTMLEmbedElement(element).isExposed()))
25 return element.getNameAttribute() == m_name;
26 if (isHTMLAppletElement(element) || (isHTMLObjectElement(element) && toHTMLObjectElement(element).isExposed()))
27 return element.getNameAttribute() == m_name || element.getIdAttribute() == m_name;
28 if (isHTMLImageElement(element))
29 return element.getNameAttribute() == m_name || (element.getIdAttribute() == m_name && element.hasName());