Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Handle CSSOM style mutation of font-palette-values
https://bugs.webkit.org/show_bug.cgi?id=230448
<rdar://problem/83343481>

Reviewed by Antti Koivisto.

LayoutTests/imported/w3c:

These tests are being upstreamed at web-platform-tests/wpt#30939.

* web-platform-tests/css/css-fonts/palette-values-rule-add-2-expected.html: Added.
* web-platform-tests/css/css-fonts/palette-values-rule-add-2.html: Added.
* web-platform-tests/css/css-fonts/palette-values-rule-add-expected-mismatch.html: Added.
* web-platform-tests/css/css-fonts/palette-values-rule-add.html: Added.
* web-platform-tests/css/css-fonts/palette-values-rule-delete-2-expected.html: Added.
* web-platform-tests/css/css-fonts/palette-values-rule-delete-2.html: Added.
* web-platform-tests/css/css-fonts/palette-values-rule-delete-expected-mismatch.html: Added.
* web-platform-tests/css/css-fonts/palette-values-rule-delete.html: Added.

Source/WebCore:

The CSSSegmentedFontFace cache needs to be sensitive to FontPaletteValues.

Tests: imported/w3c/web-platform-tests/css/css-fonts/palette-values-rule-add-2.html
       imported/w3c/web-platform-tests/css/css-fonts/palette-values-rule-add.html
       imported/w3c/web-platform-tests/css/css-fonts/palette-values-rule-delete-2.html
       imported/w3c/web-platform-tests/css/css-fonts/palette-values-rule-delete.html

* css/CSSSegmentedFontFace.cpp:
(WebCore::CSSSegmentedFontFace::fontRanges):
* css/CSSSegmentedFontFace.h:
* platform/graphics/FontCache.h:
(WTF::DefaultHash<WebCore::FontDescriptionKey>::hash):
(WTF::DefaultHash<WebCore::FontDescriptionKey>::equal):
(WebCore::FontDescriptionKeyHash::hash): Deleted.
(WebCore::FontDescriptionKeyHash::equal): Deleted.
* platform/graphics/FontPaletteValues.h:
(WTF::DefaultHash<WebCore::FontPaletteValues>::hash):
(WTF::DefaultHash<WebCore::FontPaletteValues>::equal):


Canonical link: https://commits.webkit.org/242091@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@283031 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
litherum committed Sep 24, 2021
1 parent 8d308cf commit ce1d7dd
Show file tree
Hide file tree
Showing 14 changed files with 307 additions and 5 deletions.
19 changes: 19 additions & 0 deletions LayoutTests/imported/w3c/ChangeLog
@@ -1,3 +1,22 @@
2021-09-24 Myles C. Maxfield <mmaxfield@apple.com>

Handle CSSOM style mutation of font-palette-values
https://bugs.webkit.org/show_bug.cgi?id=230448
<rdar://problem/83343481>

Reviewed by Antti Koivisto.

These tests are being upstreamed at https://github.com/web-platform-tests/wpt/pull/30939.

* web-platform-tests/css/css-fonts/palette-values-rule-add-2-expected.html: Added.
* web-platform-tests/css/css-fonts/palette-values-rule-add-2.html: Added.
* web-platform-tests/css/css-fonts/palette-values-rule-add-expected-mismatch.html: Added.
* web-platform-tests/css/css-fonts/palette-values-rule-add.html: Added.
* web-platform-tests/css/css-fonts/palette-values-rule-delete-2-expected.html: Added.
* web-platform-tests/css/css-fonts/palette-values-rule-delete-2.html: Added.
* web-platform-tests/css/css-fonts/palette-values-rule-delete-expected-mismatch.html: Added.
* web-platform-tests/css/css-fonts/palette-values-rule-delete.html: Added.

2021-09-24 Sihui Liu <sihui_liu@apple.com>

Add initial support for File System Access API
Expand Down
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tests that dynamically adding a @font-palette-values rule causes the necessary rendering update</title>
<link rel="help" href="https://drafts.csswg.org/css-fonts/#font-palette-values">
<link rel="author" title="Myles C. Maxfield" href="mailto:mmaxfield@apple.com">
<style>
@font-face {
font-family: "Ahem-COLR";
src: url("resources/Ahem-COLOR-palettes.ttf") format("truetype");
}

