author | Eugene Ostroukhov <eugeneo@symbian.org> |
Mon, 15 Mar 2010 16:38:54 -0700 | |
changeset 263 | 0c4249e0396d |
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 UI manager manages a set of views and other user interface elements. |
|
56 |
||
57 |
// Constructor. |
|
58 |
function UIManager(viewParentElement, scrollbarParentElement, enableScrollBar, delayInit) { |
|
59 |
uiLogger.debug("UIManager(" + viewParentElement + ", " + scrollbarParentElement + ")"); |
|
60 |
if (delayInit == null) { |
|
61 |
this.init(viewParentElement, enableScrollBar, scrollbarParentElement); |
|
62 |
} |
|
63 |
} |
|
64 |
||
65 |
// Parent element for views. |
|
66 |
UIManager.prototype.viewParentElement = null; |
|
67 |
||
68 |
// Parent element for scrollbar. |
|
69 |
UIManager.prototype.scrollbarParentElement = null; |
|
70 |
||
71 |
// The currently displayed view. |
|
72 |
UIManager.prototype.currentView = null; |
|
73 |
||
74 |
// Reference to the scrollbar. |
|
75 |
UIManager.prototype.scrollbar = null; |
|
76 |
||
77 |
// Current scroll Y position. |
|
78 |
UIManager.prototype.scrollY = -1; |
|
79 |
||
80 |
// Current viewport height. |
|
81 |
UIManager.prototype.viewportHeight = -1; |
|
82 |
||
83 |
// Current document height. |
|
84 |
UIManager.prototype.documentHeight = -1; |
|
85 |
||
86 |
// Timer identifier or null if no active timer. |
|
87 |
UIManager.prototype.timerId = null; |
|
88 |
||
89 |
// Interval for timer ticks for the UI manager timer (in milliseconds) |
|
90 |
UIManager.prototype.TIMER_INTERVAL = 250; |
|
91 |
||
92 |
// Reference to the notification popup used to displays notifications. |
|
93 |
UIManager.prototype.notificationPopup = null; |
|
94 |
||
95 |
// is scrollbar enabled |
|
96 |
UIManager.prototype.enableScrollBar = null; |
|
97 |
||
98 |
// init function |
|
99 |
UIManager.prototype.init = function(viewParentElement, enableScrollBar, scrollbarParentElement) { |
|
100 |
this.enableScrollBar = enableScrollBar; |
|
101 |
||
102 |
// parent element for views |
|
103 |
if (viewParentElement == null) { |
|
104 |
// create a parent for views |
|
105 |
this.viewParentElement = document.createElement("div"); |
|
106 |
this.viewParentElement.className = "ViewContainer"; |
|
107 |
document.body.appendChild(this.viewParentElement); |
|
108 |
} |
|
109 |
else { |
|
110 |
this.viewParentElement = viewParentElement; |
|
111 |
} |
|
112 |
||
113 |
// parent element for scrollbar |
|
114 |
if (enableScrollBar) { |
|
115 |
if (scrollbarParentElement == null) { |
|
116 |
// create a parent for the scrollbar |
|
117 |
this.scrollbarParentElement = document.createElement("div"); |
|
118 |
this.scrollbarParentElement.className = "DocumentScrollbarContainer"; |
|
119 |
document.body.appendChild(this.scrollbarParentElement); |
|
120 |
} |
|
121 |
else { |
|
122 |
this.scrollbarParentElement = scrollbarParentElement; |
|
123 |
} |
|
124 |
} |
|
125 |
||
126 |
// currently selected view |
|
127 |
this.currentView = null; |
|
128 |
||
129 |
// create the notification popup |
|
130 |
// the notification popup adds itself as a child element to the document body |
|
131 |
this.notificationPopup = new NotificationPopup(); |
|
132 |
||
133 |
// create scrollbar |
|
134 |
if (enableScrollBar) { |
|
135 |
this.scrollbar = new Scrollbar(this.scrollbarParentElement); |
|
136 |
} |
|
137 |
||
138 |
// setup scrollbar tracking |
|
139 |
var self = this; |
|
140 |
this.startTimer(); |
|
141 |
if (enableScrollBar) { |
|
142 |
window.addEventListener("resize", function(){ |
|
143 |
self.updateScrollbar(); |
|
144 |
}, false); |
|
145 |
window.addEventListener("scroll", function(){ |
|
146 |
self.updateScrollbar(); |
|
147 |
}, false); |
|
148 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
149 |
}; |
73 | 150 |
|
151 |
// Returns the current view. |
|
152 |
UIManager.prototype.getView = function() { |
|
153 |
return this.currentView; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
154 |
}; |
73 | 155 |
|
156 |
// Switches to the specified view. |
|
157 |
UIManager.prototype.setView = function(view) { |
|
158 |
uiLogger.debug("View set to " + view.id); |
|
159 |
||
160 |
// remove the current view from the parent element |
|
161 |
if (this.currentView != null) { |
|
162 |
this.viewParentElement.removeChild(this.currentView.rootElement); |
|
163 |
} |
|
164 |
||
165 |
// reset scroll |
|
166 |
window.scrollTo(0, 0); |
|
167 |
||
168 |
// add the new view to the parent element |
|
169 |
if (view != null) { |
|
170 |
this.currentView = view; |
|
171 |
this.currentView.resetControlFocusStates(); |
|
172 |
this.viewParentElement.appendChild(this.currentView.rootElement); |
|
173 |
} |
|
174 |
||
175 |
// update scrollbar |
|
176 |
if (this.enableScrollBar) { |
|
177 |
this.updateScrollbar(); |
|
178 |
} |
|
179 |
||
180 |
// focus the first focusable control |
|
181 |
// a timer is used to prevent unwanted focus shift |
|
182 |
setTimeout(function() { view.focusFirstControl(); }, 1); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
183 |
}; |
73 | 184 |
|
185 |
// Updates the scrollbar. |
|
186 |
UIManager.prototype.updateScrollbar = function() { |
|
187 |
if (this.enableScrollBar) { |
|
188 |
// get current viewport and document position and dimensions |
|
189 |
var scrollY = window.scrollY; |
|
190 |
var viewportHeight = window.innerHeight; |
|
191 |
var documentHeight = Math.max(document.documentElement.scrollHeight, document.height); |
|
192 |
||
193 |
// check if the scroll position or view has changed |
|
194 |
if (this.scrollY != scrollY || |
|
195 |
this.viewportHeight != viewportHeight || |
|
196 |
this.documentHeight != documentHeight) { |
|
197 |
// scroll position or view has changed |
|
198 |
this.scrollY = scrollY; |
|
199 |
this.viewportHeight = viewportHeight; |
|
200 |
this.documentHeight = documentHeight; |
|
201 |
||
202 |
// update the scrollbar |
|
203 |
this.scrollbar.update(scrollY, viewportHeight, documentHeight); |
|
204 |
uiLogger.debug("Scrollbar updated"); |
|
205 |
} |
|
206 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
207 |
}; |
73 | 208 |
|
209 |
// Starts the view manager timer. |
|
210 |
UIManager.prototype.startTimer = function() { |
|
211 |
if (this.timerId == null) { |
|
212 |
uiLogger.debug("UIManager timer started"); |
|
213 |
var self = this; |
|
214 |
// setup the timer |
|
215 |
this.timerId = setInterval(function() { self.onTimer(); }, this.TIMER_INTERVAL); |
|
216 |
} else { |
|
217 |
uiLogger.warn("UIManager timer already running"); |
|
218 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
219 |
}; |
73 | 220 |
|
221 |
// Stops the view manager timer. |
|
222 |
UIManager.prototype.stopTimer = function() { |
|
223 |
if (this.timerId != null) { |
|
224 |
// stop the timer |
|
225 |
clearTimeout(this.timerId); |
|
226 |
this.timerId = null; |
|
227 |
} else { |
|
228 |
uiLogger.warn("UIManager timer already stopped"); |
|
229 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
230 |
}; |
73 | 231 |
|
232 |
// Timer callback function. |
|
233 |
UIManager.prototype.onTimer = function() { |
|
234 |
if (this.enableScrollBar) { |
|
235 |
// make sure the scrollbar is up to date |
|
236 |
this.updateScrollbar(); |
|
237 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
238 |
}; |
73 | 239 |
|
240 |
// Displays a notification. |
|
241 |
UIManager.prototype.showNotification = function(displayTime, type, text, progress) { |
|
242 |
uiLogger.debug("UIManager.showNotification(" + displayTime + ", " + type + ", " + text + ", " + progress + ")"); |
|
243 |
// use the notification popup to show the notification |
|
244 |
this.notificationPopup.showNotification(displayTime, type, text, progress); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
245 |
}; |
73 | 246 |
|
247 |
// Hides the currently displayed notification. |
|
248 |
UIManager.prototype.hideNotification = function() { |
|
249 |
uiLogger.debug("UIManager.hideNotification()"); |
|
250 |
// hide the notification popup |
|
251 |
this.notificationPopup.hideNotification(); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
252 |
}; |