Skip to content

Commit

Permalink
LibWeb: Rename CSS::FontFace to CSS::ParsedFontFace
Browse files Browse the repository at this point in the history
This implementation detail of CSSFontFaceRule is hogging the name of a
Web API from CSS Font Loading Module Level 3.
  • Loading branch information
ADKaster authored and awesomekling committed May 8, 2024
1 parent 3f113e7 commit 3a5eabc
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ set(SOURCES
CSS/Display.cpp
CSS/EdgeRect.cpp
CSS/Flex.cpp
CSS/FontFace.cpp
CSS/Frequency.cpp
CSS/GridTrackPlacement.cpp
CSS/GridTrackSize.cpp
Expand All @@ -79,6 +78,7 @@ set(SOURCES
CSS/Parser/SelectorParsing.cpp
CSS/Parser/Token.cpp
CSS/Parser/Tokenizer.cpp
CSS/ParsedFontFace.cpp
CSS/PercentageOr.cpp
CSS/PreferredColorScheme.cpp
CSS/Ratio.cpp
Expand Down
8 changes: 4 additions & 4 deletions Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ namespace Web::CSS {

JS_DEFINE_ALLOCATOR(CSSFontFaceRule);

JS::NonnullGCPtr<CSSFontFaceRule> CSSFontFaceRule::create(JS::Realm& realm, FontFace&& font_face)
JS::NonnullGCPtr<CSSFontFaceRule> CSSFontFaceRule::create(JS::Realm& realm, ParsedFontFace&& font_face)
{
return realm.heap().allocate<CSSFontFaceRule>(realm, realm, move(font_face));
}

CSSFontFaceRule::CSSFontFaceRule(JS::Realm& realm, FontFace&& font_face)
CSSFontFaceRule::CSSFontFaceRule(JS::Realm& realm, ParsedFontFace&& font_face)
: CSSRule(realm)
, m_font_face(move(font_face))
{
Expand All @@ -35,7 +35,7 @@ void CSSFontFaceRule::initialize(JS::Realm& realm)

CSSStyleDeclaration* CSSFontFaceRule::style()
{
// FIXME: Return a CSSStyleDeclaration subclass that directs changes to the FontFace.
// FIXME: Return a CSSStyleDeclaration subclass that directs changes to the ParsedFontFace.
return nullptr;
}

Expand Down Expand Up @@ -63,7 +63,7 @@ String CSSFontFaceRule::serialized() const
builder.append(" src: "sv);

// 2. The result of invoking serialize a comma-separated list on performing serialize a URL or serialize a LOCAL for each source on the source list.
serialize_a_comma_separated_list(builder, m_font_face.sources(), [&](StringBuilder& builder, FontFace::Source source) -> void {
serialize_a_comma_separated_list(builder, m_font_face.sources(), [&](StringBuilder& builder, ParsedFontFace::Source source) -> void {
if (source.local_or_url.has<URL::URL>()) {
serialize_a_url(builder, MUST(source.local_or_url.get<URL::URL>().to_string()));
} else {
Expand Down
10 changes: 5 additions & 5 deletions Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#pragma once

#include <LibWeb/CSS/CSSRule.h>
#include <LibWeb/CSS/FontFace.h>
#include <LibWeb/CSS/ParsedFontFace.h>

namespace Web::CSS {

Expand All @@ -17,22 +17,22 @@ class CSSFontFaceRule final : public CSSRule {
JS_DECLARE_ALLOCATOR(CSSFontFaceRule);

public:
[[nodiscard]] static JS::NonnullGCPtr<CSSFontFaceRule> create(JS::Realm&, FontFace&&);
[[nodiscard]] static JS::NonnullGCPtr<CSSFontFaceRule> create(JS::Realm&, ParsedFontFace&&);

virtual ~CSSFontFaceRule() override = default;

virtual Type type() const override { return Type::FontFace; }

FontFace const& font_face() const { return m_font_face; }
ParsedFontFace const& font_face() const { return m_font_face; }
CSSStyleDeclaration* style();

private:
CSSFontFaceRule(JS::Realm&, FontFace&&);
CSSFontFaceRule(JS::Realm&, ParsedFontFace&&);

virtual void initialize(JS::Realm&) override;
virtual String serialized() const override;

FontFace m_font_face;
ParsedFontFace m_font_face;
};

template<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibWeb/CSS/FontFace.h>
#include <LibWeb/CSS/ParsedFontFace.h>

namespace Web::CSS {

FontFace::FontFace(FlyString font_family, Optional<int> weight, Optional<int> slope, Vector<Source> sources, Vector<Gfx::UnicodeRange> unicode_ranges)
ParsedFontFace::ParsedFontFace(FlyString font_family, Optional<int> weight, Optional<int> slope, Vector<Source> sources, Vector<Gfx::UnicodeRange> unicode_ranges)
: m_font_family(move(font_family))
, m_weight(weight)
, m_slope(slope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

namespace Web::CSS {

class FontFace {
class ParsedFontFace {
public:
struct Source {
Variant<String, URL::URL> local_or_url;
// FIXME: Do we need to keep this around, or is it only needed to discard unwanted formats during parsing?
Optional<FlyString> format;
};

FontFace(FlyString font_family, Optional<int> weight, Optional<int> slope, Vector<Source> sources, Vector<Gfx::UnicodeRange> unicode_ranges);
~FontFace() = default;
ParsedFontFace(FlyString font_family, Optional<int> weight, Optional<int> slope, Vector<Source> sources, Vector<Gfx::UnicodeRange> unicode_ranges);
~ParsedFontFace() = default;

FlyString font_family() const { return m_font_family; }
Optional<int> weight() const { return m_weight; }
Expand Down
10 changes: 5 additions & 5 deletions Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4448,7 +4448,7 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
auto declarations_and_at_rules = parse_a_list_of_declarations(tokens);

Optional<FlyString> font_family;
Vector<FontFace::Source> src;
Vector<ParsedFontFace::Source> src;
Vector<Gfx::UnicodeRange> unicode_range;
Optional<int> weight;
Optional<int> slope;
Expand Down Expand Up @@ -4520,7 +4520,7 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
}
if (declaration.name().equals_ignoring_ascii_case("src"sv)) {
TokenStream token_stream { declaration.values() };
Vector<FontFace::Source> supported_sources = parse_font_face_src(token_stream);
Vector<ParsedFontFace::Source> supported_sources = parse_font_face_src(token_stream);
if (!supported_sources.is_empty())
src = move(supported_sources);
continue;
Expand Down Expand Up @@ -4560,10 +4560,10 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
unicode_range.empend(0x0u, 0x10FFFFu);
}

return CSSFontFaceRule::create(m_context.realm(), FontFace { font_family.release_value(), weight, slope, move(src), move(unicode_range) });
return CSSFontFaceRule::create(m_context.realm(), ParsedFontFace { font_family.release_value(), weight, slope, move(src), move(unicode_range) });
}

Vector<FontFace::Source> Parser::parse_font_face_src(TokenStream<ComponentValue>& component_values)
Vector<ParsedFontFace::Source> Parser::parse_font_face_src(TokenStream<ComponentValue>& component_values)
{
// FIXME: Get this information from the system somehow?
// Format-name table: https://www.w3.org/TR/css-fonts-4/#font-format-definitions
Expand All @@ -4574,7 +4574,7 @@ Vector<FontFace::Source> Parser::parse_font_face_src(TokenStream<ComponentValue>
return false;
};

Vector<FontFace::Source> supported_sources;
Vector<ParsedFontFace::Source> supported_sources;

auto list_of_source_token_lists = parse_a_comma_separated_list_of_component_values(component_values);
for (auto const& source_token_list : list_of_source_token_lists) {
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/CSS/Parser/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include <AK/Vector.h>
#include <LibGfx/Font/UnicodeRange.h>
#include <LibWeb/CSS/CSSStyleDeclaration.h>
#include <LibWeb/CSS/FontFace.h>
#include <LibWeb/CSS/GeneralEnclosed.h>
#include <LibWeb/CSS/MediaQuery.h>
#include <LibWeb/CSS/ParsedFontFace.h>
#include <LibWeb/CSS/Parser/Block.h>
#include <LibWeb/CSS/Parser/ComponentValue.h>
#include <LibWeb/CSS/Parser/Declaration.h>
Expand Down Expand Up @@ -162,7 +162,7 @@ class Parser {
Optional<GeneralEnclosed> parse_general_enclosed(TokenStream<ComponentValue>&);

CSSRule* parse_font_face_rule(TokenStream<ComponentValue>&);
Vector<FontFace::Source> parse_font_face_src(TokenStream<ComponentValue>&);
Vector<ParsedFontFace::Source> parse_font_face_src(TokenStream<ComponentValue>&);

CSSRule* convert_to_rule(NonnullRefPtr<Rule>);
CSSMediaRule* convert_to_media_rule(NonnullRefPtr<Rule>);
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/Forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ class FilterValueListStyleValue;
class Flex;
class FlexOrCalculated;
class FlexStyleValue;
class FontFace;
class Frequency;
class FrequencyOrCalculated;
class FrequencyPercentage;
Expand Down Expand Up @@ -159,6 +158,7 @@ class MediaQueryListEvent;
class Number;
class NumberOrCalculated;
class NumberStyleValue;
class ParsedFontFace;
class Percentage;
class PercentageOrCalculated;
class PercentageStyleValue;
Expand Down

0 comments on commit 3a5eabc

Please sign in to comment.