Title: [199143] trunk
Revision
199143
Author
[email protected]
Date
2016-04-06 19:09:07 -0700 (Wed, 06 Apr 2016)

Log Message

Web Inspector: Improve filtering in OpenResourceDialog
https://bugs.webkit.org/show_bug.cgi?id=155324
<rdar://problem/25094504>

Source/WebInspectorUI:

Reviewed by Joseph Pecoraro and Timothy Hatcher.

* UserInterface/Base/Utilities.js:
(value):
Added String methods isLowerCase, isUpperCase, removeWhitespace.

* UserInterface/Controllers/ResourceQueryController.js: Added.
(WebInspector.ResourceQueryController):
(WebInspector.ResourceQueryController.prototype.addResource):
(WebInspector.ResourceQueryController.prototype.removeResource):
Add and remove the resources to be queried.

(WebInspector.ResourceQueryController.prototype.reset):
Reset controller state. Current just clears resources.

(WebInspector.ResourceQueryController.prototype.executeQuery):
Executes a query against the list of resources and returns a list of
QueryResult objects, with at most one result per resource, ordered by
descending rank.

The query string is stripped of whitespace characters and lowercased
before use. Prior to running the query, resources undergo a one-time
pre-processing step to locate special characters.

(WebInspector.ResourceQueryController.prototype._findQueryMatches.pushMatch):
(WebInspector.ResourceQueryController.prototype._findQueryMatches.matchNextSpecialCharacter):
(WebInspector.ResourceQueryController.prototype._findQueryMatches.backtrack):
(WebInspector.ResourceQueryController.prototype._findQueryMatches):
Returns a list of query matches for a single resource, along with metadata
which is used to rank the matches. The algorithm attempts to match the
entire query, first comparing each query character against "special" characters
in the resource (commonly used filename separators, the first character,
and camel-case word boundaries).

If there are remaining query characters after exhausting special characters,
regular characters are matched starting from the last matched special
character. Failing that, the algorithm attempts to find a match by backtracking.
To backtrack, the last match is discarded and the query position decremented.
If a special match is now the last match, matching starts again from the
next character in the filename after the match. If a normal match is now
the last match, keep discarding until a special match is found or no matches
remain. The query fails if no matches remain. For example, consider:

   Query: "abcd"
   Filename: "AxBcdCx"

The capital A, B, and C are all special characters, and are successfully
matched with the first three query characters. Having exhausted the special
characters the "d" at the end of the query is compared with the "x" at
the end of the filename, and fails to match. Backtracking then kicks in.
The last match, "C", is discarded and the search position in the query
decremented. The search resumes after the next to last match, "B", and now
matches the non-special characters "cd", yielding the following: "A Bcd  ".

(WebInspector.ResourceQueryController.prototype._findSpecialCharacterIndices):
Pre-processing step for resources. Locates the positions of special
characters in the resource filename. Special characters are defined as:

   1. The first character
   2. Common filename separators, and the character immediately following.
   3. A capital letter that follows a lowercase character.

* UserInterface/Models/ResourceQueryMatch.js: Added.
Helper class used internally by the controller and QueryResult classes.
(WebInspector.ResourceQueryMatch):
(WebInspector.ResourceQueryMatch.prototype.get type):
(WebInspector.ResourceQueryMatch.prototype.get index):
(WebInspector.ResourceQueryMatch.prototype.get queryIndex):

* UserInterface/Models/ResourceQueryResult.js: Added.
Holds a resource that matched the executed query.
(WebInspector.ResourceQueryResult):
(WebInspector.ResourceQueryResult.prototype.get resource):
(WebInspector.ResourceQueryResult.prototype.get rank):
Ranking relative to other results returned by the query. Used by
the ResourceQueryController to sort results.

(WebInspector.ResourceQueryResult.prototype.get matchingTextRanges):
Get TextRanges for matching substrings in the resource display name.

(WebInspector.ResourceQueryResult.prototype._calculateRank):
Calculate the rank of the result. Matches are scored based on the type
of match (Special vs. Normal), the location of the match within the filename
(matches closer to the beginning are scored higher), and whether the match
is adjacent to the previous match.

Values assigned to each ranking criteria are somewhat arbitrary, and may
be fine-tuned over time to produce better results.

(WebInspector.ResourceQueryResult.prototype._createMatchingTextRanges):
(WebInspector.ResourceQueryResult.prototype.__test_createMatchesMask):
Test API for visualizing matches. For a result returned from the query
"abce", run against a filename "abcde", the mask is "a c e".

* UserInterface/Main.html:
* UserInterface/Test.html:
New files.

* UserInterface/Views/Dialog.js:
(WebInspector.Dialog.prototype.dismiss):
(WebInspector.Dialog.prototype.didDismissDialog):
Add hook for subclasses to perform actions after on dialog dismissal.

* UserInterface/Views/OpenResourceDialog.js:
(WebInspector.OpenResourceDialog):
(WebInspector.OpenResourceDialog.prototype._populateResourceTreeOutline.createHighlightedTitleFragment):
(WebInspector.OpenResourceDialog.prototype._populateResourceTreeOutline):
Add tree elements for each QueryResult returned by the last query, creating
titles with contiguous matching query characters wrapped in highlight spans.

(WebInspector.OpenResourceDialog.prototype.didDismissDialog):
Clear resources from the ResourceQueryController.
(WebInspector.OpenResourceDialog.prototype.didPresentDialog):
Add resources to the ResourceQueryController.
(WebInspector.OpenResourceDialog.prototype._updateFilter):
Execute the filter text as a resource query.

* UserInterface/Views/TreeOutline.css:
(.tree-outline.large .item .titles): Deleted.
Line height too small, hid the bottom border of highlighted matches in
tree element title spans. Removing the style had no negative visual impact
on the Quick Open or Timelines tree outlines (the only "large" trees).

LayoutTests:

Reviewed by Joseph Pecoraro.

Add test coverage for ResourceQueryController.

* inspector/unit-tests/resource-query-controller-expected.txt: Added.
* inspector/unit-tests/resource-query-controller.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (199142 => 199143)


