From 511b7a7434316df988e7e4081fb695308eed3de7 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Thu, 14 Sep 2006 06:04:29 +0000 Subject: [PATCH] "Textbox context menu generates spurious focus events.". Bug 155871, patch by neil@parkwaycc.co.uk, r=dean_tessman@hotmail.com, sr=jag --- suite/browser/navigator.js | 71 +++++++------------------------------ suite/browser/navigator.xul | 3 +- 2 files changed, 14 insertions(+), 60 deletions(-) diff --git a/suite/browser/navigator.js b/suite/browser/navigator.js index 57742542a26..3fcf5d955e2 100644 --- a/suite/browser/navigator.js +++ b/suite/browser/navigator.js @@ -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 diff --git a/suite/browser/navigator.xul b/suite/browser/navigator.xul index b40ed27bc72..cf5cf3d413b 100644 --- a/suite/browser/navigator.xul +++ b/suite/browser/navigator.xul @@ -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);">