Skip to content

Commit 3d38b74

Browse files
committed
Bug 1731541 - Implement text-wrap: balance for nsBlockFrame reflow. r=emilio
A simple form of balance for short blocks, implemented by incrementally reducing the effective inline-size used during line-breaking, up to the point where an extra line would be created. This fails the test text-wrap-balance-line-clamp-001.html, but it's unclear to me if that test is correct (see w3c/csswg-drafts#9310). If we do want the behavior expected by that test, an additional patch to handle the interaction with line-clamp will be required. Depends on D187543 Differential Revision: https://phabricator.services.mozilla.com/D187544
1 parent 5831a51 commit 3d38b74

13 files changed

+399
-239
lines changed

layout/generic/BlockReflowState.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,16 @@
2727
using namespace mozilla;
2828
using namespace mozilla::layout;
2929

30-
BlockReflowState::BlockReflowState(const ReflowInput& aReflowInput,
31-
nsPresContext* aPresContext,
32-
nsBlockFrame* aFrame, bool aBStartMarginRoot,
33-
bool aBEndMarginRoot,
34-
bool aBlockNeedsFloatManager,
35-
const nscoord aConsumedBSize,
36-
const nscoord aEffectiveContentBoxBSize)
30+
BlockReflowState::BlockReflowState(
31+
const ReflowInput& aReflowInput, nsPresContext* aPresContext,
32+
nsBlockFrame* aFrame, bool aBStartMarginRoot, bool aBEndMarginRoot,
33+
bool aBlockNeedsFloatManager, const nscoord aConsumedBSize,
34+
const nscoord aEffectiveContentBoxBSize, const nscoord aInset)
3735
: mBlock(aFrame),
3836
mPresContext(aPresContext),
3937
mReflowInput(aReflowInput),
4038
mContentArea(aReflowInput.GetWritingMode()),
39+
mInsetForBalance(aInset),
4140
mPushedFloats(nullptr),
4241
mOverflowTracker(nullptr),
4342
mBorderPadding(

layout/generic/BlockReflowState.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ class BlockReflowState {
9898
nsBlockFrame* aFrame, bool aBStartMarginRoot,
9999
bool aBEndMarginRoot, bool aBlockNeedsFloatManager,
100100
const nscoord aConsumedBSize,
101-
const nscoord aEffectiveContentBoxBSize);
101+
const nscoord aEffectiveContentBoxBSize,
102+
const nscoord aInset = 0);
102103

103104
/**
104105
* Get the available reflow space (the area not occupied by floats)
@@ -243,9 +244,9 @@ class BlockReflowState {
243244
// the block.
244245

245246
// The block frame that is using this object
246-
nsBlockFrame* mBlock;
247+
nsBlockFrame* const mBlock;
247248

248-
nsPresContext* mPresContext;
249+
nsPresContext* const mPresContext;
249250

250251
const ReflowInput& mReflowInput;
251252

@@ -301,6 +302,10 @@ class BlockReflowState {
301302
return mContentArea.Size(wm).ConvertTo(aWM, wm);
302303
}
303304

305+
// Amount of inset to apply during line-breaking, used by text-wrap:balance
306+
// to adjust line-breaks for more consistent lengths throughout the block.
307+
nscoord mInsetForBalance;
308+
304309
// Physical size. Use only for physical <-> logical coordinate conversion.
305310
nsSize mContainerSize;
306311
const nsSize& ContainerSize() const { return mContainerSize; }
@@ -345,7 +350,7 @@ class BlockReflowState {
345350

346351
// mBlock's computed logical border+padding with pre-reflow skip sides applied
347352
// (See the constructor and nsIFrame::PreReflowBlockLevelLogicalSkipSides).
348-
LogicalMargin mBorderPadding;
353+
const LogicalMargin mBorderPadding;
349354

350355
// The overflow areas of all floats placed so far
351356
OverflowAreas mFloatOverflowAreas;
@@ -383,7 +388,7 @@ class BlockReflowState {
383388
// placed, since we're on a nowrap context.
384389
nsTArray mNoWrapFloats;
385390

386-
nscoord mMinLineHeight;
391+
const nscoord mMinLineHeight;
387392

388393
int32_t mLineNumber;
389394

0 commit comments

Comments
 (0)