2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * @extends {WebInspector.SelectionDialogContentProvider}
32 * @param {!WebInspector.UISourceCode} uiSourceCode
33 * @param {function(number, number)} selectItemCallback
35 WebInspector.StyleSheetOutlineDialog = function(uiSourceCode, selectItemCallback)
37 WebInspector.SelectionDialogContentProvider.call(this);
38 this._selectItemCallback = selectItemCallback;
40 this._outlineWorker = new Worker("ScriptFormatterWorker.js");
41 this._outlineWorker.onmessage = this._didBuildOutlineChunk.bind(this);
42 this._outlineWorker.postMessage({ method: "cssOutline", params: { content: uiSourceCode.workingCopy() } });
46 * @param {!WebInspector.View} view
47 * @param {!WebInspector.UISourceCode} uiSourceCode
48 * @param {function(number, number)} selectItemCallback
50 WebInspector.StyleSheetOutlineDialog.show = function(view, uiSourceCode, selectItemCallback)
52 if (WebInspector.Dialog.currentInstance())
54 var delegate = new WebInspector.StyleSheetOutlineDialog(uiSourceCode, selectItemCallback);
55 var filteredItemSelectionDialog = new WebInspector.FilteredItemSelectionDialog(delegate);
56 WebInspector.Dialog.show(view.element, filteredItemSelectionDialog);
59 WebInspector.StyleSheetOutlineDialog.prototype = {
61 * @param {!MessageEvent} event
63 _didBuildOutlineChunk: function(event)
65 var data = /** @type {!WebInspector.StyleSheetOutlineDialog.MessageEventData} */ (event.data);
66 var chunk = data.chunk;
67 for (var i = 0; i < chunk.length; ++i)
68 this._rules.push(chunk[i]);
70 if (data.total === data.index)
81 return this._rules.length;
85 * @param {number} itemIndex
88 itemKeyAt: function(itemIndex)
90 var rule = this._rules[itemIndex];
91 return rule.selectorText || rule.atRule;
95 * @param {number} itemIndex
96 * @param {string} query
99 itemScoreAt: function(itemIndex, query)
101 var rule = this._rules[itemIndex];
102 return -rule.lineNumber;
106 * @param {number} itemIndex
107 * @param {string} query
108 * @param {!Element} titleElement
109 * @param {!Element} subtitleElement
111 renderItem: function(itemIndex, query, titleElement, subtitleElement)
113 var rule = this._rules[itemIndex];
114 titleElement.textContent = rule.selectorText || rule.atRule;
115 this.highlightRanges(titleElement, query);
116 subtitleElement.textContent = ":" + (rule.lineNumber + 1);
120 * @param {number} itemIndex
121 * @param {string} promptValue
123 selectItem: function(itemIndex, promptValue)
125 var rule = this._rules[itemIndex];
126 var lineNumber = rule.lineNumber;
127 if (!isNaN(lineNumber) && lineNumber >= 0)
128 this._selectItemCallback(lineNumber, rule.columnNumber);
133 if (this._outlineWorker) {
134 this._outlineWorker.terminate();
135 delete this._outlineWorker;
139 __proto__: WebInspector.SelectionDialogContentProvider.prototype
143 * @typedef {{index: number, total: number, chunk: !Array.<!{selectorText: ?string, atRule: ?string, lineNumber: number, columnNumber: number}>}}
145 WebInspector.StyleSheetOutlineDialog.MessageEventData;