Bug 621944, find and replace doesn't wrap in mail compose, use the correct focused frame, r=neil

This commit is contained in:
Neil Deakin 2012-10-18 09:18:30 -04:00
parent 55fc941933
commit adc5037779
2 changed files with 14 additions and 31 deletions

View File

@ -11362,26 +11362,14 @@ NS_IMETHODIMP nsDocShell::EnsureFind()
NS_ENSURE_TRUE(scriptGO, NS_ERROR_UNEXPECTED);
// default to our window
nsCOMPtr<nsIDOMWindow> windowToSearch(do_QueryInterface(mScriptGlobal));
nsCOMPtr<nsIDocShellTreeItem> root;
GetRootTreeItem(getter_AddRefs(root));
// if the active window is the same window that this docshell is in,
// use the currently focused frame
nsCOMPtr<nsIDOMWindow> rootWindow = do_GetInterface(root);
nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
if (fm) {
nsCOMPtr<nsIDOMWindow> activeWindow;
fm->GetActiveWindow(getter_AddRefs(activeWindow));
if (activeWindow == rootWindow)
fm->GetFocusedWindow(getter_AddRefs(windowToSearch));
}
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(scriptGO);
nsCOMPtr<nsPIDOMWindow> windowToSearch;
nsFocusManager::GetFocusedDescendant(ourWindow, true, getter_AddRefs(windowToSearch));
nsCOMPtr<nsIWebBrowserFindInFrames> findInFrames = do_QueryInterface(mFind);
if (!findInFrames) return NS_ERROR_NO_INTERFACE;
rv = findInFrames->SetRootSearchFrame(rootWindow);
rv = findInFrames->SetRootSearchFrame(ourWindow);
if (NS_FAILED(rv)) return rv;
rv = findInFrames->SetCurrentSearchFrame(windowToSearch);
if (NS_FAILED(rv)) return rv;

View File

@ -206,6 +206,9 @@ NS_IMETHODIMP nsWebBrowserFind::FindNext(bool *outDidFind)
curItem = do_QueryInterface(curSupports, &rv);
if (NS_FAILED(rv)) break;
searchFrame = do_GetInterface(curItem, &rv);
if (NS_FAILED(rv)) break;
if (curItem.get() == startingItem.get())
{
// Beware! This may flush notifications via synchronous
@ -217,9 +220,6 @@ NS_IMETHODIMP nsWebBrowserFind::FindNext(bool *outDidFind)
break;
}
searchFrame = do_GetInterface(curItem, &rv);
if (NS_FAILED(rv)) break;
OnStartSearchFrame(searchFrame);
// Beware! This may flush notifications via synchronous
@ -801,18 +801,13 @@ nsWebBrowserFind::GetFrameSelection(nsIDOMWindow* aWindow,
// that we must use when they have focus.
nsPresContext *presContext = presShell->GetPresContext();
nsIFrame *frame = nullptr;
nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
if (fm) {
nsCOMPtr<nsIDOMElement> focusedElement;
fm->GetFocusedElement(getter_AddRefs(focusedElement));
nsCOMPtr<nsIContent> focusedContent(do_QueryInterface(focusedElement));
if (focusedContent) {
frame = focusedContent->GetPrimaryFrame();
if (frame && frame->PresContext() != presContext)
frame = nullptr;
}
}
nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(aWindow));
nsCOMPtr<nsPIDOMWindow> focusedWindow;
nsCOMPtr<nsIContent> focusedContent =
nsFocusManager::GetFocusedDescendant(window, false, getter_AddRefs(focusedWindow));
nsIFrame *frame = focusedContent ? focusedContent->GetPrimaryFrame() : nullptr;
nsCOMPtr<nsISelectionController> selCon;
if (frame) {