Title: [208337] trunk/Source/WebInspectorUI
Revision
208337
Author
commit-qu...@webkit.org
Date
2016-11-03 11:42:12 -0700 (Thu, 03 Nov 2016)

Log Message

Web Inspector: Modify FolderTreeElement to have a Collection as a its represented object
https://bugs.webkit.org/show_bug.cgi?id=164349

Patch by Devin Rousso <dcrousso+web...@gmail.com> on 2016-11-03
Reviewed by Matt Baker.

* UserInterface/Views/FolderTreeElement.js:
(WebInspector.FolderTreeElement):
Now accepts a representedObject parameter, which must be a WebInspector.Collection.

* UserInterface/Views/FolderizedTreeElement.js:
(WebInspector.FolderizedTreeElement.prototype.registerFolderizeSettings):
(WebInspector.FolderizedTreeElement.prototype.updateParentStatus):
(WebInspector.FolderizedTreeElement.prototype._parentTreeElementForRepresentedObject):
(WebInspector.FolderizedTreeElement.prototype._settingsForRepresentedObject):
(WebInspector.FolderizedTreeElement.prototype._shouldGroupIntoFolders):
(WebInspector.FolderizedTreeElement):
Rework the logic for creating WebInspector.FolderTreeElement so that items for the
representedObject parameter may be passed in via registerFolderizeSettings.

* UserInterface/Views/FrameTreeElement.js:
(WebInspector.FrameTreeElement):
(WebInspector.FrameTreeElement.): Deleted.
(WebInspector.FrameTreeElement.makeChildCountCallback): Deleted.
Rework logic for calling registerFolderizeSettings to support the representedObject
parameter.  Also changed calls to WebInspector.Frame to support the
WebInspector.Collection class.

* UserInterface/Views/ResourceSidebarPanel.js:
(WebInspector.ResourceSidebarPanel.prototype.treeElementForRepresentedObject):
(WebInspector.ResourceSidebarPanel.prototype._scriptWasAdded):
(WebInspector.ResourceSidebarPanel.prototype._scriptsCleared):
Create WebInspector.Collection instances of Script model objects for additional folders
created by the Resources sidebar:
 - Anonymous Scripts
 - Extension Scripts
 - Extra Scripts

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (208336 => 208337)


--- trunk/Source/WebInspectorUI/ChangeLog	2016-11-03 18:04:51 UTC (rev 208336)
+++ trunk/Source/WebInspectorUI/ChangeLog	2016-11-03 18:42:12 UTC (rev 208337)
@@ -1,3 +1,42 @@
+2016-11-03  Devin Rousso  <dcrousso+web...@gmail.com>
+
+        Web Inspector: Modify FolderTreeElement to have a Collection as a its represented object
+        https://bugs.webkit.org/show_bug.cgi?id=164349
+
+        Reviewed by Matt Baker.
+
+        * UserInterface/Views/FolderTreeElement.js:
+        (WebInspector.FolderTreeElement):
+        Now accepts a representedObject parameter, which must be a WebInspector.Collection.
+
+        * UserInterface/Views/FolderizedTreeElement.js:
+        (WebInspector.FolderizedTreeElement.prototype.registerFolderizeSettings):
+        (WebInspector.FolderizedTreeElement.prototype.updateParentStatus):
+        (WebInspector.FolderizedTreeElement.prototype._parentTreeElementForRepresentedObject):
+        (WebInspector.FolderizedTreeElement.prototype._settingsForRepresentedObject):
+        (WebInspector.FolderizedTreeElement.prototype._shouldGroupIntoFolders):
+        (WebInspector.FolderizedTreeElement):
+        Rework the logic for creating WebInspector.FolderTreeElement so that items for the
+        representedObject parameter may be passed in via registerFolderizeSettings.
+
+        * UserInterface/Views/FrameTreeElement.js:
+        (WebInspector.FrameTreeElement):
+        (WebInspector.FrameTreeElement.): Deleted.
+        (WebInspector.FrameTreeElement.makeChildCountCallback): Deleted.
+        Rework logic for calling registerFolderizeSettings to support the representedObject
+        parameter.  Also changed calls to WebInspector.Frame to support the
+        WebInspector.Collection class.
+
+        * UserInterface/Views/ResourceSidebarPanel.js:
+        (WebInspector.ResourceSidebarPanel.prototype.treeElementForRepresentedObject):
+        (WebInspector.ResourceSidebarPanel.prototype._scriptWasAdded):
+        (WebInspector.ResourceSidebarPanel.prototype._scriptsCleared):
+        Create WebInspector.Collection instances of Script model objects for additional folders
+        created by the Resources sidebar:
+         - Anonymous Scripts
+         - Extension Scripts
+         - Extra Scripts
+
 2016-11-02  Joseph Pecoraro  <pecor...@apple.com>
 
         Web Inspector: Include DebuggerAgent in Workers - see, pause, and step through scripts

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/FolderTreeElement.js (208336 => 208337)


