Diff
Modified: trunk/LayoutTests/ChangeLog (109199 => 109200)
--- trunk/LayoutTests/ChangeLog 2012-02-29 07:19:45 UTC (rev 109199)
+++ trunk/LayoutTests/ChangeLog 2012-02-29 07:25:52 UTC (rev 109200)
@@ -1,3 +1,19 @@
+2012-02-28 Arko Saha <[email protected]>
+
+ Microdata: Implement HTMLPropertiesCollection collection.namedItem().
+ https://bugs.webkit.org/show_bug.cgi?id=73156
+
+ Reviewed by Kentaro Hara.
+
+ Added test-cases for collection.namedItem().
+
+ * fast/dom/MicroData/nameditem-must-be-case-sensitive-expected.txt: Added.
+ * fast/dom/MicroData/nameditem-must-be-case-sensitive.html: Added.
+ * fast/dom/MicroData/nameditem-must-return-correct-item-properties-expected.txt: Added.
+ * fast/dom/MicroData/nameditem-must-return-correct-item-properties.html: Added.
+ * fast/dom/MicroData/properties-collection-nameditem-test-expected.txt: Added.
+ * fast/dom/MicroData/properties-collection-nameditem-test.html: Added.
+
2012-02-28 Kenichi Ishibashi <[email protected]>
[Chromium] Unreviewed test expectations update after r109183
Added: trunk/LayoutTests/fast/dom/MicroData/nameditem-must-be-case-sensitive-expected.txt (0 => 109200)
--- trunk/LayoutTests/fast/dom/MicroData/nameditem-must-be-case-sensitive-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/MicroData/nameditem-must-be-case-sensitive-expected.txt 2012-02-29 07:25:52 UTC (rev 109200)
@@ -0,0 +1,23 @@
+This test ensures that namedItem must be case sensitive.
+
+Created element of type: div
+Set attribute: itemscope, value: itemscope
+PASS element.properties.namedItem('foo').length is 2
+PASS element.properties.namedItem('FOO').length is 1
+PASS element.properties.namedItem('FOo').length is 1
+PASS element.properties.namedItem('foo')[0] is element.firstChild
+PASS element.properties.namedItem('foo')[1] is element.childNodes[1].lastChild
+PASS element.properties.namedItem('FOO')[0] is element.childNodes[1].firstChild
+PASS element.properties.namedItem('FOo')[0] is element.childNodes[1].lastChild
+
+PASS element.properties['foo'].length is 2
+PASS element.properties['FOO'].length is 1
+PASS element.properties['FOo'].length is 1
+PASS element.properties['foo'][0] is element.firstChild
+PASS element.properties['foo'][1] is element.childNodes[1].lastChild
+PASS element.properties['FOO'][0] is element.childNodes[1].firstChild
+PASS element.properties['FOo'][0] is element.childNodes[1].lastChild
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/MicroData/nameditem-must-be-case-sensitive.html (0 => 109200)
--- trunk/LayoutTests/fast/dom/MicroData/nameditem-must-be-case-sensitive.html (rev 0)
+++ trunk/LayoutTests/fast/dom/MicroData/nameditem-must-be-case-sensitive.html 2012-02-29 07:25:52 UTC (rev 109200)
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p>This test ensures that namedItem must be case sensitive.</p>
+<div id="console"></div>
+<script>
+var element = createElement('div', {itemscope: 'itemscope'}, '<div itemprop="foo"></div><div itemprop="bar"><div itemprop="FOO"></div><div itemprop="foo FOo foo"></div></div><div itemprop="baz qux"></div>');
+
+shouldBe("element.properties.namedItem('foo').length", '2');
+shouldBe("element.properties.namedItem('FOO').length", '1');
+shouldBe("element.properties.namedItem('FOo').length", '1');
+
+shouldBe("element.properties.namedItem('foo')[0]", 'element.firstChild');
+shouldBe("element.properties.namedItem('foo')[1]", 'element.childNodes[1].lastChild');
+shouldBe("element.properties.namedItem('FOO')[0]", 'element.childNodes[1].firstChild');
+shouldBe("element.properties.namedItem('FOo')[0]", 'element.childNodes[1].lastChild');
+debug('');
+
+shouldBe("element.properties['foo'].length", '2');
+shouldBe("element.properties['FOO'].length", '1');
+shouldBe("element.properties['FOo'].length", '1');
+
+shouldBe("element.properties['foo'][0]", 'element.firstChild');
+shouldBe("element.properties['foo'][1]", 'element.childNodes[1].lastChild');
+shouldBe("element.properties['FOO'][0]", 'element.childNodes[1].firstChild');
+shouldBe("element.properties['FOo'][0]", 'element.childNodes[1].lastChild');
+
+</script>
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/fast/dom/MicroData/nameditem-must-return-correct-item-properties-expected.txt (0 => 109200)
--- trunk/LayoutTests/fast/dom/MicroData/nameditem-must-return-correct-item-properties-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/MicroData/nameditem-must-return-correct-item-properties-expected.txt 2012-02-29 07:25:52 UTC (rev 109200)
@@ -0,0 +1,35 @@
+This test ensures that namedItem must return the correct item properties.
+
+Created element of type: div
+
+Test properties.namedItem(name).
+PASS item.properties.namedItem('foo').length is 2
+PASS item.properties.namedItem('bar').length is 1
+PASS item.properties.namedItem('baz').length is 1
+PASS item.properties.namedItem('qux').length is 1
+PASS item.properties.namedItem('foo')[0] is element.firstChild
+PASS item.properties.namedItem('foo')[1] is item.firstChild
+PASS item.properties.namedItem('bar')[0] is item.firstChild
+PASS item.properties.namedItem('baz')[0] is element.lastChild
+PASS item.properties.namedItem('qux')[0] is element.lastChild.firstChild
+
+Test properties[name].
+PASS item.properties['foo'].length is 2
+PASS item.properties['bar'].length is 1
+PASS item.properties['baz'].length is 1
+PASS item.properties['qux'].length is 1
+PASS item.properties['foo'][0] is element.firstChild
+PASS item.properties['foo'][1] is item.firstChild
+PASS item.properties['bar'][0] is item.firstChild
+PASS item.properties['baz'][0] is element.lastChild
+PASS item.properties['qux'][0] is element.lastChild.firstChild
+
+Test properties[index].
+PASS item.properties[0] is element.firstChild
+PASS item.properties[1] is item.firstChild
+PASS item.properties[2] is element.lastChild
+PASS item.properties[3] is element.lastChild.firstChild
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/MicroData/nameditem-must-return-correct-item-properties.html (0 => 109200)
--- trunk/LayoutTests/fast/dom/MicroData/nameditem-must-return-correct-item-properties.html (rev 0)
+++ trunk/LayoutTests/fast/dom/MicroData/nameditem-must-return-correct-item-properties.html 2012-02-29 07:25:52 UTC (rev 109200)
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p>This test ensures that namedItem must return the correct item properties.</p>
+<div id="console"></div>
+<script>
+var element = createElement('div', {}, '<div itemprop="foo" id="id1"></div><div itemscope itemref="id2 id1"><div itemprop="foo bar"></div></div><div itemprop="baz" id="id2"><div itemprop="qux">');
+var item = element.childNodes[1];
+document.body.appendChild(element);
+
+debug("<br>Test properties.namedItem(name).");
+shouldBe("item.properties.namedItem('foo').length", '2');
+shouldBe("item.properties.namedItem('bar').length", '1');
+shouldBe("item.properties.namedItem('baz').length", '1');
+shouldBe("item.properties.namedItem('qux').length", '1');
+
+shouldBe("item.properties.namedItem('foo')[0]", 'element.firstChild');
+shouldBe("item.properties.namedItem('foo')[1]", 'item.firstChild');
+shouldBe("item.properties.namedItem('bar')[0]", 'item.firstChild');
+shouldBe("item.properties.namedItem('baz')[0]", 'element.lastChild');
+shouldBe("item.properties.namedItem('qux')[0]", 'element.lastChild.firstChild');
+
+debug("<br>Test properties[name].");
+shouldBe("item.properties['foo'].length", '2');
+shouldBe("item.properties['bar'].length", '1');
+shouldBe("item.properties['baz'].length", '1');
+shouldBe("item.properties['qux'].length", '1');
+
+shouldBe("item.properties['foo'][0]", 'element.firstChild');
+shouldBe("item.properties['foo'][1]", 'item.firstChild');
+shouldBe("item.properties['bar'][0]", 'item.firstChild');
+shouldBe("item.properties['baz'][0]", 'element.lastChild');
+shouldBe("item.properties['qux'][0]", 'element.lastChild.firstChild');
+
+debug("<br>Test properties[index].");
+shouldBe("item.properties[0]", 'element.firstChild');
+shouldBe("item.properties[1]", 'item.firstChild');
+shouldBe("item.properties[2]", 'element.lastChild');
+shouldBe("item.properties[3]", 'element.lastChild.firstChild')
+
+</script>
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/fast/dom/MicroData/properties-collection-nameditem-test-expected.txt (0 => 109200)
--- trunk/LayoutTests/fast/dom/MicroData/properties-collection-nameditem-test-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/MicroData/properties-collection-nameditem-test-expected.txt 2012-02-29 07:25:52 UTC (rev 109200)
@@ -0,0 +1,22 @@
+Properties collection's namedItem property simple test.
+
+Created element of type: div
+Set attribute: itemscope, value: itemscope
+
+Test properties.namedItem(name).
+PASS element.properties.namedItem('foo') is defined.
+PASS element.properties.namedItem('foo').length is 1
+PASS element.properties.namedItem('foo')[0] is element.firstChild
+
+Test properties[name].
+PASS element.properties['foo'] is defined.
+PASS element.properties['foo'].length is 1
+PASS element.properties['foo'][0] is element.firstChild
+
+Test properties[index].
+PASS element.properties[0] is defined.
+PASS element.properties[0] is element.firstChild
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/MicroData/properties-collection-nameditem-test.html (0 => 109200)
--- trunk/LayoutTests/fast/dom/MicroData/properties-collection-nameditem-test.html (rev 0)
+++ trunk/LayoutTests/fast/dom/MicroData/properties-collection-nameditem-test.html 2012-02-29 07:25:52 UTC (rev 109200)
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p>Properties collection's namedItem property simple test.</p>
+<div id="console"></div>
+<script>
+var element = createElement('div', {itemscope: 'itemscope'}, '<div itemprop="foo"></div>');
+
+debug("<br>Test properties.namedItem(name).");
+shouldBeDefined("element.properties.namedItem('foo')");
+shouldBe("element.properties.namedItem('foo').length", '1');
+shouldBe("element.properties.namedItem('foo')[0]", 'element.firstChild');
+
+debug("<br>Test properties[name].");
+shouldBeDefined("element.properties['foo']");
+shouldBe("element.properties['foo'].length", '1');
+shouldBe("element.properties['foo'][0]", 'element.firstChild');
+
+debug("<br>Test properties[index].");
+shouldBeDefined("element.properties[0]");
+shouldBe("element.properties[0]", 'element.firstChild');
+
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (109199 => 109200)
--- trunk/Source/WebCore/ChangeLog 2012-02-29 07:19:45 UTC (rev 109199)
+++ trunk/Source/WebCore/ChangeLog 2012-02-29 07:25:52 UTC (rev 109200)
@@ -1,3 +1,29 @@
+2012-02-28 Arko Saha <[email protected]>
+
+ Microdata: Implement HTMLPropertiesCollection collection.namedItem().
+ https://bugs.webkit.org/show_bug.cgi?id=73156
+
+ Reviewed by Kentaro Hara.
+
+ Tests: fast/dom/MicroData/nameditem-must-be-case-sensitive.html
+ fast/dom/MicroData/nameditem-must-return-correct-item-properties.html
+ fast/dom/MicroData/properties-collection-nameditem-test.html
+
+ * bindings/scripts/CodeGeneratorJS.pm: Modified code generator to generate
+ JS bindings code for HTMLPropertiesCollection [NamedGetter] property.
+ (GenerateImplementation):
+ * html/HTMLPropertiesCollection.cpp:
+ (WebCore::HTMLPropertiesCollection::names):
+ (WebCore):
+ (WebCore::HTMLPropertiesCollection::namedItem): Returns a NodeList object
+ containing any elements that add a property named name.
+ (WebCore::HTMLPropertiesCollection::hasNamedItem): Checks if the items can
+ be retrieved or not based on the property named name.
+ * html/HTMLPropertiesCollection.h: Added namedItem(), hasProperty(),
+ hasNamedItem() methods.
+ (HTMLPropertiesCollection):
+ * html/HTMLPropertiesCollection.idl: Added namedItem() IDL method.
+
2012-02-28 Kinuko Yasuda <[email protected]>
Add size field to Metadata in FileSystem API
Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (109199 => 109200)
--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2012-02-29 07:19:45 UTC (rev 109199)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2012-02-29 07:25:52 UTC (rev 109200)
@@ -2224,6 +2224,20 @@
}
}
+ if ($interfaceName eq "HTMLPropertiesCollection") {
+ if ($dataNode->extendedAttributes->{"NamedGetter"}) {
+ push(@implContent, "bool ${className}::canGetItemsForName(ExecState*, $implClassName* collection, const Identifier& propertyName)\n");
+ push(@implContent, "{\n");
+ push(@implContent, " return collection->hasNamedItem(identifierToAtomicString(propertyName));\n");
+ push(@implContent, "}\n\n");
+ push(@implContent, "JSValue ${className}::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)\n");
+ push(@implContent, "{\n");
+ push(@implContent, " ${className}* thisObj = static_cast<$className*>(asObject(slotBase));\n");
+ push(@implContent, " return toJS(exec, thisObj->globalObject(), static_cast<$implClassName*>(thisObj->impl())->namedItem(identifierToAtomicString(propertyName)));\n");
+ push(@implContent, "}\n\n");
+ }
+ }
+
if ((!$hasParent && !$dataNode->extendedAttributes->{"JSCustomIsReachable"})|| $dataNode->extendedAttributes->{"JSGenerateIsReachable"} || $dataNode->extendedAttributes->{"ActiveDOMObject"}) {
push(@implContent, "static inline bool isObservable(JS${implClassName}* js${implClassName})\n");
push(@implContent, "{\n");
Modified: trunk/Source/WebCore/html/HTMLPropertiesCollection.cpp (109199 => 109200)
--- trunk/Source/WebCore/html/HTMLPropertiesCollection.cpp 2012-02-29 07:19:45 UTC (rev 109199)
+++ trunk/Source/WebCore/html/HTMLPropertiesCollection.cpp 2012-02-29 07:25:52 UTC (rev 109200)
@@ -39,6 +39,7 @@
#include "HTMLElement.h"
#include "HTMLNames.h"
#include "Node.h"
+#include "StaticNodeList.h"
namespace WebCore {
@@ -172,6 +173,48 @@
return m_propertyNames;
}
+PassRefPtr<NodeList> HTMLPropertiesCollection::namedItem(const String& name) const
+{
+ if (!base()->isHTMLElement() || !toHTMLElement(base())->fastHasAttribute(itemscopeAttr))
+ return 0;
+
+ m_properties.clear();
+ Vector<RefPtr<Node> > namedItems;
+ findPropetiesOfAnItem(base());
+
+ std::sort(m_properties.begin(), m_properties.end(), compareTreeOrder);
+
+ // For each item properties, split the value of that itemprop attribute on spaces.
+ // Add element to namedItem that contains a property named name, with the order preserved.
+ for (size_t i = 0; i < m_properties.size(); ++i) {
+ DOMSettableTokenList* itemProperty = m_properties[i]->itemProp();
+ if (itemProperty->tokens().contains(name))
+ namedItems.append(m_properties[i]);
+ }
+
+ // FIXME: HTML5 specifies that this should return PropertyNodeList.
+ return namedItems.isEmpty() ? 0 : StaticNodeList::adopt(namedItems);
+}
+
+bool HTMLPropertiesCollection::hasNamedItem(const AtomicString& name) const
+{
+ if (!base()->isHTMLElement() || !toHTMLElement(base())->fastHasAttribute(itemscopeAttr))
+ return false;
+
+ m_properties.clear();
+ findPropetiesOfAnItem(base());
+
+ // For each item properties, split the value of that itemprop attribute on spaces.
+ // Return true if element contains a property named name.
+ for (size_t i = 0; i < m_properties.size(); ++i) {
+ DOMSettableTokenList* itemProperty = m_properties[i]->itemProp();
+ if (itemProperty->tokens().contains(name))
+ return true;
+ }
+
+ return false;
+}
+
} // namespace WebCore
#endif // ENABLE(MICRODATA)
Modified: trunk/Source/WebCore/html/HTMLPropertiesCollection.h (109199 => 109200)
--- trunk/Source/WebCore/html/HTMLPropertiesCollection.h 2012-02-29 07:19:45 UTC (rev 109199)
+++ trunk/Source/WebCore/html/HTMLPropertiesCollection.h 2012-02-29 07:25:52 UTC (rev 109200)
@@ -50,10 +50,14 @@
PassRefPtr<DOMStringList> names() const;
+ PassRefPtr<NodeList> namedItem(const String&) const;
+ bool hasNamedItem(const AtomicString&) const;
+
private:
HTMLPropertiesCollection(Node*);
void findPropetiesOfAnItem(Node* current) const;
+ void getNamedItems(Vector<RefPtr<Node> >&, const String&) const;
mutable Vector<Node*> m_properties;
mutable RefPtr<DOMStringList> m_propertyNames;
Modified: trunk/Source/WebCore/html/HTMLPropertiesCollection.idl (109199 => 109200)
--- trunk/Source/WebCore/html/HTMLPropertiesCollection.idl 2012-02-29 07:19:45 UTC (rev 109199)
+++ trunk/Source/WebCore/html/HTMLPropertiesCollection.idl 2012-02-29 07:25:52 UTC (rev 109200)
@@ -32,13 +32,15 @@
interface [
Conditional=MICRODATA,
- IndexedGetter
+ IndexedGetter,
+ NamedGetter
] HTMLPropertiesCollection : HTMLCollection {
readonly attribute unsigned long length;
Node item(in unsigned long index);
readonly attribute DOMStringList names;
- // FIXME: override inherited namedItem()
+ // FIXME: HTML5 specifies that this should return PropertyNodeList.
+ NodeList namedItem(in DOMString name);
};
}