Debian Codegraph @

closure-library/closure/goog/ui/menubase.js

raw
1 // Copyright 2006 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 Definition of the MenuBase class.
17 *
18 */
19
20 goog.provide('goog.ui.MenuBase');
21
22 goog.require('goog.events.EventHandler');
23 goog.require('goog.events.EventType');
24 goog.require('goog.events.KeyHandler');
25 goog.require('goog.ui.Popup');
26
27
28
29 /**
30 * The MenuBase class provides an abstract base class for different
31 * implementations of menu controls.
32 *
33 * @param {Element=} opt_element A DOM element for the popup.
34 * @deprecated Use goog.ui.Menu.
35 * @constructor
36 * @extends {goog.ui.Popup}
37 */
38 goog.ui.MenuBase = function(opt_element) {
39 goog.ui.Popup.call(this, opt_element);
40
41 /**
42 * Event handler for simplifiying adding/removing listeners.
43 * @type {goog.events.EventHandler<!goog.ui.MenuBase>}
44 * @private
45 */
46 this.eventHandler_ = new goog.events.EventHandler(this);
47
48 /**
49 * KeyHandler to cope with the vagaries of cross-browser key events.
50 * @type {goog.events.KeyHandler}
51 * @private
52 */
53 this.keyHandler_ = new goog.events.KeyHandler(this.getElement());
54 };
55 goog.inherits(goog.ui.MenuBase, goog.ui.Popup);
56
57
58 /**
59 * Events fired by the Menu
60 * @const
61 */
62 goog.ui.MenuBase.Events = {};
63
64
65 /**
66 * Event fired by the Menu when an item is "clicked".
67 */
68 goog.ui.MenuBase.Events.ITEM_ACTION = 'itemaction';
69
70
71 /** @override */
72 goog.ui.MenuBase.prototype.disposeInternal = function() {
73 goog.ui.MenuBase.superClass_.disposeInternal.call(this);
74 this.eventHandler_.dispose();
75 this.keyHandler_.dispose();
76 };
77
78
79 /**
80 * Called after the menu is shown. Derived classes can override to hook this
81 * event but should make sure to call the parent class method.
82 *
83 * @protected
84 * @override
85 */
86 goog.ui.MenuBase.prototype.onShow = function() {
87 goog.ui.MenuBase.superClass_.onShow.call(this);
88
89 // register common event handlers for derived classes
90 var el = this.getElement();
91 this.eventHandler_.listen(
92 el, goog.events.EventType.MOUSEOVER, this.onMouseOver);
93 this.eventHandler_.listen(
94 el, goog.events.EventType.MOUSEOUT, this.onMouseOut);
95 this.eventHandler_.listen(
96 el, goog.events.EventType.MOUSEDOWN, this.onMouseDown);
97 this.eventHandler_.listen(el, goog.events.EventType.MOUSEUP, this.onMouseUp);
98
99 this.eventHandler_.listen(
100 this.keyHandler_, goog.events.KeyHandler.EventType.KEY, this.onKeyDown);
101 };
102
103
104 /**
105 * Called after the menu is hidden. Derived classes can override to hook this
106 * event but should make sure to call the parent class method.
107 * @param {?Node=} opt_target Target of the event causing the hide.
108 * @protected
109 * @override
110 */
111 goog.ui.MenuBase.prototype.onHide = function(opt_target) {
112 goog.ui.MenuBase.superClass_.onHide.call(this, opt_target);
113
114 // remove listeners when hidden
115 this.eventHandler_.removeAll();
116 };
117
118
119 /**
120 * Returns the selected item
121 *
122 * @return {Object} The item selected or null if no item is selected.
123 */
124 goog.ui.MenuBase.prototype.getSelectedItem = function() {
125 return null;
126 };
127
128
129 /**
130 * Sets the selected item
131 *
132 * @param {Object} item The item to select. The type of this item is specific
133 * to the menu class.
134 */
135 goog.ui.MenuBase.prototype.setSelectedItem = function(item) {};
136
137
138 /**
139 * Mouse over handler for the menu. Derived classes should override.
140 *
141 * @param {goog.events.Event} e The event object.
142 * @protected
143 */
144 goog.ui.MenuBase.prototype.onMouseOver = function(e) {};
145
146
147 /**
148 * Mouse out handler for the menu. Derived classes should override.
149 *
150 * @param {goog.events.Event} e The event object.
151 * @protected
152 */
153 goog.ui.MenuBase.prototype.onMouseOut = function(e) {};
154
155
156 /**
157 * Mouse down handler for the menu. Derived classes should override.
158 *
159 * @param {!goog.events.Event} e The event object.
160 * @protected
161 */
162 goog.ui.MenuBase.prototype.onMouseDown = function(e) {};
163
164
165 /**
166 * Mouse up handler for the menu. Derived classes should override.
167 *
168 * @param {goog.events.Event} e The event object.
169 * @protected
170 */
171 goog.ui.MenuBase.prototype.onMouseUp = function(e) {};
172
173
174 /**
175 * Key down handler for the menu. Derived classes should override.
176 *
177 * @param {goog.events.KeyEvent} e The event object.
178 * @protected
179 */
180 goog.ui.MenuBase.prototype.onKeyDown = function(e) {};