Bug 106656 tabs' use of child nodes is inconsistent

patch by neil@parkwaycc.co.uk r=timeless sr=jag
This commit is contained in:
timeless%mac.com 2002-10-08 12:07:27 +00:00
Родитель 9365064e89
Коммит 027a88ae58
1 изменённых файлов: 58 добавлений и 68 удалений

Просмотреть файл

@ -190,18 +190,11 @@
<![CDATA[
// first and last tabs need to be able to have unique styles
// and also need to select first tab on startup.
var tabs = this.getElementsByTagNameNS(
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
"tab");
if (tabs.length) {
if (tabs.length > 1) {
tabs[0].setAttribute("first-tab", "true");
tabs[tabs.length - 1].setAttribute("last-tab", "true");
}
else if (tabs.length == 1)
tabs[0].setAttribute("first-tab", "true");
}
this.selectedItem = tabs[0];
if (this.firstChild)
this.firstChild.setAttribute("first-tab", "true");
if (this.lastChild)
this.lastChild.setAttribute("last-tab", "true");
this.selectedIndex = 0;
var o = this.getAttribute("orient");
if (!o)
this.setAttribute("orient", "horizontal");
@ -220,73 +213,70 @@
<property name="selectedIndex">
<getter>
<![CDATA[
for (var i = 0; i < this.childNodes.length; i++) {
if (this.childNodes[i].selected)
const tabs = this.childNodes;
for (var i = 0; i < tabs.length; i++) {
if (tabs.selected)
return i;
}
// throw an exception when no tab is selected (we shouldn't get here)
throw Components.results.NS_ERROR_FAILURE;
]]></getter>
<setter>
<![CDATA[
var tabs = this.getElementsByTagNameNS(
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
"tab");
var tab = tabs.length >= val ? null : tabs[val];
if (tab)
this.selectedItem = tab;
return tab;
]]></setter>
</property>
<property name="selectedItem">
<getter>
<![CDATA[
for (var i = 0; i < this.childNodes.length; i++) {
if (this.childNodes[i].selected)
return this.childNodes[i];
}
// throw an exception when no tab is selected (we shouldn't get here)
throw Components.results.NS_ERROR_FAILURE;
]]>
</getter>
<setter>
<![CDATA[
const tabs = this.childNodes;
if (0 <= val && val < tabs.length && !tabs[val].selected) {
for (var i = 0; i < tabs.length; i++)
if (i != val && tabs[i].selected)
tabs[i].selected = false;
tabs[val].selected = true;
for (var parent = this.parentNode; parent; parent = parent.parentNode) {
if (parent.localName == 'tabbox') {
var tabpanels = parent._tabpanels;
// This will cause an onselect event to fire for the tabpanel element.
if (tabpanels)
tabpanels.selectedIndex = val;
break;
}
}
// Fire an onselect event for the tabs element.
var event = document.createEvent('Events');
event.initEvent('select', false, true);
this.dispatchEvent(event);
}
return val;
]]>
</setter>
</property>
<property name="selectedItem">
<getter>
<![CDATA[
const tabs = this.childNodes;
for (var i = 0; i < tabs.length; i++) {
if (tabs[i].selected)
return tabs[i];
}
// throw an exception when no tab is selected (we shouldn't get here)
throw Components.results.NS_ERROR_FAILURE;
]]>
</getter>
<setter>
<![CDATA[
if (!val)
throw Components.results.NS_ERROR_NULL_POINTER;
if (!val.selected)
val.selected = true;
var selectedIndex = 0;
for (var i = 0; i < this.childNodes.length; i++) {
if (this.childNodes[i].selected) {
if (this.childNodes[i] != val)
this.childNodes[i].selected = false;
else
selectedIndex = i;
}
if (!val.selected) {
const tabs = this.childNodes;
for (var i = 0; i < tabs.length; i++)
if (tabs[i] == val)
this.selectedIndex = i;
}
// Fire an onselect event for the tabs element.
var event = document.createEvent('Events');
event.initEvent('select', false, true);
this.dispatchEvent(event);
var parent = this.parentNode;
while (parent && parent.localName != 'tabbox')
parent = parent.parentNode;
if (!parent)
return val;
var tabpanels = parent.getElementsByTagNameNS(
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
"tabpanels");
tabpanels = tabpanels.length ? tabpanels[0] : null;
// This will cause an onselect event to fire for the tabpanel element.
if (tabpanels)
tabpanels.selectedIndex = selectedIndex;
return val;
]]>
</setter>