source: webkit/trunk/Source/WebCore/css/FontFaceSet.h

Last change on this file was 281951, checked in by [email protected], 4 years ago

FontFaceSet.add() needs to throw when called on a CSS-connected font
https://bugs.webkit.org/show_bug.cgi?id=229641

Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

  • web-platform-tests/css/css-font-loading/fontfaceset-add-css-connected-expected.txt:

Source/WebCore:

https://drafts.csswg.org/css-font-loading-3/#dom-fontfaceset-add
"2. If font is CSS-connected, throw an InvalidModificationError exception and exit this algorithm immediately."

Test: imported/w3c/web-platform-tests/css/css-font-loading/fontfaceset-add-css-connected.html

  • css/FontFaceSet.cpp:

(WebCore::FontFaceSet::add): Deleted.

  • css/FontFaceSet.h:

LayoutTests:

  • fast/text/font-face-set-document-expected.txt:
  • fast/text/font-face-set-document.html:
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Rev URL
File size: 4.5 KB
Line 
1/*
2 * Copyright (C) 2016 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "ActiveDOMObject.h"
29#include "CSSFontFaceSet.h"
30#include "EventTarget.h"
31#include "IDLTypes.h"
32#include <wtf/UniqueRef.h>
33
34namespace WebCore {
35
36template<typename IDLType> class DOMPromiseDeferred;
37template<typename IDLType> class DOMPromiseProxyWithResolveCallback;
38
39class DOMException;
40
41class FontFaceSet final : public RefCounted<FontFaceSet>, private CSSFontFaceSet::FontEventClient, public EventTargetWithInlineData, public ActiveDOMObject {
42 WTF_MAKE_ISO_ALLOCATED(FontFaceSet);
43public:
44 static Ref<FontFaceSet> create(ScriptExecutionContext&, const Vector<RefPtr<FontFace>>& initialFaces);
45 static Ref<FontFaceSet> create(ScriptExecutionContext&, CSSFontFaceSet& backing);
46 virtual ~FontFaceSet();
47
48 bool has(FontFace&) const;
49 size_t size();
50 ExceptionOr<FontFaceSet&> add(FontFace&);
51 bool remove(FontFace&);
52 void clear();
53
54 using LoadPromise = DOMPromiseDeferred<IDLSequence<IDLInterface<FontFace>>>;
55 void load(const String& font, const String& text, LoadPromise&&);
56 ExceptionOr<bool> check(const String& font, const String& text);
57
58 enum class LoadStatus { Loading, Loaded };
59 LoadStatus status() const;
60
61 using ReadyPromise = DOMPromiseProxyWithResolveCallback<IDLInterface<FontFaceSet>>;
62 ReadyPromise& ready() { return m_readyPromise.get(); }
63 void documentDidFinishLoading();
64
65 CSSFontFaceSet& backing() { return m_backing; }
66
67 class Iterator {
68 public:
69 explicit Iterator(FontFaceSet&);
70 RefPtr<FontFace> next();
71
72 private:
73 Ref<FontFaceSet> m_target;
74 size_t m_index { 0 }; // FIXME: There needs to be a mechanism to handle when fonts are added or removed from the middle of the FontFaceSet.
75 };
76 Iterator createIterator() { return Iterator(*this); }
77
78 using RefCounted::ref;
79 using RefCounted::deref;
80
81private:
82 struct PendingPromise : RefCounted<PendingPromise> {
83 static Ref<PendingPromise> create(LoadPromise&& promise)
84 {
85 return adoptRef(*new PendingPromise(WTFMove(promise)));
86 }
87 ~PendingPromise();
88
89 private:
90 PendingPromise(LoadPromise&&);
91
92 public:
93 Vector<Ref<FontFace>> faces;
94 UniqueRef<LoadPromise> promise;
95 bool hasReachedTerminalState { false };
96 };
97
98 FontFaceSet(ScriptExecutionContext&, const Vector<RefPtr<FontFace>>&);
99 FontFaceSet(ScriptExecutionContext&, CSSFontFaceSet&);
100
101 // CSSFontFaceSet::FontEventClient
102 void faceFinished(CSSFontFace&, CSSFontFace::Status) final;
103 void startedLoading() final;
104 void completedLoading() final;
105
106 // ActiveDOMObject
107 const char* activeDOMObjectName() const final { return "FontFaceSet"; }
108
109 // EventTarget
110 EventTargetInterface eventTargetInterface() const final { return FontFaceSetEventTargetInterfaceType; }
111 ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
112 void refEventTarget() final { ref(); }
113 void derefEventTarget() final { deref(); }
114
115 // Callback for ReadyPromise.
116 FontFaceSet& readyPromiseResolve();
117
118 Ref<CSSFontFaceSet> m_backing;
119 HashMap<RefPtr<FontFace>, Vector<Ref<PendingPromise>>> m_pendingPromises;
120 UniqueRef<ReadyPromise> m_readyPromise;
121
122 bool m_isDocumentLoaded { true };
123};
124
125}
Note: See TracBrowser for help on using the repository browser.