102 |
102 |
103 // set the caption |
103 // set the caption |
104 // style is not updated because the subclass will update the style later |
104 // style is not updated because the subclass will update the style later |
105 // when it has completely initialized the component |
105 // when it has completely initialized the component |
106 this.setCaption(caption, true); |
106 this.setCaption(caption, true); |
107 } |
107 }; |
108 |
108 |
109 // Returns the caption; null if none. |
109 // Returns the caption; null if none. |
110 Control.prototype.getCaption = function() { |
110 Control.prototype.getCaption = function() { |
111 return this.caption; |
111 return this.caption; |
112 } |
112 }; |
113 |
113 |
114 // Sets the caption; null if none. |
114 // Sets the caption; null if none. |
115 Control.prototype.setCaption = function(caption, noStyleUpdate) { |
115 Control.prototype.setCaption = function(caption, noStyleUpdate) { |
116 uiLogger.debug("Control.setCaption(" + caption + ")"); |
116 uiLogger.debug("Control.setCaption(" + caption + ")"); |
117 |
117 |
124 |
124 |
125 // update style |
125 // update style |
126 if (!noStyleUpdate) { |
126 if (!noStyleUpdate) { |
127 this.updateStyleFromState(); |
127 this.updateStyleFromState(); |
128 } |
128 } |
129 } |
129 }; |
130 |
130 |
131 // Returns the enabled state. |
131 // Returns the enabled state. |
132 // Override this in subclasses as required to implement the state change. |
132 // Override this in subclasses as required to implement the state change. |
133 Control.prototype.isEnabled = function() { |
133 Control.prototype.isEnabled = function() { |
134 return false; |
134 return false; |
135 } |
135 }; |
136 |
136 |
137 // Sets the enabled state. |
137 // Sets the enabled state. |
138 // Override this in subclasses as required to implement the state change. |
138 // Override this in subclasses as required to implement the state change. |
139 Control.prototype.setEnabled = function(enabled) { |
139 Control.prototype.setEnabled = function(enabled) { |
140 uiLogger.debug("Control.setEnabled(" + enabled + ")"); |
140 uiLogger.debug("Control.setEnabled(" + enabled + ")"); |
141 } |
141 }; |
142 |
142 |
143 // Returns the focusable state for the control. |
143 // Returns the focusable state for the control. |
144 // Defaults focusable if enabled - override this in subclasses as required. |
144 // Defaults focusable if enabled - override this in subclasses as required. |
145 Control.prototype.isFocusable = function() { |
145 Control.prototype.isFocusable = function() { |
146 return this.isEnabled(); |
146 return this.isEnabled(); |
147 } |
147 }; |
148 |
148 |
149 // Returns the focused state for the control. |
149 // Returns the focused state for the control. |
150 Control.prototype.isFocused = function() { |
150 Control.prototype.isFocused = function() { |
151 return this.focused; |
151 return this.focused; |
152 } |
152 }; |
153 |
153 |
154 // Sets the focused state for the control. |
154 // Sets the focused state for the control. |
155 // Note: This may not always succeed. |
155 // Note: This may not always succeed. |
156 // Override this in subclasses as required to implement the state change. |
156 // Override this in subclasses as required to implement the state change. |
157 Control.prototype.setFocused = function(focused) { |
157 Control.prototype.setFocused = function(focused) { |
158 uiLogger.debug("Control.setFocused(" + focused + ")"); |
158 uiLogger.debug("Control.setFocused(" + focused + ")"); |
159 // note that this.focused gets set as a result of focusStateChanged() being called |
159 // note that this.focused gets set as a result of focusStateChanged() being called |
160 // rather than setting it explicitly here |
160 // rather than setting it explicitly here |
161 } |
161 }; |
162 |
162 |
163 // Called when the focus state has changed for this control. |
163 // Called when the focus state has changed for this control. |
164 Control.prototype.focusStateChanged = function(focused) { |
164 Control.prototype.focusStateChanged = function(focused) { |
165 uiLogger.debug("Control.focusStateChanged(" + focused + ")"); |
165 uiLogger.debug("Control.focusStateChanged(" + focused + ")"); |
166 if (this.focused != focused) { |
166 if (this.focused != focused) { |
175 this.updateStyleFromState(); |
175 this.updateStyleFromState(); |
176 |
176 |
177 // notify event listeners |
177 // notify event listeners |
178 this.fireEvent(this.createEvent("FocusStateChanged", focused)); |
178 this.fireEvent(this.createEvent("FocusStateChanged", focused)); |
179 } |
179 } |
180 } |
180 }; |
181 |
181 |
182 // Called when the hover state has changed for this control. |
182 // Called when the hover state has changed for this control. |
183 Control.prototype.hoverStateChanged = function(hovering) { |
183 Control.prototype.hoverStateChanged = function(hovering) { |
184 uiLogger.debug("Control.hoverStateChanged(" + hovering + ")"); |
184 uiLogger.debug("Control.hoverStateChanged(" + hovering + ")"); |
185 if (this.hovering != hovering) { |
185 if (this.hovering != hovering) { |
189 this.updateStyleFromState(); |
189 this.updateStyleFromState(); |
190 |
190 |
191 // notify event listeners |
191 // notify event listeners |
192 this.fireEvent(this.createEvent("HoverStateChanged", hovering)); |
192 this.fireEvent(this.createEvent("HoverStateChanged", hovering)); |
193 } |
193 } |
194 } |
194 }; |
195 |
195 |
196 // Helper method that returns the state name for the current state. |
196 // Helper method that returns the state name for the current state. |
197 Control.prototype.getStyleStateName = function() { |
197 Control.prototype.getStyleStateName = function() { |
198 var focusable = this.isFocusable(); |
198 var focusable = this.isFocusable(); |
199 if (focusable && this.focused) { |
199 if (focusable && this.focused) { |
203 } else if (!this.isEnabled()) { |
203 } else if (!this.isEnabled()) { |
204 return "Disabled"; |
204 return "Disabled"; |
205 } else { |
205 } else { |
206 return "Normal"; |
206 return "Normal"; |
207 } |
207 } |
208 } |
208 }; |
209 |
209 |
210 // Resets the state tracking for focus and hover. |
210 // Resets the state tracking for focus and hover. |
211 // Override this in subclasses as required to implement the state reset. |
211 // Override this in subclasses as required to implement the state reset. |
212 Control.prototype.resetFocusState = function() { |
212 Control.prototype.resetFocusState = function() { |
213 uiLogger.debug("Control.resetFocusState()"); |
213 uiLogger.debug("Control.resetFocusState()"); |
214 this.hovering = false; |
214 this.hovering = false; |
215 this.focused = false; |
215 this.focused = false; |
216 this.updateStyleFromState(); |
216 this.updateStyleFromState(); |
217 } |
217 }; |
218 |
218 |
219 // Helper function that sets a classname for an element. |
219 // Helper function that sets a classname for an element. |
220 // Only sets the class name if it actually is different from the current value. |
220 // Only sets the class name if it actually is different from the current value. |
221 Control.prototype.setClassName = function(element, className) { |
221 Control.prototype.setClassName = function(element, className) { |
222 if (element.className != className) { |
222 if (element.className != className) { |
223 element.className = className; |
223 element.className = className; |
224 } |
224 } |
225 } |
225 }; |
226 |
226 |
227 // Updates the style of the control to reflects the state of the control. |
227 // Updates the style of the control to reflects the state of the control. |
228 // Override this in subclasses as required to implement the state change. |
228 // Override this in subclasses as required to implement the state change. |
229 Control.prototype.updateStyleFromState = function() { |
229 Control.prototype.updateStyleFromState = function() { |
230 uiLogger.debug("Control.updateStyleFromState()"); |
230 uiLogger.debug("Control.updateStyleFromState()"); |
231 } |
231 }; |