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 * @fileoverview Support for omnibox behavior in offline mode or when API | |
7 * features are not supported on the server. | |
8 */ | |
9 | |
10 // ========================================================== | |
11 // Enums. | |
12 // ========================================================== | |
13 | |
14 /** | |
15 * Possible behaviors for navigateContentWindow. | |
16 * @enum {number} | |
17 * @private | |
18 */ | |
19 var WindowOpenDisposition_ = { | |
Evan Stade
2013/02/22 22:28:29
why are there trailing underscores here and below?
dougw
2013/02/22 23:32:19
Unless I'm mistaken (and that's very possible), th
| |
20 CURRENT_TAB: 1, | |
21 NEW_BACKGROUND_TAB: 2 | |
22 }; | |
23 | |
24 /** | |
25 * The JavaScript button event value for a middle click. | |
26 * @type {number} | |
27 * @private | |
28 * @const | |
29 */ | |
30 var MIDDLE_MOUSE_BUTTON_ = 1; | |
31 | |
5 // ============================================================================= | 32 // ============================================================================= |
6 // Util functions | 33 // Util functions |
7 // ============================================================================= | 34 // ============================================================================= |
8 | 35 |
9 /** | 36 /** |
10 * The maximum number of suggestions to show. | 37 * The maximum number of suggestions to show. |
11 * @type {number} | 38 * @type {number} |
12 * @const | 39 * @const |
13 */ | 40 */ |
14 var MAX_SUGGESTIONS_TO_SHOW = 5; | 41 var MAX_SUGGESTIONS_TO_SHOW = 5; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 suggestionDiv.classList.add('suggestion'); | 73 suggestionDiv.classList.add('suggestion'); |
47 if (select) | 74 if (select) |
48 suggestionDiv.classList.add('selected'); | 75 suggestionDiv.classList.add('selected'); |
49 | 76 |
50 var contentsContainer = document.createElement('div'); | 77 var contentsContainer = document.createElement('div'); |
51 contentsContainer.className = 'contents'; | 78 contentsContainer.className = 'contents'; |
52 var contents = suggestion.combinedNode; | 79 var contents = suggestion.combinedNode; |
53 contentsContainer.appendChild(contents); | 80 contentsContainer.appendChild(contents); |
54 suggestionDiv.appendChild(contentsContainer); | 81 suggestionDiv.appendChild(contentsContainer); |
55 var restrictedId = suggestion.rid; | 82 var restrictedId = suggestion.rid; |
56 suggestionDiv.onclick = function() { | 83 suggestionDiv.onclick = function(event) { |
57 handleSuggestionClick(restrictedId); | 84 handleSuggestionClick(restrictedId, event); |
58 }; | 85 }; |
59 | 86 |
60 restrictedIds.push(restrictedId); | 87 restrictedIds.push(restrictedId); |
61 box.appendChild(suggestionDiv); | 88 box.appendChild(suggestionDiv); |
62 } | 89 } |
63 | 90 |
64 /** | 91 /** |
65 * Renders the input suggestions. | 92 * Renders the input suggestions. |
66 * @param {Array} nativeSuggestions An array of native suggestions to render. | 93 * @param {Array} nativeSuggestions An array of native suggestions to render. |
67 */ | 94 */ |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 ' -webkit-margin-end: ' + apiHandle.endMargin + 'px;' + | 216 ' -webkit-margin-end: ' + apiHandle.endMargin + 'px;' + |
190 ' font: ' + apiHandle.fontSize + 'px "' + apiHandle.font + '";' + | 217 ' font: ' + apiHandle.fontSize + 'px "' + apiHandle.font + '";' + |
191 '}'; | 218 '}'; |
192 document.querySelector('head').appendChild(style); | 219 document.querySelector('head').appendChild(style); |
193 } | 220 } |
194 | 221 |
195 /** | 222 /** |
196 * Handles suggestion clicks. | 223 * Handles suggestion clicks. |
197 * @param {integer} restrictedId The restricted id of the suggestion being | 224 * @param {integer} restrictedId The restricted id of the suggestion being |
198 * clicked. | 225 * clicked. |
226 * @param {Event} event The native click event. | |
Evan Stade
2013/02/22 22:28:29
not sure what "native" means in this context. Sugg
dougw
2013/02/22 23:32:19
Done.
| |
199 */ | 227 */ |
200 function handleSuggestionClick(restrictedId) { | 228 function handleSuggestionClick(restrictedId, event) { |
201 clearSuggestions(); | 229 clearSuggestions(); |
202 getApiObjectHandle().navigateContentWindow(restrictedId); | 230 var disposition = WindowOpenDisposition_.CURRENT_TAB; |
231 if (event.button == MIDDLE_MOUSE_BUTTON_) | |
232 disposition = WindowOpenDisposition_.NEW_BACKGROUND_TAB; | |
233 getApiObjectHandle().navigateContentWindow(restrictedId, disposition); | |
203 } | 234 } |
204 | 235 |
205 /** | 236 /** |
206 * chrome.searchBox.onkeypress implementation. | 237 * chrome.searchBox.onkeypress implementation. |
207 * @param {Object} e The key being pressed. | 238 * @param {Object} e The key being pressed. |
208 */ | 239 */ |
209 function handleKeyPress(e) { | 240 function handleKeyPress(e) { |
210 switch (e.keyCode) { | 241 switch (e.keyCode) { |
211 case 38: // Up arrow | 242 case 38: // Up arrow |
212 updateSelectedSuggestion(false); | 243 updateSelectedSuggestion(false); |
(...skipping 18 matching lines...) Expand all Loading... | |
231 apiHandle.onnativesuggestions = handleNativeSuggestions; | 262 apiHandle.onnativesuggestions = handleNativeSuggestions; |
232 apiHandle.onkeypress = handleKeyPress; | 263 apiHandle.onkeypress = handleKeyPress; |
233 apiHandle.onsubmit = onSubmit; | 264 apiHandle.onsubmit = onSubmit; |
234 appendSuggestionStyles(); | 265 appendSuggestionStyles(); |
235 | 266 |
236 if (apiHandle.nativeSuggestions.length) | 267 if (apiHandle.nativeSuggestions.length) |
237 handleNativeSuggestions(); | 268 handleNativeSuggestions(); |
238 } | 269 } |
239 | 270 |
240 document.addEventListener('DOMContentLoaded', setUpApi); | 271 document.addEventListener('DOMContentLoaded', setUpApi); |
OLD | NEW |