browser_options_startup_page_list.js revision 21d179b334e59e9a3bfcaed4c4430bef1bc5759d
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
3// found in the LICENSE file.
4
5cr.define('options.browser_options', function() {
6  const DeletableItemList = options.DeletableItemList;
7  const DeletableItem = options.DeletableItem;
8
9  /**
10   * Creates a new startup page list item.
11   * @param {Object} pageInfo The page this item represents.
12   * @constructor
13   * @extends {cr.ui.ListItem}
14   */
15  function StartupPageListItem(pageInfo) {
16    var el = cr.doc.createElement('div');
17    el.pageInfo_ = pageInfo;
18    StartupPageListItem.decorate(el);
19    return el;
20  }
21
22  /**
23   * Decorates an element as a startup page list item.
24   * @param {!HTMLElement} el The element to decorate.
25   */
26  StartupPageListItem.decorate = function(el) {
27    el.__proto__ = StartupPageListItem.prototype;
28    el.decorate();
29  };
30
31  StartupPageListItem.prototype = {
32    __proto__: DeletableItem.prototype,
33
34    /** @inheritDoc */
35    decorate: function() {
36      DeletableItem.prototype.decorate.call(this);
37
38      var titleEl = this.ownerDocument.createElement('span');
39      titleEl.className = 'title';
40      titleEl.classList.add('favicon-cell');
41      titleEl.textContent = this.pageInfo_['title'];
42      titleEl.style.backgroundImage = url('chrome://favicon/' +
43                                          this.pageInfo_['url']);
44      titleEl.title = this.pageInfo_['tooltip'];
45
46      this.contentElement.appendChild(titleEl);
47    },
48  };
49
50  var StartupPageList = cr.ui.define('list');
51
52  StartupPageList.prototype = {
53    __proto__: DeletableItemList.prototype,
54
55    /** @inheritDoc */
56    createItem: function(pageInfo) {
57      return new StartupPageListItem(pageInfo);
58    },
59
60    /** @inheritDoc */
61    deleteItemAtIndex: function(index) {
62      chrome.send('removeStartupPages', [String(index)]);
63    },
64  };
65
66  return {
67    StartupPageList: StartupPageList
68  };
69});
70