summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-01 19:32:49 +0200
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-01 19:32:49 +0200
commit1f4ce97ecd5fa47eead41e1408d2d26ce50749fa (patch)
treed47291e5471dc98ebf2e4f4d5281d9c3eda15518
parentdc8aad9b9dc6983bb88aa586f34d9db007840eb8 (diff)
downloaduxp-1f4ce97ecd5fa47eead41e1408d2d26ce50749fa.tar.gz
moebius#90: CSS - implement text-justify property
-rw-r--r--devtools/shared/css/generated/properties-db.js21
-rw-r--r--layout/base/nsLayoutUtils.cpp3
-rw-r--r--layout/generic/nsTextFrame.cpp30
-rwxr-xr-xlayout/reftests/w3c-css/submitted/check-for-references.sh2
-rw-r--r--layout/reftests/w3c-css/submitted/text3/reftest.list5
-rw-r--r--layout/reftests/w3c-css/submitted/text3/text-justify-distribute-001.html28
-rw-r--r--layout/reftests/w3c-css/submitted/text3/text-justify-inter-character-001-ref.html24
-rw-r--r--layout/reftests/w3c-css/submitted/text3/text-justify-inter-character-001.html28
-rw-r--r--layout/reftests/w3c-css/submitted/text3/text-justify-inter-word-001-ref.html25
-rw-r--r--layout/reftests/w3c-css/submitted/text3/text-justify-inter-word-001.html29
-rw-r--r--layout/reftests/w3c-css/submitted/text3/text-justify-none-001-ref.html22
-rw-r--r--layout/reftests/w3c-css/submitted/text3/text-justify-none-001.html29
-rw-r--r--layout/style/nsCSSKeywordList.h4
-rw-r--r--layout/style/nsCSSPropList.h11
-rw-r--r--layout/style/nsCSSProps.cpp11
-rw-r--r--layout/style/nsCSSProps.h1
-rw-r--r--layout/style/nsComputedDOMStyle.cpp10
-rw-r--r--layout/style/nsComputedDOMStyle.h1
-rw-r--r--layout/style/nsComputedDOMStylePropertyList.h1
-rw-r--r--layout/style/nsRuleNode.cpp7
-rw-r--r--layout/style/nsStyleConsts.h8
-rw-r--r--layout/style/nsStyleStruct.cpp3
-rw-r--r--layout/style/nsStyleStruct.h1
-rw-r--r--layout/style/test/property_database.js11
-rw-r--r--modules/libpref/init/all.js3
-rw-r--r--testing/profiles/prefs_general.js3
26 files changed, 312 insertions, 9 deletions
diff --git a/devtools/shared/css/generated/properties-db.js b/devtools/shared/css/generated/properties-db.js
index 83b3efafc4..0701674967 100644
--- a/devtools/shared/css/generated/properties-db.js
+++ b/devtools/shared/css/generated/properties-db.js
@@ -3064,6 +3064,7 @@ exports.CSS_PROPERTIES = {
"text-emphasis-style",
"-webkit-text-fill-color",
"text-indent",
+ "text-justify",
"text-orientation",
"text-overflow",
"text-rendering",
@@ -3240,6 +3241,7 @@ exports.CSS_PROPERTIES = {
"dialog",
"difference",
"disabled",
+ "distribute",
"dotted",
"double",
"drag",
@@ -3299,6 +3301,8 @@ exports.CSS_PROPERTIES = {
"inline-table",
"inset",
"inside",
+ "inter-character",
+ "inter-word",
"intersect",
"isolate",
"italic",
@@ -8865,6 +8869,23 @@ exports.CSS_PROPERTIES = {
"unset"
]
},
+ "text-justify": {
+ "isInherited": true,
+ "subproperties": [
+ "text-justify"
+ ],
+ "supports": [],
+ "values": [
+ "auto",
+ "distribute",
+ "inherit",
+ "initial",
+ "inter-character",
+ "inter-word",
+ "none",
+ "unset"
+ ]
+ },
"text-orientation": {
"isInherited": true,
"subproperties": [
diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp
index c8c91b251c..86874f4041 100644
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -7013,7 +7013,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 00c0016fd1..fa31443fdd 100644
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -2936,22 +2936,40 @@ 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')
+ 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())
+ if (!aFrag->Is2b()) {
return true;
+ }
return !nsTextFrameUtils::IsSpaceCombiningSequenceTail(
- aFrag->Get2b() + aPos + 1, aFrag->GetLength() - (aPos + 1));
+ aFrag->Get2b() + aPos + 1, aFrag->GetLength() - (aPos + 1));
}
- if (ch < 0x2150u)
+
+ 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
@@ -3279,7 +3297,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;
}
diff --git a/layout/reftests/w3c-css/submitted/check-for-references.sh b/layout/reftests/w3c-css/submitted/check-for-references.sh
index 977cee3f48..c30e185152 100755
--- a/layout/reftests/w3c-css/submitted/check-for-references.sh
+++ b/layout/reftests/w3c-css/submitted/check-for-references.sh
@@ -15,7 +15,7 @@ do
else
echo "Unexpected type $TYPE for $DIRNAME/$TEST"
fi
- if grep "rel=\"$REFTYPE\"" "$DIRNAME/$TEST" | head -1 | grep -q "href=\"$REF\""
+ if grep "rel=\(\"$REFTYPE\"\|'$REFTYPE'\)" "$DIRNAME/$TEST" | head -1 | grep -q "href=\(\"$REF\"\|'$REF'\)"
then
#echo "Good link for $DIRNAME/$TEST"
echo -n
diff --git a/layout/reftests/w3c-css/submitted/text3/reftest.list b/layout/reftests/w3c-css/submitted/text3/reftest.list
index 2712e4363b..a1e3d70d0c 100644
--- a/layout/reftests/w3c-css/submitted/text3/reftest.list
+++ b/layout/reftests/w3c-css/submitted/text3/reftest.list
@@ -5,4 +5,9 @@
== text-align-match-parent-root-ltr.html text-align-match-parent-root-ltr-ref.html
== text-align-match-parent-root-rtl.html text-align-match-parent-root-rtl-ref.html
+pref(layout.css.text-justify.enabled,true) == text-justify-none-001.html text-justify-none-001-ref.html
+pref(layout.css.text-justify.enabled,true) == text-justify-inter-word-001.html text-justify-inter-word-001-ref.html
+pref(layout.css.text-justify.enabled,true) == text-justify-inter-character-001.html text-justify-inter-character-001-ref.html
+pref(layout.css.text-justify.enabled,true) == text-justify-distribute-001.html text-justify-inter-character-001-ref.html
+
== text-word-spacing-001.html text-word-spacing-ref.html
diff --git a/layout/reftests/w3c-css/submitted/text3/text-justify-distribute-001.html b/layout/reftests/w3c-css/submitted/text3/text-justify-distribute-001.html
new file mode 100644
index 0000000000..4d29f0fee5
--- /dev/null
+++ b/layout/reftests/w3c-css/submitted/text3/text-justify-distribute-001.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>CSS Text 7.4. Justification Method: text-justify: distribute</title>
+<link rel="author" title="Chun-Min (Jeremy) Chen" href="mailto:jeremychen@mozilla.com">
+<link rel="author" title="Mozilla" href="https://www.mozilla.org">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#text-justify-property">
+<link rel='match' href='text-justify-inter-character-001-ref.html'>
+<meta name="assert" content="text-justify:distribute means justification adjusts spacing between each pair of adjacent typographic character units.">
+<style type='text/css'>
+p {
+ font-size: 1.5em;
+ border: 1px solid black;
+ padding: 10px;
+ margin-right: 310px;
+}
+.test {
+ text-align-last: justify;
+ text-justify: distribute;
+}
+</style>
+</head>
+<body>
+<p lang="en" class="test">XX</p>
+<p lang="ja" class="test">文字</p>
+</body>
+</html>
diff --git a/layout/reftests/w3c-css/submitted/text3/text-justify-inter-character-001-ref.html b/layout/reftests/w3c-css/submitted/text3/text-justify-inter-character-001-ref.html
new file mode 100644
index 0000000000..0a42a5cf8c
--- /dev/null
+++ b/layout/reftests/w3c-css/submitted/text3/text-justify-inter-character-001-ref.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>CSS Text 7.4. Justification Method: text-justify: inter-character</title>
+<link rel="author" title="Chun-Min (Jeremy) Chen" href="mailto:jeremychen@mozilla.com">
+<link rel="author" title="Mozilla" href="https://www.mozilla.org">
+<style type='text/css'>
+p {
+ font-size: 1.5em;
+ border: 1px solid black;
+ padding: 10px;
+ margin-right: 310px;
+}
+.right {
+ float: right;
+}
+</style>
+</head>
+<body>
+<p lang="en">X<span class="right">X</span></p>
+<p lang="ja">文<span class="right">字</span></p>
+</body>
+</html>
diff --git a/layout/reftests/w3c-css/submitted/text3/text-justify-inter-character-001.html b/layout/reftests/w3c-css/submitted/text3/text-justify-inter-character-001.html
new file mode 100644
index 0000000000..639ab7ecb7
--- /dev/null
+++ b/layout/reftests/w3c-css/submitted/text3/text-justify-inter-character-001.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>CSS Text 7.4. Justification Method: text-justify: inter-character</title>
+<link rel="author" title="Chun-Min (Jeremy) Chen" href="mailto:jeremychen@mozilla.com">
+<link rel="author" title="Mozilla" href="https://www.mozilla.org">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#text-justify-property">
+<link rel='match' href='text-justify-inter-character-001-ref.html'>
+<meta name="assert" content="text-justify:inter-character means justification adjusts spacing between each pair of adjacent typographic character units.">
+<style type='text/css'>
+p {
+ font-size: 1.5em;
+ border: 1px solid black;
+ padding: 10px;
+ margin-right: 310px;
+}
+.test {
+ text-align-last: justify;
+ text-justify: inter-character;
+}
+</style>
+</head>
+<body>
+<p lang="en" class="test">XX</p>
+<p lang="ja" class="test">文字</p>
+</body>
+</html>
diff --git a/layout/reftests/w3c-css/submitted/text3/text-justify-inter-word-001-ref.html b/layout/reftests/w3c-css/submitted/text3/text-justify-inter-word-001-ref.html
new file mode 100644
index 0000000000..687e864e7d
--- /dev/null
+++ b/layout/reftests/w3c-css/submitted/text3/text-justify-inter-word-001-ref.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>CSS Text 7.4. Justification Method: text-justify: inter-word</title>
+<link rel="author" title="Chun-Min (Jeremy) Chen" href="mailto:jeremychen@mozilla.com">
+<link rel="author" title="Mozilla" href="https://www.mozilla.org">
+<style type='text/css'>
+p {
+ font-size: 1.5em;
+ border: 1px solid black;
+ padding: 10px;
+ margin-right: 310px;
+}
+.right {
+ float: right;
+}
+</style>
+</head>
+<body>
+<p lang="en">Latin<span class="right">text</span></p>
+<p lang="ja">日本<span class="right">文字</span></p>
+<p lang="th">อักษรไทย<span class="right">อักษรไทย</span></p>
+</body>
+</html>
diff --git a/layout/reftests/w3c-css/submitted/text3/text-justify-inter-word-001.html b/layout/reftests/w3c-css/submitted/text3/text-justify-inter-word-001.html
new file mode 100644
index 0000000000..75aec2f5f6
--- /dev/null
+++ b/layout/reftests/w3c-css/submitted/text3/text-justify-inter-word-001.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>CSS Text 7.4. Justification Method: text-justify: inter-word</title>
+<link rel="author" title="Chun-Min (Jeremy) Chen" href="mailto:jeremychen@mozilla.com">
+<link rel="author" title="Mozilla" href="https://www.mozilla.org">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#text-justify-property">
+<link rel='match' href='text-justify-inter-word-001-ref.html'>
+<meta name="assert" content="text-justify:inter-word means justification adjusts spacing at word separators only.">
+<style type='text/css'>
+p {
+ font-size: 1.5em;
+ border: 1px solid black;
+ padding: 10px;
+ margin-right: 310px;
+}
+.test {
+ text-align-last: justify;
+ text-justify: inter-word;
+}
+</style>
+</head>
+<body>
+<p lang="en" class="test">Latin text</p>
+<p lang="ja" class="test">日本 文字</p>
+<p lang="th" class="test">อักษรไทย อักษรไทย</p>
+</body>
+</html>
diff --git a/layout/reftests/w3c-css/submitted/text3/text-justify-none-001-ref.html b/layout/reftests/w3c-css/submitted/text3/text-justify-none-001-ref.html
new file mode 100644
index 0000000000..c8500ac9f3
--- /dev/null
+++ b/layout/reftests/w3c-css/submitted/text3/text-justify-none-001-ref.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>CSS Text 7.4. Justification Method: text-justify: none</title>
+<link rel="author" title="Chun-Min (Jeremy) Chen" href="mailto:jeremychen@mozilla.com">
+<link rel="author" title="Mozilla" href="https://www.mozilla.org">
+<style type='text/css'>
+p {
+ font-size: 1.5em;
+ border: 1px solid black;
+ padding: 10px;
+ margin-right: 310px;
+}
+</style>
+</head>
+<body>
+<p lang="en">Latin text</p>
+<p lang="ja">日本 文字</p>
+<p lang="th">อักษรไทย อักษรไทย</p>
+</body>
+</html>
diff --git a/layout/reftests/w3c-css/submitted/text3/text-justify-none-001.html b/layout/reftests/w3c-css/submitted/text3/text-justify-none-001.html
new file mode 100644
index 0000000000..2b55111954
--- /dev/null
+++ b/layout/reftests/w3c-css/submitted/text3/text-justify-none-001.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>CSS Text 7.4. Justification Method: text-justify: none</title>
+<link rel="author" title="Chun-Min (Jeremy) Chen" href="mailto:jeremychen@mozilla.com">
+<link rel="author" title="Mozilla" href="https://www.mozilla.org">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#text-justify-property">
+<link rel='match' href='text-justify-none-001-ref.html'>
+<meta name="assert" content="text-justify:none means justification is disabled: there are no justification opportunities within the text.">
+<style type='text/css'>
+p {
+ font-size: 1.5em;
+ border: 1px solid black;
+ padding: 10px;
+ margin-right: 310px;
+}
+.test {
+ text-align-last: justify;
+ text-justify: none;
+}
+</style>
+</head>
+<body>
+<p lang="en" class="test">Latin text</p>
+<p lang="ja" class="test">日本 文字</p>
+<p lang="th" class="test">อักษรไทย อักษรไทย</p>
+</body>
+</html>
diff --git a/layout/style/nsCSSKeywordList.h b/layout/style/nsCSSKeywordList.h
index 933ff6e7b6..94968faca3 100644
--- a/layout/style/nsCSSKeywordList.h
+++ b/layout/style/nsCSSKeywordList.h
@@ -238,6 +238,7 @@ CSS_KEY(disc, disc)
CSS_KEY(disclosure-closed, disclosure_closed)
CSS_KEY(disclosure-open, disclosure_open)
CSS_KEY(discretionary-ligatures, discretionary_ligatures)
+CSS_KEY(distribute, distribute)
CSS_KEY(dot, dot)
CSS_KEY(dotted, dotted)
CSS_KEY(double, double)
@@ -333,7 +334,8 @@ CSS_KEY(inline-start, inline_start)
CSS_KEY(inline-table, inline_table)
CSS_KEY(inset, inset)
CSS_KEY(inside, inside)
-// CSS_KEY(inter-character, inter_character) // TODO see bug 1055672
+CSS_KEY(inter-character, inter_character)
+CSS_KEY(inter-word, inter_word)
CSS_KEY(interpolatematrix, interpolatematrix)
CSS_KEY(intersect, intersect)
CSS_KEY(isolate, isolate)
diff --git a/layout/style/nsCSSPropList.h b/layout/style/nsCSSPropList.h
index 6931d8c2b4..b04921dcb5 100644
--- a/layout/style/nsCSSPropList.h
+++ b/layout/style/nsCSSPropList.h
@@ -4027,6 +4027,17 @@ CSS_PROP_TEXT(
nullptr,
offsetof(nsStyleText, mTextIndent),
eStyleAnimType_Coord)
+CSS_PROP_TEXT(
+ text-justify,
+ text_justify,
+ TextJustify,
+ CSS_PROPERTY_PARSE_VALUE |
+ CSS_PROPERTY_APPLIES_TO_PLACEHOLDER,
+ "layout.css.text-justify.enabled",
+ VARIANT_HK,
+ kTextJustifyKTable,
+ CSS_PROP_NO_OFFSET,
+ eStyleAnimType_Discrete)
CSS_PROP_VISIBILITY(
text-orientation,
text_orientation,
diff --git a/layout/style/nsCSSProps.cpp b/layout/style/nsCSSProps.cpp
index f3a7f898de..9805eae14e 100644
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -2035,6 +2035,17 @@ KTableEntry nsCSSProps::kTextAlignLastKTable[] = {
{ eCSSKeyword_UNKNOWN, -1 }
};
+const KTableEntry nsCSSProps::kTextJustifyKTable[] = {
+ { eCSSKeyword_none, StyleTextJustify::None },
+ { eCSSKeyword_auto, StyleTextJustify::Auto },
+ { eCSSKeyword_inter_word, StyleTextJustify::InterWord },
+ { eCSSKeyword_inter_character, StyleTextJustify::InterCharacter },
+ // For legacy reasons, UAs must also support the keyword "distribute" with
+ // the exact same meaning and behavior as "inter-character".
+ { eCSSKeyword_distribute, StyleTextJustify::InterCharacter },
+ { eCSSKeyword_UNKNOWN, -1 }
+};
+
const KTableEntry nsCSSProps::kTextCombineUprightKTable[] = {
{ eCSSKeyword_none, NS_STYLE_TEXT_COMBINE_UPRIGHT_NONE },
{ eCSSKeyword_all, NS_STYLE_TEXT_COMBINE_UPRIGHT_ALL },
diff --git a/layout/style/nsCSSProps.h b/layout/style/nsCSSProps.h
index ab78e61741..dfe35afd82 100644
--- a/layout/style/nsCSSProps.h
+++ b/layout/style/nsCSSProps.h
@@ -869,6 +869,7 @@ public:
static const KTableEntry kTextEmphasisPositionKTable[];
static const KTableEntry kTextEmphasisStyleFillKTable[];
static const KTableEntry kTextEmphasisStyleShapeKTable[];
+ static const KTableEntry kTextJustifyKTable[];
static const KTableEntry kTextOrientationKTable[];
static const KTableEntry kTextOverflowKTable[];
static const KTableEntry kTextTransformKTable[];
diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp
index 4eb24b76b9..4f8d3edf66 100644
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -3875,6 +3875,16 @@ nsComputedDOMStyle::DoGetTextIndent()
}
already_AddRefed<CSSValue>
+nsComputedDOMStyle::DoGetTextJustify()
+{
+ RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
+ val->SetIdent(
+ nsCSSProps::ValueToKeywordEnum(StyleText()->mTextJustify,
+ nsCSSProps::kTextJustifyKTable));
+ return val.forget();
+}
+
+already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetTextOrientation()
{
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
diff --git a/layout/style/nsComputedDOMStyle.h b/layout/style/nsComputedDOMStyle.h
index 223b29a141..27e2086e92 100644
--- a/layout/style/nsComputedDOMStyle.h
+++ b/layout/style/nsComputedDOMStyle.h
@@ -421,6 +421,7 @@ private:
already_AddRefed<CSSValue> DoGetTextEmphasisPosition();
already_AddRefed<CSSValue> DoGetTextEmphasisStyle();
already_AddRefed<CSSValue> DoGetTextIndent();
+ already_AddRefed<CSSValue> DoGetTextJustify();
already_AddRefed<CSSValue> DoGetTextOrientation();
already_AddRefed<CSSValue> DoGetTextOverflow();
already_AddRefed<CSSValue> DoGetTextTransform();
diff --git a/layout/style/nsComputedDOMStylePropertyList.h b/layout/style/nsComputedDOMStylePropertyList.h
index 7c0457e342..1983208acc 100644
--- a/layout/style/nsComputedDOMStylePropertyList.h
+++ b/layout/style/nsComputedDOMStylePropertyList.h
@@ -239,6 +239,7 @@ COMPUTED_STYLE_PROP(text_emphasis_color, TextEmphasisColor)
COMPUTED_STYLE_PROP(text_emphasis_position, TextEmphasisPosition)
COMPUTED_STYLE_PROP(text_emphasis_style, TextEmphasisStyle)
COMPUTED_STYLE_PROP(text_indent, TextIndent)
+COMPUTED_STYLE_PROP(text_justify, TextJustify)
COMPUTED_STYLE_PROP(text_orientation, TextOrientation)
COMPUTED_STYLE_PROP(text_overflow, TextOverflow)
COMPUTED_STYLE_PROP(text_shadow, TextShadow)
diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp
index fa29fe0f17..9b9fc3948e 100644
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -1414,6 +1414,7 @@ struct SetEnumValueHelper
DEFINE_ENUM_CLASS_SETTER(StyleFillRule, Nonzero, Evenodd)
DEFINE_ENUM_CLASS_SETTER(StyleFloat, None, InlineEnd)
DEFINE_ENUM_CLASS_SETTER(StyleFloatEdge, ContentBox, MarginBox)
+ DEFINE_ENUM_CLASS_SETTER(StyleTextJustify, None, InterCharacter)
DEFINE_ENUM_CLASS_SETTER(StyleUserFocus, None, SelectMenu)
DEFINE_ENUM_CLASS_SETTER(StyleUserSelect, None, MozText)
DEFINE_ENUM_CLASS_SETTER(StyleUserInput, None, Auto)
@@ -4783,6 +4784,12 @@ nsRuleNode::ComputeTextData(void* aStartStruct,
SETCOORD_UNSET_INHERIT,
aContext, mPresContext, conditions);
+ // text-justify: enum, inherit, initial
+ SetValue(*aRuleData->ValueForTextJustify(), text->mTextJustify, conditions,
+ SETVAL_ENUMERATED | SETVAL_UNSET_INHERIT,
+ parentText->mTextJustify,
+ StyleTextJustify::Auto);
+
// text-transform: enum, inherit, initial
SetValue(*aRuleData->ValueForTextTransform(), text->mTextTransform, conditions,
SETVAL_ENUMERATED | SETVAL_UNSET_INHERIT,
diff --git a/layout/style/nsStyleConsts.h b/layout/style/nsStyleConsts.h
index ee78dcb64d..be588113e9 100644
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -185,6 +185,14 @@ enum class StyleShapeSourceType : uint8_t {
Box,
};
+// text-justify
+enum class StyleTextJustify : uint8_t {
+ None,
+ Auto,
+ InterWord,
+ InterCharacter,
+};
+
// user-focus
enum class StyleUserFocus : uint8_t {
None,
diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp
index 2f12d62018..68ae88d249 100644
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -3797,6 +3797,7 @@ nsStyleText::nsStyleText(StyleStructContext aContext)
, mTextAlignLast(NS_STYLE_TEXT_ALIGN_AUTO)
, mTextAlignTrue(false)
, mTextAlignLastTrue(false)
+ , mTextJustify(StyleTextJustify::Auto)
, mTextTransform(NS_STYLE_TEXT_TRANSFORM_NONE)
, mWhiteSpace(NS_STYLE_WHITESPACE_NORMAL)
, mWordBreak(NS_STYLE_WORDBREAK_NORMAL)
@@ -3833,6 +3834,7 @@ nsStyleText::nsStyleText(const nsStyleText& aSource)
, mTextAlignLast(aSource.mTextAlignLast)
, mTextAlignTrue(false)
, mTextAlignLastTrue(false)
+ , mTextJustify(aSource.mTextJustify)
, mTextTransform(aSource.mTextTransform)
, mWhiteSpace(aSource.mWhiteSpace)
, mWordBreak(aSource.mWordBreak)
@@ -3894,6 +3896,7 @@ nsStyleText::CalcDifference(const nsStyleText& aNewData) const
(mTextSizeAdjust != aNewData.mTextSizeAdjust) ||
(mLetterSpacing != aNewData.mLetterSpacing) ||
(mLineHeight != aNewData.mLineHeight) ||
+ (mTextJustify != aNewData.mTextJustify) ||
(mTextIndent != aNewData.mTextIndent) ||
(mWordSpacing != aNewData.mWordSpacing) ||
(mTabSize != aNewData.mTabSize)) {
diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h
index ca5d030566..41bb356a8b 100644
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -2068,6 +2068,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleText
uint8_t mTextAlignLast; // [inherited] see nsStyleConsts.h
bool mTextAlignTrue : 1; // [inherited] see nsStyleConsts.h
bool mTextAlignLastTrue : 1; // [inherited] see nsStyleConsts.h
+ mozilla::StyleTextJustify mTextJustify; // [inherited]
uint8_t mTextTransform; // [inherited] see nsStyleConsts.h
uint8_t mWhiteSpace; // [inherited] see nsStyleConsts.h
uint8_t mWordBreak; // [inherited] see nsStyleConsts.h
diff --git a/layout/style/test/property_database.js b/layout/style/test/property_database.js
index 62d413d983..272931c15e 100644
--- a/layout/style/test/property_database.js
+++ b/layout/style/test/property_database.js
@@ -5694,6 +5694,17 @@ if (IsCSSPropertyPrefEnabled("layout.css.text-combine-upright.enabled")) {
}
}
+if (IsCSSPropertyPrefEnabled("layout.css.text-justify.enabled")) {
+ gCSSProperties["text-justify"] = {
+ domProp: "textJustify",
+ inherited: true,
+ type: CSS_TYPE_LONGHAND,
+ initial_values: [ "auto" ],
+ other_values: [ "none", "inter-word", "inter-character", "distribute" ],
+ invalid_values: []
+ };
+}
+
if (IsCSSPropertyPrefEnabled("svg.paint-order.enabled")) {
gCSSProperties["paint-order"] = {
domProp: "paintOrder",
diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js
index ff47dc8e3b..689ef31c6a 100644
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -2502,6 +2502,9 @@ pref("layout.css.convertFromNode.enabled", true);
// Is support for CSS "text-align: unsafe X" enabled?
pref("layout.css.text-align-unsafe-value.enabled", false);
+// Is support for CSS text-justify property enabled?
+pref("layout.css.text-justify.enabled", true);
+
// Is support for CSS "float: inline-{start,end}" and
// "clear: inline-{start,end}" enabled?
#if defined(MOZ_B2G) || !defined(RELEASE_OR_BETA)
diff --git a/testing/profiles/prefs_general.js b/testing/profiles/prefs_general.js
index 91218b5f39..a9572b912b 100644
--- a/testing/profiles/prefs_general.js
+++ b/testing/profiles/prefs_general.js
@@ -181,6 +181,9 @@ user_pref("layout.css.prefixes.device-pixel-ratio-webkit", true);
// Enable CSS shape-outside for testing
user_pref("layout.css.shape-outside.enabled", true);
+// Enable CSS text-justify for testing
+user_pref("layout.css.text-justify.enabled", true);
+
// Disable spammy layout warnings because they pollute test logs
user_pref("layout.spammy_warnings.enabled", false);