Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(798)

Unified Diff: Source/core/html/HTMLAllCollection.cpp

Issue 158563004: Make HTMLAllCollection named property getter behave more according to spec (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix linking error Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLAllCollection.h ('k') | Source/core/html/HTMLAllCollection.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLAllCollection.cpp
diff --git a/Source/core/html/HTMLAllCollection.cpp b/Source/core/html/HTMLAllCollection.cpp
index dfbc4661c25779369797a710732d05c58175c6a4..c2e83aafac09e28f18e1005c1abca222dea4be7d 100644
--- a/Source/core/html/HTMLAllCollection.cpp
+++ b/Source/core/html/HTMLAllCollection.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2009, 2011, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2014 Samsung Electronics. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,11 +27,16 @@
#include "config.h"
#include "core/html/HTMLAllCollection.h"
+#include "HTMLNames.h"
#include "core/dom/Element.h"
#include "core/dom/NamedNodesCollection.h"
+#include "core/html/HTMLElement.h"
+#include "wtf/HashSet.h"
namespace WebCore {
+using namespace HTMLNames;
+
PassRefPtr<HTMLAllCollection> HTMLAllCollection::create(ContainerNode* node, CollectionType type)
{
return adoptRef(new HTMLAllCollection(node, type));
@@ -42,6 +48,52 @@ HTMLAllCollection::HTMLAllCollection(ContainerNode* node, CollectionType type)
ScriptWrappable::init(this);
}
+bool HTMLAllCollection::elementNameShouldBeVisible(const HTMLElement& element)
+{
+ // The document.all collection returns only certain types of elements by name,
+ // although it returns any type of element by id.
+ return element.hasLocalName(aTag)
+ || element.hasLocalName(appletTag)
+ || element.hasLocalName(areaTag)
+ || element.hasLocalName(embedTag)
+ || element.hasLocalName(formTag)
+ || element.hasLocalName(frameTag)
+ || element.hasLocalName(framesetTag)
+ || element.hasLocalName(iframeTag)
+ || element.hasLocalName(imgTag)
+ || element.hasLocalName(objectTag)
+ || element.hasLocalName(inputTag) // FIXME: Not according to spec.
arv (Not doing code reviews) 2014/02/11 20:48:42 If IE11 behaves this way we should get the spec ch
Inactive 2014/02/11 20:50:37 Yes, based on my testing IE11 return the names of
Inactive 2014/02/11 20:55:10 http://jsfiddle.net/jAx2t/3/
Inactive 2014/02/11 21:02:39 I filed a bug against the spec: https://www.w3.org
Inactive 2014/02/12 01:32:37 Would you like me to remove those 2 FIXME comments
+ || element.hasLocalName(selectTag); // FIXME: Not according to spec.
+}
+
+void HTMLAllCollection::supportedPropertyNames(Vector<String>& names)
+{
+ // As per the specification (http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#htmlallcollection-0):
+ // The supported property names consist of the non-empty values of all the id attributes of all the elements
+ // represented by the collection, and the non-empty values of all the name attributes of all the a, applet,
+ // area, embed, form, frame, frameset, iframe, img, and object 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;
+ ContainerNode& root = rootNode();
+ for (Element* element = traverseToFirstElement(root); element; element = traverseNextElement(*element, root)) {
haraken 2014/02/12 01:23:01 We're duplicating this code in several files. It s
Inactive 2014/02/12 01:31:05 If it was just about the condition, I would have s
Inactive 2014/02/12 16:28:41 I am updating the id/name order in HTMLCollection
+ const AtomicString& idAttribute = element->getIdAttribute();
+ if (!idAttribute.isEmpty()) {
+ HashSet<AtomicString>::AddResult addResult = existingNames.add(idAttribute);
+ if (addResult.isNewEntry)
+ names.append(idAttribute);
+ }
+ if (!element->isHTMLElement())
+ continue;
+ const AtomicString& nameAttribute = element->getNameAttribute();
+ if (!nameAttribute.isEmpty() && elementNameShouldBeVisible(toHTMLElement(*element))) {
+ HashSet<AtomicString>::AddResult addResult = existingNames.add(nameAttribute);
+ if (addResult.isNewEntry)
+ names.append(nameAttribute);
+ }
+ }
+}
+
HTMLAllCollection::~HTMLAllCollection()
{
}
@@ -64,7 +116,7 @@ Element* HTMLAllCollection::namedItemWithIndex(const AtomicString& name, unsigne
return 0;
}
-void HTMLAllCollection::anonymousNamedGetter(const AtomicString& name, bool& returnValue0Enabled, RefPtr<NodeList>& returnValue0, bool& returnValue1Enabled, RefPtr<Element>& returnValue1)
+void HTMLAllCollection::namedGetter(const AtomicString& name, bool& returnValue0Enabled, RefPtr<NodeList>& returnValue0, bool& returnValue1Enabled, RefPtr<Element>& returnValue1)
{
Vector<RefPtr<Element> > namedItems;
this->namedItems(name, namedItems);
« no previous file with comments | « Source/core/html/HTMLAllCollection.h ('k') | Source/core/html/HTMLAllCollection.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698