Bug 524025 - Remove LL_* constants in nsLineLayout with separate booleans with field widths. r=dbaron

This commit is contained in:
Leonard Camacho 2012-09-27 21:26:40 -04:30
parent 952e98bb47
commit 4420e1cb45
2 changed files with 70 additions and 86 deletions

View File

@ -64,7 +64,20 @@ nsLineLayout::nsLineLayout(nsPresContext* aPresContext,
mLastOptionalBreakContentOffset(-1), mLastOptionalBreakContentOffset(-1),
mForceBreakContentOffset(-1), mForceBreakContentOffset(-1),
mMinLineHeight(0), mMinLineHeight(0),
mTextIndent(0) mTextIndent(0),
mFirstLetterStyleOK(false),
mIsTopOfPage(false),
mImpactedByFloats(false),
mLastFloatWasLetterFrame(false),
mLineIsEmpty(false),
mLineEndsInBR(false),
mNeedBackup(false),
mInFirstLine(false),
mGotLineBox(false),
mInFirstLetter(false),
mHasBullet(false),
mDirtyNextLine(false),
mLineAtStart(false)
{ {
NS_ASSERTION(aFloatManager || aOuterReflowState->frame->GetType() == NS_ASSERTION(aFloatManager || aOuterReflowState->frame->GetType() ==
nsGkAtoms::letterFrame, nsGkAtoms::letterFrame,
@ -74,7 +87,6 @@ nsLineLayout::nsLineLayout(nsPresContext* aPresContext,
// Stash away some style data that we need // Stash away some style data that we need
mStyleText = aOuterReflowState->frame->GetStyleText(); mStyleText = aOuterReflowState->frame->GetStyleText();
mLineNumber = 0; mLineNumber = 0;
mFlags = 0; // default all flags to false except those that follow here...
mTotalPlacedFrames = 0; mTotalPlacedFrames = 0;
mTopEdge = 0; mTopEdge = 0;
mTrimmableWidth = 0; mTrimmableWidth = 0;
@ -94,7 +106,7 @@ nsLineLayout::nsLineLayout(nsPresContext* aPresContext,
mSpanDepth = 0; mSpanDepth = 0;
if (aLine) { if (aLine) {
SetFlag(LL_GOTLINEBOX, true); mGotLineBox = true;
mLineBox = *aLine; mLineBox = *aLine;
} }
} }
@ -162,17 +174,17 @@ nsLineLayout::BeginLineReflow(nscoord aX, nscoord aY,
mSpansAllocated = mSpansFreed = mFramesAllocated = mFramesFreed = 0; mSpansAllocated = mSpansFreed = mFramesAllocated = mFramesFreed = 0;
#endif #endif
SetFlag(LL_FIRSTLETTERSTYLEOK, false); mFirstLetterStyleOK = false;
SetFlag(LL_ISTOPOFPAGE, aIsTopOfPage); mIsTopOfPage = aIsTopOfPage;
SetFlag(LL_IMPACTEDBYFLOATS, aImpactedByFloats); mImpactedByFloats = aImpactedByFloats;
mTotalPlacedFrames = 0; mTotalPlacedFrames = 0;
SetFlag(LL_LINEISEMPTY, true); mLineIsEmpty = true;
SetFlag(LL_LINEATSTART, true); mLineAtStart = true;
SetFlag(LL_LINEENDSINBR, false); mLineEndsInBR = false;
mSpanDepth = 0; mSpanDepth = 0;
mMaxTopBoxHeight = mMaxBottomBoxHeight = 0; mMaxTopBoxHeight = mMaxBottomBoxHeight = 0;
if (GetFlag(LL_GOTLINEBOX)) { if (mGotLineBox) {
mLineBox->ClearHasBullet(); mLineBox->ClearHasBullet();
} }
@ -200,7 +212,7 @@ nsLineLayout::BeginLineReflow(nscoord aX, nscoord aY,
pctBasis = pctBasis =
nsHTMLReflowState::GetContainingBlockContentWidth(mBlockReflowState); nsHTMLReflowState::GetContainingBlockContentWidth(mBlockReflowState);
if (GetFlag(LL_GOTLINEBOX)) { if (mGotLineBox) {
mLineBox->DisableResizeReflowOptimization(); mLineBox->DisableResizeReflowOptimization();
} }
} }
@ -325,10 +337,9 @@ nsLineLayout::UpdateBand(const nsRect& aNewAvailSpace,
} }
mTopEdge = aNewAvailSpace.y; mTopEdge = aNewAvailSpace.y;
SetFlag(LL_IMPACTEDBYFLOATS, true); mImpactedByFloats = true;
SetFlag(LL_LASTFLOATWASLETTERFRAME, mLastFloatWasLetterFrame = nsGkAtoms::letterFrame == aFloatFrame->GetType();
nsGkAtoms::letterFrame == aFloatFrame->GetType());
} }
nsresult nsresult
@ -594,8 +605,8 @@ bool
nsLineLayout::LineIsBreakable() const nsLineLayout::LineIsBreakable() const
{ {
// XXX mTotalPlacedFrames should go away and we should just use // XXX mTotalPlacedFrames should go away and we should just use
// LL_LINEISEMPTY here instead // mLineIsEmpty here instead
if ((0 != mTotalPlacedFrames) || GetFlag(LL_IMPACTEDBYFLOATS)) { if ((0 != mTotalPlacedFrames) || mImpactedByFloats) {
return true; return true;
} }
return false; return false;
@ -737,7 +748,7 @@ nsLineLayout::ReflowFrame(nsIFrame* aFrame,
// Capture this state *before* we reflow the frame in case it clears // Capture this state *before* we reflow the frame in case it clears
// the state out. We need to know how to treat the current frame // the state out. We need to know how to treat the current frame
// when breaking. // when breaking.
bool notSafeToBreak = LineIsEmpty() && !GetFlag(LL_IMPACTEDBYFLOATS); bool notSafeToBreak = LineIsEmpty() && !mImpactedByFloats;
// Figure out whether we're talking about a textframe here // Figure out whether we're talking about a textframe here
nsIAtom* frameType = aFrame->GetType(); nsIAtom* frameType = aFrame->GetType();
@ -773,7 +784,7 @@ nsLineLayout::ReflowFrame(nsIFrame* aFrame,
aFrame, availSize); aFrame, availSize);
nsHTMLReflowState& reflowState = reflowStateHolder.ref(); nsHTMLReflowState& reflowState = reflowStateHolder.ref();
reflowState.mLineLayout = this; reflowState.mLineLayout = this;
reflowState.mFlags.mIsTopOfPage = GetFlag(LL_ISTOPOFPAGE); reflowState.mFlags.mIsTopOfPage = mIsTopOfPage;
if (reflowState.ComputedWidth() == NS_UNCONSTRAINEDSIZE) if (reflowState.ComputedWidth() == NS_UNCONSTRAINEDSIZE)
reflowState.availableWidth = availableSpaceOnLine; reflowState.availableWidth = availableSpaceOnLine;
pfd->mMargin = reflowState.mComputedMargin; pfd->mMargin = reflowState.mComputedMargin;
@ -802,7 +813,7 @@ nsLineLayout::ReflowFrame(nsIFrame* aFrame,
// this IsPercentageAware check *after* we've constructed our // this IsPercentageAware check *after* we've constructed our
// nsHTMLReflowState, because that construction may be what forces aFrame // nsHTMLReflowState, because that construction may be what forces aFrame
// to lazily initialize its (possibly-percent-valued) intrinsic size.) // to lazily initialize its (possibly-percent-valued) intrinsic size.)
if (GetFlag(LL_GOTLINEBOX) && IsPercentageAware(aFrame)) { if (mGotLineBox && IsPercentageAware(aFrame)) {
mLineBox->DisableResizeReflowOptimization(); mLineBox->DisableResizeReflowOptimization();
} }
@ -1000,10 +1011,10 @@ nsLineLayout::ReflowFrame(nsIFrame* aFrame,
aReflowStatus, &optionalBreakAfterFits)) { aReflowStatus, &optionalBreakAfterFits)) {
if (!isEmpty) { if (!isEmpty) {
psd->mHasNonemptyContent = true; psd->mHasNonemptyContent = true;
SetFlag(LL_LINEISEMPTY, false); mLineIsEmpty = false;
if (!pfd->mSpan) { if (!pfd->mSpan) {
// nonempty leaf content has been placed // nonempty leaf content has been placed
SetFlag(LL_LINEATSTART, false); mLineAtStart = false;
} }
} }
@ -1271,7 +1282,7 @@ nsLineLayout::CanPlaceFrame(PerFrameData* pfd,
#endif #endif
// We will want to try backup. // We will want to try backup.
SetFlag(LL_NEEDBACKUP, true); mNeedBackup = true;
return true; return true;
} }
@ -1318,14 +1329,14 @@ nsLineLayout::AddBulletFrame(nsIFrame* aFrame,
const nsHTMLReflowMetrics& aMetrics) const nsHTMLReflowMetrics& aMetrics)
{ {
NS_ASSERTION(mCurrentSpan == mRootSpan, "bad linelayout user"); NS_ASSERTION(mCurrentSpan == mRootSpan, "bad linelayout user");
NS_ASSERTION(GetFlag(LL_GOTLINEBOX), "must have line box"); NS_ASSERTION(mGotLineBox, "must have line box");
nsIFrame *blockFrame = mBlockReflowState->frame; nsIFrame *blockFrame = mBlockReflowState->frame;
NS_ASSERTION(blockFrame->IsFrameOfType(nsIFrame::eBlockFrame), NS_ASSERTION(blockFrame->IsFrameOfType(nsIFrame::eBlockFrame),
"must be for block"); "must be for block");
if (!static_cast<nsBlockFrame*>(blockFrame)->BulletIsEmpty()) { if (!static_cast<nsBlockFrame*>(blockFrame)->BulletIsEmpty()) {
SetFlag(LL_HASBULLET, true); mHasBullet = true;
mLineBox->SetHasBullet(); mLineBox->SetHasBullet();
} }
@ -2034,8 +2045,8 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd)
// BR) (NN4/IE5 quirk) // BR) (NN4/IE5 quirk)
// (1) and (2) above // (1) and (2) above
bool applyMinLH = !psd->mZeroEffectiveSpanBox || GetFlag(LL_HASBULLET); bool applyMinLH = !psd->mZeroEffectiveSpanBox || mHasBullet;
bool isLastLine = (!mLineBox->IsLineWrapped() && !GetFlag(LL_LINEENDSINBR)); bool isLastLine = (!mLineBox->IsLineWrapped() && !mLineEndsInBR);
if (!applyMinLH && isLastLine) { if (!applyMinLH && isLastLine) {
nsIContent* blockContent = mRootSpan->mFrame->mFrame->GetContent(); nsIContent* blockContent = mRootSpan->mFrame->mFrame->GetContent();
if (blockContent) { if (blockContent) {
@ -2049,7 +2060,7 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd)
} }
} }
if (applyMinLH) { if (applyMinLH) {
if (psd->mHasNonemptyContent || preMode || GetFlag(LL_HASBULLET)) { if (psd->mHasNonemptyContent || preMode || mHasBullet) {
#ifdef NOISY_VERTICAL_ALIGN #ifdef NOISY_VERTICAL_ALIGN
printf(" [span]==> adjusting min/maxY: currentValues: %d,%d", minY, maxY); printf(" [span]==> adjusting min/maxY: currentValues: %d,%d", minY, maxY);
#endif #endif

View File

@ -110,45 +110,6 @@ public:
*/ */
void RelativePositionFrames(nsOverflowAreas& aOverflowAreas); void RelativePositionFrames(nsOverflowAreas& aOverflowAreas);
//----------------------------------------
// Supporting methods and data for flags
protected:
#define LL_FIRSTLETTERSTYLEOK 0x00000008
#define LL_ISTOPOFPAGE 0x00000010
#define LL_IMPACTEDBYFLOATS 0x00000040
#define LL_LASTFLOATWASLETTERFRAME 0x00000080
#define LL_LINEISEMPTY 0x00000100
#define LL_LINEENDSINBR 0x00000200
#define LL_NEEDBACKUP 0x00000400
#define LL_INFIRSTLINE 0x00000800
#define LL_GOTLINEBOX 0x00001000
#define LL_INFIRSTLETTER 0x00002000
#define LL_HASBULLET 0x00004000
#define LL_DIRTYNEXTLINE 0x00008000
#define LL_LINEATSTART 0x00010000
#define LL_LASTFLAG LL_LINEATSTART
void SetFlag(uint32_t aFlag, bool aValue)
{
NS_ASSERTION(aFlag<=LL_LASTFLAG, "bad flag");
NS_ASSERTION(aValue==false || aValue==true, "bad value");
if (aValue) { // set flag
mFlags |= aFlag;
}
else { // unset flag
mFlags &= ~aFlag;
}
}
bool GetFlag(uint32_t aFlag) const
{
NS_ASSERTION(aFlag<=LL_LASTFLAG, "bad flag");
return !!(mFlags & aFlag);
}
public:
// Support methods for word-wrapping during line reflow // Support methods for word-wrapping during line reflow
void SetTextJustificationWeights(int32_t aNumSpaces, int32_t aNumLetters) { void SetTextJustificationWeights(int32_t aNumSpaces, int32_t aNumLetters) {
@ -162,7 +123,7 @@ public:
*/ */
bool LineIsEmpty() const bool LineIsEmpty() const
{ {
return GetFlag(LL_LINEISEMPTY); return mLineIsEmpty;
} }
/** /**
@ -172,19 +133,19 @@ public:
*/ */
bool LineAtStart() const bool LineAtStart() const
{ {
return GetFlag(LL_LINEATSTART); return mLineAtStart;
} }
bool LineIsBreakable() const; bool LineIsBreakable() const;
bool GetLineEndsInBR() const bool GetLineEndsInBR() const
{ {
return GetFlag(LL_LINEENDSINBR); return mLineEndsInBR;
} }
void SetLineEndsInBR(bool aOn) void SetLineEndsInBR(bool aOn)
{ {
SetFlag(LL_LINEENDSINBR, aOn); mLineEndsInBR = aOn;
} }
//---------------------------------------- //----------------------------------------
@ -202,36 +163,36 @@ public:
//---------------------------------------- //----------------------------------------
bool GetFirstLetterStyleOK() const { bool GetFirstLetterStyleOK() const {
return GetFlag(LL_FIRSTLETTERSTYLEOK); return mFirstLetterStyleOK;
} }
void SetFirstLetterStyleOK(bool aSetting) { void SetFirstLetterStyleOK(bool aSetting) {
SetFlag(LL_FIRSTLETTERSTYLEOK, aSetting); mFirstLetterStyleOK = aSetting;
} }
bool GetInFirstLetter() const { bool GetInFirstLetter() const {
return GetFlag(LL_INFIRSTLETTER); return mInFirstLetter;
} }
void SetInFirstLetter(bool aSetting) { void SetInFirstLetter(bool aSetting) {
SetFlag(LL_INFIRSTLETTER, aSetting); mInFirstLetter = aSetting;
} }
bool GetInFirstLine() const { bool GetInFirstLine() const {
return GetFlag(LL_INFIRSTLINE); return mInFirstLine;
} }
void SetInFirstLine(bool aSetting) { void SetInFirstLine(bool aSetting) {
SetFlag(LL_INFIRSTLINE, aSetting); mInFirstLine = aSetting;
} }
// Calling this during block reflow ensures that the next line of inlines // Calling this during block reflow ensures that the next line of inlines
// will be marked dirty, if there is one. // will be marked dirty, if there is one.
void SetDirtyNextLine() { void SetDirtyNextLine() {
SetFlag(LL_DIRTYNEXTLINE, true); mDirtyNextLine = true;
} }
bool GetDirtyNextLine() { bool GetDirtyNextLine() {
return GetFlag(LL_DIRTYNEXTLINE); return mDirtyNextLine;
} }
//---------------------------------------- //----------------------------------------
@ -264,7 +225,7 @@ public:
*/ */
bool NotifyOptionalBreakPosition(nsIContent* aContent, int32_t aOffset, bool NotifyOptionalBreakPosition(nsIContent* aContent, int32_t aOffset,
bool aFits, gfxBreakPriority aPriority) { bool aFits, gfxBreakPriority aPriority) {
NS_ASSERTION(!aFits || !GetFlag(LL_NEEDBACKUP), NS_ASSERTION(!aFits || !mNeedBackup,
"Shouldn't be updating the break position with a break that fits after we've already flagged an overrun"); "Shouldn't be updating the break position with a break that fits after we've already flagged an overrun");
// Remember the last break position that fits; if there was no break that fit, // Remember the last break position that fits; if there was no break that fit,
// just remember the first break // just remember the first break
@ -278,7 +239,7 @@ public:
mForceBreakContentOffset == aOffset; mForceBreakContentOffset == aOffset;
} }
/** /**
* Like NotifyOptionalBreakPosition, but here it's OK for LL_NEEDBACKUP * Like NotifyOptionalBreakPosition, but here it's OK for mNeedBackup
* to be set, because the caller is merely pruning some saved break position(s) * to be set, because the caller is merely pruning some saved break position(s)
* that are actually not feasible. * that are actually not feasible.
*/ */
@ -292,7 +253,7 @@ public:
* Signal that no backing up will be required after all. * Signal that no backing up will be required after all.
*/ */
void ClearOptionalBreakPosition() { void ClearOptionalBreakPosition() {
SetFlag(LL_NEEDBACKUP, false); mNeedBackup = false;
mLastOptionalBreakContent = nullptr; mLastOptionalBreakContent = nullptr;
mLastOptionalBreakContentOffset = -1; mLastOptionalBreakContentOffset = -1;
mLastOptionalBreakPriority = eNoBreak; mLastOptionalBreakPriority = eNoBreak;
@ -310,7 +271,7 @@ public:
* Check whether frames overflowed the available width and CanPlaceFrame * Check whether frames overflowed the available width and CanPlaceFrame
* requested backing up to a saved break position. * requested backing up to a saved break position.
*/ */
bool NeedsBackup() { return GetFlag(LL_NEEDBACKUP); } bool NeedsBackup() { return mNeedBackup; }
// Line layout may place too much content on a line, overflowing its available // Line layout may place too much content on a line, overflowing its available
// width. When that happens, if SetLastOptionalBreakPosition has been // width. When that happens, if SetLastOptionalBreakPosition has been
@ -340,10 +301,10 @@ public:
return mBlockReflowState; return mBlockReflowState;
} }
const nsLineList::iterator* GetLine() const { const nsLineList::iterator* GetLine() const {
return GetFlag(LL_GOTLINEBOX) ? &mLineBox : nullptr; return mGotLineBox ? &mLineBox : nullptr;
} }
nsLineList::iterator* GetLine() { nsLineList::iterator* GetLine() {
return GetFlag(LL_GOTLINEBOX) ? &mLineBox : nullptr; return mGotLineBox ? &mLineBox : nullptr;
} }
/** /**
@ -526,6 +487,20 @@ protected:
// Amount of trimmable whitespace width for the trailing text frame, if any // Amount of trimmable whitespace width for the trailing text frame, if any
nscoord mTrimmableWidth; nscoord mTrimmableWidth;
bool mFirstLetterStyleOK : 1;
bool mIsTopOfPage : 1;
bool mImpactedByFloats : 1;
bool mLastFloatWasLetterFrame : 1;
bool mLineIsEmpty : 1;
bool mLineEndsInBR : 1;
bool mNeedBackup : 1;
bool mInFirstLine : 1;
bool mGotLineBox : 1;
bool mInFirstLetter : 1;
bool mHasBullet : 1;
bool mDirtyNextLine : 1;
bool mLineAtStart : 1;
int32_t mSpanDepth; int32_t mSpanDepth;
#ifdef DEBUG #ifdef DEBUG
int32_t mSpansAllocated, mSpansFreed; int32_t mSpansAllocated, mSpansFreed;
@ -533,8 +508,6 @@ protected:
#endif #endif
PLArenaPool mArena; // Per span and per frame data, 4 byte aligned PLArenaPool mArena; // Per span and per frame data, 4 byte aligned
uint32_t mFlags;
nsresult NewPerFrameData(PerFrameData** aResult); nsresult NewPerFrameData(PerFrameData** aResult);
nsresult NewPerSpanData(PerSpanData** aResult); nsresult NewPerSpanData(PerSpanData** aResult);