Add "display" to FontFace Javascript object
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Oct 2017 01:25:01 +0000 (01:25 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Oct 2017 01:25:01 +0000 (01:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175383
<rdar://problem/33813239>

Reviewed by Simon Fraser.

Source/WebCore:

We already have all the necessary infrastructure. Just hook it up to the .idl file!

Test: fast/text/font-loading-font-display.html

* css/CSSFontFace.h:
* css/CSSPrimitiveValueMappings.h:
* css/FontFace.cpp:
(WebCore::FontFace::create):
(WebCore::FontFace::setDisplay):
(WebCore::FontFace::display const):
* css/FontFace.h:
* css/FontFace.idl:

LayoutTests:

* fast/text/font-loading-font-display-expected.txt: Added.
* fast/text/font-loading-font-display.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222949 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/text/font-loading-font-display-expected.txt [new file with mode: 0644]
LayoutTests/fast/text/font-loading-font-display.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSFontFace.h
Source/WebCore/css/CSSPrimitiveValueMappings.h
Source/WebCore/css/FontFace.cpp
Source/WebCore/css/FontFace.h
Source/WebCore/css/FontFace.idl

index 3ee018e..40b9430 100644 (file)
@@ -1,3 +1,14 @@
+2017-10-05  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Add "display" to FontFace Javascript object
+        https://bugs.webkit.org/show_bug.cgi?id=175383
+        <rdar://problem/33813239>
+
+        Reviewed by Simon Fraser.
+
+        * fast/text/font-loading-font-display-expected.txt: Added.
+        * fast/text/font-loading-font-display.html: Added.
+
 2017-10-05  John Wilander  <wilander@apple.com>
 
         Storage Access API: Web process should ask UI process for grant/deny
diff --git a/LayoutTests/fast/text/font-loading-font-display-expected.txt b/LayoutTests/fast/text/font-loading-font-display-expected.txt
new file mode 100644 (file)
index 0000000..c22d46a
--- /dev/null
@@ -0,0 +1,17 @@
+PASS fontFaceRule.style.getPropertyValue('font-display') is ""
+PASS fontFace.display is "auto"
+PASS fontFaceRule.style.getPropertyValue('font-display') is ""
+PASS fontFace.display is "auto"
+PASS fontFaceRule.style.getPropertyValue('font-display') is "block"
+PASS fontFace.display is "block"
+PASS fontFaceRule.style.getPropertyValue('font-display') is "swap"
+PASS fontFace.display is "swap"
+PASS fontFaceRule.style.getPropertyValue('font-display') is "fallback"
+PASS fontFace.display is "fallback"
+PASS fontFaceRule.style.getPropertyValue('font-display') is "optional"
+PASS fontFace.display is "optional"
+PASS fontFace.display = 'garbage' threw exception SyntaxError: The string did not match the expected pattern..
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/text/font-loading-font-display.html b/LayoutTests/fast/text/font-loading-font-display.html
new file mode 100644 (file)
index 0000000..991c3b7
--- /dev/null
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<style id="styleElement">
+@font-face {
+    font-family: "WebFont";
+    src: url("garbage");
+}
+</style>
+</head>
+<body>
+<script>
+var styleElement = document.getElementById("styleElement");
+let fontFaceRule = styleElement.sheet.rules[0];
+let fontFace = document.fonts.entries().next().value;
+
+shouldBeEqualToString("fontFaceRule.style.getPropertyValue('font-display')", "");
+shouldBeEqualToString("fontFace.display", "auto");
+
+let values = ["auto", "block", "swap", "fallback", "optional"];
+for (let value of values) {
+    fontFace.display = value;
+    shouldBeEqualToString("fontFaceRule.style.getPropertyValue('font-display')", value == "auto" ? "" : value);
+    shouldBeEqualToString("fontFace.display", value);
+}
+shouldThrow("fontFace.display = 'garbage'");
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index 2a6cfa8..fe06d98 100644 (file)
@@ -1,3 +1,24 @@
+2017-10-05  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Add "display" to FontFace Javascript object
+        https://bugs.webkit.org/show_bug.cgi?id=175383
+        <rdar://problem/33813239>
+
+        Reviewed by Simon Fraser.
+
+        We already have all the necessary infrastructure. Just hook it up to the .idl file!
+
+        Test: fast/text/font-loading-font-display.html
+
+        * css/CSSFontFace.h:
+        * css/CSSPrimitiveValueMappings.h:
+        * css/FontFace.cpp:
+        (WebCore::FontFace::create):
+        (WebCore::FontFace::setDisplay):
+        (WebCore::FontFace::display const):
+        * css/FontFace.h:
+        * css/FontFace.idl:
+
 2017-10-05  Jer Noble  <jer.noble@apple.com>
 
         [Cocoa] Enable ENABLE_ENCRYPTED_MEDIA build-time setting
index 230eac5..3301ef8 100644 (file)
@@ -88,6 +88,7 @@ public:
     const Vector<UnicodeRange>& ranges() const { return m_ranges; }
     const FontFeatureSettings& featureSettings() const { return m_featureSettings; }
     const FontVariantSettings& variantSettings() const { return m_variantSettings; }
+    FontLoadingBehavior loadingBehavior() const { return m_loadingBehavior; }
     void setVariantSettings(const FontVariantSettings& variantSettings) { m_variantSettings = variantSettings; }
     void setWeight(FontSelectionRange weight) { m_fontSelectionCapabilities.weight = weight; }
     void setStretch(FontSelectionRange stretch) { m_fontSelectionCapabilities.width = stretch; }
index fa1040f..8571efc 100644 (file)
@@ -5698,10 +5698,4 @@ template<> inline CSSPrimitiveValue::operator FontLoadingBehavior() const
     return FontLoadingBehavior::Auto;
 }
 
-/*
-enum class FontLoadingBehavior {
-    Auto, Block, Swap, Fallback, Optional
-};
-*/
-
 }
