UIEvent button property is incorrect according to the DOM2 spec. Changing values to 0, 1, 2 (left, middle, right mouse buttons respectively) from 1, 2, 3. |event.which| continues to use the old values for backwards compatibility. This affects future xbl, js, and c++ event button checks so please see the newsgroups for more info (60703). r=timeless sr=jst

This commit is contained in:
blakeross%telocity.com 2001-03-02 03:07:53 +00:00
parent 393596d00b
commit 38794d139f
30 changed files with 95 additions and 95 deletions

View File

@ -698,7 +698,8 @@ NS_METHOD nsDOMEvent::GetKeyCode(PRUint32* aKeyCode)
NS_METHOD nsDOMEvent::GetButton(PRUint16* aButton)
{
if (!mEvent || mEvent->eventStructType != NS_MOUSE_EVENT) {
*aButton = 0;
NS_WARNING("Tried to get mouse button for null or non-mouse event!");
*aButton = (PRUint16)-1;
return NS_OK;
}
@ -707,19 +708,19 @@ NS_METHOD nsDOMEvent::GetButton(PRUint16* aButton)
case NS_MOUSE_LEFT_BUTTON_DOWN:
case NS_MOUSE_LEFT_CLICK:
case NS_MOUSE_LEFT_DOUBLECLICK:
*aButton = 1;
*aButton = 0;
break;
case NS_MOUSE_MIDDLE_BUTTON_UP:
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
case NS_MOUSE_MIDDLE_CLICK:
case NS_MOUSE_MIDDLE_DOUBLECLICK:
*aButton = 2;
*aButton = 1;
break;
case NS_MOUSE_RIGHT_BUTTON_UP:
case NS_MOUSE_RIGHT_BUTTON_DOWN:
case NS_MOUSE_RIGHT_CLICK:
case NS_MOUSE_RIGHT_DOUBLECLICK:
*aButton = 3;
*aButton = 2;
break;
default:
break;
@ -860,7 +861,7 @@ NS_METHOD nsDOMEvent::GetWhich(PRUint32* aWhich)
{
PRUint16 button;
(void) GetButton(&button);
*aWhich = button;
*aWhich = button + 1;
break;
}
default:

View File

@ -331,7 +331,7 @@ XULPopupListenerImpl::PreLaunchPopup(nsIDOMEvent* aMouseEvent)
case eXULPopupType_popup:
// Check for left mouse button down
mouseEvent->GetButton(&button);
if (button == 1) {
if (button == 0) {
// Time to launch a popup menu.
LaunchPopup(aMouseEvent);
aMouseEvent->PreventBubble();
@ -341,7 +341,7 @@ XULPopupListenerImpl::PreLaunchPopup(nsIDOMEvent* aMouseEvent)
case eXULPopupType_context:
// Check for right mouse button down
mouseEvent->GetButton(&button);
if (button == 3) {
if (button == 2) {
// Time to launch a context menu
// If the context menu launches on mousedown,

View File

@ -376,10 +376,10 @@ nsTextEditorMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
nsCOMPtr<nsIEditor> editor (do_QueryInterface(mEditor));
if (!editor) { return NS_OK; }
PRUint16 button = 0;
PRUint16 button = (PRUint16)-1;
mouseEvent->GetButton(&button);
// middle-mouse click (paste);
if (button == 2)
if (button == 1)
{
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefService, kPrefServiceCID, &rv);

View File

@ -193,7 +193,7 @@ nsEditorShellMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
res = mouseEvent->GetCtrlKey(&isContextClick);
#else
// Right mouse button for Windows, UNIX
isContextClick = buttonNumber == 3;
isContextClick = buttonNumber == 2;
res = mouseEvent->GetCtrlKey(&tableMode);
#endif
if (NS_FAILED(res)) return res;
@ -253,7 +253,7 @@ nsEditorShellMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
}
}
if (isContextClick || (buttonNumber == 1 && clickCount == 2))
if (isContextClick || (buttonNumber == 0 && clickCount == 2))
{
// Context menu or double click
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(target);
@ -281,7 +281,7 @@ nsEditorShellMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
mEditorShell->SelectElement(element);
}
}
else if (buttonNumber == 1)
else if (buttonNumber == 0)
{
if (tableMode && clickCount == 2)
{

View File

@ -193,7 +193,7 @@ nsEditorShellMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
res = mouseEvent->GetCtrlKey(&isContextClick);
#else
// Right mouse button for Windows, UNIX
isContextClick = buttonNumber == 3;
isContextClick = buttonNumber == 2;
res = mouseEvent->GetCtrlKey(&tableMode);
#endif
if (NS_FAILED(res)) return res;
@ -253,7 +253,7 @@ nsEditorShellMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
}
}
if (isContextClick || (buttonNumber == 1 && clickCount == 2))
if (isContextClick || (buttonNumber == 0 && clickCount == 2))
{
// Context menu or double click
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(target);
@ -281,7 +281,7 @@ nsEditorShellMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
mEditorShell->SelectElement(element);
}
}
else if (buttonNumber == 1)
else if (buttonNumber == 0)
{
if (tableMode && clickCount == 2)
{

View File

@ -376,10 +376,10 @@ nsTextEditorMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
nsCOMPtr<nsIEditor> editor (do_QueryInterface(mEditor));
if (!editor) { return NS_OK; }
PRUint16 button = 0;
PRUint16 button = (PRUint16)-1;
mouseEvent->GetButton(&button);
// middle-mouse click (paste);
if (button == 2)
if (button == 1)
{
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefService, kPrefServiceCID, &rv);

View File

@ -515,7 +515,7 @@ function moveMouse(event){
function downMouse(event){
dump(event.target.parentNode.id+"\n");
if (event.button == 1){
if (event.button == 0){
if (currentTool != "poly"){
startX = event.clientX+window.frames[0].pageXOffset;
startY = event.clientY+window.frames[0].pageYOffset;
@ -630,7 +630,7 @@ function downMouse(event){
}
function clickMouse(event){
if (event.button == 1){
if (event.button == 0){
dump("body clicked\n");
//alert(frameDoc.+'\n');
startX = event.clientX+window.frames[0].pageXOffset;

View File

@ -988,7 +988,7 @@ ChromeListener::MouseDown(nsIDOMEvent* aMouseEvent)
nsresult res = mouseEvent->GetButton(&buttonNumber);
if (NS_FAILED(res))
return res;
if (buttonNumber != 3) // 3 is the magic number
if (buttonNumber != 2) // 2 is the magic number
return NS_OK;
nsCOMPtr<nsIDOMEventTarget> targetNode;

View File

@ -151,8 +151,8 @@
</implementation>
<handlers>
<handler event="mousedown"><![CDATA[
if (this.parentItem.getAttribute("selected") == "true" && event.button == 1)
<handler event="mousedown" button="0"><![CDATA[
if (this.parentItem.getAttribute("selected") == "true")
this.startEdit();
]]></handler>
</handlers>

View File

@ -64,7 +64,7 @@ function lbox_chandler (e)
/* Check for the button number first */
/* FIXME: are there constants for this stuff? */
if (e.event.which == 3)
if (e.event.button == 2)
{
return;
}

View File

@ -575,13 +575,13 @@ mozXMLTermMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
return NS_OK;
}
PRUint16 buttonCode = 0;
PRUint16 buttonCode = (PRUint16)-1;
mouseEvent->GetButton(&buttonCode);
XMLT_LOG(mozXMLTermMouseListener::MouseDown,50,("buttonCode=%d\n",
buttonCode));
if (buttonCode == 2) {
if (buttonCode == 1) {
// Middle-mouse button pressed; initiate paste
mXMLTerminal->Paste();
}
@ -612,7 +612,7 @@ mozXMLTermMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
return NS_OK;
}
PRUint16 buttonCode = 0;
PRUint16 buttonCode = (PRUint16)-1;
mouseEvent->GetButton(&buttonCode);
PRInt32 screenX, screenY;

View File

@ -838,13 +838,13 @@ nsSliderFrame::MouseDown(nsIDOMEvent* aMouseEvent)
PRUint16 button = 0;
mouseEvent->GetButton(&button);
if((mMiddlePref && button != 1 && button != 2) ||
(!mMiddlePref && button != 1))
if((mMiddlePref && button != 0 && button != 1) ||
(!mMiddlePref && button != 0))
return NS_OK;
// If middle button, first place the middle of the slider thumb
// under the click
if (button == 2) {
if (button == 1) {
nscoord pos;
nscoord pospx;

View File

@ -813,7 +813,7 @@ nsSplitterFrameInner::MouseDown(nsIDOMEvent* aMouseEvent)
mouseEvent->GetButton(&button);
// only if left button
if (button != 1)
if (button != 0)
return NS_OK;
nsCOMPtr<nsIContent> content;

View File

@ -273,7 +273,7 @@ function HandleKeyEvent( aEvent )
function HandleClickEvent( aEvent )
{
if( aEvent.detail == 2 && aEvent.which == 1 ) {
if( aEvent.detail == 2 && aEvent.button == 0 ) {
if( aEvent.target.nodeName.toLowerCase() == "treecell" &&
aEvent.target.parentNode.parentNode.nodeName.toLowerCase() != "treehead" )
return onStart();

View File

@ -77,7 +77,7 @@
<handler event="click">
<![CDATA[
if (event.originalTarget.getAttribute("emattr") == "field")
if (event.button == 1) this.doFocus();
if (event.button == 0) this.doFocus();
]]>
</handler>
<handler event="blur">

View File

@ -153,7 +153,7 @@ Contributor(s): ______________________________________. -->
<image id="page-proxy-button" ondraggesture="nsDragAndDrop.startDrag(event, proxyIconDNDObserver);"/>
<textfield autocomplete="true" timeout="300" class="plain"
searchSessionType="urlbar" id="urlbar" tooltip="aTooltip" tooltiptext="&locationBar.tooltip;"
onclick="if (event.button==1) URLBarLeftClickHandler(event);"
onclick="if (event.button == 0) URLBarLeftClickHandler(event);"
onblur="URLBarBlurHandler(event);"
onkeypress="if( event.keyCode == 13 ) { addToUrlbarHistory(); BrowserLoadURL(); }" flex="1"/>
</box>

View File

@ -111,8 +111,8 @@
break;
case "input":
if ((event.target.type.toLowerCase() == "text" || event.target.type == "") // text field
&& event.detail == "2" // double click
&& event.button == "1" // left mouse button
&& event.detail == 2 // double click
&& event.button == 0 // left mouse button
&& event.target.value.length == 0) { // no text has been entered
prefillTextField(target); // prefill the empty text field if possible
}
@ -138,7 +138,7 @@
function handleLinkClick(event, href)
{
switch (event.button) {
case 1: // if left button clicked
case 0: // if left button clicked
if (event.metaKey || event.ctrlKey) { // and meta or ctrl are down
openNewWindowWith(href); // open link in new window
event.preventBubble();
@ -151,7 +151,7 @@
if (event.altKey) // if alt is down
return true; // do nothing
return false;
case 2: // if middle button clicked
case 1: // if middle button clicked
if (pref && pref.GetBoolPref("middlemouse.openNewWindow")) { // and the pref is on
openNewWindowWith(href); // open link in new window
event.preventBubble();

View File

@ -169,7 +169,7 @@ function doEnabling()
function OpenURL(event, node, root)
{
if (event.button != 1 ||
if (event.button != 0 ||
event.detail != 2 ||
node.nodeName != "treeitem" ||
node.getAttribute("container") == "true") {

View File

@ -28,7 +28,7 @@
function clicked(event, target)
{
if ((event.button != 1) || (event.detail != 2) || (target.nodeName != "treeitem"))
if ((event.button != 0) || (event.detail != 2) || (target.nodeName != "treeitem"))
return false;
if (event.altKey)

View File

@ -572,7 +572,7 @@ function getAbsoluteID(root, node)
function OpenURL(event, node, root)
{
if ((event.button != 1) || (event.detail != 2)
if ((event.button != 0) || (event.detail != 2)
|| (node.nodeName != "treeitem"))
return false;

View File

@ -279,7 +279,7 @@ BookmarksTree.prototype = {
isValidOpenEvent: function (aEvent)
{
return !(aEvent.type == "click" &&
(aEvent.button != 1 || aEvent.detail != this.openClickCount))
(aEvent.button != 0 || aEvent.detail != this.openClickCount))
},
/////////////////////////////////////////////////////////////////////////////
@ -397,7 +397,7 @@ BookmarksTree.prototype = {
// editable cells.
treeClicked: function (aEvent)
{
if (this.tree.selectedItems.length > 1 || aEvent.detail > 1 || aEvent.button != 1)
if (this.tree.selectedItems.length > 1 || aEvent.detail > 1 || aEvent.button != 0)
return;
if (gSelectionTracker.currentItem == this.tree.currentItem &&
gSelectionTracker.currentCell == aEvent.target)
@ -441,8 +441,12 @@ BookmarksTree.prototype = {
else if (aEvent.keyCode == 113)
goDoCommand("cmd_rename");
else if (aEvent.keyCode == 13 &&
this.tree.currentItem.firstChild.getAttribute("inline-edit") != "true")
goDoCommand("cmd_open");
this.tree.currentItem.firstChild.getAttribute("inline-edit") != "true") {
if (aEvent.altKey)
goDoCommand("cmd_properties");
else
goDoCommand("cmd_open");
}
},
selectFolderItem: function (aFolderURI, aItemURI, aAdditiveFlag)

View File

@ -226,7 +226,7 @@ function DoUnload()
function OnClick(event, node)
{
if( event.type == "click" &&
( event.button != 1 || event.detail != 2 || node.nodeName != "treeitem") )
( event.button != 0 || event.detail != 2 || node.nodeName != "treeitem") )
return(false);
if( event.type == "keypress" && event.keyCode != 13 )
return(false);

View File

@ -183,7 +183,7 @@ var historyDNDObserver = {
function OpenURL(event, node, root)
{
if ((event.button != 1) || (event.detail != 2)
if ((event.button != 0) || (event.detail != 2)
|| (node.nodeName != "treeitem"))
return false;

View File

@ -207,7 +207,7 @@ function treeSelect(event)
function treeClick(event)
{
if (event.detail == 2 && event.which == 1)
if (event.detail == 2 && event.button == 0)
searchResultsOpenURL(event);
else
treeSelect(event);

View File

@ -97,7 +97,7 @@
resource2="http://home.netscape.com/NC-rdf#Name"
sortDirection="ascending" sortActive="true"
flex="1" datasources="rdf:internetsearch"
onclick="if (event.button == 1 &amp;&amp; event.target.localName == 'treecell')
onclick="if (event.button == 0 &amp;&amp; event.target.localName == 'treecell')
sidebarOpenURL(event.target.parentNode.parentNode);"
style="-moz-user-focus:ignore !important;">

View File

@ -52,33 +52,31 @@
<!-- On a click (up+down on the same item), deselect everything
except this item. -->
<handler event="click">
<![CDATA[
// XXX Check for cycler.
if (event.button != 1) return;
var row = {};
var col = {};
var b = this.parentNode.outlinerBoxObject;
b.getCellAt(event.clientX, event.clientY, row, col);
var augment = event.ctrlKey || event.metaKey;
if (event.shiftKey) {
b.selection.rangedSelect(-1, row.value, augment);
b.currentIndex = row.value;
}
else if (augment) {
b.selection.toggleSelect(row.value);
b.selection.currentIndex = row.value;
}
else {
/* We want to deselect all the selected items except what was
clicked, UNLESS it was a right-click. We have to do this
in click rather than mousedown so that you can drag a
selected group of items */
<handler event="click" button="0">
<![CDATA[
// XXX Check for cycler.
var row = {};
var col = {};
var b = this.parentNode.outlinerBoxObject;
b.getCellAt(event.clientX, event.clientY, row, col);
var augment = event.ctrlKey || event.metaKey;
if (event.shiftKey) {
b.selection.rangedSelect(-1, row.value, augment);
b.currentIndex = row.value;
}
else if (augment) {
b.selection.toggleSelect(row.value);
b.selection.currentIndex = row.value;
}
else {
/* We want to deselect all the selected items except what was
clicked, UNLESS it was a right-click. We have to do this
in click rather than mousedown so that you can drag a
selected group of items */
if (event.button == 1)
b.selection.select(row.value);
}
]]>
b.selection.select(row.value);
}
]]>
</handler>
<!-- double-click -->

View File

@ -129,14 +129,14 @@
</method>
</implementation>
<handlers>
<handler event="click" button="1">
<handler event="click" button="0">
<![CDATA[
if (event.target.localName == "radio" && !event.target.disabled)
this.selectedItem = event.target;
]]>
</handler>
<handler event="mousedown" button="1">
<handler event="mousedown" button="0">
<![CDATA[
if (event.target.localName == "radio" && !event.target.disabled)
this.focusedItem = event.target;

View File

@ -179,7 +179,7 @@
</property>
</implementation>
<handlers>
<handler event="click" button="1">
<handler event="click" button="0">
<![CDATA[
var tabbox = this.parentNode;
do {

View File

@ -536,9 +536,8 @@
<!-- On a click (up+down on the same item), deselect everything
except this item. -->
<handler event="click">
<handler event="click" button="0">
<![CDATA[
if (event.button != 1) return;
var t = event.originalTarget;
if (t.localName == 'treecell') {
if (event.ctrlKey || event.metaKey) {
@ -555,24 +554,22 @@
in click rather than mousedown so that you can drag a
selected group of items */
if (event.button == 1) {
var selectedItems = parentNode.selectedItems;
var didSuppressSelect = false;
var i = 0;
while (i < selectedItems.length) {
if (selectedItems[i] != t.parentNode.parentNode) {
if (!didSuppressSelect) {
parentNode.suppressOnSelect = true;
didSuppressSelect = true;
}
parentNode.removeItemFromSelection(selectedItems[i]);
var selectedItems = parentNode.selectedItems;
var didSuppressSelect = false;
var i = 0;
while (i < selectedItems.length) {
if (selectedItems[i] != t.parentNode.parentNode) {
if (!didSuppressSelect) {
parentNode.suppressOnSelect = true;
didSuppressSelect = true;
}
else
i++;
parentNode.removeItemFromSelection(selectedItems[i]);
}
if (didSuppressSelect)
parentNode.suppressOnSelect = false;
else
i++;
}
if (didSuppressSelect)
parentNode.suppressOnSelect = false;
}
}
]]>

View File

@ -156,7 +156,7 @@
if (v == 'true') return true; return false;"/>
</implementation>
<handlers>
<handler event="click" button="1" action="if (!this.disabled) this.checked = !this.checked;"/>
<handler event="click" button="0" action="if (!this.disabled) this.checked = !this.checked;"/>
<handler event="keypress" key=" " action="if (!this.disabled) this.checked = !this.checked;"/>
</handlers>
</binding>