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

Side by Side Diff: chrome/browser/resources/options/search_engine_manager_engine_list.js

Issue 2939273002: DO NOT SUBMIT: what chrome/browser/resources/ could eventually look like with clang-format (Closed)
Patch Set: Created 3 years, 6 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
OLDNEW
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 /** 5 /**
6 * @typedef {{canBeDefault: boolean, 6 * @typedef {{canBeDefault: boolean,
7 * canBeEdited: boolean, 7 * canBeEdited: boolean,
8 * canBeRemoved: boolean, 8 * canBeRemoved: boolean,
9 * default: boolean, 9 * default: boolean,
10 * displayName: string, 10 * displayName: string,
11 * extension: (Object|undefined), 11 * extension: (Object|undefined),
12 * iconURL: (string|undefined), 12 * iconURL: (string|undefined),
13 * isOmniboxExtension: boolean, 13 * isOmniboxExtension: boolean,
14 * keyword: string, 14 * keyword: string,
15 * modelIndex: string, 15 * modelIndex: string,
16 * name: string, 16 * name: string,
17 * url: string, 17 * url: string,
18 * urlLocked: boolean}} 18 * urlLocked: boolean}}
19 * @see chrome/browser/ui/webui/options/search_engine_manager_handler.cc 19 * @see chrome/browser/ui/webui/options/search_engine_manager_handler.cc
20 */ 20 */
21 var SearchEngine; 21 var SearchEngine;
22 22
23 cr.define('options.search_engines', function() { 23 cr.define('options.search_engines', function() {
24 /** @const */ var ControlledSettingIndicator = 24 /** @const */ var ControlledSettingIndicator =
25 options.ControlledSettingIndicator; 25 options.ControlledSettingIndicator;
26 /** @const */ var InlineEditableItemList = options.InlineEditableItemList; 26 /** @const */ var InlineEditableItemList = options.InlineEditableItemList;
27 /** @const */ var InlineEditableItem = options.InlineEditableItem; 27 /** @const */ var InlineEditableItem = options.InlineEditableItem;
28 /** @const */ var ListSelectionController = cr.ui.ListSelectionController; 28 /** @const */ var ListSelectionController = cr.ui.ListSelectionController;
29 29
30 /** 30 /**
31 * Creates a new search engine list item. 31 * Creates a new search engine list item.
32 * @param {SearchEngine} searchEngine The search engine this represents. 32 * @param {SearchEngine} searchEngine The search engine this represents.
33 * @constructor 33 * @constructor
34 * @extends {options.InlineEditableItem} 34 * @extends {options.InlineEditableItem}
35 */ 35 */
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // Don't select the row when clicking the button. 166 // Don't select the row when clicking the button.
167 e.stopPropagation(); 167 e.stopPropagation();
168 // Don't focus on the button. 168 // Don't focus on the button.
169 e.preventDefault(); 169 e.preventDefault();
170 }; 170 };
171 urlWithButtonEl.appendChild(makeDefaultButtonEl); 171 urlWithButtonEl.appendChild(makeDefaultButtonEl);
172 } 172 }
173 } 173 }
174 174
175 // Do final adjustment to the input fields. 175 // Do final adjustment to the input fields.
176 this.nameField_ = /** @type {HTMLElement} */( 176 this.nameField_ =
177 nameEl.querySelector('input')); 177 /** @type {HTMLElement} */ (nameEl.querySelector('input'));
178 // The editable field uses the raw name, not the display name. 178 // The editable field uses the raw name, not the display name.
179 this.nameField_.value = engine.name; 179 this.nameField_.value = engine.name;
180 this.keywordField_ = /** @type {HTMLElement} */( 180 this.keywordField_ =
181 keywordEl.querySelector('input')); 181 /** @type {HTMLElement} */ (keywordEl.querySelector('input'));
182 this.urlField_ = /** @type {HTMLElement} */(urlEl.querySelector('input')); 182 this.urlField_ =
183 /** @type {HTMLElement} */ (urlEl.querySelector('input'));
183 184
184 if (engine.urlLocked) 185 if (engine.urlLocked)
185 this.urlField_.disabled = true; 186 this.urlField_.disabled = true;
186 187
187 if (this.isPlaceholder) { 188 if (this.isPlaceholder) {
188 this.nameField_.placeholder = 189 this.nameField_.placeholder =
189 loadTimeData.getString('searchEngineTableNamePlaceholder'); 190 loadTimeData.getString('searchEngineTableNamePlaceholder');
190 this.keywordField_.placeholder = 191 this.keywordField_.placeholder =
191 loadTimeData.getString('searchEngineTableKeywordPlaceholder'); 192 loadTimeData.getString('searchEngineTableKeywordPlaceholder');
192 this.urlField_.placeholder = 193 this.urlField_.placeholder =
193 loadTimeData.getString('searchEngineTableURLPlaceholder'); 194 loadTimeData.getString('searchEngineTableURLPlaceholder');
194 } 195 }
195 196
196 this.setFocusableColumnIndex(this.nameField_, 0); 197 this.setFocusableColumnIndex(this.nameField_, 0);
197 this.setFocusableColumnIndex(this.keywordField_, 1); 198 this.setFocusableColumnIndex(this.keywordField_, 1);
198 this.setFocusableColumnIndex(this.urlField_, 2); 199 this.setFocusableColumnIndex(this.urlField_, 2);
199 this.setFocusableColumnIndex(makeDefaultButtonEl, 3); 200 this.setFocusableColumnIndex(makeDefaultButtonEl, 3);
200 this.setFocusableColumnIndex(this.closeButtonElement, 4); 201 this.setFocusableColumnIndex(this.closeButtonElement, 4);
201 202
202 var fields = [this.nameField_, this.keywordField_, this.urlField_]; 203 var fields = [this.nameField_, this.keywordField_, this.urlField_];
203 for (var i = 0; i < fields.length; i++) { 204 for (var i = 0; i < fields.length; i++) {
204 fields[i].oninput = this.startFieldValidation_.bind(this); 205 fields[i].oninput = this.startFieldValidation_.bind(this);
205 } 206 }
206 207
207 // Listen for edit events. 208 // Listen for edit events.
208 if (engine.canBeEdited) { 209 if (engine.canBeEdited) {
209 this.addEventListener('edit', this.onEditStarted_.bind(this)); 210 this.addEventListener('edit', this.onEditStarted_.bind(this));
210 this.addEventListener('canceledit', this.onEditCancelled_.bind(this)); 211 this.addEventListener('canceledit', this.onEditCancelled_.bind(this));
211 this.addEventListener('commitedit', this.onEditCommitted_.bind(this)); 212 this.addEventListener('commitedit', this.onEditCommitted_.bind(this));
212 } else { 213 } else {
213 this.editable = false; 214 this.editable = false;
214 this.querySelector('.row-delete-button').hidden = true; 215 this.querySelector('.row-delete-button').hidden = true;
215 var indicator = new ControlledSettingIndicator(); 216 var indicator = new ControlledSettingIndicator();
216 indicator.setAttribute('setting', 'search-engine'); 217 indicator.setAttribute('setting', 'search-engine');
217 // Create a synthetic pref change event decorated as 218 // Create a synthetic pref change event decorated as
218 // CoreOptionsHandler::CreateValueForPref() does. 219 // CoreOptionsHandler::CreateValueForPref() does.
219 var event = new Event(this.contentType); 220 var event = new Event(this.contentType);
220 if (engine.extension) { 221 if (engine.extension) {
221 event.value = { controlledBy: 'extension', 222 event.value = {
222 extension: engine.extension }; 223 controlledBy: 'extension',
224 extension: engine.extension
225 };
223 } else { 226 } else {
224 event.value = { controlledBy: 'policy' }; 227 event.value = {controlledBy: 'policy'};
225 } 228 }
226 indicator.handlePrefChange(event); 229 indicator.handlePrefChange(event);
227 this.appendChild(indicator); 230 this.appendChild(indicator);
228 } 231 }
229 }, 232 },
230 233
231 /** @override */ 234 /** @override */
232 get currentInputIsValid() { 235 get currentInputIsValid() {
233 return !this.waitingForValidation_ && this.currentlyValid_; 236 return !this.waitingForValidation_ && this.currentlyValid_;
234 }, 237 },
235 238
236 /** @override */ 239 /** @override */
237 get hasBeenEdited() { 240 get hasBeenEdited() {
238 var engine = this.searchEngine_; 241 var engine = this.searchEngine_;
239 return this.nameField_.value != engine.name || 242 return this.nameField_.value != engine.name ||
240 this.keywordField_.value != engine.keyword || 243 this.keywordField_.value != engine.keyword ||
241 this.urlField_.value != engine.url; 244 this.urlField_.value != engine.url;
242 }, 245 },
243 246
244 /** 247 /**
245 * Called when entering edit mode; starts an edit session in the model. 248 * Called when entering edit mode; starts an edit session in the model.
246 * @param {Event} e The edit event. 249 * @param {Event} e The edit event.
247 * @private 250 * @private
248 */ 251 */
249 onEditStarted_: function(e) { 252 onEditStarted_: function(e) {
250 var editIndex = this.searchEngine_.modelIndex; 253 var editIndex = this.searchEngine_.modelIndex;
251 chrome.send('editSearchEngine', [String(editIndex)]); 254 chrome.send('editSearchEngine', [String(editIndex)]);
(...skipping 24 matching lines...) Expand all
276 this.currentlyValid_ = !this.isPlaceholder; 279 this.currentlyValid_ = !this.isPlaceholder;
277 }, 280 },
278 281
279 /** 282 /**
280 * Returns the input field values as an array suitable for passing to 283 * Returns the input field values as an array suitable for passing to
281 * chrome.send. The order of the array is important. 284 * chrome.send. The order of the array is important.
282 * @private 285 * @private
283 * @return {Array} The current input field values. 286 * @return {Array} The current input field values.
284 */ 287 */
285 getInputFieldValues_: function() { 288 getInputFieldValues_: function() {
286 return [this.nameField_.value, 289 return [
287 this.keywordField_.value, 290 this.nameField_.value, this.keywordField_.value, this.urlField_.value
288 this.urlField_.value]; 291 ];
289 }, 292 },
290 293
291 /** 294 /**
292 * Begins the process of asynchronously validing the input fields. 295 * Begins the process of asynchronously validing the input fields.
293 * @private 296 * @private
294 */ 297 */
295 startFieldValidation_: function() { 298 startFieldValidation_: function() {
296 this.waitingForValidation_ = true; 299 this.waitingForValidation_ = true;
297 var args = this.getInputFieldValues_(); 300 var args = this.getInputFieldValues_();
298 args.push(this.searchEngine_.modelIndex); 301 args.push(this.searchEngine_.modelIndex);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 var currentSelection = this.selectedItem; 367 var currentSelection = this.selectedItem;
365 if (!currentSelection) 368 if (!currentSelection)
366 return; 369 return;
367 var listItem = this.getListItem(currentSelection); 370 var listItem = this.getListItem(currentSelection);
368 if (listItem.editing && currentSelection.modelIndex == modelIndex) 371 if (listItem.editing && currentSelection.modelIndex == modelIndex)
369 listItem.validationComplete(validity); 372 listItem.validationComplete(validity);
370 }, 373 },
371 }; 374 };
372 375
373 // Export 376 // Export
374 return { 377 return {SearchEngineList: SearchEngineList};
375 SearchEngineList: SearchEngineList
376 };
377 378
378 }); 379 });
379
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698