OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Javascript for omnibox.html, served from chrome://omnibox/ | 6 * Javascript for omnibox.html, served from chrome://omnibox/ |
7 * This is used to debug omnibox ranking. The user enters some text | 7 * This is used to debug omnibox ranking. The user enters some text |
8 * into a box, submits it, and then sees lots of debug information | 8 * into a box, submits it, and then sees lots of debug information |
9 * from the autocompleter that shows what omnibox would do with that | 9 * from the autocompleter that shows what omnibox would do with that |
10 * input. | 10 * input. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 /** | 56 /** |
57 * Returns a simple object with information about how to display an | 57 * Returns a simple object with information about how to display an |
58 * autocomplete result data field. | 58 * autocomplete result data field. |
59 * @param {string} header the label for the top of the column/table. | 59 * @param {string} header the label for the top of the column/table. |
60 * @param {string} urlLabelForHeader the URL that the header should point | 60 * @param {string} urlLabelForHeader the URL that the header should point |
61 * to (if non-empty). | 61 * to (if non-empty). |
62 * @param {string} propertyName the name of the property in the autocomplete | 62 * @param {string} propertyName the name of the property in the autocomplete |
63 * result record that we lookup. | 63 * result record that we lookup. |
64 * @param {boolean} displayAlways whether the property should be displayed | 64 * @param {boolean} displayAlways whether the property should be displayed |
65 * regardless of whether we're in detailed more. | 65 * regardless of whether we're in detailed more. |
66 * @param {string} tooltip a description of the property that will be | |
67 * presented as a tooltip when the mouse is hovered over the column title. | |
66 * @constructor | 68 * @constructor |
67 */ | 69 */ |
68 function PresentationInfoRecord(header, url, propertyName, displayAlways) { | 70 function PresentationInfoRecord(header, url, propertyName, displayAlways, |
71 tooltip) { | |
69 this.header = header; | 72 this.header = header; |
70 this.urlLabelForHeader = url; | 73 this.urlLabelForHeader = url; |
71 this.propertyName = propertyName; | 74 this.propertyName = propertyName; |
72 this.displayAlways = displayAlways; | 75 this.displayAlways = displayAlways; |
76 this.tooltip = tooltip; | |
73 } | 77 } |
74 | 78 |
75 /** | 79 /** |
76 * A constant that's used to decide what autocomplete result | 80 * A constant that's used to decide what autocomplete result |
77 * properties to output in what order. This is an array of | 81 * properties to output in what order. This is an array of |
78 * PresentationInfoRecord() objects; for details see that | 82 * PresentationInfoRecord() objects; for details see that |
79 * function. | 83 * function. |
80 * @type {Array.<Object>} | 84 * @type {Array.<Object>} |
81 * @const | 85 * @const |
82 */ | 86 */ |
83 var PROPERTY_OUTPUT_ORDER = [ | 87 var PROPERTY_OUTPUT_ORDER = [ |
84 new PresentationInfoRecord('Provider', '', 'provider_name', true), | 88 new PresentationInfoRecord('Provider', '', 'provider_name', true, |
85 new PresentationInfoRecord('Type', '', 'type', true), | 89 'The AutocompleteProvider suggesting this result.'), |
86 new PresentationInfoRecord('Relevance', '', 'relevance', true), | 90 new PresentationInfoRecord('Type', '', 'type', true, |
87 new PresentationInfoRecord('Contents', '', 'contents', true), | 91 'The type of the result.'), |
88 new PresentationInfoRecord('Starred', '', 'starred', false), | 92 new PresentationInfoRecord('Relevance', '', 'relevance', true, |
93 'The result score. Higher is more relevant.'), | |
94 new PresentationInfoRecord('Contents', '', 'contents', true, | |
95 'The text that is presented identifying the result.'), | |
96 new PresentationInfoRecord('Starred', '', 'starred', false, | |
97 'A green checkmark indicates that the result has been bookmarked.'), | |
89 new PresentationInfoRecord( | 98 new PresentationInfoRecord( |
90 'Is History What You Typed Match', '', | 99 'HWYT', '', 'is_history_what_you_typed_match', false, |
91 'is_history_what_you_typed_match', false), | 100 'A green checkmark indicates that the result is an History What You ' + |
92 new PresentationInfoRecord('Description', '', 'description', false), | 101 'Typed Match'), |
93 new PresentationInfoRecord('URL', '', 'destination_url', true), | 102 new PresentationInfoRecord('Description', '', 'description', false, |
94 new PresentationInfoRecord('Fill Into Edit', '', 'fill_into_edit', false), | 103 'The page title of the result.'), |
104 new PresentationInfoRecord('URL', '', 'destination_url', true, | |
105 'The URL for the result.'), | |
106 new PresentationInfoRecord('Fill Into Edit', '', 'fill_into_edit', false, | |
107 'The text shown in the omnibox when the result is selected.'), | |
95 new PresentationInfoRecord( | 108 new PresentationInfoRecord( |
96 'Inline Autocomplete Offset', '', 'inline_autocomplete_offset', false), | 109 'IAO', '', 'inline_autocomplete_offset', false, |
97 new PresentationInfoRecord('Deletable', '', 'deletable', false), | 110 'The Inline Autocomplete Offset.'), |
98 new PresentationInfoRecord('From Previous', '', 'from_previous', false), | 111 new PresentationInfoRecord('Del', '', 'deletable', false, |
112 'A green checkmark indicates that the results can be deleted from ' + | |
113 'the visit history.'), | |
114 new PresentationInfoRecord('Prev', '', 'from_previous', false, ''), | |
99 new PresentationInfoRecord( | 115 new PresentationInfoRecord( |
100 'Transition Type', | 116 'Tran', |
101 'http://code.google.com/codesearch#OAMlx_jo-ck/src/content/public/' + | 117 'http://code.google.com/codesearch#OAMlx_jo-ck/src/content/public/' + |
102 'common/page_transition_types.h&exact_package=chromium&l=24', | 118 'common/page_transition_types.h&exact_package=chromium&l=24', |
103 'transition', false), | 119 'transition', false, |
120 'How the user got to the result.'), | |
104 new PresentationInfoRecord( | 121 new PresentationInfoRecord( |
105 'Is This Provider Done', '', 'provider_done', false), | 122 'Done', '', 'provider_done', false, |
123 'A green checkmark indicates that the provider is done looking for ' + | |
124 'more results.'), | |
106 new PresentationInfoRecord( | 125 new PresentationInfoRecord( |
107 'Template URL', '', 'template_url', false), | 126 'Template URL', '', 'template_url', false, ''), |
108 new PresentationInfoRecord( | 127 new PresentationInfoRecord( |
109 'Associated Keyword', '', 'associated_keyword', false) | 128 'Associated Keyword', '', 'associated_keyword', false, ''), |
129 new PresentationInfoRecord( | |
130 'Diagnostics', '', 'diagnostics', false, | |
131 'Provider-specific information about the result.') | |
110 ]; | 132 ]; |
111 | 133 |
112 /** | 134 /** |
113 * Returns an HTML Element of type table row that contains the | 135 * Returns an HTML Element of type table row that contains the |
114 * headers we'll use for labeling the columns. If we're in | 136 * headers we'll use for labeling the columns. If we're in |
115 * detailed_mode, we use all the headers. If not, we only use ones | 137 * detailed_mode, we use all the headers. If not, we only use ones |
116 * marked displayAlways. | 138 * marked displayAlways. |
117 */ | 139 */ |
118 function createAutocompleteResultTableHeader() { | 140 function createAutocompleteResultTableHeader() { |
119 var row = document.createElement('tr'); | 141 var row = document.createElement('tr'); |
120 var inDetailedMode = $('show-details').checked; | 142 var inDetailedMode = $('show-details').checked; |
121 for (var i = 0; i < PROPERTY_OUTPUT_ORDER.length; i++) { | 143 for (var i = 0; i < PROPERTY_OUTPUT_ORDER.length; i++) { |
122 if (inDetailedMode || PROPERTY_OUTPUT_ORDER[i].displayAlways) { | 144 if (inDetailedMode || PROPERTY_OUTPUT_ORDER[i].displayAlways) { |
123 var headerCell = document.createElement('th'); | 145 var headerCell = document.createElement('th'); |
124 if (PROPERTY_OUTPUT_ORDER[i].urlLabelForHeader != '') { | 146 if (PROPERTY_OUTPUT_ORDER[i].urlLabelForHeader != '') { |
125 // Wrap header text in URL. | 147 // Wrap header text in URL. |
126 var linkNode = document.createElement('a'); | 148 var linkNode = document.createElement('a'); |
127 linkNode.href = PROPERTY_OUTPUT_ORDER[i].urlLabelForHeader; | 149 linkNode.href = PROPERTY_OUTPUT_ORDER[i].urlLabelForHeader; |
128 linkNode.textContent = PROPERTY_OUTPUT_ORDER[i].header; | 150 linkNode.textContent = PROPERTY_OUTPUT_ORDER[i].header; |
129 headerCell.appendChild(linkNode); | 151 headerCell.appendChild(linkNode); |
130 } else { | 152 } else { |
131 // Output header text without a URL. | 153 // Output header text without a URL. |
132 headerCell.textContent = PROPERTY_OUTPUT_ORDER[i].header; | 154 headerCell.textContent = PROPERTY_OUTPUT_ORDER[i].header; |
133 headerCell.className = 'table-header'; | 155 headerCell.className = 'table-header'; |
156 headerCell.title = PROPERTY_OUTPUT_ORDER[i].tooltip; | |
134 } | 157 } |
135 row.appendChild(headerCell); | 158 row.appendChild(headerCell); |
136 } | 159 } |
137 } | 160 } |
138 return row; | 161 return row; |
139 } | 162 } |
140 | 163 |
141 /** | 164 /** |
142 * @param {Object} autocompleteSuggestion the particular autocomplete | 165 * @param {Object} autocompleteSuggestion the particular autocomplete |
143 * suggestion we're in the process of displaying. | 166 * suggestion we're in the process of displaying. |
144 * @param {string} propertyName the particular property of the autocomplete | 167 * @param {string} propertyName the particular property of the autocomplete |
145 * suggestion that should go in this cell. | 168 * suggestion that should go in this cell. |
146 * @return {HTMLTableCellElement} that contains the value within this | 169 * @return {HTMLTableCellElement} that contains the value within this |
147 * autocompleteSuggestion associated with propertyName. | 170 * autocompleteSuggestion associated with propertyName. |
148 */ | 171 */ |
149 function createCellForPropertyAndRemoveProperty(autocompleteSuggestion, | 172 function createCellForPropertyAndRemoveProperty(autocompleteSuggestion, |
150 propertyName) { | 173 propertyName) { |
151 var cell = document.createElement('td'); | 174 var cell = document.createElement('td'); |
152 if (propertyName in autocompleteSuggestion) { | 175 if (propertyName in autocompleteSuggestion) { |
153 if (typeof autocompleteSuggestion[propertyName] == 'boolean') { | 176 if (propertyName == 'diagnostics') { |
177 // |diagnostics| embeds a two-column table of provider-specific data | |
178 // within this cell. | |
179 var diagnostic_table = document.createElement('table'); | |
arv (Not doing code reviews)
2012/07/26 21:02:00
no underscores in js
mrossetti
2012/07/26 23:17:13
Done throughout.
| |
180 for (var diagnostic_key in autocompleteSuggestion[propertyName]) { | |
181 var diagnostic_row = document.createElement('tr'); | |
182 var property_cell = document.createElement('td'); | |
183 property_cell.textContent = diagnostic_key + ':'; | |
184 property_cell.className = 'diagnostic-property'; | |
185 diagnostic_row.appendChild(property_cell); | |
186 var value_cell = document.createElement('td'); | |
187 value_cell.textContent = | |
188 autocompleteSuggestion[propertyName][diagnostic_key]; | |
189 value_cell.className = 'diagnostic-value'; | |
190 diagnostic_row.appendChild(value_cell); | |
191 diagnostic_table.appendChild(diagnostic_row); | |
192 } | |
193 cell.appendChild(diagnostic_table); | |
194 } else if (typeof autocompleteSuggestion[propertyName] == 'boolean') { | |
154 // If this is a boolean, display a checkmark or an X instead of | 195 // If this is a boolean, display a checkmark or an X instead of |
155 // the strings true or false. | 196 // the strings true or false. |
156 if (autocompleteSuggestion[propertyName]) { | 197 if (autocompleteSuggestion[propertyName]) { |
157 cell.className = 'check-mark'; | 198 cell.className = 'check-mark'; |
158 cell.textContent = '✔'; | 199 cell.textContent = '✔'; |
159 } else { | 200 } else { |
160 cell.className = 'x-mark'; | 201 cell.className = 'x-mark'; |
161 cell.textContent = '✗'; | 202 cell.textContent = '✗'; |
162 } | 203 } |
163 } else { | 204 } else { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 } | 406 } |
366 | 407 |
367 return { | 408 return { |
368 initialize: initialize, | 409 initialize: initialize, |
369 startOmniboxQuery: startOmniboxQuery, | 410 startOmniboxQuery: startOmniboxQuery, |
370 handleNewAutocompleteResult: handleNewAutocompleteResult | 411 handleNewAutocompleteResult: handleNewAutocompleteResult |
371 }; | 412 }; |
372 }); | 413 }); |
373 | 414 |
374 document.addEventListener('DOMContentLoaded', omniboxDebug.initialize); | 415 document.addEventListener('DOMContentLoaded', omniboxDebug.initialize); |
OLD | NEW |