Remember the expanded state of objects in the Scope Variables pane when stepping.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jun 2008 22:32:56 +0000 (22:32 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jun 2008 22:32:56 +0000 (22:32 +0000)
        https://bugs.webkit.org/show_bug.cgi?id=19584

        Reviewed by Adam Roben.

        * page/inspector/ObjectPropertiesSection.js:
        (WebInspector.ObjectPropertiesSection): Add an optional argument
        that is the treeElementConstructor to use when making TreeElements.
        (WebInspector.ObjectPropertiesSection.prototype.onpopulate): Use
        the treeElementConstructor to create TreeElements.
        (WebInspector.ObjectPropertyTreeElement.prototype.onpopulate): Use
        the treeElementConstructor to create TreeElements.
        * page/inspector/ScopeChainSidebarPane.js:
        (WebInspector.ScopeChainSidebarPane.prototype.update): Create an
        _expandedProperties object on the callframe if one doesn't exist yet.
        Pass WebInspector.ScopeVariableTreeElement to the ObjectPropertiesSection
        as the TreeElement constructor we want to use.
        (WebInspector.ScopeVariableTreeElement): Added.
        (WebInspector.ScopeVariableTreeElement.prototype.onattach): Expand if the
        propertyIdentifier is in the pane's _expandedProperties.
        (WebInspector.ScopeVariableTreeElement.prototype.onexpand): Add the
        propertyIdentifier to the pane's _expandedProperties.
        (WebInspector.ScopeVariableTreeElement.prototype.oncollapse): Remove the
        propertyIdentifier from the pane's _expandedProperties.
        (WebInspector.ScopeVariableTreeElement.prototype.get propertyIdentifier):
        Return an identifier that has the section title, subtile and propertyPath concatenated.
        (WebInspector.ScopeVariableTreeElement.prototype.get propertyPath): Return a string
        that has the propertyNames up to the root ancestor concatenated with a period.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@34633 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/page/inspector/ObjectPropertiesSection.js
WebCore/page/inspector/ScopeChainSidebarPane.js

index 6c69d88..487fa94 100644 (file)
@@ -1,5 +1,36 @@
 2008-06-17  Timothy Hatcher  <timothy@apple.com>
 
+        Remember the expanded state of objects in the Scope Variables pane when stepping.
+        https://bugs.webkit.org/show_bug.cgi?id=19584
+
+        Reviewed by Adam Roben.
+
+        * page/inspector/ObjectPropertiesSection.js:
+        (WebInspector.ObjectPropertiesSection): Add an optional argument
+        that is the treeElementConstructor to use when making TreeElements.
+        (WebInspector.ObjectPropertiesSection.prototype.onpopulate): Use
+        the treeElementConstructor to create TreeElements.
+        (WebInspector.ObjectPropertyTreeElement.prototype.onpopulate): Use
+        the treeElementConstructor to create TreeElements.
+        * page/inspector/ScopeChainSidebarPane.js:
+        (WebInspector.ScopeChainSidebarPane.prototype.update): Create an
+        _expandedProperties object on the callframe if one doesn't exist yet.
+        Pass WebInspector.ScopeVariableTreeElement to the ObjectPropertiesSection
+        as the TreeElement constructor we want to use.
+        (WebInspector.ScopeVariableTreeElement): Added.
+        (WebInspector.ScopeVariableTreeElement.prototype.onattach): Expand if the
+        propertyIdentifier is in the pane's _expandedProperties.
+        (WebInspector.ScopeVariableTreeElement.prototype.onexpand): Add the
+        propertyIdentifier to the pane's _expandedProperties.
+        (WebInspector.ScopeVariableTreeElement.prototype.oncollapse): Remove the
+        propertyIdentifier from the pane's _expandedProperties.
+        (WebInspector.ScopeVariableTreeElement.prototype.get propertyIdentifier):
+        Return an identifier that has the section title, subtile and propertyPath concatenated.
+        (WebInspector.ScopeVariableTreeElement.prototype.get propertyPath): Return a string
+        that has the propertyNames up to the root ancestor concatenated with a period.
+
+2008-06-17  Timothy Hatcher  <timothy@apple.com>
+
         Focus the mainPanelsElement in a timeout so it happens after the
         initial focus, so it doesn't get reset to the first toolbar button.
         This initial focus happens on Mac when the window is made key and
index 5736126..7f2cecf 100644 (file)
@@ -23,7 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-WebInspector.ObjectPropertiesSection = function(object, title, subtitle, emptyPlaceholder, ignoreHasOwnProperty, extraProperties)
+WebInspector.ObjectPropertiesSection = function(object, title, subtitle, emptyPlaceholder, ignoreHasOwnProperty, extraProperties, treeElementConstructor)
 {
     if (!title) {
         title = Object.describe(object);
@@ -38,6 +38,7 @@ WebInspector.ObjectPropertiesSection = function(object, title, subtitle, emptyPl
     this.object = object;
     this.ignoreHasOwnProperty = ignoreHasOwnProperty;
     this.extraProperties = extraProperties;
+    this.treeElementConstructor = treeElementConstructor || WebInspector.ObjectPropertyTreeElement;
 
     WebInspector.PropertiesSection.call(this, title, subtitle);
 }
@@ -62,7 +63,7 @@ WebInspector.ObjectPropertiesSection.prototype = {
                 continue;
             if (!this.ignoreHasOwnProperty && "hasOwnProperty" in object && !object.hasOwnProperty(propertyName))
                 continue;
-            this.propertiesTreeOutline.appendChild(new WebInspector.ObjectPropertyTreeElement(object, propertyName));
+            this.propertiesTreeOutline.appendChild(new this.treeElementConstructor(object, propertyName));
         }
 
         if (!this.propertiesTreeOutline.children.length) {
@@ -123,7 +124,7 @@ WebInspector.ObjectPropertyTreeElement.prototype = {
             var propertyName = properties[i];
             if (propertyName === "__treeElementIdentifier")
                 continue;
-            this.appendChild(new WebInspector.ObjectPropertyTreeElement(childObject, propertyName));
+            this.appendChild(new this.treeOutline.section.treeElementConstructor(childObject, propertyName));
         }
     }
 }
index d7a4c1a..f2c4ccb 100644 (file)
@@ -34,6 +34,7 @@ WebInspector.ScopeChainSidebarPane.prototype = {
         this.bodyElement.removeChildren();
 
         this.sections = [];
+        this.callFrame = callFrame;
 
         if (!callFrame) {
             var infoElement = document.createElement("div");
@@ -43,6 +44,15 @@ WebInspector.ScopeChainSidebarPane.prototype = {
             return;
         }
 
+        if (!callFrame._expandedProperties) {
+            // FIXME: fix this when https://bugs.webkit.org/show_bug.cgi?id=19410 is fixed.
+            // The callFrame is a JSInspectedObjectWrapper, so we are not allowed to assign
+            // an object created in the Inspector's context to that object. So create an
+            // Object from the inspectedWindow.
+            var inspectedWindow = InspectorController.inspectedWindow();
+            callFrame._expandedProperties = new inspectedWindow.Object;
+        }
+
         var foundLocalScope = false;
         var scopeChain = callFrame.scopeChain;
         for (var i = 0; i < scopeChain.length; ++i) {
@@ -75,7 +85,9 @@ WebInspector.ScopeChainSidebarPane.prototype = {
             if (!title || title === subtitle)
                 subtitle = null;
 
-            var section = new WebInspector.ObjectPropertiesSection(scopeObject, title, subtitle, emptyPlaceholder, true, extraProperties);
+            var section = new WebInspector.ObjectPropertiesSection(scopeObject, title, subtitle, emptyPlaceholder, true, extraProperties, WebInspector.ScopeVariableTreeElement);
+            section.pane = this;
+
             if (!foundLocalScope || localScope)
                 section.expanded = true;
 
@@ -86,3 +98,57 @@ WebInspector.ScopeChainSidebarPane.prototype = {
 }
 
 WebInspector.ScopeChainSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.prototype;
+
+WebInspector.ScopeVariableTreeElement = function(parentObject, propertyName)
+{
+    WebInspector.ObjectPropertyTreeElement.call(this, parentObject, propertyName);
+}
+
+WebInspector.ScopeVariableTreeElement.prototype = {
+    onattach: function()
+    {
+        if (this.hasChildren && this.propertyIdentifier in this.treeOutline.section.pane.callFrame._expandedProperties)
+            this.expand();
+    },
+
+    onexpand: function()
+    {
+        this.treeOutline.section.pane.callFrame._expandedProperties[this.propertyIdentifier] = true;
+    },
+
+    oncollapse: function()
+    {
+        delete this.treeOutline.section.pane.callFrame._expandedProperties[this.propertyIdentifier];
+    },
+
+    get propertyIdentifier()
+    {
+        if ("_propertyIdentifier" in this)
+            return this._propertyIdentifier;
+        var section = this.treeOutline.section;
+        this._propertyIdentifier = section.title + ":" + (section.subtitle ? section.subtitle + ":" : "") + this.propertyPath;
+        return this._propertyIdentifier;
+    },
+
+    get propertyPath()
+    {
+        if ("_propertyPath" in this)
+            return this._propertyPath;
+
+        var current = this;
+        var result;
+
+        do {
+            if (result)
+                result = current.propertyName + "." + result;
+            else
+                result = current.propertyName;
+            current = current.parent;
+        } while (current && !current.root);
+
+        this._propertyPath = result;
+        return result;
+    }
+}
+
+WebInspector.ScopeVariableTreeElement.prototype.__proto__ = WebInspector.ObjectPropertyTreeElement.prototype;