WebCore:
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Dec 2007 21:48:20 +0000 (21:48 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Dec 2007 21:48:20 +0000 (21:48 +0000)
        Reviewed by Mitz.

        - fix http://bugs.webkit.org/show_bug.cgi?id=14955
          Implement getElementsByClassName.

        This patch also renames AtomicStringList to ClassNames to better reflect its actual use,
        and takes advantage of admitting that it's class-specific to encapsulate class attribute
        parsing so it can be shared.  It also changes the class to use a Vector, rather than a linked
        list to store the class names.

        Tests: fast/dom/getElementsByClassName/001.html
               fast/dom/getElementsByClassName/002.html
               fast/dom/getElementsByClassName/003.html
               fast/dom/getElementsByClassName/004.html
               fast/dom/getElementsByClassName/005.html
               fast/dom/getElementsByClassName/006.html
               fast/dom/getElementsByClassName/007.html
               fast/dom/getElementsByClassName/008.html
               fast/dom/getElementsByClassName/009.html
               fast/dom/getElementsByClassName/010.xml
               fast/dom/getElementsByClassName/011.xml
               fast/dom/getElementsByClassName/012.html
               fast/dom/getElementsByClassName/013.html
               fast/dom/getElementsByClassName/014.html
               fast/dom/getElementsByClassName/array/001.html
               fast/dom/getElementsByClassName/array/002.html
               fast/dom/getElementsByClassName/array/003.html
               fast/dom/getElementsByClassName/array/004.html
               fast/dom/getElementsByClassName/dumpNodeList.html

        * WebCore.xcodeproj/project.pbxproj:
        * css/CSSStyleSelector.cpp:
        (WebCore::CSSStyleSelector::matchRules):
        (WebCore::CSSStyleSelector::checkOneSelector):
        * dom/AtomicStringList.h: Removed.
        * dom/ClassNames.cpp: Added.
        (WebCore::ClassNames::contains):
        (WebCore::ClassNames::parseClassAttribute):
        * dom/ClassNames.h: Copied from WebCore/dom/AtomicStringList.h.
        (WebCore::ClassNames::ClassNames):
        (WebCore::ClassNames::size):
        (WebCore::ClassNames::clear):
        (WebCore::ClassNames::operator[]):
        (WebCore::isClassWhitespace):
        * dom/ClassNodeList.cpp: Added.
        (WebCore::ClassNodeList::ClassNodeList):
        (WebCore::ClassNodeList::length):
        (WebCore::ClassNodeList::item):
        (WebCore::ClassNodeList::nodeMatches):
        * dom/ClassNodeList.h: Added.
        * dom/Document.cpp:
        (WebCore::Document::getElementsByName):
        (WebCore::Document::getElementsByClassName):
        * dom/Document.h:
        * dom/Document.idl:
        * dom/Element.cpp:
        (WebCore::Element::getClassNames):
        (WebCore::Element::getElementsByClassName):
        * dom/Element.h:
        * dom/Element.idl:
        * dom/NameNodeList.cpp:
        (WebCore::NameNodeList::NameNodeList):
        (WebCore::NameNodeList::item):
        (WebCore::NameNodeList::nodeMatches):
        * dom/NameNodeList.h:
        * dom/NamedMappedAttrMap.cpp:
        (WebCore::NamedMappedAttrMap::clearAttributes):
        (WebCore::NamedMappedAttrMap::parseClassAttribute):
        * dom/NamedMappedAttrMap.h:
        (WebCore::NamedMappedAttrMap::getClassNames):
        * dom/StyledElement.cpp:
        (WebCore::StyledElement::getClassNames):
        * dom/StyledElement.h:

LayoutTests:

        Reviewed by Mitz.

        - test for http://bugs.webkit.org/show_bug.cgi?id=14955
          Implement getElementsByClassName

        Tests added from http://tc.labs.opera.com/apis/getElementsByClassName/

        * fast/dom/Window/window-properties-expected.txt:
        * fast/dom/getElementsByClassName: Added.
        * fast/dom/getElementsByClassName/001-expected.txt: Added.
        * fast/dom/getElementsByClassName/001.html: Added.
        * fast/dom/getElementsByClassName/002-expected.txt: Added.
        * fast/dom/getElementsByClassName/002.html: Added.
        * fast/dom/getElementsByClassName/003-expected.txt: Added.
        * fast/dom/getElementsByClassName/003.html: Added.
        * fast/dom/getElementsByClassName/004-expected.txt: Added.
        * fast/dom/getElementsByClassName/004.html: Added.
        * fast/dom/getElementsByClassName/005-expected.txt: Added.
        * fast/dom/getElementsByClassName/005.html: Added.
        * fast/dom/getElementsByClassName/006-expected.txt: Added.
        * fast/dom/getElementsByClassName/006.html: Added.
        * fast/dom/getElementsByClassName/007-expected.txt: Added.
        * fast/dom/getElementsByClassName/007.html: Added.
        * fast/dom/getElementsByClassName/008-expected.txt: Added.
        * fast/dom/getElementsByClassName/008.html: Added.
        * fast/dom/getElementsByClassName/009-expected.txt: Added.
        * fast/dom/getElementsByClassName/009.html: Added.
        * fast/dom/getElementsByClassName/010-expected.txt: Added.
        * fast/dom/getElementsByClassName/010.xml: Added.
        * fast/dom/getElementsByClassName/011-expected.txt: Added.
        * fast/dom/getElementsByClassName/011.xml: Added.
        * fast/dom/getElementsByClassName/012-expected.txt: Added.
        * fast/dom/getElementsByClassName/012.html: Added.
        * fast/dom/getElementsByClassName/013-expected.txt: Added.
        * fast/dom/getElementsByClassName/013.html: Added.
        * fast/dom/getElementsByClassName/014-expected.txt: Added.
        * fast/dom/getElementsByClassName/014.html: Added.
        * fast/dom/getElementsByClassName/array: Added.
        * fast/dom/getElementsByClassName/array/001-expected.txt: Added.
        * fast/dom/getElementsByClassName/array/001.html: Added.
        * fast/dom/getElementsByClassName/array/002-expected.txt: Added.
        * fast/dom/getElementsByClassName/array/002.html: Added.
        * fast/dom/getElementsByClassName/array/003-expected.txt: Added.
        * fast/dom/getElementsByClassName/array/003.html: Added.
        * fast/dom/getElementsByClassName/array/004-expected.txt: Added.
        * fast/dom/getElementsByClassName/array/004.html: Added.
        * fast/dom/getElementsByClassName/dumpNodeList-expected.txt: Added.
        * fast/dom/getElementsByClassName/dumpNodeList.html: Added.
        * fast/dom/getElementsByClassName/resources: Added.
        * fast/dom/getElementsByClassName/resources/common.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28722 268f45cc-cd09-0410-ab3c-d52691b4dbfc

61 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/Window/window-properties-expected.txt
LayoutTests/fast/dom/getElementsByClassName/001-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/001.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/002-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/002.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/003-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/003.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/004-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/004.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/005-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/005.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/006-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/006.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/007-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/007.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/008-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/008.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/009-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/009.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/010-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/010.xml [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/011-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/011.xml [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/012-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/012.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/013-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/013.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/014-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/014.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/array/001-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/array/001.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/array/002-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/array/002.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/array/003-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/array/003.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/array/004-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/array/004.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/dumpNodeList-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/dumpNodeList.html [new file with mode: 0644]
LayoutTests/fast/dom/getElementsByClassName/resources/common.js [new file with mode: 0644]
WebCore/ChangeLog
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/css/CSSStyleSelector.cpp
WebCore/dom/AtomicStringList.h [deleted file]
WebCore/dom/ClassNames.cpp [new file with mode: 0644]
WebCore/dom/ClassNames.h [new file with mode: 0644]
WebCore/dom/ClassNodeList.cpp [new file with mode: 0644]
WebCore/dom/ClassNodeList.h [new file with mode: 0644]
WebCore/dom/Document.cpp
WebCore/dom/Document.h
WebCore/dom/Document.idl
WebCore/dom/Element.cpp
WebCore/dom/Element.h
WebCore/dom/Element.idl
WebCore/dom/NameNodeList.cpp
WebCore/dom/NameNodeList.h
WebCore/dom/NamedMappedAttrMap.cpp
WebCore/dom/NamedMappedAttrMap.h
WebCore/dom/StyledElement.cpp
WebCore/dom/StyledElement.h

index 996b8b19a578e225b80517a51eb9a05752669d2e..a371e9f9e3174805feedfc6f66c0bf19f9eebc87 100644 (file)
@@ -1,3 +1,56 @@
+2007-12-14  David Smith  <catfish.man@gmail.com>
+
+        Reviewed by Mitz.
+
+        - test for http://bugs.webkit.org/show_bug.cgi?id=14955
+          Implement getElementsByClassName
+
+        Tests added from http://tc.labs.opera.com/apis/getElementsByClassName/
+
+        * fast/dom/Window/window-properties-expected.txt:
+        * fast/dom/getElementsByClassName: Added.
+        * fast/dom/getElementsByClassName/001-expected.txt: Added.
+        * fast/dom/getElementsByClassName/001.html: Added.
+        * fast/dom/getElementsByClassName/002-expected.txt: Added.
+        * fast/dom/getElementsByClassName/002.html: Added.
+        * fast/dom/getElementsByClassName/003-expected.txt: Added.
+        * fast/dom/getElementsByClassName/003.html: Added.
+        * fast/dom/getElementsByClassName/004-expected.txt: Added.
+        * fast/dom/getElementsByClassName/004.html: Added.
+        * fast/dom/getElementsByClassName/005-expected.txt: Added.
+        * fast/dom/getElementsByClassName/005.html: Added.
+        * fast/dom/getElementsByClassName/006-expected.txt: Added.
+        * fast/dom/getElementsByClassName/006.html: Added.
+        * fast/dom/getElementsByClassName/007-expected.txt: Added.
+        * fast/dom/getElementsByClassName/007.html: Added.
+        * fast/dom/getElementsByClassName/008-expected.txt: Added.
+        * fast/dom/getElementsByClassName/008.html: Added.
+        * fast/dom/getElementsByClassName/009-expected.txt: Added.
+        * fast/dom/getElementsByClassName/009.html: Added.
+        * fast/dom/getElementsByClassName/010-expected.txt: Added.
+        * fast/dom/getElementsByClassName/010.xml: Added.
+        * fast/dom/getElementsByClassName/011-expected.txt: Added.
+        * fast/dom/getElementsByClassName/011.xml: Added.
+        * fast/dom/getElementsByClassName/012-expected.txt: Added.
+        * fast/dom/getElementsByClassName/012.html: Added.
+        * fast/dom/getElementsByClassName/013-expected.txt: Added.
+        * fast/dom/getElementsByClassName/013.html: Added.
+        * fast/dom/getElementsByClassName/014-expected.txt: Added.
+        * fast/dom/getElementsByClassName/014.html: Added.
+        * fast/dom/getElementsByClassName/array: Added.
+        * fast/dom/getElementsByClassName/array/001-expected.txt: Added.
+        * fast/dom/getElementsByClassName/array/001.html: Added.
+        * fast/dom/getElementsByClassName/array/002-expected.txt: Added.
+        * fast/dom/getElementsByClassName/array/002.html: Added.
+        * fast/dom/getElementsByClassName/array/003-expected.txt: Added.
+        * fast/dom/getElementsByClassName/array/003.html: Added.
+        * fast/dom/getElementsByClassName/array/004-expected.txt: Added.
+        * fast/dom/getElementsByClassName/array/004.html: Added.
+        * fast/dom/getElementsByClassName/dumpNodeList-expected.txt: Added.
+        * fast/dom/getElementsByClassName/dumpNodeList.html: Added.
+        * fast/dom/getElementsByClassName/resources: Added.
+        * fast/dom/getElementsByClassName/resources/common.js: Added.
+
 2007-12-14  Darin Adler  <darin@apple.com>
 
         Reviewed by Alexey.
index fcaff2d0e0ada749ee8be8e87338f1578dd36b65..0099c33286ff2b25d8cc22fd494017886d03a5b0 100644 (file)
@@ -317,6 +317,7 @@ window.Document.prototype.elementFromPoint [function]
 window.Document.prototype.evaluate [function]
 window.Document.prototype.execCommand [function]
 window.Document.prototype.getElementById [function]
+window.Document.prototype.getElementsByClassName [function]
 window.Document.prototype.getElementsByName [function]
 window.Document.prototype.getElementsByTagName [function]
 window.Document.prototype.getElementsByTagNameNS [function]
@@ -424,6 +425,7 @@ window.Element.prototype.getAttribute [function]
 window.Element.prototype.getAttributeNS [function]
 window.Element.prototype.getAttributeNode [function]
 window.Element.prototype.getAttributeNodeNS [function]
+window.Element.prototype.getElementsByClassName [function]
 window.Element.prototype.getElementsByTagName [function]
 window.Element.prototype.getElementsByTagNameNS [function]
 window.Element.prototype.hasAttribute [function]
diff --git a/LayoutTests/fast/dom/getElementsByClassName/001-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/001-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/dom/getElementsByClassName/001.html b/LayoutTests/fast/dom/getElementsByClassName/001.html
new file mode 100644 (file)
index 0000000..930aae5
--- /dev/null
@@ -0,0 +1,11 @@
+<!doctype html>
+<html class="a">
+ <head>
+  <title>document.getElementsByClassName(): simple</title>
+  <script src="resources/common.js"></script>
+ </head>
+ <body class="a">
+  <p id="r">FAIL (script did not run)</p>
+  <script> t(document.getElementsByClassName("\ta\n"), [document.documentElement, document.body]) </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/002-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/002-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/dom/getElementsByClassName/002.html b/LayoutTests/fast/dom/getElementsByClassName/002.html
new file mode 100644 (file)
index 0000000..d91b0ac
--- /dev/null
@@ -0,0 +1,13 @@
+<!doctype html>
+<html class="a
+b">
+ <head>
+  <title>document.getElementsByClassName(): also simple</title>
+  <script src="resources/common.js"></script>
+ </head>
+ <body class="a
+">
+  <p id="r">FAIL (script did not run)</p>
+  <script> t(document.getElementsByClassName("a\n"), [document.documentElement, document.body]) </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/003-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/003-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/dom/getElementsByClassName/003.html b/LayoutTests/fast/dom/getElementsByClassName/003.html
new file mode 100644 (file)
index 0000000..661dbba
--- /dev/null
@@ -0,0 +1,15 @@
+<!doctype html>
+<html class="a">
+ <head>
+  <title>document.getElementsByClassName(): changing classes</title>
+  <script src="resources/common.js"></script>
+ </head>
+ <body class="a">
+  <p id="r">FAIL (script did not run)</p>
+  <script>
+   var collection = document.getElementsByClassName("a")
+   document.body.className = "b"
+   t(collection, [document.documentElement])
+  </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/004-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/004-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/dom/getElementsByClassName/004.html b/LayoutTests/fast/dom/getElementsByClassName/004.html
new file mode 100644 (file)
index 0000000..a932dd1
--- /dev/null
@@ -0,0 +1,15 @@
+<!doctype html>
+<html class="a">
+ <head>
+  <title>document.getElementsByClassName(): changing classes</title>
+  <script src="resources/common.js"></script>
+ </head>
+ <body class="a">
+  <p id="r">FAIL (script did not run)</p>
+  <script>
+   var collection = document.getElementsByClassName("a")
+   document.body.className += "\tb"
+   t(collection, [document.documentElement, document.body])
+  </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/005-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/005-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/dom/getElementsByClassName/005.html b/LayoutTests/fast/dom/getElementsByClassName/005.html
new file mode 100644 (file)
index 0000000..5a609db
--- /dev/null
@@ -0,0 +1,15 @@
+<!doctype html>
+<html class="a">
+ <head>
+  <title>document.getElementsByClassName(): changing classes</title>
+  <script src="resources/common.js"></script>
+ </head>
+ <body class="a">
+  <p id="r">FAIL (script did not run)</p>
+  <script>
+   var collection = document.getElementsByClassName("a")
+   document.body.removeAttribute("class")
+   t(collection, [document.documentElement])
+  </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/006-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/006-expected.txt
new file mode 100644 (file)
index 0000000..9976b12
--- /dev/null
@@ -0,0 +1,3 @@
+PASS
+
+
diff --git a/LayoutTests/fast/dom/getElementsByClassName/006.html b/LayoutTests/fast/dom/getElementsByClassName/006.html
new file mode 100644 (file)
index 0000000..89be60b
--- /dev/null
@@ -0,0 +1,17 @@
+<!doctype html>
+<html>
+ <head>
+  <title>document.getElementsByClassName(): adding element with class</title>
+  <script src="resources/common.js"></script>
+ </head>
+ <body class="a">
+  <p id="r">FAIL (script did not run)</p>
+  <script>
+   var collection = document.getElementsByClassName("a"),
+       ele = document.createElement("foo");
+   ele.setAttribute("class", "a");
+   document.body.appendChild(ele)
+   t(collection, [document.body, ele])
+  </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/007-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/007-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/dom/getElementsByClassName/007.html b/LayoutTests/fast/dom/getElementsByClassName/007.html
new file mode 100644 (file)
index 0000000..bb013df
--- /dev/null
@@ -0,0 +1,11 @@
+<!doctype html>
+<html>
+ <head>
+  <title>document.getElementsByClassName(): multiple classes</title>
+  <script src="resources/common.js"></script>
+ </head>
+ <body class="a b">
+  <p id="r">FAIL (script did not run)</p>
+  <script> t(document.getElementsByClassName("b\t\f\n\na\rb"), [document.body]) </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/008-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/008-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/dom/getElementsByClassName/008.html b/LayoutTests/fast/dom/getElementsByClassName/008.html
new file mode 100644 (file)
index 0000000..b60129d
--- /dev/null
@@ -0,0 +1,11 @@
+<!doctype html>
+<html>
+ <head>
+  <title>document.getElementsByClassName(): multiple classes</title>
+  <script src="resources/common.js"></script>
+ </head>
+ <body class="a">
+  <p id="r">FAIL (script did not run)</p>
+  <script> t(document.getElementsByClassName("a\fa"), [document.body]) </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/009-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/009-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/dom/getElementsByClassName/009.html b/LayoutTests/fast/dom/getElementsByClassName/009.html
new file mode 100644 (file)
index 0000000..ce52987
--- /dev/null
@@ -0,0 +1,11 @@
+<!doctype html>
+<html class="a A">
+ <head>
+  <title>document.getElementsByClassName(): case sensitive</title>
+  <script src="resources/common.js"></script>
+ </head>
+ <body class="a a">
+  <p id="r">FAIL (script did not run)</p>
+  <script> t(document.getElementsByClassName("A a"), [document.documentElement]) </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/010-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/010-expected.txt
new file mode 100644 (file)
index 0000000..9976b12
--- /dev/null
@@ -0,0 +1,3 @@
+PASS
+
+
diff --git a/LayoutTests/fast/dom/getElementsByClassName/010.xml b/LayoutTests/fast/dom/getElementsByClassName/010.xml
new file mode 100644 (file)
index 0000000..44f8474
--- /dev/null
@@ -0,0 +1,12 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:g="http://www.w3.org/2000/svg">
+ <head>
+  <title>document.getElementsByClassName(): compound</title>
+  <script src="resources/common.js"></script>
+ </head>
+ <body>
+  <p id="r">FAIL (script did not run)</p>  
+  <x class="a"/>
+  <g:x class="a"/>
+  <script> t(document.getElementsByClassName("a"), document.getElementsByTagName("x")) </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/011-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/011-expected.txt
new file mode 100644 (file)
index 0000000..1e7d377
--- /dev/null
@@ -0,0 +1,8 @@
+This page contains the following errors:
+
+error on line 12 at column 200: Namespaced Attribute class in 'http://www.w3.org/1999/xhtml' redefined
+Below is a rendering of the page up to the first error.
+
+PASS
+
+
diff --git a/LayoutTests/fast/dom/getElementsByClassName/011.xml b/LayoutTests/fast/dom/getElementsByClassName/011.xml
new file mode 100644 (file)
index 0000000..6790b5a
--- /dev/null
@@ -0,0 +1,19 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:g="http://www.w3.org/2000/svg" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:t="http://tc.labs.opera.com/#test">
+ <head>
+  <title>document.getElementsByClassName(): "tricky" compound</title>
+  <script src="resources/common.js"></script>
+ </head>
+ <body>
+  <p id="r">FAIL (script did not run)</p>  
+  <x class="a"/>
+  <g:x class="a"/>
+  <x t:class="a" h:class="a" g:class="a"/>
+  <g:x t:class="a" h:class="a" g:class="a"/>
+  <t:x class="a" t:class="a" h:class="a" g:class="a"/>
+  <script>
+   var collection = document.getElementsByClassName("a"),
+       test = document.getElementsByTagName("x")
+   t(collection, [test[0], test[1]])
+  </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/012-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/012-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/dom/getElementsByClassName/012.html b/LayoutTests/fast/dom/getElementsByClassName/012.html
new file mode 100644 (file)
index 0000000..ed93344
--- /dev/null
@@ -0,0 +1,11 @@
+<!doctype html>
+<html class="a">
+ <head>
+  <title>element.getElementsByClassName(): simple</title>
+  <script src="resources/common.js"></script>
+ </head>
+ <body class="a">
+  <p id="r">FAIL (script did not run)</p>
+  <script> t(document.body.getElementsByClassName("a"), []) </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/013-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/013-expected.txt
new file mode 100644 (file)
index 0000000..9976b12
--- /dev/null
@@ -0,0 +1,3 @@
+PASS
+
+
diff --git a/LayoutTests/fast/dom/getElementsByClassName/013.html b/LayoutTests/fast/dom/getElementsByClassName/013.html
new file mode 100644 (file)
index 0000000..7c8c232
--- /dev/null
@@ -0,0 +1,17 @@
+<!doctype html>
+<html class="a">
+ <head>
+  <title>element.getElementsByClassName(): adding an element</title>
+  <script src="resources/common.js"></script>
+ </head>
+ <body class="a">
+  <p id="r">FAIL (script did not run)</p>
+  <script>
+   var collection = document.body.getElementsByClassName("a"),
+       ele = document.createElement("x-y-z")
+   ele.className = "a"
+   document.body.appendChild(ele) 
+   t(collection, [ele])
+  </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/014-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/014-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/dom/getElementsByClassName/014.html b/LayoutTests/fast/dom/getElementsByClassName/014.html
new file mode 100644 (file)
index 0000000..29dff66
--- /dev/null
@@ -0,0 +1,14 @@
+<html class="a A">
+ <head>
+  <title>document.getElementsByClassName(): case sensitive (quirks mode)</title>
+  <script src="resources/common.js"></script>
+ </head>
+ <body class="a a">
+  <p id="r">FAIL (script did not run)</p>
+  <script>
+    // We differ from Opera's implementation here.  We are case-insensitive in quirks mode.
+    // t(document.getElementsByClassName("A a"), [document.documentElement])
+    t(document.getElementsByClassName("A a"), [document.documentElement, document.body])
+  </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/array/001-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/array/001-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/dom/getElementsByClassName/array/001.html b/LayoutTests/fast/dom/getElementsByClassName/array/001.html
new file mode 100644 (file)
index 0000000..d002002
--- /dev/null
@@ -0,0 +1,13 @@
+<!doctype html>
+<html class="a
+b">
+ <head>
+  <title>document.getElementsByClassName(array): "a\n"</title>
+  <script src="../resources/common.js"></script>
+ </head>
+ <body class="a
+">
+  <p id="r">FAIL (script did not run)</p>
+  <script> t(document.getElementsByClassName(["a\n"]), [document.documentElement, document.body]) </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/array/002-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/array/002-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/dom/getElementsByClassName/array/002.html b/LayoutTests/fast/dom/getElementsByClassName/array/002.html
new file mode 100644 (file)
index 0000000..2148e5e
--- /dev/null
@@ -0,0 +1,12 @@
+<!doctype html>
+<html class="a
+b">
+ <head>
+  <title>document.getElementsByClassName(array): "b","a"</title>
+  <script src="../resources/common.js"></script>
+ </head>
+ <body class="b,a">
+  <p id="r">FAIL (script did not run)</p>
+  <script> t(document.getElementsByClassName(["b", "a"]), [document.body]) </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/array/003-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/array/003-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/dom/getElementsByClassName/array/003.html b/LayoutTests/fast/dom/getElementsByClassName/array/003.html
new file mode 100644 (file)
index 0000000..e110dc9
--- /dev/null
@@ -0,0 +1,11 @@
+<!doctype html>
+<html>
+ <head>
+  <title>document.getElementsByClassName(array): "b a"</title>
+  <script src="../resources/common.js"></script>
+ </head>
+ <body class="a b">
+  <p id="r">FAIL (script did not run)</p>
+  <script> t(document.getElementsByClassName(["b a"]), [document.body]) </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/array/004-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/array/004-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/dom/getElementsByClassName/array/004.html b/LayoutTests/fast/dom/getElementsByClassName/array/004.html
new file mode 100644 (file)
index 0000000..3740509
--- /dev/null
@@ -0,0 +1,11 @@
+<!doctype html>
+<html class="a,b">
+ <head>
+  <title>element.getElementsByClassName(array): "a", "b"</title>
+  <script src="../resources/common.js"></script>
+ </head>
+ <body class="a,b x">
+  <p id="r" class="a,bx">FAIL (script did not run)</p>
+  <script class="xa,b"> t(document.documentElement.getElementsByClassName(["\fa","b\n"]), [document.body]) </script>
+ </body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/dumpNodeList-expected.txt b/LayoutTests/fast/dom/getElementsByClassName/dumpNodeList-expected.txt
new file mode 100644 (file)
index 0000000..373ffbc
--- /dev/null
@@ -0,0 +1,26 @@
+Line 1
+Line 2
+Line 3
+
+line 4
+line 5
+
+[object HTMLDivElement], [object HTMLDivElement], [object HTMLDivElement], length: 3
+[object HTMLDivElement], [object HTMLDivElement], [object HTMLDivElement], [object HTMLParagraphElement], length: 4
+[object HTMLDivElement], [object HTMLDivElement], length: 2
+[object HTMLDivElement], [object HTMLDivElement], length: 2
+length: 0
+length: 0
+length: 0
+length: 0
+length: 0
+[object HTMLDivElement], length: 1
+[object HTMLDivElement], [object HTMLParagraphElement], length: 2
+[object HTMLDivElement], length: 1
+[object HTMLDivElement], length: 1
+length: 0
+length: 0
+length: 0
+length: 0
+length: 0
+
diff --git a/LayoutTests/fast/dom/getElementsByClassName/dumpNodeList.html b/LayoutTests/fast/dom/getElementsByClassName/dumpNodeList.html
new file mode 100644 (file)
index 0000000..86bd42e
--- /dev/null
@@ -0,0 +1,54 @@
+<html>
+<body>
+<div class="one">Line 1<div class="two">Line 2</div><p>Line <i>3</i></p></div>
+<div id="test" class="one two"><div class="one two">line 4</div><p class="two">line 5</p></div>
+<p><ol id="console"></ol></p>
+<script type="text/javascript">
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+
+    function log(message)
+    {
+        var item = document.createElement("li");
+        item.appendChild(document.createTextNode(message));
+        document.getElementById("console").appendChild(item);
+    }
+    
+    NodeList.prototype.dump = function()
+    {
+        var result = "";
+        var i = 0;
+        for (; i < this.length; i++)
+            result += this[i] + ", ";
+        result += "length: " + i;
+        return result;
+    }
+
+    try {
+        var elm = document.getElementById("test");
+
+        log(document.getElementsByClassName("one").dump());
+        log(document.getElementsByClassName("two").dump());
+        log(document.getElementsByClassName("one two").dump());
+        log(document.getElementsByClassName("one\t\t\n \ftwo").dump());
+        log(document.getElementsByClassName("").dump());
+        log(document.getElementsByClassName("onetwo").dump());
+        log(document.getElementsByClassName().dump());
+        log(document.getElementsByClassName(null).dump());
+        log(document.getElementsByClassName(undefined).dump());
+
+        log(elm.getElementsByClassName("one").dump());
+        log(elm.getElementsByClassName("two").dump());
+        log(elm.getElementsByClassName("one two").dump());
+        log(elm.getElementsByClassName("one\t\t\n \ftwo").dump());
+        log(elm.getElementsByClassName("").dump());
+        log(elm.getElementsByClassName("onetwo").dump());
+        log(elm.getElementsByClassName().dump());
+        log(elm.getElementsByClassName(null).dump());
+        log(elm.getElementsByClassName(undefined).dump());
+    } catch (ex) {
+        log("Exception: " + ex.description);
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/getElementsByClassName/resources/common.js b/LayoutTests/fast/dom/getElementsByClassName/resources/common.js
new file mode 100644 (file)
index 0000000..0ea011d
--- /dev/null
@@ -0,0 +1,21 @@
+// runs a test and writes a log
+function t(collection, elements) {
+  if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+  var log = "",
+      r = document.getElementById("r"),
+      pass = true
+  if(collection.length != elements.length) {
+    pass = false
+    log += "Got " + collection.length + " elements, expected " + elements.length + ". "
+  }
+  for(var i = 0, max = collection.length > elements.length ? elements.length : collection.length; i < max; i++) {
+    if(collection[i] != elements[i]) {
+      pass = false
+      log += "Got element `" + collection[i].tagName + "` (" + collection[i].namespaceURI + ")"
+      log += ", expected element `" + elements[i].tagName + "` (" + elements[i].namespaceURI + "). "
+    }
+  }
+  r.textContent = pass ? "PASS" : "FAIL (" + log + ")"
+}
index 6500f098c1441b74977a685e53be34f6c2dbe836..22ff91424935b2185fefb7a244a8c582d13637e7 100644 (file)
@@ -1,3 +1,79 @@
+2007-12-14  David Smith  <catfish.man@gmail.com>
+
+        Reviewed by Mitz.
+
+        - fix http://bugs.webkit.org/show_bug.cgi?id=14955
+          Implement getElementsByClassName.
+
+        This patch also renames AtomicStringList to ClassNames to better reflect its actual use,
+        and takes advantage of admitting that it's class-specific to encapsulate class attribute 
+        parsing so it can be shared.  It also changes the class to use a Vector, rather than a linked
+        list to store the class names.
+
+        Tests: fast/dom/getElementsByClassName/001.html
+               fast/dom/getElementsByClassName/002.html
+               fast/dom/getElementsByClassName/003.html
+               fast/dom/getElementsByClassName/004.html
+               fast/dom/getElementsByClassName/005.html
+               fast/dom/getElementsByClassName/006.html
+               fast/dom/getElementsByClassName/007.html
+               fast/dom/getElementsByClassName/008.html
+               fast/dom/getElementsByClassName/009.html
+               fast/dom/getElementsByClassName/010.xml
+               fast/dom/getElementsByClassName/011.xml
+               fast/dom/getElementsByClassName/012.html
+               fast/dom/getElementsByClassName/013.html
+               fast/dom/getElementsByClassName/014.html
+               fast/dom/getElementsByClassName/array/001.html
+               fast/dom/getElementsByClassName/array/002.html
+               fast/dom/getElementsByClassName/array/003.html
+               fast/dom/getElementsByClassName/array/004.html
+               fast/dom/getElementsByClassName/dumpNodeList.html
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::matchRules):
+        (WebCore::CSSStyleSelector::checkOneSelector):
+        * dom/AtomicStringList.h: Removed.
+        * dom/ClassNames.cpp: Added.
+        (WebCore::ClassNames::contains):
+        (WebCore::ClassNames::parseClassAttribute):
+        * dom/ClassNames.h: Copied from WebCore/dom/AtomicStringList.h.
+        (WebCore::ClassNames::ClassNames):
+        (WebCore::ClassNames::size):
+        (WebCore::ClassNames::clear):
+        (WebCore::ClassNames::operator[]):
+        (WebCore::isClassWhitespace):
+        * dom/ClassNodeList.cpp: Added.
+        (WebCore::ClassNodeList::ClassNodeList):
+        (WebCore::ClassNodeList::length):
+        (WebCore::ClassNodeList::item):
+        (WebCore::ClassNodeList::nodeMatches):
+        * dom/ClassNodeList.h: Added.
+        * dom/Document.cpp:
+        (WebCore::Document::getElementsByName):
+        (WebCore::Document::getElementsByClassName):
+        * dom/Document.h:
+        * dom/Document.idl:
+        * dom/Element.cpp:
+        (WebCore::Element::getClassNames):
+        (WebCore::Element::getElementsByClassName):
+        * dom/Element.h:
+        * dom/Element.idl:
+        * dom/NameNodeList.cpp:
+        (WebCore::NameNodeList::NameNodeList):
+        (WebCore::NameNodeList::item):
+        (WebCore::NameNodeList::nodeMatches):
+        * dom/NameNodeList.h:
+        * dom/NamedMappedAttrMap.cpp:
+        (WebCore::NamedMappedAttrMap::clearAttributes):
+        (WebCore::NamedMappedAttrMap::parseClassAttribute):
+        * dom/NamedMappedAttrMap.h:
+        (WebCore::NamedMappedAttrMap::getClassNames):
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::getClassNames):
+        * dom/StyledElement.h:
+
 2007-12-14  Darin Adler  <darin@apple.com>
 
         Reviewed by Sam.
index 9cdf59ca29e8375894de7ae77fcf5adf6e330cf0..986a7133cf32f5509578f44452929f397c84c7d2 100644 (file)
                93F199BD08245E59001E9ABC /* AXObjectCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 55998A5C052B59CC0017A6C1 /* AXObjectCache.h */; };
                93F199BE08245E59001E9ABC /* BlockExceptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 65A640F00533BB1F0085E777 /* BlockExceptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
                93F199C208245E59001E9ABC /* WebCoreKeyGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B2B1F7056BEF3A00D2B771 /* WebCoreKeyGenerator.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               93F199CF08245E59001E9ABC /* AtomicStringList.h in Headers */ = {isa = PBXBuildFile; fileRef = BC3B364705C9D5E200E42902 /* AtomicStringList.h */; settings = {ATTRIBUTES = (Private, ); }; };
                93F199DE08245E59001E9ABC /* Position.h in Headers */ = {isa = PBXBuildFile; fileRef = BE91FC8B06133666005E3790 /* Position.h */; settings = {ATTRIBUTES = (Private, ); }; };
                93F199E508245E59001E9ABC /* HTMLCanvasElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F6A3D60663BF04004D2919 /* HTMLCanvasElement.h */; };
                93F199E708245E59001E9ABC /* ClipboardMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D90660B0665D937006B6F1A /* ClipboardMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
                BC4918C90BFEA050009D6316 /* JSHTMLIFrameElement.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4918C30BFEA050009D6316 /* JSHTMLIFrameElement.h */; };
                BC491B780C023EFD009D6316 /* JSHTMLMarqueeElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC491B760C023EFD009D6316 /* JSHTMLMarqueeElement.cpp */; };
                BC491B790C023EFD009D6316 /* JSHTMLMarqueeElement.h in Headers */ = {isa = PBXBuildFile; fileRef = BC491B770C023EFD009D6316 /* JSHTMLMarqueeElement.h */; };
