Index: Source/core/svg/SVGSVGElement.cpp |
diff --git a/Source/core/svg/SVGSVGElement.cpp b/Source/core/svg/SVGSVGElement.cpp |
index 30cf7fa27e2e365a56436721ca0275a31bc85b6a..c175f07450587cf151bbca14dfe248ac3af957d2 100644 |
--- a/Source/core/svg/SVGSVGElement.cpp |
+++ b/Source/core/svg/SVGSVGElement.cpp |
@@ -767,20 +767,22 @@ void SVGSVGElement::inheritViewAttributes(SVGViewElement* viewElement) |
// See http://www.w3.org/TR/SVG11/struct.html#InterfaceSVGSVGElement |
Element* SVGSVGElement::getElementById(const AtomicString& id) const |
{ |
- Element* element = treeScope().getElementById(id); |
- if (element && element->isDescendantOf(this)) |
- return element; |
+ if (!treeScope().containsMultipleElementsWithId(id)) { |
+ Element* element = treeScope().getElementById(id); |
f(malita)
2014/02/24 23:47:24
Isn't this introducing an extra lookup for the com
|
+ if (!element || !element->isDescendantOf(this)) |
+ return 0; |
- // Fall back to traversing our subtree. Duplicate ids are allowed, the first found will |
- // be returned. |
- for (Node* node = firstChild(); node; node = NodeTraversal::next(*node, this)) { |
- if (!node->isElementNode()) |
- continue; |
+ return element; |
+ } |
- Element* element = toElement(node); |
- if (element->getIdAttribute() == id) |
- return element; |
+ // If duplicate IDs are there, return the first descendant of the svg element. |
+ const Vector<Element*>& elements = treeScope().getAllElementsById(id); |
+ Vector<Element*>::const_iterator end = elements.end(); |
+ for (Vector<Element*>::const_iterator it = elements.begin(); it != end; ++it) { |
+ if ((*it)->isDescendantOf(this)) |
+ return *it; |
} |
+ |
return 0; |
} |