diff --git a/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp b/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp index a606ef8f0d9..92c0ce6d034 100644 --- a/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp +++ b/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp @@ -939,8 +939,8 @@ static CSS::RequiredInvalidationAfterStyleChange compute_required_invalidation(H if (!old_and_new_properties.get(i)) continue; auto property_id = static_cast(i); - auto old_value = old_properties.get(property_id).value_or({}); - auto new_value = new_properties.get(property_id).value_or({}); + auto const* old_value = old_properties.get(property_id).value_or({}); + auto const* new_value = new_properties.get(property_id).value_or({}); if (!old_value && !new_value) continue; invalidation |= compute_property_invalidation(property_id, old_value, new_value); diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index e90ac84099e..32f33008ab6 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -208,7 +208,7 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_propert return {}; }; - auto get_computed_value = [this](PropertyID property_id) { + auto get_computed_value = [this](PropertyID property_id) -> auto const& { if (m_pseudo_element.has_value()) return m_element->pseudo_element_computed_css_values(m_pseudo_element.value())->property(property_id); return m_element->computed_css_values()->property(property_id); @@ -261,8 +261,8 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_propert // -> line-height // The resolved value is normal if the computed value is normal, or the used value otherwise. case PropertyID::LineHeight: { - auto line_height = get_computed_value(property_id); - if (line_height->is_keyword() && line_height->to_keyword() == Keyword::Normal) + auto const& line_height = get_computed_value(property_id); + if (line_height.is_keyword() && line_height.to_keyword() == Keyword::Normal) return line_height; return LengthStyleValue::create(Length::make_px(layout_node.computed_values().line_height())); } @@ -581,14 +581,14 @@ Optional ResolvedCSSStyleDeclaration::property(PropertyID propert auto style = m_element->document().style_computer().compute_style(const_cast(*m_element), m_pseudo_element); // FIXME: This is a stopgap until we implement shorthand -> longhand conversion. - auto value = style.maybe_null_property(property_id); + auto const* value = style.maybe_null_property(property_id); if (!value) { dbgln("FIXME: ResolvedCSSStyleDeclaration::property(property_id={:#x}) No value for property ID in newly computed style case.", to_underlying(property_id)); return {}; } return StyleProperty { .property_id = property_id, - .value = value.release_nonnull(), + .value = *value, }; } @@ -597,7 +597,7 @@ Optional ResolvedCSSStyleDeclaration::property(PropertyID propert return {}; return StyleProperty { .property_id = property_id, - .value = value.release_nonnull(), + .value = *value, }; } diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 61c03d1ac17..0baad2aedaf 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -1182,9 +1182,9 @@ static void compute_transitioned_properties(StyleProperties const& style, DOM::E element.clear_transitions(); element.set_cached_transition_property_source(*source_declaration); - auto transition_properties_value = style.property(PropertyID::TransitionProperty); - auto transition_properties = transition_properties_value->is_value_list() - ? transition_properties_value->as_value_list().values() + auto const& transition_properties_value = style.property(PropertyID::TransitionProperty); + auto transition_properties = transition_properties_value.is_value_list() + ? transition_properties_value.as_value_list().values() : StyleValueVector { transition_properties_value }; Vector> properties; @@ -1219,7 +1219,7 @@ static void compute_transitioned_properties(StyleProperties const& style, DOM::E } auto normalize_transition_length_list = [&properties, &style](PropertyID property, auto make_default_value) { - auto style_value = style.maybe_null_property(property); + auto const* style_value = style.maybe_null_property(property); StyleValueVector list; if (!style_value || !style_value->is_value_list() || style_value->as_value_list().size() == 0) { @@ -1268,14 +1268,14 @@ void StyleComputer::start_needed_transitions(StyleProperties const& previous_sty for (auto i = to_underlying(CSS::first_longhand_property_id); i <= to_underlying(CSS::last_longhand_property_id); ++i) { auto property_id = static_cast(i); auto matching_transition_properties = element.property_transition_attributes(property_id); - auto before_change_value = previous_style.property(property_id, StyleProperties::WithAnimationsApplied::No); - auto after_change_value = new_style.property(property_id, StyleProperties::WithAnimationsApplied::No); + auto const& before_change_value = previous_style.property(property_id, StyleProperties::WithAnimationsApplied::No); + auto const& after_change_value = new_style.property(property_id, StyleProperties::WithAnimationsApplied::No); auto existing_transition = element.property_transition(property_id); bool has_running_transition = existing_transition && !existing_transition->is_finished(); bool has_completed_transition = existing_transition && existing_transition->is_finished(); - auto start_a_transition = [&](auto start_time, auto end_time, auto start_value, auto end_value, auto reversing_adjusted_start_value, auto reversing_shortening_factor) { + auto start_a_transition = [&](auto start_time, auto end_time, auto const& start_value, auto const& end_value, auto const& reversing_adjusted_start_value, auto reversing_shortening_factor) { dbgln_if(CSS_TRANSITIONS_DEBUG, "Starting a transition of {} from {} to {}", string_from_property_id(property_id), start_value->to_string(), end_value->to_string()); auto transition = CSSTransition::start_a_transition(element, property_id, document().transition_generation(), @@ -1289,7 +1289,7 @@ void StyleComputer::start_needed_transitions(StyleProperties const& previous_sty // - the element does not have a running transition for the property, (!has_running_transition) && // - the before-change style is different from the after-change style for that property, and the values for the property are transitionable, - (!before_change_value->equals(after_change_value) && property_values_are_transitionable(property_id, before_change_value, after_change_value)) && + (!before_change_value.equals(after_change_value) && property_values_are_transitionable(property_id, before_change_value, after_change_value)) && // - the element does not have a completed transition for the property // or the end value of the completed transition is different from the after-change style for the property, (!has_completed_transition || !existing_transition->transition_end_value()->equals(after_change_value)) && @@ -1312,13 +1312,13 @@ void StyleComputer::start_needed_transitions(StyleProperties const& previous_sty auto end_time = start_time + matching_transition_properties->duration; // - start value is the value of the transitioning property in the before-change style, - auto start_value = before_change_value; + auto const& start_value = before_change_value; // - end value is the value of the transitioning property in the after-change style, - auto end_value = after_change_value; + auto const& end_value = after_change_value; // - reversing-adjusted start value is the same as the start value, and - auto reversing_adjusted_start_value = start_value; + auto const& reversing_adjusted_start_value = start_value; // - reversing shortening factor is 1. double reversing_shortening_factor = 1; @@ -1349,7 +1349,7 @@ void StyleComputer::start_needed_transitions(StyleProperties const& previous_sty // there is a matching transition-property value, // and the end value of the running transition is not equal to the value of the property in the after-change style, then: if (has_running_transition && matching_transition_properties.has_value() && !existing_transition->transition_end_value()->equals(after_change_value)) { - dbgln_if(CSS_TRANSITIONS_DEBUG, "Transition step 4. existing end value = {}, after change value = {}", existing_transition->transition_end_value()->to_string(), after_change_value->to_string()); + dbgln_if(CSS_TRANSITIONS_DEBUG, "Transition step 4. existing end value = {}, after change value = {}", existing_transition->transition_end_value()->to_string(), after_change_value.to_string()); // 1. If the current value of the property in the running transition is equal to the value of the property in the after-change style, // or if these two values are not transitionable, // then implementations must cancel the running transition. @@ -1401,10 +1401,10 @@ void StyleComputer::start_needed_transitions(StyleProperties const& previous_sty auto end_time = start_time + (matching_transition_properties->duration * reversing_shortening_factor); // - start value is the current value of the property in the running transition, - auto start_value = current_value; + auto const& start_value = current_value; // - end value is the value of the property in the after-change style, - auto end_value = after_change_value; + auto const& end_value = after_change_value; start_a_transition(start_time, end_time, start_value, end_value, reversing_adjusted_start_value, reversing_shortening_factor); } @@ -1425,13 +1425,13 @@ void StyleComputer::start_needed_transitions(StyleProperties const& previous_sty auto end_time = start_time + matching_transition_properties->duration; // - start value is the current value of the property in the running transition, - auto start_value = current_value; + auto const& start_value = current_value; // - end value is the value of the property in the after-change style, - auto end_value = after_change_value; + auto const& end_value = after_change_value; // - reversing-adjusted start value is the same as the start value, and - auto reversing_adjusted_start_value = start_value; + auto const& reversing_adjusted_start_value = start_value; // - reversing shortening factor is 1. double reversing_shortening_factor = 1; @@ -1528,8 +1528,8 @@ void StyleComputer::compute_cascaded_values(StyleProperties& style, DOM::Element // Animation declarations [css-animations-2] auto animation_name = [&]() -> Optional { - auto animation_name = style.maybe_null_property(PropertyID::AnimationName); - if (animation_name.is_null()) + auto const* animation_name = style.maybe_null_property(PropertyID::AnimationName); + if (!animation_name) return OptionalNone {}; if (animation_name->is_string()) return animation_name->as_string().string_value().to_string(); @@ -1687,20 +1687,20 @@ void StyleComputer::compute_defaulted_values(StyleProperties& style, DOM::Elemen // https://www.w3.org/TR/css-color-4/#resolving-other-colors // In the color property, the used value of currentcolor is the inherited value. - auto color = style.property(CSS::PropertyID::Color); - if (color->to_keyword() == Keyword::Currentcolor) { - color = get_inherit_value(document().realm(), CSS::PropertyID::Color, element, pseudo_element); - style.set_property(CSS::PropertyID::Color, color); + auto const& color = style.property(CSS::PropertyID::Color); + if (color.to_keyword() == Keyword::Currentcolor) { + auto const& inherited_value = get_inherit_value(document().realm(), CSS::PropertyID::Color, element, pseudo_element); + style.set_property(CSS::PropertyID::Color, inherited_value); } } Length::FontMetrics StyleComputer::calculate_root_element_font_metrics(StyleProperties const& style) const { - auto root_value = style.property(CSS::PropertyID::FontSize); + auto const& root_value = style.property(CSS::PropertyID::FontSize); auto font_pixel_metrics = style.first_available_computed_font().pixel_metrics(); Length::FontMetrics font_metrics { m_default_font_metrics.font_size, font_pixel_metrics }; - font_metrics.font_size = root_value->as_length().length().to_px(viewport_rect(), font_metrics, font_metrics); + font_metrics.font_size = root_value.as_length().length().to_px(viewport_rect(), font_metrics, font_metrics); font_metrics.line_height = style.compute_line_height(viewport_rect(), font_metrics, font_metrics); return font_metrics; @@ -1823,9 +1823,9 @@ RefPtr StyleComputer::compute_font_for_style_values( auto parent_font_size = [&]() -> CSSPixels { if (!parent_element || !parent_element->computed_css_values().has_value()) return font_size_in_px; - auto value = parent_element->computed_css_values()->property(CSS::PropertyID::FontSize); - if (value->is_length()) { - auto length = value->as_length().length(); + auto const& value = parent_element->computed_css_values()->property(CSS::PropertyID::FontSize); + if (value.is_length()) { + auto length = value.as_length().length(); if (length.is_absolute() || length.is_relative()) { Length::FontMetrics font_metrics { font_size_in_px, font_pixel_metrics }; return length.to_px(viewport_rect(), font_metrics, m_root_element_font_metrics); @@ -2064,11 +2064,11 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele compute_defaulted_property_value(style, element, CSS::PropertyID::FontWeight, pseudo_element); compute_defaulted_property_value(style, element, CSS::PropertyID::LineHeight, pseudo_element); - auto font_family = style.property(CSS::PropertyID::FontFamily); - auto font_size = style.property(CSS::PropertyID::FontSize); - auto font_style = style.property(CSS::PropertyID::FontStyle); - auto font_weight = style.property(CSS::PropertyID::FontWeight); - auto font_width = style.property(CSS::PropertyID::FontWidth); + auto const& font_family = style.property(CSS::PropertyID::FontFamily); + auto const& font_size = style.property(CSS::PropertyID::FontSize); + auto const& font_style = style.property(CSS::PropertyID::FontStyle); + auto const& font_weight = style.property(CSS::PropertyID::FontWeight); + auto const& font_width = style.property(CSS::PropertyID::FontWidth); auto font_list = compute_font_for_style_values(element, pseudo_element, font_family, font_size, font_style, font_weight, font_width, style.math_depth()); VERIFY(font_list); @@ -2077,7 +2077,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele RefPtr const found_font = font_list->first(); style.set_property(CSS::PropertyID::FontSize, LengthStyleValue::create(CSS::Length::make_px(CSSPixels::nearest_value_for(found_font->pixel_size())))); - style.set_property(CSS::PropertyID::FontWeight, NumberStyleValue::create(font_weight->to_font_weight())); + style.set_property(CSS::PropertyID::FontWeight, NumberStyleValue::create(font_weight.to_font_weight())); style.set_computed_font_list(*font_list); @@ -2099,7 +2099,7 @@ void StyleComputer::absolutize_values(StyleProperties& style) const style.first_available_computed_font().pixel_metrics() }; - auto font_size = style.property(CSS::PropertyID::FontSize)->as_length().length().to_px(viewport_rect(), font_metrics, m_root_element_font_metrics); + auto font_size = style.property(CSS::PropertyID::FontSize).as_length().length().to_px(viewport_rect(), font_metrics, m_root_element_font_metrics); font_metrics.font_size = font_size; // NOTE: Percentage line-height values are relative to the font-size of the element. @@ -2134,8 +2134,8 @@ void StyleComputer::resolve_effective_overflow_values(StyleProperties& style) co // https://www.w3.org/TR/css-overflow-3/#overflow-control // The visible/clip values of overflow compute to auto/hidden (respectively) if one of overflow-x or // overflow-y is neither visible nor clip. - auto overflow_x = keyword_to_overflow(style.property(PropertyID::OverflowX)->to_keyword()); - auto overflow_y = keyword_to_overflow(style.property(PropertyID::OverflowY)->to_keyword()); + auto overflow_x = keyword_to_overflow(style.property(PropertyID::OverflowX).to_keyword()); + auto overflow_y = keyword_to_overflow(style.property(PropertyID::OverflowY).to_keyword()); auto overflow_x_is_visible_or_clip = overflow_x == Overflow::Visible || overflow_x == Overflow::Clip; auto overflow_y_is_visible_or_clip = overflow_y == Overflow::Visible || overflow_y == Overflow::Clip; if (!overflow_x_is_visible_or_clip || !overflow_y_is_visible_or_clip) { @@ -2838,12 +2838,12 @@ void StyleComputer::compute_math_depth(StyleProperties& style, DOM::Element cons return element->parent_element()->computed_css_values()->math_depth(); }; - auto value = style.property(CSS::PropertyID::MathDepth); - if (!value->is_math_depth()) { + auto const& value = style.property(CSS::PropertyID::MathDepth); + if (!value.is_math_depth()) { style.set_math_depth(inherited_math_depth()); return; } - auto& math_depth = value->as_math_depth(); + auto const& math_depth = value.as_math_depth(); auto resolve_integer = [&](CSSStyleValue const& integer_value) { if (integer_value.is_integer()) @@ -2856,7 +2856,7 @@ void StyleComputer::compute_math_depth(StyleProperties& style, DOM::Element cons // The computed value of the math-depth value is determined as follows: // - If the specified value of math-depth is auto-add and the inherited value of math-style is compact // then the computed value of math-depth of the element is its inherited value plus one. - if (math_depth.is_auto_add() && style.property(CSS::PropertyID::MathStyle)->to_keyword() == Keyword::Compact) { + if (math_depth.is_auto_add() && style.property(CSS::PropertyID::MathStyle).to_keyword() == Keyword::Compact) { style.set_math_depth(inherited_math_depth() + 1); return; } diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index f5677900b73..c1785e7db90 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -5,6 +5,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -108,29 +109,29 @@ void StyleProperties::reset_animated_properties() m_data->m_animated_property_values.clear(); } -NonnullRefPtr StyleProperties::property(CSS::PropertyID property_id, WithAnimationsApplied return_animated_value) const +CSSStyleValue const& StyleProperties::property(CSS::PropertyID property_id, WithAnimationsApplied return_animated_value) const { if (return_animated_value == WithAnimationsApplied::Yes) { - if (auto animated_value = m_data->m_animated_property_values.get(property_id).value_or(nullptr)) - return *animated_value; + if (auto animated_value = m_data->m_animated_property_values.get(property_id); animated_value.has_value()) + return *animated_value.value(); } // By the time we call this method, all properties have values assigned. return *m_data->m_property_values[to_underlying(property_id)]; } -RefPtr StyleProperties::maybe_null_property(CSS::PropertyID property_id) const +CSSStyleValue const* StyleProperties::maybe_null_property(CSS::PropertyID property_id) const { - if (auto animated_value = m_data->m_animated_property_values.get(property_id).value_or(nullptr)) - return *animated_value; + if (auto animated_value = m_data->m_animated_property_values.get(property_id); animated_value.has_value()) + return animated_value.value(); return m_data->m_property_values[to_underlying(property_id)]; } CSS::Size StyleProperties::size_value(CSS::PropertyID id) const { - auto value = property(id); - if (value->is_keyword()) { - switch (value->to_keyword()) { + auto const& value = property(id); + if (value.is_keyword()) { + switch (value.to_keyword()) { case Keyword::Auto: return CSS::Size::make_auto(); case Keyword::MinContent: @@ -146,21 +147,21 @@ CSS::Size StyleProperties::size_value(CSS::PropertyID id) const } } - if (value->is_math()) - return CSS::Size::make_calculated(const_cast(value->as_math())); + if (value.is_math()) + return CSS::Size::make_calculated(const_cast(value.as_math())); - if (value->is_percentage()) - return CSS::Size::make_percentage(value->as_percentage().percentage()); + if (value.is_percentage()) + return CSS::Size::make_percentage(value.as_percentage().percentage()); - if (value->is_length()) { - auto length = value->as_length().length(); + if (value.is_length()) { + auto length = value.as_length().length(); if (length.is_auto()) return CSS::Size::make_auto(); return CSS::Size::make_length(length); } // FIXME: Support `fit-content()` - dbgln("FIXME: Unsupported size value: `{}`, treating as `auto`", value->to_string()); + dbgln("FIXME: Unsupported size value: `{}`, treating as `auto`", value.to_string()); return CSS::Size::make_auto(); } @@ -171,18 +172,18 @@ LengthPercentage StyleProperties::length_percentage_or_fallback(CSS::PropertyID Optional StyleProperties::length_percentage(CSS::PropertyID id) const { - auto value = property(id); + auto const& value = property(id); - if (value->is_math()) - return LengthPercentage { const_cast(value->as_math()) }; + if (value.is_math()) + return LengthPercentage { const_cast(value.as_math()) }; - if (value->is_percentage()) - return value->as_percentage().percentage(); + if (value.is_percentage()) + return value.as_percentage().percentage(); - if (value->is_length()) - return value->as_length().length(); + if (value.is_length()) + return value.as_length().length(); - if (value->has_auto()) + if (value.has_auto()) return LengthPercentage { Length::make_auto() }; return {}; @@ -200,10 +201,10 @@ 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_color()) + auto const& value = property(id); + if (!value.has_color()) return fallback; - return value->to_color(node); + return value.to_color(node); } NonnullRefPtr StyleProperties::font_fallback(bool monospace, bool bold) @@ -222,39 +223,39 @@ NonnullRefPtr StyleProperties::font_fallback(bool monospace, bo CSSPixels StyleProperties::compute_line_height(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const { - auto line_height = property(CSS::PropertyID::LineHeight); + auto const& line_height = property(CSS::PropertyID::LineHeight); - if (line_height->is_keyword() && line_height->to_keyword() == Keyword::Normal) + if (line_height.is_keyword() && line_height.to_keyword() == Keyword::Normal) return font_metrics.line_height; - if (line_height->is_length()) { - auto line_height_length = line_height->as_length().length(); + if (line_height.is_length()) { + auto line_height_length = line_height.as_length().length(); if (!line_height_length.is_auto()) return line_height_length.to_px(viewport_rect, font_metrics, root_font_metrics); } - if (line_height->is_number()) - return Length(line_height->as_number().number(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics); + if (line_height.is_number()) + return Length(line_height.as_number().number(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics); - if (line_height->is_percentage()) { + 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(); + auto const& percentage = line_height.as_percentage().percentage(); return Length(percentage.as_fraction(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics); } - if (line_height->is_math()) { - if (line_height->as_math().resolves_to_number()) { - auto resolved = line_height->as_math().resolve_number(); + if (line_height.is_math()) { + if (line_height.as_math().resolves_to_number()) { + auto resolved = line_height.as_math().resolve_number(); if (!resolved.has_value()) { - dbgln("FIXME: Failed to resolve calc() line-height (number): {}", line_height->as_math().to_string()); + dbgln("FIXME: Failed to resolve calc() line-height (number): {}", line_height.as_math().to_string()); return CSSPixels::nearest_value_for(m_data->m_font_list->first().pixel_metrics().line_spacing()); } return Length(resolved.value(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics); } - auto resolved = line_height->as_math().resolve_length(Length::ResolutionContext { viewport_rect, font_metrics, root_font_metrics }); + auto resolved = line_height.as_math().resolve_length(Length::ResolutionContext { viewport_rect, font_metrics, root_font_metrics }); if (!resolved.has_value()) { - dbgln("FIXME: Failed to resolve calc() line-height: {}", line_height->as_math().to_string()); + dbgln("FIXME: Failed to resolve calc() line-height: {}", line_height.as_math().to_string()); return CSSPixels::nearest_value_for(m_data->m_font_list->first().pixel_metrics().line_spacing()); } return resolved->to_px(viewport_rect, font_metrics, root_font_metrics); @@ -265,12 +266,12 @@ CSSPixels StyleProperties::compute_line_height(CSSPixelRect const& viewport_rect Optional StyleProperties::z_index() const { - auto value = property(CSS::PropertyID::ZIndex); - if (value->has_auto()) + auto const& value = property(CSS::PropertyID::ZIndex); + if (value.has_auto()) return {}; - if (value->is_integer()) { + if (value.is_integer()) { // Clamp z-index to the range of a signed 32-bit integer for consistency with other engines. - auto integer = value->as_integer().integer(); + auto integer = value.as_integer().integer(); if (integer >= NumericLimits::max()) return NumericLimits::max(); if (integer <= NumericLimits::min()) @@ -287,7 +288,7 @@ float StyleProperties::resolve_opacity_value(CSSStyleValue const& value) if (value.is_number()) { unclamped_opacity = value.as_number().number(); } else if (value.is_math()) { - auto& calculated = value.as_math(); + auto const& calculated = value.as_math(); if (calculated.resolves_to_percentage()) { auto maybe_percentage = value.as_math().resolve_percentage(); if (maybe_percentage.has_value()) @@ -310,82 +311,82 @@ float StyleProperties::resolve_opacity_value(CSSStyleValue const& value) float StyleProperties::opacity() const { - auto value = property(CSS::PropertyID::Opacity); - return resolve_opacity_value(*value); + auto const& value = property(CSS::PropertyID::Opacity); + return resolve_opacity_value(value); } float StyleProperties::fill_opacity() const { - auto value = property(CSS::PropertyID::FillOpacity); - return resolve_opacity_value(*value); + auto const& value = property(CSS::PropertyID::FillOpacity); + return resolve_opacity_value(value); } Optional StyleProperties::stroke_linecap() const { - auto value = property(CSS::PropertyID::StrokeLinecap); - return keyword_to_stroke_linecap(value->to_keyword()); + auto const& value = property(CSS::PropertyID::StrokeLinecap); + return keyword_to_stroke_linecap(value.to_keyword()); } Optional StyleProperties::stroke_linejoin() const { - auto value = property(CSS::PropertyID::StrokeLinejoin); - return keyword_to_stroke_linejoin(value->to_keyword()); + auto const& value = property(CSS::PropertyID::StrokeLinejoin); + return keyword_to_stroke_linejoin(value.to_keyword()); } NumberOrCalculated StyleProperties::stroke_miterlimit() const { - auto value = property(CSS::PropertyID::StrokeMiterlimit); + auto const& value = property(CSS::PropertyID::StrokeMiterlimit); - if (value->is_math()) { - auto const& math_value = value->as_math(); + if (value.is_math()) { + auto const& math_value = value.as_math(); VERIFY(math_value.resolves_to_number()); return NumberOrCalculated { math_value }; } - return NumberOrCalculated { value->as_number().number() }; + return NumberOrCalculated { value.as_number().number() }; } float StyleProperties::stroke_opacity() const { - auto value = property(CSS::PropertyID::StrokeOpacity); - return resolve_opacity_value(*value); + auto const& value = property(CSS::PropertyID::StrokeOpacity); + return resolve_opacity_value(value); } float StyleProperties::stop_opacity() const { - auto value = property(CSS::PropertyID::StopOpacity); - return resolve_opacity_value(*value); + auto const& value = property(CSS::PropertyID::StopOpacity); + return resolve_opacity_value(value); } Optional StyleProperties::fill_rule() const { - auto value = property(CSS::PropertyID::FillRule); - return keyword_to_fill_rule(value->to_keyword()); + auto const& value = property(CSS::PropertyID::FillRule); + return keyword_to_fill_rule(value.to_keyword()); } Optional StyleProperties::clip_rule() const { - auto value = property(CSS::PropertyID::ClipRule); - return keyword_to_fill_rule(value->to_keyword()); + auto const& value = property(CSS::PropertyID::ClipRule); + return keyword_to_fill_rule(value.to_keyword()); } Optional StyleProperties::flex_direction() const { - auto value = property(CSS::PropertyID::FlexDirection); - return keyword_to_flex_direction(value->to_keyword()); + auto const& value = property(CSS::PropertyID::FlexDirection); + return keyword_to_flex_direction(value.to_keyword()); } Optional StyleProperties::flex_wrap() const { - auto value = property(CSS::PropertyID::FlexWrap); - return keyword_to_flex_wrap(value->to_keyword()); + auto const& value = property(CSS::PropertyID::FlexWrap); + return keyword_to_flex_wrap(value.to_keyword()); } Optional StyleProperties::flex_basis() const { - auto value = property(CSS::PropertyID::FlexBasis); + auto const& value = property(CSS::PropertyID::FlexBasis); - if (value->is_keyword() && value->to_keyword() == CSS::Keyword::Content) + if (value.is_keyword() && value.to_keyword() == CSS::Keyword::Content) return CSS::FlexBasisContent {}; return size_value(CSS::PropertyID::FlexBasis); @@ -393,86 +394,86 @@ Optional StyleProperties::flex_basis() const float StyleProperties::flex_grow() const { - auto value = property(CSS::PropertyID::FlexGrow); - if (!value->is_number()) + auto const& value = property(CSS::PropertyID::FlexGrow); + if (!value.is_number()) return 0; - return value->as_number().number(); + return value.as_number().number(); } float StyleProperties::flex_shrink() const { - auto value = property(CSS::PropertyID::FlexShrink); - if (!value->is_number()) + auto const& value = property(CSS::PropertyID::FlexShrink); + if (!value.is_number()) return 1; - return value->as_number().number(); + return value.as_number().number(); } int StyleProperties::order() const { - auto value = property(CSS::PropertyID::Order); - if (!value->is_integer()) + auto const& value = property(CSS::PropertyID::Order); + if (!value.is_integer()) return 0; - return value->as_integer().integer(); + return value.as_integer().integer(); } Optional StyleProperties::image_rendering() const { - auto value = property(CSS::PropertyID::ImageRendering); - return keyword_to_image_rendering(value->to_keyword()); + auto const& value = property(CSS::PropertyID::ImageRendering); + return keyword_to_image_rendering(value.to_keyword()); } CSS::Length StyleProperties::border_spacing_horizontal(Layout::Node const& layout_node) const { - auto value = property(CSS::PropertyID::BorderSpacing); - if (value->is_length()) - return value->as_length().length(); - if (value->is_math()) - return value->as_math().resolve_length(layout_node).value_or(CSS::Length(0, CSS::Length::Type::Px)); - auto const& list = value->as_value_list(); + auto const& value = property(CSS::PropertyID::BorderSpacing); + if (value.is_length()) + return value.as_length().length(); + if (value.is_math()) + return value.as_math().resolve_length(layout_node).value_or(CSS::Length(0, CSS::Length::Type::Px)); + auto const& list = value.as_value_list(); return list.value_at(0, false)->as_length().length(); } CSS::Length StyleProperties::border_spacing_vertical(Layout::Node const& layout_node) const { - auto value = property(CSS::PropertyID::BorderSpacing); - if (value->is_length()) - return value->as_length().length(); - if (value->is_math()) - return value->as_math().resolve_length(layout_node).value_or(CSS::Length(0, CSS::Length::Type::Px)); - auto const& list = value->as_value_list(); + auto const& value = property(CSS::PropertyID::BorderSpacing); + if (value.is_length()) + return value.as_length().length(); + if (value.is_math()) + return value.as_math().resolve_length(layout_node).value_or(CSS::Length(0, CSS::Length::Type::Px)); + auto const& list = value.as_value_list(); return list.value_at(1, false)->as_length().length(); } Optional StyleProperties::caption_side() const { - auto value = property(CSS::PropertyID::CaptionSide); - return keyword_to_caption_side(value->to_keyword()); + auto const& value = property(CSS::PropertyID::CaptionSide); + return keyword_to_caption_side(value.to_keyword()); } CSS::Clip StyleProperties::clip() const { - auto value = property(CSS::PropertyID::Clip); - if (!value->is_rect()) + auto const& value = property(CSS::PropertyID::Clip); + if (!value.is_rect()) return CSS::Clip::make_auto(); - return CSS::Clip(value->as_rect().rect()); + return CSS::Clip(value.as_rect().rect()); } Optional StyleProperties::justify_content() const { - auto value = property(CSS::PropertyID::JustifyContent); - return keyword_to_justify_content(value->to_keyword()); + auto const& value = property(CSS::PropertyID::JustifyContent); + return keyword_to_justify_content(value.to_keyword()); } Optional StyleProperties::justify_items() const { - auto value = property(CSS::PropertyID::JustifyItems); - return keyword_to_justify_items(value->to_keyword()); + auto const& value = property(CSS::PropertyID::JustifyItems); + return keyword_to_justify_items(value.to_keyword()); } Optional StyleProperties::justify_self() const { - auto value = property(CSS::PropertyID::JustifySelf); - return keyword_to_justify_self(value->to_keyword()); + auto const& value = property(CSS::PropertyID::JustifySelf); + return keyword_to_justify_self(value.to_keyword()); } Vector StyleProperties::transformations_for_style_value(CSSStyleValue const& value) @@ -543,10 +544,10 @@ Vector StyleProperties::transformations() const Optional StyleProperties::rotate(Layout::Node const& layout_node) const { - auto value = property(CSS::PropertyID::Rotate); - if (!value->is_rotation()) + auto const& value = property(CSS::PropertyID::Rotate); + if (!value.is_rotation()) return {}; - auto& rotation = value->as_rotation(); + auto& rotation = value.as_rotation(); auto resolve_angle = [&layout_node](CSSStyleValue const& value) -> Optional { if (value.is_angle()) @@ -591,16 +592,16 @@ static Optional length_percentage_for_style_value(CSSStyleValu Optional StyleProperties::transform_box() const { - auto value = property(CSS::PropertyID::TransformBox); - return keyword_to_transform_box(value->to_keyword()); + auto const& value = property(CSS::PropertyID::TransformBox); + return keyword_to_transform_box(value.to_keyword()); } CSS::TransformOrigin StyleProperties::transform_origin() const { - auto value = property(CSS::PropertyID::TransformOrigin); - if (!value->is_value_list() || value->as_value_list().size() != 2) + auto const& value = property(CSS::PropertyID::TransformOrigin); + if (!value.is_value_list() || value.as_value_list().size() != 2) return {}; - auto const& list = 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()) { @@ -611,34 +612,34 @@ CSS::TransformOrigin StyleProperties::transform_origin() const Optional StyleProperties::accent_color(Layout::NodeWithStyle const& node) const { - auto value = property(CSS::PropertyID::AccentColor); - if (value->has_color()) - return value->to_color(node); + auto const& value = property(CSS::PropertyID::AccentColor); + if (value.has_color()) + return value.to_color(node); return {}; } Optional StyleProperties::align_content() const { - auto value = property(CSS::PropertyID::AlignContent); - return keyword_to_align_content(value->to_keyword()); + auto const& value = property(CSS::PropertyID::AlignContent); + return keyword_to_align_content(value.to_keyword()); } Optional StyleProperties::align_items() const { - auto value = property(CSS::PropertyID::AlignItems); - return keyword_to_align_items(value->to_keyword()); + auto const& value = property(CSS::PropertyID::AlignItems); + return keyword_to_align_items(value.to_keyword()); } Optional StyleProperties::align_self() const { - auto value = property(CSS::PropertyID::AlignSelf); - return keyword_to_align_self(value->to_keyword()); + auto const& value = property(CSS::PropertyID::AlignSelf); + return keyword_to_align_self(value.to_keyword()); } Optional StyleProperties::appearance() const { - auto value = property(CSS::PropertyID::Appearance); - auto appearance = keyword_to_appearance(value->to_keyword()); + auto const& value = property(CSS::PropertyID::Appearance); + auto appearance = keyword_to_appearance(value.to_keyword()); if (appearance.has_value()) { switch (*appearance) { // Note: All these compatibility values can be treated as 'auto' @@ -667,24 +668,24 @@ Optional StyleProperties::appearance() const CSS::Filter StyleProperties::backdrop_filter() const { - auto value = property(CSS::PropertyID::BackdropFilter); - if (value->is_filter_value_list()) - return Filter(value->as_filter_value_list()); + auto const& value = property(CSS::PropertyID::BackdropFilter); + if (value.is_filter_value_list()) + return Filter(value.as_filter_value_list()); return Filter::make_none(); } CSS::Filter StyleProperties::filter() const { - auto value = property(CSS::PropertyID::Filter); - if (value->is_filter_value_list()) - return Filter(value->as_filter_value_list()); + auto const& value = property(CSS::PropertyID::Filter); + if (value.is_filter_value_list()) + return Filter(value.as_filter_value_list()); return Filter::make_none(); } Optional StyleProperties::position() const { - auto value = property(CSS::PropertyID::Position); - return keyword_to_positioning(value->to_keyword()); + auto const& value = property(CSS::PropertyID::Position); + return keyword_to_positioning(value.to_keyword()); } bool StyleProperties::operator==(StyleProperties const& other) const @@ -715,39 +716,39 @@ bool StyleProperties::operator==(StyleProperties const& other) const Optional StyleProperties::text_anchor() const { - auto value = property(CSS::PropertyID::TextAnchor); - return keyword_to_text_anchor(value->to_keyword()); + auto const& value = property(CSS::PropertyID::TextAnchor); + return keyword_to_text_anchor(value.to_keyword()); } Optional StyleProperties::text_align() const { - auto value = property(CSS::PropertyID::TextAlign); - return keyword_to_text_align(value->to_keyword()); + auto const& value = property(CSS::PropertyID::TextAlign); + return keyword_to_text_align(value.to_keyword()); } Optional StyleProperties::text_justify() const { - auto value = property(CSS::PropertyID::TextJustify); - return keyword_to_text_justify(value->to_keyword()); + auto const& value = property(CSS::PropertyID::TextJustify); + return keyword_to_text_justify(value.to_keyword()); } Optional StyleProperties::text_overflow() const { - auto value = property(CSS::PropertyID::TextOverflow); - return keyword_to_text_overflow(value->to_keyword()); + auto const& value = property(CSS::PropertyID::TextOverflow); + return keyword_to_text_overflow(value.to_keyword()); } Optional StyleProperties::pointer_events() const { - auto value = property(CSS::PropertyID::PointerEvents); - return keyword_to_pointer_events(value->to_keyword()); + auto const& value = property(CSS::PropertyID::PointerEvents); + return keyword_to_pointer_events(value.to_keyword()); } Variant StyleProperties::tab_size() const { - auto value = property(CSS::PropertyID::TabSize); - if (value->is_math()) { - auto const& math_value = value->as_math(); + auto const& value = property(CSS::PropertyID::TabSize); + if (value.is_math()) { + auto const& math_value = value.as_math(); if (math_value.resolves_to_length()) { return LengthOrCalculated { math_value }; } @@ -756,89 +757,89 @@ Variant StyleProperties::tab_size() cons } } - if (value->is_length()) - return LengthOrCalculated { value->as_length().length() }; + if (value.is_length()) + return LengthOrCalculated { value.as_length().length() }; - return NumberOrCalculated { value->as_number().number() }; + return NumberOrCalculated { value.as_number().number() }; } Optional StyleProperties::word_break() const { - auto value = property(CSS::PropertyID::WordBreak); - return keyword_to_word_break(value->to_keyword()); + auto const& value = property(CSS::PropertyID::WordBreak); + return keyword_to_word_break(value.to_keyword()); } Optional StyleProperties::word_spacing() const { - auto value = property(CSS::PropertyID::WordSpacing); - if (value->is_math()) { - auto& math_value = value->as_math(); + auto const& value = property(CSS::PropertyID::WordSpacing); + if (value.is_math()) { + auto& math_value = value.as_math(); if (math_value.resolves_to_length()) { return LengthOrCalculated { math_value }; } } - if (value->is_length()) - return LengthOrCalculated { value->as_length().length() }; + if (value.is_length()) + return LengthOrCalculated { value.as_length().length() }; return {}; } Optional StyleProperties::white_space() const { - auto value = property(CSS::PropertyID::WhiteSpace); - return keyword_to_white_space(value->to_keyword()); + auto const& value = property(CSS::PropertyID::WhiteSpace); + return keyword_to_white_space(value.to_keyword()); } Optional StyleProperties::letter_spacing() const { - auto value = property(CSS::PropertyID::LetterSpacing); - if (value->is_math()) { - auto const& math_value = value->as_math(); + auto const& value = property(CSS::PropertyID::LetterSpacing); + if (value.is_math()) { + auto const& math_value = value.as_math(); if (math_value.resolves_to_length()) { return LengthOrCalculated { math_value }; } } - if (value->is_length()) - return LengthOrCalculated { value->as_length().length() }; + if (value.is_length()) + return LengthOrCalculated { value.as_length().length() }; return {}; } Optional StyleProperties::line_style(CSS::PropertyID property_id) const { - auto value = property(property_id); - return keyword_to_line_style(value->to_keyword()); + auto const& value = property(property_id); + return keyword_to_line_style(value.to_keyword()); } Optional StyleProperties::outline_style() const { - auto value = property(CSS::PropertyID::OutlineStyle); - return keyword_to_outline_style(value->to_keyword()); + auto const& value = property(CSS::PropertyID::OutlineStyle); + return keyword_to_outline_style(value.to_keyword()); } Optional StyleProperties::float_() const { - auto value = property(CSS::PropertyID::Float); - return keyword_to_float(value->to_keyword()); + auto const& value = property(CSS::PropertyID::Float); + return keyword_to_float(value.to_keyword()); } Optional StyleProperties::clear() const { - auto value = property(CSS::PropertyID::Clear); - return keyword_to_clear(value->to_keyword()); + auto const& value = property(CSS::PropertyID::Clear); + return keyword_to_clear(value.to_keyword()); } Optional StyleProperties::column_span() const { - auto value = property(CSS::PropertyID::ColumnSpan); - return keyword_to_column_span(value->to_keyword()); + auto const& value = property(CSS::PropertyID::ColumnSpan); + return keyword_to_column_span(value.to_keyword()); } StyleProperties::ContentDataAndQuoteNestingLevel StyleProperties::content(DOM::Element& element, u32 initial_quote_nesting_level) const { - auto value = property(CSS::PropertyID::Content); + auto const& value = property(CSS::PropertyID::Content); auto quotes_data = quotes(); auto quote_nesting_level = initial_quote_nesting_level; @@ -861,8 +862,8 @@ StyleProperties::ContentDataAndQuoteNestingLevel StyleProperties::content(DOM::E VERIFY_NOT_REACHED(); }; - if (value->is_content()) { - auto& content_style_value = value->as_content(); + if (value.is_content()) { + auto& content_style_value = value.as_content(); CSS::ContentData content_data; @@ -926,7 +927,7 @@ StyleProperties::ContentDataAndQuoteNestingLevel StyleProperties::content(DOM::E return { content_data, quote_nesting_level }; } - switch (value->to_keyword()) { + switch (value.to_keyword()) { case Keyword::None: return { { ContentData::Type::None }, quote_nesting_level }; case Keyword::Normal: @@ -940,75 +941,75 @@ StyleProperties::ContentDataAndQuoteNestingLevel StyleProperties::content(DOM::E Optional StyleProperties::content_visibility() const { - auto value = property(CSS::PropertyID::ContentVisibility); - return keyword_to_content_visibility(value->to_keyword()); + auto const& value = property(CSS::PropertyID::ContentVisibility); + return keyword_to_content_visibility(value.to_keyword()); } Optional StyleProperties::cursor() const { - auto value = property(CSS::PropertyID::Cursor); - return keyword_to_cursor(value->to_keyword()); + auto const& value = property(CSS::PropertyID::Cursor); + return keyword_to_cursor(value.to_keyword()); } Optional StyleProperties::visibility() const { - auto value = property(CSS::PropertyID::Visibility); - if (!value->is_keyword()) + auto const& value = property(CSS::PropertyID::Visibility); + if (!value.is_keyword()) return {}; - return keyword_to_visibility(value->to_keyword()); + return keyword_to_visibility(value.to_keyword()); } Display StyleProperties::display() const { - auto value = property(PropertyID::Display); - if (value->is_display()) { - return value->as_display().display(); + auto const& value = property(PropertyID::Display); + if (value.is_display()) { + return value.as_display().display(); } return Display::from_short(Display::Short::Inline); } Vector StyleProperties::text_decoration_line() const { - auto value = property(CSS::PropertyID::TextDecorationLine); + auto const& value = property(CSS::PropertyID::TextDecorationLine); - if (value->is_value_list()) { + if (value.is_value_list()) { Vector lines; - auto& values = value->as_value_list().values(); + auto& values = value.as_value_list().values(); for (auto const& item : values) { lines.append(keyword_to_text_decoration_line(item->to_keyword()).value()); } return lines; } - if (value->is_keyword() && value->to_keyword() == Keyword::None) + if (value.is_keyword() && value.to_keyword() == Keyword::None) return {}; - dbgln("FIXME: Unsupported value for text-decoration-line: {}", value->to_string()); + dbgln("FIXME: Unsupported value for text-decoration-line: {}", value.to_string()); return {}; } Optional StyleProperties::text_decoration_style() const { - auto value = property(CSS::PropertyID::TextDecorationStyle); - return keyword_to_text_decoration_style(value->to_keyword()); + auto const& value = property(CSS::PropertyID::TextDecorationStyle); + return keyword_to_text_decoration_style(value.to_keyword()); } Optional StyleProperties::text_transform() const { - auto value = property(CSS::PropertyID::TextTransform); - return keyword_to_text_transform(value->to_keyword()); + auto const& value = property(CSS::PropertyID::TextTransform); + return keyword_to_text_transform(value.to_keyword()); } Optional StyleProperties::list_style_type() const { - auto value = property(CSS::PropertyID::ListStyleType); - return keyword_to_list_style_type(value->to_keyword()); + auto const& value = property(CSS::PropertyID::ListStyleType); + return keyword_to_list_style_type(value.to_keyword()); } Optional StyleProperties::list_style_position() const { - auto value = property(CSS::PropertyID::ListStylePosition); - return keyword_to_list_style_position(value->to_keyword()); + auto const& value = property(CSS::PropertyID::ListStylePosition); + return keyword_to_list_style_position(value.to_keyword()); } Optional StyleProperties::overflow_x() const @@ -1023,13 +1024,13 @@ Optional StyleProperties::overflow_y() const Optional StyleProperties::overflow(CSS::PropertyID property_id) const { - auto value = property(property_id); - return keyword_to_overflow(value->to_keyword()); + auto const& value = property(property_id); + return keyword_to_overflow(value.to_keyword()); } Vector StyleProperties::shadow(PropertyID property_id, Layout::Node const& layout_node) const { - auto value = property(property_id); + auto const& value = property(property_id); auto resolve_to_length = [&layout_node](NonnullRefPtr const& value) -> Optional { if (value->is_length()) @@ -1062,8 +1063,8 @@ Vector StyleProperties::shadow(PropertyID property_id, Layout::Node }; }; - if (value->is_value_list()) { - auto const& value_list = value->as_value_list(); + if (value.is_value_list()) { + auto const& value_list = value.as_value_list(); Vector shadow_data; shadow_data.ensure_capacity(value_list.size()); @@ -1077,8 +1078,8 @@ Vector StyleProperties::shadow(PropertyID property_id, Layout::Node return shadow_data; } - if (value->is_shadow()) { - auto maybe_shadow_data = make_shadow_data(value->as_shadow()); + if (value.is_shadow()) { + auto maybe_shadow_data = make_shadow_data(value.as_shadow()); if (!maybe_shadow_data.has_value()) return {}; return { maybe_shadow_data.release_value() }; @@ -1099,52 +1100,52 @@ Vector StyleProperties::text_shadow(Layout::Node const& layout_node) Optional StyleProperties::box_sizing() const { - auto value = property(CSS::PropertyID::BoxSizing); - return keyword_to_box_sizing(value->to_keyword()); + auto const& value = property(CSS::PropertyID::BoxSizing); + return keyword_to_box_sizing(value.to_keyword()); } Variant StyleProperties::vertical_align() const { - auto value = property(CSS::PropertyID::VerticalAlign); + auto const& value = property(CSS::PropertyID::VerticalAlign); - if (value->is_keyword()) - return keyword_to_vertical_align(value->to_keyword()).release_value(); + if (value.is_keyword()) + return keyword_to_vertical_align(value.to_keyword()).release_value(); - if (value->is_length()) - return CSS::LengthPercentage(value->as_length().length()); + if (value.is_length()) + return CSS::LengthPercentage(value.as_length().length()); - if (value->is_percentage()) - return CSS::LengthPercentage(value->as_percentage().percentage()); + if (value.is_percentage()) + return CSS::LengthPercentage(value.as_percentage().percentage()); - if (value->is_math()) - return LengthPercentage { const_cast(value->as_math()) }; + if (value.is_math()) + return LengthPercentage { const_cast(value.as_math()) }; VERIFY_NOT_REACHED(); } Optional StyleProperties::font_variant() const { - auto value = property(CSS::PropertyID::FontVariant); - return keyword_to_font_variant(value->to_keyword()); + auto const& value = property(CSS::PropertyID::FontVariant); + return keyword_to_font_variant(value.to_keyword()); } Optional StyleProperties::font_language_override() const { - auto value = property(CSS::PropertyID::FontLanguageOverride); - if (value->is_string()) - return value->as_string().string_value(); + auto const& value = property(CSS::PropertyID::FontLanguageOverride); + if (value.is_string()) + return value.as_string().string_value(); return {}; } Optional> StyleProperties::font_feature_settings() const { - auto value = property(PropertyID::FontFeatureSettings); + auto const& value = property(PropertyID::FontFeatureSettings); - if (value->is_keyword()) + if (value.is_keyword()) return {}; // normal - if (value->is_value_list()) { - auto const& feature_tags = value->as_value_list().values(); + if (value.is_value_list()) { + auto const& feature_tags = value.as_value_list().values(); HashMap result; result.ensure_capacity(feature_tags.size()); for (auto const& tag_value : feature_tags) { @@ -1165,13 +1166,13 @@ Optional> StyleProperties::font_feature_ Optional> StyleProperties::font_variation_settings() const { - auto value = property(CSS::PropertyID::FontVariationSettings); + auto const& value = property(CSS::PropertyID::FontVariationSettings); - if (value->is_keyword()) + if (value.is_keyword()) return {}; // normal - if (value->is_value_list()) { - auto const& axis_tags = value->as_value_list().values(); + if (value.is_value_list()) { + auto const& axis_tags = value.as_value_list().values(); HashMap result; result.ensure_capacity(axis_tags.size()); for (auto const& tag_value : axis_tags) { @@ -1192,83 +1193,83 @@ Optional> StyleProperties::font_variation CSS::GridTrackSizeList StyleProperties::grid_auto_columns() const { - auto value = property(CSS::PropertyID::GridAutoColumns); - return value->as_grid_track_size_list().grid_track_size_list(); + auto const& value = property(CSS::PropertyID::GridAutoColumns); + return value.as_grid_track_size_list().grid_track_size_list(); } CSS::GridTrackSizeList StyleProperties::grid_auto_rows() const { - auto value = property(CSS::PropertyID::GridAutoRows); - return value->as_grid_track_size_list().grid_track_size_list(); + auto const& value = property(CSS::PropertyID::GridAutoRows); + return value.as_grid_track_size_list().grid_track_size_list(); } CSS::GridTrackSizeList StyleProperties::grid_template_columns() const { - auto value = property(CSS::PropertyID::GridTemplateColumns); - return value->as_grid_track_size_list().grid_track_size_list(); + auto const& value = property(CSS::PropertyID::GridTemplateColumns); + return value.as_grid_track_size_list().grid_track_size_list(); } CSS::GridTrackSizeList StyleProperties::grid_template_rows() const { - auto value = property(CSS::PropertyID::GridTemplateRows); - return value->as_grid_track_size_list().grid_track_size_list(); + auto const& value = property(CSS::PropertyID::GridTemplateRows); + return value.as_grid_track_size_list().grid_track_size_list(); } CSS::GridAutoFlow StyleProperties::grid_auto_flow() const { - auto value = property(CSS::PropertyID::GridAutoFlow); - if (!value->is_grid_auto_flow()) + auto const& value = property(CSS::PropertyID::GridAutoFlow); + if (!value.is_grid_auto_flow()) return CSS::GridAutoFlow {}; - auto& grid_auto_flow_value = value->as_grid_auto_flow(); + auto& grid_auto_flow_value = value.as_grid_auto_flow(); return CSS::GridAutoFlow { .row = grid_auto_flow_value.is_row(), .dense = grid_auto_flow_value.is_dense() }; } CSS::GridTrackPlacement StyleProperties::grid_column_end() const { - auto value = property(CSS::PropertyID::GridColumnEnd); - return value->as_grid_track_placement().grid_track_placement(); + auto const& value = property(CSS::PropertyID::GridColumnEnd); + return value.as_grid_track_placement().grid_track_placement(); } CSS::GridTrackPlacement StyleProperties::grid_column_start() const { - auto value = property(CSS::PropertyID::GridColumnStart); - return value->as_grid_track_placement().grid_track_placement(); + auto const& value = property(CSS::PropertyID::GridColumnStart); + return value.as_grid_track_placement().grid_track_placement(); } CSS::GridTrackPlacement StyleProperties::grid_row_end() const { - auto value = property(CSS::PropertyID::GridRowEnd); - return value->as_grid_track_placement().grid_track_placement(); + auto const& value = property(CSS::PropertyID::GridRowEnd); + return value.as_grid_track_placement().grid_track_placement(); } CSS::GridTrackPlacement StyleProperties::grid_row_start() const { - auto value = property(CSS::PropertyID::GridRowStart); - return value->as_grid_track_placement().grid_track_placement(); + auto const& value = property(CSS::PropertyID::GridRowStart); + return value.as_grid_track_placement().grid_track_placement(); } Optional StyleProperties::border_collapse() const { - auto value = property(CSS::PropertyID::BorderCollapse); - return keyword_to_border_collapse(value->to_keyword()); + auto const& value = property(CSS::PropertyID::BorderCollapse); + return keyword_to_border_collapse(value.to_keyword()); } Vector> StyleProperties::grid_template_areas() const { - auto value = property(CSS::PropertyID::GridTemplateAreas); - return value->as_grid_template_area().grid_template_area(); + auto const& value = property(CSS::PropertyID::GridTemplateAreas); + return value.as_grid_template_area().grid_template_area(); } Optional StyleProperties::object_fit() const { - auto value = property(CSS::PropertyID::ObjectFit); - return keyword_to_object_fit(value->to_keyword()); + auto const& value = property(CSS::PropertyID::ObjectFit); + return keyword_to_object_fit(value.to_keyword()); } CSS::ObjectPosition StyleProperties::object_position() const { - auto value = property(CSS::PropertyID::ObjectPosition); - auto const& position = value->as_position(); + auto const& value = property(CSS::PropertyID::ObjectPosition); + auto const& position = value.as_position(); CSS::ObjectPosition object_position; auto const& edge_x = position.edge_x(); auto const& edge_y = position.edge_y(); @@ -1287,40 +1288,40 @@ CSS::ObjectPosition StyleProperties::object_position() const Optional StyleProperties::table_layout() const { - auto value = property(CSS::PropertyID::TableLayout); - return keyword_to_table_layout(value->to_keyword()); + auto const& value = property(CSS::PropertyID::TableLayout); + return keyword_to_table_layout(value.to_keyword()); } Optional StyleProperties::direction() const { - auto value = property(CSS::PropertyID::Direction); - return keyword_to_direction(value->to_keyword()); + auto const& value = property(CSS::PropertyID::Direction); + return keyword_to_direction(value.to_keyword()); } Optional StyleProperties::unicode_bidi() const { - auto value = property(CSS::PropertyID::UnicodeBidi); - return keyword_to_unicode_bidi(value->to_keyword()); + auto const& value = property(CSS::PropertyID::UnicodeBidi); + return keyword_to_unicode_bidi(value.to_keyword()); } Optional StyleProperties::writing_mode() const { - auto value = property(CSS::PropertyID::WritingMode); - return keyword_to_writing_mode(value->to_keyword()); + auto const& value = property(CSS::PropertyID::WritingMode); + return keyword_to_writing_mode(value.to_keyword()); } Optional StyleProperties::mask_type() const { - auto value = property(CSS::PropertyID::MaskType); - return keyword_to_mask_type(value->to_keyword()); + auto const& value = property(CSS::PropertyID::MaskType); + return keyword_to_mask_type(value.to_keyword()); } Color StyleProperties::stop_color() const { - auto value = property(CSS::PropertyID::StopColor); + NonnullRawPtr value = property(CSS::PropertyID::StopColor); if (value->is_keyword()) { // Workaround lack of layout node to resolve current color. - auto& keyword = value->as_keyword(); + auto const& keyword = value->as_keyword(); if (keyword.keyword() == CSS::Keyword::Currentcolor) value = property(CSS::PropertyID::Color); } @@ -1341,9 +1342,9 @@ void StyleProperties::set_math_depth(int math_depth) QuotesData StyleProperties::quotes() const { - auto value = property(CSS::PropertyID::Quotes); - if (value->is_keyword()) { - switch (value->to_keyword()) { + auto const& value = property(CSS::PropertyID::Quotes); + if (value.is_keyword()) { + switch (value.to_keyword()) { case Keyword::Auto: return QuotesData { .type = QuotesData::Type::Auto }; case Keyword::None: @@ -1352,8 +1353,8 @@ QuotesData StyleProperties::quotes() const break; } } - if (value->is_value_list()) { - auto& value_list = value->as_value_list(); + if (value.is_value_list()) { + auto& value_list = value.as_value_list(); QuotesData quotes_data { .type = QuotesData::Type::Specified }; VERIFY(value_list.size() % 2 == 0); for (auto i = 0u; i < value_list.size(); i += 2) { @@ -1369,10 +1370,10 @@ QuotesData StyleProperties::quotes() const Vector StyleProperties::counter_data(PropertyID property_id) const { - auto value = property(property_id); + auto const& value = property(property_id); - if (value->is_counter_definitions()) { - auto& counter_definitions = value->as_counter_definitions().counter_definitions(); + if (value.is_counter_definitions()) { + auto& counter_definitions = value.as_counter_definitions().counter_definitions(); Vector result; for (auto& counter : counter_definitions) { CounterData data { @@ -1396,17 +1397,17 @@ Vector StyleProperties::counter_data(PropertyID property_id) const return result; } - if (value->to_keyword() == Keyword::None) + if (value.to_keyword() == Keyword::None) return {}; - dbgln("Unhandled type for {} value: '{}'", string_from_property_id(property_id), value->to_string()); + dbgln("Unhandled type for {} value: '{}'", string_from_property_id(property_id), value.to_string()); return {}; } Optional StyleProperties::scrollbar_width() const { - auto value = property(CSS::PropertyID::ScrollbarWidth); - return keyword_to_scrollbar_width(value->to_keyword()); + auto const& value = property(CSS::PropertyID::ScrollbarWidth); + return keyword_to_scrollbar_width(value.to_keyword()); } } diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h index 377637db026..328b4440f07 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h @@ -76,8 +76,8 @@ public: No, Yes, }; - NonnullRefPtr property(CSS::PropertyID, WithAnimationsApplied = WithAnimationsApplied::Yes) const; - RefPtr maybe_null_property(CSS::PropertyID) const; + CSSStyleValue const& property(CSS::PropertyID, WithAnimationsApplied = WithAnimationsApplied::Yes) const; + CSSStyleValue const* maybe_null_property(CSS::PropertyID) const; void revert_property(CSS::PropertyID, StyleProperties const& style_for_revert); JS::GCPtr animation_name_source() const { return m_data->m_animation_name_source; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 99098196d90..d2a1ba4b687 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -140,7 +140,7 @@ void HTMLInputElement::adjust_computed_style(CSS::StyleProperties& style) style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock))); if (type_state() != TypeAttributeState::FileUpload) { - if (style.property(CSS::PropertyID::Width)->has_auto()) + if (style.property(CSS::PropertyID::Width).has_auto()) style.set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length(size(), CSS::Length::Type::Ch))); } @@ -1131,9 +1131,9 @@ void HTMLInputElement::computed_css_values_changed() auto palette = document().page().palette(); auto accent_color = palette.color(ColorRole::Accent).to_string(); - auto accent_color_property = computed_css_values()->property(CSS::PropertyID::AccentColor); - if (accent_color_property->has_color()) - accent_color = accent_color_property->to_string(); + auto const& accent_color_property = computed_css_values()->property(CSS::PropertyID::AccentColor); + if (accent_color_property.has_color()) + accent_color = accent_color_property.to_string(); if (m_slider_progress_element) MUST(m_slider_progress_element->style_for_bindings()->set_property(CSS::PropertyID::BackgroundColor, accent_color)); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp index 30ce11c780b..025884af501 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp @@ -127,9 +127,9 @@ void HTMLProgressElement::computed_css_values_changed() auto palette = document().page().palette(); auto accent_color = palette.color(ColorRole::Accent).to_string(); - auto accent_color_property = computed_css_values()->property(CSS::PropertyID::AccentColor); - if (accent_color_property->has_color()) - accent_color = accent_color_property->to_string(); + auto const& accent_color_property = computed_css_values()->property(CSS::PropertyID::AccentColor); + if (accent_color_property.has_color()) + accent_color = accent_color_property.to_string(); if (m_progress_value_element) MUST(m_progress_value_element->style_for_bindings()->set_property(CSS::PropertyID::BackgroundColor, accent_color)); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp index 6bbde14305b..e0cef60d56f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp @@ -48,9 +48,9 @@ void HTMLTextAreaElement::adjust_computed_style(CSS::StyleProperties& style) if (style.display().is_inline_outside() && style.display().is_flow_inside()) style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock))); - if (style.property(CSS::PropertyID::Width)->has_auto()) + if (style.property(CSS::PropertyID::Width).has_auto()) style.set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length(cols(), CSS::Length::Type::Ch))); - if (style.property(CSS::PropertyID::Height)->has_auto()) + if (style.property(CSS::PropertyID::Height).has_auto()) style.set_property(CSS::PropertyID::Height, CSS::LengthStyleValue::create(CSS::Length(rows(), CSS::Length::Type::Lh))); } diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 97fdff363ba..eac095d5021 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -320,32 +320,32 @@ 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. computed_values.set_font_list(computed_style.computed_font_list()); - computed_values.set_font_size(computed_style.property(CSS::PropertyID::FontSize)->as_length().length().to_px(*this)); - computed_values.set_font_weight(round_to(computed_style.property(CSS::PropertyID::FontWeight)->as_number().number())); + computed_values.set_font_size(computed_style.property(CSS::PropertyID::FontSize).as_length().length().to_px(*this)); + computed_values.set_font_weight(round_to(computed_style.property(CSS::PropertyID::FontWeight).as_number().number())); computed_values.set_line_height(computed_style.line_height()); computed_values.set_vertical_align(computed_style.vertical_align()); { - auto attachments = computed_style.property(CSS::PropertyID::BackgroundAttachment); - auto clips = computed_style.property(CSS::PropertyID::BackgroundClip); - auto images = computed_style.property(CSS::PropertyID::BackgroundImage); - auto origins = computed_style.property(CSS::PropertyID::BackgroundOrigin); - auto x_positions = computed_style.property(CSS::PropertyID::BackgroundPositionX); - auto y_positions = computed_style.property(CSS::PropertyID::BackgroundPositionY); - auto repeats = computed_style.property(CSS::PropertyID::BackgroundRepeat); - auto sizes = computed_style.property(CSS::PropertyID::BackgroundSize); + auto const& attachments = computed_style.property(CSS::PropertyID::BackgroundAttachment); + auto const& clips = computed_style.property(CSS::PropertyID::BackgroundClip); + auto const& images = computed_style.property(CSS::PropertyID::BackgroundImage); + auto const& origins = computed_style.property(CSS::PropertyID::BackgroundOrigin); + auto const& x_positions = computed_style.property(CSS::PropertyID::BackgroundPositionX); + auto const& y_positions = computed_style.property(CSS::PropertyID::BackgroundPositionY); + auto const& repeats = computed_style.property(CSS::PropertyID::BackgroundRepeat); + auto const& sizes = computed_style.property(CSS::PropertyID::BackgroundSize); - auto count_layers = [](auto maybe_style_value) -> size_t { - if (maybe_style_value->is_value_list()) - return maybe_style_value->as_value_list().size(); + auto count_layers = [](auto const& maybe_style_value) -> size_t { + if (maybe_style_value.is_value_list()) + return maybe_style_value.as_value_list().size(); else return 1; }; - auto value_for_layer = [](auto& style_value, size_t layer_index) -> RefPtr { - if (style_value->is_value_list()) - return style_value->as_value_list().value_at(layer_index, true); + auto value_for_layer = [](auto const& style_value, size_t layer_index) -> RefPtr { + if (style_value.is_value_list()) + return style_value.as_value_list().value_at(layer_index, true); return style_value; }; @@ -467,33 +467,33 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) if (auto maybe_font_variation_settings = computed_style.font_variation_settings(); maybe_font_variation_settings.has_value()) computed_values.set_font_variation_settings(maybe_font_variation_settings.release_value()); - auto border_bottom_left_radius = computed_style.property(CSS::PropertyID::BorderBottomLeftRadius); - if (border_bottom_left_radius->is_border_radius()) { + auto const& border_bottom_left_radius = computed_style.property(CSS::PropertyID::BorderBottomLeftRadius); + if (border_bottom_left_radius.is_border_radius()) { computed_values.set_border_bottom_left_radius( CSS::BorderRadiusData { - border_bottom_left_radius->as_border_radius().horizontal_radius(), - border_bottom_left_radius->as_border_radius().vertical_radius() }); + border_bottom_left_radius.as_border_radius().horizontal_radius(), + border_bottom_left_radius.as_border_radius().vertical_radius() }); } - auto border_bottom_right_radius = computed_style.property(CSS::PropertyID::BorderBottomRightRadius); - if (border_bottom_right_radius->is_border_radius()) { + auto const& border_bottom_right_radius = computed_style.property(CSS::PropertyID::BorderBottomRightRadius); + if (border_bottom_right_radius.is_border_radius()) { computed_values.set_border_bottom_right_radius( CSS::BorderRadiusData { - border_bottom_right_radius->as_border_radius().horizontal_radius(), - border_bottom_right_radius->as_border_radius().vertical_radius() }); + border_bottom_right_radius.as_border_radius().horizontal_radius(), + border_bottom_right_radius.as_border_radius().vertical_radius() }); } - auto border_top_left_radius = computed_style.property(CSS::PropertyID::BorderTopLeftRadius); - if (border_top_left_radius->is_border_radius()) { + auto const& border_top_left_radius = computed_style.property(CSS::PropertyID::BorderTopLeftRadius); + if (border_top_left_radius.is_border_radius()) { computed_values.set_border_top_left_radius( CSS::BorderRadiusData { - border_top_left_radius->as_border_radius().horizontal_radius(), - border_top_left_radius->as_border_radius().vertical_radius() }); + border_top_left_radius.as_border_radius().horizontal_radius(), + border_top_left_radius.as_border_radius().vertical_radius() }); } - auto border_top_right_radius = computed_style.property(CSS::PropertyID::BorderTopRightRadius); - if (border_top_right_radius->is_border_radius()) { + auto const& border_top_right_radius = computed_style.property(CSS::PropertyID::BorderTopRightRadius); + if (border_top_right_radius.is_border_radius()) { computed_values.set_border_top_right_radius( CSS::BorderRadiusData { - border_top_right_radius->as_border_radius().horizontal_radius(), - border_top_right_radius->as_border_radius().vertical_radius() }); + border_top_right_radius.as_border_radius().horizontal_radius(), + border_top_right_radius.as_border_radius().vertical_radius() }); } computed_values.set_display(computed_style.display()); @@ -669,9 +669,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) if (auto list_style_type = computed_style.list_style_type(); list_style_type.has_value()) computed_values.set_list_style_type(list_style_type.value()); - auto list_style_image = computed_style.property(CSS::PropertyID::ListStyleImage); - if (list_style_image->is_abstract_image()) { - m_list_style_image = list_style_image->as_abstract_image(); + auto const& list_style_image = computed_style.property(CSS::PropertyID::ListStyleImage); + if (list_style_image.is_abstract_image()) { + m_list_style_image = list_style_image.as_abstract_image(); const_cast(*m_list_style_image).load_any_resources(document()); } @@ -717,12 +717,12 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) computed_values.set_transform_box(transform_box.value()); computed_values.set_transform_origin(computed_style.transform_origin()); - auto transition_delay_property = computed_style.property(CSS::PropertyID::TransitionDelay); - if (transition_delay_property->is_time()) { - auto& transition_delay = transition_delay_property->as_time(); + auto const& transition_delay_property = computed_style.property(CSS::PropertyID::TransitionDelay); + if (transition_delay_property.is_time()) { + auto const& transition_delay = transition_delay_property.as_time(); computed_values.set_transition_delay(transition_delay.time()); - } else if (transition_delay_property->is_math()) { - auto& transition_delay = transition_delay_property->as_math(); + } else if (transition_delay_property.is_math()) { + auto const& transition_delay = transition_delay_property.as_math(); computed_values.set_transition_delay(transition_delay.resolve_time().value()); } @@ -742,14 +742,14 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) border.width = 0; } else { auto resolve_border_width = [&]() -> CSSPixels { - auto value = computed_style.property(width_property); - if (value->is_math()) - return max(CSSPixels { 0 }, value->as_math().resolve_length(*this)->to_px(*this)); - if (value->is_length()) - return value->as_length().length().to_px(*this); - if (value->is_keyword()) { + auto const& value = computed_style.property(width_property); + if (value.is_math()) + return max(CSSPixels { 0 }, value.as_math().resolve_length(*this)->to_px(*this)); + if (value.is_length()) + return value.as_length().length().to_px(*this); + if (value.is_keyword()) { // https://www.w3.org/TR/css-backgrounds-3/#valdef-line-width-thin - switch (value->to_keyword()) { + switch (value.to_keyword()) { case CSS::Keyword::Thin: return 1; case CSS::Keyword::Medium: @@ -772,14 +772,14 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) do_border_style(computed_values.border_right(), CSS::PropertyID::BorderRightWidth, CSS::PropertyID::BorderRightColor, CSS::PropertyID::BorderRightStyle); do_border_style(computed_values.border_bottom(), CSS::PropertyID::BorderBottomWidth, CSS::PropertyID::BorderBottomColor, CSS::PropertyID::BorderBottomStyle); - if (auto outline_color = computed_style.property(CSS::PropertyID::OutlineColor); outline_color->has_color()) - computed_values.set_outline_color(outline_color->to_color(*this)); - if (auto outline_offset = computed_style.property(CSS::PropertyID::OutlineOffset); outline_offset->is_length()) - computed_values.set_outline_offset(outline_offset->as_length().length()); - if (auto outline_style = computed_style.outline_style(); outline_style.has_value()) + if (auto const& outline_color = computed_style.property(CSS::PropertyID::OutlineColor); outline_color.has_color()) + computed_values.set_outline_color(outline_color.to_color(*this)); + if (auto const& outline_offset = computed_style.property(CSS::PropertyID::OutlineOffset); outline_offset.is_length()) + computed_values.set_outline_offset(outline_offset.as_length().length()); + if (auto const& outline_style = computed_style.outline_style(); outline_style.has_value()) computed_values.set_outline_style(outline_style.value()); - if (auto outline_width = computed_style.property(CSS::PropertyID::OutlineWidth); outline_width->is_length()) - computed_values.set_outline_width(outline_width->as_length().length()); + if (auto const& outline_width = computed_style.property(CSS::PropertyID::OutlineWidth); outline_width.is_length()) + computed_values.set_outline_width(outline_width.as_length().length()); computed_values.set_grid_auto_columns(computed_style.grid_auto_columns()); computed_values.set_grid_auto_rows(computed_style.grid_auto_rows()); @@ -807,39 +807,39 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) if (auto y_value = computed_style.length_percentage(CSS::PropertyID::Y); y_value.has_value()) computed_values.set_y(*y_value); - auto fill = computed_style.property(CSS::PropertyID::Fill); - if (fill->has_color()) - computed_values.set_fill(fill->to_color(*this)); - else if (fill->is_url()) - computed_values.set_fill(fill->as_url().url()); - auto stroke = computed_style.property(CSS::PropertyID::Stroke); - if (stroke->has_color()) - computed_values.set_stroke(stroke->to_color(*this)); - else if (stroke->is_url()) - computed_values.set_stroke(stroke->as_url().url()); - if (auto stop_color = computed_style.property(CSS::PropertyID::StopColor); stop_color->has_color()) - computed_values.set_stop_color(stop_color->to_color(*this)); - auto stroke_width = computed_style.property(CSS::PropertyID::StrokeWidth); + auto const& fill = computed_style.property(CSS::PropertyID::Fill); + if (fill.has_color()) + computed_values.set_fill(fill.to_color(*this)); + else if (fill.is_url()) + computed_values.set_fill(fill.as_url().url()); + auto const& stroke = computed_style.property(CSS::PropertyID::Stroke); + if (stroke.has_color()) + computed_values.set_stroke(stroke.to_color(*this)); + else if (stroke.is_url()) + computed_values.set_stroke(stroke.as_url().url()); + if (auto const& stop_color = computed_style.property(CSS::PropertyID::StopColor); stop_color.has_color()) + computed_values.set_stop_color(stop_color.to_color(*this)); + auto const& 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_number()) - computed_values.set_stroke_width(CSS::Length::make_px(CSSPixels::nearest_value_for(stroke_width->as_number().number()))); - else if (stroke_width->is_length()) - computed_values.set_stroke_width(stroke_width->as_length().length()); - else if (stroke_width->is_percentage()) - computed_values.set_stroke_width(CSS::LengthPercentage { stroke_width->as_percentage().percentage() }); + if (stroke_width.is_number()) + computed_values.set_stroke_width(CSS::Length::make_px(CSSPixels::nearest_value_for(stroke_width.as_number().number()))); + else if (stroke_width.is_length()) + computed_values.set_stroke_width(stroke_width.as_length().length()); + else if (stroke_width.is_percentage()) + computed_values.set_stroke_width(CSS::LengthPercentage { stroke_width.as_percentage().percentage() }); if (auto mask_type = computed_style.mask_type(); mask_type.has_value()) computed_values.set_mask_type(*mask_type); - if (auto mask = computed_style.property(CSS::PropertyID::Mask); mask->is_url()) - computed_values.set_mask(mask->as_url().url()); + if (auto const& mask = computed_style.property(CSS::PropertyID::Mask); mask.is_url()) + computed_values.set_mask(mask.as_url().url()); - auto clip_path = computed_style.property(CSS::PropertyID::ClipPath); - if (clip_path->is_url()) - computed_values.set_clip_path(clip_path->as_url().url()); - else if (clip_path->is_basic_shape()) - computed_values.set_clip_path(clip_path->as_basic_shape()); + auto const& clip_path = computed_style.property(CSS::PropertyID::ClipPath); + if (clip_path.is_url()) + computed_values.set_clip_path(clip_path.as_url().url()); + else if (clip_path.is_basic_shape()) + computed_values.set_clip_path(clip_path.as_basic_shape()); if (auto clip_rule = computed_style.clip_rule(); clip_rule.has_value()) computed_values.set_clip_rule(*clip_rule); @@ -861,8 +861,8 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) if (auto text_anchor = computed_style.text_anchor(); text_anchor.has_value()) computed_values.set_text_anchor(*text_anchor); - if (auto column_count = computed_style.property(CSS::PropertyID::ColumnCount); column_count->is_integer()) - computed_values.set_column_count(CSS::ColumnCount::make_integer(column_count->as_integer().integer())); + if (auto const& column_count = computed_style.property(CSS::PropertyID::ColumnCount); column_count.is_integer()) + computed_values.set_column_count(CSS::ColumnCount::make_integer(column_count.as_integer().integer())); if (auto column_span = computed_style.column_span(); column_span.has_value()) computed_values.set_column_span(column_span.value()); @@ -878,31 +878,31 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) if (auto table_layout = computed_style.table_layout(); table_layout.has_value()) computed_values.set_table_layout(table_layout.value()); - auto aspect_ratio = computed_style.property(CSS::PropertyID::AspectRatio); - if (aspect_ratio->is_value_list()) { - auto& values_list = aspect_ratio->as_value_list().values(); + auto const& aspect_ratio = computed_style.property(CSS::PropertyID::AspectRatio); + if (aspect_ratio.is_value_list()) { + auto const& values_list = aspect_ratio.as_value_list().values(); if (values_list.size() == 2 && values_list[0]->is_keyword() && values_list[0]->as_keyword().keyword() == CSS::Keyword::Auto && values_list[1]->is_ratio()) { computed_values.set_aspect_ratio({ true, values_list[1]->as_ratio().ratio() }); } - } else if (aspect_ratio->is_keyword() && aspect_ratio->as_keyword().keyword() == CSS::Keyword::Auto) { + } else if (aspect_ratio.is_keyword() && aspect_ratio.as_keyword().keyword() == CSS::Keyword::Auto) { computed_values.set_aspect_ratio({ true, {} }); - } else if (aspect_ratio->is_ratio()) { + } else if (aspect_ratio.is_ratio()) { // https://drafts.csswg.org/css-sizing-4/#aspect-ratio // If the is degenerate, the property instead behaves as auto. - if (aspect_ratio->as_ratio().ratio().is_degenerate()) + if (aspect_ratio.as_ratio().ratio().is_degenerate()) computed_values.set_aspect_ratio({ true, {} }); else - computed_values.set_aspect_ratio({ false, aspect_ratio->as_ratio().ratio() }); + computed_values.set_aspect_ratio({ false, aspect_ratio.as_ratio().ratio() }); } - auto math_shift_value = computed_style.property(CSS::PropertyID::MathShift); - if (auto math_shift = keyword_to_math_shift(math_shift_value->to_keyword()); math_shift.has_value()) + auto const& math_shift_value = computed_style.property(CSS::PropertyID::MathShift); + if (auto math_shift = keyword_to_math_shift(math_shift_value.to_keyword()); math_shift.has_value()) computed_values.set_math_shift(math_shift.value()); - auto math_style_value = computed_style.property(CSS::PropertyID::MathStyle); - if (auto math_style = keyword_to_math_style(math_style_value->to_keyword()); math_style.has_value()) + auto const& math_style_value = computed_style.property(CSS::PropertyID::MathStyle); + if (auto math_style = keyword_to_math_style(math_style_value.to_keyword()); math_style.has_value()) computed_values.set_math_style(math_style.value()); computed_values.set_math_depth(computed_style.math_depth()); diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index 9094f153b18..44e61f4e4c3 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -1387,7 +1387,7 @@ Messages::WebDriverClient::GetElementCssValueResponse WebDriverConnection::get_e // computed value of parameter URL variables["property name"] from element's style declarations. if (auto property = Web::CSS::property_id_from_string(name); property.has_value()) { if (auto computed_values = element->computed_css_values(); computed_values.has_value()) - computed_value = computed_values->property(property.value())->to_string(); + computed_value = computed_values->property(property.value()).to_string(); } } // -> Otherwise