| Index: chrome/browser/resources/chromeos/menu.js
|
| diff --git a/chrome/browser/resources/chromeos/menu.js b/chrome/browser/resources/chromeos/menu.js
|
| index 68fc48e04026b9805f465d3db122ec041f1d96dc..93aa49c4f35a066ad1f524a2d37dece81531024a 100644
|
| --- a/chrome/browser/resources/chromeos/menu.js
|
| +++ b/chrome/browser/resources/chromeos/menu.js
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -29,14 +29,17 @@ function sendActivate(index, mode) {
|
|
|
| /**
|
| * MenuItem class.
|
| + * @constructor
|
| + * @extends {HTMLDivElement}
|
| */
|
| var MenuItem = cr.ui.define('div');
|
|
|
| MenuItem.prototype = {
|
| - __proto__ : HTMLDivElement.prototype,
|
| + __proto__: HTMLDivElement.prototype,
|
|
|
| /**
|
| * Decorates the menu item element.
|
| + * @this {MenuItem}
|
| */
|
| decorate: function() {
|
| this.className = 'menu-item';
|
| @@ -50,6 +53,7 @@ MenuItem.prototype = {
|
| * properties. This is created from menu model in C code. See
|
| * chromeos/views/native_menu_webui.cc.
|
| * @param {Object} model The model object.
|
| + * @this {MenuItem}
|
| */
|
| init: function(menu, attrs, model) {
|
| // The left icon's width. 0 if no icon.
|
| @@ -81,6 +85,7 @@ MenuItem.prototype = {
|
| * Changes the selection state of the menu item.
|
| * @param {boolean} selected True to set the selection, or false
|
| * otherwise.
|
| + * @this {MenuItem}
|
| */
|
| set selected(selected) {
|
| if (selected) {
|
| @@ -93,6 +98,7 @@ MenuItem.prototype = {
|
|
|
| /**
|
| * Activate the menu item.
|
| + * @this {MenuItem}
|
| */
|
| activate: function() {
|
| if (this.attrs.type == 'submenu') {
|
| @@ -106,6 +112,7 @@ MenuItem.prototype = {
|
|
|
| /**
|
| * Sends open_submenu WebUI message.
|
| + * @this {MenuItem}
|
| */
|
| sendOpenSubmenuCommand: function() {
|
| chrome.send('open_submenu',
|
| @@ -115,6 +122,7 @@ MenuItem.prototype = {
|
|
|
| /**
|
| * Internal method to initiailze the MenuItem.
|
| + * @this {MenuItem}
|
| * @private
|
| */
|
| initMenuItem_: function() {
|
| @@ -180,6 +188,8 @@ MenuItem.prototype = {
|
|
|
| /**
|
| * Menu class.
|
| + * @constructor
|
| + * @extends {HTMLDivElement}
|
| */
|
| var Menu = cr.ui.define('div');
|
|
|
| @@ -190,60 +200,61 @@ Menu.prototype = {
|
| * Configuration object.
|
| * @type {Object}
|
| */
|
| - config_ : null,
|
| + config_: null,
|
|
|
| /**
|
| * Currently selected menu item.
|
| * @type {MenuItem}
|
| */
|
| - current_ : null,
|
| + current_: null,
|
|
|
| /**
|
| * Timers for opening/closing submenu.
|
| * @type {number}
|
| */
|
| - openSubmenuTimer_ : 0,
|
| - closeSubmenuTimer_ : 0,
|
| + openSubmenuTimer_: 0,
|
| + closeSubmenuTimer_: 0,
|
|
|
| /**
|
| * Auto scroll timer.
|
| * @type {number}
|
| */
|
| - scrollTimer_ : 0,
|
| + scrollTimer_: 0,
|
|
|
| /**
|
| * Pointer to a submenu currently shown, if any.
|
| * @type {MenuItem}
|
| */
|
| - submenuShown_ : null,
|
| + submenuShown_: null,
|
|
|
| /**
|
| * True if this menu is root.
|
| * @type {boolean}
|
| */
|
| - isRoot_ : false,
|
| + isRoot_: false,
|
|
|
| /**
|
| * Scrollable Viewport.
|
| * @type {HTMLElement}
|
| */
|
| - viewpotr_ : null,
|
| + viewpotr_: null,
|
|
|
| /**
|
| * Total hight of scroll buttons. Used to adjust the height of
|
| * viewport in order to show scroll bottons without scrollbar.
|
| * @type {number}
|
| */
|
| - buttonHeight_ : 0,
|
| + buttonHeight_: 0,
|
|
|
| /**
|
| * True to enable scroll button.
|
| * @type {boolean}
|
| */
|
| - scrollEnabled : false,
|
| + scrollEnabled: false,
|
|
|
| /**
|
| * Decorates the menu element.
|
| + * @this {Menu}
|
| */
|
| decorate: function() {
|
| this.id = 'viewport';
|
| @@ -253,6 +264,7 @@ Menu.prototype = {
|
| * Initialize the menu.
|
| * @param {Object} config Configuration parameters in JSON format.
|
| * See chromeos/views/native_menu_webui.cc for details.
|
| + * @this {Menu}
|
| */
|
| init: function(config) {
|
| // List of menu items
|
| @@ -269,8 +281,8 @@ Menu.prototype = {
|
| window.addEventListener('resize', this.onResize_.bind(this));
|
|
|
| // Setup scroll events.
|
| - var up = document.getElementById('scroll-up');
|
| - var down = document.getElementById('scroll-down');
|
| + var up = $('scroll-up');
|
| + var down = $('scroll-down');
|
| up.addEventListener('mouseout', this.stopScroll_.bind(this));
|
| down.addEventListener('mouseout', this.stopScroll_.bind(this));
|
| var menu = this;
|
| @@ -299,6 +311,7 @@ Menu.prototype = {
|
| * @param {boolean} enableMnemonic True to enable mnemonic, or false
|
| * to not to interprete mnemonic key. The function removes '&'
|
| * from the label in both cases.
|
| + * @this {Menu}
|
| */
|
| addLabelTo: function(item, label, targetDiv, enableMnemonic) {
|
| var mnemonic = MNEMONIC_REGEXP.exec(label);
|
| @@ -321,6 +334,8 @@ Menu.prototype = {
|
|
|
| /**
|
| * Returns the index of the {@code item}.
|
| + * @this {Menu}
|
| + * @return {number} Menu item index.
|
| */
|
| getMenuItemIndexOf: function(item) {
|
| return this.items_.indexOf(item);
|
| @@ -331,6 +346,7 @@ Menu.prototype = {
|
| * of MenuItem, or any HTMLElement that implements {@code init},
|
| * {@code activate} methods as well as {@code selected} attribute.
|
| * @param {Object} attrs The menu item's properties passed from C++.
|
| + * @return {Object} Menu Item instance.
|
| */
|
| createMenuItem: function(attrs) {
|
| return new MenuItem();
|
| @@ -338,6 +354,8 @@ Menu.prototype = {
|
|
|
| /**
|
| * Update and display the new model.
|
| + * @param {Object} model New model object.
|
| + * @this {Menu}
|
| */
|
| updateModel: function(model) {
|
| this.isRoot = model.isRoot;
|
| @@ -358,17 +376,19 @@ Menu.prototype = {
|
| /**
|
| * Highlights the currently selected item, or
|
| * select the 1st selectable item if none is selected.
|
| + * @this {Menu}
|
| */
|
| showSelection: function() {
|
| if (this.current_) {
|
| this.current_.selected = true;
|
| - } else {
|
| + } else {
|
| this.findNextEnabled_(1).selected = true;
|
| }
|
| },
|
|
|
| /**
|
| * Add event handlers for the item.
|
| + * @this {Menu}
|
| */
|
| addHandlers: function(item, target) {
|
| var menu = this;
|
| @@ -399,6 +419,7 @@ Menu.prototype = {
|
| * submenu.
|
| *
|
| * @param {MenuItem} item The selected item.
|
| + * @this {Menu}
|
| */
|
| set selectedItem(item) {
|
| if (this.current_ != item) {
|
| @@ -435,6 +456,7 @@ Menu.prototype = {
|
| * Open submenu {@code item}. It does nothing if the submenu is
|
| * already opened.
|
| * @param {MenuItem} item The submenu item to open.
|
| + * @this {Menu}
|
| */
|
| openSubmenu: function(item) {
|
| this.cancelSubmenuTimer_();
|
| @@ -446,6 +468,7 @@ Menu.prototype = {
|
|
|
| /**
|
| * Handle keyboard navigation and activation.
|
| + * @this {Menu}
|
| * @private
|
| */
|
| onKeydown_: function(event) {
|
| @@ -467,7 +490,7 @@ Menu.prototype = {
|
| case 'U+0009': // tab
|
| break;
|
| case 'U+001B': // escape
|
| - chrome.send('close_all', []);
|
| + chrome.send('close_all');
|
| break;
|
| case 'Enter':
|
| case 'U+0020': // space
|
| @@ -480,6 +503,7 @@ Menu.prototype = {
|
|
|
| /**
|
| * Handle mnemonic keys.
|
| + * @this {Menu}
|
| * @private
|
| */
|
| onKeypress_: function(event) {
|
| @@ -492,11 +516,19 @@ Menu.prototype = {
|
| }
|
| },
|
|
|
| - // Mouse Event handlers
|
| + /**
|
| + * Mouse click event handler.
|
| + * @private
|
| + */
|
| onClick_: function(event, item) {
|
| item.activate();
|
| },
|
|
|
| + /**
|
| + * Mouse over event handler.
|
| + * @this {Menu}
|
| + * @private
|
| + */
|
| onMouseover_: function(event, item) {
|
| this.cancelSubmenuTimer_();
|
| // Ignore false mouseover event at (0,0) which is
|
| @@ -506,15 +538,25 @@ Menu.prototype = {
|
| }
|
| },
|
|
|
| + /**
|
| + * Mouse out event handler.
|
| + * @this {Menu}
|
| + * @private
|
| + */
|
| onMouseout_: function(event) {
|
| if (this.current_) {
|
| this.current_.selected = false;
|
| }
|
| },
|
|
|
| + /**
|
| + * Handles window resize action.
|
| + * @this {Menu}
|
| + * @private
|
| + */
|
| onResize_: function() {
|
| - var up = document.getElementById('scroll-up');
|
| - var down = document.getElementById('scroll-down');
|
| + var up = $('scroll-up');
|
| + var down = $('scroll-down');
|
| // this needs to be < 2 as empty page has height of 1.
|
| if (window.innerHeight < 2) {
|
| // menu window is not visible yet. just hide buttons.
|
| @@ -536,6 +578,11 @@ Menu.prototype = {
|
| }
|
| },
|
|
|
| + /**
|
| + * Mouse wheel scroll event.
|
| + * @this {Menu}
|
| + * @private
|
| + */
|
| onMouseWheel_: function(event) {
|
| var delta = event.wheelDelta / 5;
|
| this.scrollTop -= delta;
|
| @@ -544,17 +591,19 @@ Menu.prototype = {
|
| /**
|
| * Closes the submenu.
|
| * a submenu.
|
| + * @this {Menu}
|
| * @private
|
| */
|
| closeSubmenu_: function(item) {
|
| this.submenuShown_ = null;
|
| this.cancelSubmenuTimer_();
|
| - chrome.send('close_submenu', []);
|
| + chrome.send('close_submenu');
|
| },
|
|
|
| /**
|
| * Move the selection to parent menu if the current menu is
|
| * a submenu.
|
| + * @this {Menu}
|
| * @private
|
| */
|
| moveToParent_: function() {
|
| @@ -562,20 +611,21 @@ Menu.prototype = {
|
| if (this.current_) {
|
| this.current_.selected = false;
|
| }
|
| - chrome.send('move_to_parent', []);
|
| + chrome.send('move_to_parent');
|
| }
|
| },
|
|
|
| /**
|
| * Move the selection to submenu if the currently selected
|
| * menu is a submenu.
|
| + * @this {Menu}
|
| * @private
|
| */
|
| - moveToSubmenu_: function () {
|
| + moveToSubmenu_: function() {
|
| var current = this.current_;
|
| if (current && current.attrs.type == 'submenu') {
|
| this.openSubmenu(current);
|
| - chrome.send('move_to_submenu', []);
|
| + chrome.send('move_to_submenu');
|
| }
|
| },
|
|
|
| @@ -585,7 +635,10 @@ Menu.prototype = {
|
| * selectable.
|
| * @param {number} incr Specifies the direction to search, 1 to
|
| * downwards and -1 for upwards.
|
| + * @this {Menu}
|
| * @private
|
| + *
|
| + * @return {Object} Next enabled menu item.
|
| */
|
| findNextEnabled_: function(incr) {
|
| var len = this.items_.length;
|
| @@ -607,6 +660,7 @@ Menu.prototype = {
|
|
|
| /**
|
| * Cancels timers to open/close submenus.
|
| + * @this {Menu}
|
| * @private
|
| */
|
| cancelSubmenuTimer_: function() {
|
| @@ -619,6 +673,7 @@ Menu.prototype = {
|
| /**
|
| * Starts auto scroll.
|
| * @param {number} tick The number of pixels to scroll.
|
| + * @this {Menu}
|
| * @private
|
| */
|
| autoScroll_: function(tick) {
|
| @@ -634,18 +689,20 @@ Menu.prototype = {
|
|
|
| /**
|
| * Stops auto scroll.
|
| + * @this {Menu}
|
| * @private
|
| */
|
| - stopScroll_: function () {
|
| + stopScroll_: function() {
|
| clearTimeout(this.scrollTimer_);
|
| this.scrollTimer_ = 0;
|
| },
|
|
|
| /**
|
| * Scrolls the viewport to make the selected item visible.
|
| + * @this {Menu}
|
| * @private
|
| */
|
| - makeSelectedItemVisible_: function(){
|
| + makeSelectedItemVisible_: function() {
|
| this.current_.scrollIntoViewIfNeeded(false);
|
| },
|
| };
|
| @@ -653,22 +710,35 @@ Menu.prototype = {
|
| /**
|
| * functions to be called from C++.
|
| */
|
| -function init(config) {
|
| - document.getElementById('viewport').init(config);
|
| +function modelUpdated() {
|
| + chrome.send('model_updated');
|
| }
|
|
|
| function selectItem() {
|
| - document.getElementById('viewport').showSelection();
|
| + $('viewport').showSelection();
|
| }
|
|
|
| -function updateModel(model) {
|
| - document.getElementById('viewport').updateModel(model);
|
| +/**
|
| + * Function called from C++ to initialize the menu item.
|
| + * @param {Object} config Configuration parameters in JSON format.
|
| + * See chromeos/views/native_menu_webui.cc for details.
|
| + */
|
| +function init(config) {
|
| + $('viewport').init(config);
|
| }
|
|
|
| -function modelUpdated() {
|
| - chrome.send('model_updated', []);
|
| +/**
|
| + * Function called from C++ to update menu item model.
|
| + * @param {Object} model New model object.
|
| + */
|
| +function updateModel(model) {
|
| + $('viewport').updateModel(model);
|
| }
|
|
|
| +/**
|
| + * Function called from C++ to enable scroll on menu item.
|
| + * @param {boolean} enabled True if scroll should be enabled on menu item.
|
| + */
|
| function enableScroll(enabled) {
|
| - document.getElementById('viewport').scrollEnabled = enabled;
|
| + $('viewport').scrollEnabled = enabled;
|
| }
|
|
|