Not part of build. Bug 30088 - type ahead find, fixes based on comments from r=Akkana

git-svn-id: svn://10.0.0.236/trunk@126411 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
aaronl%netscape.com
2002-08-06 02:06:19 +00:00
parent 9841a537e9
commit 4ea74c2be9
10 changed files with 57 additions and 60 deletions

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

@@ -148,7 +148,10 @@ nsTypeAheadFind::nsTypeAheadFind():
return;
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
if (!prefs)
mSearchRange = do_CreateInstance(kRangeCID);
mStartPointRange = do_CreateInstance(kRangeCID);
mEndPointRange = do_CreateInstance(kRangeCID);
if (!prefs || !mSearchRange || !mStartPointRange || !mEndPointRange)
return;
mFind = do_CreateInstance(NS_FIND_CONTRACTID);
@@ -745,14 +748,18 @@ NS_IMETHODIMP nsTypeAheadFind::KeyPress(nsIDOMEvent* aEvent)
// If first character is bad, flush it away anyway
if (mTypeAheadBuffer.Length == 1)
#endif
mTypeAheadBuffer = Substring(mTypeAheadBuffer, 0, mTypeAheadBuffer.Length() - 1);
mTypeAheadBuffer = Substring(mTypeAheadBuffer, 0,
mTypeAheadBuffer.Length() - 1);
}
return NS_OK;
}
nsresult nsTypeAheadFind::FindItNow(PRBool aIsRepeatingSameChar, PRBool aIsLinksOnly, PRBool aIsFirstVisiblePreferred, PRBool aIsBackspace)
nsresult nsTypeAheadFind::FindItNow(PRBool aIsRepeatingSameChar,
PRBool aIsLinksOnly,
PRBool aIsFirstVisiblePreferred,
PRBool aIsBackspace)
{
nsCOMPtr<nsIPresShell> presShell;
nsCOMPtr<nsIPresShell> startingPresShell(do_QueryReferent(mFocusedWeakShell));
@@ -815,20 +822,17 @@ nsresult nsTypeAheadFind::FindItNow(PRBool aIsRepeatingSameChar, PRBool aIsLinks
if (NS_FAILED(GetSearchContainers(currentContainer, aIsRepeatingSameChar,
aIsFirstVisiblePreferred, PR_TRUE,
getter_AddRefs(presShell),
getter_AddRefs(presContext),
getter_AddRefs(searchRange),
getter_AddRefs(startPointRange),
getter_AddRefs(endPointRange))))
getter_AddRefs(presContext))))
return NS_ERROR_FAILURE;
if (aIsBackspace && mStartFindRange && startingDocShell == currentDocShell) {
// when backspace is pressed, start where first char was found
mStartFindRange->CloneRange(getter_AddRefs(startPointRange));
mStartFindRange->CloneRange(getter_AddRefs(mStartPointRange));
}
PRInt32 rangeCompareResult = 0;
startPointRange->CompareBoundaryPoints(nsIDOMRange::START_TO_START ,
searchRange, &rangeCompareResult);
mStartPointRange->CompareBoundaryPoints(nsIDOMRange::START_TO_START ,
searchRange, &rangeCompareResult);
// No need to wrap find in doc if starting at beginning
PRBool hasWrapped = (rangeCompareResult <= 0);
@@ -839,26 +843,28 @@ nsresult nsTypeAheadFind::FindItNow(PRBool aIsRepeatingSameChar, PRBool aIsLinks
findBuffer = PromiseFlatString(mTypeAheadBuffer);
while (PR_TRUE) { // ----- Outer while loop: go through all docs -----
while (PR_TRUE) { // Inner while loop: go through a single document
mFind->Find(findBuffer.get(), searchRange,
startPointRange, endPointRange, getter_AddRefs(returnRange));
while (PR_TRUE) { // === Inner while loop: go through a single doc ===
mFind->Find(findBuffer.get(), mSearchRange,
mStartPointRange, mEndPointRange, getter_AddRefs(returnRange));
if (!returnRange)
break;
break; // Nothing found in this doc, go to outer loop (try next doc)
// ------- Test resulting found range for success conditions ------
PRBool isInsideLink, isStartingLink;
RangeStartsInsideLink(returnRange, presShell, &isInsideLink,
&isStartingLink);
PRBool isInsideLink = PR_FALSE, isStartingLink = PR_FALSE;
if (aIsLinksOnly) // Don't check if inside link when searching all text
RangeStartsInsideLink(returnRange, presShell, &isInsideLink,
&isStartingLink);
if (!IsRangeVisible(presShell, presContext, returnRange,
aIsFirstVisiblePreferred, getter_AddRefs(startPointRange)) ||
aIsFirstVisiblePreferred,
getter_AddRefs(mStartPointRange)) ||
(aIsRepeatingSameChar && !isStartingLink) ||
(aIsLinksOnly && !isInsideLink) ||
(mStartLinksOnlyPref && aIsLinksOnly && !isStartingLink)) {
// ------ Failure ------
// Start find again from here
returnRange->CloneRange(getter_AddRefs(startPointRange));
returnRange->CloneRange(getter_AddRefs(mStartPointRange));
// Collapse to end
startPointRange->Collapse(mRepeatingMode == eRepeatingReverse);
mStartPointRange->Collapse(mRepeatingMode == eRepeatingReverse);
continue;
}
@@ -896,21 +902,20 @@ nsresult nsTypeAheadFind::FindItNow(PRBool aIsRepeatingSameChar, PRBool aIsLinks
DisplayStatus(PR_TRUE, focusedContent, PR_FALSE);
return NS_OK;
}
// ======= end-inner-while: go through a single document ==========
// ======= end-inner-while (go through a single document) ==========
// ---------- Nothing found yet -------------
// ---------- Nothing found yet, try next document -------------
do {
// ==== Second inner loop - get another while ====
if (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMoreDocShells))
&& hasMoreDocShells) {
docShellEnumerator->GetNext(getter_AddRefs(currentContainer));
NS_ASSERTION(currentContainer, "HasMoreElements lied to us!");
if (NS_FAILED(GetSearchContainers(currentContainer,
aIsRepeatingSameChar,
aIsFirstVisiblePreferred, PR_FALSE,
getter_AddRefs(presShell),
getter_AddRefs(presContext),
getter_AddRefs(searchRange),
getter_AddRefs(startPointRange),
getter_AddRefs(endPointRange))))
getter_AddRefs(presContext))))
return NS_ERROR_FAILURE;
currentDocShell = do_QueryInterface(currentContainer);
if (currentDocShell)
@@ -921,15 +926,15 @@ nsresult nsTypeAheadFind::FindItNow(PRBool aIsRepeatingSameChar, PRBool aIsLinks
nsIDocShell::ENUMERATE_FORWARDS,
getter_AddRefs(docShellEnumerator));
}
while (docShellEnumerator);
while (docShellEnumerator); // ==== end second inner while ===
if (currentDocShell != startingDocShell)
continue; // Try next document
// Finished searching through docshells:
// If aFirstVisiblePreferred == PR_TRUE, we may
// need to go through all docshells twice -
// once to look for visible matches, the second time for any match
// If aFirstVisiblePreferred == PR_TRUE, we may need to go through all
// docshells twice -once to look for visible matches, the second time
// for any match
if (!hasWrapped || aIsFirstVisiblePreferred) {
aIsFirstVisiblePreferred = PR_FALSE;
hasWrapped = PR_TRUE;
@@ -960,14 +965,8 @@ nsresult nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer,
PRBool aIsFirstVisiblePreferred,
PRBool aCanUseDocSelection,
nsIPresShell **aPresShell,
nsIPresContext **aPresContext,
nsIDOMRange **aSearchRange,
nsIDOMRange **aStartPointRange,
nsIDOMRange **aEndPointRange)
nsIPresContext **aPresContext)
{
*aSearchRange = nsnull;
*aStartPointRange = nsnull;
*aEndPointRange = nsnull;
*aPresShell = nsnull;
*aPresContext = nsnull;
@@ -993,13 +992,9 @@ nsresult nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer,
if (NS_FAILED(rootContent->ChildCount(childCount)))
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMRange> searchRange(do_CreateInstance(kRangeCID));
nsCOMPtr<nsIDOMRange> startPointRange(do_CreateInstance(kRangeCID));
nsCOMPtr<nsIDOMRange> endPointRange(do_CreateInstance(kRangeCID));
searchRange->SelectNodeContents(rootNode);
endPointRange->SetStart(rootNode, childCount);
endPointRange->SetEnd(rootNode, childCount);
mSearchRange->SelectNodeContents(rootNode);
mEndPointRange->SetStart(rootNode, childCount);
mEndPointRange->SetEnd(rootNode, childCount);
// Consider current selection as null if
// it's not in the currently focused document
@@ -1010,8 +1005,10 @@ nsresult nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer,
if (!currentSelectionRange || aIsFirstVisiblePreferred) {
// Ensure visible range, move forward if necessary
IsRangeVisible(*aPresShell, *aPresContext, searchRange,
aIsFirstVisiblePreferred, getter_AddRefs(startPointRange));
// This uses ignores the return value, but usese the side effect of
// IsRangeVisible. It returns the first visible range after searchRange
IsRangeVisible(*aPresShell, *aPresContext, mSearchRange,
aIsFirstVisiblePreferred, getter_AddRefs(mStartPointRange));
}
else {
PRInt32 startOffset;
@@ -1026,13 +1023,10 @@ nsresult nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer,
}
if (!startNode)
startNode = rootNode;
startPointRange->SetStart(startNode, startOffset);
startPointRange->Collapse(PR_TRUE); // collapse to start
mStartPointRange->SetStart(startNode, startOffset);
mStartPointRange->Collapse(PR_TRUE); // collapse to start
}
NS_ADDREF(*aSearchRange = searchRange);
NS_ADDREF(*aStartPointRange = startPointRange);
NS_ADDREF(*aEndPointRange = endPointRange);
return NS_OK;
}
@@ -1510,7 +1504,7 @@ PRBool nsTypeAheadFind::IsRangeVisible(nsIPresShell *aPresShell,
if (containingView) {
relFrameRect.x = frameOffset.x;
relFrameRect.y = frameOffset.y;
viewManager->IsRectVisible(containingView, relFrameRect
viewManager->IsRectVisible(containingView, relFrameRect,
NS_STATIC_CAST(PRUint16, (kMinPixels * p2t)),
&isFirstVisible, &isBelowViewPort);
}
@@ -1591,6 +1585,6 @@ void nsTypeAheadFind::DisplayStatus(PRBool aSuccess,
}
}
browserChrome->SetStatus(nsIWebBrowserChrome::STATUS_LINK,
PromiseFlatString(statusString).get());
PromiseFlatString(statusString).get());
}

