Not part of build. Bug 30088 - type ahead find, fix support of nsITypeAheadFind. Fix for showing link URL in status line in this checkin, but ifdef'd out for now

This commit is contained in:
aaronl%netscape.com 2002-07-29 05:59:32 +00:00
parent ed80044910
commit f7fbe2b3e5
12 changed files with 61 additions and 28 deletions

View File

@ -1 +1,2 @@
Makefile

View File

@ -96,3 +96,4 @@ xpi::
bin/components/typeaheadfind.xpt \
bin/chrome/typeaheadfind.jar \
bin/defaults/pref/typeaheadfind.js )

View File

@ -58,3 +58,4 @@ if (getLastError() == SUCCESS) {
} else {
cancelInstall(err);
}

View File

@ -1,3 +1,4 @@
typeaheadfind.jar:
locale/en-US/typeaheadfind/contents.rdf (resources/locale/en-US/contents.rdf)
locale/en-US/typeaheadfind/typeaheadfind.properties (resources/locale/en-US/typeaheadfind.properties)

View File

@ -82,4 +82,3 @@ include <$(DEPTH)\config\rules.mak>
libs::
$(MAKE_INSTALL) resources\content\prefs\typeaheadfind.js $(DIST)\bin\defaults\pref

View File

@ -68,3 +68,4 @@ interface nsITypeAheadFind : nsISupports

View File

