Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / HTMLNameCollection.cpp
index 0706e81..47f681d 100644 (file)
 #include "core/dom/Element.h"
 #include "core/dom/ElementTraversal.h"
 #include "core/dom/NodeRareData.h"
+#include "core/html/HTMLEmbedElement.h"
+#include "core/html/HTMLObjectElement.h"
 
 namespace WebCore {
 
 using namespace HTMLNames;
 
-HTMLNameCollection::HTMLNameCollection(Node* document, CollectionType type, const AtomicString& name)
+HTMLNameCollection::HTMLNameCollection(ContainerNode* document, CollectionType type, const AtomicString& name)
     : HTMLCollection(document, type, OverridesItemAfter)
     , m_name(name)
 {
@@ -44,21 +46,20 @@ HTMLNameCollection::~HTMLNameCollection()
     ASSERT(ownerNode()->isDocumentNode());
     ASSERT(type() == WindowNamedItems || type() == DocumentNamedItems);
 
-    ownerNode()->nodeLists()->removeCacheWithAtomicName(this, type(), m_name);
+    ownerNode()->nodeLists()->removeCache(this, type(), m_name);
 }
 
-Element* HTMLNameCollection::virtualItemAfter(unsigned& offsetInArray, Element* previous) const
+Element* HTMLNameCollection::virtualItemAfter(Element* previous) const
 {
-    ASSERT_UNUSED(offsetInArray, !offsetInArray);
     ASSERT(previous != ownerNode());
 
     Element* current;
     if (!previous)
-        current = ElementTraversal::firstWithin(ownerNode());
+        current = ElementTraversal::firstWithin(*ownerNode());
     else
-        current = ElementTraversal::next(previous, ownerNode());
+        current = ElementTraversal::next(*previous, ownerNode());
 
-    for (; current; current = ElementTraversal::next(current, ownerNode())) {
+    for (; current; current = ElementTraversal::next(*current, ownerNode())) {
         switch (type()) {
         case WindowNamedItems:
             // find only images, forms, applets, embeds and objects by name,
@@ -78,10 +79,13 @@ Element* HTMLNameCollection::virtualItemAfter(unsigned& offsetInArray, Element*
             // find images, forms, applets, embeds, objects and iframes by name,
             // applets and object by id, and images by id but only if they have
             // a name attribute (this very strange rule matches IE)
-            if (current->hasTagName(formTag) || current->hasTagName(embedTag) || current->hasTagName(iframeTag)) {
+            if (current->hasTagName(formTag)
+                || current->hasTagName(iframeTag)
+                || (current->hasTagName(embedTag) && toHTMLEmbedElement(current)->isExposed())) {
                 if (current->getNameAttribute() == m_name)
                     return current;
-            } else if (current->hasTagName(appletTag) || current->hasTagName(objectTag)) {
+            } else if (current->hasTagName(appletTag)
+                || (current->hasTagName(objectTag) && toHTMLObjectElement(current)->isExposed())) {
                 if (current->getNameAttribute() == m_name || current->getIdAttribute() == m_name)
                     return current;
             } else if (current->hasTagName(imgTag)) {