--- trunk/LayoutTests/ChangeLog	2016-04-07 02:07:26 UTC (rev 199142)
+++ trunk/LayoutTests/ChangeLog	2016-04-07 02:09:07 UTC (rev 199143)
@@ -1,3 +1,16 @@
+2016-04-06  Matt Baker  <[email protected]>
+
+        Web Inspector: Improve filtering in OpenResourceDialog
+        https://bugs.webkit.org/show_bug.cgi?id=155324
+        <rdar://problem/25094504>
+
+        Reviewed by Joseph Pecoraro.
+
+        Add test coverage for ResourceQueryController.
+
+        * inspector/unit-tests/resource-query-controller-expected.txt: Added.
+        * inspector/unit-tests/resource-query-controller.html: Added.
+
 2016-04-06  Saam barati  <[email protected]>
 
         jsc-layout-tests.yaml/js/script-tests/regress-141098.js failing on Yosemite Debug after r198989

Added: trunk/LayoutTests/inspector/unit-tests/resource-query-controller-expected.txt (0 => 199143)


--- trunk/LayoutTests/inspector/unit-tests/resource-query-controller-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/unit-tests/resource-query-controller-expected.txt	2016-04-07 02:09:07 UTC (rev 199143)
@@ -0,0 +1,214 @@
+Testing WebInspector.ResourceQueryController.
+
+
+== Running test suite: ResourceQueryController
+-- Running test case: FindSpecialCharacterIndices
+PASS: Result should match expected special indices.
+PASS: Result should match expected special indices.
+PASS: Result should match expected special indices.
+PASS: Result should match expected special indices.
+PASS: Result should match expected special indices.
+PASS: Result should match expected special indices.
+PASS: Result should match expected special indices.
+PASS: Result should match expected special indices.
+PASS: Result should match expected special indices.
+
+-- Running test case: ExecuteQueryAgainstNoResources
+PASS: Should return no results.
+
+-- Running test case: ExecuteWhitespaceQueryOrEmptyQuery
+PASS: Whitespace query should return no results.
+PASS: Whitespace query should return no results.
+PASS: Whitespace query should return no results.
+PASS: Whitespace query should return no results.
+PASS: Empty query should return no results.
+
+-- Running test case: ExecuteQueryContainingWhitespace
+PASS: Should match one result.
+PASS: Should match one result.
+PASS: Should match one result.
+PASS: Should match one result.
+PASS: Should match one result.
+
+-- Running test case: ExecuteQueryMatchNone
+PASS: Query "abcde" shouldn't match "abcd".
+PASS: Query "abcd-" shouldn't match "abcde".
+PASS: Query "abcde" shouldn't match "abced".
+
+-- Running test case: ExecuteQueryMatchesExpectedCharacters
+PASS: Query "abcd" should match "abcd" in "abcde".
+PASS: Query " abcd" should match "abcd" in "abcde".
+PASS: Query "abcd " should match "abcd" in "abcde".
+PASS: Query "a b c d" should match "abcd" in "abcde".
+PASS: Query "a-bcde" should match "a    - bcde" in "abcde-abcde".
+PASS: Query "abcde" should match "A B C D E" in "AaBbCcDdEe".
+PASS: Query "abcde" should match "A   B  C De" in "AbcdBcdCdDe".
+PASS: Query "abcdex" should match "A B C d ex" in "AxBxCxdxexDxyxEF".
+PASS: Query "bc" should match " bC" in "abCd".
+
+-- Running test case: ExecuteQueryShouldIgnoreCase
+All case permutations of query "abcd" should match "abcd" in "abcde".
+PASS: Permutation "abcd".
+PASS: Permutation "Abcd".
+PASS: Permutation "aBcd".
+PASS: Permutation "ABcd".
+PASS: Permutation "abCd".
+PASS: Permutation "AbCd".
+PASS: Permutation "aBCd".
+PASS: Permutation "ABCd".
+PASS: Permutation "abcD".
+PASS: Permutation "AbcD".
+PASS: Permutation "aBcD".
+PASS: Permutation "ABcD".
+PASS: Permutation "abCD".
+PASS: Permutation "AbCD".
+PASS: Permutation "aBCD".
+PASS: Permutation "ABCD".
+All case permutations of query "abcde" should match "A B C D E" in "AaBbCcDdEe".
+PASS: Permutation "abcde".
+PASS: Permutation "Abcde".
+PASS: Permutation "aBcde".
+PASS: Permutation "ABcde".
+PASS: Permutation "abCde".
+PASS: Permutation "AbCde".
+PASS: Permutation "aBCde".
+PASS: Permutation "ABCde".
+PASS: Permutation "abcDe".
+PASS: Permutation "AbcDe".
+PASS: Permutation "aBcDe".
+PASS: Permutation "ABcDe".
+PASS: Permutation "abCDe".
+PASS: Permutation "AbCDe".
+PASS: Permutation "aBCDe".
+PASS: Permutation "ABCDe".
+PASS: Permutation "abcdE".
+PASS: Permutation "AbcdE".
+PASS: Permutation "aBcdE".
+PASS: Permutation "ABcdE".
+PASS: Permutation "abCdE".
+PASS: Permutation "AbCdE".
+PASS: Permutation "aBCdE".
+PASS: Permutation "ABCdE".
+PASS: Permutation "abcDE".
+PASS: Permutation "AbcDE".
+PASS: Permutation "aBcDE".
+PASS: Permutation "ABcDE".
+PASS: Permutation "abCDE".
+PASS: Permutation "AbCDE".
+PASS: Permutation "aBCDE".
+PASS: Permutation "ABCDE".
+All case permutations of query "abcde" should match "A   B  C De" in "AbcdBcdCdDe".
+PASS: Permutation "abcde".
+PASS: Permutation "Abcde".
+PASS: Permutation "aBcde".
+PASS: Permutation "ABcde".
+PASS: Permutation "abCde".
+PASS: Permutation "AbCde".
+PASS: Permutation "aBCde".
+PASS: Permutation "ABCde".
+PASS: Permutation "abcDe".
+PASS: Permutation "AbcDe".
+PASS: Permutation "aBcDe".
+PASS: Permutation "ABcDe".
+PASS: Permutation "abCDe".
+PASS: Permutation "AbCDe".
+PASS: Permutation "aBCDe".
+PASS: Permutation "ABCDe".
+PASS: Permutation "abcdE".
+PASS: Permutation "AbcdE".
+PASS: Permutation "aBcdE".
+PASS: Permutation "ABcdE".
+PASS: Permutation "abCdE".
+PASS: Permutation "AbCdE".
+PASS: Permutation "aBCdE".
+PASS: Permutation "ABCdE".
+PASS: Permutation "abcDE".
+PASS: Permutation "AbcDE".
+PASS: Permutation "aBcDE".
+PASS: Permutation "ABcDE".
+PASS: Permutation "abCDE".
+PASS: Permutation "AbCDE".
+PASS: Permutation "aBCDE".
+PASS: Permutation "ABCDE".
+All case permutations of query "abcdex" should match "A B C d ex" in "AxBxCxdxexDxyxEF".
+PASS: Permutation "abcdex".
+PASS: Permutation "Abcdex".
+PASS: Permutation "aBcdex".
+PASS: Permutation "ABcdex".
+PASS: Permutation "abCdex".
+PASS: Permutation "AbCdex".
+PASS: Permutation "aBCdex".
+PASS: Permutation "ABCdex".
+PASS: Permutation "abcDex".
+PASS: Permutation "AbcDex".
+PASS: Permutation "aBcDex".
+PASS: Permutation "ABcDex".
+PASS: Permutation "abCDex".
+PASS: Permutation "AbCDex".
+PASS: Permutation "aBCDex".
+PASS: Permutation "ABCDex".
+PASS: Permutation "abcdEx".
+PASS: Permutation "AbcdEx".
+PASS: Permutation "aBcdEx".
+PASS: Permutation "ABcdEx".
+PASS: Permutation "abCdEx".
+PASS: Permutation "AbCdEx".
+PASS: Permutation "aBCdEx".
+PASS: Permutation "ABCdEx".
+PASS: Permutation "abcDEx".
+PASS: Permutation "AbcDEx".
+PASS: Permutation "aBcDEx".
+PASS: Permutation "ABcDEx".
+PASS: Permutation "abCDEx".
+PASS: Permutation "AbCDEx".
+PASS: Permutation "aBCDEx".
+PASS: Permutation "ABCDEx".
+PASS: Permutation "abcdeX".
+PASS: Permutation "AbcdeX".
+PASS: Permutation "aBcdeX".
+PASS: Permutation "ABcdeX".
+PASS: Permutation "abCdeX".
+PASS: Permutation "AbCdeX".
+PASS: Permutation "aBCdeX".
+PASS: Permutation "ABCdeX".
+PASS: Permutation "abcDeX".
+PASS: Permutation "AbcDeX".
+PASS: Permutation "aBcDeX".
+PASS: Permutation "ABcDeX".
+PASS: Permutation "abCDeX".
+PASS: Permutation "AbCDeX".
+PASS: Permutation "aBCDeX".
+PASS: Permutation "ABCDeX".
+PASS: Permutation "abcdEX".
+PASS: Permutation "AbcdEX".
+PASS: Permutation "aBcdEX".
+PASS: Permutation "ABcdEX".
+PASS: Permutation "abCdEX".
+PASS: Permutation "AbCdEX".
+PASS: Permutation "aBCdEX".
+PASS: Permutation "ABCdEX".
+PASS: Permutation "abcDEX".
+PASS: Permutation "AbcDEX".
+PASS: Permutation "aBcDEX".
+PASS: Permutation "ABcDEX".
+PASS: Permutation "abCDEX".
+PASS: Permutation "AbCDEX".
+PASS: Permutation "aBCDEX".
+PASS: Permutation "ABCDEX".
+All case permutations of query "bc" should match " bC" in "abCd".
+PASS: Permutation "bc".
+PASS: Permutation "Bc".
+PASS: Permutation "bC".
+PASS: Permutation "BC".
+
+-- Running test case: ExecuteQueryGeneralRankings
+PASS: Results should be ranked by descending relevancy.
+
+-- Running test case: ExecuteQueryPositionRankings
+PASS: Results should be ranked by descending relevancy.
+
+-- Running test case: GetMatchingTextRanges
+PASS: Result TextRanges should match the expected ranges.
+PASS: Result TextRanges should match the expected ranges.
+PASS: Result TextRanges should match the expected ranges.
+

