Bug 94458: change dynamically registered listeners to "create" and "destroy" events to listen to "popupshowing" and "popuphiding". r=bryner, sr=hyatt

This commit is contained in:
jaggernaut%netscape.com 2001-08-10 01:32:12 +00:00
Родитель 3393692119
Коммит 3f0c50d813
12 изменённых файлов: 18 добавлений и 432 удалений

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

@ -346,7 +346,7 @@ nsMenuListenerAccessible::~nsMenuListenerAccessible()
if (mRegistered) {
nsCOMPtr<nsIDOMEventReceiver> eventReceiver(do_QueryInterface(mDOMNode));
if (eventReceiver)
eventReceiver->RemoveEventListener(NS_LITERAL_STRING("create"), this, PR_TRUE);
eventReceiver->RemoveEventListener(NS_LITERAL_STRING("popupshowing"), this, PR_TRUE);
}
}
@ -388,7 +388,7 @@ nsMenuListenerAccessible::SetupMenuListener()
return;
}
nsresult rv = eventReceiver->AddEventListener(NS_LITERAL_STRING("create"), this, PR_TRUE);
nsresult rv = eventReceiver->AddEventListener(NS_LITERAL_STRING("popupshowing"), this, PR_TRUE);
if (NS_FAILED(rv)) {
return;

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

@ -55,7 +55,7 @@ nsHTMLComboboxAccessible::~nsHTMLComboboxAccessible()
if (mRegistered) {
nsCOMPtr<nsIDOMEventReceiver> eventReceiver(do_QueryInterface(mDOMNode));
if (eventReceiver)
eventReceiver->RemoveEventListener(NS_LITERAL_STRING("create"), this, PR_TRUE);
eventReceiver->RemoveEventListener(NS_LITERAL_STRING("popupshowing"), this, PR_TRUE);
}
}
@ -194,7 +194,7 @@ NS_IMETHODIMP nsHTMLComboboxAccessible::Close(nsIDOMEvent* aEvent)
/**
* If we aren't already registered, register ourselves as a
* listener to "create" events on our DOM node. Set our
* listener to "popupshowing" events on our DOM node. Set our
* state to registered, but don't notify MSAA as they
* don't need to know about this state.
*/
@ -204,7 +204,7 @@ nsHTMLComboboxAccessible::SetupMenuListener()
// if not already registered as a popup listener, register ourself
if (!mRegistered) {
nsCOMPtr<nsIDOMEventReceiver> eventReceiver(do_QueryInterface(mDOMNode));
if (eventReceiver && NS_SUCCEEDED(eventReceiver->AddEventListener(NS_LITERAL_STRING("create"), this, PR_TRUE)))
if (eventReceiver && NS_SUCCEEDED(eventReceiver->AddEventListener(NS_LITERAL_STRING("popupshowing"), this, PR_TRUE)))
mRegistered = PR_TRUE;
}
}

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

