From 5599f9d7d7cace72016504ac31890819e166245b Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Sat, 15 Apr 2017 00:31:44 +0200 Subject: [PATCH] Bug 944200 part 3 - [css-ui] Refactor the code to prepare for narrowing the content area by the float edges in the next part (idempotent patch). r=dholbert MozReview-Commit-ID: 8s0ynJSmBbD --- layout/generic/TextOverflow.cpp | 52 +++++++++++++++++++++------------ layout/generic/TextOverflow.h | 13 ++++++--- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/layout/generic/TextOverflow.cpp b/layout/generic/TextOverflow.cpp index 54301654cbe4..1cf6b0ab3239 100644 --- a/layout/generic/TextOverflow.cpp +++ b/layout/generic/TextOverflow.cpp @@ -465,7 +465,7 @@ TextOverflow::AnalyzeMarkerEdges(nsIFrame* aFrame, } } -void +LogicalRect TextOverflow::ExamineLineFrames(nsLineBox* aLine, FrameHashtable* aFramesToHide, AlignmentEdges* aAlignmentEdges) @@ -489,10 +489,20 @@ TextOverflow::ExamineLineFrames(nsLineBox* aLine, } LogicalRect contentArea = mContentArea; - const nscoord scrollAdjust = mAdjustForPixelSnapping ? - mBlock->PresContext()->AppUnitsPerDevPixel() : 0; - InflateIStart(mBlockWM, &contentArea, scrollAdjust); - InflateIEnd(mBlockWM, &contentArea, scrollAdjust); + bool snapStart = true, snapEnd = true; + // Save the non-snapped area since that's what we want to use when placing + // the markers (our return value). The snapped area is only for analysis. + LogicalRect nonSnappedContentArea = contentArea; + if (mAdjustForPixelSnapping) { + const nscoord scrollAdjust = mBlock->PresContext()->AppUnitsPerDevPixel(); + if (snapStart) { + InflateIStart(mBlockWM, &contentArea, scrollAdjust); + } + if (snapEnd) { + InflateIEnd(mBlockWM, &contentArea, scrollAdjust); + } + } + LogicalRect lineRect(mBlockWM, aLine->GetScrollableOverflowArea(), mBlockSize); const bool istartOverflow = @@ -501,7 +511,7 @@ TextOverflow::ExamineLineFrames(nsLineBox* aLine, !suppressIEnd && lineRect.IEnd(mBlockWM) > contentArea.IEnd(mBlockWM); if (!istartOverflow && !iendOverflow) { // The line does not overflow on a side we should ellipsize. - return; + return nonSnappedContentArea; } int pass = 0; @@ -532,7 +542,7 @@ TextOverflow::ExamineLineFrames(nsLineBox* aLine, // Calculate the area between the potential markers aligned at the // block's edge. - LogicalRect insideMarkersArea = mContentArea; + LogicalRect insideMarkersArea = nonSnappedContentArea; if (guessIStart) { InflateIStart(mBlockWM, &insideMarkersArea, -istartMarkerISize); } @@ -558,9 +568,9 @@ TextOverflow::ExamineLineFrames(nsLineBox* aLine, pass = -1; if (mIStart.IsNeeded() && mIStart.mActive && !clippedIStartMarker) { if (clippedMarkerEdges.mAssignedIStart && - clippedMarkerEdges.mIStart > mContentArea.IStart(mBlockWM)) { - mIStart.mISize = - clippedMarkerEdges.mIStart - mContentArea.IStart(mBlockWM); + clippedMarkerEdges.mIStart > nonSnappedContentArea.IStart(mBlockWM)) { + mIStart.mISize = clippedMarkerEdges.mIStart - + nonSnappedContentArea.IStart(mBlockWM); NS_ASSERTION(mIStart.mISize < mIStart.mIntrinsicISize, "clipping a marker should make it strictly smaller"); clippedIStartMarker = true; @@ -571,8 +581,9 @@ TextOverflow::ExamineLineFrames(nsLineBox* aLine, } if (mIEnd.IsNeeded() && mIEnd.mActive && !clippedIEndMarker) { if (clippedMarkerEdges.mAssignedIEnd && - mContentArea.IEnd(mBlockWM) > clippedMarkerEdges.mIEnd) { - mIEnd.mISize = mContentArea.IEnd(mBlockWM) - clippedMarkerEdges.mIEnd; + nonSnappedContentArea.IEnd(mBlockWM) > clippedMarkerEdges.mIEnd) { + mIEnd.mISize = nonSnappedContentArea.IEnd(mBlockWM) - + clippedMarkerEdges.mIEnd; NS_ASSERTION(mIEnd.mISize < mIEnd.mIntrinsicISize, "clipping a marker should make it strictly smaller"); clippedIEndMarker = true; @@ -608,6 +619,7 @@ TextOverflow::ExamineLineFrames(nsLineBox* aLine, if (!iendOverflow || !mIEnd.mActive) { mIEnd.Reset(); } + return nonSnappedContentArea; } void @@ -624,7 +636,8 @@ TextOverflow::ProcessLine(const nsDisplayListSet& aLists, FrameHashtable framesToHide(64); AlignmentEdges alignmentEdges; - ExamineLineFrames(aLine, &framesToHide, &alignmentEdges); + const LogicalRect contentArea = + ExamineLineFrames(aLine, &framesToHide, &alignmentEdges); bool needIStart = mIStart.IsNeeded(); bool needIEnd = mIEnd.IsNeeded(); if (!needIStart && !needIEnd) { @@ -638,10 +651,10 @@ TextOverflow::ProcessLine(const nsDisplayListSet& aLists, // If there is insufficient space for both markers then keep the one on the // end side per the block's 'direction'. if (needIStart && needIEnd && - mIStart.mISize + mIEnd.mISize > mContentArea.ISize(mBlockWM)) { + mIStart.mISize + mIEnd.mISize > contentArea.ISize(mBlockWM)) { needIStart = false; } - LogicalRect insideMarkersArea = mContentArea; + LogicalRect insideMarkersArea = contentArea; if (needIStart) { InflateIStart(mBlockWM, &insideMarkersArea, -mIStart.mISize); } @@ -660,7 +673,7 @@ TextOverflow::ProcessLine(const nsDisplayListSet& aLists, for (uint32_t i = 0; i < ArrayLength(lists); ++i) { PruneDisplayListContents(lists[i], framesToHide, insideMarkersArea); } - CreateMarkers(aLine, needIStart, needIEnd, insideMarkersArea); + CreateMarkers(aLine, needIStart, needIEnd, insideMarkersArea, contentArea); } void @@ -754,7 +767,8 @@ TextOverflow::CanHaveTextOverflow(nsIFrame* aBlockFrame) void TextOverflow::CreateMarkers(const nsLineBox* aLine, bool aCreateIStart, bool aCreateIEnd, - const mozilla::LogicalRect& aInsideMarkersArea) + const LogicalRect& aInsideMarkersArea, + const LogicalRect& aContentArea) { if (aCreateIStart) { DisplayListClipState::AutoSaveRestore clipState(mBuilder); @@ -765,7 +779,7 @@ TextOverflow::CreateMarkers(const nsLineBox* aLine, nsPoint offset = mBuilder->ToReferenceFrame(mBlock); nsRect markerRect = markerLogicalRect.GetPhysicalRect(mBlockWM, mBlockSize) + offset; - ClipMarker(mContentArea.GetPhysicalRect(mBlockWM, mBlockSize) + offset, + ClipMarker(aContentArea.GetPhysicalRect(mBlockWM, mBlockSize) + offset, markerRect, clipState); nsDisplayItem* marker = new (mBuilder) nsDisplayTextOverflowMarker(mBuilder, mBlock, markerRect, @@ -782,7 +796,7 @@ TextOverflow::CreateMarkers(const nsLineBox* aLine, nsPoint offset = mBuilder->ToReferenceFrame(mBlock); nsRect markerRect = markerLogicalRect.GetPhysicalRect(mBlockWM, mBlockSize) + offset; - ClipMarker(mContentArea.GetPhysicalRect(mBlockWM, mBlockSize) + offset, + ClipMarker(aContentArea.GetPhysicalRect(mBlockWM, mBlockSize) + offset, markerRect, clipState); nsDisplayItem* marker = new (mBuilder) nsDisplayTextOverflowMarker(mBuilder, mBlock, markerRect, diff --git a/layout/generic/TextOverflow.h b/layout/generic/TextOverflow.h index c08bd1478fe2..6c253d48faee 100644 --- a/layout/generic/TextOverflow.h +++ b/layout/generic/TextOverflow.h @@ -126,10 +126,12 @@ class TextOverflow { * @param aFramesToHide frames that should have their display items removed * @param aAlignmentEdges the outermost edges of all text and atomic * inline-level frames that are inside the area between the markers + * @return the area inside which we should add any markers; + * this is the block's content area. */ - void ExamineLineFrames(nsLineBox* aLine, - FrameHashtable* aFramesToHide, - AlignmentEdges* aAlignmentEdges); + LogicalRect ExamineLineFrames(nsLineBox* aLine, + FrameHashtable* aFramesToHide, + AlignmentEdges* aAlignmentEdges); /** * LineHasOverflowingText calls this to analyze edges, both the block's @@ -198,10 +200,13 @@ class TextOverflow { * @param aCreateIStart if true, create a marker on the inline start side * @param aCreateIEnd if true, create a marker on the inline end side * @param aInsideMarkersArea is the area inside the markers + * @param aContentArea is the area inside which we should add the markers; + * this is the block's content area. */ void CreateMarkers(const nsLineBox* aLine, bool aCreateIStart, bool aCreateIEnd, - const LogicalRect& aInsideMarkersArea); + const LogicalRect& aInsideMarkersArea, + const LogicalRect& aContentArea); LogicalRect mContentArea; nsDisplayListBuilder* mBuilder;