toolbar.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2007 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview A toolbar class that hosts {@link goog.ui.Control}s such as
  16. * buttons and menus, along with toolbar-specific renderers of those controls.
  17. *
  18. * @author attila@google.com (Attila Bodis)
  19. * @see ../demos/toolbar.html
  20. */
  21. goog.provide('goog.ui.Toolbar');
  22. goog.require('goog.ui.Container');
  23. goog.require('goog.ui.ToolbarRenderer');
  24. /**
  25. * A toolbar class, implemented as a {@link goog.ui.Container} that defaults to
  26. * having a horizontal orientation and {@link goog.ui.ToolbarRenderer} as its
  27. * renderer.
  28. * @param {goog.ui.ToolbarRenderer=} opt_renderer Renderer used to render or
  29. * decorate the toolbar; defaults to {@link goog.ui.ToolbarRenderer}.
  30. * @param {?goog.ui.Container.Orientation=} opt_orientation Toolbar orientation;
  31. * defaults to {@code HORIZONTAL}.
  32. * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper.
  33. * @constructor
  34. * @extends {goog.ui.Container}
  35. */
  36. goog.ui.Toolbar = function(opt_renderer, opt_orientation, opt_domHelper) {
  37. goog.ui.Container.call(
  38. this, opt_orientation,
  39. opt_renderer || goog.ui.ToolbarRenderer.getInstance(), opt_domHelper);
  40. };
  41. goog.inherits(goog.ui.Toolbar, goog.ui.Container);
  42. /** @override */
  43. goog.ui.Toolbar.prototype.handleFocus = function(e) {
  44. goog.ui.Toolbar.base(this, 'handleFocus', e);
  45. // Highlight the first highlightable item on focus via the keyboard for ARIA
  46. // spec compliance. Do not highlight the item if the mouse button is pressed,
  47. // since this method is also called from handleMouseDown when a toolbar button
  48. // is clicked.
  49. if (!this.isMouseButtonPressed()) {
  50. this.highlightFirst();
  51. }
  52. };