@ -96,6 +96,7 @@ PRBool nsTypeAheadFind::gIsFindingText = PR_FALSE;
NS_INTERFACE_MAP_BEGIN(nsTypeAheadFind)
NS_INTERFACE_MAP_ENTRY(nsITypeAheadFind)
NS_INTERFACE_MAP_ENTRY(nsIDOMFocusListener)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
@ -375,10 +376,15 @@ NS_IMETHODIMP nsTypeAheadFind::Focus(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMEventTarget> domEventTarget;
aEvent->GetTarget(getter_AddRefs(domEventTarget));
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(domEventTarget));
return HandleFocusInternal(domEventTarget);
}
nsresult nsTypeAheadFind::HandleFocusInternal(nsIDOMEventTarget *aDOMEventTarget)
{
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(aDOMEventTarget));
if (!domNode)
return NS_OK; // prevents listener callbacks from resetting us during typeahead find processing
if (!gIsFindingText)
return NS_OK;
if (!gIsFindingText) // prevents listener callbacks from resetting us during typeahead find processing
CancelFind();
nsCOMPtr<nsIDOMDocument> domDoc;
@ -395,7 +401,7 @@ NS_IMETHODIMP nsTypeAheadFind::Focus(nsIDOMEvent* aEvent)
nsCOMPtr<nsIDOMWindow> domWin(do_QueryInterface(ourGlobal));
nsCOMPtr<nsIDOMEventTarget> rootTarget(do_QueryInterface(domWin));
if (!rootTarget || (domWin == mFocusedWindow && docTarget != domEventTarget))
if (!rootTarget || (domWin == mFocusedWindow && docTarget != aDOMEventTarget))
return NS_OK; // Return early for elements focused within currently focused document
// Focus event in a new doc -- trigger keypress event listening
@ -516,7 +522,6 @@ NS_IMETHODIMP nsTypeAheadFind::KeyPress(nsIDOMEvent* aEvent)
(nsTypeAheadFind::gAccelKey == nsIDOMKeyEvent::DOM_VK_ALT && isAlt ) ||
(nsTypeAheadFind::gAccelKey == nsIDOMKeyEvent::DOM_VK_META && isMeta))) {
// We steal Accel+G (find next) and Accel+Shift+G (find prev), avoid early return
aEvent->PreventDefault(); // If back space is normally used for a command, don't do it
if (mRepeatingMode == eRepeatingChar)
mTypeAheadBuffer = mTypeAheadBuffer.First();
mRepeatingMode = (charCode=='G')? eRepeatingReverse: eRepeatingForward;
@ -571,7 +576,6 @@ NS_IMETHODIMP nsTypeAheadFind::KeyPress(nsIDOMEvent* aEvent)
else if (keyCode == nsIDOMKeyEvent::DOM_VK_BACK_SPACE) {
if (mTypeAheadBuffer.IsEmpty())
return NS_OK;
aEvent->PreventDefault(); // If back space is normally used for a command, don't do it
if (mTypeAheadBuffer.Length() == 1) {
if (mStartFindRange) {
mFocusedDocSelection->RemoveAllRanges();
@ -640,6 +644,9 @@ NS_IMETHODIMP nsTypeAheadFind::KeyPress(nsIDOMEvent* aEvent)
}
#endif
aEvent->PreventDefault(); // Prevent normal processing of this keystroke
aEvent->StopPropagation();
// ------- If accessibility.typeaheadfind.timeout is set, cancel find after specified # milliseconds
if (mTimeoutLength) {
if (!mTimer)
@ -653,7 +660,6 @@ NS_IMETHODIMP nsTypeAheadFind::KeyPress(nsIDOMEvent* aEvent)
if (NS_SUCCEEDED(rv)) {
// ------- Success!!! ---------------------------------------------------------------------------------
mKeepSelectionOnCancel = !isLinksOnly; // Next time CancelFind() is called, selection will be collapsed
DisplayStatus(PR_TRUE, PR_FALSE); // display success status
// ------- Store current find string for regular find usage: find-next or find dialog text field ------
@ -668,7 +674,7 @@ NS_IMETHODIMP nsTypeAheadFind::KeyPress(nsIDOMEvent* aEvent)
else {
// ----- Nothing found -----
nsCOMPtr<nsISound> soundInterface(do_CreateInstance("@mozilla.org/sound;1"));
DisplayStatus(PR_FALSE, PR_FALSE); // Display failure status
DisplayStatus(PR_FALSE, nsnull, PR_FALSE); // Display failure status
if (soundInterface)
soundInterface->Beep();
// Remove bad character from buffer, so we can continue typing from last matched character
@ -796,10 +802,13 @@ nsresult nsTypeAheadFind::FindItNow(PRBool aIsRepeatingSameChar, PRBool aIsLinks
nsISelectionController::SELECTION_FOCUS_REGION, PR_TRUE);
nsCOMPtr<nsIEventStateManager> esm;
presContext->GetEventStateManager(getter_AddRefs(esm));
nsCOMPtr<nsIContent> focusedContent;
if (esm) {
PRBool isSelectionWithFocus;
esm->MoveFocusToCaret(PR_TRUE, &isSelectionWithFocus);
esm->GetFocusedContent(getter_AddRefs(focusedContent));
}
DisplayStatus(PR_TRUE, focusedContent, PR_FALSE);
return NS_OK;
}
// ================= end-inner-while: go through a single document ==================
@ -1066,9 +1075,6 @@ NS_IMETHODIMP nsTypeAheadFind::StartNewFind(nsIDOMWindow *aWindow, PRBool aLinks
if (!windowInternal)
return NS_ERROR_FAILURE;
CancelFind(); // Reset. Clears out type ahead find in manual find windows completely
mLinksOnly = aLinksOnly;
nsCOMPtr<nsIDOMEventTarget> eventTarget(do_QueryInterface(aWindow));
if (!eventTarget)
return NS_ERROR_FAILURE;
@ -1076,8 +1082,16 @@ NS_IMETHODIMP nsTypeAheadFind::StartNewFind(nsIDOMWindow *aWindow, PRBool aLinks
RemoveCurrentWindowFocusListener();
AttachNewWindowFocusListener(eventTarget);
windowInternal->Focus(); // This should get chain of events started for auto find.
windowInternal->Focus();
if (mFocusedWindow != aWindow) {
nsCOMPtr<nsIDOMDocument> domDoc;
aWindow->GetDocument(getter_AddRefs(domDoc));
eventTarget = do_QueryInterface(domDoc);
if (eventTarget)
HandleFocusInternal(eventTarget); // This routine will set up the keypress listener
}
mLinksOnly = aLinksOnly;
return NS_OK;
}
@ -1118,7 +1132,7 @@ NS_IMETHODIMP nsTypeAheadFind::CancelFind()
if (!mTypeAheadBuffer.IsEmpty()) {
mTypeAheadBuffer.Truncate();
DisplayStatus(PR_FALSE, PR_TRUE); // Clear status
DisplayStatus(PR_FALSE, nsnull, PR_TRUE); // Clear status
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mFocusedWeakShell));
if (!mKeepSelectionOnCancel && presShell)
mFocusedDocSelection->CollapseToStart();
@ -1200,13 +1214,13 @@ void nsTypeAheadFind::RemoveCurrentKeypressListener()
{
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(mFocusedWindow));
if (target)
target->RemoveEventListener(NS_LITERAL_STRING("keypress"), NS_STATIC_CAST(nsIDOMKeyListener*, this), PR_FALSE);
target->RemoveEventListener(NS_LITERAL_STRING("keypress"), NS_STATIC_CAST(nsIDOMKeyListener*, this), PR_TRUE);
}
void nsTypeAheadFind::AttachNewKeypressListener(nsIDOMEventTarget *aTarget)
{
aTarget->AddEventListener(NS_LITERAL_STRING("keypress"), NS_STATIC_CAST(nsIDOMKeyListener*, this), PR_FALSE);
aTarget->AddEventListener(NS_LITERAL_STRING("keypress"), NS_STATIC_CAST(nsIDOMKeyListener*, this), PR_TRUE);
}
@ -1358,11 +1372,8 @@ nsresult nsTypeAheadFind::GetTranslatedString(const nsAString& aKey, nsAString&
}
void nsTypeAheadFind::DisplayStatus(PRBool aSuccess, PRBool aClearStatus)
void nsTypeAheadFind::DisplayStatus(PRBool aSuccess, nsIContent *aFocusedContent, PRBool aClearStatus)
{
// Cache mBrowserChrome, used for showing status messages
// XXX Change nsIPresShell:DoCopyLinkLocation to return a string so that
// we can include target URL in status message
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mFocusedWeakShell));
if (!presShell)
return;
@ -1390,11 +1401,24 @@ void nsTypeAheadFind::DisplayStatus(PRBool aSuccess, PRBool aClearStatus)
else {
if (NS_SUCCEEDED(GetTranslatedString(mLinksOnly? (aSuccess? NS_LITERAL_STRING("linkfound"): NS_LITERAL_STRING("linknotfound")):
(aSuccess? NS_LITERAL_STRING("textfound"): NS_LITERAL_STRING("textnotfound")), statusString))) {
nsAutoString closeQuoteString;
nsAutoString closeQuoteString, urlString;
GetTranslatedString(NS_LITERAL_STRING("closequote"), closeQuoteString);
statusString += mTypeAheadBuffer + closeQuoteString;
#ifdef ADD_TYPEAHEADFIND_URL_TO_STATUS
nsCOMPtr<nsIDOMNode> focusedNode(do_QueryInterface(aFocusedContent));
if (focusedNode)
presShell->GetLinkLocation(focusedNode, urlString);
if (! urlString.IsEmpty()) { // Add URL in parenthesis
nsAutoString openParenString, closeParenString;
GetTranslatedString(NS_LITERAL_STRING("openparen"), openParenString);
GetTranslatedString(NS_LITERAL_STRING("closeparen"), closeParenString);
statusString += NS_LITERAL_STRING(" ") + openParenString + urlString + closeParenString;
}
#endif
}
}
browserChrome->SetStatus(nsIWebBrowserChrome::STATUS_LINK, PromiseFlatString(statusString).get());
}

View File

@ -66,7 +66,8 @@
enum { eRepeatingNone, eRepeatingChar, eRepeatingForward, eRepeatingReverse};
class nsTypeAheadFind : public nsIDOMFocusListener,
class nsTypeAheadFind : public nsITypeAheadFind,
public nsIDOMFocusListener,
public nsIDOMKeyListener,
public nsIDOMLoadListener,
public nsIWebProgressListener,
@ -120,6 +121,7 @@ protected:
static int PR_CALLBACK TypeAheadFindPrefsReset(const char* aPrefName, void* instance_data);
// Helper methods
nsresult nsTypeAheadFind::HandleFocusInternal(nsIDOMEventTarget *aDOMEventTarget);
void AttachNewSelectionListener();
void RemoveCurrentSelectionListener();
void AttachNewScrollPositionListener(nsIPresShell *aPresShell);
@ -140,7 +142,7 @@ protected:
PRBool aIsFirstVisiblePreferred, PRBool aCanUseDocSelection,
nsIPresShell **aPresShell, nsIPresContext **aPresContext,
nsIDOMRange **aSearchRange, nsIDOMRange **aStartRange, nsIDOMRange **aEndRange);
void DisplayStatus(PRBool aSuccess, PRBool aClearStatus);
void DisplayStatus(PRBool aSuccess, nsIContent *aFocusedContent, PRBool aClearStatus);
nsresult GetTranslatedString(const nsAString& aKey, nsAString& aStringOut);
// Used by GetInstance and ReleaseInstance
@ -184,3 +186,5 @@ protected:
nsCOMPtr<nsISupportsArray> mManualFindWindows; // List of windows where automatic typeahead find is disabled
};

View File

@ -91,7 +91,3 @@ static const nsModuleComponentInfo components[] =
};
NS_IMPL_NSGETMODULE_WITH_DTOR(nsTypeAheadFind, components, TypeAheadFindModuleDtor)

View File

@ -39,3 +39,4 @@
pref("accessibility.typeaheadfind", true);
pref("accessibility.typeaheadfind.linksonly", true);
pref("accessibility.typeaheadfind.timeout", 2500);

View File

@ -19,3 +19,4 @@
chrome:localeVersion="1.0.0"/>
</RDF:RDF>

View File

@ -1,6 +1,9 @@
openparen = (
closeparen = )
textfound = Text found: "
textnotfound = Text not found: "
linkfound = Link found: "
linknotfound = Link not found: "
closequote = "
stopfind = Type ahead find stopped.