@font-palette-values MyPalette {
font-family: "Ahem-COLR";
base-palette: 1;
}
</style>
</head>
<body>
<div style="font: 48px 'Ahem-COLR'; font-palette: MyPalette;">A</div>
</body>
</html>
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html class="reftest-wait">
<head>
<meta charset="utf-8">
<title>Tests that dynamically adding a @font-palette-values rule causes the necessary rendering update</title>
<link rel="help" href="https://drafts.csswg.org/css-fonts/#font-palette-values">
<link rel="author" title="Myles C. Maxfield" href="mailto:mmaxfield@apple.com">
<link rel="match" href="palette-values-rule-add-2-ref.html">
<style>
@font-face {
font-family: "Ahem-COLR";
src: url("resources/Ahem-COLOR-palettes.ttf") format("truetype");
}
</style>
</head>
<body>
<div style="font: 48px 'Ahem-COLR'; font-palette: MyPalette;">A</div>
<script>
let count = 0;
function tick() {
if (count > 3) {
let style = document.createElement("style");
document.head.appendChild(style);
style.sheet.insertRule(`
@font-palette-values MyPalette {
font-family: "Ahem-COLR";
base-palette: 1;
}`);
document.documentElement.classList.remove("reftest-wait");
} else {
++count;
requestAnimationFrame(tick);
}
}
requestAnimationFrame(tick);
</script>
</body>
</html>
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tests that dynamically adding a @font-palette-values rule causes the necessary rendering update</title>
<link rel="help" href="https://drafts.csswg.org/css-fonts/#font-palette-values">
<link rel="author" title="Myles C. Maxfield" href="mailto:mmaxfield@apple.com">
<style>
@font-face {
font-family: "Ahem-COLR";
src: url("resources/Ahem-COLOR-palettes.ttf") format("truetype");
}
</style>
</head>
<body>
<div style="font: 48px 'Ahem-COLR'; font-palette: MyPalette;">A</div>
</body>
</html>
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html class="reftest-wait">
<head>
<meta charset="utf-8">
<title>Tests that dynamically adding a @font-palette-values rule causes the necessary rendering update</title>
<link rel="help" href="https://drafts.csswg.org/css-fonts/#font-palette-values">
<link rel="author" title="Myles C. Maxfield" href="mailto:mmaxfield@apple.com">
<link rel="mismatch" href="palette-values-rule-add-notref.html">
<style>
@font-face {
font-family: "Ahem-COLR";
src: url("resources/Ahem-COLOR-palettes.ttf") format("truetype");
}
</style>
</head>
<body>
<div style="font: 48px 'Ahem-COLR'; font-palette: MyPalette;">A</div>
<script>
let count = 0;
function tick() {
if (count > 3) {
let style = document.createElement("style");
document.head.appendChild(style);
style.sheet.insertRule(`
@font-palette-values MyPalette {
font-family: "Ahem-COLR";
base-palette: 1;
}`);
document.documentElement.classList.remove("reftest-wait");
} else {
++count;
requestAnimationFrame(tick);
}
}
requestAnimationFrame(tick);
</script>
</body>
</html>
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tests that dynamically deleting a @font-palette-values rule causes the necessary rendering update</title>
<link rel="help" href="https://drafts.csswg.org/css-fonts/#font-palette-values">
<link rel="author" title="Myles C. Maxfield" href="mailto:mmaxfield@apple.com">
<style id="style">
@font-face {
font-family: "Ahem-COLR";
src: url("resources/Ahem-COLOR-palettes.ttf") format("truetype");
}
</style>
</head>
<body>
<div style="font: 48px 'Ahem-COLR'; font-palette: MyPalette;">A</div>
</body>
</html>
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html class="reftest-wait">
<head>
<meta charset="utf-8">
<title>Tests that dynamically deleting a @font-palette-values rule causes the necessary rendering update</title>
<link rel="help" href="https://drafts.csswg.org/css-fonts/#font-palette-values">
<link rel="author" title="Myles C. Maxfield" href="mailto:mmaxfield@apple.com">
<link rel="match" href="palette-values-rule-delete-2-ref.html">
<style id="style">
@font-face {
font-family: "Ahem-COLR";
src: url("resources/Ahem-COLOR-palettes.ttf") format("truetype");
}

