~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/html/HTMLNameCollection.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 *
 
21
 */
 
22
 
 
23
#include "config.h"
 
24
#include "HTMLNameCollection.h"
 
25
 
 
26
#include "Element.h"
 
27
#include "HTMLDocument.h"
 
28
#include "HTMLNames.h"
 
29
#include "HTMLObjectElement.h"
 
30
#include "NodeRareData.h"
 
31
 
 
32
namespace WebCore {
 
33
 
 
34
using namespace HTMLNames;
 
35
 
 
36
HTMLNameCollection::HTMLNameCollection(Node* document, CollectionType type, const AtomicString& name)
 
37
    : HTMLCollection(document, type, OverridesItemAfter)
 
38
    , m_name(name)
 
39
{
 
40
}
 
41
 
 
42
HTMLNameCollection::~HTMLNameCollection()
 
43
{
 
44
    ASSERT(base());
 
45
    ASSERT(base()->isDocumentNode());
 
46
    ASSERT(type() == WindowNamedItems || type() == DocumentNamedItems);
 
47
 
 
48
    ownerNode()->nodeLists()->removeCacheWithAtomicName(this, type(), m_name);
 
49
}
 
50
 
 
51
Element* HTMLNameCollection::virtualItemAfter(unsigned& offsetInArray, Element* previous) const
 
52
{
 
53
    ASSERT_UNUSED(offsetInArray, !offsetInArray);
 
54
    ASSERT(previous != base());
 
55
 
 
56
    Node* current;
 
57
    if (!previous)
 
58
        current = base()->firstChild();
 
59
    else
 
60
        current = previous->traverseNextNode(base());
 
61
 
 
62
    for (; current; current = current->traverseNextNode(base())) {
 
63
        if (!current->isElementNode())
 
64
            continue;
 
65
        Element* e = static_cast<Element*>(current);
 
66
        switch (type()) {
 
67
            case WindowNamedItems:
 
68
                // find only images, forms, applets, embeds and objects by name, 
 
69
                // but anything by id
 
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)
 
76
                        return e;
 
77
                if (e->getIdAttribute() == m_name)
 
78
                    return e;
 
79
                break;
 
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)
 
86
                        return e;
 
87
                } else if (e->hasTagName(appletTag)) {
 
88
                    if (e->getNameAttribute() == m_name || e->getIdAttribute() == m_name)
 
89
                        return e;
 
90
                } else if (e->hasTagName(objectTag)) {
 
91
                    if ((e->getNameAttribute() == m_name || e->getIdAttribute() == m_name)
 
92
                            && static_cast<HTMLObjectElement*>(e)->isDocNamedItem())
 
93
                        return e;
 
94
                } else if (e->hasTagName(imgTag)) {
 
95
                    if (e->getNameAttribute() == m_name || (e->getIdAttribute() == m_name && e->hasName()))
 
96
                        return e;
 
97
                }
 
98
                break;
 
99
        default:
 
100
            ASSERT_NOT_REACHED();
 
101
        }
 
102
    }
 
103
 
 
104
    return 0;
 
105
}
 
106
 
 
107
}