| 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. |
| 11 * | 11 * |
| 12 * The simple object defined in this javascript file listens for | 12 * The simple object defined in this javascript file listens for |
| 13 * certain events on omnibox.html, sends (when appropriate) the | 13 * certain events on omnibox.html, sends (when appropriate) the |
| 14 * input text to C++ code to start the omnibox autcomplete controller | 14 * input text to C++ code to start the omnibox autcomplete controller |
| 15 * working, and listens from callbacks from the C++ code saying that | 15 * working, and listens from callbacks from the C++ code saying that |
| 16 * results are available. When results (possibly intermediate ones) | 16 * results are available. When results (possibly intermediate ones) |
| 17 * are available, the Javascript formats them and displays them. | 17 * are available, the Javascript formats them and displays them. |
| 18 */ | 18 */ |
| 19 cr.define('omniboxDebug', function() { | 19 cr.define('omniboxDebug', function() { |
| 20 'use strict'; | 20 'use strict'; |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * Register our event handlers. | 23 * Register our event handlers. |
| 24 */ | 24 */ |
| 25 function initialize() { | 25 function initialize() { |
| 26 $('omnibox-input-form').addEventListener( | 26 $('omnibox-input-form').addEventListener( |
| 27 'submit', startOmniboxQuery, false); | 27 'submit', startOmniboxQuery, false); |
| 28 $('prevent-inline-autocomplete').addEventListener( | 28 $('prevent-inline-autocomplete').addEventListener( |
| 29 'change', startOmniboxQuery); | 29 'change', startOmniboxQuery); |
| 30 $('prefer-keyword').addEventListener('change', startOmniboxQuery); |
| 30 $('show-details').addEventListener('change', refresh); | 31 $('show-details').addEventListener('change', refresh); |
| 31 $('show-incomplete-results').addEventListener('change', refresh); | 32 $('show-incomplete-results').addEventListener('change', refresh); |
| 32 $('show-all-providers').addEventListener('change', refresh); | 33 $('show-all-providers').addEventListener('change', refresh); |
| 33 } | 34 } |
| 34 | 35 |
| 35 /** | 36 /** |
| 36 * @type {Array.<Object>} an array of all autocomplete results we've seen | 37 * @type {Array.<Object>} an array of all autocomplete results we've seen |
| 37 * for this query. We append to this list once for every call to | 38 * for this query. We append to this list once for every call to |
| 38 * handleNewAutocompleteResult. For details on the structure of | 39 * handleNewAutocompleteResult. For details on the structure of |
| 39 * the object inside, see the comments by addResultToOutput. | 40 * the object inside, see the comments by addResultToOutput. |
| 40 */ | 41 */ |
| 41 var progressiveAutocompleteResults = []; | 42 var progressiveAutocompleteResults = []; |
| 42 | 43 |
| 43 /** | 44 /** |
| 44 * @type {number} the value for cursor position we sent with the most | 45 * @type {number} the value for cursor position we sent with the most |
| 45 * recent request. We need to remember this in order to display it | 46 * recent request. We need to remember this in order to display it |
| 46 * in the output; otherwise it's hard or impossible to determine | 47 * in the output; otherwise it's hard or impossible to determine |
| 47 * from screen captures or print-to-PDFs. | 48 * from screen captures or print-to-PDFs. |
| 48 */ | 49 */ |
| 49 var cursorPositionUsed = -1; | 50 var cursorPositionUsed = -1; |
| 50 | 51 |
| 51 /** | 52 /** |
| 52 * Extracts the input text from the text field and sends it to the | 53 * Extracts the input text from the text field and sends it to the |
| 53 * C++ portion of chrome to handle. The C++ code will iteratively | 54 * C++ portion of chrome to handle. The C++ code will iteratively |
| 54 * call handleNewAutocompleteResult as results come in. | 55 * call handleNewAutocompleteResult as results come in. |
| 55 */ | 56 */ |
| 56 function startOmniboxQuery(event) { | 57 function startOmniboxQuery(event) { |
| 57 // First, clear the results of past calls (if any). | 58 // First, clear the results of past calls (if any). |
| 58 progressiveAutocompleteResults = []; | 59 progressiveAutocompleteResults = []; |
| 59 // Then, call chrome with a three-element list: | 60 // Then, call chrome with a four-element list: |
| 60 // - first element: the value in the text box | 61 // - first element: the value in the text box |
| 61 // - second element: the value of prevent-inline-autocomplete | 62 // - second element: the location of the cursor in the text box |
| 62 // - third element: the location of the cursor in the text box | 63 // - third element: the value of prevent-inline-autocomplete |
| 64 // - forth element: the value of prefer-keyword |
| 63 cursorPositionUsed = $('input-text').selectionEnd; | 65 cursorPositionUsed = $('input-text').selectionEnd; |
| 64 chrome.send('startOmniboxQuery', [ | 66 chrome.send('startOmniboxQuery', [ |
| 65 $('input-text').value, | 67 $('input-text').value, |
| 68 cursorPositionUsed, |
| 66 $('prevent-inline-autocomplete').checked, | 69 $('prevent-inline-autocomplete').checked, |
| 67 cursorPositionUsed]); | 70 $('prefer-keyword').checked]); |
| 68 // Cancel the submit action. i.e., don't submit the form. (We handle | 71 // Cancel the submit action. i.e., don't submit the form. (We handle |
| 69 // display the results solely with Javascript.) | 72 // display the results solely with Javascript.) |
| 70 event.preventDefault(); | 73 event.preventDefault(); |
| 71 } | 74 } |
| 72 | 75 |
| 73 /** | 76 /** |
| 74 * Returns a simple object with information about how to display an | 77 * Returns a simple object with information about how to display an |
| 75 * autocomplete result data field. | 78 * autocomplete result data field. |
| 76 * @param {string} header the label for the top of the column/table. | 79 * @param {string} header the label for the top of the column/table. |
| 77 * @param {string} urlLabelForHeader the URL that the header should point | 80 * @param {string} urlLabelForHeader the URL that the header should point |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 } | 436 } |
| 434 | 437 |
| 435 return { | 438 return { |
| 436 initialize: initialize, | 439 initialize: initialize, |
| 437 startOmniboxQuery: startOmniboxQuery, | 440 startOmniboxQuery: startOmniboxQuery, |
| 438 handleNewAutocompleteResult: handleNewAutocompleteResult | 441 handleNewAutocompleteResult: handleNewAutocompleteResult |
| 439 }; | 442 }; |
| 440 }); | 443 }); |
| 441 | 444 |
| 442 document.addEventListener('DOMContentLoaded', omniboxDebug.initialize); | 445 document.addEventListener('DOMContentLoaded', omniboxDebug.initialize); |
| OLD | NEW |