зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1072107 - Part 9. Expose FontFaceSet on workers. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D149254
This commit is contained in:
Родитель
15c3439858
Коммит
c5989fee52
|
@ -31,8 +31,8 @@ enum FontFaceLoadStatus { "unloaded", "loading", "loaded", "error" };
|
|||
|
||||
// Bug 1072107 is for exposing this in workers.
|
||||
// [Exposed=(Window,Worker)]
|
||||
[Pref="layout.css.font-loading-api.enabled",
|
||||
Exposed=Window]
|
||||
[Func="FontFaceSet::IsEnabled",
|
||||
Exposed=(Window,Worker)]
|
||||
interface FontFace {
|
||||
[Throws]
|
||||
constructor(UTF8String family,
|
||||
|
|
|
@ -19,7 +19,7 @@ dictionary FontFaceSetIteratorResult
|
|||
|
||||
// To implement FontFaceSet's iterator until we can use setlike.
|
||||
[LegacyNoInterfaceObject,
|
||||
Exposed=Window]
|
||||
Exposed=(Window,Worker)]
|
||||
interface FontFaceSetIterator {
|
||||
[Throws] FontFaceSetIteratorResult next();
|
||||
};
|
||||
|
@ -28,8 +28,8 @@ callback FontFaceSetForEachCallback = void (FontFace value, FontFace key, FontFa
|
|||
|
||||
enum FontFaceSetLoadStatus { "loading", "loaded" };
|
||||
|
||||
[Pref="layout.css.font-loading-api.enabled",
|
||||
Exposed=Window]
|
||||
[Func="FontFaceSet::IsEnabled",
|
||||
Exposed=(Window,Worker)]
|
||||
interface FontFaceSet : EventTarget {
|
||||
// Bug 1072762 is for the FontFaceSet constructor.
|
||||
// constructor(sequence<FontFace> initialFaces);
|
||||
|
|
|
@ -14,8 +14,8 @@ dictionary FontFaceSetLoadEventInit : EventInit {
|
|||
sequence<FontFace> fontfaces = [];
|
||||
};
|
||||
|
||||
[Pref="layout.css.font-loading-api.enabled",
|
||||
Exposed=Window]
|
||||
[Func="FontFaceSet::IsEnabled",
|
||||
Exposed=(Window,Worker)]
|
||||
interface FontFaceSetLoadEvent : Event {
|
||||
constructor(DOMString type,
|
||||
optional FontFaceSetLoadEventInit eventInitDict = {});
|
||||
|
|
|
@ -12,6 +12,6 @@
|
|||
|
||||
interface mixin FontFaceSource {
|
||||
|
||||
[Pref="layout.css.font-loading-api.enabled"]
|
||||
[Func="FontFaceSet::IsEnabled"]
|
||||
readonly attribute FontFaceSet fonts;
|
||||
};
|
||||
|
|
|
@ -33,11 +33,9 @@ interface WorkerGlobalScope : EventTarget {
|
|||
};
|
||||
|
||||
WorkerGlobalScope includes GlobalCrypto;
|
||||
WorkerGlobalScope includes FontFaceSource;
|
||||
WorkerGlobalScope includes WindowOrWorkerGlobalScope;
|
||||
|
||||
// Not implemented yet: bug 1072107.
|
||||
// WorkerGlobalScope implements FontFaceSource;
|
||||
|
||||
// Mozilla extensions
|
||||
partial interface WorkerGlobalScope {
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
#include "mozilla/dom/DedicatedWorkerGlobalScopeBinding.h"
|
||||
#include "mozilla/dom/DOMString.h"
|
||||
#include "mozilla/dom/Fetch.h"
|
||||
#include "mozilla/dom/FontFaceSet.h"
|
||||
#include "mozilla/dom/IDBFactory.h"
|
||||
#include "mozilla/dom/ImageBitmap.h"
|
||||
#include "mozilla/dom/ImageBitmapSource.h"
|
||||
|
@ -383,6 +384,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(WorkerGlobalScope,
|
|||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWebTaskScheduler)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLocation)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNavigator)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFontFaceSet)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIndexedDB)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCacheStorage)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDebuggerNotificationManager)
|
||||
|
@ -398,6 +400,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(WorkerGlobalScope,
|
|||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLocation)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mNavigator)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFontFaceSet)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIndexedDB)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCacheStorage)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDebuggerNotificationManager)
|
||||
|
@ -467,6 +470,17 @@ already_AddRefed<WorkerNavigator> WorkerGlobalScope::GetExistingNavigator()
|
|||
return navigator.forget();
|
||||
}
|
||||
|
||||
FontFaceSet* WorkerGlobalScope::Fonts() {
|
||||
AssertIsOnWorkerThread();
|
||||
|
||||
if (!mFontFaceSet) {
|
||||
mFontFaceSet = FontFaceSet::CreateForWorker(this, mWorkerPrivate);
|
||||
MOZ_ASSERT(mFontFaceSet);
|
||||
}
|
||||
|
||||
return mFontFaceSet;
|
||||
}
|
||||
|
||||
OnErrorEventHandlerNonNull* WorkerGlobalScope::GetOnerror() {
|
||||
AssertIsOnWorkerThread();
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ class DOMString;
|
|||
class DebuggerNotificationManager;
|
||||
enum class EventCallbackDebuggerNotificationType : uint8_t;
|
||||
class EventHandlerNonNull;
|
||||
class FontFaceSet;
|
||||
class Function;
|
||||
class IDBFactory;
|
||||
class OnErrorEventHandlerNonNull;
|
||||
|
@ -234,6 +235,8 @@ class WorkerGlobalScope : public WorkerGlobalScopeBase {
|
|||
|
||||
already_AddRefed<WorkerNavigator> GetExistingNavigator() const;
|
||||
|
||||
FontFaceSet* Fonts() final;
|
||||
|
||||
void ImportScripts(JSContext* aCx, const Sequence<nsString>& aScriptURLs,
|
||||
ErrorResult& aRv);
|
||||
|
||||
|
@ -347,6 +350,7 @@ class WorkerGlobalScope : public WorkerGlobalScopeBase {
|
|||
RefPtr<Crypto> mCrypto;
|
||||
RefPtr<WorkerLocation> mLocation;
|
||||
RefPtr<WorkerNavigator> mNavigator;
|
||||
RefPtr<FontFaceSet> mFontFaceSet;
|
||||
RefPtr<Performance> mPerformance;
|
||||
RefPtr<IDBFactory> mIndexedDB;
|
||||
RefPtr<cache::CacheStorage> mCacheStorage;
|
||||
|
|
|
@ -303,7 +303,7 @@ void FontFace::EnsurePromise() {
|
|||
// If the pref is not set, don't create the Promise (which the page wouldn't
|
||||
// be able to get to anyway) as it causes the window.FontFace constructor
|
||||
// to be created.
|
||||
if (FontFaceSet::PrefEnabled()) {
|
||||
if (FontFaceSet::IsEnabled()) {
|
||||
ErrorResult rv;
|
||||
mLoaded = Promise::Create(mParent, rv);
|
||||
|
||||
|
|
|
@ -107,6 +107,13 @@ FontFaceSet::~FontFaceSet() {
|
|||
Destroy();
|
||||
}
|
||||
|
||||
/* static */ bool FontFaceSet::IsEnabled() {
|
||||
if (NS_IsMainThread()) {
|
||||
return StaticPrefs::layout_css_font_loading_api_enabled();
|
||||
}
|
||||
return StaticPrefs::layout_css_font_loading_api_workers_enabled();
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<FontFaceSet> FontFaceSet::CreateForDocument(
|
||||
dom::Document* aDocument) {
|
||||
RefPtr<FontFaceSet> set = new FontFaceSet(aDocument->GetScopeObject());
|
||||
|
@ -387,7 +394,7 @@ void FontFaceSet::DispatchLoadingEventAndReplaceReadyPromise() {
|
|||
(new AsyncEventDispatcher(this, u"loading"_ns, CanBubble::eNo))
|
||||
->PostDOMEvent();
|
||||
|
||||
if (PrefEnabled()) {
|
||||
if (IsEnabled()) {
|
||||
if (mReady && mReady->State() != Promise::PromiseState::Pending) {
|
||||
if (GetParentObject()) {
|
||||
ErrorResult rv;
|
||||
|
@ -461,11 +468,6 @@ void FontFaceSet::DispatchLoadingFinishedEvent(
|
|||
(new AsyncEventDispatcher(this, event))->PostDOMEvent();
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool FontFaceSet::PrefEnabled() {
|
||||
return StaticPrefs::layout_css_font_loading_api_enabled();
|
||||
}
|
||||
|
||||
void FontFaceSet::FlushUserFontSet() { mImpl->FlushUserFontSet(); }
|
||||
|
||||
void FontFaceSet::RefreshStandardFontLoadPrincipal() {
|
||||
|
|
|
@ -37,6 +37,12 @@ class FontFaceSet final : public DOMEventTargetHelper {
|
|||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FontFaceSet, DOMEventTargetHelper)
|
||||
|
||||
static bool IsEnabled();
|
||||
|
||||
static bool IsEnabled(JSContext* aCx, JSObject* aObj) {
|
||||
return IsEnabled();
|
||||
}
|
||||
|
||||
static already_AddRefed<FontFaceSet> CreateForDocument(
|
||||
dom::Document* aDocument);
|
||||
|
||||
|
@ -55,11 +61,6 @@ class FontFaceSet final : public DOMEventTargetHelper {
|
|||
*/
|
||||
void DidRefresh();
|
||||
|
||||
/**
|
||||
* Returns whether the "layout.css.font-loading-api.enabled" pref is true.
|
||||
*/
|
||||
static bool PrefEnabled();
|
||||
|
||||
void FlushUserFontSet();
|
||||
|
||||
void RefreshStandardFontLoadPrincipal();
|
||||
|
|
|
@ -906,11 +906,6 @@ void FontFaceSetImpl::OnLoadingFinished() {
|
|||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool FontFaceSetImpl::PrefEnabled() {
|
||||
return StaticPrefs::layout_css_font_loading_api_enabled();
|
||||
}
|
||||
|
||||
void FontFaceSetImpl::RefreshStandardFontLoadPrincipal() {
|
||||
RecursiveMutexAutoLock lock(mMutex);
|
||||
mAllowedFontLoads.Clear();
|
||||
|
|
|
@ -121,11 +121,6 @@ class FontFaceSetImpl : public nsISupports, public gfxUserFontSet {
|
|||
*/
|
||||
virtual void DidRefresh() { MOZ_ASSERT_UNREACHABLE("Not implemented!"); }
|
||||
|
||||
/**
|
||||
* Returns whether the "layout.css.font-loading-api.enabled" pref is true.
|
||||
*/
|
||||
static bool PrefEnabled();
|
||||
|
||||
virtual void FlushUserFontSet() {}
|
||||
|
||||
static nsPresContext* GetPresContextFor(gfxUserFontSet* aUserFontSet) {
|
||||
|
|
|
@ -7738,10 +7738,16 @@
|
|||
|
||||
# Is support for document.fonts enabled?
|
||||
- name: layout.css.font-loading-api.enabled
|
||||
type: bool
|
||||
type: RelaxedAtomicBool
|
||||
value: true
|
||||
mirror: always
|
||||
|
||||
# Is support for workerGlobalScope.fonts enabled?
|
||||
- name: layout.css.font-loading-api.workers.enabled
|
||||
type: RelaxedAtomicBool
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
# Is support for the @font-face metrics override descriptors enabled?
|
||||
- name: layout.css.font-metrics-overrides.enabled
|
||||
type: RelaxedAtomicBool
|
||||
|
|
|
@ -75,3 +75,4 @@ user_pref("layout.css.prefers-color-scheme.content-override", 1);
|
|||
// Force OffscreenCanvas support
|
||||
user_pref("gfx.offscreencanvas.enabled", true);
|
||||
user_pref("dom.workers.requestAnimationFrame", true);
|
||||
user_pref("layout.css.font-loading-api.workers.enabled", true);
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
[fontfaceset-load-css-wide-keywords.html]
|
||||
expected: ERROR
|
||||
[Loading CSS-wide keyword "revert" causes SyntaxError (worker)]
|
||||
expected: NOTRUN
|
||||
|
||||
[Loading CSS-wide keyword "unset" causes SyntaxError (worker)]
|
||||
expected: NOTRUN
|
||||
|
||||
[Loading CSS-wide keyword "initial" causes SyntaxError (worker)]
|
||||
expected: TIMEOUT
|
||||
|
||||
[Loading CSS-wide keyword "inherit" causes SyntaxError (worker)]
|
||||
expected: NOTRUN
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[fontfaceset-load-var.html]
|
||||
expected: ERROR
|
||||
[Loading "var(--x, 10px) serif" causes SyntaxError (worker)]
|
||||
expected: NOTRUN
|
||||
|
||||
[Loading "var(--x) serif" causes SyntaxError (worker)]
|
||||
expected: TIMEOUT
|
||||
|
Загрузка…
Ссылка в новой задаче