+               BC4BF9E40D11E133007D247F /* ClassNames.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC4BF9E20D11E133007D247F /* ClassNames.cpp */; };
+               BC4BF9E50D11E133007D247F /* ClassNames.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4BF9E30D11E133007D247F /* ClassNames.h */; settings = {ATTRIBUTES = (Private, ); }; };
                BC4EDEF40C08F3FB007EDD49 /* JSHTMLAppletElementCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC4EDEF30C08F3FB007EDD49 /* JSHTMLAppletElementCustom.cpp */; };
                BC5156E80C03B741008BB0EE /* DOMHTMLMarqueeElement.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = BC5156E50C03B741008BB0EE /* DOMHTMLMarqueeElement.h */; };
                BC5156E90C03B741008BB0EE /* DOMHTMLMarqueeElement.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC5156E60C03B741008BB0EE /* DOMHTMLMarqueeElement.mm */; };
                BC82432C0D0CE8A200460C8F /* JSVoidCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = BC8243280D0CE8A200460C8F /* JSVoidCallback.h */; };
                BC8243E80D0CFD7500460C8F /* WindowFeatures.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC8243E60D0CFD7500460C8F /* WindowFeatures.cpp */; };
                BC8243E90D0CFD7500460C8F /* WindowFeatures.h in Headers */ = {isa = PBXBuildFile; fileRef = BC8243E70D0CFD7500460C8F /* WindowFeatures.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               BC904B760D10998F00680D32 /* ClassNodeList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC904B720D10998F00680D32 /* ClassNodeList.cpp */; };
