|
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 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
|
7 * |
|
8 * This library is free software; you can redistribute it and/or |
|
9 * modify it under the terms of the GNU Library General Public |
|
10 * License as published by the Free Software Foundation; either |
|
11 * version 2 of the License, or (at your option) any later version. |
|
12 * |
|
13 * This library is distributed in the hope that it will be useful, |
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 * Library General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU Library General Public License |
|
19 * along with this library; see the file COPYING.LIB. If not, write to |
|
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
21 * Boston, MA 02110-1301, USA. |
|
22 */ |
|
23 |
|
24 #include "config.h" |
|
25 #include "NamedMappedAttrMap.h" |
|
26 |
|
27 #include "Document.h" |
|
28 #include "Element.h" |
|
29 |
|
30 namespace WebCore { |
|
31 |
|
32 NamedMappedAttrMap::NamedMappedAttrMap(Element *e) |
|
33 : NamedAttrMap(e) |
|
34 , m_mappedAttributeCount(0) |
|
35 { |
|
36 } |
|
37 |
|
38 void NamedMappedAttrMap::clearAttributes() |
|
39 { |
|
40 m_classList.clear(); |
|
41 m_mappedAttributeCount = 0; |
|
42 NamedAttrMap::clearAttributes(); |
|
43 } |
|
44 |
|
45 bool NamedMappedAttrMap::isMappedAttributeMap() const |
|
46 { |
|
47 return true; |
|
48 } |
|
49 |
|
50 int NamedMappedAttrMap::declCount() const |
|
51 { |
|
52 int result = 0; |
|
53 for (unsigned i = 0; i < length(); i++) { |
|
54 MappedAttribute* attr = attributeItem(i); |
|
55 if (attr->decl()) |
|
56 result++; |
|
57 } |
|
58 return result; |
|
59 } |
|
60 |
|
61 bool NamedMappedAttrMap::mapsEquivalent(const NamedMappedAttrMap* otherMap) const |
|
62 { |
|
63 // The # of decls must match. |
|
64 if (declCount() != otherMap->declCount()) |
|
65 return false; |
|
66 |
|
67 // The values for each decl must match. |
|
68 for (unsigned i = 0; i < length(); i++) { |
|
69 MappedAttribute* attr = attributeItem(i); |
|
70 if (attr->decl()) { |
|
71 Attribute* otherAttr = otherMap->getAttributeItem(attr->name()); |
|
72 if (!otherAttr || (attr->value() != otherAttr->value())) |
|
73 return false; |
|
74 } |
|
75 } |
|
76 return true; |
|
77 } |
|
78 |
|
79 inline static bool isClassWhitespace(UChar c) |
|
80 { |
|
81 return c == ' ' || c == '\r' || c == '\n' || c == '\t'; |
|
82 } |
|
83 |
|
84 void NamedMappedAttrMap::parseClassAttribute(const String& classStr) |
|
85 { |
|
86 m_classList.clear(); |
|
87 if (!element->hasClass()) |
|
88 return; |
|
89 |
|
90 String classAttr = element->document()->inCompatMode() ? |
|
91 (classStr.impl()->isLower() ? classStr : String(classStr.impl()->lower())) : |
|
92 classStr; |
|
93 |
|
94 AtomicStringList* curr = 0; |
|
95 |
|
96 const UChar* str = classAttr.characters(); |
|
97 int length = classAttr.length(); |
|
98 int sPos = 0; |
|
99 |
|
100 while (true) { |
|
101 while (sPos < length && isClassWhitespace(str[sPos])) |
|
102 ++sPos; |
|
103 if (sPos >= length) |
|
104 break; |
|
105 int ePos = sPos + 1; |
|
106 while (ePos < length && !isClassWhitespace(str[ePos])) |
|
107 ++ePos; |
|
108 if (curr) { |
|
109 curr->setNext(new AtomicStringList(AtomicString(str + sPos, ePos - sPos))); |
|
110 curr = curr->next(); |
|
111 } else { |
|
112 if (sPos == 0 && ePos == length) { |
|
113 m_classList.setString(AtomicString(classAttr)); |
|
114 break; |
|
115 } |
|
116 m_classList.setString(AtomicString(str + sPos, ePos - sPos)); |
|
117 curr = &m_classList; |
|
118 } |
|
119 sPos = ePos + 1; |
|
120 } |
|
121 } |
|
122 |
|
123 } |