From 4ea74c2be94ffe99d577e63c1b5d1bdd878b24be Mon Sep 17 00:00:00 2001 From: "aaronl%netscape.com" Date: Tue, 6 Aug 2002 02:06:19 +0000 Subject: [PATCH] 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 --- mozilla/extensions/typeaheadfind/Makefile.in | 1 + mozilla/extensions/typeaheadfind/install.js | 1 + mozilla/extensions/typeaheadfind/jar.mn | 1 + mozilla/extensions/typeaheadfind/makefile.win | 1 - .../typeaheadfind/nsTypeAheadFind.cpp | 100 ++++++++---------- .../typeaheadfind/nsTypeAheadFind.h | 8 +- .../nsTypeAheadFindRegistration.cpp | 1 - .../resources/content/prefs/typeaheadfind.js | 2 +- .../resources/locale/en-US/contents.rdf | 1 + .../locale/en-US/typeaheadfind.properties | 1 + 10 files changed, 57 insertions(+), 60 deletions(-) diff --git a/mozilla/extensions/typeaheadfind/Makefile.in b/mozilla/extensions/typeaheadfind/Makefile.in index 6bc59a1ee9d..b56b88f095f 100644 --- a/mozilla/extensions/typeaheadfind/Makefile.in +++ b/mozilla/extensions/typeaheadfind/Makefile.in @@ -96,3 +96,4 @@ xpi:: bin/components/typeaheadfind.xpt \ bin/chrome/typeaheadfind.jar \ bin/defaults/pref/typeaheadfind.js ) + diff --git a/mozilla/extensions/typeaheadfind/install.js b/mozilla/extensions/typeaheadfind/install.js index 00963b45bb6..b6f30ad8dbf 100644 --- a/mozilla/extensions/typeaheadfind/install.js +++ b/mozilla/extensions/typeaheadfind/install.js @@ -58,3 +58,4 @@ if (getLastError() == SUCCESS) { } else { cancelInstall(err); } + diff --git a/mozilla/extensions/typeaheadfind/jar.mn b/mozilla/extensions/typeaheadfind/jar.mn index ce563e84d16..7db42e98914 100644 --- a/mozilla/extensions/typeaheadfind/jar.mn +++ b/mozilla/extensions/typeaheadfind/jar.mn @@ -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) + diff --git a/mozilla/extensions/typeaheadfind/makefile.win b/mozilla/extensions/typeaheadfind/makefile.win index 5f5936194ad..dd846c30f4f 100644 --- a/mozilla/extensions/typeaheadfind/makefile.win +++ b/mozilla/extensions/typeaheadfind/makefile.win @@ -82,4 +82,3 @@ include <$(DEPTH)\config\rules.mak> libs:: $(MAKE_INSTALL) resources\content\prefs\typeaheadfind.js $(DIST)\bin\defaults\pref - diff --git a/mozilla/extensions/typeaheadfind/nsTypeAheadFind.cpp b/mozilla/extensions/typeaheadfind/nsTypeAheadFind.cpp index c3d9cfc1ae6..65834b4829c 100644 --- a/mozilla/extensions/typeaheadfind/nsTypeAheadFind.cpp +++ b/mozilla/extensions/typeaheadfind/nsTypeAheadFind.cpp @@ -148,7 +148,10 @@ nsTypeAheadFind::nsTypeAheadFind(): return; nsCOMPtr 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 presShell; nsCOMPtr 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 searchRange(do_CreateInstance(kRangeCID)); - nsCOMPtr startPointRange(do_CreateInstance(kRangeCID)); - nsCOMPtr 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()); } diff --git a/mozilla/extensions/typeaheadfind/nsTypeAheadFind.h b/mozilla/extensions/typeaheadfind/nsTypeAheadFind.h index efee1dbf44f..ba74d4571fe 100644 --- a/mozilla/extensions/typeaheadfind/nsTypeAheadFind.h +++ b/mozilla/extensions/typeaheadfind/nsTypeAheadFind.h @@ -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 mStartFindRange; + nsCOMPtr mSearchRange; + nsCOMPtr mStartPointRange; + nsCOMPtr mEndPointRange; // Cached useful interfaces nsCOMPtr mFind; diff --git a/mozilla/extensions/typeaheadfind/nsTypeAheadFindRegistration.cpp b/mozilla/extensions/typeaheadfind/nsTypeAheadFindRegistration.cpp index fc4ce0045a1..1f1f8691f50 100644 --- a/mozilla/extensions/typeaheadfind/nsTypeAheadFindRegistration.cpp +++ b/mozilla/extensions/typeaheadfind/nsTypeAheadFindRegistration.cpp @@ -91,4 +91,3 @@ static const nsModuleComponentInfo components[] = }; NS_IMPL_NSGETMODULE_WITH_DTOR(nsTypeAheadFind, components, TypeAheadFindModuleDtor) - diff --git a/mozilla/extensions/typeaheadfind/resources/content/prefs/typeaheadfind.js b/mozilla/extensions/typeaheadfind/resources/content/prefs/typeaheadfind.js index 57e08ddd492..755d326dd57 100644 --- a/mozilla/extensions/typeaheadfind/resources/content/prefs/typeaheadfind.js +++ b/mozilla/extensions/typeaheadfind/resources/content/prefs/typeaheadfind.js @@ -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); diff --git a/mozilla/extensions/typeaheadfind/resources/locale/en-US/contents.rdf b/mozilla/extensions/typeaheadfind/resources/locale/en-US/contents.rdf index b8c75d620de..ad5ce3f72cd 100644 --- a/mozilla/extensions/typeaheadfind/resources/locale/en-US/contents.rdf +++ b/mozilla/extensions/typeaheadfind/resources/locale/en-US/contents.rdf @@ -18,3 +18,4 @@ + diff --git a/mozilla/extensions/typeaheadfind/resources/locale/en-US/typeaheadfind.properties b/mozilla/extensions/typeaheadfind/resources/locale/en-US/typeaheadfind.properties index 358dc985292..38bcf3326b3 100644 --- a/mozilla/extensions/typeaheadfind/resources/locale/en-US/typeaheadfind.properties +++ b/mozilla/extensions/typeaheadfind/resources/locale/en-US/typeaheadfind.properties @@ -6,3 +6,4 @@ linkfound = Link found: " linknotfound = Link not found: " closequote = " stopfind = Type ahead find stopped. +