diff options
author | Andreas Kling <kling@serenityos.org> | 2023-02-20 18:56:08 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-02-21 00:54:04 +0100 |
commit | f11899f885c18390fa17aebe1ef77b733a81fcaf (patch) | |
tree | d267dd8f55f9625312a69f1d630b8b70cefb0a0d /Userland/Libraries/LibWeb | |
parent | 68b5df6bf17c55af258f44a18d0ddd41c660d38d (diff) | |
download | serenity-f11899f885c18390fa17aebe1ef77b733a81fcaf.zip |
LibWeb+LibIDL: Fix (or paper over) various const-correctness issues
There's definitely stuff to iterate on here, but this takes care of
making the libraries compile with stricter RP and NNRP.
Diffstat (limited to 'Userland/Libraries/LibWeb')
18 files changed, 167 insertions, 143 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp index 2e0fac1430..53c581ef63 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -172,7 +172,7 @@ void ElementInlineCSSStyleDeclaration::update_style_attribute() } // https://drafts.csswg.org/cssom/#set-a-css-declaration -bool PropertyOwningCSSStyleDeclaration::set_a_css_declaration(PropertyID property_id, NonnullRefPtr<StyleValue> value, Important important) +bool PropertyOwningCSSStyleDeclaration::set_a_css_declaration(PropertyID property_id, NonnullRefPtr<StyleValue const> value, Important important) { // FIXME: Handle logical property groups. diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h index edafb34220..a04eebd38a 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -21,7 +21,7 @@ enum class Important { struct StyleProperty { Important important { Important::No }; CSS::PropertyID property_id; - NonnullRefPtr<StyleValue> value; + NonnullRefPtr<StyleValue const> value; DeprecatedString custom_name {}; }; @@ -92,7 +92,7 @@ protected: void set_the_declarations(Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties); private: - bool set_a_css_declaration(PropertyID, NonnullRefPtr<StyleValue>, Important); + bool set_a_css_declaration(PropertyID, NonnullRefPtr<StyleValue const>, Important); Vector<StyleProperty> m_properties; HashMap<DeprecatedString, StyleProperty> m_custom_properties; diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 930fe8232f..9760a3f4d0 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2020-2023, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -77,7 +77,7 @@ public: }; struct BackgroundLayerData { - RefPtr<CSS::AbstractImageStyleValue> background_image { nullptr }; + RefPtr<CSS::AbstractImageStyleValue const> background_image { nullptr }; CSS::BackgroundAttachment attachment { CSS::BackgroundAttachment::Scroll }; CSS::BackgroundBox origin { CSS::BackgroundBox::PaddingBox }; CSS::BackgroundBox clip { CSS::BackgroundBox::BorderBox }; diff --git a/Userland/Libraries/LibWeb/CSS/MediaList.cpp b/Userland/Libraries/LibWeb/CSS/MediaList.cpp index 3b850a64d1..f9523315f9 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaList.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaList.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> - * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2022-2023, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -64,11 +64,21 @@ DeprecatedString MediaList::item(u32 index) const // https://www.w3.org/TR/cssom-1/#dom-medialist-appendmedium void MediaList::append_medium(DeprecatedString medium) { + // 1. Let m be the result of parsing the given value. auto m = parse_media_query({}, medium); + + // 2. If m is null, then return. if (!m) return; - if (m_media.contains_slow(*m)) - return; + + // 3. If comparing m with any of the media queries in the collection of media queries returns true, then return. + auto serialized = m->to_string().release_value_but_fixme_should_propagate_errors(); + for (auto& existing_medium : m_media) { + if (existing_medium.to_string().release_value_but_fixme_should_propagate_errors() == serialized) + return; + } + + // 4. Append m to the collection of media queries. m_media.append(m.release_nonnull()); } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h index a7f9a75a57..b10dbeb206 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2020-2021, the SerenityOS developers. * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> + * Copyright (c) 2023, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -23,10 +24,10 @@ public: ~ComponentValue(); bool is_block() const { return m_value.has<NonnullRefPtr<Block>>(); } - Block const& block() const { return m_value.get<NonnullRefPtr<Block>>(); } + Block& block() const { return m_value.get<NonnullRefPtr<Block>>(); } bool is_function() const { return m_value.has<NonnullRefPtr<Function>>(); } - Function const& function() const { return m_value.get<NonnullRefPtr<Function>>(); } + Function& function() const { return m_value.get<NonnullRefPtr<Function>>(); } bool is_token() const { return m_value.has<Token>(); } bool is(Token::Type type) const { return is_token() && token().is(type); } diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 190916e5db..16f1459aa3 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021-2023, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org> * @@ -122,14 +122,14 @@ static RefPtr<StyleValue> style_value_for_display(CSS::Display display) TODO(); } -static NonnullRefPtr<StyleValue> value_or_default(Optional<StyleProperty> property, NonnullRefPtr<StyleValue> default_style) +static NonnullRefPtr<StyleValue const> value_or_default(Optional<StyleProperty> property, NonnullRefPtr<StyleValue> default_style) { if (property.has_value()) return property.value().value; return default_style; } -static NonnullRefPtr<StyleValue> style_value_for_length_percentage(LengthPercentage const& length_percentage) +static NonnullRefPtr<StyleValue const> style_value_for_length_percentage(LengthPercentage const& length_percentage) { if (length_percentage.is_percentage()) return PercentageStyleValue::create(length_percentage.percentage()); @@ -138,7 +138,7 @@ static NonnullRefPtr<StyleValue> style_value_for_length_percentage(LengthPercent return length_percentage.calculated(); } -static NonnullRefPtr<StyleValue> style_value_for_size(CSS::Size const& size) +static NonnullRefPtr<StyleValue const> style_value_for_size(CSS::Size const& size) { if (size.is_none()) return IdentifierStyleValue::create(ValueID::None); @@ -156,7 +156,7 @@ static NonnullRefPtr<StyleValue> style_value_for_size(CSS::Size const& size) TODO(); } -RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout::NodeWithStyle const& layout_node, PropertyID property_id) const +RefPtr<StyleValue const> ResolvedCSSStyleDeclaration::style_value_for_property(Layout::NodeWithStyle const& layout_node, PropertyID property_id) const { switch (property_id) { case CSS::PropertyID::Background: { @@ -222,7 +222,7 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout: auto maybe_top_right_radius = property(CSS::PropertyID::BorderTopRightRadius); auto maybe_bottom_left_radius = property(CSS::PropertyID::BorderBottomLeftRadius); auto maybe_bottom_right_radius = property(CSS::PropertyID::BorderBottomRightRadius); - RefPtr<BorderRadiusStyleValue> top_left_radius, top_right_radius, bottom_left_radius, bottom_right_radius; + RefPtr<BorderRadiusStyleValue const> top_left_radius, top_right_radius, bottom_left_radius, bottom_right_radius; if (maybe_top_left_radius.has_value()) { VERIFY(maybe_top_left_radius.value().value->is_border_radius()); top_left_radius = maybe_top_left_radius.value().value->as_border_radius(); @@ -337,7 +337,7 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout: auto maybe_grid_column_start = property(CSS::PropertyID::GridColumnStart); auto maybe_grid_row_end = property(CSS::PropertyID::GridRowEnd); auto maybe_grid_column_end = property(CSS::PropertyID::GridColumnEnd); - RefPtr<GridTrackPlacementStyleValue> grid_row_start, grid_column_start, grid_row_end, grid_column_end; + RefPtr<GridTrackPlacementStyleValue const> grid_row_start, grid_column_start, grid_row_end, grid_column_end; if (maybe_grid_row_start.has_value()) { VERIFY(maybe_grid_row_start.value().value->is_grid_track_placement()); grid_row_start = maybe_grid_row_start.value().value->as_grid_track_placement(); @@ -363,7 +363,7 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout: case CSS::PropertyID::GridColumn: { auto maybe_grid_column_end = property(CSS::PropertyID::GridColumnEnd); auto maybe_grid_column_start = property(CSS::PropertyID::GridColumnStart); - RefPtr<GridTrackPlacementStyleValue> grid_column_start, grid_column_end; + RefPtr<GridTrackPlacementStyleValue const> grid_column_start, grid_column_end; if (maybe_grid_column_end.has_value()) { VERIFY(maybe_grid_column_end.value().value->is_grid_track_placement()); grid_column_end = maybe_grid_column_end.value().value->as_grid_track_placement(); @@ -381,7 +381,7 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout: case CSS::PropertyID::GridRow: { auto maybe_grid_row_end = property(CSS::PropertyID::GridRowEnd); auto maybe_grid_row_start = property(CSS::PropertyID::GridRowStart); - RefPtr<GridTrackPlacementStyleValue> grid_row_start, grid_row_end; + RefPtr<GridTrackPlacementStyleValue const> grid_row_start, grid_row_end; if (maybe_grid_row_end.has_value()) { VERIFY(maybe_grid_row_end.value().value->is_grid_track_placement()); grid_row_end = maybe_grid_row_end.value().value->as_grid_track_placement(); diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h index b659be5dda..3fb7686a17 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021-2023, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -32,7 +32,7 @@ private: virtual void visit_edges(Cell::Visitor&) override; - RefPtr<StyleValue> style_value_for_property(Layout::NodeWithStyle const&, PropertyID) const; + RefPtr<StyleValue const> style_value_for_property(Layout::NodeWithStyle const&, PropertyID) const; JS::NonnullGCPtr<DOM::Element> m_element; }; diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index a1a29bee7f..f76ef83c44 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, the SerenityOS developers. * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> * @@ -587,7 +587,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope style.set_property(property_id, value); } -static RefPtr<StyleValue> get_custom_property(DOM::Element const& element, FlyString const& custom_property_name) +static RefPtr<StyleValue const> get_custom_property(DOM::Element const& element, FlyString const& custom_property_name) { for (auto const* current_element = &element; current_element; current_element = current_element->parent_element()) { if (auto it = current_element->custom_properties().find(custom_property_name.to_string().to_deprecated_string()); it != current_element->custom_properties().end()) @@ -907,7 +907,7 @@ static DOM::Element const* element_to_inherit_style_from(DOM::Element const* ele return parent_element; } -static NonnullRefPtr<StyleValue> get_inherit_value(CSS::PropertyID property_id, DOM::Element const* element, Optional<CSS::Selector::PseudoElement> pseudo_element) +static NonnullRefPtr<StyleValue const> get_inherit_value(CSS::PropertyID property_id, DOM::Element const* element, Optional<CSS::Selector::PseudoElement> pseudo_element) { auto* parent_element = element_to_inherit_style_from(element, pseudo_element); @@ -1083,7 +1083,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele else weight = Gfx::FontWeight::Black; } else if (font_weight->is_calculated()) { - auto maybe_weight = font_weight->as_calculated().resolve_integer(); + auto maybe_weight = const_cast<CalculatedStyleValue&>(font_weight->as_calculated()).resolve_integer(); if (maybe_weight.has_value()) weight = maybe_weight.value(); } @@ -1152,7 +1152,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele maybe_length = font_size->to_length(); } else if (font_size->is_calculated()) { - maybe_length = Length::make_calculated(font_size->as_calculated()); + maybe_length = Length::make_calculated(const_cast<CalculatedStyleValue&>(font_size->as_calculated())); } if (maybe_length.has_value()) { // FIXME: Support font-size: calc(...) @@ -1187,7 +1187,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele FontSelector font_selector; bool monospace = false; - auto find_font = [&](String const& family) -> RefPtr<Gfx::Font> { + auto find_font = [&](String const& family) -> RefPtr<Gfx::Font const> { float font_size_in_pt = font_size_in_px * 0.75f; font_selector = { family, font_size_in_pt, weight, width, slope }; @@ -1206,7 +1206,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele return {}; }; - auto find_generic_font = [&](ValueID font_id) -> RefPtr<Gfx::Font> { + auto find_generic_font = [&](ValueID font_id) -> RefPtr<Gfx::Font const> { Platform::GenericFont generic_font {}; switch (font_id) { case ValueID::Monospace: @@ -1241,7 +1241,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele return find_font(String::from_utf8(Platform::FontPlugin::the().generic_font_name(generic_font)).release_value_but_fixme_should_propagate_errors()); }; - RefPtr<Gfx::Font> found_font; + RefPtr<Gfx::Font const> found_font; auto family_value = style.property(PropertyID::FontFamily); if (family_value->is_value_list()) { diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index a8785b6e1c..0075dccc9f 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause @@ -31,12 +31,12 @@ NonnullRefPtr<StyleProperties> StyleProperties::clone() const return adopt_ref(*new StyleProperties(*this)); } -void StyleProperties::set_property(CSS::PropertyID id, NonnullRefPtr<StyleValue> value) +void StyleProperties::set_property(CSS::PropertyID id, NonnullRefPtr<StyleValue const> value) { m_property_values[to_underlying(id)] = move(value); } -NonnullRefPtr<StyleValue> StyleProperties::property(CSS::PropertyID property_id) const +NonnullRefPtr<StyleValue const> StyleProperties::property(CSS::PropertyID property_id) const { auto value = m_property_values[to_underlying(property_id)]; // By the time we call this method, all properties have values assigned. @@ -44,7 +44,7 @@ NonnullRefPtr<StyleValue> StyleProperties::property(CSS::PropertyID property_id) return value.release_nonnull(); } -RefPtr<StyleValue> StyleProperties::maybe_null_property(CSS::PropertyID property_id) const +RefPtr<StyleValue const> StyleProperties::maybe_null_property(CSS::PropertyID property_id) const { return m_property_values[to_underlying(property_id)]; } @@ -68,7 +68,7 @@ CSS::Size StyleProperties::size_value(CSS::PropertyID id) const } if (value->is_calculated()) - return CSS::Size::make_length(CSS::Length::make_calculated(value->as_calculated())); + return CSS::Size::make_length(CSS::Length::make_calculated(const_cast<CalculatedStyleValue&>(value->as_calculated()))); if (value->is_percentage()) return CSS::Size::make_percentage(value->as_percentage().percentage()); @@ -95,7 +95,7 @@ Optional<LengthPercentage> StyleProperties::length_percentage(CSS::PropertyID id auto value = property(id); if (value->is_calculated()) - return LengthPercentage { value->as_calculated() }; + return LengthPercentage { const_cast<CalculatedStyleValue&>(value->as_calculated()) }; if (value->is_percentage()) return value->as_percentage().percentage(); @@ -124,7 +124,7 @@ Color StyleProperties::color_or_fallback(CSS::PropertyID id, Layout::NodeWithSty return value->to_color(node); } -NonnullRefPtr<Gfx::Font> StyleProperties::font_fallback(bool monospace, bool bold) +NonnullRefPtr<Gfx::Font const> StyleProperties::font_fallback(bool monospace, bool bold) { if (monospace && bold) return Platform::FontPlugin::the().default_fixed_width_font().bold_variant(); @@ -161,7 +161,7 @@ CSSPixels StyleProperties::line_height(Layout::Node const& layout_node) const } if (line_height->is_calculated()) - return CSS::Length::make_calculated(line_height->as_calculated()).to_px(layout_node); + return CSS::Length::make_calculated(const_cast<CalculatedStyleValue&>(line_height->as_calculated())).to_px(layout_node); return layout_node.font().pixel_metrics().line_spacing(); } @@ -193,7 +193,7 @@ float StyleProperties::opacity() const else dbgln("Unable to resolve calc() as opacity (percentage): {}", value->to_string()); } else { - auto maybe_number = value->as_calculated().resolve_number(); + auto maybe_number = const_cast<CalculatedStyleValue&>(value->as_calculated()).resolve_number(); if (maybe_number.has_value()) unclamped_opacity = maybe_number.value(); else diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h index 572528a6dc..7c780fe218 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -38,9 +38,9 @@ public: auto& properties() { return m_property_values; } auto const& properties() const { return m_property_values; } - void set_property(CSS::PropertyID, NonnullRefPtr<StyleValue> value); - NonnullRefPtr<StyleValue> property(CSS::PropertyID) const; - RefPtr<StyleValue> maybe_null_property(CSS::PropertyID) const; + void set_property(CSS::PropertyID, NonnullRefPtr<StyleValue const> value); + NonnullRefPtr<StyleValue const> property(CSS::PropertyID) const; + RefPtr<StyleValue const> maybe_null_property(CSS::PropertyID) const; CSS::Size size_value(CSS::PropertyID) const; LengthPercentage length_percentage_or_fallback(CSS::PropertyID, LengthPercentage const& fallback) const; @@ -103,7 +103,7 @@ public: return *m_font; } - void set_computed_font(NonnullRefPtr<Gfx::Font> font) + void set_computed_font(NonnullRefPtr<Gfx::Font const> font) { m_font = move(font); } @@ -115,16 +115,16 @@ public: Optional<CSS::Position> position() const; Optional<int> z_index() const; - static NonnullRefPtr<Gfx::Font> font_fallback(bool monospace, bool bold); + static NonnullRefPtr<Gfx::Font const> font_fallback(bool monospace, bool bold); private: friend class StyleComputer; - Array<RefPtr<StyleValue>, to_underlying(CSS::last_property_id) + 1> m_property_values; + Array<RefPtr<StyleValue const>, to_underlying(CSS::last_property_id) + 1> m_property_values; Optional<CSS::Overflow> overflow(CSS::PropertyID) const; Vector<CSS::ShadowData> shadow(CSS::PropertyID) const; - mutable RefPtr<Gfx::Font> m_font; + mutable RefPtr<Gfx::Font const> m_font; }; } diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index 6743d32f6c..770df8b3bd 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -291,14 +291,14 @@ StyleValueList const& StyleValue::as_value_list() const } BackgroundStyleValue::BackgroundStyleValue( - ValueComparingNonnullRefPtr<StyleValue> color, - ValueComparingNonnullRefPtr<StyleValue> image, - ValueComparingNonnullRefPtr<StyleValue> position, - ValueComparingNonnullRefPtr<StyleValue> size, - ValueComparingNonnullRefPtr<StyleValue> repeat, - ValueComparingNonnullRefPtr<StyleValue> attachment, - ValueComparingNonnullRefPtr<StyleValue> origin, - ValueComparingNonnullRefPtr<StyleValue> clip) + ValueComparingNonnullRefPtr<StyleValue const> color, + ValueComparingNonnullRefPtr<StyleValue const> image, + ValueComparingNonnullRefPtr<StyleValue const> position, + ValueComparingNonnullRefPtr<StyleValue const> size, + ValueComparingNonnullRefPtr<StyleValue const> repeat, + ValueComparingNonnullRefPtr<StyleValue const> attachment, + ValueComparingNonnullRefPtr<StyleValue const> origin, + ValueComparingNonnullRefPtr<StyleValue const> clip) : StyleValueWithDefaultOperators(Type::Background) , m_properties { .color = move(color), @@ -335,7 +335,7 @@ ErrorOr<String> BackgroundStyleValue::to_string() const return String::formatted("{} {} {} {} {} {} {} {}", TRY(m_properties.color->to_string()), TRY(m_properties.image->to_string()), TRY(m_properties.position->to_string()), TRY(m_properties.size->to_string()), TRY(m_properties.repeat->to_string()), TRY(m_properties.attachment->to_string()), TRY(m_properties.origin->to_string()), TRY(m_properties.clip->to_string())); } - auto get_layer_value_string = [](ValueComparingNonnullRefPtr<StyleValue> const& style_value, size_t index) { + auto get_layer_value_string = [](ValueComparingNonnullRefPtr<StyleValue const> const& style_value, size_t index) { if (style_value->is_value_list()) return style_value->as_value_list().value_at(index, true)->to_string(); return style_value->to_string(); @@ -2236,19 +2236,19 @@ static Optional<CSS::Length> absolutized_length(CSS::Length const& length, CSSPi return {}; } -ValueComparingNonnullRefPtr<StyleValue> StyleValue::absolutized(CSSPixelRect const&, Gfx::FontPixelMetrics const&, CSSPixels, CSSPixels) const +ValueComparingNonnullRefPtr<StyleValue const> StyleValue::absolutized(CSSPixelRect const&, Gfx::FontPixelMetrics const&, CSSPixels, CSSPixels) const { return *this; } -ValueComparingNonnullRefPtr<StyleValue> LengthStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const +ValueComparingNonnullRefPtr<StyleValue const> LengthStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const { if (auto length = absolutized_length(m_length, viewport_rect, font_metrics, font_size, root_font_size); length.has_value()) return LengthStyleValue::create(length.release_value()); return *this; } -ValueComparingNonnullRefPtr<StyleValue> ShadowStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const +ValueComparingNonnullRefPtr<StyleValue const> ShadowStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const { auto absolutized_offset_x = absolutized_length(m_properties.offset_x, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_properties.offset_x); auto absolutized_offset_y = absolutized_length(m_properties.offset_y, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_properties.offset_y); @@ -2257,7 +2257,7 @@ ValueComparingNonnullRefPtr<StyleValue> ShadowStyleValue::absolutized(CSSPixelRe return ShadowStyleValue::create(m_properties.color, absolutized_offset_x, absolutized_offset_y, absolutized_blur_radius, absolutized_spread_distance, m_properties.placement); } -ValueComparingNonnullRefPtr<StyleValue> BorderRadiusStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const +ValueComparingNonnullRefPtr<StyleValue const> BorderRadiusStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const { if (m_properties.horizontal_radius.is_percentage() && m_properties.vertical_radius.is_percentage()) return *this; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index 4e842922b9..638f2dfe07 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -269,7 +269,7 @@ private: template<typename T> using ValueComparingNonnullRefPtrVector = AK::NonnullPtrVector<ValueComparingNonnullRefPtr<T>>; -using StyleValueVector = ValueComparingNonnullRefPtrVector<StyleValue>; +using StyleValueVector = ValueComparingNonnullRefPtrVector<StyleValue const>; class StyleValue : public RefCounted<StyleValue> { public: @@ -469,7 +469,7 @@ public: virtual bool has_number() const { return false; } virtual bool has_integer() const { return false; } - virtual ValueComparingNonnullRefPtr<StyleValue> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const; + virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const; virtual Color to_color(Layout::NodeWithStyle const&) const { return {}; } virtual EdgeRect to_rect() const { VERIFY_NOT_REACHED(); } @@ -533,14 +533,14 @@ private: class BackgroundStyleValue final : public StyleValueWithDefaultOperators<BackgroundStyleValue> { public: static ValueComparingNonnullRefPtr<BackgroundStyleValue> create( - ValueComparingNonnullRefPtr<StyleValue> color, - ValueComparingNonnullRefPtr<StyleValue> image, - ValueComparingNonnullRefPtr<StyleValue> position, - ValueComparingNonnullRefPtr<StyleValue> size, - ValueComparingNonnullRefPtr<StyleValue> repeat, - ValueComparingNonnullRefPtr<StyleValue> attachment, - ValueComparingNonnullRefPtr<StyleValue> origin, - ValueComparingNonnullRefPtr<StyleValue> clip) + ValueComparingNonnullRefPtr<StyleValue const> color, + ValueComparingNonnullRefPtr<StyleValue const> image, + ValueComparingNonnullRefPtr<StyleValue const> position, + ValueComparingNonnullRefPtr<StyleValue const> size, + ValueComparingNonnullRefPtr<StyleValue const> repeat, + ValueComparingNonnullRefPtr<StyleValue const> attachment, + ValueComparingNonnullRefPtr<StyleValue const> origin, + ValueComparingNonnullRefPtr<StyleValue const> clip) { return adopt_ref(*new BackgroundStyleValue(move(color), move(image), move(position), move(size), move(repeat), move(attachment), move(origin), move(clip))); } @@ -548,14 +548,14 @@ public: size_t layer_count() const { return m_properties.layer_count; } - ValueComparingNonnullRefPtr<StyleValue> attachment() const { return m_properties.attachment; } - ValueComparingNonnullRefPtr<StyleValue> clip() const { return m_properties.clip; } - ValueComparingNonnullRefPtr<StyleValue> color() const { return m_properties.color; } - ValueComparingNonnullRefPtr<StyleValue> image() const { return m_properties.image; } - ValueComparingNonnullRefPtr<StyleValue> origin() const { return m_properties.origin; } - ValueComparingNonnullRefPtr<StyleValue> position() const { return m_properties.position; } - ValueComparingNonnullRefPtr<StyleValue> repeat() const { return m_properties.repeat; } - ValueComparingNonnullRefPtr<StyleValue> size() const { return m_properties.size; } + auto attachment() const { return m_properties.attachment; } + auto clip() const { return m_properties.clip; } + auto color() const { return m_properties.color; } + auto image() const { return m_properties.image; } + auto origin() const { return m_properties.origin; } + auto position() const { return m_properties.position; } + auto repeat() const { return m_properties.repeat; } + auto size() const { return m_properties.size; } virtual ErrorOr<String> to_string() const override; @@ -563,24 +563,24 @@ public: private: BackgroundStyleValue( - ValueComparingNonnullRefPtr<StyleValue> color, - ValueComparingNonnullRefPtr<StyleValue> image, - ValueComparingNonnullRefPtr<StyleValue> position, - ValueComparingNonnullRefPtr<StyleValue> size, - ValueComparingNonnullRefPtr<StyleValue> repeat, - ValueComparingNonnullRefPtr<StyleValue> attachment, - ValueComparingNonnullRefPtr<StyleValue> origin, - ValueComparingNonnullRefPtr<StyleValue> clip); + ValueComparingNonnullRefPtr<StyleValue const> color, + ValueComparingNonnullRefPtr<StyleValue const> image, + ValueComparingNonnullRefPtr<StyleValue const> position, + ValueComparingNonnullRefPtr<StyleValue const> size, + ValueComparingNonnullRefPtr<StyleValue const> repeat, + ValueComparingNonnullRefPtr<StyleValue const> attachment, + ValueComparingNonnullRefPtr<StyleValue const> origin, + ValueComparingNonnullRefPtr<StyleValue const> clip); struct Properties { - ValueComparingNonnullRefPtr<StyleValue> color; - ValueComparingNonnullRefPtr<StyleValue> image; - ValueComparingNonnullRefPtr<StyleValue> position; - ValueComparingNonnullRefPtr<StyleValue> size; - ValueComparingNonnullRefPtr<StyleValue> repeat; - ValueComparingNonnullRefPtr<StyleValue> attachment; - ValueComparingNonnullRefPtr<StyleValue> origin; - ValueComparingNonnullRefPtr<StyleValue> clip; + ValueComparingNonnullRefPtr<StyleValue const> color; + ValueComparingNonnullRefPtr<StyleValue const> image; + ValueComparingNonnullRefPtr<StyleValue const> position; + ValueComparingNonnullRefPtr<StyleValue const> size; + ValueComparingNonnullRefPtr<StyleValue const> repeat; + ValueComparingNonnullRefPtr<StyleValue const> attachment; + ValueComparingNonnullRefPtr<StyleValue const> origin; + ValueComparingNonnullRefPtr<StyleValue const> clip; size_t layer_count; bool operator==(Properties const&) const = default; } m_properties; @@ -705,7 +705,7 @@ private: { } - virtual ValueComparingNonnullRefPtr<StyleValue> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const override; + virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const override; struct Properties { bool is_elliptical; @@ -717,33 +717,41 @@ private: class BorderRadiusShorthandStyleValue final : public StyleValueWithDefaultOperators<BorderRadiusShorthandStyleValue> { public: - static ValueComparingNonnullRefPtr<BorderRadiusShorthandStyleValue> create(ValueComparingNonnullRefPtr<BorderRadiusStyleValue> top_left, ValueComparingNonnullRefPtr<BorderRadiusStyleValue> top_right, ValueComparingNonnullRefPtr<BorderRadiusStyleValue> bottom_right, ValueComparingNonnullRefPtr<BorderRadiusStyleValue> bottom_left) + static ValueComparingNonnullRefPtr<BorderRadiusShorthandStyleValue> create( + ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_left, + ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_right, + ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_right, + ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_left) { return adopt_ref(*new BorderRadiusShorthandStyleValue(move(top_left), move(top_right), move(bottom_right), move(bottom_left))); } virtual ~BorderRadiusShorthandStyleValue() override = default; - ValueComparingNonnullRefPtr<BorderRadiusStyleValue> top_left() const { return m_properties.top_left; } - ValueComparingNonnullRefPtr<BorderRadiusStyleValue> top_right() const { return m_properties.top_right; } - ValueComparingNonnullRefPtr<BorderRadiusStyleValue> bottom_right() const { return m_properties.bottom_right; } - ValueComparingNonnullRefPtr<BorderRadiusStyleValue> bottom_left() const { return m_properties.bottom_left; } + auto top_left() const { return m_properties.top_left; } + auto top_right() const { return m_properties.top_right; } + auto bottom_right() const { return m_properties.bottom_right; } + auto bottom_left() const { return m_properties.bottom_left; } virtual ErrorOr<String> to_string() const override; bool properties_equal(BorderRadiusShorthandStyleValue const& other) const { return m_properties == other.m_properties; } private: - BorderRadiusShorthandStyleValue(ValueComparingNonnullRefPtr<BorderRadiusStyleValue> top_left, ValueComparingNonnullRefPtr<BorderRadiusStyleValue> top_right, ValueComparingNonnullRefPtr<BorderRadiusStyleValue> bottom_right, ValueComparingNonnullRefPtr<BorderRadiusStyleValue> bottom_left) + BorderRadiusShorthandStyleValue( + ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_left, + ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_right, + ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_right, + ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_left) : StyleValueWithDefaultOperators(Type::BorderRadiusShorthand) , m_properties { .top_left = move(top_left), .top_right = move(top_right), .bottom_right = move(bottom_right), .bottom_left = move(bottom_left) } { } struct Properties { - ValueComparingNonnullRefPtr<BorderRadiusStyleValue> top_left; - ValueComparingNonnullRefPtr<BorderRadiusStyleValue> top_right; - ValueComparingNonnullRefPtr<BorderRadiusStyleValue> bottom_right; - ValueComparingNonnullRefPtr<BorderRadiusStyleValue> bottom_left; + ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_left; + ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_right; + ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_right; + ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_left; bool operator==(Properties const&) const = default; } m_properties; }; @@ -1206,7 +1214,7 @@ private: class GridTrackPlacementShorthandStyleValue final : public StyleValueWithDefaultOperators<GridTrackPlacementShorthandStyleValue> { public: - static ValueComparingNonnullRefPtr<GridTrackPlacementShorthandStyleValue> create(ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> end) + static ValueComparingNonnullRefPtr<GridTrackPlacementShorthandStyleValue> create(ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> end) { return adopt_ref(*new GridTrackPlacementShorthandStyleValue(move(start), move(end))); } @@ -1216,30 +1224,34 @@ public: } virtual ~GridTrackPlacementShorthandStyleValue() override = default; - ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> start() const { return m_properties.start; } - ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> end() const { return m_properties.end; } + auto start() const { return m_properties.start; } + auto end() const { return m_properties.end; } virtual ErrorOr<String> to_string() const override; bool properties_equal(GridTrackPlacementShorthandStyleValue const& other) const { return m_properties == other.m_properties; }; private: - GridTrackPlacementShorthandStyleValue(ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> end) + GridTrackPlacementShorthandStyleValue(ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> end) : StyleValueWithDefaultOperators(Type::GridTrackPlacementShorthand) , m_properties { .start = move(start), .end = move(end) } { } struct Properties { - ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> start; - ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> end; + ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> start; + ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> end; bool operator==(Properties const&) const = default; } m_properties; }; class GridAreaShorthandStyleValue final : public StyleValueWithDefaultOperators<GridAreaShorthandStyleValue> { public: - static ValueComparingNonnullRefPtr<GridAreaShorthandStyleValue> create(ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> row_start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> column_start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> row_end, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> column_end) + static ValueComparingNonnullRefPtr<GridAreaShorthandStyleValue> create( + ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_start, + ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_start, + ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_end, + ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_end) { return adopt_ref(*new GridAreaShorthandStyleValue(row_start, column_start, row_end, column_end)); } @@ -1249,27 +1261,27 @@ public: } virtual ~GridAreaShorthandStyleValue() override = default; - ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> row_start() const { return m_properties.row_start; } - ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> column_start() const { return m_properties.column_start; } - ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> row_end() const { return m_properties.row_end; } - ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> column_end() const { return m_properties.column_end; } + auto row_start() const { return m_properties.row_start; } + auto column_start() const { return m_properties.column_start; } + auto row_end() const { return m_properties.row_end; } + auto column_end() const { return m_properties.column_end; } virtual ErrorOr<String> to_string() const override; bool properties_equal(GridAreaShorthandStyleValue const& other) const { return m_properties == other.m_properties; } private: - GridAreaShorthandStyleValue(ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> row_start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> column_start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> row_end, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> column_end) + GridAreaShorthandStyleValue(ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_end, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_end) : StyleValueWithDefaultOperators(Type::GridAreaShorthand) , m_properties { .row_start = move(row_start), .column_start = move(column_start), .row_end = move(row_end), .column_end = move(column_end) } { } struct Properties { - ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> row_start; - ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> column_start; - ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> row_end; - ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue> column_end; + ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_start; + ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_start; + ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_end; + ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_end; bool operator==(Properties const&) const = default; } m_properties; }; @@ -1623,7 +1635,7 @@ public: virtual ErrorOr<String> to_string() const override { return m_length.to_string(); } virtual Length to_length() const override { return m_length; } virtual ValueID to_identifier() const override { return has_auto() ? ValueID::Auto : ValueID::Invalid; } - virtual ValueComparingNonnullRefPtr<StyleValue> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const override; + virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const override; bool properties_equal(LengthStyleValue const& other) const { return m_length == other.m_length; } @@ -1852,7 +1864,7 @@ private: { } - virtual ValueComparingNonnullRefPtr<StyleValue> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const override; + virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const override; struct Properties { Color color; @@ -2038,7 +2050,7 @@ public: size_t size() const { return m_properties.values.size(); } StyleValueVector const& values() const { return m_properties.values; } - ValueComparingNonnullRefPtr<StyleValue> value_at(size_t i, bool allow_loop) const + ValueComparingNonnullRefPtr<StyleValue const> value_at(size_t i, bool allow_loop) const { if (allow_loop) return m_properties.values[i % size()]; diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 7b1ca4b494..5beb5257bf 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -122,6 +122,7 @@ public: DeprecatedString name() const { return attribute(HTML::AttributeNames::name); } + CSS::StyleProperties* computed_css_values() { return m_computed_css_values.ptr(); } CSS::StyleProperties const* computed_css_values() const { return m_computed_css_values.ptr(); } void set_computed_css_values(RefPtr<CSS::StyleProperties> style) { m_computed_css_values = move(style); } NonnullRefPtr<CSS::StyleProperties> resolved_css_values(); diff --git a/Userland/Libraries/LibWeb/FontCache.cpp b/Userland/Libraries/LibWeb/FontCache.cpp index 30b93f641f..b37bf8e553 100644 --- a/Userland/Libraries/LibWeb/FontCache.cpp +++ b/Userland/Libraries/LibWeb/FontCache.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -13,7 +13,7 @@ FontCache& FontCache::the() return cache; } -RefPtr<Gfx::Font> FontCache::get(FontSelector const& font_selector) const +RefPtr<Gfx::Font const> FontCache::get(FontSelector const& font_selector) const { auto cached_font = m_fonts.get(font_selector); if (cached_font.has_value()) @@ -21,7 +21,7 @@ RefPtr<Gfx::Font> FontCache::get(FontSelector const& font_selector) const return nullptr; } -void FontCache::set(FontSelector const& font_selector, NonnullRefPtr<Gfx::Font> font) +void FontCache::set(FontSelector const& font_selector, NonnullRefPtr<Gfx::Font const> font) { m_fonts.set(font_selector, move(font)); } diff --git a/Userland/Libraries/LibWeb/FontCache.h b/Userland/Libraries/LibWeb/FontCache.h index ce9cfe7622..daf725305f 100644 --- a/Userland/Libraries/LibWeb/FontCache.h +++ b/Userland/Libraries/LibWeb/FontCache.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -34,10 +34,10 @@ struct Traits<FontSelector> : public GenericTraits<FontSelector> { class FontCache { public: static FontCache& the(); - RefPtr<Gfx::Font> get(FontSelector const&) const; - void set(FontSelector const&, NonnullRefPtr<Gfx::Font>); + RefPtr<Gfx::Font const> get(FontSelector const&) const; + void set(FontSelector const&, NonnullRefPtr<Gfx::Font const>); private: FontCache() = default; - mutable HashMap<FontSelector, NonnullRefPtr<Gfx::Font>> m_fonts; + mutable HashMap<FontSelector, NonnullRefPtr<Gfx::Font const>> m_fonts; }; diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 8809e9c832..7bfd886de5 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -277,7 +277,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) return 1; }; - auto value_for_layer = [](auto& style_value, size_t layer_index) -> RefPtr<CSS::StyleValue> { + auto value_for_layer = [](auto& style_value, size_t layer_index) -> RefPtr<CSS::StyleValue const> { if (style_value->is_value_list()) return style_value->as_value_list().value_at(layer_index, true); return style_value; @@ -301,7 +301,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) if (auto image_value = value_for_layer(images, layer_index); image_value) { if (image_value->is_abstract_image()) { layer.background_image = image_value->as_abstract_image(); - layer.background_image->load_any_resources(document()); + const_cast<CSS::AbstractImageStyleValue&>(*layer.background_image).load_any_resources(document()); } } @@ -517,7 +517,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) 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(); - m_list_style_image->load_any_resources(document()); + const_cast<CSS::AbstractImageStyleValue&>(*m_list_style_image).load_any_resources(document()); } computed_values.set_color(computed_style.color_or_fallback(CSS::PropertyID::Color, *this, CSS::InitialValues::color())); @@ -574,7 +574,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) auto resolve_border_width = [&]() { auto value = computed_style.property(width_property); if (value->is_calculated()) - return CSS::Length::make_calculated(value->as_calculated()).to_px(*this).value(); + return CSS::Length::make_calculated(const_cast<CSS::CalculatedStyleValue&>(value->as_calculated())).to_px(*this).value(); if (value->has_length()) return value->to_length().to_px(*this).value(); if (value->is_identifier()) { diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index effb811f01..6df5d3495b 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -195,9 +195,9 @@ protected: private: CSS::ComputedValues m_computed_values; - RefPtr<Gfx::Font> m_font; + RefPtr<Gfx::Font const> m_font; CSSPixels m_line_height { 0 }; - RefPtr<CSS::AbstractImageStyleValue> m_list_style_image; + RefPtr<CSS::AbstractImageStyleValue const> m_list_style_image; }; class NodeWithStyleAndBoxModelMetrics : public NodeWithStyle { diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index bb1c807eeb..e3af41b338 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2022-2023, Andreas Kling <kling@serenityos.org> * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause @@ -513,7 +513,7 @@ static void paint_text_fragment(PaintContext& context, Layout::TextNode const& t Utf8View view { text.substring_view(fragment.start(), fragment.length()) }; auto& font = fragment.layout_node().font(); - auto scaled_font = [&]() -> RefPtr<Gfx::Font> { + auto scaled_font = [&]() -> RefPtr<Gfx::Font const> { auto device_font_pt_size = context.enclosing_device_pixels(font.presentation_size()); FontSelector font_selector = { FlyString::from_utf8(font.family()).release_value_but_fixme_should_propagate_errors(), static_cast<float>(device_font_pt_size.value()), font.weight(), font.width(), font.slope() }; if (auto cached_font = FontCache::the().get(font_selector)) { |