View File

@@ -152,10 +152,7 @@ protected:
PRBool aIsFirstVisiblePreferred,
PRBool aCanUseDocSelection,
nsIPresShell **aPresShell,
nsIPresContext **aPresContext,
nsIDOMRange **aSearchRange,
nsIDOMRange **aStartRange,
nsIDOMRange **aEndRange);
nsIPresContext **aPresContext);
void DisplayStatus(PRBool aSuccess, nsIContent *aFocusedContent,
PRBool aClearStatus);
nsresult GetTranslatedString(const nsAString& aKey, nsAString& aStringOut);
@@ -183,6 +180,9 @@ protected:
// where selection was when user started the find
nsCOMPtr<nsIDOMRange> mStartFindRange;
nsCOMPtr<nsIDOMRange> mSearchRange;
nsCOMPtr<nsIDOMRange> mStartPointRange;
nsCOMPtr<nsIDOMRange> mEndPointRange;
// Cached useful interfaces
nsCOMPtr<nsIFind> mFind;

View File

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

View File

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

View File

@@ -18,3 +18,4 @@
<RDF:Description about="urn:mozilla:locale:en-US:typeaheadfind"
chrome:localeVersion="1.0.0"/>
</RDF:RDF>

View File

@@ -6,3 +6,4 @@ linkfound = Link found: "
linknotfound = Link not found: "
closequote = "
stopfind = Type ahead find stopped.