--- trunk/Source/WebInspectorUI/UserInterface/Views/FolderTreeElement.js	2016-11-03 18:04:51 UTC (rev 208336)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/FolderTreeElement.js	2016-11-03 18:42:12 UTC (rev 208337)
@@ -25,22 +25,15 @@
 
 WebInspector.FolderTreeElement = class FolderTreeElement extends WebInspector.GeneralTreeElement
 {
-    constructor(title, subtitle, additionalClassNames, representedObject)
+    constructor(title, representedObject)
     {
-        var classNames;
-        if (!additionalClassNames)
-            classNames = [];
-        else if (additionalClassNames.constructor === Array)
-            classNames = additionalClassNames;
-        else if (typeof additionalClassNames === "string")
-            classNames = [additionalClassNames];
+        console.assert(!representedObject || representedObject instanceof WebInspector.Collection);
 
-        classNames.unshift(WebInspector.FolderTreeElement.FolderIconStyleClassName);
-
-        super(classNames, title, subtitle, representedObject, true);
+        const classNames = [WebInspector.FolderTreeElement.FolderIconStyleClassName];
+        const subtitle = null;
+        const hasChildren = true;
+        super(classNames, title, subtitle, representedObject, hasChildren);
     }
-
-    // No Methods or Properties
 };
 
 WebInspector.FolderTreeElement.FolderIconStyleClassName = "folder-icon";

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/FolderizedTreeElement.js (208336 => 208337)


--- trunk/Source/WebInspectorUI/UserInterface/Views/FolderizedTreeElement.js	2016-11-03 18:04:51 UTC (rev 208336)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/FolderizedTreeElement.js	2016-11-03 18:42:12 UTC (rev 208337)
@@ -51,20 +51,18 @@
         this._folderSettingsKey = x;
     }
 
