From ec96d9f267ae67dba4303f311e7d3428a42d4477 Mon Sep 17 00:00:00 2001 From: "jeremychen@mozilla.com" Date: Wed, 1 Mar 2017 20:58:25 +0800 Subject: [PATCH] Bug 276079 - add layout support for CSS text-justify property. r=xidorn MozReview-Commit-ID: Kiwu8UNfbSj --HG-- extra : rebase_source : 7673c42f8d401832437b0bb891f87aa22acabe15 --- layout/base/nsLayoutUtils.cpp | 3 ++- layout/generic/nsTextFrame.cpp | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 6ed1c6542731..7d5104e783a3 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -6974,7 +6974,8 @@ nsLayoutUtils::GetTextRunFlagsForStyle(nsStyleContext* aStyleContext, nscoord aLetterSpacing) { uint32_t result = 0; - if (aLetterSpacing != 0) { + if (aLetterSpacing != 0 || + aStyleText->mTextJustify == StyleTextJustify::InterCharacter) { result |= gfxTextRunFactory::TEXT_DISABLE_OPTIONAL_LIGATURES; } if (aStyleText->mControlCharacterVisibility == NS_STYLE_CONTROL_CHARACTER_VISIBILITY_HIDDEN) { diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index 84e55bb2131b..6105631dd468 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -2964,10 +2964,17 @@ nsTextFrame::GetTrimmedOffsets(const nsTextFragment* aFrag, return offsets; } -static bool IsJustifiableCharacter(const nsTextFragment* aFrag, int32_t aPos, +static bool IsJustifiableCharacter(const nsStyleText* aTextStyle, + const nsTextFragment* aFrag, int32_t aPos, bool aLangIsCJ) { NS_ASSERTION(aPos >= 0, "negative position?!"); + + StyleTextJustify justifyStyle = aTextStyle->mTextJustify; + if (justifyStyle == StyleTextJustify::None) { + return false; + } + char16_t ch = aFrag->CharAt(aPos); if (ch == '\n' || ch == '\t' || ch == '\r') { return true; @@ -2980,6 +2987,14 @@ static bool IsJustifiableCharacter(const nsTextFragment* aFrag, int32_t aPos, return !nsTextFrameUtils::IsSpaceCombiningSequenceTail( aFrag->Get2b() + aPos + 1, aFrag->GetLength() - (aPos + 1)); } + + if (justifyStyle == StyleTextJustify::InterCharacter) { + return true; + } else if (justifyStyle == StyleTextJustify::InterWord) { + return false; + } + + // text-justify: auto if (ch < 0x2150u) { return false; } @@ -3310,7 +3325,7 @@ PropertyProvider::ComputeJustification( gfxSkipCharsIterator iter = run.GetPos(); for (uint32_t i = 0; i < length; ++i) { uint32_t offset = originalOffset + i; - if (!IsJustifiableCharacter(mFrag, offset, isCJ)) { + if (!IsJustifiableCharacter(mTextStyle, mFrag, offset, isCJ)) { continue; }