diff options
author | zvorygin@chromium.org <zvorygin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 18:06:20 +0000 |
---|---|---|
committer | zvorygin@chromium.org <zvorygin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 18:06:20 +0000 |
commit | 74a5da941800db7be37bba080d5b6a351ccc47e1 (patch) | |
tree | 1591747eadb615e41bdf63703c9ba0656a65a837 | |
parent | b4fcefc6fbd5f127441c222d29ba3f415c2ff194 (diff) | |
download | chromium_src-74a5da941800db7be37bba080d5b6a351ccc47e1.zip chromium_src-74a5da941800db7be37bba080d5b6a351ccc47e1.tar.gz chromium_src-74a5da941800db7be37bba080d5b6a351ccc47e1.tar.bz2 |
Added menuItem icon support, and little API for menu modification.
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com/10377169
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137687 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/resources/shared/js/cr/ui/menu.js | 42 | ||||
-rw-r--r-- | chrome/browser/resources/shared/js/cr/ui/menu_item.js | 15 |
2 files changed, 57 insertions, 0 deletions
diff --git a/chrome/browser/resources/shared/js/cr/ui/menu.js b/chrome/browser/resources/shared/js/cr/ui/menu.js index 94fea75..1928293 100644 --- a/chrome/browser/resources/shared/js/cr/ui/menu.js +++ b/chrome/browser/resources/shared/js/cr/ui/menu.js @@ -34,6 +34,41 @@ cr.define('cr.ui', function() { }, /** + * Adds menu item at the end of the list. + * @param {Object} item Menu item properties. + * @return {cr.ui.MenuItem} The created menu item. + */ + addMenuItem: function(item) { + var menuItem = this.ownerDocument.createElement('menuitem'); + this.appendChild(menuItem); + + cr.ui.decorate(menuItem, MenuItem); + + if (item.label) + menuItem.label = item.label; + + if (item.iconUrl) + menuItem.iconUrl = item.iconUrl; + + return menuItem; + }, + + /** + * Adds separator at the end of the list. + */ + addSeparator: function() { + var separator = this.ownerDocument.createElement('hr'); + this.appendChild(separator); + }, + + /** + * Clears menu. + */ + clear: function() { + this.textContent = ''; + }, + + /** * Walks up the ancestors of |el| until a menu item belonging to this menu * is found. * @param {Element} el The element to start searching from. @@ -79,6 +114,13 @@ cr.define('cr.ui', function() { }, /** + * Menu length + */ + get length() { + return this.children.length; + }, + + /** * This is the function that handles keyboard navigation. This is usually * called by the element responsible for managing the menu. * @param {Event} e The keydown event object. diff --git a/chrome/browser/resources/shared/js/cr/ui/menu_item.js b/chrome/browser/resources/shared/js/cr/ui/menu_item.js index 667d2f0..5b1ce65 100644 --- a/chrome/browser/resources/shared/js/cr/ui/menu_item.js +++ b/chrome/browser/resources/shared/js/cr/ui/menu_item.js @@ -39,6 +39,10 @@ cr.define('cr.ui', function() { // Adding the 'custom-appearance' class prevents widgets.css from changing // the appearance of this element. this.classList.add('custom-appearance'); + + var iconUrl; + if ((iconUrl = this.getAttribute('icon'))) + this.iconUrl = iconUrl; }, /** @@ -92,6 +96,17 @@ cr.define('cr.ui', function() { }, /** + * Menu icon. + * @type {string} + */ + get iconUrl() { + return this.style.backgroundImage; + }, + set iconUrl(url) { + this.style.backgroundImage = 'url(' + url + ')'; + }, + + /** * @return {boolean} Whether the menu item is a separator. */ isSeparator: function() { |