| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 this.hasChildren = false; | 44 this.hasChildren = false; |
| 45 this.expanded = true; | 45 this.expanded = true; |
| 46 this.selected = false; | 46 this.selected = false; |
| 47 this.treeOutline = this; | 47 this.treeOutline = this; |
| 48 /** @type {function(TreeElement,TreeElement):number|null} */ | 48 /** @type {function(TreeElement,TreeElement):number|null} */ |
| 49 this.comparator = null; | 49 this.comparator = null; |
| 50 | 50 |
| 51 this.setFocusable(!nonFocusable); | 51 this.setFocusable(!nonFocusable); |
| 52 this._childrenListNode.addEventListener("keydown", this._treeKeyDown.bind(th
is), true); | 52 this._childrenListNode.addEventListener("keydown", this._treeKeyDown.bind(th
is), true); |
| 53 | 53 |
| 54 /** @type {!Map.<Object, !Array.<!TreeElement>>} */ | 54 /** @type {!Map.<!Object, !Array.<!TreeElement>>} */ |
| 55 this._treeElementsMap = new Map(); | 55 this._treeElementsMap = new Map(); |
| 56 /** @type {!Map.<Object, boolean>} */ | 56 /** @type {!Map.<!Object, boolean>} */ |
| 57 this._expandedStateMap = new Map(); | 57 this._expandedStateMap = new Map(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 TreeOutline.prototype.setFocusable = function(focusable) | 60 TreeOutline.prototype.setFocusable = function(focusable) |
| 61 { | 61 { |
| 62 if (focusable) | 62 if (focusable) |
| 63 this._childrenListNode.setAttribute("tabIndex", 0); | 63 this._childrenListNode.setAttribute("tabIndex", 0); |
| 64 else | 64 else |
| 65 this._childrenListNode.removeAttribute("tabIndex"); | 65 this._childrenListNode.removeAttribute("tabIndex"); |
| 66 } | 66 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 */ | 258 */ |
| 259 TreeOutline.prototype._forgetChildrenRecursive = function(parentElement) | 259 TreeOutline.prototype._forgetChildrenRecursive = function(parentElement) |
| 260 { | 260 { |
| 261 var child = parentElement.children[0]; | 261 var child = parentElement.children[0]; |
| 262 while (child) { | 262 while (child) { |
| 263 this._forgetTreeElement(child); | 263 this._forgetTreeElement(child); |
| 264 child = child.traverseNextTreeElement(false, parentElement, true); | 264 child = child.traverseNextTreeElement(false, parentElement, true); |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 | 267 |
| 268 /** |
| 269 * @param {Object} representedObject |
| 270 * @return {TreeElement} |
| 271 */ |
| 268 TreeOutline.prototype.getCachedTreeElement = function(representedObject) | 272 TreeOutline.prototype.getCachedTreeElement = function(representedObject) |
| 269 { | 273 { |
| 270 if (!representedObject) | 274 if (!representedObject) |
| 271 return null; | 275 return null; |
| 272 | 276 |
| 273 var elements = this._treeElementsMap.get(representedObject); | 277 var elements = this._treeElementsMap.get(representedObject); |
| 274 if (elements && elements.length) | 278 if (elements && elements.length) |
| 275 return elements[0]; | 279 return elements[0]; |
| 276 return null; | 280 return null; |
| 277 } | 281 } |
| 278 | 282 |
| 283 /** |
| 284 * @param {Object} representedObject |
| 285 * @return {TreeElement} |
| 286 */ |
| 279 TreeOutline.prototype.findTreeElement = function(representedObject, isAncestor,
getParent) | 287 TreeOutline.prototype.findTreeElement = function(representedObject, isAncestor,
getParent) |
| 280 { | 288 { |
| 281 if (!representedObject) | 289 if (!representedObject) |
| 282 return null; | 290 return null; |
| 283 | 291 |
| 284 var cachedElement = this.getCachedTreeElement(representedObject); | 292 var cachedElement = this.getCachedTreeElement(representedObject); |
| 285 if (cachedElement) | 293 if (cachedElement) |
| 286 return cachedElement; | 294 return cachedElement; |
| 287 | 295 |
| 288 // Walk up the parent pointers from the desired representedObject | 296 // Walk up the parent pointers from the desired representedObject |
| (...skipping 10 matching lines...) Expand all Loading... |
| 299 // Walk down to populate each ancestor's children, to fill in the tree and t
he cache. | 307 // Walk down to populate each ancestor's children, to fill in the tree and t
he cache. |
| 300 for (var i = ancestors.length - 1; i >= 0; --i) { | 308 for (var i = ancestors.length - 1; i >= 0; --i) { |
| 301 var treeElement = this.getCachedTreeElement(ancestors[i]); | 309 var treeElement = this.getCachedTreeElement(ancestors[i]); |
| 302 if (treeElement) | 310 if (treeElement) |
| 303 treeElement.onpopulate(); // fill the cache with the children of tr
eeElement | 311 treeElement.onpopulate(); // fill the cache with the children of tr
eeElement |
| 304 } | 312 } |
| 305 | 313 |
| 306 return this.getCachedTreeElement(representedObject); | 314 return this.getCachedTreeElement(representedObject); |
| 307 } | 315 } |
| 308 | 316 |
| 317 /** |
| 318 * @param {number} x |
| 319 * @param {number} y |
| 320 * @return {TreeElement} |
| 321 */ |
| 309 TreeOutline.prototype.treeElementFromPoint = function(x, y) | 322 TreeOutline.prototype.treeElementFromPoint = function(x, y) |
| 310 { | 323 { |
| 311 var node = this._childrenListNode.ownerDocument.elementFromPoint(x, y); | 324 var node = this._childrenListNode.ownerDocument.elementFromPoint(x, y); |
| 312 if (!node) | 325 if (!node) |
| 313 return null; | 326 return null; |
| 314 | 327 |
| 315 var listNode = node.enclosingNodeOrSelfWithNodeNameInArray(["ol", "li"]); | 328 var listNode = node.enclosingNodeOrSelfWithNodeNameInArray(["ol", "li"]); |
| 316 if (listNode) | 329 if (listNode) |
| 317 return listNode.parentTreeElement || listNode.treeElement; | 330 return listNode.parentTreeElement || listNode.treeElement; |
| 318 return null; | 331 return null; |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 } | 938 } |
| 926 | 939 |
| 927 TreeElement.prototype.isEventWithinDisclosureTriangle = function(event) | 940 TreeElement.prototype.isEventWithinDisclosureTriangle = function(event) |
| 928 { | 941 { |
| 929 // FIXME: We should not use getComputedStyle(). For that we need to get rid
of using ::before for disclosure triangle. (http://webk.it/74446) | 942 // FIXME: We should not use getComputedStyle(). For that we need to get rid
of using ::before for disclosure triangle. (http://webk.it/74446) |
| 930 var paddingLeftValue = window.getComputedStyle(this._listItemNode).getProper
tyCSSValue("padding-left"); | 943 var paddingLeftValue = window.getComputedStyle(this._listItemNode).getProper
tyCSSValue("padding-left"); |
| 931 var computedLeftPadding = paddingLeftValue ? paddingLeftValue.getFloatValue(
CSSPrimitiveValue.CSS_PX) : 0; | 944 var computedLeftPadding = paddingLeftValue ? paddingLeftValue.getFloatValue(
CSSPrimitiveValue.CSS_PX) : 0; |
| 932 var left = this._listItemNode.totalOffsetLeft() + computedLeftPadding; | 945 var left = this._listItemNode.totalOffsetLeft() + computedLeftPadding; |
| 933 return event.pageX >= left && event.pageX <= left + this.arrowToggleWidth &&
this.hasChildren; | 946 return event.pageX >= left && event.pageX <= left + this.arrowToggleWidth &&
this.hasChildren; |
| 934 } | 947 } |
| OLD | NEW |