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

Unified Diff: third_party/polymer/v0_8/components-chromium/iron-menu-behavior/iron-menu-behavior-extracted.js

Issue 1134013004: Rerun reproduce.sh and pick up some missing elements with git add -f. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Lots of small fixes to help wire things together for the 0.8 upgrade. Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/polymer/v0_8/components-chromium/iron-menu-behavior/iron-menu-behavior-extracted.js
diff --git a/third_party/polymer/v0_8/components-chromium/iron-menu-behavior/iron-menu-behavior-extracted.js b/third_party/polymer/v0_8/components-chromium/iron-menu-behavior/iron-menu-behavior-extracted.js
new file mode 100644
index 0000000000000000000000000000000000000000..332ec73ec48af54c0348d1a80b4b930f44e6cacd
--- /dev/null
+++ b/third_party/polymer/v0_8/components-chromium/iron-menu-behavior/iron-menu-behavior-extracted.js
@@ -0,0 +1,121 @@
+
+
+ Polymer.IronMenuBehavior = Polymer.IronMultiSelectableBehavior.concat({
+
+ properties: {
+
+ /**
+ * Returns the currently focused item.
+ *
+ * @attribute focusedItem
+ * @type Object
+ */
+ focusedItem: {
+ observer: '_focusedItemChanged',
+ readOnly: true,
+ type: Object
+ },
+
+ /**
+ * The attribute to use on menu items to look up the item title. Typing the first
+ * letter of an item when the menu is open focuses that item. If unset, `textContent`
+ * will be used.
+ *
+ * @attribute attrForItemTitle
+ * @type String
+ */
+ attrForItemTitle: {
+ type: String
+ }
+
+ },
+
+ observers: [
+ '_selectedItemsChanged(selectedItems)',
+ '_selectedItemChanged(selectedItem)'
+ ],
+
+ hostAttributes: {
+ 'role': 'menu',
+ 'tabindex': '0'
+ },
+
+ listeners: {
+ 'focus': '_onFocus',
+ 'keydown': '_onKeydown'
+ },
+
+ _focusedItemChanged: function(focusedItem, old) {
+ old && old.setAttribute('tabindex', '-1');
+ if (focusedItem) {
+ focusedItem.setAttribute('tabindex', '0');
+ focusedItem.focus();
+ }
+ },
+
+ _selectedItemsChanged: function(selectedItems) {
+ this._setFocusedItem(selectedItems[0]);
+ },
+
+ _selectedItemChanged: function(selectedItem) {
+ this._setFocusedItem(selectedItem);
+ },
+
+ _onFocus: function(event) {
+ // clear the cached focus item
+ this._setFocusedItem(null);
+ // focus the selected item when the menu receives focus, or the first item
+ // if no item is selected
+ var selectedItem = this.multi ? (this.selectedItems && this.selectedItems[0]) : this.selectedItem;
+ if (selectedItem) {
+ this._setFocusedItem(selectedItem);
+ } else {
+ this._setFocusedItem(this.items[0]);
+ }
+ },
+
+ _onKeydown: function(event) {
+ // FIXME want to define these somewhere, core-a11y-keys?
+ var DOWN = 40;
+ var UP = 38;
+ var ESC = 27;
+ var ENTER = 13;
+ if (event.keyCode === DOWN) {
+ // up and down arrows moves the focus
+ this._focusNext();
+ } else if (event.keyCode === UP) {
+ this._focusPrevious();
+ } else if (event.keyCode === ESC) {
+ // esc blurs the control
+ this.focusedItem.blur();
+ } else if (event.keyCode === ENTER) {
+ // enter activates the item unless it is disabled
+ if (!this.focusedItem.hasAttribute('disabled')) {
+ this._activateHandler(event);
+ }
+ } else {
+ // all other keys focus the menu item starting with that character
+ for (var i = 0, item; item = this.items[i]; i++) {
+ var attr = this.attrForItemTitle || 'textContent';
+ var title = item[attr] || item.getAttribute(attr);
+ if (title && title.trim().charAt(0).toLowerCase() === String.fromCharCode(event.keyCode).toLowerCase()) {
+ this._setFocusedItem(item);
+ break;
+ }
+ }
+ }
+ },
+
+ _focusPrevious: function() {
+ var length = this.items.length;
+ var index = (Number(this.indexOf(this.focusedItem)) - 1 + length) % length;
+ this._setFocusedItem(this.items[index]);
+ },
+
+ _focusNext: function() {
+ var index = (Number(this.indexOf(this.focusedItem)) + 1) % this.items.length;
+ this._setFocusedItem(this.items[index]);
+ }
+
+ });
+

Powered by Google App Engine
This is Rietveld 408576698