Bug 298524 - Add init() method to richlistbox. r=robstrong,mconnor a=bsmedberg

This commit is contained in:
doronr%us.ibm.com 2005-06-23 20:04:57 +00:00
parent 512da6f988
commit b011da6386
2 changed files with 109 additions and 88 deletions

View File

@ -64,14 +64,14 @@
<property name="children"> <property name="children">
<getter> <getter>
<![CDATA[ <![CDATA[
var childNodes = []; var childNodes = [];
for (var i = 0; i < this.childNodes.length; ++i) { for (var i = 0; i < this.childNodes.length; ++i) {
if ("fireEvent" in this.childNodes[i]) if ("fireEvent" in this.childNodes[i])
childNodes.push(this.childNodes[i]); childNodes.push(this.childNodes[i]);
} }
return childNodes; return childNodes;
]]> ]]>
</getter> </getter>
</property> </property>
@ -87,7 +87,7 @@
]]> ]]>
</body> </body>
</method> </method>
<field name="_selectedItem">null</field> <field name="_selectedItem">null</field>
<property name="selectedItem"> <property name="selectedItem">
<getter> <getter>
@ -102,69 +102,102 @@
if (val) { if (val) {
val.selected = true; val.selected = true;
this.scrollBoxObject.ensureElementIsVisible(val); this.scrollBoxObject.scrollToElement(val);
this.fireActiveItemEvent(); this.fireActiveItemEvent();
} }
this.fireEvent("select"); this.fireEvent("select");
]]> ]]>
</setter> </setter>
</property> </property>
<method name="clearSelection"> <method name="clearSelection">
<body> <body>
<![CDATA[ <![CDATA[
this.selectedItem = null; this.selectedItem = null;
]]> ]]>
</body> </body>
</method> </method>
<method name="goUp"> <method name="goUp">
<body> <body>
<![CDATA[ <![CDATA[
// if nothing selected, we go from the bottom // if nothing selected, we go from the bottom
for (var i = this.selectedItem ? this.selectedItem.previousSibling : this.lastChild; i; i = i.previousSibling) { for (var i = this.selectedItem ? this.selectedItem.previousSibling : this.lastChild; i; i = i.previousSibling) {
if ("fireEvent" in i) { if ("fireEvent" in i) {
this.selectedItem = i; this.selectedItem = i;
return true; return true;
}
} }
} return false;
return false; ]]>
]]>
</body> </body>
</method> </method>
<method name="goDown"> <method name="goDown">
<body> <body>
<![CDATA[ <![CDATA[
// if nothing selected, we go from the top // if nothing selected, we go from the top
for (var i = this.selectedItem ? this.selectedItem.nextSibling : this.firstChild; i; i = i.nextSibling) { for (var i = this.selectedItem ? this.selectedItem.nextSibling : this.firstChild; i; i = i.nextSibling) {
if ("fireEvent" in i) { if ("fireEvent" in i) {
this.selectedItem = i; this.selectedItem = i;
return true; return true;
}
} }
} return false;
return false; ]]>
]]> </body>
</method>
<method name="init">
<body>
<![CDATA[
var lastSelected = this.getAttribute("last-selected");
if (lastSelected != "")
lastSelected = document.getElementById(lastSelected);
if (!lastSelected)
this.goDown();
else
this.selectedItem = lastSelected;
]]>
</body>
</method>
<method name="ensureElementIsVisible">
<parameter name="aElement"/>
<body>
<![CDATA[
this.scrollBoxObject.ensureElementIsVisible(aElement);
]]>
</body>
</method>
<method name="ensureSelectedElementIsVisible">
<body>
<![CDATA[
this.scrollBoxObject.ensureElementIsVisible(this.selectedItem);
]]>
</body> </body>
</method> </method>
<method name="fireEvent"> <method name="fireEvent">
<parameter name="aEventType"/> <parameter name="aEventType"/>
<body> <body>
<![CDATA[ <![CDATA[
var e = document.createEvent("Events"); var e = document.createEvent("Events");
var eventType = "richview-" + aEventType; var eventType = "richview-" + aEventType;
e.initEvent(eventType, false, true); e.initEvent(eventType, false, true);
this.dispatchEvent(e); this.dispatchEvent(e);
var handler = this.getAttribute("onrichview-" + aEventType); var handler = this.getAttribute("onrichview-" + aEventType);
if (handler != "") { if (handler != "") {
var fn = new Function("event", handler); var fn = new Function("event", handler);
fn(e); fn(e);
} }
document.commandDispatcher.updateCommands(eventType); document.commandDispatcher.updateCommands(eventType);
]]> ]]>
</body> </body>
</method> </method>
</implementation> </implementation>
@ -175,25 +208,25 @@
<handler event="keypress" keycode="VK_HOME" action="clearSelection(); goDown(); event.preventDefault();"/> <handler event="keypress" keycode="VK_HOME" action="clearSelection(); goDown(); event.preventDefault();"/>
<handler event="keypress" keycode="VK_END" action="clearSelection(); goUp(); event.preventDefault();"/> <handler event="keypress" keycode="VK_END" action="clearSelection(); goUp(); event.preventDefault();"/>
<handler event="click"> <handler event="click">
<![CDATA[ <![CDATA[
// clicking into nothing should unselect // clicking into nothing should unselect
if (event.originalTarget.getAttribute("anonid") == "main-box") if (event.originalTarget.getAttribute("anonid") == "main-box")
this.clearSelection(); this.clearSelection();
]]> ]]>
</handler> </handler>
<handler event="contextmenu"> <handler event="contextmenu">
<![CDATA[ <![CDATA[
// if the context menu was opened via the keyboard, display it in the // if the context menu was opened via the keyboard, display it in the
// right location. // right location.
if (event.button != 2) { if (event.button != 2) {
var popup = document.getElementById(this.getAttribute("context")); var popup = document.getElementById(this.getAttribute("context"));
if (popup) if (popup)
popup.showPopup(this.selectedItem, -1, -1, "context", "bottomleft", "topleft"); popup.showPopup(this.selectedItem, -1, -1, "context", "bottomleft", "topleft");
} }
]]> ]]>
</handler> </handler>
<handler event="focus"> <handler event="focus">
<![CDATA[ <![CDATA[
if (event.target == this) if (event.target == this)
this.fireActiveItemEvent(); this.fireActiveItemEvent();
]]> ]]>
@ -208,15 +241,6 @@
</content> </content>
<implementation implements="nsIAccessibleProvider, nsIDOMXULSelectControlItemElement"> <implementation implements="nsIAccessibleProvider, nsIDOMXULSelectControlItemElement">
<constructor>
<![CDATA[
// When first item is created, select it if we don't have a selection yet
var listbox = this.control;
if (!listbox.selectedItem) {
setTimeout(listbox.goDown, 0);
}
]]>
</constructor>
<!-- ///////////////// nsIAccessibleProvider ///////////////// --> <!-- ///////////////// nsIAccessibleProvider ///////////////// -->
<property name="accessible"> <property name="accessible">
<getter> <getter>
@ -225,9 +249,9 @@
return accService.createXULListitemAccessible(this); return accService.createXULListitemAccessible(this);
]]> ]]>
</getter> </getter>
</property> </property>
<!-- ///////////////// nsIDOMXULSelectControlItemElement ///////////////// --> <!-- ///////////////// nsIDOMXULSelectControlItemElement ///////////////// -->
<property name="value" onget="return this.getAttribute('value');" <property name="value" onget="return this.getAttribute('value');"
onset="this.setAttribute('value', val); return val;"/> onset="this.setAttribute('value', val); return val;"/>
@ -253,21 +277,23 @@
]]> ]]>
</getter> </getter>
</property> </property>
<property name="selected" <property name="selected"
onget="return this.getAttribute('selected');" onget="return this.getAttribute('selected');"
onset="return this.setAttribute('selected',val);"/> onset="return this.setAttribute('selected',val);"/>
<property name="control"> <property name="control">
<getter><![CDATA[ <getter>
var parent = this.parentNode; <![CDATA[
while (parent) { var parent = this.parentNode;
if (parent.localName == "richlistbox") while (parent) {
return parent; if (parent.localName == "richlistbox")
parent = parent.parentNode; return parent;
} parent = parent.parentNode;
return null; }
]]></getter> return null;
]]>
</getter>
</property> </property>
</implementation> </implementation>

View File

@ -187,14 +187,9 @@ function Startup()
optionsButton.hidden = true; optionsButton.hidden = true;
} }
// Restore the last-selected extension // Initialize the richlistbox. This will select the last selected extension
var lastSelected = gExtensionsView.getAttribute("last-selected"); // or default to the first listed one.
if (lastSelected != "") gExtensionsView.init();
lastSelected = document.getElementById(lastSelected);
if (!lastSelected)
gExtensionsView.goDown();
else
gExtensionsView.selectedItem = lastSelected;
var extensionsStrings = document.getElementById("extensionsStrings"); var extensionsStrings = document.getElementById("extensionsStrings");
document.title = extensionsStrings.getString(gWindowState + "Title"); document.title = extensionsStrings.getString(gWindowState + "Title");