Title: [101504] trunk
Revision
101504
Author
[email protected]
Date
2011-11-30 06:15:20 -0800 (Wed, 30 Nov 2011)

Log Message

@font-face: unquoted local font names containing spaces don't work
https://bugs.webkit.org/show_bug.cgi?id=64783

Source/WebCore:

Allows local font names with spaces.
Rejects the src descriptor if there is invalid identifiers in local(), as the same as Firefox.

Reviewed by Ryosuke Niwa.

Tests: fast/css/font-face-unquoted-local-expected.html
       fast/css/font-face-unquoted-local.html

* css/CSSParser.cpp:
(WebCore::parseFontFaceSrcFunction): Added. Treats multiple identifiers in local() as a font name separated by spaces.
(WebCore::CSSParser::parseFontFaceSrc): Moved the code block which parses local() and format() to parseFontFaceSrcFunction().

LayoutTests:

Adds a test which makes sure that unquoted local font names contains spaces are allowed.

Reviewed by Ryosuke Niwa.

* fast/css/font-face-unquoted-local-expected.html: Added.
* fast/css/font-face-unquoted-local.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (101503 => 101504)


--- trunk/LayoutTests/ChangeLog	2011-11-30 14:08:15 UTC (rev 101503)
+++ trunk/LayoutTests/ChangeLog	2011-11-30 14:15:20 UTC (rev 101504)
@@ -1,3 +1,15 @@
+2011-11-30  Kenichi Ishibashi  <[email protected]>
+
+        @font-face: unquoted local font names containing spaces don't work
+        https://bugs.webkit.org/show_bug.cgi?id=64783
+
+        Adds a test which makes sure that unquoted local font names contains spaces are allowed.
+
+        Reviewed by Ryosuke Niwa.
+
+        * fast/css/font-face-unquoted-local-expected.html: Added.
+        * fast/css/font-face-unquoted-local.html: Added.
+
 2011-11-30  Andreas Kling  <[email protected]>
 
         REGRESSION(r101172): It made fast/dom/clone-node-style.html assert.

Added: trunk/LayoutTests/fast/css/font-face-unquoted-local-expected.html (0 => 101504)


--- trunk/LayoutTests/fast/css/font-face-unquoted-local-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/font-face-unquoted-local-expected.html	2011-11-30 14:15:20 UTC (rev 101504)
@@ -0,0 +1,21 @@
+<style>
+@font-face {
+    font-family: ahem;
+    src: url(../../resources/Ahem.ttf);
+}
+</style>
+<p>This test ensures that unquoted font names are allowed in local().</p>
+
+<p>The text below should be a series of black boxes.</p>
+<p style="font-family: ahem;">FAIL</p>
+
+<p>The text below should not be a series of black boxes.</p>
+<p>SUCCESS</p>
+
+<script>
+if (window.layoutTestController) {
+    layoutTestController.waitUntilDone();
+    document.documentElement.offsetTop;
+    setTimeout(function() { layoutTestController.notifyDone(); }, 200);
+}
+</script>

Added: trunk/LayoutTests/fast/css/font-face-unquoted-local.html (0 => 101504)


--- trunk/LayoutTests/fast/css/font-face-unquoted-local.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/font-face-unquoted-local.html	2011-11-30 14:15:20 UTC (rev 101504)
@@ -0,0 +1,25 @@
+<style>
+@font-face {
+    font-family: ahem;
+    src: local(unquoted name), url(../../resources/Ahem.ttf);
+}
+@font-face {
+    font-family: invalid;
+    src: local(invalid '' name), url(../../resources/Ahem.ttf);
+}
+</style>
+<p>This test ensures that unquoted font names are allowed in local().</p>
+
+<p>The text below should be a series of black boxes.</p>
+<p style="font-family: ahem;">FAIL</p>
+
+<p>The text below should not be a series of black boxes.</p>
+<p style="font-family: invalid;">SUCCESS</p>
+
+<script>
+if (window.layoutTestController) {
+    layoutTestController.waitUntilDone();
+    document.documentElement.offsetTop;
+    setTimeout(function() { layoutTestController.notifyDone(); }, 200);
+}
+</script>

Modified: trunk/Source/WebCore/ChangeLog (101503 => 101504)


