Use content-language from http-equiv to set document locale and font

https://bugs.webkit.org/show_bug.cgi?id=76701

Patch by Matt Falkenhagen <falken@chromium.org> on 2012-02-02
Reviewed by Darin Adler.

Source/WebCore:

So far, only content-language set through http-equiv is used; the HTTP Content-Language
header is not yet supported.

Tests: fast/text/content-language-case-insensitivity.html
       fast/text/content-language-mapped-to-webkit-locale.html
       fast/text/international/content-language-font-selection-expected.html
       fast/text/international/content-language-font-selection.html
       fast/text/international/content-language-with-subtags-expected.html
       fast/text/international/content-language-with-subtags.html

* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::styleForDocument): Use content language when selecting initial font.
* dom/Document.cpp:
(WebCore::Document::setContentLanguage): Recalculate style so language is taken into account.
(WebCore):
* dom/Document.h:
(Document):

LayoutTests:

Add tests that content-language from http-equiv sets document locale and is used in font selection.

* fast/text/content-language-case-insensitivity-expected.txt: Added.
* fast/text/content-language-case-insensitivity.html: Added.
* fast/text/content-language-mapped-to-webkit-locale-expected.txt: Added.
* fast/text/content-language-mapped-to-webkit-locale.html: Added.
* fast/text/international/content-language-font-selection-expected.html: Added.
* fast/text/international/content-language-font-selection.html: Added.
* fast/text/international/content-language-with-subtags-expected.html: Added.
* fast/text/international/content-language-with-subtags.html: Added.
* fast/text/lang-mapped-to-webkit-locale-expected.txt:
* fast/text/lang-mapped-to-webkit-locale.xhtml: Fix some style issues.
* fast/text/xml-lang-ignored-in-html-expected.txt:
* fast/text/xml-lang-ignored-in-html.html: Fix some style issues.
* platform/efl/Skipped: Skip tests using overridePreference("WebKit*FontMap"...) on non-Chromium ports.
* platform/gtk-wk2/Skipped: Ditto.
* platform/gtk/Skipped: Ditto.
* platform/mac/Skipped: Ditto.
* platform/qt/Skipped: Ditto.
* platform/win/Skipped: Ditto.
* platform/wincairo/Skipped: Ditto.
* platform/wk2/Skipped: Ditto.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@106632 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1dfe7331
2012-02-02 Matt Falkenhagen <falken@chromium.org>
Use content-language from http-equiv to set document locale and font
https://bugs.webkit.org/show_bug.cgi?id=76701
Reviewed by Darin Adler.
Add tests that content-language from http-equiv sets document locale and is used in font selection.
* fast/text/content-language-case-insensitivity-expected.txt: Added.
* fast/text/content-language-case-insensitivity.html: Added.
* fast/text/content-language-mapped-to-webkit-locale-expected.txt: Added.
* fast/text/content-language-mapped-to-webkit-locale.html: Added.
* fast/text/international/content-language-font-selection-expected.html: Added.
* fast/text/international/content-language-font-selection.html: Added.
* fast/text/international/content-language-with-subtags-expected.html: Added.
* fast/text/international/content-language-with-subtags.html: Added.
* fast/text/lang-mapped-to-webkit-locale-expected.txt:
* fast/text/lang-mapped-to-webkit-locale.xhtml: Fix some style issues.
* fast/text/xml-lang-ignored-in-html-expected.txt:
* fast/text/xml-lang-ignored-in-html.html: Fix some style issues.
* platform/efl/Skipped: Skip tests using overridePreference("WebKit*FontMap"...) on non-Chromium ports.
* platform/gtk-wk2/Skipped: Ditto.
* platform/gtk/Skipped: Ditto.
* platform/mac/Skipped: Ditto.
* platform/qt/Skipped: Ditto.
* platform/win/Skipped: Ditto.
* platform/wincairo/Skipped: Ditto.
* platform/wk2/Skipped: Ditto.
2012-02-02 Csaba Osztrogonác <ossy@webkit.org>
[Qt] Unreviewed gardening after r106554.
Test for bug 76701: map content-language to -webkit-locale. This particular test tests that the matching of the http-equiv attribute to the content-language state is case insensitive.
PASS languageOfNode('x1') is "ja-JP"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="cONtENT-LAnguAGE" content="ja-JP">
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=76701">bug 76701</a>:
map content-language to -webkit-locale. This particular test tests that the
matching of the http-equiv attribute to the content-language state is case
insensitive.
</p>
<div id="console"></div>
<div id="x1"/>
<script>
function languageOfNode(id) {
var element = document.getElementById(id);
return window.getComputedStyle(element).webkitLocale;
}
shouldBeEqualToString("languageOfNode('x1')", "ja-JP");
var successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
Test for bug 76701: map content-language to -webkit-locale.
PASS languageOfNode('x1') is "zh-CN"
PASS languageOfNode('m1') is "ar"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-language" content="zh-CN">
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=76701">bug 76701</a>:
map content-language to -webkit-locale.</p>
<div id="console"></div>
<div id="x1"/>
<div lang="ar" id="m1"/>
<script>
function languageOfNode(id) {
var element = document.getElementById(id);
return window.getComputedStyle(element).webkitLocale;
}
shouldBeEqualToString("languageOfNode('x1')", "zh-CN");
shouldBeEqualToString("languageOfNode('m1')", "ar");
var successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
<html>
<head>
<title>Test font selection based on content-language</title>
</head>
<body style="font-family: 'Ahem'">
This is in Ahem font.
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-language" content="zh-TW">
<script>
if (window.layoutTestController)
layoutTestController.overridePreference("WebKitStandardFontMap", [ "Hant", "Ahem" ]);
</script>
<title>Test font selection based on content-language</title>
</head>
<body>
<!-- This tests font selection based on content-language <https://bugs.webkit.org/show_bug.cgi?id=76701>. The text should be in Ahem font. -->
This is in Ahem font.
</body>
</html>
<html>
<head>
<title>Test font selection based on content-language</title>
</head>
<body style="font-family: 'Ahem'">
This is in Ahem font.
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-language" content="zh_tw_foobar">
<script>
if (window.layoutTestController)
layoutTestController.overridePreference("WebKitStandardFontMap", [ "Hant", "Ahem" ]);
</script>
<title>Test font selection based on content-language</title>
</head>
<body>
<!-- This tests font selection based on content-language
<https://bugs.webkit.org/show_bug.cgi?id=76701>, when content-language has
extra subtags. The language "zh_tw_foobar" should match Han Traditional script,
so the text should be in Ahem font. -->
This is in Ahem font.
</body>
</html>
This is a test for bug 67586. HTML attributes lang and xml:lang are mapped to '-webkit-locale' to use their value in font fallback.
PASS getLangOfNode('x1') is "ja"
PASS getLangOfNode('x2') is "ja"
PASS getLangOfNode('x3') is "ja"
PASS getLangOfNode('l1') is "zh"
PASS getLangOfNode('l2') is "zh"
PASS getLangOfNode('l3') is "zh"
PASS getLangOfNode('m1') is "ko"
PASS getLangOfNode('m2') is "fr"
PASS getLangOfNode('m3') is "fr"
PASS getLangOfNode('n1') is "fr"
PASS getLangOfNode('n2') is "fr"
PASS getLangOfNode('n3') is "sv"
PASS getLangOfNode('p1') is "ja"
PASS getLangOfNode('p2') is "auto"
PASS getLangOfNode('q1') is "ja"
PASS getLangOfNode('q2') is "auto"
PASS getLangOfNode('q3') is "auto"
PASS getLangOfNode('q4') is "ar"
PASS getLangOfNode('q5') is "auto"
PASS getLangOfNode('q6') is "' '"
PASS getLangOfNode('q7') is "auto"
PASS getLangOfNode('q8') is "xyzzy"
PASS getLangOfNode('q9') is "'][;][['"
PASS languageOfNode('x1') is "ja"
PASS languageOfNode('x2') is "ja"
PASS languageOfNode('x3') is "ja"
PASS languageOfNode('l1') is "zh"
PASS languageOfNode('l2') is "zh"
PASS languageOfNode('l3') is "zh"
PASS languageOfNode('m1') is "ko"
PASS languageOfNode('m2') is "fr"
PASS languageOfNode('m3') is "fr"
PASS languageOfNode('n1') is "fr"
PASS languageOfNode('n2') is "fr"
PASS languageOfNode('n3') is "sv"
PASS languageOfNode('p1') is "ja"
PASS languageOfNode('p2') is "auto"
PASS languageOfNode('q1') is "ja"
PASS languageOfNode('q2') is "auto"
PASS languageOfNode('q3') is "auto"
PASS languageOfNode('q4') is "ar"
PASS languageOfNode('q5') is "auto"
PASS languageOfNode('q6') is "' '"
PASS languageOfNode('q7') is "auto"
PASS languageOfNode('q8') is "xyzzy"
PASS languageOfNode('q9') is "'][;][['"
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -24,33 +24,33 @@
<div lang="][;][[" id="q9"></div>
</div>
<script>
function getLangOfNode(n) {
e = document.getElementById(n);
return window.getComputedStyle(e).webkitLocale;
function languageOfNode(id) {
var element = document.getElementById(id);
return window.getComputedStyle(element).webkitLocale;
}
shouldBeEqualToString("getLangOfNode('x1')", "ja");
shouldBeEqualToString("getLangOfNode('x2')", "ja");
shouldBeEqualToString("getLangOfNode('x3')", "ja");
shouldBeEqualToString("getLangOfNode('l1')", "zh");
shouldBeEqualToString("getLangOfNode('l2')", "zh");
shouldBeEqualToString("getLangOfNode('l3')", "zh");
shouldBeEqualToString("getLangOfNode('m1')", "ko");
shouldBeEqualToString("getLangOfNode('m2')", "fr");
shouldBeEqualToString("getLangOfNode('m3')", "fr");
shouldBeEqualToString("getLangOfNode('n1')", "fr");
shouldBeEqualToString("getLangOfNode('n2')", "fr");
shouldBeEqualToString("getLangOfNode('n3')", "sv");
shouldBeEqualToString("getLangOfNode('p1')", "ja");
shouldBeEqualToString("getLangOfNode('p2')", "auto");
shouldBeEqualToString("getLangOfNode('q1')", "ja");
shouldBeEqualToString("getLangOfNode('q2')", "auto");
shouldBeEqualToString("getLangOfNode('q3')", "auto");
shouldBeEqualToString("getLangOfNode('q4')", "ar");
shouldBeEqualToString("getLangOfNode('q5')", "auto");
shouldBeEqualToString("getLangOfNode('q6')", "' '");
shouldBeEqualToString("getLangOfNode('q7')", "auto");
shouldBeEqualToString("getLangOfNode('q8')", "xyzzy");
shouldBeEqualToString("getLangOfNode('q9')", "'][;][['");
shouldBeEqualToString("languageOfNode('x1')", "ja");
shouldBeEqualToString("languageOfNode('x2')", "ja");
shouldBeEqualToString("languageOfNode('x3')", "ja");
shouldBeEqualToString("languageOfNode('l1')", "zh");
shouldBeEqualToString("languageOfNode('l2')", "zh");
shouldBeEqualToString("languageOfNode('l3')", "zh");
shouldBeEqualToString("languageOfNode('m1')", "ko");
shouldBeEqualToString("languageOfNode('m2')", "fr");
shouldBeEqualToString("languageOfNode('m3')", "fr");
shouldBeEqualToString("languageOfNode('n1')", "fr");
shouldBeEqualToString("languageOfNode('n2')", "fr");
shouldBeEqualToString("languageOfNode('n3')", "sv");
shouldBeEqualToString("languageOfNode('p1')", "ja");
shouldBeEqualToString("languageOfNode('p2')", "auto");
shouldBeEqualToString("languageOfNode('q1')", "ja");
shouldBeEqualToString("languageOfNode('q2')", "auto");
shouldBeEqualToString("languageOfNode('q3')", "auto");
shouldBeEqualToString("languageOfNode('q4')", "ar");
shouldBeEqualToString("languageOfNode('q5')", "auto");
shouldBeEqualToString("languageOfNode('q6')", "' '");
shouldBeEqualToString("languageOfNode('q7')", "auto");
shouldBeEqualToString("languageOfNode('q8')", "xyzzy");
shouldBeEqualToString("languageOfNode('q9')", "'][;][['");
var successfullyParsed = true;
</script>
......
This tests that the attribute in no namespace with no prefix and with the literal localname "xml:lang" is ignored in HTML. See bug 67586.
PASS getLangOfNode('m1') is "auto"
PASS getLangOfNode('n1') is "ko"
PASS getLangOfNode('o1') is "ar"
PASS getLangOfNode('o2') is "ar"
PASS languageOfNode('m1') is "auto"
PASS languageOfNode('n1') is "ko"
PASS languageOfNode('o1') is "ar"
PASS languageOfNode('o2') is "ar"
PASS successfullyParsed is true
TEST COMPLETE
......
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css" />
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<p>This tests that the attribute in no namespace with no prefix and with the literal localname "xml:lang" is ignored in HTML. See
<a href="http://webkit.org/b/67586">bug 67586</a>.</p>
<div id="console"></div>
<div xml:lang="ar" id="m1"></div></div>
<div xml:lang="ar" id="m1"></div>
<div lang="ko"><div xml:lang="ar" id="n1"></div></div>
<div lang="ar" id="o1"><div xml:lang="" id="o2"></div></div>
<script>
function getLangOfNode(n) {
e = document.getElementById(n);
return window.getComputedStyle(e).webkitLocale;
function languageOfNode(id) {
var element = document.getElementById(id);
return window.getComputedStyle(element).webkitLocale;
}
shouldBeEqualToString("getLangOfNode('m1')", "auto");
shouldBeEqualToString("getLangOfNode('n1')", "ko");
shouldBeEqualToString("getLangOfNode('o1')", "ar");
shouldBeEqualToString("getLangOfNode('o2')", "ar");
shouldBeEqualToString("languageOfNode('m1')", "auto");
shouldBeEqualToString("languageOfNode('n1')", "ko");
shouldBeEqualToString("languageOfNode('o1')", "ar");
shouldBeEqualToString("languageOfNode('o2')", "ar");
var successfullyParsed = true;
</script>
......
......@@ -718,6 +718,8 @@ fast/parser/noscript-with-javascript-enabled.html
fast/parser/pre-html5-parser-quirks.html
fast/repaint/no-caret-repaint-in-non-content-editable-element.html
fast/spatial-navigation
fast/text/international/content-language-font-selection.html
fast/text/international/content-language-with-subtags.html
fast/text/international/locale-sensitive-fonts.html
fast/text/zero-font-size.html
fast/viewport/viewport-128.html
......
......@@ -208,6 +208,8 @@ fast/events/wheelevent-direction-inverted-from-device.html
# WebKit2 needs layoutTestController.overridePreference
# https://bugs.webkit.org/show_bug.cgi?id=42197
fast/text/international/content-language-font-selection.html
fast/text/international/content-language-with-subtags.html
fast/text/international/locale-sensitive-fonts.html
fast/repaint/no-caret-repaint-in-non-content-editable-element.html
editing/selection/caret-mode-paragraph-keys-navigation.html
......
......@@ -374,6 +374,8 @@ fast/mutation
# layoutTestController.overridePreference("WebKit*FontMap"...) is not
# supported.
fast/text/international/content-language-font-selection.html
fast/text/international/content-language-with-subtags.html
fast/text/international/locale-sensitive-fonts.html
# Needs layoutTestController.enableAutoResizeMode()
......
......@@ -493,6 +493,8 @@ fast/canvas/webgl/uniform-location-length-limits.html
fast/repaint/table-extra-bottom-grow.html
# DRT doesn't support overridePreference("WebKit*FontMap"...)
fast/text/international/content-language-font-selection.html
fast/text/international/content-language-with-subtags.html
fast/text/international/locale-sensitive-fonts.html
# Web Intents is not yet enabled.
......
......@@ -994,6 +994,8 @@ java
# Missing DRT ability to override 'standard' preferences.
fast/dom/Window/timer-resume-on-navigation-back.html
fast/text/international/content-language-font-selection.html
fast/text/international/content-language-with-subtags.html
fast/text/international/locale-sensitive-fonts.html
loader/go-back-to-different-window-size.html
......
......@@ -1502,6 +1502,8 @@ fast/events/platform-wheelevent-paging-y-in-scrolling-div.html
fast/events/platform-wheelevent-paging-y-in-scrolling-page.html
# DRT doesn't support overridePreference("WebKit*FontMap"...)
fast/text/international/content-language-font-selection.html
fast/text/international/content-language-with-subtags.html
fast/text/international/locale-sensitive-fonts.html
# Web Intents is not yet enabled.
......
......@@ -2026,6 +2026,8 @@ fast/events/platform-wheelevent-paging-y-in-scrolling-div.html
fast/events/platform-wheelevent-paging-y-in-scrolling-page.html
# DRT doesn't support overridePreference("WebKit*FontMap"...)
fast/text/international/content-language-font-selection.html
fast/text/international/content-language-with-subtags.html
fast/text/international/locale-sensitive-fonts.html
# Web Intents is not yet enabled.
......
......@@ -290,6 +290,8 @@ fast/harness/override-preferences-2.html
fast/images/animated-gif-restored-from-bfcache.html
fast/repaint/no-caret-repaint-in-non-content-editable-element.html
fast/text/zero-font-size.html
fast/text/international/content-language-font-selection.html
fast/text/international/content-language-with-subtags.html
fast/text/international/locale-sensitive-fonts.html
css3/filters/effect-combined.html
css3/filters/filter-repaint.html
......
2012-02-02 Matt Falkenhagen <falken@chromium.org>
Use content-language from http-equiv to set document locale and font
https://bugs.webkit.org/show_bug.cgi?id=76701
Reviewed by Darin Adler.
So far, only content-language set through http-equiv is used; the HTTP Content-Language
header is not yet supported.
Tests: fast/text/content-language-case-insensitivity.html
fast/text/content-language-mapped-to-webkit-locale.html
fast/text/international/content-language-font-selection-expected.html
fast/text/international/content-language-font-selection.html
fast/text/international/content-language-with-subtags-expected.html
fast/text/international/content-language-with-subtags.html
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::styleForDocument): Use content language when selecting initial font.
* dom/Document.cpp:
(WebCore::Document::setContentLanguage): Recalculate style so language is taken into account.
(WebCore):
* dom/Document.h:
(Document):
2012-02-02 Sheriff Bot <webkit.review.bot@gmail.com>
Unreviewed, rolling out r106620.
......@@ -1403,6 +1403,7 @@ PassRefPtr<RenderStyle> CSSStyleSelector::styleForDocument(Document* document, C
documentStyle->setZoom(frame ? frame->pageZoomFactor() : 1);
documentStyle->setPageScaleTransform(frame ? frame->frameScaleFactor() : 1);
documentStyle->setUserModify(document->inDesignMode() ? READ_WRITE : READ_ONLY);
documentStyle->setLocale(document->contentLanguage());
Element* docElement = document->documentElement();
RenderObject* docElementRenderer = docElement ? docElement->renderer() : 0;
......@@ -1433,12 +1434,13 @@ PassRefPtr<RenderStyle> CSSStyleSelector::styleForDocument(Document* document, C
FontDescription fontDescription;
fontDescription.setUsePrinterFont(document->printing());
fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle->locale()));
if (Settings* settings = document->settings()) {
fontDescription.setRenderingMode(settings->fontRenderingMode());
const AtomicString& stdfont = settings->standardFontFamily();
if (!stdfont.isEmpty()) {
const AtomicString& standardFont = settings->standardFontFamily(fontDescription.script());
if (!standardFont.isEmpty()) {
fontDescription.setGenericFamily(FontDescription::StandardFamily);
fontDescription.firstFamily().setFamily(stdfont);
fontDescription.firstFamily().setFamily(standardFont);
fontDescription.firstFamily().appendFamily(0);
}
fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
......
......@@ -1102,6 +1102,16 @@ void Document::setCharset(const String& charset)
decoder()->setEncoding(charset, TextResourceDecoder::UserChosenEncoding);
}
void Document::setContentLanguage(const String& language)
{
if (m_contentLanguage == language)
return;
m_contentLanguage = language;
// Recalculate style so language is used when selecting the initial font.
styleSelectorChanged(DeferRecalcStyle);
}
void Document::setXMLVersion(const String& version, ExceptionCode& ec)
{
if (!implementation()->hasFeature("XML", String())) {
......
......@@ -387,7 +387,7 @@ public:
String suggestedMIMEType() const;
String contentLanguage() const { return m_contentLanguage; }
void setContentLanguage(const String& lang) { m_contentLanguage = lang; }
void setContentLanguage(const String&);
String xmlEncoding() const { return m_xmlEncoding; }
String xmlVersion() const { return m_xmlVersion; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment