"Textbox context menu generates spurious focus events.". Bug 155871,

patch by neil@parkwaycc.co.uk, r=dean_tessman@hotmail.com, sr=jag


git-svn-id: svn://10.0.0.236/trunk@124837 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bzbarsky%mit.edu 2002-07-09 08:42:11 +00:00
parent 941afc1277
commit cc593fa8c5
3 changed files with 41 additions and 94 deletions

View File

@ -54,8 +54,7 @@ var gLastValidURL = null;
var gHaveUpdatedToolbarState = false;
var gClickSelectsAll = false;
var gIgnoreFocus = false;
var gIgnoreFocusCount = 0;
var gMouseDownX = -1;
var gIgnoreClick = false;
var pref = null;
@ -1550,71 +1549,27 @@ function getNewThemes()
function URLBarFocusHandler(aEvent)
{
if (gClickSelectsAll)
if (!gIgnoreFocus)
gURLBar.select();
else {
// check if gIgnoreFocusCount >= 2 because right-clicking on the url bar
// causes two blur and two focus events before the context menu is displayed.
// we need to eat all those events and not select all, because the user
// may want to work with the selection (eg. copy the selection).
// a normal click in URLBarMouseDownHandler() primes gIgnoreFocusCount
// to 1 so that when it hits this code it will only ignore 1 focus event.
gIgnoreFocusCount++;
if (gIgnoreFocusCount >= 2) {
gIgnoreFocusCount = 0;
gIgnoreFocus = false;
}
}
}
function URLBarBlurHandler(aEvent)
{
// reset the selection so the next time the urlbar is focused it
// doesn't re-select the old selection
if (gClickSelectsAll && !gIgnoreFocus)
gURLBar.setSelectionRange(0, 0);
if (gIgnoreFocus)
gIgnoreFocus = false;
else if (gClickSelectsAll)
gURLBar.select();
}
function URLBarMouseDownHandler(aEvent)
{
gMouseDownX = -1;
if (gURLBar) {
if (gClickSelectsAll) {
var focusedElement = null;
if (document.commandDispatcher.focusedElement)
focusedElement = document.commandDispatcher.focusedElement.parentNode.parentNode.parentNode;
if (!focusedElement || (focusedElement && focusedElement != gURLBar))
{
// clicking onto the url bar when it doesn't have focus.
// see note in URLBarFocusHandler() about gIgnoreFocusCount.
gIgnoreFocusCount = 1;
gIgnoreFocus = true;
gMouseDownX = aEvent.screenX;
}
else if (aEvent.button == 2 && focusedElement && focusedElement == gURLBar) {
gIgnoreFocusCount = 0;
gIgnoreFocus = true;
}
}
if (gURLBar.hasAttribute("focused")) {
gIgnoreClick = true;
} else {
gIgnoreFocus = true;
gIgnoreClick = false;
gURLBar.setSelectionRange(0, 0);
}
}
function URLBarMouseUpHandler(aEvent)
function URLBarClickHandler(aEvent)
{
if (gMouseDownX > -1 && Math.abs(aEvent.screenX - gMouseDownX) <= 2) {
// mouse has moved less than two horizontal pixels between mouse down
// and mouse up - call it a click
if (!gIgnoreClick && gClickSelectsAll && gURLBar.selectionStart == gURLBar.selectionEnd)
gURLBar.select();
gMouseDownX = -1;
}
}
function URLBarKeyupHandler(aEvent)
{
if (aEvent.keyCode == aEvent.DOM_VK_TAB ) {
ShowAndSelectContentsOfURLBar();
}
}
// This function gets the "windows hooks" service and has it check its setting

View File

@ -169,9 +169,8 @@ Contributor(s):
ontextcommand="return handleURLBarCommand(eventParam, domEvent);"
ontextrevert="return handleURLBarRevert();"
onfocus="URLBarFocusHandler(event);"
onblur="URLBarBlurHandler(event);"
onmousedown="URLBarMouseDownHandler(event);"
onmouseup="URLBarMouseUpHandler(event);">
onclick="URLBarClickHandler(event);">
<deck id="page-proxy-deck">
<image id="page-proxy-button"
onclick="BookmarksUtils.addBookmarkForBrowser(getBrowser().webNavigation, true);"

View File

@ -64,8 +64,6 @@
<property name="selectionEnd" onset="this.inputField.selectionEnd = val; return val;"
onget="return this.inputField.selectionEnd;"/>
<field name="suppressFocusBlur">false</field>
<method name="setSelectionRange">
<parameter name="aSelectionStart"/>
<parameter name="aSelectionEnd"/>
@ -85,23 +83,19 @@
<handlers>
<handler event="focus" phase="capturing">
<![CDATA[
if (!this.hasAttribute('focused')) {
this.setAttribute('focused','true');
this.suppressFocusBlur = true;
if (document.commandDispatcher.focusedElement != this.inputField)
this.inputField.focus();
this.suppressFocusBlur = false;
}
]]>
<![CDATA[
if (!this.hasAttribute('focused')) {
if (document.commandDispatcher.focusedElement != this.inputField)
this.inputField.focus();
this.setAttribute('focused','true');
}
]]>
</handler>
<handler event="blur" phase="capturing">
<![CDATA[
if (!this.suppressFocusBlur && this.hasAttribute('focused')) {
<![CDATA[
this.removeAttribute('focused');
}
]]>
]]>
</handler>
</handlers>
</binding>
@ -118,27 +112,16 @@
<binding id="input-box">
<content context="_child">
<children/>
<xul:menupopup onpopupshowing="this.parentNode.focus(); this.parentNode.doPopupItemEnabling(this);">
<xul:menuitem label="&undoCmd.label;" accesskey="&undoCmd.accesskey;" cmd="cmd_undo"
oncommand="var controller = document.commandDispatcher.getControllerForCommand('cmd_undo');
controller.doCommand('cmd_undo');"/>
<xul:menupopup onpopupshowing="this.parentNode.firstChild.focus(); this.parentNode.doPopupItemEnabling(this);"
oncommand="this.parentNode.doCommand(event.originalTarget.getAttribute('cmd'));">
<xul:menuitem label="&undoCmd.label;" accesskey="&undoCmd.accesskey;" cmd="cmd_undo"/>
<xul:menuseparator/>
<xul:menuitem label="&cutCmd.label;" accesskey="&cutCmd.accesskey;" cmd="cmd_cut"
oncommand="var controller = document.commandDispatcher.getControllerForCommand('cmd_cut');
controller.doCommand('cmd_cut');"/>
<xul:menuitem label="&copyCmd.label;" accesskey="&copyCmd.accesskey;" cmd="cmd_copy"
oncommand="var controller = document.commandDispatcher.getControllerForCommand('cmd_copy');
controller.doCommand('cmd_copy');"/>
<xul:menuitem label="&pasteCmd.label;" accesskey="&pasteCmd.accesskey;" cmd="cmd_paste"
oncommand="var controller = document.commandDispatcher.getControllerForCommand('cmd_paste');
controller.doCommand('cmd_paste');"/>
<xul:menuitem label="&deleteCmd.label;" accesskey="&deleteCmd.accesskey;" cmd="cmd_delete"
oncommand="var controller = document.commandDispatcher.getControllerForCommand('cmd_delete');
controller.doCommand('cmd_delete');"/>
<xul:menuitem label="&cutCmd.label;" accesskey="&cutCmd.accesskey;" cmd="cmd_cut"/>
<xul:menuitem label="&copyCmd.label;" accesskey="&copyCmd.accesskey;" cmd="cmd_copy"/>
<xul:menuitem label="&pasteCmd.label;" accesskey="&pasteCmd.accesskey;" cmd="cmd_paste"/>
<xul:menuitem label="&deleteCmd.label;" accesskey="&deleteCmd.accesskey;" cmd="cmd_delete"/>
<xul:menuseparator/>
<xul:menuitem label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;" cmd="cmd_selectAll"
oncommand="var controller = document.commandDispatcher.getControllerForCommand('cmd_selectAll');
controller.doCommand('cmd_selectAll');"/>
<xul:menuitem label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;" cmd="cmd_selectAll"/>
</xul:menupopup>
</content>
@ -162,6 +145,16 @@
]]>
</body>
</method>
<method name="doCommand">
<parameter name="command"/>
<body>
<![CDATA[
var controller = document.commandDispatcher.getControllerForCommand(command);
controller.doCommand(command);
]]>
</body>
</method>
</implementation>
</binding>