OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // ========================================================== |
| 6 // Enums. |
| 7 // ========================================================== |
| 8 /** |
| 9 * Possible behaviors for navigateContentWindow. |
| 10 * @enum {number} |
| 11 * @private |
| 12 */ |
| 13 var WindowOpenDisposition_ = { |
| 14 CURRENT_TAB: 1, |
| 15 NEW_BACKGROUND_TAB: 2 |
| 16 }; |
| 17 |
| 18 /** |
| 19 * The JavaScript button event value for a middle click. |
| 20 * @type {number} |
| 21 * @private |
| 22 * @const |
| 23 */ |
| 24 var MIDDLE_MOUSE_BUTTON_ = 1; |
| 25 |
5 // ============================================================================= | 26 // ============================================================================= |
6 // Util functions | 27 // Util functions |
7 // ============================================================================= | 28 // ============================================================================= |
8 | 29 |
9 /** | 30 /** |
10 * The maximum number of suggestions to show. | 31 * The maximum number of suggestions to show. |
11 * @type {number} | 32 * @type {number} |
12 * @const | 33 * @const |
13 */ | 34 */ |
14 var MAX_SUGGESTIONS_TO_SHOW = 5; | 35 var MAX_SUGGESTIONS_TO_SHOW = 5; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 suggestionDiv.classList.add('suggestion'); | 67 suggestionDiv.classList.add('suggestion'); |
47 if (select) | 68 if (select) |
48 suggestionDiv.classList.add('selected'); | 69 suggestionDiv.classList.add('selected'); |
49 | 70 |
50 var contentsContainer = document.createElement('div'); | 71 var contentsContainer = document.createElement('div'); |
51 contentsContainer.className = 'contents'; | 72 contentsContainer.className = 'contents'; |
52 var contents = suggestion.combinedNode; | 73 var contents = suggestion.combinedNode; |
53 contentsContainer.appendChild(contents); | 74 contentsContainer.appendChild(contents); |
54 suggestionDiv.appendChild(contentsContainer); | 75 suggestionDiv.appendChild(contentsContainer); |
55 var restrictedId = suggestion.rid; | 76 var restrictedId = suggestion.rid; |
56 suggestionDiv.onclick = function() { | 77 suggestionDiv.onclick = function(event) { |
57 handleSuggestionClick(restrictedId); | 78 handleSuggestionClick(restrictedId, event); |
58 }; | 79 }; |
59 | 80 |
60 restrictedIds.push(restrictedId); | 81 restrictedIds.push(restrictedId); |
61 box.appendChild(suggestionDiv); | 82 box.appendChild(suggestionDiv); |
62 } | 83 } |
63 | 84 |
64 /** | 85 /** |
65 * Renders the input suggestions. | 86 * Renders the input suggestions. |
66 * @param {Array} nativeSuggestions An array of native suggestions to render. | 87 * @param {Array} nativeSuggestions An array of native suggestions to render. |
67 */ | 88 */ |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 ' -webkit-margin-end: ' + apiHandle.endMargin + 'px;' + | 213 ' -webkit-margin-end: ' + apiHandle.endMargin + 'px;' + |
193 ' font: ' + apiHandle.fontSize + 'px "' + apiHandle.font + '";' + | 214 ' font: ' + apiHandle.fontSize + 'px "' + apiHandle.font + '";' + |
194 '}'; | 215 '}'; |
195 document.querySelector('head').appendChild(style); | 216 document.querySelector('head').appendChild(style); |
196 } | 217 } |
197 | 218 |
198 /** | 219 /** |
199 * Handles suggestion clicks. | 220 * Handles suggestion clicks. |
200 * @param {integer} restrictedId The restricted id of the suggestion being | 221 * @param {integer} restrictedId The restricted id of the suggestion being |
201 * clicked. | 222 * clicked. |
| 223 * @param {Event} event The native click event. |
202 */ | 224 */ |
203 function handleSuggestionClick(restrictedId) { | 225 function handleSuggestionClick(restrictedId, event) { |
204 clearSuggestions(); | 226 clearSuggestions(); |
205 getApiObjectHandle().navigateContentWindow(restrictedId); | 227 var disposition = WindowOpenDisposition_.CURRENT_TAB; |
| 228 if (event.button == MIDDLE_MOUSE_BUTTON_) |
| 229 disposition = WindowOpenDisposition_.NEW_BACKGROUND_TAB; |
| 230 getApiObjectHandle().navigateContentWindow( |
| 231 restrictedId, disposition); |
206 } | 232 } |
207 | 233 |
208 /** | 234 /** |
209 * chrome.searchBox.onkeypress implementation. | 235 * chrome.searchBox.onkeypress implementation. |
210 * @param {Object} e The key being pressed. | 236 * @param {Object} e The key being pressed. |
211 */ | 237 */ |
212 function handleKeyPress(e) { | 238 function handleKeyPress(e) { |
213 switch (e.keyCode) { | 239 switch (e.keyCode) { |
214 case 38: // Up arrow | 240 case 38: // Up arrow |
215 updateSelectedSuggestion(false); | 241 updateSelectedSuggestion(false); |
(...skipping 14 matching lines...) Expand all Loading... |
230 * Sets up the searchBox API. | 256 * Sets up the searchBox API. |
231 */ | 257 */ |
232 function setUpApi() { | 258 function setUpApi() { |
233 var apiHandle = getApiObjectHandle(); | 259 var apiHandle = getApiObjectHandle(); |
234 apiHandle.onnativesuggestions = handleNativeSuggestions; | 260 apiHandle.onnativesuggestions = handleNativeSuggestions; |
235 apiHandle.onkeypress = handleKeyPress; | 261 apiHandle.onkeypress = handleKeyPress; |
236 apiHandle.onsubmit = onSubmit; | 262 apiHandle.onsubmit = onSubmit; |
237 } | 263 } |
238 | 264 |
239 document.addEventListener('DOMContentLoaded', setUpApi); | 265 document.addEventListener('DOMContentLoaded', setUpApi); |
OLD | NEW |