Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: chrome/browser/resources/local_omnibox_popup/local_omnibox_popup.js

Issue 11644009: Added support for passing WindowOpenDisposition into BrowserInstantController::OpenURL() from the o… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/instant/instant_page.cc ('k') | chrome/browser/ui/browser_instant_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 */
18 var WindowOpenDisposition = {
19 CURRENT_TAB: 1,
20 NEW_BACKGROUND_TAB: 2
21 };
22
23 /**
24 * The JavaScript button event value for a middle click.
25 * @type {number}
26 * @const
27 */
28 var MIDDLE_MOUSE_BUTTON = 1;
29
5 // ============================================================================= 30 // =============================================================================
6 // Util functions 31 // Util functions
7 // ============================================================================= 32 // =============================================================================
8 33
9 /** 34 /**
10 * The maximum number of suggestions to show. 35 * The maximum number of suggestions to show.
11 * @type {number} 36 * @type {number}
12 * @const 37 * @const
13 */ 38 */
14 var MAX_SUGGESTIONS_TO_SHOW = 5; 39 var MAX_SUGGESTIONS_TO_SHOW = 5;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 suggestionDiv.classList.add('suggestion'); 71 suggestionDiv.classList.add('suggestion');
47 if (select) 72 if (select)
48 suggestionDiv.classList.add('selected'); 73 suggestionDiv.classList.add('selected');
49 74
50 var contentsContainer = document.createElement('div'); 75 var contentsContainer = document.createElement('div');
51 contentsContainer.className = 'contents'; 76 contentsContainer.className = 'contents';
52 var contents = suggestion.combinedNode; 77 var contents = suggestion.combinedNode;
53 contentsContainer.appendChild(contents); 78 contentsContainer.appendChild(contents);
54 suggestionDiv.appendChild(contentsContainer); 79 suggestionDiv.appendChild(contentsContainer);
55 var restrictedId = suggestion.rid; 80 var restrictedId = suggestion.rid;
56 suggestionDiv.onclick = function() { 81 suggestionDiv.onclick = function(event) {
57 handleSuggestionClick(restrictedId); 82 handleSuggestionClick(restrictedId, event);
58 }; 83 };
59 84
60 restrictedIds.push(restrictedId); 85 restrictedIds.push(restrictedId);
61 box.appendChild(suggestionDiv); 86 box.appendChild(suggestionDiv);
62 } 87 }
63 88
64 /** 89 /**
65 * Renders the input suggestions. 90 * Renders the input suggestions.
66 * @param {Array} nativeSuggestions An array of native suggestions to render. 91 * @param {Array} nativeSuggestions An array of native suggestions to render.
67 */ 92 */
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 style.textContent = 211 style.textContent =
187 '.suggestion {' + 212 '.suggestion {' +
188 ' -webkit-margin-start: ' + apiHandle.startMargin + 'px;' + 213 ' -webkit-margin-start: ' + apiHandle.startMargin + 'px;' +
189 ' -webkit-margin-end: ' + apiHandle.endMargin + 'px;' + 214 ' -webkit-margin-end: ' + apiHandle.endMargin + 'px;' +
190 ' font: ' + apiHandle.fontSize + 'px "' + apiHandle.font + '";' + 215 ' font: ' + apiHandle.fontSize + 'px "' + apiHandle.font + '";' +
191 '}'; 216 '}';
192 document.querySelector('head').appendChild(style); 217 document.querySelector('head').appendChild(style);
193 } 218 }
194 219
195 /** 220 /**
221 * Extract the desired navigation behavior from a click event.
222 * @param {Event} event The click event.
223 * @return {WindowOpenDisposition} The desired behavior for
224 * navigateContentWindow.
225 */
226 function getDispositionFromClick(event) {
227 if (event.button == MIDDLE_MOUSE_BUTTON)
228 return WindowOpenDisposition.NEW_BACKGROUND_TAB;
229 return WindowOpenDisposition.CURRENT_TAB;
230 }
231
232 /**
196 * Handles suggestion clicks. 233 * Handles suggestion clicks.
197 * @param {integer} restrictedId The restricted id of the suggestion being 234 * @param {integer} restrictedId The restricted id of the suggestion being
198 * clicked. 235 * clicked.
236 * @param {Event} event The click event.
199 */ 237 */
200 function handleSuggestionClick(restrictedId) { 238 function handleSuggestionClick(restrictedId, event) {
201 clearSuggestions(); 239 clearSuggestions();
202 getApiObjectHandle().navigateContentWindow(restrictedId); 240 getApiObjectHandle().navigateContentWindow(restrictedId,
241 getDispositionFromClick(event));
203 } 242 }
204 243
205 /** 244 /**
206 * chrome.searchBox.onkeypress implementation. 245 * chrome.searchBox.onkeypress implementation.
207 * @param {Object} e The key being pressed. 246 * @param {Object} e The key being pressed.
208 */ 247 */
209 function handleKeyPress(e) { 248 function handleKeyPress(e) {
210 switch (e.keyCode) { 249 switch (e.keyCode) {
211 case 38: // Up arrow 250 case 38: // Up arrow
212 updateSelectedSuggestion(false); 251 updateSelectedSuggestion(false);
(...skipping 18 matching lines...) Expand all
231 apiHandle.onnativesuggestions = handleNativeSuggestions; 270 apiHandle.onnativesuggestions = handleNativeSuggestions;
232 apiHandle.onkeypress = handleKeyPress; 271 apiHandle.onkeypress = handleKeyPress;
233 apiHandle.onsubmit = onSubmit; 272 apiHandle.onsubmit = onSubmit;
234 appendSuggestionStyles(); 273 appendSuggestionStyles();
235 274
236 if (apiHandle.nativeSuggestions.length) 275 if (apiHandle.nativeSuggestions.length)
237 handleNativeSuggestions(); 276 handleNativeSuggestions();
238 } 277 }
239 278
240 document.addEventListener('DOMContentLoaded', setUpApi); 279 document.addEventListener('DOMContentLoaded', setUpApi);
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_page.cc ('k') | chrome/browser/ui/browser_instant_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698