Added: trunk/LayoutTests/inspector/unit-tests/resource-query-controller.html (0 => 199143)


--- trunk/LayoutTests/inspector/unit-tests/resource-query-controller.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/unit-tests/resource-query-controller.html	2016-04-07 02:09:07 UTC (rev 199143)
@@ -0,0 +1,328 @@
+<!doctype html>
+<html>
+<head>
+<script src=""
+<script>
+function test()
+{
+    let suite = InspectorTest.createSyncSuite("ResourceQueryController");
+
+    suite.addTestCase({
+        name: "FindSpecialCharacterIndices",
+        description: "Should correctly find special filename characters.",
+        test: function() {
+            let matcher = new WebInspector.ResourceQueryController;
+            let tests = [
+                {
+                    filename: "Abcd",
+                    expected: "^"
+                },
+                {
+                    filename: "ABCDE",
+                    expected: "^"
+                },
+                {
+                    filename: "abcdef",
+                    expected: "^",
+                },
+                {
+                    filename: "abc-def",
+                    expected: "^  ^^",
+                },
+                {
+                    filename: "abc---def",
+                    expected: "^  ^^^^",
+                },
+                {
+                    filename: "a-bc_de.f",
+                    expected: "^^^ ^^ ^^",
+                },
+                {
+                    filename: "AxBxCxDxExFx",
+                    expected: "^ ^ ^ ^ ^ ^",
+                },
+                {
+                    filename: "ab-c_d.ef",
+                    expected: "^ ^^^^^^",
+                },
+                {
+                    filename: "AxBxCxdxexDxyxEF",
+                    expected: "^ ^ ^     ^   ^",
+                },
+            ];
+
+            function createSpecialMask(filename, specialIndices) {
+                let mask = " ".repeat(filename.length);
+                specialIndices.forEach((index) => {
+                    mask = mask.substr(0, index) + "^" + mask.substr(index + 1);
+                });
+                return mask.trim();
+            }
+
+            for (let {filename, expected} of tests) {
+                let actual = createSpecialMask(filename, matcher._findSpecialCharacterIndices(filename));
+                InspectorTest.expectThat(actual === expected, "Result should match expected special indices.");
+            }
+        }
+    });
+
+    suite.addTestCase({
+        name: "ExecuteQueryAgainstNoResources",
+        description: "Should return no results if no resources were added to the controller.",
+        test: function() {
+            let matcher = new WebInspector.ResourceQueryController;
+            let results = matcher.executeQuery("abcde");
+            InspectorTest.expectThat(!results.length, "Should return no results.")
+        }
+    });
+
+    suite.addTestCase({
+        name: "ExecuteWhitespaceQueryOrEmptyQuery",
+        description: "Empty queries and queries containing only whitespace should return no results.",
+        test: function() {
+            const whitespaceCharacters = " \t\r\n";
+            let matcher = new WebInspector.ResourceQueryController;
+            matcher.addResource(new WebInspector.Resource("abcde"));
+
+            for (let query of whitespaceCharacters) {
+                let results = matcher.executeQuery(query);
+                InspectorTest.expectThat(!results.length, "Whitespace query should return no results.");
+            }
+
+            let results = matcher.executeQuery("");
+            InspectorTest.expectThat(!results.length, "Empty query should return no results.");
+        }
+    });
+
+    suite.addTestCase({
+        name: "ExecuteQueryContainingWhitespace",
+        description: "Whitespace within a query should be ignored.",
+        test: function() {
+            let matcher = new WebInspector.ResourceQueryController;
+            matcher.addResource(new WebInspector.Resource("abcde"));
+
+            for (let query of [" abcde", "abcde ", " abcde ", "a b c d e", "a  b  c  d  e"]) {
+                let results = matcher.executeQuery(query);
+                InspectorTest.expectThat(results.length === 1, "Should match one result.");
+            }
+        }
+    });
+
+    suite.addTestCase({
+        name: "ExecuteQueryMatchNone",
+        description: "Should not find a match.",
+        test: function() {
+            let matcher = new WebInspector.ResourceQueryController;
+            let tests = [
+                {query: "abcde", filename: "abcd"},
+                {query: "abcd-", filename: "abcde"},
+                {query: "abcde", filename: "abced"},
+            ];
+
+            for (let {query, filename} of tests) {
+                matcher.reset();
+                matcher.addResource(new WebInspector.Resource(filename));
+                let results = matcher.executeQuery(query);
+                InspectorTest.expectThat(!results.length, `Query "${query}" shouldn't match "${filename}".`);
+            }
+        }
+    });
+
+    suite.addTestCase({
+        name: "ExecuteQueryMatchesExpectedCharacters",
+        description: "Should match the expected query characters.",
+        test: function() {
+            let matcher = new WebInspector.ResourceQueryController;
+            let tests = [
+                {
+                    query: "abcd",
+                    filename: "abcde",
+                    expected: "abcd"
+                },
+                {
+                    query: " abcd",
+                    filename: "abcde",
+                    expected: "abcd"
+                },
+                {
+                    query: "abcd ",
+                    filename: "abcde",
+                    expected: "abcd"
+                },
+                {
+                    query: "a b c d",
+                    filename: "abcde",
+                    expected: "abcd"
+                },
+                {
+                    query: "a-bcde",
+                    filename: "abcde-abcde",
+                    expected: "a    - bcde"
+                },
+                {
+                    query: "abcde",
+                    filename: "AaBbCcDdEe",
+                    expected: "A B C D E"
+                },
+                {
+                    query: "abcde",
+                    filename: "AbcdBcdCdDe",
+                    expected: "A   B  C De"
+                },
+                {
+                    query: "abcdex",
+                    filename: "AxBxCxdxexDxyxEF",
+                    expected: "A B C d ex"
+                },
+                {
+                    query: "bc",
+                    filename: "abCd",
+                    expected: " bC"
+                },
+            ];
+
+            for (let {query, filename, expected} of tests) {
+                matcher.reset();
+                matcher.addResource(new WebInspector.Resource(filename));
+
+                let results = matcher.executeQuery(query);
+                InspectorTest.assert(results.length === 1, "Should return exactly one match.");
+                let actual = results[0].__test_createMatchesMask();
+                InspectorTest.expectThat(actual === expected, `Query "${query}" should match "${expected}" in "${filename}".`);
+            }
+        }
+    });
+
+    // Generator for creating a sequence of case permutations for a string.
+    // Example: "xx" => ["xx", "Xx", "xX", "XX"]
+    function *casePermutations(string) {
+        let permutationCount = Math.pow(2, string.length);
+        InspectorTest.assert(permutationCount !== Infinity, "String length exceeds permutations limit.");
+        if (permutationCount === Infinity)
+            return;
+
+        let index = 0;
+        while (index < permutationCount) {
+            let result = "";
+            for (let i = 0; i < string.length; ++i)
+                result += (index & (1 << i)) ? string[i].toUpperCase() : string[i].toLowerCase();
+
+            index++;
+            yield result;
+        }
+
+        return;
+    }
+
+    suite.addTestCase({
+        name: "ExecuteQueryShouldIgnoreCase",
+        description: "Queries that differ only in case should return identical results.",
+        test: function() {
+            let matcher = new WebInspector.ResourceQueryController;
+            let tests = [
+                {
+                    query: "abcd",
+                    filename: "abcde",
+                    expected: "abcd"
+                },
+                {
+                    query: "abcde",
+                    filename: "AaBbCcDdEe",
+                    expected: "A B C D E"
+                },
+                {
+                    query: "abcde",
+                    filename: "AbcdBcdCdDe",
+                    expected: "A   B  C De"
+                },
+                {
+                    query: "abcdex",
+                    filename: "AxBxCxdxexDxyxEF",
+                    expected: "A B C d ex"
+                },
+                {
+                    query: "bc",
+                    filename: "abCd",
+                    expected: " bC"
+                },
+            ];
+
+            for (let {query, filename, expected} of tests) {
+                InspectorTest.log(`All case permutations of query "${query}" should match "${expected}" in "${filename}".`);
+
+                matcher.reset();
+                matcher.addResource(new WebInspector.Resource(filename));
+
+                for (let queryPermutation of casePermutations(query)) {
+                    let results = matcher.executeQuery(queryPermutation);
+                    let actual = results.length === 1 ? results[0].__test_createMatchesMask() : "";
+                    InspectorTest.expectThat(expected === actual, `Permutation "${queryPermutation}".`);
+                }
+            }
+        }
+    });
+
+    suite.addTestCase({
+        name: "ExecuteQueryGeneralRankings",
+        description: "Check that query results are ranked by descending relevance.",
+        test: function() {
+            let filenames = ["AxBxCxDxEx", "AbCdE", "AbcDe", "AxbcDe", "AxbxcDe", "abcde", "xabcde"]; // Filenames in order of descending rank.
+            let matcher = new WebInspector.ResourceQueryController;
+            filenames.forEach((filename) => matcher.addResource(new WebInspector.Resource(filename)));
+
+            let query = "abcde";
+            let results = matcher.executeQuery(query);
+            let resultFilenames = results.map((filename) => filename.resource.displayName);
+            InspectorTest.expectThat(Object.shallowEqual(resultFilenames, filenames), "Results should be ranked by descending relevancy.");
+        }
+    });
+
+    suite.addTestCase({
+        name: "ExecuteQueryPositionRankings",
+        description: "Check that matches close to the beginning of the filename rank higher.",
+        test: function() {
+            let filenames = ["BxCxDx", "AxBxCxDx", "xxxAxxxBxxxCxxxD", "bcd", "abcd"]; // Filenames in order of descending rank.
+            let matcher = new WebInspector.ResourceQueryController;
+            filenames.forEach((filename) => matcher.addResource(new WebInspector.Resource(filename)));
+
+            let query = "bcd";
+            let results = matcher.executeQuery(query);
+            let resultFilenames = results.map((result) => result.resource.displayName);
+            InspectorTest.expectThat(Object.shallowEqual(resultFilenames, filenames), "Results should be ranked by descending relevancy.");
+        }
+    });
+
+    suite.addTestCase({
+        name: "GetMatchingTextRanges",
+        description: "Check that query result TextRanges are correct.",
+        test: function() {
+            function textRange(start, end) {
+                return new WebInspector.TextRange(0, start, 0, end);
+            }
+
+            let matcher = new WebInspector.ResourceQueryController;
+            let tests = [
+                {filename: "a", ranges: []},
+                {filename: "abcde", ranges: [textRange(0, 5)]},
+                {filename: "AxBxCxDe", ranges: [textRange(0, 1), textRange(2, 3), textRange(4, 5), textRange(6, 8)]},
+            ];
+
+            for (let {filename, ranges} of tests) {
+                matcher.reset();
+                matcher.addResource(new WebInspector.Resource(filename));
+
+                let results = matcher.executeQuery("abcde");
+                let resultTextRanges = results.length ? results[0].matchingTextRanges : [];
+                InspectorTest.expectThat(JSON.stringify(resultTextRanges) === JSON.stringify(ranges), "Result TextRanges should match the expected ranges.");
+            }
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body _onload_="runTest()">
+    <p>Testing WebInspector.ResourceQueryController.</p>
+</body>
+</html>

Modified: trunk/Source/WebInspectorUI/ChangeLog (199142 => 199143)


--- trunk/Source/WebInspectorUI/ChangeLog	2016-04-07 02:07:26 UTC (rev 199142)
+++ trunk/Source/WebInspectorUI/ChangeLog	2016-04-07 02:09:07 UTC (rev 199143)
@@ -1,3 +1,132 @@
+2016-04-06  Matt Baker  <[email protected]>
+
+        Web Inspector: Improve filtering in OpenResourceDialog
+        https://bugs.webkit.org/show_bug.cgi?id=155324
+        <rdar://problem/25094504>
+
+        Reviewed by Joseph Pecoraro and Timothy Hatcher.
+
+        * UserInterface/Base/Utilities.js:
+        (value):
+        Added String methods isLowerCase, isUpperCase, removeWhitespace.
+
+        * UserInterface/Controllers/ResourceQueryController.js: Added.
+        (WebInspector.ResourceQueryController):
+        (WebInspector.ResourceQueryController.prototype.addResource):
+        (WebInspector.ResourceQueryController.prototype.removeResource):
+        Add and remove the resources to be queried.
+
+        (WebInspector.ResourceQueryController.prototype.reset):
+        Reset controller state. Current just clears resources.
+
+        (WebInspector.ResourceQueryController.prototype.executeQuery):
+        Executes a query against the list of resources and returns a list of
+        QueryResult objects, with at most one result per resource, ordered by
+        descending rank.
+
+        The query string is stripped of whitespace characters and lowercased
+        before use. Prior to running the query, resources undergo a one-time
+        pre-processing step to locate special characters.
+
+        (WebInspector.ResourceQueryController.prototype._findQueryMatches.pushMatch):
+        (WebInspector.ResourceQueryController.prototype._findQueryMatches.matchNextSpecialCharacter):
+        (WebInspector.ResourceQueryController.prototype._findQueryMatches.backtrack):
+        (WebInspector.ResourceQueryController.prototype._findQueryMatches):
+        Returns a list of query matches for a single resource, along with metadata
+        which is used to rank the matches. The algorithm attempts to match the
+        entire query, first comparing each query character against "special" characters
+        in the resource (commonly used filename separators, the first character,
+        and camel-case word boundaries).
+
+        If there are remaining query characters after exhausting special characters,
+        regular characters are matched starting from the last matched special
+        character. Failing that, the algorithm attempts to find a match by backtracking.
+        To backtrack, the last match is discarded and the query position decremented.
+        If a special match is now the last match, matching starts again from the
+        next character in the filename after the match. If a normal match is now
+        the last match, keep discarding until a special match is found or no matches
+        remain. The query fails if no matches remain. For example, consider:
+
+           Query: "abcd"
+           Filename: "AxBcdCx"
+
+        The capital A, B, and C are all special characters, and are successfully
+        matched with the first three query characters. Having exhausted the special
+        characters the "d" at the end of the query is compared with the "x" at
+        the end of the filename, and fails to match. Backtracking then kicks in.
+        The last match, "C", is discarded and the search position in the query
+        decremented. The search resumes after the next to last match, "B", and now
+        matches the non-special characters "cd", yielding the following: "A Bcd  ".
+
+        (WebInspector.ResourceQueryController.prototype._findSpecialCharacterIndices):
+        Pre-processing step for resources. Locates the positions of special
+        characters in the resource filename. Special characters are defined as:
+
+           1. The first character
+           2. Common filename separators, and the character immediately following.
+           3. A capital letter that follows a lowercase character.
+
+        * UserInterface/Models/ResourceQueryMatch.js: Added.
+        Helper class used internally by the controller and QueryResult classes.
+        (WebInspector.ResourceQueryMatch):
+        (WebInspector.ResourceQueryMatch.prototype.get type):
+        (WebInspector.ResourceQueryMatch.prototype.get index):
+        (WebInspector.ResourceQueryMatch.prototype.get queryIndex):
+
+        * UserInterface/Models/ResourceQueryResult.js: Added.
+        Holds a resource that matched the executed query.
+        (WebInspector.ResourceQueryResult):
+        (WebInspector.ResourceQueryResult.prototype.get resource):
+        (WebInspector.ResourceQueryResult.prototype.get rank):
+        Ranking relative to other results returned by the query. Used by
+        the ResourceQueryController to sort results.
+
+        (WebInspector.ResourceQueryResult.prototype.get matchingTextRanges):
+        Get TextRanges for matching substrings in the resource display name.
+
+        (WebInspector.ResourceQueryResult.prototype._calculateRank):
+        Calculate the rank of the result. Matches are scored based on the type
+        of match (Special vs. Normal), the location of the match within the filename
+        (matches closer to the beginning are scored higher), and whether the match
+        is adjacent to the previous match.
+
+        Values assigned to each ranking criteria are somewhat arbitrary, and may
+        be fine-tuned over time to produce better results.
+
+        (WebInspector.ResourceQueryResult.prototype._createMatchingTextRanges):
+        (WebInspector.ResourceQueryResult.prototype.__test_createMatchesMask):
+        Test API for visualizing matches. For a result returned from the query
+        "abce", run against a filename "abcde", the mask is "a c e".
+
+        * UserInterface/Main.html:
+        * UserInterface/Test.html:
+        New files.
+
+        * UserInterface/Views/Dialog.js:
+        (WebInspector.Dialog.prototype.dismiss):
+        (WebInspector.Dialog.prototype.didDismissDialog):
+        Add hook for subclasses to perform actions after on dialog dismissal.
+
+        * UserInterface/Views/OpenResourceDialog.js:
+        (WebInspector.OpenResourceDialog):
+        (WebInspector.OpenResourceDialog.prototype._populateResourceTreeOutline.createHighlightedTitleFragment):
+        (WebInspector.OpenResourceDialog.prototype._populateResourceTreeOutline):
+        Add tree elements for each QueryResult returned by the last query, creating
+        titles with contiguous matching query characters wrapped in highlight spans.
+
+        (WebInspector.OpenResourceDialog.prototype.didDismissDialog):
+        Clear resources from the ResourceQueryController.
+        (WebInspector.OpenResourceDialog.prototype.didPresentDialog):
+        Add resources to the ResourceQueryController.
+        (WebInspector.OpenResourceDialog.prototype._updateFilter):
+        Execute the filter text as a resource query.
+
+        * UserInterface/Views/TreeOutline.css:
+        (.tree-outline.large .item .titles): Deleted.
+        Line height too small, hid the bottom border of highlighted matches in
+        tree element title spans. Removing the style had no negative visual impact
+        on the Quick Open or Timelines tree outlines (the only "large" trees).
+
 2016-04-05  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Do not create CodeMirror color/gradient markers in _javascript_ resources

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js (199142 => 199143)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2016-04-07 02:07:26 UTC (rev 199142)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2016-04-07 02:09:07 UTC (rev 199143)
@@ -484,6 +484,22 @@
     }
 });
 
+Object.defineProperty(String.prototype, "isLowerCase",
+{
+    value: function()
+    {
+        return String(this) === this.toLowerCase();
+    }
+});
+
+Object.defineProperty(String.prototype, "isUpperCase",
+{
+    value: function()
+    {
+        return String(this) === this.toUpperCase();
+    }
+});
+
 Object.defineProperty(String.prototype, "trimMiddle",
 {
     value: function(maxLength)
@@ -532,6 +548,14 @@
     }
 });
 
