Web Inspector: Debugger sidebar should have a filter button for breakpoints
authorjonowells@apple.com <jonowells@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Mar 2015 22:00:19 +0000 (22:00 +0000)
committerjonowells@apple.com <jonowells@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Mar 2015 22:00:19 +0000 (22:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142779

Reviewed by Timothy Hatcher.

Add the infrastructure for activation filter buttons that can appear next to the text filters at the bottom
of any navigation sidebar panel. These filter bar buttons have defined within them a function that returns
a boolean value that indicates whether the input, typically a tree element, should be filtered or not.

This infrastructure is then used to create a filter for the debugger sidebar that, when applied, only shows
scripts that have breakpoints set on them.

* Localizations/en.lproj/localizedStrings.js: Updated.
* UserInterface/Main.html: Files added.

* UserInterface/Views/DebuggerSidebarPanel.js:
(WebInspector.DebuggerSidebarPanel.showResourcesWithChildrenOnlyFilterFunction):
(WebInspector.DebuggerSidebarPanel):
(WebInspector.DebuggerSidebarPanel.prototype._addBreakpoint): Drive-by fix.
Add filter button to filter bar.

* UserInterface/Views/FilterBar.css:
(.filter-bar > .navigation-bar > .item):
Style filter button.

* UserInterface/Views/FilterBar.js:
(WebInspector.FilterBar):
(WebInspector.FilterBar.prototype.get filters):
(WebInspector.FilterBar.prototype.set filters):
(WebInspector.FilterBar.prototype.hasActiveFilters):
(WebInspector.FilterBar.prototype._handleFilterChanged):
(WebInspector.FilterBar.prototype._inputFieldChanged): Deleted.
Create space for filter bar buttons and set up event handlers to deal with them.

* UserInterface/Views/FilterBarButton.js: Copied from Source/WebInspectorUI/UserInterface/Views/FilterBar.css.
(WebInspector.FilterBarButton):
(WebInspector.FilterBarButton.prototype.get filterFunction):
(WebInspector.FilterBarButton.prototype.toggle):
Create class for a filter bar button that stores a filter function.

* UserInterface/Views/NavigationSidebarPanel.js:
(WebInspector.NavigationSidebarPanel):
(WebInspector.NavigationSidebarPanel.prototype.matchTreeElementAgainstFilterFunctions):
(WebInspector.NavigationSidebarPanel.prototype.applyFiltersToTreeElement):
(WebInspector.NavigationSidebarPanel.prototype._filterDidChange):
(WebInspector.NavigationSidebarPanel.prototype._updateFilter):
(WebInspector.NavigationSidebarPanel.prototype._textFilterDidChange): Deleted.
Add functionality to support button filters and process their corresponding functions correctly when filtering.

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js
Source/WebInspectorUI/UserInterface/Main.html
Source/WebInspectorUI/UserInterface/Views/DebuggerSidebarPanel.js
Source/WebInspectorUI/UserInterface/Views/FilterBar.css
Source/WebInspectorUI/UserInterface/Views/FilterBar.js
Source/WebInspectorUI/UserInterface/Views/FilterBarButton.js [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Views/NavigationSidebarPanel.js
Source/WebInspectorUI/WebInspectorUI.esproj/Project.espressostorage [new file with mode: 0644]
Source/WebInspectorUI/WebInspectorUI.esproj/user.jonowells.espressostorage [new file with mode: 0644]

index 2f938ae..3e17093 100644 (file)
@@ -1,3 +1,54 @@
+2015-03-17  Jono Wells  <jonowells@apple.com>
+
+        Web Inspector: Debugger sidebar should have a filter button for breakpoints
+        https://bugs.webkit.org/show_bug.cgi?id=142779
+
+        Reviewed by Timothy Hatcher.
+
+        Add the infrastructure for activation filter buttons that can appear next to the text filters at the bottom
+        of any navigation sidebar panel. These filter bar buttons have defined within them a function that returns
+        a boolean value that indicates whether the input, typically a tree element, should be filtered or not.
+
+        This infrastructure is then used to create a filter for the debugger sidebar that, when applied, only shows
+        scripts that have breakpoints set on them.
+
+        * Localizations/en.lproj/localizedStrings.js: Updated.
+        * UserInterface/Main.html: Files added.
+
+        * UserInterface/Views/DebuggerSidebarPanel.js:
+        (WebInspector.DebuggerSidebarPanel.showResourcesWithChildrenOnlyFilterFunction):
+        (WebInspector.DebuggerSidebarPanel):
+        (WebInspector.DebuggerSidebarPanel.prototype._addBreakpoint): Drive-by fix.
+        Add filter button to filter bar.
+
+        * UserInterface/Views/FilterBar.css:
+        (.filter-bar > .navigation-bar > .item):
+        Style filter button.
+
+        * UserInterface/Views/FilterBar.js:
+        (WebInspector.FilterBar):
+        (WebInspector.FilterBar.prototype.get filters):
+        (WebInspector.FilterBar.prototype.set filters):
+        (WebInspector.FilterBar.prototype.hasActiveFilters):
+        (WebInspector.FilterBar.prototype._handleFilterChanged):
+        (WebInspector.FilterBar.prototype._inputFieldChanged): Deleted.
+        Create space for filter bar buttons and set up event handlers to deal with them.
+
+        * UserInterface/Views/FilterBarButton.js: Copied from Source/WebInspectorUI/UserInterface/Views/FilterBar.css.
+        (WebInspector.FilterBarButton):
+        (WebInspector.FilterBarButton.prototype.get filterFunction):
+        (WebInspector.FilterBarButton.prototype.toggle):
+        Create class for a filter bar button that stores a filter function.
+
+        * UserInterface/Views/NavigationSidebarPanel.js:
+        (WebInspector.NavigationSidebarPanel):
+        (WebInspector.NavigationSidebarPanel.prototype.matchTreeElementAgainstFilterFunctions):
+        (WebInspector.NavigationSidebarPanel.prototype.applyFiltersToTreeElement):
+        (WebInspector.NavigationSidebarPanel.prototype._filterDidChange):
+        (WebInspector.NavigationSidebarPanel.prototype._updateFilter):
+        (WebInspector.NavigationSidebarPanel.prototype._textFilterDidChange): Deleted.
+        Add functionality to support button filters and process their corresponding functions correctly when filtering.
+
 2015-03-22  Matt Baker  <mattbaker@apple.com>
 
         Web Inspector: Adopt ES6 Class Syntax for all Controller Objects
index b1467d0..b40b1e6 100644 (file)
Binary files a/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js and b/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js differ
index b0dc22a..180dac2 100644 (file)
     <script src="Views/EventListenerSection.js"></script>
     <script src="Views/EventListenerSectionGroup.js"></script>
     <script src="Views/FilterBar.js"></script>
+    <script src="Views/FilterBarButton.js"></script>
     <script src="Views/FindBanner.js"></script>
     <script src="Views/FlexibleSpaceNavigationItem.js"></script>
     <script src="Views/FontResourceContentView.js"></script>
index d8a149c..6787299 100644 (file)
@@ -53,23 +53,15 @@ WebInspector.DebuggerSidebarPanel = function()
 
     this._navigationBar = new WebInspector.NavigationBar;
     this.element.appendChild(this._navigationBar.element);
+    
+    var imageSize = WebInspector.Platform.isLegacyMacOS ? 16 : 15;
 
-    var breakpointsImage, pauseImage, resumeImage, stepOverImage, stepIntoImage, stepOutImage;
-    if (WebInspector.Platform.isLegacyMacOS) {
-        breakpointsImage = {src: "Images/Legacy/Breakpoints.svg", width: 16, height: 16};
-        pauseImage = {src: "Images/Legacy/Pause.svg", width: 16, height: 16};
-        resumeImage = {src: "Images/Legacy/Resume.svg", width: 16, height: 16};
-        stepOverImage = {src: "Images/Legacy/StepOver.svg", width: 16, height: 16};
-        stepIntoImage = {src: "Images/Legacy/StepInto.svg", width: 16, height: 16};
-        stepOutImage = {src: "Images/Legacy/StepOut.svg", width: 16, height: 16};
-    } else {
-        breakpointsImage = {src: "Images/Breakpoints.svg", width: 15, height: 15};
-        pauseImage = {src: "Images/Pause.svg", width: 15, height: 15};
-        resumeImage = {src: "Images/Resume.svg", width: 15, height: 15};
-        stepOverImage = {src: "Images/StepOver.svg", width: 15, height: 15};
-        stepIntoImage = {src: "Images/StepInto.svg", width: 15, height: 15};
-        stepOutImage = {src: "Images/StepOut.svg", width: 15, height: 15};
-    }
+    var breakpointsImage = {src: platformImagePath("Breakpoints.svg"), width: imageSize, height: imageSize};
+    var pauseImage = {src: platformImagePath("Pause.svg"), width: imageSize, height: imageSize};
+    var resumeImage = {src: platformImagePath("Resume.svg"), width: imageSize, height: imageSize};
+    var stepOverImage = {src: platformImagePath("StepOver.svg"), width: imageSize, height: imageSize};
+    var stepIntoImage = {src: platformImagePath("StepInto.svg"), width: imageSize, height: imageSize};
+    var stepOutImage = {src: platformImagePath("StepOut.svg"), width: imageSize, height: imageSize};
 
     var toolTip = WebInspector.UIString("Enable all breakpoints (%s)").format(this._toggleBreakpointsKeyboardShortcut.displayName);
     var altToolTip = WebInspector.UIString("Disable all breakpoints (%s)").format(this._toggleBreakpointsKeyboardShortcut.displayName);
@@ -109,6 +101,23 @@ WebInspector.DebuggerSidebarPanel = function()
     this._allUncaughtExceptionsBreakpointTreeElement = new WebInspector.BreakpointTreeElement(WebInspector.debuggerManager.allUncaughtExceptionsBreakpoint, WebInspector.DebuggerSidebarPanel.ExceptionIconStyleClassName, WebInspector.UIString("All Uncaught Exceptions"));
 
     this.filterBar.placeholder = WebInspector.UIString("Filter Breakpoint List");
+    var showResourcesWithBreakpointsOnlyFilterFunction = function(treeElement)
+    {
+        // Keep breakpoints and other elements that aren't resources.
+        if (!treeElement instanceof WebInspector.ResourceTreeElement || treeElement instanceof WebInspector.BreakpointTreeElement)
+            return true;
+
+        // Keep resources with breakpoints.
+        if (treeElement.hasChildren) {
+            for (var child of treeElement.children) {
+                if (child instanceof WebInspector.BreakpointTreeElement)
+                    return true;
+            }
+        }
+        return false;
+    };
+
+    this.filterBar.addFilterBarButton("debugger-show-resources-with-children-only", showResourcesWithBreakpointsOnlyFilterFunction, true, WebInspector.UIString("Show only resources with breakpoints."), WebInspector.UIString("Show resources with and without breakpoints."), platformImagePath("Breakpoints.svg"), 15, 15);
 
     this._breakpointsContentTreeOutline = this.contentTreeOutline;
     this._breakpointsContentTreeOutline.onselect = this._treeElementSelected.bind(this);
@@ -282,7 +291,7 @@ WebInspector.DebuggerSidebarPanel.prototype = {
         WebInspector.debuggerManager.breakpointsEnabled = !this._debuggerBreakpointsButtonItem.activated;
     },
 
-    _addBreakpoint: function(breakpoint, sourceCode)
+    _addBreakpoint: function(breakpoint)
     {
         var sourceCode = breakpoint.sourceCodeLocation.displaySourceCode;
         if (!sourceCode)
index db44998..3553edd 100644 (file)
@@ -36,6 +36,10 @@ body.mac-platform.legacy .filter-bar {
     height: 21px;
 }
 
+.filter-bar > .navigation-bar > .item {
+    padding: 0 0 3px 8px;
+}
+
 .filter-bar > input[type="search"] {
     display: flex;
     flex: 1;
index 633ece7..2ac8207 100644 (file)
@@ -30,11 +30,16 @@ WebInspector.FilterBar = function(element) {
     this._element = element || document.createElement("div");
     this._element.classList.add(WebInspector.FilterBar.StyleClassName);
 
+    this._filtersNavigationBar = new WebInspector.NavigationBar;
+    this._element.appendChild(this._filtersNavigationBar.element);
+
+    this._filterFunctionsMap = new Map;
+
     this._inputField = document.createElement("input");
     this._inputField.type = "search";
     this._inputField.spellcheck = false;
     this._inputField.incremental = true;
-    this._inputField.addEventListener("search", this._inputFieldChanged.bind(this), false);
+    this._inputField.addEventListener("search", this._handleFilterChanged.bind(this), false);
     this._element.appendChild(this._inputField);
 };
 
@@ -44,11 +49,12 @@ WebInspector.Object.deprecatedAddConstructorFunctions(WebInspector.FilterBar);
 WebInspector.FilterBar.StyleClassName = "filter-bar";
 
 WebInspector.FilterBar.Event = {
-    TextFilterDidChange: "filter-bar-text-filter-did-change"
+    FilterDidChange: "filter-bar-text-filter-did-change"
 };
 
 WebInspector.FilterBar.prototype = {
     constructor: WebInspector.FilterBar,
+    __proto__: WebInspector.Object.prototype,
 
     // Public
 
@@ -74,7 +80,7 @@ WebInspector.FilterBar.prototype = {
 
     get filters()
     {
-        return {text: this._inputField.value};
+        return {text: this._inputField.value, functions: [...this._filterFunctionsMap.values()]};
     },
 
     set filters(filters)
@@ -84,22 +90,46 @@ WebInspector.FilterBar.prototype = {
         var oldTextValue = this._inputField.value;
         this._inputField.value = filters.text || "";
         if (oldTextValue !== this._inputField.value)
-            this._inputFieldChanged();
+            this._handleFilterChanged();
+    },
+
+    addFilterBarButton: function(identifier, filterFunction, activatedByDefault, defaultToolTip, activatedToolTip, image, imageWidth, imageHeight, suppressEmboss)
+    {
+        var filterBarButton = new WebInspector.FilterBarButton(identifier, filterFunction, activatedByDefault, defaultToolTip, activatedToolTip, image, imageWidth, imageHeight, suppressEmboss);
+        filterBarButton.addEventListener(WebInspector.ButtonNavigationItem.Event.Clicked, this._handleFilterBarButtonClicked, this);
+        filterBarButton.addEventListener(WebInspector.FilterBarButton.Event.ActivatedStateToggled, this._handleFilterButtonToggled, this);
+        this._filtersNavigationBar.addNavigationItem(filterBarButton);
+        if (filterBarButton.activated) {
+            this._filterFunctionsMap.set(filterBarButton.identifier, filterBarButton.filterFunction);
+            this._handleFilterChanged();
+        }
     },
 
     hasActiveFilters: function()
     {
-        if (this._inputField.value)
-            return true;
-        return false;
+        return !!this._inputField.value || !!this._filterFunctionsMap.size;
     },
 
     // Private
 
-    _inputFieldChanged: function(event)
+    _handleFilterBarButtonClicked(event)
+    {
+        var filterBarButton = event.target;
+        filterBarButton.toggle();
+    },
+
+    _handleFilterButtonToggled: function(event)
+    {
+        var filterBarButton = event.target;
+        if (filterBarButton.activated)
+            this._filterFunctionsMap.set(filterBarButton.identifier, filterBarButton.filterFunction);
+        else
+            this._filterFunctionsMap.delete(filterBarButton.identifier);
+        this._handleFilterChanged();
+    },
+
+    _handleFilterChanged: function()
     {
-        this.dispatchEventToListeners(WebInspector.FilterBar.Event.TextFilterDidChange);
+        this.dispatchEventToListeners(WebInspector.FilterBar.Event.FilterDidChange);
     }
 };
-
-WebInspector.FilterBar.prototype.__proto__ = WebInspector.Object.prototype;
diff --git a/Source/WebInspectorUI/UserInterface/Views/FilterBarButton.js b/Source/WebInspectorUI/UserInterface/Views/FilterBarButton.js
new file mode 100644 (file)
index 0000000..b09ce6e
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.FilterBarButton = function(identifier, filterFunction, activatedByDefault, defaultToolTip, activatedToolTip, image, imageWidth, imageHeight, suppressEmboss, role)
+{
+    WebInspector.ActivateButtonNavigationItem.call(this, identifier, defaultToolTip, activatedToolTip, image, imageWidth, imageHeight, suppressEmboss, role);
+
+    this._filterFunction = filterFunction;
+
+    this._activatedSetting = new WebInspector.Setting(identifier, activatedByDefault);
+
+    this.activated = !!this._activatedSetting.value;
+};
+
+WebInspector.FilterBarButton.StyleClassName = "filter-bar-button";
+
+WebInspector.FilterBarButton.Event = {
+    ActivatedStateToggled: "filter-bar-activated-state-toggled"
+};
+
+WebInspector.FilterBarButton.prototype = {
+    constructor: WebInspector.FilterBarButton,
+    __proto__: WebInspector.ActivateButtonNavigationItem.prototype,
+
+    // Public
+
+    get filterFunction()
+    {
+        return this._filterFunction;
+    },
+
+    toggle: function()
+    {
+        this.activated = !this.activated;
+        this._activatedSetting.value = this.activated;
+        this.dispatchEventToListeners(WebInspector.FilterBarButton.Event.ActivatedStateToggled);
+    }
+};
index 4a1f930..80e098b 100644 (file)
@@ -52,7 +52,7 @@ WebInspector.NavigationSidebarPanel = function(identifier, displayName, image, k
     this._contentTreeOutline = this.createContentTreeOutline(true);
 
     this._filterBar = new WebInspector.FilterBar();
-    this._filterBar.addEventListener(WebInspector.FilterBar.Event.TextFilterDidChange, this._textFilterDidChange, this);
+    this._filterBar.addEventListener(WebInspector.FilterBar.Event.FilterDidChange, this._filterDidChange, this);
     this.element.appendChild(this._filterBar.element);
 
     this._bottomOverflowShadowElement = document.createElement("div");
@@ -312,6 +312,15 @@ WebInspector.NavigationSidebarPanel.prototype = {
         return true;
     },
 
+    matchTreeElementAgainstFilterFunctions: function(treeElement)
+    {
+        for (var filterFunction of this._filterFunctions) {
+            if (filterFunction(treeElement))
+                return true;
+        }
+        return false;
+    },
+
     applyFiltersToTreeElement: function(treeElement)
     {
         if (!this._filterBar.hasActiveFilters() && !this.hasCustomFilters()) {
@@ -375,7 +384,7 @@ WebInspector.NavigationSidebarPanel.prototype = {
             }
         }
 
-        if (matchTextFilter(filterableData.text) && this.matchTreeElementAgainstCustomFilters(treeElement)) {
+        if (matchTextFilter(filterableData.text) && this.matchTreeElementAgainstFilterFunctions(treeElement) && this.matchTreeElementAgainstCustomFilters(treeElement)) {
             // Make this element visible since it matches.
             makeVisible();
 
@@ -490,7 +499,7 @@ WebInspector.NavigationSidebarPanel.prototype = {
         this._emptyFilterResults = true;
     },
 
-    _textFilterDidChange: function()
+    _filterDidChange: function()
     {
         this._updateFilter();
     },
@@ -503,6 +512,7 @@ WebInspector.NavigationSidebarPanel.prototype = {
         var filters = this._filterBar.filters;
         this._textFilterRegex = simpleGlobStringToRegExp(filters.text, "i");
         this._filtersSetting.value = filters;
+        this._filterFunctions = filters.functions;
 
         // Don't populate if we don't have any active filters.
         // We only need to populate when a filter needs to reveal.
diff --git a/Source/WebInspectorUI/WebInspectorUI.esproj/Project.espressostorage b/Source/WebInspectorUI/WebInspectorUI.esproj/Project.espressostorage
new file mode 100644 (file)
index 0000000..cf53f27
Binary files /dev/null and b/Source/WebInspectorUI/WebInspectorUI.esproj/Project.espressostorage differ
diff --git a/Source/WebInspectorUI/WebInspectorUI.esproj/user.jonowells.espressostorage b/Source/WebInspectorUI/WebInspectorUI.esproj/user.jonowells.espressostorage
new file mode 100644 (file)
index 0000000..6789e93
Binary files /dev/null and b/Source/WebInspectorUI/WebInspectorUI.esproj/user.jonowells.espressostorage differ