-    registerFolderizeSettings(type, folderDisplayName, validateRepresentedObjectCallback, countChildrenCallback, treeElementConstructor)
+    registerFolderizeSettings(type, displayName, representedObject, treeElementConstructor)
     {
         console.assert(type);
-        console.assert(folderDisplayName);
-        console.assert(typeof validateRepresentedObjectCallback === "function");
-        console.assert(typeof countChildrenCallback === "function");
+        console.assert(displayName);
+        console.assert(representedObject);
         console.assert(typeof treeElementConstructor === "function");
 
-        var settings = {
+        let settings = {
             type,
-            folderDisplayName,
-            validateRepresentedObjectCallback,
-            countChildrenCallback,
-            treeElementConstructor
+            displayName,
+            representedObject,
+            treeElementConstructor,
         };
 
         this._folderizeSettingsMap.set(type, settings);
@@ -147,9 +145,9 @@
 
     updateParentStatus()
     {
-        var hasChildren = false;
-        for (var settings of this._folderizeSettingsMap.values()) {
-            if (settings.countChildrenCallback()) {
+        let hasChildren = false;
+        for (let settings of this._folderizeSettingsMap.values()) {
+            if (settings.representedObject.items.size) {
                 hasChildren = true;
                 break;
             }
@@ -272,10 +270,10 @@
 
         console.assert(this._folderSettingsKey !== "");
 
-        function createFolderTreeElement(type, displayName)
+        function createFolderTreeElement(settings)
         {
-            let folderTreeElement = new WebInspector.FolderTreeElement(displayName);
-            let folderExpandedSetting = new WebInspector.Setting(type + "-folder-expanded-" + this._folderSettingsKey, false);
+            let folderTreeElement = new WebInspector.FolderTreeElement(settings.displayName, settings.representedObject);
+            let folderExpandedSetting = new WebInspector.Setting(settings.type + "-folder-expanded-" + this._folderSettingsKey, false);
             this._folderExpandedSettingMap.set(folderTreeElement, folderExpandedSetting);
 
             if (folderExpandedSetting.value)
@@ -296,7 +294,7 @@
         if (folder)
             return folder;
 
-        folder = createFolderTreeElement.call(this, settings.type, settings.folderDisplayName);
+        folder = createFolderTreeElement.call(this, settings);
         this._folderTypeMap.set(settings.type, folder);
         return folder;
     }
@@ -313,8 +311,8 @@
 
     _settingsForRepresentedObject(representedObject)
     {
-        for (var settings of this._folderizeSettingsMap.values()) {
-            if (settings.validateRepresentedObjectCallback(representedObject))
+        for (let settings of this._folderizeSettingsMap.values()) {
+            if (settings.representedObject.typeVerifier(representedObject))
                 return settings;
         }
         return null;
@@ -369,7 +367,7 @@
 
         // Iterate over all the available child object types.
         for (var settings of this._folderizeSettingsMap.values()) {
-            if (pushCategory(settings.countChildrenCallback()))
+            if (pushCategory(settings.representedObject.items.size))
                 return true;
         }
         return false;

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/FrameTreeElement.js (208336 => 208337)


--- trunk/Source/WebInspectorUI/UserInterface/Views/FrameTreeElement.js	2016-11-03 18:04:51 UTC (rev 208336)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/FrameTreeElement.js	2016-11-03 18:42:12 UTC (rev 208337)
@@ -49,46 +49,15 @@
         this.shouldRefreshChildren = true;
         this.folderSettingsKey = this._frame.url.hash;
 
-        this.registerFolderizeSettings("frames", WebInspector.UIString("Frames"),
-            (representedObject) => representedObject instanceof WebInspector.Frame,
-            () => this.frame.childFrameCollection.items.size,
-            WebInspector.FrameTreeElement
-        );
+        this.registerFolderizeSettings("frames", WebInspector.UIString("Frames"), this._frame.childFrameCollection, WebInspector.FrameTreeElement);
+        this.registerFolderizeSettings("flows", WebInspector.UIString("Flows"), this._frame.domTree.contentFlowCollection, WebInspector.ContentFlowTreeElement);
+        this.registerFolderizeSettings("extra-scripts", WebInspector.UIString("Extra Scripts"), this._frame.extraScriptCollection, WebInspector.ScriptTreeElement);
 
-        this.registerFolderizeSettings("flows", WebInspector.UIString("Flows"),
-            (representedObject) => representedObject instanceof WebInspector.ContentFlow,
-            () => this.frame.domTree.contentFlowCollection.items.size,
-            WebInspector.ContentFlowTreeElement
-        );
-
-        this.registerFolderizeSettings("extra-scripts", WebInspector.UIString("Extra Scripts"),
-            (representedObject) => representedObject instanceof WebInspector.Script && representedObject.dynamicallyAddedScriptElement,
-            () => this.frame.extraScriptCollection.items.size,
-            WebInspector.ScriptTreeElement
-        );
-
-        function makeValidateCallback(resourceType) {
-            return function(representedObject) {
-                return representedObject instanceof WebInspector.Resource && representedObject.type === resourceType;
-            };
+        for (let [key, value] of Object.entries(WebInspector.Resource.Type)) {
+            let folderName = WebInspector.Resource.displayNameForType(value, true);
+            this.registerFolderizeSettings(key, folderName, this._frame.resourceCollectionForType(value), WebInspector.ResourceTreeElement);
         }
 
-        function makeChildCountCallback(frame, resourceType) {
-            return function() {
-                return frame.resourceCollectionForType(resourceType).items.size;
-            };
-        }
-
-        for (var key in WebInspector.Resource.Type) {
-            var value = WebInspector.Resource.Type[key];
-            var folderName = WebInspector.Resource.displayNameForType(value, true);
-            this.registerFolderizeSettings(key, folderName,
-                makeValidateCallback(value),
-                makeChildCountCallback(this.frame, value),
-                WebInspector.ResourceTreeElement
-            );
-        }
-
         this.updateParentStatus();
     }
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ResourceSidebarPanel.js (208336 => 208337)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ResourceSidebarPanel.js	2016-11-03 18:04:51 UTC (rev 208336)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ResourceSidebarPanel.js	2016-11-03 18:42:12 UTC (rev 208337)
@@ -171,8 +171,10 @@
         // window.eval() or browser features like Auto Fill and Reader. They are not normally added to the sidebar, but since
         // we have a ScriptContentView asking for the tree element we will make a ScriptTreeElement on demand and add it.
 
-        if (!this._anonymousScriptsFolderTreeElement)
-            this._anonymousScriptsFolderTreeElement = new WebInspector.FolderTreeElement(WebInspector.UIString("Anonymous Scripts"));
+        if (!this._anonymousScriptsFolderTreeElement) {
+            let collection = new WebInspector.Collection(WebInspector.Collection.TypeVerifier.Script);
+            this._anonymousScriptsFolderTreeElement = new WebInspector.FolderTreeElement(WebInspector.UIString("Anonymous Scripts"), collection);
+        }
 
         if (!this._anonymousScriptsFolderTreeElement.parent) {
             var index = insertionIndexForObjectInListSortedByFunction(this._anonymousScriptsFolderTreeElement, this.contentTreeOutline.children, this._compareTreeElements);
@@ -179,6 +181,8 @@
             this.contentTreeOutline.insertChild(this._anonymousScriptsFolderTreeElement, index);
         }
 
+        this._anonymousScriptsFolderTreeElement.representedObject.add(representedObject);
+
         var scriptTreeElement = new WebInspector.ScriptTreeElement(representedObject);
         this._anonymousScriptsFolderTreeElement.appendChild(scriptTreeElement);
 
@@ -293,22 +297,31 @@
             return;
         }
 
-        var insertIntoTopLevel = false;
+        let insertIntoTopLevel = false;
+        let parentFolderTreeElement = null;
 
         if (script.injected) {
-            if (!this._extensionScriptsFolderTreeElement)
-                this._extensionScriptsFolderTreeElement = new WebInspector.FolderTreeElement(WebInspector.UIString("Extension Scripts"));
-            var parentFolderTreeElement = this._extensionScriptsFolderTreeElement;
+            if (!this._extensionScriptsFolderTreeElement) {
+                let collection = new WebInspector.Collection(WebInspector.Collection.TypeVerifier.Script);
+                this._extensionScriptsFolderTreeElement = new WebInspector.FolderTreeElement(WebInspector.UIString("Extension Scripts"), collection);
+            }
+
+            parentFolderTreeElement = this._extensionScriptsFolderTreeElement;
         } else {
             if (WebInspector.debuggableType === WebInspector.DebuggableType._javascript_ && !WebInspector.hasExtraDomains)
                 insertIntoTopLevel = true;
             else {
-                if (!this._extraScriptsFolderTreeElement)
-                    this._extraScriptsFolderTreeElement = new WebInspector.FolderTreeElement(WebInspector.UIString("Extra Scripts"));
-                var parentFolderTreeElement = this._extraScriptsFolderTreeElement;
+                if (!this._extraScriptsFolderTreeElement) {
+                    let collection = new WebInspector.Collection(WebInspector.Collection.TypeVerifier.Script);
+                    this._extraScriptsFolderTreeElement = new WebInspector.FolderTreeElement(WebInspector.UIString("Extra Scripts"), collection);
+                }
+
+                parentFolderTreeElement = this._extraScriptsFolderTreeElement;
             }
         }
 
+        parentFolderTreeElement.representedObject.add(script);
+
         var scriptTreeElement = new WebInspector.ScriptTreeElement(script);
 
         if (insertIntoTopLevel) {
@@ -346,6 +359,8 @@
         if (this._extensionScriptsFolderTreeElement) {
             if (this._extensionScriptsFolderTreeElement.parent)
                 this._extensionScriptsFolderTreeElement.parent.removeChild(this._extensionScriptsFolderTreeElement, suppressOnDeselect, suppressSelectSibling);
+
+            this._extensionScriptsFolderTreeElement.representedObject.clear();
             this._extensionScriptsFolderTreeElement = null;
         }
 
@@ -352,6 +367,8 @@
         if (this._extraScriptsFolderTreeElement) {
             if (this._extraScriptsFolderTreeElement.parent)
                 this._extraScriptsFolderTreeElement.parent.removeChild(this._extraScriptsFolderTreeElement, suppressOnDeselect, suppressSelectSibling);
+
+            this._extraScriptsFolderTreeElement.representedObject.clear();
             this._extraScriptsFolderTreeElement = null;
         }
 
@@ -358,6 +375,8 @@
         if (this._anonymousScriptsFolderTreeElement) {
             if (this._anonymousScriptsFolderTreeElement.parent)
                 this._anonymousScriptsFolderTreeElement.parent.removeChild(this._anonymousScriptsFolderTreeElement, suppressOnDeselect, suppressSelectSibling);
+
+            this._anonymousScriptsFolderTreeElement.representedObject.clear();
             this._anonymousScriptsFolderTreeElement = null;
         }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to