diff options
author | Steve Block <steveblock@google.com> | 2009-10-08 17:19:54 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2009-10-20 00:41:58 +0100 |
commit | 231d4e3152a9c27a73b6ac7badbe6be673aa3ddf (patch) | |
tree | a6c7e2d6cd7bfa7011cc39abbb436142d7a4a7c8 /WebCore/inspector/front-end/treeoutline.js | |
parent | e196732677050bd463301566a68a643b6d14b907 (diff) | |
download | external_webkit-231d4e3152a9c27a73b6ac7badbe6be673aa3ddf.zip external_webkit-231d4e3152a9c27a73b6ac7badbe6be673aa3ddf.tar.gz external_webkit-231d4e3152a9c27a73b6ac7badbe6be673aa3ddf.tar.bz2 |
Merge webkit.org at R49305 : Automatic merge by git.
Change-Id: I8968561bc1bfd72b8923b7118d3728579c6dbcc7
Diffstat (limited to 'WebCore/inspector/front-end/treeoutline.js')
-rw-r--r-- | WebCore/inspector/front-end/treeoutline.js | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/WebCore/inspector/front-end/treeoutline.js b/WebCore/inspector/front-end/treeoutline.js index 579e7fb..ecc322b 100644 --- a/WebCore/inspector/front-end/treeoutline.js +++ b/WebCore/inspector/front-end/treeoutline.js @@ -249,35 +249,40 @@ TreeOutline.prototype._forgetChildrenRecursive = function(parentElement) } } -TreeOutline.prototype.findTreeElement = function(representedObject, isAncestor, getParent, equal) +TreeOutline.prototype.getCachedTreeElement = function(representedObject) { if (!representedObject) return null; - if (!equal) - equal = function(a, b) { return a === b }; - if ("__treeElementIdentifier" in representedObject) { // If this representedObject has a tree element identifier, and it is a known TreeElement // in our tree we can just return that tree element. var elements = this._knownTreeElements[representedObject.__treeElementIdentifier]; if (elements) { for (var i = 0; i < elements.length; ++i) - if (equal(elements[i].representedObject, representedObject)) + if (elements[i].representedObject === representedObject) return elements[i]; } } + return null; +} - if (!isAncestor || !(isAncestor instanceof Function) || !getParent || !(getParent instanceof Function)) +TreeOutline.prototype.findTreeElement = function(representedObject, isAncestor, getParent) +{ + if (!representedObject) return null; + var cachedElement = this.getCachedTreeElement(representedObject); + if (cachedElement) + return cachedElement; + // The representedObject isn't know, so we start at the top of the tree and work down to find the first // tree element that represents representedObject or one of its ancestors. var item; var found = false; for (var i = 0; i < this.children.length; ++i) { item = this.children[i]; - if (equal(item.representedObject, representedObject) || isAncestor(item.representedObject, representedObject)) { + if (item.representedObject === representedObject || isAncestor(item.representedObject, representedObject)) { found = true; break; } @@ -292,7 +297,7 @@ TreeOutline.prototype.findTreeElement = function(representedObject, isAncestor, var currentObject = representedObject; while (currentObject) { ancestors.unshift(currentObject); - if (equal(currentObject, item.representedObject)) + if (currentObject === item.representedObject) break; currentObject = getParent(currentObject); } @@ -301,18 +306,16 @@ TreeOutline.prototype.findTreeElement = function(representedObject, isAncestor, for (var i = 0; i < ancestors.length; ++i) { // Make sure we don't call findTreeElement with the same representedObject // again, to prevent infinite recursion. - if (equal(ancestors[i], representedObject)) + if (ancestors[i] === representedObject) continue; // FIXME: we could do something faster than findTreeElement since we will know the next // ancestor exists in the tree. - item = this.findTreeElement(ancestors[i], isAncestor, getParent, equal); + item = this.findTreeElement(ancestors[i], isAncestor, getParent); if (item && item.onpopulate) item.onpopulate(item); } - // Now that all the ancestors are populated, try to find the representedObject again. This time - // without the isAncestor and getParent functions to prevent an infinite recursion if it isn't found. - return this.findTreeElement(representedObject, null, null, equal); + return this.getCachedTreeElement(representedObject); } TreeOutline.prototype.treeElementFromPoint = function(x, y) |