Bug 404624. Silence assertion failures by allowing PropertyProvider's content length to be PR_INT32_MAX. r=smontagu

This commit is contained in:
roc+@cs.cmu.edu 2007-11-30 11:59:03 -08:00
parent 2dfebb2e83
commit 6d826063d8

View File

@ -1941,6 +1941,8 @@ static PRBool IsInBounds(const gfxSkipCharsIterator& aStart, PRInt32 aContentLen
PRUint32 aOffset, PRUint32 aLength) {
if (aStart.GetSkippedOffset() > aOffset)
return PR_FALSE;
if (aContentLength == PR_INT32_MAX)
return PR_TRUE;
gfxSkipCharsIterator iter(aStart);
iter.AdvanceOriginal(aContentLength);
return iter.GetSkippedOffset() >= aOffset + aLength;
@ -1952,6 +1954,11 @@ public:
/**
* Use this constructor for reflow, when we don't know what text is
* really mapped by the frame and we have a lot of other data around.
*
* @param aLength can be PR_INT32_MAX to indicate we cover all the text
* associated with aFrame up to where its flow chain ends in the given
* textrun. If PR_INT32_MAX is passed, justification and hyphen-related methods
* cannot be called, nor can GetOriginalLength().
*/
PropertyProvider(gfxTextRun* aTextRun, const nsStyleText* aTextStyle,
const nsTextFragment* aFrag, nsTextFrame* aFrame,
@ -2019,7 +2026,11 @@ public:
// adjusted for whitespace trimming according to the state bits set in the frame
// (for the static provider)
const gfxSkipCharsIterator& GetStart() { return mStart; }
PRUint32 GetOriginalLength() { return mLength; }
// May return PR_INT32_MAX if that was given to the constructor
PRUint32 GetOriginalLength() {
NS_ASSERTION(mLength != PR_INT32_MAX, "Length not known");
return mLength;
}
const nsTextFragment* GetFragment() { return mFrag; }
gfxFontGroup* GetFontGroup() {
@ -2045,7 +2056,7 @@ protected:
gfxSkipCharsIterator mStart; // Offset in original and transformed string
gfxSkipCharsIterator mTempIterator;
nsTArray<gfxFloat>* mTabWidths; // widths for each transformed string character
PRInt32 mLength; // DOM string length
PRInt32 mLength; // DOM string length, may be PR_INT32_MAX
gfxFloat mWordSpacing; // space for each whitespace char
gfxFloat mLetterSpacing; // space for each letter
gfxFloat mJustificationSpacing;
@ -2316,6 +2327,7 @@ PropertyProvider::GetHyphenationBreaks(PRUint32 aStart, PRUint32 aLength,
PRPackedBool* aBreakBefore)
{
NS_PRECONDITION(IsInBounds(mStart, mLength, aStart, aLength), "Range out of bounds");
NS_PRECONDITION(mLength != PR_INT32_MAX, "Can't call this with undefined length");
if (!mTextStyle->WhiteSpaceCanWrap()) {
memset(aBreakBefore, PR_FALSE, aLength);
@ -2375,7 +2387,9 @@ void
PropertyProvider::FindJustificationRange(gfxSkipCharsIterator* aStart,
gfxSkipCharsIterator* aEnd)
{
NS_PRECONDITION(mLength != PR_INT32_MAX, "Can't call this with undefined length");
NS_ASSERTION(aStart && aEnd, "aStart or/and aEnd is null");
aStart->SetOriginalOffset(mStart.GetOriginalOffset());
aEnd->SetOriginalOffset(mStart.GetOriginalOffset() + mLength);
@ -2403,6 +2417,8 @@ PropertyProvider::FindJustificationRange(gfxSkipCharsIterator* aStart,
void
PropertyProvider::SetupJustificationSpacing()
{
NS_PRECONDITION(mLength != PR_INT32_MAX, "Can't call this with undefined length");
if (NS_STYLE_TEXT_ALIGN_JUSTIFY != mTextStyle->mTextAlign ||
mTextStyle->WhiteSpaceIsSignificant())
return;
@ -4837,7 +4853,7 @@ nsTextFrame::AddInlineMinWidthForFlow(nsIRenderingContext *aRenderingContext,
// OK since we can't really handle tabs for intrinsic sizing anyway.
const nsTextFragment* frag = mContent->GetText();
PropertyProvider provider(mTextRun, GetStyleText(), frag, this,
iter, GetInFlowContentLength(), nsnull, 0);
iter, PR_INT32_MAX, nsnull, 0);
PRBool collapseWhitespace = !provider.GetStyleText()->WhiteSpaceIsSignificant();
PRUint32 start =
@ -4938,7 +4954,7 @@ nsTextFrame::AddInlinePrefWidthForFlow(nsIRenderingContext *aRenderingContext,
// Pass null for the line container. This will disable tab spacing, but that's
// OK since we can't really handle tabs for intrinsic sizing anyway.
PropertyProvider provider(mTextRun, GetStyleText(), mContent->GetText(), this,
iter, GetInFlowContentLength(), nsnull, 0);
iter, PR_INT32_MAX, nsnull, 0);
PRBool collapseWhitespace = !provider.GetStyleText()->WhiteSpaceIsSignificant();
PRUint32 start =