Make the ranges used by find code able to span anonymous content. Bug 384706,

r+sr=sicking
This commit is contained in:
bzbarsky@mit.edu 2007-06-18 20:01:03 -07:00
Родитель c6fd1128cc
Коммит 2d74f9107f
6 изменённых файлов: 47 добавлений и 22 удалений

Просмотреть файл

@ -56,7 +56,8 @@ public:
mStartOffset(0), mStartOffset(0),
mEndOffset(0), mEndOffset(0),
mIsPositioned(PR_FALSE), mIsPositioned(PR_FALSE),
mIsDetached(PR_FALSE) mIsDetached(PR_FALSE),
mMaySpanAnonymousSubtrees(PR_FALSE)
{ {
} }
@ -101,6 +102,11 @@ public:
mStartOffset == mEndOffset; mStartOffset == mEndOffset;
} }
void SetMaySpanAnonymousSubtrees(PRBool aMaySpanAnonymousSubtrees)
{
mMaySpanAnonymousSubtrees = aMaySpanAnonymousSubtrees;
}
virtual nsINode* GetCommonAncestor() = 0; virtual nsINode* GetCommonAncestor() = 0;
virtual void Reset() = 0; virtual void Reset() = 0;
@ -114,6 +120,7 @@ protected:
PRPackedBool mIsPositioned; PRPackedBool mIsPositioned;
PRPackedBool mIsDetached; PRPackedBool mIsDetached;
PRPackedBool mMaySpanAnonymousSubtrees;
}; };
NS_DEFINE_STATIC_IID_ACCESSOR(nsIRange, NS_IRANGE_IID) NS_DEFINE_STATIC_IID_ACCESSOR(nsIRange, NS_IRANGE_IID)

Просмотреть файл

@ -388,8 +388,6 @@ nsRange::ComparePoint(nsIDOMNode* aParent, PRInt32 aOffset, PRInt16* aResult)
* Private helper routines * Private helper routines
******************************************************/ ******************************************************/
static nsINode* IsValidBoundary(nsINode* aNode);
// Get the length of aNode // Get the length of aNode
static PRInt32 GetNodeLength(nsINode *aNode) static PRInt32 GetNodeLength(nsINode *aNode)
{ {
@ -551,8 +549,7 @@ nsresult nsRange::GetCommonAncestorContainer(nsIDOMNode** aCommonParent)
return NS_ERROR_NOT_INITIALIZED; return NS_ERROR_NOT_INITIALIZED;
} }
static nsINode* nsINode* nsRange::IsValidBoundary(nsINode* aNode)
IsValidBoundary(nsINode* aNode)
{ {
if (!aNode) { if (!aNode) {
return nsnull; return nsnull;
@ -564,11 +561,13 @@ IsValidBoundary(nsINode* aNode)
return nsnull; return nsnull;
} }
// If the node has a binding parent, that should be the root. if (!mMaySpanAnonymousSubtrees) {
// XXXbz maybe only for native anonymous content? // If the node has a binding parent, that should be the root.
nsINode* root = content->GetBindingParent(); // XXXbz maybe only for native anonymous content?
if (root) { nsINode* root = content->GetBindingParent();
return root; if (root) {
return root;
}
} }
} }
@ -1546,6 +1545,8 @@ nsresult nsRange::CloneRange(nsIDOMRange** aReturn)
NS_ADDREF(*aReturn = range); NS_ADDREF(*aReturn = range);
range->SetMaySpanAnonymousSubtrees(mMaySpanAnonymousSubtrees);
range->DoSetRange(mStartParent, mStartOffset, mEndParent, mEndOffset, mRoot); range->DoSetRange(mStartParent, mStartOffset, mEndParent, mEndOffset, mRoot);
return NS_OK; return NS_OK;

Просмотреть файл

