Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / HTMLFormControlsCollection.cpp
index 6212683..6b2a290 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010, 2011, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2014 Samsung Electronics. 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 "core/html/HTMLFormControlsCollection.h"
 
 #include "HTMLNames.h"
+#include "core/frame/UseCounter.h"
 #include "core/html/HTMLFieldSetElement.h"
 #include "core/html/HTMLFormElement.h"
 #include "core/html/HTMLImageElement.h"
+#include "wtf/HashSet.h"
 
 namespace WebCore {
 
@@ -101,9 +104,9 @@ Element* HTMLFormControlsCollection::virtualItemAfter(Element* previous) const
     return 0;
 }
 
-void HTMLFormControlsCollection::invalidateCache() const
+void HTMLFormControlsCollection::invalidateCache(Document* oldDocument) const
 {
-    HTMLCollection::invalidateCache();
+    HTMLCollection::invalidateCache(oldDocument);
     m_cachedElement = 0;
     m_cachedElementOffsetInArray = 0;
 }
@@ -124,14 +127,16 @@ static HTMLElement* firstNamedItem(const Vector<FormAssociatedElement*>& element
 
     for (unsigned i = 0; i < imageElementsArray->size(); ++i) {
         HTMLImageElement* element = (*imageElementsArray)[i];
-        if (element->fastGetAttribute(attrName) == name)
+        if (element->fastGetAttribute(attrName) == name) {
+            UseCounter::count(element->document(), UseCounter::FormNameAccessForImageElement);
             return element;
+        }
     }
 
     return 0;
 }
 
-Node* HTMLFormControlsCollection::namedItem(const AtomicString& name) const
+Element* HTMLFormControlsCollection::namedItem(const AtomicString& name) const
 {
     // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/nameditem.asp
     // This method first searches for an object with a matching id
@@ -145,9 +150,9 @@ Node* HTMLFormControlsCollection::namedItem(const AtomicString& name) const
     return firstNamedItem(formControlElements(), imagesElements, nameAttr, name);
 }
 
-void HTMLFormControlsCollection::updateNameCache() const
+void HTMLFormControlsCollection::updateIdNameCache() const
 {
-    if (hasNameCache())
+    if (hasValidIdNameCache())
         return;
 
     HashSet<StringImpl*> foundInputElements;
@@ -184,25 +189,52 @@ void HTMLFormControlsCollection::updateNameCache() const
         }
     }
 
-    setHasNameCache();
+    setHasValidIdNameCache();
 }
 
-void HTMLFormControlsCollection::namedGetter(const AtomicString& name, bool& returnValue0Enabled, RefPtr<RadioNodeList>& returnValue0, bool& returnValue1Enabled, RefPtr<Node>& returnValue1)
+void HTMLFormControlsCollection::namedGetter(const AtomicString& name, bool& radioNodeListEnabled, RefPtr<RadioNodeList>& radioNodeList, bool& elementEnabled, RefPtr<Element>& element)
 {
-    Vector<RefPtr<Node> > namedItems;
+    Vector<RefPtr<Element> > namedItems;
     this->namedItems(name, namedItems);
 
-    if (!namedItems.size())
+    if (namedItems.isEmpty())
         return;
 
     if (namedItems.size() == 1) {
-        returnValue1Enabled = true;
-        returnValue1 = namedItems.at(0);
+        elementEnabled = true;
+        element = namedItems.first();
         return;
     }
 
-    returnValue0Enabled = true;
-    returnValue0 = this->ownerNode()->radioNodeList(name);
+    radioNodeListEnabled = true;
+    radioNodeList = ownerNode()->radioNodeList(name);
+}
+
+void HTMLFormControlsCollection::supportedPropertyNames(Vector<String>& names)
+{
+    // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#htmlformcontrolscollection-0:
+    // The supported property names consist of the non-empty values of all the id and name attributes
+    // of all the elements represented by the collection, in tree order, ignoring later duplicates,
+    // with the id of an element preceding its name if it contributes both, they differ from each
+    // other, and neither is the duplicate of an earlier entry.
+    HashSet<AtomicString> existingNames;
+    unsigned length = this->length();
+    for (unsigned i = 0; i < length; ++i) {
+        Element* element = item(i);
+        ASSERT(element);
+        const AtomicString& idAttribute = element->getIdAttribute();
+        if (!idAttribute.isEmpty()) {
+            HashSet<AtomicString>::AddResult addResult = existingNames.add(idAttribute);
+            if (addResult.isNewEntry)
+                names.append(idAttribute);
+        }
+        const AtomicString& nameAttribute = element->getNameAttribute();
+        if (!nameAttribute.isEmpty()) {
+            HashSet<AtomicString>::AddResult addResult = existingNames.add(nameAttribute);
+            if (addResult.isNewEntry)
+                names.append(nameAttribute);
+        }
+    }
 }
 
 }