Bug 276079 - add layout support for CSS text-justify property. draft
authorjeremychen@mozilla.com <jeremychen@mozilla.com>
Wed, 01 Mar 2017 20:58:25 +0800
changeset 490897 4e54885fdf5263dd138757630b9216c035c71edf
parent 490896 c0c46c4e46220cda55fe87d02db7bb1871b184c9
child 490898 4524539d5188c591b877b9c5cdd11cbd980ebf38
push id47261
push userjichen@mozilla.com
push dateWed, 01 Mar 2017 12:59:44 +0000
bugs276079
milestone54.0a1
Bug 276079 - add layout support for CSS text-justify property. MozReview-Commit-ID: Kiwu8UNfbSj
layout/base/nsLayoutUtils.cpp
layout/generic/nsTextFrame.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -6969,17 +6969,18 @@ nsLayoutUtils::GetReferenceFrame(nsIFram
 
 /* static */ uint32_t
 nsLayoutUtils::GetTextRunFlagsForStyle(nsStyleContext* aStyleContext,
                                        const nsStyleFont* aStyleFont,
                                        const nsStyleText* aStyleText,
                                        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) {
     result |= gfxTextRunFactory::TEXT_HIDE_CONTROL_CHARACTERS;
   }
   switch (aStyleContext->StyleText()->mTextRendering) {
   case NS_STYLE_TEXT_RENDERING_OPTIMIZESPEED:
     result |= gfxTextRunFactory::TEXT_OPTIMIZE_SPEED;
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -2959,32 +2959,47 @@ nsTextFrame::GetTrimmedOffsets(const nsT
     int32_t whitespaceCount =
       GetTrimmableWhitespaceCount(aFrag,
                                   offsets.GetEnd() - 1, offsets.mLength, -1);
     offsets.mLength -= whitespaceCount;
   }
   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;
   }
   if (ch == ' ' || ch == CH_NBSP) {
     // Don't justify spaces that are combined with diacriticals
     if (!aFrag->Is2b()) {
       return true;
     }
     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;
   }
   if (aLangIsCJ) {
     if ((0x2150u <= ch && ch <= 0x22ffu) || // Number Forms, Arrows, Mathematical Operators
         (0x2460u <= ch && ch <= 0x24ffu) || // Enclosed Alphanumerics
         (0x2580u <= ch && ch <= 0x27bfu) || // Block Elements, Geometric Shapes, Miscellaneous Symbols, Dingbats
         (0x27f0u <= ch && ch <= 0x2bffu) || // Supplemental Arrows-A, Braille Patterns, Supplemental Arrows-B,
@@ -3305,17 +3320,17 @@ PropertyProvider::ComputeJustification(
     uint32_t originalOffset = run.GetOriginalOffset();
     uint32_t skippedOffset = run.GetSkippedOffset();
     uint32_t length = run.GetRunLength();
     assignments.SetLength(skippedOffset + length - mJustificationArrayStart);
 
     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;
       }
 
       iter.SetOriginalOffset(offset);
 
       FindClusterStart(mTextRun, originalOffset, &iter);
       uint32_t firstCharOffset = iter.GetSkippedOffset();
       uint32_t firstChar = firstCharOffset > mJustificationArrayStart ?