OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 * @typedef {{canBeDefault: boolean, |
| 7 * canBeEdited: boolean, |
| 8 * canBeRemoved: boolean, |
| 9 * default: boolean, |
| 10 * displayName: string, |
| 11 * extension: (Object|undefined), |
| 12 * iconURL: (string|undefined), |
| 13 * isExtension: boolean, |
| 14 * keyword: string, |
| 15 * modelIndex: string, |
| 16 * name: string, |
| 17 * url: string, |
| 18 * urlLocked: boolean}} |
| 19 * @see chrome/browser/ui/webui/options/search_engine_manager_handler.cc |
| 20 */ |
| 21 var SearchEngine; |
| 22 |
5 cr.define('options.search_engines', function() { | 23 cr.define('options.search_engines', function() { |
6 /** @const */ var ControlledSettingIndicator = | 24 /** @const */ var ControlledSettingIndicator = |
7 options.ControlledSettingIndicator; | 25 options.ControlledSettingIndicator; |
8 /** @const */ var InlineEditableItemList = options.InlineEditableItemList; | 26 /** @const */ var InlineEditableItemList = options.InlineEditableItemList; |
9 /** @const */ var InlineEditableItem = options.InlineEditableItem; | 27 /** @const */ var InlineEditableItem = options.InlineEditableItem; |
10 /** @const */ var ListSelectionController = cr.ui.ListSelectionController; | 28 /** @const */ var ListSelectionController = cr.ui.ListSelectionController; |
11 | 29 |
12 /** | 30 /** |
13 * Creates a new search engine list item. | 31 * Creates a new search engine list item. |
14 * @param {Object} searchEngine The search engine this represents. | 32 * @param {SearchEngine} searchEngine The search engine this represents. |
15 * @constructor | 33 * @constructor |
16 * @extends {cr.ui.ListItem} | 34 * @extends {options.InlineEditableItem} |
17 */ | 35 */ |
18 function SearchEngineListItem(searchEngine) { | 36 function SearchEngineListItem(searchEngine) { |
19 var el = cr.doc.createElement('div'); | 37 var el = cr.doc.createElement('div'); |
20 el.searchEngine_ = searchEngine; | 38 el.searchEngine_ = searchEngine; |
21 SearchEngineListItem.decorate(el); | 39 SearchEngineListItem.decorate(el); |
22 return el; | 40 return el; |
23 } | 41 } |
24 | 42 |
25 /** | 43 /** |
26 * Decorates an element as a search engine list item. | 44 * Decorates an element as a search engine list item. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 */ | 80 */ |
63 waitingForValidation_: false, | 81 waitingForValidation_: false, |
64 | 82 |
65 /** | 83 /** |
66 * Whether or not the current set of input is known to be valid. | 84 * Whether or not the current set of input is known to be valid. |
67 * @type {boolean} | 85 * @type {boolean} |
68 * @private | 86 * @private |
69 */ | 87 */ |
70 currentlyValid_: false, | 88 currentlyValid_: false, |
71 | 89 |
| 90 /** |
| 91 * @type {?SearchEngine} |
| 92 */ |
| 93 searchEngine_: null, |
| 94 |
72 /** @override */ | 95 /** @override */ |
73 decorate: function() { | 96 decorate: function() { |
74 InlineEditableItem.prototype.decorate.call(this); | 97 InlineEditableItem.prototype.decorate.call(this); |
75 | 98 |
76 var engine = this.searchEngine_; | 99 var engine = this.searchEngine_; |
77 | 100 |
78 if (engine.modelIndex == '-1') { | 101 if (engine.modelIndex == '-1') { |
79 this.isPlaceholder = true; | 102 this.isPlaceholder = true; |
80 engine.name = ''; | 103 engine.name = ''; |
81 engine.keyword = ''; | 104 engine.keyword = ''; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // Don't select the row when clicking the button. | 162 // Don't select the row when clicking the button. |
140 e.stopPropagation(); | 163 e.stopPropagation(); |
141 // Don't focus on the button. | 164 // Don't focus on the button. |
142 e.preventDefault(); | 165 e.preventDefault(); |
143 }; | 166 }; |
144 urlWithButtonEl.appendChild(makeDefaultButtonEl); | 167 urlWithButtonEl.appendChild(makeDefaultButtonEl); |
145 } | 168 } |
146 } | 169 } |
147 | 170 |
148 // Do final adjustment to the input fields. | 171 // Do final adjustment to the input fields. |
149 this.nameField_ = nameEl.querySelector('input'); | 172 this.nameField_ = /** @type {HTMLElement} */( |
| 173 nameEl.querySelector('input')); |
150 // The editable field uses the raw name, not the display name. | 174 // The editable field uses the raw name, not the display name. |
151 this.nameField_.value = engine.name; | 175 this.nameField_.value = engine.name; |
152 this.keywordField_ = keywordEl.querySelector('input'); | 176 this.keywordField_ = /** @type {HTMLElement} */( |
153 this.urlField_ = urlEl.querySelector('input'); | 177 keywordEl.querySelector('input')); |
| 178 this.urlField_ = /** @type {HTMLElement} */(urlEl.querySelector('input')); |
154 | 179 |
155 if (engine.urlLocked) | 180 if (engine.urlLocked) |
156 this.urlField_.disabled = true; | 181 this.urlField_.disabled = true; |
157 | 182 |
158 if (engine.isExtension) | 183 if (engine.isExtension) |
159 this.nameField_.disabled = true; | 184 this.nameField_.disabled = true; |
160 | 185 |
161 if (this.isPlaceholder) { | 186 if (this.isPlaceholder) { |
162 this.nameField_.placeholder = | 187 this.nameField_.placeholder = |
163 loadTimeData.getString('searchEngineTableNamePlaceholder'); | 188 loadTimeData.getString('searchEngineTableNamePlaceholder'); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 this.urlField_.setCustomValidity(''); | 318 this.urlField_.setCustomValidity(''); |
294 } else { | 319 } else { |
295 this.urlField_.setCustomValidity( | 320 this.urlField_.setCustomValidity( |
296 loadTimeData.getString('editSearchEngineInvalidURLToolTip')); | 321 loadTimeData.getString('editSearchEngineInvalidURLToolTip')); |
297 } | 322 } |
298 | 323 |
299 this.currentlyValid_ = validity.name && validity.keyword && validity.url; | 324 this.currentlyValid_ = validity.name && validity.keyword && validity.url; |
300 }, | 325 }, |
301 }; | 326 }; |
302 | 327 |
| 328 /** |
| 329 * @constructor |
| 330 * @extends {options.InlineEditableItemList} |
| 331 */ |
303 var SearchEngineList = cr.ui.define('list'); | 332 var SearchEngineList = cr.ui.define('list'); |
304 | 333 |
305 SearchEngineList.prototype = { | 334 SearchEngineList.prototype = { |
306 __proto__: InlineEditableItemList.prototype, | 335 __proto__: InlineEditableItemList.prototype, |
307 | 336 |
308 /** @override */ | 337 /** |
| 338 * @override |
| 339 * @param {SearchEngine} searchEngine |
| 340 */ |
309 createItem: function(searchEngine) { | 341 createItem: function(searchEngine) { |
310 return new SearchEngineListItem(searchEngine); | 342 return new SearchEngineListItem(searchEngine); |
311 }, | 343 }, |
312 | 344 |
313 /** @override */ | 345 /** @override */ |
314 deleteItemAtIndex: function(index) { | 346 deleteItemAtIndex: function(index) { |
315 var modelIndex = this.dataModel.item(index).modelIndex; | 347 var modelIndex = this.dataModel.item(index).modelIndex; |
316 chrome.send('removeSearchEngine', [String(modelIndex)]); | 348 chrome.send('removeSearchEngine', [String(modelIndex)]); |
317 }, | 349 }, |
318 | 350 |
(...skipping 14 matching lines...) Expand all Loading... |
333 }, | 365 }, |
334 }; | 366 }; |
335 | 367 |
336 // Export | 368 // Export |
337 return { | 369 return { |
338 SearchEngineList: SearchEngineList | 370 SearchEngineList: SearchEngineList |
339 }; | 371 }; |
340 | 372 |
341 }); | 373 }); |
342 | 374 |
OLD | NEW |