@font-palette-values MyPalette {
font-family: "Ahem-COLR";
base-palette: 1;
}
</style>
</head>
<body>
<div style="font: 48px 'Ahem-COLR'; font-palette: MyPalette;">A</div>
<script>
let count = 0;
function tick() {
if (count > 3) {
document.getElementById("style").sheet.deleteRule(1);
document.documentElement.classList.remove("reftest-wait");
} else {
++count;
requestAnimationFrame(tick);
}
}
requestAnimationFrame(tick);
</script>
</body>
</html>
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tests that dynamically deleting a @font-palette-values rule causes the necessary rendering update</title>
<link rel="help" href="https://drafts.csswg.org/css-fonts/#font-palette-values">
<link rel="author" title="Myles C. Maxfield" href="mailto:mmaxfield@apple.com">
<style id="style">
@font-face {
font-family: "Ahem-COLR";
src: url("resources/Ahem-COLOR-palettes.ttf") format("truetype");
}

@font-palette-values MyPalette {
font-family: "Ahem-COLR";
base-palette: 1;
}
</style>
</head>
<body>
<div style="font: 48px 'Ahem-COLR'; font-palette: MyPalette;">A</div>
</body>
</html>
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html class="reftest-wait">
<head>
<meta charset="utf-8">
<title>Tests that dynamically deleting a @font-palette-values rule causes the necessary rendering update</title>
<link rel="help" href="https://drafts.csswg.org/css-fonts/#font-palette-values">
<link rel="author" title="Myles C. Maxfield" href="mailto:mmaxfield@apple.com">
<link rel="mismatch" href="palette-values-rule-delete-notref.html">
<style id="style">
@font-face {
font-family: "Ahem-COLR";
src: url("resources/Ahem-COLOR-palettes.ttf") format("truetype");
}

@font-palette-values MyPalette {
font-family: "Ahem-COLR";
base-palette: 1;
}
</style>
</head>
<body>
<div style="font: 48px 'Ahem-COLR'; font-palette: MyPalette;">A</div>
<script>
let count = 0;
function tick() {
if (count > 3) {
document.getElementById("style").sheet.deleteRule(1);
document.documentElement.classList.remove("reftest-wait");
} else {
++count;
requestAnimationFrame(tick);
}
}
requestAnimationFrame(tick);
</script>
</body>
</html>
27 changes: 27 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,30 @@
2021-09-24 Myles C. Maxfield <mmaxfield@apple.com>

Handle CSSOM style mutation of font-palette-values
https://bugs.webkit.org/show_bug.cgi?id=230448
<rdar://problem/83343481>

Reviewed by Antti Koivisto.

The CSSSegmentedFontFace cache needs to be sensitive to FontPaletteValues.

Tests: imported/w3c/web-platform-tests/css/css-fonts/palette-values-rule-add-2.html
imported/w3c/web-platform-tests/css/css-fonts/palette-values-rule-add.html
imported/w3c/web-platform-tests/css/css-fonts/palette-values-rule-delete-2.html
imported/w3c/web-platform-tests/css/css-fonts/palette-values-rule-delete.html

* css/CSSSegmentedFontFace.cpp:
(WebCore::CSSSegmentedFontFace::fontRanges):
* css/CSSSegmentedFontFace.h:
* platform/graphics/FontCache.h:
(WTF::DefaultHash<WebCore::FontDescriptionKey>::hash):
(WTF::DefaultHash<WebCore::FontDescriptionKey>::equal):
(WebCore::FontDescriptionKeyHash::hash): Deleted.
(WebCore::FontDescriptionKeyHash::equal): Deleted.
* platform/graphics/FontPaletteValues.h:
(WTF::DefaultHash<WebCore::FontPaletteValues>::hash):
(WTF::DefaultHash<WebCore::FontPaletteValues>::equal):

