Bug 1751940 - Language-depeendent quote marks generated with quotes:auto should be based on the lang of the parent. r=layout-reviewers,emilio

This implements the first resolution from https://github.com/w3c/csswg-drafts/issues/5478,
and makes simple cases of quoting a foreign-language snippet work as desired.

Still to do: the match-parent value (second resolution in that issue), required for full
support of nested mixed-language quotes if the author wants the conventions of the
outermost language to propagate down to all nested levels.

Differential Revision: https://phabricator.services.mozilla.com/D137178
This commit is contained in:
Jonathan Kew 2022-01-27 22:12:47 +00:00
Родитель d6911a4e30
Коммит fd6d94936e
3 изменённых файлов: 19 добавлений и 9 удалений

Просмотреть файл

@ -50,10 +50,18 @@ nsString nsQuoteNode::Text() {
const auto& quotesProp = mPseudoFrame->StyleList()->mQuotes;
if (quotesProp.IsAuto()) {
// Look up CLDR-derived quotation marks for current language;
// if none available, use built-in default.
// Look up CLDR-derived quotation marks for the language of the context.
const nsIFrame* frame = mPseudoFrame->GetParent();
// Parent of the pseudo is the element around which the quotes are applied;
// we want lang from *its* parent, unless it is the root.
// XXX Are there other cases where we shouldn't look up to the parent?
if (!frame->Style()->IsRootElementStyle()) {
frame = frame->GetParent();
}
const intl::Quotes* quotes =
intl::QuotesForLang(mPseudoFrame->StyleFont()->mLanguage);
intl::QuotesForLang(frame->StyleFont()->mLanguage);
// If we don't have quote-mark data for the language, use built-in
// defaults.
if (!quotes) {
static const intl::Quotes sDefaultQuotes = {
{0x201c, 0x201d, 0x2018, 0x2019}};

Просмотреть файл

@ -2,14 +2,16 @@
<html lang="en">
<meta charset=utf-8>
<title>CSS Generated Content test: quotes</title>
<meta name="assert" content="quotes:auto with mixed languages uses appropriate CLDR quotes for each language">
<meta name="assert" content="quotes:auto with mixed languages uses appropriate CLDR quotes for each language,
based on the parent language (not the language of the element itself)">
<link rel="author" title="Jonathan Kew" href="mailto:jkew@mozilla.com">
<link rel="help" href="https://drafts.csswg.org/css-content-3/#quotes">
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/5478#issuecomment-701507076">
<link rel=match href="reference/quotes-030-ref.html">
<style>
body { font: 32px serif; quotes: auto; }
body { font: 32px Arial, Helvetica, Noto Sans, DejaVu Sans, FreeSans, sans-serif; quotes: auto; }
</style>
<body>
<p>Test passes if the quote marks in both lines match:
<p>One <q>two <q lang="ja">three <q lang="fr">four</q></q></q>
<p>One “two <span lang="ja">『three <span lang="fr">«four»</span></span>
<p>One “two <span lang="ja">three <span lang="fr">『four』</span></span>

Просмотреть файл

@ -4,9 +4,9 @@
<title>CSS Generated Content reference: quotes</title>
<link rel="author" title="Jonathan Kew" href="mailto:jkew@mozilla.com">
<style>
body { font: 32px serif; }
body { font: 32px Arial, Helvetica, Noto Sans, DejaVu Sans, FreeSans, sans-serif; quotes: auto; }
</style>
<body>
<p>Test passes if the quote marks in both lines match:
<p>One “two <span lang="ja">『three <span lang="fr">«four»</span></span>
<p>One “two <span lang="ja">『three <span lang="fr">«four»</span></span>
<p>One “two <span lang="ja">three <span lang="fr">『four』</span></span>
<p>One “two <span lang="ja">three <span lang="fr">『four』</span></span>