--- trunk/Source/WebCore/ChangeLog	2011-11-30 14:08:15 UTC (rev 101503)
+++ trunk/Source/WebCore/ChangeLog	2011-11-30 14:15:20 UTC (rev 101504)
@@ -1,3 +1,20 @@
+2011-11-30  Kenichi Ishibashi  <[email protected]>
+
+        @font-face: unquoted local font names containing spaces don't work
+        https://bugs.webkit.org/show_bug.cgi?id=64783
+
+        Allows local font names with spaces.
+        Rejects the src descriptor if there is invalid identifiers in local(), as the same as Firefox.
+
+        Reviewed by Ryosuke Niwa.
+
+        Tests: fast/css/font-face-unquoted-local-expected.html
+               fast/css/font-face-unquoted-local.html
+
+        * css/CSSParser.cpp:
+        (WebCore::parseFontFaceSrcFunction): Added. Treats multiple identifiers in local() as a font name separated by spaces.
+        (WebCore::CSSParser::parseFontFaceSrc): Moved the code block which parses local() and format() to parseFontFaceSrcFunction().
+
 2011-11-30  Pavel Feldman  <[email protected]>
 
         Web Inspector: get rid of deferred backend->front-end commands processing.

Modified: trunk/Source/WebCore/css/CSSParser.cpp (101503 => 101504)


--- trunk/Source/WebCore/css/CSSParser.cpp	2011-11-30 14:08:15 UTC (rev 101503)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2011-11-30 14:15:20 UTC (rev 101504)
@@ -88,6 +88,7 @@
 #include <wtf/HexNumber.h>
 #include <wtf/dtoa.h>
 #include <wtf/text/StringBuffer.h>
+#include <wtf/text/StringBuilder.h>
 
 #if ENABLE(DASHBOARD_SUPPORT)
 #include "DashboardRegion.h"
@@ -4359,6 +4360,39 @@
     return equalIgnoringCase(val->function->name, "format(") && (args->current()->unit == CSSPrimitiveValue::CSS_STRING || args->current()->unit == CSSPrimitiveValue::CSS_IDENT);
 }
 
+static bool parseFontFaceSrcFunction(CSSParserValue* value, bool& expectComma, bool& allowFormat, RefPtr<CSSFontFaceSrcValue>& uriValue, RefPtr<CSSFontFaceSrcValue>& parsedValue)
+{
+    CSSParserValueList* args = value->function->args.get();
+    if (!args || !args->size())
+        return false;
+
+    if (equalIgnoringCase(value->function->name, "local(") && !expectComma) {
+        expectComma = true;
+        allowFormat = false;
+        uriValue.clear();
+        if (args->current()->unit == CSSPrimitiveValue::CSS_STRING)
+            parsedValue = CSSFontFaceSrcValue::createLocal(args->current()->string);
+        else if (args->current()->unit == CSSPrimitiveValue::CSS_IDENT) {
+            StringBuilder builder;
+            for (CSSParserValue* localValue = args->current(); localValue; localValue = args->next()) {
+                if (localValue->unit != CSSPrimitiveValue::CSS_IDENT)
+                    return false;
+                if (!builder.isEmpty())
+                    builder.append(' ');
+                builder.append(localValue->string);
+            }
+            parsedValue = CSSFontFaceSrcValue::createLocal(builder.toString());
+        }
+    } else if (args->size() == 1 && allowFormat && uriValue && isValidFormatFunction(value)) {
+        expectComma = true;
+        allowFormat = false;
+        uriValue->setFormat(args->current()->string);
+        uriValue.clear();
+        parsedValue.clear();
+    }
+    return true;
+}
+
 bool CSSParser::parseFontFaceSrc()
 {
     RefPtr<CSSValueList> values(CSSValueList::createCommaSeparated());
@@ -4377,24 +4411,14 @@
             allowFormat = true;
             expectComma = true;
         } else if (val->unit == CSSParserValue::Function) {
-            // There are two allowed functions: local() and format().
-            CSSParserValueList* args = val->function->args.get();
-            if (args && args->size() == 1) {
-                if (equalIgnoringCase(val->function->name, "local(") && !expectComma && (args->current()->unit == CSSPrimitiveValue::CSS_STRING || args->current()->unit == CSSPrimitiveValue::CSS_IDENT)) {
-                    expectComma = true;
-                    allowFormat = false;
-                    CSSParserValue* a = args->current();
-                    uriValue.clear();
-                    parsedValue = CSSFontFaceSrcValue::createLocal(a->string);
-                } else if (allowFormat && uriValue && isValidFormatFunction(val)) {
-                    expectComma = true;
-                    allowFormat = false;
-                    uriValue->setFormat(args->current()->string);
-                    uriValue.clear();
-                    m_valueList->next();
-                    continue;
-                }
+            if (!parseFontFaceSrcFunction(val, expectComma, allowFormat, uriValue, parsedValue)) {
+                failed = true;
+                break;
             }
+            if (parsedValue)
+                values->append(parsedValue.release());
+            m_valueList->next();
+            continue;
         } else if (val->unit == CSSParserValue::Operator && val->iValue == ',' && expectComma) {
             expectComma = false;
             allowFormat = false;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to