2021-09-24 Brandon Stewart <brandonstewart@apple.com>

[RenderTreeUpdater] NULL ptr deref in updateRenderTree
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSSegmentedFontFace.cpp
Expand Up @@ -112,7 +112,7 @@ static void appendFont(FontRanges& ranges, Ref<FontAccessor>&& fontAccessor, con

FontRanges CSSSegmentedFontFace::fontRanges(const FontDescription& fontDescription, const FontPaletteValues& fontPaletteValues)
{
auto addResult = m_cache.add(FontDescriptionKey(fontDescription), FontRanges());
auto addResult = m_cache.add(std::make_tuple(FontDescriptionKey(fontDescription), fontPaletteValues), FontRanges());
auto& ranges = addResult.iterator->value;

if (!addResult.isNewEntry)
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/css/CSSSegmentedFontFace.h
Expand Up @@ -62,7 +62,8 @@ class CSSSegmentedFontFace final : public RefCounted<CSSSegmentedFontFace>, publ
CSSSegmentedFontFace();
void fontLoaded(CSSFontFace&) final;

HashMap<FontDescriptionKey, FontRanges, FontDescriptionKeyHash, WTF::SimpleClassHashTraits<FontDescriptionKey>> m_cache;
// FIXME: Add support for font-feature-values in the key for this cache.
HashMap<std::tuple<FontDescriptionKey, FontPaletteValues>, FontRanges> m_cache;
Vector<Ref<CSSFontFace>, 1> m_fontFaces;
};

Expand Down
18 changes: 15 additions & 3 deletions Source/WebCore/platform/graphics/FontCache.h
Expand Up @@ -40,6 +40,7 @@
#include <limits.h>
#include <wtf/FastMalloc.h>
#include <wtf/Forward.h>
#include <wtf/HashFunctions.h>
#include <wtf/HashTraits.h>
#include <wtf/ListHashSet.h>
#include <wtf/PointerComparison.h>
Expand Down Expand Up @@ -216,12 +217,23 @@ inline void add(Hasher& hasher, const FontDescriptionKey& key)
add(hasher, *key.m_rareData);
}

struct FontDescriptionKeyHash {
static unsigned hash(const FontDescriptionKey& key) { return computeHash(key); }
static bool equal(const FontDescriptionKey& a, const FontDescriptionKey& b) { return a == b; }
} // namespace WebCore

namespace WTF {

template<> struct DefaultHash<WebCore::FontDescriptionKey> {
static unsigned hash(const WebCore::FontDescriptionKey& key) { return computeHash(key); }
static bool equal(const WebCore::FontDescriptionKey& a, const WebCore::FontDescriptionKey& b) { return a == b; }
static constexpr bool safeToCompareToEmptyOrDeleted = true;
};

template<> struct HashTraits<WebCore::FontDescriptionKey> : WTF::SimpleClassHashTraits<WebCore::FontDescriptionKey> {
};

}

namespace WebCore {

// This class holds the name of a font family, and defines hashing and == of this name to
// use the rules for font family names instead of using straight string comparison.
class FontFamilyName {
Expand Down
11 changes: 11 additions & 0 deletions Source/WebCore/platform/graphics/FontPaletteValues.h
Expand Up @@ -27,6 +27,7 @@

#include "Color.h"
#include "Gradient.h"
#include <wtf/HashFunctions.h>
#include <wtf/Variant.h>
#include <wtf/Vector.h>
#include <wtf/text/AtomString.h>
Expand Down Expand Up @@ -78,4 +79,14 @@ inline void add(Hasher& hasher, const FontPaletteValues& fontPaletteValues)
add(hasher, fontPaletteValues.overrideColor());
}

} // namespace WebCore

namespace WTF {

template<> struct DefaultHash<WebCore::FontPaletteValues> {
static unsigned hash(const WebCore::FontPaletteValues& key) { return computeHash(key); }
static bool equal(const WebCore::FontPaletteValues& a, const WebCore::FontPaletteValues& b) { return a == b; }
static constexpr bool safeToCompareToEmptyOrDeleted = true;
};

}

0 comments on commit ce1d7dd

Please sign in to comment.