LibWeb/CSS: Implement add for FontFaceSet
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-22.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-22.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run

There is still some work to do with some of the underying methods
called inside this method (e.g is_css_connected) but this is a start.
This commit is contained in:
Kostya Farber 2024-09-26 10:52:54 +01:00 committed by Andrew Kaster
parent 9098e39a43
commit 14d62d7f31
Notes: github-actions[bot] 2024-09-27 20:50:24 +00:00
3 changed files with 37 additions and 4 deletions

View file

@ -70,6 +70,8 @@ public:
String line_gap_override() const { return m_line_gap_override; } String line_gap_override() const { return m_line_gap_override; }
WebIDL::ExceptionOr<void> set_line_gap_override(String const&); WebIDL::ExceptionOr<void> set_line_gap_override(String const&);
bool is_css_connected() const { return m_is_css_connected; }
Bindings::FontFaceLoadStatus status() const { return m_status; } Bindings::FontFaceLoadStatus status() const { return m_status; }
JS::NonnullGCPtr<JS::Promise> load(); JS::NonnullGCPtr<JS::Promise> load();

View file

@ -61,14 +61,41 @@ void FontFaceSet::visit_edges(Cell::Visitor& visitor)
Base::visit_edges(visitor); Base::visit_edges(visitor);
visitor.visit(m_set_entries); visitor.visit(m_set_entries);
visitor.visit(m_ready_promise); visitor.visit(m_ready_promise);
visitor.visit(m_loading_fonts);
visitor.visit(m_loaded_fonts);
visitor.visit(m_failed_fonts);
} }
// https://drafts.csswg.org/css-font-loading/#dom-fontfaceset-add // https://drafts.csswg.org/css-font-loading/#dom-fontfaceset-add
JS::NonnullGCPtr<FontFaceSet> FontFaceSet::add(JS::Handle<FontFace> face) WebIDL::ExceptionOr<JS::NonnullGCPtr<FontFaceSet>>
FontFaceSet::add(JS::Handle<FontFace> face)
{ {
// FIXME: Do the actual spec steps // 1. If font is already in the FontFaceSets set entries, skip to the last step of this algorithm immediately.
if (m_set_entries->set_has(face))
return JS::NonnullGCPtr<FontFaceSet>(*this);
// 2. If font is CSS-connected, throw an InvalidModificationError exception and exit this algorithm immediately.
if (face->is_css_connected()) {
return WebIDL::InvalidModificationError::create(realm(), "Cannot add a CSS-connected FontFace to a FontFaceSet"_fly_string);
}
// 3. Add the font argument to the FontFaceSets set entries.
m_set_entries->set_add(face); m_set_entries->set_add(face);
return *this;
// 4. If fonts status attribute is "loading"
if (face->status() == Bindings::FontFaceLoadStatus::Loading) {
// 1. If the FontFaceSets [[LoadingFonts]] list is empty, switch the FontFaceSet to loading.
if (m_loading_fonts.is_empty()) {
m_status = Bindings::FontFaceSetLoadStatus::Loading;
}
// 2. Append font to the FontFaceSets [[LoadingFonts]] list.
m_loading_fonts.append(*face);
}
// 5. Return the FontFaceSet.
return JS::NonnullGCPtr<FontFaceSet>(*this);
} }
// https://drafts.csswg.org/css-font-loading/#dom-fontfaceset-delete // https://drafts.csswg.org/css-font-loading/#dom-fontfaceset-delete

View file

@ -27,7 +27,7 @@ public:
JS::NonnullGCPtr<JS::Set> set_entries() const { return m_set_entries; } JS::NonnullGCPtr<JS::Set> set_entries() const { return m_set_entries; }
JS::NonnullGCPtr<FontFaceSet> add(JS::Handle<FontFace>); WebIDL::ExceptionOr<JS::NonnullGCPtr<FontFaceSet>> add(JS::Handle<FontFace>);
bool delete_(JS::Handle<FontFace>); bool delete_(JS::Handle<FontFace>);
void clear(); void clear();
@ -52,6 +52,10 @@ private:
JS::NonnullGCPtr<JS::Set> m_set_entries; JS::NonnullGCPtr<JS::Set> m_set_entries;
JS::GCPtr<WebIDL::Promise> m_ready_promise; // [[ReadyPromise]] JS::GCPtr<WebIDL::Promise> m_ready_promise; // [[ReadyPromise]]
Vector<JS::NonnullGCPtr<FontFace>> m_loading_fonts {}; // [[LoadingFonts]]
Vector<JS::NonnullGCPtr<FontFace>> m_loaded_fonts {}; // [[LoadedFonts]]
Vector<JS::NonnullGCPtr<FontFace>> m_failed_fonts {}; // [[FailedFonts]]
Bindings::FontFaceSetLoadStatus m_status { Bindings::FontFaceSetLoadStatus::Loading }; Bindings::FontFaceSetLoadStatus m_status { Bindings::FontFaceSetLoadStatus::Loading };
}; };