2
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3
* (C) 1999 Antti Koivisto (koivisto@kde.org)
4
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2011, 2012 Apple Inc. All rights reserved.
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Library General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Library General Public License for more details.
16
* You should have received a copy of the GNU Library General Public License
17
* along with this library; see the file COPYING.LIB. If not, write to
18
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301, USA.
24
#include "HTMLNameCollection.h"
27
#include "HTMLDocument.h"
28
#include "HTMLNames.h"
29
#include "HTMLObjectElement.h"
30
#include "NodeRareData.h"
34
using namespace HTMLNames;
36
HTMLNameCollection::HTMLNameCollection(Node* document, CollectionType type, const AtomicString& name)
37
: HTMLCollection(document, type, OverridesItemAfter)
42
HTMLNameCollection::~HTMLNameCollection()
45
ASSERT(base()->isDocumentNode());
46
ASSERT(type() == WindowNamedItems || type() == DocumentNamedItems);
48
ownerNode()->nodeLists()->removeCacheWithAtomicName(this, type(), m_name);
51
Element* HTMLNameCollection::virtualItemAfter(unsigned& offsetInArray, Element* previous) const
53
ASSERT_UNUSED(offsetInArray, !offsetInArray);
54
ASSERT(previous != base());
58
current = base()->firstChild();
60
current = previous->traverseNextNode(base());
62
for (; current; current = current->traverseNextNode(base())) {
63
if (!current->isElementNode())
65
Element* e = static_cast<Element*>(current);
67
case WindowNamedItems:
68
// find only images, forms, applets, embeds and objects by name,
70
if (e->hasTagName(imgTag) ||
71
e->hasTagName(formTag) ||
72
e->hasTagName(appletTag) ||
73
e->hasTagName(embedTag) ||
74
e->hasTagName(objectTag))
75
if (e->getNameAttribute() == m_name)
77
if (e->getIdAttribute() == m_name)
80
case DocumentNamedItems:
81
// find images, forms, applets, embeds, objects and iframes by name,
82
// applets and object by id, and images by id but only if they have
83
// a name attribute (this very strange rule matches IE)
84
if (e->hasTagName(formTag) || e->hasTagName(embedTag) || e->hasTagName(iframeTag)) {
85
if (e->getNameAttribute() == m_name)
87
} else if (e->hasTagName(appletTag)) {
88
if (e->getNameAttribute() == m_name || e->getIdAttribute() == m_name)
90
} else if (e->hasTagName(objectTag)) {
91
if ((e->getNameAttribute() == m_name || e->getIdAttribute() == m_name)
92
&& static_cast<HTMLObjectElement*>(e)->isDocNamedItem())
94
} else if (e->hasTagName(imgTag)) {
95
if (e->getNameAttribute() == m_name || (e->getIdAttribute() == m_name && e->hasName()))
100
ASSERT_NOT_REACHED();