Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 cr.define('options.browser_options', function() { | 5 cr.define('options.browser_options', function() { |
| 6 const DeletableItemList = options.DeletableItemList; | 6 const InlineEditableItem = options.InlineEditableItem; |
| 7 const DeletableItem = options.DeletableItem; | 7 const InlineEditableItemList = options.InlineEditableItemList; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Creates a new startup page list item. | 10 * Creates a new startup page list item. |
| 11 * @param {Object} pageInfo The page this item represents. | 11 * @param {Object} pageInfo The page this item represents. |
| 12 * @constructor | 12 * @constructor |
| 13 * @extends {cr.ui.ListItem} | 13 * @extends {cr.ui.ListItem} |
| 14 */ | 14 */ |
| 15 function StartupPageListItem(pageInfo) { | 15 function StartupPageListItem(pageInfo) { |
| 16 var el = cr.doc.createElement('div'); | 16 var el = cr.doc.createElement('div'); |
| 17 el.pageInfo_ = pageInfo; | 17 el.pageInfo_ = pageInfo; |
| 18 StartupPageListItem.decorate(el); | 18 StartupPageListItem.decorate(el); |
| 19 return el; | 19 return el; |
| 20 } | 20 } |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * Decorates an element as a startup page list item. | 23 * Decorates an element as a startup page list item. |
| 24 * @param {!HTMLElement} el The element to decorate. | 24 * @param {!HTMLElement} el The element to decorate. |
| 25 */ | 25 */ |
| 26 StartupPageListItem.decorate = function(el) { | 26 StartupPageListItem.decorate = function(el) { |
| 27 el.__proto__ = StartupPageListItem.prototype; | 27 el.__proto__ = StartupPageListItem.prototype; |
| 28 el.decorate(); | 28 el.decorate(); |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 StartupPageListItem.prototype = { | 31 StartupPageListItem.prototype = { |
| 32 __proto__: DeletableItem.prototype, | 32 __proto__: InlineEditableItem.prototype, |
| 33 | |
| 34 /** | |
| 35 * Input field for editing the page url. | |
| 36 * @type {HTMLElement} | |
| 37 * @private | |
| 38 */ | |
| 39 urlField_: null, | |
| 33 | 40 |
| 34 /** @inheritDoc */ | 41 /** @inheritDoc */ |
| 35 decorate: function() { | 42 decorate: function() { |
| 36 DeletableItem.prototype.decorate.call(this); | 43 InlineEditableItem.prototype.decorate.call(this); |
| 37 | 44 |
| 38 var titleEl = this.ownerDocument.createElement('span'); | 45 var titleEl = this.ownerDocument.createElement('div'); |
| 39 titleEl.className = 'title'; | 46 titleEl.className = 'title'; |
| 40 titleEl.classList.add('favicon-cell'); | 47 titleEl.classList.add('favicon-cell'); |
| 41 titleEl.textContent = this.pageInfo_['title']; | 48 titleEl.textContent = this.pageInfo_['title']; |
| 42 titleEl.style.backgroundImage = url('chrome://favicon/' + | 49 titleEl.style.backgroundImage = url('chrome://favicon/' + |
| 43 this.pageInfo_['url']); | 50 this.pageInfo_['url']); |
| 44 titleEl.title = this.pageInfo_['tooltip']; | 51 titleEl.title = this.pageInfo_['tooltip']; |
| 45 | 52 |
| 46 this.contentElement.appendChild(titleEl); | 53 this.contentElement.appendChild(titleEl); |
| 54 | |
| 55 var urlEl = this.createEditableTextCell(this.pageInfo_['url']); | |
| 56 urlEl.className = 'url'; | |
| 57 this.contentElement.appendChild(urlEl); | |
| 58 | |
| 59 this.urlField_ = urlEl.querySelector('input'); | |
| 60 this.urlField_.required = true; | |
| 61 | |
| 62 this.addEventListener('commitedit', this.onEditCommitted_.bind(this)); | |
| 63 }, | |
| 64 | |
| 65 /** @inheritDoc */ | |
| 66 get currentInputIsValid() { | |
| 67 return this.urlField_.validity.valid; | |
| 68 }, | |
| 69 | |
| 70 /** @inheritDoc */ | |
| 71 get hasBeenEdited() { | |
| 72 return this.urlField_.value != this.pageInfo_['url']; | |
| 73 }, | |
| 74 | |
| 75 /** | |
| 76 * Called when committing an edit; updates the model. | |
| 77 * @param {Event} e The end event. | |
| 78 * @private | |
| 79 */ | |
| 80 onEditCommitted_: function(e) { | |
| 81 chrome.send('editStartupPage', | |
| 82 [ this.pageInfo_['modelIndex'], this.urlField_.value ]); | |
|
Evan Stade
2011/01/13 23:12:46
are the spaces around the [] typical? you don't us
stuartmorgan
2011/01/13 23:35:37
Done.
| |
| 47 }, | 83 }, |
| 48 }; | 84 }; |
| 49 | 85 |
| 50 var StartupPageList = cr.ui.define('list'); | 86 var StartupPageList = cr.ui.define('list'); |
| 51 | 87 |
| 52 StartupPageList.prototype = { | 88 StartupPageList.prototype = { |
| 53 __proto__: DeletableItemList.prototype, | 89 __proto__: InlineEditableItemList.prototype, |
| 54 | 90 |
| 55 /** @inheritDoc */ | 91 /** @inheritDoc */ |
| 56 createItem: function(pageInfo) { | 92 createItem: function(pageInfo) { |
| 57 return new StartupPageListItem(pageInfo); | 93 return new StartupPageListItem(pageInfo); |
| 58 }, | 94 }, |
| 59 | 95 |
| 60 /** @inheritDoc */ | 96 /** @inheritDoc */ |
| 61 deleteItemAtIndex: function(index) { | 97 deleteItemAtIndex: function(index) { |
| 62 chrome.send('removeStartupPages', [String(index)]); | 98 chrome.send('removeStartupPages', [String(index)]); |
| 63 }, | 99 }, |
| 64 }; | 100 }; |
| 65 | 101 |
| 66 return { | 102 return { |
| 67 StartupPageList: StartupPageList | 103 StartupPageList: StartupPageList |
| 68 }; | 104 }; |
| 69 }); | 105 }); |
| OLD | NEW |