102239 - [XUL 1.0] implement new control element methods, r=blake, sr=hyatt

This commit is contained in:
hewitt%netscape.com 2001-10-21 03:58:21 +00:00
parent 462e8a8292
commit 47c604d7e4
8 changed files with 356 additions and 56 deletions

View File

@ -41,6 +41,8 @@ XPIDLSRCS = \
nsIDOMXULDescriptionElement.idl \
nsIDOMXULLabelElement.idl \
nsIDOMXULImageElement.idl \
nsIDOMXULSelectControlElement.idl \
nsIDOMXULSelectControlItemElement.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -37,6 +37,8 @@ XPIDLSRCS = \
.\nsIDOMXULDescriptionElement.idl \
.\nsIDOMXULLabelElement.idl \
.\nsIDOMXULImageElement.idl \
.\nsIDOMXULSelectControlElement.idl \
.\nsIDOMXULSelectControlItemElement.idl \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@ -48,6 +48,7 @@ interface nsIDOMXULControlElement : nsIDOMXULElement {
attribute boolean disabled;
attribute long tabIndex;
// XXX defined in XULElement, but should be defined here
// readonly attribute nsIControllers controllers;
// void focus();

View File

@ -0,0 +1,54 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Original Author: David W. Hyatt (hyatt@netscape.com)
* Contributor(s): Joe Hewitt (hewitt@netscape.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsIDOMXULControlElement.idl"
interface nsIDOMXULSelectControlItemElement;
[scriptable, uuid(59FEC127-2A0E-445b-84B5-A66DC90245DB)]
interface nsIDOMXULSelectControlElement : nsIDOMXULControlElement {
attribute nsIDOMXULSelectControlItemElement selectedItem;
attribute long selectedIndex;
attribute DOMString value;
nsIDOMXULSelectControlItemElement appendItem(in DOMString label, in DOMString value);
nsIDOMXULSelectControlItemElement insertItemAt(in long index, in DOMString label, in DOMString value);
nsIDOMXULSelectControlItemElement removeItemAt(in long index);
};

View File

@ -0,0 +1,62 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Original Author: David W. Hyatt (hyatt@netscape.com)
* Contributor(s): Joe Hewitt (hewitt@netscape.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsIDOMXULElement.idl"
interface nsIDOMXULSelectControlElement;
[scriptable, uuid(6AAAA30D-54AB-434a-8AE8-6D29A566D870)]
interface nsIDOMXULSelectControlItemElement : nsIDOMXULElement {
attribute boolean disabled;
attribute DOMString crop;
attribute DOMString image;
attribute DOMString label;
attribute DOMString accessKey;
attribute DOMString command;
attribute DOMString value;
readonly attribute boolean selected;
readonly attribute nsIDOMXULSelectControlElement control;
// XXX defined in XULElement, but should be defined here
// void doCommand();
};

View File

@ -37,7 +37,7 @@
</handler>
</handlers>
<implementation>
<implementation implements="nsIDOMXULSelectControlElement">
<constructor>
this.setInitialSelection()
</constructor>
@ -165,6 +165,59 @@
]]>
</setter>
</property>
<method name="appendItem">
<parameter name="label"/>
<parameter name="value"/>
<body>
<![CDATA[
var popup = this.getElementsByTagName("menupopup")[0];
if (popup) {
var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var item = document.createElementNS(XULNS, "menuitem");
item.setAttribute("label", label);
item.setAttribute("value", value);
popup.appendChild(item);
}
]]>
</body>
</method>
<method name="insertItemAt">
<parameter name="index"/>
<parameter name="label"/>
<parameter name="value"/>
<body>
<![CDATA[
var popup = this.getElementsByTagName("menupopup")[0];
if (popup) {
var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var item = document.createElementNS(XULNS, "menuitem");
item.setAttribute("label", label);
item.setAttribute("value", value);
var before = popup.childNodes[index];
if (before)
popup.insertBefore(item, before);
else
popup.appendChild(item);
}
]]>
</body>
</method>
<method name="removeItemAt">
<parameter name="index"/>
<body>
<![CDATA[
var popup = this.getElementsByTagName("menupopup")[0];
if (popup) {
var remove = popup.childNodes[index];
if (remove)
popup.removeChild(remove);
}
]]>
</body>
</method>
</implementation>
</binding>

View File

@ -9,7 +9,7 @@
<stylesheet src="chrome://global/skin/radio.css"/>
</resources>
<implementation>
<implementation implements="nsIDOMXULSelectControlElement">
<property name="value" onset="this.setAttribute('value',val); return val;"
onget="return this.getAttribute('value');"/>
<property name="disabled">
@ -124,6 +124,50 @@
]]>
</body>
</method>
<method name="appendItem">
<parameter name="label"/>
<parameter name="value"/>
<body>
<![CDATA[
var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var radio = document.createElementNS(XULNS, "radio");
radio.setAttribute("label", label);
radio.setAttribute("value", value);
this.appendChild(radio);
]]>
</body>
</method>
<method name="insertItemAt">
<parameter name="index"/>
<parameter name="label"/>
<parameter name="value"/>
<body>
<![CDATA[
var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var radio = document.createElementNS(XULNS, "radio");
radio.setAttribute("label", label);
radio.setAttribute("value", value);
var before = this.childNodes[index];
if (before)
this.insertBefore(radio, before);
else
this.appendChild(radio);
]]>
</body>
</method>
<method name="removeItemAt">
<parameter name="index"/>
<body>
<![CDATA[
var remove = this.childNodes[index];
if (remove)
this.removeChild(remove);
]]>
</body>
</method>
</implementation>
<handlers>

