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

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

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

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

@ -115,6 +115,8 @@ private:
// no copy's or assigns
nsRange(const nsRange&);
nsRange& operator=(const nsRange&);
nsINode* IsValidBoundary(nsINode* aNode);
public:
/******************************************************************************

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

@ -1,5 +1,4 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil;
c-basic-offset: 2 -*- */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -65,6 +64,7 @@ c-basic-offset: 2 -*- */
#include "nsIDOMElement.h"
#include "nsIWordBreaker.h"
#include "nsCRT.h"
#include "nsIRange.h"
// Yikes! Casting a char to unichar can fill with ones!
#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
// reset the outer one in the process.
nsCOMPtr<nsIDOMRange> range (do_CreateInstance(kRangeCID));
nsCOMPtr<nsIDOMRange> range = nsFind::CreateRange();
range->SetStart(mStartNode, mStartOffset);
range->SetEnd(mEndNode, mEndOffset);
mOuterIterator->Init(range);
@ -400,8 +400,8 @@ nsFindContentIterator::SetupInnerIterator(nsIContent* aContent)
editor->GetRootElement(getter_AddRefs(rootElement));
nsCOMPtr<nsIContent> rootContent(do_QueryInterface(rootElement));
nsCOMPtr<nsIDOMRange> innerRange(do_CreateInstance(kRangeCID));
nsCOMPtr<nsIDOMRange> outerRange(do_CreateInstance(kRangeCID));
nsCOMPtr<nsIDOMRange> innerRange = nsFind::CreateRange();
nsCOMPtr<nsIDOMRange> outerRange = nsFind::CreateRange();
if (!innerRange || !outerRange) {
return;
}
@ -1210,7 +1210,7 @@ nsFind::Find(const PRUnichar *aPatText, nsIDOMRange* aSearchRange,
// Make the range:
nsCOMPtr<nsIDOMNode> startParent;
nsCOMPtr<nsIDOMNode> endParent;
nsCOMPtr<nsIDOMRange> range (do_CreateInstance(kRangeCID));
nsCOMPtr<nsIDOMRange> range = CreateRange();
if (range)
{
PRInt32 matchStartOffset, matchEndOffset;
@ -1327,4 +1327,18 @@ nsFind::Find(const PRUnichar *aPatText, nsIDOMRange* aSearchRange,
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();
virtual ~nsFind();
static already_AddRefed<nsIDOMRange> CreateRange();
protected:
static PRInt32 sInstanceCount;

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

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