Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / google_input_tools / third_party / closure_library / closure / goog / ui / menuseparatorrenderer.js
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.MenuSeparator}s.
17  *
18  * @author attila@google.com (Attila Bodis)
19  */
20
21 goog.provide('goog.ui.MenuSeparatorRenderer');
22
23 goog.require('goog.dom');
24 goog.require('goog.dom.classes');
25 goog.require('goog.ui.ControlContent');
26 goog.require('goog.ui.ControlRenderer');
27
28
29
30 /**
31  * Renderer for menu separators.
32  * @constructor
33  * @extends {goog.ui.ControlRenderer}
34  */
35 goog.ui.MenuSeparatorRenderer = function() {
36   goog.ui.ControlRenderer.call(this);
37 };
38 goog.inherits(goog.ui.MenuSeparatorRenderer, goog.ui.ControlRenderer);
39 goog.addSingletonGetter(goog.ui.MenuSeparatorRenderer);
40
41
42 /**
43  * Default CSS class to be applied to the root element of components rendered
44  * by this renderer.
45  * @type {string}
46  */
47 goog.ui.MenuSeparatorRenderer.CSS_CLASS = goog.getCssName('goog-menuseparator');
48
49
50 /**
51  * Returns an empty, styled menu separator DIV.  Overrides {@link
52  * goog.ui.ControlRenderer#createDom}.
53  * @param {goog.ui.Control} separator goog.ui.Separator to render.
54  * @return {Element} Root element for the separator.
55  * @override
56  */
57 goog.ui.MenuSeparatorRenderer.prototype.createDom = function(separator) {
58   return separator.getDomHelper().createDom('div', this.getCssClass());
59 };
60
61
62 /**
63  * Takes an existing element, and decorates it with the separator.  Overrides
64  * {@link goog.ui.ControlRenderer#decorate}.
65  * @param {goog.ui.Control} separator goog.ui.MenuSeparator to decorate the
66  *     element.
67  * @param {Element} element Element to decorate.
68  * @return {Element} Decorated element.
69  * @override
70  */
71 goog.ui.MenuSeparatorRenderer.prototype.decorate = function(separator,
72                                                             element) {
73   // Normally handled in the superclass. But we don't call the superclass.
74   if (element.id) {
75     separator.setId(element.id);
76   }
77
78   if (element.tagName == 'HR') {
79     // Replace HR with separator.
80     var hr = element;
81     element = this.createDom(separator);
82     goog.dom.insertSiblingBefore(element, hr);
83     goog.dom.removeNode(hr);
84   } else {
85     goog.dom.classes.add(element, this.getCssClass());
86   }
87   return element;
88 };
89
90
91 /**
92  * Overrides {@link goog.ui.ControlRenderer#setContent} to do nothing, since
93  * separators are empty.
94  * @param {Element} separator The separator's root element.
95  * @param {goog.ui.ControlContent} content Text caption or DOM structure to be
96  *    set as the separators's content (ignored).
97  * @override
98  */
99 goog.ui.MenuSeparatorRenderer.prototype.setContent = function(separator,
100                                                               content) {
101   // Do nothing.  Separators are empty.
102 };
103
104
105 /**
106  * Returns the CSS class to be applied to the root element of components
107  * rendered using this renderer.
108  * @return {string} Renderer-specific CSS class.
109  * @override
110  */
111 goog.ui.MenuSeparatorRenderer.prototype.getCssClass = function() {
112   return goog.ui.MenuSeparatorRenderer.CSS_CLASS;
113 };