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.View} view
33 * @param {!WebInspector.UISourceCode} uiSourceCode
34 * @param {function(number, number)} selectItemCallback
36 WebInspector.StyleSheetOutlineDialog = function(view, uiSourceCode, selectItemCallback)
38 WebInspector.SelectionDialogContentProvider.call(this);
39 this._selectItemCallback = selectItemCallback;
42 this._uiSourceCode = uiSourceCode;
47 * @param {!WebInspector.View} view
48 * @param {!WebInspector.UISourceCode} uiSourceCode
49 * @param {function(number, number)} selectItemCallback
51 WebInspector.StyleSheetOutlineDialog.show = function(view, uiSourceCode, selectItemCallback)
53 if (WebInspector.Dialog.currentInstance())
55 var delegate = new WebInspector.StyleSheetOutlineDialog(view, uiSourceCode, selectItemCallback);
56 var filteredItemSelectionDialog = new WebInspector.FilteredItemSelectionDialog(delegate);
57 WebInspector.Dialog.show(view.element, filteredItemSelectionDialog);
60 WebInspector.StyleSheetOutlineDialog.prototype = {
66 return this._rules.length;
70 * @param {number} itemIndex
73 itemKeyAt: function(itemIndex)
75 return this._rules[itemIndex].selectorText;
79 * @param {number} itemIndex
80 * @param {string} query
83 itemScoreAt: function(itemIndex, query)
85 var rule = this._rules[itemIndex];
86 return -rule.rawLocation.lineNumber;
90 * @param {number} itemIndex
91 * @param {string} query
92 * @param {!Element} titleElement
93 * @param {!Element} subtitleElement
95 renderItem: function(itemIndex, query, titleElement, subtitleElement)
97 var rule = this._rules[itemIndex];
98 titleElement.textContent = rule.selectorText;
99 this.highlightRanges(titleElement, query);
100 subtitleElement.textContent = ":" + (rule.rawLocation.lineNumber + 1);
103 _requestItems: function()
106 * @param {?Protocol.Error} error
107 * @param {!Array.<!CSSAgent.CSSStyleSheetHeader>} infos
108 * @this {WebInspector.StyleSheetOutlineDialog}
110 function didGetAllStyleSheets(error, infos)
115 for (var i = 0; i < infos.length; ++i) {
117 if (info.sourceURL === this._uiSourceCode.url) {
118 WebInspector.CSSStyleSheet.createForId(info.styleSheetId, didGetStyleSheet.bind(this));
124 CSSAgent.getAllStyleSheets(didGetAllStyleSheets.bind(this));
127 * @param {?WebInspector.CSSStyleSheet} styleSheet
128 * @this {WebInspector.StyleSheetOutlineDialog}
130 function didGetStyleSheet(styleSheet)
135 this._rules = styleSheet.rules;
141 * @param {number} itemIndex
142 * @param {string} promptValue
144 selectItem: function(itemIndex, promptValue)
146 var rule = this._rules[itemIndex];
147 var lineNumber = rule.rawLocation.lineNumber;
148 if (!isNaN(lineNumber) && lineNumber >= 0)
149 this._selectItemCallback(lineNumber, rule.rawLocation.columnNumber);
152 __proto__: WebInspector.SelectionDialogContentProvider.prototype