toolbarrenderer.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2008 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 Renderer for {@link goog.ui.Toolbar}s.
  16. *
  17. * @author attila@google.com (Attila Bodis)
  18. */
  19. goog.provide('goog.ui.ToolbarRenderer');
  20. goog.require('goog.a11y.aria.Role');
  21. goog.require('goog.dom.TagName');
  22. goog.require('goog.ui.Container');
  23. goog.require('goog.ui.ContainerRenderer');
  24. goog.require('goog.ui.Separator');
  25. goog.require('goog.ui.ToolbarSeparatorRenderer');
  26. /**
  27. * Default renderer for {@link goog.ui.Toolbar}s, based on {@link
  28. * goog.ui.ContainerRenderer}.
  29. * @constructor
  30. * @extends {goog.ui.ContainerRenderer}
  31. */
  32. goog.ui.ToolbarRenderer = function() {
  33. goog.ui.ContainerRenderer.call(this, goog.a11y.aria.Role.TOOLBAR);
  34. };
  35. goog.inherits(goog.ui.ToolbarRenderer, goog.ui.ContainerRenderer);
  36. goog.addSingletonGetter(goog.ui.ToolbarRenderer);
  37. /**
  38. * Default CSS class to be applied to the root element of toolbars rendered
  39. * by this renderer.
  40. * @type {string}
  41. */
  42. goog.ui.ToolbarRenderer.CSS_CLASS = goog.getCssName('goog-toolbar');
  43. /**
  44. * Inspects the element, and creates an instance of {@link goog.ui.Control} or
  45. * an appropriate subclass best suited to decorate it. Overrides the superclass
  46. * implementation by recognizing HR elements as separators.
  47. * @param {Element} element Element to decorate.
  48. * @return {goog.ui.Control?} A new control suitable to decorate the element
  49. * (null if none).
  50. * @override
  51. */
  52. goog.ui.ToolbarRenderer.prototype.getDecoratorForChild = function(element) {
  53. return element.tagName == goog.dom.TagName.HR ?
  54. new goog.ui.Separator(goog.ui.ToolbarSeparatorRenderer.getInstance()) :
  55. goog.ui.ToolbarRenderer.superClass_.getDecoratorForChild.call(
  56. this, element);
  57. };
  58. /**
  59. * Returns the CSS class to be applied to the root element of containers
  60. * rendered using this renderer.
  61. * @return {string} Renderer-specific CSS class.
  62. * @override
  63. */
  64. goog.ui.ToolbarRenderer.prototype.getCssClass = function() {
  65. return goog.ui.ToolbarRenderer.CSS_CLASS;
  66. };
  67. /**
  68. * Returns the default orientation of containers rendered or decorated by this
  69. * renderer. This implementation returns {@code HORIZONTAL}.
  70. * @return {goog.ui.Container.Orientation} Default orientation for containers
  71. * created or decorated by this renderer.
  72. * @override
  73. */
  74. goog.ui.ToolbarRenderer.prototype.getDefaultOrientation = function() {
  75. return goog.ui.Container.Orientation.HORIZONTAL;
  76. };