@ -346,7 +346,7 @@ nsMenuListenerAccessible::~nsMenuListenerAccessible()
if (mRegistered) {
nsCOMPtr<nsIDOMEventReceiver> eventReceiver(do_QueryInterface(mDOMNode));
if (eventReceiver)
eventReceiver->RemoveEventListener(NS_LITERAL_STRING("create"), this, PR_TRUE);
eventReceiver->RemoveEventListener(NS_LITERAL_STRING("popupshowing"), this, PR_TRUE);
}
}
@ -388,7 +388,7 @@ nsMenuListenerAccessible::SetupMenuListener()
return;
}
nsresult rv = eventReceiver->AddEventListener(NS_LITERAL_STRING("create"), this, PR_TRUE);
nsresult rv = eventReceiver->AddEventListener(NS_LITERAL_STRING("popupshowing"), this, PR_TRUE);
if (NS_FAILED(rv)) {
return;

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

@ -1,413 +0,0 @@
<?xml version="1.0"?>
<bindings id="formWidgets"
xmlns="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="select-base">
<implementation>
<property name="size">
<getter>
var size = this.getAttribute("size")
return !size ? 1 : size;
</getter>
<setter>
this.setAttribute("size", val);
return val;
</setter>
</property>
<property name="_selectArray">[]</property>
<method name="_initSelection">
<body>
<![CDATA[
// Note that here we only initialize a _selectArray[0], as a selection
// of more than one option in the case of a regular select is meaningless.
var options = this.getElementsByTagName("option");
for (var i = 0; i < options.length; ++i) {
if (options[i].hasAttribute("selected")) {
this._selectArray.push(options[i]);
this._selectArray[0].selected = true; // XXX lame
break;
}
}
if (this.size == 1 && options.length &&
!this._selectArray.length)
options[0].selected = true;
]]>
</body>
</method>
</implementation>
</binding>
<binding id="select-size" display="xul:tree"
extends="resource:///res/builtin/selectBindings.xml#select-base">
<implementation>
<property name="value" onget="return this.getAttribute('value');">
<setter>
<![CDATA[
var options = this.getElementsByTagName("option");
for (var i = 0; i < options.length; ++i) {
if (options[i].getAttribute("value") == val)
this._selectArray.push(options[i]);
}
this.setAttribute("value", val);
return val;
]]>
</setter>
</property>
<property name="disabled" onset="if (val) this.setAttribute('disabled',true);
else this.removeAttribute('disabled');
return val;"
onget="return (this.getAttribute('disabled')=='true');"/>
<property name="selectedIndex">
<getter>
<![CDATA[
if (!this._selectArray)
return -1;
var options = this.getElementsByTagName("option");
for (var i = 0; i < options.length; ++i) {
if (options[i].getAttribute("selected"))
return i;
}
return -1;
]]>
</getter>
<setter>
<![CDATA[
if (val >= 0 && this.hasChildNodes() && this.childNodes[val]) {
this.childNodes[val].setAttribute("selected", "true");
this._selectArray.push(this.childNodes[val]);
}
return val;
]]>
</setter>
</property>
<!-- Internal Implementation Methods -->
<method name="getElementByAttribute">
<parameter name="aAttributeName"/>
<parameter name="aAttributeValue"/>
<body>
<![CDATA[
var anonymousNodes = document.getAnonymousNodes(this);
for (var i = 0; i < anonymousNodes.length; ++i)
return this.recursiveAttributeSearch(anonymousNodes[i], aAttributeName, aAttributeValue);
return null;
]]>
</body>
</method>
<method name="recursiveAttributeSearch">
<parameter name="aNode"/>
<parameter name="aAttributeName"/>
<parameter name="aAttributeValue"/>
<body>
<![CDATA[
if (aNode) {
if (aNode.getAttribute(aAttributeName) == aAttributeValue)
return aNode;
for (var i = 0; i < aNode.childNodes.length; ++i)
return this.recursiveAttributeSearch(aNode.childNodes[i], aAttributeName, aAttributeValue);
}
return null;
]]>
</body>
</method>
<method name="_deselectAll">
<body>
<![CDATA[
for (var i = 0; i < this._selectArray.length; ++i) {
dump("*** clearing selection for = " + this._selectArray[i].text + "\n");
this._selectArray[i].selected = false;
}
]]>
</body>
</method>
<method name="_adjustSelection">
<parameter name="aSelectUp"/>
<paramater name="aAdditive"/>
<body>
<![CDATA[
if (this._selectArray.length < 1) return;
for (var i = 0; i < this._selectArray.length; ++i) {
if (this._selectArray[i] == this.childNodes[this.selectedIndex]) {
var currItem = this._selectArray[i];
this._deselectAll();
var nextItem = aSelectUp ? currItem.previousSibling : currItem.nextSibling;
if (nextItem) this.selectedIndex = nextItem.index;
break;
}
}
]]>
</body>
</method>
<constructor action="this._initSelection()"/>
</implementation>
<handlers>
<handler event="mousedown">
<![CDATA[
if (event.target.localName != "OPTION")
return;
for (var i = 0; i < this._selectArray.length; ++i)
this._selectArray[i].removeAttribute('selected');
this._selectArray = [event.target];
event.target.setAttribute("selected", "true");
]]>
</handler>
<handler event="command" phase="capturing">
<![CDATA[
if (event.target.localName == "menuitem")
this.selectedItem = event.target;
]]>
</handler>
<handler event="create">
<![CDATA[
if (event.target.parentNode == this && this.selectedItem) {
// Not ready for auto-setting the active child in hierarchies yet.
// For now, only do this when the outermost menupopup opens.
var menuBox = this.boxObject.QueryInterface(Components.interfaces.nsIMenuBoxObject);
menuBox.activeChild = this.selectedItem;
}
]]>
</handler>
<!-- Selection Management -->
<handler event="keypress" keycode="vk_up">
<![CDATA[
if (event.target == this)
this._adjustSelection(true);
event.preventDefault();
]]>
</handler>
<handler event="keypress" keycode="vk_down">
<![CDATA[
if (event.target == this)
this._adjustSelection(false);
event.preventDefault();
]]>
</handler>
</handlers>
</binding>
<binding id="select" display="xul:menu"
extends="resource:///res/builtin/selectBindings.xml#select-base">
<implementation>
<property name="value" onget="return this.getAttribute('value');">
<setter>
<![CDATA[
var options = this.getElementsByTagName("option");
for (var i = 0; i < options.length; ++i) {
if (options[i].getAttribute("value") == val)
this._selectArray.push(options[i]);
}
this.setAttribute("value", val);
return val;
]]>
</setter>
</property>
<property name="disabled">
<getter>
return this.hasAttribute("disabled");
</getter>
<setter>
if (val == "true") this.setAttribute("disabled", "true");
else this.removeAttribute("disabled");
return val;
</setter>
</property>
<property name="selectedIndex">
<getter>
<![CDATA[
if (!this._selectArray)
return -1;
var options = this.getElementsByTagName("option");
for (var i = 0; i < options.length; ++i) {
if (options[i].getAttribute("selected"))
return i;
}
return -1;
]]>
</getter>
<setter>
<![CDATA[
this._selectArray = [];
if (val >= 0 && this.hasChildNodes() && this.childNodes[val]) {
this.childNodes[val].setAttribute("selected", "true");
this._selectArray.push(this.childNodes[val]);
var textDisplayNode = this.getElementByAttribute("selectattr", "text");
if (textDisplayNode) {
var text = this.childNodes[val].text;
text = text.replace(/\n/g, "");
textDisplayNode.setAttribute("value", text);
}
}
return val;
]]>
</setter>
</property>
<!-- Internal Implementation Methods -->
<method name="getElementByAttribute">
<parameter name="aAttributeName"/>
<parameter name="aAttributeValue"/>
<body>
<![CDATA[
var anonymousNodes = document.getAnonymousNodes(this);
for (var i = 0; i < anonymousNodes.length; ++i)
return this.recursiveAttributeSearch(anonymousNodes[i], aAttributeName, aAttributeValue);
return null;
]]>
</body>
</method>
<method name="recursiveAttributeSearch">
<parameter name="aNode"/>
<parameter name="aAttributeName"/>
<parameter name="aAttributeValue"/>
<body>
<![CDATA[
if (aNode) {
if (aNode.getAttribute(aAttributeName) == aAttributeValue)
return aNode;
for (var i = 0; i < aNode.childNodes.length; ++i)
return this.recursiveAttributeSearch(aNode.childNodes[i], aAttributeName, aAttributeValue);
}
return null;
]]>
</body>
</method>
</implementation>
<handlers>
<handler event="command" phase="capturing">
<![CDATA[
if (event.target.localName == "OPTION")
this.selectedIndex = event.target.index;
]]>
</handler>
<handler event="create">
<![CDATA[
if (event.target == this && this._selectArray.length) {
// Not ready for auto-setting the active child in hierarchies yet.
// For now, only do this when the outermost menupopup opens.
var boxObject = document.getBoxObjectFor(this);
var menuBox = boxObject.QueryInterface(Components.interfaces.nsIMenuBoxObject);
menuBox.activeChild = this._selectArray[0];
}
]]>
</handler>
<handler event="mouseover">
<![CDATA[
if (event.target.localName == "OPTION") {
var oldactive = this.getElementByAttribute("menuactive", "true");
if (oldactive)
oldactive.removeAttribute("menuactive");
}
]]>
</handler>
<handler event="bindingattached" action="this._initSelection()"/>
</handlers>
</binding>
<binding id="option" display="xul:menuitem"
extends="resource:///res/builtin/selectBindings.xml#option-base"/>
<binding id="option-size" display="xul:treerow"
extends="resource:///res/builtin/selectBindings.xml#option-base"/>
<binding id="option-base">
<implementation>
<property name="form" readonly="true"/>
<property name="defaultSelected">false</property>
<property name="text" readonly="true">
<getter>
<![CDATA[
var textString = "";
if (this.hasChildNodes()) {
for (var i = 0; i < this.childNodes.length; ++i)
textString += this.childNodes[i].nodeValue;
}
return textString;
]]>
</getter>
</property>
<property name="index" readonly="true">
<getter>
<![CDATA[
var parent = this.parentNode;
// bail on supporting optgroup at this juncture.
if (!parent) return -1;
for (var i = 0; i < parent.childNodes.length; ++i) {
if (parent.childNodes[i] == this)
return i;
}
return -1;
]]>
</getter>
</property>
<property name="disabled">
<getter>
return this.hasAttribute("disabled");
</getter>
<setter>
if (val) this.setAttribute("disabled", "true");
else this.removeAttribute("disabled");
</setter>
</property>
<property name="label">
<getter>
return this.getAttribute("label");
</getter>
<setter>
this.setAttribute("label", val);
return val;
</setter>
</property>
<property name="selected">
<getter>
return this.hasAttribute("selected");
</getter>
<setter>
var parent = this.parentNode;
if (parent)
parent.selectedIndex = this.index;
return val;
</setter>
</property>
<property name="value">
<getter>
return this.getAttribute("value");
</getter>
<setter>
this.setAttribute("value", val);
return val;
</setter>
</property>
<property name="_textNode">
</property>
</implementation>
</binding>
</bindings>

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

@ -99,7 +99,7 @@
addContextMenuItemListeners : function (aEvent) {
var contextPopup = document.getElementById("contentAreaContextSet");
contextPopup.addEventListener("create", cookieContextMenu.initImageBlocking, false);
contextPopup.addEventListener("popupshowing", cookieContextMenu.initImageBlocking, false);
}
}

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

