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

Side by Side Diff: Source/core/svg/SVGSVGElement.cpp

Issue 178323002: Simply SVGSVGElement::getElementById method (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: using containsMultipleElementsWithId for single tag use case 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Rob Buis <buis@kde.org>
4 * Copyright (C) 2007 Apple Inc. All rights reserved. 4 * Copyright (C) 2007 Apple Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 if (viewElement->hasAttribute(SVGNames::zoomAndPanAttr)) 760 if (viewElement->hasAttribute(SVGNames::zoomAndPanAttr))
761 view->setZoomAndPan(viewElement->zoomAndPan()); 761 view->setZoomAndPan(viewElement->zoomAndPan());
762 else 762 else
763 view->setZoomAndPan(zoomAndPan()); 763 view->setZoomAndPan(zoomAndPan());
764 } 764 }
765 765
766 // getElementById on SVGSVGElement is restricted to only the child subtree defin ed by the <svg> element. 766 // getElementById on SVGSVGElement is restricted to only the child subtree defin ed by the <svg> element.
767 // See http://www.w3.org/TR/SVG11/struct.html#InterfaceSVGSVGElement 767 // See http://www.w3.org/TR/SVG11/struct.html#InterfaceSVGSVGElement
768 Element* SVGSVGElement::getElementById(const AtomicString& id) const 768 Element* SVGSVGElement::getElementById(const AtomicString& id) const
769 { 769 {
770 Element* element = treeScope().getElementById(id); 770 if (!treeScope().containsMultipleElementsWithId(id)) {
771 if (element && element->isDescendantOf(this)) 771 Element* element = treeScope().getElementById(id);
772 return element; 772 if (element && element->isDescendantOf(this))
773 return element;
774 } else {
Inactive 2014/02/24 22:14:04 you need to return 0 before the else. And then the
775 Vector<Element*> elements = treeScope().getAllElementsById(id);
Inactive 2014/02/24 22:14:04 Should be a const Vector<Element*>& to avoid copyi
776 Vector<Element*>::iterator end = elements.end();
777 for (Vector<Element*>::iterator it = elements.begin(); it != end; ++it) {
778 Element* element = *it;
Inactive 2014/02/24 22:14:04 You don't really need this assignment, you can use
779 if (element->isDescendantOf(this))
780 return element;
781 }
782 }
773 783
774 // Fall back to traversing our subtree. Duplicate ids are allowed, the first found will
775 // be returned.
776 for (Node* node = firstChild(); node; node = NodeTraversal::next(*node, this )) {
777 if (!node->isElementNode())
778 continue;
779
780 Element* element = toElement(node);
781 if (element->getIdAttribute() == id)
782 return element;
783 }
784 return 0; 784 return 0;
785 } 785 }
786 786
787 } 787 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698