1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 */
24
25 #include "config.h"
26 #include "NamedMappedAttrMap.h"
27
28 #include "Document.h"
29 #include "Element.h"
30 #include "MappedAttribute.h"
31
32 namespace WebCore {
33
clearAttributes()34 void NamedMappedAttrMap::clearAttributes()
35 {
36 m_classNames.clear();
37 m_mappedAttributeCount = 0;
38 NamedNodeMap::clearAttributes();
39 }
40
isMappedAttributeMap() const41 bool NamedMappedAttrMap::isMappedAttributeMap() const
42 {
43 return true;
44 }
45
declCount() const46 int NamedMappedAttrMap::declCount() const
47 {
48 int result = 0;
49 for (unsigned i = 0; i < length(); i++) {
50 Attribute* attr = attributeItem(i);
51 if (attr->isMappedAttribute() &&
52 static_cast<MappedAttribute*>(attr)->decl())
53 result++;
54 }
55 return result;
56 }
57
mapsEquivalent(const NamedMappedAttrMap * otherMap) const58 bool NamedMappedAttrMap::mapsEquivalent(const NamedMappedAttrMap* otherMap) const
59 {
60 // The # of decls must match.
61 if (declCount() != otherMap->declCount())
62 return false;
63
64 // The values for each decl must match.
65 for (unsigned i = 0; i < length(); i++) {
66 Attribute* attr = attributeItem(i);
67 if (attr->isMappedAttribute() &&
68 static_cast<MappedAttribute*>(attr)->decl()) {
69 Attribute* otherAttr = otherMap->getAttributeItem(attr->name());
70 if (!otherAttr || (attr->value() != otherAttr->value()))
71 return false;
72 }
73 }
74 return true;
75 }
76
setClass(const String & classStr)77 void NamedMappedAttrMap::setClass(const String& classStr)
78 {
79 if (!element()->hasClass()) {
80 m_classNames.clear();
81 return;
82 }
83
84 m_classNames.set(classStr, element()->document()->inCompatMode());
85 }
86
87 }
88