+               BC904B770D10998F00680D32 /* ClassNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = BC904B730D10998F00680D32 /* ClassNodeList.h */; };
                BC926F800C0552470082776B /* JSHTMLFrameSetElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC926F7E0C0552470082776B /* JSHTMLFrameSetElement.cpp */; };
                BC926F810C0552470082776B /* JSHTMLFrameSetElement.h in Headers */ = {isa = PBXBuildFile; fileRef = BC926F7F0C0552470082776B /* JSHTMLFrameSetElement.h */; };
                BC94D1080C274F88006BC617 /* PlatformScreenMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC94D1070C274F88006BC617 /* PlatformScreenMac.mm */; };
                BC305C770C076BB300CD20F0 /* JSHTMLObjectElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLObjectElement.cpp; sourceTree = "<group>"; };
                BC305C780C076BB300CD20F0 /* JSHTMLObjectElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLObjectElement.h; sourceTree = "<group>"; };
                BC305CA30C0781BB00CD20F0 /* JSHTMLObjectElementCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLObjectElementCustom.cpp; sourceTree = "<group>"; };
-               BC3B364705C9D5E200E42902 /* AtomicStringList.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = AtomicStringList.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                BC3C39B40C0D3D8D005F4D7A /* JSMediaList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaList.cpp; sourceTree = "<group>"; };
                BC3C39B50C0D3D8D005F4D7A /* JSMediaList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSMediaList.h; sourceTree = "<group>"; };
                BC3FCAA80AC3DB5800BA54AD /* PlatformScrollBar.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PlatformScrollBar.h; sourceTree = "<group>"; };
                BC491B4E0C023E2D009D6316 /* HTMLMarqueeElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = HTMLMarqueeElement.idl; sourceTree = "<group>"; };
                BC491B760C023EFD009D6316 /* JSHTMLMarqueeElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLMarqueeElement.cpp; sourceTree = "<group>"; };
                BC491B770C023EFD009D6316 /* JSHTMLMarqueeElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLMarqueeElement.h; sourceTree = "<group>"; };
+               BC4BF9E20D11E133007D247F /* ClassNames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ClassNames.cpp; sourceTree = "<group>"; };
+               BC4BF9E30D11E133007D247F /* ClassNames.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClassNames.h; sourceTree = "<group>"; };
                BC4EDEF30C08F3FB007EDD49 /* JSHTMLAppletElementCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLAppletElementCustom.cpp; sourceTree = "<group>"; };
                BC5156E50C03B741008BB0EE /* DOMHTMLMarqueeElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMHTMLMarqueeElement.h; sourceTree = "<group>"; };
                BC5156E60C03B741008BB0EE /* DOMHTMLMarqueeElement.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMHTMLMarqueeElement.mm; sourceTree = "<group>"; };
                BC8243280D0CE8A200460C8F /* JSVoidCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSVoidCallback.h; sourceTree = "<group>"; };
                BC8243E60D0CFD7500460C8F /* WindowFeatures.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WindowFeatures.cpp; sourceTree = "<group>"; };
                BC8243E70D0CFD7500460C8F /* WindowFeatures.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowFeatures.h; sourceTree = "<group>"; };
+               BC904B720D10998F00680D32 /* ClassNodeList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ClassNodeList.cpp; sourceTree = "<group>"; };
+               BC904B730D10998F00680D32 /* ClassNodeList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClassNodeList.h; sourceTree = "<group>"; };
                BC926F7E0C0552470082776B /* JSHTMLFrameSetElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLFrameSetElement.cpp; sourceTree = "<group>"; };
                BC926F7F0C0552470082776B /* JSHTMLFrameSetElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLFrameSetElement.h; sourceTree = "<group>"; };
                BC94D1070C274F88006BC617 /* PlatformScreenMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformScreenMac.mm; sourceTree = "<group>"; };
                F523D32402DE4478018635CA /* dom */ = {
                        isa = PBXGroup;
                        children = (
-                               BC3B364705C9D5E200E42902 /* AtomicStringList.h */,
                                A8C4A7FC09D563270003AC8D /* Attr.cpp */,
                                A8C4A7FB09D563270003AC8D /* Attr.h */,
                                93EEC1E509C2877700C515D1 /* Attr.idl */,
                                93EEC1E609C2877700C515D1 /* CharacterData.idl */,
                                A818721A0977D3C0005826D9 /* ChildNodeList.cpp */,
                                A81872150977D3C0005826D9 /* ChildNodeList.h */,
+                               BC4BF9E20D11E133007D247F /* ClassNames.cpp */,
+                               BC4BF9E30D11E133007D247F /* ClassNames.h */,
+                               BC904B720D10998F00680D32 /* ClassNodeList.cpp */,
+                               BC904B730D10998F00680D32 /* ClassNodeList.h */,
                                A784941A0B5FE507001E237A /* Clipboard.cpp */,
                                85031B280A44EFC700F992E0 /* Clipboard.h */,
                                4B8AF4A90B1CE02B00687690 /* ClipboardAccessPolicy.h */,
                                BCB16B8D0979B01400467741 /* ArrayImpl.h in Headers */,
                                B2C3DA1F0D006C1D00EF6F26 /* AtomicString.h in Headers */,
                                B2C3DA200D006C1D00EF6F26 /* AtomicStringImpl.h in Headers */,
-                               93F199CF08245E59001E9ABC /* AtomicStringList.h in Headers */,
                                A8C4A80D09D563270003AC8D /* Attr.h in Headers */,
                                A8C4A80B09D563270003AC8D /* Attribute.h in Headers */,
                                514C766C0CE923A1007EF3CD /* AuthenticationChallenge.h in Headers */,
                                93309DF8099E64920056E581 /* markup.h in Headers */,
                                93309E1E099E64920056E581 /* visible_units.h in Headers */,
                                51CBFC990D10E483002DBF51 /* CachedPagePlatformData.h in Headers */,
+                               BC904B770D10998F00680D32 /* ClassNodeList.h in Headers */,
+                               BC4BF9E50D11E133007D247F /* ClassNames.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                93309DF7099E64920056E581 /* markup.cpp in Sources */,
                                93309E1D099E64920056E581 /* visible_units.cpp in Sources */,
                                93A38B4B0D0E5808006872C2 /* EditorCommand.cpp in Sources */,
+                               BC904B760D10998F00680D32 /* ClassNodeList.cpp in Sources */,
+                               BC4BF9E40D11E133007D247F /* ClassNames.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 3533b41f365d7e164b6ede5969aec5c431321b7b..11ea2f2dd03181bd1e871c0ecd362c92ad908495 100644 (file)
@@ -390,8 +390,9 @@ void CSSStyleSelector::matchRules(CSSRuleSet* rules, int& firstRuleIndex, int& l
     if (element->hasID())
         matchRulesForList(rules->getIDRules(element->getIDAttribute().impl()), firstRuleIndex, lastRuleIndex);
     if (element->hasClass()) {
-        for (const AtomicStringList* singleClass = element->getClassList(); singleClass; singleClass = singleClass->next())
-            matchRulesForList(rules->getClassRules(singleClass->string().impl()), firstRuleIndex, lastRuleIndex);
+        const ClassNames& classNames = *element->getClassNames();
+        for (size_t i = 0; i < classNames.size(); ++i)
+            matchRulesForList(rules->getClassRules(classNames[i].impl()), firstRuleIndex, lastRuleIndex);
     }
     matchRulesForList(rules->getTagRules(element->localName().impl()), firstRuleIndex, lastRuleIndex);
     matchRulesForList(rules->getUniversalRules(), firstRuleIndex, lastRuleIndex);
@@ -1431,12 +1432,13 @@ bool CSSStyleSelector::checkOneSelector(CSSSelector* sel, Element* e, bool isAnc
         if (sel->m_match == CSSSelector::Class) {
             if (!e->hasClass())
                 return false;
-            for (const AtomicStringList* c = e->getClassList(); c; c = c->next())
-                if (c->string() == sel->m_value)
+            const ClassNames& classNames = *e->getClassNames();
+            for (size_t i = 0; i < classNames.size(); ++i) {
+                if (classNames[i] == sel->m_value)
                     return true;
+            }
             return false;
-        }
-        else if (sel->m_match == CSSSelector::Id)
+        } else if (sel->m_match == CSSSelector::Id)
             return e->hasID() && e->getIDAttribute() == sel->m_value;
         else if (style && (e != element || !styledElement || (!styledElement->isMappedAttribute(sel->m_attr) && sel->m_attr != typeAttr && sel->m_attr != readonlyAttr))) {
             style->setAffectedByAttributeSelectors(); // Special-case the "type" and "readonly" attributes so input form controls can share style.
diff --git a/WebCore/dom/AtomicStringList.h b/WebCore/dom/AtomicStringList.h
deleted file mode 100644 (file)
index f9ce57c..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * This file is part of the DOM implementation for KDE.
- *
- * Copyright (C) 2004 Apple Computer, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef AtomicStringList_h
-#define AtomicStringList_h
-
-#include "AtomicString.h"
-
-namespace WebCore {
-
-class AtomicStringList {
-public:
-    AtomicStringList() : m_next(0) {}
-    AtomicStringList(const AtomicString& str, AtomicStringList* n = 0) : m_string(str), m_next(n) {}
-    ~AtomicStringList() { delete m_next; }
-    
-    AtomicStringList* next() const { return m_next; }
-    void setNext(AtomicStringList* n) { m_next = n; }
-    const AtomicString& string() const { return m_string; }
-    void setString(const AtomicString& str) { m_string = str; }
-
-    AtomicStringList* clone() { return new AtomicStringList(m_string, m_next ? m_next->clone() : 0); }
-    void clear() { m_string = nullAtom; delete m_next; m_next = 0; }
-    
-private:
-    AtomicString m_string;
-    AtomicStringList* m_next;
-};
-
-}
-
-#endif
diff --git a/WebCore/dom/ClassNames.cpp b/WebCore/dom/ClassNames.cpp
new file mode 100644 (file)
index 0000000..27728af
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2007 David Smith (catfish.man@gmail.com)
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+#include "ClassNames.h"
+
+namespace WebCore {
+    
+bool ClassNames::contains(const AtomicString& str) const 
+{
+    if (!m_nameVector)
+        return false;
+
+    for (size_t i = 0; i < m_nameVector->size(); ++i) {
+        if ((*m_nameVector)[i] == str)
+            return true;
+    }
+
+    return false;
+}
+
+void ClassNames::parseClassAttribute(const String& classStr, const bool inCompatMode)
+{
+    if (!m_nameVector)
+        m_nameVector.set(new Vector<AtomicString>);
+    else
+        m_nameVector->clear();
+
+    if (classStr.isEmpty())
+        return;
+
+    String classAttr = inCompatMode ? classStr.foldCase() : classStr;
+
+    const UChar* str = classAttr.characters();
+    const int length = classAttr.length();
+    int start = 0;
+    while (true) {
+        while (start < length && isClassWhitespace(str[start]))
+            ++start;
+        if (start >= length)
+            break;
+        int end = start + 1;
+        while (end < length && !isClassWhitespace(str[end]))
+            ++end;
+
+        m_nameVector->append(AtomicString(str + start, end - start));
+
+        start = end + 1;
+    }
+}
+
+} // namespace WebCore
diff --git a/WebCore/dom/ClassNames.h b/WebCore/dom/ClassNames.h
new file mode 100644 (file)
index 0000000..15ba086
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2007 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef ClassNames_h
+#define ClassNames_h
+
+#include "AtomicString.h"
+#include <wtf/Vector.h>
+#include <wtf/OwnPtr.h>
+
+namespace WebCore {
+
+    class ClassNames {
+    public:
+        ClassNames()
+        {
+        }
+
+        bool contains(const AtomicString&) const;
+        void parseClassAttribute(const String&, const bool inCompatMode);
+
+        size_t size() const { return m_nameVector ? m_nameVector->size() : 0; }
+        void clear() { if (m_nameVector) m_nameVector->clear(); }
+        const AtomicString& operator[](size_t i) const { return m_nameVector ? (*m_nameVector)[i] : nullAtom; }
+
+    private:
+        OwnPtr<Vector<AtomicString> > m_nameVector;
+    };
+
+    inline static bool isClassWhitespace(UChar c)
+    {
+        return c == ' ' || c == '\r' || c == '\n' || c == '\t' || c == '\f';
+    }
+
+} // namespace WebCore
+
+#endif // ClassNames_h
diff --git a/WebCore/dom/ClassNodeList.cpp b/WebCore/dom/ClassNodeList.cpp
new file mode 100644 (file)
index 0000000..390fc35
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2007 David Smith (catfish.man@gmail.com)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ClassNodeList.h"
+
+#include "Document.h"
+#include "Element.h"
+#include "Node.h"
+
+namespace WebCore {
+
+ClassNodeList::ClassNodeList(PassRefPtr<Node> rootNode, const AtomicString& className)
+    : NodeList(rootNode)
+{
+    m_classNames.parseClassAttribute(className, m_rootNode->document()->inCompatMode());
+}
+
+unsigned ClassNodeList::length() const
+{
+    return recursiveLength();
+}
+
+Node* ClassNodeList::item(unsigned index) const
+{
+    return recursiveItem(index);
+}
+
+bool ClassNodeList::nodeMatches(Node* testNode) const
+{
+    if (!testNode->isElementNode())
+        return false;
+
+    if (!testNode->hasClass())
+        return false;
+
+    if (!m_classNames.size())
+        return false;
+
+    const ClassNames& classes = *static_cast<Element*>(testNode)->getClassNames();
+    for (size_t i = 0; i < m_classNames.size(); ++i) {
+        if (!classes.contains(m_classNames[i]))
+            return false;
+    }
+
+    return true;
+}
+
+} // namespace WebCore
diff --git a/WebCore/dom/ClassNodeList.h b/WebCore/dom/ClassNodeList.h
new file mode 100644 (file)
index 0000000..1ba05a7
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2007 David Smith (catfish.man@gmail.com)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ClassNodeList_h
+#define ClassNodeList_h
+
+#include "AtomicString.h"
+#include "ClassNames.h"
+#include "NodeList.h"
+
+namespace WebCore {
+
+    class ClassNodeList : public NodeList {
+    public:
+        ClassNodeList(PassRefPtr<Node> rootNode, const AtomicString& className);
+
+        virtual unsigned length() const;
+        virtual Node* item(unsigned index) const;
+
+    private:
+        virtual bool nodeMatches(Node*) const;
+
+        ClassNames m_classNames;
+    };
+
+} // namespace WebCore
+
+#endif // ClassNodeList_h
index a84c895bcb31004f0301cb9ebf6d1e5b38a9fa0b..ec237154a61fe873e56590f314975fd14afe6445 100644 (file)
 #include "CSSStyleSelector.h"
 #include "CSSStyleSheet.h"
 #include "CSSValueKeywords.h"
+#include "ClassNodeList.h"
 #include "Comment.h"
 #include "CookieJar.h"
-#include "DatabaseThread.h"
 #include "DOMImplementation.h"
+#include "DatabaseThread.h"
 #include "DocLoader.h"
 #include "DocumentFragment.h"
 #include "DocumentLoader.h"
@@ -3494,11 +3495,16 @@ HTMLCollection::CollectionInfo* Document::nameCollectionInfo(HTMLCollection::Typ
     return iter->second;
 }
 
-PassRefPtr<NameNodeList> Document::getElementsByName(const String &elementName)
+PassRefPtr<NameNodeList> Document::getElementsByName(const StringelementName)
 {
     return new NameNodeList(this, elementName);
 }
 
+PassRefPtr<NodeList> Document::getElementsByClassName(const String& className)
+{
+    return new ClassNodeList(this, className);
+}
+
 void Document::finishedParsing()
 {
     setParsing(false);
index 376355ef380370ffb93f52de04651d04068e5f6b..1bf52fbd2b29be89ff53b0bc8a68181e8390bf62 100644 (file)
@@ -213,6 +213,7 @@ public:
     PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&);
     
     PassRefPtr<NameNodeList> getElementsByName(const String& elementName);
+    PassRefPtr<NodeList> getElementsByClassName(const String& className);
 
     PassRefPtr<HTMLCollection> images();
     PassRefPtr<HTMLCollection> embeds();
index c4fadbb13c19a619647e8c34d65bf4863e1d591c..544aedca9f49fe639af009834c050c6a4fbadc52 100644 (file)
@@ -220,6 +220,8 @@ module core {
                                                   in [Optional] boolean authorOnly);
 #endif
 
+        // HTML 5
+        NodeList            getElementsByClassName(in DOMString tagname);
     };
 
 }
index 579771734f61def63a4868e97cab37d88b5abf52..ecbdf18a70bc9a6b82ca51e2561e4cff1d23a075 100644 (file)
@@ -3,6 +3,7 @@
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2001 Peter Kelly (pmk@post.com)
  *           (C) 2001 Dirk Mueller (mueller@kde.org)
+ *           (C) 2007 David Smith (catfish.man@gmail.com)
  * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
  *           (C) 2007 Eric Seidel (eric@webkit.org)
  *
@@ -26,6 +27,8 @@
 #include "Element.h"
 
 #include "CSSStyleSelector.h"
+#include "ClassNames.h"
+#include "ClassNodeList.h"
 #include "Document.h"
 #include "Editor.h"
 #include "ExceptionCode.h"
@@ -36,6 +39,7 @@
 #include "HTMLNames.h"
 #include "KURL.h"
 #include "NamedAttrMap.h"
+#include "NodeList.h"
 #include "Page.h"
 #include "RenderBlock.h"
 #include "SelectionController.h"
@@ -196,7 +200,7 @@ Node::NodeType Element::nodeType() const
     return ELEMENT_NODE;
 }
 
-const AtomicStringList* Element::getClassList() const
+const ClassNames* Element::getClassNames() const
 {
     return 0;
 }
@@ -1119,6 +1123,11 @@ RenderStyle* Element::computedStyle()
     return rd->m_computedStyle;
 }
 
+PassRefPtr<NodeList> Element::getElementsByClassName(const String& className)
+{
+    return new ClassNodeList(this, className);
+}
+
 void Element::cancelFocusAppearanceUpdate()
 {
     if (ElementRareData* rd = rareData())
index d87ce771101901a7e3644855c176abc903e7597c..163d54803e306fa7c54fec60fcf29436354688e0 100644 (file)
 
 namespace WebCore {
 
-class AtomicStringList;
 class Attr;
 class Attribute;
 class CSSStyleDeclaration;
+class ClassNames;
 class ElementRareData;
 class IntSize;
 
@@ -44,7 +44,7 @@ public:
     ~Element();
 
     // Used to quickly determine whether or not an element has a given CSS class.
-    virtual const AtomicStringList* getClassList() const;
+    virtual const ClassNames* getClassNames() const;
     const AtomicString& getIDAttribute() const;
     bool hasAttribute(const QualifiedName&) const;
     const AtomicString& getAttribute(const QualifiedName&) const;
@@ -162,6 +162,8 @@ public:
     virtual void focus(bool restorePreviousSelection = true);
     virtual void updateFocusAppearance(bool restorePreviousSelection);
     void blur();
+    
+    PassRefPtr<NodeList> getElementsByClassName(const String&);
 
 #ifndef NDEBUG
     virtual void dump(TextStream* , DeprecatedString ind = "") const;
index 397c4d62c6543253c8e4a53ec26c3a2d43ed472c..103eddab275b55461594bda02dae2a90ffc5e9a1 100644 (file)
@@ -102,6 +102,9 @@ module core {
         void scrollByLines(in long lines);
         void scrollByPages(in long pages);
 
+        // HTML 5
+        NodeList getElementsByClassName(in DOMString name);
+
 #if defined(LANGUAGE_OBJECTIVE_C)
         // Objective-C extensions
         readonly attribute DOMString innerText;
index d459e78dd917b0401f95901c49a8a58fd3663add..5fd9eb57d05db7bc59f39e92e31bc4f2fd5f13cb 100644 (file)
@@ -1,10 +1,8 @@
 /**
- * This file is part of the DOM implementation for KDE.
- *
  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2001 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2004 Apple Computer, Inc.
+ * Copyright (C) 2004, 2007 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
 #include "Element.h"
 #include "HTMLNames.h"
 
-using namespace WebCore;
-
 namespace WebCore {
 
 using namespace HTMLNames;
 
-NameNodeList::NameNodeList(Node *n, const String &t)
-  : NodeList(n), nodeName(t)
+NameNodeList::NameNodeList(Node* root, const String& name)
+    : NodeList(root)
+    , m_nodeName(name)
 {
 }
 
@@ -44,14 +41,14 @@ unsigned NameNodeList::length() const
     return recursiveLength();
 }
 
-Node *NameNodeList::item (unsigned index) const
+NodeNameNodeList::item (unsigned index) const
 {
     return recursiveItem(index);
 }
 
-bool NameNodeList::nodeMatches(Node *testNode) const
+bool NameNodeList::nodeMatches(NodetestNode) const
 {
-    return static_cast<Element*>(testNode)->getAttribute(nameAttr) == nodeName;
+    return static_cast<Element*>(testNode)->getAttribute(nameAttr) == m_nodeName;
 }
 
-}
+} // namespace WebCore
index 2d440975b23e5f957d77ef1add70c763cec79a49..aa801e261183d8a4497cf71637af98ba8cd65233 100644 (file)
@@ -1,10 +1,8 @@
 /*
- * This file is part of the DOM implementation for KDE.
- *
  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2001 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2004 Apple Computer, Inc.
+ * Copyright (C) 2004, 2007 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -35,7 +33,7 @@ namespace WebCore {
  */
 class NameNodeList : public NodeList {
 public:
-    NameNodeList(Node* doc, const String& name);
+    NameNodeList(Node* root, const String& name);
 
     // DOM methods overridden from  parent classes
 
@@ -48,7 +46,8 @@ public:
 protected:
     virtual bool nodeMatches(Node* testNode) const;
 
-    String nodeName;
+private:
+    String m_nodeName;
 };
 
 } // namespace WebCore
index a81f76d3a579acd9b3412ff52ce80a52c2b5d799..afa4d761fa224504c5341ea83c361e64361c3b7f 100644 (file)
@@ -3,6 +3,7 @@
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2001 Peter Kelly (pmk@post.com)
  *           (C) 2001 Dirk Mueller (mueller@kde.org)
+ *           (C) 2007 David Smith (catfish.man@gmail.com)
  * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
@@ -37,7 +38,7 @@ NamedMappedAttrMap::NamedMappedAttrMap(Element *e)
 
 void NamedMappedAttrMap::clearAttributes()
 {
-    m_classList.clear();
+    m_classNames.clear();
     m_mappedAttributeCount = 0;
     NamedAttrMap::clearAttributes();
 }
@@ -76,48 +77,15 @@ bool NamedMappedAttrMap::mapsEquivalent(const NamedMappedAttrMap* otherMap) cons
     return true;
 }
 
