From 3fa85fd10e85e19fd031c012dedc2eaedbd4ce77 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Fri, 15 Aug 2014 22:47:46 +1200 Subject: [PATCH] Bug 263049. Hack nsTypeAheadFind to search XMLPrettyPrinter's pretty-printed DOM when the root node has an XBL binding. r=mrbkap --HG-- extra : rebase_source : 33bfe389b08dfb76964eb986f13ee7b93a2f0f54 --- .../typeaheadfind/nsTypeAheadFind.cpp | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp index 359c5a3cc94d..459d4810dbd7 100644 --- a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp +++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp @@ -51,6 +51,7 @@ #include "mozilla/dom/Element.h" #include "mozilla/dom/Link.h" #include "nsRange.h" +#include "nsXBLBinding.h" #include "nsTypeAheadFind.h" @@ -746,19 +747,36 @@ nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer, if (!rootNode) return NS_ERROR_FAILURE; - uint32_t childCount = rootContent->GetChildCount(); - if (!mSearchRange) { - mSearchRange = new nsRange(rootContent); + mSearchRange = new nsRange(doc); } + nsCOMPtr searchRootNode = rootNode; + + // Hack for XMLPrettyPrinter. nsFind can't handle complex anonymous content. + // If the root node has an XBL binding then there's not much we can do in + // in general, but we can try searching the binding's first child, which + // in the case of XMLPrettyPrinter contains the visible pretty-printed + // content. + nsXBLBinding* binding = rootContent->GetXBLBinding(); + if (binding) { + nsIContent* child = binding->GetAnonymousContent()->GetFirstChild(); + if (child) { + searchRootNode = do_QueryInterface(child); + } + } + mSearchRange->SelectNodeContents(searchRootNode); + + if (!mStartPointRange) { + mStartPointRange = new nsRange(doc); + } + mStartPointRange->SetStart(searchRootNode, 0); + mStartPointRange->Collapse(true); // collapse to start if (!mEndPointRange) { - mEndPointRange = new nsRange(rootContent); + mEndPointRange = new nsRange(doc); } - - mSearchRange->SelectNodeContents(rootNode); - - mEndPointRange->SetEnd(rootNode, childCount); + nsCOMPtr searchRootTmp = do_QueryInterface(searchRootNode); + mEndPointRange->SetEnd(searchRootNode, searchRootTmp->Length()); mEndPointRange->Collapse(false); // collapse to end // Consider current selection as null if @@ -773,10 +791,6 @@ nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer, selection->GetRangeAt(0, getter_AddRefs(currentSelectionRange)); } - if (!mStartPointRange) { - mStartPointRange = new nsRange(doc); - } - if (!currentSelectionRange) { // Ensure visible range, move forward if necessary // This uses ignores the return value, but usese the side effect of