Title: [101315] trunk/Source/WebCore
Revision
101315
Author
timo...@apple.com
Date
2011-11-28 18:34:38 -0800 (Mon, 28 Nov 2011)

Log Message

Add support for knowing when a TreeElement is added or changed anywhere in a TreeOutline.

Reviewed by Brian Weinstein.

* inspector/front-end/treeoutline.js:
(TreeOutline.prototype.appendChild): Call onadd if it exists.
(TreeOutline.prototype.insertChild): Ditto.
(TreeOutline.prototype._treeElementDidChange): Added. Call onchange if it exists.
(TreeElement.prototype.set title): Call didChange.
(TreeElement.prototype.set titleHTML): Ditto.
(TreeElement.prototype.set tooltip): Ditto.
(TreeElement.prototype.set hasChildren): Ditto.
(TreeElement.prototype._fireDidChange): Added. Call TreeOutline._treeElementDidChange.
(TreeElement.prototype.didChange): Added. Schedule a timeout for _fireDidChange.
(TreeElement.prototype.expand): Move the code that sets the expanded flag to the beginning
which is before onpopulate. Since onpopulate can add elements and call onadd, this makes
sure the expanded flag is true before calling those functions.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (101314 => 101315)


--- trunk/Source/WebCore/ChangeLog	2011-11-29 02:34:22 UTC (rev 101314)
+++ trunk/Source/WebCore/ChangeLog	2011-11-29 02:34:38 UTC (rev 101315)
@@ -1,5 +1,25 @@
 2011-11-28  Timothy Hatcher  <timo...@apple.com>
 
+        Add support for knowing when a TreeElement is added or changed anywhere in a TreeOutline.
+
+        Reviewed by Brian Weinstein.
+
+        * inspector/front-end/treeoutline.js:
+        (TreeOutline.prototype.appendChild): Call onadd if it exists.
+        (TreeOutline.prototype.insertChild): Ditto.
+        (TreeOutline.prototype._treeElementDidChange): Added. Call onchange if it exists.
+        (TreeElement.prototype.set title): Call didChange.
+        (TreeElement.prototype.set titleHTML): Ditto.
+        (TreeElement.prototype.set tooltip): Ditto.
+        (TreeElement.prototype.set hasChildren): Ditto.
+        (TreeElement.prototype._fireDidChange): Added. Call TreeOutline._treeElementDidChange.
+        (TreeElement.prototype.didChange): Added. Schedule a timeout for _fireDidChange.
+        (TreeElement.prototype.expand): Move the code that sets the expanded flag to the beginning
+        which is before onpopulate. Since onpopulate can add elements and call onadd, this makes
+        sure the expanded flag is true before calling those functions.
+
+2011-11-28  Timothy Hatcher  <timo...@apple.com>
+
         Skip selecting TreeElements that are hidden when keyboard navigating.
 
         We already skipped non-selectable tree elements in the common cases, this just makes selectable

Modified: trunk/Source/WebCore/inspector/front-end/treeoutline.js (101314 => 101315)


--- trunk/Source/WebCore/inspector/front-end/treeoutline.js	2011-11-29 02:34:22 UTC (rev 101314)
+++ trunk/Source/WebCore/inspector/front-end/treeoutline.js	2011-11-29 02:34:38 UTC (rev 101315)
@@ -92,6 +92,9 @@
     }
 
     child._attach();
+
+    if (this.treeOutline.onadd)
+        this.treeOutline.onadd(child);
 }
 
 TreeOutline.prototype.insertChild = function(child, index)
@@ -140,6 +143,9 @@
     }
 
     child._attach();
+
+    if (this.treeOutline.onadd)
+        this.treeOutline.onadd(child);
 }
 
 TreeOutline.prototype.removeChildAtIndex = function(childIndex)
@@ -335,6 +341,15 @@
     return this.getCachedTreeElement(representedObject);
 }
 
+TreeOutline.prototype._treeElementDidChange = function(treeElement)
+{
+    if (treeElement.treeOutline !== this)
+        return;
+
+    if (this.onchange)
+        this.onchange(treeElement);
+}
+
 TreeOutline.prototype.treeElementFromPoint = function(x, y)
 {
     var node = this._childrenListNode.ownerDocument.elementFromPoint(x, y);
@@ -512,6 +527,7 @@
     set title(x) {
         this._title = x;
         this._setListItemNodeContent();
+        this.didChange();
     },
 
     get titleHTML() {
@@ -521,6 +537,7 @@
     set titleHTML(x) {
         this._titleHTML = x;
         this._setListItemNodeContent();
+        this.didChange();
     },
 
     get tooltip() {
@@ -531,6 +548,7 @@
         this._tooltip = x;
         if (this._listItemNode)
             this._listItemNode.title = x ? x : "";
+        this.didChange();
     },
 
     get hasChildren() {
@@ -552,6 +570,8 @@
             this._listItemNode.classList.remove("parent");
             this.collapse();
         }
+
+        this.didChange();
     },
 
     get hidden() {
@@ -587,6 +607,24 @@
             this.expand();
     },
 
+    _fireDidChange: function()
+    {
+        delete this._didChangeTimeoutIdentifier;
+
+        if (this.treeOutline)
+            this.treeOutline._treeElementDidChange(this);
+    },
+
+    didChange: function()
+    {
+        if (!this.treeOutline)
+            return;
+
+        // Prevent telling the TreeOutline multiple times in a row by delaying it with a timeout.
+        if (!this._didChangeTimeoutIdentifier)
+            this._didChangeTimeoutIdentifier = setTimeout(this._fireDidChange.bind(this), 0);
+    },
+
     _setListItemNodeContent: function()
     {
         if (!this._listItemNode)
@@ -741,6 +779,14 @@
     if (!this.hasChildren || (this.expanded && !this._shouldRefreshChildren && this._childrenListNode))
         return;
 
+    // Set this before onpopulate. Since onpopulate can add elements and call onadd, this makes
+    // sure the expanded flag is true before calling those functions. This prevents the possibility
+    // of an infinite loop if onpopulate or onadd were to call expand.
+
+    this.expanded = true;
+    if (this.treeOutline)
+        this.treeOutline._treeElementsExpandedState[this.identifier] = true;
+
     if (this.treeOutline && (!this._childrenListNode || this._shouldRefreshChildren)) {
         if (this._childrenListNode && this._childrenListNode.parentNode)
             this._childrenListNode.parentNode.removeChild(this._childrenListNode);
@@ -769,10 +815,6 @@
     if (this._childrenListNode)
         this._childrenListNode.classList.add("expanded");
 
-    this.expanded = true;
-    if (this.treeOutline)
-        this.treeOutline._treeElementsExpandedState[this.identifier] = true;
-
     if (this.onexpand)
         this.onexpand(this);
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to