Index: third_party/google_input_tools/third_party/closure_library/closure/goog/ui/container.js |
diff --git a/third_party/google_input_tools/third_party/closure_library/closure/goog/ui/container.js b/third_party/google_input_tools/third_party/closure_library/closure/goog/ui/container.js |
index b33947b292fbd5b03ff2f26b66fe2b45342f5e65..5f4eb5c5b5baa32efd238664a5ac5ab88e3c7e3a 100644 |
--- a/third_party/google_input_tools/third_party/closure_library/closure/goog/ui/container.js |
+++ b/third_party/google_input_tools/third_party/closure_library/closure/goog/ui/container.js |
@@ -575,6 +575,15 @@ goog.ui.Container.prototype.handleCloseItem = function(e) { |
if (e.target == this.openItem_) { |
this.openItem_ = null; |
} |
+ |
+ var element = this.getElement(); |
+ var targetEl = e.target.getElement(); |
+ // Set the active descendant to the menu item when its submenu is closed and |
+ // it is still highlighted. This can sometimes be called when the menuitem is |
+ // unhighlighted because the focus moved elsewhere, do nothing at that point. |
+ if (element && e.target.isHighlighted() && targetEl) { |
+ goog.a11y.aria.setActiveDescendant(element, targetEl); |
+ } |
}; |
@@ -882,6 +891,8 @@ goog.ui.Container.prototype.getChildAt; |
* @override |
*/ |
goog.ui.Container.prototype.addChildAt = function(control, index, opt_render) { |
+ goog.asserts.assertInstanceof(control, goog.ui.Control); |
+ |
// Make sure the child control dispatches HIGHLIGHT, UNHIGHLIGHT, OPEN, and |
// CLOSE events, and that it doesn't steal keyboard focus. |
control.setDispatchTransitionEvents(goog.ui.Component.State.HOVER, true); |
@@ -893,6 +904,9 @@ goog.ui.Container.prototype.addChildAt = function(control, index, opt_render) { |
// Disable mouse event handling by child controls. |
control.setHandleMouseEvents(false); |
+ var srcIndex = (control.getParent() == this) ? |
+ this.indexOfChild(control) : -1; |
+ |
// Let the superclass implementation do the work. |
goog.ui.Container.superClass_.addChildAt.call(this, control, index, |
opt_render); |
@@ -901,9 +915,33 @@ goog.ui.Container.prototype.addChildAt = function(control, index, opt_render) { |
this.registerChildId_(control); |
} |
- // Update the highlight index, if needed. |
- if (index <= this.highlightedIndex_) { |
+ this.updateHighlightedIndex_(srcIndex, index); |
+}; |
+ |
+ |
+/** |
+ * Updates the highlighted index when children are added or moved. |
+ * @param {number} fromIndex Index of the child before it was moved, or -1 if |
+ * the child was added. |
+ * @param {number} toIndex Index of the child after it was moved or added. |
+ * @private |
+ */ |
+goog.ui.Container.prototype.updateHighlightedIndex_ = function( |
+ fromIndex, toIndex) { |
+ if (fromIndex == -1) { |
+ fromIndex = this.getChildCount(); |
+ } |
+ if (fromIndex == this.highlightedIndex_) { |
+ // The highlighted element itself was moved. |
+ this.highlightedIndex_ = Math.min(this.getChildCount() - 1, toIndex); |
+ } else if (fromIndex > this.highlightedIndex_ && |
+ toIndex <= this.highlightedIndex_) { |
+ // The control was added or moved behind the highlighted index. |
this.highlightedIndex_++; |
+ } else if (fromIndex < this.highlightedIndex_ && |
+ toIndex > this.highlightedIndex_) { |
+ // The control was moved from before to behind the highlighted index. |
+ this.highlightedIndex_--; |
} |
}; |
@@ -922,6 +960,7 @@ goog.ui.Container.prototype.addChildAt = function(control, index, opt_render) { |
*/ |
goog.ui.Container.prototype.removeChild = function(control, opt_unrender) { |
control = goog.isString(control) ? this.getChild(control) : control; |
+ goog.asserts.assertInstanceof(control, goog.ui.Control); |
if (control) { |
var index = this.indexOfChild(control); |
@@ -941,7 +980,7 @@ goog.ui.Container.prototype.removeChild = function(control, opt_unrender) { |
} |
} |
- control = /** @type {goog.ui.Control} */ ( |
+ control = /** @type {!goog.ui.Control} */ ( |
goog.ui.Container.superClass_.removeChild.call(this, control, |
opt_unrender)); |
@@ -1243,8 +1282,9 @@ goog.ui.Container.prototype.highlightPrevious = function() { |
/** |
* Helper function that manages the details of moving the highlight among |
* child controls in response to keyboard events. |
- * @param {function(number, number) : number} fn Function that accepts the |
- * current and maximum indices, and returns the next index to check. |
+ * @param {function(this: goog.ui.Container, number, number) : number} fn |
+ * Function that accepts the current and maximum indices, and returns the |
+ * next index to check. |
* @param {number} startIndex Start index. |
* @return {boolean} Whether the highlight has changed. |
* @protected |