Bug 308755 Change in behavior with type-to-find for non-link text and pressing TAB r=mconnor
git-svn-id: svn://10.0.0.236/trunk@180984 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
b5945ba305
commit
5d101affc4
@ -49,6 +49,7 @@ const CHAR_CODE_APOSTROPHE = "'".charCodeAt(0);
|
||||
// Global find variables
|
||||
var gFindMode = FIND_NORMAL;
|
||||
var gFoundLink = null;
|
||||
var gCurrentWindow = null;
|
||||
var gTmpOutline = null;
|
||||
var gTmpOutlineOffset = "0";
|
||||
var gDrawOutline = false;
|
||||
@ -392,10 +393,20 @@ function setFoundLink(foundLink)
|
||||
|
||||
function finishFAYT(aKeypressEvent)
|
||||
{
|
||||
if (!gFoundLink)
|
||||
try {
|
||||
if (gFoundLink)
|
||||
gFoundLink.focus();
|
||||
else if (gCurrentWindow)
|
||||
gCurrentWindow.focus();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
catch(e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
gFoundLink.focus(); // In this function, gFoundLink is set null.
|
||||
// NOTE: In this time, gFoundLink and gCurrentWindow are set null.
|
||||
// Because find toolbar lost focus.
|
||||
|
||||
if (aKeypressEvent)
|
||||
aKeypressEvent.preventDefault();
|
||||
@ -416,22 +427,34 @@ function delayedCloseFindBar()
|
||||
if (focusedElement && focusedElement.parentNode &&
|
||||
(focusedElement.parentNode == findToolbar ||
|
||||
focusedElement.parentNode.parentNode == findField)) {
|
||||
if (gFoundLink) {
|
||||
// block scrolling on focus since find already scrolls, further
|
||||
// scrolling is due to user action, so don't override this
|
||||
var suppressedScroll = document.commandDispatcher.suppressFocusScroll;
|
||||
document.commandDispatcher.suppressFocusScroll = true;
|
||||
gFoundLink.focus();
|
||||
document.commandDispatcher.suppressFocusScroll = suppressedScroll;
|
||||
// block scrolling on focus since find already scrolls, further
|
||||
// scrolling is due to user action, so don't override this
|
||||
var suppressedScroll = document.commandDispatcher.suppressFocusScroll;
|
||||
document.commandDispatcher.suppressFocusScroll = true;
|
||||
// We MUST reset suppressFocusScroll.
|
||||
try {
|
||||
if (gFoundLink)
|
||||
gFoundLink.focus();
|
||||
else if (gCurrentWindow)
|
||||
gCurrentWindow.focus();
|
||||
else
|
||||
window.content.focus();
|
||||
}
|
||||
else
|
||||
window.content.focus();
|
||||
catch(e) {
|
||||
// Retry to set focus.
|
||||
try {
|
||||
window.content.focus();
|
||||
}
|
||||
catch(e) { /* We lose focused element! */ }
|
||||
}
|
||||
document.commandDispatcher.suppressFocusScroll = suppressedScroll;
|
||||
}
|
||||
}
|
||||
|
||||
findToolbar.hidden = true;
|
||||
setFindMode(FIND_NORMAL);
|
||||
setFoundLink(null);
|
||||
gCurrentWindow = null;
|
||||
changeSelectionColor(false);
|
||||
if (gQuickFindTimeout) {
|
||||
clearTimeout(gQuickFindTimeout);
|
||||
@ -479,6 +502,7 @@ function onFindBarBlur()
|
||||
{
|
||||
changeSelectionColor(false);
|
||||
setFoundLink(null);
|
||||
gCurrentWindow = null;
|
||||
}
|
||||
|
||||
function onBrowserMouseUp(evt)
|
||||
@ -568,8 +592,7 @@ function onFindBarKeyPress(evt)
|
||||
}
|
||||
else if (evt.keyCode == KeyEvent.DOM_VK_TAB) {
|
||||
var shouldHandle = !evt.altKey && !evt.ctrlKey && !evt.metaKey;
|
||||
if (shouldHandle && gFindMode != FIND_NORMAL &&
|
||||
gFoundLink && finishFAYT(evt)) {
|
||||
if (shouldHandle && gFindMode != FIND_NORMAL && finishFAYT(evt)) {
|
||||
if (evt.shiftKey)
|
||||
document.commandDispatcher.rewindFocus();
|
||||
else
|
||||
@ -610,10 +633,13 @@ function enableFindButtons(aEnable)
|
||||
function updateFoundLink(res)
|
||||
{
|
||||
var val = document.getElementById("find-field").value;
|
||||
if (res == Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND || !val)
|
||||
if (res == Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND || !val) {
|
||||
setFoundLink(null);
|
||||
else
|
||||
gCurrentWindow = null;
|
||||
} else {
|
||||
setFoundLink(getBrowser().fastFind.foundLink);
|
||||
gCurrentWindow = getBrowser().fastFind.currentWindow;
|
||||
}
|
||||
}
|
||||
|
||||
function find(val)
|
||||
|
||||
@ -20,7 +20,8 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Original Author: Blake Ross (blake@cs.stanford.edu)
|
||||
* Blake Ross <blake@cs.stanford.edu> (Original Author)
|
||||
* Masayuki Nakano <masayuki@d-toybox.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
|
||||
@ -42,7 +43,7 @@
|
||||
|
||||
interface nsIDocShell;
|
||||
|
||||
[scriptable, uuid(09ccaa1d-422c-48a8-93fe-9c6e03dc4746)]
|
||||
[scriptable, uuid(376da416-e6b3-4bac-98f3-6aa408742751)]
|
||||
interface nsITypeAheadFind : nsISupports
|
||||
{
|
||||
void init(in nsIDocShell aDocShell);
|
||||
@ -61,5 +62,6 @@ interface nsITypeAheadFind : nsISupports
|
||||
attribute boolean focusLinks;
|
||||
attribute boolean caseSensitive;
|
||||
readonly attribute nsIDOMElement foundLink;
|
||||
readonly attribute nsIDOMWindow currentWindow;
|
||||
};
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
* Contributor(s):
|
||||
* Aaron Leventhal (aaronl@netscape.com)
|
||||
* Blake Ross (blake@cs.stanford.edu)
|
||||
* Masayuki Nakano (masayuki@d-toybox.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
|
||||
@ -83,7 +84,6 @@
|
||||
|
||||
#include "nsICaret.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
@ -278,6 +278,7 @@ nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell,
|
||||
{
|
||||
*aResult = FIND_NOTFOUND;
|
||||
mFoundLink = nsnull;
|
||||
mCurrentWindow = nsnull;
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
nsCOMPtr<nsISelectionController> selectionController;
|
||||
nsCOMPtr<nsIPresShell> startingPresShell (GetPresShell());
|
||||
@ -439,6 +440,10 @@ nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell,
|
||||
lastFocusedElement(do_QueryInterface(lastFocusedContent));
|
||||
mFoundLink = lastFocusedElement;
|
||||
}
|
||||
nsCOMPtr<nsIDocument> doc =
|
||||
do_QueryInterface(presShell->GetDocument());
|
||||
NS_ASSERTION(doc, "Wow, presShell doesn't have document!");
|
||||
mCurrentWindow = do_QueryInterface(doc->GetScriptGlobalObject());
|
||||
}
|
||||
|
||||
if (hasWrapped)
|
||||
@ -531,6 +536,15 @@ nsTypeAheadFind::GetFoundLink(nsIDOMElement** aFoundLink)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTypeAheadFind::GetCurrentWindow(nsIDOMWindow** aCurrentWindow)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aCurrentWindow);
|
||||
*aCurrentWindow = mCurrentWindow;
|
||||
NS_IF_ADDREF(*aCurrentWindow);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTypeAheadFind::GetFocusLinks(PRBool* aFocusLinks)
|
||||
{
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
* Contributor(s):
|
||||
* Aaron Leventhal (aaronl@netscape.com)
|
||||
* Blake Ross (blake@cs.stanford.edu)
|
||||
* Masayuki Nakano (masayuki@d-toybox.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
|
||||
@ -125,6 +126,7 @@ protected:
|
||||
PRBool mCaretBrowsingOn;
|
||||
PRBool mFocusLinks;
|
||||
nsCOMPtr<nsIDOMElement> mFoundLink;
|
||||
nsCOMPtr<nsIDOMWindow> mCurrentWindow;
|
||||
PRPackedBool mLiteralTextSearchOnly;
|
||||
PRPackedBool mDontTryExactMatch;
|
||||
// mAllTheSame Char starts out PR_TRUE, becomes false when
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user