Changeset 109200 in webkit


Ignore:
Timestamp:
Feb 28, 2012 11:25:52 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Microdata: Implement HTMLPropertiesCollection collection.namedItem().
https://bugs.webkit.org/show_bug.cgi?id=73156

Patch by Arko Saha <arko@motorola.com> on 2012-02-28
Reviewed by Kentaro Hara.

Source/WebCore:

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.

LayoutTests:

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.
Location:
trunk
Files:
6 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r109199 r109200  
     12012-02-28  Arko Saha  <arko@motorola.com>
     2
     3        Microdata: Implement HTMLPropertiesCollection collection.namedItem().
     4        https://bugs.webkit.org/show_bug.cgi?id=73156
     5
     6        Reviewed by Kentaro Hara.
     7
     8        Added test-cases for collection.namedItem().
     9
     10        * fast/dom/MicroData/nameditem-must-be-case-sensitive-expected.txt: Added.
     11        * fast/dom/MicroData/nameditem-must-be-case-sensitive.html: Added.
     12        * fast/dom/MicroData/nameditem-must-return-correct-item-properties-expected.txt: Added.
     13        * fast/dom/MicroData/nameditem-must-return-correct-item-properties.html: Added.
     14        * fast/dom/MicroData/properties-collection-nameditem-test-expected.txt: Added.
     15        * fast/dom/MicroData/properties-collection-nameditem-test.html: Added.
     16
    1172012-02-28  Kenichi Ishibashi  <bashi@chromium.org>
    218
  • trunk/Source/WebCore/ChangeLog

    r109198 r109200  
     12012-02-28  Arko Saha  <arko@motorola.com>
     2
     3        Microdata: Implement HTMLPropertiesCollection collection.namedItem().
     4        https://bugs.webkit.org/show_bug.cgi?id=73156
     5
     6        Reviewed by Kentaro Hara.
     7
     8        Tests: fast/dom/MicroData/nameditem-must-be-case-sensitive.html
     9               fast/dom/MicroData/nameditem-must-return-correct-item-properties.html
     10               fast/dom/MicroData/properties-collection-nameditem-test.html
     11
     12        * bindings/scripts/CodeGeneratorJS.pm: Modified code generator to generate
     13        JS bindings code for HTMLPropertiesCollection [NamedGetter] property.
     14        (GenerateImplementation):
     15        * html/HTMLPropertiesCollection.cpp:
     16        (WebCore::HTMLPropertiesCollection::names):
     17        (WebCore):
     18        (WebCore::HTMLPropertiesCollection::namedItem): Returns a NodeList object
     19        containing any elements that add a property named name.
     20        (WebCore::HTMLPropertiesCollection::hasNamedItem): Checks if the items can
     21        be retrieved or not based on the property named name.
     22        * html/HTMLPropertiesCollection.h: Added namedItem(), hasProperty(),
     23        hasNamedItem() methods.
     24        (HTMLPropertiesCollection):
     25        * html/HTMLPropertiesCollection.idl: Added namedItem() IDL method.
     26
    1272012-02-28  Kinuko Yasuda  <kinuko@chromium.org>
    228
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r109029 r109200  
    22252225    }
    22262226
     2227    if ($interfaceName eq "HTMLPropertiesCollection") {
     2228        if ($dataNode->extendedAttributes->{"NamedGetter"}) {
     2229            push(@implContent, "bool ${className}::canGetItemsForName(ExecState*, $implClassName* collection, const Identifier& propertyName)\n");
     2230            push(@implContent, "{\n");
     2231            push(@implContent, "    return collection->hasNamedItem(identifierToAtomicString(propertyName));\n");
     2232            push(@implContent, "}\n\n");
     2233            push(@implContent, "JSValue ${className}::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)\n");
     2234            push(@implContent, "{\n");
     2235            push(@implContent, "    ${className}* thisObj = static_cast<$className*>(asObject(slotBase));\n");
     2236            push(@implContent, "    return toJS(exec, thisObj->globalObject(), static_cast<$implClassName*>(thisObj->impl())->namedItem(identifierToAtomicString(propertyName)));\n");
     2237            push(@implContent, "}\n\n");
     2238        }
     2239    }
     2240
    22272241    if ((!$hasParent && !$dataNode->extendedAttributes->{"JSCustomIsReachable"})|| $dataNode->extendedAttributes->{"JSGenerateIsReachable"} || $dataNode->extendedAttributes->{"ActiveDOMObject"}) {
    22282242        push(@implContent, "static inline bool isObservable(JS${implClassName}* js${implClassName})\n");
  • trunk/Source/WebCore/html/HTMLPropertiesCollection.cpp

    r105655 r109200  
    4040#include "HTMLNames.h"
    4141#include "Node.h"
     42#include "StaticNodeList.h"
    4243
    4344namespace WebCore {
     
    173174}
    174175
     176PassRefPtr<NodeList> HTMLPropertiesCollection::namedItem(const String& name) const
     177{
     178    if (!base()->isHTMLElement() || !toHTMLElement(base())->fastHasAttribute(itemscopeAttr))
     179      return 0;
     180
     181    m_properties.clear();
     182    Vector<RefPtr<Node> > namedItems;
     183    findPropetiesOfAnItem(base());
     184
     185    std::sort(m_properties.begin(), m_properties.end(), compareTreeOrder);
     186
     187    // For each item properties, split the value of that itemprop attribute on spaces.
     188    // Add element to namedItem that contains a property named name, with the order preserved.
     189    for (size_t i = 0; i < m_properties.size(); ++i) {
     190        DOMSettableTokenList* itemProperty = m_properties[i]->itemProp();
     191        if (itemProperty->tokens().contains(name))
     192            namedItems.append(m_properties[i]);
     193    }
     194
     195    // FIXME: HTML5 specifies that this should return PropertyNodeList.
     196    return namedItems.isEmpty() ? 0 : StaticNodeList::adopt(namedItems);
     197}
     198
     199bool HTMLPropertiesCollection::hasNamedItem(const AtomicString& name) const
     200{
     201    if (!base()->isHTMLElement() || !toHTMLElement(base())->fastHasAttribute(itemscopeAttr))
     202        return false;
     203
     204    m_properties.clear();
     205    findPropetiesOfAnItem(base());
     206
     207    // For each item properties, split the value of that itemprop attribute on spaces.
     208    // Return true if element contains a property named name.
     209    for (size_t i = 0; i < m_properties.size(); ++i) {
     210        DOMSettableTokenList* itemProperty = m_properties[i]->itemProp();
     211        if (itemProperty->tokens().contains(name))
     212            return true;
     213    }
     214
     215    return false;
     216}
     217
    175218} // namespace WebCore
    176219
  • trunk/Source/WebCore/html/HTMLPropertiesCollection.h

    r105655 r109200  
    5151    PassRefPtr<DOMStringList> names() const;
    5252
     53    PassRefPtr<NodeList> namedItem(const String&) const;
     54    bool hasNamedItem(const AtomicString&) const;
     55
    5356private:
    5457    HTMLPropertiesCollection(Node*);
    5558
    5659    void findPropetiesOfAnItem(Node* current) const;
     60    void getNamedItems(Vector<RefPtr<Node> >&, const String&) const;
    5761
    5862    mutable Vector<Node*> m_properties;
  • trunk/Source/WebCore/html/HTMLPropertiesCollection.idl

    r106798 r109200  
    3333    interface [
    3434        Conditional=MICRODATA,
    35         IndexedGetter
     35        IndexedGetter,
     36        NamedGetter
    3637    ] HTMLPropertiesCollection : HTMLCollection {
    3738        readonly attribute unsigned long length;
     
    4041        readonly attribute DOMStringList names;
    4142
    42         // FIXME: override inherited namedItem()
     43        // FIXME: HTML5 specifies that this should return PropertyNodeList.
     44        NodeList namedItem(in DOMString name);
    4345    };
    4446}
Note: See TracChangeset for help on using the changeset viewer.