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 // ============================================================================= | 5 // ============================================================================= |
6 // Util functions | 6 // Util functions |
7 // ============================================================================= | 7 // ============================================================================= |
8 | 8 |
9 /** | 9 /** |
10 * The maximum number of suggestions to show. | 10 * The maximum number of suggestions to show. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return window.navigator.searchBox; | 138 return window.navigator.searchBox; |
139 if (window.chrome && window.chrome.searchBox) | 139 if (window.chrome && window.chrome.searchBox) |
140 return window.chrome.searchBox; | 140 return window.chrome.searchBox; |
141 return null; | 141 return null; |
142 } | 142 } |
143 | 143 |
144 /** | 144 /** |
145 * chrome.searchBox.onnativesuggestions implementation. | 145 * chrome.searchBox.onnativesuggestions implementation. |
146 */ | 146 */ |
147 function handleNativeSuggestions() { | 147 function handleNativeSuggestions() { |
148 // This can't be done in setUpApi(), because apiHandle.font/fontSize | |
149 // isn't available yet. | |
150 var suggestionStyleNode = $('suggestionStyle'); | |
151 if (!suggestionStyleNode) | |
152 appendSuggestionStyles(); | |
153 | |
154 var apiHandle = getApiObjectHandle(); | 148 var apiHandle = getApiObjectHandle(); |
155 | 149 |
156 // Used to workaround repeated undesired asynchronous onnativesuggestions | 150 // Used to workaround repeated undesired asynchronous onnativesuggestions |
157 // events and the fact that when a suggestion is clicked, the omnibox unfocus | 151 // events and the fact that when a suggestion is clicked, the omnibox unfocus |
158 // can cause onnativesuggestions to fire, preventing the suggestion onclick | 152 // can cause onnativesuggestions to fire, preventing the suggestion onclick |
159 // from registering. | 153 // from registering. |
160 if (lastInputValue == apiHandle.value && $('suggestionsBox')) { | 154 if (lastInputValue == apiHandle.value && $('suggestionsBox')) { |
161 return; | 155 return; |
162 } | 156 } |
163 lastInputValue = apiHandle.value; | 157 lastInputValue = apiHandle.value; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 } | 221 } |
228 | 222 |
229 /** | 223 /** |
230 * Sets up the searchBox API. | 224 * Sets up the searchBox API. |
231 */ | 225 */ |
232 function setUpApi() { | 226 function setUpApi() { |
233 var apiHandle = getApiObjectHandle(); | 227 var apiHandle = getApiObjectHandle(); |
234 apiHandle.onnativesuggestions = handleNativeSuggestions; | 228 apiHandle.onnativesuggestions = handleNativeSuggestions; |
235 apiHandle.onkeypress = handleKeyPress; | 229 apiHandle.onkeypress = handleKeyPress; |
236 apiHandle.onsubmit = onSubmit; | 230 apiHandle.onsubmit = onSubmit; |
| 231 appendSuggestionStyles(); |
| 232 |
| 233 if (apiHandle.nativeSuggestions.length) |
| 234 handleNativeSuggestions(); |
237 } | 235 } |
238 | 236 |
239 document.addEventListener('DOMContentLoaded', setUpApi); | 237 document.addEventListener('DOMContentLoaded', setUpApi); |
OLD | NEW |