author | Eugene Ostroukhov <eugeneo@symbian.org> |
Wed, 10 Mar 2010 09:22:00 -0800 | |
changeset 238 | 977c9f9adc30 |
parent 211 | 7b148352159e |
child 273 | b1f63c2c240c |
permissions | -rw-r--r-- |
210
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
1 |
/** |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
2 |
* Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies). |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
3 |
* All rights reserved. |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
8 |
* |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
9 |
* Initial Contributors: |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
10 |
* Symbian Foundation - initial contribution. |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
11 |
* Contributors: |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
12 |
*/ |
73 | 13 |
/* |
211 | 14 |
© Copyright 2008 Nokia Corporation. All rights reserved. |
73 | 15 |
|
16 |
IMPORTANT: The Nokia software ("WRTKit and Example Widget files") is supplied to you by Nokia |
|
211 | 17 |
Corporation ("Nokia") in consideration of your agreement to the following terms. Your use, installation |
73 | 18 |
and/or redistribution of the WRTKit and Example Widget files constitutes acceptance of these terms. If |
19 |
you do not agree with these terms, please do not use, install, or redistribute the WRTKit and Example |
|
20 |
Widget files. |
|
21 |
||
22 |
In consideration of your agreement to abide by the following terms, and subject to these terms, Nokia |
|
211 | 23 |
grants you a personal, non-exclusive license, under Nokia's copyrights in the WRTKit and Example |
73 | 24 |
Widget files, to use, reproduce, and redistribute the WRTKit and Example files, in text form (for HTML, |
25 |
CSS, or JavaScript files) or binary form (for associated images), for the sole purpose of creating S60 |
|
26 |
Widgets. |
|
27 |
||
28 |
If you redistribute the WRTKit and Example files, you must retain this entire notice in all such |
|
29 |
redistributions of the WRTKit and Example files. |
|
30 |
||
31 |
You may not use the name, trademarks, service marks or logos of Nokia to endorse or promote products |
|
32 |
that include the WRTKit and Example files without the prior written explicit agreement with Nokia. |
|
33 |
Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by |
|
34 |
Nokia herein, including but not limited to any patent rights that may be infringed by your products that |
|
35 |
incorporate the WRTKit and Example files or by other works in which the WRTKit and Example files |
|
36 |
may be incorporated. |
|
37 |
||
38 |
The WRTKit and Example files are provided on an "AS IS" basis. NOKIA MAKES NO |
|
39 |
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED |
|
40 |
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A |
|
41 |
PARTICULAR PURPOSE, REGARDING THE EXAMPLES OR ITS USE AND OPERATION |
|
42 |
ALONE OR IN COMBINATION WITH YOUR PRODUCTS. |
|
43 |
||
44 |
IN NO EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR |
|
45 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
46 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
47 |
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR |
|
48 |
DISTRIBUTION OF THE EXAMPLES, HOWEVER CAUSED AND WHETHER UNDER THEORY |
|
49 |
OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, |
|
50 |
EVEN IF NOKIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
51 |
||
52 |
*/ |
|
53 |
||
54 |
/////////////////////////////////////////////////////////////////////////////// |
|
55 |
// The Control class is an abstract base class for all user interface controls. |
|
56 |
||
57 |
// Constructor. |
|
58 |
function Control(id, caption) { |
|
59 |
if (id != UI_NO_INIT_ID) { |
|
60 |
this.init(id, caption); |
|
61 |
} |
|
62 |
} |
|
63 |
||
64 |
// Control inherits from UIElement. |
|
65 |
Control.prototype = new UIElement(UI_NO_INIT_ID); |
|
66 |
||
67 |
// The view that control belongs to. |
|
68 |
Control.prototype.view = null; |
|
69 |
||
70 |
// Is the control focused? |
|
71 |
Control.prototype.focused = false; |
|
72 |
||
73 |
// Is the pointer over this control? |
|
74 |
Control.prototype.hovering = false; |
|
75 |
||
76 |
// The element hierarchy in a control is as follows: |
|
77 |
// |
|
78 |
// rootElement |
|
79 |
// assemblyElement |
|
80 |
// captionElement |
|
81 |
// controlElement |
|
82 |
// |
|
83 |
// The assembly element groups the portion of a control that typically handle |
|
84 |
// the visual effects for focus and hover states. Having a separate root and |
|
85 |
// assembly elements allows other elements to be added to a control without |
|
86 |
// them being affected by the CSS rules of the assembly element. |
|
87 |
||
88 |
// The assembly element of this control. |
|
89 |
Control.prototype.assemblyElement = null; |
|
90 |
||
91 |
// The caption of this control; null if none. |
|
92 |
Control.prototype.caption = null; |
|
93 |
||
94 |
// The caption element of this control. |
|
95 |
Control.prototype.captionElement = null; |
|
96 |
||
97 |
// The control element of this control. |
|
98 |
Control.prototype.controlElement = null; |
|
99 |
||
100 |
// Initializer - called from constructor. |
|
101 |
Control.prototype.init = function(id, caption) { |
|
102 |
uiLogger.debug("Control.init(" + id + ", " + caption + ")"); |
|
103 |
||
104 |
// call superclass initializer |
|
105 |
UIElement.prototype.init.call(this, id); |
|
106 |
||
107 |
// create assembly, caption and control elements |
|
108 |
this.assemblyElement = document.createElement("div"); |
|
109 |
this.captionElement = document.createElement("div"); |
|
110 |
this.assemblyElement.appendChild(this.captionElement); |
|
111 |
this.controlElement = document.createElement("div"); |
|
112 |
this.assemblyElement.appendChild(this.controlElement); |
|
113 |
this.rootElement.appendChild(this.assemblyElement); |
|
114 |
||
115 |
// set the caption |
|
116 |
// style is not updated because the subclass will update the style later |
|
117 |
// when it has completely initialized the component |
|
118 |
this.setCaption(caption, true); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
119 |
}; |
73 | 120 |
|
121 |
// Returns the caption; null if none. |
|
122 |
Control.prototype.getCaption = function() { |
|
123 |
return this.caption; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
124 |
}; |
73 | 125 |
|
126 |
// Sets the caption; null if none. |
|
127 |
Control.prototype.setCaption = function(caption, noStyleUpdate) { |
|
128 |
uiLogger.debug("Control.setCaption(" + caption + ")"); |
|
129 |
||
130 |
// set the display style |
|
131 |
this.captionElement.style.display = (caption == null) ? "none" : "block"; |
|
132 |
||
133 |
// set the caption |
|
134 |
this.caption = caption; |
|
135 |
this.captionElement.innerHTML = (caption == null) ? "" : caption; |
|
136 |
||
137 |
// update style |
|
138 |
if (!noStyleUpdate) { |
|
139 |
this.updateStyleFromState(); |
|
140 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
141 |
}; |
73 | 142 |
|
143 |
// Returns the enabled state. |
|
144 |
// Override this in subclasses as required to implement the state change. |
|
145 |
Control.prototype.isEnabled = function() { |
|
146 |
return false; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
147 |
}; |
73 | 148 |
|
149 |
// Sets the enabled state. |
|
150 |
// Override this in subclasses as required to implement the state change. |
|
151 |
Control.prototype.setEnabled = function(enabled) { |
|
152 |
uiLogger.debug("Control.setEnabled(" + enabled + ")"); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
153 |
}; |
73 | 154 |
|
155 |
// Returns the focusable state for the control. |
|
156 |
// Defaults focusable if enabled - override this in subclasses as required. |
|
157 |
Control.prototype.isFocusable = function() { |
|
158 |
return this.isEnabled(); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
159 |
}; |
73 | 160 |
|
161 |
// Returns the focused state for the control. |
|
162 |
Control.prototype.isFocused = function() { |
|
163 |
return this.focused; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
164 |
}; |
73 | 165 |
|
166 |
// Sets the focused state for the control. |
|
167 |
// Note: This may not always succeed. |
|
168 |
// Override this in subclasses as required to implement the state change. |
|
169 |
Control.prototype.setFocused = function(focused) { |
|
170 |
uiLogger.debug("Control.setFocused(" + focused + ")"); |
|
171 |
// note that this.focused gets set as a result of focusStateChanged() being called |
|
172 |
// rather than setting it explicitly here |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
173 |
}; |
73 | 174 |
|
175 |
// Called when the focus state has changed for this control. |
|
176 |
Control.prototype.focusStateChanged = function(focused) { |
|
177 |
uiLogger.debug("Control.focusStateChanged(" + focused + ")"); |
|
178 |
if (this.focused != focused) { |
|
179 |
this.focused = focused; |
|
180 |
||
181 |
// let the view know about the focus change |
|
182 |
if (this.view != null) { |
|
183 |
this.view.focusedControlChanged(focused ? this : null); |
|
184 |
} |
|
185 |
||
186 |
// update the style from the current state |
|
187 |
this.updateStyleFromState(); |
|
188 |
||
189 |
// notify event listeners |
|
190 |
this.fireEvent(this.createEvent("FocusStateChanged", focused)); |
|
191 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
192 |
}; |
73 | 193 |
|
194 |
// Called when the hover state has changed for this control. |
|
195 |
Control.prototype.hoverStateChanged = function(hovering) { |
|
196 |
uiLogger.debug("Control.hoverStateChanged(" + hovering + ")"); |
|
197 |
if (this.hovering != hovering) { |
|
198 |
this.hovering = hovering; |
|
199 |
||
200 |
// update the style from the current state |
|
201 |
this.updateStyleFromState(); |
|
202 |
||
203 |
// notify event listeners |
|
204 |
this.fireEvent(this.createEvent("HoverStateChanged", hovering)); |
|
205 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
206 |
}; |
73 | 207 |
|
208 |
// Helper method that returns the state name for the current state. |
|
209 |
Control.prototype.getStyleStateName = function() { |
|
210 |
var focusable = this.isFocusable(); |
|
211 |
if (focusable && this.focused) { |
|
212 |
return "Focus"; |
|
213 |
} else if (focusable && this.hovering) { |
|
214 |
return "Hover"; |
|
215 |
} else if (!this.isEnabled()) { |
|
216 |
return "Disabled"; |
|
217 |
} else { |
|
218 |
return "Normal"; |
|
219 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
220 |
}; |
73 | 221 |
|
222 |
// Resets the state tracking for focus and hover. |
|
223 |
// Override this in subclasses as required to implement the state reset. |
|
224 |
Control.prototype.resetFocusState = function() { |
|
225 |
uiLogger.debug("Control.resetFocusState()"); |
|
226 |
this.hovering = false; |
|
227 |
this.focused = false; |
|
228 |
this.updateStyleFromState(); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
229 |
}; |
73 | 230 |
|
231 |
// Helper function that sets a classname for an element. |
|
232 |
// Only sets the class name if it actually is different from the current value. |
|
233 |
Control.prototype.setClassName = function(element, className) { |
|
234 |
if (element.className != className) { |
|
235 |
element.className = className; |
|
236 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
237 |
}; |
73 | 238 |
|
239 |
// Updates the style of the control to reflects the state of the control. |
|
240 |
// Override this in subclasses as required to implement the state change. |
|
241 |
Control.prototype.updateStyleFromState = function() { |
|
242 |
uiLogger.debug("Control.updateStyleFromState()"); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
243 |
}; |