diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-04-14 11:52:35 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-14 14:54:06 +0200 |
commit | e941f07931818c3db67732707bd8132f4729beb1 (patch) | |
tree | f202bf9b44410ddd929ec5bb341e437b14d38560 /Userland/Libraries | |
parent | a20188cd917f787b9dcc8612eba8efcf949cde01 (diff) | |
download | serenity-e941f07931818c3db67732707bd8132f4729beb1.zip |
LibWeb: Make StyleProperties::property() always return a value
By the time that property() gets called, we've already given every
single property a value, so we can just return it. This simplifies a
lot of places that were manually handling a lack of value
unnecessarily.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleProperties.cpp | 208 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleProperties.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Node.cpp | 58 |
5 files changed, 109 insertions, 189 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index d943a7c99e..a43077c5d8 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -400,12 +400,10 @@ Optional<StyleProperty> ResolvedCSSStyleDeclaration::property(PropertyID propert if (!m_element->layout_node()) { auto style = m_element->document().style_computer().compute_style(const_cast<DOM::Element&>(*m_element)); - if (auto maybe_property = style->property(property_id); maybe_property.has_value()) { - return StyleProperty { - .property_id = property_id, - .value = maybe_property.release_value(), - }; - } + return StyleProperty { + .property_id = property_id, + .value = style->property(property_id), + }; return {}; } diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 61228e0b70..07d970d6a3 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -772,7 +772,7 @@ static NonnullRefPtr<StyleValue> get_inherit_value(CSS::PropertyID property_id, if (!parent_element || !parent_element->computed_css_values()) return property_initial_value(property_id); - return parent_element->computed_css_values()->property(property_id).release_value(); + return parent_element->computed_css_values()->property(property_id); }; void StyleComputer::compute_defaulted_property_value(StyleProperties& style, DOM::Element const* element, CSS::PropertyID property_id, Optional<CSS::Selector::PseudoElement> pseudo_element) const @@ -835,11 +835,9 @@ float StyleComputer::root_element_font_size() const if (!computed_root_style) return default_root_element_font_size; - auto maybe_root_value = computed_root_style->property(CSS::PropertyID::FontSize); - if (!maybe_root_value.has_value()) - return default_root_element_font_size; + auto root_value = computed_root_style->property(CSS::PropertyID::FontSize); - return maybe_root_value.value()->to_length().to_px(viewport_rect(), computed_root_style->computed_font().pixel_metrics(), default_root_element_font_size, default_root_element_font_size); + return root_value->to_length().to_px(viewport_rect(), computed_root_style->computed_font().pixel_metrics(), default_root_element_font_size, default_root_element_font_size); } void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* element, Optional<CSS::Selector::PseudoElement> pseudo_element) const @@ -853,9 +851,9 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele auto* parent_element = get_parent_element(element, pseudo_element); - auto font_size = style.property(CSS::PropertyID::FontSize).value(); - auto font_style = style.property(CSS::PropertyID::FontStyle).value(); - auto font_weight = style.property(CSS::PropertyID::FontWeight).value(); + auto font_size = style.property(CSS::PropertyID::FontSize); + auto font_style = style.property(CSS::PropertyID::FontStyle); + auto font_weight = style.property(CSS::PropertyID::FontWeight); int weight = Gfx::FontWeight::Regular; if (font_weight->is_identifier()) { @@ -930,7 +928,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele auto parent_font_size = [&]() -> float { if (!parent_element || !parent_element->computed_css_values()) return font_size_in_px; - auto value = parent_element->computed_css_values()->property(CSS::PropertyID::FontSize).value(); + auto value = parent_element->computed_css_values()->property(CSS::PropertyID::FontSize); if (value->is_length()) { auto length = static_cast<LengthStyleValue const&>(*value).to_length(); if (length.is_absolute() || length.is_relative()) @@ -1028,7 +1026,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele RefPtr<Gfx::Font> found_font; - auto family_value = style.property(PropertyID::FontFamily).value(); + auto family_value = style.property(PropertyID::FontFamily); if (family_value->is_value_list()) { auto const& family_list = static_cast<StyleValueList const&>(*family_value).values(); for (auto const& family : family_list) { @@ -1068,7 +1066,7 @@ void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const { auto font_metrics = style.computed_font().pixel_metrics(); float root_font_size = root_element_font_size(); - float font_size = style.property(CSS::PropertyID::FontSize).value()->to_length().to_px(viewport_rect(), font_metrics, root_font_size, root_font_size); + float font_size = style.property(CSS::PropertyID::FontSize)->to_length().to_px(viewport_rect(), font_metrics, root_font_size, root_font_size); for (size_t i = 0; i < style.m_property_values.size(); ++i) { auto& value_slot = style.m_property_values[i]; diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index e97a1ce5b2..38bfe0b2f9 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -35,20 +35,17 @@ void StyleProperties::set_property(CSS::PropertyID id, NonnullRefPtr<StyleValue> m_property_values[to_underlying(id)] = move(value); } -Optional<NonnullRefPtr<StyleValue>> StyleProperties::property(CSS::PropertyID property_id) const +NonnullRefPtr<StyleValue> StyleProperties::property(CSS::PropertyID property_id) const { auto value = m_property_values[to_underlying(property_id)]; - if (!value) - return {}; + // By the time we call this method, all properties have values assigned. + VERIFY(!value.is_null()); return value.release_nonnull(); } Length StyleProperties::length_or_fallback(CSS::PropertyID id, Length const& fallback) const { - auto maybe_value = property(id); - if (!maybe_value.has_value()) - return fallback; - auto& value = maybe_value.value(); + auto value = property(id); if (value->is_calculated()) return Length::make_calculated(value->as_calculated()); @@ -66,10 +63,7 @@ LengthPercentage StyleProperties::length_percentage_or_fallback(CSS::PropertyID Optional<LengthPercentage> StyleProperties::length_percentage(CSS::PropertyID id) const { - auto maybe_value = property(id); - if (!maybe_value.has_value()) - return {}; - auto& value = maybe_value.value(); + auto value = property(id); if (value->is_calculated()) return LengthPercentage { value->as_calculated() }; @@ -96,9 +90,9 @@ LengthBox StyleProperties::length_box(CSS::PropertyID left_id, CSS::PropertyID t Color StyleProperties::color_or_fallback(CSS::PropertyID id, Layout::NodeWithStyle const& node, Color fallback) const { auto value = property(id); - if (!value.has_value() || !value.value()->has_color()) + if (!value->has_color()) return fallback; - return value.value()->to_color(node); + return value->to_color(node); } NonnullRefPtr<Gfx::Font> StyleProperties::font_fallback(bool monospace, bool bold) @@ -117,26 +111,24 @@ NonnullRefPtr<Gfx::Font> StyleProperties::font_fallback(bool monospace, bool bol float StyleProperties::line_height(Layout::Node const& layout_node) const { - if (auto maybe_line_height = property(CSS::PropertyID::LineHeight); maybe_line_height.has_value()) { - auto line_height = maybe_line_height.release_value(); + auto line_height = property(CSS::PropertyID::LineHeight); - if (line_height->is_identifier() && line_height->to_identifier() == ValueID::Normal) - return layout_node.font().pixel_metrics().line_spacing(); + if (line_height->is_identifier() && line_height->to_identifier() == ValueID::Normal) + return layout_node.font().pixel_metrics().line_spacing(); - if (line_height->is_length()) { - auto line_height_length = line_height->to_length(); - if (!line_height_length.is_auto()) - return line_height_length.to_px(layout_node); - } + if (line_height->is_length()) { + auto line_height_length = line_height->to_length(); + if (!line_height_length.is_auto()) + return line_height_length.to_px(layout_node); + } - if (line_height->is_numeric()) - return Length(line_height->to_number(), Length::Type::Em).to_px(layout_node); + if (line_height->is_numeric()) + return Length(line_height->to_number(), Length::Type::Em).to_px(layout_node); - if (line_height->is_percentage()) { - // Percentages are relative to 1em. https://www.w3.org/TR/css-inline-3/#valdef-line-height-percentage - auto& percentage = line_height->as_percentage().percentage(); - return Length(percentage.as_fraction(), Length::Type::Em).to_px(layout_node); - } + if (line_height->is_percentage()) { + // Percentages are relative to 1em. https://www.w3.org/TR/css-inline-3/#valdef-line-height-percentage + auto& percentage = line_height->as_percentage().percentage(); + return Length(percentage.as_fraction(), Length::Type::Em).to_px(layout_node); } return layout_node.font().pixel_metrics().line_spacing(); @@ -144,11 +136,7 @@ float StyleProperties::line_height(Layout::Node const& layout_node) const Optional<int> StyleProperties::z_index() const { - auto maybe_value = property(CSS::PropertyID::ZIndex); - if (!maybe_value.has_value()) - return {}; - auto& value = maybe_value.value(); - + auto value = property(CSS::PropertyID::ZIndex); if (value->has_auto()) return {}; if (value->has_integer()) @@ -158,10 +146,7 @@ Optional<int> StyleProperties::z_index() const float StyleProperties::opacity() const { - auto maybe_value = property(CSS::PropertyID::Opacity); - if (!maybe_value.has_value()) - return 1.0f; - auto& value = maybe_value.value(); + auto value = property(CSS::PropertyID::Opacity); float unclamped_opacity = 1.0f; @@ -192,25 +177,18 @@ float StyleProperties::opacity() const Optional<CSS::FlexDirection> StyleProperties::flex_direction() const { auto value = property(CSS::PropertyID::FlexDirection); - if (!value.has_value()) - return {}; - return value_id_to_flex_direction(value.value()->to_identifier()); + return value_id_to_flex_direction(value->to_identifier()); } Optional<CSS::FlexWrap> StyleProperties::flex_wrap() const { auto value = property(CSS::PropertyID::FlexWrap); - if (!value.has_value()) - return {}; - return value_id_to_flex_wrap(value.value()->to_identifier()); + return value_id_to_flex_wrap(value->to_identifier()); } Optional<CSS::FlexBasisData> StyleProperties::flex_basis() const { - auto maybe_value = property(CSS::PropertyID::FlexBasis); - if (!maybe_value.has_value()) - return {}; - auto& value = maybe_value.value(); + auto value = property(CSS::PropertyID::FlexBasis); if (value->is_identifier() && value->to_identifier() == CSS::ValueID::Content) return { { CSS::FlexBasis::Content, {} } }; @@ -230,56 +208,50 @@ Optional<CSS::FlexBasisData> StyleProperties::flex_basis() const float StyleProperties::flex_grow() const { auto value = property(CSS::PropertyID::FlexGrow); - if (!value.has_value() || !value.value()->has_number()) + if (!value->has_number()) return 0; - return value.value()->to_number(); + return value->to_number(); } float StyleProperties::flex_shrink() const { auto value = property(CSS::PropertyID::FlexShrink); - if (!value.has_value() || !value.value()->has_number()) + if (!value->has_number()) return 1; - return value.value()->to_number(); + return value->to_number(); } int StyleProperties::order() const { auto value = property(CSS::PropertyID::Order); - if (!value.has_value() || !value.value()->has_integer()) + if (!value->has_integer()) return 0; - return value.value()->to_integer(); + return value->to_integer(); } Optional<CSS::ImageRendering> StyleProperties::image_rendering() const { auto value = property(CSS::PropertyID::ImageRendering); - if (!value.has_value()) - return {}; - return value_id_to_image_rendering(value.value()->to_identifier()); + return value_id_to_image_rendering(value->to_identifier()); } Optional<CSS::JustifyContent> StyleProperties::justify_content() const { auto value = property(CSS::PropertyID::JustifyContent); - if (!value.has_value()) - return {}; - return value_id_to_justify_content(value.value()->to_identifier()); + return value_id_to_justify_content(value->to_identifier()); } Vector<CSS::Transformation> StyleProperties::transformations() const { auto value = property(CSS::PropertyID::Transform); - if (!value.has_value()) - return {}; - if (value.value()->is_identifier() && value.value()->to_identifier() == CSS::ValueID::None) + if (value->is_identifier() && value->to_identifier() == CSS::ValueID::None) return {}; - if (!value.value()->is_value_list()) + if (!value->is_value_list()) return {}; - auto& list = value.value()->as_value_list(); + auto& list = value->as_value_list(); Vector<CSS::Transformation> transformations; @@ -321,9 +293,9 @@ static Optional<LengthPercentage> length_percentage_for_style_value(StyleValue c CSS::TransformOrigin StyleProperties::transform_origin() const { auto value = property(CSS::PropertyID::TransformOrigin); - if (!value.has_value() || !value.value()->is_value_list() || value.value()->as_value_list().size() != 2) + if (!value->is_value_list() || value->as_value_list().size() != 2) return {}; - auto const& list = value.value()->as_value_list(); + auto const& list = value->as_value_list(); auto x_value = length_percentage_for_style_value(list.values()[0]); auto y_value = length_percentage_for_style_value(list.values()[1]); if (!x_value.has_value() || !y_value.has_value()) { @@ -335,17 +307,13 @@ CSS::TransformOrigin StyleProperties::transform_origin() const Optional<CSS::AlignItems> StyleProperties::align_items() const { auto value = property(CSS::PropertyID::AlignItems); - if (!value.has_value()) - return {}; - return value_id_to_align_items(value.value()->to_identifier()); + return value_id_to_align_items(value->to_identifier()); } Optional<CSS::Position> StyleProperties::position() const { auto value = property(CSS::PropertyID::Position); - if (!value.has_value()) - return {}; - return value_id_to_position(value.value()->to_identifier()); + return value_id_to_position(value->to_identifier()); } bool StyleProperties::operator==(StyleProperties const& other) const @@ -377,66 +345,48 @@ bool StyleProperties::operator==(StyleProperties const& other) const Optional<CSS::TextAlign> StyleProperties::text_align() const { auto value = property(CSS::PropertyID::TextAlign); - if (!value.has_value()) - return {}; - return value_id_to_text_align(value.value()->to_identifier()); + return value_id_to_text_align(value->to_identifier()); } Optional<CSS::TextJustify> StyleProperties::text_justify() const { auto value = property(CSS::PropertyID::TextJustify); - if (!value.has_value()) - return {}; - return value_id_to_text_justify(value.value()->to_identifier()); + return value_id_to_text_justify(value->to_identifier()); } Optional<CSS::PointerEvents> StyleProperties::pointer_events() const { auto value = property(CSS::PropertyID::PointerEvents); - if (!value.has_value()) - return {}; - return value_id_to_pointer_events(value.value()->to_identifier()); + return value_id_to_pointer_events(value->to_identifier()); } Optional<CSS::WhiteSpace> StyleProperties::white_space() const { auto value = property(CSS::PropertyID::WhiteSpace); - if (!value.has_value()) - return {}; - return value_id_to_white_space(value.value()->to_identifier()); + return value_id_to_white_space(value->to_identifier()); } Optional<CSS::LineStyle> StyleProperties::line_style(CSS::PropertyID property_id) const { auto value = property(property_id); - if (!value.has_value()) - return {}; - return value_id_to_line_style(value.value()->to_identifier()); + return value_id_to_line_style(value->to_identifier()); } Optional<CSS::Float> StyleProperties::float_() const { auto value = property(CSS::PropertyID::Float); - if (!value.has_value()) - return {}; - return value_id_to_float(value.value()->to_identifier()); + return value_id_to_float(value->to_identifier()); } Optional<CSS::Clear> StyleProperties::clear() const { auto value = property(CSS::PropertyID::Clear); - if (!value.has_value()) - return {}; - return value_id_to_clear(value.value()->to_identifier()); + return value_id_to_clear(value->to_identifier()); } CSS::ContentData StyleProperties::content() const { - auto maybe_value = property(CSS::PropertyID::Content); - if (!maybe_value.has_value()) - return CSS::ContentData {}; - - auto& value = maybe_value.value(); + auto value = property(CSS::PropertyID::Content); if (value->is_content()) { auto& content_style_value = value->as_content(); @@ -486,25 +436,23 @@ CSS::ContentData StyleProperties::content() const Optional<CSS::Cursor> StyleProperties::cursor() const { auto value = property(CSS::PropertyID::Cursor); - if (!value.has_value()) - return {}; - return value_id_to_cursor(value.value()->to_identifier()); + return value_id_to_cursor(value->to_identifier()); } Optional<CSS::Visibility> StyleProperties::visibility() const { auto value = property(CSS::PropertyID::Visibility); - if (!value.has_value() || !value.value()->is_identifier()) + if (!value->is_identifier()) return {}; - return value_id_to_visibility(value.value()->to_identifier()); + return value_id_to_visibility(value->to_identifier()); } CSS::Display StyleProperties::display() const { auto value = property(CSS::PropertyID::Display); - if (!value.has_value() || !value.value()->is_identifier()) + if (!value->is_identifier()) return CSS::Display::from_short(CSS::Display::Short::Inline); - switch (value.value()->to_identifier()) { + switch (value->to_identifier()) { case CSS::ValueID::None: return CSS::Display::from_short(CSS::Display::Short::None); case CSS::ValueID::Block: @@ -545,33 +493,25 @@ CSS::Display StyleProperties::display() const Optional<CSS::TextDecorationLine> StyleProperties::text_decoration_line() const { auto value = property(CSS::PropertyID::TextDecorationLine); - if (!value.has_value()) - return {}; - return value_id_to_text_decoration_line(value.value()->to_identifier()); + return value_id_to_text_decoration_line(value->to_identifier()); } Optional<CSS::TextDecorationStyle> StyleProperties::text_decoration_style() const { auto value = property(CSS::PropertyID::TextDecorationStyle); - if (!value.has_value()) - return {}; - return value_id_to_text_decoration_style(value.value()->to_identifier()); + return value_id_to_text_decoration_style(value->to_identifier()); } Optional<CSS::TextTransform> StyleProperties::text_transform() const { auto value = property(CSS::PropertyID::TextTransform); - if (!value.has_value()) - return {}; - return value_id_to_text_transform(value.value()->to_identifier()); + return value_id_to_text_transform(value->to_identifier()); } Optional<CSS::ListStyleType> StyleProperties::list_style_type() const { auto value = property(CSS::PropertyID::ListStyleType); - if (!value.has_value()) - return {}; - return value_id_to_list_style_type(value.value()->to_identifier()); + return value_id_to_list_style_type(value->to_identifier()); } Optional<CSS::Overflow> StyleProperties::overflow_x() const @@ -587,18 +527,12 @@ Optional<CSS::Overflow> StyleProperties::overflow_y() const Optional<CSS::Overflow> StyleProperties::overflow(CSS::PropertyID property_id) const { auto value = property(property_id); - if (!value.has_value()) - return {}; - return value_id_to_overflow(value.value()->to_identifier()); + return value_id_to_overflow(value->to_identifier()); } Vector<ShadowData> StyleProperties::shadow(PropertyID property_id) const { - auto value_or_error = property(property_id); - if (!value_or_error.has_value()) - return {}; - - auto value = value_or_error.value(); + auto value = property(property_id); auto make_shadow_data = [](ShadowStyleValue const& value) { return ShadowData { value.color(), value.offset_x(), value.offset_y(), value.blur_radius(), value.spread_distance(), value.placement() }; @@ -636,25 +570,21 @@ Vector<ShadowData> StyleProperties::text_shadow() const Optional<CSS::BoxSizing> StyleProperties::box_sizing() const { auto value = property(CSS::PropertyID::BoxSizing); - if (!value.has_value()) - return {}; - return value_id_to_box_sizing(value.value()->to_identifier()); + return value_id_to_box_sizing(value->to_identifier()); } Variant<CSS::VerticalAlign, CSS::LengthPercentage> StyleProperties::vertical_align() const { auto value = property(CSS::PropertyID::VerticalAlign); - if (!value.has_value()) - VERIFY_NOT_REACHED(); - if (value.value()->is_identifier()) - return value_id_to_vertical_align(value.value()->to_identifier()).release_value(); + if (value->is_identifier()) + return value_id_to_vertical_align(value->to_identifier()).release_value(); - if (value.value()->is_length()) - return CSS::LengthPercentage(value.value()->to_length()); + if (value->is_length()) + return CSS::LengthPercentage(value->to_length()); - if (value.value()->is_percentage()) - return CSS::LengthPercentage(value.value()->as_percentage().percentage()); + if (value->is_percentage()) + return CSS::LengthPercentage(value->as_percentage().percentage()); VERIFY_NOT_REACHED(); } @@ -662,9 +592,7 @@ Variant<CSS::VerticalAlign, CSS::LengthPercentage> StyleProperties::vertical_ali Optional<CSS::FontVariant> StyleProperties::font_variant() const { auto value = property(CSS::PropertyID::FontVariant); - if (!value.has_value()) - return {}; - return value_id_to_font_variant(value.value()->to_identifier()); + return value_id_to_font_variant(value->to_identifier()); } } diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h index 1a55552440..9826d266da 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h @@ -39,7 +39,7 @@ public: auto const& properties() const { return m_property_values; } void set_property(CSS::PropertyID, NonnullRefPtr<StyleValue> value); - Optional<NonnullRefPtr<StyleValue>> property(CSS::PropertyID) const; + NonnullRefPtr<StyleValue> property(CSS::PropertyID) const; Length length_or_fallback(CSS::PropertyID, Length const& fallback) const; LengthPercentage length_percentage_or_fallback(CSS::PropertyID, LengthPercentage const& fallback) const; diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 3ce80add85..729633876a 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -204,7 +204,7 @@ void NodeWithStyle::did_insert_into_layout_tree(CSS::StyleProperties const& styl auto const* containing_block = this->containing_block(); auto containing_block_has_definite_size = containing_block && (width ? containing_block->m_has_definite_width : containing_block->m_has_definite_height); - if (!maybe_value.has_value() || maybe_value.value()->has_auto()) { + if (maybe_value->has_auto()) { // NOTE: The width of a non-flex-item block is considered definite if it's auto and the containing block has definite width. if (width && is_block_container() && parent() && !parent()->computed_values().display().is_flex_inside()) return containing_block_has_definite_size; @@ -235,8 +235,8 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) // m_font is used by Length::to_px() when resolving sizes against this layout node. // That's why it has to be set before everything else. m_font = computed_style.computed_font(); - computed_values.set_font_size(computed_style.property(CSS::PropertyID::FontSize).value()->to_length().to_px(*this)); - computed_values.set_font_weight(computed_style.property(CSS::PropertyID::FontWeight).value()->to_integer()); + computed_values.set_font_size(computed_style.property(CSS::PropertyID::FontSize)->to_length().to_px(*this)); + computed_values.set_font_weight(computed_style.property(CSS::PropertyID::FontWeight)->to_integer()); m_line_height = computed_style.line_height(*this); computed_values.set_vertical_align(computed_style.vertical_align()); @@ -251,16 +251,13 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) auto sizes = computed_style.property(CSS::PropertyID::BackgroundSize); auto count_layers = [](auto maybe_style_value) -> size_t { - if (maybe_style_value.has_value() && maybe_style_value.value()->is_value_list()) - return maybe_style_value.value()->as_value_list().size(); + if (maybe_style_value->is_value_list()) + return maybe_style_value->as_value_list().size(); else return 1; }; - auto value_for_layer = [](auto maybe_style_value, size_t layer_index) -> RefPtr<CSS::StyleValue> { - if (!maybe_style_value.has_value()) - return nullptr; - auto& style_value = maybe_style_value.value(); + auto value_for_layer = [](auto& style_value, size_t layer_index) -> RefPtr<CSS::StyleValue> { if (style_value->is_value_list()) return style_value->as_value_list().value_at(layer_index, true); return style_value; @@ -371,20 +368,20 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) // FIXME: BorderXRadius properties are now BorderRadiusStyleValues, so make use of that. auto border_bottom_left_radius = computed_style.property(CSS::PropertyID::BorderBottomLeftRadius); - if (border_bottom_left_radius.has_value() && border_bottom_left_radius.value()->is_border_radius()) - computed_values.set_border_bottom_left_radius(border_bottom_left_radius.value()->as_border_radius().horizontal_radius()); + if (border_bottom_left_radius->is_border_radius()) + computed_values.set_border_bottom_left_radius(border_bottom_left_radius->as_border_radius().horizontal_radius()); auto border_bottom_right_radius = computed_style.property(CSS::PropertyID::BorderBottomRightRadius); - if (border_bottom_right_radius.has_value() && border_bottom_right_radius.value()->is_border_radius()) - computed_values.set_border_bottom_right_radius(border_bottom_right_radius.value()->as_border_radius().horizontal_radius()); + if (border_bottom_right_radius->is_border_radius()) + computed_values.set_border_bottom_right_radius(border_bottom_right_radius->as_border_radius().horizontal_radius()); auto border_top_left_radius = computed_style.property(CSS::PropertyID::BorderTopLeftRadius); - if (border_top_left_radius.has_value() && border_top_left_radius.value()->is_border_radius()) - computed_values.set_border_top_left_radius(border_top_left_radius.value()->as_border_radius().horizontal_radius()); + if (border_top_left_radius->is_border_radius()) + computed_values.set_border_top_left_radius(border_top_left_radius->as_border_radius().horizontal_radius()); auto border_top_right_radius = computed_style.property(CSS::PropertyID::BorderTopRightRadius); - if (border_top_right_radius.has_value() && border_top_right_radius.value()->is_border_radius()) - computed_values.set_border_top_right_radius(border_top_right_radius.value()->as_border_radius().horizontal_radius()); + if (border_top_right_radius->is_border_radius()) + computed_values.set_border_top_right_radius(border_top_right_radius->as_border_radius().horizontal_radius()); computed_values.set_display(computed_style.display()); @@ -472,8 +469,8 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) computed_values.set_list_style_type(list_style_type.value()); auto list_style_image = computed_style.property(CSS::PropertyID::ListStyleImage); - if (list_style_image.has_value() && list_style_image.value()->is_image()) { - m_list_style_image = list_style_image.value()->as_image(); + if (list_style_image->is_image()) { + m_list_style_image = list_style_image->as_image(); m_list_style_image->load_bitmap(document()); } @@ -539,18 +536,17 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) computed_values.set_content(computed_style.content()); - if (auto fill = computed_style.property(CSS::PropertyID::Fill); fill.has_value()) - computed_values.set_fill(fill.value()->to_color(*this)); - if (auto stroke = computed_style.property(CSS::PropertyID::Stroke); stroke.has_value()) - computed_values.set_stroke(stroke.value()->to_color(*this)); - if (auto stroke_width = computed_style.property(CSS::PropertyID::StrokeWidth); stroke_width.has_value()) { - // FIXME: Converting to pixels isn't really correct - values should be in "user units" - // https://svgwg.org/svg2-draft/coords.html#TermUserUnits - if (stroke_width.value()->is_numeric()) - computed_values.set_stroke_width(CSS::Length::make_px(stroke_width.value()->to_number())); - else - computed_values.set_stroke_width(stroke_width.value()->to_length()); - } + if (auto fill = computed_style.property(CSS::PropertyID::Fill); fill->has_color()) + computed_values.set_fill(fill->to_color(*this)); + if (auto stroke = computed_style.property(CSS::PropertyID::Stroke); stroke->has_color()) + computed_values.set_stroke(stroke->to_color(*this)); + auto stroke_width = computed_style.property(CSS::PropertyID::StrokeWidth); + // FIXME: Converting to pixels isn't really correct - values should be in "user units" + // https://svgwg.org/svg2-draft/coords.html#TermUserUnits + if (stroke_width->is_numeric()) + computed_values.set_stroke_width(CSS::Length::make_px(stroke_width->to_number())); + else + computed_values.set_stroke_width(stroke_width->to_length()); } bool Node::is_root_element() const |