@ -19,7 +19,7 @@
document.getElementById("menu_inspectPage").setAttribute("hidden", "true");
} else {
var popup = document.getElementById("contentAreaContextMenu");
popup.addEventListener("create", inspectorContextCreate, false);
popup.addEventListener("popupshowing", inspectorContextCreate, false);
}
}

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

@ -238,7 +238,7 @@ inSearchService.prototype =
var mod = this.mCurrentModule;
if (mod) {
var menu = this.mContextMenu;
menu.addEventListener("create", inSearchService_onCreatePopup, true);
menu.addEventListener("popupshowing", inSearchService_onCreatePopup, true);
mod.installContextMenu(menu, this.mCMInsertPt, this.mCMInsert);
}
},
@ -249,7 +249,7 @@ inSearchService.prototype =
if (mod) {
// remove the createion listener
var menu = this.mContextMenu;
menu.removeEventListener("create", inSearchService_onCreatePopup, true);
menu.removeEventListener("popupshowing", inSearchService_onCreatePopup, true);
mod.uninstallContextMenu(menu, this.mCMInsertPt, this.mCMInsert);
}
},
@ -400,4 +400,3 @@ inSearchServiceLoadObserver.prototype = {
},
*/

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

@ -94,7 +94,7 @@
</handler>
<!-- Location Bar Type-In History -->
<handler event="create">
<handler event="popupshowing">
<![CDATA[
if (event.originalTarget.getAttribute("emattr") == "menupopup")
this.createUBHistory();

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

@ -229,7 +229,7 @@ function registerZoomManager()
textZoomMenu.removeAttribute("hidden");
var parentMenu = textZoomMenu.parentNode;
parentMenu.addEventListener("create", updateViewMenu, false);
parentMenu.addEventListener("popupshowing", updateViewMenu, false);
var insertBefore = document.getElementById("menu_textZoomInsertBefore");
var popup = insertBefore.parentNode;

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

@ -99,7 +99,7 @@
addContextMenuItemListeners : function (aEvent) {
var contextPopup = document.getElementById("contentAreaContextSet");
contextPopup.addEventListener("create", cookieContextMenu.initImageBlocking, false);
contextPopup.addEventListener("popupshowing", cookieContextMenu.initImageBlocking, false);
}
}

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

@ -25,7 +25,7 @@
<handler event="command" phase="capturing"
action="if (event.originalTarget.localName == 'menuitem') this.selectedItem = event.originalTarget;"/>
<handler event="create">
<handler event="popupshowing">
<![CDATA[
if (event.target.parentNode == this && this.selectedItem) {
// Not ready for auto-setting the active child in hierarchies yet.
@ -326,7 +326,7 @@
]]>
</handler>
<handler event="create">
<handler event="popupshowing">
<![CDATA[
// BUG in Classic skin: doesn't shift focus when popup is opened
// so force it to inputField here
@ -367,4 +367,4 @@
</handlers>
</binding>
</bindings>
</bindings>

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

@ -492,7 +492,7 @@
]]>
</handler>
<!-- clean up, release the mouse, etc -->
<handler event="destroy">
<handler event="popuphiding">
<![CDATA[
dump("*** destroy: releasing mouse\n");
this.cleanUp(event);