mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-26 19:32:06 -05:00
LibWeb: Replace FontStyleValue with ShorthandStyleValue
Also, actually include font-variant since we were already parsing it but throwing it away.
This commit is contained in:
parent
34591549b1
commit
9b4ddff6a9
8 changed files with 25 additions and 35 deletions
|
@ -15,7 +15,6 @@ source_set("StyleValues") {
|
|||
"EasingStyleValue.cpp",
|
||||
"EdgeStyleValue.cpp",
|
||||
"FilterValueListStyleValue.cpp",
|
||||
"FontStyleValue.cpp",
|
||||
"GridAreaShorthandStyleValue.cpp",
|
||||
"GridAutoFlowStyleValue.cpp",
|
||||
"GridTemplateAreaStyleValue.cpp",
|
||||
|
|
|
@ -92,7 +92,6 @@ set(SOURCES
|
|||
CSS/StyleValues/EasingStyleValue.cpp
|
||||
CSS/StyleValues/EdgeStyleValue.cpp
|
||||
CSS/StyleValues/FilterValueListStyleValue.cpp
|
||||
CSS/StyleValues/FontStyleValue.cpp
|
||||
CSS/StyleValues/GridAreaShorthandStyleValue.cpp
|
||||
CSS/StyleValues/GridAutoFlowStyleValue.cpp
|
||||
CSS/StyleValues/GridTemplateAreaStyleValue.cpp
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/EasingStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FontStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridAreaShorthandStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h>
|
||||
|
@ -4094,16 +4093,20 @@ RefPtr<StyleValue> Parser::parse_font_value(Vector<ComponentValue> const& compon
|
|||
if (!font_size || !font_families)
|
||||
return nullptr;
|
||||
|
||||
if (!font_stretch)
|
||||
font_stretch = property_initial_value(m_context.realm(), PropertyID::FontStretch);
|
||||
if (!font_style)
|
||||
font_style = property_initial_value(m_context.realm(), PropertyID::FontStyle);
|
||||
if (!font_variant)
|
||||
font_variant = property_initial_value(m_context.realm(), PropertyID::FontVariant);
|
||||
if (!font_weight)
|
||||
font_weight = property_initial_value(m_context.realm(), PropertyID::FontWeight);
|
||||
if (!font_stretch)
|
||||
font_stretch = property_initial_value(m_context.realm(), PropertyID::FontStretch);
|
||||
if (!line_height)
|
||||
line_height = property_initial_value(m_context.realm(), PropertyID::LineHeight);
|
||||
|
||||
return FontStyleValue::create(font_stretch.release_nonnull(), font_style.release_nonnull(), font_weight.release_nonnull(), font_size.release_nonnull(), line_height.release_nonnull(), font_families.release_nonnull());
|
||||
return ShorthandStyleValue::create(PropertyID::Font,
|
||||
{ PropertyID::FontStyle, PropertyID::FontVariant, PropertyID::FontWeight, PropertyID::FontStretch, PropertyID::FontSize, PropertyID::LineHeight, PropertyID::FontFamily },
|
||||
{ font_style.release_nonnull(), font_variant.release_nonnull(), font_weight.release_nonnull(), font_stretch.release_nonnull(), font_size.release_nonnull(), line_height.release_nonnull(), font_families.release_nonnull() });
|
||||
}
|
||||
|
||||
RefPtr<StyleValue> Parser::parse_font_family_value(TokenStream<ComponentValue>& tokens)
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/EasingStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FontStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridAreaShorthandStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackPlacementShorthandStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
|
||||
|
@ -751,25 +750,13 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::Font) {
|
||||
if (value.is_font()) {
|
||||
auto const& font_shorthand = value.as_font();
|
||||
set_longhand_property(CSS::PropertyID::FontSize, font_shorthand.font_size());
|
||||
set_longhand_property(CSS::PropertyID::FontFamily, font_shorthand.font_families());
|
||||
set_longhand_property(CSS::PropertyID::FontStretch, font_shorthand.font_stretch());
|
||||
set_longhand_property(CSS::PropertyID::FontStyle, font_shorthand.font_style());
|
||||
set_longhand_property(CSS::PropertyID::FontWeight, font_shorthand.font_weight());
|
||||
set_longhand_property(CSS::PropertyID::LineHeight, font_shorthand.line_height());
|
||||
// FIXME: Implement font-variant
|
||||
return;
|
||||
}
|
||||
|
||||
set_longhand_property(CSS::PropertyID::FontStyle, value);
|
||||
set_longhand_property(CSS::PropertyID::FontVariant, value);
|
||||
set_longhand_property(CSS::PropertyID::FontWeight, value);
|
||||
set_longhand_property(CSS::PropertyID::FontStretch, value);
|
||||
set_longhand_property(CSS::PropertyID::FontSize, value);
|
||||
set_longhand_property(CSS::PropertyID::FontFamily, value);
|
||||
set_longhand_property(CSS::PropertyID::FontStyle, value);
|
||||
set_longhand_property(CSS::PropertyID::FontWeight, value);
|
||||
set_longhand_property(CSS::PropertyID::LineHeight, value);
|
||||
// FIXME: Implement font-variant
|
||||
set_longhand_property(CSS::PropertyID::FontFamily, value);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/EasingStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FontStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridAreaShorthandStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h>
|
||||
|
|
|
@ -97,7 +97,6 @@ using StyleValueVector = Vector<ValueComparingNonnullRefPtr<StyleValue const>>;
|
|||
__ENUMERATE_STYLE_VALUE_TYPE(Easing, easing) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(Edge, edge) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(FilterValueList, filter_value_list) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(Font, font) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(Frequency, frequency) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(GridAreaShorthand, grid_area_shorthand) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(GridAutoFlow, grid_auto_flow) \
|
||||
|
|
|
@ -103,7 +103,6 @@ class ElementInlineCSSStyleDeclaration;
|
|||
class ExplicitGridTrack;
|
||||
class FilterValueListStyleValue;
|
||||
class FontFace;
|
||||
class FontStyleValue;
|
||||
class Frequency;
|
||||
class FrequencyOrCalculated;
|
||||
class FrequencyPercentage;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/StyleComputer.h>
|
||||
#include <LibWeb/CSS/StyleValues/FontStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ShorthandStyleValue.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/HTML/Canvas/CanvasState.h>
|
||||
|
||||
|
@ -28,12 +28,12 @@ public:
|
|||
}
|
||||
|
||||
// On getting, the font attribute must return the serialized form of the current font of the context (with no 'line-height' component).
|
||||
auto const& font_style_value = my_drawing_state().font_style_value->as_font();
|
||||
return DeprecatedString::formatted("{} {} {} {}",
|
||||
font_style_value.font_style()->to_string(),
|
||||
font_style_value.font_weight()->to_string(),
|
||||
font_style_value.font_size()->to_string(),
|
||||
font_style_value.font_families()->to_string());
|
||||
auto const& font_style_value = my_drawing_state().font_style_value->as_shorthand();
|
||||
auto font_style = font_style_value.longhand(CSS::PropertyID::FontStyle);
|
||||
auto font_weight = font_style_value.longhand(CSS::PropertyID::FontWeight);
|
||||
auto font_size = font_style_value.longhand(CSS::PropertyID::FontSize);
|
||||
auto font_family = font_style_value.longhand(CSS::PropertyID::FontFamily);
|
||||
return DeprecatedString::formatted("{} {} {} {}", font_style->to_string(), font_weight->to_string(), font_size->to_string(), font_family->to_string());
|
||||
}
|
||||
|
||||
void set_font(StringView font)
|
||||
|
@ -51,9 +51,14 @@ public:
|
|||
my_drawing_state().font_style_value = font_style_value_result.release_nonnull();
|
||||
|
||||
// Load font with font style value properties
|
||||
auto const& font_style_value = my_drawing_state().font_style_value->as_font();
|
||||
auto const& font_style_value = my_drawing_state().font_style_value->as_shorthand();
|
||||
auto& canvas_element = reinterpret_cast<IncludingClass&>(*this).canvas_element();
|
||||
my_drawing_state().current_font = canvas_element.document().style_computer().compute_font_for_style_values(&canvas_element, {}, font_style_value.font_families(), font_style_value.font_size(), font_style_value.font_style(), font_style_value.font_weight(), font_style_value.font_stretch());
|
||||
auto& font_style = *font_style_value.longhand(CSS::PropertyID::FontStyle);
|
||||
auto& font_weight = *font_style_value.longhand(CSS::PropertyID::FontWeight);
|
||||
auto& font_stretch = *font_style_value.longhand(CSS::PropertyID::FontStretch);
|
||||
auto& font_size = *font_style_value.longhand(CSS::PropertyID::FontSize);
|
||||
auto& font_family = *font_style_value.longhand(CSS::PropertyID::FontFamily);
|
||||
my_drawing_state().current_font = canvas_element.document().style_computer().compute_font_for_style_values(&canvas_element, {}, font_family, font_size, font_style, font_weight, font_stretch);
|
||||
}
|
||||
|
||||
Bindings::CanvasTextAlign text_align() const { return my_drawing_state().text_align; }
|
||||
|
|
Loading…
Add table
Reference in a new issue