index 966b7fa..1f0b012 100644 (file)
@@ -31,6 +31,7 @@
 #include "CSSFontFeatureValue.h"
 #include "CSSFontStyleValue.h"
 #include "CSSParser.h"
+#include "CSSPrimitiveValueMappings.h"
 #include "CSSUnicodeRangeValue.h"
 #include "CSSValueList.h"
 #include "CSSValuePool.h"
@@ -104,6 +105,9 @@ ExceptionOr<Ref<FontFace>> FontFace::create(Document& document, const String& fa
     auto setFeatureSettingsResult = result->setFeatureSettings(descriptors.featureSettings.isEmpty() ? ASCIILiteral("normal") : descriptors.featureSettings);
     if (setFeatureSettingsResult.hasException())
         return setFeatureSettingsResult.releaseException();
+    auto setDisplayResult = result->setDisplay(descriptors.display.isEmpty() ? ASCIILiteral("auto") : descriptors.display);
+    if (setDisplayResult.hasException())
+        return setDisplayResult.releaseException();
 
     if (!dataRequiresAsynchronousLoading) {
         result->backing().load();
@@ -278,6 +282,19 @@ ExceptionOr<void> FontFace::setFeatureSettings(const String& featureSettings)
     return { };
 }
 
+ExceptionOr<void> FontFace::setDisplay(const String& display)
+{
+    if (display.isEmpty())
+        return Exception { SyntaxError };
+
+    if (auto value = parseString(display, CSSPropertyFontDisplay)) {
+        m_backing->setLoadingBehavior(*value);
+        return { };
+    }
+
+    return Exception { SyntaxError };
+}
+
 String FontFace::family() const
 {
     m_backing->updateStyleIfNeeded();
@@ -384,6 +401,12 @@ String FontFace::featureSettings() const
     return list->cssText();
 }
 
+String FontFace::display() const
+{
+    m_backing->updateStyleIfNeeded();
+    return CSSValuePool::singleton().createValue(m_backing->loadingBehavior())->cssText();
+}
+
 auto FontFace::status() const -> LoadStatus
 {
     switch (m_backing->status()) {
index 2f4c889..3480030 100644 (file)
@@ -47,6 +47,7 @@ public:
         String unicodeRange;
         String variant;
         String featureSettings;
+        String display;
     };
     
     using Source = Variant<String, RefPtr<JSC::ArrayBuffer>, RefPtr<JSC::ArrayBufferView>>;
@@ -61,6 +62,7 @@ public:
     ExceptionOr<void> setUnicodeRange(const String&);
     ExceptionOr<void> setVariant(const String&);
     ExceptionOr<void> setFeatureSettings(const String&);
+    ExceptionOr<void> setDisplay(const String&);
 
     String family() const;
     String style() const;
@@ -69,6 +71,7 @@ public:
     String unicodeRange() const;
     String variant() const;
     String featureSettings() const;
+    String display() const;
 
     enum class LoadStatus { Unloaded, Loading, Loaded, Error };
     LoadStatus status() const;
index 1bf508e..9af7214 100644 (file)
@@ -39,6 +39,7 @@ dictionary FontFaceDescriptors {
     DOMString unicodeRange = "U+0-10FFFF";
     DOMString variant = "normal";
     DOMString featureSettings = "normal";
+    DOMString display = "auto";
 };
 
 [
@@ -53,6 +54,7 @@ dictionary FontFaceDescriptors {
     attribute DOMString unicodeRange;
     attribute DOMString variant;
     attribute DOMString featureSettings;
+    attribute DOMString display;
 
     readonly attribute FontFaceLoadStatus status;