-inline static bool isClassWhitespace(UChar c)
-{
-    return c == ' ' || c == '\r' || c == '\n' || c == '\t';
-}
-
-void NamedMappedAttrMap::parseClassAttribute(const String& classStr)
-{
-    m_classList.clear();
-    if (!element->hasClass())
+void NamedMappedAttrMap::parseClassAttribute(const String& classStr) 
+{ 
+    if (!element->hasClass()) { 
+        m_classNames.clear(); 
         return;
-    
-    String classAttr = element->document()->inCompatMode() ? 
-        (classStr.impl()->isLower() ? classStr : String(classStr.impl()->lower())) :
-        classStr;
-    
-    AtomicStringList* curr = 0;
-    
-    const UChar* str = classAttr.characters();
-    int length = classAttr.length();
-    int sPos = 0;
-
-    while (true) {
-        while (sPos < length && isClassWhitespace(str[sPos]))
-            ++sPos;
-        if (sPos >= length)
-            break;
-        int ePos = sPos + 1;
-        while (ePos < length && !isClassWhitespace(str[ePos]))
-            ++ePos;
-        if (curr) {
-            curr->setNext(new AtomicStringList(AtomicString(str + sPos, ePos - sPos)));
-            curr = curr->next();
-        } else {
-            if (sPos == 0 && ePos == length) {
-                m_classList.setString(AtomicString(classAttr));
-                break;
-            }
-            m_classList.setString(AtomicString(str + sPos, ePos - sPos));
-            curr = &m_classList;
-        }
-        sPos = ePos + 1;
     }
+
+    m_classNames.parseClassAttribute(classStr, element->document()->inCompatMode()); 
 }
 
+
 }
index 8df5a0ee27d99e99d4b0a96cfce6079d8d67afef..2889a3433ddbe93a0cb1802804ee6815655598bf 100644 (file)
@@ -5,6 +5,7 @@
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2001 Peter Kelly (pmk@post.com)
  *           (C) 2001 Dirk Mueller (mueller@kde.org)
+ *           (C) 2007 David Smith (catfish.man@gmail.com)
  * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
  *
  * This library is free software; you can redistribute it and/or
@@ -27,9 +28,9 @@
 #ifndef NamedMappedAttrMap_h
 #define NamedMappedAttrMap_h
 
-#include "NamedAttrMap.h"
-#include "AtomicStringList.h"
+#include "ClassNames.h"
 #include "MappedAttribute.h"
+#include "NamedAttrMap.h"
 
 namespace WebCore {
 
@@ -42,8 +43,9 @@ public:
     
     virtual bool isMappedAttributeMap() const;
     
-    virtual void parseClassAttribute(const String& classAttr);
-    const AtomicStringList* getClassList() const { return &m_classList; }
+    void parseClassAttribute(const String&);
+
+    const ClassNames* getClassNames() const { return &m_classNames; }
     
     virtual bool hasMappedAttributes() const { return m_mappedAttributeCount > 0; }
     void declRemoved() { m_mappedAttributeCount--; }
@@ -60,7 +62,7 @@ public:
         { return static_cast<MappedAttribute*>(NamedAttrMap::getAttributeItem(name)); }
     
 private:
-    AtomicStringList m_classList;
+    ClassNames m_classNames;
     int m_mappedAttributeCount;
 };
 
index f499bd7e9e72b99cb474f2aed1b98edd4facb83f..4e1901a2dccd6dfc8324c8a33e77d3d42b05af63 100644 (file)
@@ -29,6 +29,7 @@
 #include "CSSStyleSelector.h"
 #include "CSSStyleSheet.h"
 #include "CSSValueKeywords.h"
+#include "ClassNames.h"
 #include "Document.h"
 #include "HTMLNames.h"
 
@@ -103,11 +104,6 @@ void StyledElement::updateStyleAttributeIfNeeded() const
     }
 }
 