@ -116,6 +116,8 @@ private:
nsRange(const nsRange&); nsRange(const nsRange&);
nsRange& operator=(const nsRange&); nsRange& operator=(const nsRange&);
nsINode* IsValidBoundary(nsINode* aNode);
public: public:
/****************************************************************************** /******************************************************************************
* Utility routine to detect if a content node starts before a range and/or * Utility routine to detect if a content node starts before a range and/or

Просмотреть файл

@ -1,5 +1,4 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
* *
@ -65,6 +64,7 @@ c-basic-offset: 2 -*- */
#include "nsIDOMElement.h" #include "nsIDOMElement.h"
#include "nsIWordBreaker.h" #include "nsIWordBreaker.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsIRange.h"
// Yikes! Casting a char to unichar can fill with ones! // Yikes! Casting a char to unichar can fill with ones!
#define CHAR_TO_UNICHAR(c) ((PRUnichar)(const unsigned char)c) #define CHAR_TO_UNICHAR(c) ((PRUnichar)(const unsigned char)c)
@ -300,10 +300,10 @@ nsFindContentIterator::Reset()
} }
} }
// Note: OK to just set up the outer iterator here; if our range has an // Note: OK to just set up the outer iterator here; if our range has a native
// anonymous endpoint we'll end up setting up an inner iterator, and // anonymous endpoint we'll end up setting up an inner iterator, and
// reset the outer one in the process. // reset the outer one in the process.
nsCOMPtr<nsIDOMRange> range (do_CreateInstance(kRangeCID)); nsCOMPtr<nsIDOMRange> range = nsFind::CreateRange();
range->SetStart(mStartNode, mStartOffset); range->SetStart(mStartNode, mStartOffset);
range->SetEnd(mEndNode, mEndOffset); range->SetEnd(mEndNode, mEndOffset);
mOuterIterator->Init(range); mOuterIterator->Init(range);
@ -400,8 +400,8 @@ nsFindContentIterator::SetupInnerIterator(nsIContent* aContent)
editor->GetRootElement(getter_AddRefs(rootElement)); editor->GetRootElement(getter_AddRefs(rootElement));
nsCOMPtr<nsIContent> rootContent(do_QueryInterface(rootElement)); nsCOMPtr<nsIContent> rootContent(do_QueryInterface(rootElement));
nsCOMPtr<nsIDOMRange> innerRange(do_CreateInstance(kRangeCID)); nsCOMPtr<nsIDOMRange> innerRange = nsFind::CreateRange();
nsCOMPtr<nsIDOMRange> outerRange(do_CreateInstance(kRangeCID)); nsCOMPtr<nsIDOMRange> outerRange = nsFind::CreateRange();
if (!innerRange || !outerRange) { if (!innerRange || !outerRange) {
return; return;
} }
@ -1210,7 +1210,7 @@ nsFind::Find(const PRUnichar *aPatText, nsIDOMRange* aSearchRange,
// Make the range: // Make the range:
nsCOMPtr<nsIDOMNode> startParent; nsCOMPtr<nsIDOMNode> startParent;
nsCOMPtr<nsIDOMNode> endParent; nsCOMPtr<nsIDOMNode> endParent;
nsCOMPtr<nsIDOMRange> range (do_CreateInstance(kRangeCID)); nsCOMPtr<nsIDOMRange> range = CreateRange();
if (range) if (range)
{ {
PRInt32 matchStartOffset, matchEndOffset; PRInt32 matchStartOffset, matchEndOffset;
@ -1327,4 +1327,18 @@ nsFind::Find(const PRUnichar *aPatText, nsIDOMRange* aSearchRange,
return NS_OK; return NS_OK;
} }
/* static */
already_AddRefed<nsIDOMRange>
nsFind::CreateRange()
{
nsCOMPtr<nsIRange> range = do_CreateInstance(kRangeCID);
if (!range) {
return nsnull;
}
range->SetMaySpanAnonymousSubtrees(PR_TRUE);
nsIDOMRange* result;
CallQueryInterface(range.get(), &result);
return result;
}

Просмотреть файл

@ -67,6 +67,8 @@ public:
nsFind(); nsFind();
virtual ~nsFind(); virtual ~nsFind();
static already_AddRefed<nsIDOMRange> CreateRange();
protected: protected:
static PRInt32 sInstanceCount; static PRInt32 sInstanceCount;

Просмотреть файл

@ -73,6 +73,7 @@
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsISupportsPrimitives.h" #include "nsISupportsPrimitives.h"
#include "nsITimelineService.h" #include "nsITimelineService.h"
#include "nsFind.h"
#if DEBUG #if DEBUG
#include "nsIWebNavigation.h" #include "nsIWebNavigation.h"
@ -85,8 +86,6 @@
#endif #endif
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
//***************************************************************************** //*****************************************************************************
// nsWebBrowserFind // nsWebBrowserFind
//***************************************************************************** //*****************************************************************************
@ -771,11 +770,11 @@ nsresult nsWebBrowserFind::SearchInFrame(nsIDOMWindow* aWindow,
GetFrameSelection(aWindow, getter_AddRefs(sel)); GetFrameSelection(aWindow, getter_AddRefs(sel));
NS_ENSURE_ARG_POINTER(sel); NS_ENSURE_ARG_POINTER(sel);
nsCOMPtr<nsIDOMRange> searchRange (do_CreateInstance(kRangeCID)); nsCOMPtr<nsIDOMRange> searchRange = nsFind::CreateRange();
NS_ENSURE_ARG_POINTER(searchRange); NS_ENSURE_ARG_POINTER(searchRange);
nsCOMPtr<nsIDOMRange> startPt (do_CreateInstance(kRangeCID)); nsCOMPtr<nsIDOMRange> startPt = nsFind::CreateRange();
NS_ENSURE_ARG_POINTER(startPt); NS_ENSURE_ARG_POINTER(startPt);
nsCOMPtr<nsIDOMRange> endPt (do_CreateInstance(kRangeCID)); nsCOMPtr<nsIDOMRange> endPt = nsFind::CreateRange();
NS_ENSURE_ARG_POINTER(endPt); NS_ENSURE_ARG_POINTER(endPt);
nsCOMPtr<nsIDOMRange> foundRange; nsCOMPtr<nsIDOMRange> foundRange;