+Object.defineProperty(String.prototype, "removeWhitespace",
+{
+    value: function()
+    {
+        return this.replace(/[\s\xA0]+/g, "");
+    }
+});
+
 Object.defineProperty(String.prototype, "escapeCharacters",
 {
     value: function(chars)

Added: trunk/Source/WebInspectorUI/UserInterface/Controllers/ResourceQueryController.js (0 => 199143)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/ResourceQueryController.js	                        (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/ResourceQueryController.js	2016-04-07 02:09:07 UTC (rev 199143)
@@ -0,0 +1,194 @@
+/*
+ * Copyright (C) 2016 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.ResourceQueryController = class ResourceQueryController extends WebInspector.Object
+{
+    constructor()
+    {
+        super();
+
+        this._resourceDataMap = new Map;
+    }
+
+    // Public
+
+    addResource(resource)
+    {
+        this._resourceDataMap.set(resource, {});
+    }
+
+    removeResource(resource)
+    {
+        this._resourceDataMap.delete(resource);
+    }
+
+    reset()
+    {
+        this._resourceDataMap.clear();
+    }
+
+    executeQuery(query)
+    {
+        if (!query || !this._resourceDataMap.size)
+            return [];
+
+        query = query.removeWhitespace().toLowerCase();
+
+        let results = [];
+        for (let [resource, cachedData] of this._resourceDataMap) {
+            if (!cachedData.searchString) {
+                let displayName = resource.displayName;
+                cachedData.searchString = displayName.toLowerCase();
+                cachedData.specialCharacterIndices = this._findSpecialCharacterIndices(displayName);
+            }
+
+            let matches = this._findQueryMatches(query, cachedData.searchString, cachedData.specialCharacterIndices);
+            if (matches.length)
+                results.push(new WebInspector.ResourceQueryResult(resource, matches));
+        }
+
+        // Resources are sorted in descending order by rank. Resources of equal
+        // rank are sorted by display name.
+        return results.sort((a, b) => {
+            if (a.rank === b.rank)
+                return a.resource.displayName.localeCompare(b.resource.displayName);
+            return b.rank - a.rank;
+        });
+    }
+
+    // Private
+
+    _findQueryMatches(query, searchString, specialCharacterIndices)
+    {
+        let matches = [];
+        let queryIndex = 0;
+        let searchIndex = 0;
+        let specialIndex = 0;
+        let deadBranches = new Array(query.length).fill(Infinity);
+        let type = WebInspector.ResourceQueryMatch.Type.Special;
+
+        function pushMatch(index)
+        {
+            matches.push(new WebInspector.ResourceQueryMatch(type, index, queryIndex));
+            searchIndex = index + 1;
+            queryIndex++;
+        }
+
+        function matchNextSpecialCharacter()
+        {
+            if (specialIndex >= specialCharacterIndices.length)
+                return false;
+
+            let originalSpecialIndex = specialIndex;
+            while (specialIndex < specialCharacterIndices.length) {
+                // Normal character matching can move past special characters,
+                // so advance the special character index if it's before the
+                // current search string position.
+                let index = specialCharacterIndices[specialIndex++];
+                if (index < searchIndex)
+                    continue;
+
+                if (query[queryIndex] === searchString[index]) {
+                    pushMatch(index);
+                    return true;
+                }
+            }
+
+            specialIndex = originalSpecialIndex;
+            return false;
+        }
+
+        function backtrack()
+        {
+            while (matches.length) {
+                queryIndex--;
+
+                let lastMatch = matches.pop();
+                if (lastMatch.type !== WebInspector.ResourceQueryMatch.Type.Special)
+                    continue;
+
+                deadBranches[lastMatch.queryIndex] = lastMatch.index - 1;
+                searchIndex = matches.lastValue ? matches.lastValue.index + 1 : 0;
+                return true;
+            }
+
+            return false;
+        }
+
+        while (queryIndex < query.length && searchIndex < searchString.length) {
+            if (type === WebInspector.ResourceQueryMatch.Type.Special && !matchNextSpecialCharacter())
+                type = WebInspector.ResourceQueryMatch.Type.Normal;
+
+            if (type === WebInspector.ResourceQueryMatch.Type.Normal) {
+                let index = searchString.indexOf(query[queryIndex], searchIndex);
+                if (index >= 0 && index < deadBranches[queryIndex]) {
+                    pushMatch(index);
+                    type = WebInspector.ResourceQueryMatch.Type.Special;
+                } else if (!backtrack())
+                    return [];
+            }
+        }
+
+        if (queryIndex < query.length)
+            return [];
+
+        return matches;
+    }
+
+    _findSpecialCharacterIndices(string)
+    {
+        if (!string.length)
+            return [];
+
+        const filenameSeparators = "_.-";
+
+        // Special characters include the following:
+        // 1. The first character.
+        // 2. Uppercase characters that follow a lowercase letter.
+        // 3. Filename separators and the first character following the separator.
+        let indices = [0];
+
+        for (let i = 1; i < string.length; ++i) {
+            let character = string[i];
+            let isSpecial = false;
+
+            if (filenameSeparators.includes(character))
+                isSpecial = true;
+            else {
+                let previousCharacter = string[i - 1];
+                let previousCharacterIsSeparator = filenameSeparators.includes(previousCharacter);
+                if (previousCharacterIsSeparator)
+                    isSpecial = true;
+                else if (character.isUpperCase() && previousCharacter.isLowerCase())
+                    isSpecial = true;
+            }
+
+            if (isSpecial)
+                indices.push(i);
+        }
+
+        return indices;
+    }
+};

Modified: trunk/Source/WebInspectorUI/UserInterface/Main.html (199142 => 199143)


--- trunk/Source/WebInspectorUI/UserInterface/Main.html	2016-04-07 02:07:26 UTC (rev 199142)
+++ trunk/Source/WebInspectorUI/UserInterface/Main.html	2016-04-07 02:09:07 UTC (rev 199143)
@@ -351,6 +351,8 @@
     <script src=""
     <script src=""
     <script src=""
+    <script src=""
+    <script src=""
     <script src=""
     <script src=""
     <script src=""
@@ -690,6 +692,7 @@
     <script src=""
     <script src=""
     <script src=""
+    <script src=""
     <script src=""
     <script src=""
     <script src=""

Added: trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryMatch.js (0 => 199143)


--- trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryMatch.js	                        (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryMatch.js	2016-04-07 02:09:07 UTC (rev 199143)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2016 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.ResourceQueryMatch = class QueryMatch extends WebInspector.Object
+{
+    constructor(type, index, queryIndex)
+    {
+        super();
+
+        this._type = type;
+        this._index = index;
+        this._queryIndex = queryIndex;
+        this._rank = undefined;
+    }
+
+    // Public
+
+    get type() { return this._type; }
+    get index() { return this._index; }
+    get queryIndex() { return this._queryIndex; }
+};
+
+WebInspector.ResourceQueryMatch.Type = {
+    Normal: Symbol("normal"),
+    Special: Symbol("special")
+};

Added: trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryResult.js (0 => 199143)


--- trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryResult.js	                        (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryResult.js	2016-04-07 02:09:07 UTC (rev 199143)
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2016 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.ResourceQueryResult = class QueryResult extends WebInspector.Object
+{
+    constructor(resource, matches)
+    {
+        console.assert(matches.length, "Query matches list can't be empty.");
+
+        super();
+
+        this._resource = resource;
+        this._matches = matches;
+    }
+
+    // Public
+
+    get resource() { return this._resource; }
+
+    get rank()
+    {
+        if (this._rank === undefined)
+            this._calculateRank();
+
+        return this._rank;
+    }
+
+    get matchingTextRanges()
+    {
+        if (!this._matchingTextRanges)
+            this._matchingTextRanges = this._createMatchingTextRanges();
+
+        return this._matchingTextRanges;
+    }
+
+    // Private
+
+    _calculateRank()
+    {
+        const specialWeight = 50;
+        const normalWeight = 10;
+        const consecutiveMatchWeight = 5;
+
+        this._rank = 0;
+
+        let previousMatch = null;
+        for (let match of this._matches) {
+            this._rank += match.type === WebInspector.ResourceQueryMatch.Type.Special ? specialWeight : normalWeight;
+            if (previousMatch && previousMatch.index === match.index - 1)
+                this._rank += consecutiveMatchWeight;
+
+            previousMatch = match;
+
+            // The match index is deducted from the total rank, so matches that
+            // occur closer to the beginning of the string are ranked higher.
+            this._rank -= match.index;
+        }
+    }
+
+    _createMatchingTextRanges()
+    {
+        if (!this._matches.length)
+            return [];
+
+        let ranges = [];
+        let startIndex = this._matches[0].index;
+        let endIndex = startIndex;
+        for (let i = 1; i < this._matches.length; ++i) {
+            let match = this._matches[i];
+
+            // Increment endIndex for consecutive match.
+            if (match.index === endIndex + 1) {
+                endIndex++;
+                continue;
+            }
+
+            // Begin a new range when a gap between this match and the previous match is found.
+            ranges.push(new WebInspector.TextRange(0, startIndex, 0, endIndex + 1));
+            startIndex = match.index;
+            endIndex = startIndex;
+        }
+
+        ranges.push(new WebInspector.TextRange(0, startIndex, 0, endIndex + 1));
+        return ranges;
+    }
+
+    // Testing
+
+    __test_createMatchesMask()
+    {
+        let filename = this._resource.displayName;
+        let lastIndex = -1;
+        let result = "";
+
+        for (let match of this._matches) {
+            let gap = " ".repeat(match.index - lastIndex - 1);
+            result += gap;
+            result += filename[match.index];
+            lastIndex = match.index;
+        }
+
+        return result;
+    }
+};

Modified: trunk/Source/WebInspectorUI/UserInterface/Test.html (199142 => 199143)


--- trunk/Source/WebInspectorUI/UserInterface/Test.html	2016-04-07 02:07:26 UTC (rev 199142)
+++ trunk/Source/WebInspectorUI/UserInterface/Test.html	2016-04-07 02:09:07 UTC (rev 199143)
@@ -142,6 +142,8 @@
     <script src=""
     <script src=""
     <script src=""
+    <script src=""
+    <script src=""
     <script src=""
     <script src=""
     <script src=""
@@ -180,6 +182,7 @@
 
     <script src=""
     <script src=""
+    <script src=""
     <script src=""
     <script src=""
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/Dialog.js (199142 => 199143)


--- trunk/Source/WebInspectorUI/UserInterface/Views/Dialog.js	2016-04-07 02:07:26 UTC (rev 199142)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/Dialog.js	2016-04-07 02:09:07 UTC (rev 199143)
@@ -82,10 +82,17 @@
             this._delegate.dialogWasDismissed(this);
 
         this._dismissing = false;
+
+        this.didDismissDialog();
     }
 
     // Protected
 
+    didDismissDialog()
+    {
+        // Implemented by subclasses.
+    }
+
     didPresetDialog()
     {
         // Implemented by subclasses.

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/OpenResourceDialog.js (199142 => 199143)


--- trunk/Source/WebInspectorUI/UserInterface/Views/OpenResourceDialog.js	2016-04-07 02:07:26 UTC (rev 199142)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/OpenResourceDialog.js	2016-04-07 02:09:07 UTC (rev 199143)
@@ -58,14 +58,35 @@
 
         this.element.appendChild(this._treeOutline.element);
 
-        this._resources = [];
-        this._filteredResources = [];
+        this._queryController = new WebInspector.ResourceQueryController;
+        this._filteredResults = [];
     }
 
     // Protected
 
     _populateResourceTreeOutline()
     {
+        function createHighlightedTitleFragment(title, highlightTextRanges)
+        {
+            let titleFragment = document.createDocumentFragment();
+            let lastIndex = 0;
+            for (let textRange of highlightTextRanges) {
+                if (textRange.startColumn > lastIndex)
+                    titleFragment.append(title.substring(lastIndex, textRange.startColumn));
+
+                let highlightSpan = document.createElement("span");
+                highlightSpan.classList.add("highlighted");
+                highlightSpan.append(title.substring(textRange.startColumn, textRange.endColumn));
+                titleFragment.append(highlightSpan);
+                lastIndex = textRange.endColumn;
+            }
+
+            if (lastIndex < title.length)
+                titleFragment.append(title.substring(lastIndex, title.length));
+
+            return titleFragment;
+        }
+
         function createTreeElement(representedObject)
         {
             let treeElement = null;
@@ -80,14 +101,16 @@
             return treeElement;
         }
 
-        for (let resource of this._filteredResources) {
+        for (let result of this._filteredResults) {
+            let resource = result.resource;
+            if (this._treeOutline.findTreeElement(resource))
+                continue;
+
             let treeElement = createTreeElement(resource);
             if (!treeElement)
                 continue;
 
-            if (this._treeOutline.findTreeElement(resource))
-                continue;
-
+            treeElement.mainTitle = createHighlightedTitleFragment(resource.displayName, result.matchingTextRanges);
             this._treeOutline.appendChild(treeElement);
         }
 
@@ -95,6 +118,11 @@
             this._treeOutline.children[0].select(true, false, true, true);
     }
 
+    didDismissDialog()
+    {
+        this._queryController.reset();
+    }
+
     didPresentDialog()
     {
         this._inputElement.focus();
@@ -103,11 +131,12 @@
         let frames = [WebInspector.frameResourceManager.mainFrame];
         while (frames.length) {
             let frame = frames.shift();
-            for (let resource of frame.resources) {
+            let resources = [frame.mainResource].concat(frame.resources);
+            for (let resource of resources) {
                 if (!this.representedObjectIsValid(resource))
                     continue;
 
-                this._resources.push(resource);
+                this._queryController.addResource(resource);
             }
 
             frames = frames.concat(frame.childFrames);
@@ -193,7 +222,7 @@
 
     _updateFilter()
     {
-        this._filteredResources = [];
+        this._filteredResults = [];
         this._treeOutline.hidden = true;
         this._treeOutline.removeChildren();
 
@@ -201,28 +230,8 @@
         if (!filterText)
             return;
 
-        // FIXME: <https://webkit.org/b/155324> Web Inspector: Improve filtering in OpenResourceDialog
-        let filters = [simpleGlobStringToRegExp(filterText)];
+        this._filteredResults = this._queryController.executeQuery(filterText);
 
-        for (let resource of this._resources) {
-            for (let i = 0; i < filters.length; ++i) {
-                if (!filters[i].test(resource.displayName))
-                    continue;
-
-                resource.__weight = filters.length - i;
-                this._filteredResources.push(resource);
-                break;
-            }
-        }
-
-        // Sort filtered resources by weight, then alphabetically.
-        this._filteredResources.sort((a, b) => {
-            if (a.__weight === b.__weight)
-                return a.displayName.localeCompare(b.displayName);
-
-            return b.__weight - a.__weight;
-        });
-
         this._populateResourceTreeOutline();
         if (this._treeOutline.children.length)
             this._treeOutline.hidden = false;

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TreeOutline.css (199142 => 199143)


--- trunk/Source/WebInspectorUI/UserInterface/Views/TreeOutline.css	2016-04-07 02:07:26 UTC (rev 199142)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TreeOutline.css	2016-04-07 02:09:07 UTC (rev 199143)
@@ -183,7 +183,6 @@
 
 .tree-outline.large .item .titles {
     top: 10px;
-    line-height: 11px;
 }
 
 .tree-outline .item .highlighted {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to