-inline static bool isClassWhitespace(UChar c)
-{
-    return c == ' ' || c == '\r' || c == '\n' || c == '\t';
-}
-
 StyledElement::StyledElement(const QualifiedName& name, Document *doc)
     : Element(name, doc)
 {
@@ -263,9 +259,9 @@ CSSMutableStyleDeclaration* StyledElement::additionalAttributeStyleDecl()
     return 0;
 }
 
-const AtomicStringList* StyledElement::getClassList() const
+const ClassNames* StyledElement::getClassNames() const
 {
-    return namedAttrMap ? mappedAttributes()->getClassList() : 0;
+    return namedAttrMap ? mappedAttributes()->getClassNames() : 0;
 }
 
 static inline int toHex(UChar c) {
index 57c9f59deba613450d37e3bfd9ff41dbd95dd401..afc3369bdd0b0e9e67116e64da59a535ef29fcf1 100644 (file)
@@ -66,7 +66,7 @@ public:
     void invalidateStyleAttribute();
     virtual void updateStyleAttributeIfNeeded() const;
     
-    virtual const AtomicStringList* getClassList() const;
+    virtual const ClassNames* getClassNames() const;
     virtual void attributeChanged(Attribute* attr, bool preserveDecls = false);
     virtual void parseMappedAttribute(MappedAttribute* attr);
     virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;