author | Eugene Ostroukhov <eugeneo@symbian.org> |
Thu, 18 Mar 2010 11:10:35 -0700 | |
changeset 275 | 12c2ea2194c7 |
parent 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: |
273
b1f63c2c240c
Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
211
diff
changeset
|
10 |
* Nokia Corporation - initial contribution. |
b1f63c2c240c
Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
211
diff
changeset
|
11 |
* |
210
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
12 |
* Contributors: |
273
b1f63c2c240c
Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
211
diff
changeset
|
13 |
* |
b1f63c2c240c
Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
211
diff
changeset
|
14 |
* Description: |
b1f63c2c240c
Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
211
diff
changeset
|
15 |
* |
210
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
16 |
*/ |
73 | 17 |
|
18 |
/////////////////////////////////////////////////////////////////////////////// |
|
19 |
// The ActionControl class is an abstract base class for action controls like |
|
20 |
// buttons. Don't use ActionControl directly. |
|
21 |
||
22 |
// Constructor. |
|
23 |
function ActionControl(id, caption) { |
|
24 |
if (id != UI_NO_INIT_ID) { |
|
25 |
this.init(id, caption); |
|
26 |
} |
|
27 |
} |
|
28 |
||
29 |
// ActionControl inherits from Control. |
|
30 |
ActionControl.prototype = new Control(UI_NO_INIT_ID); |
|
31 |
||
32 |
// Reference to the button element. |
|
33 |
ActionControl.prototype.buttonElement = null; |
|
34 |
||
35 |
// Reference to the link element. |
|
36 |
ActionControl.prototype.linkElement = null; |
|
37 |
||
38 |
// Enabled status. |
|
39 |
ActionControl.prototype.enabled = false; |
|
40 |
||
41 |
// Initializer - called from constructor. |
|
42 |
ActionControl.prototype.init = function(id, caption) { |
|
43 |
uiLogger.debug("ActionControl.init(" + id + ", " + caption + ")"); |
|
44 |
||
45 |
// call superclass initializer |
|
46 |
Control.prototype.init.call(this, id, caption); |
|
47 |
||
48 |
// the control defaults to enabled |
|
49 |
this.enabled = true; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
50 |
}; |
73 | 51 |
|
52 |
// Common event listeners hookup function called from subclasses. |
|
53 |
ActionControl.prototype.bindActionControlListeners = function() { |
|
54 |
var self = this; |
|
55 |
this.linkElement.addEventListener("focus", function() { self.focusStateChanged(true); }, false); |
|
56 |
this.linkElement.addEventListener("blur", function() { self.focusStateChanged(false); }, false); |
|
57 |
this.buttonElement.addEventListener("mouseover", function() { self.hoverStateChanged(true); }, false); |
|
58 |
this.buttonElement.addEventListener("mouseout", function() { self.hoverStateChanged(false); }, false); |
|
59 |
this.buttonElement.addEventListener("mousedown", function(event) { |
|
60 |
self.controlClicked(event); |
|
61 |
event.stopPropagation(); |
|
62 |
event.preventDefault(); |
|
63 |
}, true); |
|
64 |
this.buttonElement.addEventListener("keydown", function(event) { |
|
65 |
// center and enter trigger the action |
|
66 |
if (event.keyCode == 0 || event.keyCode == 13) { |
|
67 |
self.controlClicked(); |
|
68 |
event.stopPropagation(); |
|
69 |
event.preventDefault(); |
|
70 |
} |
|
71 |
}, true); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
72 |
}; |
73 | 73 |
|
74 |
// Returns the enabled state. |
|
75 |
ActionControl.prototype.isEnabled = function() { |
|
76 |
return this.enabled; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
77 |
}; |
73 | 78 |
|
79 |
// Sets the enabled state. |
|
80 |
ActionControl.prototype.setEnabled = function(enabled) { |
|
81 |
uiLogger.debug("ActionControl.setEnabled(" + enabled + ")"); |
|
82 |
// switch the state |
|
83 |
this.enabled = enabled; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
84 |
}; |
73 | 85 |
|
86 |
// Sets the focused state for the control. |
|
87 |
// Note: This may not always succeed. |
|
88 |
ActionControl.prototype.setFocused = function(focused) { |
|
89 |
uiLogger.debug("ActionControl.setFocused(" + focused + ")"); |
|
90 |
if (this.enabled) { |
|
91 |
if (focused) { |
|
92 |
this.linkElement.focus(); |
|
93 |
} else { |
|
94 |
this.linkElement.blur(); |
|
95 |
} |
|
96 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
97 |
}; |
73 | 98 |
|
99 |
// Callback for clicks. |
|
100 |
ActionControl.prototype.controlClicked = function(event) { |
|
101 |
uiLogger.debug("ActionControl.controlClicked()"); |
|
102 |
||
103 |
// if we're enabled then a click results in an action performed event |
|
104 |
if (this.enabled) { |
|
105 |
// focus when clicked |
|
106 |
if (!this.focused) { |
|
107 |
this.linkElement.focus(); |
|
108 |
} |
|
109 |
||
110 |
// notify event listeners |
|
111 |
this.actionPerformed(event); |
|
112 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
113 |
}; |
73 | 114 |
|
115 |
// Callback for action performed events. |
|
116 |
ActionControl.prototype.actionPerformed = function(event) { |
|
117 |
uiLogger.debug("ActionControl.actionPerformed()"); |
|
118 |
// notify event listeners |
|
119 |
this.fireEvent(this.createEvent("ActionPerformed", event)); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
120 |
}; |