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