View File

@ -15,53 +15,78 @@
<content orient="vertical"/>
<implementation>
<property name="selectedTab">
<setter>
<![CDATA[
if (!val)
throw Components.results.NS_ERROR_NULL_POINTER;
var tabs = this.getElementsByTagNameNS(
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
"tabs");
tabs = tabs.length ? tabs[0] : null;
if (tabs)
tabs.selectedTab = val;
return val;
]]>
</setter>
<property name="_tabs">
<getter>
<![CDATA[
var tabs = this.getElementsByTagNameNS(
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
"tabs");
tabs = tabs.length ? tabs[0] : null;
return tabs ? tabs.selectedTab : null;
return tabs.length ? tabs[0] : null;
]]>
</getter>
</property>
<property name="_tabpanels">
<getter>
<![CDATA[
var tabpanels = this.getElementsByTagNameNS(
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
"tabpanels");
return tabpanels.length ? tabpanels[0] : null;
]]>
</getter>
</property>
<property name="selectedIndex"
onget="return this._tabs ? this._tabs.selectedIndex : null;">
<setter>
<![CDATA[
if (this._tabs)
this._tabs.selectedIndex = val;
return val;
]]>
</setter>
</property>
<property name="selectedTab"
onget="return this._tabs ? this._tabs.selectedItem : null;">
<setter>
<![CDATA[
if (!val)
throw Components.results.NS_ERROR_NULL_POINTER;
if (this._tabs)
this._tabs.selectedItem = val;
return val;
]]>
</setter>
</property>
<property name="selectedPanel"
onget="return this._tabpanels ? this._tabpanels.selectedPanel : null;">
<setter>
<![CDATA[
if (!val)
throw Components.results.NS_ERROR_NULL_POINTER;
if (this._tabpanels)
this._tabpanels.selectedPanel = val;
return val;
]]>
</setter>
</property>
</implementation>
<handlers>
<handler event="keypress" keycode="vk_tab" modifiers="control">
<![CDATA[
var tabs = this.getElementsByTagNameNS(
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
"tabs");
tabs = tabs.length ? tabs[0] : null;
if (tabs)
tabs.advanceSelectedTab(1);
if (this._tabs)
this._tabs.advanceSelectedTab(1);
]]>
</handler>
<handler event="keypress" keycode="vk_tab" modifiers="control,shift">
<![CDATA[
var tabs = this.getElementsByTagNameNS(
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
"tabs");
tabs = tabs.length ? tabs[0] : null;
if (tabs)
tabs.advanceSelectedTab(-1);
if (this._tabs)
this._tabs.advanceSelectedTab(-1);
]]>
</handler>
</handlers>
@ -69,7 +94,7 @@
<binding id="tabs" display="xul:box"
extends="chrome://global/content/bindings/tabbox.xml#tab-base">
<implementation>
<implementation implements="nsIDOMXULSelectControlElement">
<constructor>
<![CDATA[
// first and last tabs need to be able to have unique styles
@ -85,14 +110,37 @@
else if (tabs.length == 1)
tabs[0].setAttribute("first-tab", "true");
}
this.selectedTab = tabs[0];
this.selectedItem = tabs[0];
var o = this.getAttribute("orient");
if (!o)
this.setAttribute("orient", "horizontal");
]]>
</constructor>
<property name="selectedTab">
<property name="selectedIndex">
<getter>
<![CDATA[
for (var i = 0; i < this.childNodes.length; i++) {
if (this.childNodes[i].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++) {
@ -107,6 +155,7 @@
<![CDATA[
if (!val)
throw Components.results.NS_ERROR_NULL_POINTER;
if (!val.selected)
val.selected = true;
var selectedIndex = 0;
@ -118,7 +167,7 @@
selectedIndex = i;
}
}
// Fire an onselect event for the tabs element.
var event = document.createEvent('Events');
event.initEvent('select', false, true);
@ -135,8 +184,9 @@
"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.index = selectedIndex; // This will cause an onselect event to fire for the tabpanel element.
tabpanels.selectedIndex = selectedIndex;
return val;
]]>
</setter>
@ -146,34 +196,66 @@
<parameter name="aDir"/>
<body>
<![CDATA[
var next = this.selectedTab[aDir == -1 ? "previousSibling" : "nextSibling"];
var next = this.selectedItem[aDir == -1 ? "previousSibling" : "nextSibling"];
if (next && !next.getAttribute("hidden")) {
this.selectedTab = next;
this.selectedItem = next;
next.focus();
}
]]>
</body>
</method>
<method name="appendItem">
<parameter name="label"/>
<parameter name="value"/>
<body>
<![CDATA[
var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var tab = document.createElementNS(XULNS, "tab");
tab.setAttribute("label", label);
tab.setAttribute("value", value);
this.appendChild(tab);
]]>
</body>
</method>
<method name="insertItemAt">
<parameter name="index"/>
<parameter name="label"/>
<parameter name="value"/>
<body>
<![CDATA[
var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var tab = document.createElementNS(XULNS, "tab");
tab.setAttribute("label", label);
tab.setAttribute("value", value);
var before = this.childNodes[index];
if (before)
this.insertBefore(tab, before);
else
this.appendChild(tab);
]]>
</body>
</method>
<method name="removeItemAt">
<parameter name="index"/>
<body>
<![CDATA[
var remove = this.childNodes[index];
if (remove)
this.removeChild(remove);
]]>
</body>
</method>
</implementation>
</binding>
<binding id="tabpanels" display="xul:deck"
extends="chrome://global/content/bindings/tabbox.xml#tab-base">
<implementation>
<!-- should be defined on deck! -->
<property name="index"
onget="return this.getAttribute('index');">
<setter>
if (this.index == val)
return val;
this.setAttribute("index", val);
var event = document.createEvent('Events');
event.initEvent('select', false, true);
this.dispatchEvent(event);
return val;
</setter>
</property>
</implementation>
<binding id="tabpanels"
extends="chrome://global/content/bindings/general.xml#deck">
<resources>
<stylesheet src="chrome://global/skin/tabbox.css"/>
</resources>
</binding>
<binding id="tab" display="xul:button"
@ -225,7 +307,7 @@
break;
tabs = tabs.parentNode;
} while(tabs.localName != "tabbox");
tabs.selectedTab = this;
tabs.selectedItem = this;
if (!this.selected) this.selected = true;
]]>
</handler>