mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-19 00:31:52 +00:00
LibWeb/CSS: Inline CSSStyleValue::to_font_variant_foo() methods
Now that these are only called from ComputedProperties getters, we can put the code there directly.
This commit is contained in:
parent
62c18d1dec
commit
80eee82ea9
Notes:
github-actions[bot]
2025-02-12 16:01:49 +00:00
Author: https://github.com/AtkinsSJ
Commit: 80eee82ea9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3482
Reviewed-by: https://github.com/jdahlin
3 changed files with 163 additions and 210 deletions
|
@ -474,200 +474,4 @@ int CSSStyleValue::to_font_width() const
|
|||
return width;
|
||||
}
|
||||
|
||||
Optional<Gfx::FontVariantAlternates> CSSStyleValue::to_font_variant_alternates() const
|
||||
{
|
||||
VERIFY(is_keyword());
|
||||
switch (as_keyword().keyword()) {
|
||||
case Keyword::Normal:
|
||||
return {};
|
||||
case Keyword::HistoricalForms:
|
||||
return Gfx::FontVariantAlternates { .historical_forms = true };
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
Optional<FontVariantCaps> CSSStyleValue::to_font_variant_caps() const
|
||||
{
|
||||
VERIFY(is_keyword());
|
||||
return keyword_to_font_variant_caps(as_keyword().keyword());
|
||||
}
|
||||
|
||||
Optional<Gfx::FontVariantEastAsian> CSSStyleValue::to_font_variant_east_asian() const
|
||||
{
|
||||
Gfx::FontVariantEastAsian east_asian {};
|
||||
bool normal = false;
|
||||
|
||||
auto apply_keyword = [&east_asian, &normal](Keyword keyword) {
|
||||
switch (keyword) {
|
||||
case Keyword::Normal:
|
||||
normal = true;
|
||||
break;
|
||||
case Keyword::Jis78:
|
||||
east_asian.variant = Gfx::FontVariantEastAsian::Variant::Jis78;
|
||||
break;
|
||||
case Keyword::Jis83:
|
||||
east_asian.variant = Gfx::FontVariantEastAsian::Variant::Jis83;
|
||||
break;
|
||||
case Keyword::Jis90:
|
||||
east_asian.variant = Gfx::FontVariantEastAsian::Variant::Jis90;
|
||||
break;
|
||||
case Keyword::Jis04:
|
||||
east_asian.variant = Gfx::FontVariantEastAsian::Variant::Jis04;
|
||||
break;
|
||||
case Keyword::Simplified:
|
||||
east_asian.variant = Gfx::FontVariantEastAsian::Variant::Simplified;
|
||||
break;
|
||||
case Keyword::Traditional:
|
||||
east_asian.variant = Gfx::FontVariantEastAsian::Variant::Traditional;
|
||||
break;
|
||||
case Keyword::FullWidth:
|
||||
east_asian.width = Gfx::FontVariantEastAsian::Width::FullWidth;
|
||||
break;
|
||||
case Keyword::ProportionalWidth:
|
||||
east_asian.width = Gfx::FontVariantEastAsian::Width::Proportional;
|
||||
break;
|
||||
case Keyword::Ruby:
|
||||
east_asian.ruby = true;
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
};
|
||||
|
||||
if (is_keyword()) {
|
||||
apply_keyword(to_keyword());
|
||||
} else if (is_value_list()) {
|
||||
for (auto& value : as_value_list().values()) {
|
||||
apply_keyword(value->to_keyword());
|
||||
}
|
||||
}
|
||||
|
||||
if (normal)
|
||||
return {};
|
||||
|
||||
return east_asian;
|
||||
}
|
||||
|
||||
Optional<FontVariantEmoji> CSSStyleValue::to_font_variant_emoji() const
|
||||
{
|
||||
VERIFY(is_keyword());
|
||||
return keyword_to_font_variant_emoji(as_keyword().keyword());
|
||||
}
|
||||
|
||||
Optional<Gfx::FontVariantLigatures> CSSStyleValue::to_font_variant_ligatures() const
|
||||
{
|
||||
Gfx::FontVariantLigatures ligatures {};
|
||||
bool normal = false;
|
||||
|
||||
auto apply_keyword = [&ligatures, &normal](Keyword keyword) {
|
||||
switch (keyword) {
|
||||
case Keyword::Normal:
|
||||
normal = true;
|
||||
break;
|
||||
case Keyword::None:
|
||||
ligatures.none = true;
|
||||
break;
|
||||
case Keyword::CommonLigatures:
|
||||
ligatures.common = Gfx::FontVariantLigatures::Common::Common;
|
||||
break;
|
||||
case Keyword::NoCommonLigatures:
|
||||
ligatures.common = Gfx::FontVariantLigatures::Common::NoCommon;
|
||||
break;
|
||||
case Keyword::DiscretionaryLigatures:
|
||||
ligatures.discretionary = Gfx::FontVariantLigatures::Discretionary::Discretionary;
|
||||
break;
|
||||
case Keyword::NoDiscretionaryLigatures:
|
||||
ligatures.discretionary = Gfx::FontVariantLigatures::Discretionary::NoDiscretionary;
|
||||
break;
|
||||
case Keyword::HistoricalLigatures:
|
||||
ligatures.historical = Gfx::FontVariantLigatures::Historical::Historical;
|
||||
break;
|
||||
case Keyword::NoHistoricalLigatures:
|
||||
ligatures.historical = Gfx::FontVariantLigatures::Historical::NoHistorical;
|
||||
break;
|
||||
case Keyword::Contextual:
|
||||
ligatures.contextual = Gfx::FontVariantLigatures::Contextual::Contextual;
|
||||
break;
|
||||
case Keyword::NoContextual:
|
||||
ligatures.contextual = Gfx::FontVariantLigatures::Contextual::NoContextual;
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
};
|
||||
|
||||
if (is_keyword()) {
|
||||
apply_keyword(to_keyword());
|
||||
} else if (is_value_list()) {
|
||||
for (auto& value : as_value_list().values()) {
|
||||
apply_keyword(value->to_keyword());
|
||||
}
|
||||
}
|
||||
|
||||
if (normal)
|
||||
return {};
|
||||
|
||||
return ligatures;
|
||||
}
|
||||
|
||||
Optional<Gfx::FontVariantNumeric> CSSStyleValue::to_font_variant_numeric() const
|
||||
{
|
||||
Gfx::FontVariantNumeric numeric {};
|
||||
bool normal = false;
|
||||
|
||||
auto apply_keyword = [&numeric, &normal](Keyword keyword) {
|
||||
switch (keyword) {
|
||||
case Keyword::Normal:
|
||||
normal = true;
|
||||
break;
|
||||
case Keyword::Ordinal:
|
||||
numeric.ordinal = true;
|
||||
break;
|
||||
case Keyword::SlashedZero:
|
||||
numeric.slashed_zero = true;
|
||||
break;
|
||||
case Keyword::OldstyleNums:
|
||||
numeric.figure = Gfx::FontVariantNumeric::Figure::Oldstyle;
|
||||
break;
|
||||
case Keyword::LiningNums:
|
||||
numeric.figure = Gfx::FontVariantNumeric::Figure::Lining;
|
||||
break;
|
||||
case Keyword::ProportionalNums:
|
||||
numeric.spacing = Gfx::FontVariantNumeric::Spacing::Proportional;
|
||||
break;
|
||||
case Keyword::TabularNums:
|
||||
numeric.spacing = Gfx::FontVariantNumeric::Spacing::Tabular;
|
||||
break;
|
||||
case Keyword::DiagonalFractions:
|
||||
numeric.fraction = Gfx::FontVariantNumeric::Fraction::Diagonal;
|
||||
break;
|
||||
case Keyword::StackedFractions:
|
||||
numeric.fraction = Gfx::FontVariantNumeric::Fraction::Stacked;
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
};
|
||||
|
||||
if (is_keyword()) {
|
||||
apply_keyword(to_keyword());
|
||||
} else if (is_value_list()) {
|
||||
for (auto& value : as_value_list().values()) {
|
||||
apply_keyword(value->to_keyword());
|
||||
}
|
||||
}
|
||||
|
||||
if (normal)
|
||||
return {};
|
||||
|
||||
return numeric;
|
||||
}
|
||||
|
||||
Optional<FontVariantPosition> CSSStyleValue::to_font_variant_position() const
|
||||
{
|
||||
VERIFY(is_keyword());
|
||||
return keyword_to_font_variant_position(as_keyword().keyword());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue