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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 ' -webkit-margin-end: ' + apiHandle.endMargin + 'px;' + | 210 ' -webkit-margin-end: ' + apiHandle.endMargin + 'px;' + |
190 ' font: ' + apiHandle.fontSize + 'px "' + apiHandle.font + '";' + | 211 ' font: ' + apiHandle.fontSize + 'px "' + apiHandle.font + '";' + |
191 '}'; | 212 '}'; |
192 document.querySelector('head').appendChild(style); | 213 document.querySelector('head').appendChild(style); |
193 } | 214 } |
194 | 215 |
195 /** | 216 /** |
196 * Handles suggestion clicks. | 217 * Handles suggestion clicks. |
197 * @param {integer} restrictedId The restricted id of the suggestion being | 218 * @param {integer} restrictedId The restricted id of the suggestion being |
198 * clicked. | 219 * clicked. |
220 * @param {Event} event The native click event. | |
199 */ | 221 */ |
200 function handleSuggestionClick(restrictedId) { | 222 function handleSuggestionClick(restrictedId, event) { |
201 clearSuggestions(); | 223 clearSuggestions(); |
202 getApiObjectHandle().navigateContentWindow(restrictedId); | 224 var disposition = WindowOpenDisposition_.CURRENT_TAB; |
225 if (event.button == MIDDLE_MOUSE_BUTTON_) | |
226 disposition = WindowOpenDisposition_.NEW_BACKGROUND_TAB; | |
227 getApiObjectHandle().navigateContentWindow( | |
samarth
2013/02/20 23:55:16
nit: fits on one line?
dougw
2013/02/21 00:49:00
Done.
| |
228 restrictedId, disposition); | |
203 } | 229 } |
204 | 230 |
205 /** | 231 /** |
206 * chrome.searchBox.onkeypress implementation. | 232 * chrome.searchBox.onkeypress implementation. |
207 * @param {Object} e The key being pressed. | 233 * @param {Object} e The key being pressed. |
208 */ | 234 */ |
209 function handleKeyPress(e) { | 235 function handleKeyPress(e) { |
210 switch (e.keyCode) { | 236 switch (e.keyCode) { |
211 case 38: // Up arrow | 237 case 38: // Up arrow |
212 updateSelectedSuggestion(false); | 238 updateSelectedSuggestion(false); |
(...skipping 18 matching lines...) Expand all Loading... | |
231 apiHandle.onnativesuggestions = handleNativeSuggestions; | 257 apiHandle.onnativesuggestions = handleNativeSuggestions; |
232 apiHandle.onkeypress = handleKeyPress; | 258 apiHandle.onkeypress = handleKeyPress; |
233 apiHandle.onsubmit = onSubmit; | 259 apiHandle.onsubmit = onSubmit; |
234 appendSuggestionStyles(); | 260 appendSuggestionStyles(); |
235 | 261 |
236 if (apiHandle.nativeSuggestions.length) | 262 if (apiHandle.nativeSuggestions.length) |
237 handleNativeSuggestions(); | 263 handleNativeSuggestions(); |
238 } | 264 } |
239 | 265 |
240 document.addEventListener('DOMContentLoaded', setUpApi); | 266 document.addEventListener('DOMContentLoaded', setUpApi); |
OLD | NEW |